[sushi] evince: cleanup the PDF loader when changing file



commit 52a8997ed2d33e172a13631529968f148744336c
Author: Cosimo Cecchi <cosimoc gnome org>
Date:   Wed Apr 27 16:18:21 2011 -0400

    evince: cleanup the PDF loader when changing file

 src/js/viewers/evince.js        |    6 ++++++
 src/libsushi/sushi-pdf-loader.c |   26 +++++++++++++++++++++-----
 src/libsushi/sushi-pdf-loader.h |    7 ++++---
 3 files changed, 31 insertions(+), 8 deletions(-)
---
diff --git a/src/js/viewers/evince.js b/src/js/viewers/evince.js
index 040735a..f877768 100644
--- a/src/js/viewers/evince.js
+++ b/src/js/viewers/evince.js
@@ -115,6 +115,12 @@ EvinceRenderer.prototype = {
         this._toolbarActor.set_size(32, 32);
 
         return this._toolbarActor;
+    },
+
+    clear : function() {
+        this._pdfLoader.cleanup_document();
+        delete this._document;
+        delete this._pdfLoader;
     }
 }
 
diff --git a/src/libsushi/sushi-pdf-loader.c b/src/libsushi/sushi-pdf-loader.c
index 88292e0..aa59a51 100644
--- a/src/libsushi/sushi-pdf-loader.c
+++ b/src/libsushi/sushi-pdf-loader.c
@@ -15,6 +15,8 @@ struct _SushiPdfLoaderPrivate {
   EvDocument *document;
   gchar *uri;
   gchar *pdf_path;
+
+  GPid unoconv_pid;
 };
 
 static void
@@ -59,6 +61,7 @@ unoconv_child_watch_cb (GPid pid,
   gchar *uri;
 
   g_spawn_close_pid (pid);
+  self->priv->unoconv_pid = -1;
 
   file = g_file_new_for_path (self->priv->pdf_path);
   uri = g_file_get_uri (file);
@@ -121,6 +124,7 @@ load_openoffice (SushiPdfLoader *self)
   }
 
   g_child_watch_add (pid, unoconv_child_watch_cb, self);
+  self->priv->unoconv_pid = pid;
 }
 
 static gboolean
@@ -201,19 +205,30 @@ sushi_pdf_loader_set_uri (SushiPdfLoader *self,
   start_loading_document (self);
 }
 
+void
+sushi_pdf_loader_cleanup_document (SushiPdfLoader *self)
+{
+  if (self->priv->pdf_path) {
+    g_unlink (self->priv->pdf_path);
+    g_free (self->priv->pdf_path);
+  }
+
+  if (self->priv->unoconv_pid != -1) {
+    kill (self->priv->unoconv_pid, SIGKILL);
+    self->priv->unoconv_pid = -1;
+  }
+}
+
 static void
 sushi_pdf_loader_dispose (GObject *object)
 {
   SushiPdfLoader *self = SUSHI_PDF_LOADER (object);
 
+  sushi_pdf_loader_cleanup_document (self);
+
   g_clear_object (&self->priv->document);
   g_free (self->priv->uri);
 
-  if (self->priv->pdf_path) {
-    g_unlink (self->priv->pdf_path);
-    g_free (self->priv->pdf_path);
-  }
-
   G_OBJECT_CLASS (sushi_pdf_loader_parent_class)->dispose (object);
 }
 
@@ -294,6 +309,7 @@ sushi_pdf_loader_init (SushiPdfLoader *self)
     G_TYPE_INSTANCE_GET_PRIVATE (self,
                                  SUSHI_TYPE_PDF_LOADER,
                                  SushiPdfLoaderPrivate);
+  self->priv->unoconv_pid = -1;
 }
 
 SushiPdfLoader *
diff --git a/src/libsushi/sushi-pdf-loader.h b/src/libsushi/sushi-pdf-loader.h
index 50a5e83..a50d369 100644
--- a/src/libsushi/sushi-pdf-loader.h
+++ b/src/libsushi/sushi-pdf-loader.h
@@ -31,9 +31,10 @@ struct _SushiPdfLoaderClass
 GType    sushi_pdf_loader_get_type     (void) G_GNUC_CONST;
 
 SushiPdfLoader *sushi_pdf_loader_new (const gchar *uri);
-void     sushi_pdf_loader_get_max_page_size (SushiPdfLoader *self,
-                                             gdouble *width,
-                                             gdouble *height);
+void sushi_pdf_loader_cleanup_document (SushiPdfLoader *self);
+void sushi_pdf_loader_get_max_page_size (SushiPdfLoader *self,
+                                         gdouble *width,
+                                         gdouble *height);
 
 
 G_END_DECLS



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