Philipp Hörist pushed to branch master at gajim / gajim

Commits:
036c8679 by Alexei Sorokin at 2018-08-19T08:38:22Z
Support notification daemons with no actions once again

- - - - -


1 changed file:

- gajim/notify.py


Changes:

=====================================
gajim/notify.py
=====================================
--- a/gajim/notify.py
+++ b/gajim/notify.py
@@ -25,6 +25,7 @@
 # You should have received a copy of the GNU General Public License
 # along with Gajim. If not, see <http://www.gnu.org/licenses/>.
 
+import logging
 import sys
 
 from gi.repository import GLib
@@ -37,6 +38,8 @@ from gajim.common import app
 from gajim.common import helpers
 from gajim.common import ged
 
+log = logging.getLogger('gajim.notify')
+
 
 def get_show_in_roster(event, account, jid, session=None):
     """
@@ -72,6 +75,32 @@ class Notification:
     Handle notifications
     """
     def __init__(self):
+        self.daemon_capabilities = ['actions']
+
+        # Detect if actions are supported by the notification daemon
+        if sys.platform == 'linux':
+            def on_proxy_ready(source, res, data=None):
+                try:
+                    proxy = Gio.DBusProxy.new_finish(res)
+                    self.daemon_capabilities = proxy.GetCapabilities()
+                except GLib.Error as e:
+                    if e.domain == 'g-dbus-error-quark':
+                        log.info('Notifications D-Bus connection failed: %s',
+                                 e.message)
+                    else:
+                        raise
+                else:
+                    log.debug('Notifications D-Bus connected')
+
+            log.debug('Connecting to Notifications D-Bus')
+            Gio.DBusProxy.new_for_bus(Gio.BusType.SESSION,
+                                      
Gio.DBusProxyFlags.DO_NOT_CONNECT_SIGNALS,
+                                      None,
+                                      'org.freedesktop.Notifications',
+                                      '/org/freedesktop/Notifications',
+                                      'org.freedesktop.Notifications',
+                                      None, on_proxy_ready)
+
         app.ged.register_event_handler(
             'notification', ged.GUI2, self._nec_notification)
         app.ged.register_event_handler(
@@ -159,15 +188,18 @@ class Notification:
         _('File Transfer Error'), _('File Transfer Completed'),
         _('File Transfer Stopped'), _('Groupchat Invitation'),
         _('Connection Failed'), _('Subscription request'), _('Unsubscribed')):
-            # Create Variant Dict
-            dict_ = {'account': GLib.Variant('s', account),
-                     'jid': GLib.Variant('s', jid),
-                     'type_': GLib.Variant('s', type_)}
-            variant_dict = GLib.Variant('a{sv}', dict_)
-            action = 'app.{}-open-event'.format(account)
-            #Button in notification
-            notification.add_button_with_target(_('Open'), action, 
variant_dict)
-            notification.set_default_action_and_target(action, variant_dict)
+            if 'actions' in self.daemon_capabilities:
+                # Create Variant Dict
+                dict_ = {'account': GLib.Variant('s', account),
+                         'jid': GLib.Variant('s', jid),
+                         'type_': GLib.Variant('s', type_)}
+                variant_dict = GLib.Variant('a{sv}', dict_)
+                action = 'app.{}-open-event'.format(account)
+                #Button in notification
+                notification.add_button_with_target(_('Open'), action,
+                                                    variant_dict)
+                notification.set_default_action_and_target(action,
+                                                           variant_dict)
 
             # Only one notification per JID
             if event_type in (_('Contact Signed In'), _('Contact Signed Out'),



View it on GitLab: 
https://dev.gajim.org/gajim/gajim/commit/036c867902ca0a7506628eb8ed79d01dbcfcd131

-- 
View it on GitLab: 
https://dev.gajim.org/gajim/gajim/commit/036c867902ca0a7506628eb8ed79d01dbcfcd131
You're receiving this email because of your account on dev.gajim.org.
_______________________________________________
Commits mailing list
[email protected]
https://lists.gajim.org/cgi-bin/listinfo/commits

Reply via email to