summaryrefslogtreecommitdiffstats
path: root/src/xsession.cpp
diff options
context:
space:
mode:
authorJan Darmochwal2010-10-02 18:50:09 +0200
committerJan Darmochwal2010-10-02 18:50:09 +0200
commit6117049617df720fb744a90773a3580b3450b005 (patch)
treec3b605ab7a7c2e9fd9d14572e8c0e69432d6ac76 /src/xsession.cpp
parentfixed bad copy & paste in CMakeLists.txt (diff)
downloadvmchooser-6117049617df720fb744a90773a3580b3450b005.tar.gz
vmchooser-6117049617df720fb744a90773a3580b3450b005.tar.xz
vmchooser-6117049617df720fb744a90773a3580b3450b005.zip
Qt port is almost complete (at least it compiles)
Major change: * struct DataEntry has become class Session with sub-classes XSession and VSession * functions from addInfo.cpp, addPrinters.cpp, addScanners.cpp, readLinSess.cpp, readXmlDir.cpp, runImage.cpp have been moved to XSession and VSession Several minor changes: * new files globals.h and globals.cpp for global variables (replaces constants.h and paths.h) * replaced (all) libxml2, (much) std:: and (most) boost:: stuff by Qt stuff Things left to do: * remove tons of debug printfs * show error messages on errors * tidy up anyoption stuff in main() * highlight session run previously * readGroupXml stuff * tree view (with "X Sessions" and "Virtual Sessions" sections) instead of list view for session selection
Diffstat (limited to 'src/xsession.cpp')
-rw-r--r--src/xsession.cpp135
1 files changed, 135 insertions, 0 deletions
diff --git a/src/xsession.cpp b/src/xsession.cpp
new file mode 100644
index 0000000..2c1ed57
--- /dev/null
+++ b/src/xsession.cpp
@@ -0,0 +1,135 @@
+#include <QDir>
+#include <QSettings>
+#include <QLocale>
+#include <QApplication>
+#include <QProcess>
+
+#include "xsession.h"
+
+// TODO: void instead of bool? (or return something useful)
+bool XSession::init(const QString& name, const QString& exec,
+ const QString& comment, const QString& icon) {
+ printf("XSession::init()\n");
+ this->name_ = name;
+ this->exec_ = exec;
+ this->comment_ = comment;
+ this->icon_ = icon;
+}
+
+bool XSession::isActive() const {
+ return true;
+}
+
+bool XSession::isLocked() const {
+ return false;
+}
+
+int XSession::priority() const {
+ return 0;
+}
+
+QString XSession::icon() const {
+ QString icon(this->icon_);
+
+ if(icon.isEmpty()) {
+ if (this->name_.contains("kde", Qt::CaseInsensitive)) {
+ icon = "kde";
+ } else if (this->name_.contains("gnome", Qt::CaseInsensitive)) {
+ icon = "gnome";
+ } else if (this->name_.contains("xfce", Qt::CaseInsensitive)) {
+ icon = "xfce";
+ } else {
+ icon = "linux";
+ }
+ }
+
+ return icon;
+}
+
+bool XSession::run() {
+ return QProcess::startDetached(this->exec_);
+}
+
+QList<Session*> XSession::readSessions(const QString& path) {
+ printf("XSession::readSessions(%s)\n", path.toAscii().data());
+ QList<Session*> retval;
+ foreach (QFileInfo fi, QDir(path).entryInfoList(QStringList("*.desktop"))) {
+ printf(" reading %s\n", fi.absoluteFilePath().toAscii().data());
+ if (fi.baseName().compare("default.desktop") == 0) {
+ continue;
+ }
+
+ QSettings settings(fi.absoluteFilePath(), QSettings::IniFormat);
+ settings.setIniCodec("UTF-8");
+
+ settings.beginGroup("Desktop Entry");
+ printf(" keys: %s\n", settings.allKeys().join(",").toAscii().data());
+
+ if (settings.value("NoDisplay").toString().compare("true") == 0 ||
+ settings.value("Hidden").toString().compare("true") == 0) {
+ continue;
+ printf(" session is hidden\n");
+ }
+
+ if (!settings.contains("Exec")) {
+ // TODO: error message
+ printf(" no exec found\n");
+ continue;
+ }
+ QString exec(settings.value("Exec").toString());
+
+ QString locale(QLocale::system().name());
+ QString language(locale.split("_").at(0));
+ QString name;
+ if (settings.contains("Name[" + locale + "]")) {
+ name = settings.value("Name[" + locale + "]").toString();
+ } else if (settings.contains("Name[" + language + "]")) {
+ name = settings.value("Name[" + language + "]").toString();
+ } else if (settings.contains("Name")) {
+ name = settings.value("Name").toString();
+ } else {
+ // TODO: error message
+ printf(" no name found\n");
+ continue;
+ }
+
+ QString comment;
+ if (settings.contains("Comment[" + locale + "]")) {
+ comment = settings.value("Comment[" + locale + "]").toString();
+ } else if (settings.contains("Comment[" + language + "]")) {
+ comment = settings.value("Comment[" + language + "]").toString();
+ } else {
+ comment = settings.value("Comment").toString();
+ }
+
+ QString icon(settings.value("Icon").toString());
+ if (QDir::isRelativePath(icon)) {
+ // icons with relative paths are too complicated to find
+ // see http://freedesktop.org/wiki/Specifications/icon-theme-spec
+ // let's just ignore them
+ icon = QString();
+ }
+
+ printf(" adding session %s\n", name.toAscii().data());
+
+ XSession* session = new XSession;
+ session->init(name, exec, comment, icon);
+
+ retval.append(session);
+ }
+
+ return retval;
+}
+
+bool XSession::operator<(const Session& other) const {
+ int p0 = this->priority();
+ int p1 = other.priority();
+
+ if (p0 < p1) return true;
+ if (p0 == p1) {
+ QString d0 = this->shortDescription();
+ QString d1 = other.shortDescription();
+ return d0.localeAwareCompare(d1) < 0;
+ }
+ return false;
+}