2008-07-01 22:57:50 +00:00
|
|
|
/* GTK - The GIMP Toolkit
|
2007-04-29 03:31:03 +00:00
|
|
|
* gtkprintbackendlpr.c: LPR implementation of GtkPrintBackend
|
2006-04-21 15:09:32 +00:00
|
|
|
* for printing to lpr
|
2007-04-29 03:31:03 +00:00
|
|
|
* Copyright (C) 2006, 2007 Red Hat, Inc.
|
2006-04-21 15:09:32 +00:00
|
|
|
*
|
|
|
|
* 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
|
|
|
*/
|
|
|
|
|
2008-06-22 14:28:52 +00:00
|
|
|
#include "config.h"
|
2006-04-21 15:09:32 +00:00
|
|
|
#include <unistd.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include <errno.h>
|
|
|
|
#include <cairo.h>
|
|
|
|
#include <cairo-ps.h>
|
|
|
|
|
|
|
|
#include <glib/gi18n-lib.h>
|
|
|
|
|
2008-05-28 12:49:11 +00:00
|
|
|
#include <gtk/gtk.h>
|
2019-05-26 20:29:57 +00:00
|
|
|
#include "gtkprinterprivate.h"
|
2006-04-21 15:09:32 +00:00
|
|
|
|
2008-05-28 12:49:11 +00:00
|
|
|
#include "gtkprintbackendlpr.h"
|
|
|
|
|
2006-04-21 15:09:32 +00:00
|
|
|
typedef struct _GtkPrintBackendLprClass GtkPrintBackendLprClass;
|
|
|
|
|
|
|
|
#define GTK_PRINT_BACKEND_LPR_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GTK_TYPE_PRINT_BACKEND_LPR, GtkPrintBackendLprClass))
|
|
|
|
#define GTK_IS_PRINT_BACKEND_LPR_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GTK_TYPE_PRINT_BACKEND_LPR))
|
|
|
|
#define GTK_PRINT_BACKEND_LPR_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GTK_TYPE_PRINT_BACKEND_LPR, GtkPrintBackendLprClass))
|
|
|
|
|
|
|
|
#define _LPR_MAX_CHUNK_SIZE 8192
|
|
|
|
|
|
|
|
struct _GtkPrintBackendLprClass
|
|
|
|
{
|
2006-05-04 13:43:32 +00:00
|
|
|
GtkPrintBackendClass parent_class;
|
2006-04-21 15:09:32 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct _GtkPrintBackendLpr
|
|
|
|
{
|
2006-05-04 13:43:32 +00:00
|
|
|
GtkPrintBackend parent_instance;
|
2006-04-21 15:09:32 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static GObjectClass *backend_parent_class;
|
|
|
|
|
|
|
|
static void lpr_printer_get_settings_from_options (GtkPrinter *printer,
|
|
|
|
GtkPrinterOptionSet *options,
|
|
|
|
GtkPrintSettings *settings);
|
|
|
|
static GtkPrinterOptionSet *lpr_printer_get_options (GtkPrinter *printer,
|
|
|
|
GtkPrintSettings *settings,
|
2006-06-19 05:09:49 +00:00
|
|
|
GtkPageSetup *page_setup,
|
|
|
|
GtkPrintCapabilities capabilities);
|
2006-04-21 15:09:32 +00:00
|
|
|
static void lpr_printer_prepare_for_print (GtkPrinter *printer,
|
|
|
|
GtkPrintJob *print_job,
|
|
|
|
GtkPrintSettings *settings,
|
|
|
|
GtkPageSetup *page_setup);
|
2006-05-04 13:43:32 +00:00
|
|
|
static cairo_surface_t * lpr_printer_create_cairo_surface (GtkPrinter *printer,
|
2006-06-16 18:29:09 +00:00
|
|
|
GtkPrintSettings *settings,
|
2020-07-24 20:32:16 +00:00
|
|
|
double width,
|
|
|
|
double height,
|
2006-06-21 18:16:58 +00:00
|
|
|
GIOChannel *cache_io);
|
2006-05-04 13:43:32 +00:00
|
|
|
static void gtk_print_backend_lpr_print_stream (GtkPrintBackend *print_backend,
|
|
|
|
GtkPrintJob *job,
|
2006-06-21 18:16:58 +00:00
|
|
|
GIOChannel *data_io,
|
2006-05-04 13:43:32 +00:00
|
|
|
GtkPrintJobCompleteFunc callback,
|
|
|
|
gpointer user_data,
|
2006-06-21 18:16:58 +00:00
|
|
|
GDestroyNotify dnotify);
|
2006-04-21 15:09:32 +00:00
|
|
|
|
2018-02-19 02:07:09 +00:00
|
|
|
G_DEFINE_DYNAMIC_TYPE (GtkPrintBackendLpr, gtk_print_backend_lpr, GTK_TYPE_PRINT_BACKEND)
|
2006-04-21 15:09:32 +00:00
|
|
|
|
2018-02-18 23:00:42 +00:00
|
|
|
void
|
|
|
|
g_io_module_load (GIOModule *module)
|
2006-04-21 15:09:32 +00:00
|
|
|
{
|
2018-02-18 23:00:42 +00:00
|
|
|
g_type_module_use (G_TYPE_MODULE (module));
|
2006-04-21 15:09:32 +00:00
|
|
|
|
2018-02-18 23:00:42 +00:00
|
|
|
gtk_print_backend_lpr_register_type (G_TYPE_MODULE (module));
|
2006-04-21 15:09:32 +00:00
|
|
|
|
2018-02-18 23:00:42 +00:00
|
|
|
g_io_extension_point_implement (GTK_PRINT_BACKEND_EXTENSION_POINT_NAME,
|
2018-02-19 02:07:09 +00:00
|
|
|
GTK_TYPE_PRINT_BACKEND_LPR,
|
2018-02-18 23:00:42 +00:00
|
|
|
"lpr",
|
|
|
|
10);
|
2006-04-21 15:09:32 +00:00
|
|
|
}
|
2018-02-18 23:00:42 +00:00
|
|
|
|
|
|
|
void
|
|
|
|
g_io_module_unload (GIOModule *module)
|
2006-04-21 15:09:32 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2018-02-18 23:00:42 +00:00
|
|
|
char **
|
|
|
|
g_io_module_query (void)
|
2006-04-21 15:09:32 +00:00
|
|
|
{
|
2018-02-18 23:00:42 +00:00
|
|
|
char *eps[] = {
|
|
|
|
GTK_PRINT_BACKEND_EXTENSION_POINT_NAME,
|
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
|
|
|
return g_strdupv (eps);
|
2006-04-21 15:09:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gtk_print_backend_lpr_new:
|
|
|
|
*
|
|
|
|
* Creates a new #GtkPrintBackendLpr object. #GtkPrintBackendLpr
|
|
|
|
* implements the #GtkPrintBackend interface with direct access to
|
|
|
|
* the filesystem using Unix/Linux API calls
|
|
|
|
*
|
2014-02-19 23:49:43 +00:00
|
|
|
* Returns: the new #GtkPrintBackendLpr object
|
2006-04-21 15:09:32 +00:00
|
|
|
**/
|
|
|
|
GtkPrintBackend *
|
|
|
|
gtk_print_backend_lpr_new (void)
|
|
|
|
{
|
|
|
|
return g_object_new (GTK_TYPE_PRINT_BACKEND_LPR, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_print_backend_lpr_class_init (GtkPrintBackendLprClass *class)
|
|
|
|
{
|
2006-05-04 13:43:32 +00:00
|
|
|
GtkPrintBackendClass *backend_class = GTK_PRINT_BACKEND_CLASS (class);
|
|
|
|
|
2006-04-21 15:09:32 +00:00
|
|
|
backend_parent_class = g_type_class_peek_parent (class);
|
|
|
|
|
2006-05-04 13:43:32 +00:00
|
|
|
backend_class->print_stream = gtk_print_backend_lpr_print_stream;
|
|
|
|
backend_class->printer_create_cairo_surface = lpr_printer_create_cairo_surface;
|
|
|
|
backend_class->printer_get_options = lpr_printer_get_options;
|
|
|
|
backend_class->printer_get_settings_from_options = lpr_printer_get_settings_from_options;
|
|
|
|
backend_class->printer_prepare_for_print = lpr_printer_prepare_for_print;
|
2006-04-21 15:09:32 +00:00
|
|
|
}
|
|
|
|
|
2018-02-18 23:00:42 +00:00
|
|
|
static void
|
|
|
|
gtk_print_backend_lpr_class_finalize (GtkPrintBackendLprClass *class)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2006-04-21 15:09:32 +00:00
|
|
|
static cairo_status_t
|
2006-06-16 18:29:09 +00:00
|
|
|
_cairo_write (void *closure,
|
2006-04-21 15:09:32 +00:00
|
|
|
const unsigned char *data,
|
|
|
|
unsigned int length)
|
|
|
|
{
|
2006-06-21 18:16:58 +00:00
|
|
|
GIOChannel *io = (GIOChannel *)closure;
|
|
|
|
gsize written;
|
|
|
|
GError *error;
|
|
|
|
|
|
|
|
error = NULL;
|
|
|
|
|
|
|
|
GTK_NOTE (PRINTING,
|
2020-08-21 12:41:13 +00:00
|
|
|
g_print ("LPR Backend: Writing %i byte chunk to temp file\n", length));
|
2006-06-21 18:16:58 +00:00
|
|
|
|
2006-06-16 18:29:09 +00:00
|
|
|
while (length > 0)
|
|
|
|
{
|
2020-07-24 18:40:36 +00:00
|
|
|
g_io_channel_write_chars (io, (const char *)data, length, &written, &error);
|
2006-06-16 18:29:09 +00:00
|
|
|
|
2006-06-21 18:16:58 +00:00
|
|
|
if (error != NULL)
|
2006-06-16 18:29:09 +00:00
|
|
|
{
|
2006-06-21 18:16:58 +00:00
|
|
|
GTK_NOTE (PRINTING,
|
2020-08-21 12:41:13 +00:00
|
|
|
g_print ("LPR Backend: Error writing to temp file, %s\n", error->message));
|
2006-06-21 18:16:58 +00:00
|
|
|
|
|
|
|
g_error_free (error);
|
2006-06-16 18:29:09 +00:00
|
|
|
return CAIRO_STATUS_WRITE_ERROR;
|
|
|
|
}
|
|
|
|
|
2006-06-21 18:16:58 +00:00
|
|
|
GTK_NOTE (PRINTING,
|
2009-10-21 03:19:39 +00:00
|
|
|
g_print ("LPR Backend: Wrote %" G_GSIZE_FORMAT " bytes to temp file\n", written));
|
2006-06-21 18:16:58 +00:00
|
|
|
|
2006-06-16 18:29:09 +00:00
|
|
|
data += written;
|
|
|
|
length -= written;
|
|
|
|
}
|
|
|
|
|
|
|
|
return CAIRO_STATUS_SUCCESS;
|
2006-04-21 15:09:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static cairo_surface_t *
|
2006-06-16 18:29:09 +00:00
|
|
|
lpr_printer_create_cairo_surface (GtkPrinter *printer,
|
|
|
|
GtkPrintSettings *settings,
|
2020-07-24 20:32:16 +00:00
|
|
|
double width,
|
|
|
|
double height,
|
2006-06-21 18:16:58 +00:00
|
|
|
GIOChannel *cache_io)
|
2006-04-21 15:09:32 +00:00
|
|
|
{
|
|
|
|
cairo_surface_t *surface;
|
|
|
|
|
2006-06-21 18:16:58 +00:00
|
|
|
surface = cairo_ps_surface_create_for_stream (_cairo_write, cache_io, width, height);
|
2006-04-21 15:09:32 +00:00
|
|
|
|
2008-10-30 16:24:27 +00:00
|
|
|
cairo_surface_set_fallback_resolution (surface,
|
|
|
|
2.0 * gtk_print_settings_get_printer_lpi (settings),
|
|
|
|
2.0 * gtk_print_settings_get_printer_lpi (settings));
|
2006-04-21 15:09:32 +00:00
|
|
|
|
|
|
|
return surface;
|
|
|
|
}
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
GtkPrintBackend *backend;
|
|
|
|
GtkPrintJobCompleteFunc callback;
|
|
|
|
GtkPrintJob *job;
|
|
|
|
gpointer user_data;
|
|
|
|
GDestroyNotify dnotify;
|
|
|
|
|
2006-06-21 18:16:58 +00:00
|
|
|
GIOChannel *in;
|
2006-04-21 15:09:32 +00:00
|
|
|
} _PrintStreamData;
|
|
|
|
|
|
|
|
static void
|
|
|
|
lpr_print_cb (GtkPrintBackendLpr *print_backend,
|
2006-06-16 18:29:09 +00:00
|
|
|
GError *error,
|
|
|
|
gpointer user_data)
|
2006-04-21 15:09:32 +00:00
|
|
|
{
|
|
|
|
_PrintStreamData *ps = (_PrintStreamData *) user_data;
|
|
|
|
|
2006-06-21 18:16:58 +00:00
|
|
|
if (ps->in != NULL)
|
|
|
|
g_io_channel_unref (ps->in);
|
2006-04-21 15:09:32 +00:00
|
|
|
|
|
|
|
if (ps->callback)
|
|
|
|
ps->callback (ps->job, ps->user_data, error);
|
|
|
|
|
|
|
|
if (ps->dnotify)
|
|
|
|
ps->dnotify (ps->user_data);
|
|
|
|
|
2006-06-21 05:56:14 +00:00
|
|
|
gtk_print_job_set_status (ps->job,
|
|
|
|
error ? GTK_PRINT_STATUS_FINISHED_ABORTED
|
|
|
|
: GTK_PRINT_STATUS_FINISHED);
|
2006-04-21 15:09:32 +00:00
|
|
|
|
|
|
|
if (ps->job)
|
|
|
|
g_object_unref (ps->job);
|
|
|
|
|
|
|
|
g_free (ps);
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2006-06-16 18:29:09 +00:00
|
|
|
lpr_write (GIOChannel *source,
|
|
|
|
GIOCondition con,
|
|
|
|
gpointer user_data)
|
2006-04-21 15:09:32 +00:00
|
|
|
{
|
2020-07-24 18:40:36 +00:00
|
|
|
char buf[_LPR_MAX_CHUNK_SIZE];
|
2006-04-21 15:09:32 +00:00
|
|
|
gsize bytes_read;
|
|
|
|
GError *error;
|
2006-06-21 18:16:58 +00:00
|
|
|
GIOStatus status;
|
2006-04-21 15:09:32 +00:00
|
|
|
_PrintStreamData *ps = (_PrintStreamData *) user_data;
|
|
|
|
|
|
|
|
error = NULL;
|
|
|
|
|
2006-06-21 18:16:58 +00:00
|
|
|
status =
|
|
|
|
g_io_channel_read_chars (source,
|
|
|
|
buf,
|
|
|
|
_LPR_MAX_CHUNK_SIZE,
|
|
|
|
&bytes_read,
|
|
|
|
&error);
|
2006-04-21 15:09:32 +00:00
|
|
|
|
2006-06-21 18:16:58 +00:00
|
|
|
if (status != G_IO_STATUS_ERROR)
|
2006-04-21 15:09:32 +00:00
|
|
|
{
|
2006-06-21 18:16:58 +00:00
|
|
|
gsize bytes_written;
|
|
|
|
|
2009-09-16 07:59:56 +00:00
|
|
|
g_io_channel_write_chars (ps->in,
|
2006-06-21 18:16:58 +00:00
|
|
|
buf,
|
|
|
|
bytes_read,
|
|
|
|
&bytes_written,
|
|
|
|
&error);
|
2006-04-21 15:09:32 +00:00
|
|
|
}
|
|
|
|
|
2006-06-21 18:16:58 +00:00
|
|
|
if (error != NULL || status == G_IO_STATUS_EOF)
|
2006-04-21 15:09:32 +00:00
|
|
|
{
|
2006-06-21 05:56:14 +00:00
|
|
|
lpr_print_cb (GTK_PRINT_BACKEND_LPR (ps->backend),
|
|
|
|
error, user_data);
|
|
|
|
|
2006-04-21 15:09:32 +00:00
|
|
|
|
2006-06-21 18:16:58 +00:00
|
|
|
if (error != NULL)
|
|
|
|
{
|
|
|
|
GTK_NOTE (PRINTING,
|
|
|
|
g_print ("LPR Backend: %s\n", error->message));
|
|
|
|
|
|
|
|
g_error_free (error);
|
|
|
|
}
|
|
|
|
|
2006-04-21 15:09:32 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2006-06-21 18:16:58 +00:00
|
|
|
GTK_NOTE (PRINTING,
|
2020-08-21 12:41:13 +00:00
|
|
|
g_print ("LPR Backend: Writing %" G_GSIZE_FORMAT " byte chunk to lpr pipe\n", bytes_read));
|
2006-06-21 18:16:58 +00:00
|
|
|
|
|
|
|
|
2006-04-21 15:09:32 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
#define LPR_COMMAND "lpr"
|
|
|
|
|
|
|
|
static void
|
2006-06-16 18:29:09 +00:00
|
|
|
gtk_print_backend_lpr_print_stream (GtkPrintBackend *print_backend,
|
|
|
|
GtkPrintJob *job,
|
2006-06-21 18:16:58 +00:00
|
|
|
GIOChannel *data_io,
|
2006-04-21 15:09:32 +00:00
|
|
|
GtkPrintJobCompleteFunc callback,
|
2006-06-16 18:29:09 +00:00
|
|
|
gpointer user_data,
|
2006-06-21 18:16:58 +00:00
|
|
|
GDestroyNotify dnotify)
|
2006-04-21 15:09:32 +00:00
|
|
|
{
|
2006-06-21 05:56:14 +00:00
|
|
|
GError *print_error = NULL;
|
2006-04-21 15:09:32 +00:00
|
|
|
_PrintStreamData *ps;
|
|
|
|
GtkPrintSettings *settings;
|
2020-07-24 13:54:49 +00:00
|
|
|
int argc;
|
|
|
|
int in_fd;
|
2020-07-24 18:40:36 +00:00
|
|
|
char **argv = NULL;
|
2006-06-21 18:16:58 +00:00
|
|
|
const char *cmd_line;
|
2009-09-09 04:53:32 +00:00
|
|
|
|
2006-04-21 15:09:32 +00:00
|
|
|
settings = gtk_print_job_get_settings (job);
|
|
|
|
|
|
|
|
cmd_line = gtk_print_settings_get (settings, "lpr-commandline");
|
|
|
|
if (cmd_line == NULL)
|
|
|
|
cmd_line = LPR_COMMAND;
|
2009-09-09 04:53:32 +00:00
|
|
|
|
2006-04-21 15:09:32 +00:00
|
|
|
ps = g_new0 (_PrintStreamData, 1);
|
|
|
|
ps->callback = callback;
|
|
|
|
ps->user_data = user_data;
|
|
|
|
ps->dnotify = dnotify;
|
|
|
|
ps->job = g_object_ref (job);
|
2006-06-21 18:16:58 +00:00
|
|
|
ps->in = NULL;
|
2006-04-21 15:09:32 +00:00
|
|
|
|
|
|
|
/* spawn lpr with pipes and pipe ps file to lpr */
|
2006-06-21 05:56:14 +00:00
|
|
|
if (!g_shell_parse_argv (cmd_line, &argc, &argv, &print_error))
|
2009-09-09 04:53:32 +00:00
|
|
|
goto out;
|
2006-04-21 15:09:32 +00:00
|
|
|
|
|
|
|
if (!g_spawn_async_with_pipes (NULL,
|
|
|
|
argv,
|
|
|
|
NULL,
|
|
|
|
G_SPAWN_SEARCH_PATH,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
2006-06-21 18:16:58 +00:00
|
|
|
&in_fd,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
2006-06-21 05:56:14 +00:00
|
|
|
&print_error))
|
2006-04-21 15:09:32 +00:00
|
|
|
goto out;
|
|
|
|
|
2006-06-21 18:16:58 +00:00
|
|
|
ps->in = g_io_channel_unix_new (in_fd);
|
|
|
|
|
|
|
|
g_io_channel_set_encoding (ps->in, NULL, &print_error);
|
|
|
|
if (print_error != NULL)
|
|
|
|
{
|
|
|
|
if (ps->in != NULL)
|
|
|
|
g_io_channel_unref (ps->in);
|
2009-09-09 04:53:32 +00:00
|
|
|
|
2006-06-21 18:16:58 +00:00
|
|
|
goto out;
|
2006-04-21 15:09:32 +00:00
|
|
|
}
|
|
|
|
|
2006-12-28 04:22:46 +00:00
|
|
|
g_io_channel_set_close_on_unref (ps->in, TRUE);
|
|
|
|
|
2009-09-09 04:53:32 +00:00
|
|
|
g_io_add_watch (data_io,
|
2006-04-21 15:09:32 +00:00
|
|
|
G_IO_IN | G_IO_PRI | G_IO_ERR | G_IO_HUP,
|
|
|
|
(GIOFunc) lpr_write,
|
|
|
|
ps);
|
|
|
|
|
|
|
|
out:
|
2006-06-21 18:16:58 +00:00
|
|
|
if (argv != NULL)
|
|
|
|
g_strfreev (argv);
|
|
|
|
|
|
|
|
if (print_error != NULL)
|
|
|
|
{
|
|
|
|
lpr_print_cb (GTK_PRINT_BACKEND_LPR (print_backend),
|
|
|
|
print_error, ps);
|
|
|
|
g_error_free (print_error);
|
|
|
|
}
|
2006-04-21 15:09:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2006-05-04 13:43:32 +00:00
|
|
|
gtk_print_backend_lpr_init (GtkPrintBackendLpr *backend)
|
2006-04-21 15:09:32 +00:00
|
|
|
{
|
|
|
|
GtkPrinter *printer;
|
|
|
|
|
2018-11-17 18:04:35 +00:00
|
|
|
printer = g_object_new (GTK_TYPE_PRINTER,
|
|
|
|
"name", _("Print to LPR"),
|
|
|
|
"backend", backend,
|
|
|
|
"is-virtual", FALSE,
|
|
|
|
"accepts-pdf", TRUE,
|
|
|
|
"accepts-ps", TRUE,
|
|
|
|
NULL);
|
2006-04-21 15:09:32 +00:00
|
|
|
gtk_printer_set_has_details (printer, TRUE);
|
2010-08-10 00:09:02 +00:00
|
|
|
gtk_printer_set_icon_name (printer, "printer");
|
2006-04-21 15:09:32 +00:00
|
|
|
gtk_printer_set_is_active (printer, TRUE);
|
2006-05-04 13:43:32 +00:00
|
|
|
gtk_printer_set_is_default (printer, TRUE);
|
2006-04-21 15:09:32 +00:00
|
|
|
|
2006-05-04 13:43:32 +00:00
|
|
|
gtk_print_backend_add_printer (GTK_PRINT_BACKEND (backend), printer);
|
|
|
|
g_object_unref (printer);
|
2007-04-26 06:14:03 +00:00
|
|
|
gtk_print_backend_set_list_done (GTK_PRINT_BACKEND (backend));
|
2006-04-21 15:09:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static GtkPrinterOptionSet *
|
2006-06-19 05:09:49 +00:00
|
|
|
lpr_printer_get_options (GtkPrinter *printer,
|
|
|
|
GtkPrintSettings *settings,
|
|
|
|
GtkPageSetup *page_setup,
|
|
|
|
GtkPrintCapabilities capabilities)
|
2006-04-21 15:09:32 +00:00
|
|
|
{
|
|
|
|
GtkPrinterOptionSet *set;
|
|
|
|
GtkPrinterOption *option;
|
|
|
|
const char *command;
|
|
|
|
char *n_up[] = {"1", "2", "4", "6", "9", "16" };
|
|
|
|
|
|
|
|
set = gtk_printer_option_set_new ();
|
|
|
|
|
|
|
|
option = gtk_printer_option_new ("gtk-n-up", _("Pages Per Sheet"), GTK_PRINTER_OPTION_TYPE_PICKONE);
|
|
|
|
gtk_printer_option_choices_from_array (option, G_N_ELEMENTS (n_up),
|
|
|
|
n_up, n_up);
|
|
|
|
gtk_printer_option_set (option, "1");
|
|
|
|
gtk_printer_option_set_add (set, option);
|
|
|
|
g_object_unref (option);
|
|
|
|
|
|
|
|
option = gtk_printer_option_new ("gtk-main-page-custom-input", _("Command Line"), GTK_PRINTER_OPTION_TYPE_STRING);
|
2009-08-11 07:24:18 +00:00
|
|
|
gtk_printer_option_set_activates_default (option, TRUE);
|
2006-06-17 05:19:18 +00:00
|
|
|
option->group = g_strdup ("GtkPrintDialogExtension");
|
2006-04-21 15:09:32 +00:00
|
|
|
if (settings != NULL &&
|
|
|
|
(command = gtk_print_settings_get (settings, "lpr-commandline"))!= NULL)
|
|
|
|
gtk_printer_option_set (option, command);
|
|
|
|
else
|
|
|
|
gtk_printer_option_set (option, LPR_COMMAND);
|
|
|
|
gtk_printer_option_set_add (set, option);
|
|
|
|
|
|
|
|
return set;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2006-06-16 18:29:09 +00:00
|
|
|
lpr_printer_get_settings_from_options (GtkPrinter *printer,
|
2006-04-21 15:09:32 +00:00
|
|
|
GtkPrinterOptionSet *options,
|
2006-06-16 18:29:09 +00:00
|
|
|
GtkPrintSettings *settings)
|
2006-04-21 15:09:32 +00:00
|
|
|
{
|
|
|
|
GtkPrinterOption *option;
|
|
|
|
|
|
|
|
option = gtk_printer_option_set_lookup (options, "gtk-main-page-custom-input");
|
2009-05-13 16:28:42 +00:00
|
|
|
if (option)
|
|
|
|
gtk_print_settings_set (settings, "lpr-commandline", option->value);
|
|
|
|
|
|
|
|
option = gtk_printer_option_set_lookup (options, "gtk-n-up");
|
|
|
|
if (option)
|
|
|
|
gtk_print_settings_set (settings, GTK_PRINT_SETTINGS_NUMBER_UP, option->value);
|
|
|
|
|
|
|
|
option = gtk_printer_option_set_lookup (options, "gtk-n-up-layout");
|
|
|
|
if (option)
|
|
|
|
gtk_print_settings_set (settings, GTK_PRINT_SETTINGS_NUMBER_UP_LAYOUT, option->value);
|
2006-04-21 15:09:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2006-06-16 18:29:09 +00:00
|
|
|
lpr_printer_prepare_for_print (GtkPrinter *printer,
|
|
|
|
GtkPrintJob *print_job,
|
2006-04-21 15:09:32 +00:00
|
|
|
GtkPrintSettings *settings,
|
2006-06-16 18:29:09 +00:00
|
|
|
GtkPageSetup *page_setup)
|
2006-04-21 15:09:32 +00:00
|
|
|
{
|
|
|
|
double scale;
|
2010-12-18 22:45:31 +00:00
|
|
|
GtkPrintPages pages;
|
|
|
|
GtkPageRange *ranges;
|
2020-07-24 13:54:49 +00:00
|
|
|
int n_ranges;
|
2006-04-21 15:09:32 +00:00
|
|
|
|
2010-12-18 22:45:31 +00:00
|
|
|
pages = gtk_print_settings_get_print_pages (settings);
|
|
|
|
gtk_print_job_set_pages (print_job, pages);
|
|
|
|
|
|
|
|
if (pages == GTK_PRINT_PAGES_RANGES)
|
|
|
|
ranges = gtk_print_settings_get_page_ranges (settings, &n_ranges);
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ranges = NULL;
|
|
|
|
n_ranges = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
gtk_print_job_set_page_ranges (print_job, ranges, n_ranges);
|
|
|
|
gtk_print_job_set_collate (print_job, gtk_print_settings_get_collate (settings));
|
|
|
|
gtk_print_job_set_reverse (print_job, gtk_print_settings_get_reverse (settings));
|
|
|
|
gtk_print_job_set_num_copies (print_job, gtk_print_settings_get_n_copies (settings));
|
|
|
|
gtk_print_job_set_n_up (print_job, gtk_print_settings_get_number_up (settings));
|
|
|
|
gtk_print_job_set_n_up_layout (print_job, gtk_print_settings_get_number_up_layout (settings));
|
2006-04-21 15:09:32 +00:00
|
|
|
|
|
|
|
scale = gtk_print_settings_get_scale (settings);
|
|
|
|
if (scale != 100.0)
|
2010-12-18 22:45:31 +00:00
|
|
|
gtk_print_job_set_scale (print_job, scale / 100.0);
|
2006-04-21 15:09:32 +00:00
|
|
|
|
2010-12-18 22:45:31 +00:00
|
|
|
gtk_print_job_set_page_set (print_job, gtk_print_settings_get_page_set (settings));
|
|
|
|
gtk_print_job_set_rotate (print_job, TRUE);
|
2006-04-21 15:09:32 +00:00
|
|
|
}
|