[maemo-commits] [maemo-commits] r16720 - in projects/haf/trunk/hildon-thumbnail: . daemon daemon/plugins
From: subversion at stage.maemo.org subversion at stage.maemo.orgDate: Tue Nov 18 12:54:33 EET 2008
- Previous message: [maemo-commits] r16719 - projects/haf/trunk/hildon-help
- Next message: [maemo-commits] r16721 - projects/haf/trunk/hildon-help/src
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Author: pvanhoof Date: 2008-11-18 12:54:31 +0200 (Tue, 18 Nov 2008) New Revision: 16720 Modified: projects/haf/trunk/hildon-thumbnail/ChangeLog projects/haf/trunk/hildon-thumbnail/config.h.in projects/haf/trunk/hildon-thumbnail/configure.ac projects/haf/trunk/hildon-thumbnail/daemon/hildon-thumbnail-plugin.c projects/haf/trunk/hildon-thumbnail/daemon/hildon-thumbnail-plugin.h projects/haf/trunk/hildon-thumbnail/daemon/plugins/Makefile.am projects/haf/trunk/hildon-thumbnail/daemon/plugins/gdkpixbuf-jpeg-out-plugin.c projects/haf/trunk/hildon-thumbnail/daemon/plugins/gdkpixbuf-png-out-plugin.c Log: 2008-11-17 Philip Van Hoof <philip at codeminded.be> * config.h.in * daemon/hildon-thumbnail-plugin.h * daemon/plugins/gdkpixbuf-png-out-plugin.c * daemon/plugins/gdkpixbuf-jpeg-out-plugin.c * daemon/plugins/Makefile.am * daemon/hildon-thumbnail-plugin.c * configure.ac: Storing metadata in a SQLite in case of JPeg and in tExt in case of PNG Modified: projects/haf/trunk/hildon-thumbnail/ChangeLog =================================================================== --- projects/haf/trunk/hildon-thumbnail/ChangeLog 2008-11-18 10:38:48 UTC (rev 16719) +++ projects/haf/trunk/hildon-thumbnail/ChangeLog 2008-11-18 10:54:31 UTC (rev 16720) @@ -1,5 +1,16 @@ 2008-11-17 Philip Van Hoof <philip at codeminded.be> + * config.h.in + * daemon/hildon-thumbnail-plugin.h + * daemon/plugins/gdkpixbuf-png-out-plugin.c + * daemon/plugins/gdkpixbuf-jpeg-out-plugin.c + * daemon/plugins/Makefile.am + * daemon/hildon-thumbnail-plugin.c + * configure.ac: Storing metadata in a SQLite in case of JPeg and in + tExt in case of PNG + +2008-11-17 Philip Van Hoof <philip at codeminded.be> + * daemon/plugins/epeg-plugin.c: Bugfix in error handling * daemon/README.yourplugin: Added documentation for plugin writers Modified: projects/haf/trunk/hildon-thumbnail/config.h.in =================================================================== --- projects/haf/trunk/hildon-thumbnail/config.h.in 2008-11-18 10:38:48 UTC (rev 16719) +++ projects/haf/trunk/hildon-thumbnail/config.h.in 2008-11-18 10:54:31 UTC (rev 16720) @@ -9,6 +9,9 @@ /* Define to 1 if you have the <memory.h> header file. */ #undef HAVE_MEMORY_H +/* SQLite3 */ +#undef HAVE_SQLITE3 + /* Define to 1 if you have the <stdint.h> header file. */ #undef HAVE_STDINT_H Modified: projects/haf/trunk/hildon-thumbnail/configure.ac =================================================================== --- projects/haf/trunk/hildon-thumbnail/configure.ac 2008-11-18 10:38:48 UTC (rev 16719) +++ projects/haf/trunk/hildon-thumbnail/configure.ac 2008-11-18 10:54:31 UTC (rev 16720) @@ -84,22 +84,38 @@ if test "x$enable_gstreamer" = "xyes"; then PKG_CHECK_MODULES(GSTREAMER,[gstreamer-0.10 >= 0.10.0], - [have_gstreamer=yes], - [have_gstreamer=no]) + [have_gstreamer=yes], + [have_gstreamer=no]) AC_SUBST(GSTREAMER_CFLAGS) AC_SUBST(GSTREAMER_LIBS) fi AM_CONDITIONAL(HAVE_GSTREAMER, test "$have_gstreamer" = "yes") +PKG_CHECK_MODULES(PNG,[libpng >= 1.2], + [have_png=yes], + [have_png=no]) +AC_SUBST(PNG_CFLAGS) +AC_SUBST(PNG_LIBS) +AM_CONDITIONAL(HAVE_PNG, test "$have_png" = "yes") + PKG_CHECK_MODULES(EPEG,[epeg >= 0.9.0], - [have_epeg=yes], - [have_epeg=no]) + [have_epeg=yes], + [have_epeg=no]) AC_SUBST(EPEG_CFLAGS) AC_SUBST(EPEG_LIBS) AM_CONDITIONAL(HAVE_EPEG, test "$have_epeg" = "yes") +PKG_CHECK_MODULES(SQLITE3, [sqlite3], + [have_sqlite3=yes], + [have_sqlite3=no]) +AC_SUBST(SQLITE3_CFLAGS) +AC_SUBST(SQLITE3_LIBS) +if test "$have_sqlite3" = "yes"; then + AC_DEFINE(HAVE_SQLITE3, [], [SQLite3]) +fi + ################################################## # Check for gtk-doc. ################################################## Modified: projects/haf/trunk/hildon-thumbnail/daemon/hildon-thumbnail-plugin.c =================================================================== --- projects/haf/trunk/hildon-thumbnail/daemon/hildon-thumbnail-plugin.c 2008-11-18 10:38:48 UTC (rev 16719) +++ projects/haf/trunk/hildon-thumbnail/daemon/hildon-thumbnail-plugin.c 2008-11-18 10:54:31 UTC (rev 16720) @@ -31,7 +31,40 @@ typedef gboolean (*IsActiveFunc) (void); typedef gboolean (*StopFunc) (void); +typedef gchar * (*GetOrigFunc) (const gchar *path); +gchar * +hildon_thumbnail_outplugins_get_orig (const gchar *path) +{ + GList *copy; + gchar *retval = NULL; + + g_static_rec_mutex_lock (&mutex); + copy = g_list_copy (outplugs); + + while (copy && !retval) { + GModule *module = copy->data; + GetOrigFunc orig_func; + + if (g_module_symbol (module, "hildon_thumbnail_outplugin_get_orig", (gpointer *) &orig_func)) { + IsActiveFunc isac_func; + if (g_module_symbol (module, "hildon_thumbnail_outplugin_is_active", (gpointer *) &isac_func)) { + if (isac_func ()) { + retval = orig_func (path); + } + } + } + + copy = g_list_next (copy); + } + + g_static_rec_mutex_unlock (&mutex); + + g_list_free (copy); + + return retval; +} + void hildon_thumbnail_outplugin_unload (GModule *module) { @@ -87,7 +120,7 @@ hildon_thumbnail_outplugins_needs_out (HildonThumbnailPluginOutType type, guint64 mtime, const gchar *uri) { - GList *copy = g_list_copy (outplugs); + GList *copy; gboolean retval = FALSE; g_static_rec_mutex_lock (&mutex); Modified: projects/haf/trunk/hildon-thumbnail/daemon/hildon-thumbnail-plugin.h =================================================================== --- projects/haf/trunk/hildon-thumbnail/daemon/hildon-thumbnail-plugin.h 2008-11-18 10:38:48 UTC (rev 16719) +++ projects/haf/trunk/hildon-thumbnail/daemon/hildon-thumbnail-plugin.h 2008-11-18 10:54:31 UTC (rev 16720) @@ -72,7 +72,9 @@ gboolean hildon_thumbnail_outplugins_needs_out (HildonThumbnailPluginOutType type, guint64 mtime, const gchar *uri); +gchar * hildon_thumbnail_outplugins_get_orig (const gchar *path); + G_END_DECLS #endif Modified: projects/haf/trunk/hildon-thumbnail/daemon/plugins/Makefile.am =================================================================== --- projects/haf/trunk/hildon-thumbnail/daemon/plugins/Makefile.am 2008-11-18 10:38:48 UTC (rev 16719) +++ projects/haf/trunk/hildon-thumbnail/daemon/plugins/Makefile.am 2008-11-18 10:54:31 UTC (rev 16720) @@ -3,9 +3,12 @@ outputpluginsdir = $(libdir)/hildon-thumbnailer/output-plugins -outputplugins_LTLIBRARIES = libhildon-thumbnailer-jpeg.la \ - libhildon-thumbnailer-png.la +outputplugins_LTLIBRARIES = libhildon-thumbnailer-jpeg.la +if HAVE_PNG +outputplugins_LTLIBRARIES += libhildon-thumbnailer-png.la +endif + plugins_LTLIBRARIES = libhildon-thumbnailer-gdkpixbuf.la \ libhildon-thumbnailer-exec.la @@ -33,13 +36,17 @@ libhildon_thumbnailer_jpeg_la_SOURCES = gdkpixbuf-jpeg-out-plugin.c libhildon_thumbnailer_jpeg_la_LDFLAGS = $(plugin_flags) -libhildon_thumbnailer_jpeg_la_CFLAGS = $(libhildon_thumbnailer_gdkpixbuf_la_CFLAGS) -libhildon_thumbnailer_jpeg_la_LIBADD = $(libhildon_thumbnailer_gdkpixbuf_la_LIBADD) +libhildon_thumbnailer_jpeg_la_CFLAGS = $(libhildon_thumbnailer_gdkpixbuf_la_CFLAGS) \ + $(SQLITE3_CFLAGS) +libhildon_thumbnailer_jpeg_la_LIBADD = $(libhildon_thumbnailer_gdkpixbuf_la_LIBADD) \ + $(SQLITE3_LIBS) libhildon_thumbnailer_png_la_SOURCES = gdkpixbuf-png-out-plugin.c libhildon_thumbnailer_png_la_LDFLAGS = $(plugin_flags) -libhildon_thumbnailer_png_la_CFLAGS = $(libhildon_thumbnailer_gdkpixbuf_la_CFLAGS) -libhildon_thumbnailer_png_la_LIBADD = $(libhildon_thumbnailer_gdkpixbuf_la_LIBADD) +libhildon_thumbnailer_png_la_CFLAGS = $(libhildon_thumbnailer_gdkpixbuf_la_CFLAGS) \ + $(PNG_CFLAGS) +libhildon_thumbnailer_png_la_LIBADD = $(libhildon_thumbnailer_gdkpixbuf_la_LIBADD) \ + $(PNG_LIBS) libhildon_thumbnailer_exec_la_CFLAGS = \ -I. -I$(top_srcdir)/daemon \ Modified: projects/haf/trunk/hildon-thumbnail/daemon/plugins/gdkpixbuf-jpeg-out-plugin.c =================================================================== --- projects/haf/trunk/hildon-thumbnail/daemon/plugins/gdkpixbuf-jpeg-out-plugin.c 2008-11-18 10:38:48 UTC (rev 16719) +++ projects/haf/trunk/hildon-thumbnail/daemon/plugins/gdkpixbuf-jpeg-out-plugin.c 2008-11-18 10:54:31 UTC (rev 16720) @@ -42,13 +42,73 @@ #include "utils.h" +#ifdef HAVE_SQLITE3 +#include <sqlite3.h> +#endif + #include <hildon-thumbnail-plugin.h> static gboolean had_init = FALSE; static gboolean is_active = TRUE; static GFileMonitor *monitor = NULL; +#ifdef HAVE_SQLITE3 +sqlite3 *db = NULL; +#endif +gchar * +hildon_thumbnail_outplugin_get_orig (const gchar *path) +{ +#ifdef HAVE_SQLITE3 + gchar *retval = NULL; + gchar *dbfile; + sqlite3_stmt *stmt; + gint result = SQLITE_OK; + + dbfile = g_build_filename (g_get_home_dir (), ".thumbnails", + "meta.db", NULL); + + if (!db) + sqlite3_open (dbfile, &db); + + if (db) { + const unsigned char *tmp; + gchar *sql = g_strdup_printf ("select URI from jpegthumbnails where Path = '%s'", + path); + sqlite3_prepare_v2 (db, sql, -1, &stmt, NULL); + g_free (sql); + + while (result == SQLITE_OK || result == SQLITE_ROW || result == SQLITE_BUSY) { + result = sqlite3_step (stmt); + + if (result == SQLITE_ERROR) { + sqlite3_reset (stmt); + result = SQLITE_OK; + continue; + } + + if (result == SQLITE_BUSY) { + g_usleep (10); + result = SQLITE_OK; + continue; + } + + tmp = sqlite3_column_text (stmt, 0); + + if (tmp) { + retval = g_strdup (tmp); + break; + } + } + } + g_free (dbfile); + + return retval; +#else + return NULL; +#endif +} + gboolean hildon_thumbnail_outplugin_needs_out (HildonThumbnailPluginOutType type, guint64 mtime, const gchar *uri) { @@ -87,6 +147,12 @@ return retval; } + +#ifdef HAVE_SQLITE3 +static gint +callback (void *NotUsed, gint argc, gchar **argv, gchar **azColName) { } +#endif + void hildon_thumbnail_outplugin_out (const guchar *rgb8_pixmap, guint width, guint height, @@ -99,6 +165,7 @@ GdkPixbuf *pixbuf; gchar *large, *normal, *cropped, *filen; struct utimbuf buf; + GError *nerror = NULL; hildon_thumbnail_util_get_thumb_paths (uri, &large, &normal, &cropped, NULL, NULL, NULL, FALSE); @@ -121,14 +188,45 @@ NULL, NULL); gdk_pixbuf_save (pixbuf, filen, "jpeg", - error, NULL); + &nerror, NULL); g_object_unref (pixbuf); - buf.actime = buf.modtime = mtime; + if (!nerror) { +#ifdef HAVE_SQLITE3 + gchar *dbfile; + sqlite3_stmt *stmt; + gboolean create; - utime (filen, &buf); + dbfile = g_build_filename (g_get_home_dir (), ".thumbnails", + "meta.db", NULL); + create = !g_file_test (dbfile, G_FILE_TEST_EXISTS); + + if (!db) + sqlite3_open (dbfile, &db); + + if (db) { + gchar *sql, *errm = NULL; + if (create) { + sqlite3_exec (db, "create table jpegthumbnails (Path, URI, MTime)" , + callback, 0, NULL); + } + sql = g_strdup_printf ("insert into jpegthumbnails (Path, URI, MTime) values ('%s', '%s', %d)", + filen, uri, mtime); + sqlite3_exec (db, sql, callback, 0, &errm); + g_free (sql); + } + + g_free (dbfile); +#endif + + buf.actime = buf.modtime = mtime; + utime (filen, &buf); + } else + g_propagate_error (error, nerror); + + g_free (normal); g_free (large); g_free (cropped); @@ -178,6 +276,11 @@ { if (monitor) g_object_unref (monitor); +#ifdef HAVE_SQLITE3 + if (db) + sqlite3_close (db); + db = NULL; +#endif return FALSE; } Modified: projects/haf/trunk/hildon-thumbnail/daemon/plugins/gdkpixbuf-png-out-plugin.c =================================================================== --- projects/haf/trunk/hildon-thumbnail/daemon/plugins/gdkpixbuf-png-out-plugin.c 2008-11-18 10:38:48 UTC (rev 16719) +++ projects/haf/trunk/hildon-thumbnail/daemon/plugins/gdkpixbuf-png-out-plugin.c 2008-11-18 10:54:31 UTC (rev 16720) @@ -29,6 +29,11 @@ #include "config.h" #endif + +#ifndef _GNU_SOURCE +#define _GNU_SOURCE +#endif + #include <sys/types.h> #include <utime.h> @@ -40,6 +45,13 @@ #include <gdk-pixbuf/gdk-pixbuf.h> #include <gdk-pixbuf/gdk-pixbuf-io.h> +#include <fcntl.h> +#include <sys/stat.h> +#include <unistd.h> + +#include <png.h> + + #include "utils.h" #include <hildon-thumbnail-plugin.h> @@ -55,9 +67,74 @@ #define SOFTWARE_OPTION "tEXt::Software" -//gchar * -//hildon_thumbnail_outplugin_ (HildonThumbnailPluginOutType type, guint64 mtime, const gchar *uri) +gchar * +hildon_thumbnail_outplugin_get_orig (const gchar *path) +{ + gint fd_png; + FILE *png; + png_structp png_ptr; + png_infop info_ptr; + png_uint_32 width, height; + gint num_text; + png_textp text_ptr; + gint bit_depth, color_type; + gint interlace_type, compression_type, filter_type; + gchar *retval = NULL; +#if defined(__linux__) + if ((fd_png = g_open (path, (O_RDONLY | O_NOATIME))) == -1) { +#else + if ((fd_png = g_open (path, O_RDONLY)) == -1) { +#endif + return NULL; + } + + if ((png = fdopen (fd_png, "r"))) { + png_ptr = png_create_read_struct (PNG_LIBPNG_VER_STRING, + NULL, + NULL, + NULL); + if (!png_ptr) { + fclose (png); + return NULL; + } + + info_ptr = png_create_info_struct (png_ptr); + if (!info_ptr) { + png_destroy_read_struct (&png_ptr, &info_ptr, NULL); + fclose (png); + return NULL; + } + + png_init_io (png_ptr, png); + png_read_info (png_ptr, info_ptr); + + if (png_get_text (png_ptr, info_ptr, &text_ptr, &num_text) > 0) { + gint i; + gint j; + + for (i = 0; i < num_text; i++) { + if (!text_ptr[i].key) { + continue; + } + if (strcasecmp ("Thumb::URI", text_ptr[i].key) != 0) { + continue; + } + if (text_ptr[i].text && text_ptr[i].text[0] != '\0') { + retval = g_strdup (text_ptr[i].text); + break; + } + } + } + png_destroy_read_struct (&png_ptr, &info_ptr, NULL); + fclose (png); + } else { + close (fd_png); + } + + return retval; +} + gboolean hildon_thumbnail_outplugin_needs_out (HildonThumbnailPluginOutType type, guint64 mtime, const gchar *uri) {
- Previous message: [maemo-commits] r16719 - projects/haf/trunk/hildon-help
- Next message: [maemo-commits] r16721 - projects/haf/trunk/hildon-help/src
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]