[virt-tools-list] [PATCH virt-viewer 3/4] virt-viewer-app: Add way to exit normally on user cancel

Pavel Grunt pgrunt at redhat.com
Tue Mar 17 09:08:23 UTC 2015


Related to https://bugzilla.redhat.com/show_bug.cgi?id=1201604
---
 src/remote-viewer-main.c |  6 +++++-
 src/virt-viewer-app.c    | 15 +++++++++++++++
 src/virt-viewer-app.h    |  2 ++
 src/virt-viewer-main.c   |  6 +++++-
 4 files changed, 27 insertions(+), 2 deletions(-)

diff --git a/src/remote-viewer-main.c b/src/remote-viewer-main.c
index e8784ba..9db2a17 100644
--- a/src/remote-viewer-main.c
+++ b/src/remote-viewer-main.c
@@ -174,8 +174,12 @@ main(int argc, char **argv)
 
     app = VIRT_VIEWER_APP(viewer);
 
-    if (!virt_viewer_app_start(app))
+    if (!virt_viewer_app_start(app)) {
+        if (virt_viewer_app_get_user_cancelled(app)) {
+            ret = 0;
+        }
         goto cleanup;
+    }
 
     g_signal_connect(virt_viewer_app_get_session(app), "session-connected",
                      G_CALLBACK(connected), app);
diff --git a/src/virt-viewer-app.c b/src/virt-viewer-app.c
index 2af1b93..660acdb 100644
--- a/src/virt-viewer-app.c
+++ b/src/virt-viewer-app.c
@@ -119,6 +119,7 @@ struct _VirtViewerAppPrivate {
     gboolean enable_accel;
     gboolean authretry;
     gboolean started;
+    gboolean user_cancelled;
     gboolean fullscreen;
     gboolean attach;
     gboolean quitting;
@@ -2406,6 +2407,20 @@ virt_viewer_app_get_windows(VirtViewerApp *self)
     return self->priv->windows;
 }
 
+void
+virt_viewer_app_set_user_cancelled(VirtViewerApp *self, gboolean user_cancelled)
+{
+    g_return_if_fail(VIRT_VIEWER_IS_APP(self));
+    self->priv->user_cancelled = user_cancelled;
+}
+
+gboolean
+virt_viewer_app_get_user_cancelled(VirtViewerApp *self)
+{
+    g_return_val_if_fail(VIRT_VIEWER_IS_APP(self), NULL);
+    return self->priv->user_cancelled;
+}
+
 static void
 share_folder_changed(VirtViewerApp *self)
 {
diff --git a/src/virt-viewer-app.h b/src/virt-viewer-app.h
index d214279..de4653e 100644
--- a/src/virt-viewer-app.h
+++ b/src/virt-viewer-app.h
@@ -101,6 +101,8 @@ gint virt_viewer_app_get_n_initial_displays(VirtViewerApp* self);
 gint virt_viewer_app_get_initial_monitor_for_display(VirtViewerApp* self, gint display);
 void virt_viewer_app_set_enable_accel(VirtViewerApp *app, gboolean enable);
 void virt_viewer_app_show_preferences(VirtViewerApp *app, GtkWidget *parent);
+void virt_viewer_app_set_user_cancelled(VirtViewerApp *app, gboolean user_cancelled);
+gboolean virt_viewer_app_get_user_cancelled(VirtViewerApp *app);
 
 G_END_DECLS
 
diff --git a/src/virt-viewer-main.c b/src/virt-viewer-main.c
index 3fae955..9a53799 100644
--- a/src/virt-viewer-main.c
+++ b/src/virt-viewer-main.c
@@ -113,8 +113,12 @@ int main(int argc, char **argv)
     if (viewer == NULL)
         goto cleanup;
 
-    if (!virt_viewer_app_start(VIRT_VIEWER_APP(viewer)))
+    if (!virt_viewer_app_start(VIRT_VIEWER_APP(viewer))) {
+        if (virt_viewer_app_get_user_cancelled(VIRT_VIEWER_APP(viewer))) {
+            ret = 0;
+        }
         goto cleanup;
+    }
 
     gtk_main();
 
-- 
2.3.2




More information about the virt-tools-list mailing list