From df168536ca1aaf0b147e67ef214bf35dfd34e441 Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Thu, 30 May 2019 01:14:31 +0200 Subject: Cleanup, and rewrite cmdline + settings handling Command line parsing now uses QCommandLineXXX classes Old unused options have been removed, like the "pools" feature Closes #3599 --- src/dialog.cpp | 59 ++++++++++++++++++++++++++++++++++------------------------ 1 file changed, 35 insertions(+), 24 deletions(-) (limited to 'src/dialog.cpp') diff --git a/src/dialog.cpp b/src/dialog.cpp index 10ebe22..8c02c9a 100644 --- a/src/dialog.cpp +++ b/src/dialog.cpp @@ -1,4 +1,5 @@ #include "dialog.h" +#include "config.h" #include #include @@ -24,17 +25,13 @@ static bool isProcessRunning(const QString &binary); -Dialog::Dialog(int defaultTab, bool examMode, QWidget *parent) +Dialog::Dialog(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; genericExpandedOnce_ = false; - examMode_ = examMode; autoQuit_ = g_autoQuitSeconds; ui->setupUi(this); @@ -71,11 +68,11 @@ Dialog::Dialog(int defaultTab, bool examMode, QWidget *parent) this, SLOT(treeView_selectionChanged(const QModelIndex&, const QModelIndex&))); */ - ui->PVS_checkbox->setVisible(g_pvsEnabled); - ui->PVS_checkbox->setChecked(g_pvsChecked); + ui->PVS_checkbox->setVisible(Config::isSet(Config::PVS)); + ui->PVS_checkbox->setChecked(Config::isSet(Config::PVS_CHECKED)); activeTab_ = -1; - if (examMode_) { + if (Config::isSet(Config::EXAM_MODE)) { ui->tabButtonLocal->setEnabled(false); this->onTabButtonChanged(TAB_ALL_VMS); /* modify the pvs checkbox */ @@ -88,7 +85,7 @@ Dialog::Dialog(int defaultTab, bool examMode, QWidget *parent) this->selectPreviousSession(); } - ui->chkAdminMode->setVisible(g_allowVmEdit); + ui->chkAdminMode->setVisible(Config::isSet(Config::ALLOW_VM_EDIT)); ui->chkAdminMode->setEnabled(false); ui->btnScreenSetup->setVisible(isProcessRunning("beamergui")); @@ -132,7 +129,7 @@ void Dialog::on_treeView_doubleClicked(const QModelIndex& index) return; // These two are up here in case run-virt cares... - if (g_pvsEnabled) { + if (Config::isSet(Config::PVS)) { if (ui->PVS_checkbox->isChecked()) { setenv("PVS_AUTO_CONNECT", "TRUE", 1); } else { @@ -217,7 +214,7 @@ void Dialog::addItems(const QList& entries, int tab) { if (tab < 0 || tab > 2) { return; } - if (examMode_ && tab == TAB_NATIVE) + if (Config::isSet(Config::EXAM_MODE) && tab == TAB_NATIVE) return; this->model_[tab]->addItems(entries); tabs_[tab]->setEnabled(this->model_[tab]->rowCount() != 0); @@ -346,7 +343,10 @@ void Dialog::selectPreviousSession() { qDebug() << "Not selecting previous session as user interacted or session was already selected"; return; } - QString lastSession = ChooserSettings::getSetting("last-session"); + QString lastSession = Config::get(Config::DEFAULT_SESSION); + if (lastSession.isEmpty()) { + lastSession = ChooserSettings::getSetting("last-session"); + } if (!lastSession.isEmpty()) { qDebug() << "Trying to select last session: " << lastSession; ui->treeView->clearSelection(); @@ -362,9 +362,10 @@ void Dialog::selectPreviousSession() { qDebug() << "Trying to select last tab " << lastTab; this->onTabButtonChanged(lastTab.toInt()); } else { - qDebug() << "Selected default tab " << defaultTab_; + int defaultTab = Config::get(Config::DEFAULT_TAB).toInt(); + qDebug() << "Selected default tab " << defaultTab; // Select default tab - this->onTabButtonChanged(defaultTab_); + this->onTabButtonChanged(defaultTab); } } @@ -377,12 +378,15 @@ void Dialog::setTheme() { QString backgroundColor, imageLeft, imageRight; QString themePathBase, themePathIni, themePathImgLeft, themePathImgRight; - if (g_themeName.isEmpty()) return; + if (Config::isSet(Config::THEME)) + return; - themePathBase = QString("%1/%2/").arg(VMCHOOSER_THEME_BASE).arg(g_themeName); - themePathIni = QString("%1%2.ini").arg(themePathBase).arg(g_themeName); + QString theme(Config::get(Config::THEME)); + themePathBase = QString("%1/%2/").arg(VMCHOOSER_THEME_BASE).arg(theme); + themePathIni = QString("%1%2.ini").arg(themePathBase).arg(theme); - if (!QFile::exists(themePathIni)) return; + if (!QFile::exists(themePathIni)) + return; QSettings themeSettings(themePathIni, QSettings::IniFormat); @@ -437,13 +441,15 @@ void Dialog::onCenterTimer() { * Download lecture list, news and help */ void Dialog::downloadData(const QString& locationIds) { - QUrl listUrl(g_urlList); + QUrl listUrl(Config::isSet(Config::URL_LIST) + ? Config::get(Config::URL_LIST) + : Config::get(Config::URL_BASE).append("/list")); QUrlQuery listQuery(listUrl); if (!locationIds.isEmpty()) { listQuery.addQueryItem("locations", locationIds); } - if (examMode_) { + if (Config::isSet(Config::EXAM_MODE)) { listQuery.addQueryItem("exams", "exam-mode"); } listUrl.setQuery(listQuery); @@ -509,7 +515,9 @@ void Dialog::downloadData(const QString& locationIds) { }); // // News - FileDownloader::download(QUrl(g_urlNews), [this](QNetworkReply::NetworkError err, const QByteArray& data) { + FileDownloader::download(QUrl(Config::isSet(Config::URL_NEWS) + ? Config::get(Config::URL_NEWS) + : Config::get(Config::URL_BASE).append("/news")), [this](QNetworkReply::NetworkError err, const QByteArray& data) { if (err != QNetworkReply::NoError) { if (g_debugMode) { qDebug() << "Could not get news. Try to get cached news."; @@ -580,7 +588,9 @@ void Dialog::downloadData(const QString& locationIds) { }); // // Download help - FileDownloader::download(QUrl(g_urlHelp), [this](QNetworkReply::NetworkError err, const QByteArray& data) { + FileDownloader::download(QUrl(Config::isSet(Config::URL_HELP) + ? Config::get(Config::URL_HELP) + : Config::get(Config::URL_BASE).append("/help")), [this](QNetworkReply::NetworkError err, const QByteArray& data) { if (err != QNetworkReply::NoError) { if (g_debugMode) { qDebug() << "Could not get help xml. Try to get cached help..."; @@ -673,7 +683,8 @@ void Dialog::treeView_selectionChanged(const QModelIndex& current, const QModelI ui->label_platform->setText(vs->getAttribute("virtualizer_name", "param")); ui->label_platform->setToolTip(vs->getAttribute("virtualizer_name", "param")); - ui->chkAdminMode->setEnabled(vs->canEdit() || g_allowVmEdit); + // TODO: This is a bug? vs->canEdit() seems completely pointless right now... + ui->chkAdminMode->setEnabled(vs->canEdit() || Config::isSet(Config::ALLOW_VM_EDIT)); if (vs->keywords().length() > 0) { description = "\n\nKeywords: "; @@ -709,7 +720,7 @@ void Dialog::on_tabButtonAllClasses_clicked() { } void Dialog::onTabButtonChanged(int tab) { - if (tab < 0 || tab > 2) { + if (tab < 0 || tab >= TAB_COUNT) { // no valid button return; } -- cgit v1.2.3-55-g7522