2021-02-02 Fred Gleason <fredg@paravelsystems.com>

* Added 'RDSchedCodeListModel'.
	* Refactored the 'Rivendell Scheduler Codes List' dialog in
	rdadmin(1) to use the model-based API.

Signed-off-by: Fred Gleason <fredg@paravelsystems.com>
This commit is contained in:
Fred Gleason 2021-02-02 19:57:51 -05:00
parent 6512148633
commit b2f5bf72a5
18 changed files with 592 additions and 233 deletions

View File

@ -20986,3 +20986,7 @@
2021-02-02 Fred Gleason <fredg@paravelsystems.com>
* Commented out support for editing hotkeys in the 'Configure
RDAirPlay' dialog in rdadmin(1).
2021-02-02 Fred Gleason <fredg@paravelsystems.com>
* Added 'RDSchedCodeListModel'.
* Refactored the 'Rivendell Scheduler Codes List' dialog in
rdadmin(1) to use the model-based API.

View File

@ -228,6 +228,7 @@ dist_librd_la_SOURCES = dbversion.h\
rdrsscategorybox.cpp rdrsscategorybox.h\
rdschedcartlist.cpp rdschedcartlist.h\
rdschedcode.cpp rdschedcode.h\
rdschedcodelistmodel.cpp rdschedcodelistmodel.h\
rdschedcodes_dialog.cpp rdschedcodes_dialog.h\
rdschedruleslist.cpp rdschedruleslist.h\
rdsegmeter.cpp rdsegmeter.h\
@ -379,6 +380,7 @@ nodist_librd_la_SOURCES = moc_rd3emptycart.cpp\
moc_rdreplicatorlistmodel.cpp\
moc_rdresourcelistmodel.cpp\
moc_rdripc.cpp\
moc_rdschedcodelistmodel.cpp\
moc_rdschedcodes_dialog.cpp\
moc_rdrsscategorybox.cpp\
moc_rdsegmeter.cpp\

View File

@ -170,6 +170,7 @@ SOURCES += rdripc.cpp
SOURCES += rdrssschemas.cpp
SOURCES += rdrsscategorybox.cpp
SOURCES += rdschedcode.cpp
SOURCES += rdschedcodelistmodel.cpp
SOURCES += rdsegmeter.cpp
SOURCES += rdsendmail.cpp
SOURCES += rdsettings.cpp
@ -343,6 +344,7 @@ HEADERS += rdripc.h
HEADERS += rdrssschemas.h
HEADERS += rdrsscategorybox.h
HEADERS += rdschedcode.h
HEADERS += rdschedcodelistmodel.h
HEADERS += rdsegmeter.h
HEADERS += rdsendmail.h
HEADERS += rdservicelistmodel.h

View File

@ -3985,6 +3985,17 @@ Zkuste to, prosím, znovu!</translation>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>RDSchedCodeListModel</name>
<message>
<source>Code</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Description</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>RDServiceListModel</name>
<message>

View File

@ -3966,6 +3966,17 @@ bitte erneut versuchen!</translation>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>RDSchedCodeListModel</name>
<message>
<source>Code</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Description</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>RDServiceListModel</name>
<message>

View File

@ -3945,6 +3945,17 @@ please try again!</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>RDSchedCodeListModel</name>
<message>
<source>Code</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Description</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>RDServiceListModel</name>
<message>

View File

@ -3238,6 +3238,17 @@ please try again!</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>RDSchedCodeListModel</name>
<message>
<source>Code</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Description</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>RDServiceListModel</name>
<message>

View File

@ -3848,6 +3848,17 @@ prøv ein gong til!</translation>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>RDSchedCodeListModel</name>
<message>
<source>Code</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Description</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>RDServiceListModel</name>
<message>

View File

@ -3848,6 +3848,17 @@ prøv ein gong til!</translation>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>RDSchedCodeListModel</name>
<message>
<source>Code</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Description</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>RDServiceListModel</name>
<message>

View File

@ -3899,6 +3899,17 @@ por favor, tente novamente!</translation>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>RDSchedCodeListModel</name>
<message>
<source>Code</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Description</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>RDServiceListModel</name>
<message>

View File

@ -0,0 +1,270 @@
// rdschedcodelistmodel.cpp
//
// Data model for Rivendell schedule codes
//
// (C) Copyright 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
// published by the Free Software Foundation.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public
// License along with this program; if not, write to the Free Software
// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
//
#include "rdapplication.h"
#include "rdescape_string.h"
#include "rdschedcodelistmodel.h"
RDSchedCodeListModel::RDSchedCodeListModel(QObject *parent)
: QAbstractTableModel(parent)
{
//
// Column Attributes
//
unsigned left=Qt::AlignLeft|Qt::AlignVCenter;
// unsigned center=Qt::AlignCenter;
// unsigned right=Qt::AlignRight|Qt::AlignVCenter;
d_headers.push_back(tr("Code"));
d_alignments.push_back(left);
d_headers.push_back(tr("Description"));
d_alignments.push_back(left);
updateModel();
}
RDSchedCodeListModel::~RDSchedCodeListModel()
{
}
QPalette RDSchedCodeListModel::palette()
{
return d_palette;
}
void RDSchedCodeListModel::setPalette(const QPalette &pal)
{
d_palette=pal;
}
void RDSchedCodeListModel::setFont(const QFont &font)
{
d_font=font;
d_bold_font=font;
d_bold_font.setWeight(QFont::Bold);
}
int RDSchedCodeListModel::columnCount(const QModelIndex &parent) const
{
return d_headers.size();
}
int RDSchedCodeListModel::rowCount(const QModelIndex &parent) const
{
return d_texts.size();
}
QVariant RDSchedCodeListModel::headerData(int section,Qt::Orientation orient,
int role) const
{
if((orient==Qt::Horizontal)&&(role==Qt::DisplayRole)) {
return d_headers.at(section);
}
return QVariant();
}
QVariant RDSchedCodeListModel::data(const QModelIndex &index,int role) const
{
QString str;
int col=index.column();
int row=index.row();
if(row<d_texts.size()) {
switch((Qt::ItemDataRole)role) {
case Qt::DisplayRole:
return d_texts.at(row).at(col);
case Qt::DecorationRole:
// Nothing to do!
break;
case Qt::TextAlignmentRole:
return d_alignments.at(col);
case Qt::FontRole:
if(col==0) {
return d_bold_font;
}
return d_font;
case Qt::TextColorRole:
// Nothing to do!
break;
case Qt::BackgroundRole:
// Nothing to do!
break;
default:
break;
}
}
return QVariant();
}
QString RDSchedCodeListModel::schedCode(const QModelIndex &row) const
{
return d_texts.at(row.row()).at(0).toString();
}
QModelIndex RDSchedCodeListModel::addSchedCode(const QString &scode)
{
//
// Find the insertion offset
//
int offset=d_texts.size();
for(int i=0;i<d_texts.size();i++) {
if(scode.toLower()<d_texts.at(i).at(0).toString().toLower()) {
offset=i;
break;
}
}
beginInsertRows(QModelIndex(),offset,offset);
QList<QVariant> list;
for(int i=0;i<columnCount();i++) {
list.push_back(QVariant());
}
list[0]=scode;
d_texts.insert(offset,list);
updateRowLine(offset);
endInsertRows();
return createIndex(offset,0);
}
void RDSchedCodeListModel::removeSchedCode(const QModelIndex &row)
{
beginRemoveRows(QModelIndex(),row.row(),row.row());
d_texts.removeAt(row.row());
endRemoveRows();
}
void RDSchedCodeListModel::removeSchedCode(const QString &scode)
{
for(int i=0;i<d_texts.size();i++) {
if(d_texts.at(i).at(0)==scode) {
removeSchedCode(createIndex(i,0));
return;
}
}
}
void RDSchedCodeListModel::refresh(const QModelIndex &row)
{
if(row.row()<d_texts.size()) {
QString sql=sqlFields()+
"where CODE=\""+
RDEscapeString(d_texts.at(row.row()).at(0).toString())+
"\"";
RDSqlQuery *q=new RDSqlQuery(sql);
if(q->first()) {
updateRow(row.row(),q);
emit dataChanged(createIndex(row.row(),0),
createIndex(row.row(),columnCount()));
}
delete q;
}
}
void RDSchedCodeListModel::refresh(const QString &scode)
{
for(int i=0;i<d_texts.size();i++) {
if(d_texts.at(i).at(0)==scode) {
updateRowLine(i);
return;
}
}
}
void RDSchedCodeListModel::updateModel()
{
QList<QVariant> texts;
RDSqlQuery *q=NULL;
QString sql=sqlFields();
sql+="order by CODE ";
beginResetModel();
d_texts.clear();
q=new RDSqlQuery(sql);
while(q->next()) {
d_texts.push_back(texts);
updateRow(d_texts.size()-1,q);
}
delete q;
endResetModel();
}
void RDSchedCodeListModel::updateRowLine(int line)
{
if(line<d_texts.size()) {
QString sql=sqlFields()+
"where CODE=\""+RDEscapeString(d_texts.at(line).at(0).toString())+"\"";
RDSqlQuery *q=new RDSqlQuery(sql);
if(q->first()) {
updateRow(line,q);
}
delete q;
}
}
void RDSchedCodeListModel::updateRow(int row,RDSqlQuery *q)
{
QList<QVariant> texts;
// Code
texts.push_back(q->value(0));
// Description
texts.push_back(q->value(1));
d_texts[row]=texts;
}
QString RDSchedCodeListModel::sqlFields() const
{
QString sql=QString("select ")+
"CODE,"+ // 00
"DESCRIPTION "+ // 01
"from SCHED_CODES ";
return sql;
}

View File

@ -0,0 +1,70 @@
// rdschedcodelistmodel.h
//
// Data model for Rivendell schedule codes
//
// (C) Copyright 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
// published by the Free Software Foundation.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public
// License along with this program; if not, write to the Free Software
// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
//
#ifndef RDSCHEDCODELISTMODEL_H
#define RDSCHEDCODELISTMODEL_H
#include <QAbstractTableModel>
#include <QFont>
#include <QList>
#include <QPalette>
#include <rddb.h>
#include <rdnotification.h>
#include <rduser.h>
class RDSchedCodeListModel : public QAbstractTableModel
{
Q_OBJECT
public:
RDSchedCodeListModel(QObject *parent=0);
~RDSchedCodeListModel();
QPalette palette();
void setPalette(const QPalette &pal);
void setFont(const QFont &font);
int columnCount(const QModelIndex &parent=QModelIndex()) const;
int rowCount(const QModelIndex &parent=QModelIndex()) const;
QVariant headerData(int section,Qt::Orientation orient,
int role=Qt::DisplayRole) const;
QVariant data(const QModelIndex &index,int role=Qt::DisplayRole) const;
QString schedCode(const QModelIndex &row) const;
QModelIndex addSchedCode(const QString &scode);
void removeSchedCode(const QModelIndex &row);
void removeSchedCode(const QString &scode);
void refresh(const QModelIndex &row);
void refresh(const QString &scode);
protected:
void updateModel();
void updateRowLine(int line);
void updateRow(int row,RDSqlQuery *q);
QString sqlFields() const;
private:
QPalette d_palette;
QFont d_font;
QFont d_bold_font;
QList<QVariant> d_headers;
QList<QVariant> d_alignments;
QList<QList<QVariant> > d_texts;
};
#endif // RDSCHEDCODELISTMODEL_H

View File

@ -3,7 +3,7 @@
// Add scheduler codes dialog
//
// (C) Copyright 2005-2018 Stefan Gabriel <stg@st-gabriel.de>
// (C) Copyright 2018-2019 Fred Gleason <fredg@paravelsystems.com>
// (C) Copyright 2018-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
@ -19,56 +19,33 @@
// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
//
#include <qstring.h>
#include <qpushbutton.h>
#include <q3listbox.h>
#include <q3textedit.h>
#include <qlabel.h>
#include <qpainter.h>
#include <qevent.h>
#include <qmessagebox.h>
#include <qcheckbox.h>
#include <q3buttongroup.h>
#include <QMessageBox>
#include <QPushButton>
#include <rddb.h>
#include <rdescape_string.h>
#include <rdpasswd.h>
#include <rdtextvalidator.h>
#include "edit_schedcodes.h"
#include "add_schedcodes.h"
AddSchedCode::AddSchedCode(QString *schedCode,QWidget *parent)
AddSchedCode::AddSchedCode(QWidget *parent)
: RDDialog(parent)
{
setModal(true);
schedcode_schedCode=schedCode;
//
// Fix the Window Size
//
setMinimumWidth(sizeHint().width());
setMaximumWidth(sizeHint().width());
setMinimumHeight(sizeHint().height());
setMaximumHeight(sizeHint().height());
setMinimumSize(sizeHint());
setMaximumSize(sizeHint());
setWindowTitle("RDAdmin - "+tr("Add Scheduler Code"));
//
// Text Validator
//
RDTextValidator *validator=new RDTextValidator(this,"validator");
validator->addBannedChar(' ');
//
// Code Name
//
schedcode_name_edit=new QLineEdit(this);
schedcode_name_edit->setGeometry(105,11,sizeHint().width()-150,19);
schedcode_name_edit->setMaxLength(10);
schedcode_name_edit->setValidator(validator);
QLabel *label=new QLabel(schedcode_name_edit,tr("&New Code:"),this);
d_code_edit=new QLineEdit(this);
d_code_edit->setGeometry(105,11,sizeHint().width()-150,19);
d_code_edit->setMaxLength(10);
QLabel *label=new QLabel(d_code_edit,tr("&New Code:"),this);
label->setGeometry(10,11,90,19);
label->setFont(labelFont());
label->setAlignment(Qt::AlignRight|Qt::AlignVCenter);
@ -97,7 +74,7 @@ AddSchedCode::AddSchedCode(QString *schedCode,QWidget *parent)
AddSchedCode::~AddSchedCode()
{
delete schedcode_name_edit;
delete d_code_edit;
}
@ -113,42 +90,38 @@ QSizePolicy AddSchedCode::sizePolicy() const
}
int AddSchedCode::exec(QString *scode)
{
d_sched_code=scode;
d_code_edit->setText("");
return QDialog::exec();
}
void AddSchedCode::okData()
{
RDSqlQuery *q;
QString sql;
if(schedcode_name_edit->text().isEmpty()) {
QMessageBox::warning(this,tr("Invalid Name"),tr("Invalid Name!"));
if(d_code_edit->text().isEmpty()) {
QMessageBox::warning(this,"RDAdmin - "+tr("Error"),
tr("Invalid Schedule Code!"));
return;
}
sql=QString("insert into SCHED_CODES set ")+
"CODE=\""+RDEscapeString(schedcode_name_edit->text())+"\"";
q=new RDSqlQuery(sql);
if(!q->isActive()) {
QMessageBox::warning(this,tr("Code Exists"),tr("Code Already Exists!"),
1,0,0);
delete q;
QString sql=QString("insert into SCHED_CODES set ")+
"CODE=\""+RDEscapeString(d_code_edit->text())+"\"";
if(!RDSqlQuery::apply(sql)) {
QMessageBox::warning(this,"RDAdmin - "+tr("Error"),
tr("Schedule Code Already Exists!"));
return;
}
delete q;
*d_sched_code=d_code_edit->text();
EditSchedCode *schedCode=
new EditSchedCode(schedcode_name_edit->text(),"",this);
if(schedCode->exec()<0) {
delete schedCode;
done(-1);
return;
}
delete schedCode;
*schedcode_schedCode=schedcode_name_edit->text();
done(0);
done(true);
}
void AddSchedCode::cancelData()
{
done(-1);
done(false);
}

View File

@ -3,7 +3,7 @@
// Add scheduler codes dialog
//
// (C) Copyright Stefan Gabriel <stg@st-gabriel.de>
// (C) Copyright 2002-2019 Fred Gleason <fredg@paravelsystems.com>
// (C) Copyright 2002-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
@ -22,8 +22,7 @@
#ifndef ADD_SCHEDCODES_H
#define ADD_SCHEDCODES_H
#include <qcheckbox.h>
#include <qlineedit.h>
#include <QLineEdit>
#include <rddialog.h>
@ -31,18 +30,21 @@ class AddSchedCode : public RDDialog
{
Q_OBJECT
public:
AddSchedCode(QString *schedCode,QWidget *parent=0);
AddSchedCode(QWidget *parent=0);
~AddSchedCode();
QSize sizeHint() const;
QSizePolicy sizePolicy() const;
public slots:
int exec(QString *scode);
private slots:
void okData();
void cancelData();
private:
QLineEdit *schedcode_name_edit;
QString *schedcode_schedCode;
QLineEdit *d_code_edit;
QString *d_sched_code;
};
#endif // ADD_SCHEDCODES_H

View File

@ -2,9 +2,9 @@
//
// Edit scheduler codes dialog
//
// Stefan Gabriel <stg@st-gabriel.de>
// Based on original code by Stefan Gabriel <stg@st-gabriel.de>
// (C) Copyright 2005-2018
// (C) Copyright 2002-2019 Fred Gleason <fredg@paravelsystems.com>
// (C) Copyright 2002-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
@ -22,44 +22,28 @@
#include <rddb.h>
#include <rdescape_string.h>
#include <rdtextvalidator.h>
#include "edit_group.h"
#include "edit_schedcodes.h"
EditSchedCode::EditSchedCode(QString schedcode,QString description,
QWidget *parent)
EditSchedCode::EditSchedCode(QWidget *parent)
: RDDialog(parent)
{
setModal(true);
//
// Fix the Window Size
//
setMinimumWidth(sizeHint().width());
setMaximumWidth(sizeHint().width());
setMinimumHeight(sizeHint().height());
setMaximumHeight(sizeHint().height());
schedcode_code=new QString(schedcode);
schedcode_description=new QString(description);
setWindowTitle("RDAdmin - "+tr("Scheduler Code: ")+schedcode);
//
// Text Validators
//
RDTextValidator *validator=new RDTextValidator(this);
setMinimumSize(sizeHint());
setMaximumSize(sizeHint());
//
// Code Name
//
schedcode_name_edit=new QLineEdit(this);
schedcode_name_edit->setGeometry(125,11,100,19);
schedcode_name_edit->setMaxLength(10);
schedcode_name_edit->setReadOnly(true);
d_code_edit=new QLineEdit(this);
d_code_edit->setGeometry(125,11,100,19);
d_code_edit->setMaxLength(10);
d_code_edit->setReadOnly(true);
QLabel *schedcode_name_label=
new QLabel(schedcode_name_edit,tr("Scheduler Code:"),this);
new QLabel(d_code_edit,tr("Scheduler Code:"),this);
schedcode_name_label->setGeometry(10,11,110,19);
schedcode_name_label->setFont(labelFont());
schedcode_name_label->setAlignment(Qt::AlignRight|Qt::AlignVCenter);
@ -67,12 +51,11 @@ EditSchedCode::EditSchedCode(QString schedcode,QString description,
//
// Code Description
//
schedcode_description_edit=new QLineEdit(this);
schedcode_description_edit->setGeometry(125,32,sizeHint().width()-135,19);
schedcode_description_edit->setMaxLength(255);
schedcode_description_edit->setValidator(validator);
d_description_edit=new QLineEdit(this);
d_description_edit->setGeometry(125,32,sizeHint().width()-135,19);
d_description_edit->setMaxLength(255);
QLabel *schedcode_description_label=
new QLabel(schedcode_description_edit,tr("Code Description:"),this);
new QLabel(d_description_edit,tr("Code Description:"),this);
schedcode_description_label->setGeometry(10,32,110,19);
schedcode_description_label->setFont(labelFont());
schedcode_description_label->setAlignment(Qt::AlignRight|Qt::AlignVCenter);
@ -96,19 +79,13 @@ EditSchedCode::EditSchedCode(QString schedcode,QString description,
cancel_button->setFont(buttonFont());
cancel_button->setText(tr("&Cancel"));
connect(cancel_button,SIGNAL(clicked()),this,SLOT(cancelData()));
//
// Populate Fields
//
schedcode_name_edit->setText(*schedcode_code);
schedcode_description_edit->setText(*schedcode_description);
}
EditSchedCode::~EditSchedCode()
{
delete schedcode_name_edit;
delete schedcode_description_edit;
delete d_code_edit;
delete d_description_edit;
}
@ -124,24 +101,43 @@ QSizePolicy EditSchedCode::sizePolicy() const
}
int EditSchedCode::exec(const QString &scode)
{
setWindowTitle("RDAdmin - "+tr("Scheduler Code: ")+scode);
d_code_edit->setText(scode);
QString sql=QString("select ")+
"DESCRIPTION "+ // 00
"from SCHED_CODES where "+
"CODE=\""+RDEscapeString(scode)+"\"";
RDSqlQuery *q=new RDSqlQuery(sql);
if(q->first()) {
d_description_edit->setText(q->value(0).toString());
}
delete q;
return QDialog::exec();
}
void EditSchedCode::okData()
{
RDSqlQuery *q;
QString sql;
sql=QString("update SCHED_CODES set ")+
"DESCRIPTION=\""+RDEscapeString(schedcode_description_edit->text())+"\" "+
"where CODE=\""+RDEscapeString(schedcode_name_edit->text())+"\"";
"DESCRIPTION=\""+RDEscapeString(d_description_edit->text())+"\" "+
"where CODE=\""+RDEscapeString(d_code_edit->text())+"\"";
q=new RDSqlQuery(sql);
delete q;
*schedcode_description=schedcode_description_edit->text();
done(0);
done(true);
}
void EditSchedCode::cancelData()
{
done(-1);
done(false);
}

View File

@ -2,8 +2,8 @@
//
// Edit scheduler codes dialog
//
// Stefan Gabriel <stg@st-gabriel.de>
// (C) Copyright 2002-2019 Fred Gleason <fredg@paravelsystems.com>
// Based on original code by Stefan Gabriel <stg@st-gabriel.de>
// (C) Copyright 2002-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
@ -22,7 +22,7 @@
#ifndef EDIT_SCHEDCODES_H
#define EDIT_SCHEDCODES_H
#include <qlineedit.h>
#include <QLineEdit>
#include <rddialog.h>
@ -30,20 +30,21 @@ class EditSchedCode : public RDDialog
{
Q_OBJECT
public:
EditSchedCode(QString schedcode,QString description,QWidget *parent=0);
EditSchedCode(QWidget *parent=0);
~EditSchedCode();
QSize sizeHint() const;
QSizePolicy sizePolicy() const;
public slots:
int exec(const QString &scode);
private slots:
void okData();
void cancelData();
private:
QString *schedcode_code;
QString *schedcode_description;
QLineEdit *schedcode_name_edit;
QLineEdit *schedcode_description_edit;
QLineEdit *d_code_edit;
QLineEdit *d_description_edit;
};

View File

@ -2,8 +2,8 @@
//
// The scheduler codes dialog for rdadmin
//
// Stefan Gabriel <stg@st-gabriel.de>
// (C) Copyright 2002-2019 Fred Gleason <fredg@paravelsyustems.com>
// Based on original code by Stefan Gabriel <stg@st-gabriel.de>
// (C) Copyright 2002-2021 Fred Gleason <fredg@paravelsyustems.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
@ -19,7 +19,7 @@
// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
//
#include <qmessagebox.h>
#include <QMessageBox>
#include <rdcart.h>
#include <rddb.h>
@ -33,8 +33,6 @@
ListSchedCodes::ListSchedCodes(QWidget *parent)
: RDDialog(parent)
{
setModal(true);
//
// Fix the Window Size
//
@ -42,6 +40,12 @@ ListSchedCodes::ListSchedCodes(QWidget *parent)
setWindowTitle("RDAdmin - "+tr("Rivendell Scheduler Codes List"));
//
// Dialogs
//
list_add_schedcode_dialog=new AddSchedCode(this);
list_edit_schedcode_dialog=new EditSchedCode(this);
//
// Add Button
//
@ -76,27 +80,28 @@ ListSchedCodes::ListSchedCodes(QWidget *parent)
connect(list_close_button,SIGNAL(clicked()),this,SLOT(closeData()));
//
// Group List
// Schedule Codes List
//
list_schedCodes_view=new Q3ListView(this);
list_schedCodes_view->setAllColumnsShowFocus(true);
list_schedCodes_view->addColumn(tr("CODE"));
list_schedCodes_view->addColumn(tr("DESCRIPTION"));
QLabel *list_box_label=
new QLabel(list_schedCodes_view,tr("Scheduler Codes:"),this);
list_box_label->setFont(buttonFont());
list_box_label->setGeometry(14,11,200,19);
connect(list_schedCodes_view,
SIGNAL(doubleClicked(Q3ListViewItem *,const QPoint &,int)),
this,
SLOT(doubleClickedData(Q3ListViewItem *,const QPoint &,int)));
RefreshList();
list_schedcodes_view=new RDTableView(this);
list_schedcodes_model=new RDSchedCodeListModel(this);
list_schedcodes_model->setFont(defaultFont());
list_schedcodes_model->setPalette(palette());
list_schedcodes_view->setModel(list_schedcodes_model);
list_schedcodes_label=
new QLabel(list_schedcodes_view,tr("Replicators:"),this);
list_schedcodes_label->setFont(labelFont());
connect(list_schedcodes_view,SIGNAL(doubleClicked(const QModelIndex &)),
this,SLOT(doubleClickedData(const QModelIndex &)));
connect(list_schedcodes_model,SIGNAL(modelReset()),
list_schedcodes_view,SLOT(resizeColumnsToContents()));
list_schedcodes_view->resizeColumnsToContents();
}
ListSchedCodes::~ListSchedCodes()
{
delete list_edit_schedcode_dialog;
delete list_add_schedcode_dialog;
}
@ -114,55 +119,49 @@ QSizePolicy ListSchedCodes::sizePolicy() const
void ListSchedCodes::addData()
{
QString schedCode;
QString scode;
AddSchedCode *add_schedCode=new AddSchedCode(&schedCode,this);
if(add_schedCode->exec()<0) {
delete add_schedCode;
return;
if(list_add_schedcode_dialog->exec(&scode)) {
QModelIndex index=list_schedcodes_model->addSchedCode(scode);
if(index.isValid()) {
list_schedcodes_view->selectRow(index.row());
}
}
else {
QString sql=QString("delete from SCHED_CODES where ")+
"CODE=\""+RDEscapeString(scode)+"\"";
RDSqlQuery::apply(sql);
}
delete add_schedCode;
add_schedCode=NULL;
Q3ListViewItem *item=new Q3ListViewItem(list_schedCodes_view);
item->setText(0,schedCode);
RefreshItem(item);
item->setSelected(true);
list_schedCodes_view->setCurrentItem(item);
list_schedCodes_view->ensureItemVisible(item);
}
void ListSchedCodes::editData()
{
Q3ListViewItem *item=list_schedCodes_view->selectedItem();
if(item==NULL) {
QModelIndexList rows=list_schedcodes_view->selectionModel()->selectedRows();
if(rows.size()!=1) {
return;
}
EditSchedCode *edit_schedCode=
new EditSchedCode(item->text(0),item->text(1),this);
edit_schedCode->exec();
delete edit_schedCode;
edit_schedCode=NULL;
RefreshItem(item);
if(list_edit_schedcode_dialog->
exec(list_schedcodes_model->schedCode(rows.first()))) {
list_schedcodes_model->refresh(rows.first());
}
}
void ListSchedCodes::deleteData()
{
Q3ListViewItem *item=list_schedCodes_view->selectedItem();
if(item==NULL) {
QModelIndexList rows=list_schedcodes_view->selectionModel()->selectedRows();
if(rows.size()!=1) {
return;
}
QString sql;
RDSqlQuery *q;
QString warning;
QString str;
QString codename=item->text(0);
if(codename.isEmpty()) {
return;
}
QString codename=list_schedcodes_model->schedCode(rows.first());
if(QMessageBox::question(this,"RDAdmin - "+tr("Delete Scheduler Code"),
tr("This operation will delete the selected scheduler code and")+
"\n"+tr("all of its associated data.")+" "+
@ -174,20 +173,16 @@ void ListSchedCodes::deleteData()
sql=QString("delete from DROPBOX_SCHED_CODES where ")+
"SCHED_CODE=\""+RDEscapeString(codename)+"\"";
q=new RDSqlQuery(sql);
delete q;
RDSqlQuery::apply(sql);
sql=QString("delete from SCHED_CODES where ")+
"CODE=\""+RDEscapeString(codename)+"\"";
q=new RDSqlQuery(sql);
delete q;
item->setSelected(false);
delete item;
RDSqlQuery::apply(sql);
list_schedcodes_model->removeSchedCode(rows.first());
}
void ListSchedCodes::doubleClickedData(Q3ListViewItem *item,const QPoint &pt,
int col)
void ListSchedCodes::doubleClickedData(const QModelIndex &index)
{
editData();
}
@ -195,7 +190,7 @@ void ListSchedCodes::doubleClickedData(Q3ListViewItem *item,const QPoint &pt,
void ListSchedCodes::closeData()
{
done(0);
done(true);
}
@ -203,46 +198,8 @@ void ListSchedCodes::resizeEvent(QResizeEvent *e)
{
list_add_button->setGeometry(size().width()-90,30,80,50);
list_edit_button->setGeometry(size().width()-90,90,80,50);
list_delete_button->setGeometry(size().width()-90,210,80,50);
list_delete_button->setGeometry(size().width()-90,150,80,50);
list_close_button->setGeometry(size().width()-90,size().height()-60,80,50);
list_schedCodes_view->setGeometry(10,30,size().width()-120,size().height()-40);
list_schedcodes_view->
setGeometry(10,30,size().width()-120,size().height()-40);
}
void ListSchedCodes::RefreshList()
{
QString sql;
RDSqlQuery *q;
Q3ListViewItem *item;
list_schedCodes_view->clear();
q=new RDSqlQuery("select CODE,DESCRIPTION from SCHED_CODES");
while (q->next()) {
item=new Q3ListViewItem(list_schedCodes_view);
WriteItem(item,q);
}
delete q;
}
void ListSchedCodes::RefreshItem(Q3ListViewItem *item)
{
QString sql;
RDSqlQuery *q;
sql=QString().sprintf("select CODE,DESCRIPTION from SCHED_CODES where CODE=\"%s\"",
(const char *)item->text(0));
q=new RDSqlQuery(sql);
if(q->next()) {
WriteItem(item,q);
}
delete q;
}
void ListSchedCodes::WriteItem(Q3ListViewItem *item,RDSqlQuery *q)
{
item->setText(0,q->value(0).toString());
item->setText(1,q->value(1).toString());
}

View File

@ -2,7 +2,7 @@
//
// The scheduler codes dialog for rdadmin
//
// Stefan Gabriel <stg@st-gabriel.de>
// Based on original code by Stefan Gabriel <stg@st-gabriel.de>
// (C) Copyright 2002-2019 Fred Gleason <fredg@paravelsystems.com>
//
// This program is free software; you can redistribute it and/or modify
@ -22,12 +22,16 @@
#ifndef LIST_SCHEDCODES_H
#define LIST_SCHEDCODES_H
#include <qpixmap.h>
#include <qpushbutton.h>
#include <QLabel>
#include <QPushButton>
#include <rddb.h>
#include <rddialog.h>
#include <rdlistviewitem.h>
#include <rdschedcodelistmodel.h>
#include <rdtableview.h>
#include "add_schedcodes.h"
#include "edit_schedcodes.h"
class ListSchedCodes : public RDDialog
{
@ -42,21 +46,22 @@ class ListSchedCodes : public RDDialog
void addData();
void editData();
void deleteData();
void doubleClickedData(Q3ListViewItem *item,const QPoint &pt,int col);
void doubleClickedData(const QModelIndex &index);
void closeData();
protected:
void resizeEvent(QResizeEvent *e);
private:
void RefreshList();
void RefreshItem(Q3ListViewItem *item);
void WriteItem(Q3ListViewItem *item,RDSqlQuery *q);
Q3ListView *list_schedCodes_view;
RDTableView *list_schedcodes_view;
QLabel *list_schedcodes_label;
RDSchedCodeListModel *list_schedcodes_model;
QPushButton *list_add_button;
QPushButton *list_edit_button;
QPushButton *list_delete_button;
QPushButton *list_close_button;
AddSchedCode *list_add_schedcode_dialog;
EditSchedCode *list_edit_schedcode_dialog;
};