[Pkg-owncloud-commits] [qtkeychain] 04/16: Add desktop environment detection

Sandro Knauß hefee-guest at moszumanska.debian.org
Wed Sep 3 22:15:54 UTC 2014


This is an automated email from the git hooks/post-receive script.

hefee-guest pushed a commit to branch master
in repository qtkeychain.

commit affe9dcaed3a705d7c93ebda0724ca1cf6625438
Author: Daniel Molkentin <daniel at molkentin.de>
Date:   Fri Apr 4 15:00:07 2014 +0200

    Add desktop environment detection
    
    My last patch causes Gnome Keyring to be launched even though the
    desktop environment is KDE. This patch detects the running desktop
    environments and tries to pick the matching storage backend.
---
 keychain_unix.cpp | 70 ++++++++++++++++++++++++++++++++++++++++++++++++++++---
 1 file changed, 67 insertions(+), 3 deletions(-)

diff --git a/keychain_unix.cpp b/keychain_unix.cpp
index 87f3656..527a676 100644
--- a/keychain_unix.cpp
+++ b/keychain_unix.cpp
@@ -30,12 +30,76 @@ enum KeyringBackend {
     Backend_Kwallet
 };
 
+enum DesktopEnvironment {
+    DesktopEnv_Gnome,
+    DesktopEnv_Kde4,
+    DesktopEnv_Unity,
+    DesktopEnv_Xfce,
+    DesktopEnv_Other
+};
+
+// the following detection algorithm is derived from chromium,
+// licensed under BSD, see base/nix/xdg_util.cc
+
+static const char kKDE4SessionEnvVar[] = "KDE_SESSION_VERSION";
+
+static DesktopEnvironment detectDesktopEnvironment() {
+    QByteArray xdgCurrentDesktop = qgetenv("XDG_CURRENT_DESKTOP");
+    if ( xdgCurrentDesktop == "GNOME" ) {
+        return DesktopEnv_Gnome;
+    } else if ( xdgCurrentDesktop == "Unity" ) {
+            return DesktopEnv_Unity;
+    } else if ( xdgCurrentDesktop == "KDE" ) {
+        return DesktopEnv_Kde4;
+    }
+
+    QByteArray desktopSession = qgetenv("DESKTOP_SESSION");
+    if ( desktopSession == "gnome" ) {
+        return DesktopEnv_Gnome;
+    } else if ( desktopSession == "kde" ) {
+        if ( qgetenv(kKDE4SessionEnvVar).isEmpty() ) {
+            // most likely KDE3
+            return DesktopEnv_Other;
+        } else {
+            return DesktopEnv_Kde4;
+        }
+    } else if ( desktopSession == "kde4" ) {
+        return DesktopEnv_Kde4;
+    } else if ( desktopSession.contains("xfce") || desktopSession == "xubuntu" ) {
+        return DesktopEnv_Xfce;
+    }
+
+    if ( !qgetenv("GNOME_DESKTOP_SESSION_ID").isEmpty() ) {
+        return DesktopEnv_Gnome;
+    } else if ( !qgetenv("KDE_FULL_SESSION").isEmpty() ) {
+        if ( qgetenv(kKDE4SessionEnvVar).isEmpty() ) {
+            // most likely KDE3
+            return DesktopEnv_Other;
+        } else {
+            return DesktopEnv_Kde4;
+        }
+    }
+}
+
 static KeyringBackend detectKeyringBackend()
 {
-    if ( GnomeKeyring::isAvailable() )
-        return Backend_GnomeKeyring;
-    else
+    switch (detectDesktopEnvironment()) {
+    case DesktopEnv_Kde4:
         return Backend_Kwallet;
+        break;
+    // fall through
+    case DesktopEnv_Gnome:
+    case DesktopEnv_Unity:
+    case DesktopEnv_Xfce:
+    case DesktopEnv_Other:
+    default:
+        if ( GnomeKeyring::isAvailable() ) {
+            return Backend_GnomeKeyring;
+        } else {
+            return Backend_Kwallet;
+        }
+    }
+
 }
 
 static KeyringBackend getKeyringBackend()

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-owncloud/qtkeychain.git



More information about the Pkg-owncloud-commits mailing list