diff options
author | Eduardo Lima (Etrunko) <etrunko@redhat.com> | 2015-12-09 18:11:37 -0200 |
---|---|---|
committer | Fabiano FidĂȘncio <fidencio@redhat.com> | 2016-02-18 21:45:56 +0100 |
commit | a9ce19f84864cc402ea1b4682a94fe53895bb13f (patch) | |
tree | 167a3de3998be59443ec506944d06f9eb675d4d2 /src/virt-viewer-main.c | |
parent | 7a54b96dbebfeb44f73a3e48e11f32006763a3b6 (diff) | |
download | virt-viewer-a9ce19f84864cc402ea1b4682a94fe53895bb13f.tar.gz virt-viewer-a9ce19f84864cc402ea1b4682a94fe53895bb13f.tar.xz virt-viewer-a9ce19f84864cc402ea1b4682a94fe53895bb13f.zip |
Port to GtkApplication API's
Most of this patch consists in code being shuffled around to fit the
expected flow while using the new APIs. I tried my best to make this
patch the less intrusive as possible. Main changes are:
- Updated build requirements
* glib version 2.38
* gtk+ version 3.10
* gio
- VirtViewerApp is now a subclass of GtkApplication.
Some mainloop calls were replaced:
* gtk_main() -> g_application_run()
* gtk_quit() -> g_application_quit()
- Unified command line option handling.
The logic has moved from the main functions and split in common
options, and specific ones for each application. With this, the main
functions were highly simplified, and now basically responsible for
instantiating the App object and running the main loop.
- All Window objects must be associated with the Application.
With this, there is no need to emit our own 'window-added'/'window-
removed' signals, as those will be emited by GtkApplication whenever
gtk_application_add_window() and gtk_application_remove_window() are
called. Also, 'window-removed' was not being used anywhere.
Signed-off-by: Eduardo Lima (Etrunko) <etrunko@redhat.com>
Diffstat (limited to 'src/virt-viewer-main.c')
-rw-r--r-- | src/virt-viewer-main.c | 110 |
1 files changed, 6 insertions, 104 deletions
diff --git a/src/virt-viewer-main.c b/src/virt-viewer-main.c index 505b472..56521f2 100644 --- a/src/virt-viewer-main.c +++ b/src/virt-viewer-main.c @@ -22,121 +22,23 @@ #include <config.h> #include <locale.h> +#include <gio/gio.h> #include <gtk/gtk.h> #include <glib/gi18n.h> #include <stdlib.h> -#ifdef HAVE_GTK_VNC -#include <vncdisplay.h> -#endif -#ifdef HAVE_SPICE_GTK -#include <spice-option.h> -#endif -#include "virt-viewer.h" - -static void virt_viewer_version(void) -{ - g_print(_("%s version %s\n"), PACKAGE, VERSION BUILDID); - - exit(EXIT_SUCCESS); -} +#include "virt-viewer.h" int main(int argc, char **argv) { - GOptionContext *context; - GError *error = NULL; int ret = 1; - char *uri = NULL; - gchar **args = NULL; - gboolean direct = FALSE; - gboolean attach = FALSE; - gboolean waitvm = FALSE; - gboolean reconnect = FALSE; - VirtViewer *viewer = NULL; - char *base_name; - char *help_msg = NULL; - const GOptionEntry options [] = { - { "version", 'V', G_OPTION_FLAG_NO_ARG, G_OPTION_ARG_CALLBACK, - virt_viewer_version, N_("Display version information"), NULL }, - { "direct", 'd', 0, G_OPTION_ARG_NONE, &direct, - N_("Direct connection with no automatic tunnels"), NULL }, - { "attach", 'a', 0, G_OPTION_ARG_NONE, &attach, - N_("Attach to the local display using libvirt"), NULL }, - { "connect", 'c', 0, G_OPTION_ARG_STRING, &uri, - N_("Connect to hypervisor"), "URI"}, - { "wait", 'w', 0, G_OPTION_ARG_NONE, &waitvm, - N_("Wait for domain to start"), NULL }, - { "reconnect", 'r', 0, G_OPTION_ARG_NONE, &reconnect, - N_("Reconnect to domain upon restart"), NULL }, - { G_OPTION_REMAINING, '\0', 0, G_OPTION_ARG_STRING_ARRAY, &args, - NULL, "-- DOMAIN-NAME|ID|UUID" }, - { NULL, 0, 0, G_OPTION_ARG_NONE, NULL, NULL, NULL } - }; - GOptionGroup* app_options = NULL; + GApplication *app= NULL; virt_viewer_util_init(_("Virt Viewer")); + app = G_APPLICATION(virt_viewer_new()); - base_name = g_path_get_basename(argv[0]); - help_msg = g_strdup_printf(_("Run '%s --help' to see a full list of available command line options"), - base_name); - g_free(base_name); - - /* Setup command line options */ - context = g_option_context_new (NULL); - g_option_context_set_summary (context, _("Virtual machine graphical console")); - 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 ()); -#endif -#ifdef HAVE_SPICE_GTK - g_option_context_add_group (context, spice_get_option_group ()); -#endif - g_option_context_parse (context, &argc, &argv, &error); - if (error) { - g_printerr("%s\n%s\n", - error->message, help_msg); - goto cleanup; - } - - g_option_context_free(context); - - if (args && (g_strv_length(args) != 1)) { - g_printerr(_("\nUsage: %s [OPTIONS] [DOMAIN-NAME|ID|UUID]\n\n%s\n\n"), argv[0], help_msg); - goto cleanup; - } - - if (args == NULL && waitvm) { - g_printerr(_("\nNo DOMAIN-NAME|ID|UUID was specified for '--wait'\n\n")); - goto cleanup; - } - - viewer = virt_viewer_new(uri, (args) ? args[0] : NULL, direct, attach, waitvm, reconnect); - if (viewer == NULL) - goto cleanup; - - if (!virt_viewer_app_start(VIRT_VIEWER_APP(viewer), &error)) { - if (g_error_matches(error, VIRT_VIEWER_ERROR, VIRT_VIEWER_ERROR_CANCELLED)) - ret = 0; - else if (error) { - virt_viewer_app_simple_message_dialog(VIRT_VIEWER_APP(viewer), error->message); - } - goto cleanup; - } - - gtk_main(); - - ret = 0; - - cleanup: - if (viewer) - g_object_unref(viewer); - g_free(uri); - g_strfreev(args); - g_free(help_msg); - g_clear_error(&error); + ret = g_application_run(app, argc, argv); + g_object_unref(app); return ret; } |