#include <stdlib.h>
#include <string.h>
#include <unistd.h>
+#include <math.h>
#include <glib/gstdio.h>
#include <glib/gi18n.h>
#ifdef WITH_GCONF
GConfClient *gconf_client;
#endif
+#ifdef ENABLE_DBUS
+ /* DBus */
+ guint dbus_object_id;
+ gchar *dbus_object_path;
+#endif
};
#define EV_WINDOW_GET_PRIVATE(object) \
#define GCONF_LOCKDOWN_PRINT "/desktop/gnome/lockdown/disable_printing"
#define GCONF_LOCKDOWN_PRINT_SETUP "/desktop/gnome/lockdown/disable_print_setup"
+#ifdef ENABLE_DBUS
+#define EV_WINDOW_DBUS_OBJECT_PATH "/org/gnome/evince/Window/%d"
+#define EV_WINDOW_DBUS_INTERFACE "org.gnome.evince.Window"
+#endif
+
#define GS_SCHEMA_NAME "org.gnome.Evince"
#define GS_OVERRIDE_RESTRICTIONS "override-restrictions"
#define EV_TOOLBARS_FILENAME "evince-toolbar.xml"
#define MIN_SCALE 0.05409
-#define MAX_SCALE 4.0
+#define PAGE_CACHE_SIZE 52428800 /* 50MB */
#define MAX_RECENT_ITEM_LEN (40)
static void ev_window_media_player_key_pressed (EvWindow *window,
const gchar *key,
gpointer user_data);
+static void ev_window_update_max_min_scale (EvWindow *window);
+#ifdef ENABLE_DBUS
+static void ev_window_emit_closed (EvWindow *window);
+#endif
static guint ev_window_n_copies = 0;
GtkAction *action;
ev_window->priv->setup_document_idle = 0;
-
+
ev_window_refresh_window_thumbnail (ev_window);
ev_window_set_page_mode (ev_window, PAGE_MODE_DOCUMENT);
g_object_unref (ev_window->priv->document);
ev_window->priv->document = g_object_ref (document);
+ ev_window_update_max_min_scale (ev_window);
+
ev_window_set_message_area (ev_window, NULL);
if (ev_document_get_n_pages (document) <= 0) {
_("The document contains only empty pages"));
}
+ if (EV_WINDOW_IS_PRESENTATION (ev_window)) {
+ gtk_widget_destroy (ev_window->priv->presentation_view);
+ ev_window->priv->presentation_view = NULL;
+ ev_window_run_presentation (ev_window);
+ }
+
if (ev_window->priv->setup_document_idle > 0)
g_source_remove (ev_window->priv->setup_document_idle);
ev_window_close_dialogs (ev_window);
ev_window_clear_load_job (ev_window);
ev_window_clear_local_uri (ev_window);
- ev_view_set_loading (EV_VIEW (ev_window->priv->view), TRUE);
ev_window->priv->window_mode = mode;
if (!g_file_is_native (source_file) && !ev_window->priv->local_uri) {
ev_window_load_file_remote (ev_window, source_file);
} else {
+ ev_view_set_loading (EV_VIEW (ev_window->priv->view), TRUE);
g_object_unref (source_file);
ev_job_scheduler_push_job (ev_window->priv->load_job, EV_JOB_PRIORITY_NONE);
}
key_file = get_print_settings_file ();
gtk_print_settings_to_key_file (print_settings, key_file, EV_PRINT_SETTINGS_GROUP);
- save_print_setting_file (key_file);
- g_key_file_free (key_file);
-
- if (!window->priv->metadata)
- return;
/* Save print settings that are specific to the document */
for (i = 0; i < G_N_ELEMENTS (document_print_settings); i++) {
- const gchar *value;
+ /* Remove it from global settings */
+ g_key_file_remove_key (key_file, EV_PRINT_SETTINGS_GROUP,
+ document_print_settings[i], NULL);
- value = gtk_print_settings_get (print_settings,
- document_print_settings[i]);
- ev_metadata_set_string (window->priv->metadata,
- document_print_settings[i], value);
+ if (window->priv->metadata) {
+ const gchar *value;
+
+ value = gtk_print_settings_get (print_settings,
+ document_print_settings[i]);
+ ev_metadata_set_string (window->priv->metadata,
+ document_print_settings[i], value);
+ }
}
+
+ save_print_setting_file (key_file);
+ g_key_file_free (key_file);
}
static void
key_file = get_print_settings_file ();
gtk_page_setup_to_key_file (page_setup, key_file, EV_PAGE_SETUP_GROUP);
+
+ /* Do not save document settings in global file */
+ g_key_file_remove_key (key_file, EV_PAGE_SETUP_GROUP,
+ "page-setup-orientation", NULL);
+ g_key_file_remove_key (key_file, EV_PAGE_SETUP_GROUP,
+ "page-setup-margin-top", NULL);
+ g_key_file_remove_key (key_file, EV_PAGE_SETUP_GROUP,
+ "page-setup-margin-bottom", NULL);
+ g_key_file_remove_key (key_file, EV_PAGE_SETUP_GROUP,
+ "page-setup-margin-left", NULL);
+ g_key_file_remove_key (key_file, EV_PAGE_SETUP_GROUP,
+ "page-setup-margin-right", NULL);
+
save_print_setting_file (key_file);
g_key_file_free (key_file);
g_free (menubar_accel_accel);
}
+static void
+ev_window_update_max_min_scale (EvWindow *window)
+{
+ gdouble dpi;
+ GtkAction *action;
+ gdouble min_width, min_height;
+ gdouble width, height;
+ gdouble max_scale;
+ gint rotation = ev_document_model_get_rotation (window->priv->model);
+
+ if (!window->priv->document)
+ return;
+
+ dpi = get_screen_dpi (window) / 72.0;
+
+ ev_document_get_min_page_size (window->priv->document, &min_width, &min_height);
+ width = (rotation == 0 || rotation == 180) ? min_width : min_height;
+ height = (rotation == 0 || rotation == 180) ? min_height : min_width;
+ max_scale = sqrt (PAGE_CACHE_SIZE / (width * dpi * 4 * height * dpi));
+
+ action = gtk_action_group_get_action (window->priv->action_group,
+ ZOOM_CONTROL_ACTION);
+ ephy_zoom_action_set_max_zoom_level (EPHY_ZOOM_ACTION (action), max_scale * dpi);
+
+ ev_document_model_set_min_scale (window->priv->model, MIN_SCALE * dpi);
+ ev_document_model_set_max_scale (window->priv->model, max_scale * dpi);
+}
+
static void
ev_window_screen_changed (GtkWidget *widget,
GdkScreen *old_screen)
{
EvWindow *window = EV_WINDOW (widget);
- EvWindowPrivate *priv = window->priv;
GdkScreen *screen;
- gdouble dpi;
screen = gtk_widget_get_screen (widget);
if (screen == old_screen)
return;
ev_window_setup_gtk_settings (window);
- dpi = get_screen_dpi (window);
- ev_document_model_set_min_scale (priv->model, MIN_SCALE * dpi / 72.0);
- ev_document_model_set_max_scale (priv->model, MAX_SCALE * dpi / 72.0);
+ ev_window_update_max_min_scale (window);
if (GTK_WIDGET_CLASS (ev_window_parent_class)->screen_changed) {
GTK_WIDGET_CLASS (ev_window_parent_class)->screen_changed (widget, old_screen);
ev_metadata_set_int (window->priv->metadata, "rotation",
rotation);
+ ev_window_update_max_min_scale (window);
ev_window_refresh_window_thumbnail (window);
}
window);
}
+#ifdef ENABLE_DBUS
+ if (priv->dbus_object_id > 0) {
+ ev_window_emit_closed (window);
+ g_dbus_connection_unregister_object (ev_application_get_dbus_connection (EV_APP),
+ priv->dbus_object_id);
+ priv->dbus_object_id = 0;
+ }
+
+ if (priv->dbus_object_path) {
+ g_free (priv->dbus_object_path);
+ priv->dbus_object_path = NULL;
+ }
+#endif /* ENABLE_DBUS */
+
if (priv->metadata) {
g_object_unref (priv->metadata);
priv->metadata = NULL;
return toolbars_model;
}
+#ifdef ENABLE_DBUS
+static void
+ev_window_sync_source (EvWindow *window,
+ EvSourceLink *link)
+{
+ GDBusConnection *connection;
+ GError *error = NULL;
+
+ if (window->priv->dbus_object_id <= 0)
+ return;
+
+ connection = ev_application_get_dbus_connection (EV_APP);
+ if (!connection)
+ return;
+
+ g_dbus_connection_emit_signal (connection,
+ NULL,
+ window->priv->dbus_object_path,
+ EV_WINDOW_DBUS_INTERFACE,
+ "SyncSource",
+ g_variant_new ("(s(ii))",
+ link->filename,
+ link->line,
+ link->col),
+ &error);
+ if (error) {
+ g_printerr ("Failed to emit DBus signal SyncSource: %s\n",
+ error->message);
+ g_error_free (error);
+ }
+}
+
+static void
+ev_window_emit_closed (EvWindow *window)
+{
+ GDBusConnection *connection;
+ GError *error = NULL;
+
+ if (window->priv->dbus_object_id <= 0)
+ return;
+
+ connection = ev_application_get_dbus_connection (EV_APP);
+ if (!connection)
+ return;
+
+ /* TODO: figure out if this is the last window and use
+ * g_dbus_connection_flush_sync() to make sure the signal
+ * is emitted.
+ */
+ g_dbus_connection_emit_signal (connection,
+ NULL,
+ window->priv->dbus_object_path,
+ EV_WINDOW_DBUS_INTERFACE,
+ "Closed",
+ NULL,
+ &error);
+ if (error) {
+ g_printerr ("Failed to emit DBus signal Closed: %s\n",
+ error->message);
+ g_error_free (error);
+ }
+}
+
+static void
+method_call_cb (GDBusConnection *connection,
+ const gchar *sender,
+ const gchar *object_path,
+ const gchar *interface_name,
+ const gchar *method_name,
+ GVariant *parameters,
+ GDBusMethodInvocation *invocation,
+ gpointer user_data)
+{
+ EvWindow *window = EV_WINDOW (user_data);
+
+ if (g_strcmp0 (method_name, "SyncView") != 0)
+ return;
+
+ if (window->priv->document && ev_document_has_synctex (window->priv->document)) {
+ EvSourceLink link;
+
+ g_variant_get (parameters, "(&s(ii))", &link.filename, &link.line, &link.col);
+ ev_view_highlight_forward_search (EV_VIEW (window->priv->view), &link);
+ gtk_window_present (GTK_WINDOW (window));
+ }
+
+ g_dbus_method_invocation_return_value (invocation, g_variant_new ("()"));
+}
+
+static const char introspection_xml[] =
+ "<node>"
+ "<interface name='org.gnome.evince.Window'>"
+ "<method name='SyncView'>"
+ "<arg type='s' name='source_file' direction='in'/>"
+ "<arg type='(ii)' name='source_point' direction='in'/>"
+ "</method>"
+ "<signal name='SyncSource'>"
+ "<arg type='s' name='source_file' direction='out'/>"
+ "<arg type='(ii)' name='source_point' direction='out'/>"
+ "</signal>"
+ "<signal name='Closed'/>"
+ "</interface>"
+ "</node>";
+
+static const GDBusInterfaceVTable interface_vtable = {
+ method_call_cb,
+ NULL,
+ NULL
+};
+
+static GDBusNodeInfo *introspection_data;
+#endif /* ENABLE_DBUS */
+
static void
ev_window_init (EvWindow *ev_window)
{
EggToolbarsModel *toolbars_model;
GObject *mpkeys;
gchar *ui_path;
- gdouble dpi;
+#ifdef ENABLE_DBUS
+ GDBusConnection *connection;
+ static gint window_id = 0;
+#endif
g_signal_connect (ev_window, "configure_event",
G_CALLBACK (window_configure_event_cb), NULL);
ev_window->priv = EV_WINDOW_GET_PRIVATE (ev_window);
+#ifdef ENABLE_DBUS
+ connection = ev_application_get_dbus_connection (EV_APP);
+ if (connection) {
+ if (!introspection_data) {
+ introspection_data = g_dbus_node_info_new_for_xml (introspection_xml, &error);
+ if (error) g_warning ("%s\n", error->message);
+ }
+ g_assert (introspection_data != NULL);
+
+ ev_window->priv->dbus_object_path = g_strdup_printf (EV_WINDOW_DBUS_OBJECT_PATH, window_id++);
+ ev_window->priv->dbus_object_id =
+ g_dbus_connection_register_object (connection,
+ ev_window->priv->dbus_object_path,
+ introspection_data->interfaces[0],
+ &interface_vtable,
+ ev_window, NULL,
+ &error);
+ if (ev_window->priv->dbus_object_id == 0) {
+ g_printerr ("Failed to register bus object %s: %s\n",
+ ev_window->priv->dbus_object_path, error->message);
+ g_error_free (error);
+ g_free (ev_window->priv->dbus_object_path);
+ ev_window->priv->dbus_object_path = NULL;
+ error = NULL;
+ }
+ }
+
+#endif /* ENABLE_DBUS */
+
ev_window->priv->model = ev_document_model_new ();
ev_window->priv->page_mode = PAGE_MODE_DOCUMENT;
gtk_widget_show (ev_window->priv->view_box);
ev_window->priv->view = ev_view_new ();
+ ev_view_set_page_cache_size (EV_VIEW (ev_window->priv->view), PAGE_CACHE_SIZE);
ev_view_set_model (EV_VIEW (ev_window->priv->view), ev_window->priv->model);
- dpi = get_screen_dpi (ev_window);
- ev_document_model_set_min_scale (ev_window->priv->model, MIN_SCALE * dpi / 72.0);
- ev_document_model_set_max_scale (ev_window->priv->model, MAX_SCALE * dpi / 72.0);
+
ev_window->priv->password_view = ev_password_view_new (GTK_WINDOW (ev_window));
g_signal_connect_swapped (ev_window->priv->password_view,
"unlock",
g_signal_connect_object (ev_window->priv->view, "selection-changed",
G_CALLBACK (view_selection_changed_cb),
ev_window, 0);
+#ifdef ENABLE_DBUS
+ g_signal_connect_swapped (ev_window->priv->view, "sync-source",
+ G_CALLBACK (ev_window_sync_source),
+ ev_window);
+#endif
gtk_widget_show (ev_window->priv->view);
gtk_widget_show (ev_window->priv->password_view);
return ev_window;
}
+