From 0d3c7962a42fa9dbd7c563658da430531eec8e8d Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Thu, 4 Dec 2014 16:07:23 +0100 Subject: Minor fixes --- src/dialog.cpp | 128 ++++++++++++++++++++++++++++----------------------------- 1 file changed, 62 insertions(+), 66 deletions(-) (limited to 'src/dialog.cpp') diff --git a/src/dialog.cpp b/src/dialog.cpp index 490dd9b..6104e22 100644 --- a/src/dialog.cpp +++ b/src/dialog.cpp @@ -57,7 +57,7 @@ Dialog::Dialog(QWidget *parent) * TODO: why connect signal/slot when no item was loaded yet? QObject::connect(ui->treeView->selectionModel(), SIGNAL(currentChanged ( const QModelIndex&, const QModelIndex&)), this, SLOT(treeView_selectionChanged(const QModelIndex&, const QModelIndex&))); - */ + */ this->onTabButtonChanged(2); @@ -85,65 +85,61 @@ void Dialog::changeEvent(QEvent *e) { void Dialog::on_treeView_activated(QModelIndex index) { - // this method gets called when a Session has been activated - - SessionTreeItem* item = - static_cast(index.internalPointer()); - - const Session* s(item->session()); - if (!s) { - // no valid session has been selected, do nothing - return; - } - - if (s->run()) - { - // Run session start script - if (QFile::exists(sessionStartScript)) - { - // Use the current environment variables and add the necessary - // information for the startUpScipt. - char pvs_ac[128]; - sprintf(pvs_ac, "PVS_AUTO_CONNECT=%s", ui->PVS_checkbox->isChecked()?"TRUE":"FALSE"); - putenv(pvs_ac); - - // Fork this process twice to detach - pid_t pid = fork(); - if (pid == 0){ - - // Close all filedescriptors - for (int i = 3; i < 1024; ++i) ::close(i); - - // Change process group - pid_t sid = setsid(); - if (sid < 0) - exit(EXIT_FAILURE); - - // Reopen standard pipes - freopen("/dev/null", "r", stdin); - freopen("/dev/null", "w", stdout); - freopen("/dev/null", "w", stdout); - - pid = fork(); - if (pid == 0){ - // At this point we are executing as the 2nd child process - // Replace this clone with the process we'd like to start - char const * const args[] = {VMCHOOSER_SESSION_START_SCRIPT, NULL}; - execv(VMCHOOSER_SESSION_START_SCRIPT, (char**)args); - } - _exit(0); // Dont use exit hooks - } - // Wait and cleanup the intermediate process - waitpid(pid, NULL, 0); - } - ChooserSettings::setSetting("last-session", (s->shortDescription())); - ChooserSettings::setSetting("last-tab", QString::number(activeTab_)); - setVisible(false); - } else { - QMessageBox::warning( - this, trUtf8("vmchooser"), - trUtf8("Vmchooser failed to run the selected session!")); - } + // this method gets called when a Session has been activated + + SessionTreeItem* item = + static_cast(index.internalPointer()); + + const Session* s(item->session()); + if (s == NULL) // no valid session has been selected, do nothing + return; + + if (s->run()) { + // Run session start script + if (QFile::exists(sessionStartScript)) { + // Use the current environment variables and add the necessary + // information for the startUpScipt. + if (ui->PVS_checkbox->isChecked()) + setenv("PVS_AUTO_CONNECT", "TRUE", 1); + else + setenv("PVS_AUTO_CONNECT", "FALSE", 1); + + // Fork this process twice to detach + pid_t pid = fork(); + if (pid == 0) { + + // Close all filedescriptors + for (int i = 3; i < 1024; ++i) + ::close(i); + + // Change process group + setsid(); + + // Reopen standard pipes + freopen("/dev/null", "r", stdin); + freopen("/dev/null", "w", stdout); + freopen("/dev/null", "w", stderr); + + pid = fork(); + if (pid == 0) { + // At this point we are executing as the 2nd child process + // Replace this clone with the process we'd like to start + char const * const args[] = {VMCHOOSER_SESSION_START_SCRIPT, NULL}; + execv(VMCHOOSER_SESSION_START_SCRIPT, (char**)args); + } + _exit(0); // Dont use exit hooks + } + // Wait and cleanup the intermediate process + waitpid(pid, NULL, 0); + } + ChooserSettings::setSetting("last-session", (s->shortDescription())); + ChooserSettings::setSetting("last-tab", QString::number(activeTab_)); + setVisible(false); + } else { + QMessageBox::warning( + this, trUtf8("vmchooser"), + trUtf8("Vmchooser failed to run the selected session!")); + } } void Dialog::addItems(const QList& entries, int tab) { @@ -159,8 +155,8 @@ void Dialog::addItems(const QList& entries, int tab) { } void Dialog::addStatusString(const int status) { - if (status < 0 || status >= STR__MAX) - return; + 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); @@ -170,8 +166,8 @@ void Dialog::addStatusString(const int status) { } void Dialog::removeStatusString(const int status) { - if (status < 0 || status >= STR__MAX) - return; + 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); @@ -405,7 +401,7 @@ void Dialog::onTabButtonChanged(int tab) { // Update pressed status of buttons for (int i = 0; i < 3; ++i) { - tabs_[i]->setChecked(tab == i); + tabs_[i]->setChecked(tab == i); } // clear filter if necessary @@ -414,7 +410,7 @@ void Dialog::onTabButtonChanged(int tab) { } // save old row - //oldRow_ = ui->treeView->selectionModel()->currentIndex().row(); + //oldRow_ = ui->treeView->selectionModel()->currentIndex().row(); // load the new list setListModel(model_[tab]); -- cgit v1.2.3-55-g7522