Lyrics: print an error if importing Lyricwiki client fails.
[nephilim.git] / nephilim / connect_wg.py
blob8df84f122144f576c7b882c679a909b1113e61d7
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 from PyQt4.QtCore import QVariant
21 import time
23 class ConnectWidget(QtGui.QWidget):
24 host_txt = None
25 port_txt = None
26 pass_txt = None
27 connect_btn = None
28 mpclient = None
29 settings = None
31 def __init__(self):
32 QtGui.QWidget.__init__(self)
33 self.mpclient = QtGui.QApplication.instance().mpclient
34 self.settings = QtCore.QSettings()
36 self.host_txt = QtGui.QLineEdit(self.settings.value('MPD/host', QVariant('localhost')).toString())
37 self.host_txt.setToolTip('Host')
39 self.port_txt = QtGui.QLineEdit(self.settings.value('MPD/port', QVariant('6600')).toString())
40 self.port_txt.setValidator(QtGui.QIntValidator(1, 65535, self.port_txt))
41 self.port_txt.setToolTip('Port')
43 self.pass_txt = QtGui.QLineEdit(self.settings.value('MPD/password').toString())
44 self.pass_txt.setEchoMode(QtGui.QLineEdit.Password)
45 self.pass_txt.setToolTip('Password')
47 self.connect_btn = QtGui.QPushButton('Connect')
48 self.connect(self.connect_btn, QtCore.SIGNAL('clicked()'), self.connect_mpd)
50 self.setLayout(QtGui.QGridLayout())
51 self.layout().addWidget(QtGui.QLabel('host:port:password'), 0, 0, 1, 3, QtCore.Qt.AlignHCenter)
52 self.layout().addWidget(self.host_txt, 1, 0)
53 self.layout().addWidget(self.port_txt, 1, 1)
54 self.layout().addWidget(self.pass_txt, 1, 2)
55 self.layout().addWidget(self.connect_btn, 2, 0, 1, 3, QtCore.Qt.AlignHCenter)
57 self.setWindowTitle('Connect to MPD')
58 self.center()
60 self.connect(self.mpclient, QtCore.SIGNAL('connected'), self.on_connected)
62 def center(self):
63 screen = QtGui.QDesktopWidget().screenGeometry()
64 size = self.geometry()
65 self.move((screen.width()-size.width())/2, (screen.height()-size.height())/2+100)
67 def monitor(self):
68 self.show()
69 self.activateWindow()
70 self.raise_()
71 if self.host_txt:
72 self.connect_mpd()
74 def connect_mpd(self):
75 host = str(self.host_txt.text())
76 port = int(self.port_txt.text()) if self.port_txt.text() else None
77 passw = str(self.pass_txt.text())
79 self.mpclient.connect_mpd(host, port, passw)
81 def on_connected(self):
82 self.settings.setValue('MPD/host', QVariant(self.host_txt.text()))
83 self.settings.setValue('MPD/port', QVariant(self.port_txt.text()))
84 self.settings.setValue('MPD/password', QVariant(self.pass_txt.text()))
85 self.hide()