summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/config.cpp1
-rw-r--r--src/config.h1
-rw-r--r--src/dialog.cpp28
3 files changed, 26 insertions, 4 deletions
diff --git a/src/config.cpp b/src/config.cpp
index 0d4a72d..ca83bfc 100644
--- a/src/config.cpp
+++ b/src/config.cpp
@@ -56,6 +56,7 @@ const ConfigOption* const Config::PVS_CHECKED = new ConfigOption("", "pvs-checke
const ConfigOption* const Config::RUNSCRIPT = new ConfigOption("S", "runscript", "runscript", "path", RUN_VIRT_PATH, "Path to run-virt script");
const ConfigOption* const Config::WINDOW_SIZE = new ConfigOption("s", "size", "size", "WxH", "640x480", "Size of window if not using fullscreen");
const ConfigOption* const Config::DEFAULT_TAB = new ConfigOption("T", "tab", "tab", "tabno", "2", "Default tab to show, first tab being 0");
+const ConfigOption* const Config::FORCE_DEFAULT_TAB = new ConfigOption("", "force-tab", "force-tab", "", "", "Force the default tab to be shown, even if saved session is available");
const ConfigOption* const Config::THEME = new ConfigOption("t", "theme", "theme", "name", "", "Name of theme to load");
const ConfigOption* const Config::URL_BASE = new ConfigOption("u", "url", "url", "url", "", "Base URL path to fetch resources from");
const ConfigOption* const Config::URL_LIST = new ConfigOption("", "url-list", "url-list", "url", "", "Use this URL for the VM list instead of <urlbase>/list");
diff --git a/src/config.h b/src/config.h
index 011e82a..a1eecec 100644
--- a/src/config.h
+++ b/src/config.h
@@ -24,6 +24,7 @@ public:
static const ConfigOption* const RUNSCRIPT;
static const ConfigOption* const WINDOW_SIZE;
static const ConfigOption* const DEFAULT_TAB;
+ static const ConfigOption* const FORCE_DEFAULT_TAB;
static const ConfigOption* const THEME;
static const ConfigOption* const URL_BASE;
static const ConfigOption* const URL_LIST;
diff --git a/src/dialog.cpp b/src/dialog.cpp
index 94b271c..8acaa9d 100644
--- a/src/dialog.cpp
+++ b/src/dialog.cpp
@@ -289,10 +289,11 @@ bool Dialog::selectSession(const QString& name, int preferredTab) {
QModelIndex root(ui->treeView->rootIndex());
int bestTab = -1;
+ int matchLevel = 0;
+ int boost;
QModelIndex bestIndex;
for (int tab = TAB_COUNT - 1; tab >= 0; --tab) {
- if (bestTab != -1 && preferredTab != tab) // We already have a potential match, only keep going if this is the desired tab
- continue;
+ boost = (tab == preferredTab);
for (int i = 0; i < model_[tab]->rowCount(root); ++i) {
QModelIndex section(model_[tab]->index(i, 0, root));
if (!section.isValid())
@@ -309,8 +310,19 @@ bool Dialog::selectSession(const QString& name, int preferredTab) {
if ((!s->uuid().isEmpty() && s->uuid() == name) || s->shortDescription() == name) {
bestTab = tab;
bestIndex = index;
+ matchLevel = 5 + boost;
break; // Break inner, keep checking other tabs
}
+ if (matchLevel < 3 + boost && s->shortDescription().startsWith(name)) {
+ bestTab = tab;
+ bestIndex = index;
+ matchLevel = 3 + boost;
+ }
+ if (matchLevel < 1 + boost && name.length() > 3 && s->shortDescription().contains(name)) {
+ bestTab = tab;
+ bestIndex = index;
+ matchLevel = 1 + boost;
+ }
}
}
}
@@ -337,8 +349,16 @@ void Dialog::selectPreviousSession() {
return;
}
int lastTab = UserConfig::getLastTab();
+
+ if (Config::isSet(Config::FORCE_DEFAULT_TAB)) {
+ // Force specific tab preselect
+ lastTab = Config::get(Config::DEFAULT_TAB).toInt();
+ }
+
+ // Command line default session takes precedence
QString lastSession = Config::get(Config::DEFAULT_SESSION);
- if (lastSession.isEmpty()) {
+ if (lastSession.isEmpty() && !Config::isSet(Config::FORCE_DEFAULT_TAB)) {
+ // If no cmdline, use user's last session if we don't force a tab via cmdline
auto list = UserConfig::getLastSessions();
if (!list.isEmpty()) {
lastSession = list.back();
@@ -357,7 +377,7 @@ void Dialog::selectPreviousSession() {
if (lastTab >= 0 && lastTab < TAB_COUNT) {
qDebug() << "Trying to select last tab " << lastTab;
this->onTabButtonChanged(lastTab);
- } else {
+ } else if (Config::isSet(Config::DEFAULT_TAB)) {
int defaultTab = Config::get(Config::DEFAULT_TAB).toInt();
qDebug() << "Selected default tab " << defaultTab;
// Select default tab