File: cdprefs.py

package info (click to toggle)
exaile 0.3.2.2-3
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 9,564 kB
  • sloc: python: 35,424; makefile: 265; sh: 58
file content (127 lines) | stat: -rw-r--r-- 4,330 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
# Copyright (C) 2009-2010 Aren Olson
#
# This program 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 2, or (at your option)
# any later version.
#
# This program 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, write to the Free Software
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
#
#
# The developers of the Exaile media player hereby grant permission
# for non-GPL compatible GStreamer and Exaile plugins to be used and
# distributed together with GStreamer and Exaile. This permission is
# above and beyond the permissions granted by the GPL license by which
# Exaile is covered. If you modify this code, you may extend this
# exception to your version of the code, but you are not obligated to
# do so. If you do not wish to do so, delete this exception statement
# from your version.

from __future__ import with_statement
import gobject
import gtk
import os
import warnings 

from xl import event, settings, transcoder
from xl.nls import gettext as _
from xlgui.preferences import widgets

name = _("CD")
basedir = os.path.dirname(os.path.realpath(__file__))
ui = os.path.join(basedir, "cdprefs_pane.ui")

FORMAT_WIDGET = None

# TODO: allow setting cddb server?

class OutputFormatPreference(widgets.ComboPreference):
    name = 'cd_import/format'

class OutputQualityPreference(widgets.ComboPreference, widgets.Conditional):
    name = 'cd_import/quality'
    condition_preference_name = 'cd_import/format'

    def __init__(self, preferences, widget):
        widgets.ComboPreference.__init__(self, preferences, widget)
        widgets.Conditional.__init__(self)
        self.format = settings.get_option("cd_import/format", None)
        self.default = settings.get_option("cd_import/quality", None)

    def on_check_condition(self):
        """
            Specifies the condition to meet

            :returns: Whether the condition is met or not
            :rtype: bool
        """
        model = self.widget.get_model()
        format = self.condition_widget.get_active_text()
        formatinfo = transcoder.FORMATS[format]
        if self.format != format:
            self.format = format
            default = formatinfo['default']

            if self.default != default:
                self.default = default # raw value

        default_title = formatinfo['kbs_steps'][
            formatinfo['raw_steps'].index(self.default)]
        active_iter = self.widget.get_active_iter()

        if active_iter is not None:
            active_title = float(model.get_value(active_iter, 1))
        else:
            active_title = default_title

        self.widget.set_model(None)
        model.clear()

        steps = zip(formatinfo['raw_steps'], formatinfo['kbs_steps'])

        for item, title in steps:
            iter = model.append([item, title])

        self.widget.set_model(model)

        if active_title not in formatinfo['kbs_steps']:
            active_title = default_title

        index = formatinfo['kbs_steps'].index(active_title)
        self.widget.set_active(index)

        return True

class OutputPathPreference(widgets.ComboEntryPreference):
    name = 'cd_import/outpath'
    completion_items = {
        '$tracknumber': _('Track number'),
        '$title': _('Title'),
        '$artist': _('Artist'),
        '$composer': _('Composer'),
        '$album': _('Album'),
        '$__length': _('Length'),
        '$discnumber': _('Disc number'),
        '$__rating': _('Rating'),
        '$date': _('Date'),
        '$genre': _('Genre'),
        '$bitrate': _('Bitrate'),
        '$__location': _('Location'),
        '$filename': _('Filename'),
        '$__playcount': _('Play count'),
        '$__last_played': _('Last played'),
        '$bpm': _('BPM'),
    }
    preset_items = [
        "%s/$artist/$album/$tracknumber - $title" % os.getenv("HOME")
    ]
    default = "%s/$artist/$album/$tracknumber - $title" % os.getenv("HOME")

# vim: et sts=4 sw=4