summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Nicholson <dbn.lists@gmail.com>2012-03-03 15:13:33 -0800
committerDan Nicholson <dbn.lists@gmail.com>2012-03-03 15:13:33 -0800
commitfc11b623161ede884306913e79f7278a2d9d5454 (patch)
treee9e28f91c842d93778de2eeeabc1a9908bbfbf91
parentfb1f9f83b11cf5c5a42396b717259af8a33c1406 (diff)
plugin: Greatly simplify plugin
And it works! Instead of using the EvPreviewer object, just create the documents and widgets straight in the plugin. This removes the toolbar for now and just leaves a scrolled window for the view. We'll get that back later.
-rw-r--r--Makefile.am2
-rw-r--r--configure.ac11
-rw-r--r--previewer/Makefile.am21
-rw-r--r--previewer/ev-page-action-widget.c495
-rw-r--r--previewer/ev-page-action-widget.h46
-rw-r--r--previewer/ev-page-action.c239
-rw-r--r--previewer/ev-page-action.h68
-rw-r--r--previewer/ev-previewer.c758
-rw-r--r--previewer/ev-previewer.h52
-rw-r--r--src/Makefile.am3
-rw-r--r--src/evbp.c45
-rw-r--r--src/evbp.h9
-rw-r--r--test/Makefile.am7
13 files changed, 51 insertions, 1705 deletions
diff --git a/Makefile.am b/Makefile.am
index 8dc5668..b4b5bc3 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -1 +1 @@
-SUBDIRS = previewer src test
+SUBDIRS = src test
diff --git a/configure.ac b/configure.ac
index 4d4b7a5..dc1f72d 100644
--- a/configure.ac
+++ b/configure.ac
@@ -2,7 +2,7 @@ AC_INIT([Evince Browser Plugin],
[0.1.0],
[dbn.lists@gmail.com],
[evince-browser-plugin])
-AC_CONFIG_SRCDIR([previewer/ev-previewer.c])
+AC_CONFIG_SRCDIR([src/evbp.c])
AC_CONFIG_HEADERS([config.h])
AM_INIT_AUTOMAKE([foreign])
LT_INIT([disable-static])
@@ -12,10 +12,10 @@ m4_ifdef([AM_SILENT_RULES], [AM_SILENT_RULES([yes])])
GTK_REQUIRED=2.14.0
GLIB_REQUIRED=2.18.0
-previewer_pkgs="gtk+-2.0 >= $GTK_REQUIRED gthread-2.0\
- gio-2.0 >= $GLIB_REQUIRED evince-view-2.30 evince-document-2.30"
-plugin_pkgs="mozilla-plugin nspr $previewer_pkgs"
-PKG_CHECK_MODULES([PREVIEWER], [$previewer_pkgs])
+EVINCE_API=2.32
+plugin_pkgs="mozilla-plugin nspr \
+ gtk+-2.0 >= $GTK_REQUIRED gio-2.0 >= $GLIB_REQUIRED \
+ evince-view-$EVINCE_API evince-document-$EVINCE_API"
PKG_CHECK_MODULES([PLUGIN], [$plugin_pkgs])
GETTEXT_PACKAGE=evince
@@ -50,7 +50,6 @@ test "x$debug" = xyes && E_CFLAGS="$E_CFLAGS -DDEBUG=1"
AC_CONFIG_FILES([
Makefile
-previewer/Makefile
src/Makefile
test/Makefile
])
diff --git a/previewer/Makefile.am b/previewer/Makefile.am
deleted file mode 100644
index 22c45b2..0000000
--- a/previewer/Makefile.am
+++ /dev/null
@@ -1,21 +0,0 @@
-noinst_LTLIBRARIES = libevpreviewer.la
-
-libevpreviewer_la_SOURCES = \
- ev-previewer.h \
- ev-previewer.c \
- ev-page-action-widget.c \
- ev-page-action-widget.h \
- ev-page-action.c \
- ev-page-action.h
-
-libevpreviewer_la_CPPFLAGS = \
- -DGNOMELOCALEDIR=\"$(datadir)/locale\" \
- $(AM_CPPFLAGS)
-
-libevpreviewer_la_CFLAGS = \
- $(PREVIEWER_CFLAGS) \
- $(E_CFLAGS) \
- $(AM_CFLAGS)
-
-libevpreviewer_la_LIBADD = \
- $(PREVIEWER_LIBS)
diff --git a/previewer/ev-page-action-widget.c b/previewer/ev-page-action-widget.c
deleted file mode 100644
index bb8ef2e..0000000
--- a/previewer/ev-page-action-widget.c
+++ /dev/null
@@ -1,495 +0,0 @@
-/*
- * Copyright (C) 2003, 2004 Marco Pesenti Gritti
- * Copyright (C) 2003, 2004 Christian Persch
- *
- * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- */
-
-#include "config.h"
-
-#include <string.h>
-#include <glib/gi18n.h>
-#include <gtk/gtk.h>
-
-#include <evince-document.h>
-#include "ev-page-action.h"
-#include "ev-page-action-widget.h"
-
-/* Widget we pass back */
-static void ev_page_action_widget_init (EvPageActionWidget *action_widget);
-static void ev_page_action_widget_class_init (EvPageActionWidgetClass *action_widget);
-
-enum
-{
- WIDGET_ACTIVATE_LINK,
- WIDGET_N_SIGNALS
-};
-
-struct _EvPageActionWidget
-{
- GtkToolItem parent;
-
- EvDocument *document;
- EvDocumentModel *doc_model;
-
- GtkWidget *entry;
- GtkWidget *label;
- guint signal_id;
- GtkTreeModel *filter_model;
- GtkTreeModel *model;
-};
-
-static guint widget_signals[WIDGET_N_SIGNALS] = {0, };
-
-G_DEFINE_TYPE (EvPageActionWidget, ev_page_action_widget, GTK_TYPE_TOOL_ITEM)
-
-static void
-update_pages_label (EvPageActionWidget *action_widget,
- gint page)
-{
- char *label_text;
- gint n_pages;
-
- n_pages = ev_document_get_n_pages (action_widget->document);
- if (ev_document_has_text_page_labels (action_widget->document)) {
- label_text = g_strdup_printf (_("(%d of %d)"), page + 1, n_pages);
- } else {
- label_text = g_strdup_printf (_("of %d"), n_pages);
- }
- gtk_label_set_text (GTK_LABEL (action_widget->label), label_text);
- g_free (label_text);
-}
-
-static void
-ev_page_action_widget_set_current_page (EvPageActionWidget *action_widget,
- gint page)
-{
- if (page >= 0) {
- gchar *page_label;
-
- gtk_entry_set_width_chars (GTK_ENTRY (action_widget->entry),
- CLAMP (ev_document_get_max_label_len (action_widget->document),
- 6, 12));
-
- page_label = ev_document_get_page_label (action_widget->document, page);
- gtk_entry_set_text (GTK_ENTRY (action_widget->entry), page_label);
- gtk_editable_set_position (GTK_EDITABLE (action_widget->entry), -1);
- g_free (page_label);
-
- } else {
- gtk_entry_set_text (GTK_ENTRY (action_widget->entry), "");
- }
-
- update_pages_label (action_widget, page);
-}
-
-static void
-page_changed_cb (EvDocumentModel *model,
- gint old_page,
- gint new_page,
- EvPageActionWidget *action_widget)
-{
- ev_page_action_widget_set_current_page (action_widget, new_page);
-}
-
-static gboolean
-page_scroll_cb (EvPageActionWidget *action_widget, GdkEventScroll *event)
-{
- EvDocumentModel *model = action_widget->doc_model;
- gint pageno;
-
- pageno = ev_document_model_get_page (model);
- if ((event->direction == GDK_SCROLL_DOWN) &&
- (pageno < ev_document_get_n_pages (action_widget->document) - 1))
- pageno++;
- if ((event->direction == GDK_SCROLL_UP) && (pageno > 0))
- pageno--;
- ev_document_model_set_page (model, pageno);
-
- return TRUE;
-}
-
-static void
-activate_cb (EvPageActionWidget *action_widget)
-{
- EvDocumentModel *model;
- const char *text;
- EvLinkDest *link_dest;
- EvLinkAction *link_action;
- EvLink *link;
- gchar *link_text;
- gint current_page;
-
- model = action_widget->doc_model;
- current_page = ev_document_model_get_page (model);
-
- text = gtk_entry_get_text (GTK_ENTRY (action_widget->entry));
-
- link_dest = ev_link_dest_new_page_label (text);
- link_action = ev_link_action_new_dest (link_dest);
- link_text = g_strdup_printf ("Page: %s", text);
- link = ev_link_new (link_text, link_action);
-
- g_signal_emit (action_widget, widget_signals[WIDGET_ACTIVATE_LINK], 0, link);
-
- g_object_unref (link);
- g_free (link_text);
-
- if (current_page == ev_document_model_get_page (model))
- ev_page_action_widget_set_current_page (action_widget, current_page);
-}
-
-static void
-ev_page_action_widget_init (EvPageActionWidget *action_widget)
-{
- GtkWidget *hbox;
- AtkObject *obj;
-
- hbox = gtk_hbox_new (FALSE, 0);
- gtk_box_set_spacing (GTK_BOX (hbox), 6);
-
- action_widget->entry = gtk_entry_new ();
- gtk_widget_add_events (action_widget->entry,
- GDK_BUTTON_MOTION_MASK);
- gtk_entry_set_width_chars (GTK_ENTRY (action_widget->entry), 5);
- gtk_entry_set_text (GTK_ENTRY (action_widget->entry), "");
- g_signal_connect_swapped (action_widget->entry, "scroll-event",
- G_CALLBACK (page_scroll_cb),
- action_widget);
- g_signal_connect_swapped (action_widget->entry, "activate",
- G_CALLBACK (activate_cb),
- action_widget);
-
- obj = gtk_widget_get_accessible (action_widget->entry);
- atk_object_set_name (obj, "page-label-entry");
-
- gtk_box_pack_start (GTK_BOX (hbox), action_widget->entry,
- FALSE, FALSE, 0);
- gtk_widget_show (action_widget->entry);
-
- action_widget->label = gtk_label_new (NULL);
- gtk_box_pack_start (GTK_BOX (hbox), action_widget->label,
- FALSE, FALSE, 0);
- gtk_widget_show (action_widget->label);
-
- gtk_container_set_border_width (GTK_CONTAINER (action_widget), 6);
- gtk_container_add (GTK_CONTAINER (action_widget), hbox);
- gtk_widget_show (hbox);
-
- gtk_widget_show (GTK_WIDGET (action_widget));
-}
-
-static void
-ev_page_action_widget_document_changed_cb (EvDocumentModel *model,
- GParamSpec *pspec,
- EvPageActionWidget *action_widget)
-{
- EvDocument *document = ev_document_model_get_document (model);
-
- g_object_ref (document);
- if (action_widget->document)
- g_object_unref (action_widget->document);
- action_widget->document = document;
-
- if (action_widget->signal_id > 0) {
- g_signal_handler_disconnect (action_widget->doc_model,
- action_widget->signal_id);
- action_widget->signal_id = 0;
- }
- action_widget->signal_id =
- g_signal_connect_object (action_widget->doc_model,
- "page-changed",
- G_CALLBACK (page_changed_cb),
- action_widget, 0);
-
- ev_page_action_widget_set_current_page (action_widget,
- ev_document_model_get_page (model));
-}
-
-void
-ev_page_action_widget_set_model (EvPageActionWidget *action_widget,
- EvDocumentModel *model)
-{
- if (action_widget->doc_model) {
- g_object_remove_weak_pointer (G_OBJECT (action_widget->doc_model),
- (gpointer)&action_widget->doc_model);
- }
- action_widget->doc_model = model;
- g_object_add_weak_pointer (G_OBJECT (model),
- (gpointer)&action_widget->doc_model);
-
- g_signal_connect (model, "notify::document",
- G_CALLBACK (ev_page_action_widget_document_changed_cb),
- action_widget);
-}
-
-static void
-ev_page_action_widget_finalize (GObject *object)
-{
- EvPageActionWidget *action_widget = EV_PAGE_ACTION_WIDGET (object);
-
- if (action_widget->doc_model != NULL) {
- if (action_widget->signal_id > 0) {
- g_signal_handler_disconnect (action_widget->doc_model,
- action_widget->signal_id);
- action_widget->signal_id = 0;
- }
- g_object_remove_weak_pointer (G_OBJECT (action_widget->doc_model),
- (gpointer)&action_widget->doc_model);
- action_widget->doc_model = NULL;
- }
-
- if (action_widget->document) {
- g_object_unref (action_widget->document);
- action_widget->document = NULL;
- }
-
- G_OBJECT_CLASS (ev_page_action_widget_parent_class)->finalize (object);
-}
-
-static void
-ev_page_action_widget_class_init (EvPageActionWidgetClass *class)
-{
- GObjectClass *object_class = G_OBJECT_CLASS (class);
-
- object_class->finalize = ev_page_action_widget_finalize;
-
- widget_signals[WIDGET_ACTIVATE_LINK] =
- g_signal_new ("activate_link",
- G_OBJECT_CLASS_TYPE (object_class),
- G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
- G_STRUCT_OFFSET (EvPageActionClass, activate_link),
- NULL, NULL,
- g_cclosure_marshal_VOID__OBJECT,
- G_TYPE_NONE, 1,
- G_TYPE_OBJECT);
-
-}
-
-static gboolean
-match_selected_cb (GtkEntryCompletion *completion,
- GtkTreeModel *filter_model,
- GtkTreeIter *filter_iter,
- EvPageActionWidget *proxy)
-{
- EvLink *link;
- GtkTreeIter *iter;
-
- gtk_tree_model_get (filter_model, filter_iter,
- 0, &iter,
- -1);
- gtk_tree_model_get (proxy->model, iter,
- EV_DOCUMENT_LINKS_COLUMN_LINK, &link,
- -1);
-
- g_signal_emit (proxy, widget_signals[WIDGET_ACTIVATE_LINK], 0, link);
-
- if (link)
- g_object_unref (link);
-
- gtk_tree_iter_free (iter);
-
- return TRUE;
-}
-
-
-static void
-display_completion_text (GtkCellLayout *cell_layout,
- GtkCellRenderer *renderer,
- GtkTreeModel *filter_model,
- GtkTreeIter *filter_iter,
- EvPageActionWidget *proxy)
-{
- EvLink *link;
- GtkTreeIter *iter;
-
- gtk_tree_model_get (filter_model, filter_iter,
- 0, &iter,
- -1);
- gtk_tree_model_get (proxy->model, iter,
- EV_DOCUMENT_LINKS_COLUMN_LINK, &link,
- -1);
-
- g_object_set (renderer, "text", ev_link_get_title (link), NULL);
-
- if (link)
- g_object_unref (link);
-
- gtk_tree_iter_free (iter);
-}
-
-static gboolean
-match_completion (GtkEntryCompletion *completion,
- const gchar *key,
- GtkTreeIter *filter_iter,
- EvPageActionWidget *proxy)
-{
- EvLink *link;
- GtkTreeIter *iter;
- const gchar *text = NULL;
-
- gtk_tree_model_get (gtk_entry_completion_get_model (completion),
- filter_iter,
- 0, &iter,
- -1);
- gtk_tree_model_get (proxy->model, iter,
- EV_DOCUMENT_LINKS_COLUMN_LINK, &link,
- -1);
-
-
- if (link) {
- text = ev_link_get_title (link);
- g_object_unref (link);
- }
-
- gtk_tree_iter_free (iter);
-
- if (text && key) {
- gchar *normalized_text;
- gchar *normalized_key;
- gchar *case_normalized_text;
- gchar *case_normalized_key;
- gboolean retval = FALSE;
-
- normalized_text = g_utf8_normalize (text, -1, G_NORMALIZE_ALL);
- normalized_key = g_utf8_normalize (key, -1, G_NORMALIZE_ALL);
- case_normalized_text = g_utf8_casefold (normalized_text, -1);
- case_normalized_key = g_utf8_casefold (normalized_key, -1);
-
- if (strstr (case_normalized_text, case_normalized_key))
- retval = TRUE;
-
- g_free (normalized_text);
- g_free (normalized_key);
- g_free (case_normalized_text);
- g_free (case_normalized_key);
-
- return retval;
- }
-
- return FALSE;
-}
-
-/* user data to set on the widget. */
-#define EPA_FILTER_MODEL_DATA "epa-filter-model"
-
-static gboolean
-build_new_tree_cb (GtkTreeModel *model,
- GtkTreePath *path,
- GtkTreeIter *iter,
- gpointer data)
-{
- GtkTreeModel *filter_model = GTK_TREE_MODEL (data);
- EvLink *link;
- EvLinkAction *action;
- EvLinkActionType type;
-
- gtk_tree_model_get (model, iter,
- EV_DOCUMENT_LINKS_COLUMN_LINK, &link,
- -1);
-
- if (!link)
- return FALSE;
-
- action = ev_link_get_action (link);
- if (!action) {
- g_object_unref (link);
- return FALSE;
- }
-
- type = ev_link_action_get_action_type (action);
-
- if (type == EV_LINK_ACTION_TYPE_GOTO_DEST) {
- GtkTreeIter filter_iter;
-
- gtk_list_store_append (GTK_LIST_STORE (filter_model), &filter_iter);
- gtk_list_store_set (GTK_LIST_STORE (filter_model), &filter_iter,
- 0, iter,
- -1);
- }
-
- g_object_unref (link);
-
- return FALSE;
-}
-
-static GtkTreeModel *
-get_filter_model_from_model (GtkTreeModel *model)
-{
- GtkTreeModel *filter_model;
-
- filter_model =
- (GtkTreeModel *) g_object_get_data (G_OBJECT (model), EPA_FILTER_MODEL_DATA);
- if (filter_model == NULL) {
- filter_model = (GtkTreeModel *) gtk_list_store_new (1, GTK_TYPE_TREE_ITER);
-
- gtk_tree_model_foreach (model,
- build_new_tree_cb,
- filter_model);
- g_object_set_data_full (G_OBJECT (model), EPA_FILTER_MODEL_DATA, filter_model, g_object_unref);
- }
-
- return filter_model;
-}
-
-
-void
-ev_page_action_widget_update_links_model (EvPageActionWidget *proxy, GtkTreeModel *model)
-{
- GtkTreeModel *filter_model;
- GtkEntryCompletion *completion;
- GtkCellRenderer *renderer;
-
- if (!model)
- return;
-
- /* Magik */
- proxy->model = model;
- filter_model = get_filter_model_from_model (model);
-
- completion = gtk_entry_completion_new ();
- g_object_set (G_OBJECT (completion),
- "popup-set-width", FALSE,
- "model", filter_model,
- NULL);
-
- g_signal_connect (completion, "match-selected", G_CALLBACK (match_selected_cb), proxy);
- gtk_entry_completion_set_match_func (completion,
- (GtkEntryCompletionMatchFunc) match_completion,
- proxy, NULL);
-
- /* Set up the layout */
- renderer = (GtkCellRenderer *)
- g_object_new (GTK_TYPE_CELL_RENDERER_TEXT,
- "ellipsize", PANGO_ELLIPSIZE_END,
- "width_chars", 30,
- NULL);
- gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (completion), renderer, TRUE);
- gtk_cell_layout_set_cell_data_func (GTK_CELL_LAYOUT (completion),
- renderer,
- (GtkCellLayoutDataFunc) display_completion_text,
- proxy, NULL);
- gtk_entry_set_completion (GTK_ENTRY (proxy->entry), completion);
-
- g_object_unref (completion);
-}
-
-void
-ev_page_action_widget_grab_focus (EvPageActionWidget *proxy)
-{
- gtk_widget_grab_focus (proxy->entry);
-}
-
diff --git a/previewer/ev-page-action-widget.h b/previewer/ev-page-action-widget.h
deleted file mode 100644
index cf33b55..0000000
--- a/previewer/ev-page-action-widget.h
+++ /dev/null
@@ -1,46 +0,0 @@
-/*
- * Copyright (C) 2003, 2004 Marco Pesenti Gritti
- * Copyright (C) 2003, 2004 Christian Persch
- *
- * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- */
-
-#include <evince-view.h>
-
-#include <gtk/gtk.h>
-
-#define EV_TYPE_PAGE_ACTION_WIDGET (ev_page_action_widget_get_type ())
-#define EV_PAGE_ACTION_WIDGET(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), EV_TYPE_PAGE_ACTION_WIDGET, EvPageActionWidget))
-
-typedef struct _EvPageActionWidget EvPageActionWidget;
-typedef struct _EvPageActionWidgetClass EvPageActionWidgetClass;
-
-struct _EvPageActionWidgetClass
-{
- GtkToolItemClass parent_class;
-
- void (* activate_link) (EvPageActionWidget *page_action,
- EvLink *link);
-};
-
-GType ev_page_action_widget_get_type (void) G_GNUC_CONST;
-
-void ev_page_action_widget_update_links_model (EvPageActionWidget *proxy,
- GtkTreeModel *model);
-
-void ev_page_action_widget_set_model (EvPageActionWidget *action_widget,
- EvDocumentModel *doc_model);
-void ev_page_action_widget_grab_focus (EvPageActionWidget *proxy);
diff --git a/previewer/ev-page-action.c b/previewer/ev-page-action.c
deleted file mode 100644
index ce01862..0000000
--- a/previewer/ev-page-action.c
+++ /dev/null
@@ -1,239 +0,0 @@
-/*
- * Copyright (C) 2003, 2004 Marco Pesenti Gritti
- * Copyright (C) 2003, 2004 Christian Persch
- *
- * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- */
-
-#ifdef HAVE_CONFIG_H
-#include "config.h"
-#endif
-
-#include <string.h>
-#include <stdlib.h>
-
-#include <glib/gi18n.h>
-#include <gtk/gtk.h>
-
-#include "ev-page-action.h"
-#include "ev-page-action-widget.h"
-
-struct _EvPageActionPrivate
-{
- EvDocumentModel *doc_model;
- GtkTreeModel *model;
-};
-
-
-static void ev_page_action_init (EvPageAction *action);
-static void ev_page_action_class_init (EvPageActionClass *class);
-
-enum
-{
- ACTIVATE_LINK,
- N_SIGNALS
-};
-
-static guint signals[N_SIGNALS] = {0, };
-
-G_DEFINE_TYPE (EvPageAction, ev_page_action, GTK_TYPE_ACTION)
-
-#define EV_PAGE_ACTION_GET_PRIVATE(object)(G_TYPE_INSTANCE_GET_PRIVATE ((object), EV_TYPE_PAGE_ACTION, EvPageActionPrivate))
-
-enum {
- PROP_0,
- PROP_MODEL
-};
-
-static GtkWidget *
-create_tool_item (GtkAction *action)
-{
- GtkWidget *proxy;
-
- proxy = g_object_new (EV_TYPE_PAGE_ACTION_WIDGET, NULL);
-
- return proxy;
-}
-
-static void
-update_model (EvPageAction *page, GParamSpec *pspec, EvPageActionWidget *proxy)
-{
- ev_page_action_widget_update_links_model (proxy, page->priv->model);
-}
-
-static void
-activate_link_cb (EvPageActionWidget *proxy, EvLink *link, EvPageAction *action)
-{
- g_signal_emit (action, signals[ACTIVATE_LINK], 0, link);
-}
-
-static void
-connect_proxy (GtkAction *action, GtkWidget *proxy)
-{
- EvPageAction *page = EV_PAGE_ACTION (action);
-
- if (GTK_IS_TOOL_ITEM (proxy)) {
- ev_page_action_widget_set_model (EV_PAGE_ACTION_WIDGET (proxy),
- page->priv->doc_model);
- g_signal_connect (proxy, "activate_link",
- G_CALLBACK (activate_link_cb),
- action);
- g_signal_connect_object (action, "notify::model",
- G_CALLBACK (update_model),
- proxy, 0);
- }
-
- GTK_ACTION_CLASS (ev_page_action_parent_class)->connect_proxy (action, proxy);
-}
-
-static void
-ev_page_action_dispose (GObject *object)
-{
- EvPageAction *page = EV_PAGE_ACTION (object);
-
- if (page->priv->model) {
- g_object_unref (page->priv->model);
- page->priv->model = NULL;
- }
-
- page->priv->doc_model = NULL;
-
- G_OBJECT_CLASS (ev_page_action_parent_class)->dispose (object);
-}
-
-static void
-ev_page_action_set_property (GObject *object,
- guint prop_id,
- const GValue *value,
- GParamSpec *pspec)
-{
- EvPageAction *page = EV_PAGE_ACTION (object);
-
- switch (prop_id)
- {
- case PROP_MODEL:
- ev_page_action_set_links_model (page, g_value_get_object (value));
- break;
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
- break;
- }
-}
-
-static void
-ev_page_action_get_property (GObject *object,
- guint prop_id,
- GValue *value,
- GParamSpec *pspec)
-{
- EvPageAction *page = EV_PAGE_ACTION (object);
-
- switch (prop_id)
- {
- case PROP_MODEL:
- g_value_set_object (value, page->priv->model);
- break;
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
- break;
- }
-}
-
-void
-ev_page_action_set_model (EvPageAction *page,
- EvDocumentModel *model)
-{
- g_return_if_fail (EV_IS_PAGE_ACTION (page));
- g_return_if_fail (EV_IS_DOCUMENT_MODEL (model));
-
- if (page->priv->doc_model == model)
- return;
-
- page->priv->doc_model = model;
-}
-
-void
-ev_page_action_set_links_model (EvPageAction *page,
- GtkTreeModel *links_model)
-{
- g_return_if_fail (EV_IS_PAGE_ACTION (page));
- g_return_if_fail (GTK_IS_TREE_MODEL (links_model));
-
- if (page->priv->model == links_model)
- return;
-
- if (page->priv->model)
- g_object_unref (page->priv->model);
- page->priv->model = g_object_ref (links_model);
-
- g_object_notify (G_OBJECT (page), "model");
-}
-
-void
-ev_page_action_grab_focus (EvPageAction *page_action)
-{
- GSList *proxies;
-
- proxies = gtk_action_get_proxies (GTK_ACTION (page_action));
- for (; proxies != NULL; proxies = proxies->next) {
- EvPageActionWidget *proxy;
-
- proxy = EV_PAGE_ACTION_WIDGET (proxies->data);
-
- if (GTK_WIDGET_MAPPED (GTK_WIDGET (proxy)))
- ev_page_action_widget_grab_focus (proxy);
- }
-}
-
-static void
-ev_page_action_init (EvPageAction *page)
-{
- page->priv = EV_PAGE_ACTION_GET_PRIVATE (page);
-}
-
-static void
-ev_page_action_class_init (EvPageActionClass *class)
-{
- GObjectClass *object_class = G_OBJECT_CLASS (class);
- GtkActionClass *action_class = GTK_ACTION_CLASS (class);
-
- object_class->dispose = ev_page_action_dispose;
- object_class->set_property = ev_page_action_set_property;
- object_class->get_property = ev_page_action_get_property;
-
- action_class->toolbar_item_type = GTK_TYPE_TOOL_ITEM;
- action_class->create_tool_item = create_tool_item;
- action_class->connect_proxy = connect_proxy;
-
- signals[ACTIVATE_LINK] = g_signal_new ("activate_link",
- G_OBJECT_CLASS_TYPE (object_class),
- G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
- G_STRUCT_OFFSET (EvPageActionClass, activate_link),
- NULL, NULL,
- g_cclosure_marshal_VOID__OBJECT,
- G_TYPE_NONE, 1,
- G_TYPE_OBJECT);
-
- g_object_class_install_property (object_class,
- PROP_MODEL,
- g_param_spec_object ("model",
- "Model",
- "Current Links Model",
- GTK_TYPE_TREE_MODEL,
- G_PARAM_READWRITE));
-
- g_type_class_add_private (object_class, sizeof (EvPageActionPrivate));
-}
diff --git a/previewer/ev-page-action.h b/previewer/ev-page-action.h
deleted file mode 100644
index b18db61..0000000
--- a/previewer/ev-page-action.h
+++ /dev/null
@@ -1,68 +0,0 @@
-/*
- * Copyright (C) 2003, 2004 Marco Pesenti Gritti
- * Copyright (C) 2003, 2004 Christian Persch
- *
- * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- */
-
-#ifndef EV_PAGE_ACTION_H
-#define EV_PAGE_ACTION_H
-
-#include <gtk/gtk.h>
-
-#include <evince-document.h>
-#include <evince-view.h>
-
-G_BEGIN_DECLS
-
-#define EV_TYPE_PAGE_ACTION (ev_page_action_get_type ())
-#define EV_PAGE_ACTION(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), EV_TYPE_PAGE_ACTION, EvPageAction))
-#define EV_PAGE_ACTION_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), EV_TYPE_PAGE_ACTION, EvPageActionClass))
-#define EV_IS_PAGE_ACTION(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), EV_TYPE_PAGE_ACTION))
-#define EV_IS_PAGE_ACTION_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((obj), EV_TYPE_PAGE_ACTION))
-#define EV_PAGE_ACTION_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), EV_TYPE_PAGE_ACTION, EvPageActionClass))
-
-typedef struct _EvPageAction EvPageAction;
-typedef struct _EvPageActionPrivate EvPageActionPrivate;
-typedef struct _EvPageActionClass EvPageActionClass;
-
-struct _EvPageAction
-{
- GtkAction parent;
-
- /*< private >*/
- EvPageActionPrivate *priv;
-};
-
-struct _EvPageActionClass
-{
- GtkActionClass parent_class;
-
- void (* activate_link) (EvPageAction *page_action,
- EvLink *link);
-};
-
-GType ev_page_action_get_type (void) G_GNUC_CONST;
-
-void ev_page_action_set_model (EvPageAction *page_action,
- EvDocumentModel *model);
-void ev_page_action_set_links_model (EvPageAction *page_action,
- GtkTreeModel *links_model);
-void ev_page_action_grab_focus (EvPageAction *page_action);
-
-G_END_DECLS
-
-#endif
diff --git a/previewer/ev-previewer.c b/previewer/ev-previewer.c
deleted file mode 100644
index 5924b8d..0000000
--- a/previewer/ev-previewer.c
+++ /dev/null
@@ -1,758 +0,0 @@
-/* -*- mode: c; indent-tabs-mode: t; c-basic-offset: 8 -*- */
-/* ev-previewer.c:
- * this file is part of evince, a gnome document viewer
- *
- * Copyright (C) 2009 Carlos Garcia Campos <carlosgc@gnome.org>
- * Copyright (C) 2010 Dan Nicholson <dbn.lists@gmail.com>
- *
- * Evince 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 of the License, or
- * (at your option) any later version.
- *
- * Evince 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., 51 Franklin Street, Fifth Floor, Boston, MA
- * 02110-1301, USA.
- */
-
-#include <config.h>
-
-#if GTKUNIXPRINT_ENABLED
-#include <gtk/gtkunixprint.h>
-#endif
-#include <glib/gi18n.h>
-#include <evince-view.h>
-#include "ev-page-action.h"
-
-#include "ev-previewer.h"
-
-struct _EvPreviewer {
- GtkVBox base_instance;
-
- EvDocumentModel *model;
- EvDocument *document;
-
- GtkActionGroup *action_group;
- GtkActionGroup *accels_group;
- GtkUIManager *ui_manager;
-
- GtkWidget *toplevel;
-
- GtkWidget *swindow;
- EvView *view;
-
- /* Printing */
- GtkPrintSettings *print_settings;
- GtkPageSetup *print_page_setup;
-#if GTKUNIXPRINT_ENABLED
- GtkPrinter *printer;
-#endif
- gchar *print_job_title;
- gchar *source_file;
-};
-
-struct _EvPreviewerClass {
- GtkVBoxClass base_class;
-};
-
-#define MIN_SCALE 0.05409
-#define MAX_SCALE 4.0
-
-G_DEFINE_TYPE (EvPreviewer, ev_previewer, GTK_TYPE_VBOX)
-
-#if GTKUNIXPRINT_ENABLED
-static void
-ev_previewer_error_dialog_run (EvPreviewer *pview,
- GError *error)
-{
- GtkWidget *dialog;
-
- if (!pview->toplevel)
- return;
-
- dialog = gtk_message_dialog_new (GTK_WINDOW (pview->toplevel),
- GTK_DIALOG_MODAL |
- GTK_DIALOG_DESTROY_WITH_PARENT,
- GTK_MESSAGE_ERROR,
- GTK_BUTTONS_CLOSE,
- "%s", _("Failed to print document"));
- gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog),
- "%s", error->message);
- gtk_dialog_run (GTK_DIALOG (dialog));
- gtk_widget_destroy (dialog);
-}
-#endif
-
-static void
-ev_previewer_close (GtkAction *action,
- EvPreviewer *pview)
-{
- if (pview->toplevel)
- gtk_widget_destroy (GTK_WIDGET (pview->toplevel));
-}
-
-static void
-ev_previewer_previous_page (GtkAction *action,
- EvPreviewer *pview)
-{
- ev_view_previous_page (pview->view);
-}
-
-static void
-ev_previewer_next_page (GtkAction *action,
- EvPreviewer *pview)
-{
- ev_view_next_page (pview->view);
-}
-
-static void
-ev_previewer_zoom_in (GtkAction *action,
- EvPreviewer *pview)
-{
- ev_document_model_set_sizing_mode (pview->model, EV_SIZING_FREE);
- ev_view_zoom_in (pview->view);
-}
-
-static void
-ev_previewer_zoom_out (GtkAction *action,
- EvPreviewer *pview)
-{
- ev_document_model_set_sizing_mode (pview->model, EV_SIZING_FREE);
- ev_view_zoom_out (pview->view);
-}
-
-static void
-ev_previewer_zoom_best_fit (GtkToggleAction *action,
- EvPreviewer *pview)
-{
- ev_document_model_set_sizing_mode (pview->model,
- gtk_toggle_action_get_active (action) ?
- EV_SIZING_BEST_FIT : EV_SIZING_FREE);
-}
-
-static void
-ev_previewer_zoom_page_width (GtkToggleAction *action,
- EvPreviewer *pview)
-{
- ev_document_model_set_sizing_mode (pview->model,
- gtk_toggle_action_get_active (action) ?
- EV_SIZING_FIT_WIDTH : EV_SIZING_FREE);
-}
-
-static void
-ev_previewer_action_page_activated (GtkAction *action,
- EvLink *link,
- EvPreviewer *pview)
-{
- ev_view_handle_link (pview->view, link);
- gtk_widget_grab_focus (GTK_WIDGET (pview->view));
-}
-
-static void
-ev_previewer_focus_page_selector (GtkAction *action,
- EvPreviewer *pview)
-{
- GtkAction *page_action;
-
- page_action = gtk_action_group_get_action (pview->action_group,
- "PageSelector");
- ev_page_action_grab_focus (EV_PAGE_ACTION (page_action));
-}
-
-static void
-ev_previewer_scroll_forward (GtkAction *action,
- EvPreviewer *pview)
-{
- ev_view_scroll (pview->view, GTK_SCROLL_PAGE_FORWARD, FALSE);
-}
-
-static void
-ev_previewer_scroll_backward (GtkAction *action,
- EvPreviewer *pview)
-{
- ev_view_scroll (pview->view, GTK_SCROLL_PAGE_BACKWARD, FALSE);
-}
-
-#if GTKUNIXPRINT_ENABLED
-static void
-ev_previewer_print_finished (GtkPrintJob *print_job,
- EvPreviewer *pview,
- GError *error)
-{
- if (error) {
- ev_previewer_error_dialog_run (pview, error);
- }
-
- g_object_unref (print_job);
- gtk_widget_destroy (GTK_WIDGET (pview));
-}
-
-static void
-ev_previewer_do_print (EvPreviewer *pview)
-{
- GtkPrintJob *job;
- GError *error = NULL;
-
- job = gtk_print_job_new (pview->print_job_title ?
- pview->print_job_title :
- pview->source_file,
- pview->printer,
- pview->print_settings,
- pview->print_page_setup);
- if (gtk_print_job_set_source_file (job, pview->source_file, &error)) {
- gtk_print_job_send (job,
- (GtkPrintJobCompleteFunc)ev_previewer_print_finished,
- pview, NULL);
- } else {
- ev_previewer_error_dialog_run (pview, error);
- g_error_free (error);
- }
-
- gtk_widget_hide (GTK_WIDGET (pview));
-}
-
-static void
-ev_previewer_enumerate_finished (EvPreviewer *pview)
-{
- if (pview->printer) {
- ev_previewer_do_print (pview);
- } else {
- GError *error = NULL;
-
- g_set_error (&error,
- GTK_PRINT_ERROR,
- GTK_PRINT_ERROR_GENERAL,
- _("The selected printer '%s' could not be found"),
- gtk_print_settings_get_printer (pview->print_settings));
-
- ev_previewer_error_dialog_run (pview, error);
- g_error_free (error);
- }
-}
-
-static gboolean
-ev_previewer_enumerate_printers (GtkPrinter *printer,
- EvPreviewer *pview)
-{
- const gchar *printer_name;
-
- printer_name = gtk_print_settings_get_printer (pview->print_settings);
- if ((printer_name
- && strcmp (printer_name, gtk_printer_get_name (printer)) == 0) ||
- (!printer_name && gtk_printer_is_default (printer))) {
- if (pview->printer)
- g_object_unref (pview->printer);
- pview->printer = g_object_ref (printer);
-
- return TRUE; /* we're done */
- }
-
- return FALSE; /* continue the enumeration */
-}
-
-static void
-ev_previewer_print (GtkAction *action,
- EvPreviewer *pview)
-{
- if (!pview->print_settings)
- pview->print_settings = gtk_print_settings_new ();
- if (!pview->print_page_setup)
- pview->print_page_setup = gtk_page_setup_new ();
- gtk_enumerate_printers ((GtkPrinterFunc)ev_previewer_enumerate_printers,
- pview,
- (GDestroyNotify)ev_previewer_enumerate_finished,
- FALSE);
-}
-#endif
-
-static void
-ev_previewer_load_job_finished (EvJob *job,
- EvDocumentModel *model)
-{
- if (ev_job_is_failed (job)) {
- g_warning ("%s", job->error->message);
- g_object_unref (job);
-
- return;
- }
- ev_document_model_set_document (model, job->document);
- g_object_unref (job);
-}
-
-static void
-ev_previewer_load_document (const gchar *filename,
- EvDocumentModel *model)
-{
- EvJob *job;
- gchar *uri;
- GFile *file;
-
- file = g_file_new_for_commandline_arg (filename);
- uri = g_file_get_uri (file);
- g_object_unref (file);
-
- job = ev_job_load_new (uri);
- g_signal_connect (job, "finished",
- G_CALLBACK (ev_previewer_load_job_finished),
- model);
- ev_job_scheduler_push_job (job, EV_JOB_PRIORITY_NONE);
- g_free (uri);
-}
-
-static const GtkActionEntry action_entries[] = {
- { "FileCloseWindow", GTK_STOCK_CLOSE, NULL, "<control>W",
- NULL,
- G_CALLBACK (ev_previewer_close) },
- { "GoPreviousPage", GTK_STOCK_GO_UP, N_("_Previous Page"), "<control>Page_Up",
- N_("Go to the previous page"),
- G_CALLBACK (ev_previewer_previous_page) },
- { "GoNextPage", GTK_STOCK_GO_DOWN, N_("_Next Page"), "<control>Page_Down",
- N_("Go to the next page"),
- G_CALLBACK (ev_previewer_next_page) },
- { "ViewZoomIn", GTK_STOCK_ZOOM_IN, NULL, "<control>plus",
- N_("Enlarge the document"),
- G_CALLBACK (ev_previewer_zoom_in) },
- { "ViewZoomOut", GTK_STOCK_ZOOM_OUT, NULL, "<control>minus",
- N_("Shrink the document"),
- G_CALLBACK (ev_previewer_zoom_out) },
-#if GTKUNIXPRINT_ENABLED
- { "PreviewPrint", GTK_STOCK_PRINT, N_("Print"), NULL,
- N_("Print this document"),
- G_CALLBACK (ev_previewer_print) }
-#endif
-};
-
-static const GtkActionEntry accel_entries[] = {
- { "Space", NULL, "", "space", NULL,
- G_CALLBACK (ev_previewer_scroll_forward) },
- { "ShiftSpace", NULL, "", "<shift>space", NULL,
- G_CALLBACK (ev_previewer_scroll_backward) },
- { "BackSpace", NULL, "", "BackSpace", NULL,
- G_CALLBACK (ev_previewer_scroll_backward) },
- { "ShiftBackSpace", NULL, "", "<shift>BackSpace", NULL,
- G_CALLBACK (ev_previewer_scroll_forward) },
- { "Return", NULL, "", "Return", NULL,
- G_CALLBACK (ev_previewer_scroll_forward) },
- { "ShiftReturn", NULL, "", "<shift>Return", NULL,
- G_CALLBACK (ev_previewer_scroll_backward) },
- { "p", GTK_STOCK_GO_UP, "", "p", NULL,
- G_CALLBACK (ev_previewer_previous_page) },
- { "n", GTK_STOCK_GO_DOWN, "", "n", NULL,
- G_CALLBACK (ev_previewer_next_page) },
- { "Plus", GTK_STOCK_ZOOM_IN, NULL, "plus", NULL,
- G_CALLBACK (ev_previewer_zoom_in) },
- { "CtrlEqual", GTK_STOCK_ZOOM_IN, NULL, "<control>equal", NULL,
- G_CALLBACK (ev_previewer_zoom_in) },
- { "Equal", GTK_STOCK_ZOOM_IN, NULL, "equal", NULL,
- G_CALLBACK (ev_previewer_zoom_in) },
- { "Minus", GTK_STOCK_ZOOM_OUT, NULL, "minus", NULL,
- G_CALLBACK (ev_previewer_zoom_out) },
- { "KpPlus", GTK_STOCK_ZOOM_IN, NULL, "KP_Add", NULL,
- G_CALLBACK (ev_previewer_zoom_in) },
- { "KpMinus", GTK_STOCK_ZOOM_OUT, NULL, "KP_Subtract", NULL,
- G_CALLBACK (ev_previewer_zoom_out) },
- { "CtrlKpPlus", GTK_STOCK_ZOOM_IN, NULL, "<control>KP_Add", NULL,
- G_CALLBACK (ev_previewer_zoom_in) },
- { "CtrlKpMinus", GTK_STOCK_ZOOM_OUT, NULL, "<control>KP_Subtract", NULL,
- G_CALLBACK (ev_previewer_zoom_out) },
- { "FocusPageSelector", NULL, "", "<control>l", NULL,
- G_CALLBACK (ev_previewer_focus_page_selector) }
-
-};
-
-static const GtkToggleActionEntry toggle_action_entries[] = {
- { "ViewBestFit", EV_STOCK_ZOOM_PAGE, N_("_Best Fit"), NULL,
- N_("Make the current document fill the window"),
- G_CALLBACK (ev_previewer_zoom_best_fit) },
- { "ViewPageWidth", EV_STOCK_ZOOM_WIDTH, N_("Fit Page _Width"), NULL,
- N_("Make the current document fill the window width"),
- G_CALLBACK (ev_previewer_zoom_page_width) }
-};
-
-static gboolean
-view_focus_changed (GtkWidget *widget,
- GdkEventFocus *event,
- EvPreviewer *pview)
-{
- if (pview->accels_group)
- gtk_action_group_set_sensitive (pview->accels_group, event->in);
-
- return FALSE;
-}
-
-static void
-view_sizing_mode_changed (EvDocumentModel *model,
- GParamSpec *pspec,
- EvPreviewer *pview)
-{
- EvSizingMode sizing_mode = ev_document_model_get_sizing_mode (model);
- GtkAction *action;
-
- action = gtk_action_group_get_action (pview->action_group, "ViewBestFit");
- g_signal_handlers_block_by_func (action,
- G_CALLBACK (ev_previewer_zoom_best_fit),
- pview);
- gtk_toggle_action_set_active (GTK_TOGGLE_ACTION (action),
- sizing_mode == EV_SIZING_BEST_FIT);
- g_signal_handlers_unblock_by_func (action,
- G_CALLBACK (ev_previewer_zoom_best_fit),
- pview);
-
- action = gtk_action_group_get_action (pview->action_group, "ViewPageWidth");
- g_signal_handlers_block_by_func (action,
- G_CALLBACK (ev_previewer_zoom_page_width),
- pview);
- gtk_toggle_action_set_active (GTK_TOGGLE_ACTION (action),
- sizing_mode == EV_SIZING_FIT_WIDTH);
- g_signal_handlers_unblock_by_func (action,
- G_CALLBACK (ev_previewer_zoom_page_width),
- pview);
-}
-
-static void
-ev_previewer_set_document (EvPreviewer *pview,
- GParamSpec *pspec,
- EvDocumentModel *model)
-{
- EvDocument *document = ev_document_model_get_document (model);
-
- pview->document = g_object_ref (document);
-
- g_signal_connect (model, "notify::sizing-mode",
- G_CALLBACK (view_sizing_mode_changed),
- pview);
- ev_view_set_loading (pview->view, FALSE);
- gtk_action_group_set_sensitive (pview->action_group, TRUE);
- gtk_action_group_set_sensitive (pview->accels_group, TRUE);
-}
-
-static void
-ev_previewer_connect_action_accelerators (EvPreviewer *pview)
-{
- GList *actions;
-
- gtk_ui_manager_ensure_update (pview->ui_manager);
-
- actions = gtk_action_group_list_actions (pview->action_group);
- g_list_foreach (actions, (GFunc)gtk_action_connect_accelerator, NULL);
- g_list_free (actions);
-}
-
-static void
-ev_previewer_dispose (GObject *object)
-{
- EvPreviewer *pview = EV_PREVIEWER (object);
-
- if (pview->model) {
- g_object_unref (pview->model);
- pview->model = NULL;
- }
-
- if (pview->document) {
- g_object_unref (pview->document);
- pview->document = NULL;
- }
-
- if (pview->action_group) {
- g_object_unref (pview->action_group);
- pview->action_group = NULL;
- }
-
- if (pview->accels_group) {
- g_object_unref (pview->accels_group);
- pview->accels_group = NULL;
- }
-
- if (pview->ui_manager) {
- g_object_unref (pview->ui_manager);
- pview->ui_manager = NULL;
- }
-
- if (pview->print_settings) {
- g_object_unref (pview->print_settings);
- pview->print_settings = NULL;
- }
-
- if (pview->print_page_setup) {
- g_object_unref (pview->print_page_setup);
- pview->print_page_setup = NULL;
- }
-
-#if GTKUNIXPRINT_ENABLED
- if (pview->printer) {
- g_object_unref (pview->printer);
- pview->printer = NULL;
- }
-#endif
-
- if (pview->print_job_title) {
- g_free (pview->print_job_title);
- pview->print_job_title = NULL;
- }
-
- if (pview->source_file) {
- g_free (pview->source_file);
- pview->source_file = NULL;
- }
-
- G_OBJECT_CLASS (ev_previewer_parent_class)->dispose (object);
-}
-
-static void
-ev_previewer_screen_changed (GtkWidget *widget,
- GdkScreen *previous_screen)
-{
- EvPreviewer *pview = EV_PREVIEWER (widget);
- GdkScreen *screen;
- gdouble dpi;
-
- if (!gtk_widget_has_screen (widget))
- return;
-
- screen = gtk_widget_get_screen (widget);
- dpi = ev_document_misc_get_screen_dpi (screen);
-
- ev_document_model_set_min_scale (pview->model, MIN_SCALE * dpi / 72.0);
- ev_document_model_set_max_scale (pview->model, MAX_SCALE * dpi / 72.0);
-}
-
-static void
-ev_previewer_hierarchy_changed (GtkWidget *widget,
- GtkWidget *previous_toplevel)
-{
- EvPreviewer *pview = EV_PREVIEWER (widget);
- GtkWidget *toplevel;
- GtkAccelGroup *accel_group;
-
- toplevel = gtk_widget_get_toplevel (widget);
- if (gtk_widget_is_toplevel (toplevel))
- pview->toplevel = toplevel;
- else {
- pview->toplevel = NULL;
- return;
- }
-
- accel_group = gtk_ui_manager_get_accel_group (pview->ui_manager);
- gtk_window_add_accel_group (GTK_WINDOW (pview->toplevel), accel_group);
-}
-
-static const gchar ui_string[] =
-"<ui>\n"
-" <toolbar name=\"PreviewToolbar\">\n"
-" <toolitem name=\"GoPreviousPage\" action=\"GoPreviousPage\"/>\n"
-" <toolitem name=\"GoNextPage\" action=\"GoNextPage\"/>\n"
-" <separator/>\n"
-" <toolitem name=\"PageSelector\" action=\"PageSelector\"/>\n"
-" <separator/>\n"
-" <toolitem name=\"ViewPageWidth\" action=\"ViewPageWidth\"/>\n"
-" <toolitem name=\"ViewBestFit\" action=\"ViewBestFit\"/>\n"
-" <toolitem name=\"ViewZoomIn\" action=\"ViewZoomIn\"/>\n"
-" <toolitem name=\"ViewZoomOut\" action=\"ViewZoomOut\"/>\n"
-#if GTKUNIXPRINT_ENABLED
-" <separator/>\n"
-" <toolitem name=\"PreviewPrint\" action=\"PreviewPrint\"/>\n"
-#endif
-" </toolbar>\n"
-"\n"
-" <accelerator name=\"FileCloseWindowAccel\" action=\"FileCloseWindow\"/>\n"
-" <accelerator name=\"SpaceAccel\" action=\"Space\"/>\n"
-" <accelerator name=\"ReturnAccel\" action=\"Return\"/>\n"
-" <accelerator name=\"BackSpaceAccel\" action=\"BackSpace\"/>\n"
-" <accelerator name=\"ShiftSpaceAccel\" action=\"ShiftSpace\"/>\n"
-" <accelerator name=\"ShiftBackSpaceAccel\" action=\"ShiftBackSpace\"/>\n"
-" <accelerator name=\"pAccel\" action=\"p\"/>\n"
-" <accelerator name=\"nAccel\" action=\"n\"/>\n"
-" <accelerator name=\"ShiftReturnAccel\" action=\"ShiftReturn\"/>\n"
-" <accelerator name=\"FocusPageSelectorAccel\" action=\"FocusPageSelector\"/>\n"
-" <accelerator name=\"PlusAccel\" action=\"Plus\"/>\n"
-" <accelerator name=\"MinusAccel\" action=\"Minus\"/>\n"
-" <accelerator name=\"Equal\" action=\"Equal\"/>\n"
-" <accelerator name=\"CtrlEqualAccel\" action=\"CtrlEqual\"/>\n"
-" <accelerator name=\"KpPlusAccel\" action=\"KpPlus\"/>\n"
-" <accelerator name=\"KpMinusAccel\" action=\"KpMinus\"/>\n"
-" <accelerator name=\"CtrlKpPlusAccel\" action=\"CtrlKpPlus\"/>\n"
-" <accelerator name=\"CtrlKpMinusAccel\" action=\"CtrlKpMinus\"/>\n"
-"</ui>\n";
-
-static void
-ev_previewer_init (EvPreviewer *pview)
-{
- GtkWidget *toolbar;
- GtkAction *action;
- GError *error = NULL;
-
- pview->model = ev_document_model_new();
- ev_document_model_set_sizing_mode (pview->model, EV_SIZING_FIT_WIDTH);
- g_signal_connect_swapped (pview->model, "notify::document",
- G_CALLBACK (ev_previewer_set_document),
- pview);
-
- pview->action_group = gtk_action_group_new ("PreviewerActions");
- gtk_action_group_set_translation_domain (pview->action_group, NULL);
- gtk_action_group_add_actions (pview->action_group, action_entries,
- G_N_ELEMENTS (action_entries),
- pview);
- gtk_action_group_add_toggle_actions (pview->action_group, toggle_action_entries,
- G_N_ELEMENTS (toggle_action_entries),
- pview);
- gtk_action_group_set_sensitive (pview->action_group, FALSE);
-
- action = g_object_new (EV_TYPE_PAGE_ACTION,
- "name", "PageSelector",
- "label", _("Page"),
- "tooltip", _("Select Page"),
- "icon_name", "text-x-generic",
- "visible_overflown", FALSE,
- NULL);
- ev_page_action_set_model (EV_PAGE_ACTION (action), pview->model);
- g_signal_connect (action, "activate_link",
- G_CALLBACK (ev_previewer_action_page_activated),
- pview);
- gtk_action_group_add_action (pview->action_group, action);
- g_object_unref (action);
-
- pview->accels_group = gtk_action_group_new ("PreviewerAccelerators");
- gtk_action_group_add_actions (pview->accels_group, accel_entries,
- G_N_ELEMENTS (accel_entries),
- pview);
- gtk_action_group_set_sensitive (pview->accels_group, FALSE);
-
- pview->ui_manager = gtk_ui_manager_new ();
- gtk_ui_manager_insert_action_group (pview->ui_manager,
- pview->action_group, 0);
- gtk_ui_manager_insert_action_group (pview->ui_manager,
- pview->accels_group, 1);
- if (!gtk_ui_manager_add_ui_from_string (pview->ui_manager, ui_string,
- sizeof(ui_string) - 1, &error)) {
- g_warning ("Failed to load ui from string: %s",
- error->message);
- g_error_free (error);
- }
-
- /* GTKUIManager connects actions accels only for menu items,
- * but not for tool items. See bug #612972.
- */
- ev_previewer_connect_action_accelerators (pview);
-
- view_sizing_mode_changed (pview->model, NULL, pview);
-
- toolbar = gtk_ui_manager_get_widget (pview->ui_manager, "/PreviewToolbar");
- gtk_box_pack_start (GTK_BOX (pview), toolbar, FALSE, FALSE, 0);
- gtk_widget_show (toolbar);
-
- pview->swindow = gtk_scrolled_window_new (NULL, NULL);
- gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (pview->swindow),
- GTK_POLICY_AUTOMATIC,
- GTK_POLICY_AUTOMATIC);
-
- pview->view = EV_VIEW (ev_view_new ());
- g_signal_connect_object (pview->view, "focus_in_event",
- G_CALLBACK (view_focus_changed),
- pview, 0);
- g_signal_connect_object (pview->view, "focus_out_event",
- G_CALLBACK (view_focus_changed),
- pview, 0);
- ev_view_set_model (pview->view, pview->model);
- ev_document_model_set_continuous (pview->model, FALSE);
- ev_view_set_loading (pview->view, TRUE);
-
- gtk_container_add (GTK_CONTAINER (pview->swindow), GTK_WIDGET (pview->view));
- gtk_widget_show (GTK_WIDGET (pview->view));
-
- gtk_box_pack_start (GTK_BOX (pview), pview->swindow, TRUE, TRUE, 0);
- gtk_widget_show (pview->swindow);
-}
-
-static void
-ev_previewer_class_init (EvPreviewerClass *klass)
-{
- GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
- GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
-
- gobject_class->dispose = ev_previewer_dispose;
-
- widget_class->screen_changed = ev_previewer_screen_changed;
- widget_class->hierarchy_changed = ev_previewer_hierarchy_changed;
-}
-
-/* Public methods */
-GtkWidget *
-ev_previewer_new (void)
-{
- return GTK_WIDGET (g_object_new (EV_TYPE_PREVIEWER, NULL));
-}
-
-void
-ev_previewer_set_print_settings (EvPreviewer *pview,
- const gchar *print_settings)
-{
- if (pview->print_settings)
- g_object_unref (pview->print_settings);
- if (pview->print_page_setup)
- g_object_unref (pview->print_page_setup);
- if (pview->print_job_title)
- g_free (pview->print_job_title);
-
- if (print_settings && g_file_test (print_settings, G_FILE_TEST_IS_REGULAR)) {
- GKeyFile *key_file;
- GError *error = NULL;
-
- key_file = g_key_file_new ();
- g_key_file_load_from_file (key_file,
- print_settings,
- G_KEY_FILE_KEEP_COMMENTS |
- G_KEY_FILE_KEEP_TRANSLATIONS,
- &error);
- if (!error) {
- GtkPrintSettings *psettings;
- GtkPageSetup *psetup;
- gchar *job_name;
-
- psettings = gtk_print_settings_new_from_key_file (key_file,
- "Print Settings",
- NULL);
- pview->print_settings = psettings ? psettings : gtk_print_settings_new ();
-
- psetup = gtk_page_setup_new_from_key_file (key_file,
- "Page Setup",
- NULL);
- pview->print_page_setup = psetup ? psetup : gtk_page_setup_new ();
-
- job_name = g_key_file_get_string (key_file,
- "Print Job", "title",
- NULL);
- if (job_name) {
- pview->print_job_title = job_name;
- if (pview->toplevel)
- gtk_window_set_title (GTK_WINDOW (pview->toplevel),
- job_name);
- }
- } else {
- pview->print_settings = gtk_print_settings_new ();
- pview->print_page_setup = gtk_page_setup_new ();
- g_error_free (error);
- }
-
- g_key_file_free (key_file);
- } else {
- pview->print_settings = gtk_print_settings_new ();
- pview->print_page_setup = gtk_page_setup_new ();
- }
-}
-
-void
-ev_previewer_set_source_file (EvPreviewer *pview,
- const gchar *source_file)
-{
- if (pview->source_file)
- g_free (pview->source_file);
- pview->source_file = g_strdup (source_file);
-
- ev_previewer_load_document (pview->source_file, pview->model);
-}
diff --git a/previewer/ev-previewer.h b/previewer/ev-previewer.h
deleted file mode 100644
index 7cf62f4..0000000
--- a/previewer/ev-previewer.h
+++ /dev/null
@@ -1,52 +0,0 @@
-/* ev-previewer-window.h:
- * this file is part of evince, a gnome document viewer
- *
- * Copyright (C) 2009 Carlos Garcia Campos <carlosgc@gnome.org>
- *
- * Evince 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 of the License, or
- * (at your option) any later version.
- *
- * Evince 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., 51 Franklin Street, Fifth Floor, Boston, MA
- * 02110-1301, USA.
- */
-
-#ifndef EV_PREVIEWER_H
-#define EV_PREVIEWER_H
-
-#include <gtk/gtk.h>
-
-#include <evince-document.h>
-#include <evince-view.h>
-
-G_BEGIN_DECLS
-
-#define EV_TYPE_PREVIEWER (ev_previewer_get_type())
-#define EV_PREVIEWER(object) (G_TYPE_CHECK_INSTANCE_CAST((object), EV_TYPE_PREVIEWER, EvPreviewer))
-#define EV_PREVIEWER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), EV_TYPE_PREVIEWER, EvPreviewerClass))
-#define EV_IS_PREVIEWER(object) (G_TYPE_CHECK_INSTANCE_TYPE((object), EV_TYPE_PREVIEWER))
-#define EV_IS_PREVIEWER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), EV_TYPE_PREVIEWER))
-#define EV_PREVIEWER_GET_CLASS(object) (G_TYPE_INSTANCE_GET_CLASS((object), EV_TYPE_PREVIEWER, EvPreviewerClass))
-
-typedef struct _EvPreviewer EvPreviewer;
-typedef struct _EvPreviewerClass EvPreviewerClass;
-
-GType ev_previewer_get_type (void) G_GNUC_CONST;
-GtkWidget *ev_previewer_new (void);
-
-void ev_previewer_set_print_settings (EvPreviewer *window,
- const gchar *print_settings);
-void ev_previewer_set_source_file (EvPreviewer *window,
- const gchar *source_file);
-
-G_END_DECLS
-
-#endif /* EV_PREVIEWER_WINDOW_H */
diff --git a/src/Makefile.am b/src/Makefile.am
index 1d58179..211e1c0 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -3,6 +3,5 @@ AM_CFLAGS = $(PLUGIN_CFLAGS) $(E_CFLAGS)
plugindir = $(libdir)/mozilla/plugins
plugin_LTLIBRARIES = libevbp.la
libevbp_la_LDFLAGS = -avoid-version -module
-libevbp_la_LIBADD = $(top_builddir)/previewer/libevpreviewer.la \
- $(PLUGIN_LIBS)
+libevbp_la_LIBADD = $(PLUGIN_LIBS)
libevbp_la_SOURCES = evbp.c evbp.h evbp-mime.h evbp-mime.c
diff --git a/src/evbp.c b/src/evbp.c
index 4f95bf2..de4b8a8 100644
--- a/src/evbp.c
+++ b/src/evbp.c
@@ -14,9 +14,7 @@
#include <prtypes.h>
#include <glib.h>
#include <glib/gi18n.h>
-#include <gtk/gtk.h>
#include <gdk/gdkx.h>
-#include <evince-document.h>
#ifdef PACKAGE_VERSION
#define EVBP_VERSION PACKAGE_VERSION
@@ -96,7 +94,15 @@ evbp_new(NPMIMEType pluginType, NPP instance, uint16_t mode,
instance->pdata = priv;
/* create new previewer */
- priv->pview = ev_previewer_new();
+ priv->model = ev_document_model_new();
+ priv->scroll = gtk_scrolled_window_new(NULL, NULL);
+ gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(priv->scroll),
+ GTK_POLICY_AUTOMATIC,
+ GTK_POLICY_AUTOMATIC);
+ priv->view = ev_view_new();
+ ev_view_set_model(EV_VIEW(priv->view), priv->model);
+ ev_view_set_loading(EV_VIEW(priv->view), TRUE);
+ gtk_container_add(GTK_CONTAINER(priv->scroll), priv->view);
return NPERR_NO_ERROR;
}
@@ -108,7 +114,10 @@ evbp_destroy(NPP instance, NPSavedData** save)
evbp_debug(NULL);
- g_object_unref(priv->pview);
+ g_object_unref(priv->document);
+ g_object_unref(priv->model);
+ g_object_unref(priv->view);
+ g_object_unref(priv->scroll);
npn_funcs->memfree(instance->pdata);
instance->pdata = NULL;
@@ -119,7 +128,6 @@ static NPError
evbp_set_window(NPP instance, NPWindow *window)
{
evbp_priv_t *priv = instance->pdata;
- GtkWidget *pview = priv->pview;
GdkNativeWindow id;
GtkWidget *plug;
@@ -137,9 +145,8 @@ evbp_set_window(NPP instance, NPWindow *window)
id = (GdkNativeWindow)(unsigned long)window->window;
evbp_debug("Plugging previewer into window id %u\n", id);
plug = gtk_plug_new(id);
- gtk_container_add(GTK_CONTAINER(plug), pview);
- gtk_widget_show(pview);
- gtk_widget_show(plug);
+ gtk_container_add(GTK_CONTAINER(plug), priv->scroll);
+ gtk_widget_show_all(plug);
return NPERR_NO_ERROR;
}
@@ -185,7 +192,9 @@ static void
evbp_stream_as_file(NPP instance, NPStream *stream, const char *fname)
{
evbp_priv_t *priv = instance->pdata;
- EvPreviewer *pview = EV_PREVIEWER(priv->pview);
+ GFile *file;
+ gchar *uri;
+ GError *error = NULL;
evbp_debug(NULL);
@@ -196,7 +205,21 @@ evbp_stream_as_file(NPP instance, NPStream *stream, const char *fname)
}
priv->filename = fname;
- ev_previewer_set_source_file(pview, fname);
+ /* convert the filename to a uri */
+ file = g_file_new_for_commandline_arg(fname);
+ uri = g_file_get_uri(file);
+ g_object_unref(file);
+
+ /* create a new document */
+ priv->document = ev_document_factory_get_document(uri, &error);
+ if (error) {
+ evbp_debug("Failed to load document \"%s\": %s\n", uri,
+ error->message);
+ g_error_free(error);
+ return;
+ }
+ ev_document_model_set_document(priv->model, priv->document);
+ ev_view_set_loading(EV_VIEW(priv->view), FALSE);
}
static void
@@ -340,7 +363,7 @@ NP_GetPluginVersion(void)
return EVBP_VERSION;
}
-char *
+const char *
NP_GetMIMEDescription(void)
{
GString *mimes;
diff --git a/src/evbp.h b/src/evbp.h
index 501a7e0..ee83434 100644
--- a/src/evbp.h
+++ b/src/evbp.h
@@ -2,13 +2,18 @@
#define EVBP_PLUGIN_H
#include <npapi.h>
-#include "previewer/ev-previewer.h"
+#include <evince-document.h>
+#include <evince-view.h>
+#include <gtk/gtk.h>
typedef struct evbp_priv {
NPP npp;
NPWindow *window;
const char *filename;
- GtkWidget *pview;
+ EvDocument *document;
+ EvDocumentModel *model;
+ GtkWidget *scroll;
+ GtkWidget *view;
} evbp_priv_t;
#endif /* EVBP_PLUGIN_H */
diff --git a/test/Makefile.am b/test/Makefile.am
index a395d08..8974c61 100644
--- a/test/Makefile.am
+++ b/test/Makefile.am
@@ -1,7 +1,6 @@
-AM_CFLAGS = $(PREVIEWER_CFLAGS) $(E_CFLAGS)
-LDADD = $(top_builddir)/previewer/libevpreviewer.la $(PREVIEWER_LIBS)
+AM_CFLAGS = $(PLUGIN_CFLAGS) $(E_CFLAGS)
+LDADD = $(PLUGIN_LIBS)
-noinst_PROGRAMS = previewer mime
+noinst_PROGRAMS = mime
mime_SOURCES = mime.c $(top_srcdir)/src/evbp-mime.c
-mime_LDADD = $(PREVIEWER_LIBS)