-
Notifications
You must be signed in to change notification settings - Fork 574
Expand file tree
/
Copy pathindicator_libmessaging.py
More file actions
78 lines (65 loc) · 2.44 KB
/
indicator_libmessaging.py
File metadata and controls
78 lines (65 loc) · 2.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# -*- coding: utf-8 -*-
"""
Indicator plugin using libmessaging
"""
import gi
gi.require_version('MessagingMenu', '1.0') # noqa:E402
from gi.repository import MessagingMenu
from pybitmessage.bitmessageqt.utils import str_broadcast_subscribers
from pybitmessage.tr import _translate
class IndicatorLibmessaging(object):
"""Plugin for libmessage indicator"""
def __init__(self, form):
try:
self.app = MessagingMenu.App(desktop_id='pybitmessage.desktop')
self.app.register()
self.app.connect('activate-source', self.activate)
except:
self.app = None
return
self._menu = {
'send': unicode(_translate('MainWindow', 'Send')),
'messages': unicode(_translate('MainWindow', 'Messages')),
'subscriptions': unicode(_translate('MainWindow', 'Subscriptions'))
}
self.new_message_item = self.new_broadcast_item = None
self.form = form
self.show_unread()
def __del__(self):
if self.app:
self.app.unregister()
def activate(self, app, source): # pylint: disable=unused-argument
"""Activate the libmessaging indicator plugin"""
self.form.appIndicatorInbox(
self.new_message_item if source == 'messages'
else self.new_broadcast_item
)
def show_unread(self, draw_attention=False):
"""
show the number of unread messages and subscriptions
on the messaging menu
"""
for source, count in zip(
('messages', 'subscriptions'),
self.form.getUnread()
):
if count > 0:
if self.app.has_source(source):
self.app.set_source_count(source, count)
else:
self.app.append_source_with_count(
source, None, self._menu[source], count)
if draw_attention:
self.app.draw_attention(source)
# update the Ubuntu messaging menu
def __call__(self, draw_attention, item=None, to_label=None):
if not self.app:
return
# remember this item to that the activate() can find it
if item:
if to_label == str_broadcast_subscribers:
self.new_broadcast_item = item
else:
self.new_message_item = item
self.show_unread(draw_attention)
connect_plugin = IndicatorLibmessaging