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 EvPageCache *page_cache;
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 void ev_sidebar_thumbnails_set_document (EvSidebarPage *sidebar_page,
98 EvDocument *document);
99 static const gchar* ev_sidebar_thumbnails_get_label (EvSidebarPage *sidebar_page);
100 static void thumbnail_job_completed_callback (EvJobThumbnail *job,
101 EvSidebarThumbnails *sidebar_thumbnails);
102 static void adjustment_changed_cb (EvSidebarThumbnails *sidebar_thumbnails);
104 G_DEFINE_TYPE_EXTENDED (EvSidebarThumbnails,
105 ev_sidebar_thumbnails,
108 G_IMPLEMENT_INTERFACE (EV_TYPE_SIDEBAR_PAGE,
109 ev_sidebar_thumbnails_page_iface_init))
111 #define EV_SIDEBAR_THUMBNAILS_GET_PRIVATE(object) \
112 (G_TYPE_INSTANCE_GET_PRIVATE ((object), EV_TYPE_SIDEBAR_THUMBNAILS, EvSidebarThumbnailsPrivate));
114 /* Thumbnails dimensions cache */
115 #define EV_THUMBNAILS_SIZE_CACHE_KEY "ev-thumbnails-size-cache"
117 static EvThumbsSizeCache *
118 ev_thumbnails_size_cache_new (EvDocument *document)
120 EvThumbsSizeCache *cache;
123 EvThumbsSize *thumb_size;
125 cache = g_new0 (EvThumbsSizeCache, 1);
127 n_pages = ev_document_get_n_pages (document);
129 /* Assume all pages are the same size until proven otherwise */
130 cache->uniform = TRUE;
132 for (i = 0; i < n_pages; i++) {
134 gdouble page_width, page_height;
135 gint thumb_width = 0;
136 gint thumb_height = 0;
138 page = ev_document_get_page (document, i);
140 ev_document_get_page_size (document, i, &page_width, &page_height);
143 rc = ev_render_context_new (page, 0, (gdouble)THUMBNAIL_WIDTH / page_width);
145 ev_render_context_set_page (rc, page);
146 ev_render_context_set_scale (rc, (gdouble)THUMBNAIL_WIDTH / page_width);
149 ev_document_thumbnails_get_dimensions (EV_DOCUMENT_THUMBNAILS (document),
150 rc, &thumb_width, &thumb_height);
153 cache->uniform_width = thumb_width;
154 cache->uniform_height = thumb_height;
155 } else if (cache->uniform &&
156 (cache->uniform_width != thumb_width ||
157 cache->uniform_height != thumb_height)) {
158 /* It's a different thumbnail size. Backfill the array. */
161 cache->sizes = g_new0 (EvThumbsSize, n_pages);
163 for (j = 0; j < i; j++) {
164 thumb_size = &(cache->sizes[j]);
165 thumb_size->width = cache->uniform_width;
166 thumb_size->height = cache->uniform_height;
168 cache->uniform = FALSE;
171 if (! cache->uniform) {
172 thumb_size = &(cache->sizes[i]);
174 thumb_size->width = thumb_width;
175 thumb_size->height = thumb_height;
178 g_object_unref (page);
189 ev_thumbnails_size_cache_get_size (EvThumbsSizeCache *cache,
197 if (cache->uniform) {
198 w = cache->uniform_width;
199 h = cache->uniform_height;
201 EvThumbsSize *thumb_size;
203 thumb_size = &(cache->sizes[page]);
205 w = thumb_size->width;
206 h = thumb_size->height;
209 if (rotation == 0 || rotation == 180) {
210 if (width) *width = w;
211 if (height) *height = h;
213 if (width) *width = h;
214 if (height) *height = w;
219 ev_thumbnails_size_cache_free (EvThumbsSizeCache *cache)
222 g_free (cache->sizes);
229 static EvThumbsSizeCache *
230 ev_thumbnails_size_cache_get (EvDocument *document)
232 EvThumbsSizeCache *cache;
234 cache = g_object_get_data (G_OBJECT (document), EV_THUMBNAILS_SIZE_CACHE_KEY);
236 cache = ev_thumbnails_size_cache_new (document);
237 g_object_set_data_full (G_OBJECT (document),
238 EV_THUMBNAILS_SIZE_CACHE_KEY,
240 (GDestroyNotify)ev_thumbnails_size_cache_free);
248 ev_sidebar_thumbnails_dispose (GObject *object)
250 EvSidebarThumbnails *sidebar_thumbnails = EV_SIDEBAR_THUMBNAILS (object);
252 if (sidebar_thumbnails->priv->loading_icons) {
253 g_hash_table_destroy (sidebar_thumbnails->priv->loading_icons);
254 sidebar_thumbnails->priv->loading_icons = NULL;
257 if (sidebar_thumbnails->priv->list_store) {
258 ev_sidebar_thumbnails_clear_model (sidebar_thumbnails);
259 g_object_unref (sidebar_thumbnails->priv->list_store);
260 sidebar_thumbnails->priv->list_store = NULL;
263 G_OBJECT_CLASS (ev_sidebar_thumbnails_parent_class)->dispose (object);
267 ev_sidebar_thumbnails_get_property (GObject *object,
272 EvSidebarThumbnails *sidebar = EV_SIDEBAR_THUMBNAILS (object);
276 if (sidebar->priv->tree_view)
277 g_value_set_object (value, sidebar->priv->tree_view);
279 g_value_set_object (value, sidebar->priv->icon_view);
282 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
288 ev_sidebar_thumbnails_map (GtkWidget *widget)
290 EvSidebarThumbnails *sidebar;
292 sidebar = EV_SIDEBAR_THUMBNAILS (widget);
294 GTK_WIDGET_CLASS (ev_sidebar_thumbnails_parent_class)->map (widget);
296 adjustment_changed_cb (sidebar);
300 ev_sidebar_thumbnails_class_init (EvSidebarThumbnailsClass *ev_sidebar_thumbnails_class)
302 GObjectClass *g_object_class;
303 GtkObjectClass *gtk_object_class;
304 GtkWidgetClass *widget_class;
306 g_object_class = G_OBJECT_CLASS (ev_sidebar_thumbnails_class);
307 gtk_object_class = GTK_OBJECT_CLASS (ev_sidebar_thumbnails_class);
308 widget_class = GTK_WIDGET_CLASS (ev_sidebar_thumbnails_class);
310 g_object_class->dispose = ev_sidebar_thumbnails_dispose;
311 g_object_class->get_property = ev_sidebar_thumbnails_get_property;
312 widget_class->map = ev_sidebar_thumbnails_map;
314 g_object_class_override_property (g_object_class,
318 g_type_class_add_private (g_object_class, sizeof (EvSidebarThumbnailsPrivate));
322 ev_sidebar_thumbnails_new (void)
324 GtkWidget *ev_sidebar_thumbnails;
326 ev_sidebar_thumbnails = g_object_new (EV_TYPE_SIDEBAR_THUMBNAILS, NULL);
328 return ev_sidebar_thumbnails;
332 ev_sidebar_thumbnails_get_loading_icon (EvSidebarThumbnails *sidebar_thumbnails,
339 key = g_strdup_printf ("%dx%d", width, height);
340 icon = g_hash_table_lookup (sidebar_thumbnails->priv->loading_icons, key);
342 icon = ev_document_misc_get_thumbnail_frame (width, height, NULL);
343 g_hash_table_insert (sidebar_thumbnails->priv->loading_icons,
353 clear_range (EvSidebarThumbnails *sidebar_thumbnails,
357 EvSidebarThumbnailsPrivate *priv = sidebar_thumbnails->priv;
361 gint prev_width = -1;
362 gint prev_height = -1;
364 g_assert (start_page <= end_page);
366 path = gtk_tree_path_new_from_indices (start_page, -1);
367 for (result = gtk_tree_model_get_iter (GTK_TREE_MODEL (priv->list_store), &iter, path);
368 result && start_page <= end_page;
369 result = gtk_tree_model_iter_next (GTK_TREE_MODEL (priv->list_store), &iter), start_page ++) {
371 GdkPixbuf *loading_icon = NULL;
374 gtk_tree_model_get (GTK_TREE_MODEL (priv->list_store),
380 g_signal_handlers_disconnect_by_func (job, thumbnail_job_completed_callback, sidebar_thumbnails);
381 ev_job_cancel (EV_JOB (job));
382 g_object_unref (job);
385 ev_thumbnails_size_cache_get_size (priv->size_cache, start_page,
388 if (!loading_icon || (width != prev_width && height != prev_height)) {
390 ev_sidebar_thumbnails_get_loading_icon (sidebar_thumbnails,
395 prev_height = height;
397 gtk_list_store_set (priv->list_store, &iter,
399 COLUMN_THUMBNAIL_SET, FALSE,
400 COLUMN_PIXBUF, loading_icon,
403 gtk_tree_path_free (path);
407 get_scale_for_page (EvSidebarThumbnails *sidebar_thumbnails,
410 EvSidebarThumbnailsPrivate *priv = sidebar_thumbnails->priv;
413 ev_document_get_page_size (priv->document, page, &width, NULL);
415 return (gdouble)THUMBNAIL_WIDTH / width;
419 add_range (EvSidebarThumbnails *sidebar_thumbnails,
423 EvSidebarThumbnailsPrivate *priv = sidebar_thumbnails->priv;
427 gint page = start_page;
429 g_assert (start_page <= end_page);
431 path = gtk_tree_path_new_from_indices (start_page, -1);
432 for (result = gtk_tree_model_get_iter (GTK_TREE_MODEL (priv->list_store), &iter, path);
433 result && page <= end_page;
434 result = gtk_tree_model_iter_next (GTK_TREE_MODEL (priv->list_store), &iter), page ++) {
436 gboolean thumbnail_set;
438 gtk_tree_model_get (GTK_TREE_MODEL (priv->list_store), &iter,
440 COLUMN_THUMBNAIL_SET, &thumbnail_set,
443 if (job == NULL && !thumbnail_set) {
444 job = ev_job_thumbnail_new (priv->document,
445 page, priv->rotation,
446 get_scale_for_page (sidebar_thumbnails, page));
447 ev_job_scheduler_push_job (EV_JOB (job), EV_JOB_PRIORITY_HIGH);
449 g_object_set_data_full (G_OBJECT (job), "tree_iter",
450 gtk_tree_iter_copy (&iter),
451 (GDestroyNotify) gtk_tree_iter_free);
452 g_signal_connect (job, "finished",
453 G_CALLBACK (thumbnail_job_completed_callback),
455 gtk_list_store_set (priv->list_store, &iter,
459 /* The queue and the list own a ref to the job now */
460 g_object_unref (job);
462 g_object_unref (job);
465 gtk_tree_path_free (path);
468 /* This modifies start */
470 update_visible_range (EvSidebarThumbnails *sidebar_thumbnails,
474 EvSidebarThumbnailsPrivate *priv = sidebar_thumbnails->priv;
475 int old_start_page, old_end_page;
477 old_start_page = priv->start_page;
478 old_end_page = priv->end_page;
480 if (start_page == old_start_page &&
481 end_page == old_end_page)
484 /* Clear the areas we no longer display */
485 if (old_start_page >= 0 && old_start_page < start_page)
486 clear_range (sidebar_thumbnails, old_start_page, MIN (start_page - 1, old_end_page));
488 if (old_end_page > 0 && old_end_page > end_page)
489 clear_range (sidebar_thumbnails, MAX (end_page + 1, old_start_page), old_end_page);
491 add_range (sidebar_thumbnails, start_page, end_page);
493 priv->start_page = start_page;
494 priv->end_page = end_page;
498 adjustment_changed_cb (EvSidebarThumbnails *sidebar_thumbnails)
500 EvSidebarThumbnailsPrivate *priv = sidebar_thumbnails->priv;
501 GtkTreePath *path = NULL;
502 GtkTreePath *path2 = NULL;
506 /* Widget is not currently visible */
507 if (!GTK_WIDGET_MAPPED (sidebar_thumbnails))
510 if (priv->vadjustment->page_size == 0)
513 if (priv->tree_view) {
514 if (! GTK_WIDGET_REALIZED (priv->tree_view))
517 gtk_tree_view_convert_tree_to_bin_window_coords (GTK_TREE_VIEW (priv->tree_view),
518 0, (int) priv->vadjustment->value,
520 gtk_tree_view_convert_tree_to_bin_window_coords (GTK_TREE_VIEW (priv->tree_view),
521 0, (int) (priv->vadjustment->value + priv->vadjustment->page_size),
523 gtk_tree_view_get_path_at_pos (GTK_TREE_VIEW (priv->tree_view),
526 gtk_tree_view_get_path_at_pos (GTK_TREE_VIEW (priv->tree_view),
529 } else if (priv->icon_view) {
530 if (! GTK_WIDGET_REALIZED (priv->icon_view))
532 if (! gtk_icon_view_get_visible_range (GTK_ICON_VIEW (priv->icon_view), &path, &path2))
539 update_visible_range (sidebar_thumbnails,
540 gtk_tree_path_get_indices (path)[0],
541 gtk_tree_path_get_indices (path2)[0]);
544 gtk_tree_path_free (path);
545 gtk_tree_path_free (path2);
549 ev_sidebar_thumbnails_fill_model (EvSidebarThumbnails *sidebar_thumbnails)
551 EvSidebarThumbnailsPrivate *priv = sidebar_thumbnails->priv;
554 gint prev_width = -1;
555 gint prev_height = -1;
557 for (i = 0; i < sidebar_thumbnails->priv->n_pages; i++) {
560 GdkPixbuf *loading_icon = NULL;
563 page_label = ev_document_get_page_label (priv->document, i);
564 page_string = g_markup_printf_escaped ("<i>%s</i>", page_label);
565 ev_thumbnails_size_cache_get_size (sidebar_thumbnails->priv->size_cache, i,
566 sidebar_thumbnails->priv->rotation,
568 if (!loading_icon || (width != prev_width && height != prev_height)) {
570 ev_sidebar_thumbnails_get_loading_icon (sidebar_thumbnails,
575 prev_height = height;
577 gtk_list_store_append (priv->list_store, &iter);
578 gtk_list_store_set (priv->list_store, &iter,
579 COLUMN_PAGE_STRING, page_string,
580 COLUMN_PIXBUF, loading_icon,
581 COLUMN_THUMBNAIL_SET, FALSE,
584 g_free (page_string);
589 refresh (EvSidebarThumbnails *sidebar_thumbnails)
591 adjustment_changed_cb (sidebar_thumbnails);
596 ev_sidebar_thumbnails_refresh (EvSidebarThumbnails *sidebar_thumbnails,
599 sidebar_thumbnails->priv->rotation = rotation;
600 if (sidebar_thumbnails->priv->loading_icons)
601 g_hash_table_remove_all (sidebar_thumbnails->priv->loading_icons);
603 if (sidebar_thumbnails->priv->document == NULL ||
604 sidebar_thumbnails->priv->n_pages <= 0)
607 ev_sidebar_thumbnails_clear_model (sidebar_thumbnails);
608 ev_sidebar_thumbnails_fill_model (sidebar_thumbnails);
610 /* Trigger a redraw */
611 sidebar_thumbnails->priv->start_page = -1;
612 sidebar_thumbnails->priv->end_page = -1;
613 g_idle_add ((GSourceFunc)refresh, sidebar_thumbnails);
617 ev_sidebar_tree_selection_changed (GtkTreeSelection *selection,
618 EvSidebarThumbnails *ev_sidebar_thumbnails)
620 EvSidebarThumbnailsPrivate *priv = ev_sidebar_thumbnails->priv;
625 if (!gtk_tree_selection_get_selected (selection, NULL, &iter))
628 path = gtk_tree_model_get_path (GTK_TREE_MODEL (priv->list_store),
630 page = gtk_tree_path_get_indices (path)[0];
631 gtk_tree_path_free (path);
633 ev_page_cache_set_current_page_history (priv->page_cache, page);
637 ev_sidebar_icon_selection_changed (GtkIconView *icon_view,
638 EvSidebarThumbnails *ev_sidebar_thumbnails)
640 EvSidebarThumbnailsPrivate *priv = ev_sidebar_thumbnails->priv;
645 selected = gtk_icon_view_get_selected_items (icon_view);
646 if (selected == NULL)
649 /* We don't handle or expect multiple selection. */
650 g_assert (selected->next == NULL);
652 path = selected->data;
653 page = gtk_tree_path_get_indices (path)[0];
655 gtk_tree_path_free (path);
656 g_list_free (selected);
658 ev_page_cache_set_current_page_history (priv->page_cache, page);
662 ev_sidebar_init_tree_view (EvSidebarThumbnails *ev_sidebar_thumbnails)
664 EvSidebarThumbnailsPrivate *priv;
665 GtkTreeSelection *selection;
666 GtkCellRenderer *renderer;
668 priv = ev_sidebar_thumbnails->priv;
669 priv->tree_view = gtk_tree_view_new_with_model (GTK_TREE_MODEL (priv->list_store));
671 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->tree_view));
672 g_signal_connect (selection, "changed",
673 G_CALLBACK (ev_sidebar_tree_selection_changed), ev_sidebar_thumbnails);
674 gtk_tree_view_set_headers_visible (GTK_TREE_VIEW (priv->tree_view), FALSE);
675 renderer = g_object_new (GTK_TYPE_CELL_RENDERER_PIXBUF,
679 gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (priv->tree_view), -1,
683 gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (priv->tree_view), -1,
684 NULL, gtk_cell_renderer_text_new (),
686 gtk_container_add (GTK_CONTAINER (priv->swindow), priv->tree_view);
687 gtk_widget_show (priv->tree_view);
691 ev_sidebar_init_icon_view (EvSidebarThumbnails *ev_sidebar_thumbnails)
693 EvSidebarThumbnailsPrivate *priv;
695 priv = ev_sidebar_thumbnails->priv;
697 priv->icon_view = gtk_icon_view_new_with_model (GTK_TREE_MODEL (priv->list_store));
698 gtk_icon_view_set_markup_column (GTK_ICON_VIEW (priv->icon_view), 0);
699 gtk_icon_view_set_pixbuf_column (GTK_ICON_VIEW (priv->icon_view), 1);
700 g_signal_connect (priv->icon_view, "selection-changed",
701 G_CALLBACK (ev_sidebar_icon_selection_changed), ev_sidebar_thumbnails);
703 gtk_container_add (GTK_CONTAINER (priv->swindow), priv->icon_view);
704 gtk_widget_show (priv->icon_view);
708 ev_sidebar_thumbnails_use_icon_view (EvSidebarThumbnails *sidebar_thumbnails)
710 EvSidebarThumbnailsPrivate *priv = sidebar_thumbnails->priv;
712 return (ev_document_get_n_pages (priv->document) <= MAX_ICON_VIEW_PAGE_COUNT);
716 ev_sidebar_thumbnails_init (EvSidebarThumbnails *ev_sidebar_thumbnails)
718 EvSidebarThumbnailsPrivate *priv;
720 priv = ev_sidebar_thumbnails->priv = EV_SIDEBAR_THUMBNAILS_GET_PRIVATE (ev_sidebar_thumbnails);
722 priv->list_store = gtk_list_store_new (NUM_COLUMNS,
726 EV_TYPE_JOB_THUMBNAIL);
728 priv->swindow = gtk_scrolled_window_new (NULL, NULL);
730 /* We actually don't want GTK_POLICY_AUTOMATIC for horizontal scrollbar here
731 * it's just a workaround for bug #449462
733 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (priv->swindow),
734 GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
735 gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (priv->swindow),
737 priv->vadjustment = gtk_scrolled_window_get_vadjustment (GTK_SCROLLED_WINDOW (priv->swindow));
738 g_signal_connect_data (priv->vadjustment, "value-changed",
739 G_CALLBACK (adjustment_changed_cb),
740 ev_sidebar_thumbnails, NULL,
741 G_CONNECT_SWAPPED | G_CONNECT_AFTER);
742 g_signal_connect_swapped (priv->swindow, "size-allocate",
743 G_CALLBACK (adjustment_changed_cb),
744 ev_sidebar_thumbnails);
745 gtk_box_pack_start (GTK_BOX (ev_sidebar_thumbnails), priv->swindow, TRUE, TRUE, 0);
747 /* Put it all together */
748 gtk_widget_show_all (priv->swindow);
752 page_changed_cb (EvPageCache *page_cache,
754 EvSidebarThumbnails *sidebar)
756 GtkTreeView *tree_view;
759 path = gtk_tree_path_new_from_indices (page, -1);
761 if (sidebar->priv->tree_view) {
762 tree_view = GTK_TREE_VIEW (sidebar->priv->tree_view);
763 gtk_tree_view_set_cursor (tree_view, path, NULL, FALSE);
764 gtk_tree_view_scroll_to_cell (tree_view, path, NULL, FALSE, 0.0, 0.0);
765 } else if (sidebar->priv->icon_view) {
767 g_signal_handlers_block_by_func
768 (sidebar->priv->icon_view,
769 G_CALLBACK (ev_sidebar_icon_selection_changed), sidebar);
771 gtk_icon_view_select_path (GTK_ICON_VIEW (sidebar->priv->icon_view), path);
773 g_signal_handlers_unblock_by_func
774 (sidebar->priv->icon_view,
775 G_CALLBACK (ev_sidebar_icon_selection_changed), sidebar);
777 gtk_icon_view_set_cursor (GTK_ICON_VIEW (sidebar->priv->icon_view), path, NULL, FALSE);
780 gtk_tree_path_free (path);
784 thumbnail_job_completed_callback (EvJobThumbnail *job,
785 EvSidebarThumbnails *sidebar_thumbnails)
787 EvSidebarThumbnailsPrivate *priv = sidebar_thumbnails->priv;
790 iter = (GtkTreeIter *) g_object_get_data (G_OBJECT (job), "tree_iter");
791 gtk_list_store_set (priv->list_store,
793 COLUMN_PIXBUF, job->thumbnail,
794 COLUMN_THUMBNAIL_SET, TRUE,
800 ev_sidebar_thumbnails_set_document (EvSidebarPage *sidebar_page,
801 EvDocument *document)
803 EvSidebarThumbnails *sidebar_thumbnails = EV_SIDEBAR_THUMBNAILS (sidebar_page);
805 EvSidebarThumbnailsPrivate *priv = sidebar_thumbnails->priv;
807 priv->page_cache = ev_page_cache_get (document);
809 if (!EV_IS_DOCUMENT_THUMBNAILS (document) ||
810 ev_document_get_n_pages (document) <= 0 ||
811 !ev_document_check_dimensions (document)) {
815 priv->size_cache = ev_thumbnails_size_cache_get (document);
816 priv->document = document;
817 priv->n_pages = ev_document_get_n_pages (document);
818 priv->loading_icons = g_hash_table_new_full (g_str_hash,
820 (GDestroyNotify)g_free,
821 (GDestroyNotify)g_object_unref);
823 ev_sidebar_thumbnails_clear_model (sidebar_thumbnails);
824 ev_sidebar_thumbnails_fill_model (sidebar_thumbnails);
826 /* Create the view widget, and remove the old one, if needed */
827 if (ev_sidebar_thumbnails_use_icon_view (sidebar_thumbnails)) {
828 if (priv->tree_view) {
829 gtk_container_remove (GTK_CONTAINER (priv->swindow), priv->tree_view);
830 priv->tree_view = NULL;
833 if (! priv->icon_view) {
834 ev_sidebar_init_icon_view (sidebar_thumbnails);
835 g_object_notify (G_OBJECT (sidebar_thumbnails), "main_widget");
837 gtk_widget_queue_resize (priv->icon_view);
840 if (priv->icon_view) {
841 gtk_container_remove (GTK_CONTAINER (priv->swindow), priv->icon_view);
842 priv->icon_view = NULL;
845 if (! priv->tree_view) {
846 ev_sidebar_init_tree_view (sidebar_thumbnails);
847 g_object_notify (G_OBJECT (sidebar_thumbnails), "main_widget");
851 /* Connect to the signal and trigger a fake callback */
852 g_signal_connect (priv->page_cache, "page-changed", G_CALLBACK (page_changed_cb), sidebar_thumbnails);
853 sidebar_thumbnails->priv->start_page = -1;
854 sidebar_thumbnails->priv->end_page = -1;
855 page_changed_cb (priv->page_cache,
856 ev_page_cache_get_current_page (priv->page_cache),
858 adjustment_changed_cb (sidebar_thumbnails);
862 ev_sidebar_thumbnails_clear_job (GtkTreeModel *model,
869 gtk_tree_model_get (model, iter, COLUMN_JOB, &job, -1);
873 g_signal_handlers_disconnect_by_func (job, thumbnail_job_completed_callback, data);
874 g_object_unref (job);
881 ev_sidebar_thumbnails_clear_model (EvSidebarThumbnails *sidebar_thumbnails)
883 EvSidebarThumbnailsPrivate *priv = sidebar_thumbnails->priv;
885 gtk_tree_model_foreach (GTK_TREE_MODEL (priv->list_store), ev_sidebar_thumbnails_clear_job, sidebar_thumbnails);
886 gtk_list_store_clear (priv->list_store);
890 ev_sidebar_thumbnails_support_document (EvSidebarPage *sidebar_page,
891 EvDocument *document)
893 return (EV_IS_DOCUMENT_THUMBNAILS (document));
897 ev_sidebar_thumbnails_get_label (EvSidebarPage *sidebar_page)
899 return _("Thumbnails");
903 ev_sidebar_thumbnails_page_iface_init (EvSidebarPageIface *iface)
905 iface->support_document = ev_sidebar_thumbnails_support_document;
906 iface->set_document = ev_sidebar_thumbnails_set_document;
907 iface->get_label = ev_sidebar_thumbnails_get_label;