[virt-tools-list] [PATCHv2 virt-viewer 07/10] kiosk: add --kiosk-quit option

Marc-André Lureau marcandre.lureau at gmail.com
Fri Aug 16 19:47:43 UTC 2013


In kiosk mode, it's useful to keep the app alive, even if the remote
session ended for example. Ie, we want to prevent the app from quiting
itself, even if the remote end closed, lost network, or crashed etc.
---
 src/virt-viewer-app.c | 44 +++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 43 insertions(+), 1 deletion(-)

diff --git a/src/virt-viewer-app.c b/src/virt-viewer-app.c
index 99c5fe7..844cfa9 100644
--- a/src/virt-viewer-app.c
+++ b/src/virt-viewer-app.c
@@ -148,6 +148,7 @@ struct _VirtViewerAppPrivate {
     GdkModifierType insert_smartcard_accel_mods;
     guint remove_smartcard_accel_key;
     GdkModifierType remove_smartcard_accel_mods;
+    gboolean quit_on_disconnect;
 };
 
 
@@ -167,6 +168,7 @@ enum {
     PROP_HAS_FOCUS,
     PROP_FULLSCREEN_AUTO_CONF,
     PROP_KIOSK,
+    PROP_QUIT_ON_DISCONNECT,
 };
 
 enum {
@@ -1126,7 +1128,8 @@ virt_viewer_app_default_deactivated(VirtViewerApp *self, gboolean connect_error)
                               priv->guest_name);
     }
 
-    gtk_main_quit();
+    if (self->priv->quit_on_disconnect)
+        gtk_main_quit();
 }
 
 static void
@@ -1335,6 +1338,10 @@ virt_viewer_app_get_property (GObject *object, guint property_id,
         g_value_set_boolean(value, priv->kiosk);
         break;
 
+    case PROP_QUIT_ON_DISCONNECT:
+        g_value_set_boolean(value, priv->quit_on_disconnect);
+        break;
+
     default:
         G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
     }
@@ -1384,6 +1391,10 @@ virt_viewer_app_set_property (GObject *object, guint property_id,
         virt_viewer_app_set_kiosk(self, g_value_get_boolean(value));
         break;
 
+    case PROP_QUIT_ON_DISCONNECT:
+        priv->quit_on_disconnect = g_value_get_boolean(value);
+        break;
+
     default:
         G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
     }
@@ -1452,6 +1463,7 @@ static gboolean opt_debug = FALSE;
 static gboolean opt_fullscreen = FALSE;
 static gboolean opt_fullscreen_auto_conf = FALSE;
 static gboolean opt_kiosk = FALSE;
+static gboolean opt_kiosk_quit = FALSE;
 
 static void
 virt_viewer_app_init (VirtViewerApp *self)
@@ -1481,6 +1493,7 @@ virt_viewer_app_init (VirtViewerApp *self)
 
     self->priv->verbose = opt_verbose;
     self->priv->fullscreen_auto_conf = opt_fullscreen_auto_conf;
+    self->priv->quit_on_disconnect = opt_kiosk ? opt_kiosk_quit : TRUE;
 }
 
 static void
@@ -1678,6 +1691,15 @@ virt_viewer_app_class_init (VirtViewerAppClass *klass)
                                                          G_PARAM_READWRITE |
                                                          G_PARAM_STATIC_STRINGS));
 
+    g_object_class_install_property(object_class,
+                                    PROP_QUIT_ON_DISCONNECT,
+                                    g_param_spec_boolean("quit-on-disconnect",
+                                                         "Quit on disconnect",
+                                                         "Quit on disconnect",
+                                                         TRUE,
+                                                         G_PARAM_READWRITE |
+                                                         G_PARAM_STATIC_STRINGS));
+
     signals[SIGNAL_WINDOW_ADDED] =
         g_signal_new("window-added",
                      G_OBJECT_CLASS_TYPE(object_class),
@@ -2145,6 +2167,24 @@ option_fullscreen(G_GNUC_UNUSED const gchar *option_name,
     return FALSE;
 }
 
+static gboolean
+option_kiosk_quit(G_GNUC_UNUSED const gchar *option_name,
+                  const gchar *value,
+                  G_GNUC_UNUSED gpointer data, GError **error)
+{
+    if (g_str_equal(value, "never")) {
+        opt_kiosk_quit = FALSE;
+        return TRUE;
+    }
+    if (g_str_equal(value, "on-disconnect")) {
+        opt_kiosk_quit = TRUE;
+        return TRUE;
+    }
+
+    g_set_error(error, G_OPTION_ERROR, G_OPTION_ERROR_FAILED, _("Invalid kiosk-quit argument: %s"), value);
+    return FALSE;
+}
+
 const GOptionEntry *
 virt_viewer_app_get_options(void)
 {
@@ -2157,6 +2197,8 @@ virt_viewer_app_get_options(void)
           N_("Customise hotkeys"), NULL },
         { "kiosk", 'k', 0, G_OPTION_ARG_NONE, &opt_kiosk,
           N_("Enable kiosk mode"), NULL },
+        { "kiosk-quit", '\0', 0, G_OPTION_ARG_CALLBACK, option_kiosk_quit,
+          N_("Quit on given condition in kiosk mode"), N_("<never|on-disconnect>") },
         { "verbose", 'v', 0, G_OPTION_ARG_NONE, &opt_verbose,
           N_("Display verbose information"), NULL },
         { "debug", '\0', 0, G_OPTION_ARG_NONE, &opt_debug,
-- 
1.8.3.rc1.49.g8d97506




More information about the virt-tools-list mailing list