2008-07-01 22:57:50 +00:00
|
|
|
/* GTK - The GIMP Toolkit
|
2006-06-16 03:40:47 +00:00
|
|
|
* gtkprintoperation-unix.c: Print Operation Details for Unix
|
|
|
|
* and Unix-like platforms
|
2006-04-21 15:09:32 +00:00
|
|
|
* Copyright (C) 2006, Red Hat, Inc.
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
2012-02-27 13:01:10 +00:00
|
|
|
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
2006-04-21 15:09:32 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
#ifdef HAVE_UNISTD_H
|
|
|
|
#include <unistd.h>
|
|
|
|
#endif
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <string.h>
|
2006-06-02 15:16:13 +00:00
|
|
|
#include <errno.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <fcntl.h>
|
2006-04-21 15:09:32 +00:00
|
|
|
|
2007-04-29 18:22:27 +00:00
|
|
|
#include <glib/gstdio.h>
|
2006-04-21 15:09:32 +00:00
|
|
|
#include "gtkprintoperation-private.h"
|
2016-07-05 05:36:56 +00:00
|
|
|
#include "gtkprintoperation-portal.h"
|
2006-04-21 15:09:32 +00:00
|
|
|
#include "gtkmessagedialog.h"
|
|
|
|
|
2006-05-23 08:09:08 +00:00
|
|
|
#include <cairo-pdf.h>
|
|
|
|
#include <cairo-ps.h>
|
2006-06-16 16:57:02 +00:00
|
|
|
#include "gtkprivate.h"
|
2006-04-21 15:09:32 +00:00
|
|
|
#include "gtkprintunixdialog.h"
|
|
|
|
#include "gtkpagesetupunixdialog.h"
|
2019-05-26 21:57:23 +00:00
|
|
|
#include "gtkprintbackendprivate.h"
|
2006-04-21 15:09:32 +00:00
|
|
|
#include "gtkprinter.h"
|
|
|
|
#include "gtkprintjob.h"
|
2006-05-23 08:09:08 +00:00
|
|
|
#include "gtklabel.h"
|
2006-05-03 17:34:55 +00:00
|
|
|
#include "gtkintl.h"
|
2010-07-09 17:22:23 +00:00
|
|
|
|
2006-04-21 15:09:32 +00:00
|
|
|
|
2006-06-03 03:11:31 +00:00
|
|
|
typedef struct
|
|
|
|
{
|
2006-04-24 15:23:24 +00:00
|
|
|
GtkWindow *parent; /* just in case we need to throw error dialogs */
|
2006-05-04 13:43:32 +00:00
|
|
|
GMainLoop *loop;
|
|
|
|
gboolean data_sent;
|
2006-06-02 15:16:13 +00:00
|
|
|
|
2006-06-08 16:30:51 +00:00
|
|
|
/* Real printing (not preview) */
|
2006-06-02 15:16:13 +00:00
|
|
|
GtkPrintJob *job; /* the job we are sending to the printer */
|
|
|
|
cairo_surface_t *surface;
|
|
|
|
gulong job_status_changed_tag;
|
|
|
|
|
|
|
|
|
2006-04-21 15:09:32 +00:00
|
|
|
} GtkPrintOperationUnix;
|
|
|
|
|
2006-05-04 13:43:32 +00:00
|
|
|
typedef struct _PrinterFinder PrinterFinder;
|
|
|
|
|
|
|
|
static void printer_finder_free (PrinterFinder *finder);
|
2006-06-03 03:11:31 +00:00
|
|
|
static void find_printer (const gchar *printer,
|
2006-05-04 13:43:32 +00:00
|
|
|
GFunc func,
|
|
|
|
gpointer data);
|
|
|
|
|
2006-04-21 15:09:32 +00:00
|
|
|
static void
|
|
|
|
unix_start_page (GtkPrintOperation *op,
|
2006-04-24 15:23:24 +00:00
|
|
|
GtkPrintContext *print_context,
|
|
|
|
GtkPageSetup *page_setup)
|
2006-04-21 15:09:32 +00:00
|
|
|
{
|
2006-06-02 15:16:13 +00:00
|
|
|
GtkPrintOperationUnix *op_unix;
|
2006-05-05 11:03:33 +00:00
|
|
|
GtkPaperSize *paper_size;
|
|
|
|
cairo_surface_type_t type;
|
2006-06-03 03:11:31 +00:00
|
|
|
gdouble w, h;
|
2006-04-21 15:09:32 +00:00
|
|
|
|
2006-06-02 15:16:13 +00:00
|
|
|
op_unix = op->priv->platform_data;
|
|
|
|
|
2006-05-05 11:03:33 +00:00
|
|
|
paper_size = gtk_page_setup_get_paper_size (page_setup);
|
|
|
|
|
|
|
|
w = gtk_paper_size_get_width (paper_size, GTK_UNIT_POINTS);
|
|
|
|
h = gtk_paper_size_get_height (paper_size, GTK_UNIT_POINTS);
|
|
|
|
|
2006-06-02 15:16:13 +00:00
|
|
|
type = cairo_surface_get_type (op_unix->surface);
|
2006-05-05 11:03:33 +00:00
|
|
|
|
2009-05-13 16:28:42 +00:00
|
|
|
if ((op->priv->manual_number_up < 2) ||
|
|
|
|
(op->priv->page_position % op->priv->manual_number_up == 0))
|
|
|
|
{
|
|
|
|
if (type == CAIRO_SURFACE_TYPE_PS)
|
2009-09-30 16:46:58 +00:00
|
|
|
{
|
|
|
|
cairo_ps_surface_set_size (op_unix->surface, w, h);
|
|
|
|
cairo_ps_surface_dsc_begin_page_setup (op_unix->surface);
|
|
|
|
switch (gtk_page_setup_get_orientation (page_setup))
|
|
|
|
{
|
|
|
|
case GTK_PAGE_ORIENTATION_PORTRAIT:
|
|
|
|
case GTK_PAGE_ORIENTATION_REVERSE_PORTRAIT:
|
|
|
|
cairo_ps_surface_dsc_comment (op_unix->surface, "%%PageOrientation: Portrait");
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GTK_PAGE_ORIENTATION_LANDSCAPE:
|
|
|
|
case GTK_PAGE_ORIENTATION_REVERSE_LANDSCAPE:
|
|
|
|
cairo_ps_surface_dsc_comment (op_unix->surface, "%%PageOrientation: Landscape");
|
|
|
|
break;
|
2017-10-06 19:19:42 +00:00
|
|
|
default:
|
|
|
|
break;
|
2009-09-30 16:46:58 +00:00
|
|
|
}
|
|
|
|
}
|
2009-05-13 16:28:42 +00:00
|
|
|
else if (type == CAIRO_SURFACE_TYPE_PDF)
|
2009-09-30 16:46:58 +00:00
|
|
|
{
|
2012-09-12 09:34:09 +00:00
|
|
|
if (!op->priv->manual_orientation)
|
|
|
|
{
|
|
|
|
w = gtk_page_setup_get_paper_width (page_setup, GTK_UNIT_POINTS);
|
|
|
|
h = gtk_page_setup_get_paper_height (page_setup, GTK_UNIT_POINTS);
|
|
|
|
}
|
2009-09-30 16:46:58 +00:00
|
|
|
cairo_pdf_surface_set_size (op_unix->surface, w, h);
|
|
|
|
}
|
2009-05-13 16:28:42 +00:00
|
|
|
}
|
2006-04-21 15:09:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
unix_end_page (GtkPrintOperation *op,
|
2006-04-24 15:23:24 +00:00
|
|
|
GtkPrintContext *print_context)
|
2006-04-21 15:09:32 +00:00
|
|
|
{
|
|
|
|
cairo_t *cr;
|
|
|
|
|
2006-05-31 13:38:10 +00:00
|
|
|
cr = gtk_print_context_get_cairo_context (print_context);
|
2009-05-13 16:28:42 +00:00
|
|
|
|
|
|
|
if ((op->priv->manual_number_up < 2) ||
|
|
|
|
((op->priv->page_position + 1) % op->priv->manual_number_up == 0) ||
|
|
|
|
(op->priv->page_position == op->priv->nr_of_pages_to_print - 1))
|
|
|
|
cairo_show_page (cr);
|
2006-04-21 15:09:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
op_unix_free (GtkPrintOperationUnix *op_unix)
|
|
|
|
{
|
|
|
|
if (op_unix->job)
|
|
|
|
{
|
2014-03-14 14:36:10 +00:00
|
|
|
if (op_unix->job_status_changed_tag > 0)
|
|
|
|
g_signal_handler_disconnect (op_unix->job,
|
|
|
|
op_unix->job_status_changed_tag);
|
2006-04-21 15:09:32 +00:00
|
|
|
g_object_unref (op_unix->job);
|
|
|
|
}
|
|
|
|
|
|
|
|
g_free (op_unix);
|
|
|
|
}
|
|
|
|
|
2006-06-03 03:11:31 +00:00
|
|
|
static gchar *
|
2006-06-02 15:16:13 +00:00
|
|
|
shell_command_substitute_file (const gchar *cmd,
|
2007-04-29 06:59:27 +00:00
|
|
|
const gchar *pdf_filename,
|
|
|
|
const gchar *settings_filename,
|
|
|
|
gboolean *pdf_filename_replaced,
|
|
|
|
gboolean *settings_filename_replaced)
|
2006-06-02 15:16:13 +00:00
|
|
|
{
|
2006-06-03 03:11:31 +00:00
|
|
|
const gchar *inptr, *start;
|
2006-06-02 15:16:13 +00:00
|
|
|
GString *final;
|
|
|
|
|
|
|
|
g_return_val_if_fail (cmd != NULL, NULL);
|
2007-04-29 06:59:27 +00:00
|
|
|
g_return_val_if_fail (pdf_filename != NULL, NULL);
|
|
|
|
g_return_val_if_fail (settings_filename != NULL, NULL);
|
2006-06-02 15:16:13 +00:00
|
|
|
|
|
|
|
final = g_string_new (NULL);
|
|
|
|
|
2007-04-29 06:59:27 +00:00
|
|
|
*pdf_filename_replaced = FALSE;
|
|
|
|
*settings_filename_replaced = FALSE;
|
2006-06-02 15:16:13 +00:00
|
|
|
|
2007-04-29 06:59:27 +00:00
|
|
|
start = inptr = cmd;
|
2006-06-02 15:16:13 +00:00
|
|
|
while ((inptr = strchr (inptr, '%')) != NULL)
|
|
|
|
{
|
|
|
|
g_string_append_len (final, start, inptr - start);
|
|
|
|
inptr++;
|
|
|
|
switch (*inptr)
|
|
|
|
{
|
|
|
|
case 'f':
|
2007-04-29 06:59:27 +00:00
|
|
|
g_string_append (final, pdf_filename);
|
|
|
|
*pdf_filename_replaced = TRUE;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 's':
|
|
|
|
g_string_append (final, settings_filename);
|
|
|
|
*settings_filename_replaced = TRUE;
|
2006-06-02 15:16:13 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case '%':
|
|
|
|
g_string_append_c (final, '%');
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
g_string_append_c (final, '%');
|
|
|
|
if (*inptr)
|
|
|
|
g_string_append_c (final, *inptr);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (*inptr)
|
|
|
|
inptr++;
|
|
|
|
start = inptr;
|
|
|
|
}
|
|
|
|
g_string_append (final, start);
|
|
|
|
|
2007-04-29 18:22:27 +00:00
|
|
|
return g_string_free (final, FALSE);
|
2006-06-02 15:16:13 +00:00
|
|
|
}
|
|
|
|
|
2016-07-05 05:36:56 +00:00
|
|
|
static void
|
|
|
|
gtk_print_operation_unix_launch_preview (GtkPrintOperation *op,
|
|
|
|
cairo_surface_t *surface,
|
|
|
|
GtkWindow *parent,
|
|
|
|
const gchar *filename)
|
2006-06-02 15:16:13 +00:00
|
|
|
{
|
2010-12-15 07:38:43 +00:00
|
|
|
GAppInfo *appinfo;
|
2010-12-15 13:06:44 +00:00
|
|
|
GdkAppLaunchContext *context;
|
2006-06-02 15:16:13 +00:00
|
|
|
gchar *cmd;
|
|
|
|
gchar *preview_cmd;
|
|
|
|
GtkSettings *settings;
|
2009-10-26 16:47:37 +00:00
|
|
|
GtkPrintSettings *print_settings = NULL;
|
2009-04-07 16:45:11 +00:00
|
|
|
GtkPageSetup *page_setup;
|
|
|
|
GKeyFile *key_file = NULL;
|
|
|
|
gchar *data = NULL;
|
|
|
|
gsize data_len;
|
2007-04-29 18:22:27 +00:00
|
|
|
gchar *settings_filename = NULL;
|
2006-06-02 15:16:13 +00:00
|
|
|
gchar *quoted_filename;
|
2007-04-29 06:59:27 +00:00
|
|
|
gchar *quoted_settings_filename;
|
2007-04-29 18:22:27 +00:00
|
|
|
gboolean filename_used = FALSE;
|
|
|
|
gboolean settings_used = FALSE;
|
2017-10-31 02:52:49 +00:00
|
|
|
GdkDisplay *display;
|
2006-06-02 15:16:13 +00:00
|
|
|
GError *error = NULL;
|
2007-04-29 06:59:27 +00:00
|
|
|
gint fd;
|
2007-04-29 18:22:27 +00:00
|
|
|
gboolean retval;
|
2006-06-08 09:09:50 +00:00
|
|
|
|
2006-06-08 09:18:38 +00:00
|
|
|
cairo_surface_destroy (surface);
|
2017-10-31 02:52:49 +00:00
|
|
|
|
2007-04-29 06:59:27 +00:00
|
|
|
if (parent)
|
2017-10-31 02:52:49 +00:00
|
|
|
display = gtk_widget_get_display (GTK_WIDGET (parent));
|
2007-04-29 06:59:27 +00:00
|
|
|
else
|
2017-10-31 02:52:49 +00:00
|
|
|
display = gdk_display_get_default ();
|
2007-04-29 06:59:27 +00:00
|
|
|
|
2007-04-29 18:22:27 +00:00
|
|
|
fd = g_file_open_tmp ("settingsXXXXXX.ini", &settings_filename, &error);
|
|
|
|
if (fd < 0)
|
|
|
|
goto out;
|
2007-04-29 06:59:27 +00:00
|
|
|
|
2009-04-07 16:45:11 +00:00
|
|
|
key_file = g_key_file_new ();
|
|
|
|
|
2009-10-26 16:47:37 +00:00
|
|
|
print_settings = gtk_print_settings_copy (gtk_print_operation_get_print_settings (op));
|
|
|
|
|
|
|
|
if (print_settings != NULL)
|
|
|
|
{
|
|
|
|
gtk_print_settings_set_reverse (print_settings, FALSE);
|
|
|
|
gtk_print_settings_set_page_set (print_settings, GTK_PAGE_SET_ALL);
|
|
|
|
gtk_print_settings_set_scale (print_settings, 1.0);
|
|
|
|
gtk_print_settings_set_number_up (print_settings, 1);
|
|
|
|
gtk_print_settings_set_number_up_layout (print_settings, GTK_NUMBER_UP_LAYOUT_LEFT_TO_RIGHT_TOP_TO_BOTTOM);
|
|
|
|
|
|
|
|
/* These removals are neccessary because cups-* settings have higher priority
|
|
|
|
* than normal settings.
|
|
|
|
*/
|
|
|
|
gtk_print_settings_unset (print_settings, "cups-reverse");
|
|
|
|
gtk_print_settings_unset (print_settings, "cups-page-set");
|
|
|
|
gtk_print_settings_unset (print_settings, "cups-scale");
|
|
|
|
gtk_print_settings_unset (print_settings, "cups-number-up");
|
|
|
|
gtk_print_settings_unset (print_settings, "cups-number-up-layout");
|
|
|
|
|
|
|
|
gtk_print_settings_to_key_file (print_settings, key_file, NULL);
|
|
|
|
g_object_unref (print_settings);
|
|
|
|
}
|
2009-04-07 16:45:11 +00:00
|
|
|
|
|
|
|
page_setup = gtk_print_context_get_page_setup (op->priv->print_context);
|
|
|
|
gtk_page_setup_to_key_file (page_setup, key_file, NULL);
|
2007-04-29 18:22:27 +00:00
|
|
|
|
2009-04-07 17:02:48 +00:00
|
|
|
g_key_file_set_string (key_file, "Print Job", "title", op->priv->job_name);
|
|
|
|
|
2009-04-07 16:45:11 +00:00
|
|
|
data = g_key_file_to_data (key_file, &data_len, &error);
|
|
|
|
if (!data)
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
retval = g_file_set_contents (settings_filename, data, data_len, &error);
|
2007-04-29 18:22:27 +00:00
|
|
|
if (!retval)
|
2007-04-29 06:59:27 +00:00
|
|
|
goto out;
|
|
|
|
|
2017-10-31 02:52:49 +00:00
|
|
|
settings = gtk_settings_get_for_display (display);
|
2006-06-02 15:16:13 +00:00
|
|
|
g_object_get (settings, "gtk-print-preview-command", &preview_cmd, NULL);
|
|
|
|
|
|
|
|
quoted_filename = g_shell_quote (filename);
|
2007-04-29 06:59:27 +00:00
|
|
|
quoted_settings_filename = g_shell_quote (settings_filename);
|
|
|
|
cmd = shell_command_substitute_file (preview_cmd, quoted_filename, quoted_settings_filename, &filename_used, &settings_used);
|
2010-12-15 07:38:43 +00:00
|
|
|
|
|
|
|
appinfo = g_app_info_create_from_commandline (cmd,
|
|
|
|
"Print Preview",
|
|
|
|
G_APP_INFO_CREATE_NONE,
|
|
|
|
&error);
|
2006-06-02 15:16:13 +00:00
|
|
|
|
2007-04-29 06:59:27 +00:00
|
|
|
g_free (preview_cmd);
|
|
|
|
g_free (quoted_filename);
|
|
|
|
g_free (quoted_settings_filename);
|
|
|
|
g_free (cmd);
|
|
|
|
|
2006-06-03 03:11:31 +00:00
|
|
|
if (error != NULL)
|
2006-06-02 15:16:13 +00:00
|
|
|
goto out;
|
|
|
|
|
2017-10-31 02:52:49 +00:00
|
|
|
context = gdk_display_get_app_launch_context (display);
|
2010-12-15 13:06:44 +00:00
|
|
|
g_app_info_launch (appinfo, NULL, G_APP_LAUNCH_CONTEXT (context), &error);
|
2006-06-02 15:16:13 +00:00
|
|
|
|
2010-12-15 07:38:43 +00:00
|
|
|
g_object_unref (context);
|
|
|
|
g_object_unref (appinfo);
|
2007-04-29 06:59:27 +00:00
|
|
|
|
2009-11-30 12:20:43 +00:00
|
|
|
if (error != NULL)
|
|
|
|
{
|
|
|
|
gchar* uri;
|
|
|
|
|
2016-02-28 16:06:25 +00:00
|
|
|
g_warning ("Error launching preview: %s", error->message);
|
2009-11-30 12:20:43 +00:00
|
|
|
|
|
|
|
g_error_free (error);
|
|
|
|
error = NULL;
|
|
|
|
uri = g_filename_to_uri (filename, NULL, NULL);
|
2020-04-12 01:58:19 +00:00
|
|
|
gtk_show_uri (parent, uri, GDK_CURRENT_TIME);
|
2009-11-30 12:20:43 +00:00
|
|
|
g_free (uri);
|
|
|
|
}
|
|
|
|
|
2006-06-02 15:16:13 +00:00
|
|
|
out:
|
|
|
|
if (error != NULL)
|
|
|
|
{
|
2010-06-07 12:52:38 +00:00
|
|
|
if (op->priv->error == NULL)
|
|
|
|
op->priv->error = error;
|
|
|
|
else
|
|
|
|
g_error_free (error);
|
2007-04-29 06:59:27 +00:00
|
|
|
|
2010-12-15 07:38:43 +00:00
|
|
|
filename_used = FALSE;
|
2007-04-29 06:59:27 +00:00
|
|
|
settings_used = FALSE;
|
2010-12-15 07:38:43 +00:00
|
|
|
}
|
2006-06-02 15:16:13 +00:00
|
|
|
|
2007-04-29 06:59:27 +00:00
|
|
|
if (!filename_used)
|
|
|
|
g_unlink (filename);
|
|
|
|
|
|
|
|
if (!settings_used)
|
|
|
|
g_unlink (settings_filename);
|
|
|
|
|
2009-04-07 16:45:11 +00:00
|
|
|
if (fd > 0)
|
|
|
|
close (fd);
|
2010-12-15 07:38:43 +00:00
|
|
|
|
2009-04-07 16:45:11 +00:00
|
|
|
if (key_file)
|
|
|
|
g_key_file_free (key_file);
|
|
|
|
g_free (data);
|
2007-04-29 06:59:27 +00:00
|
|
|
g_free (settings_filename);
|
2006-06-02 15:16:13 +00:00
|
|
|
}
|
|
|
|
|
2006-04-21 15:09:32 +00:00
|
|
|
static void
|
2010-06-07 12:52:38 +00:00
|
|
|
unix_finish_send (GtkPrintJob *job,
|
|
|
|
gpointer user_data,
|
|
|
|
const GError *error)
|
2006-04-21 15:09:32 +00:00
|
|
|
{
|
2007-05-25 17:22:55 +00:00
|
|
|
GtkPrintOperation *op = (GtkPrintOperation *) user_data;
|
|
|
|
GtkPrintOperationUnix *op_unix = op->priv->platform_data;
|
2006-04-21 15:09:32 +00:00
|
|
|
|
2010-06-07 12:52:38 +00:00
|
|
|
if (error != NULL && op->priv->error == NULL)
|
|
|
|
op->priv->error = g_error_copy (error);
|
2006-05-04 13:43:32 +00:00
|
|
|
|
|
|
|
op_unix->data_sent = TRUE;
|
2006-06-02 15:16:13 +00:00
|
|
|
|
2006-05-04 13:43:32 +00:00
|
|
|
if (op_unix->loop)
|
|
|
|
g_main_loop_quit (op_unix->loop);
|
2007-05-25 17:22:55 +00:00
|
|
|
|
|
|
|
g_object_unref (op);
|
2006-04-21 15:09:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2006-05-04 13:43:32 +00:00
|
|
|
unix_end_run (GtkPrintOperation *op,
|
2006-05-23 16:30:45 +00:00
|
|
|
gboolean wait,
|
|
|
|
gboolean cancelled)
|
2006-04-21 15:09:32 +00:00
|
|
|
{
|
|
|
|
GtkPrintOperationUnix *op_unix = op->priv->platform_data;
|
2006-05-04 13:43:32 +00:00
|
|
|
|
2006-06-02 15:16:13 +00:00
|
|
|
cairo_surface_finish (op_unix->surface);
|
|
|
|
|
2006-05-23 16:30:45 +00:00
|
|
|
if (cancelled)
|
|
|
|
return;
|
|
|
|
|
2006-05-04 13:43:32 +00:00
|
|
|
if (wait)
|
|
|
|
op_unix->loop = g_main_loop_new (NULL, FALSE);
|
|
|
|
|
2006-04-21 15:09:32 +00:00
|
|
|
/* TODO: Check for error */
|
2006-06-02 15:16:13 +00:00
|
|
|
if (op_unix->job != NULL)
|
2007-05-25 17:22:55 +00:00
|
|
|
{
|
|
|
|
g_object_ref (op);
|
|
|
|
gtk_print_job_send (op_unix->job,
|
|
|
|
unix_finish_send,
|
|
|
|
op, NULL);
|
|
|
|
}
|
2006-05-04 13:43:32 +00:00
|
|
|
|
|
|
|
if (wait)
|
|
|
|
{
|
2006-12-22 19:10:43 +00:00
|
|
|
g_object_ref (op);
|
2006-05-04 13:43:32 +00:00
|
|
|
if (!op_unix->data_sent)
|
2018-02-02 15:34:40 +00:00
|
|
|
g_main_loop_run (op_unix->loop);
|
2006-05-04 13:43:32 +00:00
|
|
|
g_main_loop_unref (op_unix->loop);
|
2006-12-22 19:10:43 +00:00
|
|
|
op_unix->loop = NULL;
|
|
|
|
g_object_unref (op);
|
2006-05-04 13:43:32 +00:00
|
|
|
}
|
2006-04-21 15:09:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2006-04-24 15:23:24 +00:00
|
|
|
job_status_changed_cb (GtkPrintJob *job,
|
|
|
|
GtkPrintOperation *op)
|
2006-04-21 15:09:32 +00:00
|
|
|
{
|
|
|
|
_gtk_print_operation_set_status (op, gtk_print_job_get_status (job), NULL);
|
|
|
|
}
|
|
|
|
|
2006-04-24 17:00:44 +00:00
|
|
|
|
2009-04-21 11:06:49 +00:00
|
|
|
static void
|
2009-08-30 01:17:47 +00:00
|
|
|
print_setup_changed_cb (GtkPrintUnixDialog *print_dialog,
|
|
|
|
GParamSpec *pspec,
|
|
|
|
gpointer user_data)
|
2009-04-21 11:06:49 +00:00
|
|
|
{
|
|
|
|
GtkPageSetup *page_setup;
|
|
|
|
GtkPrintSettings *print_settings;
|
|
|
|
GtkPrintOperation *op = user_data;
|
|
|
|
GtkPrintOperationPrivate *priv = op->priv;
|
|
|
|
|
|
|
|
page_setup = gtk_print_unix_dialog_get_page_setup (print_dialog);
|
|
|
|
print_settings = gtk_print_unix_dialog_get_settings (print_dialog);
|
|
|
|
|
|
|
|
g_signal_emit_by_name (op,
|
|
|
|
"update-custom-widget",
|
|
|
|
priv->custom_widget,
|
|
|
|
page_setup,
|
|
|
|
print_settings);
|
|
|
|
}
|
|
|
|
|
2006-04-24 17:00:44 +00:00
|
|
|
static GtkWidget *
|
|
|
|
get_print_dialog (GtkPrintOperation *op,
|
|
|
|
GtkWindow *parent)
|
2006-04-21 15:09:32 +00:00
|
|
|
{
|
2006-05-02 12:48:52 +00:00
|
|
|
GtkPrintOperationPrivate *priv = op->priv;
|
2006-05-23 08:09:08 +00:00
|
|
|
GtkWidget *pd, *label;
|
2006-05-24 16:15:15 +00:00
|
|
|
const gchar *custom_tab_label;
|
2006-04-21 15:09:32 +00:00
|
|
|
|
|
|
|
pd = gtk_print_unix_dialog_new (NULL, parent);
|
|
|
|
|
2006-05-24 10:50:57 +00:00
|
|
|
gtk_print_unix_dialog_set_manual_capabilities (GTK_PRINT_UNIX_DIALOG (pd),
|
|
|
|
GTK_PRINT_CAPABILITY_PAGE_SET |
|
|
|
|
GTK_PRINT_CAPABILITY_COPIES |
|
|
|
|
GTK_PRINT_CAPABILITY_COLLATE |
|
|
|
|
GTK_PRINT_CAPABILITY_REVERSE |
|
2006-06-16 03:40:47 +00:00
|
|
|
GTK_PRINT_CAPABILITY_SCALE |
|
2009-05-13 16:28:42 +00:00
|
|
|
GTK_PRINT_CAPABILITY_PREVIEW |
|
|
|
|
GTK_PRINT_CAPABILITY_NUMBER_UP |
|
|
|
|
GTK_PRINT_CAPABILITY_NUMBER_UP_LAYOUT);
|
2006-05-24 10:50:57 +00:00
|
|
|
|
2006-05-02 12:48:52 +00:00
|
|
|
if (priv->print_settings)
|
2006-04-21 15:09:32 +00:00
|
|
|
gtk_print_unix_dialog_set_settings (GTK_PRINT_UNIX_DIALOG (pd),
|
2006-05-02 12:48:52 +00:00
|
|
|
priv->print_settings);
|
2009-07-10 09:28:31 +00:00
|
|
|
|
2006-05-02 12:48:52 +00:00
|
|
|
if (priv->default_page_setup)
|
2008-05-21 02:17:30 +00:00
|
|
|
gtk_print_unix_dialog_set_page_setup (GTK_PRINT_UNIX_DIALOG (pd),
|
|
|
|
priv->default_page_setup);
|
2006-04-21 15:09:32 +00:00
|
|
|
|
2009-07-10 09:28:31 +00:00
|
|
|
gtk_print_unix_dialog_set_embed_page_setup (GTK_PRINT_UNIX_DIALOG (pd),
|
|
|
|
priv->embed_page_setup);
|
|
|
|
|
2008-10-16 11:20:33 +00:00
|
|
|
gtk_print_unix_dialog_set_current_page (GTK_PRINT_UNIX_DIALOG (pd),
|
|
|
|
priv->current_page);
|
|
|
|
|
2009-06-08 13:37:32 +00:00
|
|
|
gtk_print_unix_dialog_set_support_selection (GTK_PRINT_UNIX_DIALOG (pd),
|
|
|
|
priv->support_selection);
|
|
|
|
|
|
|
|
gtk_print_unix_dialog_set_has_selection (GTK_PRINT_UNIX_DIALOG (pd),
|
|
|
|
priv->has_selection);
|
|
|
|
|
2006-05-23 08:09:08 +00:00
|
|
|
g_signal_emit_by_name (op, "create-custom-widget",
|
2006-05-24 16:15:15 +00:00
|
|
|
&priv->custom_widget);
|
|
|
|
|
|
|
|
if (priv->custom_widget)
|
|
|
|
{
|
|
|
|
custom_tab_label = priv->custom_tab_label;
|
|
|
|
|
|
|
|
if (custom_tab_label == NULL)
|
|
|
|
{
|
|
|
|
custom_tab_label = g_get_application_name ();
|
|
|
|
if (custom_tab_label == NULL)
|
|
|
|
custom_tab_label = _("Application");
|
|
|
|
}
|
|
|
|
|
|
|
|
label = gtk_label_new (custom_tab_label);
|
|
|
|
|
|
|
|
gtk_print_unix_dialog_add_custom_tab (GTK_PRINT_UNIX_DIALOG (pd),
|
2006-06-03 03:11:31 +00:00
|
|
|
priv->custom_widget, label);
|
2009-04-21 11:06:49 +00:00
|
|
|
|
2009-08-30 01:17:47 +00:00
|
|
|
g_signal_connect (pd, "notify::selected-printer", (GCallback) print_setup_changed_cb, op);
|
|
|
|
g_signal_connect (pd, "notify::page-setup", (GCallback) print_setup_changed_cb, op);
|
2006-05-24 16:15:15 +00:00
|
|
|
}
|
2006-05-23 08:09:08 +00:00
|
|
|
|
2006-04-24 17:00:44 +00:00
|
|
|
return pd;
|
|
|
|
}
|
2006-04-21 15:09:32 +00:00
|
|
|
|
2006-06-03 03:11:31 +00:00
|
|
|
typedef struct
|
|
|
|
{
|
2006-04-24 17:00:44 +00:00
|
|
|
GtkPrintOperation *op;
|
|
|
|
gboolean do_print;
|
2006-06-08 16:30:51 +00:00
|
|
|
gboolean do_preview;
|
2006-04-24 17:00:44 +00:00
|
|
|
GtkPrintOperationResult result;
|
|
|
|
GtkPrintOperationPrintFunc print_cb;
|
|
|
|
GDestroyNotify destroy;
|
2006-05-04 13:43:32 +00:00
|
|
|
GtkWindow *parent;
|
|
|
|
GMainLoop *loop;
|
2006-04-24 17:00:44 +00:00
|
|
|
} PrintResponseData;
|
|
|
|
|
|
|
|
static void
|
|
|
|
print_response_data_free (gpointer data)
|
|
|
|
{
|
|
|
|
PrintResponseData *rdata = data;
|
|
|
|
|
|
|
|
g_object_unref (rdata->op);
|
|
|
|
g_free (rdata);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2006-05-04 13:43:32 +00:00
|
|
|
finish_print (PrintResponseData *rdata,
|
2006-06-03 03:11:31 +00:00
|
|
|
GtkPrinter *printer,
|
|
|
|
GtkPageSetup *page_setup,
|
2009-07-10 09:28:31 +00:00
|
|
|
GtkPrintSettings *settings,
|
|
|
|
gboolean page_setup_set)
|
2006-04-24 17:00:44 +00:00
|
|
|
{
|
|
|
|
GtkPrintOperation *op = rdata->op;
|
2006-05-02 12:48:52 +00:00
|
|
|
GtkPrintOperationPrivate *priv = op->priv;
|
2006-06-03 03:11:31 +00:00
|
|
|
GtkPrintJob *job;
|
2009-11-21 09:37:14 +00:00
|
|
|
gdouble top, bottom, left, right;
|
2006-05-04 13:43:32 +00:00
|
|
|
|
|
|
|
if (rdata->do_print)
|
2006-04-21 15:09:32 +00:00
|
|
|
{
|
|
|
|
gtk_print_operation_set_print_settings (op, settings);
|
2006-06-02 15:16:13 +00:00
|
|
|
priv->print_context = _gtk_print_context_new (op);
|
2008-05-21 02:17:30 +00:00
|
|
|
|
2009-11-21 10:40:36 +00:00
|
|
|
if (gtk_print_settings_get_number_up (settings) < 2)
|
|
|
|
{
|
2018-04-12 09:31:37 +00:00
|
|
|
if (printer && (gtk_printer_get_hard_margins_for_paper_size (printer, gtk_page_setup_get_paper_size (page_setup), &top, &bottom, &left, &right) ||
|
|
|
|
gtk_printer_get_hard_margins (printer, &top, &bottom, &left, &right)))
|
2009-11-21 10:40:36 +00:00
|
|
|
_gtk_print_context_set_hard_margins (priv->print_context, top, bottom, left, right);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Pages do not have any unprintable area when printing n-up as each page on the
|
|
|
|
* sheet has been scaled down and translated to a position within the printable
|
|
|
|
* area of the sheet.
|
|
|
|
*/
|
|
|
|
_gtk_print_context_set_hard_margins (priv->print_context, 0, 0, 0, 0);
|
|
|
|
}
|
2009-11-21 09:37:14 +00:00
|
|
|
|
2009-07-10 09:28:31 +00:00
|
|
|
if (page_setup != NULL &&
|
|
|
|
(gtk_print_operation_get_default_page_setup (op) == NULL ||
|
|
|
|
page_setup_set))
|
2008-05-21 02:17:30 +00:00
|
|
|
gtk_print_operation_set_default_page_setup (op, page_setup);
|
|
|
|
|
2006-06-02 15:16:13 +00:00
|
|
|
_gtk_print_context_set_page_setup (priv->print_context, page_setup);
|
2006-05-15 16:22:38 +00:00
|
|
|
|
2006-06-08 16:30:51 +00:00
|
|
|
if (!rdata->do_preview)
|
2006-04-21 15:09:32 +00:00
|
|
|
{
|
2006-06-02 15:16:13 +00:00
|
|
|
GtkPrintOperationUnix *op_unix;
|
|
|
|
cairo_t *cr;
|
|
|
|
|
2006-06-07 15:09:03 +00:00
|
|
|
op_unix = g_new0 (GtkPrintOperationUnix, 1);
|
2006-06-02 15:16:13 +00:00
|
|
|
priv->platform_data = op_unix;
|
|
|
|
priv->free_platform_data = (GDestroyNotify) op_unix_free;
|
|
|
|
op_unix->parent = rdata->parent;
|
|
|
|
|
|
|
|
priv->start_page = unix_start_page;
|
|
|
|
priv->end_page = unix_end_page;
|
|
|
|
priv->end_run = unix_end_run;
|
|
|
|
|
2006-06-03 03:11:31 +00:00
|
|
|
job = gtk_print_job_new (priv->job_name, printer, settings, page_setup);
|
|
|
|
op_unix->job = job;
|
|
|
|
gtk_print_job_set_track_print_status (job, priv->track_print_status);
|
2006-06-02 15:16:13 +00:00
|
|
|
|
2006-06-07 15:09:03 +00:00
|
|
|
op_unix->surface = gtk_print_job_get_surface (job, &priv->error);
|
2006-06-03 03:11:31 +00:00
|
|
|
if (op_unix->surface == NULL)
|
|
|
|
{
|
2006-06-07 15:09:03 +00:00
|
|
|
rdata->result = GTK_PRINT_OPERATION_RESULT_ERROR;
|
2006-06-03 03:11:31 +00:00
|
|
|
rdata->do_print = FALSE;
|
|
|
|
goto out;
|
|
|
|
}
|
2006-06-02 15:16:13 +00:00
|
|
|
|
|
|
|
cr = cairo_create (op_unix->surface);
|
2006-06-03 03:11:31 +00:00
|
|
|
gtk_print_context_set_cairo_context (priv->print_context, cr, 72, 72);
|
2006-06-02 15:16:13 +00:00
|
|
|
cairo_destroy (cr);
|
|
|
|
|
2006-06-03 03:11:31 +00:00
|
|
|
_gtk_print_operation_set_status (op, gtk_print_job_get_status (job), NULL);
|
2006-06-02 15:16:13 +00:00
|
|
|
|
|
|
|
op_unix->job_status_changed_tag =
|
2006-06-03 03:11:31 +00:00
|
|
|
g_signal_connect (job, "status-changed",
|
2006-06-02 15:16:13 +00:00
|
|
|
G_CALLBACK (job_status_changed_cb), op);
|
|
|
|
|
2010-12-18 22:45:31 +00:00
|
|
|
priv->print_pages = gtk_print_job_get_pages (job);
|
|
|
|
priv->page_ranges = gtk_print_job_get_page_ranges (job, &priv->num_page_ranges);
|
|
|
|
priv->manual_num_copies = gtk_print_job_get_num_copies (job);
|
|
|
|
priv->manual_collation = gtk_print_job_get_collate (job);
|
|
|
|
priv->manual_reverse = gtk_print_job_get_reverse (job);
|
|
|
|
priv->manual_page_set = gtk_print_job_get_page_set (job);
|
|
|
|
priv->manual_scale = gtk_print_job_get_scale (job);
|
|
|
|
priv->manual_orientation = gtk_print_job_get_rotate (job);
|
|
|
|
priv->manual_number_up = gtk_print_job_get_n_up (job);
|
|
|
|
priv->manual_number_up_layout = gtk_print_job_get_n_up_layout (job);
|
2006-06-02 15:16:13 +00:00
|
|
|
}
|
2006-04-21 15:09:32 +00:00
|
|
|
}
|
2006-06-02 15:16:13 +00:00
|
|
|
out:
|
2006-04-24 17:00:44 +00:00
|
|
|
if (rdata->print_cb)
|
2006-06-08 09:18:38 +00:00
|
|
|
rdata->print_cb (op, rdata->parent, rdata->do_print, rdata->result);
|
2006-04-24 17:00:44 +00:00
|
|
|
|
|
|
|
if (rdata->destroy)
|
|
|
|
rdata->destroy (rdata);
|
|
|
|
}
|
|
|
|
|
2006-06-02 15:16:13 +00:00
|
|
|
static void
|
2006-05-04 13:43:32 +00:00
|
|
|
handle_print_response (GtkWidget *dialog,
|
|
|
|
gint response,
|
|
|
|
gpointer data)
|
|
|
|
{
|
|
|
|
GtkPrintUnixDialog *pd = GTK_PRINT_UNIX_DIALOG (dialog);
|
|
|
|
PrintResponseData *rdata = data;
|
|
|
|
GtkPrintSettings *settings = NULL;
|
|
|
|
GtkPageSetup *page_setup = NULL;
|
|
|
|
GtkPrinter *printer = NULL;
|
2009-07-10 09:28:31 +00:00
|
|
|
gboolean page_setup_set = FALSE;
|
2006-05-04 13:43:32 +00:00
|
|
|
|
|
|
|
if (response == GTK_RESPONSE_OK)
|
|
|
|
{
|
|
|
|
printer = gtk_print_unix_dialog_get_selected_printer (GTK_PRINT_UNIX_DIALOG (pd));
|
2006-06-08 16:30:51 +00:00
|
|
|
|
|
|
|
rdata->result = GTK_PRINT_OPERATION_RESULT_APPLY;
|
|
|
|
rdata->do_preview = FALSE;
|
2006-06-02 15:16:13 +00:00
|
|
|
if (printer != NULL)
|
|
|
|
rdata->do_print = TRUE;
|
|
|
|
}
|
|
|
|
else if (response == GTK_RESPONSE_APPLY)
|
|
|
|
{
|
|
|
|
/* print preview */
|
2006-06-08 16:30:51 +00:00
|
|
|
rdata->result = GTK_PRINT_OPERATION_RESULT_APPLY;
|
|
|
|
rdata->do_preview = TRUE;
|
2006-05-04 13:43:32 +00:00
|
|
|
rdata->do_print = TRUE;
|
2006-06-16 16:36:25 +00:00
|
|
|
|
|
|
|
rdata->op->priv->action = GTK_PRINT_OPERATION_ACTION_PREVIEW;
|
2006-06-02 15:16:13 +00:00
|
|
|
}
|
2006-05-04 13:43:32 +00:00
|
|
|
|
2006-06-02 15:16:13 +00:00
|
|
|
if (rdata->do_print)
|
|
|
|
{
|
2006-05-04 13:43:32 +00:00
|
|
|
settings = gtk_print_unix_dialog_get_settings (GTK_PRINT_UNIX_DIALOG (pd));
|
|
|
|
page_setup = gtk_print_unix_dialog_get_page_setup (GTK_PRINT_UNIX_DIALOG (pd));
|
2009-07-10 09:28:31 +00:00
|
|
|
page_setup_set = gtk_print_unix_dialog_get_page_setup_set (GTK_PRINT_UNIX_DIALOG (pd));
|
2010-12-12 11:54:47 +00:00
|
|
|
|
|
|
|
/* Set new print settings now so that custom-widget options
|
|
|
|
* can be added to the settings in the callback
|
|
|
|
*/
|
|
|
|
gtk_print_operation_set_print_settings (rdata->op, settings);
|
2006-05-23 08:09:08 +00:00
|
|
|
g_signal_emit_by_name (rdata->op, "custom-widget-apply", rdata->op->priv->custom_widget);
|
2006-06-02 15:16:13 +00:00
|
|
|
}
|
2020-05-12 18:09:51 +00:00
|
|
|
|
|
|
|
if (rdata->loop)
|
|
|
|
g_main_loop_quit (rdata->loop);
|
2006-06-02 15:16:13 +00:00
|
|
|
|
2009-07-10 09:28:31 +00:00
|
|
|
finish_print (rdata, printer, page_setup, settings, page_setup_set);
|
2006-05-04 13:43:32 +00:00
|
|
|
|
|
|
|
if (settings)
|
|
|
|
g_object_unref (settings);
|
2006-06-02 15:16:13 +00:00
|
|
|
|
2020-05-09 14:26:22 +00:00
|
|
|
gtk_window_destroy (GTK_WINDOW (pd));
|
2006-05-04 13:43:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
2006-06-03 03:11:31 +00:00
|
|
|
found_printer (GtkPrinter *printer,
|
2006-05-04 13:43:32 +00:00
|
|
|
PrintResponseData *rdata)
|
|
|
|
{
|
|
|
|
GtkPrintOperation *op = rdata->op;
|
|
|
|
GtkPrintOperationPrivate *priv = op->priv;
|
|
|
|
GtkPrintSettings *settings = NULL;
|
|
|
|
GtkPageSetup *page_setup = NULL;
|
2020-04-30 15:28:00 +00:00
|
|
|
|
2006-05-04 13:43:32 +00:00
|
|
|
if (rdata->loop)
|
|
|
|
g_main_loop_quit (rdata->loop);
|
|
|
|
|
2006-06-03 03:11:31 +00:00
|
|
|
if (printer != NULL)
|
|
|
|
{
|
2006-06-07 15:09:03 +00:00
|
|
|
rdata->result = GTK_PRINT_OPERATION_RESULT_APPLY;
|
2006-05-04 13:43:32 +00:00
|
|
|
|
|
|
|
rdata->do_print = TRUE;
|
|
|
|
|
|
|
|
if (priv->print_settings)
|
|
|
|
settings = gtk_print_settings_copy (priv->print_settings);
|
|
|
|
else
|
|
|
|
settings = gtk_print_settings_new ();
|
|
|
|
|
|
|
|
gtk_print_settings_set_printer (settings,
|
|
|
|
gtk_printer_get_name (printer));
|
|
|
|
|
|
|
|
if (priv->default_page_setup)
|
|
|
|
page_setup = gtk_page_setup_copy (priv->default_page_setup);
|
|
|
|
else
|
|
|
|
page_setup = gtk_page_setup_new ();
|
|
|
|
}
|
|
|
|
|
2009-07-10 09:28:31 +00:00
|
|
|
finish_print (rdata, printer, page_setup, settings, FALSE);
|
2006-05-04 13:43:32 +00:00
|
|
|
|
|
|
|
if (settings)
|
|
|
|
g_object_unref (settings);
|
|
|
|
|
|
|
|
if (page_setup)
|
|
|
|
g_object_unref (page_setup);
|
|
|
|
}
|
|
|
|
|
2016-07-05 05:36:56 +00:00
|
|
|
static void
|
|
|
|
gtk_print_operation_unix_run_dialog_async (GtkPrintOperation *op,
|
|
|
|
gboolean show_dialog,
|
|
|
|
GtkWindow *parent,
|
|
|
|
GtkPrintOperationPrintFunc print_cb)
|
2006-04-24 17:00:44 +00:00
|
|
|
{
|
|
|
|
GtkWidget *pd;
|
|
|
|
PrintResponseData *rdata;
|
2006-06-03 03:11:31 +00:00
|
|
|
const gchar *printer_name;
|
2006-04-24 17:00:44 +00:00
|
|
|
|
|
|
|
rdata = g_new (PrintResponseData, 1);
|
|
|
|
rdata->op = g_object_ref (op);
|
|
|
|
rdata->do_print = FALSE;
|
2007-03-10 06:55:44 +00:00
|
|
|
rdata->do_preview = FALSE;
|
2006-04-24 17:00:44 +00:00
|
|
|
rdata->result = GTK_PRINT_OPERATION_RESULT_CANCEL;
|
|
|
|
rdata->print_cb = print_cb;
|
2006-05-04 13:43:32 +00:00
|
|
|
rdata->parent = parent;
|
|
|
|
rdata->loop = NULL;
|
2006-04-24 17:00:44 +00:00
|
|
|
rdata->destroy = print_response_data_free;
|
2006-04-21 15:09:32 +00:00
|
|
|
|
2006-06-07 15:09:03 +00:00
|
|
|
if (show_dialog)
|
2006-05-04 13:43:32 +00:00
|
|
|
{
|
|
|
|
pd = get_print_dialog (op, parent);
|
|
|
|
gtk_window_set_modal (GTK_WINDOW (pd), TRUE);
|
2006-04-24 17:00:44 +00:00
|
|
|
|
2006-05-04 13:43:32 +00:00
|
|
|
g_signal_connect (pd, "response",
|
|
|
|
G_CALLBACK (handle_print_response), rdata);
|
2018-07-25 15:42:26 +00:00
|
|
|
|
2006-05-04 13:43:32 +00:00
|
|
|
gtk_window_present (GTK_WINDOW (pd));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
printer_name = NULL;
|
|
|
|
if (op->priv->print_settings)
|
|
|
|
printer_name = gtk_print_settings_get_printer (op->priv->print_settings);
|
|
|
|
|
2006-06-03 03:11:31 +00:00
|
|
|
find_printer (printer_name, (GFunc) found_printer, rdata);
|
2006-05-04 13:43:32 +00:00
|
|
|
}
|
2006-04-24 17:00:44 +00:00
|
|
|
}
|
|
|
|
|
2006-06-16 17:17:56 +00:00
|
|
|
static cairo_status_t
|
|
|
|
write_preview (void *closure,
|
|
|
|
const unsigned char *data,
|
|
|
|
unsigned int length)
|
|
|
|
{
|
|
|
|
gint fd = GPOINTER_TO_INT (closure);
|
|
|
|
gssize written;
|
|
|
|
|
|
|
|
while (length > 0)
|
|
|
|
{
|
|
|
|
written = write (fd, data, length);
|
|
|
|
|
|
|
|
if (written == -1)
|
|
|
|
{
|
|
|
|
if (errno == EAGAIN || errno == EINTR)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
return CAIRO_STATUS_WRITE_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
data += written;
|
|
|
|
length -= written;
|
|
|
|
}
|
|
|
|
|
|
|
|
return CAIRO_STATUS_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
close_preview (void *data)
|
|
|
|
{
|
|
|
|
gint fd = GPOINTER_TO_INT (data);
|
|
|
|
|
|
|
|
close (fd);
|
|
|
|
}
|
|
|
|
|
2016-07-05 05:36:56 +00:00
|
|
|
static cairo_surface_t *
|
|
|
|
gtk_print_operation_unix_create_preview_surface (GtkPrintOperation *op,
|
|
|
|
GtkPageSetup *page_setup,
|
|
|
|
gdouble *dpi_x,
|
|
|
|
gdouble *dpi_y,
|
|
|
|
gchar **target)
|
2006-06-02 15:16:13 +00:00
|
|
|
{
|
2006-06-16 17:17:56 +00:00
|
|
|
gchar *filename;
|
|
|
|
gint fd;
|
2006-06-02 15:16:13 +00:00
|
|
|
GtkPaperSize *paper_size;
|
2006-06-03 03:11:31 +00:00
|
|
|
gdouble w, h;
|
2006-06-16 17:17:56 +00:00
|
|
|
cairo_surface_t *surface;
|
|
|
|
static cairo_user_data_key_t key;
|
2006-06-02 15:16:13 +00:00
|
|
|
|
2006-06-16 17:17:56 +00:00
|
|
|
filename = g_build_filename (g_get_tmp_dir (), "previewXXXXXX.pdf", NULL);
|
|
|
|
fd = g_mkstemp (filename);
|
2008-07-01 05:38:49 +00:00
|
|
|
|
|
|
|
if (fd < 0)
|
|
|
|
{
|
|
|
|
g_free (filename);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2006-06-16 17:17:56 +00:00
|
|
|
*target = filename;
|
2006-06-08 09:09:50 +00:00
|
|
|
|
2006-06-02 15:16:13 +00:00
|
|
|
paper_size = gtk_page_setup_get_paper_size (page_setup);
|
|
|
|
w = gtk_paper_size_get_width (paper_size, GTK_UNIT_POINTS);
|
|
|
|
h = gtk_paper_size_get_height (paper_size, GTK_UNIT_POINTS);
|
|
|
|
|
|
|
|
*dpi_x = *dpi_y = 72;
|
2008-07-01 05:38:49 +00:00
|
|
|
surface = cairo_pdf_surface_create_for_stream (write_preview, GINT_TO_POINTER (fd), w, h);
|
2006-06-16 17:17:56 +00:00
|
|
|
|
|
|
|
cairo_surface_set_user_data (surface, &key, GINT_TO_POINTER (fd), close_preview);
|
|
|
|
|
|
|
|
return surface;
|
2006-06-08 09:09:50 +00:00
|
|
|
}
|
|
|
|
|
2016-07-05 05:36:56 +00:00
|
|
|
static void
|
|
|
|
gtk_print_operation_unix_preview_start_page (GtkPrintOperation *op,
|
|
|
|
cairo_surface_t *surface,
|
|
|
|
cairo_t *cr)
|
2006-06-08 09:09:50 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2016-07-05 05:36:56 +00:00
|
|
|
static void
|
|
|
|
gtk_print_operation_unix_preview_end_page (GtkPrintOperation *op,
|
|
|
|
cairo_surface_t *surface,
|
|
|
|
cairo_t *cr)
|
2006-06-08 09:09:50 +00:00
|
|
|
{
|
|
|
|
cairo_show_page (cr);
|
2006-06-02 15:16:13 +00:00
|
|
|
}
|
|
|
|
|
2016-07-05 05:36:56 +00:00
|
|
|
static void
|
|
|
|
gtk_print_operation_unix_resize_preview_surface (GtkPrintOperation *op,
|
|
|
|
GtkPageSetup *page_setup,
|
|
|
|
cairo_surface_t *surface)
|
2006-06-02 15:16:13 +00:00
|
|
|
{
|
2006-06-03 03:11:31 +00:00
|
|
|
gdouble w, h;
|
2006-06-02 15:16:13 +00:00
|
|
|
|
2012-09-12 09:34:09 +00:00
|
|
|
w = gtk_page_setup_get_paper_width (page_setup, GTK_UNIT_POINTS);
|
|
|
|
h = gtk_page_setup_get_paper_height (page_setup, GTK_UNIT_POINTS);
|
2006-06-02 15:16:13 +00:00
|
|
|
cairo_pdf_surface_set_size (surface, w, h);
|
|
|
|
}
|
|
|
|
|
2016-07-05 05:36:56 +00:00
|
|
|
static GtkPrintOperationResult
|
|
|
|
gtk_print_operation_unix_run_dialog (GtkPrintOperation *op,
|
|
|
|
gboolean show_dialog,
|
|
|
|
GtkWindow *parent,
|
|
|
|
gboolean *do_print)
|
2006-04-24 17:00:44 +00:00
|
|
|
{
|
|
|
|
GtkWidget *pd;
|
|
|
|
PrintResponseData rdata;
|
2006-06-03 03:11:31 +00:00
|
|
|
const gchar *printer_name;
|
2006-04-24 17:00:44 +00:00
|
|
|
|
|
|
|
rdata.op = op;
|
|
|
|
rdata.do_print = FALSE;
|
2007-03-10 06:55:44 +00:00
|
|
|
rdata.do_preview = FALSE;
|
2006-04-24 17:00:44 +00:00
|
|
|
rdata.result = GTK_PRINT_OPERATION_RESULT_CANCEL;
|
|
|
|
rdata.print_cb = NULL;
|
|
|
|
rdata.destroy = NULL;
|
2006-05-04 13:43:32 +00:00
|
|
|
rdata.parent = parent;
|
|
|
|
rdata.loop = NULL;
|
2006-04-24 17:00:44 +00:00
|
|
|
|
2006-06-07 15:09:03 +00:00
|
|
|
if (show_dialog)
|
2006-05-04 13:43:32 +00:00
|
|
|
{
|
|
|
|
pd = get_print_dialog (op, parent);
|
2020-04-30 15:28:00 +00:00
|
|
|
gtk_window_set_modal (GTK_WINDOW (pd), TRUE);
|
|
|
|
|
|
|
|
g_signal_connect (pd, "response",
|
|
|
|
G_CALLBACK (handle_print_response), &rdata);
|
2006-06-02 15:16:13 +00:00
|
|
|
|
2020-04-30 15:28:00 +00:00
|
|
|
gtk_window_present (GTK_WINDOW (pd));
|
|
|
|
|
|
|
|
rdata.loop = g_main_loop_new (NULL, FALSE);
|
|
|
|
g_main_loop_run (rdata.loop);
|
|
|
|
g_main_loop_unref (rdata.loop);
|
|
|
|
rdata.loop = NULL;
|
2006-05-04 13:43:32 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
printer_name = NULL;
|
|
|
|
if (op->priv->print_settings)
|
|
|
|
printer_name = gtk_print_settings_get_printer (op->priv->print_settings);
|
|
|
|
|
|
|
|
rdata.loop = g_main_loop_new (NULL, FALSE);
|
|
|
|
find_printer (printer_name,
|
|
|
|
(GFunc) found_printer, &rdata);
|
2006-04-24 17:00:44 +00:00
|
|
|
|
2006-05-04 13:43:32 +00:00
|
|
|
g_main_loop_run (rdata.loop);
|
|
|
|
g_main_loop_unref (rdata.loop);
|
2006-06-02 15:16:13 +00:00
|
|
|
rdata.loop = NULL;
|
2006-05-04 13:43:32 +00:00
|
|
|
}
|
2006-04-24 17:00:44 +00:00
|
|
|
|
2006-05-04 13:43:32 +00:00
|
|
|
*do_print = rdata.do_print;
|
|
|
|
|
2006-04-24 17:00:44 +00:00
|
|
|
return rdata.result;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-06-03 03:11:31 +00:00
|
|
|
typedef struct
|
|
|
|
{
|
2006-05-03 17:34:55 +00:00
|
|
|
GtkPageSetup *page_setup;
|
|
|
|
GtkPageSetupDoneFunc done_cb;
|
|
|
|
gpointer data;
|
|
|
|
GDestroyNotify destroy;
|
2020-04-30 15:28:00 +00:00
|
|
|
GMainLoop *loop;
|
2006-04-24 17:00:44 +00:00
|
|
|
} PageSetupResponseData;
|
|
|
|
|
|
|
|
static void
|
|
|
|
page_setup_data_free (gpointer data)
|
|
|
|
{
|
|
|
|
PageSetupResponseData *rdata = data;
|
|
|
|
|
2006-06-11 02:59:51 +00:00
|
|
|
if (rdata->page_setup)
|
|
|
|
g_object_unref (rdata->page_setup);
|
|
|
|
|
2006-04-24 17:00:44 +00:00
|
|
|
g_free (rdata);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
handle_page_setup_response (GtkWidget *dialog,
|
|
|
|
gint response,
|
|
|
|
gpointer data)
|
|
|
|
{
|
|
|
|
GtkPageSetupUnixDialog *psd;
|
|
|
|
PageSetupResponseData *rdata = data;
|
2006-04-21 15:09:32 +00:00
|
|
|
|
2020-04-30 15:28:00 +00:00
|
|
|
if (rdata->loop)
|
|
|
|
g_main_loop_quit (rdata->loop);
|
|
|
|
|
2006-04-24 17:00:44 +00:00
|
|
|
psd = GTK_PAGE_SETUP_UNIX_DIALOG (dialog);
|
|
|
|
if (response == GTK_RESPONSE_OK)
|
|
|
|
rdata->page_setup = gtk_page_setup_unix_dialog_get_page_setup (psd);
|
|
|
|
|
2020-05-09 14:26:22 +00:00
|
|
|
gtk_window_destroy (GTK_WINDOW (dialog));
|
2006-04-24 17:00:44 +00:00
|
|
|
|
|
|
|
if (rdata->done_cb)
|
|
|
|
rdata->done_cb (rdata->page_setup, rdata->data);
|
|
|
|
|
|
|
|
if (rdata->destroy)
|
|
|
|
rdata->destroy (rdata);
|
|
|
|
}
|
|
|
|
|
|
|
|
static GtkWidget *
|
|
|
|
get_page_setup_dialog (GtkWindow *parent,
|
|
|
|
GtkPageSetup *page_setup,
|
|
|
|
GtkPrintSettings *settings)
|
|
|
|
{
|
|
|
|
GtkWidget *dialog;
|
|
|
|
|
|
|
|
dialog = gtk_page_setup_unix_dialog_new (NULL, parent);
|
|
|
|
if (page_setup)
|
|
|
|
gtk_page_setup_unix_dialog_set_page_setup (GTK_PAGE_SETUP_UNIX_DIALOG (dialog),
|
|
|
|
page_setup);
|
|
|
|
gtk_page_setup_unix_dialog_set_print_settings (GTK_PAGE_SETUP_UNIX_DIALOG (dialog),
|
|
|
|
settings);
|
|
|
|
|
|
|
|
return dialog;
|
2006-04-21 15:09:32 +00:00
|
|
|
}
|
|
|
|
|
2006-04-24 05:42:12 +00:00
|
|
|
/**
|
|
|
|
* gtk_print_run_page_setup_dialog:
|
2009-12-10 10:23:40 +00:00
|
|
|
* @parent: (allow-none): transient parent
|
|
|
|
* @page_setup: (allow-none): an existing #GtkPageSetup
|
2006-04-24 05:42:12 +00:00
|
|
|
* @settings: a #GtkPrintSettings
|
2009-12-10 10:23:40 +00:00
|
|
|
*
|
|
|
|
* Runs a page setup dialog, letting the user modify the values from
|
|
|
|
* @page_setup. If the user cancels the dialog, the returned #GtkPageSetup
|
2006-04-24 17:00:44 +00:00
|
|
|
* is identical to the passed in @page_setup, otherwise it contains the
|
|
|
|
* modifications done in the dialog.
|
|
|
|
*
|
|
|
|
* Note that this function may use a recursive mainloop to show the page
|
|
|
|
* setup dialog. See gtk_print_run_page_setup_dialog_async() if this is
|
|
|
|
* a problem.
|
2006-04-24 05:42:12 +00:00
|
|
|
*
|
2014-02-19 23:49:43 +00:00
|
|
|
* Returns: (transfer full): a new #GtkPageSetup
|
2006-04-24 05:42:12 +00:00
|
|
|
*/
|
2006-04-21 15:09:32 +00:00
|
|
|
GtkPageSetup *
|
|
|
|
gtk_print_run_page_setup_dialog (GtkWindow *parent,
|
|
|
|
GtkPageSetup *page_setup,
|
|
|
|
GtkPrintSettings *settings)
|
|
|
|
{
|
|
|
|
GtkWidget *dialog;
|
2006-04-24 17:00:44 +00:00
|
|
|
PageSetupResponseData rdata;
|
2006-04-21 15:09:32 +00:00
|
|
|
|
2006-04-24 17:00:44 +00:00
|
|
|
rdata.page_setup = NULL;
|
|
|
|
rdata.done_cb = NULL;
|
|
|
|
rdata.data = NULL;
|
|
|
|
rdata.destroy = NULL;
|
2020-04-30 15:28:00 +00:00
|
|
|
rdata.loop = g_main_loop_new (NULL, FALSE);
|
2006-04-24 17:00:44 +00:00
|
|
|
|
|
|
|
dialog = get_page_setup_dialog (parent, page_setup, settings);
|
2020-04-30 15:28:00 +00:00
|
|
|
|
|
|
|
g_signal_connect (dialog, "response",
|
|
|
|
G_CALLBACK (handle_page_setup_response),
|
|
|
|
&rdata);
|
|
|
|
|
|
|
|
gtk_window_present (GTK_WINDOW (dialog));
|
2006-04-24 17:00:44 +00:00
|
|
|
|
2020-04-30 15:28:00 +00:00
|
|
|
g_main_loop_run (rdata.loop);
|
|
|
|
g_main_loop_unref (rdata.loop);
|
|
|
|
rdata.loop = NULL;
|
|
|
|
|
2006-04-24 17:00:44 +00:00
|
|
|
if (rdata.page_setup)
|
|
|
|
return rdata.page_setup;
|
|
|
|
else if (page_setup)
|
|
|
|
return gtk_page_setup_copy (page_setup);
|
|
|
|
else
|
|
|
|
return gtk_page_setup_new ();
|
2006-04-21 15:09:32 +00:00
|
|
|
}
|
|
|
|
|
2006-04-24 17:00:44 +00:00
|
|
|
/**
|
|
|
|
* gtk_print_run_page_setup_dialog_async:
|
2010-02-19 16:53:17 +00:00
|
|
|
* @parent: (allow-none): transient parent, or %NULL
|
|
|
|
* @page_setup: (allow-none): an existing #GtkPageSetup, or %NULL
|
2006-04-24 17:00:44 +00:00
|
|
|
* @settings: a #GtkPrintSettings
|
2011-01-18 09:14:56 +00:00
|
|
|
* @done_cb: (scope async): a function to call when the user saves
|
|
|
|
* the modified page setup
|
2006-04-24 17:00:44 +00:00
|
|
|
* @data: user data to pass to @done_cb
|
|
|
|
*
|
2006-04-24 20:44:22 +00:00
|
|
|
* Runs a page setup dialog, letting the user modify the values from @page_setup.
|
2006-04-24 17:00:44 +00:00
|
|
|
*
|
2006-04-24 20:44:22 +00:00
|
|
|
* In contrast to gtk_print_run_page_setup_dialog(), this function returns after
|
|
|
|
* showing the page setup dialog on platforms that support this, and calls @done_cb
|
|
|
|
* from a signal handler for the ::response signal of the dialog.
|
2006-04-24 17:00:44 +00:00
|
|
|
*/
|
|
|
|
void
|
|
|
|
gtk_print_run_page_setup_dialog_async (GtkWindow *parent,
|
|
|
|
GtkPageSetup *page_setup,
|
|
|
|
GtkPrintSettings *settings,
|
|
|
|
GtkPageSetupDoneFunc done_cb,
|
|
|
|
gpointer data)
|
|
|
|
{
|
|
|
|
GtkWidget *dialog;
|
|
|
|
PageSetupResponseData *rdata;
|
|
|
|
|
|
|
|
dialog = get_page_setup_dialog (parent, page_setup, settings);
|
|
|
|
gtk_window_set_modal (GTK_WINDOW (dialog), TRUE);
|
|
|
|
|
|
|
|
rdata = g_new (PageSetupResponseData, 1);
|
|
|
|
rdata->page_setup = NULL;
|
|
|
|
rdata->done_cb = done_cb;
|
|
|
|
rdata->data = data;
|
|
|
|
rdata->destroy = page_setup_data_free;
|
2020-04-30 15:28:00 +00:00
|
|
|
rdata->loop = NULL;
|
2006-04-24 17:00:44 +00:00
|
|
|
|
|
|
|
g_signal_connect (dialog, "response",
|
|
|
|
G_CALLBACK (handle_page_setup_response), rdata);
|
2018-07-25 15:42:26 +00:00
|
|
|
|
2006-04-24 17:00:44 +00:00
|
|
|
gtk_window_present (GTK_WINDOW (dialog));
|
|
|
|
}
|
|
|
|
|
2006-06-03 03:11:31 +00:00
|
|
|
struct _PrinterFinder
|
|
|
|
{
|
2006-05-04 13:43:32 +00:00
|
|
|
gboolean found_printer;
|
|
|
|
GFunc func;
|
|
|
|
gpointer data;
|
2006-06-03 03:11:31 +00:00
|
|
|
gchar *printer_name;
|
2006-05-04 13:43:32 +00:00
|
|
|
GList *backends;
|
|
|
|
guint timeout_tag;
|
|
|
|
GtkPrinter *printer;
|
|
|
|
GtkPrinter *default_printer;
|
|
|
|
GtkPrinter *first_printer;
|
|
|
|
};
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
find_printer_idle (gpointer data)
|
|
|
|
{
|
|
|
|
PrinterFinder *finder = data;
|
|
|
|
GtkPrinter *printer;
|
|
|
|
|
|
|
|
if (finder->printer != NULL)
|
|
|
|
printer = finder->printer;
|
|
|
|
else if (finder->default_printer != NULL)
|
|
|
|
printer = finder->default_printer;
|
|
|
|
else if (finder->first_printer != NULL)
|
|
|
|
printer = finder->first_printer;
|
|
|
|
else
|
|
|
|
printer = NULL;
|
|
|
|
|
|
|
|
finder->func (printer, finder->data);
|
|
|
|
|
|
|
|
printer_finder_free (finder);
|
|
|
|
|
2012-01-31 00:12:27 +00:00
|
|
|
return G_SOURCE_REMOVE;
|
2006-05-04 13:43:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
printer_added_cb (GtkPrintBackend *backend,
|
|
|
|
GtkPrinter *printer,
|
|
|
|
PrinterFinder *finder)
|
|
|
|
{
|
2006-06-03 03:30:21 +00:00
|
|
|
if (finder->found_printer)
|
|
|
|
return;
|
|
|
|
|
|
|
|
/* FIXME this skips "Print to PDF" - is this intentional ? */
|
|
|
|
if (gtk_printer_is_virtual (printer))
|
2006-05-04 13:43:32 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
if (finder->printer_name != NULL &&
|
|
|
|
strcmp (gtk_printer_get_name (printer), finder->printer_name) == 0)
|
|
|
|
{
|
|
|
|
finder->printer = g_object_ref (printer);
|
|
|
|
finder->found_printer = TRUE;
|
|
|
|
}
|
|
|
|
else if (finder->default_printer == NULL &&
|
|
|
|
gtk_printer_is_default (printer))
|
|
|
|
{
|
|
|
|
finder->default_printer = g_object_ref (printer);
|
|
|
|
if (finder->printer_name == NULL)
|
|
|
|
finder->found_printer = TRUE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
if (finder->first_printer == NULL)
|
|
|
|
finder->first_printer = g_object_ref (printer);
|
|
|
|
|
|
|
|
if (finder->found_printer)
|
|
|
|
g_idle_add (find_printer_idle, finder);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
printer_list_done_cb (GtkPrintBackend *backend,
|
|
|
|
PrinterFinder *finder)
|
|
|
|
{
|
|
|
|
finder->backends = g_list_remove (finder->backends, backend);
|
|
|
|
|
|
|
|
g_signal_handlers_disconnect_by_func (backend, printer_added_cb, finder);
|
|
|
|
g_signal_handlers_disconnect_by_func (backend, printer_list_done_cb, finder);
|
|
|
|
|
|
|
|
gtk_print_backend_destroy (backend);
|
|
|
|
g_object_unref (backend);
|
|
|
|
|
|
|
|
if (finder->backends == NULL && !finder->found_printer)
|
|
|
|
g_idle_add (find_printer_idle, finder);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2006-06-03 03:11:31 +00:00
|
|
|
find_printer_init (PrinterFinder *finder,
|
2006-05-04 13:43:32 +00:00
|
|
|
GtkPrintBackend *backend)
|
|
|
|
{
|
|
|
|
GList *list;
|
|
|
|
GList *node;
|
|
|
|
|
|
|
|
list = gtk_print_backend_get_printer_list (backend);
|
|
|
|
|
|
|
|
node = list;
|
|
|
|
while (node != NULL)
|
|
|
|
{
|
|
|
|
printer_added_cb (backend, node->data, finder);
|
|
|
|
node = node->next;
|
|
|
|
|
|
|
|
if (finder->found_printer)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
g_list_free (list);
|
|
|
|
|
|
|
|
if (gtk_print_backend_printer_list_is_done (backend))
|
|
|
|
{
|
|
|
|
finder->backends = g_list_remove (finder->backends, backend);
|
|
|
|
gtk_print_backend_destroy (backend);
|
|
|
|
g_object_unref (backend);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2006-06-03 03:11:31 +00:00
|
|
|
g_signal_connect (backend, "printer-added",
|
2006-05-04 13:43:32 +00:00
|
|
|
(GCallback) printer_added_cb,
|
|
|
|
finder);
|
2006-06-03 03:11:31 +00:00
|
|
|
g_signal_connect (backend, "printer-list-done",
|
2006-05-04 13:43:32 +00:00
|
|
|
(GCallback) printer_list_done_cb,
|
|
|
|
finder);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
printer_finder_free (PrinterFinder *finder)
|
|
|
|
{
|
|
|
|
GList *l;
|
|
|
|
|
|
|
|
g_free (finder->printer_name);
|
|
|
|
|
|
|
|
if (finder->printer)
|
|
|
|
g_object_unref (finder->printer);
|
|
|
|
|
|
|
|
if (finder->default_printer)
|
|
|
|
g_object_unref (finder->default_printer);
|
|
|
|
|
|
|
|
if (finder->first_printer)
|
|
|
|
g_object_unref (finder->first_printer);
|
|
|
|
|
|
|
|
for (l = finder->backends; l != NULL; l = l->next)
|
|
|
|
{
|
|
|
|
GtkPrintBackend *backend = l->data;
|
|
|
|
g_signal_handlers_disconnect_by_func (backend, printer_added_cb, finder);
|
|
|
|
g_signal_handlers_disconnect_by_func (backend, printer_list_done_cb, finder);
|
|
|
|
gtk_print_backend_destroy (backend);
|
|
|
|
g_object_unref (backend);
|
|
|
|
}
|
|
|
|
|
|
|
|
g_list_free (finder->backends);
|
|
|
|
|
|
|
|
g_free (finder);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2006-06-03 03:11:31 +00:00
|
|
|
find_printer (const gchar *printer,
|
|
|
|
GFunc func,
|
|
|
|
gpointer data)
|
2006-05-04 13:43:32 +00:00
|
|
|
{
|
|
|
|
GList *node, *next;
|
|
|
|
PrinterFinder *finder;
|
|
|
|
|
|
|
|
finder = g_new0 (PrinterFinder, 1);
|
|
|
|
|
|
|
|
finder->printer_name = g_strdup (printer);
|
|
|
|
finder->func = func;
|
|
|
|
finder->data = data;
|
|
|
|
|
|
|
|
finder->backends = NULL;
|
|
|
|
if (g_module_supported ())
|
|
|
|
finder->backends = gtk_print_backend_load_modules ();
|
|
|
|
|
|
|
|
for (node = finder->backends; !finder->found_printer && node != NULL; node = next)
|
|
|
|
{
|
|
|
|
next = node->next;
|
|
|
|
find_printer_init (finder, GTK_PRINT_BACKEND (node->data));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (finder->backends == NULL && !finder->found_printer)
|
|
|
|
g_idle_add (find_printer_idle, finder);
|
|
|
|
}
|
2016-07-05 05:36:56 +00:00
|
|
|
|
|
|
|
|
|
|
|
GtkPrintOperationResult
|
|
|
|
_gtk_print_operation_platform_backend_run_dialog (GtkPrintOperation *op,
|
|
|
|
gboolean show_dialog,
|
|
|
|
GtkWindow *parent,
|
|
|
|
gboolean *do_print)
|
|
|
|
{
|
2018-11-01 17:46:04 +00:00
|
|
|
if (gdk_should_use_portal ())
|
2016-07-05 05:36:56 +00:00
|
|
|
return gtk_print_operation_portal_run_dialog (op, show_dialog, parent, do_print);
|
|
|
|
else
|
|
|
|
return gtk_print_operation_unix_run_dialog (op, show_dialog, parent, do_print);
|
|
|
|
}
|
|
|
|
void
|
|
|
|
_gtk_print_operation_platform_backend_run_dialog_async (GtkPrintOperation *op,
|
|
|
|
gboolean show_dialog,
|
|
|
|
GtkWindow *parent,
|
|
|
|
GtkPrintOperationPrintFunc print_cb)
|
|
|
|
{
|
2018-11-01 17:46:04 +00:00
|
|
|
if (gdk_should_use_portal ())
|
2016-07-05 05:36:56 +00:00
|
|
|
gtk_print_operation_portal_run_dialog_async (op, show_dialog, parent, print_cb);
|
|
|
|
else
|
|
|
|
gtk_print_operation_unix_run_dialog_async (op, show_dialog, parent, print_cb);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
_gtk_print_operation_platform_backend_launch_preview (GtkPrintOperation *op,
|
|
|
|
cairo_surface_t *surface,
|
|
|
|
GtkWindow *parent,
|
|
|
|
const gchar *filename)
|
|
|
|
{
|
2018-11-01 17:46:04 +00:00
|
|
|
if (gdk_should_use_portal ())
|
2016-07-05 05:36:56 +00:00
|
|
|
gtk_print_operation_portal_launch_preview (op, surface, parent, filename);
|
|
|
|
else
|
|
|
|
gtk_print_operation_unix_launch_preview (op, surface, parent, filename);
|
|
|
|
}
|
|
|
|
|
|
|
|
cairo_surface_t *
|
|
|
|
_gtk_print_operation_platform_backend_create_preview_surface (GtkPrintOperation *op,
|
|
|
|
GtkPageSetup *page_setup,
|
|
|
|
gdouble *dpi_x,
|
|
|
|
gdouble *dpi_y,
|
|
|
|
gchar **target)
|
|
|
|
{
|
|
|
|
return gtk_print_operation_unix_create_preview_surface (op, page_setup, dpi_x, dpi_y, target);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
_gtk_print_operation_platform_backend_resize_preview_surface (GtkPrintOperation *op,
|
|
|
|
GtkPageSetup *page_setup,
|
|
|
|
cairo_surface_t *surface)
|
|
|
|
{
|
|
|
|
gtk_print_operation_unix_resize_preview_surface (op, page_setup, surface);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
_gtk_print_operation_platform_backend_preview_start_page (GtkPrintOperation *op,
|
|
|
|
cairo_surface_t *surface,
|
|
|
|
cairo_t *cr)
|
|
|
|
{
|
|
|
|
gtk_print_operation_unix_preview_start_page (op, surface, cr);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
_gtk_print_operation_platform_backend_preview_end_page (GtkPrintOperation *op,
|
|
|
|
cairo_surface_t *surface,
|
|
|
|
cairo_t *cr)
|
|
|
|
{
|
|
|
|
gtk_print_operation_unix_preview_end_page (op, surface, cr);
|
|
|
|
}
|