// rdstationlistmodel.cpp // // Data model for Rivendell hosts // // (C) Copyright 2021 Fred Gleason // // 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(bool incl_none, const QString &localhost_name, QObject *parent) : QAbstractTableModel(parent) { d_localhost_name=localhost_name; d_include_none=incl_none; // // 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 list; for(int i=0;ifirst()) { 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 texts; QList icons; RDSqlQuery *q=NULL; QString sql=sqlFields(); sql+="order by `NAME` "; beginResetModel(); d_hostnames.clear(); d_texts.clear(); d_icons.clear(); if(d_include_none) { d_hostnames.push_back(tr("[none]")); d_texts.push_back(texts); d_texts.back().push_back(tr("[none]")); d_icons.push_back(texts); for(int i=1;inext()) { d_hostnames.push_back(QString()); 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(linefirst()) { updateRow(line,q); } delete q; } } void RDStationListModel::updateRow(int row,RDSqlQuery *q) { QList texts; QList icons; // Hostname 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 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 if(q->value(6).toString().toLower().trimmed()=="localhost") { texts.push_back(q->value(0)); } else { texts.push_back(q->value(6)); } icons.push_back(rda->iconEngine()->stationIcon()); // CAE Host if(q->value(7).toString().toLower().trimmed()=="localhost") { texts.push_back(q->value(0)); } else { texts.push_back(q->value(7)); } icons.push_back(rda->iconEngine()->stationIcon()); // Report Editor if(q->value(8).toString().isEmpty()) { texts.push_back("vi"); } 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; }