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