1 /* this file is part of evince, a gnome document viewer
3 * Copyright (C) 2004 Red Hat, Inc.
4 * Copyright (C) 2004, 2005 Anders Carlsson <andersca@gnome.org>
7 * Jonathan Blandford <jrb@alum.mit.edu>
8 * Anders Carlsson <andersca@gnome.org>
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.
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.
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.
31 #include <glib/gi18n.h>
34 #include "ev-document-misc.h"
35 #include "ev-document-thumbnails.h"
36 #include "ev-job-scheduler.h"
37 #include "ev-sidebar-page.h"
38 #include "ev-sidebar-thumbnails.h"
40 #include "ev-window.h"
42 #define THUMBNAIL_WIDTH 100
44 /* The IconView doesn't scale nearly as well as the TreeView, so we arbitrarily
46 #define MAX_ICON_VIEW_PAGE_COUNT 1500
48 typedef struct _EvThumbsSize
54 typedef struct _EvThumbsSizeCache {
61 struct _EvSidebarThumbnailsPrivate {
65 GtkAdjustment *vadjustment;
66 GtkListStore *list_store;
67 GHashTable *loading_icons;
69 EvDocumentModel *model;
70 EvThumbsSizeCache *size_cache;
72 gint n_pages, pages_done;
77 gint start_page, end_page;
93 static void ev_sidebar_thumbnails_clear_model (EvSidebarThumbnails *sidebar);
94 static gboolean ev_sidebar_thumbnails_support_document (EvSidebarPage *sidebar_page,
95 EvDocument *document);
96 static void ev_sidebar_thumbnails_page_iface_init (EvSidebarPageIface *iface);
97 static const gchar* ev_sidebar_thumbnails_get_label (EvSidebarPage *sidebar_page);
98 static void thumbnail_job_completed_callback (EvJobThumbnail *job,
99 EvSidebarThumbnails *sidebar_thumbnails);
100 static void adjustment_changed_cb (EvSidebarThumbnails *sidebar_thumbnails);
102 G_DEFINE_TYPE_EXTENDED (EvSidebarThumbnails,
103 ev_sidebar_thumbnails,
106 G_IMPLEMENT_INTERFACE (EV_TYPE_SIDEBAR_PAGE,
107 ev_sidebar_thumbnails_page_iface_init))
109 #define EV_SIDEBAR_THUMBNAILS_GET_PRIVATE(object) \
110 (G_TYPE_INSTANCE_GET_PRIVATE ((object), EV_TYPE_SIDEBAR_THUMBNAILS, EvSidebarThumbnailsPrivate));
112 /* Thumbnails dimensions cache */
113 #define EV_THUMBNAILS_SIZE_CACHE_KEY "ev-thumbnails-size-cache"
115 static EvThumbsSizeCache *
116 ev_thumbnails_size_cache_new (EvDocument *document)
118 EvThumbsSizeCache *cache;
119 EvRenderContext *rc = NULL;
121 EvThumbsSize *thumb_size;
123 cache = g_new0 (EvThumbsSizeCache, 1);
125 n_pages = ev_document_get_n_pages (document);
127 /* Assume all pages are the same size until proven otherwise */
128 cache->uniform = TRUE;
130 for (i = 0; i < n_pages; i++) {
132 gdouble page_width, page_height;
133 gint thumb_width = 0;
134 gint thumb_height = 0;
136 page = ev_document_get_page (document, i);
138 ev_document_get_page_size (document, i, &page_width, &page_height);
141 rc = ev_render_context_new (page, 0, (gdouble)THUMBNAIL_WIDTH / page_width);
143 ev_render_context_set_page (rc, page);
144 ev_render_context_set_scale (rc, (gdouble)THUMBNAIL_WIDTH / page_width);
147 ev_document_thumbnails_get_dimensions (EV_DOCUMENT_THUMBNAILS (document),
148 rc, &thumb_width, &thumb_height);
151 cache->uniform_width = thumb_width;
152 cache->uniform_height = thumb_height;
153 } else if (cache->uniform &&
154 (cache->uniform_width != thumb_width ||
155 cache->uniform_height != thumb_height)) {
156 /* It's a different thumbnail size. Backfill the array. */
159 cache->sizes = g_new0 (EvThumbsSize, n_pages);
161 for (j = 0; j < i; j++) {
162 thumb_size = &(cache->sizes[j]);
163 thumb_size->width = cache->uniform_width;
164 thumb_size->height = cache->uniform_height;
166 cache->uniform = FALSE;
169 if (! cache->uniform) {
170 thumb_size = &(cache->sizes[i]);
172 thumb_size->width = thumb_width;
173 thumb_size->height = thumb_height;
176 g_object_unref (page);
187 ev_thumbnails_size_cache_get_size (EvThumbsSizeCache *cache,
195 if (cache->uniform) {
196 w = cache->uniform_width;
197 h = cache->uniform_height;
199 EvThumbsSize *thumb_size;
201 thumb_size = &(cache->sizes[page]);
203 w = thumb_size->width;
204 h = thumb_size->height;
207 if (rotation == 0 || rotation == 180) {
208 if (width) *width = w;
209 if (height) *height = h;
211 if (width) *width = h;
212 if (height) *height = w;
217 ev_thumbnails_size_cache_free (EvThumbsSizeCache *cache)
220 g_free (cache->sizes);
227 static EvThumbsSizeCache *
228 ev_thumbnails_size_cache_get (EvDocument *document)
230 EvThumbsSizeCache *cache;
232 cache = g_object_get_data (G_OBJECT (document), EV_THUMBNAILS_SIZE_CACHE_KEY);
234 cache = ev_thumbnails_size_cache_new (document);
235 g_object_set_data_full (G_OBJECT (document),
236 EV_THUMBNAILS_SIZE_CACHE_KEY,
238 (GDestroyNotify)ev_thumbnails_size_cache_free);
246 ev_sidebar_thumbnails_dispose (GObject *object)
248 EvSidebarThumbnails *sidebar_thumbnails = EV_SIDEBAR_THUMBNAILS (object);
250 if (sidebar_thumbnails->priv->loading_icons) {
251 g_hash_table_destroy (sidebar_thumbnails->priv->loading_icons);
252 sidebar_thumbnails->priv->loading_icons = NULL;
255 if (sidebar_thumbnails->priv->list_store) {
256 ev_sidebar_thumbnails_clear_model (sidebar_thumbnails);
257 g_object_unref (sidebar_thumbnails->priv->list_store);
258 sidebar_thumbnails->priv->list_store = NULL;
261 G_OBJECT_CLASS (ev_sidebar_thumbnails_parent_class)->dispose (object);
265 ev_sidebar_thumbnails_get_property (GObject *object,
270 EvSidebarThumbnails *sidebar = EV_SIDEBAR_THUMBNAILS (object);
274 if (sidebar->priv->tree_view)
275 g_value_set_object (value, sidebar->priv->tree_view);
277 g_value_set_object (value, sidebar->priv->icon_view);
280 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
286 ev_sidebar_thumbnails_map (GtkWidget *widget)
288 EvSidebarThumbnails *sidebar;
290 sidebar = EV_SIDEBAR_THUMBNAILS (widget);
292 GTK_WIDGET_CLASS (ev_sidebar_thumbnails_parent_class)->map (widget);
294 adjustment_changed_cb (sidebar);
298 ev_sidebar_thumbnails_class_init (EvSidebarThumbnailsClass *ev_sidebar_thumbnails_class)
300 GObjectClass *g_object_class;
301 GtkObjectClass *gtk_object_class;
302 GtkWidgetClass *widget_class;
304 g_object_class = G_OBJECT_CLASS (ev_sidebar_thumbnails_class);
305 gtk_object_class = GTK_OBJECT_CLASS (ev_sidebar_thumbnails_class);
306 widget_class = GTK_WIDGET_CLASS (ev_sidebar_thumbnails_class);
308 g_object_class->dispose = ev_sidebar_thumbnails_dispose;
309 g_object_class->get_property = ev_sidebar_thumbnails_get_property;
310 widget_class->map = ev_sidebar_thumbnails_map;
312 g_object_class_override_property (g_object_class,
316 g_type_class_add_private (g_object_class, sizeof (EvSidebarThumbnailsPrivate));
320 ev_sidebar_thumbnails_new (void)
322 GtkWidget *ev_sidebar_thumbnails;
324 ev_sidebar_thumbnails = g_object_new (EV_TYPE_SIDEBAR_THUMBNAILS, NULL);
326 return ev_sidebar_thumbnails;
330 ev_sidebar_thumbnails_get_loading_icon (EvSidebarThumbnails *sidebar_thumbnails,
337 key = g_strdup_printf ("%dx%d", width, height);
338 icon = g_hash_table_lookup (sidebar_thumbnails->priv->loading_icons, key);
340 icon = ev_document_misc_get_thumbnail_frame (width, height, NULL);
341 g_hash_table_insert (sidebar_thumbnails->priv->loading_icons,
351 clear_range (EvSidebarThumbnails *sidebar_thumbnails,
355 EvSidebarThumbnailsPrivate *priv = sidebar_thumbnails->priv;
359 gint prev_width = -1;
360 gint prev_height = -1;
362 g_assert (start_page <= end_page);
364 path = gtk_tree_path_new_from_indices (start_page, -1);
365 for (result = gtk_tree_model_get_iter (GTK_TREE_MODEL (priv->list_store), &iter, path);
366 result && start_page <= end_page;
367 result = gtk_tree_model_iter_next (GTK_TREE_MODEL (priv->list_store), &iter), start_page ++) {
369 GdkPixbuf *loading_icon = NULL;
372 gtk_tree_model_get (GTK_TREE_MODEL (priv->list_store),
378 g_signal_handlers_disconnect_by_func (job, thumbnail_job_completed_callback, sidebar_thumbnails);
379 ev_job_cancel (EV_JOB (job));
380 g_object_unref (job);
383 ev_thumbnails_size_cache_get_size (priv->size_cache, start_page,
386 if (!loading_icon || (width != prev_width && height != prev_height)) {
388 ev_sidebar_thumbnails_get_loading_icon (sidebar_thumbnails,
393 prev_height = height;
395 gtk_list_store_set (priv->list_store, &iter,
397 COLUMN_THUMBNAIL_SET, FALSE,
398 COLUMN_PIXBUF, loading_icon,
401 gtk_tree_path_free (path);
405 get_scale_for_page (EvSidebarThumbnails *sidebar_thumbnails,
408 EvSidebarThumbnailsPrivate *priv = sidebar_thumbnails->priv;
411 ev_document_get_page_size (priv->document, page, &width, NULL);
413 return (gdouble)THUMBNAIL_WIDTH / width;
417 add_range (EvSidebarThumbnails *sidebar_thumbnails,
421 EvSidebarThumbnailsPrivate *priv = sidebar_thumbnails->priv;
425 gint page = start_page;
427 g_assert (start_page <= end_page);
429 path = gtk_tree_path_new_from_indices (start_page, -1);
430 for (result = gtk_tree_model_get_iter (GTK_TREE_MODEL (priv->list_store), &iter, path);
431 result && page <= end_page;
432 result = gtk_tree_model_iter_next (GTK_TREE_MODEL (priv->list_store), &iter), page ++) {
434 gboolean thumbnail_set;
436 gtk_tree_model_get (GTK_TREE_MODEL (priv->list_store), &iter,
438 COLUMN_THUMBNAIL_SET, &thumbnail_set,
441 if (job == NULL && !thumbnail_set) {
442 job = ev_job_thumbnail_new (priv->document,
443 page, priv->rotation,
444 get_scale_for_page (sidebar_thumbnails, page));
445 ev_job_scheduler_push_job (EV_JOB (job), EV_JOB_PRIORITY_HIGH);
447 g_object_set_data_full (G_OBJECT (job), "tree_iter",
448 gtk_tree_iter_copy (&iter),
449 (GDestroyNotify) gtk_tree_iter_free);
450 g_signal_connect (job, "finished",
451 G_CALLBACK (thumbnail_job_completed_callback),
453 gtk_list_store_set (priv->list_store, &iter,
457 /* The queue and the list own a ref to the job now */
458 g_object_unref (job);
460 g_object_unref (job);
463 gtk_tree_path_free (path);
466 /* This modifies start */
468 update_visible_range (EvSidebarThumbnails *sidebar_thumbnails,
472 EvSidebarThumbnailsPrivate *priv = sidebar_thumbnails->priv;
473 int old_start_page, old_end_page;
475 old_start_page = priv->start_page;
476 old_end_page = priv->end_page;
478 if (start_page == old_start_page &&
479 end_page == old_end_page)
482 /* Clear the areas we no longer display */
483 if (old_start_page >= 0 && old_start_page < start_page)
484 clear_range (sidebar_thumbnails, old_start_page, MIN (start_page - 1, old_end_page));
486 if (old_end_page > 0 && old_end_page > end_page)
487 clear_range (sidebar_thumbnails, MAX (end_page + 1, old_start_page), old_end_page);
489 add_range (sidebar_thumbnails, start_page, end_page);
491 priv->start_page = start_page;
492 priv->end_page = end_page;
496 adjustment_changed_cb (EvSidebarThumbnails *sidebar_thumbnails)
498 EvSidebarThumbnailsPrivate *priv = sidebar_thumbnails->priv;
499 GtkTreePath *path = NULL;
500 GtkTreePath *path2 = NULL;
504 /* Widget is not currently visible */
505 if (!GTK_WIDGET_MAPPED (sidebar_thumbnails))
508 if (priv->vadjustment->page_size == 0)
511 if (priv->tree_view) {
512 if (! GTK_WIDGET_REALIZED (priv->tree_view))
515 gtk_tree_view_convert_tree_to_bin_window_coords (GTK_TREE_VIEW (priv->tree_view),
516 0, (int) priv->vadjustment->value,
518 gtk_tree_view_convert_tree_to_bin_window_coords (GTK_TREE_VIEW (priv->tree_view),
519 0, (int) (priv->vadjustment->value + priv->vadjustment->page_size),
521 gtk_tree_view_get_path_at_pos (GTK_TREE_VIEW (priv->tree_view),
524 gtk_tree_view_get_path_at_pos (GTK_TREE_VIEW (priv->tree_view),
527 } else if (priv->icon_view) {
528 if (! GTK_WIDGET_REALIZED (priv->icon_view))
530 if (! gtk_icon_view_get_visible_range (GTK_ICON_VIEW (priv->icon_view), &path, &path2))
537 update_visible_range (sidebar_thumbnails,
538 gtk_tree_path_get_indices (path)[0],
539 gtk_tree_path_get_indices (path2)[0]);
542 gtk_tree_path_free (path);
543 gtk_tree_path_free (path2);
547 ev_sidebar_thumbnails_fill_model (EvSidebarThumbnails *sidebar_thumbnails)
549 EvSidebarThumbnailsPrivate *priv = sidebar_thumbnails->priv;
552 gint prev_width = -1;
553 gint prev_height = -1;
555 for (i = 0; i < sidebar_thumbnails->priv->n_pages; i++) {
558 GdkPixbuf *loading_icon = NULL;
561 page_label = ev_document_get_page_label (priv->document, i);
562 page_string = g_markup_printf_escaped ("<i>%s</i>", page_label);
563 ev_thumbnails_size_cache_get_size (sidebar_thumbnails->priv->size_cache, i,
564 sidebar_thumbnails->priv->rotation,
566 if (!loading_icon || (width != prev_width && height != prev_height)) {
568 ev_sidebar_thumbnails_get_loading_icon (sidebar_thumbnails,
573 prev_height = height;
575 gtk_list_store_append (priv->list_store, &iter);
576 gtk_list_store_set (priv->list_store, &iter,
577 COLUMN_PAGE_STRING, page_string,
578 COLUMN_PIXBUF, loading_icon,
579 COLUMN_THUMBNAIL_SET, FALSE,
582 g_free (page_string);
587 ev_sidebar_tree_selection_changed (GtkTreeSelection *selection,
588 EvSidebarThumbnails *ev_sidebar_thumbnails)
590 EvSidebarThumbnailsPrivate *priv = ev_sidebar_thumbnails->priv;
595 if (!gtk_tree_selection_get_selected (selection, NULL, &iter))
598 path = gtk_tree_model_get_path (GTK_TREE_MODEL (priv->list_store),
600 page = gtk_tree_path_get_indices (path)[0];
601 gtk_tree_path_free (path);
603 ev_document_model_set_page (priv->model, page);
607 ev_sidebar_icon_selection_changed (GtkIconView *icon_view,
608 EvSidebarThumbnails *ev_sidebar_thumbnails)
610 EvSidebarThumbnailsPrivate *priv = ev_sidebar_thumbnails->priv;
615 selected = gtk_icon_view_get_selected_items (icon_view);
616 if (selected == NULL)
619 /* We don't handle or expect multiple selection. */
620 g_assert (selected->next == NULL);
622 path = selected->data;
623 page = gtk_tree_path_get_indices (path)[0];
625 gtk_tree_path_free (path);
626 g_list_free (selected);
628 ev_document_model_set_page (priv->model, page);
632 ev_sidebar_init_tree_view (EvSidebarThumbnails *ev_sidebar_thumbnails)
634 EvSidebarThumbnailsPrivate *priv;
635 GtkTreeSelection *selection;
636 GtkCellRenderer *renderer;
638 priv = ev_sidebar_thumbnails->priv;
639 priv->tree_view = gtk_tree_view_new_with_model (GTK_TREE_MODEL (priv->list_store));
641 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->tree_view));
642 g_signal_connect (selection, "changed",
643 G_CALLBACK (ev_sidebar_tree_selection_changed), ev_sidebar_thumbnails);
644 gtk_tree_view_set_headers_visible (GTK_TREE_VIEW (priv->tree_view), FALSE);
645 renderer = g_object_new (GTK_TYPE_CELL_RENDERER_PIXBUF,
649 gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (priv->tree_view), -1,
653 gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (priv->tree_view), -1,
654 NULL, gtk_cell_renderer_text_new (),
656 gtk_container_add (GTK_CONTAINER (priv->swindow), priv->tree_view);
657 gtk_widget_show (priv->tree_view);
661 ev_sidebar_init_icon_view (EvSidebarThumbnails *ev_sidebar_thumbnails)
663 EvSidebarThumbnailsPrivate *priv;
665 priv = ev_sidebar_thumbnails->priv;
667 priv->icon_view = gtk_icon_view_new_with_model (GTK_TREE_MODEL (priv->list_store));
668 gtk_icon_view_set_markup_column (GTK_ICON_VIEW (priv->icon_view), 0);
669 gtk_icon_view_set_pixbuf_column (GTK_ICON_VIEW (priv->icon_view), 1);
670 g_signal_connect (priv->icon_view, "selection-changed",
671 G_CALLBACK (ev_sidebar_icon_selection_changed), ev_sidebar_thumbnails);
673 gtk_container_add (GTK_CONTAINER (priv->swindow), priv->icon_view);
674 gtk_widget_show (priv->icon_view);
678 ev_sidebar_thumbnails_use_icon_view (EvSidebarThumbnails *sidebar_thumbnails)
680 EvSidebarThumbnailsPrivate *priv = sidebar_thumbnails->priv;
682 return (ev_document_get_n_pages (priv->document) <= MAX_ICON_VIEW_PAGE_COUNT);
686 ev_sidebar_thumbnails_init (EvSidebarThumbnails *ev_sidebar_thumbnails)
688 EvSidebarThumbnailsPrivate *priv;
690 priv = ev_sidebar_thumbnails->priv = EV_SIDEBAR_THUMBNAILS_GET_PRIVATE (ev_sidebar_thumbnails);
692 priv->list_store = gtk_list_store_new (NUM_COLUMNS,
696 EV_TYPE_JOB_THUMBNAIL);
698 priv->swindow = gtk_scrolled_window_new (NULL, NULL);
700 /* We actually don't want GTK_POLICY_AUTOMATIC for horizontal scrollbar here
701 * it's just a workaround for bug #449462
703 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (priv->swindow),
704 GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
705 gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (priv->swindow),
707 priv->vadjustment = gtk_scrolled_window_get_vadjustment (GTK_SCROLLED_WINDOW (priv->swindow));
708 g_signal_connect_data (priv->vadjustment, "value-changed",
709 G_CALLBACK (adjustment_changed_cb),
710 ev_sidebar_thumbnails, NULL,
711 G_CONNECT_SWAPPED | G_CONNECT_AFTER);
712 g_signal_connect_swapped (priv->swindow, "size-allocate",
713 G_CALLBACK (adjustment_changed_cb),
714 ev_sidebar_thumbnails);
715 gtk_box_pack_start (GTK_BOX (ev_sidebar_thumbnails), priv->swindow, TRUE, TRUE, 0);
717 /* Put it all together */
718 gtk_widget_show_all (priv->swindow);
722 ev_sidebar_thumbnails_set_current_page (EvSidebarThumbnails *sidebar,
725 GtkTreeView *tree_view;
728 path = gtk_tree_path_new_from_indices (page, -1);
730 if (sidebar->priv->tree_view) {
731 tree_view = GTK_TREE_VIEW (sidebar->priv->tree_view);
732 gtk_tree_view_set_cursor (tree_view, path, NULL, FALSE);
733 gtk_tree_view_scroll_to_cell (tree_view, path, NULL, FALSE, 0.0, 0.0);
734 } else if (sidebar->priv->icon_view) {
736 g_signal_handlers_block_by_func
737 (sidebar->priv->icon_view,
738 G_CALLBACK (ev_sidebar_icon_selection_changed), sidebar);
740 gtk_icon_view_select_path (GTK_ICON_VIEW (sidebar->priv->icon_view), path);
742 g_signal_handlers_unblock_by_func
743 (sidebar->priv->icon_view,
744 G_CALLBACK (ev_sidebar_icon_selection_changed), sidebar);
746 gtk_icon_view_set_cursor (GTK_ICON_VIEW (sidebar->priv->icon_view), path, NULL, FALSE);
749 gtk_tree_path_free (path);
753 page_changed_cb (EvSidebarThumbnails *sidebar,
757 ev_sidebar_thumbnails_set_current_page (sidebar, new_page);
761 refresh (EvSidebarThumbnails *sidebar_thumbnails)
763 adjustment_changed_cb (sidebar_thumbnails);
768 ev_sidebar_thumbnails_rotation_changed_cb (EvDocumentModel *model,
770 EvSidebarThumbnails *sidebar_thumbnails)
772 gint rotation = ev_document_model_get_rotation (model);
774 sidebar_thumbnails->priv->rotation = rotation;
775 if (sidebar_thumbnails->priv->loading_icons)
776 g_hash_table_remove_all (sidebar_thumbnails->priv->loading_icons);
778 if (sidebar_thumbnails->priv->document == NULL ||
779 sidebar_thumbnails->priv->n_pages <= 0)
782 ev_sidebar_thumbnails_clear_model (sidebar_thumbnails);
783 ev_sidebar_thumbnails_fill_model (sidebar_thumbnails);
785 /* Trigger a redraw */
786 sidebar_thumbnails->priv->start_page = -1;
787 sidebar_thumbnails->priv->end_page = -1;
788 ev_sidebar_thumbnails_set_current_page (sidebar_thumbnails,
789 ev_document_model_get_page (model));
790 g_idle_add ((GSourceFunc)refresh, sidebar_thumbnails);
794 thumbnail_job_completed_callback (EvJobThumbnail *job,
795 EvSidebarThumbnails *sidebar_thumbnails)
797 EvSidebarThumbnailsPrivate *priv = sidebar_thumbnails->priv;
800 iter = (GtkTreeIter *) g_object_get_data (G_OBJECT (job), "tree_iter");
801 gtk_list_store_set (priv->list_store,
803 COLUMN_PIXBUF, job->thumbnail,
804 COLUMN_THUMBNAIL_SET, TRUE,
810 ev_sidebar_thumbnails_document_changed_cb (EvDocumentModel *model,
812 EvSidebarThumbnails *sidebar_thumbnails)
814 EvDocument *document = ev_document_model_get_document (model);
815 EvSidebarThumbnailsPrivate *priv = sidebar_thumbnails->priv;
817 if (!EV_IS_DOCUMENT_THUMBNAILS (document) ||
818 ev_document_get_n_pages (document) <= 0 ||
819 !ev_document_check_dimensions (document)) {
823 priv->size_cache = ev_thumbnails_size_cache_get (document);
824 priv->document = document;
825 priv->n_pages = ev_document_get_n_pages (document);
826 priv->rotation = ev_document_model_get_rotation (model);
827 priv->loading_icons = g_hash_table_new_full (g_str_hash,
829 (GDestroyNotify)g_free,
830 (GDestroyNotify)g_object_unref);
832 ev_sidebar_thumbnails_clear_model (sidebar_thumbnails);
833 ev_sidebar_thumbnails_fill_model (sidebar_thumbnails);
835 /* Create the view widget, and remove the old one, if needed */
836 if (ev_sidebar_thumbnails_use_icon_view (sidebar_thumbnails)) {
837 if (priv->tree_view) {
838 gtk_container_remove (GTK_CONTAINER (priv->swindow), priv->tree_view);
839 priv->tree_view = NULL;
842 if (! priv->icon_view) {
843 ev_sidebar_init_icon_view (sidebar_thumbnails);
844 g_object_notify (G_OBJECT (sidebar_thumbnails), "main_widget");
846 gtk_widget_queue_resize (priv->icon_view);
849 if (priv->icon_view) {
850 gtk_container_remove (GTK_CONTAINER (priv->swindow), priv->icon_view);
851 priv->icon_view = NULL;
854 if (! priv->tree_view) {
855 ev_sidebar_init_tree_view (sidebar_thumbnails);
856 g_object_notify (G_OBJECT (sidebar_thumbnails), "main_widget");
860 /* Connect to the signal and trigger a fake callback */
861 g_signal_connect_swapped (priv->model, "page-changed",
862 G_CALLBACK (page_changed_cb),
864 g_signal_connect (priv->model, "notify::rotation",
865 G_CALLBACK (ev_sidebar_thumbnails_rotation_changed_cb),
867 sidebar_thumbnails->priv->start_page = -1;
868 sidebar_thumbnails->priv->end_page = -1;
869 ev_sidebar_thumbnails_set_current_page (sidebar_thumbnails,
870 ev_document_model_get_page (model));
871 adjustment_changed_cb (sidebar_thumbnails);
875 ev_sidebar_thumbnails_set_model (EvSidebarPage *sidebar_page,
876 EvDocumentModel *model)
878 EvSidebarThumbnails *sidebar_thumbnails = EV_SIDEBAR_THUMBNAILS (sidebar_page);
879 EvSidebarThumbnailsPrivate *priv = sidebar_thumbnails->priv;
881 if (priv->model == model)
885 g_signal_connect (model, "notify::document",
886 G_CALLBACK (ev_sidebar_thumbnails_document_changed_cb),
891 ev_sidebar_thumbnails_clear_job (GtkTreeModel *model,
898 gtk_tree_model_get (model, iter, COLUMN_JOB, &job, -1);
902 g_signal_handlers_disconnect_by_func (job, thumbnail_job_completed_callback, data);
903 g_object_unref (job);
910 ev_sidebar_thumbnails_clear_model (EvSidebarThumbnails *sidebar_thumbnails)
912 EvSidebarThumbnailsPrivate *priv = sidebar_thumbnails->priv;
914 gtk_tree_model_foreach (GTK_TREE_MODEL (priv->list_store), ev_sidebar_thumbnails_clear_job, sidebar_thumbnails);
915 gtk_list_store_clear (priv->list_store);
919 ev_sidebar_thumbnails_support_document (EvSidebarPage *sidebar_page,
920 EvDocument *document)
922 return (EV_IS_DOCUMENT_THUMBNAILS (document));
926 ev_sidebar_thumbnails_get_label (EvSidebarPage *sidebar_page)
928 return _("Thumbnails");
932 ev_sidebar_thumbnails_page_iface_init (EvSidebarPageIface *iface)
934 iface->support_document = ev_sidebar_thumbnails_support_document;
935 iface->set_model = ev_sidebar_thumbnails_set_model;
936 iface->get_label = ev_sidebar_thumbnails_get_label;