]> www.fi.muni.cz Git - evince.git/blob - shell/ev-sidebar-attachments.c
Use GdkAppLaunchContext when available to open attachments.
[evince.git] / shell / ev-sidebar-attachments.c
1 /* ev-sidebar-attachments.c
2  *  this file is part of evince, a gnome document viewer
3  *
4  * Copyright (C) 2006 Carlos Garcia Campos
5  *
6  * Author:
7  *   Carlos Garcia Campos <carlosgc@gnome.org>
8  *
9  * Evince is free software; you can redistribute it and/or modify it
10  * under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  *
14  * Evince is distributed in the hope that it will be useful, but
15  * WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17  * General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, write to the Free Software
21  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
22  */
23
24 #ifdef HAVE_CONFIG_H
25 #include "config.h"
26 #endif
27
28 #include <string.h>
29
30 #include <glib/gi18n.h>
31 #include <glib/gstdio.h>
32 #include <gtk/gtk.h>
33
34 #include "ev-jobs.h"
35 #include "ev-job-scheduler.h"
36 #include "ev-file-helpers.h"
37 #include "ev-sidebar-attachments.h"
38 #include "ev-sidebar-page.h"
39
40 enum {
41         COLUMN_ICON,
42         COLUMN_NAME,
43         COLUMN_DESCRIPTION,
44         COLUMN_ATTACHMENT,
45         N_COLS
46 };
47
48 enum {
49         PROP_0,
50         PROP_WIDGET,
51 };
52
53 enum {
54         SIGNAL_POPUP_MENU,
55         N_SIGNALS
56 };
57
58 static const GtkTargetEntry drag_targets[] = {
59         { "text/uri-list", 0, 0 }
60 };
61
62 static guint signals[N_SIGNALS];
63
64 struct _EvSidebarAttachmentsPrivate {
65         GtkWidget      *icon_view;
66         GtkListStore   *model;
67
68         /* Icons */
69         GtkIconTheme   *icon_theme;
70         GHashTable     *icon_cache;
71 };
72
73 static void ev_sidebar_attachments_page_iface_init (EvSidebarPageIface *iface);
74
75 G_DEFINE_TYPE_EXTENDED (EvSidebarAttachments,
76                         ev_sidebar_attachments,
77                         GTK_TYPE_VBOX,
78                         0, 
79                         G_IMPLEMENT_INTERFACE (EV_TYPE_SIDEBAR_PAGE, 
80                                                ev_sidebar_attachments_page_iface_init))
81
82 #define EV_SIDEBAR_ATTACHMENTS_GET_PRIVATE(object) \
83                 (G_TYPE_INSTANCE_GET_PRIVATE ((object), EV_TYPE_SIDEBAR_ATTACHMENTS, EvSidebarAttachmentsPrivate))
84
85 /* Icon cache */
86 static void
87 ev_sidebar_attachments_icon_cache_add (EvSidebarAttachments *ev_attachbar,
88                                        const gchar          *mime_type,
89                                        const GdkPixbuf      *pixbuf)
90 {
91         g_assert (mime_type != NULL);
92         g_assert (GDK_IS_PIXBUF (pixbuf));
93
94         g_hash_table_insert (ev_attachbar->priv->icon_cache,
95                              (gpointer)g_strdup (mime_type),
96                              (gpointer)pixbuf);
97                              
98 }
99
100 static GdkPixbuf *
101 icon_theme_get_pixbuf_from_mime_type (GtkIconTheme *icon_theme,
102                                       const gchar  *mime_type)
103 {
104         const char *separator;
105         GString *icon_name;
106         GdkPixbuf *pixbuf;
107
108         separator = strchr (mime_type, '/');
109         if (!separator)
110                 return NULL; /* maybe we should return a GError with "invalid MIME-type" */
111
112         icon_name = g_string_new ("gnome-mime-");
113         g_string_append_len (icon_name, mime_type, separator - mime_type);
114         g_string_append_c (icon_name, '-');
115         g_string_append (icon_name, separator + 1);
116         pixbuf = gtk_icon_theme_load_icon (icon_theme, icon_name->str, 48, 0, NULL);
117         g_string_free (icon_name, TRUE);
118         if (pixbuf)
119                 return pixbuf;
120         
121         icon_name = g_string_new ("gnome-mime-");
122         g_string_append_len (icon_name, mime_type, separator - mime_type);
123         pixbuf = gtk_icon_theme_load_icon (icon_theme, icon_name->str, 48, 0, NULL);
124         g_string_free (icon_name, TRUE);
125         
126         return pixbuf;
127 }
128
129 static GdkPixbuf *
130 ev_sidebar_attachments_icon_cache_get (EvSidebarAttachments *ev_attachbar,
131                                        const gchar          *mime_type)
132 {
133         GdkPixbuf *pixbuf = NULL;
134         
135         g_assert (mime_type != NULL);
136
137         pixbuf = g_hash_table_lookup (ev_attachbar->priv->icon_cache,
138                                       mime_type);
139
140         if (GDK_IS_PIXBUF (pixbuf))
141                 return pixbuf;
142
143         pixbuf = icon_theme_get_pixbuf_from_mime_type (ev_attachbar->priv->icon_theme,
144                                                        mime_type);
145
146         if (GDK_IS_PIXBUF (pixbuf))
147                 ev_sidebar_attachments_icon_cache_add (ev_attachbar,
148                                                        mime_type,
149                                                        pixbuf);
150
151         return pixbuf;
152 }
153
154 static gboolean
155 icon_cache_update_icon (gchar                *key,
156                         GdkPixbuf            *value,
157                         EvSidebarAttachments *ev_attachbar)
158 {
159         GdkPixbuf *pixbuf = NULL;
160
161         pixbuf = icon_theme_get_pixbuf_from_mime_type (ev_attachbar->priv->icon_theme,
162                                                        key);
163
164         ev_sidebar_attachments_icon_cache_add (ev_attachbar,
165                                                key,
166                                                pixbuf);
167         
168         return FALSE;
169 }
170
171 static void
172 ev_sidebar_attachments_icon_cache_refresh (EvSidebarAttachments *ev_attachbar)
173 {
174         g_hash_table_foreach_remove (ev_attachbar->priv->icon_cache,
175                                      (GHRFunc) icon_cache_update_icon,
176                                      ev_attachbar);
177 }
178
179 static EvAttachment *
180 ev_sidebar_attachments_get_attachment_at_pos (EvSidebarAttachments *ev_attachbar,
181                                               gint                  x,
182                                               gint                  y)
183 {
184         GtkTreePath  *path = NULL;
185         GtkTreeIter   iter;
186         EvAttachment *attachment = NULL;
187
188         path = gtk_icon_view_get_path_at_pos (GTK_ICON_VIEW (ev_attachbar->priv->icon_view),
189                                               x, y);
190         if (!path) {
191                 return NULL;
192         }
193
194         gtk_tree_model_get_iter (GTK_TREE_MODEL (ev_attachbar->priv->model),
195                                  &iter, path);
196         gtk_tree_model_get (GTK_TREE_MODEL (ev_attachbar->priv->model), &iter,
197                             COLUMN_ATTACHMENT, &attachment,
198                             -1);
199
200         gtk_icon_view_select_path (GTK_ICON_VIEW (ev_attachbar->priv->icon_view),
201                                    path);
202         
203         gtk_tree_path_free (path);
204
205         return attachment;
206 }
207
208 static gboolean
209 ev_sidebar_attachments_popup_menu_show (EvSidebarAttachments *ev_attachbar,
210                                         gint                  x,
211                                         gint                  y)
212 {
213         GtkIconView *icon_view;
214         GtkTreePath *path;
215         GList       *selected = NULL, *l;
216         GList       *attach_list = NULL;
217
218         icon_view = GTK_ICON_VIEW (ev_attachbar->priv->icon_view);
219         
220         path = gtk_icon_view_get_path_at_pos (icon_view, x, y);
221         if (!path)
222                 return FALSE;
223
224         if (!gtk_icon_view_path_is_selected (icon_view, path)) {
225                 gtk_icon_view_unselect_all (icon_view);
226                 gtk_icon_view_select_path (icon_view, path);
227         }
228
229         gtk_tree_path_free (path);
230         
231         selected = gtk_icon_view_get_selected_items (icon_view);
232         if (!selected)
233                 return FALSE;
234
235         for (l = selected; l && l->data; l = g_list_next (l)) {
236                 GtkTreeIter   iter;
237                 EvAttachment *attachment = NULL;
238
239                 path = (GtkTreePath *) l->data;
240
241                 gtk_tree_model_get_iter (GTK_TREE_MODEL (ev_attachbar->priv->model),
242                                          &iter, path);
243                 gtk_tree_model_get (GTK_TREE_MODEL (ev_attachbar->priv->model), &iter,
244                                     COLUMN_ATTACHMENT, &attachment,
245                                     -1);
246
247                 if (attachment)
248                         attach_list = g_list_prepend (attach_list, attachment);
249
250                 gtk_tree_path_free (path);
251         }
252
253         g_list_free (selected);
254
255         if (!attach_list)
256                 return FALSE;
257
258         g_signal_emit (ev_attachbar, signals[SIGNAL_POPUP_MENU], 0, attach_list);
259
260         return TRUE;
261 }
262
263 static gboolean
264 ev_sidebar_attachments_popup_menu (GtkWidget *widget)
265 {
266         EvSidebarAttachments *ev_attachbar = EV_SIDEBAR_ATTACHMENTS (widget);
267         gint                  x, y;
268
269         gtk_widget_get_pointer (widget, &x, &y);
270
271         return ev_sidebar_attachments_popup_menu_show (ev_attachbar, x, y);
272 }
273
274 static gboolean
275 ev_sidebar_attachments_button_press (EvSidebarAttachments *ev_attachbar,
276                                      GdkEventButton       *event,
277                                      GtkWidget            *icon_view)
278 {
279         if (!GTK_WIDGET_HAS_FOCUS (icon_view)) {
280                 gtk_widget_grab_focus (icon_view);
281         }
282         
283         if (event->button == 2)
284                 return FALSE;
285
286         switch (event->button) {
287                 case 1:
288                         if (event->type == GDK_2BUTTON_PRESS) {
289                                 GError *error = NULL;
290                                 EvAttachment *attachment;
291                                 
292                                 attachment = ev_sidebar_attachments_get_attachment_at_pos (ev_attachbar,
293                                                                                            event->x,
294                                                                                            event->y);
295                                 if (!attachment)
296                                         return FALSE;
297                                 
298                                 ev_attachment_open (attachment,
299                                                     gtk_widget_get_screen (GTK_WIDGET (ev_attachbar)),
300                                                     event->time,
301                                                     &error);
302                                 
303                                 if (error) {
304                                         g_warning ("%s", error->message);
305                                         g_error_free (error);
306                                 }
307                                 
308                                 g_object_unref (attachment);
309                                 
310                                 return TRUE;
311                         }
312                         break;
313                 case 3: 
314                         return ev_sidebar_attachments_popup_menu_show (ev_attachbar, event->x, event->y);
315         }
316
317         return FALSE;
318 }
319
320 static void
321 ev_sidebar_attachments_update_icons (EvSidebarAttachments *ev_attachbar,
322                                      gpointer              user_data)
323 {
324         GtkTreeIter iter;
325         gboolean    valid;
326
327         ev_sidebar_attachments_icon_cache_refresh (ev_attachbar);
328         
329         valid = gtk_tree_model_get_iter_first (
330                 GTK_TREE_MODEL (ev_attachbar->priv->model),
331                 &iter);
332
333         while (valid) {
334                 EvAttachment *attachment = NULL;
335                 GdkPixbuf    *pixbuf = NULL;
336                 const gchar  *mime_type;
337
338                 gtk_tree_model_get (GTK_TREE_MODEL (ev_attachbar->priv->model), &iter,
339                                     COLUMN_ATTACHMENT, &attachment,
340                                     -1);
341
342                 mime_type = ev_attachment_get_mime_type (attachment);
343
344                 if (attachment)
345                         g_object_unref (attachment);
346
347                 pixbuf = ev_sidebar_attachments_icon_cache_get (ev_attachbar,
348                                                                 mime_type);
349
350                 gtk_list_store_set (ev_attachbar->priv->model, &iter,
351                                     COLUMN_ICON, pixbuf,
352                                     -1);
353
354                 valid = gtk_tree_model_iter_next (
355                         GTK_TREE_MODEL (ev_attachbar->priv->model),
356                         &iter);
357         }
358 }
359
360 static void
361 ev_sidebar_attachments_screen_changed (GtkWidget *widget,
362                                        GdkScreen *old_screen)
363 {
364         EvSidebarAttachments *ev_attachbar = EV_SIDEBAR_ATTACHMENTS (widget);
365         GdkScreen            *screen;
366
367         if (!ev_attachbar->priv->icon_theme)
368                 return;
369         
370         screen = gtk_widget_get_screen (widget);
371         if (screen == old_screen)
372                 return;
373
374         if (old_screen) {
375                 g_signal_handlers_disconnect_by_func (
376                         gtk_icon_theme_get_for_screen (old_screen),
377                         G_CALLBACK (ev_sidebar_attachments_update_icons),
378                         ev_attachbar);
379         }
380
381         ev_attachbar->priv->icon_theme = gtk_icon_theme_get_for_screen (screen);
382         g_signal_connect_swapped (ev_attachbar->priv->icon_theme,
383                                   "changed",
384                                   G_CALLBACK (ev_sidebar_attachments_update_icons),
385                                   (gpointer) ev_attachbar);
386
387         if (GTK_WIDGET_CLASS (ev_sidebar_attachments_parent_class)->screen_changed) {
388                 GTK_WIDGET_CLASS (ev_sidebar_attachments_parent_class)->screen_changed (widget, old_screen);
389         }
390 }
391
392 static void
393 ev_sidebar_attachments_drag_data_get (GtkWidget        *widget,
394                                       GdkDragContext   *drag_context,
395                                       GtkSelectionData *data,
396                                       guint             info,
397                                       guint             time,
398                                       gpointer          user_data)
399 {
400         EvSidebarAttachments *ev_attachbar = EV_SIDEBAR_ATTACHMENTS (user_data);
401         GString              *uri_list;
402         gchar                *uris = NULL;
403         GList                *selected = NULL, *l;
404
405         selected = gtk_icon_view_get_selected_items (GTK_ICON_VIEW (ev_attachbar->priv->icon_view));
406         if (!selected)
407                 return;
408
409         uri_list = g_string_new (NULL);
410         
411         for (l = selected; l && l->data; l = g_list_next (l)) {
412                 EvAttachment *attachment;
413                 GtkTreePath  *path;
414                 GtkTreeIter   iter;
415                 GFile        *file;
416                 gchar        *filename;
417                 GError       *error = NULL;
418                 
419                 path = (GtkTreePath *) l->data;
420
421                 gtk_tree_model_get_iter (GTK_TREE_MODEL (ev_attachbar->priv->model),
422                                          &iter, path);
423                 gtk_tree_model_get (GTK_TREE_MODEL (ev_attachbar->priv->model), &iter,
424                                     COLUMN_ATTACHMENT, &attachment,
425                                     -1);
426
427                 filename = g_build_filename (ev_tmp_dir (),
428                                              ev_attachment_get_name (attachment),
429                                              NULL);
430                 file = g_file_new_for_path (filename);
431                 g_free (filename);
432                 
433                 if (ev_attachment_save (attachment, file, &error)) {
434                         gchar *uri;
435
436                         uri = g_file_get_uri (file);
437                         g_string_append (uri_list, uri);
438                         g_string_append_c (uri_list, '\n');
439                         g_free (uri);
440                 }
441         
442                 if (error) {
443                         g_warning ("%s", error->message);
444                         g_error_free (error);
445                 }
446
447                 gtk_tree_path_free (path);
448                 g_object_unref (file);
449                 g_object_unref (attachment);
450         }
451
452         uris = g_string_free (uri_list, FALSE);
453
454         if (uris) {
455                 gtk_selection_data_set (data,
456                                         data->target,
457                                         8,
458                                         (guchar *)uris,
459                                         strlen (uris));
460         }
461
462         g_list_free (selected);
463 }
464
465 static void
466 ev_sidebar_attachments_get_property (GObject    *object,
467                                      guint       prop_id,
468                                      GValue     *value,
469                                      GParamSpec *pspec)
470 {
471         EvSidebarAttachments *ev_sidebar_attachments;
472   
473         ev_sidebar_attachments = EV_SIDEBAR_ATTACHMENTS (object);
474
475         switch (prop_id) {
476                 case PROP_WIDGET:
477                         g_value_set_object (value, ev_sidebar_attachments->priv->icon_view);
478                         break;
479                 default:
480                         G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
481                         break;
482         }
483 }
484
485 static void
486 ev_sidebar_attachments_destroy (GtkObject *object)
487 {
488         EvSidebarAttachments *ev_attachbar = EV_SIDEBAR_ATTACHMENTS (object);
489
490         if (ev_attachbar->priv->icon_theme) {
491                 g_signal_handlers_disconnect_by_func (
492                         ev_attachbar->priv->icon_theme, 
493                         G_CALLBACK (ev_sidebar_attachments_update_icons),
494                         ev_attachbar);
495                 ev_attachbar->priv->icon_theme = NULL;
496         }
497         
498         if (ev_attachbar->priv->model) {
499                 g_object_unref (ev_attachbar->priv->model);
500                 ev_attachbar->priv->model = NULL;
501         }
502
503         if (ev_attachbar->priv->icon_cache) {
504                 g_hash_table_destroy (ev_attachbar->priv->icon_cache);
505                 ev_attachbar->priv->icon_cache = NULL;
506         }
507
508         (* GTK_OBJECT_CLASS (ev_sidebar_attachments_parent_class)->destroy) (object);
509 }
510
511 static void
512 ev_sidebar_attachments_class_init (EvSidebarAttachmentsClass *ev_attachbar_class)
513 {
514         GObjectClass   *g_object_class;
515         GtkObjectClass *gtk_object_class;
516         GtkWidgetClass *gtk_widget_class;
517
518         g_object_class = G_OBJECT_CLASS (ev_attachbar_class);
519         gtk_object_class = GTK_OBJECT_CLASS (ev_attachbar_class);
520         gtk_widget_class = GTK_WIDGET_CLASS (ev_attachbar_class);
521
522         g_object_class->get_property = ev_sidebar_attachments_get_property;
523         gtk_object_class->destroy = ev_sidebar_attachments_destroy;
524         gtk_widget_class->popup_menu = ev_sidebar_attachments_popup_menu;
525         gtk_widget_class->screen_changed = ev_sidebar_attachments_screen_changed;
526
527         g_type_class_add_private (g_object_class, sizeof (EvSidebarAttachmentsPrivate));
528
529         /* Signals */
530         signals[SIGNAL_POPUP_MENU] =
531                 g_signal_new ("popup",
532                               G_TYPE_FROM_CLASS (g_object_class),
533                               G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
534                               G_STRUCT_OFFSET (EvSidebarAttachmentsClass, popup_menu),
535                               NULL, NULL,
536                               g_cclosure_marshal_VOID__POINTER,
537                               G_TYPE_NONE, 1,
538                               G_TYPE_POINTER);
539
540         g_object_class_override_property (g_object_class,
541                                           PROP_WIDGET,
542                                           "main-widget");
543 }
544
545 static void
546 ev_sidebar_attachments_init (EvSidebarAttachments *ev_attachbar)
547 {
548         GtkWidget *swindow;
549         
550         ev_attachbar->priv = EV_SIDEBAR_ATTACHMENTS_GET_PRIVATE (ev_attachbar);
551
552         swindow = gtk_scrolled_window_new (NULL, NULL);
553         gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (swindow),
554                                         GTK_POLICY_NEVER,
555                                         GTK_POLICY_AUTOMATIC);
556         gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (swindow),
557                                              GTK_SHADOW_IN);
558         /* Data Model */
559         ev_attachbar->priv->model = gtk_list_store_new (N_COLS,
560                                                         GDK_TYPE_PIXBUF, 
561                                                         G_TYPE_STRING,  
562                                                         G_TYPE_STRING,
563                                                         EV_TYPE_ATTACHMENT);
564
565         /* Icon View */
566         ev_attachbar->priv->icon_view =
567                 gtk_icon_view_new_with_model (GTK_TREE_MODEL (ev_attachbar->priv->model));
568         gtk_icon_view_set_selection_mode (GTK_ICON_VIEW (ev_attachbar->priv->icon_view),
569                                           GTK_SELECTION_MULTIPLE);
570         gtk_icon_view_set_columns (GTK_ICON_VIEW (ev_attachbar->priv->icon_view), -1);
571         g_object_set (G_OBJECT (ev_attachbar->priv->icon_view),
572                       "text-column", COLUMN_NAME,
573                       "pixbuf-column", COLUMN_ICON,
574                       NULL);
575         g_signal_connect_swapped (G_OBJECT (ev_attachbar->priv->icon_view),
576                                   "button-press-event",
577                                   G_CALLBACK (ev_sidebar_attachments_button_press),
578                                   (gpointer) ev_attachbar);
579
580         gtk_container_add (GTK_CONTAINER (swindow),
581                            ev_attachbar->priv->icon_view);
582
583         gtk_container_add (GTK_CONTAINER (ev_attachbar),
584                            swindow);
585         gtk_widget_show_all (GTK_WIDGET (ev_attachbar));
586
587         /* Icon Theme */
588         ev_attachbar->priv->icon_theme = NULL;
589
590         /* Icon Cache */
591         ev_attachbar->priv->icon_cache = g_hash_table_new_full (g_str_hash,
592                                                                 g_str_equal,
593                                                                 g_free,
594                                                                 g_object_unref);
595
596         /* Drag and Drop */
597         gtk_icon_view_enable_model_drag_source (
598                 GTK_ICON_VIEW (ev_attachbar->priv->icon_view),
599                 GDK_BUTTON1_MASK,
600                 drag_targets,
601                 G_N_ELEMENTS (drag_targets),
602                 GDK_ACTION_COPY);
603
604         g_signal_connect (G_OBJECT (ev_attachbar->priv->icon_view),
605                           "drag-data-get",
606                           G_CALLBACK (ev_sidebar_attachments_drag_data_get),
607                           (gpointer) ev_attachbar);     
608 }
609
610 GtkWidget *
611 ev_sidebar_attachments_new (void)
612 {
613         GtkWidget *ev_attachbar;
614
615         ev_attachbar = g_object_new (EV_TYPE_SIDEBAR_ATTACHMENTS, NULL);
616
617         return ev_attachbar;
618 }
619
620 static void
621 job_finished_callback (EvJobAttachments     *job,
622                        EvSidebarAttachments *ev_attachbar)
623 {
624         GList *l;
625         
626         for (l = job->attachments; l && l->data; l = g_list_next (l)) {
627                 EvAttachment *attachment;
628                 GtkTreeIter   iter;
629                 GdkPixbuf    *pixbuf = NULL;
630                 const gchar  *mime_type;
631
632                 attachment = EV_ATTACHMENT (l->data);
633
634                 mime_type = ev_attachment_get_mime_type (attachment);
635                 pixbuf = ev_sidebar_attachments_icon_cache_get (ev_attachbar,
636                                                                 mime_type);
637
638                 gtk_list_store_append (ev_attachbar->priv->model, &iter);
639                 gtk_list_store_set (ev_attachbar->priv->model, &iter,
640                                     COLUMN_NAME, ev_attachment_get_name (attachment),
641                                     COLUMN_ICON, pixbuf,
642                                     COLUMN_ATTACHMENT, attachment, 
643                                     -1);
644         }
645
646         g_object_unref (job);
647 }
648
649 static void
650 ev_sidebar_attachments_set_document (EvSidebarPage   *page,
651                                      EvDocument      *document)
652 {
653         EvSidebarAttachments *ev_attachbar = EV_SIDEBAR_ATTACHMENTS (page);
654         EvJob *job;
655         
656         if (!ev_document_has_attachments (document))
657                 return;
658
659         if (!ev_attachbar->priv->icon_theme) {
660                 GdkScreen *screen;
661
662                 screen = gtk_widget_get_screen (GTK_WIDGET (ev_attachbar));
663                 ev_attachbar->priv->icon_theme = gtk_icon_theme_get_for_screen (screen);
664                 g_signal_connect_swapped (G_OBJECT (ev_attachbar->priv->icon_theme),
665                                           "changed",
666                                           G_CALLBACK (ev_sidebar_attachments_update_icons),
667                                           (gpointer) ev_attachbar);
668         }
669                 
670         gtk_list_store_clear (ev_attachbar->priv->model);
671
672         job = ev_job_attachments_new (document);
673         g_signal_connect (job, "finished",
674                           G_CALLBACK (job_finished_callback),
675                           ev_attachbar);
676         g_signal_connect (job, "cancelled",
677                           G_CALLBACK (g_object_unref),
678                           NULL);
679         /* The priority doesn't matter for this job */
680         ev_job_scheduler_push_job (job, EV_JOB_PRIORITY_NONE);
681 }
682
683 static gboolean
684 ev_sidebar_attachments_support_document (EvSidebarPage   *sidebar_page,
685                                          EvDocument      *document)
686 {
687         return ev_document_has_attachments (document);
688 }
689
690 static const gchar*
691 ev_sidebar_attachments_get_label (EvSidebarPage *sidebar_page)
692 {
693         return _("Attachments");
694 }
695
696 static void
697 ev_sidebar_attachments_page_iface_init (EvSidebarPageIface *iface)
698 {
699         iface->support_document = ev_sidebar_attachments_support_document;
700         iface->set_document = ev_sidebar_attachments_set_document;
701         iface->get_label = ev_sidebar_attachments_get_label;
702 }
703