#include <glib/gi18n.h>
#include <gio/gio.h>
#include <gtk/gtk.h>
+#if GTK_CHECK_VERSION (2, 14, 0)
+#include <gtk/gtkunixprint.h>
+#else
#include <gtk/gtkprintunixdialog.h>
+#endif
#include <gconf/gconf-client.h>
#include "egg-editable-toolbar.h"
#include "ev-sidebar-links.h"
#include "ev-sidebar-page.h"
#include "ev-sidebar-thumbnails.h"
+#include "ev-sidebar-layers.h"
#include "ev-stock-icons.h"
#include "ev-utils.h"
#include "ev-view.h"
GtkWidget *sidebar_thumbs;
GtkWidget *sidebar_links;
GtkWidget *sidebar_attachments;
+ GtkWidget *sidebar_layers;
/* Dialogs */
GtkWidget *properties;
#define LINKS_SIDEBAR_ID "links"
#define THUMBNAILS_SIDEBAR_ID "thumbnails"
#define ATTACHMENTS_SIDEBAR_ID "attachments"
+#define LAYERS_SIDEBAR_ID "layers"
static const gchar *document_print_settings[] = {
GTK_PRINT_SETTINGS_N_COPIES,
}
static void
-ev_window_error_message (GtkWindow *window, const gchar *msg, GError *error)
+ev_window_error_message (EvWindow *window,
+ GError *error,
+ const gchar *format,
+ ...)
{
GtkWidget *area;
+ va_list args;
+ gchar *msg = NULL;
- if (EV_WINDOW (window)->priv->message_area)
+ if (window->priv->message_area)
return;
+ va_start (args, format);
+ msg = g_strdup_vprintf (format, args);
+ va_end (args);
+
area = ev_message_area_new (GTK_MESSAGE_ERROR,
msg,
GTK_STOCK_CLOSE,
GTK_RESPONSE_CANCEL,
NULL);
+ g_free (msg);
+
if (error)
ev_message_area_set_secondary_text (EV_MESSAGE_AREA (area), error->message);
g_signal_connect (area, "response",
G_CALLBACK (ev_window_message_area_response_cb),
window);
gtk_widget_show (area);
- ev_window_set_message_area (EV_WINDOW (window), area);
+ ev_window_set_message_area (window, area);
}
static void
-ev_window_warning_message (GtkWindow *window, const gchar *msg)
+ev_window_warning_message (EvWindow *window,
+ const gchar *format,
+ ...)
{
GtkWidget *area;
+ va_list args;
+ gchar *msg = NULL;
- if (EV_WINDOW (window)->priv->message_area)
+ if (window->priv->message_area)
return;
+ va_start (args, format);
+ msg = g_strdup_vprintf (format, args);
+ va_end (args);
+
area = ev_message_area_new (GTK_MESSAGE_WARNING,
msg,
GTK_STOCK_CLOSE,
GTK_RESPONSE_CANCEL,
NULL);
+ g_free (msg);
g_signal_connect (area, "response",
G_CALLBACK (ev_window_message_area_response_cb),
window);
gtk_widget_show (area);
- ev_window_set_message_area (EV_WINDOW (window), area);
+ ev_window_set_message_area (window, area);
}
static void
GtkWidget *links = window->priv->sidebar_links;
GtkWidget *thumbs = window->priv->sidebar_thumbs;
GtkWidget *attachments = window->priv->sidebar_attachments;
+ GtkWidget *layers = window->priv->sidebar_layers;
GValue sidebar_size = { 0, };
GValue sidebar_page = { 0, };
GValue sidebar_visibility = { 0, };
g_value_unset(&sidebar_size);
}
- if (document && ev_metadata_manager_get (uri, "sidebar_page", &sidebar_page, FALSE)) {
+ if (document && ev_metadata_manager_get (uri, "sidebar_page", &sidebar_page, TRUE)) {
const char *page_id = g_value_get_string (&sidebar_page);
-
+
if (strcmp (page_id, LINKS_SIDEBAR_ID) == 0 && ev_sidebar_page_support_document (EV_SIDEBAR_PAGE (links), document)) {
ev_sidebar_set_page (EV_SIDEBAR (sidebar), links);
- } else if (strcmp (page_id, THUMBNAILS_SIDEBAR_ID) && ev_sidebar_page_support_document (EV_SIDEBAR_PAGE (thumbs), document)) {
+ } else if (strcmp (page_id, THUMBNAILS_SIDEBAR_ID) == 0 && ev_sidebar_page_support_document (EV_SIDEBAR_PAGE (thumbs), document)) {
ev_sidebar_set_page (EV_SIDEBAR (sidebar), thumbs);
- } else if (strcmp (page_id, ATTACHMENTS_SIDEBAR_ID) && ev_sidebar_page_support_document (EV_SIDEBAR_PAGE (attachments), document)) {
+ } else if (strcmp (page_id, ATTACHMENTS_SIDEBAR_ID) == 0 && ev_sidebar_page_support_document (EV_SIDEBAR_PAGE (attachments), document)) {
ev_sidebar_set_page (EV_SIDEBAR (sidebar), attachments);
+ } else if (strcmp (page_id, LAYERS_SIDEBAR_ID) == 0 && ev_sidebar_page_support_document (EV_SIDEBAR_PAGE (layers), document)) {
+ ev_sidebar_set_page (EV_SIDEBAR (sidebar), layers);
}
g_value_unset (&sidebar_page);
- } else if (document && ev_sidebar_page_support_document (EV_SIDEBAR_PAGE (links), document)) {
- ev_sidebar_set_page (EV_SIDEBAR (sidebar), links);
+ } else if (document) {
+ if (ev_sidebar_page_support_document (EV_SIDEBAR_PAGE (links), document)) {
+ ev_sidebar_set_page (EV_SIDEBAR (sidebar), links);
+ } else if (ev_sidebar_page_support_document (EV_SIDEBAR_PAGE (thumbs), document)) {
+ ev_sidebar_set_page (EV_SIDEBAR (sidebar), thumbs);
+ } else if (ev_sidebar_page_support_document (EV_SIDEBAR_PAGE (attachments), document)) {
+ ev_sidebar_set_page (EV_SIDEBAR (sidebar), attachments);
+ } else if (ev_sidebar_page_support_document (EV_SIDEBAR_PAGE (layers), document)) {
+ ev_sidebar_set_page (EV_SIDEBAR (sidebar), layers);
+ }
}
if (ev_metadata_manager_get (uri, "sidebar_visibility", &sidebar_visibility, FALSE)) {
if (ev_page_cache_get_n_pages (ev_window->priv->page_cache) > 0) {
ev_view_set_document (view, document);
} else {
- ev_window_warning_message (GTK_WINDOW (ev_window),
+ ev_window_warning_message (ev_window, "%s",
_("The document contains no pages"));
}
ev_window_popup_password_dialog (ev_window);
} else {
- ev_window_error_message (GTK_WINDOW (ev_window),
- _("Unable to open document"),
- job->error);
+ ev_window_error_message (ev_window, job->error,
+ "%s", _("Unable to open document"));
ev_window_clear_load_job (ev_window);
}
}
{
ev_view_set_loading (EV_VIEW (ev_window->priv->view), FALSE);
ev_window->priv->in_reload = FALSE;
- ev_window_error_message (GTK_WINDOW (ev_window),
- _("Unable to open document"),
- error);
+ ev_window_error_message (ev_window, error,
+ "%s", _("Unable to open document"));
g_free (ev_window->priv->local_uri);
ev_window->priv->local_uri = NULL;
}
new_filename = ev_window_create_tmp_symlink (old_filename, &error);
if (error) {
- ev_window_error_message (GTK_WINDOW (window),
- _("Cannot open a copy."),
- error);
-
+ ev_window_error_message (window, error,
+ "%s", _("Cannot open a copy."));
g_error_free (error);
g_free (old_filename);
g_free (new_filename);
GFile *dst)
{
EvWindow *window;
- GtkWidget *dialog;
gchar *name;
GError *error = NULL;
return;
}
- window = g_object_get_data (G_OBJECT (dst), "ev-window");
+ window = EV_WINDOW (g_object_get_data (G_OBJECT (dst), "ev-window"));
name = g_file_get_basename (dst);
- dialog = gtk_message_dialog_new (GTK_WINDOW (window),
- GTK_DIALOG_DESTROY_WITH_PARENT,
- GTK_MESSAGE_ERROR,
- GTK_BUTTONS_CLOSE,
- _("The file could not be saved as “%s”."),
- name);
- gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog),
- "%s", error->message);
- g_signal_connect (dialog, "response",
- G_CALLBACK (gtk_widget_destroy),
- NULL);
- gtk_widget_show (dialog);
+ ev_window_error_message (window, error,
+ _("The file could not be saved as “%s”."),
+ name);
ev_tmp_file_unlink (src);
-
g_free (name);
g_error_free (error);
}
EvWindow *window)
{
if (ev_job_is_failed (job)) {
- gchar *msg;
-
- msg = g_strdup_printf (_("The file could not be saved as “%s”."),
- EV_JOB_SAVE (job)->uri);
- ev_window_error_message (GTK_WINDOW (window), msg, job->error);
- g_free (msg);
+ ev_window_error_message (window, job->error,
+ _("The file could not be saved as “%s”."),
+ EV_JOB_SAVE (job)->uri);
}
ev_window_clear_save_job (window);
ev_window_clear_print_job (window);
if (error) {
- GtkWidget *dialog;
-
- dialog = gtk_message_dialog_new (GTK_WINDOW (window),
- GTK_DIALOG_MODAL,
- GTK_MESSAGE_ERROR,
- GTK_BUTTONS_OK,
- _("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);
+ ev_window_error_message (window, error,
+ "%s", _("Failed to print document"));
} else {
/* If printed successfully, save print settings */
ev_application_set_print_settings (EV_APP,
ev_application_set_print_settings (EV_APP,
window->priv->print_settings);
-#if GTK_CHECK_VERSION (2, 11, 0)
print_settings_file = ev_tmp_filename ("print-settings");
gtk_print_settings_to_file (settings, print_settings_file, NULL);
-#endif
+
uri = g_filename_to_uri (filename, NULL, NULL);
ev_application_open_uri_at_dest (EV_APP,
uri,
GTK_PRINT_SETTINGS_OUTPUT_FILE_FORMAT);
if (!gtk_printer_accepts_ps (window->priv->printer)) {
- GtkWidget *msgdialog;
-
- msgdialog = gtk_message_dialog_new (GTK_WINDOW (dialog),
- GTK_DIALOG_MODAL,
- GTK_MESSAGE_ERROR,
- GTK_BUTTONS_OK,
- _("Printing is not supported on this printer."));
-
- gtk_dialog_run (GTK_DIALOG (msgdialog));
- gtk_widget_destroy (msgdialog);
-
+ ev_window_error_message (window, NULL, "%s",
+ _("Printing is not supported on this printer."));
return FALSE;
}
presentation = gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action));
if (presentation) {
ev_window_run_presentation (window);
- } else {
- ev_window_stop_presentation (window, TRUE);
}
}
action = gtk_action_group_get_action (window->priv->action_group,
"PreviewPrint");
-#if GTK_CHECK_VERSION (2, 11, 0)
gtk_action_set_visible (action, TRUE);
-#else
- gtk_action_set_visible (action, FALSE);
-#endif
update_chrome_visibility (window);
}
ev_view_autoscroll_start (EV_VIEW (ev_window->priv->view));
}
+#if GTK_CHECK_VERSION (2, 14, 0)
+static void
+ev_window_cmd_help_contents (GtkAction *action, EvWindow *ev_window)
+{
+ GError *error = NULL;
+
+ gtk_show_uri (gtk_window_get_screen (GTK_WINDOW (ev_window)),
+ "ghelp:evince",
+ GDK_CURRENT_TIME,
+ &error);
+ if (error) {
+ ev_window_error_message (ev_window, error,
+ "%s", _("There was an error displaying help"));
+ g_error_free (error);
+ }
+}
+#else /* !GTK_CHECK_VERSION (2, 14, 0) */
static void
ev_window_cmd_help_contents (GtkAction *action, EvWindow *ev_window)
{
}
g_free (command);
}
+#endif /* GTK_CHECK_VERSION (2, 14, 0) */
static void
ev_window_cmd_leave_fullscreen (GtkAction *action, EvWindow *window)
GError *error)
{
if (error) {
- GtkWidget *dialog;
-
- dialog = gtk_message_dialog_new (GTK_WINDOW (window),
- GTK_DIALOG_MODAL,
- GTK_MESSAGE_ERROR,
- GTK_BUTTONS_OK,
- _("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);
+ ev_window_error_message (window, error,
+ "%s", _("Failed to print document"));
}
g_object_unref (print_job);
{
EvWindowPrivate *priv = window->priv;
GtkPrintSettings *print_settings = NULL;
-#if GTK_CHECK_VERSION (2, 11, 0)
const gchar *print_settings_file = priv->print_settings_file;
if (print_settings_file) {
}
}
}
-#endif /* GTK 2.11.0 */
if (!print_settings)
print_settings = gtk_print_settings_new ();
id = THUMBNAILS_SIDEBAR_ID;
} else if (current_page == ev_window->priv->sidebar_attachments) {
id = ATTACHMENTS_SIDEBAR_ID;
+ } else if (current_page == ev_window->priv->sidebar_layers) {
+ id = LAYERS_SIDEBAR_ID;
} else {
g_assert_not_reached();
}
gtk_widget_grab_focus (window->priv->view);
}
+static void
+sidebar_layers_visibility_changed (EvSidebarLayers *layers,
+ EvWindow *window)
+{
+ ev_view_reload (EV_VIEW (window->priv->view));
+}
+
static void
register_custom_actions (EvWindow *window, GtkActionGroup *group)
{
launch_action (EvWindow *window, EvLinkAction *action)
{
const char *filename = ev_link_action_get_filename (action);
- const char *content_type;
GAppInfo *app_info;
- GFileInfo *file_info;
GFile *file;
- GList *file_list = NULL;
-
+ GList file_list = {NULL};
+ GAppLaunchContext *context = NULL;
+ GError *error = NULL;
+
if (filename == NULL)
return;
file = g_file_new_for_path (filename);
} else {
GFile *base_file;
+ gchar *dir;
+
+ dir = g_path_get_dirname (window->priv->uri);
+ base_file = g_file_new_for_uri (dir);
+ g_free (dir);
- base_file = g_file_new_for_uri (window->priv->uri);
- file = g_file_resolve_relative_path (base_file,
- filename);
-
+ file = g_file_resolve_relative_path (base_file, filename);
g_object_unref (base_file);
}
-
- file_info = g_file_query_info (file,
- G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE,
- 0, NULL, NULL);
- if (file_info == NULL) {
+
+ app_info = g_file_query_default_handler (file, NULL, &error);
+ if (!app_info) {
+ ev_window_error_message (window, error,
+ "%s",
+ _("Unable to launch external application."));
g_object_unref (file);
+ g_error_free (error);
+
return;
}
-
- content_type = g_file_info_get_content_type (file_info);
- app_info = g_app_info_get_default_for_type (content_type, TRUE);
-
- file_list = g_list_append (file_list, file);
- /* FIXME: should we use a GAppLaunchContext? */
- g_app_info_launch (app_info, file_list,
- NULL, NULL);
+#if GTK_CHECK_VERSION (2, 14, 0)
+ context = G_APP_LAUNCH_CONTEXT (gdk_app_launch_context_new ());
+ gdk_app_launch_context_set_screen (GDK_APP_LAUNCH_CONTEXT (context),
+ gtk_window_get_screen (GTK_WINDOW (window)));
+ gdk_app_launch_context_set_timestamp (GDK_APP_LAUNCH_CONTEXT (context), GDK_CURRENT_TIME);
+#endif
+
+ file_list.data = file;
+ if (!g_app_info_launch (app_info, &file_list, context, &error)) {
+ ev_window_error_message (window, error,
+ "%s",
+ _("Unable to launch external application."));
+ g_error_free (error);
+ }
- g_list_free (file_list);
g_object_unref (app_info);
- g_object_unref (file_info);
g_object_unref (file);
/* According to the PDF spec filename can be an executable. I'm not sure
launch_external_uri (EvWindow *window, EvLinkAction *action)
{
const gchar *uri = ev_link_action_get_uri (action);
- GAppLaunchContext *context = NULL;
GError *error = NULL;
gboolean ret;
+#if GTK_CHECK_VERSION (2, 14, 0)
+ GAppLaunchContext *context = NULL;
+#endif
#if GTK_CHECK_VERSION (2, 14, 0)
context = G_APP_LAUNCH_CONTEXT (gdk_app_launch_context_new ());
GDK_CURRENT_TIME);
#endif
- if (!g_strstr_len (uri, strlen (uri), "://")) {
+ if (!g_strstr_len (uri, strlen (uri), "://") &&
+ !g_str_has_prefix (uri, "mailto:")) {
gchar *http;
/* Not a valid uri, assuming it's http */
}
if (ret == FALSE) {
- ev_window_error_message (GTK_WINDOW (window),
- _("Unable to open external link"),
- error);
+ ev_window_error_message (window, error,
+ "%s", _("Unable to open external link"));
g_error_free (error);
}
}
}
if (format == NULL) {
- ev_window_error_message (GTK_WINDOW (ev_window),
- _("Couldn't find appropriate format to save image"),
- NULL);
+ ev_window_error_message (ev_window, NULL,
+ "%s",
+ _("Couldn't find appropriate format to save image"));
g_free (uri);
gtk_widget_destroy (fc);
g_object_unref (pixbuf);
if (error) {
- ev_window_error_message (GTK_WINDOW (ev_window),
- _("The image could not be saved."),
- error);
+ ev_window_error_message (ev_window, error,
+ "%s", _("The image could not be saved."));
g_error_free (error);
g_free (filename);
g_object_unref (target_file);
ev_attachment_open (attachment, screen, GDK_CURRENT_TIME, &error);
if (error) {
- ev_window_error_message (GTK_WINDOW (window),
- _("Unable to open attachment"),
- error);
+ ev_window_error_message (window, error,
+ "%s", _("Unable to open attachment"));
g_error_free (error);
}
}
ev_attachment_save (attachment, save_to, &error);
if (error) {
- ev_window_error_message (GTK_WINDOW (ev_window),
- _("The attachment could not be saved."),
- error);
+ ev_window_error_message (ev_window, error,
+ "%s", _("The attachment could not be saved."));
g_error_free (error);
g_object_unref (save_to);
g_error_free (error);
}
-#if GTK_CHECK_VERSION(2,11,4)
ev_window->priv->recent_manager = gtk_recent_manager_get_default ();
-#else
- /* It's fine to just use the one of the default screen here */
- ev_window->priv->recent_manager = gtk_recent_manager_get_for_screen (
- gdk_screen_get_default ());
-#endif
ev_window->priv->recent_action_group = NULL;
ev_window->priv->recent_ui_id = 0;
g_signal_connect_swapped (ev_window->priv->recent_manager,
ev_sidebar_add_page (EV_SIDEBAR (ev_window->priv->sidebar),
sidebar_widget);
+ sidebar_widget = ev_sidebar_layers_new ();
+ ev_window->priv->sidebar_layers = sidebar_widget;
+ g_signal_connect (sidebar_widget,
+ "layers_visibility_changed",
+ G_CALLBACK (sidebar_layers_visibility_changed),
+ ev_window);
+ gtk_widget_show (sidebar_widget);
+ ev_sidebar_add_page (EV_SIDEBAR (ev_window->priv->sidebar),
+ sidebar_widget);
+
ev_window->priv->view_box = gtk_vbox_new (FALSE, 0);
ev_window->priv->scrolled_window =
GTK_WIDGET (g_object_new (GTK_TYPE_SCROLLED_WINDOW,