[virt-tools-list] [PATCH virt-viewer] app: Factor out common code

Pavel Grunt pgrunt at redhat.com
Wed Oct 5 09:29:18 UTC 2016


---
 src/virt-viewer-app.c | 14 ++++++--------
 1 file changed, 6 insertions(+), 8 deletions(-)

diff --git a/src/virt-viewer-app.c b/src/virt-viewer-app.c
index e8412ac..ee3800b 100644
--- a/src/virt-viewer-app.c
+++ b/src/virt-viewer-app.c
@@ -1032,21 +1032,16 @@ virt_viewer_app_create_session(VirtViewerApp *self, const gchar *type, GError **
     VirtViewerAppPrivate *priv = self->priv;
     g_return_val_if_fail(priv->session == NULL, FALSE);
     g_return_val_if_fail(type != NULL, FALSE);
+    VirtViewerSession *(*session_new_f)(VirtViewerApp *, GtkWindow *);
 
 #ifdef HAVE_GTK_VNC
     if (g_ascii_strcasecmp(type, "vnc") == 0) {
-        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(self, window);
+        session_new_f = virt_viewer_session_vnc_new;
     } else
 #endif
 #ifdef HAVE_SPICE_GTK
     if (g_ascii_strcasecmp(type, "spice") == 0) {
-        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_spice_new(self, window);
+        session_new_f = virt_viewer_session_spice_new;
     } else
 #endif
     {
@@ -1059,6 +1054,9 @@ virt_viewer_app_create_session(VirtViewerApp *self, const gchar *type, GError **
         return FALSE;
     }
 
+    virt_viewer_app_trace(self, "Guest %s has a %s display", priv->guest_name, type);
+    priv->session = session_new_f(self, virt_viewer_window_get_window(priv->main_window));
+
     g_signal_connect(priv->session, "session-initialized",
                      G_CALLBACK(virt_viewer_app_initialized), self);
     g_signal_connect(priv->session, "session-connected",
-- 
2.10.0




More information about the virt-tools-list mailing list