1 # -*- coding: utf-8 -*-
3 # gPodder - A media aggregator and podcast client
4 # Copyright (c) 2005-2010 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/>.
22 # services.py -- Core Services for gPodder
23 # Thomas Perl <thp@perli.net> 2007-08-24
28 from gpodder
.liblogger
import log
30 from gpodder
import util
31 from gpodder
import download
40 class ObservableService(object):
41 def __init__(self
, signal_names
=[]):
43 for signal
in signal_names
:
44 self
.observers
[signal
] = []
46 def register(self
, signal_name
, observer
):
47 if signal_name
in self
.observers
:
48 if not observer
in self
.observers
[signal_name
]:
49 self
.observers
[signal_name
].append(observer
)
51 log('Observer already added to signal "%s".', signal_name
, sender
=self
)
53 log('Signal "%s" is not available for registration.', signal_name
, sender
=self
)
55 def unregister(self
, signal_name
, observer
):
56 if signal_name
in self
.observers
:
57 if observer
in self
.observers
[signal_name
]:
58 self
.observers
[signal_name
].remove(observer
)
60 log('Observer could not be removed from signal "%s".', signal_name
, sender
=self
)
62 log('Signal "%s" is not available for un-registration.', signal_name
, sender
=self
)
64 def notify(self
, signal_name
, *args
):
65 if signal_name
in self
.observers
:
66 for observer
in self
.observers
[signal_name
]:
67 util
.idle_add(observer
, *args
)
69 log('Signal "%s" is not available for notification.', signal_name
, sender
=self
)
72 class DependencyManager(object):
74 self
.dependencies
= []
76 def depend_on(self
, feature_name
, description
, modules
, tools
):
77 self
.dependencies
.append([feature_name
, description
, modules
, tools
])
79 def modules_available(self
, modules
):
81 Receives a list of modules and checks if each
82 of them is available. Returns a tuple with the
83 first item being a boolean variable that is True
84 when all required modules are available and False
85 otherwise. The second item is a dictionary that
86 lists every module as key with the available as
91 for module
in modules
:
96 result
[module
] = False
99 return (all_available
, result
)
101 def tools_available(self
, tools
):
103 See modules_available.
108 if util
.find_command(tool
):
112 all_available
= False
114 return (all_available
, result
)
117 dependency_manager
= DependencyManager()
120 # Register non-module-specific dependencies here
121 dependency_manager
.depend_on(_('Bluetooth file transfer'), _('Send podcast episodes to Bluetooth devices. Needs Python Bluez bindings.'), ['bluetooth'], ['bluetooth-sendto'])
122 dependency_manager
.depend_on(_('HTML episode shownotes'), _('Display episode shownotes in HTML format using GTKHTML2.'), ['gtkhtml2'], [])