# HG changeset patch # User Dirk Olmes # Date 1412298297 -7200 # Node ID fb7442228526c469c7a9e65b289a6803b470664f # Parent c0ef1794e27568dc1590c8fc7ec4dacc1764a260 if configured, prompt for password before connecting diff -r c0ef1794e275 -r fb7442228526 RemoteViewer/Connection.py --- a/RemoteViewer/Connection.py Fri Sep 26 07:48:25 2014 +0200 +++ b/RemoteViewer/Connection.py Fri Oct 03 03:04:57 2014 +0200 @@ -1,7 +1,7 @@ from uuid import uuid4 from .Viewer import VncViewer, FreeRdp -KEYS = ['geometry', 'id', 'host', 'lowColor', 'title', 'type', 'user'] +KEYS = ['geometry', 'id', 'host', 'lowColor', 'promptForPassword', 'title', 'type', 'user'] def filter_string(func): """decorator function to filter turn empty strings into None""" @@ -23,12 +23,13 @@ def __init__(self): self.geometry = None + self.host = None self.id = str(uuid4()) - self.host = None + self.lowColor = False + self.promptForPassword = False self.title = None self.type = 'vnc' self.user = None - self.lowColor = False def __str__(self): return 'connection@{} "{}" of type {} to {} with user {} and geometry {}'.format(self.title, id(self), self.type, self.host, self.user, self.geometry) @@ -52,6 +53,10 @@ """This is a slot that is connected to a signal in the GUI""" self.user = user + def setPromptForPassword(self, flag): + """This is a slot that is connected to a signal in the GUI""" + self.promptForPassword = flag + @filter_string def setGeometry(self, geometry): """This is a slot that is connected to a signal in the GUI""" diff -r c0ef1794e275 -r fb7442228526 RemoteViewer/ConnectionDialog.py --- a/RemoteViewer/ConnectionDialog.py Fri Sep 26 07:48:25 2014 +0200 +++ b/RemoteViewer/ConnectionDialog.py Fri Oct 03 03:04:57 2014 +0200 @@ -30,17 +30,22 @@ self.ui.type.setCurrentIndex(index) self.ui.hostname.setText(self.connection.host) self.ui.username.setText(self.connection.user) + self.__initCheckbox(self.ui.promptForPassword, self.connection.promptForPassword) self.ui.geometry.setText(self.connection.geometry) + self.__initCheckbox(self.ui.lowColor, self.connection.lowColor) + + def __initCheckbox(self, checkbox, value): checkState = Qt.Unchecked - if self.connection.lowColor is True: + if value is True: checkState = Qt.Checked - self.ui.lowColor.setCheckState(checkState) + checkbox.setCheckState(checkState) def __connectWidgetSlots(self): self.ui.title.textChanged.connect(self.connection.setTitle) self.ui.type.activated[str].connect(self.connection.setType) self.ui.hostname.textChanged.connect(self.connection.setHost) self.ui.username.textChanged.connect(self.connection.setUser) + self.ui.promptForPassword.clicked[bool].connect(self.connection.setPromptForPassword) self.ui.geometry.textChanged.connect(self.connection.setGeometry) self.ui.lowColor.clicked[bool].connect(self.connection.setLowColor) diff -r c0ef1794e275 -r fb7442228526 RemoteViewer/ConnectionDialog.ui --- a/RemoteViewer/ConnectionDialog.ui Fri Sep 26 07:48:25 2014 +0200 +++ b/RemoteViewer/ConnectionDialog.ui Fri Oct 03 03:04:57 2014 +0200 @@ -7,7 +7,7 @@ 0 0 400 - 233 + 263 @@ -54,7 +54,7 @@ - + Geometry: @@ -67,7 +67,7 @@ - + Qt::Horizontal @@ -77,7 +77,7 @@ - + @@ -93,20 +93,34 @@ - + - + Low Color: + + + + + + + + + + + <html><head/><body><p>Password:</p></body></html> + + + diff -r c0ef1794e275 -r fb7442228526 RemoteViewer/PasswordDialog.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/RemoteViewer/PasswordDialog.py Fri Oct 03 03:04:57 2014 +0200 @@ -0,0 +1,25 @@ +from PyQt4.QtGui import QDialog +from .Ui_PasswordDialog import Ui_PasswordDialog + +class PasswordDialog(QDialog): + def __init__(self, connection): + super(PasswordDialog, self).__init__() + self.__initUi() + self.__setTitle(connection) + self.__setUserLabel(connection) + + def __initUi(self): + self.ui = Ui_PasswordDialog() + self.ui.setupUi(self) + + def __setTitle(self, connection): + title = 'Password for ' + connection.displayString() + self.setWindowTitle(title) + + def __setUserLabel(self, connection): + label = 'User: ' + connection.user + self.ui.user.setText(label) + + def accept(self): + self.password = self.ui.password.text() + super(PasswordDialog, self).accept() diff -r c0ef1794e275 -r fb7442228526 RemoteViewer/PasswordDialog.ui --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/RemoteViewer/PasswordDialog.ui Fri Oct 03 03:04:57 2014 +0200 @@ -0,0 +1,78 @@ + + + PasswordDialog + + + + 0 + 0 + 400 + 103 + + + + Dialog + + + + + + + + + + + + + QLineEdit::Password + + + + + + + Qt::Horizontal + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + + + + + + + buttonBox + accepted() + PasswordDialog + accept() + + + 248 + 254 + + + 157 + 274 + + + + + buttonBox + rejected() + PasswordDialog + reject() + + + 316 + 260 + + + 286 + 274 + + + + + diff -r c0ef1794e275 -r fb7442228526 RemoteViewer/Viewer.py --- a/RemoteViewer/Viewer.py Fri Sep 26 07:48:25 2014 +0200 +++ b/RemoteViewer/Viewer.py Fri Oct 03 03:04:57 2014 +0200 @@ -2,6 +2,7 @@ from threading import Thread from .LogViewer import LogViewer +from .PasswordDialog import PasswordDialog class ReadThread(Thread): def __init__(self, process, viewer): @@ -27,11 +28,26 @@ self.process = None def open(self, parent): + if not self.__runPasswordDialog(): + return self.buildCommand() - self.process = subprocess.Popen(self.command, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) + self.process = subprocess.Popen(self.command, stdin=subprocess.PIPE, + stdout=subprocess.PIPE, stderr=subprocess.STDOUT) self.__startLogThread() self.process.wait() + def __runPasswordDialog(self): + if self.connection.promptForPassword: + dialog = PasswordDialog(self.connection) + success = dialog.exec_() + if success: + self.connection.password = dialog.password + return True + else: + return False + else: + return True + def __startLogThread(self): logViewer = self.__createLogViewer() readThread = ReadThread(self.process, logViewer) @@ -66,6 +82,8 @@ self.append('/v:', self.connection.host) self.append('/t:', self.connection.displayString()) self.append('/u:', self.connection.user) + if self.connection.password is not None: + self.append('/p:', self.connection.password) self.append('/size:', self.connection.geometry) if self.connection.lowColor: self.command.append('/bpp:8')