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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 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;
75 gboolean inverted_colors;
78 gint start_page, end_page;
94 static void ev_sidebar_thumbnails_clear_model (EvSidebarThumbnails *sidebar);
95 static gboolean ev_sidebar_thumbnails_support_document (EvSidebarPage *sidebar_page,
96 EvDocument *document);
97 static void ev_sidebar_thumbnails_page_iface_init (EvSidebarPageIface *iface);
98 static const gchar* ev_sidebar_thumbnails_get_label (EvSidebarPage *sidebar_page);
99 static void thumbnail_job_completed_callback (EvJobThumbnail *job,
100 EvSidebarThumbnails *sidebar_thumbnails);
101 static void adjustment_changed_cb (EvSidebarThumbnails *sidebar_thumbnails);
103 G_DEFINE_TYPE_EXTENDED (EvSidebarThumbnails,
104 ev_sidebar_thumbnails,
107 G_IMPLEMENT_INTERFACE (EV_TYPE_SIDEBAR_PAGE,
108 ev_sidebar_thumbnails_page_iface_init))
110 #define EV_SIDEBAR_THUMBNAILS_GET_PRIVATE(object) \
111 (G_TYPE_INSTANCE_GET_PRIVATE ((object), EV_TYPE_SIDEBAR_THUMBNAILS, EvSidebarThumbnailsPrivate));
113 /* Thumbnails dimensions cache */
114 #define EV_THUMBNAILS_SIZE_CACHE_KEY "ev-thumbnails-size-cache"
116 static EvThumbsSizeCache *
117 ev_thumbnails_size_cache_new (EvDocument *document)
119 EvThumbsSizeCache *cache;
120 EvRenderContext *rc = NULL;
122 EvThumbsSize *thumb_size;
124 cache = g_new0 (EvThumbsSizeCache, 1);
126 n_pages = ev_document_get_n_pages (document);
128 /* Assume all pages are the same size until proven otherwise */
129 cache->uniform = TRUE;
131 for (i = 0; i < n_pages; i++) {
133 gdouble page_width, page_height;
134 gint thumb_width = 0;
135 gint thumb_height = 0;
137 page = ev_document_get_page (document, i);
139 ev_document_get_page_size (document, i, &page_width, &page_height);
142 rc = ev_render_context_new (page, 0, (gdouble)THUMBNAIL_WIDTH / page_width);
144 ev_render_context_set_page (rc, page);
145 ev_render_context_set_scale (rc, (gdouble)THUMBNAIL_WIDTH / page_width);
148 ev_document_thumbnails_get_dimensions (EV_DOCUMENT_THUMBNAILS (document),
149 rc, &thumb_width, &thumb_height);
152 cache->uniform_width = thumb_width;
153 cache->uniform_height = thumb_height;
154 } else if (cache->uniform &&
155 (cache->uniform_width != thumb_width ||
156 cache->uniform_height != thumb_height)) {
157 /* It's a different thumbnail size. Backfill the array. */
160 cache->sizes = g_new0 (EvThumbsSize, n_pages);
162 for (j = 0; j < i; j++) {
163 thumb_size = &(cache->sizes[j]);
164 thumb_size->width = cache->uniform_width;
165 thumb_size->height = cache->uniform_height;
167 cache->uniform = FALSE;
170 if (! cache->uniform) {
171 thumb_size = &(cache->sizes[i]);
173 thumb_size->width = thumb_width;
174 thumb_size->height = thumb_height;
177 g_object_unref (page);
188 ev_thumbnails_size_cache_get_size (EvThumbsSizeCache *cache,
196 if (cache->uniform) {
197 w = cache->uniform_width;
198 h = cache->uniform_height;
200 EvThumbsSize *thumb_size;
202 thumb_size = &(cache->sizes[page]);
204 w = thumb_size->width;
205 h = thumb_size->height;
208 if (rotation == 0 || rotation == 180) {
209 if (width) *width = w;
210 if (height) *height = h;
212 if (width) *width = h;
213 if (height) *height = w;
218 ev_thumbnails_size_cache_free (EvThumbsSizeCache *cache)
221 g_free (cache->sizes);
228 static EvThumbsSizeCache *
229 ev_thumbnails_size_cache_get (EvDocument *document)
231 EvThumbsSizeCache *cache;
233 cache = g_object_get_data (G_OBJECT (document), EV_THUMBNAILS_SIZE_CACHE_KEY);
235 cache = ev_thumbnails_size_cache_new (document);
236 g_object_set_data_full (G_OBJECT (document),
237 EV_THUMBNAILS_SIZE_CACHE_KEY,
239 (GDestroyNotify)ev_thumbnails_size_cache_free);
247 ev_sidebar_thumbnails_dispose (GObject *object)
249 EvSidebarThumbnails *sidebar_thumbnails = EV_SIDEBAR_THUMBNAILS (object);
251 if (sidebar_thumbnails->priv->loading_icons) {
252 g_hash_table_destroy (sidebar_thumbnails->priv->loading_icons);
253 sidebar_thumbnails->priv->loading_icons = NULL;
256 if (sidebar_thumbnails->priv->list_store) {
257 ev_sidebar_thumbnails_clear_model (sidebar_thumbnails);
258 g_object_unref (sidebar_thumbnails->priv->list_store);
259 sidebar_thumbnails->priv->list_store = NULL;
262 G_OBJECT_CLASS (ev_sidebar_thumbnails_parent_class)->dispose (object);
266 ev_sidebar_thumbnails_get_property (GObject *object,
271 EvSidebarThumbnails *sidebar = EV_SIDEBAR_THUMBNAILS (object);
275 if (sidebar->priv->tree_view)
276 g_value_set_object (value, sidebar->priv->tree_view);
278 g_value_set_object (value, sidebar->priv->icon_view);
281 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
287 ev_sidebar_thumbnails_map (GtkWidget *widget)
289 EvSidebarThumbnails *sidebar;
291 sidebar = EV_SIDEBAR_THUMBNAILS (widget);
293 GTK_WIDGET_CLASS (ev_sidebar_thumbnails_parent_class)->map (widget);
295 adjustment_changed_cb (sidebar);
299 ev_sidebar_thumbnails_class_init (EvSidebarThumbnailsClass *ev_sidebar_thumbnails_class)
301 GObjectClass *g_object_class;
302 GtkObjectClass *gtk_object_class;
303 GtkWidgetClass *widget_class;
305 g_object_class = G_OBJECT_CLASS (ev_sidebar_thumbnails_class);
306 gtk_object_class = GTK_OBJECT_CLASS (ev_sidebar_thumbnails_class);
307 widget_class = GTK_WIDGET_CLASS (ev_sidebar_thumbnails_class);
309 g_object_class->dispose = ev_sidebar_thumbnails_dispose;
310 g_object_class->get_property = ev_sidebar_thumbnails_get_property;
311 widget_class->map = ev_sidebar_thumbnails_map;
313 g_object_class_override_property (g_object_class,
317 g_type_class_add_private (g_object_class, sizeof (EvSidebarThumbnailsPrivate));
321 ev_sidebar_thumbnails_new (void)
323 GtkWidget *ev_sidebar_thumbnails;
325 ev_sidebar_thumbnails = g_object_new (EV_TYPE_SIDEBAR_THUMBNAILS, NULL);
327 return ev_sidebar_thumbnails;
331 ev_sidebar_thumbnails_get_loading_icon (EvSidebarThumbnails *sidebar_thumbnails,
338 key = g_strdup_printf ("%dx%d", width, height);
339 icon = g_hash_table_lookup (sidebar_thumbnails->priv->loading_icons, key);
341 icon = ev_document_misc_get_thumbnail_frame (width, height, NULL);
342 g_hash_table_insert (sidebar_thumbnails->priv->loading_icons,
352 clear_range (EvSidebarThumbnails *sidebar_thumbnails,
356 EvSidebarThumbnailsPrivate *priv = sidebar_thumbnails->priv;
360 gint prev_width = -1;
361 gint prev_height = -1;
363 g_assert (start_page <= end_page);
365 path = gtk_tree_path_new_from_indices (start_page, -1);
366 for (result = gtk_tree_model_get_iter (GTK_TREE_MODEL (priv->list_store), &iter, path);
367 result && start_page <= end_page;
368 result = gtk_tree_model_iter_next (GTK_TREE_MODEL (priv->list_store), &iter), start_page ++) {
370 GdkPixbuf *loading_icon = NULL;
373 gtk_tree_model_get (GTK_TREE_MODEL (priv->list_store),
379 g_signal_handlers_disconnect_by_func (job, thumbnail_job_completed_callback, sidebar_thumbnails);
380 ev_job_cancel (EV_JOB (job));
381 g_object_unref (job);
384 ev_thumbnails_size_cache_get_size (priv->size_cache, start_page,
387 if (!loading_icon || (width != prev_width && height != prev_height)) {
389 ev_sidebar_thumbnails_get_loading_icon (sidebar_thumbnails,
394 prev_height = height;
396 gtk_list_store_set (priv->list_store, &iter,
398 COLUMN_THUMBNAIL_SET, FALSE,
399 COLUMN_PIXBUF, loading_icon,
402 gtk_tree_path_free (path);
406 get_scale_for_page (EvSidebarThumbnails *sidebar_thumbnails,
409 EvSidebarThumbnailsPrivate *priv = sidebar_thumbnails->priv;
412 ev_document_get_page_size (priv->document, page, &width, NULL);
414 return (gdouble)THUMBNAIL_WIDTH / width;
418 add_range (EvSidebarThumbnails *sidebar_thumbnails,
422 EvSidebarThumbnailsPrivate *priv = sidebar_thumbnails->priv;
426 gint page = start_page;
428 g_assert (start_page <= end_page);
430 path = gtk_tree_path_new_from_indices (start_page, -1);
431 for (result = gtk_tree_model_get_iter (GTK_TREE_MODEL (priv->list_store), &iter, path);
432 result && page <= end_page;
433 result = gtk_tree_model_iter_next (GTK_TREE_MODEL (priv->list_store), &iter), page ++) {
435 gboolean thumbnail_set;
437 gtk_tree_model_get (GTK_TREE_MODEL (priv->list_store), &iter,
439 COLUMN_THUMBNAIL_SET, &thumbnail_set,
442 if (job == NULL && !thumbnail_set) {
443 job = ev_job_thumbnail_new (priv->document,
444 page, priv->rotation,
445 get_scale_for_page (sidebar_thumbnails, page));
446 ev_job_scheduler_push_job (EV_JOB (job), EV_JOB_PRIORITY_HIGH);
448 g_object_set_data_full (G_OBJECT (job), "tree_iter",
449 gtk_tree_iter_copy (&iter),
450 (GDestroyNotify) gtk_tree_iter_free);
451 g_signal_connect (job, "finished",
452 G_CALLBACK (thumbnail_job_completed_callback),
454 gtk_list_store_set (priv->list_store, &iter,
458 /* The queue and the list own a ref to the job now */
459 g_object_unref (job);
461 g_object_unref (job);
464 gtk_tree_path_free (path);
467 /* This modifies start */
469 update_visible_range (EvSidebarThumbnails *sidebar_thumbnails,
473 EvSidebarThumbnailsPrivate *priv = sidebar_thumbnails->priv;
474 int old_start_page, old_end_page;
476 old_start_page = priv->start_page;
477 old_end_page = priv->end_page;
479 if (start_page == old_start_page &&
480 end_page == old_end_page)
483 /* Clear the areas we no longer display */
484 if (old_start_page >= 0 && old_start_page < start_page)
485 clear_range (sidebar_thumbnails, old_start_page, MIN (start_page - 1, old_end_page));
487 if (old_end_page > 0 && old_end_page > end_page)
488 clear_range (sidebar_thumbnails, MAX (end_page + 1, old_start_page), old_end_page);
490 add_range (sidebar_thumbnails, start_page, end_page);
492 priv->start_page = start_page;
493 priv->end_page = end_page;
497 adjustment_changed_cb (EvSidebarThumbnails *sidebar_thumbnails)
499 EvSidebarThumbnailsPrivate *priv = sidebar_thumbnails->priv;
500 GtkTreePath *path = NULL;
501 GtkTreePath *path2 = NULL;
507 /* Widget is not currently visible */
508 if (!gtk_widget_get_mapped (GTK_WIDGET (sidebar_thumbnails)))
511 page_size = gtk_adjustment_get_page_size (priv->vadjustment);
516 value = gtk_adjustment_get_value (priv->vadjustment);
518 if (priv->tree_view) {
519 if (! gtk_widget_get_realized (priv->tree_view))
522 gtk_tree_view_convert_tree_to_bin_window_coords (GTK_TREE_VIEW (priv->tree_view),
525 gtk_tree_view_convert_tree_to_bin_window_coords (GTK_TREE_VIEW (priv->tree_view),
526 0, (int) (value + page_size),
528 gtk_tree_view_get_path_at_pos (GTK_TREE_VIEW (priv->tree_view),
531 gtk_tree_view_get_path_at_pos (GTK_TREE_VIEW (priv->tree_view),
534 } else if (priv->icon_view) {
535 if (! gtk_widget_get_realized (priv->icon_view))
537 if (! gtk_icon_view_get_visible_range (GTK_ICON_VIEW (priv->icon_view), &path, &path2))
544 update_visible_range (sidebar_thumbnails,
545 gtk_tree_path_get_indices (path)[0],
546 gtk_tree_path_get_indices (path2)[0]);
549 gtk_tree_path_free (path);
550 gtk_tree_path_free (path2);
554 ev_sidebar_thumbnails_fill_model (EvSidebarThumbnails *sidebar_thumbnails)
556 EvSidebarThumbnailsPrivate *priv = sidebar_thumbnails->priv;
559 gint prev_width = -1;
560 gint prev_height = -1;
562 for (i = 0; i < sidebar_thumbnails->priv->n_pages; i++) {
565 GdkPixbuf *loading_icon = NULL;
568 page_label = ev_document_get_page_label (priv->document, i);
569 page_string = g_markup_printf_escaped ("<i>%s</i>", page_label);
570 ev_thumbnails_size_cache_get_size (sidebar_thumbnails->priv->size_cache, i,
571 sidebar_thumbnails->priv->rotation,
573 if (!loading_icon || (width != prev_width && height != prev_height)) {
575 ev_sidebar_thumbnails_get_loading_icon (sidebar_thumbnails,
580 prev_height = height;
582 gtk_list_store_append (priv->list_store, &iter);
583 gtk_list_store_set (priv->list_store, &iter,
584 COLUMN_PAGE_STRING, page_string,
585 COLUMN_PIXBUF, loading_icon,
586 COLUMN_THUMBNAIL_SET, FALSE,
589 g_free (page_string);
594 ev_sidebar_tree_selection_changed (GtkTreeSelection *selection,
595 EvSidebarThumbnails *ev_sidebar_thumbnails)
597 EvSidebarThumbnailsPrivate *priv = ev_sidebar_thumbnails->priv;
602 if (!gtk_tree_selection_get_selected (selection, NULL, &iter))
605 path = gtk_tree_model_get_path (GTK_TREE_MODEL (priv->list_store),
607 page = gtk_tree_path_get_indices (path)[0];
608 gtk_tree_path_free (path);
610 ev_document_model_set_page (priv->model, page);
614 ev_sidebar_icon_selection_changed (GtkIconView *icon_view,
615 EvSidebarThumbnails *ev_sidebar_thumbnails)
617 EvSidebarThumbnailsPrivate *priv = ev_sidebar_thumbnails->priv;
622 selected = gtk_icon_view_get_selected_items (icon_view);
623 if (selected == NULL)
626 /* We don't handle or expect multiple selection. */
627 g_assert (selected->next == NULL);
629 path = selected->data;
630 page = gtk_tree_path_get_indices (path)[0];
632 gtk_tree_path_free (path);
633 g_list_free (selected);
635 ev_document_model_set_page (priv->model, page);
639 ev_sidebar_init_tree_view (EvSidebarThumbnails *ev_sidebar_thumbnails)
641 EvSidebarThumbnailsPrivate *priv;
642 GtkTreeSelection *selection;
643 GtkCellRenderer *renderer;
645 priv = ev_sidebar_thumbnails->priv;
646 priv->tree_view = gtk_tree_view_new_with_model (GTK_TREE_MODEL (priv->list_store));
648 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->tree_view));
649 g_signal_connect (selection, "changed",
650 G_CALLBACK (ev_sidebar_tree_selection_changed), ev_sidebar_thumbnails);
651 gtk_tree_view_set_headers_visible (GTK_TREE_VIEW (priv->tree_view), FALSE);
652 renderer = g_object_new (GTK_TYPE_CELL_RENDERER_PIXBUF,
656 gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (priv->tree_view), -1,
660 gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (priv->tree_view), -1,
661 NULL, gtk_cell_renderer_text_new (),
663 gtk_container_add (GTK_CONTAINER (priv->swindow), priv->tree_view);
664 gtk_widget_show (priv->tree_view);
668 ev_sidebar_init_icon_view (EvSidebarThumbnails *ev_sidebar_thumbnails)
670 EvSidebarThumbnailsPrivate *priv;
672 priv = ev_sidebar_thumbnails->priv;
674 priv->icon_view = gtk_icon_view_new_with_model (GTK_TREE_MODEL (priv->list_store));
675 gtk_icon_view_set_markup_column (GTK_ICON_VIEW (priv->icon_view), 0);
676 gtk_icon_view_set_pixbuf_column (GTK_ICON_VIEW (priv->icon_view), 1);
677 g_signal_connect (priv->icon_view, "selection-changed",
678 G_CALLBACK (ev_sidebar_icon_selection_changed), ev_sidebar_thumbnails);
680 gtk_container_add (GTK_CONTAINER (priv->swindow), priv->icon_view);
681 gtk_widget_show (priv->icon_view);
685 ev_sidebar_thumbnails_use_icon_view (EvSidebarThumbnails *sidebar_thumbnails)
687 EvSidebarThumbnailsPrivate *priv = sidebar_thumbnails->priv;
689 return (ev_document_get_n_pages (priv->document) <= MAX_ICON_VIEW_PAGE_COUNT);
693 ev_sidebar_thumbnails_init (EvSidebarThumbnails *ev_sidebar_thumbnails)
695 EvSidebarThumbnailsPrivate *priv;
697 priv = ev_sidebar_thumbnails->priv = EV_SIDEBAR_THUMBNAILS_GET_PRIVATE (ev_sidebar_thumbnails);
699 priv->list_store = gtk_list_store_new (NUM_COLUMNS,
703 EV_TYPE_JOB_THUMBNAIL);
705 priv->swindow = gtk_scrolled_window_new (NULL, NULL);
707 /* We actually don't want GTK_POLICY_AUTOMATIC for horizontal scrollbar here
708 * it's just a workaround for bug #449462
710 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (priv->swindow),
711 GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
712 gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (priv->swindow),
714 priv->vadjustment = gtk_scrolled_window_get_vadjustment (GTK_SCROLLED_WINDOW (priv->swindow));
715 g_signal_connect_data (priv->vadjustment, "value-changed",
716 G_CALLBACK (adjustment_changed_cb),
717 ev_sidebar_thumbnails, NULL,
718 G_CONNECT_SWAPPED | G_CONNECT_AFTER);
719 g_signal_connect_swapped (priv->swindow, "size-allocate",
720 G_CALLBACK (adjustment_changed_cb),
721 ev_sidebar_thumbnails);
722 gtk_box_pack_start (GTK_BOX (ev_sidebar_thumbnails), priv->swindow, TRUE, TRUE, 0);
724 /* Put it all together */
725 gtk_widget_show_all (priv->swindow);
729 ev_sidebar_thumbnails_set_current_page (EvSidebarThumbnails *sidebar,
732 GtkTreeView *tree_view;
735 path = gtk_tree_path_new_from_indices (page, -1);
737 if (sidebar->priv->tree_view) {
738 tree_view = GTK_TREE_VIEW (sidebar->priv->tree_view);
739 gtk_tree_view_set_cursor (tree_view, path, NULL, FALSE);
740 gtk_tree_view_scroll_to_cell (tree_view, path, NULL, FALSE, 0.0, 0.0);
741 } else if (sidebar->priv->icon_view) {
743 g_signal_handlers_block_by_func
744 (sidebar->priv->icon_view,
745 G_CALLBACK (ev_sidebar_icon_selection_changed), sidebar);
747 gtk_icon_view_select_path (GTK_ICON_VIEW (sidebar->priv->icon_view), path);
749 g_signal_handlers_unblock_by_func
750 (sidebar->priv->icon_view,
751 G_CALLBACK (ev_sidebar_icon_selection_changed), sidebar);
753 gtk_icon_view_set_cursor (GTK_ICON_VIEW (sidebar->priv->icon_view), path, NULL, FALSE);
756 gtk_tree_path_free (path);
760 page_changed_cb (EvSidebarThumbnails *sidebar,
764 ev_sidebar_thumbnails_set_current_page (sidebar, new_page);
768 refresh (EvSidebarThumbnails *sidebar_thumbnails)
770 adjustment_changed_cb (sidebar_thumbnails);
775 ev_sidebar_thumbnails_reload (EvSidebarThumbnails *sidebar_thumbnails)
777 EvDocumentModel *model;
779 if (sidebar_thumbnails->priv->loading_icons)
780 g_hash_table_remove_all (sidebar_thumbnails->priv->loading_icons);
782 if (sidebar_thumbnails->priv->document == NULL ||
783 sidebar_thumbnails->priv->n_pages <= 0)
786 model = sidebar_thumbnails->priv->model;
788 ev_sidebar_thumbnails_clear_model (sidebar_thumbnails);
789 ev_sidebar_thumbnails_fill_model (sidebar_thumbnails);
791 /* Trigger a redraw */
792 sidebar_thumbnails->priv->start_page = -1;
793 sidebar_thumbnails->priv->end_page = -1;
794 ev_sidebar_thumbnails_set_current_page (sidebar_thumbnails,
795 ev_document_model_get_page (model));
796 g_idle_add ((GSourceFunc)refresh, sidebar_thumbnails);
800 ev_sidebar_thumbnails_rotation_changed_cb (EvDocumentModel *model,
802 EvSidebarThumbnails *sidebar_thumbnails)
804 gint rotation = ev_document_model_get_rotation (model);
806 sidebar_thumbnails->priv->rotation = rotation;
807 ev_sidebar_thumbnails_reload (sidebar_thumbnails);
811 ev_sidebar_thumbnails_inverted_colors_changed_cb (EvDocumentModel *model,
813 EvSidebarThumbnails *sidebar_thumbnails)
815 gboolean inverted_colors = ev_document_model_get_inverted_colors (model);
817 sidebar_thumbnails->priv->inverted_colors = inverted_colors;
818 ev_sidebar_thumbnails_reload (sidebar_thumbnails);
822 thumbnail_job_completed_callback (EvJobThumbnail *job,
823 EvSidebarThumbnails *sidebar_thumbnails)
825 EvSidebarThumbnailsPrivate *priv = sidebar_thumbnails->priv;
828 iter = (GtkTreeIter *) g_object_get_data (G_OBJECT (job), "tree_iter");
829 if (priv->inverted_colors)
830 ev_document_misc_invert_pixbuf (job->thumbnail);
831 gtk_list_store_set (priv->list_store,
833 COLUMN_PIXBUF, job->thumbnail,
834 COLUMN_THUMBNAIL_SET, TRUE,
840 ev_sidebar_thumbnails_document_changed_cb (EvDocumentModel *model,
842 EvSidebarThumbnails *sidebar_thumbnails)
844 EvDocument *document = ev_document_model_get_document (model);
845 EvSidebarThumbnailsPrivate *priv = sidebar_thumbnails->priv;
847 if (!EV_IS_DOCUMENT_THUMBNAILS (document) ||
848 ev_document_get_n_pages (document) <= 0 ||
849 !ev_document_check_dimensions (document)) {
853 priv->size_cache = ev_thumbnails_size_cache_get (document);
854 priv->document = document;
855 priv->n_pages = ev_document_get_n_pages (document);
856 priv->rotation = ev_document_model_get_rotation (model);
857 priv->inverted_colors = ev_document_model_get_inverted_colors (model);
858 priv->loading_icons = g_hash_table_new_full (g_str_hash,
860 (GDestroyNotify)g_free,
861 (GDestroyNotify)g_object_unref);
863 ev_sidebar_thumbnails_clear_model (sidebar_thumbnails);
864 ev_sidebar_thumbnails_fill_model (sidebar_thumbnails);
866 /* Create the view widget, and remove the old one, if needed */
867 if (ev_sidebar_thumbnails_use_icon_view (sidebar_thumbnails)) {
868 if (priv->tree_view) {
869 gtk_container_remove (GTK_CONTAINER (priv->swindow), priv->tree_view);
870 priv->tree_view = NULL;
873 if (! priv->icon_view) {
874 ev_sidebar_init_icon_view (sidebar_thumbnails);
875 g_object_notify (G_OBJECT (sidebar_thumbnails), "main_widget");
877 gtk_widget_queue_resize (priv->icon_view);
880 if (priv->icon_view) {
881 gtk_container_remove (GTK_CONTAINER (priv->swindow), priv->icon_view);
882 priv->icon_view = NULL;
885 if (! priv->tree_view) {
886 ev_sidebar_init_tree_view (sidebar_thumbnails);
887 g_object_notify (G_OBJECT (sidebar_thumbnails), "main_widget");
891 /* Connect to the signal and trigger a fake callback */
892 g_signal_connect_swapped (priv->model, "page-changed",
893 G_CALLBACK (page_changed_cb),
895 g_signal_connect (priv->model, "notify::rotation",
896 G_CALLBACK (ev_sidebar_thumbnails_rotation_changed_cb),
898 g_signal_connect (priv->model, "notify::inverted-colors",
899 G_CALLBACK (ev_sidebar_thumbnails_inverted_colors_changed_cb),
901 sidebar_thumbnails->priv->start_page = -1;
902 sidebar_thumbnails->priv->end_page = -1;
903 ev_sidebar_thumbnails_set_current_page (sidebar_thumbnails,
904 ev_document_model_get_page (model));
905 adjustment_changed_cb (sidebar_thumbnails);
909 ev_sidebar_thumbnails_set_model (EvSidebarPage *sidebar_page,
910 EvDocumentModel *model)
912 EvSidebarThumbnails *sidebar_thumbnails = EV_SIDEBAR_THUMBNAILS (sidebar_page);
913 EvSidebarThumbnailsPrivate *priv = sidebar_thumbnails->priv;
915 if (priv->model == model)
919 g_signal_connect (model, "notify::document",
920 G_CALLBACK (ev_sidebar_thumbnails_document_changed_cb),
925 ev_sidebar_thumbnails_clear_job (GtkTreeModel *model,
932 gtk_tree_model_get (model, iter, COLUMN_JOB, &job, -1);
936 g_signal_handlers_disconnect_by_func (job, thumbnail_job_completed_callback, data);
937 g_object_unref (job);
944 ev_sidebar_thumbnails_clear_model (EvSidebarThumbnails *sidebar_thumbnails)
946 EvSidebarThumbnailsPrivate *priv = sidebar_thumbnails->priv;
948 gtk_tree_model_foreach (GTK_TREE_MODEL (priv->list_store), ev_sidebar_thumbnails_clear_job, sidebar_thumbnails);
949 gtk_list_store_clear (priv->list_store);
953 ev_sidebar_thumbnails_support_document (EvSidebarPage *sidebar_page,
954 EvDocument *document)
956 return (EV_IS_DOCUMENT_THUMBNAILS (document));
960 ev_sidebar_thumbnails_get_label (EvSidebarPage *sidebar_page)
962 return _("Thumbnails");
966 ev_sidebar_thumbnails_page_iface_init (EvSidebarPageIface *iface)
968 iface->support_document = ev_sidebar_thumbnails_support_document;
969 iface->set_model = ev_sidebar_thumbnails_set_model;
970 iface->get_label = ev_sidebar_thumbnails_get_label;