+
+ g_signal_connect (op, "begin_print",
+ G_CALLBACK (ev_window_print_operation_begin_print),
+ (gpointer)ev_window);
+ g_signal_connect (op, "status_changed",
+ G_CALLBACK (ev_window_print_operation_status_changed),
+ (gpointer)ev_window);
+ g_signal_connect (op, "done",
+ G_CALLBACK (ev_window_print_operation_done),
+ (gpointer)ev_window);
+
+ current_page = ev_document_model_get_page (ev_window->priv->model);
+ document_last_page = ev_document_get_n_pages (ev_window->priv->document);
+
+ print_settings_file = get_print_settings_file ();
+
+ print_settings = get_print_settings (print_settings_file);
+ ev_window_load_print_settings_from_metadata (ev_window, print_settings);
+
+ print_page_setup = get_print_page_setup (print_settings_file);
+ ev_window_load_print_page_setup_from_metadata (ev_window, print_page_setup);
+
+ if (first_page != 1 || last_page != document_last_page) {
+ GtkPageRange range;
+
+ /* Ranges in GtkPrint are 0 - N */
+ range.start = first_page - 1;
+ range.end = last_page - 1;
+
+ gtk_print_settings_set_print_pages (print_settings,
+ GTK_PRINT_PAGES_RANGES);
+ gtk_print_settings_set_page_ranges (print_settings,
+ &range, 1);
+ }
+
+ ev_print_operation_set_job_name (op, gtk_window_get_title (GTK_WINDOW (ev_window)));
+ ev_print_operation_set_current_page (op, current_page);
+ ev_print_operation_set_print_settings (op, print_settings);
+ ev_print_operation_set_default_page_setup (op, print_page_setup);
+ embed_page_setup = ev_window->priv->lockdown_settings ?
+ !g_settings_get_boolean (ev_window->priv->lockdown_settings,
+ GS_LOCKDOWN_PRINT_SETUP) :
+ TRUE;
+ ev_print_operation_set_embed_page_setup (op, embed_page_setup);
+
+ g_object_unref (print_settings);
+ g_object_unref (print_page_setup);
+ g_key_file_free (print_settings_file);
+
+ ev_print_operation_run (op, GTK_WINDOW (ev_window));
+}
+
+static void
+ev_window_print (EvWindow *window)
+{
+ ev_window_print_range (window, 1,
+ ev_document_get_n_pages (window->priv->document));
+}
+
+static void
+ev_window_cmd_file_print (GtkAction *action, EvWindow *ev_window)
+{
+ ev_window_print (ev_window);
+}
+
+static void
+ev_window_cmd_file_properties (GtkAction *action, EvWindow *ev_window)
+{
+ if (ev_window->priv->properties == NULL) {
+ ev_window->priv->properties = ev_properties_dialog_new ();
+ ev_properties_dialog_set_document (EV_PROPERTIES_DIALOG (ev_window->priv->properties),
+ ev_window->priv->uri,
+ ev_window->priv->document);
+ g_object_add_weak_pointer (G_OBJECT (ev_window->priv->properties),
+ (gpointer) &(ev_window->priv->properties));
+ gtk_window_set_transient_for (GTK_WINDOW (ev_window->priv->properties),
+ GTK_WINDOW (ev_window));
+ }
+
+ ev_document_fc_mutex_lock ();
+ gtk_widget_show (ev_window->priv->properties);
+ ev_document_fc_mutex_unlock ();
+}
+
+static void
+document_modified_confirmation_dialog_response (GtkDialog *dialog,
+ gint response,
+ EvWindow *ev_window)
+{
+ gtk_widget_destroy (GTK_WIDGET (dialog));
+
+ switch (response) {
+ case GTK_RESPONSE_YES:
+ ev_window_cmd_save_as (NULL, ev_window);
+ break;
+ case GTK_RESPONSE_NO:
+ gtk_widget_destroy (GTK_WIDGET (ev_window));
+ break;
+ case GTK_RESPONSE_CANCEL:
+ default:
+ break;
+ }
+}
+
+static gboolean
+ev_window_check_document_modified (EvWindow *ev_window)
+{
+ EvDocument *document = ev_window->priv->document;
+ GtkWidget *dialog;
+ gchar *text, *markup;
+ const gchar *secondary_text;
+
+ if (!document)
+ return FALSE;
+
+ if (EV_IS_DOCUMENT_FORMS (document) &&
+ ev_document_forms_document_is_modified (EV_DOCUMENT_FORMS (document))) {
+ secondary_text = _("Document contains form fields that have been filled out. "
+ "If you don't save a copy, changes will be permanently lost.");
+ } else if (EV_IS_DOCUMENT_ANNOTATIONS (document) &&
+ ev_document_annotations_document_is_modified (EV_DOCUMENT_ANNOTATIONS (document))) {
+ secondary_text = _("Document contains new or modified annotations. "
+ "If you don't save a copy, changes will be permanently lost.");
+ } else {
+ return FALSE;
+ }
+
+
+ text = g_markup_printf_escaped (_("Save a copy of document “%s” before closing?"),
+ gtk_window_get_title (GTK_WINDOW (ev_window)));
+
+ dialog = gtk_message_dialog_new (GTK_WINDOW (ev_window),
+ GTK_DIALOG_MODAL,
+ GTK_MESSAGE_QUESTION,
+ GTK_BUTTONS_NONE,
+ NULL);
+
+ markup = g_strdup_printf ("<b>%s</b>", text);
+ g_free (text);
+
+ gtk_message_dialog_set_markup (GTK_MESSAGE_DIALOG (dialog), markup);
+ g_free (markup);
+
+ gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog),
+ "%s", secondary_text);
+
+ gtk_dialog_add_buttons (GTK_DIALOG (dialog),
+ _("Close _without Saving"),
+ GTK_RESPONSE_NO,
+ GTK_STOCK_CANCEL,
+ GTK_RESPONSE_CANCEL,
+ _("Save a _Copy"),
+ GTK_RESPONSE_YES,
+ NULL);
+ gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_YES);
+ gtk_dialog_set_alternative_button_order (GTK_DIALOG (dialog),
+ GTK_RESPONSE_YES,
+ GTK_RESPONSE_NO,
+ GTK_RESPONSE_CANCEL,
+ -1);
+
+ g_signal_connect (dialog, "response",
+ G_CALLBACK (document_modified_confirmation_dialog_response),
+ ev_window);
+ gtk_widget_show (dialog);
+
+ return TRUE;
+}
+
+static void
+print_jobs_confirmation_dialog_response (GtkDialog *dialog,
+ gint response,
+ EvWindow *ev_window)
+{
+ gtk_widget_destroy (GTK_WIDGET (dialog));