File: | modules/printbackends/test/ctkprintbackendtest.c |
Warning: | line 495, column 3 Value stored to 'format' is never read |
Press '?' to see keyboard shortcuts
Keyboard shortcuts:
1 | /* CTK - The GIMP Toolkit |
2 | * ctkprintbackendpdf.c: Test implementation of CtkPrintBackend |
3 | * for printing to a test |
4 | * Copyright (C) 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 | |
22 | #include <unistd.h> |
23 | #include <sys/types.h> |
24 | #include <sys/stat.h> |
25 | #include <fcntl.h> |
26 | #include <stdlib.h> |
27 | #include <string.h> |
28 | |
29 | #include <errno(*__errno_location ()).h> |
30 | #include <cairo.h> |
31 | #include <cairo-pdf.h> |
32 | #include <cairo-ps.h> |
33 | |
34 | #include <glib/gi18n-lib.h> |
35 | |
36 | #include <ctk/ctkprintbackend.h> |
37 | #include <ctk/ctkunixprint.h> |
38 | #include <ctk/ctkprinter-private.h> |
39 | |
40 | #include "ctkprintbackendtest.h" |
41 | |
42 | |
43 | typedef struct _CtkPrintBackendTestClass CtkPrintBackendTestClass; |
44 | |
45 | #define CTK_PRINT_BACKEND_TEST_CLASS(klass)((((CtkPrintBackendTestClass*) (void *) g_type_check_class_cast ((GTypeClass*) ((klass)), ((ctk_print_backend_test_get_type ( ))))))) (G_TYPE_CHECK_CLASS_CAST ((klass), CTK_TYPE_PRINT_BACKEND_TEST, CtkPrintBackendTestClass)(((CtkPrintBackendTestClass*) (void *) g_type_check_class_cast ((GTypeClass*) ((klass)), ((ctk_print_backend_test_get_type ( ))))))) |
46 | #define CTK_IS_PRINT_BACKEND_TEST_CLASS(klass)(((__extension__ ({ GTypeClass *__class = (GTypeClass*) ((klass )); GType __t = ((ctk_print_backend_test_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_TEST)((__extension__ ({ GTypeClass *__class = (GTypeClass*) ((klass )); GType __t = ((ctk_print_backend_test_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; })))) |
47 | #define CTK_PRINT_BACKENDTEST_GET_CLASS(obj)((((CtkPrintBackendTestClass*) (((GTypeInstance*) ((obj)))-> g_class)))) (G_TYPE_INSTANCE_GET_CLASS ((obj), CTK_TYPE_PRINT_BACKEND_TEST, CtkPrintBackendTestClass)(((CtkPrintBackendTestClass*) (((GTypeInstance*) ((obj)))-> g_class)))) |
48 | |
49 | #define _STREAM_MAX_CHUNK_SIZE8192 8192 |
50 | |
51 | static GType print_backend_test_type = 0; |
52 | |
53 | struct _CtkPrintBackendTestClass |
54 | { |
55 | CtkPrintBackendClass parent_class; |
56 | }; |
57 | |
58 | struct _CtkPrintBackendTest |
59 | { |
60 | CtkPrintBackend parent_instance; |
61 | }; |
62 | |
63 | typedef enum |
64 | { |
65 | FORMAT_PDF, |
66 | FORMAT_PS, |
67 | N_FORMATS |
68 | } OutputFormat; |
69 | |
70 | static const gchar* formats[N_FORMATS] = |
71 | { |
72 | "pdf", |
73 | "ps" |
74 | }; |
75 | |
76 | static GObjectClass *backend_parent_class; |
77 | |
78 | static void ctk_print_backend_test_class_init (CtkPrintBackendTestClass *class); |
79 | static void ctk_print_backend_test_init (CtkPrintBackendTest *impl); |
80 | static void test_printer_get_settings_from_options (CtkPrinter *printer, |
81 | CtkPrinterOptionSet *options, |
82 | CtkPrintSettings *settings); |
83 | static CtkPrinterOptionSet *test_printer_get_options (CtkPrinter *printer, |
84 | CtkPrintSettings *settings, |
85 | CtkPageSetup *page_setup, |
86 | CtkPrintCapabilities capabilities); |
87 | static void test_printer_prepare_for_print (CtkPrinter *printer, |
88 | CtkPrintJob *print_job, |
89 | CtkPrintSettings *settings, |
90 | CtkPageSetup *page_setup); |
91 | static void ctk_print_backend_test_print_stream (CtkPrintBackend *print_backend, |
92 | CtkPrintJob *job, |
93 | GIOChannel *data_io, |
94 | CtkPrintJobCompleteFunc callback, |
95 | gpointer user_data, |
96 | GDestroyNotify dnotify); |
97 | static cairo_surface_t * test_printer_create_cairo_surface (CtkPrinter *printer, |
98 | CtkPrintSettings *settings, |
99 | gdouble width, |
100 | gdouble height, |
101 | GIOChannel *cache_io); |
102 | |
103 | static void test_printer_request_details (CtkPrinter *printer); |
104 | |
105 | static void |
106 | ctk_print_backend_test_register_type (GTypeModule *module) |
107 | { |
108 | const GTypeInfo print_backend_test_info = |
109 | { |
110 | .class_size = sizeof (CtkPrintBackendTestClass), |
111 | .class_init = (GClassInitFunc) ctk_print_backend_test_class_init, |
112 | .instance_size = sizeof (CtkPrintBackendTest), |
113 | .n_preallocs = 0, |
114 | .instance_init = (GInstanceInitFunc) ctk_print_backend_test_init, |
115 | }; |
116 | |
117 | print_backend_test_type = g_type_module_register_type (module, |
118 | CTK_TYPE_PRINT_BACKEND(ctk_print_backend_get_type ()), |
119 | "CtkPrintBackendTest", |
120 | &print_backend_test_info, 0); |
121 | } |
122 | |
123 | G_MODULE_EXPORT__attribute__((visibility("default"))) void |
124 | pb_module_init (GTypeModule *module) |
125 | { |
126 | ctk_print_backend_test_register_type (module); |
127 | } |
128 | |
129 | G_MODULE_EXPORT__attribute__((visibility("default"))) void |
130 | pb_module_exit (void) |
131 | { |
132 | |
133 | } |
134 | |
135 | G_MODULE_EXPORT__attribute__((visibility("default"))) CtkPrintBackend * |
136 | pb_module_create (void) |
137 | { |
138 | return ctk_print_backend_test_new (); |
139 | } |
140 | |
141 | /* |
142 | * CtkPrintBackendTest |
143 | */ |
144 | GType |
145 | ctk_print_backend_test_get_type (void) |
146 | { |
147 | return print_backend_test_type; |
148 | } |
149 | |
150 | /** |
151 | * ctk_print_backend_test_new: |
152 | * |
153 | * Creates a new #CtkPrintBackendTest object. #CtkPrintBackendTest |
154 | * implements the #CtkPrintBackend interface with direct access to |
155 | * the testsystem using Unix/Linux API calls |
156 | * |
157 | * Returns: the new #CtkPrintBackendTest object |
158 | **/ |
159 | CtkPrintBackend * |
160 | ctk_print_backend_test_new (void) |
161 | { |
162 | return g_object_new (CTK_TYPE_PRINT_BACKEND_TEST(ctk_print_backend_test_get_type ()), NULL((void*)0)); |
163 | } |
164 | |
165 | static void |
166 | ctk_print_backend_test_class_init (CtkPrintBackendTestClass *class) |
167 | { |
168 | CtkPrintBackendClass *backend_class = CTK_PRINT_BACKEND_CLASS (class)((((CtkPrintBackendClass*) (void *) g_type_check_class_cast ( (GTypeClass*) ((class)), ((ctk_print_backend_get_type ()))))) ); |
169 | |
170 | backend_parent_class = g_type_class_peek_parent (class); |
171 | |
172 | backend_class->print_stream = ctk_print_backend_test_print_stream; |
173 | backend_class->printer_create_cairo_surface = test_printer_create_cairo_surface; |
174 | backend_class->printer_get_options = test_printer_get_options; |
175 | backend_class->printer_get_settings_from_options = test_printer_get_settings_from_options; |
176 | backend_class->printer_prepare_for_print = test_printer_prepare_for_print; |
177 | backend_class->printer_request_details = test_printer_request_details; |
178 | } |
179 | |
180 | /* return N_FORMATS if no explicit format in the settings */ |
181 | static OutputFormat |
182 | format_from_settings (CtkPrintSettings *settings) |
183 | { |
184 | const gchar *value; |
185 | gint i; |
186 | |
187 | if (settings == NULL((void*)0)) |
188 | return N_FORMATS; |
189 | |
190 | value = ctk_print_settings_get (settings, CTK_PRINT_SETTINGS_OUTPUT_FILE_FORMAT"output-file-format"); |
191 | if (value == NULL((void*)0)) |
192 | return N_FORMATS; |
193 | |
194 | for (i = 0; i < N_FORMATS; ++i) |
195 | if (strcmp (value, formats[i]) == 0) |
196 | break; |
197 | |
198 | g_assert (i < N_FORMATS)do { if (i < N_FORMATS) ; else g_assertion_message_expr (( (gchar*) 0), "ctkprintbackendtest.c", 198, ((const char*) (__func__ )), "i < N_FORMATS"); } while (0); |
199 | |
200 | return (OutputFormat) i; |
201 | } |
202 | |
203 | static gchar * |
204 | output_test_from_settings (CtkPrintSettings *settings, |
205 | const gchar *default_format) |
206 | { |
207 | gchar *uri = NULL((void*)0); |
208 | |
209 | if (settings) |
210 | uri = g_strdup (ctk_print_settings_get (settings, CTK_PRINT_SETTINGS_OUTPUT_URI))g_strdup_inline (ctk_print_settings_get (settings, "output-uri" )); |
211 | |
212 | if (uri == NULL((void*)0)) |
213 | { |
214 | const gchar *extension; |
215 | gchar *name, *locale_name; |
216 | |
217 | if (default_format) |
218 | extension = default_format; |
219 | else |
220 | { |
221 | OutputFormat format; |
222 | |
223 | format = format_from_settings (settings); |
224 | extension = format == FORMAT_PS ? "ps" : "pdf"; |
225 | } |
226 | |
227 | /* default filename used for print-to-test */ |
228 | name = g_strdup_printf (_("test-output.%s")((char *) g_dgettext ("ctk30", "test-output.%s")), extension); |
229 | locale_name = g_filename_from_utf8 (name, -1, NULL((void*)0), NULL((void*)0), NULL((void*)0)); |
230 | g_free (name); |
231 | |
232 | if (locale_name != NULL((void*)0)) |
233 | { |
234 | gchar *path; |
235 | |
236 | gchar *current_dir = g_get_current_dir (); |
237 | path = g_build_filename (current_dir, locale_name, NULL((void*)0)); |
238 | g_free (locale_name); |
239 | |
240 | uri = g_filename_to_uri (path, NULL((void*)0), NULL((void*)0)); |
241 | g_free (path); |
242 | g_free (current_dir); |
243 | } |
244 | } |
245 | |
246 | return uri; |
247 | } |
248 | |
249 | static cairo_status_t |
250 | _cairo_write (void *closure, |
251 | const unsigned char *data, |
252 | unsigned int length) |
253 | { |
254 | GIOChannel *io = (GIOChannel *)closure; |
255 | gsize written; |
256 | GError *error; |
257 | |
258 | error = NULL((void*)0); |
259 | |
260 | CTK_NOTE (PRINTING, |
261 | g_print ("TEST Backend: Writing %i byte chunk to temp test\n", length)); |
262 | |
263 | while (length > 0) |
264 | { |
265 | g_io_channel_write_chars (io, (const gchar *) data, length, &written, &error); |
266 | |
267 | if (error != NULL((void*)0)) |
268 | { |
269 | CTK_NOTE (PRINTING, |
270 | g_print ("TEST Backend: Error writing to temp test, %s\n", error->message)); |
271 | |
272 | g_error_free (error); |
273 | return CAIRO_STATUS_WRITE_ERROR; |
274 | } |
275 | |
276 | CTK_NOTE (PRINTING, |
277 | g_print ("TEST Backend: Wrote %i bytes to temp test\n", (int)written)); |
278 | |
279 | data += written; |
280 | length -= written; |
281 | } |
282 | |
283 | return CAIRO_STATUS_SUCCESS; |
284 | } |
285 | |
286 | |
287 | static cairo_surface_t * |
288 | test_printer_create_cairo_surface (CtkPrinter *printer G_GNUC_UNUSED__attribute__ ((__unused__)), |
289 | CtkPrintSettings *settings, |
290 | gdouble width, |
291 | gdouble height, |
292 | GIOChannel *cache_io) |
293 | { |
294 | cairo_surface_t *surface; |
295 | OutputFormat format; |
296 | |
297 | format = format_from_settings (settings); |
298 | |
299 | if (format == FORMAT_PS) |
300 | surface = cairo_ps_surface_create_for_stream (_cairo_write, cache_io, width, height); |
301 | else |
302 | surface = cairo_pdf_surface_create_for_stream (_cairo_write, cache_io, width, height); |
303 | |
304 | cairo_surface_set_fallback_resolution (surface, |
305 | 2.0 * ctk_print_settings_get_printer_lpi (settings), |
306 | 2.0 * ctk_print_settings_get_printer_lpi (settings)); |
307 | |
308 | return surface; |
309 | } |
310 | |
311 | typedef struct { |
312 | CtkPrintBackend *backend; |
313 | CtkPrintJobCompleteFunc callback; |
314 | CtkPrintJob *job; |
315 | GIOChannel *target_io; |
316 | gpointer user_data; |
317 | GDestroyNotify dnotify; |
318 | } _PrintStreamData; |
319 | |
320 | static void |
321 | test_print_cb (CtkPrintBackendTest *print_backend G_GNUC_UNUSED__attribute__ ((__unused__)), |
322 | GError *error, |
323 | gpointer user_data) |
324 | { |
325 | _PrintStreamData *ps = (_PrintStreamData *) user_data; |
326 | |
327 | if (ps->target_io != NULL((void*)0)) |
328 | g_io_channel_unref (ps->target_io); |
329 | |
330 | if (ps->callback) |
331 | ps->callback (ps->job, ps->user_data, error); |
332 | |
333 | if (ps->dnotify) |
334 | ps->dnotify (ps->user_data); |
335 | |
336 | ctk_print_job_set_status (ps->job, |
337 | (error != NULL((void*)0))?CTK_PRINT_STATUS_FINISHED_ABORTED:CTK_PRINT_STATUS_FINISHED); |
338 | |
339 | if (ps->job) |
340 | g_object_unref (ps->job); |
341 | |
342 | g_free (ps); |
343 | } |
344 | |
345 | static gboolean |
346 | test_write (GIOChannel *source, |
347 | GIOCondition con G_GNUC_UNUSED__attribute__ ((__unused__)), |
348 | gpointer user_data) |
349 | { |
350 | gchar buf[_STREAM_MAX_CHUNK_SIZE8192]; |
351 | gsize bytes_read; |
352 | GError *error; |
353 | GIOStatus read_status; |
354 | _PrintStreamData *ps = (_PrintStreamData *) user_data; |
355 | |
356 | error = NULL((void*)0); |
357 | |
358 | read_status = |
359 | g_io_channel_read_chars (source, |
360 | buf, |
361 | _STREAM_MAX_CHUNK_SIZE8192, |
362 | &bytes_read, |
363 | &error); |
364 | |
365 | if (read_status != G_IO_STATUS_ERROR) |
366 | { |
367 | gsize bytes_written; |
368 | |
369 | g_io_channel_write_chars (ps->target_io, |
370 | buf, |
371 | bytes_read, |
372 | &bytes_written, |
373 | &error); |
374 | } |
375 | |
376 | if (error != NULL((void*)0) || read_status == G_IO_STATUS_EOF) |
377 | { |
378 | test_print_cb (CTK_PRINT_BACKEND_TEST (ps->backend)((((CtkPrintBackendTest*) (void *) g_type_check_instance_cast ((GTypeInstance*) ((ps->backend)), ((ctk_print_backend_test_get_type ())))))), error, user_data); |
379 | |
380 | if (error != NULL((void*)0)) |
381 | { |
382 | CTK_NOTE (PRINTING, |
383 | g_print ("TEST Backend: %s\n", error->message)); |
384 | |
385 | g_error_free (error); |
386 | } |
387 | |
388 | return FALSE(0); |
389 | } |
390 | |
391 | CTK_NOTE (PRINTING, |
392 | g_print ("TEST Backend: Writing %i byte chunk to target test\n", (int)bytes_read)); |
393 | |
394 | return TRUE(!(0)); |
395 | } |
396 | |
397 | static void |
398 | ctk_print_backend_test_print_stream (CtkPrintBackend *print_backend, |
399 | CtkPrintJob *job, |
400 | GIOChannel *data_io, |
401 | CtkPrintJobCompleteFunc callback, |
402 | gpointer user_data, |
403 | GDestroyNotify dnotify) |
404 | { |
405 | GError *internal_error = NULL((void*)0); |
406 | CtkPrinter *printer; |
407 | _PrintStreamData *ps; |
408 | CtkPrintSettings *settings; |
409 | gchar *uri, *testname; |
410 | |
411 | printer = ctk_print_job_get_printer (job); |
412 | settings = ctk_print_job_get_settings (job); |
413 | |
414 | ps = g_new0 (_PrintStreamData, 1)((_PrintStreamData *) g_malloc0_n ((1), sizeof (_PrintStreamData ))); |
415 | ps->callback = callback; |
416 | ps->user_data = user_data; |
417 | ps->dnotify = dnotify; |
418 | ps->job = g_object_ref (job)((__typeof__ (job)) (g_object_ref) (job)); |
419 | ps->backend = print_backend; |
420 | |
421 | internal_error = NULL((void*)0); |
422 | uri = output_test_from_settings (settings, NULL((void*)0)); |
423 | testname = g_filename_from_uri (uri, NULL((void*)0), &internal_error); |
424 | g_free (uri); |
425 | |
426 | if (testname == NULL((void*)0)) |
427 | goto error; |
428 | |
429 | ps->target_io = g_io_channel_new_file (testname, "w", &internal_error); |
430 | |
431 | g_free (testname); |
432 | |
433 | if (internal_error == NULL((void*)0)) |
434 | g_io_channel_set_encoding (ps->target_io, NULL((void*)0), &internal_error); |
435 | |
436 | error: |
437 | if (internal_error != NULL((void*)0)) |
438 | { |
439 | test_print_cb (CTK_PRINT_BACKEND_TEST (print_backend)((((CtkPrintBackendTest*) (void *) g_type_check_instance_cast ((GTypeInstance*) ((print_backend)), ((ctk_print_backend_test_get_type ())))))), |
440 | internal_error, ps); |
441 | |
442 | g_error_free (internal_error); |
443 | return; |
444 | } |
445 | |
446 | g_io_add_watch (data_io, |
447 | G_IO_IN | G_IO_PRI | G_IO_ERR | G_IO_HUP, |
448 | (GIOFunc) test_write, |
449 | ps); |
450 | } |
451 | |
452 | static void |
453 | ctk_print_backend_test_init (CtkPrintBackendTest *backend) |
454 | { |
455 | int i; |
456 | |
457 | /* make 100 of these printers */ |
458 | for (i = 0; i < 100; i++) |
459 | { |
460 | CtkPrinter *printer; |
461 | char *name; |
462 | |
463 | name = g_strdup_printf ("%s %i", _("Print to Test Printer")((char *) g_dgettext ("ctk30", "Print to Test Printer")), i); |
464 | printer = g_object_new (CTK_TYPE_PRINTER(ctk_printer_get_type ()), |
465 | "name", name, |
466 | "backend", backend, |
467 | "is-virtual", FALSE(0), /* treat printer like a real one*/ |
468 | NULL((void*)0)); |
469 | g_free (name); |
470 | |
471 | g_message ("TEST Backend: Adding printer %d\n", i); |
472 | |
473 | ctk_printer_set_has_details (printer, FALSE(0)); |
474 | ctk_printer_set_icon_name (printer, "edit-delete"); /* use a delete icon just for fun */ |
475 | ctk_printer_set_is_active (printer, TRUE(!(0))); |
476 | |
477 | ctk_print_backend_add_printer (CTK_PRINT_BACKEND (backend)((((CtkPrintBackend*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((backend)), ((ctk_print_backend_get_type ())))))), printer); |
478 | g_object_unref (printer); |
479 | } |
480 | |
481 | ctk_print_backend_set_list_done (CTK_PRINT_BACKEND (backend)((((CtkPrintBackend*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((backend)), ((ctk_print_backend_get_type ()))))))); |
482 | } |
483 | |
484 | static CtkPrinterOptionSet * |
485 | test_printer_get_options (CtkPrinter *printer G_GNUC_UNUSED__attribute__ ((__unused__)), |
486 | CtkPrintSettings *settings, |
487 | CtkPageSetup *page_setup G_GNUC_UNUSED__attribute__ ((__unused__)), |
488 | CtkPrintCapabilities capabilities G_GNUC_UNUSED__attribute__ ((__unused__))) |
489 | { |
490 | CtkPrinterOptionSet *set; |
491 | CtkPrinterOption *option; |
492 | const gchar *n_up[] = { "1" }; |
493 | OutputFormat format; |
494 | |
495 | format = format_from_settings (settings); |
Value stored to 'format' is never read | |
496 | |
497 | set = ctk_printer_option_set_new (); |
498 | |
499 | option = ctk_printer_option_new ("ctk-n-up", _("Pages per _sheet:")((char *) g_dgettext ("ctk30", "Pages per _sheet:")), CTK_PRINTER_OPTION_TYPE_PICKONE); |
500 | ctk_printer_option_choices_from_array (option, G_N_ELEMENTS (n_up)(sizeof (n_up) / sizeof ((n_up)[0])), |
501 | (char **) n_up, (char **) n_up /* FIXME i18n (localised digits)! */); |
502 | ctk_printer_option_set (option, "1"); |
503 | ctk_printer_option_set_add (set, option); |
504 | g_object_unref (option); |
505 | |
506 | return set; |
507 | } |
508 | |
509 | static void |
510 | test_printer_get_settings_from_options (CtkPrinter *printer G_GNUC_UNUSED__attribute__ ((__unused__)), |
511 | CtkPrinterOptionSet *options G_GNUC_UNUSED__attribute__ ((__unused__)), |
512 | CtkPrintSettings *settings G_GNUC_UNUSED__attribute__ ((__unused__))) |
513 | { |
514 | } |
515 | |
516 | static void |
517 | test_printer_prepare_for_print (CtkPrinter *printer G_GNUC_UNUSED__attribute__ ((__unused__)), |
518 | CtkPrintJob *print_job, |
519 | CtkPrintSettings *settings, |
520 | CtkPageSetup *page_setup G_GNUC_UNUSED__attribute__ ((__unused__))) |
521 | { |
522 | gdouble scale; |
523 | |
524 | ctk_print_job_set_pages (print_job, ctk_print_settings_get_print_pages (settings)); |
525 | ctk_print_job_set_page_ranges (print_job, NULL((void*)0), 0); |
526 | |
527 | if (ctk_print_job_get_pages (print_job) == CTK_PRINT_PAGES_RANGES) |
528 | { |
529 | CtkPageRange *page_ranges; |
530 | gint num_page_ranges; |
531 | page_ranges = ctk_print_settings_get_page_ranges (settings, &num_page_ranges); |
532 | ctk_print_job_set_page_ranges (print_job, page_ranges, num_page_ranges); |
533 | } |
534 | |
535 | ctk_print_job_set_collate (print_job, ctk_print_settings_get_collate (settings)); |
536 | ctk_print_job_set_reverse (print_job, ctk_print_settings_get_reverse (settings)); |
537 | ctk_print_job_set_num_copies (print_job, ctk_print_settings_get_n_copies (settings)); |
538 | |
539 | scale = ctk_print_settings_get_scale (settings); |
540 | if (scale != 100.0) |
541 | ctk_print_job_set_scale (print_job, scale/100.0); |
542 | |
543 | ctk_print_job_set_page_set (print_job, ctk_print_settings_get_page_set (settings)); |
544 | ctk_print_job_set_rotate (print_job, TRUE(!(0))); |
545 | } |
546 | |
547 | static gboolean |
548 | test_printer_details_acquired_cb (CtkPrinter *printer) |
549 | { |
550 | gboolean success; |
551 | gint weight; |
552 | |
553 | /* weight towards success */ |
554 | weight = g_random_int_range (0, 100); |
555 | |
556 | success = FALSE(0); |
557 | if (weight < 75) |
558 | success = TRUE(!(0)); |
559 | |
560 | g_message ("success %i", success); |
561 | ctk_printer_set_has_details (printer, success); |
562 | g_signal_emit_by_name (printer, "details-acquired", success); |
563 | |
564 | return G_SOURCE_REMOVE(0); |
565 | } |
566 | |
567 | static void |
568 | test_printer_request_details (CtkPrinter *printer) |
569 | { |
570 | gint weight; |
571 | gint time; |
572 | /* set the timer to succeed or fail at a random time interval */ |
573 | /* weight towards the shorter end */ |
574 | weight = g_random_int_range (0, 100); |
575 | if (weight < 50) |
576 | time = g_random_int_range (0, 2); |
577 | else if (weight < 75) |
578 | time = g_random_int_range (1, 5); |
579 | else |
580 | time = g_random_int_range (1, 10); |
581 | |
582 | g_message ("Gathering details in %i seconds", time); |
583 | |
584 | if (time == 0) |
585 | time = 10; |
586 | else |
587 | time *= 1000; |
588 | |
589 | g_timeout_add (time, (GSourceFunc) test_printer_details_acquired_cb, printer); |
590 | } |
591 | |
592 |