[virt-tools-list] [virt-viewer][PATCH 1/3] virt-viewer: Changed reconnect field to property

Lukas Venhoda lvenhoda at redhat.com
Tue May 12 10:21:02 UTC 2015


Reconnect field in virt-viewer.c changed to property.
This will be used in virt-viewer-window.c for implementing a "reconnect"
button in the GUI.
---
In virt_viewer_new() function, there's comment "/* should probably be properties instead */".
If someone thinks it's a good idea, I can change all of those fields to properties.
---
 src/virt-viewer.c | 29 ++++++++++++++++++++++++++++-
 1 file changed, 28 insertions(+), 1 deletion(-)

diff --git a/src/virt-viewer.c b/src/virt-viewer.c
index 9c3ccc9..ab9e8b4 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,13 @@ static void
 virt_viewer_get_property (GObject *object, guint property_id,
                           GValue *value G_GNUC_UNUSED, GParamSpec *pspec)
 {
+    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 +97,14 @@ static void
 virt_viewer_set_property (GObject *object, guint property_id,
                           const GValue *value G_GNUC_UNUSED, GParamSpec *pspec)
 {
+    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(G_OBJECT(self), "reconnect");
+        break;
     default:
         G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
     }
@@ -108,6 +126,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 +1017,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 +1029,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