2021-01-22 Fred Gleason <fredg@paravelsystems.com>

* Added 'RDStationListModel' class
	* Refactored the 'List Hosts' 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-01-22 11:48:53 -05:00
parent 52cb6be95f
commit cd22c3268b
22 changed files with 1100 additions and 59 deletions

View File

@ -20864,3 +20864,7 @@
* Added 'RDServiceListModel' class
* Refactored the 'List Services' dialog in rdadmin(1) to use the
model-based API.
2021-01-22 Fred Gleason <fredg@paravelsystems.com>
* Added 'RDStationListModel' class
* Refactored the 'List Hosts' dialog in rdadmin(1) to use the
model-based API.

View File

@ -227,6 +227,7 @@ dist_librd_la_SOURCES = dbversion.h\
rdsocketstrings.cpp rdsocketstrings.h\
rdsound_panel.cpp rdsound_panel.h\
rdstation.cpp rdstation.h\
rdstationlistmodel.cpp rdstationlistmodel.h\
rdstatus.cpp rdstatus.h\
rdstereometer.cpp rdstereometer.h\
rdstringlist.cpp rdstringlist.h\
@ -354,6 +355,7 @@ nodist_librd_la_SOURCES = moc_rdadd_cart.cpp\
moc_rdsound_panel.cpp\
moc_rdslotbox.cpp\
moc_rdslotdialog.cpp\
moc_rdstationlistmodel.cpp\
moc_rdstereometer.cpp\
moc_rdsvc.cpp\
moc_rdtimeedit.cpp\

View File

@ -164,6 +164,7 @@ SOURCES += rdsocket.cpp
SOURCES += rdsocketstrings.cpp
SOURCES += rdsound_panel.cpp
SOURCES += rdstation.cpp
SOURCES += rdstationlistmodel.cpp
SOURCES += rdstatus.cpp
SOURCES += rdstereometer.cpp
SOURCES += rdsvc.cpp
@ -318,6 +319,7 @@ HEADERS += rdsocket.h
HEADERS += rdsocketstrings.h
HEADERS += rdsound_panel.h
HEADERS += rdstation.h
HEADERS += rdstationlistmodel.h
HEADERS += rdstatus.h
HEADERS += rdstereometer.h
HEADERS += rdsvc.h

View File

@ -3522,6 +3522,73 @@ Zkuste to, prosím, znovu!</translation>
<translation type="obsolete">Databázové spojení se nezdařilo:</translation>
</message>
</context>
<context>
<name>RDStationListModel</name>
<message>
<source>Name</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Description</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>IP Address</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Default User</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Short Name</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Xport Host</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>CAE Host</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Report Editor</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Web Browser</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Maint Pool</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Drag &amp; Drop</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>HPI Ver</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>JACK Ver</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>ALSA Ver</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>[none]</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>[unavailable]</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>RDStereoMeter</name>
<message>

View File

@ -3503,6 +3503,73 @@ bitte erneut versuchen!</translation>
<translation type="obsolete">Datenbankverbindung fehlgeschlagen:</translation>
</message>
</context>
<context>
<name>RDStationListModel</name>
<message>
<source>Name</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Description</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>IP Address</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Default User</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Short Name</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Xport Host</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>CAE Host</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Report Editor</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Web Browser</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Maint Pool</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Drag &amp; Drop</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>HPI Ver</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>JACK Ver</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>ALSA Ver</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>[none]</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>[unavailable]</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>RDStereoMeter</name>
<message>

View File

@ -3482,6 +3482,73 @@ please try again!</source>
<translation type="obsolete">Falló la conexión a la base de datos : </translation>
</message>
</context>
<context>
<name>RDStationListModel</name>
<message>
<source>Name</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Description</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>IP Address</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Default User</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Short Name</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Xport Host</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>CAE Host</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Report Editor</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Web Browser</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Maint Pool</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Drag &amp; Drop</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>HPI Ver</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>JACK Ver</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>ALSA Ver</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>[none]</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>[unavailable]</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>RDStereoMeter</name>
<message>

View File

@ -2772,6 +2772,73 @@ please try again!</source>
<translation>Panneau</translation>
</message>
</context>
<context>
<name>RDStationListModel</name>
<message>
<source>Name</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Description</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>IP Address</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Default User</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Short Name</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Xport Host</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>CAE Host</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Report Editor</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Web Browser</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Maint Pool</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Drag &amp; Drop</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>HPI Ver</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>JACK Ver</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>ALSA Ver</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>[none]</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>[unavailable]</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>RDStereoMeter</name>
<message>

View File

@ -3385,6 +3385,73 @@ prøv ein gong til!</translation>
<translation type="obsolete">Feil med databasetilkoplinga: </translation>
</message>
</context>
<context>
<name>RDStationListModel</name>
<message>
<source>Name</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Description</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>IP Address</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Default User</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Short Name</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Xport Host</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>CAE Host</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Report Editor</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Web Browser</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Maint Pool</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Drag &amp; Drop</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>HPI Ver</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>JACK Ver</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>ALSA Ver</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>[none]</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>[unavailable]</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>RDStereoMeter</name>
<message>

View File

@ -3385,6 +3385,73 @@ prøv ein gong til!</translation>
<translation type="obsolete">Feil med databasetilkoplinga: </translation>
</message>
</context>
<context>
<name>RDStationListModel</name>
<message>
<source>Name</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Description</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>IP Address</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Default User</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Short Name</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Xport Host</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>CAE Host</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Report Editor</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Web Browser</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Maint Pool</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Drag &amp; Drop</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>HPI Ver</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>JACK Ver</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>ALSA Ver</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>[none]</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>[unavailable]</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>RDStereoMeter</name>
<message>

View File

@ -3436,6 +3436,73 @@ por favor, tente novamente!</translation>
<translation type="obsolete">Conexão à Base de Daods falhou: </translation>
</message>
</context>
<context>
<name>RDStationListModel</name>
<message>
<source>Name</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Description</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>IP Address</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Default User</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Short Name</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Xport Host</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>CAE Host</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Report Editor</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Web Browser</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Maint Pool</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Drag &amp; Drop</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>HPI Ver</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>JACK Ver</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>ALSA Ver</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>[none]</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>[unavailable]</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>RDStereoMeter</name>
<message>

424
lib/rdstationlistmodel.cpp Normal file
View File

@ -0,0 +1,424 @@
// rdstationlistmodel.cpp
//
// Data model for Rivendell hosts
//
// (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 "rdstationlistmodel.h"
RDStationListModel::RDStationListModel(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("Name"));
d_alignments.push_back(left);
d_headers.push_back(tr("Description"));
d_alignments.push_back(left);
d_headers.push_back(tr("IP Address"));
d_alignments.push_back(left);
d_headers.push_back(tr("Default User"));
d_alignments.push_back(left);
d_headers.push_back(tr("Short Name"));
d_alignments.push_back(left);
d_headers.push_back(tr("Xport Host"));
d_alignments.push_back(left);
d_headers.push_back(tr("CAE Host"));
d_alignments.push_back(left);
d_headers.push_back(tr("Report Editor"));
d_alignments.push_back(left);
d_headers.push_back(tr("Web Browser"));
d_alignments.push_back(left);
d_headers.push_back(tr("Maint Pool"));
d_alignments.push_back(center);
d_headers.push_back(tr("Drag & Drop"));
d_alignments.push_back(center);
d_headers.push_back(tr("HPI Ver"));
d_alignments.push_back(left);
d_headers.push_back(tr("JACK Ver"));
d_alignments.push_back(left);
d_headers.push_back(tr("ALSA Ver"));
d_alignments.push_back(left);
updateModel();
}
RDStationListModel::~RDStationListModel()
{
}
QPalette RDStationListModel::palette()
{
return d_palette;
}
void RDStationListModel::setPalette(const QPalette &pal)
{
d_palette=pal;
}
void RDStationListModel::setFont(const QFont &font)
{
d_font=font;
d_bold_font=font;
d_bold_font.setWeight(QFont::Bold);
}
int RDStationListModel::columnCount(const QModelIndex &parent) const
{
return d_headers.size();
}
int RDStationListModel::rowCount(const QModelIndex &parent) const
{
return d_texts.size();
}
QVariant RDStationListModel::headerData(int section,Qt::Orientation orient,
int role) const
{
if((orient==Qt::Horizontal)&&(role==Qt::DisplayRole)) {
return d_headers.at(section);
}
return QVariant();
}
QVariant RDStationListModel::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:
return d_icons.at(row).at(col);
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 RDStationListModel::stationName(const QModelIndex &row) const
{
return d_texts.at(row.row()).at(0).toString();
}
QModelIndex RDStationListModel::addStation(const QString &hostname)
{
//
// Find the insertion offset
//
int offset=d_texts.size();
for(int i=0;i<d_texts.size();i++) {
if(hostname.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]=hostname;
d_texts.insert(offset,list);
d_icons.insert(offset,list);
updateRowLine(offset);
endInsertRows();
return createIndex(offset,0);
}
void RDStationListModel::removeStation(const QModelIndex &row)
{
beginRemoveRows(QModelIndex(),row.row(),row.row());
d_texts.removeAt(row.row());
d_icons.removeAt(row.row());
endRemoveRows();
}
void RDStationListModel::removeStation(const QString &hostname)
{
for(int i=0;i<d_texts.size();i++) {
if(d_texts.at(i).at(0)==hostname) {
removeStation(createIndex(i,0));
return;
}
}
}
void RDStationListModel::refresh(const QModelIndex &row)
{
if(row.row()<d_texts.size()) {
QString sql=sqlFields()+
"where STATIONS.NAME=\""+
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 RDStationListModel::refresh(const QString &grpname)
{
for(int i=0;i<d_texts.size();i++) {
if(d_texts.at(i).at(0)==grpname) {
updateRowLine(i);
return;
}
}
}
void RDStationListModel::updateModel()
{
QList<QVariant> texts;
QList<QVariant> icons;
RDSqlQuery *q=NULL;
QString sql=sqlFields();
sql+="order by NAME ";
beginResetModel();
d_texts.clear();
d_icons.clear();
q=new RDSqlQuery(sql);
while(q->next()) {
d_texts.push_back(texts);
d_icons.push_back(texts);
updateRow(d_texts.size()-1,q);
}
delete q;
endResetModel();
}
void RDStationListModel::updateRowLine(int line)
{
if(line<d_texts.size()) {
QString sql=sqlFields()+
"where NAME=\""+RDEscapeString(d_texts.at(line).at(0).toString())+"\"";
RDSqlQuery *q=new RDSqlQuery(sql);
if(q->first()) {
updateRow(line,q);
}
delete q;
}
}
void RDStationListModel::updateRow(int row,RDSqlQuery *q)
{
QList<QVariant> texts;
QList<QVariant> icons;
// Hostname
texts.push_back(q->value(0));
icons.push_back(QVariant());
// Description
texts.push_back(q->value(1));
icons.push_back(QVariant());
// IP Address
texts.push_back(q->value(2));
icons.push_back(QVariant());
// Default User
texts.push_back(q->value(3));
if(q->value(4).toString()=="Y") {
icons.push_back(rda->iconEngine()->userIcon(RDUser::TypeLocalUser));
}
else {
icons.push_back(rda->iconEngine()->userIcon(RDUser::TypeExternalUser));
}
// Short Name
texts.push_back(q->value(5));
icons.push_back(QVariant());
// Xport Host
texts.push_back(q->value(6));
icons.push_back(QVariant());
// CAE Host
texts.push_back(q->value(7));
icons.push_back(QVariant());
// Report Editor
if(q->value(8).toString().isEmpty()) {
texts.push_back(tr("[none]"));
}
else {
texts.push_back(q->value(8).toString().
split("/",QString::SkipEmptyParts).last());
}
icons.push_back(QVariant());
// Web Editor
if(q->value(9).toString().isEmpty()) {
texts.push_back(tr("[none]"));
}
else {
texts.push_back(q->value(9).toString().
split("/",QString::SkipEmptyParts).last());
}
icons.push_back(QVariant());
// Maint Pool
texts.push_back(q->value(10));
icons.push_back(QVariant());
// Drag & Drop
texts.push_back(q->value(11));
icons.push_back(QVariant());
if(q->value(12).toString()=="Y") {
// HPI Ver
if(q->value(13).toString().isEmpty()) {
texts.push_back(tr("[none]"));
}
else {
texts.push_back(q->value(13));
}
icons.push_back(QVariant());
// Jack Ver
if(q->value(14).toString().isEmpty()) {
texts.push_back(tr("[none]"));
}
else {
texts.push_back(q->value(14));
}
icons.push_back(QVariant());
// ALSA Ver
if(q->value(15).toString().isEmpty()) {
texts.push_back(tr("[none]"));
}
else {
texts.push_back(q->value(15));
}
icons.push_back(QVariant());
}
else {
// HPI Ver
texts.push_back(tr("[unavailable]"));
icons.push_back(QVariant());
// Jack Ver
texts.push_back(tr("[unavailable]"));
icons.push_back(QVariant());
// ALSA Ver
texts.push_back(tr("[unavailable]"));
icons.push_back(QVariant());
}
d_texts[row]=texts;
d_icons[row]=icons;
}
QString RDStationListModel::sqlFields() const
{
QString sql=QString("select ")+
"STATIONS.NAME,"+ // 00
"STATIONS.DESCRIPTION,"+ // 01
"STATIONS.IPV4_ADDRESS,"+ // 02
"STATIONS.DEFAULT_NAME,"+ // 03
"USERS.LOCAL_AUTH,"+ // 04
"STATIONS.SHORT_NAME,"+ // 05
"STATIONS.HTTP_STATION,"+ // 06
"STATIONS.CAE_STATION,"+ // 07
"STATIONS.REPORT_EDITOR_PATH,"+ // 08
"STATIONS.BROWSER_PATH,"+ // 09
"STATIONS.SYSTEM_MAINT,"+ // 10
"STATIONS.ENABLE_DRAGDROP,"+ // 11
"STATIONS.STATION_SCANNED,"+ // 12
"STATIONS.HPI_VERSION,"+ // 13
"STATIONS.JACK_VERSION,"+ // 14
"STATIONS.ALSA_VERSION "+ // 15
"from STATIONS left join USERS "+
"on STATIONS.DEFAULT_NAME=USERS.LOGIN_NAME ";
return sql;
}

79
lib/rdstationlistmodel.h Normal file
View File

@ -0,0 +1,79 @@
// rdstationlistmodel.h
//
// Data model for Rivendell hosts
//
// (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 RDSTATIONLISTMODEL_H
#define RDSTATIONLISTMODEL_H
#include <QAbstractTableModel>
#include <QFont>
#include <QList>
#include <QPalette>
#include <rddb.h>
#include <rdnotification.h>
#include <rduser.h>
//
// MAINTAINERS NOTE
//
// We could arguably just use a QSqlQueryModel for this, but rolling our own
// lets us use the same backend-facing API pattern as the other Rivendell
// models.
//
class RDStationListModel : public QAbstractTableModel
{
Q_OBJECT
public:
RDStationListModel(QObject *parent=0);
~RDStationListModel();
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 stationName(const QModelIndex &row) const;
QModelIndex addStation(const QString &hostname);
void removeStation(const QModelIndex &row);
void removeStation(const QString &hostname);
void refresh(const QModelIndex &row);
void refresh(const QString &username);
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;
QStringList d_service_names;
QList<QVariant> d_headers;
QList<QVariant> d_alignments;
QList<QList<QVariant> > d_texts;
QList<QList<QVariant> > d_icons;
};
#endif // RDSTATIONLISTMODEL_H

View File

@ -744,13 +744,13 @@ void EditStation::okData()
void EditStation::okTimerData()
{
done(0);
done(true);
}
void EditStation::cancelData()
{
done(-1);
done(false);
}

View File

@ -2,7 +2,7 @@
//
// List Rivendell Workstations
//
// (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
@ -18,7 +18,7 @@
// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
//
#include <qmessagebox.h>
#include <QMessageBox>
#include <rdairplay_conf.h>
#include <rddb.h>
@ -31,8 +31,6 @@
ListStations::ListStations(QWidget *parent)
: RDDialog(parent)
{
setModal(true);
//
// Fix the Window Size
//
@ -76,6 +74,25 @@ ListStations::ListStations(QWidget *parent)
//
// Station List Box
//
list_stations_view=new QTableView(this);
list_title_label=new QLabel(list_stations_view,tr("H&osts:"),this);
list_title_label->setFont(labelFont());
list_title_label->setGeometry(14,11,85,19);
list_stations_view->setSelectionBehavior(QAbstractItemView::SelectRows);
list_stations_view->setSelectionMode(QAbstractItemView::SingleSelection);
list_stations_view->setShowGrid(false);
list_stations_view->setSortingEnabled(false);
list_stations_view->setWordWrap(false);
list_stations_model=new RDStationListModel(this);
list_stations_model->setFont(defaultFont());
list_stations_model->setPalette(palette());
list_stations_view->setModel(list_stations_model);
connect(list_stations_view,SIGNAL(doubleClicked(const QModelIndex &)),
this,SLOT(doubleClickedData(const QModelIndex &)));
connect(list_stations_model,SIGNAL(modelReset()),
list_stations_view,SLOT(resizeColumnsToContents()));
list_stations_view->resizeColumnsToContents();
/*
list_box=new Q3ListBox(this);
QLabel *list_box_label=new QLabel(list_box,tr("Ho&sts:"),this);
list_box_label->setFont(labelFont());
@ -84,12 +101,14 @@ ListStations::ListStations(QWidget *parent)
this,SLOT(doubleClickedData(Q3ListBoxItem *)));
RefreshList();
*/
}
ListStations::~ListStations()
{
delete list_box;
delete list_stations_view;
delete list_stations_model;
}
@ -107,52 +126,65 @@ QSizePolicy ListStations::sizePolicy() const
void ListStations::addData()
{
QString stationname;
QString hostname;
AddStation *add_station=new AddStation(&stationname,this);
if(add_station->exec()<0) {
RDStation::remove(stationname);
delete add_station;
return;
AddStation *d=new AddStation(&hostname,this);
if(d->exec()) {
QModelIndex row=list_stations_model->addStation(hostname);
if(row.isValid()) {
list_stations_view->selectRow(row.row());
}
}
delete add_station;
RefreshList(stationname);
else {
RDStation::remove(hostname);
}
delete d;
}
void ListStations::editData()
{
if(list_box->currentItem()<0) {
QModelIndexList rows=list_stations_view->selectionModel()->selectedRows();
if(rows.size()!=1) {
return;
}
EditStation *edit_station=new EditStation(list_box->currentText(),this);
edit_station->exec();
delete edit_station;
EditStation *d=
new EditStation(list_stations_model->stationName(rows.first()),this);
if(d->exec()) {
list_stations_model->refresh(rows.first());
}
delete d;
}
void ListStations::deleteData()
{
QModelIndexList rows=list_stations_view->selectionModel()->selectedRows();
if(rows.size()!=1) {
return;
}
QString hostname=list_stations_model->stationName(rows.first());
if(QMessageBox::warning(this,"RDAdmin - "+tr("Delete Station"),
tr("Are you sure you want to delete host")+
" \""+list_box->currentText()+"\"?",
QMessageBox::Yes,QMessageBox::No)==QMessageBox::Yes) {
RDStation::remove(list_box->currentText());
list_box->removeItem(list_box->currentItem());
if(list_box->currentItem()>=0) {
list_box->setSelected(list_box->currentItem(),true);
}
tr("Are you sure you want to delete host")+
" \""+hostname+"\"?",
QMessageBox::Yes,QMessageBox::No)==
QMessageBox::Yes) {
RDStation::remove(hostname);
list_stations_model->removeStation(hostname);
}
}
void ListStations::closeData()
{
done(0);
done(true);
}
void ListStations::doubleClickedData(Q3ListBoxItem *item)
void ListStations::doubleClickedData(const QModelIndex &index)
{
editData();
}
@ -164,10 +196,10 @@ void ListStations::resizeEvent(QResizeEvent *e)
list_edit_button->setGeometry(size().width()-90,90,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_box->setGeometry(10,30,size().width()-110,size().height()-40);
list_stations_view->setGeometry(10,30,size().width()-110,size().height()-40);
}
/*
void ListStations::RefreshList(QString stationname)
{
QString sql;
@ -183,3 +215,4 @@ void ListStations::RefreshList(QString stationname)
}
delete q;
}
*/

View File

@ -2,7 +2,7 @@
//
// List Rivendell Workstations
//
// (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
@ -21,12 +21,14 @@
#ifndef LIST_STATIONS_H
#define LIST_STATIONS_H
#include <q3listbox.h>
//#include <q3listbox.h>
#include <qlabel.h>
#include <qpushbutton.h>
#include <QLabel>
#include <QPushButton>
#include <QTableView>
#include <rddialog.h>
#include <rdstationlistmodel.h>
class ListStations : public RDDialog
{
@ -41,16 +43,18 @@ class ListStations : public RDDialog
void addData();
void editData();
void deleteData();
void doubleClickedData(Q3ListBoxItem *item);
void doubleClickedData(const QModelIndex &index);
void closeData();
protected:
void resizeEvent(QResizeEvent *e);
private:
void RefreshList(QString stationname="");
// void RefreshList(QString stationname="");
QLabel *list_title_label;
Q3ListBox *list_box;
// Q3ListBox *list_box;
QTableView *list_stations_view;
RDStationListModel *list_stations_model;
QPushButton *list_add_button;
QPushButton *list_edit_button;
QPushButton *list_delete_button;

View File

@ -6101,20 +6101,24 @@ vozíky</translation>
</message>
<message>
<source>Ho&amp;sts:</source>
<translation>&amp;Servery:</translation>
<translation type="obsolete">&amp;Servery:</translation>
</message>
<message>
<source>Are you sure you want to delete host</source>
<translation>Opravdu chcete smazat tento server</translation>
<translation type="unfinished">Opravdu chcete smazat tento server</translation>
</message>
<message>
<source>Delete Station</source>
<translation>Smazat stanici</translation>
<translation type="unfinished">Smazat stanici</translation>
</message>
<message>
<source>Rivendell Host List</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>H&amp;osts:</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>ListSvcs</name>

View File

@ -5797,20 +5797,24 @@ Carts</source>
</message>
<message>
<source>Ho&amp;sts:</source>
<translation>Ho&amp;sts:</translation>
<translation type="obsolete">Ho&amp;sts:</translation>
</message>
<message>
<source>Are you sure you want to delete host</source>
<translation>Sind Sie sicher, daß sie den Host löschen wollen</translation>
<translation type="unfinished">Sind Sie sicher, daß sie den Host löschen wollen</translation>
</message>
<message>
<source>Delete Station</source>
<translation>Station löschen</translation>
<translation type="unfinished">Station löschen</translation>
</message>
<message>
<source>Rivendell Host List</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>H&amp;osts:</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>ListSvcs</name>

View File

@ -6055,20 +6055,24 @@ Cartuchos</translation>
</message>
<message>
<source>Ho&amp;sts:</source>
<translation>C&amp;omputadores:</translation>
<translation type="obsolete">C&amp;omputadores:</translation>
</message>
<message>
<source>Are you sure you want to delete host</source>
<translation>Está seguro de querer eliminar este equipo</translation>
<translation type="unfinished">Está seguro de querer eliminar este equipo</translation>
</message>
<message>
<source>Delete Station</source>
<translation>Eliminar equipo</translation>
<translation type="unfinished">Eliminar equipo</translation>
</message>
<message>
<source>Rivendell Host List</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>H&amp;osts:</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>ListSvcs</name>

View File

@ -4790,11 +4790,11 @@ Carts</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Ho&amp;sts:</source>
<source>Rivendell Host List</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Are you sure you want to delete host</source>
<source>H&amp;osts:</source>
<translation type="unfinished"></translation>
</message>
<message>
@ -4802,7 +4802,7 @@ Carts</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Rivendell Host List</source>
<source>Are you sure you want to delete host</source>
<translation type="unfinished"></translation>
</message>
</context>

View File

@ -5658,20 +5658,24 @@ Carts</source>
</message>
<message>
<source>Ho&amp;sts:</source>
<translation>Ver&amp;tar:</translation>
<translation type="obsolete">Ver&amp;tar:</translation>
</message>
<message>
<source>Are you sure you want to delete host</source>
<translation>Er du sikker at du vil sletta verten</translation>
<translation type="unfinished">Er du sikker at du vil sletta verten</translation>
</message>
<message>
<source>Delete Station</source>
<translation>Slett stasjonen</translation>
<translation type="unfinished">Slett stasjonen</translation>
</message>
<message>
<source>Rivendell Host List</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>H&amp;osts:</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>ListSvcs</name>

View File

@ -5658,20 +5658,24 @@ Carts</source>
</message>
<message>
<source>Ho&amp;sts:</source>
<translation>Ver&amp;tar:</translation>
<translation type="obsolete">Ver&amp;tar:</translation>
</message>
<message>
<source>Are you sure you want to delete host</source>
<translation>Er du sikker at du vil sletta verten</translation>
<translation type="unfinished">Er du sikker at du vil sletta verten</translation>
</message>
<message>
<source>Delete Station</source>
<translation>Slett stasjonen</translation>
<translation type="unfinished">Slett stasjonen</translation>
</message>
<message>
<source>Rivendell Host List</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>H&amp;osts:</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>ListSvcs</name>

View File

@ -5769,20 +5769,24 @@ Carts</source>
</message>
<message>
<source>Ho&amp;sts:</source>
<translation>&amp;Clientes:</translation>
<translation type="obsolete">&amp;Clientes:</translation>
</message>
<message>
<source>Are you sure you want to delete host</source>
<translation>Tem certeza que quer deletar este Cliente?</translation>
<translation type="unfinished">Tem certeza que quer deletar este Cliente?</translation>
</message>
<message>
<source>Delete Station</source>
<translation>Deletar Estação</translation>
<translation type="unfinished">Deletar Estação</translation>
</message>
<message>
<source>Rivendell Host List</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>H&amp;osts:</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>ListSvcs</name>