]> www.fi.muni.cz Git - evince.git/commitdiff
Show a confirmation dialog when there are pending print jobs while closing
authorCarlos Garcia Campos <carlosgc@gnome.org>
Sun, 28 Dec 2008 13:28:06 +0000 (13:28 +0000)
committerCarlos Garcia Campos <carlosgc@src.gnome.org>
Sun, 28 Dec 2008 13:28:06 +0000 (13:28 +0000)
2008-12-28  Carlos Garcia Campos  <carlosgc@gnome.org>

* shell/ev-print-operation.c: (export_cancel),
(export_job_cancelled), (ev_print_operation_export_begin),
(ev_print_operation_export_cancel):
* shell/ev-window.c: (ev_window_print_cancel),
(ev_window_print_update_pending_jobs_message),
(ev_window_print_operation_done),
(ev_window_print_operation_status_changed),
(print_jobs_confirmation_dialog_response),
(ev_window_cmd_file_close_window):

Show a confirmation dialog when there are pending print jobs while
closing the main window. Fixes bug #480964.

svn path=/trunk/; revision=3311

ChangeLog
shell/ev-print-operation.c
shell/ev-window.c

index 2eb94ef4ecc0f0d377d59a2a0fee7108873bdc9b..89248180b48b41916222726670ef04a7f3138457 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,18 @@
+2008-12-28  Carlos Garcia Campos  <carlosgc@gnome.org>
+
+       * shell/ev-print-operation.c: (export_cancel),
+       (export_job_cancelled), (ev_print_operation_export_begin),
+       (ev_print_operation_export_cancel):
+       * shell/ev-window.c: (ev_window_print_cancel),
+       (ev_window_print_update_pending_jobs_message),
+       (ev_window_print_operation_done),
+       (ev_window_print_operation_status_changed),
+       (print_jobs_confirmation_dialog_response),
+       (ev_window_cmd_file_close_window):
+
+       Show a confirmation dialog when there are pending print jobs while
+       closing the main window. Fixes bug #480964.
+       
 2008-12-27  Carlos Garcia Campos  <carlosgc@gnome.org>
 
        * shell/ev-print-operation.[ch]: (ev_print_operation_class_init),
index af9cb677654a83d3fe38ae8ad2809688849e250f..48d69a145e4eb52f7f561cfbc57ece35e755745f 100644 (file)
@@ -341,6 +341,7 @@ GType           ev_print_operation_export_get_type (void) G_GNUC_CONST;
 
 static void     ev_print_operation_export_begin    (EvPrintOperationExport *export);
 static gboolean export_print_page                  (EvPrintOperationExport *export);
+static void     export_cancel                      (EvPrintOperationExport *export);
 
 struct _EvPrintOperationExport {
        EvPrintOperation parent;
@@ -840,6 +841,12 @@ export_job_finished (EvJobExport            *job,
 static void
 export_job_cancelled (EvJobExport            *job,
                      EvPrintOperationExport *export)
+{
+       export_cancel (export);
+}
+
+static void
+export_cancel (EvPrintOperationExport *export)
 {
        EvPrintOperation *op = EV_PRINT_OPERATION (export);
 
@@ -847,15 +854,17 @@ export_job_cancelled (EvJobExport            *job,
                g_source_remove (export->idle_id);
        export->idle_id = 0;
 
-       g_signal_handlers_disconnect_by_func (export->job_export,
-                                             export_job_finished,
-                                             export);
-       g_signal_handlers_disconnect_by_func (export->job_export,
-                                             export_job_cancelled,
-                                             export);
-       g_object_unref (export->job_export);
-       export->job_export = NULL;
-
+       if (export->job_export) {
+               g_signal_handlers_disconnect_by_func (export->job_export,
+                                                     export_job_finished,
+                                                     export);
+               g_signal_handlers_disconnect_by_func (export->job_export,
+                                                     export_job_cancelled,
+                                                     export);
+               g_object_unref (export->job_export);
+               export->job_export = NULL;
+       }
+       
        if (export->fd != -1) {
                close (export->fd);
                export->fd = -1;
@@ -864,7 +873,7 @@ export_job_cancelled (EvJobExport            *job,
        ev_print_operation_export_clear_temp_file (export);
 
        g_signal_emit (op, signals[DONE], 0, GTK_PRINT_OPERATION_RESULT_CANCEL);
-       
+
        ev_print_operation_export_run_next (export);
 }
 
@@ -938,6 +947,9 @@ static void
 ev_print_operation_export_begin (EvPrintOperationExport *export)
 {
        EvPrintOperation *op = EV_PRINT_OPERATION (export);
+
+       if (!export->temp_file)
+               return; /* cancelled */
        
        ev_document_doc_mutex_lock ();
        ev_file_exporter_begin (EV_FILE_EXPORTER (op->document), &export->fc);
@@ -1151,13 +1163,11 @@ ev_print_operation_export_cancel (EvPrintOperation *op)
 {
        EvPrintOperationExport *export = EV_PRINT_OPERATION_EXPORT (op);
 
-       if (export->job_export) {
-               if (!ev_job_is_finished (export->job_export)) {
-                       ev_job_cancel (export->job_export);
-               } else {
-                       export_job_cancelled (EV_JOB_EXPORT (export->job_export),
-                                             export);
-               }
+       if (export->job_export &&
+           !ev_job_is_finished (export->job_export)) {
+               ev_job_cancel (export->job_export);
+       } else {
+               export_cancel (export);
        }
 }
 
index 697eb737f5605a4b5a673c32c42ba956c1c29aad..3c61eabf69fc3d883fe7fa05a614ad939359c2e4 100644 (file)
@@ -194,7 +194,7 @@ struct _EvWindowPrivate {
        GtkPrinter       *printer;
        GtkPrintSettings *print_settings;
        GtkPageSetup     *print_page_setup;
-
+       gboolean          close_after_print;
 };
 
 #define EV_WINDOW_GET_PRIVATE(object) \
@@ -2327,16 +2327,28 @@ ev_window_save_print_settings (EvWindow *window)
 }
 
 static void
-ev_window_print_update_pending_jobs_message (EvWindow *ev_window)
+ev_window_print_cancel (EvWindow *ev_window)
+{
+       EvPrintOperation *op;
+       
+       if (!ev_window->priv->print_queue)
+               return;
+
+       while ((op = g_queue_peek_tail (ev_window->priv->print_queue))) {
+               ev_print_operation_cancel (op);
+       }
+}
+
+static void
+ev_window_print_update_pending_jobs_message (EvWindow *ev_window,
+                                            gint      n_jobs)
 {
-       gint   n_jobs;
        gchar *text = NULL;
        
        if (!EV_IS_PROGRESS_MESSAGE_AREA (ev_window->priv->message_area) ||
            !ev_window->priv->print_queue)
                return;
 
-       n_jobs = g_queue_get_length (ev_window->priv->print_queue);
        if (n_jobs == 0) {
                ev_window_set_message_area (ev_window, NULL);
                return;
@@ -2353,11 +2365,21 @@ ev_window_print_update_pending_jobs_message (EvWindow *ev_window)
        g_free (text);
 }
 
+static gboolean
+destroy_window (GtkWidget *window)
+{
+       gtk_widget_destroy (window);
+       
+       return FALSE;
+}
+
 static void
 ev_window_print_operation_done (EvPrintOperation       *op,
                                GtkPrintOperationResult result,
                                EvWindow               *ev_window)
 {
+       gint n_jobs;
+       
        switch (result) {
        case GTK_PRINT_OPERATION_RESULT_APPLY: {
                GtkPrintSettings *print_settings;
@@ -2407,7 +2429,12 @@ ev_window_print_operation_done (EvPrintOperation       *op,
 
        g_queue_remove (ev_window->priv->print_queue, op);
        g_object_unref (op);
-       ev_window_print_update_pending_jobs_message (ev_window);
+       n_jobs = g_queue_get_length (ev_window->priv->print_queue);
+       ev_window_print_update_pending_jobs_message (ev_window, n_jobs);
+
+       if (n_jobs == 0 && ev_window->priv->close_after_print)
+               g_idle_add ((GSourceFunc)destroy_window,
+                           ev_window);
 }
 
 static void
@@ -2450,7 +2477,7 @@ ev_window_print_operation_status_changed (EvPrintOperation *op,
                                                     GTK_STOCK_CANCEL,
                                                     GTK_RESPONSE_CANCEL,
                                                     NULL);
-               ev_window_print_update_pending_jobs_message (ev_window);
+               ev_window_print_update_pending_jobs_message (ev_window, 1);
                g_signal_connect (area, "response",
                                  G_CALLBACK (ev_window_print_progress_response_cb),
                                  ev_window);
@@ -2475,7 +2502,8 @@ ev_window_print_operation_begin_print (EvPrintOperation *op,
                ev_window->priv->print_queue = g_queue_new ();
 
        g_queue_push_head (ev_window->priv->print_queue, op);
-       ev_window_print_update_pending_jobs_message (ev_window);
+       ev_window_print_update_pending_jobs_message (ev_window,
+                                                    g_queue_get_length (ev_window->priv->print_queue));
        
        if (ev_window->priv->print_settings)
                g_object_unref (ev_window->priv->print_settings);
@@ -2578,13 +2606,97 @@ ev_window_cmd_file_properties (GtkAction *action, EvWindow *ev_window)
        gtk_widget_show (ev_window->priv->properties);
        ev_document_fc_mutex_unlock ();
 }
-                                       
+
+static void
+print_jobs_confirmation_dialog_response (GtkDialog *dialog,
+                                        gint       response,
+                                        EvWindow  *ev_window)
+{
+       gtk_widget_destroy (GTK_WIDGET (dialog));       
+       
+       switch (response) {
+       case GTK_RESPONSE_YES:
+               if (!ev_window->priv->print_queue ||
+                   g_queue_is_empty (ev_window->priv->print_queue))
+                       gtk_widget_destroy (GTK_WIDGET (ev_window));
+               else
+                       ev_window->priv->close_after_print = TRUE;
+               break;
+       case GTK_RESPONSE_NO:
+               ev_window->priv->close_after_print = TRUE;
+               if (ev_window->priv->print_queue &&
+                   !g_queue_is_empty (ev_window->priv->print_queue)) {
+                       gtk_widget_set_sensitive (GTK_WIDGET (ev_window), FALSE);
+                       ev_window_print_cancel (ev_window);
+               } else {
+                       gtk_widget_destroy (GTK_WIDGET (ev_window));
+               }
+               break;
+       case GTK_RESPONSE_CANCEL:
+       default:
+               ev_window->priv->close_after_print = FALSE;
+       }
+}
+
 static void
 ev_window_cmd_file_close_window (GtkAction *action, EvWindow *ev_window)
 {
-       g_return_if_fail (EV_IS_WINDOW (ev_window));
+       GtkWidget *dialog;
+       gchar     *text, *markup;
+       gint       n_print_jobs;
+
+       n_print_jobs = ev_window->priv->print_queue ?
+               g_queue_get_length (ev_window->priv->print_queue) : 0;
+       
+       if (n_print_jobs == 0) {
+               gtk_widget_destroy (GTK_WIDGET (ev_window));
+               return;
+       }
+
+       dialog = gtk_message_dialog_new (GTK_WINDOW (ev_window),
+                                        GTK_DIALOG_MODAL,
+                                        GTK_MESSAGE_QUESTION,
+                                        GTK_BUTTONS_NONE,
+                                        NULL);
+       if (n_print_jobs == 1) {
+               EvPrintOperation *op;
+               const gchar      *job_name;
 
-       gtk_widget_destroy (GTK_WIDGET (ev_window));
+               op = g_queue_peek_tail (ev_window->priv->print_queue);
+               job_name = ev_print_operation_get_job_name (op);
+
+               text = g_strdup_printf (_("Wait until print job ā€œ%sā€ finishes before closing?"),
+                                       job_name);
+       } else {
+               text = g_strdup_printf (_("There are %d print jobs active. "
+                                         "Wait until print finishes before closing?"),
+                                       n_print_jobs);
+       }
+
+       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",
+                                                 _("If you close the window, pending print "
+                                                   "jobs will not be printed."));
+       
+       gtk_dialog_add_buttons (GTK_DIALOG (dialog),
+                               _("Cancel _print and Close"),
+                               GTK_RESPONSE_NO,
+                               GTK_STOCK_CANCEL,
+                               GTK_RESPONSE_CANCEL,
+                               _("Close after _Printing"),
+                               GTK_RESPONSE_YES,
+                               NULL);
+       gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_YES);
+
+       g_signal_connect (dialog, "response",
+                         G_CALLBACK (print_jobs_confirmation_dialog_response),
+                         ev_window);
+       gtk_widget_show (dialog);
 }
 
 static void