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
)
75 self
.setLayout(QtGui
.QVBoxLayout())
76 self
._add
_widget
(self
.host_txt
, 'Host', 'Host or socket to connect to')
77 self
._add
_widget
(self
.port_txt
, 'Port', 'Port to use (empty when using sockets)')
78 self
._add
_widget
(self
.pass_txt
, 'Password', 'Password')
79 self
._add
_widget
(self
.lib_txt
, 'Music library', 'Path to music library')
80 self
.layout().addWidget(self
.update
)
81 self
.layout().addWidget(outputs
)
83 def save_settings(self
):
86 self
.settings
.beginGroup('MPD')
87 if self
.host_txt
.text() != self
.settings
.value('host'):
88 self
.settings
.setValue('host', self
.host_txt
.text())
90 if self
.port_txt
.text() != self
.settings
.value('port'):
91 self
.settings
.setValue('port', self
.port_txt
.text())
93 if self
.pass_txt
.text() != self
.settings
.value('password'):
94 self
.settings
.setValue('password', self
.pass_txt
.text())
95 if self
.pass_txt
.text():
96 self
.mpclient
.password(self
.pass_txt
.text())
97 self
.settings
.setValue('music_dir', self
.lib_txt
.text())
98 self
.settings
.endGroup()
101 self
.mpclient
.disconnect_mpd()
102 self
.mpclient
.connect_mpd(self
.host_txt
.text(), int(self
.port_txt
.text()), self
.pass_txt
.text())
105 self
.mpclient
.update_db()
107 def __init__(self
, mpclient
, plugins
):
108 QtGui
.QWidget
.__init
__(self
, None, QtCore
.Qt
.Window
)
109 self
.settings
= QtCore
.QSettings()
110 self
.plugins
= plugins
111 self
.mpclient
= mpclient
113 self
.save_btn
= Button('save all', self
.save_clicked
)
114 self
.close_btn
= Button('close', self
.close_clicked
)
116 tab_wg
= QtGui
.QTabWidget(self
)
117 self
.settings_wg
= []
118 self
.settings_wg
.append(self
.SettingsWidgetMPD(mpclient
))
119 tab_wg
.addTab(self
.settings_wg
[-1], 'MPD settings')
121 self
.pluginlist
= QtGui
.QListWidget(self
)
122 self
.fill_pluginlist()
123 tab_wg
.addTab(self
.pluginlist
, 'Plugins')
125 for plugin
in self
.plugins
.loaded_plugins():
126 wg
= plugin
.get_settings_widget()
128 self
.settings_wg
.append(wg
)
129 tab_wg
.addTab(self
.settings_wg
[-1], plugin
.name
)
131 self
.setLayout(QtGui
.QGridLayout())
132 self
.layout().addWidget(tab_wg
, 0, 0, 1, 2)
133 self
.layout().addWidget(self
.save_btn
, 1, 0)
134 self
.layout().addWidget(self
.close_btn
, 1, 1)
136 self
.pluginlist
.itemChanged
.connect(self
.plugin_checked
)
138 self
.setWindowTitle('Settings')
139 self
.setAttribute(QtCore
.Qt
.WA_DeleteOnClose
)
143 def fill_pluginlist(self
):
144 self
.pluginlist
.clear()
145 for plugin
in self
.plugins
.plugins():
146 item
= QtGui
.QListWidgetItem("%s\t%s"%(plugin
.name
, plugin
.info
))
148 item
.setCheckState(QtCore
.Qt
.Checked
)
150 item
.setCheckState(QtCore
.Qt
.Unchecked
)
152 self
.pluginlist
.addItem(item
)
155 screen
= QtGui
.QDesktopWidget().screenGeometry()
156 size
= self
.geometry()
157 self
.move((screen
.width()-size
.width())/2, (screen
.height()-size
.height())/2+100)
159 def save_clicked(self
):
160 for wg
in self
.settings_wg
:
163 def close_clicked(self
):
166 def plugin_checked(self
, item
):
167 toload
= int(item
.checkState() == QtCore
.Qt
.Checked
)
168 name
= str(item
.text()[0:str(item
.text()).find('\t')])
170 # refresh the plugin file
171 self
.plugins
.load(name
)
172 self
.fill_pluginlist()
174 self
.plugins
.unload(name
)
175 self
.settings
.setValue(name
+ '/load', toload
)
177 def closeEvent(self
, event
):