]> www.fi.muni.cz Git - evince.git/commitdiff
Remove attachments from EvDocument interface and use EvDocumentAttachments instead
authorCarlos Garcia Campos <carlosgc@gnome.org>
Tue, 18 Aug 2009 08:18:55 +0000 (10:18 +0200)
committerCarlos Garcia Campos <carlosgc@gnome.org>
Tue, 15 Sep 2009 13:56:00 +0000 (15:56 +0200)
backend/pdf/ev-poppler.cc
libdocument/ev-document.c
libdocument/ev-document.h
libview/ev-jobs.c
shell/ev-sidebar-attachments.c

index 0a073ca0b04ae48a5501281bb202e11bf30c077b..0333d715564810d5209bc9856e0c2386fc8b6733 100644 (file)
@@ -48,6 +48,7 @@
 #include "ev-document-layers.h"
 #include "ev-document-print.h"
 #include "ev-document-annotations.h"
+#include "ev-document-attachments.h"
 #include "ev-selection.h"
 #include "ev-transition-effect.h"
 #include "ev-attachment.h"
@@ -124,6 +125,7 @@ static void pdf_document_document_layers_iface_init      (EvDocumentLayersIface
 static void pdf_document_document_print_iface_init       (EvDocumentPrintIface       *iface);
 #endif
 static void pdf_document_document_annotations_iface_init (EvDocumentAnnotationsIface *iface);
+static void pdf_document_document_attachments_iface_init (EvDocumentAttachmentsIface *iface);
 static void pdf_document_find_iface_init                 (EvDocumentFindIface        *iface);
 static void pdf_document_file_exporter_iface_init        (EvFileExporterIface        *iface);
 static void pdf_selection_iface_init                     (EvSelectionIface           *iface);
@@ -163,6 +165,8 @@ EV_BACKEND_REGISTER_WITH_CODE (PdfDocument, pdf_document,
 #endif
                                 EV_BACKEND_IMPLEMENT_INTERFACE (EV_TYPE_DOCUMENT_ANNOTATIONS,
                                                                 pdf_document_document_annotations_iface_init);
+                                EV_BACKEND_IMPLEMENT_INTERFACE (EV_TYPE_DOCUMENT_ATTACHMENTS,
+                                                                pdf_document_document_attachments_iface_init);
                                 EV_BACKEND_IMPLEMENT_INTERFACE (EV_TYPE_DOCUMENT_FIND,
                                                                 pdf_document_find_iface_init);
                                 EV_BACKEND_IMPLEMENT_INTERFACE (EV_TYPE_FILE_EXPORTER,
@@ -361,122 +365,6 @@ pdf_document_get_page_label (EvDocument *document,
        return label;
 }
 
-static gboolean
-pdf_document_has_attachments (EvDocument *document)
-{
-       PdfDocument *pdf_document;
-
-       pdf_document = PDF_DOCUMENT (document);
-
-       return poppler_document_has_attachments (pdf_document->document);
-}
-
-struct SaveToBufferData {
-       gchar *buffer;
-       gsize len, max;
-};
-
-static gboolean
-attachment_save_to_buffer_callback (const gchar  *buf,
-                                   gsize         count,
-                                   gpointer      user_data,
-                                   GError      **error)
-{
-       struct SaveToBufferData *sdata = (SaveToBufferData *)user_data;
-       gchar *new_buffer;
-       gsize new_max;
-
-       if (sdata->len + count > sdata->max) {
-               new_max = MAX (sdata->max * 2, sdata->len + count);
-               new_buffer = (gchar *)g_realloc (sdata->buffer, new_max);
-
-               sdata->buffer = new_buffer;
-               sdata->max = new_max;
-       }
-       
-       memcpy (sdata->buffer + sdata->len, buf, count);
-       sdata->len += count;
-       
-       return TRUE;
-}
-
-static gboolean
-attachment_save_to_buffer (PopplerAttachment  *attachment,
-                          gchar             **buffer,
-                          gsize              *buffer_size,
-                          GError            **error)
-{
-       static const gint initial_max = 1024;
-       struct SaveToBufferData sdata;
-
-       *buffer = NULL;
-       *buffer_size = 0;
-
-       sdata.buffer = (gchar *) g_malloc (initial_max);
-       sdata.max = initial_max;
-       sdata.len = 0;
-
-       if (! poppler_attachment_save_to_callback (attachment,
-                                                  attachment_save_to_buffer_callback,
-                                                  &sdata,
-                                                  error)) {
-               g_free (sdata.buffer);
-               return FALSE;
-       }
-
-       *buffer = sdata.buffer;
-       *buffer_size = sdata.len;
-       
-       return TRUE;
-}
-
-static GList *
-pdf_document_get_attachments (EvDocument *document)
-{
-       PdfDocument *pdf_document;
-       GList *attachments;
-       GList *list;
-       GList *retval = NULL;
-
-       pdf_document = PDF_DOCUMENT (document);
-
-       if (!pdf_document_has_attachments (document))
-               return NULL;
-
-       attachments = poppler_document_get_attachments (pdf_document->document);
-       
-       for (list = attachments; list; list = list->next) {
-               PopplerAttachment *attachment;
-               EvAttachment *ev_attachment;
-               gchar *data = NULL;
-               gsize size;
-               GError *error = NULL;
-
-               attachment = (PopplerAttachment *) list->data;
-
-               if (attachment_save_to_buffer (attachment, &data, &size, &error)) {
-                       ev_attachment = ev_attachment_new (attachment->name,
-                                                          attachment->description,
-                                                          attachment->mtime,
-                                                          attachment->ctime,
-                                                          size, data);
-                       
-                       retval = g_list_prepend (retval, ev_attachment);
-               } else {
-                       if (error) {
-                               g_warning ("%s", error->message);
-                               g_error_free (error);
-
-                               g_free (data);
-                       }
-               }
-
-               g_object_unref (attachment);
-       }
-
-       return g_list_reverse (retval);
-}
-
 static cairo_surface_t *
 pdf_page_render (PopplerPage     *page,
                 gint             width,
@@ -841,8 +729,6 @@ pdf_document_document_iface_init (EvDocumentIface *iface)
        iface->get_page = pdf_document_get_page;
        iface->get_page_size = pdf_document_get_page_size;
        iface->get_page_label = pdf_document_get_page_label;
-       iface->has_attachments = pdf_document_has_attachments;
-       iface->get_attachments = pdf_document_get_attachments;
        iface->render = pdf_document_render;
        iface->get_info = pdf_document_get_info;
 };
@@ -2655,6 +2541,123 @@ pdf_document_document_annotations_iface_init (EvDocumentAnnotationsIface *iface)
        iface->annotation_set_contents = pdf_document_annotations_annotation_set_contents;
 }
 
+/* Attachments */
+struct SaveToBufferData {
+       gchar *buffer;
+       gsize len, max;
+};
+
+static gboolean
+attachment_save_to_buffer_callback (const gchar  *buf,
+                                   gsize         count,
+                                   gpointer      user_data,
+                                   GError      **error)
+{
+       struct SaveToBufferData *sdata = (SaveToBufferData *)user_data;
+       gchar *new_buffer;
+       gsize new_max;
+
+       if (sdata->len + count > sdata->max) {
+               new_max = MAX (sdata->max * 2, sdata->len + count);
+               new_buffer = (gchar *)g_realloc (sdata->buffer, new_max);
+
+               sdata->buffer = new_buffer;
+               sdata->max = new_max;
+       }
+
+       memcpy (sdata->buffer + sdata->len, buf, count);
+       sdata->len += count;
+
+       return TRUE;
+}
+
+static gboolean
+attachment_save_to_buffer (PopplerAttachment  *attachment,
+                          gchar             **buffer,
+                          gsize              *buffer_size,
+                          GError            **error)
+{
+       static const gint initial_max = 1024;
+       struct SaveToBufferData sdata;
+
+       *buffer = NULL;
+       *buffer_size = 0;
+
+       sdata.buffer = (gchar *) g_malloc (initial_max);
+       sdata.max = initial_max;
+       sdata.len = 0;
+
+       if (! poppler_attachment_save_to_callback (attachment,
+                                                  attachment_save_to_buffer_callback,
+                                                  &sdata,
+                                                  error)) {
+               g_free (sdata.buffer);
+               return FALSE;
+       }
+
+       *buffer = sdata.buffer;
+       *buffer_size = sdata.len;
+
+       return TRUE;
+}
+
+static GList *
+pdf_document_attachments_get_attachments (EvDocumentAttachments *document)
+{
+       PdfDocument *pdf_document = PDF_DOCUMENT (document);
+       GList *attachments;
+       GList *list;
+       GList *retval = NULL;
+
+       attachments = poppler_document_get_attachments (pdf_document->document);
+
+       for (list = attachments; list; list = list->next) {
+               PopplerAttachment *attachment;
+               EvAttachment *ev_attachment;
+               gchar *data = NULL;
+               gsize size;
+               GError *error = NULL;
+
+               attachment = (PopplerAttachment *) list->data;
+
+               if (attachment_save_to_buffer (attachment, &data, &size, &error)) {
+                       ev_attachment = ev_attachment_new (attachment->name,
+                                                          attachment->description,
+                                                          attachment->mtime,
+                                                          attachment->ctime,
+                                                          size, data);
+
+                       retval = g_list_prepend (retval, ev_attachment);
+               } else {
+                       if (error) {
+                               g_warning ("%s", error->message);
+                               g_error_free (error);
+
+                               g_free (data);
+                       }
+               }
+
+               g_object_unref (attachment);
+       }
+
+       return g_list_reverse (retval);
+}
+
+static gboolean
+pdf_document_attachments_has_attachments (EvDocumentAttachments *document)
+{
+       PdfDocument *pdf_document = PDF_DOCUMENT (document);
+
+       return poppler_document_has_attachments (pdf_document->document);
+}
+
+static void
+pdf_document_document_attachments_iface_init (EvDocumentAttachmentsIface *iface)
+{
+       iface->has_attachments = pdf_document_attachments_has_attachments;
+       iface->get_attachments = pdf_document_attachments_get_attachments;
+}
+
 /* Layers */
 static gboolean
 pdf_document_layers_has_layers (EvDocumentLayers *document)
index e1521b7b5596982c3e10c5d089f29f9b968390e8..9d1144a1b71997bde47f3915aa5aecbd6c9eb5ff 100644 (file)
@@ -221,30 +221,6 @@ ev_document_get_info (EvDocument *document)
        return iface->get_info (document);
 }
 
-gboolean
-ev_document_has_attachments (EvDocument *document)
-{
-       EvDocumentIface *iface = EV_DOCUMENT_GET_IFACE (document);
-
-       if (iface->has_attachments == NULL)
-               return FALSE;
-       
-       return iface->has_attachments (document);
-}
-
-GList *
-ev_document_get_attachments (EvDocument *document)
-{
-       EvDocumentIface *iface = EV_DOCUMENT_GET_IFACE (document);
-       GList *retval;
-
-       if (iface->get_attachments == NULL)
-               return NULL;
-       retval = iface->get_attachments (document);
-
-       return retval;
-}
-
 cairo_surface_t *
 ev_document_render (EvDocument      *document,
                    EvRenderContext *rc)
index 5afdb035166e60951bc0dc9a6b6fa00464da96dc..e74c49abe6f26184d261905ee9c226ac37b90188 100644 (file)
@@ -86,8 +86,6 @@ struct _EvDocumentIface
                                                double          *height);
         char            * (* get_page_label)  (EvDocument      *document,
                                                EvPage          *page);
-        gboolean          (* has_attachments) (EvDocument      *document);
-        GList           * (* get_attachments) (EvDocument      *document);
         cairo_surface_t * (* render)          (EvDocument      *document,
                                                EvRenderContext *rc);
         EvDocumentInfo *  (* get_info)        (EvDocument      *document);
@@ -124,8 +122,6 @@ void             ev_document_get_page_size    (EvDocument      *document,
                                                double          *height);
 char            *ev_document_get_page_label   (EvDocument      *document,
                                                EvPage          *page);
-gboolean         ev_document_has_attachments  (EvDocument      *document);
-GList           *ev_document_get_attachments  (EvDocument      *document);
 cairo_surface_t *ev_document_render           (EvDocument      *document,
                                                EvRenderContext *rc);
 
index 55e76a45821b06bd8f84af9c7311824c7f2ef732..c0aa0b482d5347aa4a63a361ec98c4088caf06fc 100644 (file)
@@ -35,6 +35,7 @@
 #include "ev-document-layers.h"
 #include "ev-document-print.h"
 #include "ev-document-annotations.h"
+#include "ev-document-attachments.h"
 #include "ev-debug.h"
 
 #include <errno.h>
@@ -402,13 +403,14 @@ ev_job_attachments_run (EvJob *job)
 
        ev_debug_message (DEBUG_JOBS, NULL);
        ev_profiler_start (EV_PROFILE_JOBS, "%s (%p)", EV_GET_TYPE_NAME (job), job);
-       
+
        ev_document_doc_mutex_lock ();
-       job_attachments->attachments = ev_document_get_attachments (job->document);
+       job_attachments->attachments =
+               ev_document_attachments_get_attachments (EV_DOCUMENT_ATTACHMENTS (job->document));
        ev_document_doc_mutex_unlock ();
-       
+
        ev_job_succeeded (job);
-       
+
        return FALSE;
 }
 
index 677d61fafd8cae2eae2cc5fe8a8658982c78db7b..e0779f01548755e0f2930b60eb6526bac850727c 100644 (file)
@@ -31,6 +31,7 @@
 #include <glib/gstdio.h>
 #include <gtk/gtk.h>
 
+#include "ev-document-attachments.h"
 #include "ev-jobs.h"
 #include "ev-job-scheduler.h"
 #include "ev-file-helpers.h"
@@ -656,9 +657,6 @@ ev_sidebar_attachments_set_document (EvSidebarPage   *page,
 {
        EvSidebarAttachments *ev_attachbar = EV_SIDEBAR_ATTACHMENTS (page);
        EvJob *job;
-       
-       if (!ev_document_has_attachments (document))
-               return;
 
        if (!ev_attachbar->priv->icon_theme) {
                GdkScreen *screen;
@@ -688,7 +686,8 @@ static gboolean
 ev_sidebar_attachments_support_document (EvSidebarPage   *sidebar_page,
                                         EvDocument      *document)
 {
-       return ev_document_has_attachments (document);
+       return (EV_IS_DOCUMENT_ATTACHMENTS (document) &&
+               ev_document_attachments_has_attachments (document));
 }
 
 static const gchar*