diff --git a/ChangeLog b/ChangeLog index b375cb2a..f1dcf2f6 100644 --- a/ChangeLog +++ b/ChangeLog @@ -20871,3 +20871,6 @@ 2021-01-22 Fred Gleason * Added an 'RDIconEngine::stationIcon()' method. * Added an icons for 'host' objects. +2021-01-22 Fred Gleason + * Refactored the 'Edit Host' dialog in rdadmin(1) to use the + model-based API. diff --git a/lib/rdstationlistmodel.cpp b/lib/rdstationlistmodel.cpp index 3071a1b6..10d2978b 100644 --- a/lib/rdstationlistmodel.cpp +++ b/lib/rdstationlistmodel.cpp @@ -22,9 +22,12 @@ #include "rdescape_string.h" #include "rdstationlistmodel.h" -RDStationListModel::RDStationListModel(QObject *parent) +RDStationListModel::RDStationListModel(const QString &localhost_name, + QObject *parent) : QAbstractTableModel(parent) { + d_localhost_name=localhost_name; + // // Column Attributes // @@ -167,7 +170,7 @@ QVariant RDStationListModel::data(const QModelIndex &index,int role) const QString RDStationListModel::stationName(const QModelIndex &row) const { - return d_texts.at(row.row()).at(0).toString(); + return d_hostnames.at(row.row()); } @@ -178,7 +181,7 @@ QModelIndex RDStationListModel::addStation(const QString &hostname) // int offset=d_texts.size(); for(int i=0;ifirst()) { updateRow(row.row(),q); @@ -258,10 +266,12 @@ void RDStationListModel::updateModel() QString sql=sqlFields(); sql+="order by NAME "; beginResetModel(); + d_hostnames.clear(); d_texts.clear(); d_icons.clear(); q=new RDSqlQuery(sql); while(q->next()) { + d_hostnames.push_back(QString()); d_texts.push_back(texts); d_icons.push_back(texts); updateRow(d_texts.size()-1,q); @@ -275,7 +285,7 @@ void RDStationListModel::updateRowLine(int line) { if(linefirst()) { updateRow(line,q); @@ -291,7 +301,13 @@ void RDStationListModel::updateRow(int row,RDSqlQuery *q) QList icons; // Hostname - texts.push_back(q->value(0)); + d_hostnames[row]=q->value(0).toString(); + if(q->value(0).toString()==d_localhost_name) { + texts.push_back("localhost"); + } + else { + texts.push_back(q->value(0)); + } icons.push_back(rda->iconEngine()->stationIcon()); // Description diff --git a/lib/rdstationlistmodel.h b/lib/rdstationlistmodel.h index febe440f..9f172cda 100644 --- a/lib/rdstationlistmodel.h +++ b/lib/rdstationlistmodel.h @@ -41,7 +41,7 @@ class RDStationListModel : public QAbstractTableModel { Q_OBJECT public: - RDStationListModel(QObject *parent=0); + RDStationListModel(const QString &localhost_name,QObject *parent=0); ~RDStationListModel(); QPalette palette(); void setPalette(const QPalette &pal); @@ -68,9 +68,10 @@ class RDStationListModel : public QAbstractTableModel QPalette d_palette; QFont d_font; QFont d_bold_font; - QStringList d_service_names; + QString d_localhost_name; QList d_headers; QList d_alignments; + QStringList d_hostnames; QList > d_texts; QList > d_icons; }; diff --git a/rdadmin/edit_station.cpp b/rdadmin/edit_station.cpp index 7b472a04..fa8271da 100644 --- a/rdadmin/edit_station.cpp +++ b/rdadmin/edit_station.cpp @@ -18,7 +18,7 @@ // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. // -#include +#include #include #include @@ -48,9 +48,7 @@ EditStation::EditStation(QString sname,QWidget *parent) : RDDialog(parent) { - RDSqlQuery *q; - QString sql; - char temp[256]; + char temp[1024]; // // Fix the Window Size @@ -74,6 +72,12 @@ EditStation::EditStation(QString sname,QWidget *parent) RDTextValidator *validator=new RDTextValidator(this); QIntValidator *macro_validator=new QIntValidator(1,RD_MAX_CART_NUMBER,this); + // + // Models + // + station_username_model=new RDUserListModel(this); + station_station_model=new RDStationListModel(sname,this); + // // Station Name // @@ -109,7 +113,6 @@ EditStation::EditStation(QString sname,QWidget *parent) // station_username_box=new QComboBox(this); station_username_box->setEditable(false); - station_username_model=new RDUserListModel(this); station_username_model->setTypeFilter(RDUser::TypeUser); station_username_box->setModel(station_username_model); station_username_label= @@ -319,6 +322,7 @@ EditStation::EditStation(QString sname,QWidget *parent) // station_http_station_box=new QComboBox(this); station_http_station_box->setEditable(false); + station_http_station_box->setModel(station_station_model); station_http_station_label= new QLabel(station_http_station_box,tr("HTTP Xport:"),this); station_http_station_label->setFont(labelFont()); @@ -329,6 +333,7 @@ EditStation::EditStation(QString sname,QWidget *parent) // station_cae_station_box=new QComboBox(this); station_cae_station_box->setEditable(false); + station_cae_station_box->setModel(station_station_model); connect(station_cae_station_box,SIGNAL(activated(const QString &)), this,SLOT(caeStationActivatedData(const QString &))); station_cae_station_label= @@ -342,7 +347,8 @@ EditStation::EditStation(QString sname,QWidget *parent) station_rdlibrary_button=new QPushButton(this); station_rdlibrary_button->setFont(buttonFont()); station_rdlibrary_button->setText(tr("RD&Library")); - connect(station_rdlibrary_button,SIGNAL(clicked()),this,SLOT(editLibraryData())); + connect(station_rdlibrary_button,SIGNAL(clicked()), + this,SLOT(editLibraryData())); // // RDCatch Configuration Button @@ -549,25 +555,8 @@ EditStation::EditStation(QString sname,QWidget *parent) station_panel_enforce_label->setDisabled(true); station_panel_enforce_box->setDisabled(true); } - - station_http_station_box->insertItem("localhost"); - station_cae_station_box->insertItem("localhost"); - sql=QString("select NAME from STATIONS where ")+ - "NAME!=\""+RDEscapeString(sname)+"\" order by NAME"; - q=new RDSqlQuery(sql); - while(q->next()) { - station_http_station_box->insertItem(q->value(0).toString()); - if(q->value(0).toString()==station_station->httpStation()) { - station_http_station_box-> - setCurrentItem(station_http_station_box->count()-1); - } - station_cae_station_box->insertItem(q->value(0).toString()); - if(q->value(0).toString()==station_station->caeStation()) { - station_cae_station_box-> - setCurrentItem(station_cae_station_box->count()-1); - } - } - delete q; + station_http_station_box->setCurrentText(station_station->httpStation()); + station_cae_station_box->setCurrentText(station_station->caeStation()); for(int i=0;icount();i++) { if(station_http_station_box->text(i)==station_station->httpStation()) { station_http_station_box->setCurrentItem(i); @@ -584,6 +573,7 @@ EditStation::~EditStation() delete station_station; delete station_cae_station; delete station_username_model; + delete station_station_model; } diff --git a/rdadmin/edit_station.h b/rdadmin/edit_station.h index fe559591..84ce2162 100644 --- a/rdadmin/edit_station.h +++ b/rdadmin/edit_station.h @@ -21,19 +21,20 @@ #ifndef EDIT_STATION_H #define EDIT_STATION_H -#include -#include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include +#include +#include #include #include #include #include #include +#include #include class EditStation : public RDDialog @@ -134,6 +135,7 @@ class EditStation : public RDDialog QComboBox *station_http_station_box; QLabel *station_cae_station_label; QComboBox *station_cae_station_box; + RDStationListModel *station_station_model; QPushButton *station_rdlibrary_button; QPushButton *station_rdcatch_button; QPushButton *station_rdairplay_button; diff --git a/rdadmin/list_stations.cpp b/rdadmin/list_stations.cpp index e9fb489d..aa0d3bf6 100644 --- a/rdadmin/list_stations.cpp +++ b/rdadmin/list_stations.cpp @@ -83,7 +83,7 @@ ListStations::ListStations(QWidget *parent) list_stations_view->setShowGrid(false); list_stations_view->setSortingEnabled(false); list_stations_view->setWordWrap(false); - list_stations_model=new RDStationListModel(this); + list_stations_model=new RDStationListModel("",this); list_stations_model->setFont(defaultFont()); list_stations_model->setPalette(palette()); list_stations_view->setModel(list_stations_model);