]> www.fi.muni.cz Git - evince.git/blob - shell/ev-sidebar-thumbnails.c
Refresh thumbnails when changing orientation. Not fully working yet
[evince.git] / shell / ev-sidebar-thumbnails.c
1 /* this file is part of evince, a gnome document viewer
2  *
3  *  Copyright (C) 2004 Red Hat, Inc.
4  *  Copyright (C) 2004, 2005 Anders Carlsson <andersca@gnome.org>
5  *
6  *  Authors:
7  *    Jonathan Blandford <jrb@alum.mit.edu>
8  *    Anders Carlsson <andersca@gnome.org>
9  *
10  * Evince is free software; you can redistribute it and/or modify it
11  * under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 2 of the License, or
13  * (at your option) any later version.
14  *
15  * Evince is distributed in the hope that it will be useful, but
16  * WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
18  * General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program; if not, write to the Free Software
22  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
23  */
24
25 #ifdef HAVE_CONFIG_H
26 #include "config.h"
27 #endif
28
29 #include <string.h>
30 #include <gtk/gtk.h>
31 #include <glib/gi18n.h>
32
33 #include "ev-sidebar-page.h"
34 #include "ev-sidebar-thumbnails.h"
35 #include "ev-document-thumbnails.h"
36 #include "ev-document-misc.h"
37 #include "ev-job-queue.h"
38 #include "ev-window.h"
39 #include "ev-utils.h"
40
41 #define THUMBNAIL_WIDTH 100
42
43 /* The IconView doesn't scale nearly as well as the TreeView, so we arbitrarily
44  * limit its use */
45 #define MAX_ICON_VIEW_PAGE_COUNT 1500
46
47
48 struct _EvSidebarThumbnailsPrivate {
49         GtkWidget *swindow;
50         GtkWidget *icon_view;
51         GtkWidget *tree_view;
52         GtkAdjustment *vadjustment;
53         GtkListStore *list_store;
54         GdkPixbuf *loading_icon;
55         EvDocument *document;
56         EvPageCache *page_cache;
57
58         gint n_pages, pages_done;
59
60         /* Visible pages */
61         gint start_page, end_page;
62 };
63
64 enum {
65         COLUMN_PAGE_STRING,
66         COLUMN_PIXBUF,
67         COLUMN_THUMBNAIL_SET,
68         COLUMN_JOB,
69         NUM_COLUMNS
70 };
71
72 enum {
73         PROP_0,
74         PROP_WIDGET,
75 };
76
77 static void         ev_sidebar_thumbnails_clear_model      (EvSidebarThumbnails *sidebar);
78 static gboolean     ev_sidebar_thumbnails_support_document (EvSidebarPage       *sidebar_page,
79                                                             EvDocument          *document);
80 static void         ev_sidebar_thumbnails_page_iface_init  (EvSidebarPageIface  *iface);
81 static void         ev_sidebar_thumbnails_set_document     (EvSidebarPage       *sidebar_page,
82                                                             EvDocument          *document);
83 static const gchar* ev_sidebar_thumbnails_get_label        (EvSidebarPage       *sidebar_page);
84 static void         thumbnail_job_completed_callback       (EvJobThumbnail      *job,
85                                                             EvSidebarThumbnails *sidebar_thumbnails);
86
87 G_DEFINE_TYPE_EXTENDED (EvSidebarThumbnails, 
88                         ev_sidebar_thumbnails, 
89                         GTK_TYPE_VBOX,
90                         0, 
91                         G_IMPLEMENT_INTERFACE (EV_TYPE_SIDEBAR_PAGE, 
92                                                ev_sidebar_thumbnails_page_iface_init))
93
94 #define EV_SIDEBAR_THUMBNAILS_GET_PRIVATE(object) \
95         (G_TYPE_INSTANCE_GET_PRIVATE ((object), EV_TYPE_SIDEBAR_THUMBNAILS, EvSidebarThumbnailsPrivate));
96
97
98 static void
99 ev_sidebar_thumbnails_dispose (GObject *object)
100 {
101         EvSidebarThumbnails *sidebar_thumbnails = EV_SIDEBAR_THUMBNAILS (object);
102         
103         ev_sidebar_thumbnails_clear_model (sidebar_thumbnails);
104         g_object_unref (sidebar_thumbnails->priv->loading_icon);
105         g_object_unref (sidebar_thumbnails->priv->list_store);
106
107         G_OBJECT_CLASS (ev_sidebar_thumbnails_parent_class)->dispose (object);
108 }
109
110 static void
111 ev_sidebar_thumbnails_get_property (GObject    *object,
112                                          guint       prop_id,
113                                          GValue     *value,
114                                          GParamSpec *pspec)
115 {
116         EvSidebarThumbnails *sidebar = EV_SIDEBAR_THUMBNAILS (object);
117
118         switch (prop_id)
119         {
120         case PROP_WIDGET:
121                 if (sidebar->priv->tree_view)
122                         g_value_set_object (value, sidebar->priv->tree_view);
123                 else
124                         g_value_set_object (value, sidebar->priv->icon_view);
125                 break;
126         default:
127                 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
128                 break;
129         }
130 }
131
132 static void
133 ev_sidebar_thumbnails_class_init (EvSidebarThumbnailsClass *ev_sidebar_thumbnails_class)
134 {
135         GObjectClass *g_object_class;
136         GtkObjectClass *gtk_object_class;
137
138         g_object_class = G_OBJECT_CLASS (ev_sidebar_thumbnails_class);
139         gtk_object_class = GTK_OBJECT_CLASS (ev_sidebar_thumbnails_class);
140
141         g_object_class->dispose = ev_sidebar_thumbnails_dispose;
142         g_object_class->get_property = ev_sidebar_thumbnails_get_property;
143
144         g_object_class_override_property (g_object_class,
145                                           PROP_WIDGET,
146                                           "main-widget");
147
148         g_type_class_add_private (g_object_class, sizeof (EvSidebarThumbnailsPrivate));
149 }
150
151 GtkWidget *
152 ev_sidebar_thumbnails_new (void)
153 {
154         GtkWidget *ev_sidebar_thumbnails;
155
156         ev_sidebar_thumbnails = g_object_new (EV_TYPE_SIDEBAR_THUMBNAILS, NULL);
157
158         return ev_sidebar_thumbnails;
159 }
160
161 static void
162 clear_range (EvSidebarThumbnails *sidebar_thumbnails,
163              gint                 start_page,
164              gint                 end_page)
165 {
166         EvSidebarThumbnailsPrivate *priv = sidebar_thumbnails->priv;
167         GtkTreePath *path;
168         GtkTreeIter iter;
169         gboolean result;
170
171         g_assert (start_page <= end_page);
172
173         path = gtk_tree_path_new_from_indices (start_page, -1);
174         for (result = gtk_tree_model_get_iter (GTK_TREE_MODEL (priv->list_store), &iter, path);
175              result && start_page <= end_page;
176              result = gtk_tree_model_iter_next (GTK_TREE_MODEL (priv->list_store), &iter), start_page ++) {
177                 EvJobThumbnail *job;
178
179                 gtk_tree_model_get (GTK_TREE_MODEL (priv->list_store),
180                                     &iter,
181                                     COLUMN_JOB, &job,
182                                     -1);
183
184                 if (job) {
185                         g_signal_handlers_disconnect_by_func (job, thumbnail_job_completed_callback, sidebar_thumbnails);
186                         ev_job_queue_remove_job (EV_JOB (job));
187                         g_object_unref (job);
188                 }
189
190                 gtk_list_store_set (priv->list_store, &iter,
191                                     COLUMN_JOB, NULL,
192                                     COLUMN_THUMBNAIL_SET, FALSE,
193                                     COLUMN_PIXBUF, priv->loading_icon,
194                                     -1);
195         }
196         gtk_tree_path_free (path);
197 }
198
199 static void
200 add_range (EvSidebarThumbnails *sidebar_thumbnails,
201            gint                 start_page,
202            gint                 end_page)
203 {
204         EvSidebarThumbnailsPrivate *priv = sidebar_thumbnails->priv;
205         GtkTreePath *path;
206         GtkTreeIter iter;
207         gboolean result;
208         gint page = start_page;
209
210         g_assert (start_page <= end_page);
211
212         path = gtk_tree_path_new_from_indices (start_page, -1);
213         for (result = gtk_tree_model_get_iter (GTK_TREE_MODEL (priv->list_store), &iter, path);
214              result && page <= end_page;
215              result = gtk_tree_model_iter_next (GTK_TREE_MODEL (priv->list_store), &iter), page ++) {
216                 EvJobThumbnail *job;
217                 gboolean thumbnail_set;
218
219                 gtk_tree_model_get (GTK_TREE_MODEL (priv->list_store), &iter,
220                                     COLUMN_JOB, &job,
221                                     COLUMN_THUMBNAIL_SET, &thumbnail_set,
222                                     -1);
223
224                 if (job == NULL && !thumbnail_set) {
225                         job = (EvJobThumbnail *)ev_job_thumbnail_new (priv->document, page, THUMBNAIL_WIDTH);
226                         ev_job_queue_add_job (EV_JOB (job), EV_JOB_PRIORITY_HIGH);
227                         g_object_set_data_full (G_OBJECT (job), "tree_iter",
228                                                 gtk_tree_iter_copy (&iter),
229                                                 (GDestroyNotify) gtk_tree_iter_free);
230                         g_signal_connect (job, "finished",
231                                           G_CALLBACK (thumbnail_job_completed_callback),
232                                           sidebar_thumbnails);
233                         gtk_list_store_set (priv->list_store, &iter,
234                                             COLUMN_JOB, job,
235                                             -1);
236                         /* The queue and the list own a ref to the job now */
237                         g_object_unref (job);
238                 } else if (job) {
239                         g_object_unref (job);
240                 }
241         }
242         gtk_tree_path_free (path);
243 }
244
245 /* This modifies start */
246 static void
247 update_visible_range (EvSidebarThumbnails *sidebar_thumbnails,
248                       gint                 start_page,
249                       gint                 end_page)
250 {
251         EvSidebarThumbnailsPrivate *priv = sidebar_thumbnails->priv;
252         int old_start_page, old_end_page;
253
254         old_start_page = priv->start_page;
255         old_end_page = priv->end_page;
256
257         if (start_page == old_start_page &&
258             end_page == old_end_page)
259                 return;
260
261         /* Clear the areas we no longer display */
262         if (old_start_page < start_page)
263                 clear_range (sidebar_thumbnails, old_start_page, MIN (start_page - 1, old_end_page));
264
265         if (old_end_page > end_page)
266                 clear_range (sidebar_thumbnails, MAX (end_page + 1, old_start_page), old_end_page);
267
268         add_range (sidebar_thumbnails, start_page, end_page);
269         
270         priv->start_page = start_page;
271         priv->end_page = end_page;
272 }
273
274 static void
275 adjustment_changed_cb (EvSidebarThumbnails *sidebar_thumbnails)
276 {
277         EvSidebarThumbnailsPrivate *priv = sidebar_thumbnails->priv;
278         GtkTreePath *path = NULL;
279         GtkTreePath *path2 = NULL;
280         gint wy1;
281         gint wy2;
282
283         if (priv->tree_view) {
284                 if (! GTK_WIDGET_REALIZED (priv->tree_view))
285                         return;
286
287                 gtk_tree_view_tree_to_widget_coords (GTK_TREE_VIEW (priv->tree_view),
288                                                      0, (int) priv->vadjustment->value,
289                                                      NULL, &wy1);
290                 gtk_tree_view_tree_to_widget_coords (GTK_TREE_VIEW (priv->tree_view),
291                                                      0, (int) (priv->vadjustment->value + priv->vadjustment->page_size),
292                                                      NULL, &wy2);
293                 gtk_tree_view_get_path_at_pos (GTK_TREE_VIEW (priv->tree_view),
294                                                1, wy1 + 1, &path,
295                                                NULL, NULL, NULL);
296                 gtk_tree_view_get_path_at_pos (GTK_TREE_VIEW (priv->tree_view),
297                                                1, wy2 -1, &path2,
298                                                NULL, NULL, NULL);
299         } else if (priv->icon_view) {
300 #ifdef HAVE_GTK_ICON_VIEW_GET_VISIBLE_RANGE
301                 if (! GTK_WIDGET_REALIZED (priv->icon_view))
302                         return;
303                 gtk_icon_view_get_visible_range (GTK_ICON_VIEW (priv->icon_view), &path, &path2);
304 #else
305                 g_assert_not_reached ();
306 #endif
307         } else {
308                 return;
309         }
310
311         if (path == NULL)
312                 path = gtk_tree_path_new_first ();
313         if (path2 == NULL)
314                 path2 = gtk_tree_path_new_from_indices (priv->n_pages,
315                                                         -1);
316         update_visible_range (sidebar_thumbnails,
317                               gtk_tree_path_get_indices (path)[0],
318                               gtk_tree_path_get_indices (path2)[0]);
319
320         gtk_tree_path_free (path);
321         gtk_tree_path_free (path2);
322 }
323
324 static void
325 ev_sidebar_thumbnails_fill_model (EvSidebarThumbnails *sidebar_thumbnails)
326 {
327         EvSidebarThumbnailsPrivate *priv = sidebar_thumbnails->priv;
328         GtkTreeIter iter;
329         int i;
330
331         for (i = 0; i < sidebar_thumbnails->priv->n_pages; i++) {
332                 gchar *page_label;
333                 gchar *page_string;
334
335                 page_label = ev_page_cache_get_page_label (priv->page_cache, i);
336                 page_string = g_markup_printf_escaped ("<i>%s</i>", page_label);
337
338                 gtk_list_store_append (priv->list_store, &iter);
339                 gtk_list_store_set (priv->list_store, &iter,
340                                     COLUMN_PAGE_STRING, page_string,
341                                     COLUMN_PIXBUF, priv->loading_icon,
342                                     COLUMN_THUMBNAIL_SET, FALSE,
343                                     -1);
344                 g_free (page_label);
345                 g_free (page_string);
346         }
347 }
348
349 void
350 ev_sidebar_thumbnails_refresh (EvSidebarThumbnails *sidebar_thumbnails)
351 {
352         ev_sidebar_thumbnails_clear_model (sidebar_thumbnails);
353         ev_sidebar_thumbnails_fill_model (sidebar_thumbnails);
354         adjustment_changed_cb (sidebar_thumbnails);
355 }
356
357 static void
358 ev_sidebar_tree_selection_changed (GtkTreeSelection *selection,
359                                    EvSidebarThumbnails *ev_sidebar_thumbnails)
360 {
361         EvSidebarThumbnailsPrivate *priv = ev_sidebar_thumbnails->priv;
362         GtkTreePath *path;
363         GtkTreeIter iter;
364         int page;
365
366         if (!gtk_tree_selection_get_selected (selection, NULL, &iter))
367                 return;
368
369         path = gtk_tree_model_get_path (GTK_TREE_MODEL (priv->list_store),
370                                         &iter);
371         page = gtk_tree_path_get_indices (path)[0];
372         gtk_tree_path_free (path);
373
374         ev_page_cache_set_current_page (priv->page_cache, page);
375 }
376
377 static void
378 ev_sidebar_icon_selection_changed (GtkIconView         *icon_view,
379                                    EvSidebarThumbnails *ev_sidebar_thumbnails)
380 {
381         EvSidebarThumbnailsPrivate *priv = ev_sidebar_thumbnails->priv;
382         GtkTreePath *path;
383         GList *selected;
384         int page;
385
386         selected = gtk_icon_view_get_selected_items (icon_view);
387         if (selected == NULL)
388                 return;
389
390         /* We don't handle or expect multiple selection. */
391         g_assert (selected->next == NULL);
392
393         path = selected->data;
394         page = gtk_tree_path_get_indices (path)[0];
395
396         gtk_tree_path_free (path);
397         g_list_free (selected);
398
399         ev_page_cache_set_current_page (priv->page_cache, page);
400 }
401
402 static void
403 ev_sidebar_init_tree_view (EvSidebarThumbnails *ev_sidebar_thumbnails)
404 {
405         EvSidebarThumbnailsPrivate *priv;
406         GtkTreeSelection *selection;
407         GtkCellRenderer *renderer;
408
409         priv = ev_sidebar_thumbnails->priv;
410         priv->tree_view = gtk_tree_view_new_with_model (GTK_TREE_MODEL (priv->list_store));
411
412         selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->tree_view));
413         g_signal_connect (selection, "changed",
414                           G_CALLBACK (ev_sidebar_tree_selection_changed), ev_sidebar_thumbnails);
415         gtk_tree_view_set_headers_visible (GTK_TREE_VIEW (priv->tree_view), FALSE);
416         renderer = g_object_new (GTK_TYPE_CELL_RENDERER_PIXBUF,
417                                  "xpad", 2,
418                                  "ypad", 2,
419                                  NULL);
420         gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (priv->tree_view), -1,
421                                                      NULL, renderer,
422                                                      "pixbuf", 1,
423                                                      NULL);
424         gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (priv->tree_view), -1,
425                                                      NULL, gtk_cell_renderer_text_new (),
426                                                      "markup", 0, NULL);
427         gtk_container_add (GTK_CONTAINER (priv->swindow), priv->tree_view);
428         gtk_widget_show (priv->tree_view);
429 }
430
431 static void
432 ev_sidebar_init_icon_view (EvSidebarThumbnails *ev_sidebar_thumbnails)
433 {
434         EvSidebarThumbnailsPrivate *priv;
435
436         priv = ev_sidebar_thumbnails->priv;
437
438         priv->icon_view = gtk_icon_view_new_with_model (GTK_TREE_MODEL (priv->list_store));
439         gtk_icon_view_set_markup_column (GTK_ICON_VIEW (priv->icon_view), 0);
440         gtk_icon_view_set_pixbuf_column (GTK_ICON_VIEW (priv->icon_view), 1);
441         g_signal_connect (priv->icon_view, "selection-changed",
442                           G_CALLBACK (ev_sidebar_icon_selection_changed), ev_sidebar_thumbnails);
443
444         gtk_container_add (GTK_CONTAINER (priv->swindow), priv->icon_view);
445         gtk_widget_show (priv->icon_view);
446 }
447
448 static gboolean
449 ev_sidebar_thumbnails_use_icon_view (EvSidebarThumbnails *sidebar_thumbnails)
450 {
451 #ifdef HAVE_GTK_ICON_VIEW_GET_VISIBLE_RANGE
452         EvSidebarThumbnailsPrivate *priv = sidebar_thumbnails->priv;
453         if (ev_page_cache_get_n_pages (priv->page_cache) > MAX_ICON_VIEW_PAGE_COUNT)
454                 return FALSE;
455         return TRUE;
456 #else
457         return FALSE;
458 #endif
459 }
460
461 static void
462 ev_sidebar_thumbnails_init (EvSidebarThumbnails *ev_sidebar_thumbnails)
463 {
464         EvSidebarThumbnailsPrivate *priv;
465
466         priv = ev_sidebar_thumbnails->priv = EV_SIDEBAR_THUMBNAILS_GET_PRIVATE (ev_sidebar_thumbnails);
467
468         priv->list_store = gtk_list_store_new (NUM_COLUMNS,
469                                                G_TYPE_STRING,
470                                                GDK_TYPE_PIXBUF,
471                                                G_TYPE_BOOLEAN,
472                                                EV_TYPE_JOB_THUMBNAIL);
473
474         priv->swindow = gtk_scrolled_window_new (NULL, NULL);
475         gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (priv->swindow),
476                                         GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
477         gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (priv->swindow),
478                                              GTK_SHADOW_IN);
479         priv->vadjustment = gtk_scrolled_window_get_vadjustment (GTK_SCROLLED_WINDOW (priv->swindow));
480         g_signal_connect_data (G_OBJECT (priv->vadjustment), "value-changed",
481                                G_CALLBACK (adjustment_changed_cb),
482                                ev_sidebar_thumbnails, NULL,
483                                G_CONNECT_SWAPPED | G_CONNECT_AFTER);
484         g_signal_connect_swapped (G_OBJECT (priv->swindow), "size-allocate",
485                                   G_CALLBACK (adjustment_changed_cb),
486                                   ev_sidebar_thumbnails);
487         gtk_box_pack_start (GTK_BOX (ev_sidebar_thumbnails), priv->swindow, TRUE, TRUE, 0);
488
489         /* Put it all together */
490         gtk_widget_show_all (priv->swindow);
491 }
492
493 static void
494 page_changed_cb (EvPageCache         *page_cache,
495                  int                  page,
496                  EvSidebarThumbnails *sidebar)
497 {
498         GtkTreeView *tree_view;
499         GtkTreePath *path;
500
501         path = gtk_tree_path_new_from_indices (page, -1);
502
503         if (sidebar->priv->tree_view) {
504                 tree_view = GTK_TREE_VIEW (sidebar->priv->tree_view);
505                 gtk_tree_view_set_cursor (tree_view, path, NULL, FALSE);
506                 gtk_tree_view_scroll_to_cell (tree_view, path, NULL, FALSE, 0.0, 0.0);
507         } else if (sidebar->priv->icon_view) {
508                 /* Guard against gtk-2.6 */
509 #ifdef HAVE_GTK_ICON_VIEW_GET_VISIBLE_RANGE 
510                 gtk_icon_view_select_path (GTK_ICON_VIEW (sidebar->priv->icon_view), path);
511                 gtk_icon_view_set_cursor (GTK_ICON_VIEW (sidebar->priv->icon_view), path, NULL, FALSE);
512 #endif
513         }
514
515         gtk_tree_path_free (path);
516 }
517
518 static void
519 thumbnail_job_completed_callback (EvJobThumbnail      *job,
520                                   EvSidebarThumbnails *sidebar_thumbnails)
521 {
522         EvSidebarThumbnailsPrivate *priv = sidebar_thumbnails->priv;
523         GtkTreeIter *iter;
524
525         iter = (GtkTreeIter *) g_object_get_data (G_OBJECT (job), "tree_iter");
526         gtk_list_store_set (priv->list_store,
527                             iter,
528                             COLUMN_PIXBUF, job->thumbnail,
529                             COLUMN_THUMBNAIL_SET, TRUE,
530                             COLUMN_JOB, NULL,
531                             -1);
532 }
533
534 static void
535 ev_sidebar_thumbnails_set_document (EvSidebarPage       *sidebar_page,
536                                     EvDocument          *document)
537 {
538         EvSidebarThumbnails *sidebar_thumbnails = EV_SIDEBAR_THUMBNAILS (sidebar_page);
539         gint width = THUMBNAIL_WIDTH;
540         gint height = THUMBNAIL_WIDTH;
541
542         EvSidebarThumbnailsPrivate *priv = sidebar_thumbnails->priv;
543
544         g_return_if_fail (EV_IS_DOCUMENT_THUMBNAILS (document));
545
546         priv->page_cache = ev_page_cache_get (document);
547         priv->document = document;
548         priv->n_pages = ev_page_cache_get_n_pages (priv->page_cache);
549
550         /* We get the dimensions of the first doc so that we can make a blank
551          * icon.  */
552         ev_document_doc_mutex_lock ();
553         ev_document_thumbnails_get_dimensions (EV_DOCUMENT_THUMBNAILS (priv->document),
554                                                0, THUMBNAIL_WIDTH, &width, &height);
555         ev_document_doc_mutex_unlock ();
556
557         if (priv->loading_icon)
558                 g_object_unref (priv->loading_icon);
559         priv->loading_icon = ev_document_misc_get_thumbnail_frame (width, height, NULL);
560
561         ev_sidebar_thumbnails_clear_model (sidebar_thumbnails);
562         ev_sidebar_thumbnails_fill_model (sidebar_thumbnails);
563
564         /* Create the view widget, and remove the old one, if needed */
565         if (ev_sidebar_thumbnails_use_icon_view (sidebar_thumbnails)) {
566                 if (priv->tree_view) {
567                         gtk_container_remove (GTK_CONTAINER (priv->swindow), priv->tree_view);
568                         priv->tree_view = NULL;
569                 }
570
571                 if (! priv->icon_view) {
572                         ev_sidebar_init_icon_view (sidebar_thumbnails);
573                         g_object_notify (G_OBJECT (sidebar_thumbnails), "main_widget");
574                 }
575         } else {
576                 if (priv->icon_view) {
577                         gtk_container_remove (GTK_CONTAINER (priv->swindow), priv->icon_view);
578                         priv->icon_view = NULL;
579                 }
580
581                 if (! priv->tree_view) {
582                         ev_sidebar_init_tree_view (sidebar_thumbnails);
583                         g_object_notify (G_OBJECT (sidebar_thumbnails), "main_widget");
584                 }
585         }
586
587         /* Connect to the signal and trigger a fake callback */
588         g_signal_connect (priv->page_cache, "page-changed", G_CALLBACK (page_changed_cb), sidebar_thumbnails);
589         adjustment_changed_cb (sidebar_thumbnails);
590 }
591
592 static gboolean
593 ev_sidebar_thumbnails_clear_job (GtkTreeModel *model,                                             
594                                  GtkTreePath *path,                                                                                      
595                                  GtkTreeIter *iter,                                                                                                                                   
596                                  gpointer data)
597 {
598     EvJob *job;
599     
600     gtk_tree_model_get (model, iter, COLUMN_JOB, &job, -1);
601     
602     if (job != NULL) {
603         ev_job_queue_remove_job (job);
604         g_signal_handlers_disconnect_by_func (job, thumbnail_job_completed_callback, data);
605         g_object_unref (job);
606     }
607
608     return FALSE;    
609 }
610
611 static void 
612 ev_sidebar_thumbnails_clear_model (EvSidebarThumbnails *sidebar_thumbnails)
613 {
614     EvSidebarThumbnailsPrivate *priv = sidebar_thumbnails->priv;
615     
616     gtk_tree_model_foreach (GTK_TREE_MODEL (priv->list_store), ev_sidebar_thumbnails_clear_job, sidebar_thumbnails);
617     gtk_list_store_clear (priv->list_store);
618 }
619
620 static gboolean
621 ev_sidebar_thumbnails_support_document (EvSidebarPage   *sidebar_page,
622                                         EvDocument *document)
623 {
624         return (EV_IS_DOCUMENT_THUMBNAILS (document) &&
625                     (ev_document_get_n_pages (document) > 1));
626 }
627
628 static const gchar*
629 ev_sidebar_thumbnails_get_label (EvSidebarPage *sidebar_page)
630 {
631     return _("Thumbnails");
632 }
633
634 static void
635 ev_sidebar_thumbnails_page_iface_init (EvSidebarPageIface *iface)
636 {
637         iface->support_document = ev_sidebar_thumbnails_support_document;
638         iface->set_document = ev_sidebar_thumbnails_set_document;
639         iface->get_label = ev_sidebar_thumbnails_get_label;
640 }
641