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

Hans de Goede hdegoede at redhat.com
Fri Mar 8 08:23:57 UTC 2013


ACK.

On 03/07/2013 08:55 PM, Marc-André Lureau wrote:
> 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          | 52 +++++++++++++++++++++++++++++++++++++----
>   src/virt-viewer-file.h          |  4 +++-
>   src/virt-viewer-session-spice.c |  3 ++-
>   src/virt-viewer-session-vnc.c   |  3 ++-
>   4 files changed, 55 insertions(+), 7 deletions(-)
>
> diff --git a/src/virt-viewer-file.c b/src/virt-viewer-file.c
> index 33b9666..cae7566 100644
> --- a/src/virt-viewer-file.c
> +++ b/src/virt-viewer-file.c
> @@ -36,6 +36,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
> @@ -96,6 +97,7 @@ enum  {
>       PROP_ENABLE_USB_AUTOSHARE,
>       PROP_USB_FILTER,
>       PROP_PROXY,
> +    PROP_VERSION,
>   };
>
>   VirtViewerFile*
> @@ -525,6 +527,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)
>   {
> @@ -541,11 +556,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));
> @@ -577,6 +609,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
> @@ -652,6 +686,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;
> @@ -728,6 +765,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;
> @@ -846,4 +886,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)))
>




More information about the virt-tools-list mailing list