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

From: subversion at stage.maemo.org subversion at stage.maemo.org
Date: Wed Sep 10 15:42:36 EEST 2008
Author: pvanhoof
Date: 2008-09-10 15:42:34 +0300 (Wed, 10 Sep 2008)
New Revision: 16083

Added:
   projects/haf/branches/hildon-thumbnail/daemonize/thumbs/hildon-thumbnailer-wrap.sh
Modified:
   projects/haf/branches/hildon-thumbnail/daemonize/ChangeLog
   projects/haf/branches/hildon-thumbnail/daemonize/daemon/plugins/exec-plugin.c
   projects/haf/branches/hildon-thumbnail/daemonize/thumbs/Makefile.am
   projects/haf/branches/hildon-thumbnail/daemonize/thumbs/thumber-register.c
Log:
2008-09-10  Philip Van Hoof  <pvanhoof at gnome.org>

	* thumbs/hildon-thumbnailer-wrap.sh
	* thumbs/Makefile.am
	* thumbs/thumber-register.c
	* daemon/plugins/exec-plugin.c: Making it work, a bunch of bugfixes



Modified: projects/haf/branches/hildon-thumbnail/daemonize/ChangeLog
===================================================================
--- projects/haf/branches/hildon-thumbnail/daemonize/ChangeLog	2008-09-10 10:04:14 UTC (rev 16082)
+++ projects/haf/branches/hildon-thumbnail/daemonize/ChangeLog	2008-09-10 12:42:34 UTC (rev 16083)
@@ -1,5 +1,12 @@
 2008-09-10  Philip Van Hoof  <pvanhoof at gnome.org>
 
+	* thumbs/hildon-thumbnailer-wrap.sh
+	* thumbs/Makefile.am
+	* thumbs/thumber-register.c
+	* daemon/plugins/exec-plugin.c: Making it work, a bunch of bugfixes
+
+2008-09-10  Philip Van Hoof  <pvanhoof at gnome.org>
+
 	* daemon/plugins/gdkpixbuf-plugin.c
 	* daemon/plugins/exec-plugin.c
 	* daemon/manager.c

Modified: projects/haf/branches/hildon-thumbnail/daemonize/daemon/plugins/exec-plugin.c
===================================================================
--- projects/haf/branches/hildon-thumbnail/daemonize/daemon/plugins/exec-plugin.c	2008-09-10 10:04:14 UTC (rev 16082)
+++ projects/haf/branches/hildon-thumbnail/daemonize/daemon/plugins/exec-plugin.c	2008-09-10 12:42:34 UTC (rev 16083)
@@ -71,17 +71,26 @@
 
 
 static gchar*
-string_replace (const gchar *in, const gchar *large, const gchar *normal, const gchar *cropped, const gchar *mime_type, const gchar *mime_type_at, gboolean cropping, guint mtime)
+string_replace (const gchar *in, const gchar *uri, const gchar *large, const gchar *normal, const gchar *cropped, const gchar *mime_type, const gchar *mime_type_at, gboolean cropping, guint mtime)
 {
 	gchar *ptr;
 	guint total = strlen (in);
 	guint len, i, off = 0, z, in_len = total;
 	guint large_len, normal_len, cropped_len, mime_len, 
-		mtime_len, cropping_len, mime_at_len;
+		mtime_len, cropping_len, mime_at_len, uri_len;
 	gchar *s_mtime = g_strdup_printf ("%lu", mtime);
 	gchar *ret;
 
+
 	ptr = (gchar *) in;
+	len = strlen (uri);
+	while (ptr) {
+		ptr = strstr ("{uri}", ptr);
+		total += len;
+	}
+	uri_len = len;
+
+	ptr = (gchar *) in;
 	len = strlen (normal);
 	while (ptr) {
 		ptr = strstr ("{normal}", ptr);
@@ -176,6 +185,11 @@
 					off += mime_at_len;
 				}
 
+				if (buf[0] == 'u') {
+					memcpy (ret + off, uri, uri_len);
+					off += uri_len;
+				}
+
 				if (buf[0] == 'n') {
 					memcpy (ret + off, normal, normal_len);
 					off += normal_len;
@@ -272,7 +286,7 @@
 
 		exec = g_hash_table_lookup (execs, content_type);
 
-		r_exec = string_replace (exec, large, normal, cropped, 
+		r_exec = string_replace (exec, uri, large, normal, cropped, 
 					 mime_type, mime_type_at, do_cropped, mtime);
 
 		g_free (exec);

Modified: projects/haf/branches/hildon-thumbnail/daemonize/thumbs/Makefile.am
===================================================================
--- projects/haf/branches/hildon-thumbnail/daemonize/thumbs/Makefile.am	2008-09-10 10:04:14 UTC (rev 16082)
+++ projects/haf/branches/hildon-thumbnail/daemonize/thumbs/Makefile.am	2008-09-10 12:42:34 UTC (rev 16083)
@@ -13,6 +13,8 @@
 
 bin_PROGRAMS = hildon-thumb-gdk-pixbuf hildon-thumber-register
 
+bin_SCRIPTS = hildon-thumbnailer-wrap.sh
+
 if ENABLE_OSSO
 hildon_thumb_gdk_pixbuf_CFLAGS = $(generic_includes)  $(LIBOSSO_CFLAGS) \
 	$(GDK_PIXBUF_CFLAGS)
@@ -21,7 +23,8 @@
 	$(top_builddir)/daemon/libshared.la $(GDK_PIXBUF_LIBS) \
 	$(LIBOSSO_LIBS)
 
-hildon_thumber_register_CFLAGS = $(generic_includes) $(LIBOSSO_CFLAGS)
+hildon_thumber_register_CFLAGS = $(generic_includes) $(LIBOSSO_CFLAGS) \
+	-DBIN_PATH=\"$(prefix)/bin\"
 hildon_thumber_register_SOURCES = thumber-register.c
 hildon_thumber_register_LDADD = libhildonthumbnail.la $(generic_libs) \
 	$(top_builddir)/daemon/libshared.la $(LIBOSSO_LIBS)

Added: projects/haf/branches/hildon-thumbnail/daemonize/thumbs/hildon-thumbnailer-wrap.sh
===================================================================
--- projects/haf/branches/hildon-thumbnail/daemonize/thumbs/hildon-thumbnailer-wrap.sh	2008-09-10 10:04:14 UTC (rev 16082)
+++ projects/haf/branches/hildon-thumbnail/daemonize/thumbs/hildon-thumbnailer-wrap.sh	2008-09-10 12:42:34 UTC (rev 16083)
@@ -0,0 +1,8 @@
+#! /bin/sh
+
+# Make the large
+$1 "$2" "$6" "$3" 0 256 256
+
+# Make the small
+$1 "$2" "$6" "$4" 0 128 128
+

Modified: projects/haf/branches/hildon-thumbnail/daemonize/thumbs/thumber-register.c
===================================================================
--- projects/haf/branches/hildon-thumbnail/daemonize/thumbs/thumber-register.c	2008-09-10 10:04:14 UTC (rev 16082)
+++ projects/haf/branches/hildon-thumbnail/daemonize/thumbs/thumber-register.c	2008-09-10 12:42:34 UTC (rev 16083)
@@ -32,8 +32,9 @@
 
 GQuark reg_quark = 0;
 
-#define CONVERT_CMD "%s \"{large}\" \"{mime_at}\" /tmp/.thumbnail_file 0 256 256"
+#define CONVERT_CMD BIN_PATH G_DIR_SEPARATOR_S "hildon-thumbnailer-wrap.sh \"%s\" \"{uri}\" \"{large}\" \"{normal}\" \"{cropped}\" \"{mime_at}\" \"{mime}\""
 
+
 static void
 write_keyfile (const gchar *filen, GKeyFile *keyfile)
 {
@@ -55,6 +56,11 @@
 	guint i = 0, length;
 	gchar *r_cmd;
 
+	gchar *d = g_build_filename (g_get_user_config_dir (), "hildon-thumbnailer", NULL);
+
+	g_mkdir_with_parents (d, 0770);
+	g_free (d);
+
 	keyfile = g_key_file_new ();
 	if (!g_key_file_load_from_file (keyfile, config, G_KEY_FILE_NONE, NULL)) {
 		gchar **mimetypes;
@@ -68,18 +74,22 @@
 		g_strfreev (mimetypes);
 
 	} else {
-		guint length, i;
+		guint length, i, z = 0;
 		gchar **o;
 		gchar **mimetypes;
 
 		o = g_key_file_get_string_list (keyfile, "Hildon Thumbnailer", "MimeTypes", 
 							&length, NULL);
 
-		mimetypes = (gchar **) g_malloc0 (sizeof (gchar *) * (length + 1));
-		for (i = 0; i< length; i++)
-			mimetypes[i] = g_strdup (o[i]);
+		mimetypes = (gchar **) g_malloc0 (sizeof (gchar *) * (length + 2));
+		for (i = 0; i< length; i++) {
+			if (strcmp (o[i], mime_type) != 0) {
+				mimetypes[z] = g_strdup (o[i]);
+				z++;
+			}
+		}
 
-		mimetypes[i] = g_strdup (mime_type);
+		mimetypes[z] = g_strdup (mime_type);
 		g_strfreev (o);
 
 		g_key_file_set_string_list (keyfile, "Hildon Thumbnailer", "MimeTypes", 
@@ -115,42 +125,105 @@
 	if (g_key_file_load_from_file (keyfile, config, G_KEY_FILE_NONE, NULL)) {
 		guint length, i, z;
 		gchar **o;
-		gchar **mimetypes;
+		gchar **mimetypes = NULL;
 
 		o = g_key_file_get_string_list (keyfile, "Hildon Thumbnailer", "MimeTypes", 
 							&length, NULL);
 
-		mimetypes = (gchar **) g_malloc0 (sizeof (gchar *) * length);
+		if (length > 0) {
+			mimetypes = (gchar **) g_malloc0 (sizeof (gchar *) * length);
 
-		z = 0;
+			z = 0;
 
-		for (i = 0; i< length; i++) {
-			
-			// TODO: if above it's replaced with a script, we better
-			// make sure this is fixed to cope with whatever changes
-			// above too
-			
-			gchar *exec = g_key_file_get_string (keyfile, o[i], "Exec", NULL);
+			for (i = 0; i< length; i++) {
+				gboolean doit = FALSE;
+				gchar *exec = g_key_file_get_string (keyfile, o[i], "Exec", NULL);
 
-			if (exec) {
-				gchar *ptr = strchr (exec, '"');
-				if (ptr)
-					*ptr = '\0';
-				if (strcmp (ptr, cmd) != 0) {
+				if (exec) {
+					gchar *ptr = strchr (exec, '"');
+					if (ptr) {
+						gchar *check;
+						ptr++;
+						check = ptr;
+						ptr = strchr (ptr, '"');
+						if (ptr) {
+							*ptr = '\0';
+							if (strcmp (check, cmd) == 0) {
+								g_key_file_remove_group (keyfile, o[i], NULL);
+								doit = FALSE;
+							} else
+								doit = TRUE;
+						} else
+							doit = TRUE;
+					} else
+						doit = TRUE;
+				} else
+					doit = TRUE;
+
+				if (doit) {
 					mimetypes[z] = g_strdup (o[i]);
 					z++;
+				}
+			}
+		}
+
+		g_strfreev (o);
+
+		if (mimetypes) {
+			g_key_file_set_string_list (keyfile, "Hildon Thumbnailer", "MimeTypes", 
+						    (const gchar **) mimetypes, (gsize) length+1);
+
+			g_strfreev (mimetypes);
+		}
+
+		write_keyfile (config, keyfile);
+	}
+
+	g_free (config);
+	g_key_file_free (keyfile);
+}
+
+
+void thumber_unregister_mime (char *mime, GError **err)
+{
+	gchar *config = g_build_filename (g_get_user_config_dir (), "hildon-thumbnailer", "exec-plugin.conf", NULL);
+	GKeyFile *keyfile;
+	gchar **mimetypes;
+	guint i = 0, length;
+
+	keyfile = g_key_file_new ();
+
+	if (g_key_file_load_from_file (keyfile, config, G_KEY_FILE_NONE, NULL)) {
+		guint length, i, z;
+		gchar **o;
+		gchar **mimetypes = NULL;
+
+		o = g_key_file_get_string_list (keyfile, "Hildon Thumbnailer", "MimeTypes", 
+							&length, NULL);
+
+		if (length > 0) {
+			mimetypes = (gchar **) g_malloc0 (sizeof (gchar *) * length);
+
+			z = 0;
+
+			for (i = 0; i< length; i++) {
+				if (strcmp (o[i], mime) == 0) {
+					g_key_file_remove_group (keyfile, o[i], NULL);
 				} else {
-					g_key_file_remove_group (keyfile, o[i], NULL);
+					mimetypes[z] = g_strdup (o[i]);
+					z++;
 				}
 			}
 		}
 
 		g_strfreev (o);
 
-		g_key_file_set_string_list (keyfile, "Hildon Thumbnailer", "MimeTypes", 
+		if (mimetypes) {
+			g_key_file_set_string_list (keyfile, "Hildon Thumbnailer", "MimeTypes", 
 					    (const gchar **) mimetypes, (gsize) length+1);
 
-		g_strfreev (mimetypes);
+			g_strfreev (mimetypes);
+		}
 
 		write_keyfile (config, keyfile);
 	}
@@ -170,6 +243,7 @@
         printf( "Usage:\n"
                 "    osso-thumber-register <handler-cmd> <mime-type>\n"
                 "    osso-thumber-register -u <handler-cmd>\n"
+                "    osso-thumber-register -um <mime>\n"
                 "Options:\n"
                 "    -u : unregister specified thumber command\n"
         );
@@ -180,6 +254,8 @@
 
         if(strcmp(argv[1], "-u") == 0) {
             thumber_unregister(argv[2], &err);
+        } else if(strcmp(argv[1], "-um") == 0) {
+            thumber_unregister_mime(argv[2], &err);
         } else {
             thumber_register(argv[1], argv[2], &err);
         }


More information about the maemo-commits mailing list