summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/dialog.cpp60
-rw-r--r--src/dialog.h18
-rw-r--r--src/main.cpp2
3 files changed, 47 insertions, 33 deletions
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<Session*>& 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<Session*> 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);
}
}
diff --git a/src/dialog.h b/src/dialog.h
index dee7304..94c20b0 100644
--- a/src/dialog.h
+++ b/src/dialog.h
@@ -18,22 +18,27 @@ class QTimer;
class Dialog : public QDialog {
Q_OBJECT
- public:
+ private: // Constants
+ static const int STR_LOADING = 0;
+ static const int STR_URL_ERROR = 1;
+ static const int STR_NO_ITEMS = 2;
+ static const int STR__MAX = 3;
+ public: // Public methods
explicit Dialog(QWidget *parent = 0);
~Dialog();
void addItems(const QList<Session*>&, int tab);
- void addLabelItem(const QString& label, int tab);
- void removeItem(const QString& name, int tab);
+ void addStatusString(const int status);
+ void removeStatusString(const int status);
bool selectSession(const QString& name);
void selectPreviousSession();
void showSettingsPVS();
void setTheme();
void startSession(const QString& name);
- protected:
+ protected: // Overrides
void changeEvent(QEvent *e);
- private:
+ private: // Private vars n methods
Ui::Dialog *ui;
SessionTreeModel *model_[3]; // TODO: Constants/Enum for indices
QPushButton *tabs_[3];
@@ -41,7 +46,8 @@ class Dialog : public QDialog {
QPoint oldCenter_;
QTimer *centerTimer_;
QString autoStartEntry_;
- int activeTab;
+ int activeTab_;
+ QString strings_[STR__MAX];
void readPVSSettings();
void writePVSSettings();
void onTabButtonChanged(int tab);
diff --git a/src/main.cpp b/src/main.cpp
index 2c80919..87f30b9 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -232,8 +232,6 @@ int main(int argc, char *argv[]) {
w.addItems(xsessions, 0);
}
- w.addLabelItem(a.translate("Dialog", "Loading..."), 1);
-
QSettings SLXsettings(OPENSLXCONFIG, QSettings::NativeFormat);
if (SLXsettings.contains("SLX_BENCHMARK_VM")) {
QString vm = SLXsettings.value("SLX_BENCHMARK_VM").toString();