+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),
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;
static void
export_job_cancelled (EvJobExport *job,
EvPrintOperationExport *export)
+{
+ export_cancel (export);
+}
+
+static void
+export_cancel (EvPrintOperationExport *export)
{
EvPrintOperation *op = EV_PRINT_OPERATION (export);
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;
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);
}
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);
{
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);
}
}
GtkPrinter *printer;
GtkPrintSettings *print_settings;
GtkPageSetup *print_page_setup;
-
+ gboolean close_after_print;
};
#define EV_WINDOW_GET_PRIVATE(object) \
}
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;
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;
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
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);
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);
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