[gnome-photos/wip/rishi/import-7: 3/5] base-item, utils: Query the GFileInfo directly with the BaseItem
- From: Debarshi Ray <debarshir src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-photos/wip/rishi/import-7: 3/5] base-item, utils: Query the GFileInfo directly with the BaseItem
- Date: Wed, 14 Feb 2018 19:11:38 +0000 (UTC)
commit e547d8633a9d52d15e9fe1e42daa580828da5429
Author: Debarshi Ray <debarshir gnome org>
Date: Wed Jan 24 22:21:43 2018 +0100
base-item, utils: Query the GFileInfo directly with the BaseItem
This is required to transparently query the state of the thumbnail
across different BaseItem sub-classes that might have different
thumbnail caches.
https://gitlab.gnome.org/GNOME/gnome-photos/issues/29
src/photos-base-item.c | 218 ++++++++++++++++++++++++++++++++++++++++---------
src/photos-base-item.h | 18 ++++
src/photos-utils.c | 175 ++-------------------------------------
src/photos-utils.h | 18 ----
4 files changed, 203 insertions(+), 226 deletions(-)
---
diff --git a/src/photos-base-item.c b/src/photos-base-item.c
index 0f1624df..4beb9f1e 100644
--- a/src/photos-base-item.c
+++ b/src/photos-base-item.c
@@ -140,6 +140,7 @@ EGG_DEFINE_COUNTER (instances, "PhotosBaseItem", "Instances", "Number of PhotosB
typedef struct _PhotosBaseItemMetadataAddSharedData PhotosBaseItemMetadataAddSharedData;
+typedef struct _PhotosBaseItemQueryInfoData PhotosBaseItemQueryInfoData;
typedef struct _PhotosBaseItemSaveData PhotosBaseItemSaveData;
typedef struct _PhotosBaseItemSaveBufferData PhotosBaseItemSaveBufferData;
typedef struct _PhotosBaseItemSaveToFileData PhotosBaseItemSaveToFileData;
@@ -152,6 +153,12 @@ struct _PhotosBaseItemMetadataAddSharedData
gchar *shared_id;
};
+struct _PhotosBaseItemQueryInfoData
+{
+ GFileQueryInfoFlags flags;
+ gchar *attributes;
+};
+
struct _PhotosBaseItemSaveData
{
GFile *dir;
@@ -219,6 +226,27 @@ photos_base_item_metadata_add_shared_data_free (PhotosBaseItemMetadataAddSharedD
}
+static PhotosBaseItemQueryInfoData *
+photos_base_item_query_info_data_new (const gchar *attributes, GFileQueryInfoFlags flags)
+{
+ PhotosBaseItemQueryInfoData *data;
+
+ data = g_slice_new0 (PhotosBaseItemQueryInfoData);
+ data->flags = flags;
+ data->attributes = g_strdup (attributes);
+
+ return data;
+}
+
+
+static void
+photos_base_item_query_info_data_free (PhotosBaseItemQueryInfoData *data)
+{
+ g_free (data->attributes);
+ g_slice_free (PhotosBaseItemQueryInfoData, data);
+}
+
+
static PhotosBaseItemSaveData *
photos_base_item_save_data_new (GFile *dir, GeglBuffer *buffer, const gchar *type, gdouble zoom)
{
@@ -726,30 +754,25 @@ photos_base_item_refresh_thumb_path (PhotosBaseItem *self)
static void
photos_base_item_thumbnail_path_info (GObject *source_object, GAsyncResult *res, gpointer user_data)
{
- PhotosBaseItem *self;
+ PhotosBaseItem *self = PHOTOS_BASE_ITEM (source_object);
PhotosBaseItemPrivate *priv;
- GFile *file = G_FILE (source_object);
g_autoptr (GFileInfo) info = NULL;
+ priv = photos_base_item_get_instance_private (self);
+
{
g_autoptr (GError) error = NULL;
- info = photos_utils_file_query_info_finish (file, res, &error);
+ info = photos_base_item_query_info_finish (self, res, &error);
if (error != NULL)
{
- g_autofree gchar *uri = NULL;
-
if (g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED))
goto out;
- uri = g_file_get_uri (file);
- g_warning ("Unable to query info for file at %s: %s", uri, error->message);
+ g_warning ("Unable to query info for item at %s: %s", priv->uri, error->message);
}
}
- self = PHOTOS_BASE_ITEM (user_data);
- priv = photos_base_item_get_instance_private (self);
-
g_clear_pointer (&priv->thumb_path, g_free);
if (info == NULL)
@@ -780,7 +803,6 @@ photos_base_item_create_thumbnail_cb (GObject *source_object, GAsyncResult *res,
{
PhotosBaseItem *self = PHOTOS_BASE_ITEM (source_object);
PhotosBaseItemPrivate *priv;
- g_autoptr (GFile) file = G_FILE (user_data);
gboolean success;
{
@@ -805,13 +827,13 @@ photos_base_item_create_thumbnail_cb (GObject *source_object, GAsyncResult *res,
goto out;
}
- photos_utils_file_query_info_async (file,
- G_FILE_ATTRIBUTE_THUMBNAIL_PATH,
- G_FILE_QUERY_INFO_NONE,
- G_PRIORITY_DEFAULT,
- priv->cancellable,
- photos_base_item_thumbnail_path_info,
- self);
+ photos_base_item_query_info_async (self,
+ G_FILE_ATTRIBUTE_THUMBNAIL_PATH,
+ G_FILE_QUERY_INFO_NONE,
+ G_PRIORITY_DEFAULT,
+ priv->cancellable,
+ photos_base_item_thumbnail_path_info,
+ NULL);
out:
return;
@@ -821,30 +843,25 @@ photos_base_item_create_thumbnail_cb (GObject *source_object, GAsyncResult *res,
static void
photos_base_item_file_query_info (GObject *source_object, GAsyncResult *res, gpointer user_data)
{
- PhotosBaseItem *self;
+ PhotosBaseItem *self = PHOTOS_BASE_ITEM (source_object);
PhotosBaseItemPrivate *priv;
- GFile *file = G_FILE (source_object);
g_autoptr (GFileInfo) info = NULL;
+ priv = photos_base_item_get_instance_private (self);
+
{
g_autoptr (GError) error = NULL;
- info = photos_utils_file_query_info_finish (file, res, &error);
+ info = photos_base_item_query_info_finish (self, res, &error);
if (error != NULL)
{
- g_autofree gchar *uri = NULL;
-
if (g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED))
goto out;
- uri = g_file_get_uri (file);
- g_warning ("Unable to query info for file at %s: %s", uri, error->message);
+ g_warning ("Unable to query info for item at %s: %s", priv->uri, error->message);
}
}
- self = PHOTOS_BASE_ITEM (user_data);
- priv = photos_base_item_get_instance_private (self);
-
g_clear_pointer (&priv->thumb_path, g_free);
if (info == NULL)
@@ -862,7 +879,7 @@ photos_base_item_file_query_info (GObject *source_object, GAsyncResult *res, gpo
photos_base_item_create_thumbnail_async (self,
priv->cancellable,
photos_base_item_create_thumbnail_cb,
- g_object_ref (file));
+ NULL);
}
out:
@@ -2584,7 +2601,6 @@ static void
photos_base_item_refresh_icon (PhotosBaseItem *self)
{
PhotosBaseItemPrivate *priv;
- g_autoptr (GFile) file = NULL;
priv = photos_base_item_get_instance_private (self);
@@ -2605,14 +2621,13 @@ photos_base_item_refresh_icon (PhotosBaseItem *self)
return;
}
- file = g_file_new_for_uri (priv->uri);
- photos_utils_file_query_info_async (file,
- G_FILE_ATTRIBUTE_THUMBNAIL_PATH,
- G_FILE_QUERY_INFO_NONE,
- G_PRIORITY_DEFAULT,
- priv->cancellable,
- photos_base_item_file_query_info,
- self);
+ photos_base_item_query_info_async (self,
+ G_FILE_ATTRIBUTE_THUMBNAIL_PATH,
+ G_FILE_QUERY_INFO_NONE,
+ G_PRIORITY_DEFAULT,
+ priv->cancellable,
+ photos_base_item_file_query_info,
+ NULL);
}
@@ -4227,6 +4242,133 @@ photos_base_item_print (PhotosBaseItem *self, GtkWidget *toplevel)
}
+GFileInfo *
+photos_base_item_query_info (PhotosBaseItem *self,
+ const gchar *attributes,
+ GFileQueryInfoFlags flags,
+ GCancellable *cancellable,
+ GError **error)
+{
+ PhotosBaseItemPrivate *priv;
+ GFileAttributeMatcher *matcher = NULL; /* TODO: use g_autoptr */
+ g_autoptr (GFile) file = NULL;
+ g_autoptr (GFileInfo) info = NULL;
+ GFileInfo *ret_val = NULL;
+
+ g_return_val_if_fail (PHOTOS_IS_BASE_ITEM (self), NULL);
+ priv = photos_base_item_get_instance_private (self);
+
+ g_return_val_if_fail (attributes != NULL && attributes[0] != '\0', NULL);
+ g_return_val_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable), NULL);
+ g_return_val_if_fail (error == NULL || *error == NULL, NULL);
+
+ file = g_file_new_for_uri (priv->uri);
+ info = g_file_query_info (file, attributes, flags, cancellable, error);
+ if (info == NULL)
+ goto out;
+
+ matcher = g_file_attribute_matcher_new (attributes);
+ if (g_file_attribute_matcher_matches (matcher, G_FILE_ATTRIBUTE_THUMBNAIL_IS_VALID)
+ || g_file_attribute_matcher_matches (matcher, G_FILE_ATTRIBUTE_THUMBNAIL_PATH)
+ || g_file_attribute_matcher_matches (matcher, G_FILE_ATTRIBUTE_THUMBNAILING_FAILED))
+ {
+ g_autofree gchar *path = NULL;
+
+ g_file_info_remove_attribute (info, G_FILE_ATTRIBUTE_THUMBNAIL_IS_VALID);
+ g_file_info_remove_attribute (info, G_FILE_ATTRIBUTE_THUMBNAIL_PATH);
+ g_file_info_remove_attribute (info, G_FILE_ATTRIBUTE_THUMBNAILING_FAILED);
+
+ path = photos_base_item_create_thumbnail_path (self);
+ if (g_file_test (path, G_FILE_TEST_IS_REGULAR))
+ {
+ g_file_info_set_attribute_boolean (info, G_FILE_ATTRIBUTE_THUMBNAIL_IS_VALID, TRUE);
+ g_file_info_set_attribute_byte_string (info, G_FILE_ATTRIBUTE_THUMBNAIL_PATH, path);
+ g_file_info_set_attribute_boolean (info, G_FILE_ATTRIBUTE_THUMBNAILING_FAILED, FALSE);
+ }
+ }
+
+ ret_val = g_object_ref (info);
+
+ out:
+ g_clear_pointer (&matcher, (GDestroyNotify) g_file_attribute_matcher_unref);
+ return ret_val;
+}
+
+
+static void
+photos_base_item_query_info_in_thread_func (GTask *task,
+ gpointer source_object,
+ gpointer task_data,
+ GCancellable *cancellable)
+{
+ PhotosBaseItem *self = PHOTOS_BASE_ITEM (source_object);
+ g_autoptr (GFileInfo) info = NULL;
+ PhotosBaseItemQueryInfoData *data = (PhotosBaseItemQueryInfoData *) task_data;
+
+ {
+ g_autoptr (GError) error = NULL;
+
+ info = photos_base_item_query_info (self, data->attributes, data->flags, cancellable, &error);
+ if (error != NULL)
+ {
+ g_task_return_error (task, g_steal_pointer (&error));
+ goto out;
+ }
+ }
+
+ g_task_return_pointer (task, g_object_ref (info), g_object_unref);
+
+ out:
+ return;
+}
+
+
+void
+photos_base_item_query_info_async (PhotosBaseItem *self,
+ const gchar *attributes,
+ GFileQueryInfoFlags flags,
+ gint io_priority,
+ GCancellable *cancellable,
+ GAsyncReadyCallback callback,
+ gpointer user_data)
+{
+ g_autoptr (GTask) task = NULL;
+ PhotosBaseItemQueryInfoData *data;
+ const gchar *wildcard;
+
+ g_return_if_fail (PHOTOS_IS_BASE_ITEM (self));
+ g_return_if_fail (attributes != NULL && attributes[0] != '\0');
+ g_return_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable));
+
+ wildcard = strstr (attributes, "*");
+ g_return_if_fail (wildcard == NULL);
+
+ data = photos_base_item_query_info_data_new (attributes, flags);
+
+ task = g_task_new (self, cancellable, callback, user_data);
+ g_task_set_priority (task, io_priority);
+ g_task_set_source_tag (task, photos_base_item_query_info_async);
+ g_task_set_task_data (task, data, (GDestroyNotify) photos_base_item_query_info_data_free);
+
+ g_task_run_in_thread (task, photos_base_item_query_info_in_thread_func);
+}
+
+
+GFileInfo *
+photos_base_item_query_info_finish (PhotosBaseItem *self, GAsyncResult *res, GError **error)
+{
+ GTask *task;
+
+ g_return_val_if_fail (g_task_is_valid (res, self), NULL);
+ task = G_TASK (res);
+
+ g_return_val_if_fail (g_task_get_source_tag (task) == photos_base_item_query_info_async, NULL);
+ g_return_val_if_fail (error == NULL || *error == NULL, NULL);
+
+ return g_task_propagate_pointer (task, error);
+}
+
+
void
photos_base_item_refresh (PhotosBaseItem *self)
{
diff --git a/src/photos-base-item.h b/src/photos-base-item.h
index bc929f1d..516c5828 100644
--- a/src/photos-base-item.h
+++ b/src/photos-base-item.h
@@ -270,6 +270,24 @@ void photos_base_item_pipeline_snapshot (PhotosBaseItem *se
void photos_base_item_print (PhotosBaseItem *self, GtkWidget *toplevel);
+GFileInfo *photos_base_item_query_info (PhotosBaseItem *self,
+ const gchar *attributes,
+ GFileQueryInfoFlags flags,
+ GCancellable *cancellable,
+ GError **error);
+
+void photos_base_item_query_info_async (PhotosBaseItem *self,
+ const gchar *attributes,
+ GFileQueryInfoFlags flags,
+ gint io_priority,
+ GCancellable *cancellable,
+ GAsyncReadyCallback callback,
+ gpointer user_data);
+
+GFileInfo *photos_base_item_query_info_finish (PhotosBaseItem *self,
+ GAsyncResult *res,
+ GError **error);
+
void photos_base_item_refresh (PhotosBaseItem *self);
void photos_base_item_save_to_dir_async (PhotosBaseItem *self,
diff --git a/src/photos-utils.c b/src/photos-utils.c
index c83676a6..1db54b7e 100644
--- a/src/photos-utils.c
+++ b/src/photos-utils.c
@@ -26,8 +26,6 @@
#include "config.h"
-#include <string.h>
-
#include <gdk/gdk.h>
#include <glib.h>
#include <tracker-sparql.h>
@@ -68,14 +66,6 @@
#include "photos-utils.h"
-typedef struct _PhotosUtilsFileQueryInfoData PhotosUtilsFileQueryInfoData;
-
-struct _PhotosUtilsFileQueryInfoData
-{
- GFileQueryInfoFlags flags;
- gchar *attributes;
-};
-
static const gdouble EPSILON = 1e-5;
enum
@@ -423,7 +413,6 @@ photos_utils_create_zoom_target_value (gdouble delta, PhotosZoomEvent event)
static GIcon *
photos_utils_get_thumbnail_icon (PhotosBaseItem *item)
{
- g_autoptr (GFile) file = NULL;
g_autoptr (GFile) thumb_file = NULL;
g_autoptr (GFileInfo) info = NULL;
GIcon *icon = NULL;
@@ -434,16 +423,14 @@ photos_utils_get_thumbnail_icon (PhotosBaseItem *item)
if (uri == NULL || uri[0] == '\0')
goto out;
- file = g_file_new_for_uri (uri);
-
{
g_autoptr (GError) error = NULL;
- info = photos_utils_file_query_info (file,
- G_FILE_ATTRIBUTE_THUMBNAIL_PATH,
- G_FILE_QUERY_INFO_NONE,
- NULL,
- &error);
+ info = photos_base_item_query_info (item,
+ G_FILE_ATTRIBUTE_THUMBNAIL_PATH,
+ G_FILE_QUERY_INFO_NONE,
+ NULL,
+ &error);
if (error != NULL)
{
g_warning ("Unable to fetch thumbnail path for %s: %s", uri, error->message);
@@ -853,145 +840,6 @@ photos_utils_file_copy_as_thumbnail (GFile *source,
}
-GFileInfo *
-photos_utils_file_query_info (GFile *file,
- const gchar *attributes,
- GFileQueryInfoFlags flags,
- GCancellable *cancellable,
- GError **error)
-{
- GFileAttributeMatcher *matcher = NULL; /* TODO: use g_autoptr */
- g_autoptr (GFileInfo) info = NULL;
- GFileInfo *ret_val = NULL;
-
- g_return_val_if_fail (G_IS_FILE (file), NULL);
- g_return_val_if_fail (attributes != NULL && attributes[0] != '\0', NULL);
- g_return_val_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable), NULL);
- g_return_val_if_fail (error == NULL || *error == NULL, NULL);
-
- info = g_file_query_info (file, attributes, flags, cancellable, error);
- if (info == NULL)
- goto out;
-
- matcher = g_file_attribute_matcher_new (attributes);
- if (g_file_attribute_matcher_matches (matcher, G_FILE_ATTRIBUTE_THUMBNAIL_IS_VALID)
- || g_file_attribute_matcher_matches (matcher, G_FILE_ATTRIBUTE_THUMBNAIL_PATH)
- || g_file_attribute_matcher_matches (matcher, G_FILE_ATTRIBUTE_THUMBNAILING_FAILED))
- {
- g_autofree gchar *path = NULL;
-
- g_file_info_remove_attribute (info, G_FILE_ATTRIBUTE_THUMBNAIL_IS_VALID);
- g_file_info_remove_attribute (info, G_FILE_ATTRIBUTE_THUMBNAIL_PATH);
- g_file_info_remove_attribute (info, G_FILE_ATTRIBUTE_THUMBNAILING_FAILED);
-
- path = photos_utils_get_thumbnail_path_for_file (file);
- if (g_file_test (path, G_FILE_TEST_IS_REGULAR))
- {
- g_file_info_set_attribute_boolean (info, G_FILE_ATTRIBUTE_THUMBNAIL_IS_VALID, TRUE);
- g_file_info_set_attribute_byte_string (info, G_FILE_ATTRIBUTE_THUMBNAIL_PATH, path);
- g_file_info_set_attribute_boolean (info, G_FILE_ATTRIBUTE_THUMBNAILING_FAILED, FALSE);
- }
- }
-
- ret_val = g_object_ref (info);
-
- out:
- g_clear_pointer (&matcher, (GDestroyNotify) g_file_attribute_matcher_unref);
- return ret_val;
-}
-
-
-static void
-photos_utils_file_query_info_data_free (PhotosUtilsFileQueryInfoData *data)
-{
- g_free (data->attributes);
- g_slice_free (PhotosUtilsFileQueryInfoData, data);
-}
-
-
-static PhotosUtilsFileQueryInfoData *
-photos_utils_file_query_info_data_new (const gchar *attributes, GFileQueryInfoFlags flags)
-{
- PhotosUtilsFileQueryInfoData *data;
-
- data = g_slice_new0 (PhotosUtilsFileQueryInfoData);
- data->flags = flags;
- data->attributes = g_strdup (attributes);
-
- return data;
-}
-
-
-static void
-photos_utils_file_query_info_in_thread_func (GTask *task,
- gpointer source_object,
- gpointer task_data,
- GCancellable *cancellable)
-{
- GError *error;
- GFile *file = G_FILE (source_object);
- g_autoptr (GFileInfo) info = NULL;
- PhotosUtilsFileQueryInfoData *data = (PhotosUtilsFileQueryInfoData *) task_data;
-
- error = NULL;
- info = photos_utils_file_query_info (file, data->attributes, data->flags, cancellable, &error);
- if (error != NULL)
- {
- g_task_return_error (task, error);
- goto out;
- }
-
- g_task_return_pointer (task, g_object_ref (info), g_object_unref);
-
- out:
- return;
-}
-
-
-void
-photos_utils_file_query_info_async (GFile *file,
- const gchar *attributes,
- GFileQueryInfoFlags flags,
- gint io_priority,
- GCancellable *cancellable,
- GAsyncReadyCallback callback,
- gpointer user_data)
-{
- g_autoptr (GTask) task = NULL;
- PhotosUtilsFileQueryInfoData *data;
- const gchar *wildcard;
-
- g_return_if_fail (G_IS_FILE (file));
- g_return_if_fail (attributes != NULL && attributes[0] != '\0');
- g_return_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable));
-
- wildcard = strstr (attributes, "*");
- g_return_if_fail (wildcard == NULL);
-
- data = photos_utils_file_query_info_data_new (attributes, flags);
-
- task = g_task_new (file, cancellable, callback, user_data);
- g_task_set_priority (task, io_priority);
- g_task_set_source_tag (task, photos_utils_file_query_info_async);
- g_task_set_task_data (task, data, (GDestroyNotify) photos_utils_file_query_info_data_free);
-
- g_task_run_in_thread (task, photos_utils_file_query_info_in_thread_func);
-}
-
-
-GFileInfo *
-photos_utils_file_query_info_finish (GFile *file, GAsyncResult *res, GError **error)
-{
- GTask *task = G_TASK (res);
-
- g_return_val_if_fail (g_task_is_valid (res, file), NULL);
- g_return_val_if_fail (g_task_get_source_tag (task) == photos_utils_file_query_info_async, NULL);
- g_return_val_if_fail (error == NULL || *error == NULL, NULL);
-
- return g_task_propagate_pointer (task, error);
-}
-
-
void
photos_utils_get_controller (PhotosWindowMode mode,
PhotosOffsetController **out_offset_cntrlr,
@@ -1167,19 +1015,6 @@ photos_utils_get_selection_mode (void)
}
-gchar *
-photos_utils_get_thumbnail_path_for_file (GFile *file)
-{
- gchar *path;
- g_autofree gchar *uri = NULL;
-
- uri = g_file_get_uri (file);
- path = photos_utils_get_thumbnail_path_for_uri (uri);
-
- return path;
-}
-
-
gchar *
photos_utils_get_thumbnail_path_for_uri (const gchar *uri)
{
diff --git a/src/photos-utils.h b/src/photos-utils.h
index e5aec5e1..53f89810 100644
--- a/src/photos-utils.h
+++ b/src/photos-utils.h
@@ -123,22 +123,6 @@ gboolean photos_utils_file_copy_as_thumbnail (GFile *source,
GCancellable *cancellable,
GError **error);
-GFileInfo *photos_utils_file_query_info (GFile *file,
- const gchar *attributes,
- GFileQueryInfoFlags flags,
- GCancellable *cancellable,
- GError **error);
-
-void photos_utils_file_query_info_async (GFile *file,
- const gchar *attributes,
- GFileQueryInfoFlags flags,
- gint io_priority,
- GCancellable *cancellable,
- GAsyncReadyCallback callback,
- gpointer user_data);
-
-GFileInfo *photos_utils_file_query_info_finish (GFile *file, GAsyncResult *res, GError **error);
-
void photos_utils_get_controller (PhotosWindowMode mode,
PhotosOffsetController **out_offset_cntrlr,
PhotosTrackerController **out_trk_cntrlr);
@@ -156,8 +140,6 @@ const gchar *photos_utils_get_provider_name (PhotosBaseManager *sr
gboolean photos_utils_get_selection_mode (void);
-gchar *photos_utils_get_thumbnail_path_for_file (GFile *file);
-
gchar *photos_utils_get_thumbnail_path_for_uri (const gchar *uri);
GList *photos_utils_get_urns_from_items (GList *items);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]