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/>.
29
from docky.docky import DockyItem, DockySink
30
from signal import signal, SIGTERM
32
except ImportError, e:
36
lifereabus = "org.gnome.feed.Reader"
37
readerpath = "/org/gnome/feed/Reader"
38
readeriface = "org.gnome.feed.Reader"
40
class DockyLifereaItem(DockyItem):
41
def __init__(self, path):
42
DockyItem.__init__(self, path)
46
self.bus.add_signal_receiver(self.name_owner_changed_cb,
47
dbus_interface='org.freedesktop.DBus',
48
signal_name='NameOwnerChanged')
50
obj = self.bus.get_object ("org.freedesktop.DBus", "/org/freedesktop/DBus")
51
self.bus_interface = dbus.Interface(obj, "org.freedesktop.DBus")
53
self.bus_interface.ListNames (reply_handler=self.list_names_handler, error_handler=self.list_names_error_handler)
55
def list_names_handler(self, names):
56
if lifereabus in names:
57
self.init_liferea_objects()
60
def list_names_error_handler(self, error):
61
print "error getting bus names - %s" % str(error)
63
def name_owner_changed_cb(self, name, old_owner, new_owner):
64
if name == lifereabus:
66
self.init_liferea_objects()
70
gobject.source_remove (self.timer)
74
def init_liferea_objects(self):
75
obj = self.bus.get_object(lifereabus, readerpath)
76
self.reader = dbus.Interface(obj, readeriface)
78
if not self.timer > 0:
79
self.timer = gobject.timeout_add (10000, self.update_badge)
81
def update_badge(self):
83
self.iface.ResetBadgeText()
86
items_unread = self.reader.GetUnreadItems()
87
#items_new = self.reader.GetNewItems()
89
self.iface.SetBadgeText("%s" % items_unread)
91
self.iface.ResetBadgeText()
94
class DockyLifereaSink(DockySink):
95
def item_path_found(self, pathtoitem, item):
96
if item.GetOwnsDesktopFile() and item.GetDesktopFile().endswith ("liferea.desktop"):
97
self.items[pathtoitem] = DockyLifereaItem(pathtoitem)
99
dockysink = DockyLifereaSink()
104
if __name__ == "__main__":
105
mainloop = gobject.MainLoop(is_running=True)
107
atexit.register (cleanup)
108
signal(SIGTERM, lambda signum, stack_frame: exit(1))