From 37e2f2292981bf6227482f762db15b86e42d089f Mon Sep 17 00:00:00 2001 From: Nils Schwabe Date: Mon, 24 Mar 2014 14:59:05 +0100 Subject: added choosersettings which remember the last selected session --- src/dialog.cpp | 71 ++++++++++++++++++++++++-------------------- src/main.cpp | 4 +-- src/save_restore_session.cpp | 31 ------------------- src/save_restore_session.h | 7 ----- 4 files changed, 40 insertions(+), 73 deletions(-) delete mode 100644 src/save_restore_session.cpp delete mode 100644 src/save_restore_session.h diff --git a/src/dialog.cpp b/src/dialog.cpp index 1249561..9fdbaa9 100644 --- a/src/dialog.cpp +++ b/src/dialog.cpp @@ -9,10 +9,10 @@ #include #include "ui_dialog.h" -#include "save_restore_session.h" #include "sessiontreeitem.h" #include "globals.h" #include "vsession.h" +#include "choosersettings.h" Dialog::Dialog(QWidget *parent) : QDialog(parent), ui(new Ui::Dialog) { @@ -85,7 +85,7 @@ void Dialog::on_treeView_activated(QModelIndex index) { if (s->run()) { writePVSSettings(); - writeSessionName(s->shortDescription()); + ChooserSettings::setSetting("last-session", (s->shortDescription())); setVisible(false); } else { @@ -186,31 +186,34 @@ void Dialog::on_comboBoxOthers_currentIndexChanged(int index) { bool Dialog::selectSession(const QString& name) { QModelIndex root(ui->treeView->rootIndex()); - for (int k = 0; k <= 2; ++k) { - for (int i = 0; i < model_[k]->rowCount(root); ++i) { - QModelIndex section = model_[k]->index(i, 0, root); - if (!section.isValid()) break; - for (int row = 0; row < model_[k]->rowCount(section); ++row) { - QModelIndex index = model_[k]->index(row, 0, section); - if (!index.isValid()) break; - - SessionTreeItem* item = - static_cast(index.internalPointer()); - const Session* s(item->session()); - if (!s) continue; - if (s->shortDescription() == name) { - ui->treeView->selectionModel() - ->setCurrentIndex(index, QItemSelectionModel::Select); - return true; - } + for (int tab = 0; tab <= 2; ++tab) { + for (int i = 0; i < model_[tab]->rowCount(root); ++i) { + QModelIndex index = model_[tab]->index(i, 0, root); + if (!index.isValid()) { + break; } - } + SessionTreeItem* item = static_cast(index.internalPointer()); + const Session* s(item->session()); + if (!s) { + continue; + } + if (s->shortDescription() == name) { + // change the tab + onTabButtonChanged(tab); + // set selection + ui->treeView->selectionModel() + ->setCurrentIndex(index, QItemSelectionModel::Select); + return true; + } + } } + return false; } void Dialog::selectPreviousSession() { - selectSession(readSessionName()); + qDebug() << "selecting previous session"; + selectSession(ChooserSettings::getSetting("last-session")); } void Dialog::startSession(const QString& name) { @@ -339,6 +342,9 @@ void Dialog::addSessionsAfterDownload(QNetworkReply* reply) { } else { this->addLabelItem(QCoreApplication::instance()->translate("Dialog", "No Items"), 1); } + + // select last-session + selectPreviousSession(); } void Dialog::treeView_selectionChanged(const QModelIndex& current, const QModelIndex&) { @@ -417,25 +423,24 @@ void Dialog::onTabButtonChanged(int tab) { // when button was pressed disable the other buttons if (tab == 0) { + ui->tabButtonLocal->setChecked(true); ui->tabButtonMyClasses->setChecked(false); ui->tabButtonAllClasses->setChecked(false); ui->filterEdit->setEnabled(false); } else if (tab == 1) { ui->tabButtonLocal->setChecked(false); + ui->tabButtonMyClasses->setChecked(true); ui->tabButtonAllClasses->setChecked(false); ui->filterEdit->setEnabled(true); } else { ui->tabButtonLocal->setChecked(false); ui->tabButtonMyClasses->setChecked(false); + ui->tabButtonAllClasses->setChecked(true); ui->filterEdit->setEnabled(true); } // load the new list setListModel(model_[tab]); - - // reconnect the treeModel - QObject::connect(ui->treeView->selectionModel(), SIGNAL(currentChanged ( const QModelIndex&, const QModelIndex&)), - this, SLOT(treeView_selectionChanged(const QModelIndex&, const QModelIndex&))); } void Dialog::on_filterEdit_textChanged() { @@ -450,6 +455,14 @@ void Dialog::on_filterEdit_textChanged() { } setListModel(newModel); +} + +void Dialog::setListModel(QAbstractItemModel *model) { + if (ui->treeView->model() == model_[0] || ui->treeView->model() == model_[1] || ui->treeView->model() == model_[2]) { + } else { + ui->treeView->model()->deleteLater(); + } + ui->treeView->setModel(model); // reconnect the treeModel QObject::connect(ui->treeView->selectionModel(), SIGNAL(currentChanged ( const QModelIndex&, const QModelIndex&)), @@ -461,14 +474,6 @@ void Dialog::on_filterEdit_textChanged() { } } -void Dialog::setListModel(QAbstractItemModel *model) { - if (ui->treeView->model() == model_[0] || ui->treeView->model() == model_[1] || ui->treeView->model() == model_[2]) { - } else { - ui->treeView->model()->deleteLater(); - } - ui->treeView->setModel(model); -} - void Dialog::on_helpNewsButton_clicked() { if (ui->helpBox->isVisible()) { ui->helpBox->hide(); diff --git a/src/main.cpp b/src/main.cpp index 86deb3f..722f80a 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -15,10 +15,10 @@ #include "command_line_options.h" #include "dialog.h" #include "globals.h" -#include "save_restore_session.h" #include "vsession.h" #include "xsession.h" #include "httpxmldownloader.h" +#include "choosersettings.h" int main(int argc, char *argv[]) { QApplication a(argc, argv); @@ -105,7 +105,7 @@ int main(int argc, char *argv[]) { } else if (settings.contains("default")) { defaultSession = settings.value("default").toString(); } else { - defaultSession = readSessionName(); + defaultSession = ChooserSettings::getSetting("last-session"); } if (cmdOptions.contains("path")) { diff --git a/src/save_restore_session.cpp b/src/save_restore_session.cpp deleted file mode 100644 index 8ca1f9d..0000000 --- a/src/save_restore_session.cpp +++ /dev/null @@ -1,31 +0,0 @@ -#include "save_restore_session.h" -#include -#include -#include -#include "globals.h" - -void writeSessionName(QString name) { - QDir saveFileDir(QFileInfo(previousSessionFile).absoluteDir()); - if (!saveFileDir.exists()) { - if (!saveFileDir.mkpath(saveFileDir.path())) { - // TODO: error - return; - } - } - - QFile saveFile(previousSessionFile); - if (!saveFile.open(QIODevice::WriteOnly) || - saveFile.write(name.toUtf8().data()) == -1) { - // TODO: error - } -} - -QString readSessionName() { - QFile saveFile(previousSessionFile); - - if (saveFile.open(QIODevice::ReadOnly)) { - return QString(saveFile.readAll()); - } else { - return QString(); - } -} diff --git a/src/save_restore_session.h b/src/save_restore_session.h deleted file mode 100644 index e04ee28..0000000 --- a/src/save_restore_session.h +++ /dev/null @@ -1,7 +0,0 @@ -#ifndef VMCHOOSER_SAVE_RESTORE_SESSION_H -#define VMCHOOSER_SAVE_RESTORE_SESSION_H -class QString; - -void writeSessionName(QString name); -QString readSessionName(); -#endif -- cgit v1.2.3-55-g7522