summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJohann Latocha2011-03-01 23:03:20 +0100
committerJohann Latocha2011-03-01 23:03:20 +0100
commitb796bbc803613c3061b08b6c3c2a9883724f4684 (patch)
tree210892cb3ab8791b019000d4383de8f351edd841 /src
parent[Fix] Startup problems with xsession (Quick&Dirty) (diff)
downloadvmchooser-b796bbc803613c3061b08b6c3c2a9883724f4684.tar.gz
vmchooser-b796bbc803613c3061b08b6c3c2a9883724f4684.tar.xz
vmchooser-b796bbc803613c3061b08b6c3c2a9883724f4684.zip
1) cmd-switch to use a window manager
2) openslx logo added
Diffstat (limited to 'src')
-rw-r--r--src/command_line_options.cpp6
-rw-r--r--src/dialog.cpp23
-rw-r--r--src/dialog.h3
-rw-r--r--src/images.qrc1
-rw-r--r--src/img/openslx-logo.pngbin0 -> 17520 bytes
-rw-r--r--src/main.cpp32
-rw-r--r--src/session.h5
-rw-r--r--src/ui/dialog.ui18
-rw-r--r--src/vsession.cpp4
-rw-r--r--src/vsession.h2
-rw-r--r--src/xsession.cpp4
-rw-r--r--src/xsession.h2
12 files changed, 85 insertions, 15 deletions
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<Session*>&, 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 @@
<file alias="xfce">img/xfce.png</file>
<file alias="windows">img/windows.png</file>
<file alias="vmware">img/vmware.png</file>
+ <file alias="openslx">img/openslx-logo.png</file>
</qresource>
</RCC>
diff --git a/src/img/openslx-logo.png b/src/img/openslx-logo.png
new file mode 100644
index 0000000..7e40912
--- /dev/null
+++ b/src/img/openslx-logo.png
Binary files 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 <QTranslator>
#include <QtAlgorithms>
#include <QtGui/QApplication>
+#include <QDesktopWidget>
#include <cstdlib>
#include <iostream>
@@ -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 <width>x<height>\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 <width>x<height>\n"
+ " -w, --windowmgr use <command> 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<Session*> xsessions(XSession::readSessions(xSessionPath));
QList<Session*> 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,8 +6,8 @@
<rect>
<x>0</x>
<y>0</y>
- <width>600</width>
- <height>400</height>
+ <width>784</width>
+ <height>655</height>
</rect>
</property>
<property name="windowTitle">
@@ -15,6 +15,16 @@
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
+ <widget class="QLabel" name="label">
+ <property name="text">
+ <string/>
+ </property>
+ <property name="pixmap">
+ <pixmap resource="../images.qrc">:/openslx</pixmap>
+ </property>
+ </widget>
+ </item>
+ <item>
<widget class="QTreeView" name="treeView">
<property name="iconSize">
<size>
@@ -165,6 +175,8 @@
</layout>
</widget>
<layoutdefault spacing="6" margin="11"/>
- <resources/>
+ <resources>
+ <include location="../images.qrc"/>
+ </resources>
<connections/>
</ui>
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<Session*> VSession::readXmlFile(const QString& filepath) {
QList<Session*> 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<Session*> 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<Session*> XSession::readSessions(const QString& path) {
QList<Session*> 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<Session*> readSessions(const QString& path);