From 43cc52f1ef27cab4e37da11b8d6c6041cd64acc4 Mon Sep 17 00:00:00 2001 From: Thomas Perl Date: Tue, 7 Feb 2012 00:32:52 +0100 Subject: [PATCH] Ubuntu Unity Launcher Integration --- src/gpodder/gtkui/main.py | 19 ++++++++ src/gpodder/gtkui/ubuntu.py | 104 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 123 insertions(+) create mode 100644 src/gpodder/gtkui/ubuntu.py diff --git a/src/gpodder/gtkui/main.py b/src/gpodder/gtkui/main.py index 93c936c7..197286a8 100644 --- a/src/gpodder/gtkui/main.py +++ b/src/gpodder/gtkui/main.py @@ -127,6 +127,12 @@ class gPodder(BuilderWidget, dbus.service.Object): self.episode_shownotes_window = None self.new_episodes_window = None + try: + from gpodder.gtkui import ubuntu + self.ubuntu = ubuntu.LauncherEntry() + except Exception, e: + self.ubuntu = None + # Mac OS X-specific UI tweaks: Native main menu integration # http://sourceforge.net/apps/trac/gtk-osx/wiki/Integrate if getattr(gtk.gdk, 'WINDOWING', 'x11') == 'quartz': @@ -1038,6 +1044,14 @@ class gPodder(BuilderWidget, dbus.service.Object): def remove_download_task_monitor(self, monitor): self.download_task_monitors.remove(monitor) + def set_download_progress(self, progress): + if self.ubuntu is not None: + self.ubuntu.set_progress(progress) + + def set_new_episodes_count(self, count): + if self.ubuntu is not None: + self.ubuntu.set_count(count) + def update_downloads_list(self, can_call_cleanup=True): try: model = self.download_status_model @@ -1125,9 +1139,11 @@ class gPodder(BuilderWidget, dbus.service.Object): percentage = 100.0*done_size/total_size else: percentage = 0.0 + self.set_download_progress(percentage/100.) total_speed = util.format_filesize(total_speed) title[1] += ' (%d%%, %s/s)' % (percentage, total_speed) else: + self.set_download_progress(1.) self.downloads_finished(self.download_tasks_seen) gpodder.user_extensions.on_all_episodes_downloaded() logger.info('All downloads have finished.') @@ -1963,6 +1979,9 @@ class gPodder(BuilderWidget, dbus.service.Object): reloaded; i.e. something has been added or removed since the last update of the podcast list). """ + _, _, new, _, _ = self.db.get_podcast_statistics() + self.set_new_episodes_count(new) + selection = self.treeChannels.get_selection() model, iter = selection.get_selected() diff --git a/src/gpodder/gtkui/ubuntu.py b/src/gpodder/gtkui/ubuntu.py new file mode 100644 index 00000000..05c1f0ef --- /dev/null +++ b/src/gpodder/gtkui/ubuntu.py @@ -0,0 +1,104 @@ +# -*- coding: utf-8 -*- +# +# gPodder - A media aggregator and podcast client +# Copyright (c) 2005-2012 Thomas Perl and the gPodder Team +# +# gPodder is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# gPodder is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . +# + +# Ubuntu Unity Launcher Integration +# Thomas Perl ; 2012-02-06 + +# FIXME: Due to the fact that we do not yet use the GI-style bindings, we will +# have to run this module in its own interpreter and send commands to it using +# the subprocess module. Once we use GI-style bindings, we can get rid of all +# this and still expose the same "interface' (LauncherEntry and its methods) +# to our callers. + +import subprocess +import logging + +if __name__ != '__main__': + logger = logging.getLogger(__name__) + + class LauncherEntry: + FILENAME = 'gpodder.desktop' + + def __init__(self): + self.process = subprocess.Popen(['python', __file__], + stdin=subprocess.PIPE) + + def set_count(self, count): + try: + self.process.stdin.write('count %d\n' % count) + self.process.stdin.flush() + except Exception, e: + logger.debug('Ubuntu count update failed.', exc_info=True) + + def set_progress(self, progress): + try: + self.process.stdin.write('progress %f\n' % progress) + self.process.stdin.flush() + except Exception, e: + logger.debug('Ubuntu progress update failed.', exc_info=True) + +if __name__ == '__main__': + from gi.repository import Unity, GObject + import threading + import sys + + class InputReader: + def __init__(self, fileobj, launcher): + self.fileobj = fileobj + self.launcher = launcher + + def read(self): + while True: + line = self.fileobj.readline() + if not line: + break + try: + command, value = line.strip().split() + if command == 'count': + GObject.idle_add(launcher_entry.set_count, int(value)) + elif command == 'progress': + GObject.idle_add(launcher_entry.set_progress, float(value)) + except: + pass + + class LauncherEntry: + FILENAME = 'gpodder.desktop' + + def __init__(self): + self.launcher = Unity.LauncherEntry.get_for_desktop_id( + self.FILENAME) + + def set_count(self, count): + self.launcher.set_property('count', count) + self.launcher.set_property('count_visible', count > 0) + + def set_progress(self, progress): + self.launcher.set_property('progress', progress) + self.launcher.set_property('progress_visible', 0. <= progress < 1.) + + GObject.threads_init() + loop = GObject.MainLoop() + threading.Thread(target=loop.run).start() + + launcher_entry = LauncherEntry() + reader = InputReader(sys.stdin, launcher_entry) + reader.read() + + loop.quit() + -- 2.11.4.GIT