common: split MetadataFetcher into its own file
[nephilim.git] / nephilim / connect_wg.py
blobe237527f74258d68691694be0589bfb5f25a052e
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
20 import time
22 class ConnectWidget(QtGui.QWidget):
23 host_txt = None
24 port_txt = None
25 pass_txt = None
26 connect_btn = None
27 mpclient = None
28 settings = None
30 def __init__(self):
31 QtGui.QWidget.__init__(self)
32 self.mpclient = QtGui.QApplication.instance().mpclient
33 self.settings = QtCore.QSettings()
35 self.host_txt = QtGui.QLineEdit(self.settings.value('MPD/host', 'localhost'))
36 self.host_txt.setToolTip('Host')
38 self.port_txt = QtGui.QLineEdit(self.settings.value('MPD/port', '6600'))
39 self.port_txt.setValidator(QtGui.QIntValidator(1, 65535, self.port_txt))
40 self.port_txt.setToolTip('Port')
42 self.pass_txt = QtGui.QLineEdit(self.settings.value('MPD/password'))
43 self.pass_txt.setEchoMode(QtGui.QLineEdit.Password)
44 self.pass_txt.setToolTip('Password')
46 self.connect_btn = QtGui.QPushButton('Connect')
47 self.connect(self.connect_btn, QtCore.SIGNAL('clicked()'), self.connect_mpd)
49 self.setLayout(QtGui.QGridLayout())
50 self.layout().addWidget(QtGui.QLabel('host:port:password'), 0, 0, 1, 3, QtCore.Qt.AlignHCenter)
51 self.layout().addWidget(self.host_txt, 1, 0)
52 self.layout().addWidget(self.port_txt, 1, 1)
53 self.layout().addWidget(self.pass_txt, 1, 2)
54 self.layout().addWidget(self.connect_btn, 2, 0, 1, 3, QtCore.Qt.AlignHCenter)
56 self.setWindowTitle('Connect to MPD')
57 self.center()
59 self.mpclient.connect_changed.connect(self.on_connected)
61 def center(self):
62 screen = QtGui.QDesktopWidget().screenGeometry()
63 size = self.geometry()
64 self.move((screen.width()-size.width())/2, (screen.height()-size.height())/2+100)
66 def monitor(self):
67 self.show()
68 self.activateWindow()
69 self.raise_()
70 if self.host_txt:
71 self.connect_mpd()
73 def connect_mpd(self):
74 host = str(self.host_txt.text())
75 port = int(self.port_txt.text()) if self.port_txt.text() else None
76 passw = str(self.pass_txt.text())
78 self.mpclient.connect_mpd(host, port, passw)
80 def on_connected(self, val):
81 if val:
82 self.settings.setValue('MPD/host', self.host_txt.text())
83 self.settings.setValue('MPD/port', self.port_txt.text())
84 self.settings.setValue('MPD/password', self.pass_txt.text())
85 self.hide()