[virt-tools-list] [virt-viewer 1/2] Exit virt-viewer when trying to close any window

Marc-André Lureau marcandre.lureau at gmail.com
Thu Apr 25 20:41:15 UTC 2013


ack


On Thu, Apr 25, 2013 at 9:54 PM, Christophe Fergeau <cfergeau at redhat.com>wrote:

> Currently, in multi-screen scenarios, when closing one remote-viewer
> window, the corresponding screen gets disabled in the guest OS.
> This can be confusing as this behaves very differently from
> File/Quit. This commit will exit the whole application when the user
> tries to close one of virt-viewer window.
> ---
>  src/virt-viewer-app.c    | 89
> +++++++++++++++++++++++++-----------------------
>  src/virt-viewer-app.h    |  1 +
>  src/virt-viewer-window.c |  2 +-
>  3 files changed, 49 insertions(+), 43 deletions(-)
>
> diff --git a/src/virt-viewer-app.c b/src/virt-viewer-app.c
> index 0519006..853615e 100644
> --- a/src/virt-viewer-app.c
> +++ b/src/virt-viewer-app.c
> @@ -260,6 +260,52 @@ virt_viewer_app_quit(VirtViewerApp *self)
>      gtk_main_quit();
>  }
>
> +void
> +virt_viewer_app_maybe_quit(VirtViewerApp *self, VirtViewerWindow *window)
> +{
> +    GError *error = NULL;
> +
> +    gboolean ask = g_key_file_get_boolean(self->priv->config,
> +                                          "virt-viewer", "ask-quit",
> &error);
> +    if (error) {
> +        ask = TRUE;
> +        g_clear_error(&error);
> +    }
> +
> +    if (ask) {
> +        GtkWidget *dialog =
> +            gtk_message_dialog_new (virt_viewer_window_get_window(window),
> +                    GTK_DIALOG_DESTROY_WITH_PARENT,
> +                    GTK_MESSAGE_QUESTION,
> +                    GTK_BUTTONS_OK_CANCEL,
> +                    _("Do you want to close the session?"));
> +
> +        GtkWidget *check = gtk_check_button_new_with_label(_("Do not ask
> me again"));
> +
>  gtk_container_add(GTK_CONTAINER(gtk_dialog_get_content_area(GTK_DIALOG(dialog))),
> check);
> +        gtk_widget_show(check);
> +
> +        gint result = gtk_dialog_run(GTK_DIALOG(dialog));
> +
> +        gboolean dont_ask = FALSE;
> +        g_object_get(check, "active", &dont_ask, NULL);
> +        if (dont_ask)
> +            g_key_file_set_boolean(self->priv->config,
> +                    "virt-viewer", "ask-quit", FALSE);
> +
> +        gtk_widget_destroy(dialog);
> +        switch (result) {
> +            case GTK_RESPONSE_OK:
> +                virt_viewer_app_quit(self);
> +                break;
> +            default:
> +                break;
> +        }
> +    } else {
> +        virt_viewer_app_quit(self);
> +    }
> +
> +}
> +
>  static void count_window_visible(gpointer key G_GNUC_UNUSED,
>                                   gpointer value,
>                                   gpointer user_data)
> @@ -284,8 +330,6 @@ virt_viewer_app_window_set_visible(VirtViewerApp *self,
>                                     VirtViewerWindow *window,
>                                     gboolean visible)
>  {
> -    GError *error = NULL;
> -
>      g_return_val_if_fail(VIRT_VIEWER_IS_APP(self), FALSE);
>      g_return_val_if_fail(VIRT_VIEWER_IS_WINDOW(window), FALSE);
>
> @@ -298,46 +342,7 @@ virt_viewer_app_window_set_visible(VirtViewerApp
> *self,
>              return FALSE;
>          }
>
> -        gboolean ask = g_key_file_get_boolean(self->priv->config,
> -                                              "virt-viewer", "ask-quit",
> &error);
> -        if (error) {
> -            ask = TRUE;
> -            g_clear_error(&error);
> -        }
> -
> -        if (ask) {
> -            GtkWidget *dialog =
> -                gtk_message_dialog_new
> (virt_viewer_window_get_window(window),
> -                                        GTK_DIALOG_DESTROY_WITH_PARENT,
> -                                        GTK_MESSAGE_QUESTION,
> -                                        GTK_BUTTONS_OK_CANCEL,
> -                                        _("Do you want to close the
> session?"));
> -
> -            GtkWidget *check = gtk_check_button_new_with_label(_("Do not
> ask me again"));
> -
>  gtk_container_add(GTK_CONTAINER(gtk_dialog_get_content_area(GTK_DIALOG(dialog))),
> check);
> -            gtk_widget_show(check);
> -
> -            gint result = gtk_dialog_run(GTK_DIALOG(dialog));
> -
> -            gboolean dont_ask = FALSE;
> -            g_object_get(check, "active", &dont_ask, NULL);
> -            if (dont_ask)
> -                g_key_file_set_boolean(self->priv->config,
> -                                       "virt-viewer", "ask-quit", FALSE);
> -
> -            gtk_widget_destroy(dialog);
> -            switch (result) {
> -            case GTK_RESPONSE_OK:
> -                virt_viewer_app_quit(self);
> -                break;
> -            default:
> -                break;
> -            }
> -            return FALSE;
> -        } else {
> -            virt_viewer_app_quit(self);
> -            return FALSE;
> -        }
> +        virt_viewer_app_maybe_quit(self, window);
>      }
>
>      g_warn_if_reached();
> diff --git a/src/virt-viewer-app.h b/src/virt-viewer-app.h
> index b2ef7e1..32bc7fb 100644
> --- a/src/virt-viewer-app.h
> +++ b/src/virt-viewer-app.h
> @@ -65,6 +65,7 @@ void virt_viewer_app_set_title(VirtViewerApp *app, const
> char *title);
>  void virt_viewer_app_set_debug(gboolean debug);
>  gboolean virt_viewer_app_start(VirtViewerApp *app);
>  void virt_viewer_app_quit(VirtViewerApp *self);
> +void virt_viewer_app_maybe_quit(VirtViewerApp *self, VirtViewerWindow
> *window);
>  VirtViewerWindow* virt_viewer_app_get_main_window(VirtViewerApp *self);
>  void virt_viewer_app_trace(VirtViewerApp *self, const char *fmt, ...);
>  void virt_viewer_app_simple_message_dialog(VirtViewerApp *self, const
> char *fmt, ...);
> diff --git a/src/virt-viewer-window.c b/src/virt-viewer-window.c
> index 67333f2..078c437 100644
> --- a/src/virt-viewer-window.c
> +++ b/src/virt-viewer-window.c
> @@ -701,7 +701,7 @@ virt_viewer_window_delete(GtkWidget *src G_GNUC_UNUSED,
>                            VirtViewerWindow *self)
>  {
>      DEBUG_LOG("Window closed");
> -    virt_viewer_app_window_set_visible(self->priv->app, self, FALSE);
> +    virt_viewer_app_maybe_quit(self->priv->app, self);
>      return TRUE;
>  }
>
> --
> 1.8.1.4
>
> _______________________________________________
> virt-tools-list mailing list
> virt-tools-list at redhat.com
> https://www.redhat.com/mailman/listinfo/virt-tools-list
>



-- 
Marc-André Lureau
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://listman.redhat.com/archives/virt-tools-list/attachments/20130425/44ee9e68/attachment.htm>


More information about the virt-tools-list mailing list