summaryrefslogtreecommitdiffstats
path: root/src/dialog.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/dialog.cpp')
-rw-r--r--src/dialog.cpp60
1 files changed, 38 insertions, 22 deletions
diff --git a/src/dialog.cpp b/src/dialog.cpp
index bdeab16..aea2d6e 100644
--- a/src/dialog.cpp
+++ b/src/dialog.cpp
@@ -170,35 +170,31 @@ void Dialog::on_treeView_doubleClicked(const QModelIndex& index)
UserConfig::setNewsHelpOpen(!ui->helpBox->isHidden());
UserConfig::sync();
- QProcess *process = nullptr;
+ qint64 scriptPid = 0;
if (QFile::exists(SESSION_START_SCRIPT)) {
// Companion script
- process = new QProcess;
- QProcessEnvironment env = QProcessEnvironment::systemEnvironment();
- env.insert("SESSION_NAME", s->shortDescription());
- env.insert("SESSION_UUID", s->uuid());
- env.insert("SESSION_CMD", s->execCommand());
+ setenv("SESSION_NAME", s->shortDescription().toLocal8Bit().constData(), 1);
+ setenv("SESSION_UUID", s->uuid().toLocal8Bit().constData(), 1);
+ setenv("SESSION_CMD", s->execCommand().toLocal8Bit().constData(), 1);
if (s->type() == Session::VSESSION) {
- env.insert("SESSION_TYPE", "VSESSION");
+ setenv("SESSION_TYPE", "VSESSION", 1);
} else if (s->type() == Session::XSESSION) {
- env.insert("SESSION_TYPE", "XSESSION");
+ setenv("SESSION_TYPE", "XSESSION", 1);
+ }
+ if (!QProcess::startDetached(SESSION_START_SCRIPT, QStringList(), QStringLiteral("/"), &scriptPid)) {
+ scriptPid = 0;
}
- process->setProcessEnvironment(env);
- process->start(SESSION_START_SCRIPT);
- process->closeReadChannel(QProcess::StandardError);
- process->closeReadChannel(QProcess::StandardOutput);
- process->closeWriteChannel();
}
// Run session
s->run();
// Should not return on success
- if (process != nullptr) {
- process->terminate();
+ if (scriptPid > 0) {
+ ::kill(pid_t(scriptPid), SIGTERM);
}
QMessageBox::critical(
- this, trUtf8("vmchooser"),
- trUtf8("Vmchooser failed to run the selected session!"));
+ this, tr("vmchooser"),
+ tr("Vmchooser failed to run the selected session!"));
QApplication::instance()->quit();
}
@@ -293,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())
@@ -313,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;
+ }
}
}
}
@@ -341,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();
@@ -361,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
@@ -430,7 +446,7 @@ void Dialog::onCenterTimer() {
if (autoQuit_ == 0) {
QCoreApplication::instance()->exit(0);
} else if (autoQuit_ < 60) {
- ui->lblAutoQuit->setText(trUtf8("Auto logout in %1").arg(autoQuit_));
+ ui->lblAutoQuit->setText(tr("Auto logout in %1").arg(autoQuit_));
ui->lblAutoQuit->show();
} else if (!ui->lblAutoQuit->isHidden()) {
ui->lblAutoQuit->hide();