mirror of
https://github.com/ElvishArtisan/rivendell.git
synced 2025-10-17 08:01:13 +02:00
2021-02-01 Fred Gleason <fredg@paravelsystems.com>
* Added 'RDGpioSlotsModel'. * Refactored the 'Livewire GPIO Source Assignments' dialog in rdadmin(1) to use the model-based API. Signed-off-by: Fred Gleason <fredg@paravelsystems.com>
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
//
|
||||
// Edit a Rivendell Livewire GPIO Slot Association
|
||||
//
|
||||
// (C) Copyright 2013-2019 Fred Gleason <fredg@paravelsystems.com>
|
||||
// (C) Copyright 2013-2021 Fred Gleason <fredg@paravelsystems.com>
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License version 2 as
|
||||
@@ -23,36 +23,27 @@
|
||||
#include <qmessagebox.h>
|
||||
|
||||
#include <rd.h>
|
||||
#include <rdescape_string.h>
|
||||
|
||||
#include <edit_livewiregpio.h>
|
||||
#include "edit_livewiregpio.h"
|
||||
|
||||
EditLiveWireGpio::EditLiveWireGpio(int slot,int *source,QHostAddress *addr,
|
||||
QWidget *parent)
|
||||
EditLiveWireGpio::EditLiveWireGpio(QWidget *parent)
|
||||
: RDDialog(parent)
|
||||
{
|
||||
setModal(true);
|
||||
|
||||
edit_slot=slot;
|
||||
edit_source=source;
|
||||
edit_address=addr;
|
||||
|
||||
//
|
||||
// Fix the Window Size
|
||||
//
|
||||
setMinimumWidth(sizeHint().width());
|
||||
setMaximumWidth(sizeHint().width());
|
||||
setMinimumHeight(sizeHint().height());
|
||||
setMaximumHeight(sizeHint().height());
|
||||
setMinimumSize(sizeHint());
|
||||
setMaximumSize(sizeHint());
|
||||
setWindowTitle("RDAdmin - "+tr("Edit GPIO Source"));
|
||||
|
||||
//
|
||||
// GPIO Lines
|
||||
//
|
||||
QLabel *label=new QLabel(tr("GPIO Lines")+
|
||||
QString().sprintf(" %d - %d",5*slot+1,5*slot+5),this);
|
||||
label->setGeometry(10,10,sizeHint().width()-20,20);
|
||||
label->setFont(labelFont());
|
||||
label->setAlignment(Qt::AlignCenter);
|
||||
edit_title_label=new QLabel(this);
|
||||
edit_title_label->setGeometry(10,10,sizeHint().width()-20,20);
|
||||
edit_title_label->setFont(labelFont());
|
||||
edit_title_label->setAlignment(Qt::AlignCenter);
|
||||
|
||||
//
|
||||
// Livewire Source Number
|
||||
@@ -61,7 +52,7 @@ EditLiveWireGpio::EditLiveWireGpio(int slot,int *source,QHostAddress *addr,
|
||||
edit_source_number_spin->setGeometry(130,32,60,20);
|
||||
edit_source_number_spin->setRange(0,RD_LIVEWIRE_MAX_SOURCE);
|
||||
edit_source_number_spin->setSpecialValueText(tr("None"));
|
||||
label=new QLabel(tr("Livewire Source: "),this);
|
||||
QLabel *label=new QLabel(tr("Livewire Source: "),this);
|
||||
label->setGeometry(10,32,115,20);
|
||||
label->setFont(labelFont());
|
||||
label->setAlignment(Qt::AlignVCenter|Qt::AlignRight);
|
||||
@@ -94,14 +85,6 @@ EditLiveWireGpio::EditLiveWireGpio(int slot,int *source,QHostAddress *addr,
|
||||
button->setFont(buttonFont());
|
||||
button->setText(tr("&Cancel"));
|
||||
connect(button,SIGNAL(clicked()),this,SLOT(cancelData()));
|
||||
|
||||
//
|
||||
// Load Data
|
||||
//
|
||||
edit_source_number_spin->setValue(*edit_source);
|
||||
if(!edit_address->isNull()) {
|
||||
edit_ip_address_edit->setText(edit_address->toString());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -117,6 +100,37 @@ QSizePolicy EditLiveWireGpio::sizePolicy() const
|
||||
}
|
||||
|
||||
|
||||
int EditLiveWireGpio::exec(int slot_id)
|
||||
{
|
||||
QHostAddress addr;
|
||||
|
||||
edit_id=slot_id;
|
||||
|
||||
QString sql=QString("select ")+
|
||||
"SLOT,"+ // 00
|
||||
"SOURCE_NUMBER,"+ // 01
|
||||
"IP_ADDRESS "+ // 02
|
||||
"from LIVEWIRE_GPIO_SLOTS where "+
|
||||
QString().sprintf("ID=%u",slot_id);
|
||||
RDSqlQuery *q=new RDSqlQuery(sql);
|
||||
if(q->first()) {
|
||||
edit_title_label->
|
||||
setText(tr("GPIO Lines")+
|
||||
QString().sprintf(" %d - %d",
|
||||
5*q->value(0).toInt()+1,5*q->value(0).toInt()+5));
|
||||
edit_source_number_spin->setValue(q->value(1).toInt());
|
||||
if(addr.setAddress(q->value(2).toString())) {
|
||||
edit_ip_address_edit->setText(addr.toString());
|
||||
}
|
||||
else {
|
||||
edit_ip_address_edit->setText("");
|
||||
}
|
||||
}
|
||||
|
||||
return QDialog::exec();
|
||||
}
|
||||
|
||||
|
||||
void EditLiveWireGpio::okData()
|
||||
{
|
||||
QHostAddress addr;
|
||||
@@ -125,17 +139,20 @@ void EditLiveWireGpio::okData()
|
||||
if(addr.isNull()&&(!edit_ip_address_edit->text().isEmpty())&&
|
||||
(edit_ip_address_edit->text()!="0.0.0.0")) {
|
||||
QMessageBox::warning(this,"RDAdmin - "+tr("Invalid IP Address"),
|
||||
tr("The IP address is invalid!"));
|
||||
tr("The Surface Address is invalid!"));
|
||||
return;
|
||||
}
|
||||
*edit_source=edit_source_number_spin->value();
|
||||
edit_address->setAddress(addr.toString());
|
||||
QString sql=QString("update LIVEWIRE_GPIO_SLOTS set ")+
|
||||
QString().sprintf("SOURCE_NUMBER=%d,",edit_source_number_spin->value())+
|
||||
"IP_ADDRESS=\""+RDEscapeString(addr.toString())+"\" "+
|
||||
QString().sprintf("where ID=%u",edit_id);
|
||||
RDSqlQuery::apply(sql);
|
||||
|
||||
done(0);
|
||||
done(true);
|
||||
}
|
||||
|
||||
|
||||
void EditLiveWireGpio::cancelData()
|
||||
{
|
||||
done(-1);
|
||||
done(false);
|
||||
}
|
||||
|
Reference in New Issue
Block a user