From c88a37d2caf4b34f069e0240fe9fa4dff6d673ed Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Mon, 5 May 2014 13:06:55 +0200 Subject: Improve string handling, fix list not updating after sessions are loaded --- src/dialog.cpp | 60 ++++++++++++++++++++++++++++++++++------------------------ 1 file changed, 35 insertions(+), 25 deletions(-) (limited to 'src/dialog.cpp') diff --git a/src/dialog.cpp b/src/dialog.cpp index ecfc097..8ea994a 100644 --- a/src/dialog.cpp +++ b/src/dialog.cpp @@ -27,6 +27,10 @@ Dialog::Dialog(QWidget *parent) tabs_[1] = ui->tabButtonMyClasses; tabs_[2] = ui->tabButtonAllClasses; + strings_[STR_LOADING] = QCoreApplication::instance()->translate("Dialog", "Loading..."); + strings_[STR_URL_ERROR] = QCoreApplication::instance()->translate("Dialog", "URL Error"); + strings_[STR_NO_ITEMS] = QCoreApplication::instance()->translate("Dialog", "No Items"); + pvsSettings_ = NULL; ui->PVSOptionsGroupBox->hide(); @@ -37,13 +41,15 @@ Dialog::Dialog(QWidget *parent) connect(centerTimer_, SIGNAL(timeout()), this, SLOT(onCenterTimer())); centerTimer_->start(1000); - activeTab = 0; + activeTab_ = 0; ui->tabButtonLocal->setChecked(true); ui->filterEdit->setEnabled(false); ui->helpBox->hide(); ui->newsBox->hide(); + this->addStatusString(STR_LOADING); + QObject::connect(ui->treeView->selectionModel(), SIGNAL(currentChanged ( const QModelIndex&, const QModelIndex&)), this, SLOT(treeView_selectionChanged(const QModelIndex&, const QModelIndex&))); @@ -91,7 +97,7 @@ void Dialog::on_treeView_activated(QModelIndex index) { if (s->run()) { writePVSSettings(); ChooserSettings::setSetting("last-session", (s->shortDescription())); - ChooserSettings::setSetting("last-tab", QString::number(activeTab)); + ChooserSettings::setSetting("last-tab", QString::number(activeTab_)); setVisible(false); } else { @@ -107,22 +113,27 @@ void Dialog::addItems(const QList& entries, int tab) { } this->model_[tab]->addItems(entries); tabs_[tab]->setEnabled(this->model_[tab]->rowCount() != 0); + if (tab == activeTab_) { + setListModel(this->model_[tab]); + } } -void Dialog::addLabelItem(const QString& label, int tab) { - if (tab < 0 || tab > 2) { - return; - } - this->model_[tab]->addLabelItem(label); - tabs_[tab]->setEnabled(this->model_[tab]->rowCount() != 0); +void Dialog::addStatusString(const int status) { + if (status < 0 || status >= STR__MAX) + return; + this->model_[1]->addLabelItem(strings_[status]); + this->model_[2]->addLabelItem(strings_[status]); + tabs_[1]->setEnabled(this->model_[1]->rowCount() > 1); + tabs_[2]->setEnabled(this->model_[2]->rowCount() > 1); } -void Dialog::removeItem(const QString& name, int tab) { - if (tab < 0 || tab > 2) { - return; - } - this->model_[tab]->removeItem(name); - tabs_[tab]->setEnabled(this->model_[tab]->rowCount() != 0); +void Dialog::removeStatusString(const int status) { + if (status < 0 || status >= STR__MAX) + return; + this->model_[1]->removeItem(strings_[status]); + this->model_[2]->removeItem(strings_[status]); + tabs_[1]->setEnabled(this->model_[1]->rowCount() > 1); + tabs_[2]->setEnabled(this->model_[1]->rowCount() > 1); } void Dialog::on_pushButtonAbort_clicked() { @@ -313,8 +324,8 @@ void Dialog::addSessionsAfterDownload(QNetworkReply* reply) { if (debugMode) { qDebug() << "Cannot read backup file " << xml_filename << " either"; } - this->removeItem(QCoreApplication::instance()->translate("Dialog", "Loading..."), 1); - this->addLabelItem(QCoreApplication::instance()->translate("Dialog", "URL Error"), 1); + this->removeStatusString(STR_LOADING); + this->addStatusString(STR_URL_ERROR); return; } if (debugMode) { @@ -339,13 +350,13 @@ void Dialog::addSessionsAfterDownload(QNetworkReply* reply) { QList sessions = VSession::readXmlFile(temp_filename); - this->removeItem(QCoreApplication::instance()->translate("Dialog", "Loading..."), 1); + this->removeStatusString(STR_LOADING); if (!sessions.isEmpty()) { qSort(sessions.begin(), sessions.end(), myLessThan); this->addItems(sessions, 2); // TODO: No magic number; handle user specific classes } else { - this->addLabelItem(QCoreApplication::instance()->translate("Dialog", "No Items"), 1); + this->addStatusString(STR_NO_ITEMS); } // select last-session @@ -387,8 +398,8 @@ void Dialog::treeView_selectionChanged(const QModelIndex& current, const QModelI } else { ui->label_name->setText(s->shortDescription()); ui->label_creator->setText(""); - ui->label_os->setText(QCoreApplication::instance()->translate("Dialog", "Native")); - ui->textBrowser->setPlainText(QCoreApplication::instance()->translate("Dialog", "Running on this machine.")); + ui->label_os->setText(QCoreApplication::instance()->translate("Dialog", "Native Linux")); + ui->textBrowser->setPlainText(QCoreApplication::instance()->translate("Dialog", "Linux X session running on this machine without virtualization.")); } } @@ -419,13 +430,13 @@ void Dialog::onTabButtonChanged(int tab) { } // clear filter if necessary - if (activeTab != tab) { + if (activeTab_ != tab) { this->ui->filterEdit->setText(""); } // load the new list setListModel(model_[tab]); - this->activeTab = tab; + this->activeTab_ = tab; } void Dialog::on_filterEdit_textChanged() { @@ -434,9 +445,9 @@ void Dialog::on_filterEdit_textChanged() { // filter the current model if (ui->filterEdit->text() != "" && ui->filterEdit->text().replace(" ", "").length() > 2) { newModel = new SessionTreeModel(this); - newModel->addItems(this->model_[activeTab]->lookForItem(ui->filterEdit->text())); + newModel->addItems(this->model_[activeTab_]->lookForItem(ui->filterEdit->text())); } else { - newModel = model_[activeTab]; + newModel = model_[activeTab_]; } setListModel(newModel); } @@ -453,7 +464,6 @@ void Dialog::setListModel(QAbstractItemModel *model) { this, SLOT(treeView_selectionChanged(const QModelIndex&, const QModelIndex&))); if (ui->treeView->selectionModel()->selectedRows(0).count() == 0) { - ui->treeView->selectionModel()->clearSelection(); ui->treeView->selectionModel()->setCurrentIndex(ui->treeView->model()->index(0, 0, ui->treeView->rootIndex()), QItemSelectionModel::Select); } } -- cgit v1.2.3-55-g7522