summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorSimon Rettberg2019-06-03 15:47:47 +0200
committerSimon Rettberg2019-06-03 15:47:47 +0200
commitcf77e6923cae8b21b8319b7edf6102c80915b45a (patch)
tree95114958ec59569c91bf13d7df1caa7b4b820e62 /src
parentAdd option to show the "disable screensaver" checkbox (diff)
downloadvmchooser2-cf77e6923cae8b21b8319b7edf6102c80915b45a.tar.gz
vmchooser2-cf77e6923cae8b21b8319b7edf6102c80915b45a.tar.xz
vmchooser2-cf77e6923cae8b21b8319b7edf6102c80915b45a.zip
Refactor user .ini class, support "recent VMs" tab, misc. cleanup
Diffstat (limited to 'src')
-rw-r--r--src/choosersettings.cpp57
-rw-r--r--src/choosersettings.h31
-rw-r--r--src/dialog.cpp166
-rw-r--r--src/dialog.h5
-rw-r--r--src/globals.cpp5
-rw-r--r--src/globals.h2
-rw-r--r--src/i18n/de.ts67
-rwxr-xr-xsrc/i18n/pt.ts96
-rw-r--r--src/main.cpp1
-rw-r--r--src/ui/dialog.ui2
-rw-r--r--src/userconfig.cpp79
-rw-r--r--src/userconfig.h21
12 files changed, 202 insertions, 330 deletions
diff --git a/src/choosersettings.cpp b/src/choosersettings.cpp
deleted file mode 100644
index 439c9ea..0000000
--- a/src/choosersettings.cpp
+++ /dev/null
@@ -1,57 +0,0 @@
-/*
- * choosersettings.cpp
- *
- * Created on: Mar 24, 2014
- * Author: nils
- */
-
-#include "choosersettings.h"
-#include "globals.h"
-
-bool ChooserSettings::settingsLoaded = false;
-ChooserSettings* ChooserSettings::chooserSettings = nullptr;
-
-ChooserSettings::ChooserSettings() {
- // test (and make) directory
- QDir saveFileDir(QFileInfo(PREVIOUS_SESSION_USER).absoluteDir());
- if (!saveFileDir.exists()) {
- if (!saveFileDir.mkpath(saveFileDir.path())) {
- return;
- }
- }
-
- settings = new QSettings(PREVIOUS_SESSION_USER, QSettings::IniFormat);
- settings->setIniCodec("UTF-8");
-
- if (settings->status() != QSettings::NoError) {
- if (g_debugMode) {
- qDebug() << "Settings: " << PREVIOUS_SESSION_USER << " contains erros.";
- }
- return;
- }
-
- settingsLoaded = true;
-}
-
-ChooserSettings::~ChooserSettings() {
- settings->deleteLater();
-}
-
-QString ChooserSettings::getSetting(QString key) {
- if (!settingsLoaded) {
- chooserSettings = new ChooserSettings();
- if (!settingsLoaded) return "";
- }
-
- return chooserSettings->settings->value(key).toString();
-}
-
-bool ChooserSettings::setSetting(QString key, QString value) {
- if (!settingsLoaded) {
- chooserSettings = new ChooserSettings();
- if (!settingsLoaded) return false;
- }
- chooserSettings->settings->setValue(key, value);
-// chooserSettings->settings->sync();
- return true;
-}
diff --git a/src/choosersettings.h b/src/choosersettings.h
deleted file mode 100644
index ea0bb76..0000000
--- a/src/choosersettings.h
+++ /dev/null
@@ -1,31 +0,0 @@
-/*
- * choosersettings.h
- *
- * Created on: Mar 24, 2014
- * Author: nils
- */
-
-#ifndef CHOOSERSETTINGS_H_
-#define CHOOSERSETTINGS_H_
-
-#include <QDebug>
-#include <QSettings>
-#include <QDir>
-
-// TODO: Proper name. This is the user specific settings, not global
-class ChooserSettings {
-public:
- static QString getSetting(QString key);
- static bool setSetting(QString key, QString value);
-
-private:
- static ChooserSettings* chooserSettings;
- static bool settingsLoaded;
-
- QSettings* settings;
-
- ChooserSettings();
- virtual ~ChooserSettings();
-};
-
-#endif /* CHOOSERSETTINGS_H_ */
diff --git a/src/dialog.cpp b/src/dialog.cpp
index 298efc4..8a9a79e 100644
--- a/src/dialog.cpp
+++ b/src/dialog.cpp
@@ -20,25 +20,25 @@
#include "sessiontreeitem.h"
#include "globals.h"
#include "vsession.h"
-#include "choosersettings.h"
+#include "userconfig.h"
#include "filedownloader.h"
static bool isProcessRunning(const QString &binary);
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);
+ model_[TAB_NATIVE] = new SessionTreeModel(parent);
+ model_[TAB_RECENT_COURSES] = new SessionTreeModel(parent);
+ model_[TAB_ALL_VMS] = new SessionTreeModel(parent);
userInteracted_ = false;
genericExpandedOnce_ = false;
autoQuit_ = g_autoQuitSeconds;
ui->setupUi(this);
- tabs_[0] = ui->tabButtonLocal;
- tabs_[1] = ui->tabButtonMyClasses;
- tabs_[2] = ui->tabButtonAllClasses;
+ tabs_[TAB_NATIVE] = ui->tabButtonLocal;
+ tabs_[TAB_RECENT_COURSES] = ui->tabButtonMyClasses;
+ tabs_[TAB_ALL_VMS] = ui->tabButtonAllClasses;
strings_[STR_LOADING] = QCoreApplication::instance()->translate("Dialog", "Loading...");
strings_[STR_URL_ERROR] = QCoreApplication::instance()->translate("Dialog", "URL Error");
@@ -84,7 +84,6 @@ Dialog::Dialog(QWidget *parent)
} else {
this->onTabButtonChanged(TAB_NATIVE);
- this->selectPreviousSession();
}
ui->chkAdminMode->setVisible(Config::isSet(Config::ALLOW_VM_EDIT));
@@ -193,8 +192,8 @@ void Dialog::on_treeView_doubleClicked(const QModelIndex& index)
// Wait and cleanup the intermediate process
waitpid(pid, nullptr, 0);
}
- ChooserSettings::setSetting("last-session", (s->shortDescription()));
- ChooserSettings::setSetting("last-tab", QString::number(activeTab_));
+ UserConfig::addLastSession(s->uuid().isEmpty() ? s->shortDescription() : s->uuid());
+ UserConfig::setLastTab(activeTab_);
centerTimer_->stop(); // Stop the auto-center/auto-quit timer, so we don't kill the session :>
setVisible(false);
} else {
@@ -216,6 +215,21 @@ void Dialog::addItems(const QList<Session*>& entries, int tab) {
if (tab < 0 || tab > 2) {
return;
}
+ if (tab != TAB_RECENT_COURSES) {
+ auto prev = UserConfig::getLastSessions();
+ if (!prev.isEmpty()) {
+ QList<Session*> matches;
+ for (auto it : entries) {
+ if ((!it->uuid().isEmpty() && prev.contains(it->uuid()))
+ || prev.contains(it->shortDescription())) {
+ matches.append(it);
+ }
+ }
+ if (!matches.isEmpty()) {
+ addItems(matches, TAB_RECENT_COURSES);
+ }
+ }
+ }
if (Config::isSet(Config::EXAM_MODE) && tab == TAB_NATIVE)
return;
this->model_[tab]->addItems(entries);
@@ -224,30 +238,32 @@ void Dialog::addItems(const QList<Session*>& entries, int tab) {
setListModel(this->model_[tab]);
}
model_[tab]->updateView();
- selectPreviousSession();
on_filterEdit_textChanged();
+ if (tab != TAB_RECENT_COURSES) {
+ selectPreviousSession();
+ }
}
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);
- model_[1]->updateView();
- model_[2]->updateView();
+ this->model_[TAB_RECENT_COURSES]->addLabelItem(strings_[status]);
+ this->model_[TAB_ALL_VMS]->addLabelItem(strings_[status]);
+ tabs_[TAB_RECENT_COURSES]->setEnabled(this->model_[TAB_RECENT_COURSES]->rowCount() > 1);
+ tabs_[TAB_ALL_VMS]->setEnabled(this->model_[TAB_ALL_VMS]->rowCount() > 1);
+ model_[TAB_RECENT_COURSES]->updateView();
+ model_[TAB_ALL_VMS]->updateView();
}
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);
- model_[1]->updateView();
- model_[2]->updateView();
+ this->model_[TAB_RECENT_COURSES]->removeItem(strings_[status]);
+ this->model_[TAB_ALL_VMS]->removeItem(strings_[status]);
+ tabs_[TAB_RECENT_COURSES]->setEnabled(this->model_[TAB_RECENT_COURSES]->rowCount() > 1);
+ tabs_[TAB_ALL_VMS]->setEnabled(this->model_[TAB_RECENT_COURSES]->rowCount() > 1);
+ model_[TAB_RECENT_COURSES]->updateView();
+ model_[TAB_ALL_VMS]->updateView();
}
void Dialog::on_pushButtonAbort_clicked() {
@@ -264,17 +280,24 @@ void Dialog::on_btnScreenSetup_clicked() {
QProcess::startDetached("beamergui", QStringList("-w"));
}
-bool Dialog::selectSession(const QString& name) {
+bool Dialog::selectSession(const QString& name, int preferredTab) {
QModelIndex root(ui->treeView->rootIndex());
- for (int tab = 0; tab < TAB_COUNT; ++tab) {
+ int bestTab = -1;
+ QModelIndex bestIndex;
+ for (int tab = TAB_COUNT - 1; tab >= 0; --tab) {
+ qDebug() << "bestTab:" << bestTab << "preferred:" << preferredTab << "current:" << tab;
+ if (bestTab != -1 && preferredTab != tab) // We already have a potential match, only keep going if this is the desired tab
+ continue;
+ qDebug() << "checking...";
for (int i = 0; i < model_[tab]->rowCount(root); ++i) {
QModelIndex section(model_[tab]->index(i, 0, root));
- if (!section.isValid()) {
+ qDebug() << "Section" << section << "valid:" << section.isValid();
+ if (!section.isValid())
continue;
- }
for (int j = 0; j < model_[tab]->rowCount(section); ++j) {
QModelIndex index(model_[tab]->index(j, 0, section));
+ qDebug() << "Item" << index << "valid:" << index.isValid();
if (!index.isValid())
continue;
SessionTreeItem* item = static_cast<SessionTreeItem*>(index.internalPointer());
@@ -282,59 +305,27 @@ bool Dialog::selectSession(const QString& name) {
if (s == nullptr) {
continue;
}
- if (s->shortDescription() == name) {
- // change the tab
- onTabButtonChanged(tab);
- // set selection
- ui->treeView->selectionModel()->clearSelection();
- ui->treeView->selectionModel()->clear();
- ui->treeView->selectionModel()->select(index, QItemSelectionModel::Select);
- ui->treeView->selectionModel()->setCurrentIndex(index, QItemSelectionModel::Select);
- ui->treeView->scrollTo(index);
- return true;
+ qDebug() << "Checking session" << s->shortDescription();
+ if ((!s->uuid().isEmpty() && s->uuid() == name) || s->shortDescription() == name) {
+ bestTab = tab;
+ bestIndex = index;
+ break; // Break inner, keep checking other tabs
}
}
}
}
- return false;
-}
-
-bool Dialog::selectSessionByUuid(const QString& name) {
- QModelIndex root(ui->treeView->rootIndex());
-
- for (int tab = 0; tab < TAB_COUNT; ++tab) {
- for (int i = 0; i < model_[tab]->rowCount(root); ++i) {
- QModelIndex section(model_[tab]->index(i, 0, root));
- if (!section.isValid()) {
- break;
- }
- for (int j = 0; j < model_[tab]->rowCount(section); ++j) {
- QModelIndex index(model_[tab]->index(j, 0, section));
- SessionTreeItem* item = static_cast<SessionTreeItem*>(index.internalPointer());
- const Session* s(item->session());
- if (s == nullptr) {
- continue;
- }
- /* TODO: implement this here */
- /* check if it is a vsession, then access the uuid and compare with name*/
- if (s->type() == Session::VSESSION) {
- /* cast to vsession */
- const VSession* v = static_cast<const VSession*>(s);
- if (v->uuid() == name) {
- // change the tab
- onTabButtonChanged(tab);
- // set selection
- ui->treeView->selectionModel()->clearSelection();
- ui->treeView->selectionModel()->clear();
- ui->treeView->selectionModel()->select(index, QItemSelectionModel::Select);
- ui->treeView->selectionModel()->setCurrentIndex(index, QItemSelectionModel::Select);
- ui->treeView->scrollTo(index);
- return true;
- }
- }
- }
- }
+ if (bestTab != -1) {
+ // change the tab
+ qDebug() << "Best tab is" << bestTab;
+ onTabButtonChanged(bestTab);
+ // set selection
+ ui->treeView->selectionModel()->clearSelection();
+ ui->treeView->selectionModel()->clear();
+ ui->treeView->selectionModel()->select(bestIndex, QItemSelectionModel::Select);
+ ui->treeView->selectionModel()->setCurrentIndex(bestIndex, QItemSelectionModel::Select);
+ ui->treeView->scrollTo(bestIndex);
+ return true;
}
return false;
@@ -345,24 +336,27 @@ void Dialog::selectPreviousSession() {
qDebug() << "Not selecting previous session as user interacted or session was already selected";
return;
}
+ int lastTab = UserConfig::getLastTab();
QString lastSession = Config::get(Config::DEFAULT_SESSION);
if (lastSession.isEmpty()) {
- lastSession = ChooserSettings::getSetting("last-session");
+ auto list = UserConfig::getLastSessions();
+ if (!list.isEmpty()) {
+ lastSession = list.back();
+ }
}
if (!lastSession.isEmpty()) {
qDebug() << "Trying to select last session: " << lastSession;
ui->treeView->clearSelection();
- if (selectSession(lastSession)) {
+ if (selectSession(lastSession, lastTab)) {
qDebug() << "Success";
userInteracted_ = true;
return;
}
}
// could not find last session, change to last used tab
- QString lastTab = ChooserSettings::getSetting("last-tab");
- if (!lastTab.isEmpty()) {
+ if (lastTab >= 0 && lastTab < TAB_COUNT) {
qDebug() << "Trying to select last tab " << lastTab;
- this->onTabButtonChanged(lastTab.toInt());
+ this->onTabButtonChanged(lastTab);
} else {
int defaultTab = Config::get(Config::DEFAULT_TAB).toInt();
qDebug() << "Selected default tab " << defaultTab;
@@ -561,13 +555,13 @@ void Dialog::downloadData(const QString& locationIds) {
+ infoNode.text() + "</p>"));
}
- if (ChooserSettings::getSetting("last-news").toUInt() < timestamp.toTime_t()) {
+ if (UserConfig::getLastNewsTime() < timestamp.toTime_t()) {
// show news if not seen before
on_helpNewsButton_clicked();
}
// update ini
- ChooserSettings::setSetting("last-news", QString::number(timestamp.toTime_t()));
+ UserConfig::setLastNewsTime(timestamp.toTime_t());
// make backup
QFile file(TEMP_PATH_NEWS);
@@ -713,7 +707,7 @@ void Dialog::on_tabButtonLocal_clicked() {
void Dialog::on_tabButtonMyClasses_clicked() {
userInteracted_ = true;
- onTabButtonChanged(TAB_MY_COURSES);
+ onTabButtonChanged(TAB_RECENT_COURSES);
}
void Dialog::on_tabButtonAllClasses_clicked() {
@@ -776,7 +770,7 @@ void Dialog::on_filterEdit_textChanged() {
void Dialog::setListModel(SessionTreeModel *model) {
QAbstractItemModel *old = nullptr;
- if (ui->treeView->model() == model_[0] || ui->treeView->model() == model_[1] || ui->treeView->model() == model_[2]) {
+ if (ui->treeView->model() == model_[TAB_NATIVE] || ui->treeView->model() == model_[TAB_RECENT_COURSES] || ui->treeView->model() == model_[TAB_ALL_VMS]) {
} else {
old = ui->treeView->model();
}
@@ -830,7 +824,7 @@ void Dialog::keyPressEvent(QKeyEvent* event) {
void Dialog::iconDownloaded(const QUrl& url, const QIcon&) {
qDebug() << "Icon downloaded... (" << url << ")";
// TODO: Check which model(s) contain an entry with this icon
- model_[TAB_MY_COURSES]->updateView();
+ model_[TAB_RECENT_COURSES]->updateView();
model_[TAB_ALL_VMS]->updateView();
}
@@ -903,7 +897,7 @@ bool Dialog::eventFilter(QObject*, QEvent *event) {
}
void Dialog::checkAutostart() {
if (!autoStartEntry_.isEmpty()) {
- if (this->selectSessionByUuid(autoStartEntry_) || this->selectSession(autoStartEntry_)) {
+ if (this->selectSession(autoStartEntry_)) {
this->on_treeView_doubleClicked(ui->treeView->selectionModel()->currentIndex());
} else {
QMessageBox::critical(this, "Autostart", QString::fromUtf8("Konnte %1 nicht starten.").arg(autoStartEntry_));
diff --git a/src/dialog.h b/src/dialog.h
index 0d74111..5c3af17 100644
--- a/src/dialog.h
+++ b/src/dialog.h
@@ -26,7 +26,7 @@ class Dialog : public QDialog {
static const int STR_NO_ITEMS = 2;
static const int STR__MAX = 3;
static const int TAB_NATIVE = 0;
- static const int TAB_MY_COURSES = 1;
+ static const int TAB_RECENT_COURSES = 1;
static const int TAB_ALL_VMS = 2;
static const int TAB_COUNT = 3;
@@ -36,8 +36,7 @@ class Dialog : public QDialog {
void addItems(const QList<Session*>&, int tab);
void addStatusString(const int status);
void removeStatusString(const int status);
- bool selectSession(const QString& name);
- bool selectSessionByUuid(const QString& name);
+ bool selectSession(const QString& name, int lastTab = -1);
void selectPreviousSession();
void setTheme();
void startSession(const QString& name);
diff --git a/src/globals.cpp b/src/globals.cpp
index c21598a..7780e8a 100644
--- a/src/globals.cpp
+++ b/src/globals.cpp
@@ -3,14 +3,9 @@
#include "globals.h"
#include "session.h"
-static const QString userPath(QDir::homePath() + "/.config/openslx");
-
-
const QString SESSION_START_SCRIPT(VMCHOOSER_SESSION_START_SCRIPT);
-const QString CONFIG_FILE_USER(userPath + "/vmchooser.conf");
const QString CONFIG_FILE_XSESSIONS("/opt/openslx/vmchooser/config/xsessions.conf");
-const QString PREVIOUS_SESSION_USER(userPath + "/vmchooser2.ini");
bool g_debugMode = false;
bool g_fullscreen = false;
diff --git a/src/globals.h b/src/globals.h
index 81bf2f5..3b4f344 100644
--- a/src/globals.h
+++ b/src/globals.h
@@ -24,9 +24,7 @@ extern int g_autoQuitSeconds;
// Script that is run before the xsession/vsession is started
extern const QString SESSION_START_SCRIPT;
-extern const QString CONFIG_FILE_USER;
extern const QString CONFIG_FILE_XSESSIONS;
-extern const QString PREVIOUS_SESSION_USER;
extern const QString TEMP_PATH_ICONS;
extern const QString TEMP_PATH_XML_LIST;
diff --git a/src/i18n/de.ts b/src/i18n/de.ts
index 3a9965b..e14267c 100644
--- a/src/i18n/de.ts
+++ b/src/i18n/de.ts
@@ -4,68 +4,9 @@
<context>
<name>Console</name>
<message>
- <source>vmchooser: failed to run session</source>
- <translation>vmchooser: Fehler beim Start der Sitzung</translation>
- </message>
- <message>
- <source>vmchooser: invalid session file</source>
- <translation>vmchooser: ungültige Sitzungsdatei</translation>
- </message>
- <message>
<source>vmchooser: invalid size argument</source>
<translation>Ungültige Größe</translation>
</message>
- <message>
- <source>Requested --config not found: </source>
- <translation>Gewünschte --config nicht gefunden:</translation>
- </message>
- <message>
- <source>Using user specific config: </source>
- <translation>Benutzerspezifische Konfiguration wird benutzt:</translation>
- </message>
- <message>
- <source>Using global config: </source>
- <translation>Nutze globale Konfiguration:</translation>
- </message>
- <message>
- <source>No config file found or given</source>
- <translation>Keine Konfiguration angegeben und/oder gefunden</translation>
- </message>
- <message>
- <source>Usage: vmchooser [ OPTIONS ]
-
- --allow-vm-edit show the &apos;edit this vm&apos; checkbox
- --autoquit [secs] automatically exit if no selection is made after secs seconds
- -b --base base directory where VM images are accessible
- -d, --default name of default session
- -c, --config alternative config file
- -l, --locations location id(s), space separated
- --location-mode how to treat entries for this location (IGNORE, BUMP or EXCLUSIVE)
- --exam-mode enable exam mode
- -P, --pool one or more pool names to display (comma separated)
- -f, --file direct boot .desktop file
- -x, --xpath path of X Session .desktop files
- -u, --url url of vmware .xml file
- --url-list url of vms&apos; list as .xml file
- --url-news url of the news to display
- --url-help url of the help to display
- -s, --size window size &lt;width&gt;x&lt;height&gt;
- -t, --theme theme
- --template-mode how to treat template entries (IGNORE or BUMP)
- -p, --pvs show pvs options
- --pvs-checked check pvs box by default
- -D, --debug print debug information
- -v, --version print version and exit
- -h, --help print usage information and exit
- -S, --runscript change path to run-virt.sh
- -T --tab default tab (0=xsession, 1=my vms, 2=all vms)
- --no-vtx Host doesn&apos;t support VT-x/AMD-V (mark 64bit guests)
- --start-uuid start lecture with the given uuid
-
-FILE can be a vmware .xml or an X .desktop file
-</source>
- <translation type="unfinished"></translation>
- </message>
</context>
<context>
<name>Dialog</name>
@@ -106,10 +47,6 @@ FILE can be a vmware .xml or an X .desktop file
<translation>Natives Linux</translation>
</message>
<message>
- <source>My Classes</source>
- <translation>Meine Kurse</translation>
- </message>
- <message>
<source>All Classes</source>
<translation>Alle Kurse</translation>
</message>
@@ -213,6 +150,10 @@ FILE can be a vmware .xml or an X .desktop file
<source>Disable ScreenSaver and Standby</source>
<translation>Bildschirmschoner deaktivieren</translation>
</message>
+ <message>
+ <source>Recently used</source>
+ <translation>Zuletzt verwendet</translation>
+ </message>
</context>
<context>
<name>QObject</name>
diff --git a/src/i18n/pt.ts b/src/i18n/pt.ts
index 3260fb3..22804e9 100755
--- a/src/i18n/pt.ts
+++ b/src/i18n/pt.ts
@@ -4,73 +4,7 @@
<context>
<name>Console</name>
<message>
- <location filename="../main.cpp" line="33"/>
- <source>Usage: vmchooser [ OPTIONS ]
-
- --allow-vm-edit show the &apos;edit this vm&apos; checkbox
- --autoquit [secs] automatically exit if no selection is made after secs seconds
- -b --base base directory where VM images are accessible
- -d, --default name of default session
- -c, --config alternative config file
- -l, --locations location id(s), space separated
- --location-mode how to treat entries for this location (IGNORE, BUMP or EXCLUSIVE)
- --exam-mode enable exam mode
- -P, --pool one or more pool names to display (comma separated)
- -f, --file direct boot .desktop file
- -x, --xpath path of X Session .desktop files
- -u, --url url of vmware .xml file
- --url-list url of vms&apos; list as .xml file
- --url-news url of the news to display
- --url-help url of the help to display
- -s, --size window size &lt;width&gt;x&lt;height&gt;
- -t, --theme theme
- --template-mode how to treat template entries (IGNORE or BUMP)
- -p, --pvs show pvs options
- --pvs-checked check pvs box by default
- -D, --debug print debug information
- -v, --version print version and exit
- -h, --help print usage information and exit
- -S, --runscript change path to run-virt.sh
- -T --tab default tab (0=xsession, 1=my vms, 2=all vms)
- --no-vtx Host doesn&apos;t support VT-x/AMD-V (mark 64bit guests)
- --start-uuid start lecture with the given uuid
-
-FILE can be a vmware .xml or an X .desktop file
-</source>
- <translation type="unfinished"></translation>
- </message>
- <message>
- <location filename="../main.cpp" line="91"/>
- <source>vmchooser: failed to run session</source>
- <translation>vmchooser: falhou ao executar a sessão</translation>
- </message>
- <message>
- <location filename="../main.cpp" line="97"/>
- <source>vmchooser: invalid session file</source>
- <translation>vmchooser: arquivo de sessão inválido</translation>
- </message>
- <message>
- <location filename="../main.cpp" line="117"/>
- <source>Requested --config not found: </source>
- <translation type="unfinished"></translation>
- </message>
- <message>
- <location filename="../main.cpp" line="122"/>
- <source>Using user specific config: </source>
- <translation type="unfinished"></translation>
- </message>
- <message>
- <location filename="../main.cpp" line="126"/>
- <source>Using global config: </source>
- <translation type="unfinished"></translation>
- </message>
- <message>
- <location filename="../main.cpp" line="129"/>
- <source>No config file found or given</source>
- <translation type="unfinished"></translation>
- </message>
- <message>
- <location filename="../main.cpp" line="211"/>
+ <location filename="../main.cpp" line="107"/>
<source>vmchooser: invalid size argument</source>
<translation type="unfinished"></translation>
</message>
@@ -79,7 +13,7 @@ FILE can be a vmware .xml or an X .desktop file
<name>Dialog</name>
<message>
<location filename="../ui/dialog.ui" line="14"/>
- <location filename="../dialog.cpp" line="203"/>
+ <location filename="../dialog.cpp" line="201"/>
<source>vmchooser</source>
<translation>seletor</translation>
</message>
@@ -100,7 +34,7 @@ FILE can be a vmware .xml or an X .desktop file
</message>
<message>
<location filename="../ui/dialog.ui" line="239"/>
- <source>My Classes</source>
+ <source>Recently used</source>
<translation type="unfinished"></translation>
</message>
<message>
@@ -184,22 +118,22 @@ FILE can be a vmware .xml or an X .desktop file
<translation>Iniciar</translation>
</message>
<message>
- <location filename="../dialog.cpp" line="46"/>
+ <location filename="../dialog.cpp" line="43"/>
<source>Loading...</source>
<translation type="unfinished"></translation>
</message>
<message>
- <location filename="../dialog.cpp" line="47"/>
+ <location filename="../dialog.cpp" line="44"/>
<source>URL Error</source>
<translation type="unfinished"></translation>
</message>
<message>
- <location filename="../dialog.cpp" line="48"/>
+ <location filename="../dialog.cpp" line="45"/>
<source>No Items</source>
<translation type="unfinished"></translation>
</message>
<message>
- <location filename="../dialog.cpp" line="82"/>
+ <location filename="../dialog.cpp" line="81"/>
<source>join PVS(limited)</source>
<translation type="unfinished"></translation>
</message>
@@ -209,32 +143,32 @@ FILE can be a vmware .xml or an X .desktop file
<translation type="unfinished"></translation>
</message>
<message>
- <location filename="../dialog.cpp" line="687"/>
+ <location filename="../dialog.cpp" line="694"/>
<source>Native Linux</source>
<translation type="unfinished"></translation>
</message>
<message>
- <location filename="../dialog.cpp" line="525"/>
+ <location filename="../dialog.cpp" line="529"/>
<source>Could not get news.</source>
<translation type="unfinished"></translation>
</message>
<message>
- <location filename="../dialog.cpp" line="546"/>
+ <location filename="../dialog.cpp" line="550"/>
<source>Could not get news. (//news/date or //news/info missing)</source>
<translation type="unfinished"></translation>
</message>
<message>
- <location filename="../dialog.cpp" line="596"/>
+ <location filename="../dialog.cpp" line="602"/>
<source>Could not get help.</source>
<translation type="unfinished"></translation>
</message>
<message>
- <location filename="../dialog.cpp" line="615"/>
+ <location filename="../dialog.cpp" line="621"/>
<source>Could not get help (XML has no //news/info)</source>
<translation type="unfinished"></translation>
</message>
<message>
- <location filename="../dialog.cpp" line="204"/>
+ <location filename="../dialog.cpp" line="202"/>
<source>Vmchooser failed to run the selected session!</source>
<translation>O seletor da VM falhou ao executar a sessão selecionada!</translation>
</message>
@@ -262,12 +196,12 @@ FILE can be a vmware .xml or an X .desktop file
<context>
<name>QObject</name>
<message>
- <location filename="../vsession.cpp" line="264"/>
+ <location filename="../vsession.cpp" line="258"/>
<source>Warning</source>
<translation type="unfinished"></translation>
</message>
<message>
- <location filename="../vsession.cpp" line="265"/>
+ <location filename="../vsession.cpp" line="259"/>
<source>The selected session is based on a 64 bit operating system, but this computer doesn&apos;t seem to support this (VT-x/AMD-V not supported by CPU, or disabled in BIOS). You will probably get an error message while the virtualizer is initializing.</source>
<translation type="unfinished"></translation>
</message>
diff --git a/src/main.cpp b/src/main.cpp
index e6939c2..9874f00 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -17,7 +17,6 @@
#include "dialog.h"
#include "globals.h"
#include "xsession.h"
-#include "choosersettings.h"
int main(int argc, char *argv[]) {
QApplication a(argc, argv);
diff --git a/src/ui/dialog.ui b/src/ui/dialog.ui
index e4c4e41..b6d7822 100644
--- a/src/ui/dialog.ui
+++ b/src/ui/dialog.ui
@@ -236,7 +236,7 @@ p, li { white-space: pre-wrap; }
</sizepolicy>
</property>
<property name="text">
- <string>My Classes</string>
+ <string>Recently used</string>
</property>
<property name="checkable">
<bool>true</bool>
diff --git a/src/userconfig.cpp b/src/userconfig.cpp
new file mode 100644
index 0000000..7f79015
--- /dev/null
+++ b/src/userconfig.cpp
@@ -0,0 +1,79 @@
+#include "userconfig.h"
+#include "globals.h"
+
+#include <QDebug>
+#include <QSettings>
+#include <QDir>
+
+static const QString PREVIOUS_SESSION_USER(QDir::homePath() + "/.config/openslx/vmchooser2.ini");
+static const QString KEY_LAST_SESSIONS("last-sessions");
+static const QString KEY_LAST_TAB("last-tab");
+static const QString KEY_LAST_NEWS("last-news");
+
+static QSettings *settings = nullptr;
+
+void UserConfig::init()
+{
+ if (settings != nullptr)
+ return;
+ QDir dir(QFileInfo(PREVIOUS_SESSION_USER).absoluteDir());
+ dir.mkpath(dir.path());
+ settings = new QSettings(PREVIOUS_SESSION_USER, QSettings::IniFormat);
+ if (settings->status() != QSettings::NoError) {
+ qDebug() << "Wiping old user config as it contains errors";
+ dir.remove(PREVIOUS_SESSION_USER);
+ settings->deleteLater();
+ settings = new QSettings(PREVIOUS_SESSION_USER, QSettings::IniFormat);
+ }
+ settings->setIniCodec("UTF-8");
+}
+
+void UserConfig::addLastSession(QString nameOrId)
+{
+ init();
+ auto list = getLastSessions();
+ list.removeAll(nameOrId);
+ list.push_back(nameOrId);
+ settings->setValue(KEY_LAST_SESSIONS, list);
+}
+
+QStringList UserConfig::getLastSessions()
+{
+ init();
+ auto ret = settings->value(KEY_LAST_SESSIONS).toStringList();
+ if (ret.isEmpty()) {
+ // Legacy
+ QString old = settings->value("last-session").toString();
+ if (!old.isEmpty()) {
+ ret.append(old);
+ }
+ }
+ while (ret.size() > 10) {
+ ret.pop_front();
+ }
+ return ret;
+}
+
+void UserConfig::setLastTab(int tab)
+{
+ init();
+ settings->setValue(KEY_LAST_TAB, tab);
+}
+
+int UserConfig::getLastTab()
+{
+ init();
+ return settings->value(KEY_LAST_TAB, -1).toInt();
+}
+
+void UserConfig::setLastNewsTime(uint t)
+{
+ init();
+ settings->setValue(KEY_LAST_NEWS, t);
+}
+
+uint UserConfig::getLastNewsTime()
+{
+ init();
+ return settings->value(KEY_LAST_NEWS).toUInt();
+}
diff --git a/src/userconfig.h b/src/userconfig.h
new file mode 100644
index 0000000..7f27e1b
--- /dev/null
+++ b/src/userconfig.h
@@ -0,0 +1,21 @@
+#ifndef _USERCONFIG_H_
+#define _USERCONFIG_H_
+
+#include <QString>
+#include <QSet>
+
+class UserConfig {
+public:
+ static QStringList getLastSessions();
+ static int getLastTab();
+ static uint getLastNewsTime();
+ static void addLastSession(QString nameOrId);
+ static void setLastTab(int tab);
+ static void setLastNewsTime(uint t);
+
+private:
+ UserConfig() {}
+ static void init();
+};
+
+#endif /* _USERCONFIG_H_ */