]> www.fi.muni.cz Git - evince.git/blobdiff - shell/ev-sidebar-attachments.c
[shell] Add missing cast
[evince.git] / shell / ev-sidebar-attachments.c
index 2aeadd69a68343ee2e1ca4bb4f02d5096816e8b1..b63c5efc1d165c33e4a7ddc4015a6f29f3aa95d6 100644 (file)
 #include "config.h"
 #endif
 
+#include <string.h>
+
 #include <glib/gi18n.h>
 #include <glib/gstdio.h>
 #include <gtk/gtk.h>
-#include <string.h>
 
+#include "ev-document-attachments.h"
+#include "ev-jobs.h"
+#include "ev-job-scheduler.h"
 #include "ev-file-helpers.h"
 #include "ev-sidebar-attachments.h"
 #include "ev-sidebar-page.h"
@@ -52,10 +56,6 @@ enum {
        N_SIGNALS
 };
 
-static const GtkTargetEntry drag_targets[] = {
-       { "text/uri-list", 0, 0 }
-};
-
 static guint signals[N_SIGNALS];
 
 struct _EvSidebarAttachmentsPrivate {
@@ -292,7 +292,10 @@ ev_sidebar_attachments_button_press (EvSidebarAttachments *ev_attachbar,
                                if (!attachment)
                                        return FALSE;
                                
-                               ev_attachment_open (attachment, &error);
+                               ev_attachment_open (attachment,
+                                                   gtk_widget_get_screen (GTK_WIDGET (ev_attachbar)),
+                                                   event->time,
+                                                   &error);
                                
                                if (error) {
                                        g_warning ("%s", error->message);
@@ -392,15 +395,15 @@ ev_sidebar_attachments_drag_data_get (GtkWidget        *widget,
                                      gpointer          user_data)
 {
        EvSidebarAttachments *ev_attachbar = EV_SIDEBAR_ATTACHMENTS (user_data);
-       GString              *uri_list;
-       gchar                *uris = NULL;
        GList                *selected = NULL, *l;
+        GPtrArray            *uris;
+        char                **uri_list;
 
        selected = gtk_icon_view_get_selected_items (GTK_ICON_VIEW (ev_attachbar->priv->icon_view));
        if (!selected)
                return;
 
-       uri_list = g_string_new (NULL);
+        uris = g_ptr_array_new ();
        
        for (l = selected; l && l->data; l = g_list_next (l)) {
                EvAttachment *attachment;
@@ -428,9 +431,7 @@ ev_sidebar_attachments_drag_data_get (GtkWidget        *widget,
                        gchar *uri;
 
                        uri = g_file_get_uri (file);
-                       g_string_append (uri_list, uri);
-                       g_string_append_c (uri_list, '\n');
-                       g_free (uri);
+                        g_ptr_array_add (uris, uri);
                }
        
                if (error) {
@@ -443,15 +444,10 @@ ev_sidebar_attachments_drag_data_get (GtkWidget        *widget,
                g_object_unref (attachment);
        }
 
-       uris = g_string_free (uri_list, FALSE);
-
-       if (uris) {
-               gtk_selection_data_set (data,
-                                       data->target,
-                                       8,
-                                       (guchar *)uris,
-                                       strlen (uris));
-       }
+        g_ptr_array_add (uris, NULL); /* NULL-terminate */
+        uri_list = (char **) g_ptr_array_free (uris, FALSE);
+        gtk_selection_data_set_uris (data, uri_list);
+        g_strfreev (uri_list);
 
        g_list_free (selected);
 }
@@ -539,6 +535,12 @@ ev_sidebar_attachments_class_init (EvSidebarAttachmentsClass *ev_attachbar_class
 static void
 ev_sidebar_attachments_init (EvSidebarAttachments *ev_attachbar)
 {
+#if !GTK_CHECK_VERSION (2, 15, 0)
+        const GtkTargetEntry drag_targets[] = {
+                { "text/uri-list", 0, 0 }
+        };
+#endif
+
        GtkWidget *swindow;
        
        ev_attachbar->priv = EV_SIDEBAR_ATTACHMENTS_GET_PRIVATE (ev_attachbar);
@@ -566,7 +568,7 @@ ev_sidebar_attachments_init (EvSidebarAttachments *ev_attachbar)
                      "text-column", COLUMN_NAME,
                      "pixbuf-column", COLUMN_ICON,
                      NULL);
-       g_signal_connect_swapped (G_OBJECT (ev_attachbar->priv->icon_view),
+       g_signal_connect_swapped (ev_attachbar->priv->icon_view,
                                  "button-press-event",
                                  G_CALLBACK (ev_sidebar_attachments_button_press),
                                  (gpointer) ev_attachbar);
@@ -588,14 +590,23 @@ ev_sidebar_attachments_init (EvSidebarAttachments *ev_attachbar)
                                                                g_object_unref);
 
        /* Drag and Drop */
+#if GTK_CHECK_VERSION (2, 15, 0)
+       gtk_icon_view_enable_model_drag_source (
+               GTK_ICON_VIEW (ev_attachbar->priv->icon_view),
+               GDK_BUTTON1_MASK,
+               NULL, 0,
+               GDK_ACTION_COPY);
+        gtk_drag_source_add_uri_targets (ev_attachbar->priv->icon_view);
+#else
        gtk_icon_view_enable_model_drag_source (
                GTK_ICON_VIEW (ev_attachbar->priv->icon_view),
                GDK_BUTTON1_MASK,
                drag_targets,
                G_N_ELEMENTS (drag_targets),
                GDK_ACTION_COPY);
+#endif
 
-       g_signal_connect (G_OBJECT (ev_attachbar->priv->icon_view),
+       g_signal_connect (ev_attachbar->priv->icon_view,
                          "drag-data-get",
                          G_CALLBACK (ev_sidebar_attachments_drag_data_get),
                          (gpointer) ev_attachbar);     
@@ -612,32 +623,12 @@ ev_sidebar_attachments_new (void)
 }
 
 static void
-ev_sidebar_attachments_set_document (EvSidebarPage   *page,
-                                    EvDocument      *document)
+job_finished_callback (EvJobAttachments     *job,
+                      EvSidebarAttachments *ev_attachbar)
 {
-       EvSidebarAttachments *ev_attachbar = EV_SIDEBAR_ATTACHMENTS (page);
-       GList *attachments = NULL;
        GList *l;
        
-       if (!ev_document_has_attachments (document))
-               return;
-
-       if (!ev_attachbar->priv->icon_theme) {
-               GdkScreen *screen;
-
-               screen = gtk_widget_get_screen (GTK_WIDGET (ev_attachbar));
-               ev_attachbar->priv->icon_theme = gtk_icon_theme_get_for_screen (screen);
-               g_signal_connect_swapped (G_OBJECT (ev_attachbar->priv->icon_theme),
-                                         "changed",
-                                         G_CALLBACK (ev_sidebar_attachments_update_icons),
-                                         (gpointer) ev_attachbar);
-       }
-               
-       attachments = ev_document_get_attachments (document);
-
-       gtk_list_store_clear (ev_attachbar->priv->model);
-                                          
-       for (l = attachments; l && l->data; l = g_list_next (l)) {
+       for (l = job->attachments; l && l->data; l = g_list_next (l)) {
                EvAttachment *attachment;
                GtkTreeIter   iter;
                GdkPixbuf    *pixbuf = NULL;
@@ -655,18 +646,48 @@ ev_sidebar_attachments_set_document (EvSidebarPage   *page,
                                    COLUMN_ICON, pixbuf,
                                    COLUMN_ATTACHMENT, attachment, 
                                    -1);
+       }
 
-               g_object_unref (attachment);
+       g_object_unref (job);
+}
+
+static void
+ev_sidebar_attachments_set_document (EvSidebarPage   *page,
+                                    EvDocument      *document)
+{
+       EvSidebarAttachments *ev_attachbar = EV_SIDEBAR_ATTACHMENTS (page);
+       EvJob *job;
+
+       if (!ev_attachbar->priv->icon_theme) {
+               GdkScreen *screen;
+
+               screen = gtk_widget_get_screen (GTK_WIDGET (ev_attachbar));
+               ev_attachbar->priv->icon_theme = gtk_icon_theme_get_for_screen (screen);
+               g_signal_connect_swapped (ev_attachbar->priv->icon_theme,
+                                         "changed",
+                                         G_CALLBACK (ev_sidebar_attachments_update_icons),
+                                         (gpointer) ev_attachbar);
        }
+               
+       gtk_list_store_clear (ev_attachbar->priv->model);
 
-       g_list_free (attachments);
+       job = ev_job_attachments_new (document);
+       g_signal_connect (job, "finished",
+                         G_CALLBACK (job_finished_callback),
+                         ev_attachbar);
+       g_signal_connect (job, "cancelled",
+                         G_CALLBACK (g_object_unref),
+                         NULL);
+       /* The priority doesn't matter for this job */
+       ev_job_scheduler_push_job (job, EV_JOB_PRIORITY_NONE);
 }
 
 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 (EV_DOCUMENT_ATTACHMENTS (document)));
 }
 
 static const gchar*