| File: | modules/printbackends/lpr/ctkprintbackendlpr.c |
| Warning: | line 382, column 1 Potential leak of memory pointed to by 'ps' |
Press '?' to see keyboard shortcuts
Keyboard shortcuts:
| 1 | /* CTK - The GIMP Toolkit | |||
| 2 | * ctkprintbackendlpr.c: LPR implementation of CtkPrintBackend | |||
| 3 | * for printing to lpr | |||
| 4 | * Copyright (C) 2006, 2007 Red Hat, Inc. | |||
| 5 | * | |||
| 6 | * This library is free software; you can redistribute it and/or | |||
| 7 | * modify it under the terms of the GNU Lesser General Public | |||
| 8 | * License as published by the Free Software Foundation; either | |||
| 9 | * version 2 of the License, or (at your option) any later version. | |||
| 10 | * | |||
| 11 | * This library is distributed in the hope that it will be useful, | |||
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |||
| 14 | * Lesser General Public License for more details. | |||
| 15 | * | |||
| 16 | * You should have received a copy of the GNU Lesser General Public | |||
| 17 | * License along with this library. If not, see <http://www.gnu.org/licenses/>. | |||
| 18 | */ | |||
| 19 | ||||
| 20 | #include "config.h" | |||
| 21 | #include <unistd.h> | |||
| 22 | #include <sys/types.h> | |||
| 23 | #include <sys/stat.h> | |||
| 24 | #include <fcntl.h> | |||
| 25 | #include <stdlib.h> | |||
| 26 | #include <string.h> | |||
| 27 | ||||
| 28 | #include <errno(*__errno_location ()).h> | |||
| 29 | #include <cairo.h> | |||
| 30 | #include <cairo-ps.h> | |||
| 31 | ||||
| 32 | #include <glib/gi18n-lib.h> | |||
| 33 | ||||
| 34 | #include <ctk/ctk.h> | |||
| 35 | #include "ctkprinter-private.h" | |||
| 36 | ||||
| 37 | #include "ctkprintbackendlpr.h" | |||
| 38 | ||||
| 39 | typedef struct _CtkPrintBackendLprClass CtkPrintBackendLprClass; | |||
| 40 | ||||
| 41 | #define CTK_PRINT_BACKEND_LPR_CLASS(klass)((((CtkPrintBackendLprClass*) (void *) g_type_check_class_cast ((GTypeClass*) ((klass)), ((ctk_print_backend_lpr_get_type ( ))))))) (G_TYPE_CHECK_CLASS_CAST ((klass), CTK_TYPE_PRINT_BACKEND_LPR, CtkPrintBackendLprClass)(((CtkPrintBackendLprClass*) (void *) g_type_check_class_cast ((GTypeClass*) ((klass)), ((ctk_print_backend_lpr_get_type ( ))))))) | |||
| 42 | #define CTK_IS_PRINT_BACKEND_LPR_CLASS(klass)(((__extension__ ({ GTypeClass *__class = (GTypeClass*) ((klass )); GType __t = ((ctk_print_backend_lpr_get_type ())); gboolean __r; if (!__class) __r = (0); else if (__class->g_type == __t) __r = (!(0)); else __r = g_type_check_class_is_a (__class , __t); __r; })))) (G_TYPE_CHECK_CLASS_TYPE ((klass), CTK_TYPE_PRINT_BACKEND_LPR)((__extension__ ({ GTypeClass *__class = (GTypeClass*) ((klass )); GType __t = ((ctk_print_backend_lpr_get_type ())); gboolean __r; if (!__class) __r = (0); else if (__class->g_type == __t) __r = (!(0)); else __r = g_type_check_class_is_a (__class , __t); __r; })))) | |||
| 43 | #define CTK_PRINT_BACKEND_LPR_GET_CLASS(obj)((((CtkPrintBackendLprClass*) (((GTypeInstance*) ((obj)))-> g_class)))) (G_TYPE_INSTANCE_GET_CLASS ((obj), CTK_TYPE_PRINT_BACKEND_LPR, CtkPrintBackendLprClass)(((CtkPrintBackendLprClass*) (((GTypeInstance*) ((obj)))-> g_class)))) | |||
| 44 | ||||
| 45 | #define _LPR_MAX_CHUNK_SIZE8192 8192 | |||
| 46 | ||||
| 47 | static GType print_backend_lpr_type = 0; | |||
| 48 | ||||
| 49 | struct _CtkPrintBackendLprClass | |||
| 50 | { | |||
| 51 | CtkPrintBackendClass parent_class; | |||
| 52 | }; | |||
| 53 | ||||
| 54 | struct _CtkPrintBackendLpr | |||
| 55 | { | |||
| 56 | CtkPrintBackend parent_instance; | |||
| 57 | }; | |||
| 58 | ||||
| 59 | static GObjectClass *backend_parent_class; | |||
| 60 | ||||
| 61 | static void ctk_print_backend_lpr_class_init (CtkPrintBackendLprClass *class); | |||
| 62 | static void ctk_print_backend_lpr_init (CtkPrintBackendLpr *impl); | |||
| 63 | static void lpr_printer_get_settings_from_options (CtkPrinter *printer, | |||
| 64 | CtkPrinterOptionSet *options, | |||
| 65 | CtkPrintSettings *settings); | |||
| 66 | static CtkPrinterOptionSet *lpr_printer_get_options (CtkPrinter *printer, | |||
| 67 | CtkPrintSettings *settings, | |||
| 68 | CtkPageSetup *page_setup, | |||
| 69 | CtkPrintCapabilities capabilities); | |||
| 70 | static void lpr_printer_prepare_for_print (CtkPrinter *printer, | |||
| 71 | CtkPrintJob *print_job, | |||
| 72 | CtkPrintSettings *settings, | |||
| 73 | CtkPageSetup *page_setup); | |||
| 74 | static cairo_surface_t * lpr_printer_create_cairo_surface (CtkPrinter *printer, | |||
| 75 | CtkPrintSettings *settings, | |||
| 76 | gdouble width, | |||
| 77 | gdouble height, | |||
| 78 | GIOChannel *cache_io); | |||
| 79 | static void ctk_print_backend_lpr_print_stream (CtkPrintBackend *print_backend, | |||
| 80 | CtkPrintJob *job, | |||
| 81 | GIOChannel *data_io, | |||
| 82 | CtkPrintJobCompleteFunc callback, | |||
| 83 | gpointer user_data, | |||
| 84 | GDestroyNotify dnotify); | |||
| 85 | ||||
| 86 | static void | |||
| 87 | ctk_print_backend_lpr_register_type (GTypeModule *module) | |||
| 88 | { | |||
| 89 | const GTypeInfo print_backend_lpr_info = | |||
| 90 | { | |||
| 91 | .class_size = sizeof (CtkPrintBackendLprClass), | |||
| 92 | .class_init = (GClassInitFunc) ctk_print_backend_lpr_class_init, | |||
| 93 | .instance_size = sizeof (CtkPrintBackendLpr), | |||
| 94 | .n_preallocs = 0, | |||
| 95 | .instance_init = (GInstanceInitFunc) ctk_print_backend_lpr_init, | |||
| 96 | }; | |||
| 97 | ||||
| 98 | print_backend_lpr_type = g_type_module_register_type (module, | |||
| 99 | CTK_TYPE_PRINT_BACKEND(ctk_print_backend_get_type ()), | |||
| 100 | "CtkPrintBackendLpr", | |||
| 101 | &print_backend_lpr_info, 0); | |||
| 102 | } | |||
| 103 | ||||
| 104 | G_MODULE_EXPORT__attribute__((visibility("default"))) void | |||
| 105 | pb_module_init (GTypeModule *module) | |||
| 106 | { | |||
| 107 | ctk_print_backend_lpr_register_type (module); | |||
| 108 | } | |||
| 109 | ||||
| 110 | G_MODULE_EXPORT__attribute__((visibility("default"))) void | |||
| 111 | pb_module_exit (void) | |||
| 112 | { | |||
| 113 | ||||
| 114 | } | |||
| 115 | ||||
| 116 | G_MODULE_EXPORT__attribute__((visibility("default"))) CtkPrintBackend * | |||
| 117 | pb_module_create (void) | |||
| 118 | { | |||
| 119 | return ctk_print_backend_lpr_new (); | |||
| 120 | } | |||
| 121 | ||||
| 122 | /* | |||
| 123 | * CtkPrintBackendLpr | |||
| 124 | */ | |||
| 125 | GType | |||
| 126 | ctk_print_backend_lpr_get_type (void) | |||
| 127 | { | |||
| 128 | return print_backend_lpr_type; | |||
| 129 | } | |||
| 130 | ||||
| 131 | /** | |||
| 132 | * ctk_print_backend_lpr_new: | |||
| 133 | * | |||
| 134 | * Creates a new #CtkPrintBackendLpr object. #CtkPrintBackendLpr | |||
| 135 | * implements the #CtkPrintBackend interface with direct access to | |||
| 136 | * the filesystem using Unix/Linux API calls | |||
| 137 | * | |||
| 138 | * Returns: the new #CtkPrintBackendLpr object | |||
| 139 | **/ | |||
| 140 | CtkPrintBackend * | |||
| 141 | ctk_print_backend_lpr_new (void) | |||
| 142 | { | |||
| 143 | return g_object_new (CTK_TYPE_PRINT_BACKEND_LPR(ctk_print_backend_lpr_get_type ()), NULL((void*)0)); | |||
| 144 | } | |||
| 145 | ||||
| 146 | static void | |||
| 147 | ctk_print_backend_lpr_class_init (CtkPrintBackendLprClass *class) | |||
| 148 | { | |||
| 149 | CtkPrintBackendClass *backend_class = CTK_PRINT_BACKEND_CLASS (class)((((CtkPrintBackendClass*) (void *) g_type_check_class_cast ( (GTypeClass*) ((class)), ((ctk_print_backend_get_type ()))))) ); | |||
| 150 | ||||
| 151 | backend_parent_class = g_type_class_peek_parent (class); | |||
| 152 | ||||
| 153 | backend_class->print_stream = ctk_print_backend_lpr_print_stream; | |||
| 154 | backend_class->printer_create_cairo_surface = lpr_printer_create_cairo_surface; | |||
| 155 | backend_class->printer_get_options = lpr_printer_get_options; | |||
| 156 | backend_class->printer_get_settings_from_options = lpr_printer_get_settings_from_options; | |||
| 157 | backend_class->printer_prepare_for_print = lpr_printer_prepare_for_print; | |||
| 158 | } | |||
| 159 | ||||
| 160 | static cairo_status_t | |||
| 161 | _cairo_write (void *closure, | |||
| 162 | const unsigned char *data, | |||
| 163 | unsigned int length) | |||
| 164 | { | |||
| 165 | GIOChannel *io = (GIOChannel *)closure; | |||
| 166 | gsize written; | |||
| 167 | GError *error; | |||
| 168 | ||||
| 169 | error = NULL((void*)0); | |||
| 170 | ||||
| 171 | CTK_NOTE (PRINTING,do { if ((ctk_get_debug_flags () & CTK_DEBUG_PRINTING)) { g_print ("LPR Backend: Writting %i byte chunk to temp file\n" , length); }; } while (0) | |||
| 172 | g_print ("LPR Backend: Writting %i byte chunk to temp file\n", length))do { if ((ctk_get_debug_flags () & CTK_DEBUG_PRINTING)) { g_print ("LPR Backend: Writting %i byte chunk to temp file\n" , length); }; } while (0); | |||
| 173 | ||||
| 174 | while (length > 0) | |||
| 175 | { | |||
| 176 | g_io_channel_write_chars (io, (const gchar*)data, length, &written, &error); | |||
| 177 | ||||
| 178 | if (error != NULL((void*)0)) | |||
| 179 | { | |||
| 180 | CTK_NOTE (PRINTING,do { if ((ctk_get_debug_flags () & CTK_DEBUG_PRINTING)) { g_print ("LPR Backend: Error writting to temp file, %s\n", error ->message); }; } while (0) | |||
| 181 | g_print ("LPR Backend: Error writting to temp file, %s\n", error->message))do { if ((ctk_get_debug_flags () & CTK_DEBUG_PRINTING)) { g_print ("LPR Backend: Error writting to temp file, %s\n", error ->message); }; } while (0); | |||
| 182 | ||||
| 183 | g_error_free (error); | |||
| 184 | return CAIRO_STATUS_WRITE_ERROR; | |||
| 185 | } | |||
| 186 | ||||
| 187 | CTK_NOTE (PRINTING,do { if ((ctk_get_debug_flags () & CTK_DEBUG_PRINTING)) { g_print ("LPR Backend: Wrote %" "lu" " bytes to temp file\n" , written); }; } while (0) | |||
| 188 | g_print ("LPR Backend: Wrote %" G_GSIZE_FORMAT " bytes to temp file\n", written))do { if ((ctk_get_debug_flags () & CTK_DEBUG_PRINTING)) { g_print ("LPR Backend: Wrote %" "lu" " bytes to temp file\n" , written); }; } while (0); | |||
| 189 | ||||
| 190 | data += written; | |||
| 191 | length -= written; | |||
| 192 | } | |||
| 193 | ||||
| 194 | return CAIRO_STATUS_SUCCESS; | |||
| 195 | } | |||
| 196 | ||||
| 197 | static cairo_surface_t * | |||
| 198 | lpr_printer_create_cairo_surface (CtkPrinter *printer G_GNUC_UNUSED__attribute__ ((__unused__)), | |||
| 199 | CtkPrintSettings *settings, | |||
| 200 | gdouble width, | |||
| 201 | gdouble height, | |||
| 202 | GIOChannel *cache_io) | |||
| 203 | { | |||
| 204 | cairo_surface_t *surface; | |||
| 205 | ||||
| 206 | surface = cairo_ps_surface_create_for_stream (_cairo_write, cache_io, width, height); | |||
| 207 | ||||
| 208 | cairo_surface_set_fallback_resolution (surface, | |||
| 209 | 2.0 * ctk_print_settings_get_printer_lpi (settings), | |||
| 210 | 2.0 * ctk_print_settings_get_printer_lpi (settings)); | |||
| 211 | ||||
| 212 | return surface; | |||
| 213 | } | |||
| 214 | ||||
| 215 | typedef struct { | |||
| 216 | CtkPrintBackend *backend; | |||
| 217 | CtkPrintJobCompleteFunc callback; | |||
| 218 | CtkPrintJob *job; | |||
| 219 | gpointer user_data; | |||
| 220 | GDestroyNotify dnotify; | |||
| 221 | ||||
| 222 | GIOChannel *in; | |||
| 223 | } _PrintStreamData; | |||
| 224 | ||||
| 225 | static void | |||
| 226 | lpr_print_cb (CtkPrintBackendLpr *print_backend G_GNUC_UNUSED__attribute__ ((__unused__)), | |||
| 227 | GError *error, | |||
| 228 | gpointer user_data) | |||
| 229 | { | |||
| 230 | _PrintStreamData *ps = (_PrintStreamData *) user_data; | |||
| 231 | ||||
| 232 | if (ps->in != NULL((void*)0)) | |||
| 233 | g_io_channel_unref (ps->in); | |||
| 234 | ||||
| 235 | if (ps->callback) | |||
| 236 | ps->callback (ps->job, ps->user_data, error); | |||
| 237 | ||||
| 238 | if (ps->dnotify) | |||
| 239 | ps->dnotify (ps->user_data); | |||
| 240 | ||||
| 241 | ctk_print_job_set_status (ps->job, | |||
| 242 | error ? CTK_PRINT_STATUS_FINISHED_ABORTED | |||
| 243 | : CTK_PRINT_STATUS_FINISHED); | |||
| 244 | ||||
| 245 | if (ps->job) | |||
| 246 | g_object_unref (ps->job); | |||
| 247 | ||||
| 248 | g_free (ps); | |||
| 249 | } | |||
| 250 | ||||
| 251 | static gboolean | |||
| 252 | lpr_write (GIOChannel *source, | |||
| 253 | GIOCondition con G_GNUC_UNUSED__attribute__ ((__unused__)), | |||
| 254 | gpointer user_data) | |||
| 255 | { | |||
| 256 | gchar buf[_LPR_MAX_CHUNK_SIZE8192]; | |||
| 257 | gsize bytes_read; | |||
| 258 | GError *error; | |||
| 259 | GIOStatus status; | |||
| 260 | _PrintStreamData *ps = (_PrintStreamData *) user_data; | |||
| 261 | ||||
| 262 | error = NULL((void*)0); | |||
| 263 | ||||
| 264 | status = | |||
| 265 | g_io_channel_read_chars (source, | |||
| 266 | buf, | |||
| 267 | _LPR_MAX_CHUNK_SIZE8192, | |||
| 268 | &bytes_read, | |||
| 269 | &error); | |||
| 270 | ||||
| 271 | if (status != G_IO_STATUS_ERROR) | |||
| 272 | { | |||
| 273 | gsize bytes_written; | |||
| 274 | ||||
| 275 | g_io_channel_write_chars (ps->in, | |||
| 276 | buf, | |||
| 277 | bytes_read, | |||
| 278 | &bytes_written, | |||
| 279 | &error); | |||
| 280 | } | |||
| 281 | ||||
| 282 | if (error != NULL((void*)0) || status == G_IO_STATUS_EOF) | |||
| 283 | { | |||
| 284 | lpr_print_cb (CTK_PRINT_BACKEND_LPR (ps->backend)((((CtkPrintBackendLpr*) (void *) g_type_check_instance_cast ( (GTypeInstance*) ((ps->backend)), ((ctk_print_backend_lpr_get_type ())))))), | |||
| 285 | error, user_data); | |||
| 286 | ||||
| 287 | ||||
| 288 | if (error != NULL((void*)0)) | |||
| 289 | { | |||
| 290 | CTK_NOTE (PRINTING,do { if ((ctk_get_debug_flags () & CTK_DEBUG_PRINTING)) { g_print ("LPR Backend: %s\n", error->message); }; } while (0) | |||
| 291 | g_print ("LPR Backend: %s\n", error->message))do { if ((ctk_get_debug_flags () & CTK_DEBUG_PRINTING)) { g_print ("LPR Backend: %s\n", error->message); }; } while (0); | |||
| 292 | ||||
| 293 | g_error_free (error); | |||
| 294 | } | |||
| 295 | ||||
| 296 | return FALSE(0); | |||
| 297 | } | |||
| 298 | ||||
| 299 | CTK_NOTE (PRINTING,do { if ((ctk_get_debug_flags () & CTK_DEBUG_PRINTING)) { g_print ("LPR Backend: Writting %" "lu" " byte chunk to lpr pipe\n" , bytes_read); }; } while (0) | |||
| 300 | g_print ("LPR Backend: Writting %" G_GSIZE_FORMAT " byte chunk to lpr pipe\n", bytes_read))do { if ((ctk_get_debug_flags () & CTK_DEBUG_PRINTING)) { g_print ("LPR Backend: Writting %" "lu" " byte chunk to lpr pipe\n" , bytes_read); }; } while (0); | |||
| 301 | ||||
| 302 | ||||
| 303 | return TRUE(!(0)); | |||
| 304 | } | |||
| 305 | ||||
| 306 | #define LPR_COMMAND"lpr" "lpr" | |||
| 307 | ||||
| 308 | static void | |||
| 309 | ctk_print_backend_lpr_print_stream (CtkPrintBackend *print_backend, | |||
| 310 | CtkPrintJob *job, | |||
| 311 | GIOChannel *data_io, | |||
| 312 | CtkPrintJobCompleteFunc callback, | |||
| 313 | gpointer user_data, | |||
| 314 | GDestroyNotify dnotify) | |||
| 315 | { | |||
| 316 | GError *print_error = NULL((void*)0); | |||
| 317 | _PrintStreamData *ps; | |||
| 318 | CtkPrintSettings *settings; | |||
| 319 | gint argc; | |||
| 320 | gint in_fd; | |||
| 321 | gchar **argv = NULL((void*)0); | |||
| 322 | const char *cmd_line; | |||
| 323 | ||||
| 324 | settings = ctk_print_job_get_settings (job); | |||
| 325 | ||||
| 326 | cmd_line = ctk_print_settings_get (settings, "lpr-commandline"); | |||
| 327 | if (cmd_line == NULL((void*)0)) | |||
| ||||
| 328 | cmd_line = LPR_COMMAND"lpr"; | |||
| 329 | ||||
| 330 | ps = g_new0 (_PrintStreamData, 1)((_PrintStreamData *) g_malloc0_n ((1), sizeof (_PrintStreamData ))); | |||
| 331 | ps->callback = callback; | |||
| 332 | ps->user_data = user_data; | |||
| 333 | ps->dnotify = dnotify; | |||
| 334 | ps->job = g_object_ref (job)((__typeof__ (job)) (g_object_ref) (job)); | |||
| 335 | ps->in = NULL((void*)0); | |||
| 336 | ||||
| 337 | /* spawn lpr with pipes and pipe ps file to lpr */ | |||
| 338 | if (!g_shell_parse_argv (cmd_line, &argc, &argv, &print_error)) | |||
| 339 | goto out; | |||
| 340 | ||||
| 341 | if (!g_spawn_async_with_pipes (NULL((void*)0), | |||
| 342 | argv, | |||
| 343 | NULL((void*)0), | |||
| 344 | G_SPAWN_SEARCH_PATH, | |||
| 345 | NULL((void*)0), | |||
| 346 | NULL((void*)0), | |||
| 347 | NULL((void*)0), | |||
| 348 | &in_fd, | |||
| 349 | NULL((void*)0), | |||
| 350 | NULL((void*)0), | |||
| 351 | &print_error)) | |||
| 352 | goto out; | |||
| 353 | ||||
| 354 | ps->in = g_io_channel_unix_new (in_fd); | |||
| 355 | ||||
| 356 | g_io_channel_set_encoding (ps->in, NULL((void*)0), &print_error); | |||
| 357 | if (print_error != NULL((void*)0)) | |||
| 358 | { | |||
| 359 | if (ps->in != NULL((void*)0)) | |||
| 360 | g_io_channel_unref (ps->in); | |||
| 361 | ||||
| 362 | goto out; | |||
| 363 | } | |||
| 364 | ||||
| 365 | g_io_channel_set_close_on_unref (ps->in, TRUE(!(0))); | |||
| 366 | ||||
| 367 | g_io_add_watch (data_io, | |||
| 368 | G_IO_IN | G_IO_PRI | G_IO_ERR | G_IO_HUP, | |||
| 369 | (GIOFunc) lpr_write, | |||
| 370 | ps); | |||
| 371 | ||||
| 372 | out: | |||
| 373 | if (argv != NULL((void*)0)) | |||
| 374 | g_strfreev (argv); | |||
| 375 | ||||
| 376 | if (print_error != NULL((void*)0)) | |||
| 377 | { | |||
| 378 | lpr_print_cb (CTK_PRINT_BACKEND_LPR (print_backend)((((CtkPrintBackendLpr*) (void *) g_type_check_instance_cast ( (GTypeInstance*) ((print_backend)), ((ctk_print_backend_lpr_get_type ())))))), | |||
| 379 | print_error, ps); | |||
| 380 | g_error_free (print_error); | |||
| 381 | } | |||
| 382 | } | |||
| ||||
| 383 | ||||
| 384 | static void | |||
| 385 | ctk_print_backend_lpr_init (CtkPrintBackendLpr *backend) | |||
| 386 | { | |||
| 387 | CtkPrinter *printer; | |||
| 388 | ||||
| 389 | printer = g_object_new (CTK_TYPE_PRINTER(ctk_printer_get_type ()), | |||
| 390 | "name", _("Print to LPR")((char *) g_dgettext ("ctk30", "Print to LPR")), | |||
| 391 | "backend", backend, | |||
| 392 | "is-virtual", FALSE(0), | |||
| 393 | "accepts-pdf", TRUE(!(0)), | |||
| 394 | "accepts-ps", TRUE(!(0)), | |||
| 395 | NULL((void*)0)); | |||
| 396 | ctk_printer_set_has_details (printer, TRUE(!(0))); | |||
| 397 | ctk_printer_set_icon_name (printer, "printer"); | |||
| 398 | ctk_printer_set_is_active (printer, TRUE(!(0))); | |||
| 399 | ctk_printer_set_is_default (printer, TRUE(!(0))); | |||
| 400 | ||||
| 401 | ctk_print_backend_add_printer (CTK_PRINT_BACKEND (backend)((((CtkPrintBackend*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((backend)), ((ctk_print_backend_get_type ())))))), printer); | |||
| 402 | g_object_unref (printer); | |||
| 403 | ctk_print_backend_set_list_done (CTK_PRINT_BACKEND (backend)((((CtkPrintBackend*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((backend)), ((ctk_print_backend_get_type ()))))))); | |||
| 404 | } | |||
| 405 | ||||
| 406 | static CtkPrinterOptionSet * | |||
| 407 | lpr_printer_get_options (CtkPrinter *printer G_GNUC_UNUSED__attribute__ ((__unused__)), | |||
| 408 | CtkPrintSettings *settings, | |||
| 409 | CtkPageSetup *page_setup G_GNUC_UNUSED__attribute__ ((__unused__)), | |||
| 410 | CtkPrintCapabilities capabilities G_GNUC_UNUSED__attribute__ ((__unused__))) | |||
| 411 | { | |||
| 412 | CtkPrinterOptionSet *set; | |||
| 413 | CtkPrinterOption *option; | |||
| 414 | const char *command; | |||
| 415 | char *n_up[] = {"1", "2", "4", "6", "9", "16" }; | |||
| 416 | ||||
| 417 | set = ctk_printer_option_set_new (); | |||
| 418 | ||||
| 419 | option = ctk_printer_option_new ("ctk-n-up", _("Pages Per Sheet")((char *) g_dgettext ("ctk30", "Pages Per Sheet")), CTK_PRINTER_OPTION_TYPE_PICKONE); | |||
| 420 | ctk_printer_option_choices_from_array (option, G_N_ELEMENTS (n_up)(sizeof (n_up) / sizeof ((n_up)[0])), | |||
| 421 | n_up, n_up); | |||
| 422 | ctk_printer_option_set (option, "1"); | |||
| 423 | ctk_printer_option_set_add (set, option); | |||
| 424 | g_object_unref (option); | |||
| 425 | ||||
| 426 | option = ctk_printer_option_new ("ctk-main-page-custom-input", _("Command Line")((char *) g_dgettext ("ctk30", "Command Line")), CTK_PRINTER_OPTION_TYPE_STRING); | |||
| 427 | ctk_printer_option_set_activates_default (option, TRUE(!(0))); | |||
| 428 | option->group = g_strdup ("CtkPrintDialogExtension")g_strdup_inline ("CtkPrintDialogExtension"); | |||
| 429 | if (settings != NULL((void*)0) && | |||
| 430 | (command = ctk_print_settings_get (settings, "lpr-commandline"))!= NULL((void*)0)) | |||
| 431 | ctk_printer_option_set (option, command); | |||
| 432 | else | |||
| 433 | ctk_printer_option_set (option, LPR_COMMAND"lpr"); | |||
| 434 | ctk_printer_option_set_add (set, option); | |||
| 435 | ||||
| 436 | return set; | |||
| 437 | } | |||
| 438 | ||||
| 439 | static void | |||
| 440 | lpr_printer_get_settings_from_options (CtkPrinter *printer G_GNUC_UNUSED__attribute__ ((__unused__)), | |||
| 441 | CtkPrinterOptionSet *options, | |||
| 442 | CtkPrintSettings *settings) | |||
| 443 | { | |||
| 444 | CtkPrinterOption *option; | |||
| 445 | ||||
| 446 | option = ctk_printer_option_set_lookup (options, "ctk-main-page-custom-input"); | |||
| 447 | if (option) | |||
| 448 | ctk_print_settings_set (settings, "lpr-commandline", option->value); | |||
| 449 | ||||
| 450 | option = ctk_printer_option_set_lookup (options, "ctk-n-up"); | |||
| 451 | if (option) | |||
| 452 | ctk_print_settings_set (settings, CTK_PRINT_SETTINGS_NUMBER_UP"number-up", option->value); | |||
| 453 | ||||
| 454 | option = ctk_printer_option_set_lookup (options, "ctk-n-up-layout"); | |||
| 455 | if (option) | |||
| 456 | ctk_print_settings_set (settings, CTK_PRINT_SETTINGS_NUMBER_UP_LAYOUT"number-up-layout", option->value); | |||
| 457 | } | |||
| 458 | ||||
| 459 | static void | |||
| 460 | lpr_printer_prepare_for_print (CtkPrinter *printer G_GNUC_UNUSED__attribute__ ((__unused__)), | |||
| 461 | CtkPrintJob *print_job, | |||
| 462 | CtkPrintSettings *settings, | |||
| 463 | CtkPageSetup *page_setup G_GNUC_UNUSED__attribute__ ((__unused__))) | |||
| 464 | { | |||
| 465 | double scale; | |||
| 466 | CtkPrintPages pages; | |||
| 467 | CtkPageRange *ranges; | |||
| 468 | gint n_ranges; | |||
| 469 | ||||
| 470 | pages = ctk_print_settings_get_print_pages (settings); | |||
| 471 | ctk_print_job_set_pages (print_job, pages); | |||
| 472 | ||||
| 473 | if (pages == CTK_PRINT_PAGES_RANGES) | |||
| 474 | ranges = ctk_print_settings_get_page_ranges (settings, &n_ranges); | |||
| 475 | else | |||
| 476 | { | |||
| 477 | ranges = NULL((void*)0); | |||
| 478 | n_ranges = 0; | |||
| 479 | } | |||
| 480 | ||||
| 481 | ctk_print_job_set_page_ranges (print_job, ranges, n_ranges); | |||
| 482 | ctk_print_job_set_collate (print_job, ctk_print_settings_get_collate (settings)); | |||
| 483 | ctk_print_job_set_reverse (print_job, ctk_print_settings_get_reverse (settings)); | |||
| 484 | ctk_print_job_set_num_copies (print_job, ctk_print_settings_get_n_copies (settings)); | |||
| 485 | ctk_print_job_set_n_up (print_job, ctk_print_settings_get_number_up (settings)); | |||
| 486 | ctk_print_job_set_n_up_layout (print_job, ctk_print_settings_get_number_up_layout (settings)); | |||
| 487 | ||||
| 488 | scale = ctk_print_settings_get_scale (settings); | |||
| 489 | if (scale != 100.0) | |||
| 490 | ctk_print_job_set_scale (print_job, scale / 100.0); | |||
| 491 | ||||
| 492 | ctk_print_job_set_page_set (print_job, ctk_print_settings_get_page_set (settings)); | |||
| 493 | ctk_print_job_set_rotate (print_job, TRUE(!(0))); | |||
| 494 | } |