Blame SOURCES/0008-Try-to-share-more-GOption-code-between-r-v-and-v-v.patch

4a6991
From 39533e1b6bfffc2c0d0d04477dcc722a2acd587f Mon Sep 17 00:00:00 2001
4a6991
From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= <marcandre.lureau@gmail.com>
4a6991
Date: Fri, 16 Aug 2013 17:15:37 +0200
4a6991
Subject: [PATCH] Try to share more GOption code between r-v and v-v
4a6991
4a6991
(cherry picked from commit 980de2d331cd2e2ba7e559accd887bf996e8bd81)
4a6991
https://bugzilla.redhat.com/show_bug.cgi?id=1040926
4a6991
---
4a6991
 src/remote-viewer-main.c | 54 +++---------------------------------------
4a6991
 src/remote-viewer.c      |  6 ++---
4a6991
 src/remote-viewer.h      |  6 ++---
4a6991
 src/virt-viewer-app.c    | 61 ++++++++++++++++++++++++++++++++++++++++++++++++
4a6991
 src/virt-viewer-app.h    |  1 +
4a6991
 src/virt-viewer-main.c   | 29 ++---------------------
4a6991
 src/virt-viewer.c        |  6 +----
4a6991
 src/virt-viewer.h        |  4 +---
4a6991
 8 files changed, 73 insertions(+), 94 deletions(-)
4a6991
4a6991
diff --git a/src/remote-viewer-main.c b/src/remote-viewer-main.c
4a6991
index 19e5197..a773288 100644
4a6991
--- a/src/remote-viewer-main.c
4a6991
+++ b/src/remote-viewer-main.c
4a6991
@@ -48,28 +48,6 @@ remote_viewer_version(void)
4a6991
     exit(EXIT_SUCCESS);
4a6991
 }
4a6991
 
4a6991
-gboolean fullscreen = FALSE;
4a6991
-gboolean fullscreen_auto_conf = FALSE;
4a6991
-
4a6991
-static gboolean
4a6991
-option_fullscreen(G_GNUC_UNUSED const gchar *option_name,
4a6991
-                  const gchar *value,
4a6991
-                  G_GNUC_UNUSED gpointer data, GError **error)
4a6991
-{
4a6991
-    fullscreen = TRUE;
4a6991
-
4a6991
-    if (value == NULL)
4a6991
-        return TRUE;
4a6991
-
4a6991
-    if (g_str_equal(value, "auto-conf")) {
4a6991
-        fullscreen_auto_conf = TRUE;
4a6991
-        return TRUE;
4a6991
-    }
4a6991
-
4a6991
-    g_set_error(error, G_OPTION_ERROR, G_OPTION_ERROR_FAILED, _("Invalid full-screen argument: %s"), value);
4a6991
-    return FALSE;
4a6991
-}
4a6991
-
4a6991
 static void
4a6991
 recent_add(gchar *uri, const gchar *mime_type)
4a6991
 {
4a6991
@@ -105,13 +83,9 @@ main(int argc, char **argv)
4a6991
     GOptionContext *context;
4a6991
     GError *error = NULL;
4a6991
     int ret = 1;
4a6991
-    int zoom = 100;
4a6991
     gchar **args = NULL;
4a6991
     gchar *uri = NULL;
4a6991
     char *title = NULL;
4a6991
-    char *hotkeys = NULL;
4a6991
-    gboolean verbose = FALSE;
4a6991
-    gboolean debug = FALSE;
4a6991
     RemoteViewer *viewer = NULL;
4a6991
 #ifdef HAVE_SPICE_GTK
4a6991
     gboolean controller = FALSE;
4a6991
@@ -120,22 +94,12 @@ main(int argc, char **argv)
4a6991
     const GOptionEntry options [] = {
4a6991
         { "version", 'V', G_OPTION_FLAG_NO_ARG, G_OPTION_ARG_CALLBACK,
4a6991
           remote_viewer_version, N_("Display version information"), NULL },
4a6991
-        { "verbose", 'v', 0, G_OPTION_ARG_NONE, &verbose,
4a6991
-          N_("Display verbose information"), NULL },
4a6991
         { "title", 't', 0, G_OPTION_ARG_STRING, &title,
4a6991
           N_("Set window title"), NULL },
4a6991
-        { "zoom", 'z', 0, G_OPTION_ARG_INT, &zoom,
4a6991
-          N_("Zoom level of window, in percentage"), "ZOOM" },
4a6991
-        { "debug", '\0', 0, G_OPTION_ARG_NONE, &debug,
4a6991
-          N_("Display debugging information"), NULL },
4a6991
-        { "full-screen", 'f', G_OPTION_FLAG_OPTIONAL_ARG, G_OPTION_ARG_CALLBACK, option_fullscreen,
4a6991
-          N_("Open in full screen mode (auto-conf adjusts guest resolution to fit the client's)."), N_("<auto-conf>") },
4a6991
 #ifdef HAVE_SPICE_GTK
4a6991
         { "spice-controller", '\0', 0, G_OPTION_ARG_NONE, &controller,
4a6991
           N_("Open connection using Spice controller communication"), NULL },
4a6991
 #endif
4a6991
-        { "hotkeys", 'H', 0, G_OPTION_ARG_STRING, &hotkeys,
4a6991
-          N_("Customise hotkeys"), NULL },
4a6991
         { G_OPTION_REMAINING, '\0', 0, G_OPTION_ARG_STRING_ARRAY, &args,
4a6991
           NULL, "-- URI" },
4a6991
         { NULL, 0, 0, G_OPTION_ARG_NONE, NULL, NULL, NULL }
4a6991
@@ -145,6 +109,7 @@ main(int argc, char **argv)
4a6991
 
4a6991
     /* Setup command line options */
4a6991
     context = g_option_context_new (_("- Remote viewer client"));
4a6991
+    g_option_context_add_main_entries (context, virt_viewer_app_get_options(), NULL);
4a6991
     g_option_context_add_main_entries (context, options, NULL);
4a6991
     g_option_context_add_group (context, gtk_get_option_group (TRUE));
4a6991
 #ifdef HAVE_GTK_VNC
4a6991
@@ -183,22 +148,13 @@ main(int argc, char **argv)
4a6991
         }
4a6991
     }
4a6991
 
4a6991
-    if (zoom < 10 || zoom > 200) {
4a6991
-        g_printerr(_("Zoom level must be within 10-200\n"));
4a6991
-        goto cleanup;
4a6991
-    }
4a6991
-
4a6991
-    gtk_window_set_default_icon_name("virt-viewer");
4a6991
-
4a6991
-    virt_viewer_app_set_debug(debug);
4a6991
-
4a6991
 #ifdef HAVE_SPICE_GTK
4a6991
     if (controller) {
4a6991
-        viewer = remote_viewer_new_with_controller(verbose);
4a6991
+        viewer = remote_viewer_new_with_controller();
4a6991
         g_object_set(viewer, "guest-name", "defined by Spice controller", NULL);
4a6991
     } else {
4a6991
 #endif
4a6991
-        viewer = remote_viewer_new(uri, title, verbose);
4a6991
+        viewer = remote_viewer_new(uri, title);
4a6991
         g_object_set(viewer, "guest-name", uri, NULL);
4a6991
 #ifdef HAVE_SPICE_GTK
4a6991
     }
4a6991
@@ -207,10 +163,6 @@ main(int argc, char **argv)
4a6991
         goto cleanup;
4a6991
 
4a6991
     app = VIRT_VIEWER_APP(viewer);
4a6991
-    g_object_set(app, "fullscreen-auto-conf", fullscreen_auto_conf, NULL);
4a6991
-    g_object_set(app, "fullscreen", fullscreen, NULL);
4a6991
-    virt_viewer_window_set_zoom_level(virt_viewer_app_get_main_window(app), zoom);
4a6991
-    virt_viewer_app_set_hotkeys(app, hotkeys);
4a6991
 
4a6991
     if (!virt_viewer_app_start(app))
4a6991
         goto cleanup;
4a6991
diff --git a/src/remote-viewer.c b/src/remote-viewer.c
4a6991
index b656175..3f2801f 100644
4a6991
--- a/src/remote-viewer.c
4a6991
+++ b/src/remote-viewer.c
4a6991
@@ -220,11 +220,10 @@ remote_viewer_init(RemoteViewer *self)
4a6991
 }
4a6991
 
4a6991
 RemoteViewer *
4a6991
-remote_viewer_new(const gchar *uri, const gchar *title, gboolean verbose)
4a6991
+remote_viewer_new(const gchar *uri, const gchar *title)
4a6991
 {
4a6991
     return g_object_new(REMOTE_VIEWER_TYPE,
4a6991
                         "guri", uri,
4a6991
-                        "verbose", verbose,
4a6991
                         "title", title,
4a6991
                         "open-recent-dialog", uri == NULL,
4a6991
                         NULL);
4a6991
@@ -250,7 +249,7 @@ foreign_menu_title_changed(SpiceCtrlForeignMenu *menu G_GNUC_UNUSED,
4a6991
 }
4a6991
 
4a6991
 RemoteViewer *
4a6991
-remote_viewer_new_with_controller(gboolean verbose)
4a6991
+remote_viewer_new_with_controller(void)
4a6991
 {
4a6991
     RemoteViewer *self;
4a6991
     SpiceCtrlController *ctrl = spice_ctrl_controller_new();
4a6991
@@ -259,7 +258,6 @@ remote_viewer_new_with_controller(gboolean verbose)
4a6991
     self =  g_object_new(REMOTE_VIEWER_TYPE,
4a6991
                          "controller", ctrl,
4a6991
                          "foreign-menu", menu,
4a6991
-                         "verbose", verbose,
4a6991
                          NULL);
4a6991
     g_signal_connect(menu, "notify::title",
4a6991
                      G_CALLBACK(foreign_menu_title_changed),
4a6991
diff --git a/src/remote-viewer.h b/src/remote-viewer.h
4a6991
index de701e0..6035f94 100644
4a6991
--- a/src/remote-viewer.h
4a6991
+++ b/src/remote-viewer.h
4a6991
@@ -48,10 +48,8 @@ typedef struct {
4a6991
 
4a6991
 GType remote_viewer_get_type (void);
4a6991
 
4a6991
-RemoteViewer* remote_viewer_new(const gchar *uri,
4a6991
-                                const gchar *title,
4a6991
-                                gboolean verbose);
4a6991
-RemoteViewer* remote_viewer_new_with_controller(gboolean verbose);
4a6991
+RemoteViewer* remote_viewer_new(const gchar *uri, const gchar *title);
4a6991
+RemoteViewer* remote_viewer_new_with_controller(void);
4a6991
 
4a6991
 G_END_DECLS
4a6991
 
4a6991
diff --git a/src/virt-viewer-app.c b/src/virt-viewer-app.c
4a6991
index 6d12584..637896e 100644
4a6991
--- a/src/virt-viewer-app.c
4a6991
+++ b/src/virt-viewer-app.c
4a6991
@@ -1402,11 +1402,21 @@ gboolean virt_viewer_app_start(VirtViewerApp *self)
4a6991
     return self->priv->started;
4a6991
 }
4a6991
 
4a6991
+static int opt_zoom = 100;
4a6991
+static gchar *opt_hotkeys = NULL;
4a6991
+static gboolean opt_verbose = FALSE;
4a6991
+static gboolean opt_debug = FALSE;
4a6991
+static gboolean opt_fullscreen = FALSE;
4a6991
+static gboolean opt_fullscreen_auto_conf = FALSE;
4a6991
+
4a6991
 static void
4a6991
 virt_viewer_app_init (VirtViewerApp *self)
4a6991
 {
4a6991
     GError *error = NULL;
4a6991
 
4a6991
+    gtk_window_set_default_icon_name("virt-viewer");
4a6991
+    virt_viewer_app_set_debug(opt_debug);
4a6991
+
4a6991
     self->priv = GET_PRIVATE(self);
4a6991
     self->priv->windows = g_hash_table_new_full(g_int_hash, g_int_equal, g_free, g_object_unref);
4a6991
     self->priv->config = g_key_file_new();
4a6991
@@ -1419,6 +1429,14 @@ virt_viewer_app_init (VirtViewerApp *self)
4a6991
         g_debug("Couldn't load configuration: %s", error->message);
4a6991
 
4a6991
     g_clear_error(&error);
4a6991
+
4a6991
+    if (opt_zoom < 10 || opt_zoom > 200) {
4a6991
+        g_printerr(_("Zoom level must be within 10-200\n"));
4a6991
+        opt_zoom = 100;
4a6991
+    }
4a6991
+
4a6991
+    self->priv->verbose = opt_verbose;
4a6991
+    self->priv->fullscreen_auto_conf = opt_fullscreen_auto_conf;
4a6991
 }
4a6991
 
4a6991
 static void
4a6991
@@ -1495,6 +1513,10 @@ virt_viewer_app_constructor (GType gtype,
4a6991
     gtk_accel_map_add_entry("<virt-viewer>/view/release-cursor", GDK_F12, GDK_SHIFT_MASK);
4a6991
     gtk_accel_map_add_entry("<virt-viewer>/view/zoom-reset", GDK_0, GDK_CONTROL_MASK);
4a6991
 
4a6991
+    virt_viewer_window_set_zoom_level(priv->main_window, opt_zoom);
4a6991
+    virt_viewer_app_set_fullscreen(self, opt_fullscreen);
4a6991
+    virt_viewer_app_set_hotkeys(self, opt_hotkeys);
4a6991
+
4a6991
     return obj;
4a6991
 }
4a6991
 
4a6991
@@ -2049,6 +2071,45 @@ virt_viewer_app_get_windows(VirtViewerApp *self)
4a6991
     return self->priv->windows;
4a6991
 }
4a6991
 
4a6991
+static gboolean
4a6991
+option_fullscreen(G_GNUC_UNUSED const gchar *option_name,
4a6991
+                  const gchar *value,
4a6991
+                  G_GNUC_UNUSED gpointer data, GError **error)
4a6991
+{
4a6991
+    opt_fullscreen = TRUE;
4a6991
+
4a6991
+    if (value == NULL)
4a6991
+        return TRUE;
4a6991
+
4a6991
+    if (g_str_equal(value, "auto-conf")) {
4a6991
+        opt_fullscreen_auto_conf = TRUE;
4a6991
+        return TRUE;
4a6991
+    }
4a6991
+
4a6991
+    g_set_error(error, G_OPTION_ERROR, G_OPTION_ERROR_FAILED, _("Invalid full-screen argument: %s"), value);
4a6991
+    return FALSE;
4a6991
+}
4a6991
+
4a6991
+const GOptionEntry *
4a6991
+virt_viewer_app_get_options(void)
4a6991
+{
4a6991
+    static const GOptionEntry options [] = {
4a6991
+        { "zoom", 'z', 0, G_OPTION_ARG_INT, &opt_zoom,
4a6991
+          N_("Zoom level of window, in percentage"), "ZOOM" },
4a6991
+        { "full-screen", 'f', G_OPTION_FLAG_OPTIONAL_ARG, G_OPTION_ARG_CALLBACK, option_fullscreen,
4a6991
+          N_("Open in full screen mode (auto-conf adjusts guest resolution to fit the client's)"), N_("<auto-conf>") },
4a6991
+        { "hotkeys", 'H', 0, G_OPTION_ARG_STRING, &opt_hotkeys,
4a6991
+          N_("Customise hotkeys"), NULL },
4a6991
+        { "verbose", 'v', 0, G_OPTION_ARG_NONE, &opt_verbose,
4a6991
+          N_("Display verbose information"), NULL },
4a6991
+        { "debug", '\0', 0, G_OPTION_ARG_NONE, &opt_debug,
4a6991
+          N_("Display debugging information"), NULL },
4a6991
+        { NULL, 0, 0, G_OPTION_ARG_NONE, NULL, NULL, NULL }
4a6991
+    };
4a6991
+
4a6991
+    return options;
4a6991
+}
4a6991
+
4a6991
 /*
4a6991
  * Local variables:
4a6991
  *  c-indent-level: 4
4a6991
diff --git a/src/virt-viewer-app.h b/src/virt-viewer-app.h
4a6991
index 93bb988..4721fe3 100644
4a6991
--- a/src/virt-viewer-app.h
4a6991
+++ b/src/virt-viewer-app.h
4a6991
@@ -98,6 +98,7 @@ gboolean virt_viewer_app_get_enable_accel(VirtViewerApp *self);
4a6991
 VirtViewerSession* virt_viewer_app_get_session(VirtViewerApp *self);
4a6991
 gboolean virt_viewer_app_get_fullscreen(VirtViewerApp *app);
4a6991
 gboolean virt_viewer_app_get_fullscreen_auto_conf(VirtViewerApp *app);
4a6991
+const GOptionEntry* virt_viewer_app_get_options(void);
4a6991
 
4a6991
 G_END_DECLS
4a6991
 
4a6991
diff --git a/src/virt-viewer-main.c b/src/virt-viewer-main.c
4a6991
index 96e2e00..1f3f112 100644
4a6991
--- a/src/virt-viewer-main.c
4a6991
+++ b/src/virt-viewer-main.c
4a6991
@@ -47,24 +47,17 @@ int main(int argc, char **argv)
4a6991
     GError *error = NULL;
4a6991
     int ret = 1;
4a6991
     char *uri = NULL;
4a6991
-    int zoom = 100;
4a6991
     gchar **args = NULL;
4a6991
-    gchar *hotkeys = NULL;
4a6991
-    gboolean verbose = FALSE;
4a6991
-    gboolean debug = FALSE;
4a6991
     gboolean direct = FALSE;
4a6991
     gboolean attach = FALSE;
4a6991
     gboolean waitvm = FALSE;
4a6991
     gboolean reconnect = FALSE;
4a6991
-    gboolean fullscreen = FALSE;
4a6991
     VirtViewer *viewer = NULL;
4a6991
     char *base_name;
4a6991
     char *help_msg = NULL;
4a6991
     const GOptionEntry options [] = {
4a6991
         { "version", 'V', G_OPTION_FLAG_NO_ARG, G_OPTION_ARG_CALLBACK,
4a6991
           virt_viewer_version, N_("Display version information"), NULL },
4a6991
-        { "verbose", 'v', 0, G_OPTION_ARG_NONE, &verbose,
4a6991
-          N_("Display verbose information"), NULL },
4a6991
         { "direct", 'd', 0, G_OPTION_ARG_NONE, &direct,
4a6991
           N_("Direct connection with no automatic tunnels"), NULL },
4a6991
         { "attach", 'a', 0, G_OPTION_ARG_NONE, &attach,
4a6991
@@ -75,14 +68,6 @@ int main(int argc, char **argv)
4a6991
           N_("Wait for domain to start"), NULL },
4a6991
         { "reconnect", 'r', 0, G_OPTION_ARG_NONE, &reconnect,
4a6991
           N_("Reconnect to domain upon restart"), NULL },
4a6991
-        { "zoom", 'z', 0, G_OPTION_ARG_INT, &zoom,
4a6991
-          N_("Zoom level of window, in percentage"), "ZOOM" },
4a6991
-        { "debug", '\0', 0, G_OPTION_ARG_NONE, &debug,
4a6991
-          N_("Display debugging information"), NULL },
4a6991
-        { "full-screen", 'f', 0, G_OPTION_ARG_NONE, &fullscreen,
4a6991
-          N_("Open in full screen mode"), NULL },
4a6991
-        { "hotkeys", 'H', 0, G_OPTION_ARG_STRING, &hotkeys,
4a6991
-          N_("Customise hotkeys"), NULL },
4a6991
         { G_OPTION_REMAINING, '\0', 0, G_OPTION_ARG_STRING_ARRAY, &args,
4a6991
           NULL, "-- DOMAIN-NAME|ID|UUID" },
4a6991
         { NULL, 0, 0, G_OPTION_ARG_NONE, NULL, NULL, NULL }
4a6991
@@ -98,6 +83,7 @@ int main(int argc, char **argv)
4a6991
     /* Setup command line options */
4a6991
     context = g_option_context_new (_("- Virtual machine graphical console"));
4a6991
     g_option_context_add_main_entries (context, options, NULL);
4a6991
+    g_option_context_add_main_entries (context, virt_viewer_app_get_options(), NULL);
4a6991
     g_option_context_add_group (context, gtk_get_option_group (TRUE));
4a6991
 #ifdef HAVE_GTK_VNC
4a6991
     g_option_context_add_group (context, vnc_display_get_option_group ());
4a6991
@@ -120,21 +106,10 @@ int main(int argc, char **argv)
4a6991
         goto cleanup;
4a6991
     }
4a6991
 
4a6991
-    if (zoom < 10 || zoom > 200) {
4a6991
-        g_printerr(_("Zoom level must be within 10-200\n"));
4a6991
-        goto cleanup;
4a6991
-    }
4a6991
-
4a6991
-    gtk_window_set_default_icon_name("virt-viewer");
4a6991
-
4a6991
-    virt_viewer_app_set_debug(debug);
4a6991
-
4a6991
-    viewer = virt_viewer_new(uri, args[0], zoom, direct, attach, waitvm, reconnect, verbose);
4a6991
+    viewer = virt_viewer_new(uri, args[0], direct, attach, waitvm, reconnect);
4a6991
     if (viewer == NULL)
4a6991
         goto cleanup;
4a6991
 
4a6991
-    g_object_set(viewer, "fullscreen", fullscreen, NULL);
4a6991
-    virt_viewer_app_set_hotkeys(VIRT_VIEWER_APP(viewer), hotkeys);
4a6991
     if (!virt_viewer_app_start(VIRT_VIEWER_APP(viewer)))
4a6991
         goto cleanup;
4a6991
 
4a6991
diff --git a/src/virt-viewer.c b/src/virt-viewer.c
4a6991
index b98c252..ae25fc6 100644
4a6991
--- a/src/virt-viewer.c
4a6991
+++ b/src/virt-viewer.c
4a6991
@@ -735,19 +735,16 @@ virt_viewer_start(VirtViewerApp *app)
4a6991
 VirtViewer *
4a6991
 virt_viewer_new(const char *uri,
4a6991
                 const char *name,
4a6991
-                gint zoom,
4a6991
                 gboolean direct,
4a6991
                 gboolean attach,
4a6991
                 gboolean waitvm,
4a6991
-                gboolean reconnect,
4a6991
-                gboolean verbose)
4a6991
+                gboolean reconnect)
4a6991
 {
4a6991
     VirtViewer *self;
4a6991
     VirtViewerApp *app;
4a6991
     VirtViewerPrivate *priv;
4a6991
 
4a6991
     self = g_object_new(VIRT_VIEWER_TYPE,
4a6991
-                        "verbose", verbose,
4a6991
                         "guest-name", name,
4a6991
                         NULL);
4a6991
     app = VIRT_VIEWER_APP(self);
4a6991
@@ -757,7 +754,6 @@ virt_viewer_new(const char *uri,
4a6991
      * UUID, or NAME string. To be replaced with the real guest name later
4a6991
      */
4a6991
     g_object_set(app, "title", name, NULL);
4a6991
-    virt_viewer_window_set_zoom_level(virt_viewer_app_get_main_window(app), zoom);
4a6991
     virt_viewer_app_set_direct(app, direct);
4a6991
     virt_viewer_app_set_attach(app, attach);
4a6991
 
4a6991
diff --git a/src/virt-viewer.h b/src/virt-viewer.h
4a6991
index 73d9170..c962615 100644
4a6991
--- a/src/virt-viewer.h
4a6991
+++ b/src/virt-viewer.h
4a6991
@@ -51,12 +51,10 @@ GType virt_viewer_get_type (void);
4a6991
 VirtViewer *
4a6991
 virt_viewer_new(const char *uri,
4a6991
                 const char *name,
4a6991
-                gint zoom,
4a6991
                 gboolean direct,
4a6991
                 gboolean attach,
4a6991
                 gboolean waitvm,
4a6991
-                gboolean reconnect,
4a6991
-                gboolean verbose);
4a6991
+                gboolean reconnect);
4a6991
 
4a6991
 G_END_DECLS
4a6991