changeset 5:f48a0a320815

implement basic command forking when double-clicking an entry in the host list
author Dirk Olmes <dirk@xanthippe.ping.de>
date Sat, 20 Sep 2014 05:18:05 +0200
parents 8905b45cf9fb
children 369bc16e7441
files RemoteViewer/Connection.py RemoteViewer/RemoteViewer.py RemoteViewer/RemoteViewer.ui RemoteViewer/Viewer.py
diffstat 4 files changed, 54 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- 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)
--- 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()
--- 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 @@
     </hint>
    </hints>
   </connection>
+  <connection>
+   <sender>hostList</sender>
+   <signal>doubleClicked(QModelIndex)</signal>
+   <receiver>RemoteViewer</receiver>
+   <slot>openConnection(QModelIndex)</slot>
+   <hints>
+    <hint type="sourcelabel">
+     <x>50</x>
+     <y>118</y>
+    </hint>
+    <hint type="destinationlabel">
+     <x>3</x>
+     <y>84</y>
+    </hint>
+   </hints>
+  </connection>
  </connections>
  <slots>
   <slot>newConnection()</slot>
+  <slot>openConnection(QModelIndex)</slot>
  </slots>
 </ui>
--- /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