Commit 78b06833 authored by Philipp Hörist's avatar Philipp Hörist

Notifications: Detect DE and set icons accordingly

parent b2aa7352
......@@ -314,6 +314,20 @@ def detect_dependencies():
log('gajim').info('Used language: %s', LANG)
def detect_desktop_env():
if sys.platform in ('win32', 'darwin'):
return sys.platform
desktop = os.environ.get('XDG_CURRENT_DESKTOP')
if desktop is None:
return None
if 'gnome' in desktop.lower():
return 'gnome'
return desktop
desktop_env = detect_desktop_env()
def get_an_id():
return str(uuid.uuid4())
......
......@@ -42,7 +42,6 @@
from gajim.gtk.util import get_icon_name
from gajim.gtk.util import get_monitor_scale_factor
from gajim.gtk.util import get_total_screen_geometry
from gajim.gtk.util import load_icon
log = logging.getLogger('gajim.gtk.notification')
......@@ -142,7 +141,7 @@ def popup(self, event_type, jid, account, type_='', icon_name=None,
"""
if icon_name is None:
icon_name = 'gajim-chat_msg_recv'
icon_name = 'mail-message-new'
if timeout < 0:
timeout = app.config.get('notification_timeout')
......@@ -158,8 +157,7 @@ def popup(self, event_type, jid, account, type_='', icon_name=None,
if not self._dbus_available:
return
scale = get_monitor_scale_factor()
icon_pixbuf = load_icon(icon_name, size=48, pixbuf=True, scale=scale)
icon = Gio.ThemedIcon.new(icon_name)
notification = Gio.Notification()
if title is not None:
......@@ -202,16 +200,23 @@ def popup(self, event_type, jid, account, type_='', icon_name=None,
_('New Single Message'),
_('New Private Message'),
_('New Group Chat Message')):
avatar = app.contacts.get_avatar(account, jid)
if avatar:
icon_pixbuf = avatar
if app.desktop_env == 'gnome':
icon = self._get_avatar_for_notification(account, jid)
notif_id = self._make_id('new-message', account, jid)
notification.set_icon(icon_pixbuf)
notification.set_icon(icon)
notification.set_priority(Gio.NotificationPriority.NORMAL)
app.app.send_notification(notif_id, notification)
@staticmethod
def _get_avatar_for_notification(account, jid):
scale = get_monitor_scale_factor()
contact = app.contacts.get_contact(account, jid)
if contact is None:
return None
return app.interface.get_avatar(contact, 16, scale, pixbuf=True)
def _on_popup_destroy(self, *args):
self._win32_active_popup = None
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment