From 0d8562182b5991fd8383a31311dc5a8d7ae0ea64 Mon Sep 17 00:00:00 2001 From: Amadeus Folego Date: Tue, 6 May 2014 21:32:48 -0300 Subject: [PATCH] Check for DBUS Notifications service presence Instead of checking for the presence of particular environment variables, set by Desktop Environments, we should check if there is any service on DBus that listens to org.freedesktop.Notifications. This is important for people who use different services that provide notification features like Dunst[1]. See [2] to check a more detailed list. 1: https://github.com/knopwob/dunst 2: https://wiki.archlinux.org/index.php/Desktop_Notifications --- builds/arch/PKGBUILD | 2 +- snakefire/__init__.py | 13 ++++++++++--- snakefire/mainframe.py | 6 +++--- 3 files changed, 14 insertions(+), 7 deletions(-) diff --git a/builds/arch/PKGBUILD b/builds/arch/PKGBUILD index 1d27c5a..37193f5 100644 --- a/builds/arch/PKGBUILD +++ b/builds/arch/PKGBUILD @@ -6,7 +6,7 @@ pkgdesc='A Campfire desktop client' arch=('i686' 'x86_64' 'ppc') url='http://snakefire.org' license=('MIT') -depends=('python2' 'python2-pyqt4' 'python2-keyring' 'python2-notify' 'python-pyfire>=0.3.4') +depends=('python2' 'python2-pyqt4' 'python2-keyring' 'python2-notify' 'python-pyfire>=0.3.4', 'python2-dbus') optdepends=('python-gnomekeyring: For GNOME/XFCE/LXDE users that require notifications' 'python2-pyenchant: For spell checking support') makedepends=('python2' 'python2-distribute') source=(http://snakefire.org/downloads/$pkgname-$pkgver.tar.gz) diff --git a/snakefire/__init__.py b/snakefire/__init__.py index e29a68d..4d43b2c 100644 --- a/snakefire/__init__.py +++ b/snakefire/__init__.py @@ -1,7 +1,7 @@ import os, resources, subprocess +import dbus, dbus.proxies -GNOME_ENABLED = os.getenv("GNOME_DESKTOP_SESSION_ID") -XFCE_ENABLED = os.getenv("XDG_SESSION_COOKIE") +NOTIFICATIONS_ENABLED = False KDE_ENABLED = False try: @@ -10,10 +10,17 @@ except OSError: pass +try: + dbus.proxies.ProxyObject(conn=dbus.SessionBus(), + bus_name="org.freedesktop.Notifications", + object_path="/org/freedesktop/Notifications") + NOTIFICATIONS_ENABLED = True +except dbus.exceptions.DBusException: + pass if KDE_ENABLED: from .mainframe import KSnakefire as Snakefire -elif GNOME_ENABLED or XFCE_ENABLED: +elif NOTIFICATIONS_ENABLED: from .mainframe import GSnakefire as Snakefire else: from .mainframe import QSnakefire as Snakefire diff --git a/snakefire/mainframe.py b/snakefire/mainframe.py index f0e5e0e..641b934 100644 --- a/snakefire/mainframe.py +++ b/snakefire/mainframe.py @@ -8,7 +8,7 @@ import urllib2 import enchant -from snakefire import GNOME_ENABLED, KDE_ENABLED, XFCE_ENABLED +from snakefire import NOTIFICATIONS_ENABLED, KDE_ENABLED from PyQt4 import Qt from PyQt4 import QtGui @@ -18,7 +18,7 @@ if KDE_ENABLED: from PyKDE4 import kdecore from PyKDE4 import kdeui -elif GNOME_ENABLED or XFCE_ENABLED: +elif NOTIFICATIONS_ENABLED: import subprocess import pynotify @@ -1149,7 +1149,7 @@ def _notify(self, room, message, user): kdeui.KNotification.CloseWhenWidgetActivated ) -if GNOME_ENABLED or XFCE_ENABLED: +if NOTIFICATIONS_ENABLED: class GSnakefire(QSnakefire): def __init__(self, parent=None): super(GSnakefire, self).__init__(parent)