summaryrefslogtreecommitdiffstats
path: root/src/dialog.cpp
diff options
context:
space:
mode:
authorSimon Rettberg2016-01-04 11:07:53 +0100
committerSimon Rettberg2016-01-04 11:07:53 +0100
commit42cd0a3f7e3b502693c1ef4be2a57886c86b006a (patch)
treeb6655340f987f9ef7c2d737420f64aa4d0cac80f /src/dialog.cpp
parentUpdate vmware icon (diff)
downloadvmchooser2-42cd0a3f7e3b502693c1ef4be2a57886c86b006a.tar.gz
vmchooser2-42cd0a3f7e3b502693c1ef4be2a57886c86b006a.tar.xz
vmchooser2-42cd0a3f7e3b502693c1ef4be2a57886c86b006a.zip
Update images
Diffstat (limited to 'src/dialog.cpp')
-rw-r--r--src/dialog.cpp139
1 files changed, 86 insertions, 53 deletions
diff --git a/src/dialog.cpp b/src/dialog.cpp
index 605aeb4..8572c67 100644
--- a/src/dialog.cpp
+++ b/src/dialog.cpp
@@ -20,11 +20,15 @@
#include "vsession.h"
#include "choosersettings.h"
-Dialog::Dialog(QWidget *parent)
+Dialog::Dialog(int defaultTab, QWidget *parent)
: QDialog(parent), ui(new Ui::Dialog) {
model_[0] = new SessionTreeModel(parent);
model_[1] = new SessionTreeModel(parent);
model_[2] = new SessionTreeModel(parent);
+ if (defaultTab < 0 || defaultTab > TAB_COUNT) defaultTab = TAB_ALL_VMS;
+ defaultTab_ = defaultTab;
+ qDebug() << "Default tab: " << defaultTab;
+ userInteracted_ = false;
ui->setupUi(this);
@@ -43,23 +47,23 @@ Dialog::Dialog(QWidget *parent)
connect(centerTimer_, SIGNAL(timeout()), this, SLOT(onCenterTimer()));
centerTimer_->start(1000);
- activeTab_ = 2;
- ui->tabButtonAllClasses->setChecked(true);
-
ui->helpBox->hide();
ui->newsBox->hide();
- oldRow_ = 0; // this is the old row (when switching to a new tab)
-
this->addStatusString(STR_LOADING);
/*
* TODO: why connect signal/slot when no item was loaded yet?
+ * TODO: Change "TODO" in the above line to "QUESTION", as it's just that
QObject::connect(ui->treeView->selectionModel(), SIGNAL(currentChanged ( const QModelIndex&, const QModelIndex&)),
this, SLOT(treeView_selectionChanged(const QModelIndex&, const QModelIndex&)));
*/
- this->onTabButtonChanged(2);
+ this->onTabButtonChanged(0);
+ this->selectPreviousSession();
+ //activeTab_ = 2;
+ //ui->tabButtonAllClasses->setChecked(true);
+
// TODO: Implement bug report dialog :)
ui->buttonBugReport->setEnabled(false);
@@ -82,8 +86,9 @@ void Dialog::changeEvent(QEvent *e) {
}
}
-void Dialog::on_treeView_doubleClicked(QModelIndex index)
+void Dialog::on_treeView_doubleClicked(const QModelIndex& index)
{
+ userInteracted_ = true;
// this method gets called when a Session has been selected to start
SessionTreeItem* item =
@@ -155,6 +160,7 @@ void Dialog::addItems(const QList<Session*>& entries, int tab) {
setListModel(this->model_[tab]);
}
model_[tab]->updateView();
+ selectPreviousSession();
}
void Dialog::addStatusString(const int status) {
@@ -184,13 +190,14 @@ void Dialog::on_pushButtonAbort_clicked() {
}
void Dialog::on_pushButtonStart_clicked() {
+ userInteracted_ = true;
this->on_treeView_doubleClicked(ui->treeView->selectionModel()->currentIndex());
}
bool Dialog::selectSession(const QString& name) {
QModelIndex root(ui->treeView->rootIndex());
- for (int tab = 0; tab <= 2; ++tab) {
+ for (int tab = 0; tab <= TAB_COUNT; ++tab) {
for (int i = 0; i < model_[tab]->rowCount(root); ++i) {
QModelIndex index = model_[tab]->index(i, 0, root);
if (!index.isValid()) {
@@ -218,16 +225,28 @@ bool Dialog::selectSession(const QString& name) {
}
void Dialog::selectPreviousSession() {
- if (ChooserSettings::getSetting("last-session").isEmpty()) {
- this->onTabButtonChanged(2);
- } else {
+ if (userInteracted_) {
+ qDebug() << "Not selecting previous session as user interacted or session was already selected";
+ return;
+ }
+ if (!ChooserSettings::getSetting("last-session").isEmpty()) {
+ qDebug() << "Trying to select last session: " << ChooserSettings::getSetting("last-session");
ui->treeView->clearSelection();
- if (!selectSession(ChooserSettings::getSetting("last-session"))) {
- // could not find last session, change to last used tab
- this->onTabButtonChanged(ChooserSettings::getSetting("last-tab").toInt());
+ if (selectSession(ChooserSettings::getSetting("last-session"))) {
+ qDebug() << "Success";
+ userInteracted_ = true;
+ return;
}
}
- //setListModel(this->model_[this->activeTab_]);
+ // could not find last session, change to last used tab
+ if (!ChooserSettings::getSetting("last-tab").isEmpty()) {
+ qDebug() << "Trying to select last tab " << ChooserSettings::getSetting("last-tab");
+ this->onTabButtonChanged(ChooserSettings::getSetting("last-tab").toInt());
+ } else {
+ qDebug() << "Selected default tab " << defaultTab_;
+ // Select default tab
+ this->onTabButtonChanged(defaultTab_);
+ }
}
void Dialog::startSession(const QString& name) {
@@ -294,23 +313,17 @@ void Dialog::addSessionsAfterDownload(QNetworkReply* reply) {
QString temp_filename;
if (reply->error() != QNetworkReply::NoError) {
- if (debugMode) {
- qDebug() << "Error reading from URL: " << reply->error();
- }
+ qDebug() << "Error reading from URL: " << reply->error();
QFile backup_file(xml_filename);
if (!backup_file.open(QIODevice::ReadOnly)) {
- if (debugMode) {
- qDebug() << "Cannot read backup file " << xml_filename << " either";
- }
+ qDebug() << "Cannot read backup file " << xml_filename << " either";
this->removeStatusString(STR_LOADING);
this->addStatusString(STR_URL_ERROR);
return;
}
- if (debugMode) {
- qDebug() << "Using backup file " << xml_filename;
- }
+ qDebug() << "Using backup file " << xml_filename;
backup_file.close();
temp_filename = xml_filename;
@@ -334,7 +347,8 @@ void Dialog::addSessionsAfterDownload(QNetworkReply* reply) {
if (!sessions.isEmpty()) {
qSort(sessions.begin(), sessions.end(), myLessThan);
- this->addItems(sessions, 2); // TODO: No magic number; handle user specific classes
+ this->addItems(sessions, TAB_ALL_VMS);
+ // TODO: Filter user's classes and add to tab[TAB_MY_COURSES]
} else {
this->addStatusString(STR_NO_ITEMS);
}
@@ -344,6 +358,11 @@ void Dialog::addSessionsAfterDownload(QNetworkReply* reply) {
// select last-session
selectPreviousSession();
+ userInteracted_ = true;
+}
+
+void Dialog::on_treeView_clicked(const QModelIndex&) {
+ userInteracted_ = true;
}
void Dialog::treeView_selectionChanged(const QModelIndex& current, const QModelIndex&) {
@@ -360,43 +379,50 @@ void Dialog::treeView_selectionChanged(const QModelIndex& current, const QModelI
return;
}
+ QString description;
if (s->type() == Session::VSESSION) {
const VSession* vs = (VSession*) s;
- ui->label_name->setText(vs->getAttribute("short_description", "param"));
- ui->label_name->setToolTip(vs->getAttribute("short_description", "param"));
-
ui->label_creator->setText(vs->getAttribute("creator", "param"));
ui->label_creator->setToolTip(vs->getAttribute("creator", "param"));
- ui->label_os->setText(vs->getAttribute("os", "param"));
- ui->label_os->setToolTip(vs->getAttribute("os", "param"));
+ ui->label_os->setText(vs->getAttribute("os_name", "param"));
+ ui->label_os->setToolTip(vs->getAttribute("os_name", "param"));
- QString description(vs->getAttribute("long_description", "param") + "\n\nKeywords: ");
- for (int i = 0; i < vs->keywords().length(); ++i) {
- description += vs->keywords()[i] + ", ";
- }
-
- ui->textBrowser->setText(description);
+ ui->label_platform->setText(vs->getAttribute("virtualizer_name", "param"));
+ ui->label_platform->setToolTip(vs->getAttribute("virtualizer_name", "param"));
+ if (vs->keywords().length() > 0) {
+ description = "\n\nKeywords: ";
+ for (int i = 0; i < vs->keywords().length(); ++i) {
+ description += vs->keywords()[i] + ", ";
+ }
+ }
} else {
- ui->label_name->setText(s->shortDescription());
ui->label_creator->setText("");
+ ui->label_creator->setToolTip("");
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."));
+ ui->label_platform->setText("Linux");
+ ui->label_platform->setToolTip("");
}
+ ui->label_name->setText(s->shortDescription());
+ ui->label_name->setToolTip(s->shortDescription());
+ ui->textBrowser->setPlainText(s->description() + description);
}
void Dialog::on_tabButtonLocal_clicked() {
- onTabButtonChanged(0);
+ userInteracted_ = true;
+ onTabButtonChanged(TAB_NATIVE);
}
void Dialog::on_tabButtonMyClasses_clicked() {
- onTabButtonChanged(1);
+ userInteracted_ = true;
+ onTabButtonChanged(TAB_MY_COURSES);
}
void Dialog::on_tabButtonAllClasses_clicked() {
- onTabButtonChanged(2);
+ userInteracted_ = true;
+ onTabButtonChanged(TAB_ALL_VMS);
}
void Dialog::onTabButtonChanged(int tab) {
@@ -418,9 +444,6 @@ void Dialog::onTabButtonChanged(int tab) {
this->ui->filterEdit->setText("");
}
- // save old row
- //oldRow_ = ui->treeView->selectionModel()->currentIndex().row();
-
// load the new list
setListModel(model_[tab]);
this->activeTab_ = tab;
@@ -428,28 +451,38 @@ void Dialog::onTabButtonChanged(int tab) {
ui->treeView->selectionModel()->clearSelection();
ui->treeView->selectionModel()->select(ui->treeView->model()->index(0, 0, ui->treeView->rootIndex()), QItemSelectionModel::Select);
ui->treeView->selectionModel()->setCurrentIndex(ui->treeView->model()->index(0, 0, ui->treeView->rootIndex()), QItemSelectionModel::Select);
- //treeView_selectionChanged(ui->treeView->model()->index(oldRow_, 0, ui->treeView->rootIndex()), ui->treeView->model()->index(0, 0, ui->treeView->rootIndex()));
}
void Dialog::on_filterEdit_textChanged() {
- SessionTreeModel *newModel;
+ if (activeTab_ < 0 || activeTab_ >= TAB_COUNT) return;
+ SessionTreeModel *newModel = NULL;
+ userInteracted_ = true;
// 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()));
- } else {
+ if (!ui->filterEdit->text().isEmpty() && ui->filterEdit->text().replace(" ", "").length() > 2) {
+ if (model_[activeTab_] != NULL) {
+ newModel = new SessionTreeModel(this);
+ newModel->addItems(this->model_[activeTab_]->lookForItem(ui->filterEdit->text()));
+ }
+ }
+ if (newModel == NULL) {
newModel = model_[activeTab_];
}
- setListModel(newModel);
+ if (newModel != NULL) {
+ setListModel(newModel);
+ }
}
void Dialog::setListModel(QAbstractItemModel *model) {
+ QAbstractItemModel *old = NULL;
if (ui->treeView->model() == model_[0] || ui->treeView->model() == model_[1] || ui->treeView->model() == model_[2]) {
} else {
- ui->treeView->model()->deleteLater();
+ old = ui->treeView->model();
}
ui->treeView->setModel(model);
+ if (old != NULL) {
+ old->deleteLater();
+ }
// reconnect the treeModel
QObject::connect(ui->treeView->selectionModel(), SIGNAL(currentChanged(const QModelIndex&, const QModelIndex&)),