[evince] [metadata] Run evince-convert-metadata tool at startup when needed



commit cdbc65b6566faa422bab219c0b60d30d0093eaeb
Author: Carlos Garcia Campos <carlosgc gnome org>
Date:   Sun Oct 11 14:30:18 2009 +0200

    [metadata] Run evince-convert-metadata tool at startup when needed
    
    This will migrate the old metadata file to gvfs metadata

 shell/Makefile.am |    1 +
 shell/main.c      |   80 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 81 insertions(+), 0 deletions(-)
---
diff --git a/shell/Makefile.am b/shell/Makefile.am
index 3ccc9ed..7a4489e 100644
--- a/shell/Makefile.am
+++ b/shell/Makefile.am
@@ -17,6 +17,7 @@ INCLUDES=							\
 	-I$(top_srcdir)/properties				\
 	-DGNOMELOCALEDIR=\"$(datadir)/locale\"			\
 	-DGNOMEICONDIR=\""$(datadir)/pixmaps"\" 		\
+	-DLIBEXECDIR=\""$(libexecdir)"\"			\
 	-DEVINCE_COMPILATION					\
 	$(SHELL_CFLAGS)						\
 	$(WARN_CFLAGS)						\
diff --git a/shell/main.c b/shell/main.c
index 2ad17da..a84c17f 100644
--- a/shell/main.c
+++ b/shell/main.c
@@ -26,6 +26,13 @@
 #include <glib/gi18n.h>
 #include <gtk/gtk.h>
 
+#ifndef G_OS_WIN32
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <unistd.h>
+#endif
+
 #ifdef ENABLE_DBUS
 #include <gdk/gdkx.h>
 #include <dbus/dbus-glib-bindings.h>
@@ -37,6 +44,7 @@
 #include "ev-init.h"
 #include "ev-file-helpers.h"
 #include "ev-stock-icons.h"
+#include "ev-metadata.h"
 
 #ifdef WITH_SMCLIENT
 #include "eggsmclient.h"
@@ -146,6 +154,74 @@ launch_previewer (void)
 	return retval;
 }
 
+#ifndef G_OS_WIN32
+static gboolean
+convert_metadata (const gchar *metadata)
+{
+	GFile   *file;
+	gchar   *cmd;
+	gint     exit_status;
+	GError  *error = NULL;
+	gboolean retval;
+
+	/* If metadata is not supported for a local file
+	 * is likely because and old gvfs version is running.
+	 */
+	file = g_file_new_for_path (metadata);
+	if (!ev_is_metadata_supported_for_file (file)) {
+		g_warning ("%s\n",
+			   "GVFS metadata not supported, "
+			   "Evince will run without metadata support");
+		g_object_unref (file);
+		return FALSE;
+	}
+	g_object_unref (file);
+
+	cmd = g_strdup_printf ("%s %s", LIBEXECDIR"/evince-convert-metadata", metadata);
+
+	retval = g_spawn_command_line_sync (cmd, NULL, NULL, &exit_status, &error);
+	g_free (cmd);
+
+	if (!retval) {
+		g_printerr ("Error migrating metadata: %s\n", error->message);
+		g_error_free (error);
+	}
+
+	return retval && exit_status == 0;
+}
+
+static void
+ev_migrate_metadata (void)
+{
+	gchar *updated;
+	gchar *metadata;
+
+	updated = g_build_filename (ev_application_get_dot_dir (EV_APP),
+				    "migrated-to-gvfs", NULL);
+	if (g_file_test (updated, G_FILE_TEST_EXISTS)) {
+		/* Already migrated */
+		g_free (updated);
+		return;
+	}
+
+	metadata = g_build_filename (ev_application_get_dot_dir (EV_APP),
+				     "ev-metadata.xml", NULL);
+	if (g_file_test (metadata, G_FILE_TEST_EXISTS)) {
+		if (convert_metadata (metadata)) {
+			gint fd;
+
+			fd = g_creat (updated, 0600);
+			if (fd != -1) {
+				close (fd);
+			}
+		}
+	}
+
+	g_free (updated);
+	g_free (metadata);
+}
+#endif /* !G_OS_WIN32 */
+
 static void
 value_free (GValue *value)
 {
@@ -475,6 +551,10 @@ main (int argc, char *argv[])
         if (!ev_init ())
                 return 1;
 
+#ifndef G_OS_WIN32
+	ev_migrate_metadata ();
+#endif
+
 	ev_stock_icons_init ();
 
 #if defined(WITH_SMCLIENT) && defined(GDK_WINDOWING_X11)



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]