1# Copyright (C) 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
17from xl import xdg
18from xl.nls import gettext as _
19from xlgui.preferences import widgets
20
21name = _('Collection')
22icon = 'folder-music'
23ui = xdg.get_data_path('ui', 'preferences', 'collection.ui')
24
25
26def _get_default_strip_list():
27    return []
28    # FIXME:  currently, this is broken by the backend not also having access
29    # to the default set here, so we will just NOT set one.
30
31    # TRANSLATORS: Grammatical articles that are ignored while sorting the
32    # collection panel. For example, in French locales this could be
33    # the space-separated list "l' la le les".
34    # If this practice is not common in your locale, simply
35    # translate this to string with single space.
36    default_strip_list = _("the")
37    return [v.lower() for v in default_strip_list.split(' ') if v]
38
39
40class CollectionStripArtistPreference(widgets.ListPreference):
41    default = _get_default_strip_list()
42    name = 'collection/strip_list'
43
44    def __init__(self, preferences, widget):
45        widgets.ListPreference.__init__(self, preferences, widget)
46        self.widget.connect('populate-popup', self._populate_popup_cb)
47
48    def _get_value(self):
49        """
50        Get the value, overrides the base class function
51        because we don't need shlex parsing. We actually
52        want values like "l'" here.
53        """
54        values = [v.lower() for v in self.widget.get_text().split(' ') if v]
55        return values
56
57    def _populate_popup_cb(self, entry, menu):
58        from gi.repository import Gtk
59
60        entry = Gtk.MenuItem.new_with_mnemonic(_('Reset to _Defaults'))
61        entry.connect('activate', self._reset_to_defaults_cb)
62        entry.show()
63
64        sep = Gtk.SeparatorMenuItem()
65        sep.show()
66
67        menu.attach(entry, 0, 1, 0, 1)
68        menu.attach(sep, 0, 1, 1, 2)
69
70    def _reset_to_defaults_cb(self, item):
71        self.widget.set_text(' '.join(_get_default_strip_list()))
72
73
74class FileBasedCompilationsPreference(widgets.CheckPreference):
75    default = True
76    name = 'collection/file_based_compilations'
77
78
79# vim:ts=4 et sw=4
80