Commit ab59219a authored by Debarshi Ray's avatar Debarshi Ray

utils: Add photos_utils_queue_thumbnail_job_for_file_async

Added gnome-desktop-3.0 to the list of build requirements.
parent c4f656ea
......@@ -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])
......
......@@ -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) \
......
......@@ -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);
}
......@@ -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 */
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment