[maemo-commits] [maemo-commits] r16073 - in projects/haf/branches/hildon-thumbnail/daemonize: . thumbs

From: subversion at stage.maemo.org subversion at stage.maemo.org
Date: Tue Sep 9 17:06:48 EEST 2008
Author: pvanhoof
Date: 2008-09-09 17:06:45 +0300 (Tue, 09 Sep 2008)
New Revision: 16073

Added:
   projects/haf/branches/hildon-thumbnail/daemonize/thumbs/thumber-common.c
   projects/haf/branches/hildon-thumbnail/daemonize/thumbs/thumber-gdk-pixbuf.c
   projects/haf/branches/hildon-thumbnail/daemonize/thumbs/thumber-register.c
Modified:
   projects/haf/branches/hildon-thumbnail/daemonize/ChangeLog
   projects/haf/branches/hildon-thumbnail/daemonize/configure.ac
   projects/haf/branches/hildon-thumbnail/daemonize/thumbs/Makefile.am
Log:
2008-09-09  Philip Van Hoof  <pvanhoof at gnome.org>

	* thumbs/thumber-gdk-pixbuf.c
	* thumbs/Makefile.am
	* thumbs/thumber-register.c
	* thumbs/thumber-common.c
	* configure.ac: Started to replace the register binary, reinstalled 
	the original pixbuf thumber after a rewrite to GIO



Modified: projects/haf/branches/hildon-thumbnail/daemonize/ChangeLog
===================================================================
--- projects/haf/branches/hildon-thumbnail/daemonize/ChangeLog	2008-09-09 13:37:08 UTC (rev 16072)
+++ projects/haf/branches/hildon-thumbnail/daemonize/ChangeLog	2008-09-09 14:06:45 UTC (rev 16073)
@@ -1,5 +1,14 @@
 2008-09-09  Philip Van Hoof  <pvanhoof at gnome.org>
 
+	* thumbs/thumber-gdk-pixbuf.c
+	* thumbs/Makefile.am
+	* thumbs/thumber-register.c
+	* thumbs/thumber-common.c
+	* configure.ac: Started to replace the register binary, reinstalled 
+	the original pixbuf thumber after a rewrite to GIO
+
+2008-09-09  Philip Van Hoof  <pvanhoof at gnome.org>
+
 	* daemon/plugins/gdkpixbuf-plugin.c
 	* daemon/plugins/exec-plugin.c
 	* daemon/plugins/exec-plugin.h

Modified: projects/haf/branches/hildon-thumbnail/daemonize/configure.ac
===================================================================
--- projects/haf/branches/hildon-thumbnail/daemonize/configure.ac	2008-09-09 13:37:08 UTC (rev 16072)
+++ projects/haf/branches/hildon-thumbnail/daemonize/configure.ac	2008-09-09 14:06:45 UTC (rev 16073)
@@ -125,6 +125,15 @@
 #AC_SUBST(outomoduledir)
 AC_SUBST(HTML_DIR)
 
+
+LIBOSSO_CHECK="libosso >= 0.9.19"
+PKG_CHECK_MODULES(LIBOSSO, $LIBOSSO_CHECK, [have_osso=yes], [have_osso=no])
+AC_SUBST(LIBOSSO_LIBS)
+AC_SUBST(LIBOSSO_CFLAGS)
+
+AM_CONDITIONAL(ENABLE_OSSO, test x$have_osso = xyes)
+
+
 # --- Output ---
 
 AC_CONFIG_LINKS(thumbs/pixbuf-io-loader.c:daemon/plugins/pixbuf-io-loader.c)

Modified: projects/haf/branches/hildon-thumbnail/daemonize/thumbs/Makefile.am
===================================================================
--- projects/haf/branches/hildon-thumbnail/daemonize/thumbs/Makefile.am	2008-09-09 13:37:08 UTC (rev 16072)
+++ projects/haf/branches/hildon-thumbnail/daemonize/thumbs/Makefile.am	2008-09-09 14:06:45 UTC (rev 16073)
@@ -1,24 +1,41 @@
-INCLUDES = \
+generic_includes = \
 	-DLOCALEDIR=\"$(localedir)\" \
 	-I$(top_srcdir) -I. \
 	-I$(top_srcdir)/daemon \
 	$(DBUS_CFLAGS) \
 	$(GLIB_CFLAGS) \
-	$(GIO_CFLAGS) \
+	$(GIO_CFLAGS)
+
+generic_libs = \
+	$(DBUS_LIBS) \
+	$(GLIB_LIBS) \
+	$(GIO_LIBS)
+
+bin_PROGRAMS = hildon-thumb-gdk-pixbuf hildon-thumber-register
+
+if ENABLE_OSSO
+hildon_thumb_gdk_pixbuf_CFLAGS = $(generic_includes)  $(LIBOSSO_CFLAGS) \
 	$(GDK_PIXBUF_CFLAGS)
+hildon_thumb_gdk_pixbuf_SOURCES = thumber-gdk-pixbuf.c thumber-common.c
+hildon_thumb_gdk_pixbuf_LDADD = libhildonthumbnail.la $(generic_libs) \
+	$(top_builddir)/daemon/libshared.la $(GDK_PIXBUF_LIBS) \
+	$(LIBOSSO_LIBS)
 
-# Library
+hildon_thumber_register_CFLAGS = $(generic_includes) $(LIBOSSO_CFLAGS)
+hildon_thumber_register_SOURCES = thumber-register.c
+hildon_thumber_register_LDADD = libhildonthumbnail.la $(generic_libs) \
+	$(top_builddir)/daemon/libshared.la $(LIBOSSO_LIBS)
+endif
+
 lib_LTLIBRARIES = libhildonthumbnail.la
 
-libhildonthumbnail_la_LIBADD = \
-	$(top_builddir)/daemon/libshared.la \
-	$(DBUS_LIBS) $(GLIB_LIBS) $(GIO_LIBS) \
-	$(GDK_PIXBUF_LIBS)
-
+libhildonthumbnail_la_CFLAGS = $(generic_includes) $(GDK_PIXBUF_CFLAGS)
+libhildonthumbnail_la_LIBADD = $(generic_libs) $(GDK_PIXBUF_LIBS) \
+	$(top_builddir)/daemon/libshared.la 
 libhildonthumbnail_la_LDFLAGS = -version-info 0:4:0
-libhildonthumbnail_la_SOURCES = \
-	hildon-thumbnail-factory.c hildon-thumbnail-factory.h \
-	thumbnailer-client.h pixbuf-io-loader.c
+libhildonthumbnail_la_SOURCES = hildon-thumbnail-factory.c \
+	hildon-thumbnail-factory.h thumbnailer-client.h \
+	pixbuf-io-loader.c
 
 %-client.h: $(top_srcdir)/daemon/%.xml
 	$(DBUSBINDINGTOOL) --mode=glib-client --output=$@ --prefix=$(subst -,_,$*) $^

Added: projects/haf/branches/hildon-thumbnail/daemonize/thumbs/thumber-common.c
===================================================================
--- projects/haf/branches/hildon-thumbnail/daemonize/thumbs/thumber-common.c	2008-09-09 13:37:08 UTC (rev 16072)
+++ projects/haf/branches/hildon-thumbnail/daemonize/thumbs/thumber-common.c	2008-09-09 14:06:45 UTC (rev 16073)
@@ -0,0 +1,239 @@
+/*
+ * This file is part of osso-thumbnail package
+ *
+ * Copyright (C) 2005 Nokia Corporation.  All Rights reserved.
+ *
+ * Contact: Marius Vollmer <marius.vollmer at nokia.com>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License
+ * version 2.1 as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA
+ *
+ */
+
+#include "hildon-thumbnail-factory.h"
+#include "hildon-thumber-common.h"
+//#include "thumbs-private.h"
+
+#include <stdio.h>
+#include <unistd.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include <glib.h>
+#include <glib/gprintf.h>
+
+#include <gdk-pixbuf/gdk-pixbuf.h>
+#include <gio/gio.h>
+
+
+static GdkPixbuf* create_empty_pixbuf ()
+{
+    return gdk_pixbuf_new(GDK_COLORSPACE_RGB, FALSE, 8, 1, 1);
+}
+
+#define HILDON_THUMBNAIL_OPTION_PREFIX "tEXt::Thumb::"
+#define HILDON_THUMBNAIL_APPLICATION "hildon-thumbnail"
+#define URI_OPTION HILDON_THUMBNAIL_OPTION_PREFIX "URI"
+#define MTIME_OPTION HILDON_THUMBNAIL_OPTION_PREFIX "MTime"
+#define SOFTWARE_OPTION "tEXt::Software"
+
+/* Get length of string array */
+static int str_arr_len(const char **arr)
+{
+    int i = 0;
+    while(arr && *arr++) i++;
+    return i;
+}
+
+/* Copy string array src to dest */
+static char **str_arr_copy(const char **src, char **dest)
+{
+    while(src && *src) {
+        *dest++ = *(char **)src++;
+    }
+
+    return dest;
+}
+
+
+static gboolean save_thumb_file_meta(GdkPixbuf *pixbuf, gchar *file, time_t mtime,
+    const gchar *uri, const gchar **opt_keys, const gchar **opt_values)
+{
+    GError *error = NULL;
+    gboolean ret;
+
+    char mtime_str[64];
+
+    const char *default_keys[] = {
+        URI_OPTION,
+        MTIME_OPTION,
+        SOFTWARE_OPTION,
+        NULL
+    };
+
+    const char *default_values[] = {
+        uri,
+        mtime_str,
+        HILDON_THUMBNAIL_APPLICATION "-" "4.0.0",
+        NULL
+    };
+
+    // Start pointers and iterators
+    char **keys, **ikeys;
+    char **values, **ivalues;
+
+    /* Append optional keys, values to default keys, values */
+    keys = ikeys = g_new0(char *,
+        str_arr_len(default_keys) + str_arr_len(opt_keys) + 1);
+    values = ivalues = g_new0(char *,
+        str_arr_len(default_values) + str_arr_len(opt_values) + 1);
+
+    ikeys = str_arr_copy(default_keys, ikeys);
+    ivalues = str_arr_copy(default_values, ivalues);
+
+    ikeys = str_arr_copy(opt_keys, ikeys);
+    ivalues = str_arr_copy(opt_values, ivalues);
+
+    g_sprintf(mtime_str, "%lu", mtime);
+
+    /*
+    for(int i = 0; keys[i]; i++) {
+        g_print("Saving %s: %s\n", keys[i], values[i]);
+    }
+    */
+
+    ret = gdk_pixbuf_savev(pixbuf, file, "png", keys, values, &error);
+
+    if(error) {
+        g_warning("Error saving pixbuf: %s", error->message);
+        g_clear_error(&error);
+    }
+
+    g_free(keys);
+    g_free(values);
+
+    return ret;
+}
+
+
+
+int hildon_thumber_main(
+    int *argc_p, char ***argv_p,
+    HildonThumberCreateThumb create_thumb
+)
+{
+    int argc;
+    char **argv;
+
+    guint width, height;
+    HildonThumbnailFlags flags;
+    gchar *uri, *file, *mime_type, *local_file;
+    gboolean suc = FALSE;
+
+    time_t mtime = 0;
+    GdkPixbuf *pixbuf;
+    GFile *filei;
+    GError *error = NULL;
+    int status = 0;
+
+    gchar **keys = NULL, **values = NULL;
+
+    argc = *argc_p;
+    argv = *argv_p;
+
+    if(argc != 6+1) {
+        printf("Usage: hildon-thumb-gdk-pixbuf"
+               " source_uri mime_type dest_file flags thumb_width thumb_height\n");
+
+        g_warning("Thumber invalid arguments");
+        return 2;
+    }
+
+    uri = argv[1];
+    mime_type = argv[2];
+    file = argv[3];
+    flags = atoi(argv[4]);
+    width = atoi(argv[5]);
+    height = atoi(argv[6]);
+
+    g_type_init ();
+    g_thread_init (NULL);
+
+    filei = g_file_new_for_uri (uri);
+    if(!g_file_query_exists (filei, NULL)) {
+        g_object_unref (filei);
+        g_warning("Thumber failed to create URI from: %s", uri);
+        return 4;
+    }
+
+    local_file = g_file_get_path (filei);
+
+
+    if(local_file && strlen(local_file)) {
+        GFileInfo *info = g_file_query_info (filei, G_FILE_ATTRIBUTE_TIME_MODIFIED,
+                                             G_FILE_QUERY_INFO_NONE,
+                                             NULL, &error);
+        if (!error) {
+		suc = TRUE;
+		mtime = g_file_info_get_attribute_uint64 (info, G_FILE_ATTRIBUTE_TIME_MODIFIED);
+        }
+	g_object_unref (info);
+    }
+
+    if (!suc) {
+ 
+	GFile *filed = g_file_new_for_path (file);
+	g_file_copy (filei, filed, G_FILE_COPY_NONE, NULL, NULL, NULL, &error);
+
+	if (!error) {
+ 		GFileInfo *info = g_file_query_info (filed, G_FILE_ATTRIBUTE_TIME_MODIFIED,
+                                             G_FILE_QUERY_INFO_NONE,
+                                             NULL, &error);
+		mtime = g_file_info_get_attribute_uint64 (info, G_FILE_ATTRIBUTE_TIME_MODIFIED);
+		g_object_unref (info);
+		if (local_file)
+		    g_free (local_file);
+		local_file = g_file_get_path (filei);
+	}
+	g_object_unref (filed);
+
+    }
+
+    g_object_unref (filei);
+
+    pixbuf = create_thumb(local_file, mime_type,
+        width, height, flags, &keys, &values, &error);
+
+    if(!pixbuf) {
+        g_warning("Thumbnail creation failed: %s", uri);
+
+        pixbuf = create_empty_pixbuf();
+
+        status = 10;
+    }
+
+    if(!save_thumb_file_meta(pixbuf, file, mtime, uri,
+        (const gchar **) keys, (const gchar **) values))
+        g_warning("Thumbnail save failed: %s", file);
+
+
+    if(keys) g_strfreev(keys);
+    if(values) g_strfreev(values);
+
+    gdk_pixbuf_unref(pixbuf);
+
+    g_free(local_file);
+
+    return status;
+}

Added: projects/haf/branches/hildon-thumbnail/daemonize/thumbs/thumber-gdk-pixbuf.c
===================================================================
--- projects/haf/branches/hildon-thumbnail/daemonize/thumbs/thumber-gdk-pixbuf.c	2008-09-09 13:37:08 UTC (rev 16072)
+++ projects/haf/branches/hildon-thumbnail/daemonize/thumbs/thumber-gdk-pixbuf.c	2008-09-09 14:06:45 UTC (rev 16073)
@@ -0,0 +1,246 @@
+ /*
+  * This file is part of osso-thumbnail package
+  *
+  * Copyright (C) 2005-2007 Nokia Corporation.  All rights reserved.
+  *
+  * Contact: Marius Vollmer <marius.vollmer at nokia.com>
+  *
+  * This library is free software; you can redistribute it and/or
+  * modify it under the terms of the GNU Lesser General Public License
+  * version 2.1 as published by the Free Software Foundation.
+  *
+  * This library is distributed in the hope that it will be useful,
+  * but WITHOUT ANY WARRANTY; without even the implied warranty of
+  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+  * Lesser General Public License for more details.
+  *
+  * You should have received a copy of the GNU Lesser General Public
+  * License along with this library; if not, write to the Free
+  * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+  * 02110-1301 USA
+  *
+  */
+
+#include "config.h"
+#include "hildon-thumbnail-factory.h"
+#include "hildon-thumber-common.h"
+
+#include <osso-mem.h>
+#include <osso-log.h>
+#include <unistd.h>
+#include <stdlib.h>
+#include <sys/resource.h>
+#include <stdio.h>
+#include <gdk-pixbuf/gdk-pixbuf.h>
+
+GdkPixbuf *crop_resize(GdkPixbuf *src, int width, int height) {
+    int x = width, y = height;
+    int a = gdk_pixbuf_get_width(src);
+    int b = gdk_pixbuf_get_height(src);
+
+    GdkPixbuf *dest;
+
+    // This is the automagic cropper algorithm 
+    // It is an optimized version of a system of equations
+    // Basically it maximizes the final size while minimizing the scale
+    
+    int nx, ny;
+    double na, nb;
+    double offx = 0, offy = 0;
+    double scax, scay;
+
+    na = a;
+    nb = b;
+
+    if(a < x && b < y) {
+        //nx = a;
+        //ny = b;
+        g_object_ref(src);
+        return src;
+    } else {
+        int u, v;
+
+        nx = u = x;
+        ny = v = y;
+
+        if(a < x) {
+            nx = a;
+            u = a;
+        }
+
+        if(b < y) {
+            ny = b;
+            v = b;
+        }
+
+        if(a * y < b * x) {
+            nb = (double)a * v / u;
+            // Center
+            offy = (double)(b - nb) / 2;
+        } else {
+            na = (double)b * u / v;
+            // Center
+            offx = (double)(a - na) / 2;
+        }
+    }
+
+    // gdk_pixbuf_scale has crappy inputs
+    scax = scay = (double)nx / na;
+
+    offx = -offx * scax;
+    offy = -offy * scay;
+
+    dest = gdk_pixbuf_new(gdk_pixbuf_get_colorspace(src),
+        gdk_pixbuf_get_has_alpha(src), gdk_pixbuf_get_bits_per_sample(src),
+        nx, ny);
+
+    gdk_pixbuf_scale(src, dest, 0, 0, nx, ny, offx, offy, scax, scay,
+        GDK_INTERP_BILINEAR);
+
+    return dest;
+}
+
+static void size_prepared(GdkPixbufLoader *loader,
+  gint width, gint height, gpointer user_data)
+{
+  gint pixels, desired_max_area;
+
+  desired_max_area = GPOINTER_TO_INT(user_data);
+  pixels = width * height;
+
+  /* Do we want to downscale by factor 2 or greater while unpacking */
+  if (pixels >= desired_max_area) {
+      GdkPixbufFormat *format = NULL;
+      gchar *format_name = NULL;
+      gint   factor = 1;
+
+      format = gdk_pixbuf_loader_get_format (loader);
+      if (format) {
+          format_name = gdk_pixbuf_format_get_name(format);
+      }
+
+      if (format_name && g_ascii_strcasecmp(format_name, "jpeg") == 0) {
+
+          for (factor = 1;
+               factor < 3 && ((pixels >> (2 * factor)) > desired_max_area);
+               factor++);
+
+          g_message("Scaling jpeg down by factor %d", 1 << factor);
+          gdk_pixbuf_loader_set_size (loader, width >> factor, height >> factor);
+      }
+
+      g_free (format_name);
+  }
+}
+
+#define BLK 4
+
+GdkPixbuf *create_thumb(const gchar *local_file, const gchar *mime_type,
+    guint width, guint height, HildonThumbnailFlags flags,
+    gchar ***opt_keys, gchar ***opt_values, GError **error)
+{
+    if((flags & HILDON_THUMBNAIL_FLAG_CROP)) {
+       GdkPixbuf *pixbuf, *result = NULL;
+       GdkPixbufLoader *loader;
+       guchar buffer[2048]; /* size must be dividable by BLK */
+       FILE *f; 
+       size_t items_read = sizeof(buffer) / BLK;
+       size_t desired_max_area;
+
+       f = fopen(local_file, "r");
+       if (!f) return NULL;
+
+       desired_max_area = (width * height * 4) - 1;
+       loader = gdk_pixbuf_loader_new ();
+       g_signal_connect(loader, "size-prepared", G_CALLBACK(size_prepared),
+                        GINT_TO_POINTER(desired_max_area));
+
+       while (items_read >= sizeof(buffer) / BLK)
+       {
+         long pos;
+         int nbytes;
+
+         /* read BLK bytes at a time as much as possible */
+         if ((pos = ftell(f)) == -1)
+         {
+           gdk_pixbuf_loader_close(loader, NULL);
+           goto cleanup;
+         }
+         items_read = fread(buffer, BLK, sizeof(buffer) / BLK, f);
+
+         if (items_read < sizeof(buffer) / BLK)
+         {
+           /* read again one byte at a time */
+           if (fseek(f, pos, SEEK_SET) == -1)
+           {
+             gdk_pixbuf_loader_close(loader, NULL);
+             goto cleanup;
+           }
+           nbytes = fread(buffer, 1, sizeof(buffer), f);
+         }
+         else
+           nbytes = items_read * BLK;
+
+         if (!gdk_pixbuf_loader_write(loader, buffer, nbytes, error))
+         { /* We have to call close before unreffing */
+           gdk_pixbuf_loader_close(loader, NULL);
+           goto cleanup;
+         }
+       }
+
+       if (!gdk_pixbuf_loader_close(loader, error))
+         goto cleanup;
+
+       /* Loader owns reference to this pixbuf */
+       pixbuf = gdk_pixbuf_loader_get_pixbuf(loader);
+
+       if (pixbuf)
+         result = crop_resize(pixbuf, width, height);
+cleanup:
+       fclose(f);
+       g_object_unref(loader);
+       return result;
+
+    } else {
+       GdkPixbuf *pixbuf;
+       GError *error = NULL;
+
+       pixbuf = gdk_pixbuf_new_from_file_at_size (local_file, width, height, 
+	 					  &error);
+       if (error) {
+ 	   ULOG_ERR_F("can't create thumb: %s", error->message);
+	   g_error_free (error);
+       }
+       return pixbuf;
+    }
+
+    return NULL;
+}
+
+static void
+thumbnailer_oom_func (size_t cur, size_t max, void *data)
+{
+  /* We can't do much here other than exit.  Even printing might
+     allocate memory which would put us into a loop.
+  */
+
+  exit(1);
+}
+
+int main(int argc, char **argv)
+{
+    int result;
+
+    setpriority(PRIO_PROCESS, getpid(), 10);
+    g_thread_init(NULL);
+    result = osso_mem_saw_enable(4 << 20, 64, thumbnailer_oom_func, NULL);
+    if (result != 0)
+      ULOG_ERR_F("osso_mem_saw_enable failed with error %d", result);
+    else
+      {
+	result = hildon_thumber_main(&argc, &argv, create_thumb);
+	osso_mem_saw_disable();
+      }
+
+    return result;
+}

Added: projects/haf/branches/hildon-thumbnail/daemonize/thumbs/thumber-register.c
===================================================================
--- projects/haf/branches/hildon-thumbnail/daemonize/thumbs/thumber-register.c	2008-09-09 13:37:08 UTC (rev 16072)
+++ projects/haf/branches/hildon-thumbnail/daemonize/thumbs/thumber-register.c	2008-09-09 14:06:45 UTC (rev 16073)
@@ -0,0 +1,81 @@
+/*
+ * This file is part of hildon-fm package
+ *
+ * Copyright (C) 2005 Nokia Corporation.
+ *
+ * Contact: Marius Vollmer <marius.vollmer at nokia.com>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License
+ * version 2.1 as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA
+ *
+ */
+
+#include <stdio.h>
+#include <string.h>
+
+#include <glib.h>
+
+enum {
+    THUMBER_REGISTER_ERROR = 10
+} ThumberRegisterError;
+
+GQuark reg_quark = 0;
+
+void thumber_register(char *cmd, char *mime_type, GError **err)
+{
+ 
+}
+
+void thumber_unregister(char *cmd, GError **err)
+{
+ 
+}
+
+int main(int argc, char **argv)
+{
+    int status = 0;
+
+    g_type_init();
+    reg_quark = g_quark_from_static_string("osso-thumber-register");
+
+    if(argc != 3) {
+        printf( "Usage:\n"
+                "    osso-thumber-register <handler-cmd> <mime-type>\n"
+                "    osso-thumber-register -u <handler-cmd>\n"
+                "Options:\n"
+                "    -u : unregister specified thumber command\n"
+        );
+
+        return 1;
+    } else {
+        GError *err = NULL;
+
+        if(strcmp(argv[1], "-u") == 0) {
+            thumber_unregister(argv[2], &err);
+        } else {
+            thumber_register(argv[1], argv[2], &err);
+        }
+
+        if(err) {
+            g_warning("Error in osso-thumber-register, code %d: %s",
+                err->code, err->message);
+
+            status = err->code ? err->code : 3;
+        }
+
+        g_clear_error(&err);
+    }
+
+    return status;
+}


More information about the maemo-commits mailing list