evince r3578 - in trunk: . data previewer
- From: carlosgc svn gnome org
- To: svn-commits-list gnome org
- Subject: evince r3578 - in trunk: . data previewer
- Date: Wed, 8 Apr 2009 13:10:12 +0000 (UTC)
Author: carlosgc
Date: Wed Apr 8 13:10:12 2009
New Revision: 3578
URL: http://svn.gnome.org/viewvc/evince?rev=3578&view=rev
Log:
2009-04-08 Carlos Garcia Campos <carlosgc gnome org>
* configure.ac:
* Makefile.am:
* data/Makefile.am:
* previewer/Makefile.am:
* previewer/ev-previewer-window.[ch]:
* previewer/ev-previewer.c:
Add evince-previewer as a separate applicaton that implements the
preview mode.
Added:
trunk/previewer/
trunk/previewer/Makefile.am
trunk/previewer/ev-previewer-window.c (contents, props changed)
trunk/previewer/ev-previewer-window.h (contents, props changed)
trunk/previewer/ev-previewer.c (contents, props changed)
Modified:
trunk/ChangeLog
trunk/Makefile.am
trunk/configure.ac
trunk/data/Makefile.am
Modified: trunk/Makefile.am
==============================================================================
--- trunk/Makefile.am (original)
+++ trunk/Makefile.am Wed Apr 8 13:10:12 2009
@@ -15,6 +15,10 @@
SUBDIRS += thumbnailer
endif
+if ENABLE_PREVIEWER
+SUBDIRS += previewer
+endif
+
NULL =
pkgconfigdir = $(libdir)/pkgconfig
Modified: trunk/configure.ac
==============================================================================
--- trunk/configure.ac (original)
+++ trunk/configure.ac Wed Apr 8 13:10:12 2009
@@ -121,6 +121,7 @@
PKG_CHECK_MODULES(LIBVIEW, gtk+-2.0 >= $GTK_REQUIRED gthread-2.0 gio-2.0 >= $GLIB_REQUIRED)
PKG_CHECK_MODULES(BACKEND, gtk+-2.0 >= $GTK_REQUIRED)
PKG_CHECK_MODULES(FRONTEND_CORE, gtk+-2.0 >= $GTK_REQUIRED gthread-2.0 gio-2.0 >= $GLIB_REQUIRED)
+PKG_CHECK_MODULES(PREVIEWER, gtk+-2.0 >= $GTK_REQUIRED gtk+-unix-print-2.0 >= $GTK_REQUIRED gthread-2.0 gio-2.0 >= $GLIB_REQUIRED)
PKG_CHECK_MODULES(SHELL_CORE, libxml-2.0 >= $LIBXML_REQUIRED gtk+-2.0 >= $GTK_REQUIRED gtk+-unix-print-2.0 >= $GTK_REQUIRED gio-2.0 >= $GLIB_REQUIRED gnome-icon-theme >= $GNOME_ICON_THEME_REQUIRED gthread-2.0)
if test "$os_win32" = no; then
@@ -276,6 +277,28 @@
[ENABLE_THUMBNAILER=yes]) dnl Default value
AM_CONDITIONAL(ENABLE_THUMBNAILER, test x$ENABLE_THUMBNAILER = "xyes")
+dnl Check for previewer build
+AC_ARG_ENABLE(previewer,
+ AC_HELP_STRING([--disable-previewer],[disable the GNOME Document Previewer]),
+ [case "${enableval}" in
+ yes) ENABLE_PREVIEWER=yes ;;
+ no) ENABLE_PREVIEWER=no ;;
+ *) AC_MSG_ERROR(bad value ${enableval} for --enable-previewer) ;;
+ esac],
+ [ENABLE_PREVIEWER=yes]) dnl Default value
+if test x$ENABLE_PREVIEWER = "xyes" ; then
+ PKG_CHECK_MODULES(PREVIEWER, gtk+-2.0 >= $GTK_REQUIRED gtk+-unix-print-2.0 >= $GTK_REQUIRED gthread-2.0 gio-2.0 >= $GLIB_REQUIRED,
+ [ENABLE_PREVIEWER=yes],[ENABLE_PREVIEWER=no])
+ if test x$ENABLE_PREVIEWER = "xno" ; then
+ AC_MSG_WARN([Previewer support is disabled since gtk+-unix-print $GTK_REQUIRED or higher was not found])
+ fi
+fi
+AM_CONDITIONAL(ENABLE_PREVIEWER, test x$ENABLE_PREVIEWER = "xyes")
+PREVIEWER_CFLAGS="$PREVIEWER_CFLAGS $DEBUG_FLAGS"
+PREVIEWER_LIBS="$PREVIEWER_LIBS -lz"
+AC_SUBST(PREVIEWER_CFLAGS)
+AC_SUBST(PREVIEWER_LIBS)
+
dnl GConf configuration
AM_GCONF_SOURCE_2
@@ -607,6 +630,7 @@
libview/Makefile
Makefile
po/Makefile.in
+previewer/Makefile
properties/Makefile
shell/Makefile
test/Makefile
@@ -625,6 +649,7 @@
DBUS Support.......: $enable_dbus
Nautilus Plugin....: $HAVE_NAUTILUS
Thumbnailer........: $ENABLE_THUMBNAILER
+ Previewer..........: $ENABLE_PREVIEWER
Gtk-Doc Support....: $enable_gtk_doc
Debug mode.........: $enable_debug
GObj. Introspection: $enable_introspection
Modified: trunk/data/Makefile.am
==============================================================================
--- trunk/data/Makefile.am (original)
+++ trunk/data/Makefile.am Wed Apr 8 13:10:12 2009
@@ -18,8 +18,11 @@
ui_DATA = \
evince-ui.xml \
evince-toolbar.xml \
- hand-open.png \
- $(NULL)
+ hand-open.png
+
+if ENABLE_PREVIEWER
+ui_DATA += evince-previewer-ui.xml
+endif
#
# Desktop file
Added: trunk/previewer/Makefile.am
==============================================================================
--- (empty file)
+++ trunk/previewer/Makefile.am Wed Apr 8 13:10:12 2009
@@ -0,0 +1,30 @@
+
+bin_PROGRAMS = evince-previewer
+
+evince_previewer_SOURCES = \
+ ev-previewer.c \
+ ev-previewer-window.h \
+ ev-previewer-window.c
+
+evince_previewer_CPPFLAGS = \
+ -DDATADIR=\"$(pkgdatadir)\" \
+ -I$(top_srcdir) \
+ -I$(top_builddir) \
+ -I$(top_srcdir)/libdocument \
+ -I$(top_srcdir)/libview \
+ -I$(top_srcdir)/libmisc \
+ -DGNOMELOCALEDIR=\"$(datadir)/locale\" \
+ $(AM_CPPFLAGS)
+
+evince_previewer_CFLAGS = \
+ $(PREVIEWER_CFLAGS) \
+ $(WARN_CFLAGS) \
+ $(DISABLE_DEPRECATED) \
+ $(AM_CFLAGS)
+
+evince_previewer_LDADD = \
+ $(top_builddir)/libdocument/libevdocument.la \
+ $(top_builddir)/libview/libevview.la \
+ $(top_builddir)/libmisc/libevmisc.la \
+ $(PREVIEWER_LIBS)
+
Added: trunk/previewer/ev-previewer-window.c
==============================================================================
--- (empty file)
+++ trunk/previewer/ev-previewer-window.c Wed Apr 8 13:10:12 2009
@@ -0,0 +1,572 @@
+/* ev-previewer-window.c:
+ * 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+#include <config.h>
+
+#include <gtk/gtkunixprint.h>
+#include <glib/gi18n.h>
+#include <evince-view.h>
+#include "ev-stock-icons.h"
+#include "ev-page-action.h"
+
+#include "ev-previewer-window.h"
+
+struct _EvPreviewerWindow {
+ GtkWindow base_instance;
+
+ EvDocument *document;
+
+ GtkActionGroup *action_group;
+ GtkUIManager *ui_manager;
+
+ GtkWidget *swindow;
+ EvView *view;
+ gdouble dpi;
+
+ /* Printing */
+ GtkPrintSettings *print_settings;
+ GtkPageSetup *print_page_setup;
+ GtkPrinter *printer;
+ gchar *print_job_title;
+ gchar *source_file;
+};
+
+struct _EvPreviewerWindowClass {
+ GtkWindowClass base_class;
+};
+
+G_DEFINE_TYPE (EvPreviewerWindow, ev_previewer_window, GTK_TYPE_WINDOW)
+
+static gdouble
+get_screen_dpi (GtkWindow *window)
+{
+ GdkScreen *screen;
+ gdouble xdpi, ydpi;
+
+ screen = gtk_window_get_screen (window);
+
+ xdpi = 25.4 * gdk_screen_get_width (screen) / gdk_screen_get_width_mm (screen);
+ ydpi = 25.4 * gdk_screen_get_height (screen) / gdk_screen_get_height_mm (screen);
+
+ return (xdpi + ydpi) / 2.0;
+}
+
+static void
+ev_previewer_window_set_view_size (EvPreviewerWindow *window)
+{
+ gint width, height;
+ GtkRequisition vsb_requisition;
+ GtkRequisition hsb_requisition;
+ gint scrollbar_spacing;
+
+ if (!window->view)
+ return;
+
+ /* Calculate the width available for the content */
+ width = window->swindow->allocation.width;
+ height = window->swindow->allocation.height;
+
+ if (gtk_scrolled_window_get_shadow_type (GTK_SCROLLED_WINDOW (window->swindow)) == GTK_SHADOW_IN) {
+ width -= 2 * GTK_WIDGET (window->view)->style->xthickness;
+ height -= 2 * GTK_WIDGET (window->view)->style->ythickness;
+ }
+
+ gtk_widget_size_request (GTK_SCROLLED_WINDOW (window->swindow)->vscrollbar,
+ &vsb_requisition);
+ gtk_widget_size_request (GTK_SCROLLED_WINDOW (window->swindow)->hscrollbar,
+ &hsb_requisition);
+ gtk_widget_style_get (window->swindow,
+ "scrollbar_spacing",
+ &scrollbar_spacing,
+ NULL);
+
+ ev_view_set_zoom_for_size (window->view,
+ MAX (1, width),
+ MAX (1, height),
+ vsb_requisition.width + scrollbar_spacing,
+ hsb_requisition.height + scrollbar_spacing);
+}
+
+static void
+ev_previewer_window_error_dialog_run (EvPreviewerWindow *window,
+ GError *error)
+{
+ GtkWidget *dialog;
+
+ dialog = gtk_message_dialog_new (GTK_WINDOW (window),
+ 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);
+}
+
+static void
+ev_previewer_window_previous_page (GtkAction *action,
+ EvPreviewerWindow *window)
+{
+ ev_view_previous_page (window->view);
+}
+
+static void
+ev_previewer_window_next_page (GtkAction *action,
+ EvPreviewerWindow *window)
+{
+ ev_view_next_page (window->view);
+}
+
+static void
+ev_previewer_window_zoom_in (GtkAction *action,
+ EvPreviewerWindow *window)
+{
+ ev_view_set_sizing_mode (window->view, EV_SIZING_FREE);
+ ev_view_zoom_in (window->view);
+}
+
+static void
+ev_previewer_window_zoom_out (GtkAction *action,
+ EvPreviewerWindow *window)
+{
+ ev_view_set_sizing_mode (window->view, EV_SIZING_FREE);
+ ev_view_zoom_out (window->view);
+}
+
+static void
+ev_previewer_window_zoom_best_fit (GtkToggleAction *action,
+ EvPreviewerWindow *window)
+{
+ if (gtk_toggle_action_get_active (action)) {
+ ev_view_set_sizing_mode (window->view, EV_SIZING_BEST_FIT);
+ ev_previewer_window_set_view_size (window);
+ } else {
+ ev_view_set_sizing_mode (window->view, EV_SIZING_FREE);
+ }
+}
+
+static void
+ev_previewer_window_zoom_page_width (GtkToggleAction *action,
+ EvPreviewerWindow *window)
+{
+ if (gtk_toggle_action_get_active (action)) {
+ ev_view_set_sizing_mode (window->view, EV_SIZING_FIT_WIDTH);
+ ev_previewer_window_set_view_size (window);
+ } else {
+ ev_view_set_sizing_mode (window->view, EV_SIZING_FREE);
+ }
+}
+
+static void
+ev_previewer_window_action_page_activated (GtkAction *action,
+ EvLink *link,
+ EvPreviewerWindow *window)
+{
+ ev_view_handle_link (window->view, link);
+ gtk_widget_grab_focus (GTK_WIDGET (window->view));
+}
+
+static void
+ev_previewer_window_print_finished (GtkPrintJob *print_job,
+ EvPreviewerWindow *window,
+ GError *error)
+{
+ if (error) {
+ ev_previewer_window_error_dialog_run (window, error);
+ }
+
+ g_object_unref (print_job);
+ gtk_widget_destroy (GTK_WIDGET (window));
+}
+
+static void
+ev_previewer_window_do_print (EvPreviewerWindow *window)
+{
+ GtkPrintJob *job;
+ GError *error = NULL;
+
+ job = gtk_print_job_new (window->print_job_title ?
+ window->print_job_title :
+ window->source_file,
+ window->printer,
+ window->print_settings,
+ window->print_page_setup);
+ if (gtk_print_job_set_source_file (job, window->source_file, &error)) {
+ gtk_print_job_send (job,
+ (GtkPrintJobCompleteFunc)ev_previewer_window_print_finished,
+ window, NULL);
+ } else {
+ ev_previewer_window_error_dialog_run (window, error);
+ g_error_free (error);
+ }
+
+ gtk_widget_hide (GTK_WIDGET (window));
+}
+
+static void
+ev_previewer_window_enumerate_finished (EvPreviewerWindow *window)
+{
+ if (window->printer) {
+ ev_previewer_window_do_print (window);
+ } 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 (window->print_settings));
+
+ ev_previewer_window_error_dialog_run (window, error);
+ g_error_free (error);
+ }
+}
+
+static gboolean
+ev_previewer_window_enumerate_printers (GtkPrinter *printer,
+ EvPreviewerWindow *window)
+{
+ const gchar *printer_name;
+
+ printer_name = gtk_print_settings_get_printer (window->print_settings);
+ if ((printer_name
+ && strcmp (printer_name, gtk_printer_get_name (printer)) == 0) ||
+ (!printer_name && gtk_printer_is_default (printer))) {
+ if (window->printer)
+ g_object_unref (window->printer);
+ window->printer = g_object_ref (printer);
+
+ return TRUE; /* we're done */
+ }
+
+ return FALSE; /* continue the enumeration */
+}
+
+static void
+ev_previewer_window_print (GtkAction *action,
+ EvPreviewerWindow *window)
+{
+ if (!window->print_settings)
+ window->print_settings = gtk_print_settings_new ();
+ if (!window->print_page_setup)
+ window->print_page_setup = gtk_page_setup_new ();
+ gtk_enumerate_printers ((GtkPrinterFunc)ev_previewer_window_enumerate_printers,
+ window,
+ (GDestroyNotify)ev_previewer_window_enumerate_finished,
+ FALSE);
+}
+
+static const GtkActionEntry action_entries[] = {
+ { "GoPreviousPage", GTK_STOCK_GO_UP, N_("_Previous Page"), "<control>Page_Up",
+ N_("Go to the previous page"),
+ G_CALLBACK (ev_previewer_window_previous_page) },
+ { "GoNextPage", GTK_STOCK_GO_DOWN, N_("_Next Page"), "<control>Page_Down",
+ N_("Go to the next page"),
+ G_CALLBACK (ev_previewer_window_next_page) },
+ { "ViewZoomIn", GTK_STOCK_ZOOM_IN, NULL, "<control>plus",
+ N_("Enlarge the document"),
+ G_CALLBACK (ev_previewer_window_zoom_in) },
+ { "ViewZoomOut", GTK_STOCK_ZOOM_OUT, NULL, "<control>minus",
+ N_("Shrink the document"),
+ G_CALLBACK (ev_previewer_window_zoom_out) },
+ { "PreviewPrint", GTK_STOCK_PRINT, N_("Print"), NULL,
+ N_("Print this document"),
+ G_CALLBACK (ev_previewer_window_print) }
+};
+
+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_window_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_window_zoom_page_width) }
+};
+
+/* EvView callbacks */
+static void
+view_sizing_mode_changed (EvView *view,
+ GParamSpec *pspec,
+ EvPreviewerWindow *window)
+{
+ EvSizingMode sizing_mode;
+ GtkAction *action;
+
+ if (!window->view)
+ return;
+
+ g_object_get (window->view,
+ "sizing_mode", &sizing_mode,
+ NULL);
+
+ action = gtk_action_group_get_action (window->action_group, "ViewBestFit");
+ g_signal_handlers_block_by_func (action,
+ G_CALLBACK (ev_previewer_window_zoom_best_fit),
+ window);
+ 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_window_zoom_best_fit),
+ window);
+
+ action = gtk_action_group_get_action (window->action_group, "ViewPageWidth");
+ g_signal_handlers_block_by_func (action,
+ G_CALLBACK (ev_previewer_window_zoom_page_width),
+ window);
+ 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_window_zoom_page_width),
+ window);
+}
+
+static void
+ev_previewer_window_dispose (GObject *object)
+{
+ EvPreviewerWindow *window = EV_PREVIEWER_WINDOW (object);
+
+ if (window->document) {
+ g_object_unref (window->document);
+ window->document = NULL;
+ }
+
+ if (window->action_group) {
+ g_object_unref (window->action_group);
+ window->action_group = NULL;
+ }
+
+ if (window->ui_manager) {
+ g_object_unref (window->ui_manager);
+ window->ui_manager = NULL;
+ }
+
+ if (window->print_settings) {
+ g_object_unref (window->print_settings);
+ window->print_settings = NULL;
+ }
+
+ if (window->print_page_setup) {
+ g_object_unref (window->print_page_setup);
+ window->print_page_setup = NULL;
+ }
+
+ if (window->printer) {
+ g_object_unref (window->printer);
+ window->printer = NULL;
+ }
+
+ if (window->print_job_title) {
+ g_free (window->print_job_title);
+ window->print_job_title = NULL;
+ }
+
+ if (window->source_file) {
+ g_free (window->source_file);
+ window->source_file = NULL;
+ }
+
+ G_OBJECT_CLASS (ev_previewer_window_parent_class)->dispose (object);
+}
+
+static void
+ev_previewer_window_init (EvPreviewerWindow *window)
+{
+ GtkWidget *vbox;
+ GtkWidget *toolbar;
+ GtkAction *action;
+ GError *error = NULL;
+
+ gtk_window_set_default_size (GTK_WINDOW (window), 600, 600);
+
+ window->action_group = gtk_action_group_new ("PreviewerActions");
+ gtk_action_group_set_translation_domain (window->action_group, NULL);
+ gtk_action_group_add_actions (window->action_group, action_entries,
+ G_N_ELEMENTS (action_entries),
+ window);
+ gtk_action_group_add_toggle_actions (window->action_group, toggle_action_entries,
+ G_N_ELEMENTS (toggle_action_entries),
+ window);
+ gtk_action_group_set_sensitive (window->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);
+ g_signal_connect (action, "activate_link",
+ G_CALLBACK (ev_previewer_window_action_page_activated),
+ window);
+ gtk_action_group_add_action (window->action_group, action);
+ g_object_unref (action);
+
+ window->ui_manager = gtk_ui_manager_new ();
+ gtk_ui_manager_insert_action_group (window->ui_manager,
+ window->action_group, 0);
+ gtk_window_add_accel_group (GTK_WINDOW (window),
+ gtk_ui_manager_get_accel_group (window->ui_manager));
+ if (!gtk_ui_manager_add_ui_from_file (window->ui_manager,
+ DATADIR"/evince-previewer-ui.xml",
+ &error)) {
+ g_warning ("Failed to load ui from evince-previewer-ui.xml: %s", error->message);
+ g_error_free (error);
+ }
+
+ vbox = gtk_vbox_new (FALSE, 0);
+
+ toolbar = gtk_ui_manager_get_widget (window->ui_manager, "/PreviewToolbar");
+ gtk_box_pack_start (GTK_BOX (vbox), toolbar, FALSE, FALSE, 0);
+ gtk_widget_show (toolbar);
+
+ window->swindow = gtk_scrolled_window_new (NULL, NULL);
+ gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (window->swindow),
+ GTK_POLICY_AUTOMATIC,
+ GTK_POLICY_AUTOMATIC);
+
+ window->view = EV_VIEW (ev_view_new ());
+ g_signal_connect (window->view, "notify::sizing-mode",
+ G_CALLBACK (view_sizing_mode_changed),
+ window);
+ g_signal_connect_swapped (window->view, "zoom_invalid",
+ G_CALLBACK (ev_previewer_window_set_view_size),
+ window);
+
+ ev_view_set_screen_dpi (window->view, get_screen_dpi (GTK_WINDOW (window)));
+ ev_view_set_continuous (window->view, FALSE);
+ ev_view_set_sizing_mode (window->view, EV_SIZING_FIT_WIDTH);
+ ev_view_set_loading (window->view, TRUE);
+ view_sizing_mode_changed (window->view, NULL, window);
+
+ gtk_container_add (GTK_CONTAINER (window->swindow), GTK_WIDGET (window->view));
+ gtk_widget_show (GTK_WIDGET (window->view));
+
+ gtk_box_pack_start (GTK_BOX (vbox), window->swindow, TRUE, TRUE, 0);
+ gtk_widget_show (window->swindow);
+
+ gtk_container_add (GTK_CONTAINER (window), vbox);
+ gtk_widget_show (vbox);
+}
+
+static void
+ev_previewer_window_class_init (EvPreviewerWindowClass *klass)
+{
+ GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
+
+ gobject_class->dispose = ev_previewer_window_dispose;
+}
+
+/* Public methods */
+GtkWidget *
+ev_previewer_window_new (void)
+{
+ return GTK_WIDGET (g_object_new (EV_TYPE_PREVIEWER_WINDOW, NULL));
+}
+
+void
+ev_previewer_window_set_document (EvPreviewerWindow *window,
+ EvDocument *document)
+{
+ GtkAction *action;
+
+ g_return_if_fail (EV_IS_PREVIEWER_WINDOW (window));
+ g_return_if_fail (EV_IS_DOCUMENT (document));
+
+ if (window->document)
+ return;
+
+ action = gtk_action_group_get_action (window->action_group, "PageSelector");
+ ev_page_action_set_document (EV_PAGE_ACTION (action), document);
+ gtk_action_group_set_sensitive (window->action_group, TRUE);
+
+ window->document = g_object_ref (document);
+ ev_view_set_document (window->view, document);
+ ev_view_set_zoom (window->view,
+ get_screen_dpi (GTK_WINDOW (window)) / 72.0,
+ FALSE);
+ ev_view_set_loading (window->view, FALSE);
+}
+
+void
+ev_previewer_window_set_print_settings (EvPreviewerWindow *window,
+ const gchar *print_settings)
+{
+ if (window->print_settings)
+ g_object_unref (window->print_settings);
+ if (window->print_page_setup)
+ g_object_unref (window->print_page_setup);
+ if (window->print_job_title)
+ g_free (window->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);
+ window->print_settings = psettings ? psettings : gtk_print_settings_new ();
+
+ psetup = gtk_page_setup_new_from_key_file (key_file,
+ "Page Setup",
+ NULL);
+ window->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) {
+ window->print_job_title = job_name;
+ gtk_window_set_title (GTK_WINDOW (window), job_name);
+ }
+ } else {
+ window->print_settings = gtk_print_settings_new ();
+ window->print_page_setup = gtk_page_setup_new ();
+ g_error_free (error);
+ }
+
+ g_key_file_free (key_file);
+ } else {
+ window->print_settings = gtk_print_settings_new ();
+ window->print_page_setup = gtk_page_setup_new ();
+ }
+}
+
+void
+ev_previewer_window_set_source_file (EvPreviewerWindow *window,
+ const gchar *source_file)
+{
+ if (window->source_file)
+ g_free (window->source_file);
+ window->source_file = g_strdup (source_file);
+}
Added: trunk/previewer/ev-previewer-window.h
==============================================================================
--- (empty file)
+++ trunk/previewer/ev-previewer-window.h Wed Apr 8 13:10:12 2009
@@ -0,0 +1,52 @@
+/* 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+#ifndef EV_PREVIEWER_WINDOW_H
+#define EV_PREVIEWER_WINDOW_H
+
+#include <gtk/gtk.h>
+
+#include <evince-document.h>
+
+G_BEGIN_DECLS
+
+#define EV_TYPE_PREVIEWER_WINDOW (ev_previewer_window_get_type())
+#define EV_PREVIEWER_WINDOW(object) (G_TYPE_CHECK_INSTANCE_CAST((object), EV_TYPE_PREVIEWER_WINDOW, EvPreviewerWindow))
+#define EV_PREVIEWER_WINDOW_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), EV_TYPE_PREVIEWER_WINDOW, EvPreviewerWindowClass))
+#define EV_IS_PREVIEWER_WINDOW(object) (G_TYPE_CHECK_INSTANCE_TYPE((object), EV_TYPE_PREVIEWER_WINDOW))
+#define EV_IS_PREVIEWER_WINDOW_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), EV_TYPE_PREVIEWER_WINDOW))
+#define EV_PREVIEWER_WINDOW_GET_CLASS(object) (G_TYPE_INSTANCE_GET_CLASS((object), EV_TYPE_PREVIEWER_WINDOW, EvPreviewerWindowClass))
+
+typedef struct _EvPreviewerWindow EvPreviewerWindow;
+typedef struct _EvPreviewerWindowClass EvPreviewerWindowClass;
+
+GType ev_previewer_window_get_type (void) G_GNUC_CONST;
+GtkWidget *ev_previewer_window_new (void);
+
+void ev_previewer_window_set_document (EvPreviewerWindow *window,
+ EvDocument *document);
+void ev_previewer_window_set_print_settings (EvPreviewerWindow *window,
+ const gchar *print_settings);
+void ev_previewer_window_set_source_file (EvPreviewerWindow *window,
+ const gchar *source_file);
+
+G_END_DECLS
+
+#endif /* EV_PREVIEWER_WINDOW_H */
Added: trunk/previewer/ev-previewer.c
==============================================================================
--- (empty file)
+++ trunk/previewer/ev-previewer.c Wed Apr 8 13:10:12 2009
@@ -0,0 +1,167 @@
+/* ev-previewer.c:
+ * 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+#include <config.h>
+
+#include <gtk/gtk.h>
+#include <glib/gi18n.h>
+#include <evince-document.h>
+#include <evince-view.h>
+#include "ev-stock-icons.h"
+
+#include "ev-previewer-window.h"
+
+static gboolean unlink_temp_file = FALSE;
+static const gchar *print_settings;
+static const gchar **filenames;
+
+static const GOptionEntry goption_options[] = {
+ { "unlink-tempfile", 'u', 0, G_OPTION_ARG_NONE, &unlink_temp_file, N_("Delete the temporary file"), NULL },
+ { "print-settings", 'p', 0, G_OPTION_ARG_FILENAME, &print_settings, N_("Print settings file"), N_("FILE") },
+ { G_OPTION_REMAINING, 0, 0, G_OPTION_ARG_FILENAME_ARRAY, &filenames, NULL, N_("FILE") },
+ { NULL }
+};
+
+static void
+ev_previewer_unlink_tempfile (const gchar *filename)
+{
+ GFile *file, *tempdir;
+
+ if (!unlink_temp_file)
+ return;
+
+ file = g_file_new_for_path (filename);
+ tempdir = g_file_new_for_path (g_get_tmp_dir ());
+
+ if (g_file_has_prefix (file, tempdir)) {
+ g_file_delete (file, NULL, NULL);
+ }
+
+ g_object_unref (file);
+ g_object_unref (tempdir);
+}
+
+static void
+ev_previewer_load_job_finished (EvJob *job,
+ EvPreviewerWindow *window)
+{
+ if (ev_job_is_failed (job)) {
+ g_warning ("%s", job->error->message);
+ g_object_unref (job);
+
+ return;
+ }
+
+ ev_previewer_window_set_document (window, job->document);
+ g_object_unref (job);
+}
+
+static void
+ev_previewer_load_document (const gchar *filename,
+ EvPreviewerWindow *window)
+{
+ EvJob *job;
+ gchar *uri;
+
+ uri = g_filename_to_uri (filename, NULL, NULL);
+ job = ev_job_load_new (uri);
+ g_signal_connect (job, "finished",
+ G_CALLBACK (ev_previewer_load_job_finished),
+ window);
+ ev_job_scheduler_push_job (job, EV_JOB_PRIORITY_NONE);
+ g_free (uri);
+}
+
+gint
+main (gint argc, gchar **argv)
+{
+ GtkWidget *window;
+ GOptionContext *context;
+ const gchar *filename;
+ GError *error = NULL;
+
+ /* Init glib threads asap */
+ if (!g_thread_supported ())
+ g_thread_init (NULL);
+
+#ifdef ENABLE_NLS
+ /* Initialize the i18n stuff */
+ bindtextdomain (GETTEXT_PACKAGE, GNOMELOCALEDIR);
+ bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
+ textdomain (GETTEXT_PACKAGE);
+#endif
+
+ context = g_option_context_new (_("GNOME Document Previewer"));
+ g_option_context_set_translation_domain (context, GETTEXT_PACKAGE);
+ g_option_context_add_main_entries (context, goption_options, GETTEXT_PACKAGE);
+
+ g_option_context_add_group (context, gtk_get_option_group (TRUE));
+
+ if (!g_option_context_parse (context, &argc, &argv, &error)) {
+ g_warning ("Error parsing command line arguments: %s", error->message);
+ g_error_free (error);
+ g_option_context_free (context);
+
+ return 1;
+ }
+ g_option_context_free (context);
+
+ if (!filenames) {
+ g_warning ("File argument is required");
+
+ return 1;
+ }
+
+ filename = filenames[0];
+
+ if (!g_file_test (filename, G_FILE_TEST_IS_REGULAR)) {
+ g_warning ("Filename \"%s\" does not exist or is not a regular file", filename);
+
+ return 1;
+ }
+
+ if (!ev_init ())
+ return 1;
+
+ ev_stock_icons_init ();
+
+ g_set_application_name (_("GNOME Document Previewer"));
+ gtk_window_set_default_icon_name ("evince");
+
+ window = ev_previewer_window_new ();
+ ev_previewer_window_set_source_file (EV_PREVIEWER_WINDOW (window), filename);
+ ev_previewer_window_set_print_settings (EV_PREVIEWER_WINDOW (window), print_settings);
+ g_signal_connect (window, "delete-event",
+ G_CALLBACK (gtk_main_quit), NULL);
+ g_signal_connect (window, "destroy",
+ G_CALLBACK (gtk_main_quit), NULL);
+ gtk_widget_show (window);
+
+ ev_previewer_load_document (filename, EV_PREVIEWER_WINDOW (window));
+
+ gtk_main ();
+
+ ev_previewer_unlink_tempfile (filename);
+
+ ev_shutdown ();
+ ev_stock_icons_shutdown ();
+
+ return 0;
+}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]