[gnome-photos] utils: Add photos_utils_file_query_info
- From: Debarshi Ray <debarshir src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-photos] utils: Add photos_utils_file_query_info
- Date: Tue, 14 Feb 2017 17:54:19 +0000 (UTC)
commit 40d4d31212771f3d92cf7bc57858c10da2ccfae4
Author: Debarshi Ray <debarshir gnome org>
Date: Tue Feb 14 17:33:06 2017 +0100
utils: Add photos_utils_file_query_info
This is the synchronous version of photos_utils_file_query_info_async.
We need for the search provider.
src/photos-utils.c | 77 +++++++++++++++++++++++++++++++++++-----------------
src/photos-utils.h | 6 ++++
2 files changed, 58 insertions(+), 25 deletions(-)
---
diff --git a/src/photos-utils.c b/src/photos-utils.c
index 691deb6..7bc3fbe 100644
--- a/src/photos-utils.c
+++ b/src/photos-utils.c
@@ -802,6 +802,57 @@ 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;
+ 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))
+ {
+ 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);
+ }
+
+ g_free (path);
+ }
+
+ ret_val = g_object_ref (info);
+
+ out:
+ g_clear_object (&info);
+ g_clear_pointer (&matcher, (GDestroyNotify) g_file_attribute_matcher_unref);
+ return ret_val;
+}
+
+
static void
photos_utils_file_query_info_data_free (PhotosUtilsFileQueryInfoData *data)
{
@@ -831,45 +882,21 @@ photos_utils_file_query_info_in_thread_func (GTask *task,
{
GError *error;
GFile *file = G_FILE (source_object);
- GFileAttributeMatcher *matcher = NULL;
GFileInfo *info = NULL;
PhotosUtilsFileQueryInfoData *data = (PhotosUtilsFileQueryInfoData *) task_data;
error = NULL;
- info = g_file_query_info (file, data->attributes, data->flags, cancellable, &error);
+ info = photos_utils_file_query_info (file, data->attributes, data->flags, cancellable, &error);
if (error != NULL)
{
g_task_return_error (task, error);
goto out;
}
- matcher = g_file_attribute_matcher_new (data->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))
- {
- 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);
- }
-
- g_free (path);
- }
-
g_task_return_pointer (task, g_object_ref (info), g_object_unref);
out:
g_clear_object (&info);
- g_clear_pointer (&matcher, (GDestroyNotify) g_file_attribute_matcher_unref);
}
diff --git a/src/photos-utils.h b/src/photos-utils.h
index 466fffe..e3c3faa 100644
--- a/src/photos-utils.h
+++ b/src/photos-utils.h
@@ -109,6 +109,12 @@ 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,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]