[gnome-photos] Allow remote BaseItems to be exported
- From: Debarshi Ray <debarshir src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-photos] Allow remote BaseItems to be exported
- Date: Mon, 27 Jun 2016 07:14:58 +0000 (UTC)
commit e0acad24bbb0c6630c37e03a922d4a44664f0eec
Author: Debarshi Ray <debarshir gnome org>
Date: Fri Jun 24 12:23:17 2016 +0200
Allow remote BaseItems to be exported
Implement the create_filename_fallback pure virtual method so that
a valid filename is available for all BaseItem sub-classes. The
implementations use the same logic used when caching.
Obviously, we should never hit this fallback for LocalItems unless
there is an error in the Tracker metadata.
https://bugzilla.gnome.org/show_bug.cgi?id=766162
src/photos-base-item.c | 2 +
src/photos-facebook-item.c | 36 ++++++++++++++++++++++-----------
src/photos-flickr-item.c | 22 +++++++++++++++++--
src/photos-google-item.c | 43 ++++++++++++++++++++++++++--------------
src/photos-local-item.c | 9 ++++++++
src/photos-media-server-item.c | 17 +++++++++++++++
6 files changed, 99 insertions(+), 30 deletions(-)
---
diff --git a/src/photos-base-item.c b/src/photos-base-item.c
index 9151b16..a961b02 100644
--- a/src/photos-base-item.c
+++ b/src/photos-base-item.c
@@ -1504,6 +1504,8 @@ photos_base_item_populate_from_cursor (PhotosBaseItem *self, TrackerSparqlCursor
priv->name = g_strdup (title);
priv->filename = g_strdup (tracker_sparql_cursor_get_string (cursor, PHOTOS_QUERY_COLUMNS_FILENAME, NULL));
+ if ((priv->filename == NULL || priv->filename[0] == '\0') && !priv->collection)
+ priv->filename = PHOTOS_BASE_ITEM_GET_CLASS (self)->create_filename_fallback (self);
priv->width = tracker_sparql_cursor_get_integer (cursor, PHOTOS_QUERY_COLUMNS_WIDTH);
priv->height = tracker_sparql_cursor_get_integer (cursor, PHOTOS_QUERY_COLUMNS_HEIGHT);
diff --git a/src/photos-facebook-item.c b/src/photos-facebook-item.c
index 38b55d9..00c6af6 100644
--- a/src/photos-facebook-item.c
+++ b/src/photos-facebook-item.c
@@ -63,6 +63,27 @@ G_DEFINE_TYPE_WITH_CODE (PhotosFacebookItem, photos_facebook_item, PHOTOS_TYPE_B
static gchar *
+photos_facebook_item_create_filename_fallback (PhotosBaseItem *item)
+{
+ const gchar *identifier;
+ const gchar *mime_type;
+ gchar *extension = NULL;
+ gchar *ret_val;
+
+ identifier = photos_base_item_get_identifier (item) + strlen ("facebook:");
+ mime_type = photos_base_item_get_mime_type (item);
+ extension = photos_utils_get_extension_from_mime_type (mime_type);
+ if (extension == NULL)
+ extension = g_strdup ("tmp");
+
+ ret_val = g_strdup_printf ("%s.%s", identifier, extension);
+
+ g_free (extension);
+ return ret_val;
+}
+
+
+static gchar *
photos_facebook_item_create_name_fallback (PhotosBaseItem *item)
{
PhotosFacebookItem *self = PHOTOS_FACEBOOK_ITEM (item);
@@ -171,11 +192,8 @@ photos_facebook_item_download (PhotosBaseItem *item, GCancellable *cancellable,
GFile *local_file = NULL;
GFile *remote_file = NULL;
const gchar *cache_dir;
- const gchar *mime_type;
- const gchar *identifier;
- gchar *extension = NULL;
+ const gchar *local_filename;
gchar *local_dir = NULL;
- gchar *local_filename = NULL;
gchar *local_path = NULL;
gchar *ret_val = NULL;
@@ -183,12 +201,7 @@ photos_facebook_item_download (PhotosBaseItem *item, GCancellable *cancellable,
local_dir = g_build_filename (cache_dir, PACKAGE_TARNAME, "facebook", NULL);
g_mkdir_with_parents (local_dir, 0700);
- identifier = photos_base_item_get_identifier (item) + strlen ("facebook:");
- mime_type = photos_base_item_get_mime_type (item);
- extension = photos_utils_get_extension_from_mime_type (mime_type);
- if (extension == NULL)
- extension = g_strdup ("tmp");
- local_filename = g_strdup_printf ("%s.%s", identifier, extension);
+ local_filename = photos_base_item_get_filename (item);
local_path = g_build_filename (local_dir, local_filename, NULL);
if (g_file_test (local_path, G_FILE_TEST_EXISTS))
goto end;
@@ -226,9 +239,7 @@ photos_facebook_item_download (PhotosBaseItem *item, GCancellable *cancellable,
out:
g_free (local_path);
- g_free (local_filename);
g_free (local_dir);
- g_free (extension);
g_clear_object (&local_file);
g_clear_object (&remote_file);
g_clear_object (&photo);
@@ -318,6 +329,7 @@ photos_facebook_item_class_init (PhotosFacebookItemClass *class)
object_class->constructed = photos_facebook_item_constructed;
object_class->dispose = photos_facebook_item_dispose;
+ base_item_class->create_filename_fallback = photos_facebook_item_create_filename_fallback;
base_item_class->create_name_fallback = photos_facebook_item_create_name_fallback;
base_item_class->create_thumbnail = photos_facebook_item_create_thumbnail;
base_item_class->download = photos_facebook_item_download;
diff --git a/src/photos-flickr-item.c b/src/photos-flickr-item.c
index b682cdf..249782a 100644
--- a/src/photos-flickr-item.c
+++ b/src/photos-flickr-item.c
@@ -73,6 +73,22 @@ struct _PhotosFlickrItemSyncData
static gchar *
+photos_flickr_item_create_filename_fallback (PhotosBaseItem *item)
+{
+ GFile *file = NULL;
+ const gchar *uri;
+ gchar *ret_val;
+
+ uri = photos_base_item_get_uri (item);
+ file = g_file_new_for_uri (uri);
+ ret_val = g_file_get_basename (file);
+
+ g_object_unref (file);
+ return ret_val;
+}
+
+
+static gchar *
photos_flickr_item_create_name_fallback (PhotosBaseItem *item)
{
PhotosFlickrItem *self = PHOTOS_FLICKR_ITEM (item);
@@ -263,9 +279,9 @@ photos_flickr_item_download (PhotosBaseItem *item, GCancellable *cancellable, GE
GFile *local_file = NULL;
GFile *remote_file = NULL;
const gchar *cache_dir;
+ const gchar *local_filename;
const gchar *uri;
gchar *local_dir = NULL;
- gchar *local_filename = NULL;
gchar *local_path = NULL;
gchar *ret_val = NULL;
@@ -276,7 +292,7 @@ photos_flickr_item_download (PhotosBaseItem *item, GCancellable *cancellable, GE
local_dir = g_build_filename (cache_dir, PACKAGE_TARNAME, "flickr", NULL);
g_mkdir_with_parents (local_dir, 0700);
- local_filename = g_file_get_basename (remote_file);
+ local_filename = photos_base_item_get_filename (item);
local_path = g_build_filename (local_dir, local_filename, NULL);
local_file = g_file_new_for_path (local_path);
@@ -301,7 +317,6 @@ photos_flickr_item_download (PhotosBaseItem *item, GCancellable *cancellable, GE
out:
g_free (local_path);
- g_free (local_filename);
g_free (local_dir);
g_object_unref (local_file);
g_object_unref (remote_file);
@@ -407,6 +422,7 @@ photos_flickr_item_class_init (PhotosFlickrItemClass *class)
object_class->constructed = photos_flickr_item_constructed;
object_class->dispose = photos_flickr_item_dispose;
+ base_item_class->create_filename_fallback = photos_flickr_item_create_filename_fallback;
base_item_class->create_name_fallback = photos_flickr_item_create_name_fallback;
base_item_class->create_thumbnail = photos_flickr_item_create_thumbnail;
base_item_class->download = photos_flickr_item_download;
diff --git a/src/photos-google-item.c b/src/photos-google-item.c
index 340320f..f79d995 100644
--- a/src/photos-google-item.c
+++ b/src/photos-google-item.c
@@ -61,6 +61,31 @@ G_DEFINE_TYPE_WITH_CODE (PhotosGoogleItem, photos_google_item, PHOTOS_TYPE_BASE_
static gchar *
+photos_google_item_create_filename_fallback (PhotosBaseItem *item)
+{
+ const gchar *identifier;
+ const gchar *mime_type;
+ gchar *extension = NULL;
+ gchar *identifier_hash = NULL;
+ gchar *ret_val;
+
+ identifier = photos_base_item_get_identifier (item);
+ identifier_hash = g_compute_checksum_for_string (G_CHECKSUM_SHA1, identifier, -1);
+
+ mime_type = photos_base_item_get_mime_type (item);
+ extension = photos_utils_get_extension_from_mime_type (mime_type);
+ if (extension == NULL)
+ extension = g_strdup ("tmp");
+
+ ret_val = g_strdup_printf ("%s.%s", identifier_hash, extension);
+
+ g_free (extension);
+ g_free (identifier_hash);
+ return ret_val;
+}
+
+
+static gchar *
photos_google_item_create_name_fallback (PhotosBaseItem *item)
{
PhotosGoogleItem *self = PHOTOS_GOOGLE_ITEM (item);
@@ -203,13 +228,9 @@ photos_google_item_download (PhotosBaseItem *item, GCancellable *cancellable, GE
GFile *local_file = NULL;
GFile *remote_file = NULL;
const gchar *cache_dir;
- const gchar *identifier;
- const gchar *mime_type;
+ const gchar *local_filename;
const gchar *uri;
- gchar *extension = NULL;
- gchar *identifier_hash = NULL;
gchar *local_dir = NULL;
- gchar *local_filename = NULL;
gchar *local_path = NULL;
gchar *ret_val = NULL;
@@ -217,13 +238,7 @@ photos_google_item_download (PhotosBaseItem *item, GCancellable *cancellable, GE
local_dir = g_build_filename (cache_dir, PACKAGE_TARNAME, "google", NULL);
g_mkdir_with_parents (local_dir, 0700);
- identifier = photos_base_item_get_identifier (item);
- identifier_hash = g_compute_checksum_for_string (G_CHECKSUM_SHA1, identifier, -1);
- mime_type = photos_base_item_get_mime_type (item);
- extension = photos_utils_get_extension_from_mime_type (mime_type);
- if (extension == NULL)
- extension = g_strdup ("tmp");
- local_filename = g_strdup_printf ("%s.%s", identifier_hash, extension);
+ local_filename = photos_base_item_get_filename (item);
local_path = g_build_filename (local_dir, local_filename, NULL);
if (g_file_test (local_path, G_FILE_TEST_EXISTS))
goto end;
@@ -255,10 +270,7 @@ photos_google_item_download (PhotosBaseItem *item, GCancellable *cancellable, GE
out:
g_free (local_path);
- g_free (local_filename);
g_free (local_dir);
- g_free (identifier_hash);
- g_free (extension);
g_clear_object (&local_file);
g_clear_object (&remote_file);
g_clear_object (&entry);
@@ -350,6 +362,7 @@ photos_google_item_class_init (PhotosGoogleItemClass *class)
object_class->constructed = photos_google_item_constructed;
object_class->dispose = photos_google_item_dispose;
+ base_item_class->create_filename_fallback = photos_google_item_create_filename_fallback;
base_item_class->create_name_fallback = photos_google_item_create_name_fallback;
base_item_class->create_thumbnail = photos_google_item_create_thumbnail;
base_item_class->download = photos_google_item_download;
diff --git a/src/photos-local-item.c b/src/photos-local-item.c
index b821f4c..7dffb80 100644
--- a/src/photos-local-item.c
+++ b/src/photos-local-item.c
@@ -55,6 +55,14 @@ G_DEFINE_TYPE_WITH_CODE (PhotosLocalItem, photos_local_item, PHOTOS_TYPE_BASE_IT
static gchar *
+photos_local_item_create_filename_fallback (PhotosBaseItem *item)
+{
+ g_warn_if_reached ();
+ return NULL;
+}
+
+
+static gchar *
photos_local_item_create_name_fallback (PhotosBaseItem *item)
{
const gchar *filename;
@@ -256,6 +264,7 @@ photos_local_item_class_init (PhotosLocalItemClass *class)
object_class->constructed = photos_local_item_constructed;
object_class->dispose = photos_local_item_dispose;
+ base_item_class->create_filename_fallback = photos_local_item_create_filename_fallback;
base_item_class->create_name_fallback = photos_local_item_create_name_fallback;
base_item_class->create_pipeline_path = photos_local_item_create_pipeline_path;
base_item_class->create_thumbnail = photos_local_item_create_thumbnail;
diff --git a/src/photos-media-server-item.c b/src/photos-media-server-item.c
index c0186b1..58e6a95 100644
--- a/src/photos-media-server-item.c
+++ b/src/photos-media-server-item.c
@@ -60,6 +60,22 @@ G_DEFINE_TYPE_WITH_CODE (PhotosMediaServerItem, photos_media_server_item, PHOTOS
static gchar *
+photos_media_server_item_create_filename_fallback (PhotosBaseItem *item)
+{
+ GFile *file = NULL;
+ const gchar *uri;
+ gchar *ret_val;
+
+ uri = photos_base_item_get_uri (item);
+ file = g_file_new_for_uri (uri);
+ ret_val = g_file_get_basename (file);
+
+ g_object_unref (file);
+ return ret_val;
+}
+
+
+static gchar *
photos_media_server_item_create_name_fallback (PhotosBaseItem *item)
{
/* TODO: provide a sane fallback */
@@ -202,6 +218,7 @@ photos_media_server_item_class_init (PhotosMediaServerItemClass *class)
object_class->constructed = photos_media_server_item_constructed;
object_class->dispose = photos_media_server_item_dispose;
+ base_item_class->create_filename_fallback = photos_media_server_item_create_filename_fallback;
base_item_class->create_name_fallback = photos_media_server_item_create_name_fallback;
base_item_class->create_thumbnail = photos_media_server_item_create_thumbnail;
base_item_class->download = photos_media_server_item_download;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]