[virt-tools-list] [PATCH virt-viewer 5/7] Add VirtViewerSession:file property

Marc-André Lureau marcandre.lureau at gmail.com
Fri Nov 23 12:41:10 UTC 2012


If VirtViewerSession:file is set, it should be used to define the
connection parameters. Also correct the mime type used in this case.
---
 src/remote-viewer-main.c  |  1 +
 src/virt-viewer-session.c | 39 +++++++++++++++++++++++++++++++++++++++
 src/virt-viewer-session.h |  3 +++
 3 files changed, 43 insertions(+)

diff --git a/src/remote-viewer-main.c b/src/remote-viewer-main.c
index 053e146..13cacc3 100644
--- a/src/remote-viewer-main.c
+++ b/src/remote-viewer-main.c
@@ -136,6 +136,7 @@ static gint connect_dialog(gchar **uri)
     rfilter = gtk_recent_filter_new();
     gtk_recent_filter_add_mime_type(rfilter, "application/x-spice");
     gtk_recent_filter_add_mime_type(rfilter, "application/x-vnc");
+    gtk_recent_filter_add_mime_type(rfilter, "application/x-virt-viewer");
     gtk_recent_chooser_set_filter(GTK_RECENT_CHOOSER(recent), rfilter);
     gtk_recent_chooser_set_local_only(GTK_RECENT_CHOOSER(recent), FALSE);
     g_signal_connect(recent, "selection-changed",
diff --git a/src/virt-viewer-session.c b/src/virt-viewer-session.c
index 6205e30..ccb13d0 100644
--- a/src/virt-viewer-session.c
+++ b/src/virt-viewer-session.c
@@ -38,6 +38,7 @@ struct _VirtViewerSessionPrivate
     VirtViewerApp *app;
     gboolean auto_usbredir;
     gchar *uri;
+    VirtViewerFile *file;
 };
 
 G_DEFINE_ABSTRACT_TYPE(VirtViewerSession, virt_viewer_session, G_TYPE_OBJECT)
@@ -47,6 +48,7 @@ enum {
 
     PROP_APP,
     PROP_AUTO_USBREDIR,
+    PROP_FILE
 };
 
 static void
@@ -62,6 +64,7 @@ virt_viewer_session_finalize(GObject *obj)
     g_list_free(session->priv->displays);
 
     g_free(session->priv->uri);
+    g_clear_object(&session->priv->file);
 
     G_OBJECT_CLASS(virt_viewer_session_parent_class)->finalize(obj);
 }
@@ -83,6 +86,10 @@ virt_viewer_session_set_property(GObject *object,
         self->priv->app = g_value_get_object(value);
         break;
 
+    case PROP_FILE:
+        virt_viewer_session_set_file(self, g_value_get_object(value));
+        break;
+
     default:
         G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
         break;
@@ -106,6 +113,10 @@ virt_viewer_session_get_property(GObject *object,
         g_value_set_object(value, self->priv->app);
         break;
 
+    case PROP_FILE:
+        g_value_set_object(value, self->priv->file);
+        break;
+
     default:
         G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
         break;
@@ -141,6 +152,16 @@ virt_viewer_session_class_init(VirtViewerSessionClass *class)
                                                          G_PARAM_CONSTRUCT |
                                                          G_PARAM_STATIC_STRINGS));
 
+    g_object_class_install_property(object_class,
+                                    PROP_FILE,
+                                    g_param_spec_object("file",
+                                                         "VirtViewerFile",
+                                                         "VirtViewerFile",
+                                                         VIRT_VIEWER_TYPE_FILE,
+                                                         G_PARAM_READWRITE |
+                                                         G_PARAM_CONSTRUCT |
+                                                         G_PARAM_STATIC_STRINGS));
+
     g_signal_new("session-connected",
                  G_OBJECT_CLASS_TYPE(object_class),
                  G_SIGNAL_RUN_FIRST,
@@ -373,6 +394,9 @@ const gchar* virt_viewer_session_mime_type(VirtViewerSession *self)
 
     g_return_val_if_fail(VIRT_VIEWER_IS_SESSION(self), NULL);
 
+    if (self->priv->file)
+        return "application/x-virt-viewer";
+
     klass = VIRT_VIEWER_SESSION_GET_CLASS(self);
     g_return_val_if_fail(klass->mime_type != NULL, FALSE);
 
@@ -475,6 +499,21 @@ gchar* virt_viewer_session_get_uri(VirtViewerSession *self)
     return g_strdup(self->priv->uri);
 }
 
+void virt_viewer_session_set_file(VirtViewerSession *self, VirtViewerFile *file)
+{
+    g_return_if_fail(VIRT_VIEWER_IS_SESSION(self));
+
+    g_clear_object(&self->priv->file);
+    if (file)
+        self->priv->file = g_object_ref(file);
+}
+
+VirtViewerFile* virt_viewer_session_get_file(VirtViewerSession *self)
+{
+    g_return_val_if_fail(VIRT_VIEWER_IS_SESSION(self), NULL);
+
+    return self->priv->file;
+}
 
 /*
  * Local variables:
diff --git a/src/virt-viewer-session.h b/src/virt-viewer-session.h
index 30def16..f337937 100644
--- a/src/virt-viewer-session.h
+++ b/src/virt-viewer-session.h
@@ -27,6 +27,7 @@
 #include <gtk/gtk.h>
 
 #include "virt-viewer-app.h"
+#include "virt-viewer-file.h"
 #include "virt-viewer-display.h"
 
 G_BEGIN_DECLS
@@ -124,6 +125,8 @@ void virt_viewer_session_smartcard_insert(VirtViewerSession *self);
 void virt_viewer_session_smartcard_remove(VirtViewerSession *self);
 VirtViewerApp* virt_viewer_session_get_app(VirtViewerSession *self);
 gchar* virt_viewer_session_get_uri(VirtViewerSession *self);
+void virt_viewer_session_set_file(VirtViewerSession *self, VirtViewerFile *file);
+VirtViewerFile* virt_viewer_session_get_file(VirtViewerSession *self);
 
 G_END_DECLS
 
-- 
1.7.11.7




More information about the virt-tools-list mailing list