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