# HG changeset patch # User Dirk Olmes # Date 1411183085 -7200 # Node ID f48a0a3208151feaac5e19f72e043c2823632478 # Parent 8905b45cf9fb321474152e294012d8fc0475ce58 implement basic command forking when double-clicking an entry in the host list diff -r 8905b45cf9fb -r f48a0a320815 RemoteViewer/Connection.py --- a/RemoteViewer/Connection.py Sat Sep 20 04:46:59 2014 +0200 +++ b/RemoteViewer/Connection.py Sat Sep 20 05:18:05 2014 +0200 @@ -1,3 +1,5 @@ + +from .Viewer import VncViewer, FreeRdp KEYS = ['geometry', 'host', 'title', 'type', 'user'] @@ -52,3 +54,11 @@ if hasattr(self, key): json[key] = getattr(self, key) return json + + def open(self): + if self.type == 'vnc': + VncViewer(self).open() + elif self.type == 'rdp': + FreeRdp(self).open() + else: + raise ValueError('unknown type: ' + self.type) diff -r 8905b45cf9fb -r f48a0a320815 RemoteViewer/RemoteViewer.py --- a/RemoteViewer/RemoteViewer.py Sat Sep 20 04:46:59 2014 +0200 +++ b/RemoteViewer/RemoteViewer.py Sat Sep 20 05:18:05 2014 +0200 @@ -31,6 +31,11 @@ connection = dialog.connection self.settings.addConnection(connection) + @ExceptionSafeSlot('QModelIndex') + def openConnection(self, index): + connection = index.internalPointer() + connection.open() + def close(self): self.settings.persist() super(RemoteViewer, self).close() diff -r 8905b45cf9fb -r f48a0a320815 RemoteViewer/RemoteViewer.ui --- a/RemoteViewer/RemoteViewer.ui Sat Sep 20 04:46:59 2014 +0200 +++ b/RemoteViewer/RemoteViewer.ui Sat Sep 20 05:18:05 2014 +0200 @@ -91,8 +91,25 @@ + + hostList + doubleClicked(QModelIndex) + RemoteViewer + openConnection(QModelIndex) + + + 50 + 118 + + + 3 + 84 + + + newConnection() + openConnection(QModelIndex) diff -r 8905b45cf9fb -r f48a0a320815 RemoteViewer/Viewer.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/RemoteViewer/Viewer.py Sat Sep 20 05:18:05 2014 +0200 @@ -0,0 +1,22 @@ +import subprocess + +class AbstractViewer(object): + def __init__(self, connection): + self.connection = connection + + def open(self): + command = self.buildCommand() + print(command) + subprocess.call(command) + +class VncViewer(AbstractViewer): + def buildCommand(self): + return ['vncviewer', self.connection.host] + +class FreeRdp(AbstractViewer): + def buildCommand(self): + command = ['xfreerdp', '/v:' + self.connection.host] + user = self.connection.user + if user is not None: + command.append('/u:' + user) + return command