Debian Codegraph @

xlgui/preferences/cover.py

raw
1 # Copyright (C) 2008-2010 Adam Olsen
2 #
3 # This program is free software; you can redistribute it and/or modify
4 # it under the terms of the GNU General Public License as published by
5 # the Free Software Foundation; either version 2, or (at your option)
6 # any later version.
7 #
8 # This program is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # GNU General Public License for more details.
12 #
13 # You should have received a copy of the GNU General Public License
14 # along with this program; if not, write to the Free Software
15 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 #
17 #
18 # The developers of the Exaile media player hereby grant permission
19 # for non-GPL compatible GStreamer and Exaile plugins to be used and
20 # distributed together with GStreamer and Exaile. This permission is
21 # above and beyond the permissions granted by the GPL license by which
22 # Exaile is covered. If you modify this code, you may extend this
23 # exception to your version of the code, but you are not obligated to
24 # do so. If you do not wish to do so, delete this exception statement
25 # from your version.
26
27 from xl import covers, settings, xdg
28 from xl.nls import gettext as _
29 from xlgui.preferences import widgets
30
31 name = _('Covers')
32 icon = 'image-x-generic'
33 ui = xdg.get_data_path('ui', 'preferences', 'cover.ui')
34
35
36 class TagCoverFetching(widgets.CheckPreference):
37 default = True
38 name = 'covers/use_tags'
39
40
41 class LocalCoverFetching(widgets.CheckPreference):
42 default = True
43 name = 'covers/use_localfile'
44
45
46 class LocalFilePreferredNamesPreference(widgets.Preference, widgets.CheckConditional):
47 default = ['front', 'cover', 'album']
48 name = 'covers/localfile/preferred_names'
49 condition_preference_name = 'covers/use_localfile'
50
51 def __init__(self, preferences, widget):
52 widgets.Preference.__init__(self, preferences, widget)
53 widgets.CheckConditional.__init__(self)
54
55 def _get_value(self):
56 """
57 Converts the string value to a list
58 """
59 return [v.strip() for v in widgets.Preference._get_value(self).split(',')]
60
61 def _set_value(self):
62 """
63 Converts the list to a string value
64 """
65 self.widget.set_text(', '.join(settings.get_option(self.name, self.default)))
66
67
68 class CoverOrderPreference(widgets.OrderListPreference):
69 """
70 This little preference item shows kind of a complicated preference
71 widget in action. The defaults are dynamic.
72 """
73
74 name = 'covers/preferred_order'
75
76 def __init__(self, preferences, widget):
77 self.default = covers.MANAGER._get_methods()
78 widgets.OrderListPreference.__init__(self, preferences, widget)
79
80 def _set_value(self):
81 self.model.clear()
82 for item in self.default:
83 self.model.append([item.name])
84
85 def apply(self):
86 if widgets.OrderListPreference.apply(self):
87 covers.MANAGER.set_preferred_order(self._get_value())
88 return True
89
90
91 class AutomaticCoverFetching(widgets.CheckPreference):
92 default = True
93 name = 'covers/automatic_fetching'