summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJan Darmochwal2010-10-06 17:47:13 +0200
committerJan Darmochwal2010-10-06 17:47:13 +0200
commit93c62a6c376ec919cfaa342620d9f950c7091813 (patch)
treefe6a0d69dedb890327f0932e979a3c9da0830c0c
parentRemove debug printfs (diff)
downloadvmchooser-93c62a6c376ec919cfaa342620d9f950c7091813.tar.gz
vmchooser-93c62a6c376ec919cfaa342620d9f950c7091813.tar.xz
vmchooser-93c62a6c376ec919cfaa342620d9f950c7091813.zip
XSession init from single .desktop-file
xsession.init(file) can initialize an XSession from a single .desktop file
-rw-r--r--src/xsession.cpp111
-rw-r--r--src/xsession.h4
2 files changed, 61 insertions, 54 deletions
diff --git a/src/xsession.cpp b/src/xsession.cpp
index 6fc34e3..1f02b6b 100644
--- a/src/xsession.cpp
+++ b/src/xsession.cpp
@@ -6,8 +6,7 @@
#include "xsession.h"
-// TODO: void instead of bool? (or return something useful)
-bool XSession::init(const QString& name, const QString& exec,
+void XSession::init(const QString& name, const QString& exec,
const QString& comment, const QString& icon) {
this->name_ = name;
this->exec_ = exec;
@@ -15,6 +14,60 @@ bool XSession::init(const QString& name, const QString& exec,
this->icon_ = icon;
}
+bool XSession::init(const QString& filename) {
+ QSettings settings(filename, QSettings::IniFormat);
+ settings.setIniCodec("UTF-8");
+
+ settings.beginGroup("Desktop Entry");
+
+ if (settings.value("NoDisplay").toString().compare("true") == 0 ||
+ settings.value("Hidden").toString().compare("true") == 0) {
+ return false;
+ }
+
+ if (!settings.contains("Exec")) {
+ return false;
+ }
+ 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 {
+ return false;
+ }
+
+ 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();
+ }
+
+ this->name_ = name;
+ this->exec_ = exec;
+ this->comment_ = comment;
+ this->icon_ = icon;
+
+ return true;
+}
+
bool XSession::isActive() const {
return true;
}
@@ -56,59 +109,11 @@ QList<Session*> XSession::readSessions(const QString& path) {
continue;
}
- QSettings settings(fi.absoluteFilePath(), QSettings::IniFormat);
- settings.setIniCodec("UTF-8");
-
- settings.beginGroup("Desktop Entry");
-
- if (settings.value("NoDisplay").toString().compare("true") == 0 ||
- settings.value("Hidden").toString().compare("true") == 0) {
- continue;
- }
-
- if (!settings.contains("Exec")) {
- // TODO: error message
- 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
- 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();
- }
-
XSession* session = new XSession;
- session->init(name, exec, comment, icon);
-
- retval.append(session);
+ if(session->init(fi.absoluteFilePath())) {
+ retval.append(session);
+ }
}
-
return retval;
}
diff --git a/src/xsession.h b/src/xsession.h
index aac80fd..50563c2 100644
--- a/src/xsession.h
+++ b/src/xsession.h
@@ -12,8 +12,10 @@
class XSession : public Session {
public:
- bool init(const QString& name, const QString& exec,
+ void init(const QString& name, const QString& exec,
const QString& comment, const QString& icon);
+ bool init(const QString& filename);
+
bool isActive() const;
bool isLocked() const;