[gnome-photos/wip/rishi/collection: 17/40] source: Support GMount-backed sources for importing



commit 16f317af2d98a055feba5bef9b6c88bb9122ae1c
Author: Debarshi Ray <debarshir gnome org>
Date:   Sun Sep 3 12:13:14 2017 +0200

    source: Support GMount-backed sources for importing
    
    https://bugzilla.gnome.org/show_bug.cgi?id=751212

 src/photos-source.c | 74 ++++++++++++++++++++++++++++++++++++++++++++++++++---
 src/photos-source.h |  6 ++++-
 2 files changed, 76 insertions(+), 4 deletions(-)
---
diff --git a/src/photos-source.c b/src/photos-source.c
index a5c2bf92..a61d5f6c 100644
--- a/src/photos-source.c
+++ b/src/photos-source.c
@@ -36,6 +36,7 @@ struct _PhotosSource
   GObject parent_instance;
   GIcon *icon;
   GIcon *symbolic_icon;
+  GMount *mount;
   GoaObject *object;
   gboolean builtin;
   gchar *id;
@@ -47,6 +48,7 @@ enum
   PROP_0,
   PROP_BUILTIN,
   PROP_ID,
+  PROP_MOUNT,
   PROP_NAME,
   PROP_OBJECT
 };
@@ -69,9 +71,22 @@ photos_source_build_filter_resource (PhotosSource *self)
   g_return_val_if_fail (!self->builtin, NULL);
 
   if (self->object != NULL)
-    filter = g_strdup_printf ("(nie:dataSource (?urn) = '%s')", self->id);
+    {
+      filter = g_strdup_printf ("(nie:dataSource (?urn) = '%s')", self->id);
+    }
+  else if (self->mount != NULL)
+    {
+      g_autoptr (GFile) root = NULL;
+      g_autofree gchar *root_uri = NULL;
+
+      root = g_mount_get_root (self->mount);
+      root_uri = g_file_get_uri (root);
+      filter = g_strdup_printf ("(fn:starts-with (nie:url (?urn), '%s'))", root_uri);
+    }
   else
-    g_return_val_if_reached (NULL);
+    {
+      g_return_val_if_reached (NULL);
+    }
 
   ret_val = g_steal_pointer (&filter);
   return ret_val;
@@ -111,7 +126,11 @@ photos_source_get_id (PhotosFilterable *filterable)
 static gboolean
 photos_source_is_search_criterion (PhotosFilterable *filterable)
 {
-  return TRUE;
+  PhotosSource *self = PHOTOS_SOURCE (filterable);
+  gboolean ret_val;
+
+  ret_val = self->mount == NULL;
+  return ret_val;
 }
 
 
@@ -121,6 +140,7 @@ photos_source_dispose (GObject *object)
   PhotosSource *self = PHOTOS_SOURCE (object);
 
   g_clear_object (&self->icon);
+  g_clear_object (&self->mount);
   g_clear_object (&self->object);
   g_clear_object (&self->symbolic_icon);
 
@@ -157,6 +177,10 @@ photos_source_get_property (GObject *object, guint prop_id, GValue *value, GPara
       g_value_set_string (value, self->id);
       break;
 
+    case PROP_MOUNT:
+      g_value_set_object (value, self->mount);
+      break;
+
     case PROP_NAME:
       g_value_set_string (value, self->name);
       break;
@@ -196,6 +220,27 @@ photos_source_set_property (GObject *object, guint prop_id, const GValue *value,
         break;
       }
 
+    case PROP_MOUNT:
+      {
+        g_autoptr (GFile) root = NULL;
+        const gchar *type_name;
+        g_autofree gchar *uri = NULL;
+
+        self->mount = G_MOUNT (g_value_dup_object (value));
+        if (self->mount == NULL)
+          break;
+
+        type_name = G_OBJECT_TYPE_NAME (self->mount);
+        root = g_mount_get_root (self->mount);
+        uri = g_file_get_uri (root);
+        self->id = g_strdup_printf ("gd:g-mount:%s:%s", type_name, uri);
+
+        self->icon = g_mount_get_icon (self->mount);
+        self->symbolic_icon = g_mount_get_symbolic_icon (self->mount);
+        self->name = g_mount_get_name (self->mount);
+        break;
+      }
+
     case PROP_NAME:
       {
         const gchar *name;
@@ -273,6 +318,14 @@ photos_source_class_init (PhotosSourceClass *class)
                                                         NULL,
                                                         G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE));
 
+  g_object_class_install_property (object_class,
+                                   PROP_MOUNT,
+                                   g_param_spec_object ("mount",
+                                                        "GMount instance",
+                                                        "A mount point representing a removable device (eg., 
camera)",
+                                                        G_TYPE_MOUNT,
+                                                        G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE));
+
   g_object_class_install_property (object_class,
                                    PROP_NAME,
                                    g_param_spec_string ("name",
@@ -316,6 +369,14 @@ photos_source_new_from_goa_object (GoaObject *object)
 }
 
 
+PhotosSource *
+photos_source_new_from_mount (GMount *mount)
+{
+  g_return_val_if_fail (G_IS_MOUNT (mount), NULL);
+  return g_object_new (PHOTOS_TYPE_SOURCE, "mount", mount, NULL);
+}
+
+
 const gchar *
 photos_source_get_name (PhotosSource *self)
 {
@@ -337,6 +398,13 @@ photos_source_get_icon (PhotosSource *self)
 }
 
 
+GMount *
+photos_source_get_mount (PhotosSource *self)
+{
+  return self->mount;
+}
+
+
 GIcon *
 photos_source_get_symbolic_icon (PhotosSource *self)
 {
diff --git a/src/photos-source.h b/src/photos-source.h
index 1067137a..b0d0dd15 100644
--- a/src/photos-source.h
+++ b/src/photos-source.h
@@ -23,7 +23,7 @@
 #ifndef PHOTOS_SOURCE_H
 #define PHOTOS_SOURCE_H
 
-#include <glib-object.h>
+#include <gio/gio.h>
 #include <goa/goa.h>
 
 G_BEGIN_DECLS
@@ -38,12 +38,16 @@ PhotosSource       *photos_source_new                    (const gchar *id, const
 
 PhotosSource       *photos_source_new_from_goa_object    (GoaObject *object);
 
+PhotosSource       *photos_source_new_from_mount         (GMount *mount);
+
 const gchar        *photos_source_get_name               (PhotosSource *self);
 
 GoaObject          *photos_source_get_goa_object         (PhotosSource *self);
 
 GIcon              *photos_source_get_icon               (PhotosSource *self);
 
+GMount             *photos_source_get_mount              (PhotosSource *self);
+
 GIcon              *photos_source_get_symbolic_icon      (PhotosSource *self);
 
 G_END_DECLS


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