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