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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
|
#
# Copyright (C) 2008 jerous <jerous@gmail.com>
# Copyright (C) 2009 Anton Khirnov <wyskas@gmail.com>
#
# Nephilim 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 3 of the License, or
# (at your option) any later version.
#
# Nephilim 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 Nephilim. If not, see <http://www.gnu.org/licenses/>.
#
from PyQt4 import QtGui, QtCore
from PyQt4.QtCore import QVariant
import os
from misc import Button
import plugin
class SettingsWidget(QtGui.QWidget):
save_btn = None
close_btn = None
pluginlist = None
settings = None
settings_wg = []
mpclient = None
plugins = None
class SettingsWidgetMPD(plugin.Plugin.SettingsWidget):
mpclient = None
host_txt = None
port_txt = None
pass_txt = None
lib_txt = None
update = None
outputs = None
xfade = None
def __init__(self, mpclient):
plugin.Plugin.SettingsWidget.__init__(self, None)
self.mpclient = mpclient
self.settings.beginGroup('MPD')
self.host_txt = QtGui.QLineEdit(self.settings.value('host', QVariant('localhost')).toString())
self.port_txt = QtGui.QLineEdit(self.settings.value('port', QVariant('6600')).toString())
self.pass_txt = QtGui.QLineEdit(self.settings.value('password').toString())
self.pass_txt.setEchoMode(QtGui.QLineEdit.Password)
self.lib_txt = QtGui.QLineEdit(self.settings.value('music_dir', QVariant(os.path.expanduser('~/music/'))).toString())
self.settings.endGroup()
self.update = QtGui.QPushButton('Update MPD database')
self.connect(self.update, QtCore.SIGNAL('clicked()'), self.update_db)
self.outputs = QtGui.QGroupBox('Audio outputs')
self.outputs.setLayout(QtGui.QVBoxLayout())
class Output(QtGui.QCheckBox):
id = None
mpclient = None
def __init__(self, text, mpclient, id):
QtGui.QCheckBox.__init__(self, text)
self.mpclient = mpclient
self.id = id
self.connect(self, QtCore.SIGNAL('stateChanged(int)'), self.change_state)
def change_state(self, state):
self.mpclient.set_output(self.id, state)
for output in self.mpclient.outputs():
box = Output(output['outputname'], self.mpclient, output['outputid'])
if output['outputenabled'] == '1':
box.setChecked(True)
else:
box.setChecked(False)
self.outputs.layout().addWidget(box)
self.xfade = QtGui.QSpinBox()
self.xfade.setValue(int(self.mpclient.status()['xfade']))
self.connect(self.xfade, QtCore.SIGNAL('valueChanged(int)'), self.mpclient.crossfade)
self.setLayout(QtGui.QVBoxLayout())
self._add_widget(self.host_txt, 'Host', 'Host or socket to connect to')
self._add_widget(self.port_txt, 'Port', 'Port to use (empty when using sockets)')
self._add_widget(self.pass_txt, 'Password', 'Password')
self._add_widget(self.lib_txt, 'Music library', 'Path to music library')
self.layout().addWidget(self.update)
self.layout().addWidget(self.outputs)
self._add_widget(self.xfade, 'Crossfade', 'Set crossfade between songs (in seconds).')
def save_settings(self):
reconnect = False
self.settings.beginGroup('MPD')
if self.host_txt.text() != self.settings.value('host').toString():
self.settings.setValue('host', QVariant(self.host_txt.text()))
reconnect = True
if self.port_txt.text() != self.settings.value('port').toString():
self.settings.setValue('port', QVariant(self.port_txt.text()))
reconnect = True
if self.pass_txt.text() != self.settings.value('password').toString():
self.settings.setValue('password', QVariant(self.pass_txt.text()))
if self.pass_txt.text():
self.mpclient.password(self.pass_txt.text())
self.settings.setValue('music_dir', QVariant(self.lib_txt.text()))
self.settings.endGroup()
if reconnect:
self.mpclient.disconnect_mpd()
self.mpclient.connect_mpd(str(self.host_txt.text()), str(self.port_txt.text()), str(self.pass_txt.text()))
def update_db(self):
self.mpclient.update_db()
def __init__(self, mpclient, plugins):
QtGui.QWidget.__init__(self, None, QtCore.Qt.Window)
self.settings = QtCore.QSettings()
self.plugins = plugins
self.mpclient = mpclient
self.save_btn = Button('save all', self.save_clicked)
self.close_btn = Button('close', self.close_clicked)
tab_wg = QtGui.QTabWidget(self)
self.settings_wg.append(self.SettingsWidgetMPD(mpclient))
tab_wg.addTab(self.settings_wg[-1], 'MPD settings')
self.pluginlist = QtGui.QListWidget(self)
self.fill_pluginlist()
tab_wg.addTab(self.pluginlist, 'Plugins')
for plugin in self.plugins.loaded_plugins():
wg = plugin.get_settings_widget()
if wg:
self.settings_wg.append(wg)
tab_wg.addTab(self.settings_wg[-1], plugin.name)
self.setLayout(QtGui.QGridLayout())
self.layout().addWidget(tab_wg, 0, 0, 1, 2)
self.layout().addWidget(self.save_btn, 1, 0)
self.layout().addWidget(self.close_btn, 1, 1)
self.connect(self.pluginlist, QtCore.SIGNAL('itemChanged(QListWidgetItem*)'), self.plugin_checked)
self.setWindowTitle('Settings')
self.setAttribute(QtCore.Qt.WA_DeleteOnClose)
self.center()
self.resize(800,400)
def fill_pluginlist(self):
self.pluginlist.clear()
for plugin in self.plugins.plugins():
item = QtGui.QListWidgetItem("%s\t%s"%(plugin.name, plugin.info()))
if plugin.loaded:
item.setCheckState(QtCore.Qt.Checked)
else:
item.setCheckState(QtCore.Qt.Unchecked)
self.pluginlist.addItem(item)
def center(self):
screen = QtGui.QDesktopWidget().screenGeometry()
size = self.geometry()
self.move((screen.width()-size.width())/2, (screen.height()-size.height())/2+100)
def save_clicked(self):
for wg in self.settings_wg:
wg.save_settings
def close_clicked(self):
self.close()
def plugin_checked(self, item):
toload = (item.checkState() == QtCore.Qt.Checked)
name = str(item.text()[0:str(item.text()).find('\t')])
if toload:
# refresh the plugin file
self.plugins.load(name)
self.fill_pluginlist()
else:
self.plugins.unload(name)
self.settings.setValue(name + '/load', QtCore.QVariant(toload))
def closeEvent(self, event):
self.settings_wg = None
|