4
# Copyright (C) 2009-2010 Jason Smith, Rico Tzschichholz
7
# This program is free software: you can redistribute it and/or modify
8
# it under the terms of the GNU General Public License as published by
9
# the Free Software Foundation, either version 3 of the License, or
10
# (at your option) any later version.
12
# This program is distributed in the hope that it will be useful,
13
# but WITHOUT ANY WARRANTY; without even the implied warranty of
14
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
# GNU General Public License for more details.
17
# You should have received a copy of the GNU General Public License
18
# along with this program. If not, see <http://www.gnu.org/licenses/>.
30
from docky.docky import DockyItem, DockySink
31
from signal import signal, SIGTERM
33
except ImportError, e:
36
pidginbus = "im.pidgin.purple.PurpleService"
37
pidginpath = "/im/pidgin/purple/PurpleObject"
38
pidginitem = "im.pidgin.purple.PurpleInterface"
42
bus = dbus.SessionBus()
43
obj = bus.get_object (pidginbus, pidginpath)
44
self.iface = dbus.Interface (obj, pidginitem)
46
def IsConnected(self):
47
status = self.iface.PurpleSavedstatusGetCurrent()
48
return not self.iface.PurpleSavedstatusGetType(status) == 1
51
status = self.iface.PurpleSavedstatusGetCurrent()
52
return not self.iface.PurpleSavedstatusGetType(status) == 5
55
new_status = self.iface.PurpleSavedstatusNew("", 2)
56
self.iface.PurpleSavedstatusActivate(new_status)
59
new_status = self.iface.PurpleSavedstatusNew("", 1)
60
self.iface.PurpleSavedstatusActivate(new_status)
63
new_status = self.iface.PurpleSavedstatusNew("", 5)
64
self.iface.PurpleSavedstatusActivate(new_status)
66
class DockyPidginItem(DockyItem):
67
def __init__(self, path):
68
DockyItem.__init__(self, path)
71
self.bus.add_signal_receiver(self.name_owner_changed_cb,
72
dbus_interface='org.freedesktop.DBus',
73
signal_name='NameOwnerChanged')
75
obj = self.bus.get_object ("org.freedesktop.DBus", "/org/freedesktop/DBus")
76
self.bus_interface = dbus.Interface(obj, "org.freedesktop.DBus")
78
self.bus_interface.ListNames (reply_handler=self.list_names_handler, error_handler=self.list_names_error_handler)
80
self.bus.add_signal_receiver(self.status_changed, "AccountStatusChanged", pidginitem, pidginbus, pidginpath)
81
self.bus.add_signal_receiver(self.conversation_updated, "ConversationUpdated", pidginitem, pidginbus, pidginpath)
83
def list_names_handler(self, names):
84
if pidginbus in names:
85
self.init_pidgin_objects()
86
self.set_menu_buttons()
89
def list_names_error_handler(self, error):
90
print "error getting bus names - %s" % str(error)
92
def name_owner_changed_cb(self, name, old_owner, new_owner):
95
self.init_pidgin_objects()
98
self.set_menu_buttons()
101
def init_pidgin_objects(self):
102
self.pidgin = PidginSink()
104
def status_changed(self, a, b, c):
105
self.set_menu_buttons()
108
def conversation_updated(self, conv, type):
111
def clear_menu_buttons(self):
112
for k, v in self.id_map.iteritems():
114
self.iface.RemoveItem(k)
118
def set_menu_buttons(self):
119
self.clear_menu_buttons()
121
if not self.pidgin or not self.iface:
124
if self.pidgin.IsConnected():
125
if self.pidgin.IsAway():
126
self.add_menu_item ("Set Away", "/usr/share/pixmaps/pidgin/status/16/away.png", "", "Away")
128
self.add_menu_item ("Set Available", "/usr/share/pixmaps/pidgin/status/16/available.png", "", "Connect")
129
self.add_menu_item ("Disconnect", "/usr/share/pixmaps/pidgin/status/16/offline.png", "", "Disconnect")
131
self.add_menu_item ("Connect", "/usr/share/pixmaps/pidgin/status/16/available.png", "", "Connect")
133
def update_badge(self):
135
self.iface.ResetBadgeText()
138
convs = self.pidgin.iface.PurpleGetConversations()
141
count = count + self.pidgin.iface.PurpleConversationGetData(conv, "unseen-count")
143
self.iface.SetBadgeText("%s" % count)
145
self.iface.ResetBadgeText()
148
def menu_pressed(self, menu_id):
149
menu_id = self.id_map[menu_id]
151
if menu_id == "Connect":
152
self.pidgin.Available()
153
elif menu_id == "Disconnect":
154
self.pidgin.Disconnect()
155
elif menu_id == "Away":
158
def add_menu_item(self, name, icon, group, ident):
159
menu_id = self.iface.AddMenuItem(name, icon, group)
160
self.id_map[menu_id] = ident
163
class DockyPidginSink(DockySink):
164
def item_path_found(self, pathtoitem, item):
165
if item.GetOwnsDesktopFile() and item.GetDesktopFile().endswith ("pidgin.desktop"):
166
self.items[pathtoitem] = DockyPidginItem(pathtoitem)
168
dockysink = DockyPidginSink()
173
if __name__ == "__main__":
174
mainloop = gobject.MainLoop(is_running=True)
176
atexit.register (cleanup)
177
signal(SIGTERM, lambda signum, stack_frame: exit(1))