2 # Copyright (C) 2008 jerous <jerous@gmail.com>
3 # Copyright (C) 2009 Anton Khirnov <wyskas@gmail.com>
5 # Nephilim is free software: you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation, either version 3 of the License, or
8 # (at your option) any later version.
10 # Nephilim is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with Nephilim. If not, see <http://www.gnu.org/licenses/>.
19 from PyQt4
import QtGui
, QtCore
22 from common
import Button
26 class SettingsWidget(QtGui
.QWidget
):
36 class SettingsWidgetMPD(plugin
.Plugin
.SettingsWidget
):
45 def __init__(self
, mpclient
):
46 plugin
.Plugin
.SettingsWidget
.__init
__(self
, None)
47 self
.mpclient
= mpclient
49 self
.settings
.beginGroup('MPD')
50 self
.host_txt
= QtGui
.QLineEdit(self
.settings
.value('host', 'localhost'))
51 self
.port_txt
= QtGui
.QLineEdit(self
.settings
.value('port', '6600'))
52 self
.port_txt
.setValidator(QtGui
.QIntValidator(0, 65535, self
))
53 self
.pass_txt
= QtGui
.QLineEdit(self
.settings
.value('password'))
54 self
.pass_txt
.setEchoMode(QtGui
.QLineEdit
.Password
)
55 self
.lib_txt
= QtGui
.QLineEdit(self
.settings
.value('music_dir', os
.path
.expanduser('~/music/')))
56 self
.settings
.endGroup()
58 self
.update
= QtGui
.QPushButton('Update MPD database')
59 self
.update
.clicked
.connect(self
.update_db
)
61 outputs
= QtGui
.QGroupBox('Audio outputs')
62 outputs
.setLayout(QtGui
.QVBoxLayout())
64 for output
in self
.mpclient
.outputs
:
65 box
= QtGui
.QCheckBox(output
.name
, self
)
70 box
.clicked
.connect(output
.set_state
)
71 output
.state_changed
.connect(box
.setChecked
)
72 outputs
.layout().addWidget(box
)
74 self
.xfade
= QtGui
.QSpinBox()
75 self
.xfade
.setValue(int(self
.mpclient
.status
['xfade']))
76 self
.xfade
.valueChanged
.connect(self
.mpclient
.crossfade
)
78 self
.setLayout(QtGui
.QVBoxLayout())
79 self
._add
_widget
(self
.host_txt
, 'Host', 'Host or socket to connect to')
80 self
._add
_widget
(self
.port_txt
, 'Port', 'Port to use (empty when using sockets)')
81 self
._add
_widget
(self
.pass_txt
, 'Password', 'Password')
82 self
._add
_widget
(self
.lib_txt
, 'Music library', 'Path to music library')
83 self
.layout().addWidget(self
.update
)
84 self
.layout().addWidget(outputs
)
85 self
._add
_widget
(self
.xfade
, 'Crossfade', 'Set crossfade between songs (in seconds).')
87 def save_settings(self
):
90 self
.settings
.beginGroup('MPD')
91 if self
.host_txt
.text() != self
.settings
.value('host'):
92 self
.settings
.setValue('host', self
.host_txt
.text())
94 if self
.port_txt
.text() != self
.settings
.value('port'):
95 self
.settings
.setValue('port', self
.port_txt
.text())
97 if self
.pass_txt
.text() != self
.settings
.value('password'):
98 self
.settings
.setValue('password', self
.pass_txt
.text())
99 if self
.pass_txt
.text():
100 self
.mpclient
.password(self
.pass_txt
.text())
101 self
.settings
.setValue('music_dir', self
.lib_txt
.text())
102 self
.settings
.endGroup()
105 self
.mpclient
.disconnect_mpd()
106 self
.mpclient
.connect_mpd(self
.host_txt
.text(), int(self
.port_txt
.text()), self
.pass_txt
.text())
109 self
.mpclient
.update_db()
111 def __init__(self
, mpclient
, plugins
):
112 QtGui
.QWidget
.__init
__(self
, None, QtCore
.Qt
.Window
)
113 self
.settings
= QtCore
.QSettings()
114 self
.plugins
= plugins
115 self
.mpclient
= mpclient
117 self
.save_btn
= Button('save all', self
.save_clicked
)
118 self
.close_btn
= Button('close', self
.close_clicked
)
120 tab_wg
= QtGui
.QTabWidget(self
)
121 self
.settings_wg
= []
122 self
.settings_wg
.append(self
.SettingsWidgetMPD(mpclient
))
123 tab_wg
.addTab(self
.settings_wg
[-1], 'MPD settings')
125 self
.pluginlist
= QtGui
.QListWidget(self
)
126 self
.fill_pluginlist()
127 tab_wg
.addTab(self
.pluginlist
, 'Plugins')
129 for plugin
in self
.plugins
.loaded_plugins():
130 wg
= plugin
.get_settings_widget()
132 self
.settings_wg
.append(wg
)
133 tab_wg
.addTab(self
.settings_wg
[-1], plugin
.name
)
135 self
.setLayout(QtGui
.QGridLayout())
136 self
.layout().addWidget(tab_wg
, 0, 0, 1, 2)
137 self
.layout().addWidget(self
.save_btn
, 1, 0)
138 self
.layout().addWidget(self
.close_btn
, 1, 1)
140 self
.pluginlist
.itemChanged
.connect(self
.plugin_checked
)
142 self
.setWindowTitle('Settings')
143 self
.setAttribute(QtCore
.Qt
.WA_DeleteOnClose
)
147 def fill_pluginlist(self
):
148 self
.pluginlist
.clear()
149 for plugin
in self
.plugins
.plugins():
150 item
= QtGui
.QListWidgetItem("%s\t%s"%(plugin
.name
, plugin
.info
))
152 item
.setCheckState(QtCore
.Qt
.Checked
)
154 item
.setCheckState(QtCore
.Qt
.Unchecked
)
156 self
.pluginlist
.addItem(item
)
159 screen
= QtGui
.QDesktopWidget().screenGeometry()
160 size
= self
.geometry()
161 self
.move((screen
.width()-size
.width())/2, (screen
.height()-size
.height())/2+100)
163 def save_clicked(self
):
164 for wg
in self
.settings_wg
:
167 def close_clicked(self
):
170 def plugin_checked(self
, item
):
171 toload
= int(item
.checkState() == QtCore
.Qt
.Checked
)
172 name
= str(item
.text()[0:str(item
.text()).find('\t')])
174 # refresh the plugin file
175 self
.plugins
.load(name
)
176 self
.fill_pluginlist()
178 self
.plugins
.unload(name
)
179 self
.settings
.setValue(name
+ '/load', toload
)
181 def closeEvent(self
, event
):