[virt-tools-list] [PATCH virt-viewer] Use GOptionGroup for VirtViewerApp options

Marc-André Lureau mlureau at redhat.com
Wed Jul 2 21:47:29 UTC 2014


ack

----- Original Message -----
> Encapsulate things a bit better by adding
> virt_viewer_app_get_option_group() which provides a GOptionGroup rather
> than exposing an array of options.  This option is then set as the main
> option group, and additional options can be added by subclasses, so the
> effect to the user should be equivalent.
> ---
> 
> Just a minor change that I think makes the command line option code a bit
> cleaner.
> 
>  src/remote-viewer-main.c | 6 ++++--
>  src/virt-viewer-app.c    | 9 ++++++---
>  src/virt-viewer-app.h    | 2 +-
>  src/virt-viewer-main.c   | 6 ++++--
>  4 files changed, 15 insertions(+), 8 deletions(-)
> 
> diff --git a/src/remote-viewer-main.c b/src/remote-viewer-main.c
> index e65cfd9..e8784ba 100644
> --- a/src/remote-viewer-main.c
> +++ b/src/remote-viewer-main.c
> @@ -107,14 +107,16 @@ main(int argc, char **argv)
>            NULL, "URI|VV-FILE" },
>          { NULL, 0, 0, G_OPTION_ARG_NONE, NULL, NULL, NULL }
>      };
> +    GOptionGroup *app_options = NULL;
>  
>      virt_viewer_util_init(_("Remote Viewer"));
>  
>      /* Setup command line options */
>      context = g_option_context_new (NULL);
>      g_option_context_set_summary(context, _("Remote viewer client"));
> -    g_option_context_add_main_entries (context,
> virt_viewer_app_get_options(), NULL);
> -    g_option_context_add_main_entries (context, options, NULL);
> +    app_options = virt_viewer_app_get_option_group();
> +    g_option_group_add_entries (app_options, options);
> +    g_option_context_set_main_group (context, app_options);
>      g_option_context_add_group (context, gtk_get_option_group (TRUE));
>  #ifdef HAVE_GTK_VNC
>      g_option_context_add_group (context, vnc_display_get_option_group ());
> diff --git a/src/virt-viewer-app.c b/src/virt-viewer-app.c
> index 6cf2747..7e1fe9b 100644
> --- a/src/virt-viewer-app.c
> +++ b/src/virt-viewer-app.c
> @@ -2279,8 +2279,8 @@ option_kiosk_quit(G_GNUC_UNUSED const gchar
> *option_name,
>      return FALSE;
>  }
>  
> -const GOptionEntry *
> -virt_viewer_app_get_options(void)
> +GOptionGroup*
> +virt_viewer_app_get_option_group(void)
>  {
>      static const GOptionEntry options [] = {
>          { "zoom", 'z', 0, G_OPTION_ARG_INT, &opt_zoom,
> @@ -2299,8 +2299,11 @@ virt_viewer_app_get_options(void)
>            N_("Display debugging information"), NULL },
>          { NULL, 0, 0, G_OPTION_ARG_NONE, NULL, NULL, NULL }
>      };
> +    GOptionGroup *group;
> +    group = g_option_group_new("virt-viewer", NULL, NULL, NULL, NULL);
> +    g_option_group_add_entries(group, options);
>  
> -    return options;
> +    return group;
>  }
>  
>  /*
> diff --git a/src/virt-viewer-app.h b/src/virt-viewer-app.h
> index 6a53992..f953a1e 100644
> --- a/src/virt-viewer-app.h
> +++ b/src/virt-viewer-app.h
> @@ -96,7 +96,7 @@ GHashTable* virt_viewer_app_get_windows(VirtViewerApp
> *self);
>  gboolean virt_viewer_app_get_enable_accel(VirtViewerApp *self);
>  VirtViewerSession* virt_viewer_app_get_session(VirtViewerApp *self);
>  gboolean virt_viewer_app_get_fullscreen(VirtViewerApp *app);
> -const GOptionEntry* virt_viewer_app_get_options(void);
> +GOptionGroup* virt_viewer_app_get_option_group(void);
>  void virt_viewer_app_clear_hotkeys(VirtViewerApp *app);
>  gint virt_viewer_app_get_n_initial_displays(VirtViewerApp* self);
>  gint virt_viewer_app_get_initial_monitor_for_display(VirtViewerApp* self,
>  gint display);
> diff --git a/src/virt-viewer-main.c b/src/virt-viewer-main.c
> index f6358f0..44d1182 100644
> --- a/src/virt-viewer-main.c
> +++ b/src/virt-viewer-main.c
> @@ -72,6 +72,7 @@ int main(int argc, char **argv)
>            NULL, "-- DOMAIN-NAME|ID|UUID" },
>          { NULL, 0, 0, G_OPTION_ARG_NONE, NULL, NULL, NULL }
>      };
> +    GOptionGroup* app_options = NULL;
>  
>      virt_viewer_util_init(_("Virt Viewer"));
>  
> @@ -83,8 +84,9 @@ int main(int argc, char **argv)
>      /* Setup command line options */
>      context = g_option_context_new (NULL);
>      g_option_context_set_summary (context, _("Virtual machine graphical
>      console"));
> -    g_option_context_add_main_entries (context, options, NULL);
> -    g_option_context_add_main_entries (context,
> virt_viewer_app_get_options(), NULL);
> +    app_options = virt_viewer_app_get_option_group();
> +    g_option_group_add_entries (app_options, options);
> +    g_option_context_set_main_group (context, app_options);
>      g_option_context_add_group (context, gtk_get_option_group (TRUE));
>  #ifdef HAVE_GTK_VNC
>      g_option_context_add_group (context, vnc_display_get_option_group ());
> --
> 1.9.3
> 
> _______________________________________________
> virt-tools-list mailing list
> virt-tools-list at redhat.com
> https://www.redhat.com/mailman/listinfo/virt-tools-list
> 




More information about the virt-tools-list mailing list