From b796bbc803613c3061b08b6c3c2a9883724f4684 Mon Sep 17 00:00:00 2001 From: Johann Latocha Date: Tue, 1 Mar 2011 23:03:20 +0100 Subject: 1) cmd-switch to use a window manager 2) openslx logo added --- default.desktop | 2 +- src/command_line_options.cpp | 6 +++++- src/dialog.cpp | 23 +++++++++++++++++++++-- src/dialog.h | 3 ++- src/images.qrc | 1 + src/img/openslx-logo.png | Bin 0 -> 17520 bytes src/main.cpp | 32 ++++++++++++++++++++++++-------- src/session.h | 5 +++++ src/ui/dialog.ui | 18 +++++++++++++++--- src/vsession.cpp | 4 ++++ src/vsession.h | 2 ++ src/xsession.cpp | 4 ++++ src/xsession.h | 2 ++ 13 files changed, 86 insertions(+), 16 deletions(-) create mode 100644 src/img/openslx-logo.png diff --git a/default.desktop b/default.desktop index ab2c948..5fc208e 100644 --- a/default.desktop +++ b/default.desktop @@ -1,7 +1,7 @@ [Desktop Entry] Name=RZ VMChooser Comment=This session logs you into VMChooser -Exec=vmchooser +Exec=vmchooser --windowmgr openbox TryExec=vmchooser Icon= Type=Applicatio \ No newline at end of file diff --git a/src/command_line_options.cpp b/src/command_line_options.cpp index 61eb3ad..532612d 100644 --- a/src/command_line_options.cpp +++ b/src/command_line_options.cpp @@ -12,11 +12,12 @@ CommandLineOptions::CommandLineOptions(int argc, char * const argv[]) { {"xpath", required_argument, NULL, 'x'}, {"size", required_argument, NULL, 's'}, {"version", no_argument, NULL, 'v'}, + {"windowmgr", required_argument, NULL, 'w' }, {"help", no_argument, NULL, 'h'}, {0, 0, 0, 0} }; - int opt = getopt_long(argc, argv, "c:d:P:p:x:s:vhb", longOptions, NULL); + int opt = getopt_long(argc, argv, "c:d:P:p:x:s:w:vhb", longOptions, NULL); if (opt == -1) break; switch (opt) { @@ -41,6 +42,9 @@ CommandLineOptions::CommandLineOptions(int argc, char * const argv[]) { case 'v': options.insert("version", "version"); break; + case 'w': + options.insert("windowmgr", optarg); + break; case 'h': options.insert("usage", "usage"); break; diff --git a/src/dialog.cpp b/src/dialog.cpp index 0e888cb..f2765ac 100644 --- a/src/dialog.cpp +++ b/src/dialog.cpp @@ -6,11 +6,21 @@ #include "save_restore_session.h" #include "sessiontreeitem.h" -Dialog::Dialog(QWidget *parent) +Dialog::Dialog(QString windowmgr, QWidget *parent) : QDialog(parent), ui(new Ui::Dialog) { model_ = new SessionTreeModel(parent); ui->setupUi(this); + windowmgr_ = new QProcess(this); + // start window manager + if (windowmgr != "") { + windowmgr_->start(windowmgr); + windowmgr_->waitForStarted(3000); + if (windowmgr_->error() == QProcess::FailedToStart) + QMessageBox::warning(this, tr("Warning"), + tr("Window manager '") + windowmgr + tr("' couldn't be started!")); + } + QDBusConnection dbus = QDBusConnection::sessionBus(); ifaceDBus_ = new OrgOpenslxPvsInterface("org.openslx.pvs", "/", dbus, this); @@ -33,6 +43,8 @@ Dialog::~Dialog() { delete ui; delete model_; delete ifaceDBus_; + windowmgr_->terminate(); + windowmgr_->waitForFinished(3000); } void Dialog::changeEvent(QEvent *e) { @@ -58,12 +70,19 @@ void Dialog::on_treeView_activated(QModelIndex index) { return; } + setVisible(false); + if (s->type() == Session::XSESSION) { + windowmgr_->terminate(); + windowmgr_->waitForFinished(3000); + windowmgr_->kill(); + } + if (s->run()) { if (ifaceDBus_->isValid()) { writePVSSettings(); } writeSessionName(s->shortDescription()); - setVisible(false); + } else { QMessageBox::warning( this, trUtf8("vmchooser"), diff --git a/src/dialog.h b/src/dialog.h index 1b2e7c9..ed1b49c 100644 --- a/src/dialog.h +++ b/src/dialog.h @@ -15,7 +15,7 @@ namespace Ui { class Dialog : public QDialog { Q_OBJECT public: - explicit Dialog(QWidget *parent = 0); + explicit Dialog(QString windowmgr = "", QWidget *parent = 0); ~Dialog(); void addItems(const QList&, const QString& section); void selectSession(const QString& name); @@ -28,6 +28,7 @@ class Dialog : public QDialog { Ui::Dialog *ui; SessionTreeModel *model_; OrgOpenslxPvsInterface *ifaceDBus_; + QProcess *windowmgr_; void readPVSSettings(); void writePVSSettings(); diff --git a/src/images.qrc b/src/images.qrc index 2f9e0e3..4226952 100644 --- a/src/images.qrc +++ b/src/images.qrc @@ -16,5 +16,6 @@ img/xfce.png img/windows.png img/vmware.png + img/openslx-logo.png diff --git a/src/img/openslx-logo.png b/src/img/openslx-logo.png new file mode 100644 index 0000000..7e40912 Binary files /dev/null and b/src/img/openslx-logo.png differ diff --git a/src/main.cpp b/src/main.cpp index faef051..83525a6 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -4,6 +4,7 @@ #include #include #include +#include #include #include @@ -32,13 +33,14 @@ int main(int argc, char *argv[]) { std::string usage(a.translate( "Console", "Usage: vmchooser [ OPTIONS | FILE ]\n\n" - " -d, --default name of default session\n" - " -P, --pool name of the environment\n" - " -p, --path path to vmware .xml files\n" - " -x, --xpath path of X Session .desktop files\n" - " -s, --size window size x\n" - " -v, --version print version and exit\n" - " -h, --help print usage information and exit\n" + " -d, --default name of default session\n" + " -P, --pool name of the environment\n" + " -p, --path path to vmware .xml files\n" + " -x, --xpath path of X Session .desktop files\n" + " -s, --size window size x\n" + " -w, --windowmgr use window manager\n" + " -v, --version print version and exit\n" + " -h, --help print usage information and exit\n" "\nFILE can be a vmware .xml or an X .desktop file\n") .toUtf8().data()); @@ -90,6 +92,13 @@ int main(int argc, char *argv[]) { } } + // TODO: parse args => command_line_options.cpp + QString windowmgr; + if (cmdOptions.contains("windowmgr")) { + windowmgr = cmdOptions.value("windowmgr"); + } + + // read configuration file: // file supplied as command line option or // user vmchooser.conf or @@ -162,7 +171,7 @@ int main(int argc, char *argv[]) { QList xsessions(XSession::readSessions(xSessionPath)); QList vsessions(VSession::readXmlDir(vSessionPath)); - Dialog w; + Dialog w(windowmgr); w.resize(width, height); if (xsessions.empty() && vsessions.empty()) { std::cerr << a.translate( @@ -189,5 +198,12 @@ int main(int argc, char *argv[]) { } w.selectSession(defaultSession); w.show(); + + // center dialog on screen + QRect desktopRect = QApplication::desktop()->availableGeometry(&w); + QPoint center = desktopRect.center(); + w.move(center.x()-w.width()*0.5, center.y()-w.height()*0.5); + a.setActiveWindow(&w); + return a.exec(); } diff --git a/src/session.h b/src/session.h index 2033ba7..b031991 100644 --- a/src/session.h +++ b/src/session.h @@ -14,7 +14,12 @@ class Session { virtual QString description() const = 0; virtual QString icon() const = 0; virtual bool run() const = 0; + virtual int type() const = 0; virtual bool operator<(const Session& s) const = 0; + + const static int XSESSION = 0; + const static int VSESSION = 1; + }; #endif /*VMCHOOSER_SESSION_H_*/ diff --git a/src/ui/dialog.ui b/src/ui/dialog.ui index 9ff6728..93190a8 100644 --- a/src/ui/dialog.ui +++ b/src/ui/dialog.ui @@ -6,14 +6,24 @@ 0 0 - 600 - 400 + 784 + 655 vmchooser + + + + + + + :/openslx + + + @@ -165,6 +175,8 @@ - + + + diff --git a/src/vsession.cpp b/src/vsession.cpp index 16a8a97..05e5159 100644 --- a/src/vsession.cpp +++ b/src/vsession.cpp @@ -284,6 +284,10 @@ bool VSession::run() const { return false; } +int VSession::type() const { + return Session::VSESSION; +} + QList VSession::readXmlFile(const QString& filepath) { QList retval; diff --git a/src/vsession.h b/src/vsession.h index 99e8e20..496e0a2 100644 --- a/src/vsession.h +++ b/src/vsession.h @@ -53,6 +53,8 @@ class VSession : public Session { bool run() const; + int type() const; + bool operator<(const Session& other) const; static QList readXmlDir(const QString& path); diff --git a/src/xsession.cpp b/src/xsession.cpp index 37fad17..8c32df5 100644 --- a/src/xsession.cpp +++ b/src/xsession.cpp @@ -109,6 +109,10 @@ bool XSession::run() const { return false; } +int XSession::type() const { + return Session::XSESSION; +} + QList XSession::readSessions(const QString& path) { QList retval; foreach (QFileInfo fi, QDir(path).entryInfoList(QStringList("*.desktop"))) { diff --git a/src/xsession.h b/src/xsession.h index dbdacf1..2e95a63 100644 --- a/src/xsession.h +++ b/src/xsession.h @@ -29,6 +29,8 @@ class XSession : public Session { bool run() const; + int type() const; + bool operator<(const Session& other) const; static QList readSessions(const QString& path); -- cgit v1.2.3-55-g7522