[gnome-photos/wip/rishi/collection: 41/51] 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/collection: 41/51] base-item, utils: Query the GFileInfo directly with the BaseItem
- Date: Tue, 6 Feb 2018 16:09:07 +0000 (UTC)
commit b7d3f7677566d072f5c6de194b5e23266575a0f3
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
https://bugzilla.gnome.org/show_bug.cgi?id=751212
src/photos-base-item.c | 217 ++++++++++++++++++++++++++++++++++++++++---------
src/photos-base-item.h | 18 ++++
src/photos-utils.c | 160 ++----------------------------------
src/photos-utils.h | 16 ----
4 files changed, 203 insertions(+), 208 deletions(-)
---
diff --git a/src/photos-base-item.c b/src/photos-base-item.c
index fcccb3e8..ecb16d29 100644
--- a/src/photos-base-item.c
+++ b/src/photos-base-item.c
@@ -139,6 +139,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;
@@ -151,6 +152,12 @@ struct _PhotosBaseItemMetadataAddSharedData
gchar *shared_id;
};
+struct _PhotosBaseItemQueryInfoData
+{
+ GFileQueryInfoFlags flags;
+ gchar *attributes;
+};
+
struct _PhotosBaseItemSaveData
{
GFile *dir;
@@ -223,6 +230,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)
{
@@ -730,30 +758,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)
@@ -809,13 +832,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;
@@ -825,30 +848,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)
@@ -866,7 +884,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:
@@ -2606,7 +2624,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);
@@ -2627,14 +2644,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);
}
@@ -4231,6 +4247,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 9e82592c..1679e216 100644
--- a/src/photos-base-item.h
+++ b/src/photos-base-item.h
@@ -268,6 +268,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 8d94c403..1c18cdee 100644
--- a/src/photos-utils.c
+++ b/src/photos-utils.c
@@ -71,14 +71,6 @@
#include "photos-utils.h"
-typedef struct _PhotosUtilsFileQueryInfoData PhotosUtilsFileQueryInfoData;
-
-struct _PhotosUtilsFileQueryInfoData
-{
- GFileQueryInfoFlags flags;
- gchar *attributes;
-};
-
static const gdouble EPSILON = 1e-5;
enum
@@ -426,7 +418,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;
@@ -437,16 +428,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);
@@ -858,145 +847,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,
diff --git a/src/photos-utils.h b/src/photos-utils.h
index e5aec5e1..025b6a3f 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);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]