73
65
# Only do the menu initializations if they are available.
75
67
self.init_messaging_menu()
76
if Unity and Dbusmenu:
79
69
def init_messaging_menu(self):
80
self.messaging = MessagingMenu.App(desktop_id=DESKTOP_ID)
70
self.messaging = MessagingMenu.App(desktop_id='gwibber.desktop')
81
71
self.messaging.register()
83
def init_dbus_menu(self):
84
self.launcher = Unity.LauncherEntry.get_for_desktop_id(DESKTOP_ID)
85
quicklist = Dbusmenu.Menuitem.new()
86
# The update status menu item.
87
post_menu = Dbusmenu.Menuitem.new()
88
post_menu.property_set(Dbusmenu.MENUITEM_PROP_LABEL,
90
post_menu.connect('item-activated', helper('friends-poster'))
91
# The refresh menu item.
92
refresh_menu = Dbusmenu.Menuitem.new()
93
refresh_menu.property_set(Dbusmenu.MENUITEM_PROP_LABEL, _('Refresh'))
94
refresh_menu.connect('item-activated', self._refresh)
95
# The preferences menu item.
96
preferences_menu = Dbusmenu.Menuitem.new()
97
preferences_menu.property_set(Dbusmenu.MENUITEM_PROP_LABEL,
99
preferences_menu.connect('item-activated',
100
helper('friends-preferences'))
101
# The quit menu item.
102
quit_menu = Dbusmenu.Menuitem.new()
103
quit_menu.property_set(Dbusmenu.MENUITEM_PROP_LABEL, _('Quit'))
104
quit_menu.connect('item-activated', self._shutdown)
105
# Make all the menu items visible.
106
for menu in (post_menu, refresh_menu, preferences_menu, quit_menu):
107
menu.property_set_bool(Dbusmenu.MENUITEM_PROP_VISIBLE, True)
108
quicklist.child_append(menu)
109
# Initialize the unread count to zero.
110
self.launcher.set_property('quicklist', quicklist)
111
self.update_unread_count(0)
113
73
def update_unread_count(self, count):
114
"""Update the unread count. If zoer, make it invisible."""
116
self.launcher.set_property('count', count)
117
self.launcher.set_property('count_visible', bool(count))
120
# XXX This bit allows you to test this file by running it. This doesn't fit
121
# very well into the larger testsuite architecture so we could probably
122
# improve this somehow, but I'm not sure how.
124
# In the meantime, run this like so (from the directory containing the
127
# $ python3 -m friends.utils.menus
129
# You should see the Friends icon in the launcher and switcher get the value
130
# '20'. If Friends is not running, pass in a second positional argument which
131
# is the name of a desktop file for an application that is running, e.g.:
133
# $ python3 -m friends.utils.menus gnome-terminal.desktop
135
# Pass in another argument to set some number other than 20. If you pass in
136
# 0, the count will not be visible.
140
if __name__ == '__main__':
142
from gi.repository import GObject
144
if len(sys.argv) > 1:
145
DESKTOP_ID = sys.argv[1]
146
if len(sys.argv) > 2:
147
count = int(sys.argv[2])
154
menu = MenuManager(stub, stub)
155
menu.update_unread_count(count)
158
GObject.MainLoop().run()
159
except KeyboardInterrupt:
74
"""Update the unread count. If zero, make it invisible."""
75
if not self.messaging:
78
if self.messaging.has_source('unread') and count > 0:
79
self.messaging.set_source_count('unread', count)
81
self.messaging.append_source_with_count(
86
elif self.messaging.has_source('unread') and count < 1:
87
self.messaging.remove_source('unread')