diff options
author | Christian Klinger | 2016-08-03 10:33:38 +0200 |
---|---|---|
committer | Christian Klinger | 2016-08-03 10:33:38 +0200 |
commit | 2448ecd6b87c24fe1203b80a014432ae816a9e9f (patch) | |
tree | 32b0e992175e59d711232bf8efe1f2dd6659ee1c | |
parent | Parse XML reply for help text (just like news) (diff) | |
download | vmchooser2-2448ecd6b87c24fe1203b80a014432ae816a9e9f.tar.gz vmchooser2-2448ecd6b87c24fe1203b80a014432ae816a9e9f.tar.xz vmchooser2-2448ecd6b87c24fe1203b80a014432ae816a9e9f.zip |
added --start-uuid parameter.
-rw-r--r-- | src/command_line_options.cpp | 5 | ||||
-rw-r--r-- | src/dialog.cpp | 42 | ||||
-rw-r--r-- | src/dialog.h | 1 | ||||
-rw-r--r-- | src/main.cpp | 14 | ||||
-rw-r--r-- | src/vsession.h | 4 |
5 files changed, 65 insertions, 1 deletions
diff --git a/src/command_line_options.cpp b/src/command_line_options.cpp index 4f1b4f6..bb894ce 100644 --- a/src/command_line_options.cpp +++ b/src/command_line_options.cpp @@ -2,6 +2,7 @@ #include <getopt.h> #include <QDebug> + CommandLineOptions::CommandLineOptions(int argc, char * const argv[]) { // parse command line arguments (please sort by short option for easier handling) static const struct option longOptions[] = { @@ -25,6 +26,7 @@ CommandLineOptions::CommandLineOptions(int argc, char * const argv[]) { {"xpath", required_argument, NULL, 'x'}, {"location-mode", required_argument, NULL, 'locm'}, {"template-mode", required_argument, NULL, 'tmpm'}, + {"start-uuid", required_argument, NULL, 'uuid'}, {"no-vtx", no_argument, NULL, 'nvtx'}, {0, 0, 0, 0} }; @@ -95,6 +97,9 @@ CommandLineOptions::CommandLineOptions(int argc, char * const argv[]) { case 'nvtx': options.insert("no-vtx", "no-vtx"); break; + case 'uuid': + options.insert("uuid", optarg); + break; default: options.insert("error", "error"); break; diff --git a/src/dialog.cpp b/src/dialog.cpp index aefb6f9..87eae8e 100644 --- a/src/dialog.cpp +++ b/src/dialog.cpp @@ -250,6 +250,46 @@ bool Dialog::selectSession(const QString& name) { 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 == NULL) { + 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; + } + } + } + } + } + + return false; +} + void Dialog::selectPreviousSession() { if (userInteracted_) { qDebug() << "Not selecting previous session as user interacted or session was already selected"; @@ -315,7 +355,7 @@ void Dialog::setTheme() { void Dialog::onCenterTimer() { if (!autoStartEntry_.isEmpty()) { - if (this->selectSession(autoStartEntry_)) { + if (this->selectSessionByUuid(autoStartEntry_) || 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 a170d31..a8d08ac 100644 --- a/src/dialog.h +++ b/src/dialog.h @@ -36,6 +36,7 @@ class Dialog : public QDialog { void addStatusString(const int status); void removeStatusString(const int status); bool selectSession(const QString& name); + bool selectSessionByUuid(const QString& name); void selectPreviousSession(); void setTheme(); void startSession(const QString& name); diff --git a/src/main.cpp b/src/main.cpp index 7dfdfc7..1afd052 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -30,6 +30,8 @@ int main(int argc, char *argv[]) { CommandLineOptions cmdOptions(argc, argv); + QString autostart_uuid(""); + std::string usage( a.translate("Console", "Usage: vmchooser [ OPTIONS ]\n\n" " -b --base base directory where VM images are accessible\n" @@ -51,6 +53,7 @@ int main(int argc, char *argv[]) { " -S, --runscript change path to run-virt.sh\n" " -T --tab default tab (0=xsession, 1=my vms, 2=all vms)\n" " --no-vtx Host doesn't support VT-x/AMD-V (mark 64bit guests)\n" + " --start-uuid start lecture with the given uuid\n" "\nFILE can be a vmware .xml or an X .desktop file\n").toUtf8().data()); if (cmdOptions.contains("error")) { @@ -68,6 +71,10 @@ int main(int argc, char *argv[]) { return EXIT_SUCCESS; } + if (cmdOptions.contains("uuid")) { + autostart_uuid = cmdOptions.value("uuid"); + } + if (cmdOptions.contains("file")) { QString file(cmdOptions.value("file")); @@ -298,6 +305,13 @@ int main(int argc, char *argv[]) { } w.show(); + if (autostart_uuid != "") { + qDebug() << "using startSession() from main.cpp"; + w.startSession(autostart_uuid); + } + + + // center dialog on primary screen QPoint center = desktopRect.center(); w.move(center.x() - w.width() * 0.5, center.y() - w.height() * 0.5); diff --git a/src/vsession.h b/src/vsession.h index f20b111..4fda2e1 100644 --- a/src/vsession.h +++ b/src/vsession.h @@ -49,6 +49,10 @@ class VSession : public Session { return getAttribute("os"); } + QString uuid() const { + return getAttribute("uuid"); + } + SectionType section() const { if (g_forLocationHandling != LOCATION_IGNORE && isForLocation()) { return SECTION_FOR_LOCATION; |