[virt-tools-list] [PATCH v2 15/16] app: add "vm-running" property

marcandre.lureau at redhat.com marcandre.lureau at redhat.com
Wed Sep 26 15:26:38 UTC 2018


From: Marc-André Lureau <marcandre.lureau at redhat.com>

Add "vm-running" property and modify "menu-vm-pause" check button
state when the running state changes.

Signed-off-by: Marc-André Lureau <marcandre.lureau at redhat.com>
---
 src/virt-viewer-app.c    | 19 +++++++++++++++++++
 src/virt-viewer-window.c | 16 ++++++++++++++++
 2 files changed, 35 insertions(+)

diff --git a/src/virt-viewer-app.c b/src/virt-viewer-app.c
index 402c80b..452395b 100644
--- a/src/virt-viewer-app.c
+++ b/src/virt-viewer-app.c
@@ -128,6 +128,7 @@ struct _VirtViewerAppPrivate {
     gboolean quitting;
     gboolean kiosk;
     gboolean vm_ui;
+    gboolean vm_running;
 
     VirtViewerSession *session;
     gboolean active;
@@ -176,6 +177,7 @@ enum {
     PROP_QUIT_ON_DISCONNECT,
     PROP_UUID,
     PROP_VM_UI,
+    PROP_VM_RUNNING,
 };
 
 void
@@ -1584,6 +1586,10 @@ virt_viewer_app_get_property (GObject *object, guint property_id,
         g_value_set_boolean(value, priv->vm_ui);
         break;
 
+    case PROP_VM_RUNNING:
+        g_value_set_boolean(value, priv->vm_running);
+        break;
+
     default:
         G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
     }
@@ -1642,6 +1648,10 @@ virt_viewer_app_set_property (GObject *object, guint property_id,
         priv->vm_ui = g_value_get_boolean(value);
         break;
 
+    case PROP_VM_RUNNING:
+        priv->vm_running = g_value_get_boolean(value);
+        break;
+
     default:
         G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
     }
@@ -2042,6 +2052,15 @@ virt_viewer_app_class_init (VirtViewerAppClass *klass)
                                                          FALSE,
                                                          G_PARAM_READWRITE |
                                                          G_PARAM_STATIC_STRINGS));
+
+    g_object_class_install_property(object_class,
+                                    PROP_VM_RUNNING,
+                                    g_param_spec_boolean("vm-running",
+                                                         "VM running",
+                                                         "VM running",
+                                                         FALSE,
+                                                         G_PARAM_READWRITE |
+                                                         G_PARAM_STATIC_STRINGS));
 }
 
 void
diff --git a/src/virt-viewer-window.c b/src/virt-viewer-window.c
index 514a410..d90aa7c 100644
--- a/src/virt-viewer-window.c
+++ b/src/virt-viewer-window.c
@@ -237,6 +237,20 @@ vm_ui_changed(GObject    *gobject G_GNUC_UNUSED,
     gtk_widget_set_visible(GTK_WIDGET(gtk_builder_get_object(self->priv->builder, "menu-machine")), vm_ui);
 }
 
+static void
+vm_running_changed(GObject    *gobject G_GNUC_UNUSED,
+                   GParamSpec *pspec G_GNUC_UNUSED,
+                   gpointer    user_data)
+{
+    VirtViewerWindow *self = user_data;
+    GtkCheckMenuItem *check = GTK_CHECK_MENU_ITEM(gtk_builder_get_object(self->priv->builder, "menu-vm-pause"));
+    gboolean running;
+
+    g_object_get(G_OBJECT(self->priv->app), "vm-running", &running, NULL);
+
+    gtk_check_menu_item_set_active(check, !running);
+}
+
 static void
 virt_viewer_window_constructed(GObject *object)
 {
@@ -249,6 +263,8 @@ virt_viewer_window_constructed(GObject *object)
                      G_CALLBACK(rebuild_combo_menu), object);
     g_signal_connect(priv->app, "notify::vm-ui",
                      G_CALLBACK(vm_ui_changed), object);
+    g_signal_connect(priv->app, "notify::vm-running",
+                     G_CALLBACK(vm_running_changed), object);
     rebuild_combo_menu(NULL, NULL, object);
 }
 
-- 
2.19.0.271.gfe8321ec05




More information about the virt-tools-list mailing list