[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[virt-tools-list] [PATCH virt-viewer] vnc: add connection by file



Learn to connect to a VNC server with the connection details file, ex:

[virt-viewer]
type=vnc
host=localhost
port=2356

https://bugzilla.redhat.com/show_bug.cgi?id=843410
---
 src/virt-viewer-app.c         |  2 +-
 src/virt-viewer-session-vnc.c | 47 +++++++++++++++++++++++++++----------------
 src/virt-viewer-session-vnc.h |  2 +-
 3 files changed, 32 insertions(+), 19 deletions(-)

diff --git a/src/virt-viewer-app.c b/src/virt-viewer-app.c
index 6b3ad6d..760ed77 100644
--- a/src/virt-viewer-app.c
+++ b/src/virt-viewer-app.c
@@ -706,7 +706,7 @@ virt_viewer_app_create_session(VirtViewerApp *self, const gchar *type)
         GtkWindow *window = virt_viewer_window_get_window(priv->main_window);
         virt_viewer_app_trace(self, "Guest %s has a %s display",
                               priv->guest_name, type);
-        priv->session = virt_viewer_session_vnc_new(window);
+        priv->session = virt_viewer_session_vnc_new(self, window);
     } else
 #endif
 #ifdef HAVE_SPICE_GTK
diff --git a/src/virt-viewer-session-vnc.c b/src/virt-viewer-session-vnc.c
index 3245de3..e9e21a2 100644
--- a/src/virt-viewer-session-vnc.c
+++ b/src/virt-viewer-session-vnc.c
@@ -201,7 +201,8 @@ virt_viewer_session_vnc_open_uri(VirtViewerSession* session,
                                  const gchar *uristr)
 {
     VirtViewerSessionVnc *self = VIRT_VIEWER_SESSION_VNC(session);
-    xmlURIPtr uri = NULL;
+    VirtViewerFile *file = virt_viewer_session_get_file(session);
+    VirtViewerApp *app = virt_viewer_session_get_app(session);
     gchar *portstr;
     gchar *hoststr = NULL;
     gboolean ret;
@@ -209,20 +210,33 @@ virt_viewer_session_vnc_open_uri(VirtViewerSession* session,
     g_return_val_if_fail(self != NULL, FALSE);
     g_return_val_if_fail(self->priv->vnc != NULL, FALSE);
 
-    if (!(uri = xmlParseURI(uristr)))
-        return FALSE;
-
-    portstr = g_strdup_printf("%d", uri->port);
-
-    if (uri->server) {
-        if (uri->server[0] == '[') {
-            gchar *tmp;
-            hoststr = g_strdup(uri->server + 1);
-            if ((tmp = strchr(hoststr, ']')))
-                *tmp = '\0';
-        } else {
-            hoststr = g_strdup(uri->server);
+    if (file) {
+        g_return_val_if_fail(virt_viewer_file_is_set(file, "port"), FALSE);
+        g_return_val_if_fail(virt_viewer_file_is_set(file, "host"), FALSE);
+
+        portstr = g_strdup_printf("%d", virt_viewer_file_get_port(file));
+        hoststr = g_strdup(virt_viewer_file_get_host(file));
+
+        virt_viewer_file_fill_app(file, app);
+    } else {
+        xmlURIPtr uri = NULL;
+        if (!(uri = xmlParseURI(uristr)))
+            return FALSE;
+
+        portstr = g_strdup_printf("%d", uri->port);
+
+        if (uri->server) {
+            if (uri->server[0] == '[') {
+                gchar *tmp;
+                hoststr = g_strdup(uri->server + 1);
+                if ((tmp = strchr(hoststr, ']')))
+                    *tmp = '\0';
+            } else {
+                hoststr = g_strdup(uri->server);
+            }
         }
+
+        xmlFreeURI(uri);
     }
 
     ret = vnc_display_open_host(self->priv->vnc,
@@ -230,7 +244,6 @@ virt_viewer_session_vnc_open_uri(VirtViewerSession* session,
                                 portstr);
     g_free(portstr);
     g_free(hoststr);
-    xmlFreeURI(uri);
     return ret;
 }
 
@@ -288,11 +301,11 @@ virt_viewer_session_vnc_close(VirtViewerSession* session)
 }
 
 VirtViewerSession *
-virt_viewer_session_vnc_new(GtkWindow *main_window)
+virt_viewer_session_vnc_new(VirtViewerApp *app, GtkWindow *main_window)
 {
     VirtViewerSessionVnc *session;
 
-    session = g_object_new(VIRT_VIEWER_TYPE_SESSION_VNC, NULL);
+    session = g_object_new(VIRT_VIEWER_TYPE_SESSION_VNC, "app", app, NULL);
 
     session->priv->vnc = VNC_DISPLAY(vnc_display_new());
     g_object_ref_sink(session->priv->vnc);
diff --git a/src/virt-viewer-session-vnc.h b/src/virt-viewer-session-vnc.h
index 2b95dde..ab7b595 100644
--- a/src/virt-viewer-session-vnc.h
+++ b/src/virt-viewer-session-vnc.h
@@ -64,7 +64,7 @@ struct _VirtViewerSessionVncClass {
 
 GType virt_viewer_session_vnc_get_type(void);
 
-VirtViewerSession *virt_viewer_session_vnc_new(GtkWindow *main_window);
+VirtViewerSession *virt_viewer_session_vnc_new(VirtViewerApp *app, GtkWindow *main_window);
 
 G_END_DECLS
 
-- 
1.8.1.rc1.17.g75ed918


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]