annotate finch/plugins/pietray.py @ 18236:f5a03ebb054f

Fix a crash after you close the status window, and change the status.
author Sadrul Habib Chowdhury <imadil@gmail.com>
date Sat, 23 Jun 2007 05:33:42 +0000
parents 12ab14848af4
children 22b9b6f148be
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
12ab14848af4 Dbus docklet for finch.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
81 def popup_menu(icon, button, tm, none):
12ab14848af4 Dbus docklet for finch.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
82 menu = gtk.Menu()
12ab14848af4 Dbus docklet for finch.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
83
12ab14848af4 Dbus docklet for finch.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
84 item = gtk.CheckMenuItem("Blink for unread IM")
12ab14848af4 Dbus docklet for finch.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
85 item.set_active(purple.PurplePrefsGetBool("/plugins/dbus/docklet/blink/im"))
12ab14848af4 Dbus docklet for finch.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
86 item.connect("activate", toggle_pref, "/plugins/dbus/docklet/blink/im")
12ab14848af4 Dbus docklet for finch.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
87 menu.append(item)
12ab14848af4 Dbus docklet for finch.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
88
12ab14848af4 Dbus docklet for finch.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
89 item = gtk.CheckMenuItem("Blink for unread Chats")
12ab14848af4 Dbus docklet for finch.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
90 item.set_active(purple.PurplePrefsGetBool("/plugins/dbus/docklet/blink/chat"))
12ab14848af4 Dbus docklet for finch.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
91 item.connect("activate", toggle_pref, "/plugins/dbus/docklet/blink/chat")
12ab14848af4 Dbus docklet for finch.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
92 menu.append(item)
12ab14848af4 Dbus docklet for finch.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
93
12ab14848af4 Dbus docklet for finch.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
94 menu.append(gtk.MenuItem())
12ab14848af4 Dbus docklet for finch.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
95
12ab14848af4 Dbus docklet for finch.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
96 #item = pack_image_label(menu, None, "Change Status...")
12ab14848af4 Dbus docklet for finch.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
97 item = gtk.MenuItem("Change Status...")
12ab14848af4 Dbus docklet for finch.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
98 menu.append(item)
12ab14848af4 Dbus docklet for finch.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
99 submenu = gtk.Menu()
12ab14848af4 Dbus docklet for finch.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
100 item.set_submenu(submenu)
12ab14848af4 Dbus docklet for finch.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
101 generate_status_menu(submenu)
12ab14848af4 Dbus docklet for finch.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
102
12ab14848af4 Dbus docklet for finch.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
103 menu.show_all()
12ab14848af4 Dbus docklet for finch.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
104 menu.popup(None, None, None, button, tm)
12ab14848af4 Dbus docklet for finch.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
105
12ab14848af4 Dbus docklet for finch.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
106 def get_status_message():
12ab14848af4 Dbus docklet for finch.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
107 status = purple.PurpleSavedstatusGetCurrent()
12ab14848af4 Dbus docklet for finch.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
108 msg = purple.PurpleSavedstatusGetMessage(status)
12ab14848af4 Dbus docklet for finch.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
109 if msg and len(msg) > 0:
12ab14848af4 Dbus docklet for finch.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
110 text = msg + " "
12ab14848af4 Dbus docklet for finch.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
111 else:
12ab14848af4 Dbus docklet for finch.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
112 text = ""
12ab14848af4 Dbus docklet for finch.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
113 text = text + "(" + {
12ab14848af4 Dbus docklet for finch.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
114 2: "Available",
12ab14848af4 Dbus docklet for finch.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
115 5: "Away",
12ab14848af4 Dbus docklet for finch.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
116 4: "Invisible",
12ab14848af4 Dbus docklet for finch.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
117 1: "Offline"
12ab14848af4 Dbus docklet for finch.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
118 }[purple.PurpleSavedstatusGetType(status)] + ")"
12ab14848af4 Dbus docklet for finch.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
119 return text
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 def detect_unread_conversations():
12ab14848af4 Dbus docklet for finch.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
122 im = purple.PurplePrefsGetBool("/plugins/dbus/docklet/blink/im")
12ab14848af4 Dbus docklet for finch.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
123 chat = purple.PurplePrefsGetBool("/plugins/dbus/docklet/blink/chat")
12ab14848af4 Dbus docklet for finch.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
124 tooltip = ""
12ab14848af4 Dbus docklet for finch.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
125 blink = False
12ab14848af4 Dbus docklet for finch.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
126 if im and chat:
12ab14848af4 Dbus docklet for finch.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
127 convs = purple.PurpleGetConversations()
12ab14848af4 Dbus docklet for finch.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
128 elif im:
12ab14848af4 Dbus docklet for finch.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
129 convs = purple.PurpleGetIms()
12ab14848af4 Dbus docklet for finch.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
130 elif chat:
12ab14848af4 Dbus docklet for finch.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
131 convs = purple.PurpleGetChats()
12ab14848af4 Dbus docklet for finch.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
132 else:
12ab14848af4 Dbus docklet for finch.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
133 convs = None
12ab14848af4 Dbus docklet for finch.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
134 for conv in convs:
12ab14848af4 Dbus docklet for finch.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
135 count = purple.PurpleConversationGetData(conv, "unseen-count")
12ab14848af4 Dbus docklet for finch.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
136 if count and count > 0:
12ab14848af4 Dbus docklet for finch.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
137 blink = True
12ab14848af4 Dbus docklet for finch.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
138 tooltip = tooltip + "\n" + purple.PurpleConversationGetName(conv) + " (" + str(count) + ")"
12ab14848af4 Dbus docklet for finch.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
139 t.set_from_file(path + "/share/pixmaps/pidgin.png")
12ab14848af4 Dbus docklet for finch.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
140 if blink:
12ab14848af4 Dbus docklet for finch.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
141 # I hate this icon
12ab14848af4 Dbus docklet for finch.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
142 # 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
143 tooltip = "\nUnread Messages:" + tooltip
12ab14848af4 Dbus docklet for finch.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
144 # 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
145 # Use that instead of hardcoding Finch here.
12ab14848af4 Dbus docklet for finch.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
146 t.set_tooltip("Finch: " + get_status_message() + tooltip)
12ab14848af4 Dbus docklet for finch.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
147 t.set_blinking(blink)
12ab14848af4 Dbus docklet for finch.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
148
12ab14848af4 Dbus docklet for finch.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
149 def conversation_updated(conv, type):
12ab14848af4 Dbus docklet for finch.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
150 detect_unread_conversations()
12ab14848af4 Dbus docklet for finch.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
151
12ab14848af4 Dbus docklet for finch.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
152 def savedstatus_changed(new, old):
12ab14848af4 Dbus docklet for finch.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
153 # Change the icon for status perhaps?
12ab14848af4 Dbus docklet for finch.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
154 detect_unread_conversations()
12ab14848af4 Dbus docklet for finch.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
155
12ab14848af4 Dbus docklet for finch.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
156 def init_prefs():
12ab14848af4 Dbus docklet for finch.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
157 if not purple.PurplePrefsExists("/plugins/dbus/docklet/blink"):
12ab14848af4 Dbus docklet for finch.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
158 purple.PurplePrefsAddNone("/plugins")
12ab14848af4 Dbus docklet for finch.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
159 purple.PurplePrefsAddNone("/plugins/dbus")
12ab14848af4 Dbus docklet for finch.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
160 purple.PurplePrefsAddNone("/plugins/dbus/docklet")
12ab14848af4 Dbus docklet for finch.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
161 purple.PurplePrefsAddNone("/plugins/dbus/docklet/blink")
12ab14848af4 Dbus docklet for finch.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
162 purple.PurplePrefsAddBool("/plugins/dbus/docklet/blink/im", True)
12ab14848af4 Dbus docklet for finch.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
163 purple.PurplePrefsAddBool("/plugins/dbus/docklet/blink/chat", True)
12ab14848af4 Dbus docklet for finch.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
164
12ab14848af4 Dbus docklet for finch.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
165 pkg = os.popen("pkg-config --variable=prefix pidgin")
12ab14848af4 Dbus docklet for finch.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
166 path = pkg.readline().rstrip()
12ab14848af4 Dbus docklet for finch.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
167
12ab14848af4 Dbus docklet for finch.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
168 bus.add_signal_receiver(conversation_updated,
12ab14848af4 Dbus docklet for finch.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
169 dbus_interface="im.pidgin.purple.PurpleInterface",
12ab14848af4 Dbus docklet for finch.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
170 signal_name="ConversationUpdated")
12ab14848af4 Dbus docklet for finch.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
171
12ab14848af4 Dbus docklet for finch.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
172 bus.add_signal_receiver(savedstatus_changed,
12ab14848af4 Dbus docklet for finch.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
173 dbus_interface="im.pidgin.purple.PurpleInterface",
12ab14848af4 Dbus docklet for finch.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
174 signal_name="SavedstatusChanged")
12ab14848af4 Dbus docklet for finch.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
175
12ab14848af4 Dbus docklet for finch.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
176 t = gtk.StatusIcon()
12ab14848af4 Dbus docklet for finch.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
177 t.connect("popup-menu", popup_menu, None)
12ab14848af4 Dbus docklet for finch.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
178
12ab14848af4 Dbus docklet for finch.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
179 init_prefs()
12ab14848af4 Dbus docklet for finch.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
180 detect_unread_conversations()
12ab14848af4 Dbus docklet for finch.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
181
12ab14848af4 Dbus docklet for finch.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
182 gtk.main ()
12ab14848af4 Dbus docklet for finch.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
diff changeset
183