4
# Copyright (C) 2010 Rico Tzschichholz
6
# This program is free software: you can redistribute it and/or modify
7
# it under the terms of the GNU General Public License as published by
8
# the Free Software Foundation, either version 3 of the License, or
9
# (at your option) any later version.
11
# This program is distributed in the hope that it will be useful,
12
# but WITHOUT ANY WARRANTY; without even the implied warranty of
13
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
# GNU General Public License for more details.
16
# You should have received a copy of the GNU General Public License
17
# along with this program. If not, see <http://www.gnu.org/licenses/>.
21
# * Getting Things GNOME! 0.2 or higher is required for dbus support
32
from docky.docky import DockyItem, DockySink
33
from signal import signal, SIGTERM
35
except ImportError, e:
42
class DockyGTGItem(DockyItem):
43
def __init__(self, path):
44
DockyItem.__init__(self, path)
47
self.bus.add_signal_receiver(self.name_owner_changed_cb,
48
dbus_interface='org.freedesktop.DBus',
49
signal_name='NameOwnerChanged')
51
obj = self.bus.get_object ("org.freedesktop.DBus", "/org/freedesktop/DBus")
52
self.bus_interface = dbus.Interface(obj, "org.freedesktop.DBus")
54
self.bus_interface.ListNames (reply_handler=self.list_names_handler, error_handler=self.list_names_error_handler)
56
def list_names_handler(self, names):
58
self.init_gtg_objects()
59
self.set_menu_buttons()
61
def list_names_error_handler(self, error):
62
print "error getting bus names - %s" % str(error)
64
def name_owner_changed_cb(self, name, old_owner, new_owner):
67
self.init_gtg_objects()
70
self.set_menu_buttons()
72
def init_gtg_objects(self):
73
obj = self.bus.get_object(gtgbus, gtgpath)
74
self.gtg = dbus.Interface(obj, gtgiface)
76
def clear_menu_buttons(self):
77
for k, v in self.id_map.iteritems():
79
self.iface.RemoveItem(k)
83
def set_menu_buttons(self):
84
self.clear_menu_buttons()
89
self.add_menu_item ("New Task", "list-add", "NewTask", "Task Controls")
90
self.add_menu_item ("Open Tasks List", "gtg", "OpenWindow", "Task Controls")
92
def menu_pressed(self, menu_id):
93
if not menu_id in self.id_map:
96
menu_id = self.id_map[menu_id]
98
if menu_id == "NewTask":
99
self.gtg.open_new_task()
100
elif menu_id == "OpenWindow":
101
self.gtg.show_task_browser()
103
def add_menu_item(self, name, icon, ident, title):
104
menu_id = self.iface.AddMenuItem(name, icon, title)
105
self.id_map[menu_id] = ident
108
class DockyGTGSink(DockySink):
109
def item_path_found(self, pathtoitem, item):
110
if item.GetOwnsDesktopFile() and item.GetDesktopFile().endswith ("gtg.desktop"):
111
self.items[pathtoitem] = DockyGTGItem(pathtoitem)
114
dockysink = DockyGTGSink()
119
if __name__ == "__main__":
120
mainloop = gobject.MainLoop(is_running=True)
122
atexit.register (cleanup)
123
signal(SIGTERM, lambda signum, stack_frame: exit(1))