[Spice-devel] [PATCH spice-gtk 2/2] session: add shared-dir property and option

Marc-André Lureau marcandre.lureau at gmail.com
Fri Feb 28 04:16:19 PST 2014


From: Marc-André Lureau <marcandre.lureau at redhat.com>

Allow to specify the shared directory from the command line, or at
runtime via properties. (still default to xdg public share, if none
specified)
---
 gtk/channel-webdav.c     |  8 ++++++--
 gtk/spice-option.c       |  5 +++++
 gtk/spice-session-priv.h |  3 +++
 gtk/spice-session.c      | 49 +++++++++++++++++++++++++++++++++++++++++++++++-
 4 files changed, 62 insertions(+), 3 deletions(-)

diff --git a/gtk/channel-webdav.c b/gtk/channel-webdav.c
index 28760f5..ffd617e 100644
--- a/gtk/channel-webdav.c
+++ b/gtk/channel-webdav.c
@@ -36,7 +36,11 @@ static PhodavServer* phodav_server_get(SpiceSession *session, gint *port);
  *
  * The "webdav" channel exports a directory to the guest for file
  * manipulation (read/write/copy etc). The underlying protocol is
- * implemented using WebDAV (RFC 4918)
+ * implemented using WebDAV (RFC 4918).
+ *
+ * By default, the shared directory is the one associated with GLib
+ * %G_USER_DIRECTORY_PUBLIC_SHARE. You can specify a different
+ * directory with #SpiceSession #SpiceSession:shared-dir property.
  *
  * Since: 0.24
  */
@@ -697,7 +701,7 @@ static PhodavServer* webdav_server_new(SpiceSession *session)
 
     g_warn_if_fail(!session->priv->webdav);
 
-    dav = phodav_server_new(0, g_get_user_special_dir(G_USER_DIRECTORY_PUBLIC_SHARE));
+    dav = phodav_server_new(0, spice_session_get_shared_dir(session));
     session->priv->webdav = dav;
     for (i = 0; i < sizeof(session->priv->webdav_magic); i++)
         session->priv->webdav_magic[i] = g_random_int_range(0, 255);
diff --git a/gtk/spice-option.c b/gtk/spice-option.c
index 5f7c803..1c861e2 100644
--- a/gtk/spice-option.c
+++ b/gtk/spice-option.c
@@ -41,6 +41,7 @@ static gboolean disable_usbredir = FALSE;
 static gint cache_size = 0;
 static gint glz_window_size = 0;
 static gchar *secure_channels = NULL;
+static gchar *shared_dir = NULL;
 
 G_GNUC_NORETURN
 static void option_version(void)
@@ -192,6 +193,8 @@ GOptionGroup* spice_get_option_group(void)
           N_("Image cache size"), N_("<bytes>") },
         { "spice-glz-window-size", '\0', 0, G_OPTION_ARG_INT, &glz_window_size,
           N_("Glz compression history size"), N_("<bytes>") },
+        { "spice-shared-dir", '\0', 0, G_OPTION_ARG_FILENAME, &shared_dir,
+          N_("Shared directory"), N_("<dir>") },
 
         { "spice-debug", '\0', G_OPTION_FLAG_NO_ARG, G_OPTION_ARG_CALLBACK, option_debug,
           N_("Enable Spice-GTK debugging"), NULL },
@@ -275,4 +278,6 @@ void spice_set_session_option(SpiceSession *session)
         g_object_set(session, "cache-size", cache_size, NULL);
     if (glz_window_size)
         g_object_set(session, "glz-window-size", glz_window_size, NULL);
+    if (shared_dir)
+        g_object_set(session, "shared-dir", shared_dir, NULL);
 }
diff --git a/gtk/spice-session-priv.h b/gtk/spice-session-priv.h
index cf9f9d1..94535a8 100644
--- a/gtk/spice-session-priv.h
+++ b/gtk/spice-session-priv.h
@@ -46,6 +46,7 @@ struct _SpiceSessionPrivate {
     guint             verify;
     gboolean          read_only;
     SpiceURI          *proxy;
+    gchar             *shared_dir;
 
     /* whether to enable audio */
     gboolean          audio;
@@ -160,6 +161,8 @@ void spice_session_set_name(SpiceSession *session, const gchar *name);
 gboolean spice_session_is_playback_active(SpiceSession *session);
 guint32 spice_session_get_playback_latency(SpiceSession *session);
 void spice_session_sync_playback_latency(SpiceSession *session);
+const gchar* spice_session_get_shared_dir(SpiceSession *session);
+void spice_session_set_shared_dir(SpiceSession *session, const gchar *dir);
 
 G_END_DECLS
 
diff --git a/gtk/spice-session.c b/gtk/spice-session.c
index ea32cf7..bd88b7e 100644
--- a/gtk/spice-session.c
+++ b/gtk/spice-session.c
@@ -108,7 +108,8 @@ enum {
     PROP_NAME,
     PROP_CA,
     PROP_PROXY,
-    PROP_SECURE_CHANNELS
+    PROP_SECURE_CHANNELS,
+    PROP_SHARED_DIR
 };
 
 /* signals */
@@ -237,6 +238,7 @@ spice_session_finalize(GObject *gobject)
     g_free(s->smartcard_db);
     g_strfreev(s->disable_effects);
     g_strfreev(s->secure_channels);
+    g_free(s->shared_dir);
 
     g_clear_pointer(&s->images, cache_unref);
     glz_decoder_window_destroy(s->glz_window);
@@ -502,6 +504,9 @@ static void spice_session_get_property(GObject    *gobject,
     case PROP_PROXY:
         g_value_take_string(value, spice_uri_to_string(s->proxy));
 	break;
+    case PROP_SHARED_DIR:
+        g_value_set_string(value, spice_session_get_shared_dir(session));
+        break;
     default:
 	G_OBJECT_WARN_INVALID_PROPERTY_ID(gobject, prop_id, pspec);
 	break;
@@ -624,6 +629,9 @@ static void spice_session_set_property(GObject      *gobject,
     case PROP_PROXY:
         update_proxy(session, g_value_get_string(value));
         break;
+    case PROP_SHARED_DIR:
+        spice_session_set_shared_dir(session, g_value_get_string(value));
+        break;
     default:
         G_OBJECT_WARN_INVALID_PROPERTY_ID(gobject, prop_id, pspec);
         break;
@@ -1171,6 +1179,23 @@ static void spice_session_class_init(SpiceSessionClass *klass)
                              G_PARAM_READWRITE |
                              G_PARAM_STATIC_STRINGS));
 
+    /**
+     * SpiceSession:shared-dir:
+     *
+     * Location of the shared directory
+     *
+     * Since: 0.24
+     **/
+    g_object_class_install_property
+        (gobject_class, PROP_SHARED_DIR,
+         g_param_spec_string("shared-dir",
+                             "Shared directory",
+                             "Shared directory",
+                             g_get_user_special_dir(G_USER_DIRECTORY_PUBLIC_SHARE),
+                             G_PARAM_READWRITE |
+                             G_PARAM_CONSTRUCT |
+                             G_PARAM_STATIC_STRINGS));
+
     g_type_class_add_private(klass, sizeof(SpiceSessionPrivate));
 }
 
@@ -2191,6 +2216,28 @@ guint32 spice_session_get_playback_latency(SpiceSession *session)
     }
 }
 
+G_GNUC_INTERNAL
+const gchar* spice_session_get_shared_dir(SpiceSession *session)
+{
+    SpiceSessionPrivate *s = SPICE_SESSION_GET_PRIVATE(session);
+
+    g_return_val_if_fail(s != NULL, NULL);
+
+    return s->shared_dir;
+}
+
+G_GNUC_INTERNAL
+void spice_session_set_shared_dir(SpiceSession *session, const gchar *dir)
+{
+    SpiceSessionPrivate *s = SPICE_SESSION_GET_PRIVATE(session);
+
+    g_return_if_fail(dir != NULL);
+    g_return_if_fail(s != NULL);
+
+    g_free(s->shared_dir);
+    s->shared_dir = g_strdup(dir);
+}
+
 /**
  * spice_session_get_proxy_uri:
  * @session: a #SpiceSession
-- 
1.8.5.3



More information about the Spice-devel mailing list