[gnome-photos] utils: Add photos_utils_queue_thumbnail_job_for_file_async
- From: Debarshi Ray <debarshir src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-photos] utils: Add photos_utils_queue_thumbnail_job_for_file_async
- Date: Sun, 15 Jul 2012 20:15:03 +0000 (UTC)
commit ab59219acdb5db2f4b9ed7d85a3e05ec958c8ecb
Author: Debarshi Ray <debarshir gnome org>
Date: Sun Jul 15 03:38:14 2012 +0200
utils: Add photos_utils_queue_thumbnail_job_for_file_async
Added gnome-desktop-3.0 to the list of build requirements.
configure.ac | 3 ++
src/Makefile.am | 2 +
src/photos-utils.c | 72 ++++++++++++++++++++++++++++++++++++++++++++++++++++
src/photos-utils.h | 8 ++++++
4 files changed, 85 insertions(+), 0 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index bd6b497..a8a4aaf 100644
--- a/configure.ac
+++ b/configure.ac
@@ -47,6 +47,9 @@ PKG_CHECK_MODULES(GDK_PIXBUF, [gdk-pixbuf-2.0])
PKG_CHECK_MODULES(GLIB, [glib-2.0 >= $GLIB_MIN_VERSION])
PKG_CHECK_MODULES(GIO, [gio-2.0])
+PKG_CHECK_MODULES(GNOME_DESKTOP, [gnome-desktop-3.0])
+AC_DEFINE([GNOME_DESKTOP_USE_UNSTABLE_API], [], [We are aware that GNOME_DESKTOP's API can change])
+
PKG_CHECK_MODULES(GOA, [goa-1.0])
AC_DEFINE([GOA_API_IS_SUBJECT_TO_CHANGE], [], [We are aware that GOA's API can change])
diff --git a/src/Makefile.am b/src/Makefile.am
index 8dae625..6dcd2e9 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -103,6 +103,7 @@ AM_CPPFLAGS = \
$(GDK_PIXBUF_CFLAGS) \
$(GIO_CFLAGS) \
$(GLIB_CFLAGS) \
+ $(GNOME_DESKTOP_CFLAGS) \
$(GOA_CFLAGS) \
$(GTK_CFLAGS) \
$(TRACKER_CFLAGS) \
@@ -116,6 +117,7 @@ gnome_photos_LDADD = \
$(GDK_PIXBUF_LIBS) \
$(GIO_LIBS) \
$(GLIB_LIBS) \
+ $(GNOME_DESKTOP_LIBS) \
$(GOA_LIBS) \
$(GTK_LIBS) \
$(TRACKER_LIBS) \
diff --git a/src/photos-utils.c b/src/photos-utils.c
index da25f78..97a4c8d 100644
--- a/src/photos-utils.c
+++ b/src/photos-utils.c
@@ -24,6 +24,7 @@
#include <string.h>
#include <glib.h>
+#include <libgnome-desktop/gnome-desktop-thumbnail.h>
#include "gd-main-view.h"
#include "photos-utils.h"
@@ -37,6 +38,56 @@ photos_utils_alpha_gtk_widget (GtkWidget *widget)
}
+static gboolean
+photos_utils_create_thumbnail (GIOSchedulerJob *job, GCancellable *cancellable, gpointer user_data)
+{
+ GSimpleAsyncResult *result = user_data;
+ GFile *file = G_FILE (g_async_result_get_source_object (G_ASYNC_RESULT (result)));
+ GnomeDesktopThumbnailFactory *factory;
+ GFileInfo *info;
+ const gchar *attributes = G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE","G_FILE_ATTRIBUTE_TIME_MODIFIED;
+ gchar *uri;
+ GdkPixbuf *pixbuf;
+ guint64 mtime;
+
+ uri = g_file_get_uri (file);
+ info = g_file_query_info (file, attributes, G_FILE_QUERY_INFO_NONE, NULL, NULL);
+
+ /* we don't care about reporting errors here, just fail the
+ * thumbnail.
+ */
+ if (info == NULL)
+ {
+ g_simple_async_result_set_op_res_gboolean (result, FALSE);
+ goto out;
+ }
+
+ mtime = g_file_info_get_attribute_uint64 (info, G_FILE_ATTRIBUTE_TIME_MODIFIED);
+
+ factory = gnome_desktop_thumbnail_factory_new (GNOME_DESKTOP_THUMBNAIL_SIZE_NORMAL);
+ pixbuf = gnome_desktop_thumbnail_factory_generate_thumbnail (factory, uri, g_file_info_get_content_type (info));
+
+ if (pixbuf != NULL)
+ {
+ gnome_desktop_thumbnail_factory_save_thumbnail (factory, pixbuf, uri, (time_t) mtime);
+ g_simple_async_result_set_op_res_gboolean (result, TRUE);
+ }
+ else
+ g_simple_async_result_set_op_res_gboolean (result, FALSE);
+
+ g_object_unref (info);
+ g_object_unref (file);
+ g_object_unref (factory);
+ g_clear_object (&pixbuf);
+
+ out:
+ g_simple_async_result_complete_in_idle (result);
+ g_object_unref (result);
+
+ return FALSE;
+}
+
+
static gchar *
photos_utils_filename_get_extension_offset (const gchar *filename)
{
@@ -104,3 +155,24 @@ photos_utils_get_urns_from_paths (GList *paths, GtkTreeModel *model)
return g_list_reverse (urns);
}
+
+
+void
+photos_utils_queue_thumbnail_job_for_file_async (GFile *file, GAsyncReadyCallback callback, gpointer user_data)
+{
+ GSimpleAsyncResult *result;
+
+ result = g_simple_async_result_new (G_OBJECT (file),
+ callback,
+ user_data,
+ photos_utils_queue_thumbnail_job_for_file_async);
+ g_io_scheduler_push_job (photos_utils_create_thumbnail, result, NULL, G_PRIORITY_DEFAULT, NULL);
+}
+
+
+gboolean
+photos_utils_queue_thumbnail_job_for_file_finish (GAsyncResult *res)
+{
+ GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (res);
+ return g_simple_async_result_get_op_res_gboolean (simple);
+}
diff --git a/src/photos-utils.h b/src/photos-utils.h
index 24e90c5..88c2341 100644
--- a/src/photos-utils.h
+++ b/src/photos-utils.h
@@ -21,6 +21,7 @@
#ifndef PHOTOS_UTILS_H
#define PHOTOS_UTILS_H
+#include <gio/gio.h>
#include <glib.h>
#include <gtk/gtk.h>
@@ -32,6 +33,13 @@ gchar *photos_utils_filename_strip_extension (const gchar *filename
GList *photos_utils_get_urns_from_paths (GList *paths, GtkTreeModel *model);
+void photos_utils_queue_thumbnail_job_for_file_async (GFile *file,
+ GAsyncReadyCallback callback,
+ gpointer user_data);
+
+gboolean photos_utils_queue_thumbnail_job_for_file_finish (GAsyncResult *res);
+
+
G_END_DECLS
#endif /* PHOTOS_UTILS_H */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]