Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/shell/main.c
diff options
context:
space:
mode:
authorCarlos Garcia Campos <carlosgc@gnome.org>2009-10-11 12:30:18 (GMT)
committer Carlos Garcia Campos <carlosgc@gnome.org>2009-10-11 15:12:53 (GMT)
commitcdbc65b6566faa422bab219c0b60d30d0093eaeb (patch)
treefebeb80cf918562e2ac54ea3e447f920be7616ba /shell/main.c
parentc07587236140aca6f4bda452043fb043769f0a80 (diff)
[metadata] Run evince-convert-metadata tool at startup when needed
This will migrate the old metadata file to gvfs metadata
Diffstat (limited to 'shell/main.c')
-rw-r--r--shell/main.c80
1 files changed, 80 insertions, 0 deletions
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)