| ... |
... |
@@ -25,6 +25,7 @@ |
|
25
|
25
|
# You should have received a copy of the GNU General Public License
|
|
26
|
26
|
# along with Gajim. If not, see <http://www.gnu.org/licenses/>.
|
|
27
|
27
|
|
|
|
28
|
+import logging
|
|
28
|
29
|
import sys
|
|
29
|
30
|
|
|
30
|
31
|
from gi.repository import GLib
|
| ... |
... |
@@ -37,6 +38,8 @@ from gajim.common import app |
|
37
|
38
|
from gajim.common import helpers
|
|
38
|
39
|
from gajim.common import ged
|
|
39
|
40
|
|
|
|
41
|
+log = logging.getLogger('gajim.notify')
|
|
|
42
|
+
|
|
40
|
43
|
|
|
41
|
44
|
def get_show_in_roster(event, account, jid, session=None):
|
|
42
|
45
|
"""
|
| ... |
... |
@@ -72,6 +75,32 @@ class Notification: |
|
72
|
75
|
Handle notifications
|
|
73
|
76
|
"""
|
|
74
|
77
|
def __init__(self):
|
|
|
78
|
+ self.daemon_capabilities = ['actions']
|
|
|
79
|
+
|
|
|
80
|
+ # Detect if actions are supported by the notification daemon
|
|
|
81
|
+ if sys.platform == 'linux':
|
|
|
82
|
+ def on_proxy_ready(source, res, data=None):
|
|
|
83
|
+ try:
|
|
|
84
|
+ proxy = Gio.DBusProxy.new_finish(res)
|
|
|
85
|
+ self.daemon_capabilities = proxy.GetCapabilities()
|
|
|
86
|
+ except GLib.Error as e:
|
|
|
87
|
+ if e.domain == 'g-dbus-error-quark':
|
|
|
88
|
+ log.info('Notifications D-Bus connection failed: %s',
|
|
|
89
|
+ e.message)
|
|
|
90
|
+ else:
|
|
|
91
|
+ raise
|
|
|
92
|
+ else:
|
|
|
93
|
+ log.debug('Notifications D-Bus connected')
|
|
|
94
|
+
|
|
|
95
|
+ log.debug('Connecting to Notifications D-Bus')
|
|
|
96
|
+ Gio.DBusProxy.new_for_bus(Gio.BusType.SESSION,
|
|
|
97
|
+ Gio.DBusProxyFlags.DO_NOT_CONNECT_SIGNALS,
|
|
|
98
|
+ None,
|
|
|
99
|
+ 'org.freedesktop.Notifications',
|
|
|
100
|
+ '/org/freedesktop/Notifications',
|
|
|
101
|
+ 'org.freedesktop.Notifications',
|
|
|
102
|
+ None, on_proxy_ready)
|
|
|
103
|
+
|
|
75
|
104
|
app.ged.register_event_handler(
|
|
76
|
105
|
'notification', ged.GUI2, self._nec_notification)
|
|
77
|
106
|
app.ged.register_event_handler(
|
| ... |
... |
@@ -159,15 +188,18 @@ class Notification: |
|
159
|
188
|
_('File Transfer Error'), _('File Transfer Completed'),
|
|
160
|
189
|
_('File Transfer Stopped'), _('Groupchat Invitation'),
|
|
161
|
190
|
_('Connection Failed'), _('Subscription request'), _('Unsubscribed')):
|
|
162
|
|
- # Create Variant Dict
|
|
163
|
|
- dict_ = {'account': GLib.Variant('s', account),
|
|
164
|
|
- 'jid': GLib.Variant('s', jid),
|
|
165
|
|
- 'type_': GLib.Variant('s', type_)}
|
|
166
|
|
- variant_dict = GLib.Variant('a{sv}', dict_)
|
|
167
|
|
- action = 'app.{}-open-event'.format(account)
|
|
168
|
|
- #Button in notification
|
|
169
|
|
- notification.add_button_with_target(_('Open'), action, variant_dict)
|
|
170
|
|
- notification.set_default_action_and_target(action, variant_dict)
|
|
|
191
|
+ if 'actions' in self.daemon_capabilities:
|
|
|
192
|
+ # Create Variant Dict
|
|
|
193
|
+ dict_ = {'account': GLib.Variant('s', account),
|
|
|
194
|
+ 'jid': GLib.Variant('s', jid),
|
|
|
195
|
+ 'type_': GLib.Variant('s', type_)}
|
|
|
196
|
+ variant_dict = GLib.Variant('a{sv}', dict_)
|
|
|
197
|
+ action = 'app.{}-open-event'.format(account)
|
|
|
198
|
+ #Button in notification
|
|
|
199
|
+ notification.add_button_with_target(_('Open'), action,
|
|
|
200
|
+ variant_dict)
|
|
|
201
|
+ notification.set_default_action_and_target(action,
|
|
|
202
|
+ variant_dict)
|
|
171
|
203
|
|
|
172
|
204
|
# Only one notification per JID
|
|
173
|
205
|
if event_type in (_('Contact Signed In'), _('Contact Signed Out'),
|