+ev_sidebar_thumbnails_fill_model (EvSidebarThumbnails *sidebar_thumbnails)
+{
+ EvSidebarThumbnailsPrivate *priv = sidebar_thumbnails->priv;
+ GtkTreeIter iter;
+ int i;
+
+ for (i = 0; i < sidebar_thumbnails->priv->n_pages; i++) {
+ gchar *page_label;
+ gchar *page_string;
+
+ page_label = ev_page_cache_get_page_label (priv->page_cache, i);
+ page_string = g_markup_printf_escaped ("<i>%s</i>", page_label);
+
+ gtk_list_store_append (priv->list_store, &iter);
+ gtk_list_store_set (priv->list_store, &iter,
+ COLUMN_PAGE_STRING, page_string,
+ COLUMN_PIXBUF, priv->loading_icon,
+ COLUMN_THUMBNAIL_SET, FALSE,
+ -1);
+ g_free (page_label);
+ g_free (page_string);
+ }
+}
+
+
+static void
+ev_sidebar_thumbnails_set_loading_icon (EvSidebarThumbnails *sidebar_thumbnails)
+{
+ if (sidebar_thumbnails->priv->loading_icon)
+ g_object_unref (sidebar_thumbnails->priv->loading_icon);
+
+ if (sidebar_thumbnails->priv->document) {
+ gint width, height;
+
+ /* We get the dimensions of the first page so that we can make a blank
+ * icon. */
+ ev_page_cache_get_thumbnail_size (sidebar_thumbnails->priv->page_cache, 0,
+ sidebar_thumbnails->priv->rotation,
+ &width, &height);
+
+ sidebar_thumbnails->priv->loading_icon =
+ ev_document_misc_get_thumbnail_frame (width, height, NULL);
+ } else {
+ sidebar_thumbnails->priv->loading_icon = NULL;
+ }
+
+}
+
+static gboolean
+refresh (EvSidebarThumbnails *sidebar_thumbnails)
+{
+ adjustment_changed_cb (sidebar_thumbnails);
+ return FALSE;
+}
+
+void
+ev_sidebar_thumbnails_refresh (EvSidebarThumbnails *sidebar_thumbnails,
+ int rotation)
+{
+ sidebar_thumbnails->priv->rotation = rotation;
+ ev_sidebar_thumbnails_set_loading_icon (sidebar_thumbnails);
+
+ if (sidebar_thumbnails->priv->document == NULL)
+ return;
+
+ ev_sidebar_thumbnails_clear_model (sidebar_thumbnails);
+ ev_sidebar_thumbnails_fill_model (sidebar_thumbnails);
+
+ /* Trigger a redraw */
+ sidebar_thumbnails->priv->start_page = -1;
+ sidebar_thumbnails->priv->end_page = -1;
+ g_idle_add ((GSourceFunc)refresh, sidebar_thumbnails);
+}
+
+static void
+ev_sidebar_tree_selection_changed (GtkTreeSelection *selection,
+ EvSidebarThumbnails *ev_sidebar_thumbnails)
+{
+ EvSidebarThumbnailsPrivate *priv = ev_sidebar_thumbnails->priv;
+ GtkTreePath *path;
+ GtkTreeIter iter;
+ int page;
+
+ if (!gtk_tree_selection_get_selected (selection, NULL, &iter))
+ return;
+
+ path = gtk_tree_model_get_path (GTK_TREE_MODEL (priv->list_store),
+ &iter);
+ page = gtk_tree_path_get_indices (path)[0];
+ gtk_tree_path_free (path);
+
+ ev_page_cache_set_current_page_history (priv->page_cache, page);
+}
+
+static void
+ev_sidebar_icon_selection_changed (GtkIconView *icon_view,
+ EvSidebarThumbnails *ev_sidebar_thumbnails)
+{
+ EvSidebarThumbnailsPrivate *priv = ev_sidebar_thumbnails->priv;
+ GtkTreePath *path;
+ GList *selected;
+ int page;
+
+ selected = gtk_icon_view_get_selected_items (icon_view);
+ if (selected == NULL)
+ return;
+
+ /* We don't handle or expect multiple selection. */
+ g_assert (selected->next == NULL);
+
+ path = selected->data;
+ page = gtk_tree_path_get_indices (path)[0];
+
+ gtk_tree_path_free (path);
+ g_list_free (selected);
+
+ ev_page_cache_set_current_page_history (priv->page_cache, page);
+}
+
+static void
+ev_sidebar_init_tree_view (EvSidebarThumbnails *ev_sidebar_thumbnails)