2008-08-15 19:31:51 +02:00
|
|
|
# -*- coding:utf-8 -*-
|
2008-08-15 05:20:23 +02:00
|
|
|
## src/notify.py
|
2005-11-11 20:12:02 +01:00
|
|
|
##
|
2008-08-15 05:20:23 +02:00
|
|
|
## Copyright (C) 2005 Sebastian Estienne
|
|
|
|
## Copyright (C) 2005-2006 Andrew Sayman <lorien420 AT myrealbox.com>
|
|
|
|
## Copyright (C) 2005-2007 Nikos Kouremenos <kourem AT gmail.com>
|
2014-01-02 09:33:54 +01:00
|
|
|
## Copyright (C) 2005-2014 Yann Leboulanger <asterix AT lagaule.org>
|
2008-08-15 05:20:23 +02:00
|
|
|
## Copyright (C) 2006 Travis Shirk <travis AT pobox.com>
|
|
|
|
## Copyright (C) 2006-2008 Jean-Marie Traissard <jim AT lapin.org>
|
|
|
|
## Copyright (C) 2007 Julien Pivotto <roidelapluie AT gmail.com>
|
|
|
|
## Stephan Erb <steve-e AT h3c.de>
|
|
|
|
## Copyright (C) 2008 Brendan Taylor <whateley AT gmail.com>
|
|
|
|
## Jonathan Schleifer <js-gajim AT webkeks.org>
|
2005-11-11 20:12:02 +01:00
|
|
|
##
|
2007-10-22 13:13:13 +02:00
|
|
|
## This file is part of Gajim.
|
|
|
|
##
|
|
|
|
## Gajim is free software; you can redistribute it and/or modify
|
2005-11-11 20:12:02 +01:00
|
|
|
## it under the terms of the GNU General Public License as published
|
2007-10-22 13:13:13 +02:00
|
|
|
## by the Free Software Foundation; version 3 only.
|
2005-11-11 20:12:02 +01:00
|
|
|
##
|
2007-10-22 13:13:13 +02:00
|
|
|
## Gajim is distributed in the hope that it will be useful,
|
2005-11-11 20:12:02 +01:00
|
|
|
## but WITHOUT ANY WARRANTY; without even the implied warranty of
|
2008-08-15 05:20:23 +02:00
|
|
|
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
2005-11-11 20:12:02 +01:00
|
|
|
## GNU General Public License for more details.
|
|
|
|
##
|
2007-10-22 13:13:13 +02:00
|
|
|
## You should have received a copy of the GNU General Public License
|
2008-08-15 05:20:23 +02:00
|
|
|
## along with Gajim. If not, see <http://www.gnu.org/licenses/>.
|
2007-10-22 13:13:13 +02:00
|
|
|
##
|
2005-11-11 20:12:02 +01:00
|
|
|
|
|
|
|
import os
|
2006-03-25 01:59:09 +01:00
|
|
|
import time
|
2011-05-04 14:03:22 +02:00
|
|
|
from dialogs import PopupNotificationWindow
|
2012-12-23 16:23:43 +01:00
|
|
|
from gi.repository import GObject
|
2013-07-29 21:41:01 +02:00
|
|
|
from gi.repository import GLib
|
2006-04-05 16:57:09 +02:00
|
|
|
import gtkgui_helpers
|
2005-11-11 20:12:02 +01:00
|
|
|
|
|
|
|
from common import gajim
|
2006-05-10 22:25:51 +02:00
|
|
|
from common import helpers
|
2011-05-01 22:09:50 +02:00
|
|
|
from common import ged
|
2005-11-11 20:12:02 +01:00
|
|
|
|
2006-09-29 22:49:15 +02:00
|
|
|
from common import dbus_support
|
2005-12-10 01:56:38 +01:00
|
|
|
if dbus_support.supported:
|
2010-02-08 15:08:40 +01:00
|
|
|
import dbus
|
2005-11-11 20:12:02 +01:00
|
|
|
|
2006-09-28 02:31:59 +02:00
|
|
|
|
|
|
|
USER_HAS_PYNOTIFY = True # user has pynotify module
|
|
|
|
try:
|
2015-07-25 22:03:24 +02:00
|
|
|
import gi
|
|
|
|
gi.require_version('Notify', '0.7')
|
2012-12-23 16:23:43 +01:00
|
|
|
from gi.repository import Notify
|
|
|
|
Notify.init('Gajim Notification')
|
2015-07-30 15:15:38 +02:00
|
|
|
except ValueError:
|
2010-02-08 15:08:40 +01:00
|
|
|
USER_HAS_PYNOTIFY = False
|
2006-09-28 02:31:59 +02:00
|
|
|
|
2008-09-22 11:10:18 +02:00
|
|
|
def get_show_in_roster(event, account, contact, session=None):
|
2010-02-08 15:08:40 +01:00
|
|
|
"""
|
|
|
|
Return True if this event must be shown in roster, else False
|
|
|
|
"""
|
|
|
|
if event == 'gc_message_received':
|
|
|
|
return True
|
|
|
|
if event == 'message_received':
|
|
|
|
if session and session.control:
|
|
|
|
return False
|
|
|
|
return True
|
2006-09-02 23:01:11 +02:00
|
|
|
|
2008-02-27 22:33:50 +01:00
|
|
|
def get_show_in_systray(event, account, contact, type_=None):
|
2010-02-08 15:08:40 +01:00
|
|
|
"""
|
|
|
|
Return True if this event must be shown in systray, else False
|
|
|
|
"""
|
|
|
|
if type_ == 'printed_gc_msg' and not gajim.config.get(
|
|
|
|
'notify_on_all_muc_messages'):
|
|
|
|
# it's not an highlighted message, don't show in systray
|
|
|
|
return False
|
|
|
|
return gajim.config.get('trayicon_notification_on_events')
|
2006-09-02 23:01:11 +02:00
|
|
|
|
2009-11-25 21:59:43 +01:00
|
|
|
def popup(event_type, jid, account, msg_type='', path_to_image=None, title=None,
|
2012-04-09 13:38:28 +02:00
|
|
|
text=None, timeout=-1):
|
2010-02-08 15:08:40 +01:00
|
|
|
"""
|
|
|
|
Notify a user of an event. It first tries to a valid implementation of
|
|
|
|
the Desktop Notification Specification. If that fails, then we fall back to
|
|
|
|
the older style PopupNotificationWindow method
|
|
|
|
"""
|
|
|
|
# default image
|
|
|
|
if not path_to_image:
|
|
|
|
path_to_image = gtkgui_helpers.get_icon_path('gajim-chat_msg_recv', 48)
|
|
|
|
|
2012-04-09 13:38:28 +02:00
|
|
|
if timeout < 0:
|
|
|
|
timeout = gajim.config.get('notification_timeout')
|
|
|
|
|
2010-02-08 15:08:40 +01:00
|
|
|
# Try to show our popup via D-Bus and notification daemon
|
|
|
|
if gajim.config.get('use_notif_daemon') and dbus_support.supported:
|
|
|
|
try:
|
|
|
|
DesktopNotification(event_type, jid, account, msg_type,
|
2013-07-29 21:41:01 +02:00
|
|
|
path_to_image, title, GLib.markup_escape_text(text), timeout)
|
2010-02-08 15:08:40 +01:00
|
|
|
return # sucessfully did D-Bus Notification procedure!
|
2013-01-01 23:18:36 +01:00
|
|
|
except dbus.DBusException as e:
|
2010-02-08 15:08:40 +01:00
|
|
|
# Connection to D-Bus failed
|
|
|
|
gajim.log.debug(str(e))
|
2013-01-01 23:18:36 +01:00
|
|
|
except TypeError as e:
|
2010-02-08 15:08:40 +01:00
|
|
|
# This means that we sent the message incorrectly
|
|
|
|
gajim.log.debug(str(e))
|
|
|
|
|
|
|
|
# Ok, that failed. Let's try pynotify, which also uses notification daemon
|
|
|
|
if gajim.config.get('use_notif_daemon') and USER_HAS_PYNOTIFY:
|
|
|
|
if not text and event_type == 'new_message':
|
|
|
|
# empty text for new_message means do_preview = False
|
|
|
|
# -> default value for text
|
2013-07-29 21:41:01 +02:00
|
|
|
_text = GLib.markup_escape_text(gajim.get_name_from_jid(account,
|
|
|
|
jid))
|
2010-02-08 15:08:40 +01:00
|
|
|
else:
|
2013-07-29 21:41:01 +02:00
|
|
|
_text = GLib.markup_escape_text(text)
|
2010-02-08 15:08:40 +01:00
|
|
|
|
|
|
|
if not title:
|
|
|
|
_title = ''
|
|
|
|
else:
|
|
|
|
_title = title
|
|
|
|
|
2016-03-30 20:45:50 +02:00
|
|
|
notification = Notify.Notification.new(_title, _text)
|
2012-04-09 13:38:28 +02:00
|
|
|
notification.set_timeout(timeout*1000)
|
2010-02-08 15:08:40 +01:00
|
|
|
|
|
|
|
notification.set_category(event_type)
|
2016-04-15 02:37:58 +02:00
|
|
|
notification._data = {}
|
2016-09-05 00:01:29 +02:00
|
|
|
notification._data["event_type"] = event_type
|
|
|
|
notification._data["jid"] = jid
|
|
|
|
notification._data["account"] = account
|
|
|
|
notification._data["msg_type"] = msg_type
|
2010-02-08 15:08:40 +01:00
|
|
|
notification.set_property('icon-name', path_to_image)
|
2012-12-23 16:23:43 +01:00
|
|
|
if 'actions' in Notify.get_server_caps():
|
2010-02-08 15:08:40 +01:00
|
|
|
notification.add_action('default', 'Default Action',
|
|
|
|
on_pynotify_notification_clicked)
|
|
|
|
|
|
|
|
try:
|
|
|
|
notification.show()
|
|
|
|
return
|
2013-01-01 23:18:36 +01:00
|
|
|
except GObject.GError as e:
|
2010-02-08 15:08:40 +01:00
|
|
|
# Connection to notification-daemon failed, see #2893
|
|
|
|
gajim.log.debug(str(e))
|
|
|
|
|
|
|
|
# Either nothing succeeded or the user wants old-style notifications
|
2011-05-04 14:03:22 +02:00
|
|
|
instance = PopupNotificationWindow(event_type, jid, account, msg_type,
|
2012-04-09 13:38:28 +02:00
|
|
|
path_to_image, title, text, timeout)
|
2010-02-08 15:08:40 +01:00
|
|
|
gajim.interface.roster.popup_notification_windows.append(instance)
|
2006-09-28 02:31:59 +02:00
|
|
|
|
|
|
|
def on_pynotify_notification_clicked(notification, action):
|
2016-04-08 02:17:54 +02:00
|
|
|
jid = notification._data.jid
|
|
|
|
account = notification._data.account
|
|
|
|
msg_type = notification._data.msg_type
|
2006-09-28 02:31:59 +02:00
|
|
|
|
2010-02-08 15:08:40 +01:00
|
|
|
notification.close()
|
|
|
|
gajim.interface.handle_event(account, jid, msg_type)
|
2005-11-11 20:12:02 +01:00
|
|
|
|
2011-05-01 22:09:50 +02:00
|
|
|
class Notification:
|
|
|
|
"""
|
|
|
|
Handle notifications
|
|
|
|
"""
|
|
|
|
def __init__(self):
|
|
|
|
gajim.ged.register_event_handler('notification', ged.GUI2,
|
|
|
|
self._nec_notification)
|
|
|
|
|
|
|
|
def _nec_notification(self, obj):
|
|
|
|
if obj.do_popup:
|
2013-02-18 20:52:04 +01:00
|
|
|
if obj.popup_image:
|
|
|
|
icon_path = gtkgui_helpers.get_icon_path(obj.popup_image, 48)
|
2013-01-05 17:08:07 +01:00
|
|
|
if icon_path:
|
2013-02-18 20:52:04 +01:00
|
|
|
image_path = icon_path
|
|
|
|
elif obj.popup_image_path:
|
|
|
|
image_path = obj.popup_image_path
|
|
|
|
else:
|
|
|
|
image_path = ''
|
2011-05-01 22:09:50 +02:00
|
|
|
popup(obj.popup_event_type, obj.jid, obj.conn.name,
|
2013-02-18 20:52:04 +01:00
|
|
|
obj.popup_msg_type, path_to_image=image_path,
|
2012-04-09 13:38:28 +02:00
|
|
|
title=obj.popup_title, text=obj.popup_text,
|
|
|
|
timeout=obj.popup_timeout)
|
2011-05-01 22:09:50 +02:00
|
|
|
|
|
|
|
if obj.do_sound:
|
|
|
|
if obj.sound_file:
|
|
|
|
helpers.play_sound_file(obj.sound_file)
|
|
|
|
elif obj.sound_event:
|
|
|
|
helpers.play_sound(obj.sound_event)
|
|
|
|
|
|
|
|
if obj.do_command:
|
|
|
|
try:
|
2011-11-08 22:41:07 +01:00
|
|
|
helpers.exec_command(obj.command, use_shell=True)
|
2011-05-01 22:09:50 +02:00
|
|
|
except Exception:
|
|
|
|
pass
|
|
|
|
|
2005-12-10 01:56:38 +01:00
|
|
|
class NotificationResponseManager:
|
2010-02-08 15:08:40 +01:00
|
|
|
"""
|
|
|
|
Collect references to pending DesktopNotifications and manages there
|
|
|
|
signalling. This is necessary due to a bug in DBus where you can't remove a
|
|
|
|
signal from an interface once it's connected
|
|
|
|
"""
|
|
|
|
|
|
|
|
def __init__(self):
|
|
|
|
self.pending = {}
|
|
|
|
self.received = []
|
|
|
|
self.interface = None
|
|
|
|
|
|
|
|
def attach_to_interface(self):
|
|
|
|
if self.interface is not None:
|
|
|
|
return
|
|
|
|
self.interface = dbus_support.get_notifications_interface()
|
2010-03-14 00:05:30 +01:00
|
|
|
self.interface.connect_to_signal('ActionInvoked',
|
|
|
|
self.on_action_invoked)
|
2010-02-08 15:08:40 +01:00
|
|
|
self.interface.connect_to_signal('NotificationClosed', self.on_closed)
|
|
|
|
|
|
|
|
def on_action_invoked(self, id_, reason):
|
|
|
|
if id_ in self.pending:
|
|
|
|
notification = self.pending[id_]
|
|
|
|
notification.on_action_invoked(id_, reason)
|
|
|
|
del self.pending[id_]
|
2011-09-20 16:53:29 +02:00
|
|
|
return
|
|
|
|
# got an action on popup that isn't handled yet? Maybe user clicked too
|
|
|
|
# fast. Remember it.
|
|
|
|
self.received.append((id_, time.time(), reason))
|
2010-02-08 15:08:40 +01:00
|
|
|
if len(self.received) > 20:
|
|
|
|
curt = time.time()
|
|
|
|
for rec in self.received:
|
|
|
|
diff = curt - rec[1]
|
|
|
|
if diff > 10:
|
|
|
|
self.received.remove(rec)
|
|
|
|
|
|
|
|
def on_closed(self, id_, reason=None):
|
|
|
|
if id_ in self.pending:
|
|
|
|
del self.pending[id_]
|
|
|
|
|
|
|
|
def add_pending(self, id_, object_):
|
|
|
|
# Check to make sure that we handle an event immediately if we're adding
|
|
|
|
# an id that's already been triggered
|
|
|
|
for rec in self.received:
|
|
|
|
if rec[0] == id_:
|
|
|
|
object_.on_action_invoked(id_, rec[2])
|
|
|
|
self.received.remove(rec)
|
|
|
|
return
|
|
|
|
if id_ not in self.pending:
|
|
|
|
# Add it
|
|
|
|
self.pending[id_] = object_
|
|
|
|
else:
|
|
|
|
# We've triggered an event that has a duplicate ID!
|
|
|
|
gajim.log.debug('Duplicate ID of notification. Can\'t handle this.')
|
2006-03-25 01:59:09 +01:00
|
|
|
|
2005-12-10 01:56:38 +01:00
|
|
|
notification_response_manager = NotificationResponseManager()
|
|
|
|
|
|
|
|
class DesktopNotification:
|
2010-02-08 15:08:40 +01:00
|
|
|
"""
|
2010-03-14 00:05:30 +01:00
|
|
|
A DesktopNotification that interfaces with D-Bus via the Desktop
|
|
|
|
Notification Specification
|
2010-02-08 15:08:40 +01:00
|
|
|
"""
|
|
|
|
|
|
|
|
def __init__(self, event_type, jid, account, msg_type='',
|
2012-04-09 13:38:28 +02:00
|
|
|
path_to_image=None, title=None, text=None, timeout=-1):
|
2011-09-23 20:23:56 +02:00
|
|
|
self.path_to_image = os.path.abspath(path_to_image)
|
2010-02-08 15:08:40 +01:00
|
|
|
self.event_type = event_type
|
|
|
|
self.title = title
|
|
|
|
self.text = text
|
2012-04-09 13:38:28 +02:00
|
|
|
self.timeout = timeout
|
2010-02-08 15:08:40 +01:00
|
|
|
# 0.3.1 is the only version of notification daemon that has no way
|
|
|
|
# to determine which version it is. If no method exists, it means
|
|
|
|
# they're using that one.
|
|
|
|
self.default_version = [0, 3, 1]
|
|
|
|
self.account = account
|
|
|
|
self.jid = jid
|
|
|
|
self.msg_type = msg_type
|
|
|
|
|
|
|
|
# default value of text
|
|
|
|
if not text and event_type == 'new_message':
|
|
|
|
# empty text for new_message means do_preview = False
|
|
|
|
self.text = gajim.get_name_from_jid(account, jid)
|
|
|
|
|
|
|
|
if not title:
|
|
|
|
self.title = event_type # default value
|
|
|
|
|
|
|
|
if event_type == _('Contact Signed In'):
|
|
|
|
ntype = 'presence.online'
|
|
|
|
elif event_type == _('Contact Signed Out'):
|
|
|
|
ntype = 'presence.offline'
|
|
|
|
elif event_type in (_('New Message'), _('New Single Message'),
|
2010-03-14 00:05:30 +01:00
|
|
|
_('New Private Message')):
|
2010-02-08 15:08:40 +01:00
|
|
|
ntype = 'im.received'
|
|
|
|
elif event_type == _('File Transfer Request'):
|
|
|
|
ntype = 'transfer'
|
|
|
|
elif event_type == _('File Transfer Error'):
|
|
|
|
ntype = 'transfer.error'
|
|
|
|
elif event_type in (_('File Transfer Completed'),
|
|
|
|
_('File Transfer Stopped')):
|
|
|
|
ntype = 'transfer.complete'
|
|
|
|
elif event_type == _('New E-mail'):
|
|
|
|
ntype = 'email.arrived'
|
|
|
|
elif event_type == _('Groupchat Invitation'):
|
|
|
|
ntype = 'im.invitation'
|
|
|
|
elif event_type == _('Contact Changed Status'):
|
|
|
|
ntype = 'presence.status'
|
|
|
|
elif event_type == _('Connection Failed'):
|
|
|
|
ntype = 'connection.failed'
|
|
|
|
elif event_type == _('Subscription request'):
|
|
|
|
ntype = 'subscription.request'
|
|
|
|
elif event_type == _('Unsubscribed'):
|
|
|
|
ntype = 'unsubscribed'
|
|
|
|
else:
|
|
|
|
# default failsafe values
|
|
|
|
self.path_to_image = gtkgui_helpers.get_icon_path(
|
2010-03-14 00:05:30 +01:00
|
|
|
'gajim-chat_msg_recv', 48)
|
2010-02-08 15:08:40 +01:00
|
|
|
ntype = 'im' # Notification Type
|
|
|
|
|
|
|
|
self.notif = dbus_support.get_notifications_interface(self)
|
|
|
|
if self.notif is None:
|
|
|
|
raise dbus.DBusException('unable to get notifications interface')
|
|
|
|
self.ntype = ntype
|
|
|
|
|
|
|
|
if self.kde_notifications:
|
|
|
|
self.attempt_notify()
|
|
|
|
else:
|
|
|
|
self.capabilities = self.notif.GetCapabilities()
|
|
|
|
if self.capabilities is None:
|
|
|
|
self.capabilities = ['actions']
|
|
|
|
self.get_version()
|
|
|
|
|
|
|
|
def attempt_notify(self):
|
|
|
|
ntype = self.ntype
|
|
|
|
if self.kde_notifications:
|
|
|
|
notification_text = ('<html><img src="%(image)s" align=left />' \
|
2010-03-14 00:05:30 +01:00
|
|
|
'%(title)s<br/>%(text)s</html>') % {'title': self.title,
|
|
|
|
'text': self.text, 'image': self.path_to_image}
|
2017-04-22 23:49:11 +02:00
|
|
|
gajim_icon = gtkgui_helpers.get_icon_path('org.gajim.Gajim', 48)
|
2010-03-14 00:12:18 +01:00
|
|
|
try:
|
|
|
|
self.notif.Notify(
|
2010-03-14 00:05:30 +01:00
|
|
|
dbus.String(_('Gajim')), # app_name (string)
|
|
|
|
dbus.UInt32(0), # replaces_id (uint)
|
|
|
|
ntype, # event_id (string)
|
|
|
|
dbus.String(gajim_icon), # app_icon (string)
|
|
|
|
dbus.String(''), # summary (string)
|
2010-02-08 15:08:40 +01:00
|
|
|
dbus.String(notification_text), # body (string)
|
|
|
|
# actions (stringlist)
|
|
|
|
(dbus.String('default'), dbus.String(self.event_type),
|
2010-03-14 00:05:30 +01:00
|
|
|
dbus.String('ignore'), dbus.String(_('Ignore'))),
|
2012-04-09 13:38:28 +02:00
|
|
|
[], # hints (not used in KDE yet)
|
|
|
|
dbus.UInt32(self.timeout*1000), # timeout (int), in ms
|
2010-02-08 15:08:40 +01:00
|
|
|
reply_handler=self.attach_by_id,
|
|
|
|
error_handler=self.notify_another_way)
|
2010-03-14 00:12:18 +01:00
|
|
|
return
|
|
|
|
except Exception:
|
|
|
|
pass
|
2010-02-08 15:08:40 +01:00
|
|
|
version = self.version
|
|
|
|
if version[:2] == [0, 2]:
|
|
|
|
actions = {}
|
2015-01-03 15:24:58 +01:00
|
|
|
if 'actions' in self.capabilities and self.msg_type:
|
2010-02-08 15:08:40 +01:00
|
|
|
actions = {'default': 0}
|
|
|
|
try:
|
|
|
|
self.notif.Notify(
|
2010-03-14 00:05:30 +01:00
|
|
|
dbus.String(_('Gajim')),
|
|
|
|
dbus.String(self.path_to_image),
|
|
|
|
dbus.UInt32(0),
|
|
|
|
ntype,
|
|
|
|
dbus.Byte(0),
|
|
|
|
dbus.String(self.title),
|
|
|
|
dbus.String(self.text),
|
|
|
|
[dbus.String(self.path_to_image)],
|
|
|
|
actions,
|
|
|
|
[''],
|
|
|
|
True,
|
2012-04-09 13:38:28 +02:00
|
|
|
dbus.UInt32(self.timeout),
|
2010-03-14 00:05:30 +01:00
|
|
|
reply_handler=self.attach_by_id,
|
|
|
|
error_handler=self.notify_another_way)
|
2010-02-08 15:08:40 +01:00
|
|
|
except AttributeError:
|
2010-03-14 00:05:30 +01:00
|
|
|
# we're actually dealing with the newer version
|
|
|
|
version = [0, 3, 1]
|
2010-02-08 15:08:40 +01:00
|
|
|
if version > [0, 3]:
|
|
|
|
if gajim.interface.systray_enabled and \
|
|
|
|
gajim.config.get('attach_notifications_to_systray'):
|
|
|
|
status_icon = gajim.interface.systray.status_icon
|
2013-02-17 20:59:08 +01:00
|
|
|
rect = status_icon.get_geometry()[2]
|
|
|
|
x, y, width, height = rect.x, rect.y, rect.width, rect.height
|
2010-02-08 15:08:40 +01:00
|
|
|
pos_x = x + (width / 2)
|
|
|
|
pos_y = y + (height / 2)
|
|
|
|
hints = {'x': pos_x, 'y': pos_y}
|
|
|
|
else:
|
|
|
|
hints = {}
|
|
|
|
if version >= [0, 3, 2]:
|
|
|
|
hints['urgency'] = dbus.Byte(0) # Low Urgency
|
|
|
|
hints['category'] = dbus.String(ntype)
|
|
|
|
# it seems notification-daemon doesn't like empty text
|
|
|
|
if self.text:
|
2011-09-23 21:06:36 +02:00
|
|
|
text = self.text
|
2011-09-23 20:23:56 +02:00
|
|
|
if len(self.text) > 200:
|
2017-02-04 23:29:45 +01:00
|
|
|
text = '%s\n…' % self.text[:200]
|
2010-02-08 15:08:40 +01:00
|
|
|
else:
|
|
|
|
text = ' '
|
2010-09-30 22:36:55 +02:00
|
|
|
if os.environ.get('KDE_FULL_SESSION') == 'true':
|
|
|
|
text = '<table style=\'padding: 3px\'><tr><td>' \
|
|
|
|
'<img src=\"%s\"></td><td width=20> </td>' \
|
2010-10-01 10:31:26 +02:00
|
|
|
'<td>%s</td></tr></table>' % (self.path_to_image,
|
2010-09-30 22:36:55 +02:00
|
|
|
text)
|
|
|
|
self.path_to_image = os.path.abspath(
|
2017-04-22 23:49:11 +02:00
|
|
|
gtkgui_helpers.get_icon_path('org.gajim.Gajim', 48))
|
2010-02-08 15:08:40 +01:00
|
|
|
actions = ()
|
2015-01-03 15:24:58 +01:00
|
|
|
if 'actions' in self.capabilities and self.msg_type:
|
2010-03-14 00:05:30 +01:00
|
|
|
actions = (dbus.String('default'), dbus.String(
|
|
|
|
self.event_type))
|
2010-03-14 00:12:18 +01:00
|
|
|
try:
|
|
|
|
self.notif.Notify(
|
|
|
|
dbus.String(_('Gajim')),
|
|
|
|
# this notification does not replace other
|
|
|
|
dbus.UInt32(0),
|
|
|
|
dbus.String(self.path_to_image),
|
|
|
|
dbus.String(self.title),
|
|
|
|
dbus.String(text),
|
|
|
|
actions,
|
|
|
|
hints,
|
2012-04-09 13:38:28 +02:00
|
|
|
dbus.UInt32(self.timeout*1000),
|
2010-03-14 00:12:18 +01:00
|
|
|
reply_handler=self.attach_by_id,
|
|
|
|
error_handler=self.notify_another_way)
|
2013-01-01 23:18:36 +01:00
|
|
|
except Exception as e:
|
2010-03-19 08:20:58 +01:00
|
|
|
self.notify_another_way(e)
|
2010-02-08 15:08:40 +01:00
|
|
|
else:
|
2010-03-14 00:12:18 +01:00
|
|
|
try:
|
|
|
|
self.notif.Notify(
|
|
|
|
dbus.String(_('Gajim')),
|
|
|
|
dbus.String(self.path_to_image),
|
|
|
|
dbus.UInt32(0),
|
|
|
|
dbus.String(self.title),
|
|
|
|
dbus.String(self.text),
|
|
|
|
dbus.String(''),
|
|
|
|
hints,
|
2012-04-09 13:38:28 +02:00
|
|
|
dbus.UInt32(self.timeout*1000),
|
2010-03-14 00:12:18 +01:00
|
|
|
reply_handler=self.attach_by_id,
|
|
|
|
error_handler=self.notify_another_way)
|
2013-01-01 23:18:36 +01:00
|
|
|
except Exception as e:
|
2010-03-19 08:20:58 +01:00
|
|
|
self.notify_another_way(e)
|
2010-02-08 15:08:40 +01:00
|
|
|
|
|
|
|
def attach_by_id(self, id_):
|
|
|
|
notification_response_manager.attach_to_interface()
|
2011-09-20 16:53:29 +02:00
|
|
|
notification_response_manager.add_pending(id_, self)
|
2010-02-08 15:08:40 +01:00
|
|
|
|
2010-02-10 19:24:11 +01:00
|
|
|
def notify_another_way(self, e):
|
2010-03-14 00:12:18 +01:00
|
|
|
gajim.log.debug('Error when trying to use notification daemon: %s' % \
|
|
|
|
str(e))
|
2011-05-04 14:03:22 +02:00
|
|
|
instance = PopupNotificationWindow(self.event_type, self.jid,
|
2010-03-14 00:12:18 +01:00
|
|
|
self.account, self.msg_type, self.path_to_image, self.title,
|
2012-04-09 13:38:28 +02:00
|
|
|
self.text, self.timeout)
|
2010-03-14 00:12:18 +01:00
|
|
|
gajim.interface.roster.popup_notification_windows.append(instance)
|
2010-02-08 15:08:40 +01:00
|
|
|
|
|
|
|
def on_action_invoked(self, id_, reason):
|
|
|
|
if self.notif is None:
|
|
|
|
return
|
|
|
|
self.notif.CloseNotification(dbus.UInt32(id_))
|
|
|
|
self.notif = None
|
|
|
|
|
|
|
|
if reason == 'ignore':
|
|
|
|
return
|
|
|
|
|
|
|
|
gajim.interface.handle_event(self.account, self.jid, self.msg_type)
|
|
|
|
|
|
|
|
def version_reply_handler(self, name, vendor, version, spec_version=None):
|
|
|
|
if spec_version:
|
|
|
|
version = spec_version
|
|
|
|
elif vendor == 'Xfce' and version.startswith('0.1.0'):
|
|
|
|
version = '0.9'
|
|
|
|
version_list = version.split('.')
|
|
|
|
self.version = []
|
|
|
|
try:
|
|
|
|
while len(version_list):
|
|
|
|
self.version.append(int(version_list.pop(0)))
|
|
|
|
except ValueError:
|
|
|
|
self.version_error_handler_3_x_try(None)
|
|
|
|
self.attempt_notify()
|
|
|
|
|
|
|
|
def get_version(self):
|
|
|
|
self.notif.GetServerInfo(
|
2010-03-14 00:05:30 +01:00
|
|
|
reply_handler=self.version_reply_handler,
|
|
|
|
error_handler=self.version_error_handler_2_x_try)
|
2010-02-08 15:08:40 +01:00
|
|
|
|
|
|
|
def version_error_handler_2_x_try(self, e):
|
2010-03-14 00:05:30 +01:00
|
|
|
self.notif.GetServerInformation(
|
|
|
|
reply_handler=self.version_reply_handler,
|
|
|
|
error_handler=self.version_error_handler_3_x_try)
|
2010-02-08 15:08:40 +01:00
|
|
|
|
|
|
|
def version_error_handler_3_x_try(self, e):
|
|
|
|
self.version = self.default_version
|
|
|
|
self.attempt_notify()
|