1
# -*- coding: utf-8 -*-
2
# Copyright 2004-2005 Joe Wreschnig, Michael Urman, Iñigo Serna
4
# This program is free software; you can redistribute it and/or modify
5
# it under the terms of the GNU General Public License version 2 as
6
# published by the Free Software Foundation
8
# $Id: prefs.py 4330 2008-09-14 03:19:26Z piman $
13
from quodlibet import config
14
from quodlibet import const
15
from quodlibet import player
16
from quodlibet import qltk
17
from quodlibet import util
19
from quodlibet.parse import Query
20
from quodlibet.qltk.ccb import ConfigCheckButton
21
from quodlibet.qltk.chooser import FolderChooser
22
from quodlibet.qltk.entry import ValidatingEntry
23
from quodlibet.qltk.songlist import SongList
25
class PreferencesWindow(qltk.Window):
28
def __new__(klass, parent):
29
if klass.__window is None:
30
return super(PreferencesWindow, klass).__new__(klass)
31
else: return klass.__window
33
class SongList(gtk.VBox):
35
super(PreferencesWindow.SongList, self).__init__(spacing=12)
36
self.set_border_width(12)
37
self.title = _("Song List")
38
vbox = gtk.VBox(spacing=12)
39
tips = qltk.Tooltips(self)
42
table = gtk.Table(3, 3)
43
table.set_homogeneous(True)
44
checks = config.get("settings", "headers").split()
45
for j, l in enumerate(
46
[[("~#disc", _("_Disc")),
47
("album", _("Al_bum")),
48
("~basename",_("_Filename"))],
49
[("~#track", _("_Track")),
50
("artist", _("_Artist")),
51
("~#rating", _("_Rating"))],
52
[("title", util.tag("title")),
54
("~#length",_("_Length"))]]):
55
for i, (k, t) in enumerate(l):
56
buttons[k] = gtk.CheckButton(t)
58
buttons[k].set_active(True)
61
table.attach(buttons[k], i, i + 1, j, j + 1)
63
vbox.pack_start(table, expand=False)
66
tiv = gtk.CheckButton(_("Title includes _version"))
67
if "~title~version" in checks:
68
buttons["title"].set_active(True)
70
checks.remove("~title~version")
71
aip = gtk.CheckButton(_("Album includes _disc subtitle"))
72
if "~album~discsubtitle" in checks:
73
buttons["album"].set_active(True)
75
checks.remove("~album~discsubtitle")
76
fip = gtk.CheckButton(_("Filename includes _folder"))
77
if "~filename" in checks:
78
buttons["~basename"].set_active(True)
80
checks.remove("~filename")
83
t.set_homogeneous(True)
84
t.attach(tiv, 0, 1, 0, 1)
85
t.attach(aip, 0, 1, 1, 2)
86
t.attach(fip, 1, 2, 0, 1)
87
vbox.pack_start(t, expand=False)
89
hbox = gtk.HBox(spacing=6)
90
l = gtk.Label(_("_Others:"))
91
hbox.pack_start(l, expand=False)
93
if "~current" in checks: checks.remove("~current")
94
others.set_text(" ".join(checks))
96
others, _("Other columns to display, separated by spaces"))
97
l.set_mnemonic_widget(others)
98
l.set_use_underline(True)
99
hbox.pack_start(others)
100
vbox.pack_start(hbox, expand=False)
102
apply = gtk.Button(stock=gtk.STOCK_APPLY)
104
'clicked', self.__apply, buttons, tiv, aip, fip, others)
106
b.set_layout(gtk.BUTTONBOX_END)
110
frame = qltk.Frame(_("Visible Columns"), child=vbox)
111
self.pack_start(frame, expand=False)
114
def __apply(self, button, buttons, tiv, aip, fip, others):
116
for key in ["~#disc", "~#track", "title", "album", "artist",
117
"date", "~basename", "~#rating", "~#length"]:
118
if buttons[key].get_active(): headers.append(key)
120
try: headers[headers.index("title")] = "~title~version"
121
except ValueError: pass
123
try: headers[headers.index("album")] = "~album~discsubtitle"
124
except ValueError: pass
126
try: headers[headers.index("~basename")] = "~filename"
127
except ValueError: pass
129
headers.extend(others.get_text().split())
130
if "~current" in headers: headers.remove("~current")
131
headers = [header.lower() for header in headers]
132
SongList.set_all_column_headers(headers)
134
class Browsers(gtk.VBox):
136
super(PreferencesWindow.Browsers, self).__init__(spacing=12)
137
self.set_border_width(12)
138
self.title = _("Browsers")
139
tips = qltk.Tooltips(self)
140
c = ConfigCheckButton(
141
_("Color _search terms"), 'browsers', 'color')
142
c.set_active(config.getboolean("browsers", "color"))
144
c, _("Display simple searches in blue, "
145
"advanced ones in green, and invalid ones in red"))
146
hb = gtk.HBox(spacing=6)
147
l = gtk.Label(_("_Global filter:"))
148
l.set_use_underline(True)
149
e = ValidatingEntry(Query.is_valid_color)
150
e.set_text(config.get("browsers", "background"))
151
e.connect('changed', self._entry, 'background', 'browsers')
152
l.set_mnemonic_widget(e)
153
hb.pack_start(l, expand=False)
155
self.pack_start(hb, expand=False)
157
f = qltk.Frame(_("Search Library"), child=c)
158
self.pack_start(f, expand=False)
160
def _entry(self, entry, name, section="settings"):
161
config.set(section, name, entry.get_text())
163
class Player(gtk.VBox):
165
super(PreferencesWindow.Player, self).__init__(spacing=12)
166
self.set_border_width(12)
167
self.title = _("Player")
169
tips = qltk.Tooltips(self)
170
c = ConfigCheckButton(
171
_("_Jump to playing song automatically"), 'settings', 'jump')
172
tips.set_tip(c, _("When the playing song changes, "
173
"scroll to it in the song list"))
174
c.set_active(config.getboolean("settings", "jump"))
175
self.pack_start(c, expand=False)
177
c = ConfigCheckButton(
178
_("_Replay Gain volume adjustment"), "player", "replaygain")
179
c.set_active(config.getboolean("player", "replaygain"))
180
self.pack_start(c, expand=False)
181
c.connect('toggled', self.__toggled_gain)
184
def __toggled_gain(self, activator):
185
player.playlist.volume = player.playlist.volume
187
class Library(gtk.VBox):
189
super(PreferencesWindow.Library, self).__init__(spacing=12)
190
self.set_border_width(12)
191
self.title = _("Library")
192
hb = gtk.HBox(spacing=6)
193
b = qltk.Button(_("_Select"), gtk.STOCK_OPEN)
195
e.set_text(util.fsdecode(config.get("settings", "scan")))
197
tips = qltk.Tooltips(self)
199
e, _("Songs placed in these folders (separated by ':') "
200
"will be added to your library"))
201
hb.pack_start(b, expand=False)
202
scandirs = config.get("settings", "scan").split(":")
203
if scandirs and os.path.isdir(scandirs[-1]):
204
# start with last added directory
205
initial = scandirs[-1]
208
b.connect('clicked', self.__select, e, initial)
209
e.connect('changed', self.__changed, 'settings', 'scan')
210
f = qltk.Frame(_("Scan _Directories"), child=hb)
211
f.get_label_widget().set_mnemonic_widget(e)
212
self.pack_start(f, expand=False)
214
vbox = gtk.VBox(spacing=6)
215
hb = gtk.HBox(spacing=6)
217
e.set_text(config.get("editing", "split_on"))
218
e.connect('changed', self.__changed, 'editing', 'split_on')
219
tips.set_tip(e, _('Separators for splitting tags'))
220
l = gtk.Label(_("Split _on:"))
221
l.set_use_underline(True)
222
l.set_mnemonic_widget(e)
223
hb.pack_start(l, expand=False)
225
vbox.pack_start(hb, expand=False)
227
vb2 = gtk.VBox(spacing=0)
228
cb = ConfigCheckButton(
229
_("Save ratings and play counts"), "editing", "save_to_songs")
230
cb.set_active(config.getboolean("editing", "save_to_songs"))
232
hb = gtk.HBox(spacing=3)
233
lab = gtk.Label(_("_Email:"))
235
tips.set_tip(entry, _("Ratings and play counts will be set for "
236
"this email address"))
237
entry.set_text(config.get("editing", "save_email"))
238
entry.connect('changed', self.__changed, 'editing', 'save_email')
239
hb.pack_start(lab, expand=False)
241
lab.set_mnemonic_widget(entry)
242
lab.set_use_underline(True)
244
vbox.pack_start(vb2, expand=False)
246
cb = ConfigCheckButton(
247
_("Show _programmatic tags"), 'editing', 'alltags')
248
cb.set_active(config.getboolean("editing", 'alltags'))
249
vbox.pack_start(cb, expand=False)
250
f = qltk.Frame(_("Tag Editing"), child=vbox)
254
def __select(self, button, entry, initial):
255
chooser = FolderChooser(self, _("Select Directories"), initial)
258
if fns: entry.set_text(":".join(map(util.fsdecode, fns)))
260
def __changed(self, entry, section, name):
261
config.set(section, name, entry.get_text())
263
def __init__(self, parent):
264
if type(self).__window: return
265
else: type(self).__window = self
266
super(PreferencesWindow, self).__init__()
267
self.set_title(_("Quod Libet Preferences"))
268
self.set_border_width(12)
269
self.set_resizable(False)
270
self.set_transient_for(qltk.get_top_parent(parent))
272
self.add(qltk.Notebook())
273
for Page in [self.SongList, self.Browsers, self.Player, self.Library]:
274
self.child.append_page(Page())
276
self.connect_object('destroy', PreferencesWindow.__destroy, self)
280
type(self).__window = None
281
config.write(const.CONFIG)