+2005-04-19 Nickolay V. Shmyrev <nshmyrev@yandex.ru>
+
+ * po/POTFILES.in:
+
+ ev-sidebar-thumbnails now has translatable labels
+
+ * shell/Makefile.am:
+ * shell/ev-sidebar-links.c: (ev_sidebar_links_set_document),
+ (ev_sidebar_links_support_document), (ev_sidebar_links_get_label),
+ (ev_sidebar_links_page_iface_init):
+ * shell/ev-sidebar-links.h:
+ * shell/ev-sidebar-page.c: (ev_sidebar_page_get_type),
+ (ev_sidebar_page_support_document), (ev_sidebar_page_set_document),
+ (ev_sidebar_page_get_label):
+ * shell/ev-sidebar-page.h:
+ * shell/ev-sidebar-thumbnails.c: (ev_sidebar_thumbnails_new),
+ (ev_sidebar_thumbnails_set_document),
+ (ev_sidebar_thumbnails_support_document),
+ (ev_sidebar_thumbnails_get_label),
+ (ev_sidebar_thumbnails_page_iface_init):
+ * shell/ev-sidebar-thumbnails.h:
+ * shell/ev-sidebar.c: (ev_sidebar_init), (ev_sidebar_add_page),
+ (ev_sidebar_set_document):
+ * shell/ev-sidebar.h:
+ * shell/ev-window.c: (ev_window_setup_document), (ev_window_init):
+
+ Small rework of sidebar code. Now sidebar pages should implement
+ EvSidebarPage interface. That makes page management in EvSidebar
+ easier. See bug #164811 for details
+
2005-04-19 Nickolay V. Shmyrev <nshmyrev@yandex.ru>
* shell/ev-application.c: (ev_application_open):
shell/ev-password.c
shell/ev-print-job.c
shell/ev-sidebar-links.c
+shell/ev-sidebar-thumbnails.c
shell/ev-view.c
shell/ev-window.c
shell/main.c
ev-sidebar.h \
ev-sidebar-links.c \
ev-sidebar-links.h \
+ ev-sidebar-page.c \
+ ev-sidebar-page.h \
ev-sidebar-thumbnails.c \
ev-sidebar-thumbnails.h \
ev-stock-icons.c \
#include <glib/gi18n.h>
#include <gtk/gtk.h>
+#include "ev-sidebar-page.h"
#include "ev-sidebar-links.h"
#include "ev-job-queue.h"
#include "ev-document-links.h"
};
-static void links_page_num_func (GtkTreeViewColumn *tree_column,
- GtkCellRenderer *cell,
- GtkTreeModel *tree_model,
- GtkTreeIter *iter,
- EvSidebarLinks *sidebar_links);
-static void update_page_callback (EvPageCache *page_cache,
- gint current_page,
- EvSidebarLinks *sidebar_links);
+static void links_page_num_func (GtkTreeViewColumn *tree_column,
+ GtkCellRenderer *cell,
+ GtkTreeModel *tree_model,
+ GtkTreeIter *iter,
+ EvSidebarLinks *sidebar_links);
+static void update_page_callback (EvPageCache *page_cache,
+ gint current_page,
+ EvSidebarLinks *sidebar_links);
+static void ev_sidebar_links_page_iface_init (EvSidebarPageIface *iface);
+static void ev_sidebar_links_clear_document (EvSidebarLinks *sidebar_links);
+static void ev_sidebar_links_set_document (EvSidebarPage *sidebar_page,
+ EvDocument *document);
+static gboolean ev_sidebar_links_support_document (EvSidebarPage *sidebar_page,
+ EvDocument *document);
+static const gchar* ev_sidebar_links_get_label (EvSidebarPage *sidebar_page);
-G_DEFINE_TYPE (EvSidebarLinks, ev_sidebar_links, GTK_TYPE_VBOX)
+G_DEFINE_TYPE_EXTENDED (EvSidebarLinks,
+ ev_sidebar_links,
+ GTK_TYPE_VBOX,
+ 0,
+ G_IMPLEMENT_INTERFACE (EV_TYPE_SIDEBAR_PAGE,
+ ev_sidebar_links_page_iface_init))
+
#define EV_SIDEBAR_LINKS_GET_PRIVATE(object) \
(G_TYPE_INSTANCE_GET_PRIVATE ((object), EV_TYPE_SIDEBAR_LINKS, EvSidebarLinksPrivate))
return ev_sidebar_links;
}
-void
+static void
ev_sidebar_links_clear_document (EvSidebarLinks *sidebar_links)
{
EvSidebarLinksPrivate *priv;
}
-void
-ev_sidebar_links_set_document (EvSidebarLinks *sidebar_links,
+static void
+ev_sidebar_links_set_document (EvSidebarPage *sidebar_page,
EvDocument *document)
{
+ EvSidebarLinks *sidebar_links;
EvSidebarLinksPrivate *priv;
- g_return_if_fail (EV_IS_SIDEBAR_LINKS (sidebar_links));
+ g_return_if_fail (EV_IS_SIDEBAR_PAGE (sidebar_page));
g_return_if_fail (EV_IS_DOCUMENT (document));
+
+ sidebar_links = EV_SIDEBAR_LINKS (sidebar_page);
priv = sidebar_links->priv;
}
+static gboolean
+ev_sidebar_links_support_document (EvSidebarPage *sidebar_page,
+ EvDocument *document)
+{
+ return (EV_IS_DOCUMENT_LINKS (document) &&
+ ev_document_links_has_document_links (EV_DOCUMENT_LINKS (document)));
+}
+
+static const gchar*
+ev_sidebar_links_get_label (EvSidebarPage *sidebar_page)
+{
+ return _("Index");
+}
+
+static void
+ev_sidebar_links_page_iface_init (EvSidebarPageIface *iface)
+{
+ iface->support_document = ev_sidebar_links_support_document;
+ iface->set_document = ev_sidebar_links_set_document;
+ iface->get_label = ev_sidebar_links_get_label;
+}
+
GType ev_sidebar_links_get_type (void);
GtkWidget *ev_sidebar_links_new (void);
-void ev_sidebar_links_set_document (EvSidebarLinks *ev_sidebar_links,
- EvDocument *document);
-void ev_sidebar_links_clear_document (EvSidebarLinks *sidebar_links);
G_END_DECLS
--- /dev/null
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8; c-indent-level: 8 -*- */
+/*
+ * Copyright (C) 2005 Marco Pesenti Gritti
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2, or (at your option)
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ *
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include "ev-sidebar-page.h"
+
+GType
+ev_sidebar_page_get_type (void)
+{
+ static GType type = 0;
+
+ if (G_UNLIKELY (type == 0))
+ {
+ static const GTypeInfo sidebar_page_info =
+ {
+ sizeof (EvDocumentIface),
+ NULL,
+ NULL,
+ NULL
+ };
+
+ type = g_type_register_static (G_TYPE_INTERFACE,
+ "EvSidebarPage",
+ &sidebar_page_info, (GTypeFlags)0);
+ }
+
+ return type;
+}
+
+
+gboolean
+ev_sidebar_page_support_document (EvSidebarPage *sidebar_page,
+ EvDocument *document)
+{
+ EvSidebarPageIface *iface;
+
+ g_return_val_if_fail (EV_IS_SIDEBAR_PAGE (sidebar_page), FALSE);
+ g_return_val_if_fail (EV_IS_DOCUMENT (document), FALSE);
+
+ iface = EV_SIDEBAR_PAGE_GET_IFACE (sidebar_page);
+
+ g_return_val_if_fail (iface->set_document, FALSE);
+
+ return iface->support_document (sidebar_page, document);
+}
+
+void
+ev_sidebar_page_set_document (EvSidebarPage *sidebar_page,
+ EvDocument *document)
+{
+ EvSidebarPageIface *iface;
+
+ g_return_if_fail (EV_IS_SIDEBAR_PAGE (sidebar_page));
+ g_return_if_fail (EV_IS_DOCUMENT (document));
+
+ iface = EV_SIDEBAR_PAGE_GET_IFACE (sidebar_page);
+
+ g_return_if_fail (iface->set_document);
+
+ iface->set_document (sidebar_page, document);
+
+ return;
+}
+
+const gchar*
+ev_sidebar_page_get_label (EvSidebarPage *sidebar_page)
+{
+ EvSidebarPageIface *iface;
+
+ g_return_val_if_fail (EV_IS_SIDEBAR_PAGE (sidebar_page), NULL);
+
+ iface = EV_SIDEBAR_PAGE_GET_IFACE (sidebar_page);
+
+ g_return_val_if_fail (iface->get_label, NULL);
+
+ return iface->get_label (sidebar_page);
+}
+
--- /dev/null
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8; c-indent-level: 8 -*- */
+/*
+ * Copyright (C) 2005 Marco Pesenti Gritti
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2, or (at your option)
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ *
+ */
+
+#ifndef EV_SIDEBAR_PAGE_H
+#define EV_SIDEBAR_PAGE_H
+
+#include <glib-object.h>
+#include <glib.h>
+
+#include "ev-document.h"
+
+G_BEGIN_DECLS
+
+#define EV_TYPE_SIDEBAR_PAGE (ev_sidebar_page_get_type ())
+#define EV_SIDEBAR_PAGE(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), EV_TYPE_SIDEBAR_PAGE, EvSidebarPage))
+#define EV_SIDEBAR_PAGE_IFACE(k) (G_TYPE_CHECK_CLASS_CAST((k), EV_TYPE_SIDEBAR_PAGE, EvSidebarPageIface))
+#define EV_IS_SIDEBAR_PAGE(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), EV_TYPE_SIDEBAR_PAGE))
+#define EV_IS_SIDEBAR_PAGE_IFACE(k) (G_TYPE_CHECK_CLASS_TYPE ((k), EV_TYPE_SIDEBAR_PAGE))
+#define EV_SIDEBAR_PAGE_GET_IFACE(inst) (G_TYPE_INSTANCE_GET_INTERFACE ((inst), EV_TYPE_SIDEBAR_PAGE, EvSidebarPageIface))
+
+typedef struct _EvSidebarPage EvSidebarPage;
+typedef struct _EvSidebarPageIface EvSidebarPageIface;
+
+struct _EvSidebarPageIface
+{
+ GTypeInterface base_iface;
+
+ /* Methods */
+ gboolean (* support_document) (EvSidebarPage *sidebar_page,
+ EvDocument *document);
+ void (* set_document) (EvSidebarPage *sidebar_page,
+ EvDocument *document);
+ const gchar* (* get_label) (EvSidebarPage *sidebar_page);
+};
+
+GType ev_sidebar_page_get_type (void);
+gboolean ev_sidebar_page_support_document (EvSidebarPage *sidebar_page,
+ EvDocument *document);
+void ev_sidebar_page_set_document (EvSidebarPage *sidebar_page,
+ EvDocument *document);
+const gchar* ev_sidebar_page_get_label (EvSidebarPage *page);
+
+
+G_END_DECLS
+
+#endif /* EV_SIDEBAR_PAGE */
#include <string.h>
#include <gtk/gtk.h>
+#include <glib/gi18n.h>
+#include "ev-sidebar-page.h"
#include "ev-sidebar-thumbnails.h"
#include "ev-document-thumbnails.h"
#include "ev-document-misc.h"
NUM_COLUMNS
};
-G_DEFINE_TYPE (EvSidebarThumbnails, ev_sidebar_thumbnails, GTK_TYPE_VBOX);
+static void ev_sidebar_thumbnails_clear_model (EvSidebarThumbnails *sidebar);
+static gboolean ev_sidebar_thumbnails_support_document (EvSidebarPage *sidebar_page,
+ EvDocument *document);
+static void ev_sidebar_thumbnails_page_iface_init (EvSidebarPageIface *iface);
+static void ev_sidebar_thumbnails_set_document (EvSidebarPage *sidebar_page,
+ EvDocument *document);
+static const gchar* ev_sidebar_thumbnails_get_label (EvSidebarPage *sidebar_page);
+
+G_DEFINE_TYPE_EXTENDED (EvSidebarThumbnails,
+ ev_sidebar_thumbnails,
+ GTK_TYPE_VBOX,
+ 0,
+ G_IMPLEMENT_INTERFACE (EV_TYPE_SIDEBAR_PAGE,
+ ev_sidebar_thumbnails_page_iface_init))
#define EV_SIDEBAR_THUMBNAILS_GET_PRIVATE(object) \
(G_TYPE_INSTANCE_GET_PRIVATE ((object), EV_TYPE_SIDEBAR_THUMBNAILS, EvSidebarThumbnailsPrivate));
-static void
-ev_sidebar_thumbnails_clear_model (EvSidebarThumbnails *sidebar);
static void
ev_sidebar_thumbnails_dispose (GObject *object)
g_type_class_add_private (g_object_class, sizeof (EvSidebarThumbnailsPrivate));
}
+GtkWidget *
+ev_sidebar_thumbnails_new (void)
+{
+ GtkWidget *ev_sidebar_thumbnails;
+
+ ev_sidebar_thumbnails = g_object_new (EV_TYPE_SIDEBAR_THUMBNAILS, NULL);
+
+ return ev_sidebar_thumbnails;
+}
+
static void
adjustment_changed_cb (GtkAdjustment *adjustment,
EvSidebarThumbnails *ev_sidebar_thumbnails)
gtk_widget_show_all (swindow);
}
-GtkWidget *
-ev_sidebar_thumbnails_new (void)
-{
- GtkWidget *ev_sidebar_thumbnails;
-
- ev_sidebar_thumbnails = g_object_new (EV_TYPE_SIDEBAR_THUMBNAILS, NULL);
-
- return ev_sidebar_thumbnails;
-}
-
static void
page_changed_cb (EvPageCache *page_cache,
int page,
-1);
}
-void
-ev_sidebar_thumbnails_set_document (EvSidebarThumbnails *sidebar_thumbnails,
+static void
+ev_sidebar_thumbnails_set_document (EvSidebarPage *sidebar_page,
EvDocument *document)
{
+ EvSidebarThumbnails *sidebar_thumbnails = EV_SIDEBAR_THUMBNAILS (sidebar_page);
GdkPixbuf *loading_icon;
gint i, n_pages;
GtkTreeIter iter;
gtk_list_store_clear (priv->list_store);
}
+static gboolean
+ev_sidebar_thumbnails_support_document (EvSidebarPage *sidebar_page,
+ EvDocument *document)
+{
+ return (EV_IS_DOCUMENT_THUMBNAILS (document) &&
+ (ev_document_get_n_pages (document) > 1));
+}
+
+static const gchar*
+ev_sidebar_thumbnails_get_label (EvSidebarPage *sidebar_page)
+{
+ return _("Thumbnails");
+}
+
+static void
+ev_sidebar_thumbnails_page_iface_init (EvSidebarPageIface *iface)
+{
+ iface->support_document = ev_sidebar_thumbnails_support_document;
+ iface->set_document = ev_sidebar_thumbnails_set_document;
+ iface->get_label = ev_sidebar_thumbnails_get_label;
+}
GType ev_sidebar_thumbnails_get_type (void);
GtkWidget *ev_sidebar_thumbnails_new (void);
-void ev_sidebar_thumbnails_set_document (EvSidebarThumbnails *sidebar_thumbnails,
- EvDocument *document);
-
G_END_DECLS
#endif /* __EV_SIDEBAR_THUMBNAILS_H__ */
#include <gdk/gdkkeysyms.h>
#include "ev-sidebar.h"
+#include "ev-sidebar-page.h"
#include "ev-document-thumbnails.h"
#include "ev-document-links.h"
-#include "ev-sidebar-links.h"
-#include "ev-sidebar-thumbnails.h"
-
-typedef struct
-{
- char *id;
- char *title;
- GtkWidget *main_widget;
-} EvSidebarPage;
enum
{
- PAGE_COLUMN_ID,
PAGE_COLUMN_TITLE,
PAGE_COLUMN_MENU_ITEM,
PAGE_COLUMN_MAIN_WIDGET,
/* data model */
ev_sidebar->priv->page_model = (GtkTreeModel *)
gtk_list_store_new (PAGE_COLUMN_NUM_COLS,
- G_TYPE_STRING,
G_TYPE_STRING,
GTK_TYPE_WIDGET,
GTK_TYPE_WIDGET,
gtk_box_pack_start (GTK_BOX (ev_sidebar), ev_sidebar->priv->notebook,
TRUE, TRUE, 0);
gtk_widget_show (ev_sidebar->priv->notebook);
+
+ gtk_widget_set_sensitive (GTK_WIDGET (ev_sidebar), FALSE);
}
/* Public functions */
void
ev_sidebar_add_page (EvSidebar *ev_sidebar,
- const gchar *page_id,
- const gchar *title,
GtkWidget *main_widget)
{
GtkTreeIter iter;
GtkWidget *menu_item;
gchar *label_title;
+ const gchar *title;
int index;
g_return_if_fail (EV_IS_SIDEBAR (ev_sidebar));
- g_return_if_fail (page_id != NULL);
- g_return_if_fail (title != NULL);
+ g_return_if_fail (EV_IS_SIDEBAR_PAGE (main_widget));
g_return_if_fail (GTK_IS_WIDGET (main_widget));
+
+ title = ev_sidebar_page_get_label (EV_SIDEBAR_PAGE (main_widget));
index = gtk_notebook_append_page (GTK_NOTEBOOK (ev_sidebar->priv->notebook),
main_widget, NULL);
gtk_list_store_insert_with_values (GTK_LIST_STORE (ev_sidebar->priv->page_model),
&iter, 0,
- PAGE_COLUMN_ID, page_id,
PAGE_COLUMN_TITLE, title,
PAGE_COLUMN_MENU_ITEM, menu_item,
PAGE_COLUMN_MAIN_WIDGET, main_widget,
{
EvSidebarPrivate *priv;
GtkTreeIter iter;
- gboolean result;
+ gboolean valid;
+ gboolean has_pages;
g_return_if_fail (EV_IS_SIDEBAR (sidebar));
g_return_if_fail (EV_IS_DOCUMENT (document));
priv = sidebar->priv;
- /* FIXME: We should prolly make sidebars have an interface. For now, we
- * do this bad hack (TM)
- */
- for (result = gtk_tree_model_get_iter_first (priv->page_model, &iter);
- result;
- result = gtk_tree_model_iter_next (priv->page_model, &iter)) {
+ has_pages = FALSE;
+
+ for (valid = gtk_tree_model_get_iter_first (priv->page_model, &iter);
+ valid;
+ valid = gtk_tree_model_iter_next (priv->page_model, &iter)) {
GtkWidget *widget;
GtkWidget *menu_widget;
-1);
- if (EV_IS_SIDEBAR_LINKS (widget)) {
- if (EV_IS_DOCUMENT_LINKS (document) &&
- ev_document_links_has_document_links (EV_DOCUMENT_LINKS (document))) {
- ev_sidebar_links_set_document (EV_SIDEBAR_LINKS (widget), document);
- continue;
- } else {
- gtk_widget_set_sensitive (menu_widget, FALSE);
- }
- }
-
- if (EV_IS_SIDEBAR_THUMBNAILS (widget)) {
- if (EV_IS_DOCUMENT_THUMBNAILS (document) &&
- (ev_document_get_n_pages (document) > 1)) {
- ev_sidebar_thumbnails_set_document (EV_SIDEBAR_THUMBNAILS (widget), document);
- continue;
- } else {
+ if (ev_sidebar_page_support_document (EV_SIDEBAR_PAGE (widget), document)) {
+ ev_sidebar_page_set_document (EV_SIDEBAR_PAGE (widget), document);
+ has_pages = TRUE;
+ } else {
gtk_widget_set_sensitive (menu_widget, FALSE);
- }
}
}
+
+ if (!has_pages) {
+ gtk_widget_hide (GTK_WIDGET (sidebar));
+ } else {
+ gtk_widget_set_sensitive (GTK_WIDGET (sidebar), TRUE);
+ }
}
-gboolean
-ev_sidebar_supports_document (EvSidebar *ev_sidebar,
- EvDocument *document)
-{
- gboolean need_thumbnails;
- gboolean need_index;
-
- need_thumbnails = EV_IS_DOCUMENT_THUMBNAILS (document) && (ev_document_get_n_pages (document) > 1);
- need_index = (EV_IS_DOCUMENT_LINKS (document));
-
- return need_thumbnails || need_index;
-}
-
-
-
GType ev_sidebar_get_type (void);
GtkWidget *ev_sidebar_new (void);
void ev_sidebar_add_page (EvSidebar *ev_sidebar,
- const gchar *page_id,
- const gchar *title,
GtkWidget *main_widget);
void ev_sidebar_set_document (EvSidebar *ev_sidebar,
EvDocument *document);
-gboolean ev_sidebar_supports_document (EvSidebar *ev_sidebar,
- EvDocument *document);
G_END_DECLS
GtkWidget *toolbar;
GtkWidget *hpaned;
GtkWidget *sidebar;
- GtkWidget *thumbs_sidebar;
GtkWidget *find_bar;
GtkWidget *scrolled_window;
GtkWidget *view;
g_free (title);
}
-static void
-hide_sidebar_and_actions (EvWindow *ev_window)
-{
- GtkAction *action;
- /* Alsthough we update the hiddenness of the sidebar, we don't want to
- * store the value */
- g_signal_handlers_disconnect_by_func (ev_window->priv->sidebar,
- ev_window_sidebar_visibility_changed_cb,
- ev_window);
- gtk_widget_hide (ev_window->priv->sidebar);
- action = gtk_action_group_get_action (ev_window->priv->action_group, "ViewSidebar");
- gtk_action_set_sensitive (action, FALSE);
-
-}
-
static void
find_changed_cb (EvDocument *document, int page, EvWindow *ev_window)
{
ev_window_set_page_mode (ev_window, PAGE_MODE_SINGLE_PAGE);
- if (ev_sidebar_supports_document (sidebar, document))
- ev_sidebar_set_document (sidebar, document);
- else
- hide_sidebar_and_actions (ev_window);
+ ev_sidebar_set_document (sidebar, document);
if (ev_page_cache_get_n_pages (ev_window->priv->page_cache) > 0) {
ev_view_set_document (view, document);
ev_window);
gtk_widget_show (sidebar_widget);
ev_sidebar_add_page (EV_SIDEBAR (ev_window->priv->sidebar),
- "index",
- _("Index"),
sidebar_widget);
- ev_window->priv->thumbs_sidebar = ev_sidebar_thumbnails_new ();
- gtk_widget_show (ev_window->priv->thumbs_sidebar);
+ sidebar_widget = ev_sidebar_thumbnails_new ();
+ gtk_widget_show (sidebar_widget);
ev_sidebar_add_page (EV_SIDEBAR (ev_window->priv->sidebar),
- "thumbnails",
- _("Thumbnails"),
- ev_window->priv->thumbs_sidebar);
+ sidebar_widget);
ev_window->priv->scrolled_window =
GTK_WIDGET (g_object_new (GTK_TYPE_SCROLLED_WINDOW,