[virt-tools-list] [virt-viewer][PATCH 2/4 v3] virt-viewer: Changed reconnect field to property

Lukas Venhoda lvenhoda at redhat.com
Wed May 13 14:51:01 UTC 2015


Reconnect field in virt-viewer.c changed to property.

This will be used in virt-viewer-window for binding a "Reconnect" check
button to it.
---
Changes since v2:
  - Reverted back to version 1
  - Removed object_notify

Changes since v1:
 - Moved the reconnect property from virt-viewer.c into virt-viewer-app.c,
   so it can be moved into preferences
 - Added a getter function for reconnect to access it from virt-viewer.c
 - Changed g_object_notify to g_object_notify_by_pspec for reconnect
   in virt_viewer_app_set_property
---
 src/virt-viewer.c | 31 ++++++++++++++++++++++++++++++-
 1 file changed, 30 insertions(+), 1 deletion(-)

diff --git a/src/virt-viewer.c b/src/virt-viewer.c
index 9c3ccc9..10bb129 100644
--- a/src/virt-viewer.c
+++ b/src/virt-viewer.c
@@ -66,6 +66,11 @@ G_DEFINE_TYPE (VirtViewer, virt_viewer, VIRT_VIEWER_TYPE_APP)
 #define GET_PRIVATE(o)                                                        \
     (G_TYPE_INSTANCE_GET_PRIVATE ((o), VIRT_VIEWER_TYPE, VirtViewerPrivate))

+enum {
+    PROP_0,
+    PROP_RECONNECT,
+};
+
 static gboolean virt_viewer_initial_connect(VirtViewerApp *self, GError **error);
 static gboolean virt_viewer_open_connection(VirtViewerApp *self, int *fd);
 static void virt_viewer_deactivated(VirtViewerApp *self, gboolean connect_error);
@@ -76,7 +81,14 @@ static void
 virt_viewer_get_property (GObject *object, guint property_id,
                           GValue *value G_GNUC_UNUSED, GParamSpec *pspec)
 {
+    g_return_if_fail(VIRT_VIEWER_IS(object));
+    VirtViewer *self = VIRT_VIEWER(object);
+    VirtViewerPrivate *priv = self->priv;
+
     switch (property_id) {
+    case PROP_RECONNECT:
+        g_value_set_boolean(value, priv->reconnect);
+        break;
     default:
         G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
     }
@@ -86,7 +98,15 @@ static void
 virt_viewer_set_property (GObject *object, guint property_id,
                           const GValue *value G_GNUC_UNUSED, GParamSpec *pspec)
 {
+    g_return_if_fail(VIRT_VIEWER_IS(object));
+    VirtViewer *self = VIRT_VIEWER(object);
+    VirtViewerPrivate *priv = self->priv;
+
     switch (property_id) {
+    case PROP_RECONNECT:
+        priv->reconnect = g_value_get_boolean(value);
+        g_object_notify_by_pspec(G_OBJECT(self), pspec);
+        break;
     default:
         G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
     }
@@ -108,6 +128,15 @@ virt_viewer_class_init (VirtViewerClass *klass)
     app_class->deactivated = virt_viewer_deactivated;
     app_class->open_connection = virt_viewer_open_connection;
     app_class->start = virt_viewer_start;
+
+    g_object_class_install_property(object_class,
+                                    PROP_RECONNECT,
+                                    g_param_spec_boolean("reconnect",
+                                                         "Reconnect",
+                                                         "Reconnect",
+                                                         FALSE,
+                                                         G_PARAM_READWRITE |
+                                                         G_PARAM_STATIC_STRINGS));
 }

 static void
@@ -990,6 +1019,7 @@ virt_viewer_new(const char *uri,

     self = g_object_new(VIRT_VIEWER_TYPE,
                         "guest-name", name,
+                        "reconnect", reconnect,
                         NULL);
     app = VIRT_VIEWER_APP(self);
     priv = self->priv;
@@ -1001,7 +1031,6 @@ virt_viewer_new(const char *uri,
     priv->uri = g_strdup(uri);
     priv->domkey = g_strdup(name);
     priv->waitvm = waitvm;
-    priv->reconnect = reconnect;

     return self;
 }
--
2.4.0




More information about the virt-tools-list mailing list