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

From: subversion at stage.maemo.org subversion at stage.maemo.org
Date: Tue Sep 9 18:34:31 EEST 2008
Author: pvanhoof
Date: 2008-09-09 18:34:29 +0300 (Tue, 09 Sep 2008)
New Revision: 16074

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/daemon/plugins/gdkpixbuf-plugin.c
   projects/haf/branches/hildon-thumbnail/daemonize/thumbs/thumber-register.c
Log:
2008-09-09  Philip Van Hoof  <pvanhoof at gnome.org>

	* thumbs/thumber-register.c: Reimplemented hildon-thumbnail-register
	* daemon/plugins/gdkpixbuf-plugin.c
	* daemon/plugins/exec-plugin.c: Fixed two bugs loading configuration



Modified: projects/haf/branches/hildon-thumbnail/daemonize/ChangeLog
===================================================================
--- projects/haf/branches/hildon-thumbnail/daemonize/ChangeLog	2008-09-09 14:06:45 UTC (rev 16073)
+++ projects/haf/branches/hildon-thumbnail/daemonize/ChangeLog	2008-09-09 15:34:29 UTC (rev 16074)
@@ -1,5 +1,11 @@
 2008-09-09  Philip Van Hoof  <pvanhoof at gnome.org>
 
+	* thumbs/thumber-register.c: Reimplemented hildon-thumbnail-register
+	* daemon/plugins/gdkpixbuf-plugin.c
+	* daemon/plugins/exec-plugin.c: Fixed two bugs loading configuration
+
+2008-09-09  Philip Van Hoof  <pvanhoof at gnome.org>
+
 	* thumbs/thumber-gdk-pixbuf.c
 	* thumbs/Makefile.am
 	* thumbs/thumber-register.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-09 14:06:45 UTC (rev 16073)
+++ projects/haf/branches/hildon-thumbnail/daemonize/daemon/plugins/exec-plugin.c	2008-09-09 15:34:29 UTC (rev 16074)
@@ -315,6 +315,8 @@
 	GStrv mimetypes;
 	guint i = 0, length;
 
+	keyfile = g_key_file_new ();
+
 	if (!g_key_file_load_from_file (keyfile, config, G_KEY_FILE_NONE, NULL)) {
 		g_free (config);
 		do_cropped = TRUE;

Modified: projects/haf/branches/hildon-thumbnail/daemonize/daemon/plugins/gdkpixbuf-plugin.c
===================================================================
--- projects/haf/branches/hildon-thumbnail/daemonize/daemon/plugins/gdkpixbuf-plugin.c	2008-09-09 14:06:45 UTC (rev 16073)
+++ projects/haf/branches/hildon-thumbnail/daemonize/daemon/plugins/gdkpixbuf-plugin.c	2008-09-09 15:34:29 UTC (rev 16074)
@@ -374,6 +374,8 @@
 	gchar *config = g_build_filename (g_get_user_config_dir (), "hildon-thumbnailer", "gdkpixbuf-plugin.conf", NULL);
 	GKeyFile *keyfile;
 
+	keyfile = g_key_file_new ();
+
 	if (!g_key_file_load_from_file (keyfile, config, G_KEY_FILE_NONE, NULL)) {
 		g_free (config);
 		do_cropped = TRUE;

Modified: projects/haf/branches/hildon-thumbnail/daemonize/thumbs/thumber-register.c
===================================================================
--- projects/haf/branches/hildon-thumbnail/daemonize/thumbs/thumber-register.c	2008-09-09 14:06:45 UTC (rev 16073)
+++ projects/haf/branches/hildon-thumbnail/daemonize/thumbs/thumber-register.c	2008-09-09 15:34:29 UTC (rev 16074)
@@ -32,14 +32,122 @@
 
 GQuark reg_quark = 0;
 
+#define CONVERT_CMD "%s \"{large}\" \"{mime}\" /tmp/.thumbnail_file 0 256 256"
+
+static void
+write_keyfile (const gchar *filen, GKeyFile *keyfile)
+{
+	FILE* file = fopen (filen, "w");
+
+	if (file) {
+		gsize len;
+		char *str = g_key_file_to_data (keyfile, &len, NULL);
+		fputs (str, file);
+		fclose (file);
+	}
+}
+
 void thumber_register(char *cmd, char *mime_type, 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;
+	gchar *r_cmd;
+
+	keyfile = g_key_file_new ();
+	if (!g_key_file_load_from_file (keyfile, config, G_KEY_FILE_NONE, NULL)) {
+		gchar **mimetypes;
+
+		mimetypes = (gchar **) g_malloc0 (sizeof (gchar *) * 2);
+		mimetypes[0] = g_strdup (mime_type);
+		g_key_file_set_boolean (keyfile, "Hildon Thumbnailer", "DoCropping", FALSE);
+		g_key_file_set_string_list (keyfile, "Hildon Thumbnailer", "MimeTypes", 
+					    (const gchar **) mimetypes, (gsize) 1);
+
+		g_strfreev (mimetypes);
+
+	} else {
+		guint length, i;
+		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[i] = g_strdup (mime_type);
+		g_strfreev (o);
+
+		g_key_file_set_string_list (keyfile, "Hildon Thumbnailer", "MimeTypes", 
+					    (const gchar **) mimetypes, (gsize) length+1);
+
+		g_strfreev (mimetypes);
+	}
+
+	r_cmd = g_strdup_printf (CONVERT_CMD, cmd);
+
+	g_key_file_set_string (keyfile, mime_type, "Exec", r_cmd);
+
+	write_keyfile (config, keyfile);
+
+	g_free (r_cmd);
+	g_free (config);
+	g_key_file_free (keyfile);
 }
 
 void thumber_unregister(char *cmd, 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;
+
+		o = g_key_file_get_string_list (keyfile, "Hildon Thumbnailer", "MimeTypes", 
+							&length, NULL);
+
+		mimetypes = (gchar **) g_malloc0 (sizeof (gchar *) * length);
+
+		z = 0;
+
+		for (i = 0; i< length; i++) {
+			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) {
+					mimetypes[z] = g_strdup (o[i]);
+					z++;
+				} else {
+					g_key_file_remove_group (keyfile, o[i], NULL);
+				}
+			}
+		}
+
+		g_strfreev (o);
+
+		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);
 }
 
 int main(int argc, char **argv)


More information about the maemo-commits mailing list