1 /* GTK - The GIMP Toolkit
2 * gtkprintoperation-unix.c: Print Operation Details for Unix and Unix like platforms
3 * Copyright (C) 2006, Red Hat, Inc.
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the
17 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 * Boston, MA 02111-1307, USA.
25 #include <sys/types.h>
29 #include "gtkprintoperation-private.h"
30 #include "gtkmarshal.h"
31 #include "gtkmessagedialog.h"
33 #include "gtkprintunixdialog.h"
34 #include "gtkpagesetupunixdialog.h"
35 #include "gtkprintbackend.h"
36 #include "gtkprinter.h"
37 #include "gtkprintjob.h"
41 GtkPrintJob *job; /* the job we are sending to the printer */
42 gulong job_status_changed_tag;
43 GtkWindow *parent; /* parent window just in case we need to throw error dialogs */
44 } GtkPrintOperationUnix;
47 unix_start_page (GtkPrintOperation *op,
48 GtkPrintContext *print_context,
49 GtkPageSetup *page_setup)
55 unix_end_page (GtkPrintOperation *op,
56 GtkPrintContext *print_context)
60 cr = gtk_print_context_get_cairo (print_context);
65 op_unix_free (GtkPrintOperationUnix *op_unix)
69 g_signal_handler_disconnect (op_unix->job,
70 op_unix->job_status_changed_tag);
71 g_object_unref (op_unix->job);
78 unix_finish_send (GtkPrintJob *job,
82 GtkPrintOperationUnix *op_unix;
85 op_unix = (GtkPrintOperationUnix *) user_data;
87 parent = op_unix->parent;
92 edialog = gtk_message_dialog_new (parent,
93 GTK_DIALOG_DESTROY_WITH_PARENT,
99 gtk_dialog_run (GTK_DIALOG (edialog));
100 gtk_widget_destroy (edialog);
105 unix_end_run (GtkPrintOperation *op)
107 GtkPrintOperationUnix *op_unix = op->priv->platform_data;
109 /* TODO: Check for error */
110 gtk_print_job_send (op_unix->job,
117 job_status_changed_cb (GtkPrintJob *job, GtkPrintOperation *op)
119 _gtk_print_operation_set_status (op, gtk_print_job_get_status (job), NULL);
122 GtkPrintOperationResult
123 _gtk_print_operation_platform_backend_run_dialog (GtkPrintOperation *op,
129 GtkPrintOperationResult result;
130 GtkPageSetup *page_setup;
132 result = GTK_PRINT_OPERATION_RESULT_CANCEL;
134 if (op->priv->default_page_setup)
135 page_setup = gtk_page_setup_copy (op->priv->default_page_setup);
137 page_setup = gtk_page_setup_new ();
139 pd = gtk_print_unix_dialog_new (NULL, parent);
141 if (op->priv->print_settings)
142 gtk_print_unix_dialog_set_settings (GTK_PRINT_UNIX_DIALOG (pd),
143 op->priv->print_settings);
145 gtk_print_unix_dialog_set_page_setup (GTK_PRINT_UNIX_DIALOG (pd), page_setup);
148 if (gtk_dialog_run (GTK_DIALOG (pd)) == GTK_RESPONSE_OK)
150 GtkPrintOperationUnix *op_unix;
152 GtkPrintSettings *settings;
154 result = GTK_PRINT_OPERATION_RESULT_APPLY;
156 printer = gtk_print_unix_dialog_get_selected_printer (GTK_PRINT_UNIX_DIALOG (pd));
162 settings = gtk_print_unix_dialog_get_settings (GTK_PRINT_UNIX_DIALOG (pd));
163 gtk_print_operation_set_print_settings (op, settings);
165 op_unix = g_new0 (GtkPrintOperationUnix, 1);
166 op_unix->job = gtk_print_job_new (op->priv->job_name,
170 g_object_unref (settings);
172 op->priv->surface = gtk_print_job_get_surface (op_unix->job, error);
173 if (op->priv->surface == NULL)
176 op_unix_free (op_unix);
177 result = GTK_PRINT_OPERATION_RESULT_ERROR;
181 _gtk_print_operation_set_status (op, gtk_print_job_get_status (op_unix->job), NULL);
182 op_unix->job_status_changed_tag =
183 g_signal_connect (op_unix->job, "status_changed",
184 G_CALLBACK (job_status_changed_cb), op);
186 op_unix->parent = parent;
188 op->priv->dpi_x = 72;
189 op->priv->dpi_y = 72;
191 op->priv->platform_data = op_unix;
192 op->priv->free_platform_data = (GDestroyNotify) op_unix_free;
194 op->priv->print_pages = op_unix->job->print_pages;
195 op->priv->page_ranges = op_unix->job->page_ranges;
196 op->priv->num_page_ranges = op_unix->job->num_page_ranges;
198 op->priv->manual_num_copies = op_unix->job->num_copies;
199 op->priv->manual_collation = op_unix->job->collate;
200 op->priv->manual_reverse = op_unix->job->reverse;
201 op->priv->manual_page_set = op_unix->job->page_set;
202 op->priv->manual_scale = op_unix->job->scale;
203 op->priv->manual_orientation = op_unix->job->rotate_to_orientation;
206 op->priv->start_page = unix_start_page;
207 op->priv->end_page = unix_end_page;
208 op->priv->end_run = unix_end_run;
211 g_object_unref (page_setup);
213 gtk_widget_destroy (pd);
219 * gtk_print_run_page_setup_dialog:
220 * @parent: transient parent, or %NULL
221 * @page_setup: an existing #GtkPageSetup, or %NULL
222 * @settings: a #GtkPrintSettings
224 * Runs a page setup dialog, letting the user modify
225 * the values from @page_setup. If the user cancels
226 * the dialog, the returned #GtkPageSetup is identical
227 * to the passed in @page_setup, otherwise it contains
228 * the modifications done in the dialog.
230 * Return value: a new #GtkPageSetup
235 gtk_print_run_page_setup_dialog (GtkWindow *parent,
236 GtkPageSetup *page_setup,
237 GtkPrintSettings *settings)
240 GtkPageSetup *new_page_setup;
242 dialog = gtk_page_setup_unix_dialog_new (NULL, parent);
244 gtk_page_setup_unix_dialog_set_page_setup (GTK_PAGE_SETUP_UNIX_DIALOG (dialog),
246 gtk_page_setup_unix_dialog_set_print_settings (GTK_PAGE_SETUP_UNIX_DIALOG (dialog),
248 gtk_dialog_run (GTK_DIALOG (dialog));
250 new_page_setup = gtk_page_setup_unix_dialog_get_page_setup (GTK_PAGE_SETUP_UNIX_DIALOG (dialog));
252 gtk_widget_destroy (dialog);
254 return new_page_setup;
258 #define __GTK_PRINT_OPERATION_UNIX_C__
259 #include "gtkaliasdef.c"