[sushi] pdf-loader: use PackageKit to install unoconv if it's not found



commit 5a82baafd0c613c1d5f202950b2d1a1c950fa29b
Author: Cosimo Cecchi <cosimoc gnome org>
Date:   Mon Jan 14 11:12:17 2013 -0500

    pdf-loader: use PackageKit to install unoconv if it's not found
    
    Instead of detecting its presence at build time. Based on similar code
    from gnome-documents.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=687727

 configure.ac                    |    9 -----
 src/Makefile-js.am              |    5 ---
 src/js/util/features.js.in      |   28 -----------------
 src/js/viewers/evince.js        |   25 ++++++--------
 src/libsushi/sushi-pdf-loader.c |   65 +++++++++++++++++++++++++++++++++++++++
 5 files changed, 76 insertions(+), 56 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index 204f8c2..476e560 100644
--- a/configure.ac
+++ b/configure.ac
@@ -80,15 +80,6 @@ PKG_CHECK_MODULES(SUSHI,
 GLIB_MKENUMS=`$PKG_CONFIG --variable=glib_mkenums glib-2.0`
 AC_SUBST(GLIB_MKENUMS)
 
-AC_PATH_PROG(UNOCONV, unoconv, 0)
-if test x$UNOCONV = x0; then
-   HAVE_UNOCONV=0
-else
-   HAVE_UNOCONV=1
-fi
-
-AC_SUBST(HAVE_UNOCONV)
-
 AC_CONFIG_FILES([
 Makefile
 src/Makefile
diff --git a/src/Makefile-js.am b/src/Makefile-js.am
index c71c685..203ee40 100644
--- a/src/Makefile-js.am
+++ b/src/Makefile-js.am
@@ -26,7 +26,6 @@ dist_jsutil_DATA = \
     js/util/totemMimeTypes.js
 
 jsutil_built_sources = \
-    $(srcdir)/js/util/features.js \
     $(srcdir)/js/util/path.js
 
 BUILT_SOURCES += $(jsutil_built_sources)
@@ -34,9 +33,6 @@ BUILT_SOURCES += $(jsutil_built_sources)
 js/util/path.js: Makefile js/util/path.js.in
 	$(AM_V_GEN) $(do_subst) $(srcdir)/js/util/path.js.in > $@
 
-js/util/features.js: Makefile js/util/features.js.in
-	$(AM_V_GEN) $(do_subst) $(srcdir)/js/util/features.js.in > $@
-
 nodist_jsutil_DATA = \
     $(jsutil_built_sources)
 
@@ -44,5 +40,4 @@ CLEANFILES += \
     $(BUILT_SOURCES)
 
 EXTRA_DIST += \
-    js/util/features.js.in \
     js/util/path.js.in
diff --git a/src/js/viewers/evince.js b/src/js/viewers/evince.js
index 3257028..b2b28bf 100644
--- a/src/js/viewers/evince.js
+++ b/src/js/viewers/evince.js
@@ -35,7 +35,6 @@ let Gettext = imports.gettext.domain('sushi');
 let _ = Gettext.gettext;
 
 let Utils = imports.ui.utils;
-let Features = imports.util.features;
 
 function EvinceRenderer(args) {
     this._init(args);
@@ -181,16 +180,14 @@ let renderer = new EvinceRenderer();
 let mimeTypes = Sushi.query_supported_document_types();
 handler.registerMimeTypes(mimeTypes, renderer);
 
-if (Features.HAVE_UNOCONV) {
-    let officeTypes = [
-        'application/vnd.oasis.opendocument.text',
-        'application/vnd.oasis.opendocument.presentation',
-        'application/vnd.oasis.opendocument.spreadsheet',
-        'application/msword',
-        'application/vnd.ms-excel',
-        'application/vnd.ms-powerpoint',
-        'application/rtf'
-    ];
-
-    handler.registerMimeTypes(officeTypes, renderer);
-}
+let officeTypes = [
+    'application/vnd.oasis.opendocument.text',
+    'application/vnd.oasis.opendocument.presentation',
+    'application/vnd.oasis.opendocument.spreadsheet',
+    'application/msword',
+    'application/vnd.ms-excel',
+    'application/vnd.ms-powerpoint',
+    'application/rtf'
+];
+
+handler.registerMimeTypes(officeTypes, renderer);
diff --git a/src/libsushi/sushi-pdf-loader.c b/src/libsushi/sushi-pdf-loader.c
index c2bdf6a..4682c1e 100644
--- a/src/libsushi/sushi-pdf-loader.c
+++ b/src/libsushi/sushi-pdf-loader.c
@@ -31,6 +31,7 @@
 #include <evince-document.h>
 #include <evince-view.h>
 #include <glib/gstdio.h>
+#include <gdk/gdkx.h>
 
 G_DEFINE_TYPE (SushiPdfLoader, sushi_pdf_loader, G_TYPE_OBJECT);
 
@@ -39,6 +40,8 @@ enum {
   PROP_URI
 };
 
+static void load_openoffice (SushiPdfLoader *self);
+
 struct _SushiPdfLoaderPrivate {
   EvDocument *document;
   gchar *uri;
@@ -80,6 +83,61 @@ load_pdf (SushiPdfLoader *self,
 }
 
 static void
+openoffice_missing_unoconv_ready_cb (GObject *source,
+                                     GAsyncResult *res,
+                                     gpointer user_data)
+{
+  SushiPdfLoader *self = user_data;
+  GError *error = NULL;
+
+  g_dbus_connection_call_finish (G_DBUS_CONNECTION (source), res, &error);
+  if (error != NULL) {
+    GError *local_error;
+
+    /* can't install unoconv with packagekit - nothing else we can do */
+    /* FIXME: error reporting! */
+    g_warning ("unoconv not found, and PackageKit failed to install it with error %s",
+               error->message);
+    return;
+  }
+
+  /* now that we have unoconv installed, try again loading the document */
+  load_openoffice (self);
+}
+
+static void
+openoffice_missing_unoconv (SushiPdfLoader *self)
+{
+  GApplication *app = g_application_get_default ();
+  GtkWidget *widget = GTK_WIDGET (gtk_application_get_active_window (GTK_APPLICATION (app)));
+  GDBusConnection *connection = g_application_get_dbus_connection (app);
+  guint xid = 0;
+  GdkWindow *gdk_window;
+  const gchar *unoconv_path[2];
+
+  gdk_window = gtk_widget_get_window (widget);
+  if (gdk_window != NULL)
+    xid = GDK_WINDOW_XID (gdk_window);
+
+  unoconv_path[0] = "/usr/bin/unoconv";
+  unoconv_path[1] = NULL;
+
+  g_dbus_connection_call (connection,
+                          "org.freedesktop.PackageKit",
+                          "/org/freedesktop/PackageKit",
+                          "org.freedesktop.PackageKit.Modify",
+                          "InstallProvideFiles",
+                          g_variant_new ("(u^ass)",
+                                         xid,
+                                         unoconv_path,
+                                         "hide-confirm-deps"),
+                          NULL, G_DBUS_CALL_FLAGS_NONE,
+                          G_MAXINT, NULL,
+                          openoffice_missing_unoconv_ready_cb,
+                          self);
+}
+
+static void
 unoconv_child_watch_cb (GPid pid,
                         gint status,
                         gpointer user_data)
@@ -111,6 +169,13 @@ load_openoffice (SushiPdfLoader *self)
   GPid pid;
   gchar **argv = NULL;
   GError *error = NULL;
+  const gchar *unoconv_path;
+
+  unoconv_path = g_find_program_in_path ("unoconv");
+  if (unoconv_path == NULL) {
+      openoffice_missing_unoconv (self);
+      return;
+  }
 
   file = g_file_new_for_uri (self->priv->uri);
   doc_path = g_file_get_path (file);



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