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