1 # -*- coding: utf-8 -*-
3 # gPodder - A media aggregator and podcast client
4 # Copyright (c) 2005-2012 Thomas Perl and the gPodder Team
6 # gPodder 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 # gPodder 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/>.
20 # Ubuntu Unity Launcher Integration
21 # Thomas Perl <thp@gpodder.org>; 2012-02-06
23 # FIXME: Due to the fact that we do not yet use the GI-style bindings, we will
24 # have to run this module in its own interpreter and send commands to it using
25 # the subprocess module. Once we use GI-style bindings, we can get rid of all
26 # this and still expose the same "interface' (LauncherEntry and its methods)
32 if __name__
!= '__main__':
33 logger
= logging
.getLogger(__name__
)
36 FILENAME
= 'gpodder.desktop'
39 self
.process
= subprocess
.Popen(['python', __file__
],
40 stdin
=subprocess
.PIPE
)
42 def set_count(self
, count
):
44 self
.process
.stdin
.write('count %d\n' % count
)
45 self
.process
.stdin
.flush()
47 logger
.debug('Ubuntu count update failed.', exc_info
=True)
49 def set_progress(self
, progress
):
51 self
.process
.stdin
.write('progress %f\n' % progress
)
52 self
.process
.stdin
.flush()
54 logger
.debug('Ubuntu progress update failed.', exc_info
=True)
56 if __name__
== '__main__':
57 from gi
.repository
import Unity
, GObject
62 def __init__(self
, fileobj
, launcher
):
63 self
.fileobj
= fileobj
64 self
.launcher
= launcher
68 line
= self
.fileobj
.readline()
72 command
, value
= line
.strip().split()
73 if command
== 'count':
74 GObject
.idle_add(launcher_entry
.set_count
, int(value
))
75 elif command
== 'progress':
76 GObject
.idle_add(launcher_entry
.set_progress
, float(value
))
81 FILENAME
= 'gpodder.desktop'
84 self
.launcher
= Unity
.LauncherEntry
.get_for_desktop_id(
87 def set_count(self
, count
):
88 self
.launcher
.set_property('count', count
)
89 self
.launcher
.set_property('count_visible', count
> 0)
91 def set_progress(self
, progress
):
92 self
.launcher
.set_property('progress', progress
)
93 self
.launcher
.set_property('progress_visible', 0. <= progress
< 1.)
95 GObject
.threads_init()
96 loop
= GObject
.MainLoop()
97 threading
.Thread(target
=loop
.run
).start()
99 launcher_entry
= LauncherEntry()
100 reader
= InputReader(sys
.stdin
, launcher_entry
)