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
):
43 def __init__(self
, mpclient
):
44 plugin
.Plugin
.SettingsWidget
.__init
__(self
, None)
45 self
.mpclient
= mpclient
47 self
.settings
.beginGroup('MPD')
48 self
.host_txt
= QtGui
.QLineEdit(self
.settings
.value('host', 'localhost'))
49 self
.port_txt
= QtGui
.QLineEdit(self
.settings
.value('port', '6600'))
50 self
.port_txt
.setValidator(QtGui
.QIntValidator(0, 65535, self
))
51 self
.pass_txt
= QtGui
.QLineEdit(self
.settings
.value('password'))
52 self
.pass_txt
.setEchoMode(QtGui
.QLineEdit
.Password
)
53 self
.lib_txt
= QtGui
.QLineEdit(self
.settings
.value('music_dir', os
.path
.expanduser('~/music/')))
54 self
.settings
.endGroup()
56 self
.setLayout(QtGui
.QVBoxLayout())
57 self
._add
_widget
(self
.host_txt
, 'Host', 'Host or socket to connect to')
58 self
._add
_widget
(self
.port_txt
, 'Port', 'Port to use (empty when using sockets)')
59 self
._add
_widget
(self
.pass_txt
, 'Password', 'Password')
60 self
._add
_widget
(self
.lib_txt
, 'Music library', 'Path to music library')
62 def save_settings(self
):
65 self
.settings
.beginGroup('MPD')
66 if self
.host_txt
.text() != self
.settings
.value('host'):
67 self
.settings
.setValue('host', self
.host_txt
.text())
69 if self
.port_txt
.text() != self
.settings
.value('port'):
70 self
.settings
.setValue('port', self
.port_txt
.text())
72 if self
.pass_txt
.text() != self
.settings
.value('password'):
73 self
.settings
.setValue('password', self
.pass_txt
.text())
74 if self
.pass_txt
.text():
75 self
.mpclient
.password(self
.pass_txt
.text())
76 self
.settings
.setValue('music_dir', self
.lib_txt
.text())
77 self
.settings
.endGroup()
80 self
.mpclient
.disconnect_mpd()
81 self
.mpclient
.connect_mpd(self
.host_txt
.text(), int(self
.port_txt
.text()), self
.pass_txt
.text())
83 def __init__(self
, mpclient
, plugins
):
84 QtGui
.QWidget
.__init
__(self
, None, QtCore
.Qt
.Window
)
85 self
.settings
= QtCore
.QSettings()
86 self
.plugins
= plugins
87 self
.mpclient
= mpclient
89 self
.save_btn
= Button('save all', self
.save_clicked
)
90 self
.close_btn
= Button('close', self
.close_clicked
)
92 tab_wg
= QtGui
.QTabWidget(self
)
94 self
.settings_wg
.append(self
.SettingsWidgetMPD(mpclient
))
95 tab_wg
.addTab(self
.settings_wg
[-1], 'MPD settings')
97 self
.pluginlist
= QtGui
.QListWidget(self
)
98 self
.fill_pluginlist()
99 tab_wg
.addTab(self
.pluginlist
, 'Plugins')
101 for plugin
in self
.plugins
.loaded_plugins():
102 wg
= plugin
.get_settings_widget()
104 self
.settings_wg
.append(wg
)
105 tab_wg
.addTab(self
.settings_wg
[-1], plugin
.name
)
107 self
.setLayout(QtGui
.QGridLayout())
108 self
.layout().addWidget(tab_wg
, 0, 0, 1, 2)
109 self
.layout().addWidget(self
.save_btn
, 1, 0)
110 self
.layout().addWidget(self
.close_btn
, 1, 1)
112 self
.pluginlist
.itemChanged
.connect(self
.plugin_checked
)
114 self
.setWindowTitle('Settings')
115 self
.setAttribute(QtCore
.Qt
.WA_DeleteOnClose
)
119 def fill_pluginlist(self
):
120 self
.pluginlist
.clear()
121 for plugin
in self
.plugins
.plugins():
122 item
= QtGui
.QListWidgetItem("%s\t%s"%(plugin
.name
, plugin
.info
))
124 item
.setCheckState(QtCore
.Qt
.Checked
)
126 item
.setCheckState(QtCore
.Qt
.Unchecked
)
128 self
.pluginlist
.addItem(item
)
131 screen
= QtGui
.QDesktopWidget().screenGeometry()
132 size
= self
.geometry()
133 self
.move((screen
.width()-size
.width())/2, (screen
.height()-size
.height())/2+100)
135 def save_clicked(self
):
136 for wg
in self
.settings_wg
:
139 def close_clicked(self
):
142 def plugin_checked(self
, item
):
143 toload
= int(item
.checkState() == QtCore
.Qt
.Checked
)
144 name
= str(item
.text()[0:str(item
.text()).find('\t')])
146 # refresh the plugin file
147 self
.plugins
.load(name
)
148 self
.fill_pluginlist()
150 self
.plugins
.unload(name
)
151 self
.settings
.setValue(name
+ '/load', toload
)
153 def closeEvent(self
, event
):