Mercurial > pidgin
comparison finch/plugins/pietray.py @ 18139:12ab14848af4
Dbus docklet for finch.
author | Sadrul Habib Chowdhury <imadil@gmail.com> |
---|---|
date | Sun, 17 Jun 2007 02:36:57 +0000 |
parents | |
children | 22b9b6f148be |
comparison
equal
deleted
inserted
replaced
18138:c6ee57944335 | 18139:12ab14848af4 |
---|---|
1 #!/usr/bin/env python | |
2 | |
3 # This is a dbus script to show a docklet for Finch. This should work | |
4 # for any 'compatible' purple client. | |
5 # | |
6 # By 'compatible', I mean any client that sets and updates the | |
7 # "unseen-count" data on the conversations. | |
8 # | |
9 # It allows doing the following things: | |
10 # - It allows changing status. | |
11 # - It shows the current status and info about unread messages in | |
12 # the tooltip. | |
13 # - It can blink on unread IM/Chat messages, and it allows canging | |
14 # the preference for that. | |
15 # | |
16 # It requires GTK+ 2.10 or above, since it uses GtkStatusIcon. | |
17 # | |
18 # Sadrul <sadrul@pidgin.im> | |
19 | |
20 import pygtk | |
21 pygtk.require("2.0") | |
22 import gtk | |
23 import dbus, gobject, dbus.glib | |
24 import os # to get the pkg-config output | |
25 | |
26 bus = dbus.SessionBus() | |
27 obj = bus.get_object( | |
28 "im.pidgin.purple.PurpleService", "/im/pidgin/purple/PurpleObject") | |
29 purple = dbus.Interface(obj, "im.pidgin.purple.PurpleInterface") | |
30 | |
31 def pack_image_label(menu, image, label): | |
32 item = gtk.ImageMenuItem(label) | |
33 if image: | |
34 img = gtk.Image() | |
35 img.set_from_stock(image, 1) | |
36 item.set_image(img) | |
37 menu.append(item) | |
38 return item | |
39 | |
40 def activate_primitive_status(item, status): | |
41 saved = purple.PurpleSavedstatusFindTransientByTypeAndMessage(status, "") | |
42 if not saved: | |
43 saved = purple.PurpleSavedstatusNew("", status) | |
44 purple.PurpleSavedstatusActivate(saved) | |
45 | |
46 def activate_popular_status(item, time): | |
47 saved = purple.PurpleSavedstatusFindByCreationTime(time) | |
48 if saved: | |
49 purple.PurpleSavedstatusActivate(saved) | |
50 | |
51 def generate_status_menu(menu): | |
52 item = gtk.MenuItem("Available") | |
53 item.connect("activate", activate_primitive_status, 2) | |
54 menu.append(item) | |
55 | |
56 item = gtk.MenuItem("Away") | |
57 item.connect("activate", activate_primitive_status, 5) | |
58 menu.append(item) | |
59 | |
60 item = gtk.MenuItem("Invisible") | |
61 item.connect("activate", activate_primitive_status, 4) | |
62 menu.append(item) | |
63 | |
64 item = gtk.MenuItem("Offline") | |
65 item.connect("activate", activate_primitive_status, 1) | |
66 menu.append(item) | |
67 | |
68 menu.append(gtk.MenuItem()) | |
69 | |
70 popular = purple.PurpleSavedstatusesGetPopular(10) | |
71 for pop in popular: | |
72 title = purple.PurpleSavedstatusGetTitle(pop).replace('_', '__') | |
73 item = gtk.MenuItem(title) | |
74 item.set_data("timestamp", purple.PurpleSavedstatusGetCreationTime(pop)) | |
75 item.connect("activate", activate_popular_status, purple.PurpleSavedstatusGetCreationTime(pop)) | |
76 menu.append(item) | |
77 | |
78 def toggle_pref(item, pref): | |
79 purple.PurplePrefsSetBool(pref, item.get_active()) | |
80 | |
81 def popup_menu(icon, button, tm, none): | |
82 menu = gtk.Menu() | |
83 | |
84 item = gtk.CheckMenuItem("Blink for unread IM") | |
85 item.set_active(purple.PurplePrefsGetBool("/plugins/dbus/docklet/blink/im")) | |
86 item.connect("activate", toggle_pref, "/plugins/dbus/docklet/blink/im") | |
87 menu.append(item) | |
88 | |
89 item = gtk.CheckMenuItem("Blink for unread Chats") | |
90 item.set_active(purple.PurplePrefsGetBool("/plugins/dbus/docklet/blink/chat")) | |
91 item.connect("activate", toggle_pref, "/plugins/dbus/docklet/blink/chat") | |
92 menu.append(item) | |
93 | |
94 menu.append(gtk.MenuItem()) | |
95 | |
96 #item = pack_image_label(menu, None, "Change Status...") | |
97 item = gtk.MenuItem("Change Status...") | |
98 menu.append(item) | |
99 submenu = gtk.Menu() | |
100 item.set_submenu(submenu) | |
101 generate_status_menu(submenu) | |
102 | |
103 menu.show_all() | |
104 menu.popup(None, None, None, button, tm) | |
105 | |
106 def get_status_message(): | |
107 status = purple.PurpleSavedstatusGetCurrent() | |
108 msg = purple.PurpleSavedstatusGetMessage(status) | |
109 if msg and len(msg) > 0: | |
110 text = msg + " " | |
111 else: | |
112 text = "" | |
113 text = text + "(" + { | |
114 2: "Available", | |
115 5: "Away", | |
116 4: "Invisible", | |
117 1: "Offline" | |
118 }[purple.PurpleSavedstatusGetType(status)] + ")" | |
119 return text | |
120 | |
121 def detect_unread_conversations(): | |
122 im = purple.PurplePrefsGetBool("/plugins/dbus/docklet/blink/im") | |
123 chat = purple.PurplePrefsGetBool("/plugins/dbus/docklet/blink/chat") | |
124 tooltip = "" | |
125 blink = False | |
126 if im and chat: | |
127 convs = purple.PurpleGetConversations() | |
128 elif im: | |
129 convs = purple.PurpleGetIms() | |
130 elif chat: | |
131 convs = purple.PurpleGetChats() | |
132 else: | |
133 convs = None | |
134 for conv in convs: | |
135 count = purple.PurpleConversationGetData(conv, "unseen-count") | |
136 if count and count > 0: | |
137 blink = True | |
138 tooltip = tooltip + "\n" + purple.PurpleConversationGetName(conv) + " (" + str(count) + ")" | |
139 t.set_from_file(path + "/share/pixmaps/pidgin.png") | |
140 if blink: | |
141 # I hate this icon | |
142 # t.set_from_file(path + "/share/pixmaps/pidgin/tray/22/tray-message.png") | |
143 tooltip = "\nUnread Messages:" + tooltip | |
144 # There's going to be some way to expose the client's display name in 2.1.0. | |
145 # Use that instead of hardcoding Finch here. | |
146 t.set_tooltip("Finch: " + get_status_message() + tooltip) | |
147 t.set_blinking(blink) | |
148 | |
149 def conversation_updated(conv, type): | |
150 detect_unread_conversations() | |
151 | |
152 def savedstatus_changed(new, old): | |
153 # Change the icon for status perhaps? | |
154 detect_unread_conversations() | |
155 | |
156 def init_prefs(): | |
157 if not purple.PurplePrefsExists("/plugins/dbus/docklet/blink"): | |
158 purple.PurplePrefsAddNone("/plugins") | |
159 purple.PurplePrefsAddNone("/plugins/dbus") | |
160 purple.PurplePrefsAddNone("/plugins/dbus/docklet") | |
161 purple.PurplePrefsAddNone("/plugins/dbus/docklet/blink") | |
162 purple.PurplePrefsAddBool("/plugins/dbus/docklet/blink/im", True) | |
163 purple.PurplePrefsAddBool("/plugins/dbus/docklet/blink/chat", True) | |
164 | |
165 pkg = os.popen("pkg-config --variable=prefix pidgin") | |
166 path = pkg.readline().rstrip() | |
167 | |
168 bus.add_signal_receiver(conversation_updated, | |
169 dbus_interface="im.pidgin.purple.PurpleInterface", | |
170 signal_name="ConversationUpdated") | |
171 | |
172 bus.add_signal_receiver(savedstatus_changed, | |
173 dbus_interface="im.pidgin.purple.PurpleInterface", | |
174 signal_name="SavedstatusChanged") | |
175 | |
176 t = gtk.StatusIcon() | |
177 t.connect("popup-menu", popup_menu, None) | |
178 | |
179 init_prefs() | |
180 detect_unread_conversations() | |
181 | |
182 gtk.main () | |
183 |