[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[virt-tools-list] [PATCHv2 4/4] file: add version field, raise an error if incompatibily



The virt-viewer connection file can now have a version=0.5 field. If
the virt-viewer version opening the connection doesn't provide at
least that version, an error is raised with the version required.
---
 src/virt-viewer-file.c          | 54 ++++++++++++++++++++++++++++++++++++++---
 src/virt-viewer-file.h          |  4 ++-
 src/virt-viewer-session-spice.c |  3 ++-
 src/virt-viewer-session-vnc.c   |  3 ++-
 4 files changed, 57 insertions(+), 7 deletions(-)

diff --git a/src/virt-viewer-file.c b/src/virt-viewer-file.c
index 745cae3..a1815d3 100644
--- a/src/virt-viewer-file.c
+++ b/src/virt-viewer-file.c
@@ -21,6 +21,8 @@
 
 #include <config.h>
 
+#include <glib/gi18n.h>
+
 #include "virt-viewer-util.h"
 #include "virt-viewer-file.h"
 
@@ -35,6 +37,7 @@
  * port=5900
  *
  *  The current list of [virt-viewer] keys is:
+ * - version: string
  * - type: string, mandatory, values: "spice" (later "vnc" etc..)
  * - host: string
  * - port: int
@@ -95,6 +98,7 @@ enum  {
     PROP_ENABLE_USB_AUTOSHARE,
     PROP_USB_FILTER,
     PROP_PROXY,
+    PROP_VERSION,
 };
 
 VirtViewerFile*
@@ -524,6 +528,19 @@ virt_viewer_file_set_proxy(VirtViewerFile* self, const gchar* value)
     g_object_notify(G_OBJECT(self), "proxy");
 }
 
+gchar*
+virt_viewer_file_get_version(VirtViewerFile* self)
+{
+    return virt_viewer_file_get_string(self, "version");
+}
+
+void
+virt_viewer_file_set_version(VirtViewerFile* self, const gchar* value)
+{
+    virt_viewer_file_set_string(self, "version", value);
+    g_object_notify(G_OBJECT(self), "version");
+}
+
 static void
 spice_hotkey_set_accel(VirtViewerApp *app, const gchar *accel_path, const gchar *key)
 {
@@ -540,11 +557,28 @@ spice_hotkey_set_accel(VirtViewerApp *app, const gchar *accel_path, const gchar
     g_object_set(G_OBJECT(app), "enable-accel", TRUE, NULL);
 }
 
-void
-virt_viewer_file_fill_app(VirtViewerFile* self, VirtViewerApp *app)
+gboolean
+virt_viewer_file_fill_app(VirtViewerFile* self, VirtViewerApp *app, GError **error)
 {
-    g_return_if_fail(VIRT_VIEWER_IS_FILE(self));
-    g_return_if_fail(VIRT_VIEWER_IS_APP(app));
+    g_return_val_if_fail(VIRT_VIEWER_IS_FILE(self), FALSE);
+    g_return_val_if_fail(VIRT_VIEWER_IS_APP(app), FALSE);
+
+    if (virt_viewer_file_is_set(self, "version")) {
+        gchar *val = virt_viewer_file_get_version(self);
+
+        if (virt_viewer_compare_version(val, PACKAGE_VERSION) > 0) {
+            g_set_error(error,
+                VIRT_VIEWER_ERROR,
+                VIRT_VIEWER_ERROR_FAILED,
+                _("At least %s version %s is required to setup this connection"),
+                g_get_application_name(), val);
+
+            g_free(val);
+            return FALSE;
+        }
+
+        g_free(val);
+    }
 
     if (virt_viewer_file_is_set(self, "title"))
         virt_viewer_app_set_title(app, virt_viewer_file_get_title(self));
@@ -576,6 +610,8 @@ virt_viewer_file_fill_app(VirtViewerFile* self, VirtViewerApp *app)
     if (virt_viewer_file_is_set(self, "fullscreen"))
         g_object_set(G_OBJECT(app), "fullscreen",
             virt_viewer_file_get_fullscreen(self), NULL);
+
+    return TRUE;
 }
 
 static void
@@ -651,6 +687,9 @@ virt_viewer_file_set_property(GObject* object, guint property_id,
     case PROP_PROXY:
         virt_viewer_file_set_proxy(self, g_value_get_string(value));
         break;
+    case PROP_VERSION:
+        virt_viewer_file_set_version(self, g_value_get_string(value));
+        break;
     default:
         G_OBJECT_WARN_INVALID_PROPERTY_ID(object, property_id, pspec);
         break;
@@ -727,6 +766,9 @@ virt_viewer_file_get_property(GObject* object, guint property_id,
     case PROP_PROXY:
         g_value_take_string(value, virt_viewer_file_get_proxy(self));
         break;
+    case PROP_VERSION:
+        g_value_take_string(value, virt_viewer_file_get_version(self));
+        break;
     default:
         G_OBJECT_WARN_INVALID_PROPERTY_ID(object, property_id, pspec);
         break;
@@ -845,4 +887,8 @@ virt_viewer_file_class_init(VirtViewerFileClass* klass)
     g_object_class_install_property(G_OBJECT_CLASS(klass), PROP_PROXY,
         g_param_spec_string("proxy", "proxy", "proxy", NULL,
                             G_PARAM_STATIC_STRINGS | G_PARAM_READWRITE));
+
+    g_object_class_install_property(G_OBJECT_CLASS(klass), PROP_VERSION,
+        g_param_spec_string("version", "version", "version", NULL,
+                            G_PARAM_STATIC_STRINGS | G_PARAM_READWRITE));
 }
diff --git a/src/virt-viewer-file.h b/src/virt-viewer-file.h
index f8a8577..7e26b71 100644
--- a/src/virt-viewer-file.h
+++ b/src/virt-viewer-file.h
@@ -93,13 +93,15 @@ gint virt_viewer_file_get_enable_usb_autoshare(VirtViewerFile* self);
 void virt_viewer_file_set_enable_usb_autoshare(VirtViewerFile* self, gint value);
 gchar* virt_viewer_file_get_usb_filter(VirtViewerFile* self);
 void virt_viewer_file_set_usb_filter(VirtViewerFile* self, const gchar* value);
-void virt_viewer_file_fill_app(VirtViewerFile* self, VirtViewerApp *app);
+gboolean virt_viewer_file_fill_app(VirtViewerFile* self, VirtViewerApp *app, GError **error);
 gchar* virt_viewer_file_get_smartcard_insert(VirtViewerFile* self);
 void virt_viewer_file_set_smartcard_insert(VirtViewerFile* self, const gchar* value);
 gchar* virt_viewer_file_get_smartcard_remove(VirtViewerFile* self);
 void virt_viewer_file_set_smartcard_remove(VirtViewerFile* self, const gchar* value);
 gchar* virt_viewer_file_get_proxy(VirtViewerFile* self);
 void virt_viewer_file_set_proxy(VirtViewerFile* self, const gchar* value);
+gchar* virt_viewer_file_get_version(VirtViewerFile* self);
+void virt_viewer_file_set_version(VirtViewerFile* self, const gchar* value);
 
 G_END_DECLS
 
diff --git a/src/virt-viewer-session-spice.c b/src/virt-viewer-session-spice.c
index cfe31ac..29febc3 100644
--- a/src/virt-viewer-session-spice.c
+++ b/src/virt-viewer-session-spice.c
@@ -353,7 +353,8 @@ virt_viewer_session_spice_open_uri(VirtViewerSession *session,
 
     if (file) {
         fill_session(file, self->priv->session);
-        virt_viewer_file_fill_app(file, app);
+        if (!virt_viewer_file_fill_app(file, app, error))
+            return FALSE;
     } else {
         g_object_set(self->priv->session, "uri", uri, NULL);
     }
diff --git a/src/virt-viewer-session-vnc.c b/src/virt-viewer-session-vnc.c
index bbebc7e..05e98c8 100644
--- a/src/virt-viewer-session-vnc.c
+++ b/src/virt-viewer-session-vnc.c
@@ -218,7 +218,8 @@ virt_viewer_session_vnc_open_uri(VirtViewerSession* session,
         portstr = g_strdup_printf("%d", virt_viewer_file_get_port(file));
         hoststr = g_strdup(virt_viewer_file_get_host(file));
 
-        virt_viewer_file_fill_app(file, app);
+        if (!virt_viewer_file_fill_app(file, app, error))
+            return FALSE;
     } else {
         xmlURIPtr uri = NULL;
         if (!(uri = xmlParseURI(uristr)))
-- 
1.8.1.1.439.g50a6b54


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]