File: | ctk/ctkprintsettings.c |
Warning: | line 2002, column 36 Casting a non-structure type to a structure type and accessing a field can lead to memory access errors or data corruption |
Press '?' to see keyboard shortcuts
Keyboard shortcuts:
1 | /* CTK - The GIMP Toolkit |
2 | * ctkprintsettings.c: Print Settings |
3 | * Copyright (C) 2006, Red Hat, Inc. |
4 | * |
5 | * This library is free software; you can redistribute it and/or |
6 | * modify it under the terms of the GNU Lesser General Public |
7 | * License as published by the Free Software Foundation; either |
8 | * version 2 of the License, or (at your option) any later version. |
9 | * |
10 | * This library is distributed in the hope that it will be useful, |
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | * Lesser General Public License for more details. |
14 | * |
15 | * You should have received a copy of the GNU Lesser General Public |
16 | * License along with this library. If not, see <http://www.gnu.org/licenses/>. |
17 | */ |
18 | |
19 | #include "config.h" |
20 | |
21 | #include <string.h> |
22 | #include <stdlib.h> |
23 | |
24 | #include <glib/gprintf.h> |
25 | |
26 | #include "ctkprintsettings.h" |
27 | #include "ctkprintutils.h" |
28 | #include "ctktypebuiltins.h" |
29 | #include "ctkwidget.h" |
30 | |
31 | |
32 | /** |
33 | * SECTION:ctkprintsettings |
34 | * @Short_description: Stores print settings |
35 | * @Title: CtkPrintSettings |
36 | * |
37 | * A CtkPrintSettings object represents the settings of a print dialog in |
38 | * a system-independent way. The main use for this object is that once |
39 | * you’ve printed you can get a settings object that represents the settings |
40 | * the user chose, and the next time you print you can pass that object in so |
41 | * that the user doesn’t have to re-set all his settings. |
42 | * |
43 | * Its also possible to enumerate the settings so that you can easily save |
44 | * the settings for the next time your app runs, or even store them in a |
45 | * document. The predefined keys try to use shared values as much as possible |
46 | * so that moving such a document between systems still works. |
47 | * |
48 | * Printing support was added in CTK+ 2.10. |
49 | */ |
50 | |
51 | typedef struct _CtkPrintSettingsClass CtkPrintSettingsClass; |
52 | |
53 | #define CTK_IS_PRINT_SETTINGS_CLASS(klass)(((__extension__ ({ GTypeClass *__class = (GTypeClass*) ((klass )); GType __t = ((ctk_print_settings_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_SETTINGS)((__extension__ ({ GTypeClass *__class = (GTypeClass*) ((klass )); GType __t = ((ctk_print_settings_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; })))) |
54 | #define CTK_PRINT_SETTINGS_CLASS(klass)((((CtkPrintSettingsClass*) (void *) g_type_check_class_cast ( (GTypeClass*) ((klass)), ((ctk_print_settings_get_type ())))) )) (G_TYPE_CHECK_CLASS_CAST ((klass), CTK_TYPE_PRINT_SETTINGS, CtkPrintSettingsClass)(((CtkPrintSettingsClass*) (void *) g_type_check_class_cast ( (GTypeClass*) ((klass)), ((ctk_print_settings_get_type ())))) )) |
55 | #define CTK_PRINT_SETTINGS_GET_CLASS(obj)((((CtkPrintSettingsClass*) (((GTypeInstance*) ((obj)))->g_class )))) (G_TYPE_INSTANCE_GET_CLASS ((obj), CTK_TYPE_PRINT_SETTINGS, CtkPrintSettingsClass)(((CtkPrintSettingsClass*) (((GTypeInstance*) ((obj)))->g_class )))) |
56 | |
57 | struct _CtkPrintSettings |
58 | { |
59 | GObject parent_instance; |
60 | |
61 | GHashTable *hash; |
62 | }; |
63 | |
64 | struct _CtkPrintSettingsClass |
65 | { |
66 | GObjectClass parent_class; |
67 | }; |
68 | |
69 | #define KEYFILE_GROUP_NAME"Print Settings" "Print Settings" |
70 | |
71 | G_DEFINE_TYPE (CtkPrintSettings, ctk_print_settings, G_TYPE_OBJECT)static void ctk_print_settings_init (CtkPrintSettings *self); static void ctk_print_settings_class_init (CtkPrintSettingsClass *klass); static GType ctk_print_settings_get_type_once (void ); static gpointer ctk_print_settings_parent_class = ((void*) 0); static gint CtkPrintSettings_private_offset; static void ctk_print_settings_class_intern_init (gpointer klass) { ctk_print_settings_parent_class = g_type_class_peek_parent (klass); if (CtkPrintSettings_private_offset != 0) g_type_class_adjust_private_offset (klass, &CtkPrintSettings_private_offset); ctk_print_settings_class_init ((CtkPrintSettingsClass*) klass); } __attribute__ ((__unused__ )) static inline gpointer ctk_print_settings_get_instance_private (CtkPrintSettings *self) { return (((gpointer) ((guint8*) (self ) + (glong) (CtkPrintSettings_private_offset)))); } GType ctk_print_settings_get_type (void) { static GType static_g_define_type_id = 0; if ((__extension__ ({ _Static_assert (sizeof *(&static_g_define_type_id) == sizeof (gpointer), "Expression evaluates to false"); (void) ( 0 ? (gpointer) * (&static_g_define_type_id) : ((void*)0)) ; (!(__extension__ ({ _Static_assert (sizeof *(&static_g_define_type_id ) == sizeof (gpointer), "Expression evaluates to false"); __typeof__ (*(&static_g_define_type_id)) gapg_temp_newval; __typeof__ ((&static_g_define_type_id)) gapg_temp_atomic = (&static_g_define_type_id ); __atomic_load (gapg_temp_atomic, &gapg_temp_newval, 5) ; gapg_temp_newval; })) && g_once_init_enter_pointer ( &static_g_define_type_id)); })) ) { GType g_define_type_id = ctk_print_settings_get_type_once (); (__extension__ ({ _Static_assert (sizeof *(&static_g_define_type_id) == sizeof (gpointer) , "Expression evaluates to false"); 0 ? (void) (*(&static_g_define_type_id ) = (g_define_type_id)) : (void) 0; g_once_init_leave_pointer ((&static_g_define_type_id), (gpointer) (guintptr) (g_define_type_id )); })) ; } return static_g_define_type_id; } __attribute__ ( (__noinline__)) static GType ctk_print_settings_get_type_once (void) { GType g_define_type_id = g_type_register_static_simple (((GType) ((20) << (2))), g_intern_static_string ("CtkPrintSettings" ), sizeof (CtkPrintSettingsClass), (GClassInitFunc)(void (*)( void)) ctk_print_settings_class_intern_init, sizeof (CtkPrintSettings ), (GInstanceInitFunc)(void (*)(void)) ctk_print_settings_init , (GTypeFlags) 0); { {{};} } return g_define_type_id; } |
72 | |
73 | static void |
74 | ctk_print_settings_finalize (GObject *object) |
75 | { |
76 | CtkPrintSettings *settings = CTK_PRINT_SETTINGS (object)((((CtkPrintSettings*) (void *) g_type_check_instance_cast (( GTypeInstance*) ((object)), ((ctk_print_settings_get_type ()) ))))); |
77 | |
78 | g_hash_table_destroy (settings->hash); |
79 | |
80 | G_OBJECT_CLASS (ctk_print_settings_parent_class)((((GObjectClass*) (void *) g_type_check_class_cast ((GTypeClass *) ((ctk_print_settings_parent_class)), (((GType) ((20) << (2))))))))->finalize (object); |
81 | } |
82 | |
83 | static void |
84 | ctk_print_settings_init (CtkPrintSettings *settings) |
85 | { |
86 | settings->hash = g_hash_table_new_full (g_str_hash, g_str_equal, |
87 | g_free, g_free); |
88 | } |
89 | |
90 | static void |
91 | ctk_print_settings_class_init (CtkPrintSettingsClass *class) |
92 | { |
93 | GObjectClass *gobject_class = (GObjectClass *)class; |
94 | |
95 | gobject_class->finalize = ctk_print_settings_finalize; |
96 | } |
97 | |
98 | /** |
99 | * ctk_print_settings_new: |
100 | * |
101 | * Creates a new #CtkPrintSettings object. |
102 | * |
103 | * Returns: a new #CtkPrintSettings object |
104 | * |
105 | * Since: 2.10 |
106 | */ |
107 | CtkPrintSettings * |
108 | ctk_print_settings_new (void) |
109 | { |
110 | return g_object_new (CTK_TYPE_PRINT_SETTINGS(ctk_print_settings_get_type ()), NULL((void*)0)); |
111 | } |
112 | |
113 | static void |
114 | copy_hash_entry (gpointer key, |
115 | gpointer value, |
116 | gpointer user_data) |
117 | { |
118 | CtkPrintSettings *settings = user_data; |
119 | |
120 | g_hash_table_insert (settings->hash, |
121 | g_strdup (key)g_strdup_inline (key), |
122 | g_strdup (value)g_strdup_inline (value)); |
123 | } |
124 | |
125 | |
126 | |
127 | /** |
128 | * ctk_print_settings_copy: |
129 | * @other: a #CtkPrintSettings |
130 | * |
131 | * Copies a #CtkPrintSettings object. |
132 | * |
133 | * Returns: (transfer full): a newly allocated copy of @other |
134 | * |
135 | * Since: 2.10 |
136 | */ |
137 | CtkPrintSettings * |
138 | ctk_print_settings_copy (CtkPrintSettings *other) |
139 | { |
140 | CtkPrintSettings *settings; |
141 | |
142 | if (other == NULL((void*)0)) |
143 | return NULL((void*)0); |
144 | |
145 | g_return_val_if_fail (CTK_IS_PRINT_SETTINGS (other), NULL)do { if (((((__extension__ ({ GTypeInstance *__inst = (GTypeInstance *) ((other)); GType __t = ((ctk_print_settings_get_type ())); gboolean __r; if (!__inst) __r = (0); else if (__inst->g_class && __inst->g_class->g_type == __t) __r = (!(0) ); else __r = g_type_check_instance_is_a (__inst, __t); __r; } )))))) { } else { g_return_if_fail_warning ("Ctk", ((const char *) (__func__)), "CTK_IS_PRINT_SETTINGS (other)"); return (((void *)0)); } } while (0); |
146 | |
147 | settings = ctk_print_settings_new (); |
148 | |
149 | g_hash_table_foreach (other->hash, |
150 | copy_hash_entry, |
151 | settings); |
152 | |
153 | return settings; |
154 | } |
155 | |
156 | /** |
157 | * ctk_print_settings_get: |
158 | * @settings: a #CtkPrintSettings |
159 | * @key: a key |
160 | * |
161 | * Looks up the string value associated with @key. |
162 | * |
163 | * Returns: the string value for @key |
164 | * |
165 | * Since: 2.10 |
166 | */ |
167 | const gchar * |
168 | ctk_print_settings_get (CtkPrintSettings *settings, |
169 | const gchar *key) |
170 | { |
171 | return g_hash_table_lookup (settings->hash, key); |
172 | } |
173 | |
174 | /** |
175 | * ctk_print_settings_set: |
176 | * @settings: a #CtkPrintSettings |
177 | * @key: a key |
178 | * @value: (allow-none): a string value, or %NULL |
179 | * |
180 | * Associates @value with @key. |
181 | * |
182 | * Since: 2.10 |
183 | */ |
184 | void |
185 | ctk_print_settings_set (CtkPrintSettings *settings, |
186 | const gchar *key, |
187 | const gchar *value) |
188 | { |
189 | if (value == NULL((void*)0)) |
190 | ctk_print_settings_unset (settings, key); |
191 | else |
192 | g_hash_table_insert (settings->hash, |
193 | g_strdup (key)g_strdup_inline (key), |
194 | g_strdup (value)g_strdup_inline (value)); |
195 | } |
196 | |
197 | /** |
198 | * ctk_print_settings_unset: |
199 | * @settings: a #CtkPrintSettings |
200 | * @key: a key |
201 | * |
202 | * Removes any value associated with @key. |
203 | * This has the same effect as setting the value to %NULL. |
204 | * |
205 | * Since: 2.10 |
206 | */ |
207 | void |
208 | ctk_print_settings_unset (CtkPrintSettings *settings, |
209 | const gchar *key) |
210 | { |
211 | g_hash_table_remove (settings->hash, key); |
212 | } |
213 | |
214 | /** |
215 | * ctk_print_settings_has_key: |
216 | * @settings: a #CtkPrintSettings |
217 | * @key: a key |
218 | * |
219 | * Returns %TRUE, if a value is associated with @key. |
220 | * |
221 | * Returns: %TRUE, if @key has a value |
222 | * |
223 | * Since: 2.10 |
224 | */ |
225 | gboolean |
226 | ctk_print_settings_has_key (CtkPrintSettings *settings, |
227 | const gchar *key) |
228 | { |
229 | return ctk_print_settings_get (settings, key) != NULL((void*)0); |
230 | } |
231 | |
232 | |
233 | /** |
234 | * ctk_print_settings_get_bool: |
235 | * @settings: a #CtkPrintSettings |
236 | * @key: a key |
237 | * |
238 | * Returns the boolean represented by the value |
239 | * that is associated with @key. |
240 | * |
241 | * The string “true” represents %TRUE, any other |
242 | * string %FALSE. |
243 | * |
244 | * Returns: %TRUE, if @key maps to a true value. |
245 | * |
246 | * Since: 2.10 |
247 | **/ |
248 | gboolean |
249 | ctk_print_settings_get_bool (CtkPrintSettings *settings, |
250 | const gchar *key) |
251 | { |
252 | const gchar *val; |
253 | |
254 | val = ctk_print_settings_get (settings, key); |
255 | if (g_strcmp0 (val, "true") == 0) |
256 | return TRUE(!(0)); |
257 | |
258 | return FALSE(0); |
259 | } |
260 | |
261 | /** |
262 | * ctk_print_settings_get_bool_with_default: |
263 | * @settings: a #CtkPrintSettings |
264 | * @key: a key |
265 | * @default_val: the default value |
266 | * |
267 | * Returns the boolean represented by the value |
268 | * that is associated with @key, or @default_val |
269 | * if the value does not represent a boolean. |
270 | * |
271 | * The string “true” represents %TRUE, the string |
272 | * “false” represents %FALSE. |
273 | * |
274 | * Returns: the boolean value associated with @key |
275 | * |
276 | * Since: 2.10 |
277 | */ |
278 | static gboolean |
279 | ctk_print_settings_get_bool_with_default (CtkPrintSettings *settings, |
280 | const gchar *key, |
281 | gboolean default_val) |
282 | { |
283 | const gchar *val; |
284 | |
285 | val = ctk_print_settings_get (settings, key); |
286 | if (g_strcmp0 (val, "true") == 0) |
287 | return TRUE(!(0)); |
288 | |
289 | if (g_strcmp0 (val, "false") == 0) |
290 | return FALSE(0); |
291 | |
292 | return default_val; |
293 | } |
294 | |
295 | /** |
296 | * ctk_print_settings_set_bool: |
297 | * @settings: a #CtkPrintSettings |
298 | * @key: a key |
299 | * @value: a boolean |
300 | * |
301 | * Sets @key to a boolean value. |
302 | * |
303 | * Since: 2.10 |
304 | */ |
305 | void |
306 | ctk_print_settings_set_bool (CtkPrintSettings *settings, |
307 | const gchar *key, |
308 | gboolean value) |
309 | { |
310 | if (value) |
311 | ctk_print_settings_set (settings, key, "true"); |
312 | else |
313 | ctk_print_settings_set (settings, key, "false"); |
314 | } |
315 | |
316 | /** |
317 | * ctk_print_settings_get_double_with_default: |
318 | * @settings: a #CtkPrintSettings |
319 | * @key: a key |
320 | * @def: the default value |
321 | * |
322 | * Returns the floating point number represented by |
323 | * the value that is associated with @key, or @default_val |
324 | * if the value does not represent a floating point number. |
325 | * |
326 | * Floating point numbers are parsed with g_ascii_strtod(). |
327 | * |
328 | * Returns: the floating point number associated with @key |
329 | * |
330 | * Since: 2.10 |
331 | */ |
332 | gdouble |
333 | ctk_print_settings_get_double_with_default (CtkPrintSettings *settings, |
334 | const gchar *key, |
335 | gdouble def) |
336 | { |
337 | const gchar *val; |
338 | |
339 | val = ctk_print_settings_get (settings, key); |
340 | if (val == NULL((void*)0)) |
341 | return def; |
342 | |
343 | return g_ascii_strtod (val, NULL((void*)0)); |
344 | } |
345 | |
346 | /** |
347 | * ctk_print_settings_get_double: |
348 | * @settings: a #CtkPrintSettings |
349 | * @key: a key |
350 | * |
351 | * Returns the double value associated with @key, or 0. |
352 | * |
353 | * Returns: the double value of @key |
354 | * |
355 | * Since: 2.10 |
356 | */ |
357 | gdouble |
358 | ctk_print_settings_get_double (CtkPrintSettings *settings, |
359 | const gchar *key) |
360 | { |
361 | return ctk_print_settings_get_double_with_default (settings, key, 0.0); |
362 | } |
363 | |
364 | /** |
365 | * ctk_print_settings_set_double: |
366 | * @settings: a #CtkPrintSettings |
367 | * @key: a key |
368 | * @value: a double value |
369 | * |
370 | * Sets @key to a double value. |
371 | * |
372 | * Since: 2.10 |
373 | */ |
374 | void |
375 | ctk_print_settings_set_double (CtkPrintSettings *settings, |
376 | const gchar *key, |
377 | gdouble value) |
378 | { |
379 | gchar buf[G_ASCII_DTOSTR_BUF_SIZE(29 + 10)]; |
380 | |
381 | g_ascii_dtostr (buf, G_ASCII_DTOSTR_BUF_SIZE(29 + 10), value); |
382 | ctk_print_settings_set (settings, key, buf); |
383 | } |
384 | |
385 | /** |
386 | * ctk_print_settings_get_length: |
387 | * @settings: a #CtkPrintSettings |
388 | * @key: a key |
389 | * @unit: the unit of the return value |
390 | * |
391 | * Returns the value associated with @key, interpreted |
392 | * as a length. The returned value is converted to @units. |
393 | * |
394 | * Returns: the length value of @key, converted to @unit |
395 | * |
396 | * Since: 2.10 |
397 | */ |
398 | gdouble |
399 | ctk_print_settings_get_length (CtkPrintSettings *settings, |
400 | const gchar *key, |
401 | CtkUnit unit) |
402 | { |
403 | gdouble length = ctk_print_settings_get_double (settings, key); |
404 | return _ctk_print_convert_from_mm (length, unit); |
405 | } |
406 | |
407 | /** |
408 | * ctk_print_settings_set_length: |
409 | * @settings: a #CtkPrintSettings |
410 | * @key: a key |
411 | * @value: a length |
412 | * @unit: the unit of @length |
413 | * |
414 | * Associates a length in units of @unit with @key. |
415 | * |
416 | * Since: 2.10 |
417 | */ |
418 | void |
419 | ctk_print_settings_set_length (CtkPrintSettings *settings, |
420 | const gchar *key, |
421 | gdouble value, |
422 | CtkUnit unit) |
423 | { |
424 | ctk_print_settings_set_double (settings, key, |
425 | _ctk_print_convert_to_mm (value, unit)); |
426 | } |
427 | |
428 | /** |
429 | * ctk_print_settings_get_int_with_default: |
430 | * @settings: a #CtkPrintSettings |
431 | * @key: a key |
432 | * @def: the default value |
433 | * |
434 | * Returns the value of @key, interpreted as |
435 | * an integer, or the default value. |
436 | * |
437 | * Returns: the integer value of @key |
438 | * |
439 | * Since: 2.10 |
440 | */ |
441 | gint |
442 | ctk_print_settings_get_int_with_default (CtkPrintSettings *settings, |
443 | const gchar *key, |
444 | gint def) |
445 | { |
446 | const gchar *val; |
447 | |
448 | val = ctk_print_settings_get (settings, key); |
449 | if (val == NULL((void*)0)) |
450 | return def; |
451 | |
452 | return atoi (val); |
453 | } |
454 | |
455 | /** |
456 | * ctk_print_settings_get_int: |
457 | * @settings: a #CtkPrintSettings |
458 | * @key: a key |
459 | * |
460 | * Returns the integer value of @key, or 0. |
461 | * |
462 | * Returns: the integer value of @key |
463 | * |
464 | * Since: 2.10 |
465 | */ |
466 | gint |
467 | ctk_print_settings_get_int (CtkPrintSettings *settings, |
468 | const gchar *key) |
469 | { |
470 | return ctk_print_settings_get_int_with_default (settings, key, 0); |
471 | } |
472 | |
473 | /** |
474 | * ctk_print_settings_set_int: |
475 | * @settings: a #CtkPrintSettings |
476 | * @key: a key |
477 | * @value: an integer |
478 | * |
479 | * Sets @key to an integer value. |
480 | * |
481 | * Since: 2.10 |
482 | */ |
483 | void |
484 | ctk_print_settings_set_int (CtkPrintSettings *settings, |
485 | const gchar *key, |
486 | gint value) |
487 | { |
488 | gchar buf[128]; |
489 | g_sprintf (buf, "%d", value); |
490 | ctk_print_settings_set (settings, key, buf); |
491 | } |
492 | |
493 | /** |
494 | * ctk_print_settings_foreach: |
495 | * @settings: a #CtkPrintSettings |
496 | * @func: (scope call): the function to call |
497 | * @user_data: user data for @func |
498 | * |
499 | * Calls @func for each key-value pair of @settings. |
500 | * |
501 | * Since: 2.10 |
502 | */ |
503 | void |
504 | ctk_print_settings_foreach (CtkPrintSettings *settings, |
505 | CtkPrintSettingsFunc func, |
506 | gpointer user_data) |
507 | { |
508 | g_hash_table_foreach (settings->hash, (GHFunc)func, user_data); |
509 | } |
510 | |
511 | /** |
512 | * ctk_print_settings_get_printer: |
513 | * @settings: a #CtkPrintSettings |
514 | * |
515 | * Convenience function to obtain the value of |
516 | * %CTK_PRINT_SETTINGS_PRINTER. |
517 | * |
518 | * Returns: the printer name |
519 | * |
520 | * Since: 2.10 |
521 | */ |
522 | const gchar * |
523 | ctk_print_settings_get_printer (CtkPrintSettings *settings) |
524 | { |
525 | return ctk_print_settings_get (settings, CTK_PRINT_SETTINGS_PRINTER"printer"); |
526 | } |
527 | |
528 | |
529 | /** |
530 | * ctk_print_settings_set_printer: |
531 | * @settings: a #CtkPrintSettings |
532 | * @printer: the printer name |
533 | * |
534 | * Convenience function to set %CTK_PRINT_SETTINGS_PRINTER |
535 | * to @printer. |
536 | * |
537 | * Since: 2.10 |
538 | */ |
539 | void |
540 | ctk_print_settings_set_printer (CtkPrintSettings *settings, |
541 | const gchar *printer) |
542 | { |
543 | ctk_print_settings_set (settings, CTK_PRINT_SETTINGS_PRINTER"printer", printer); |
544 | } |
545 | |
546 | /** |
547 | * ctk_print_settings_get_orientation: |
548 | * @settings: a #CtkPrintSettings |
549 | * |
550 | * Get the value of %CTK_PRINT_SETTINGS_ORIENTATION, |
551 | * converted to a #CtkPageOrientation. |
552 | * |
553 | * Returns: the orientation |
554 | * |
555 | * Since: 2.10 |
556 | */ |
557 | CtkPageOrientation |
558 | ctk_print_settings_get_orientation (CtkPrintSettings *settings) |
559 | { |
560 | const gchar *val; |
561 | |
562 | val = ctk_print_settings_get (settings, CTK_PRINT_SETTINGS_ORIENTATION"orientation"); |
563 | |
564 | if (val == NULL((void*)0) || strcmp (val, "portrait") == 0) |
565 | return CTK_PAGE_ORIENTATION_PORTRAIT; |
566 | |
567 | if (strcmp (val, "landscape") == 0) |
568 | return CTK_PAGE_ORIENTATION_LANDSCAPE; |
569 | |
570 | if (strcmp (val, "reverse_portrait") == 0) |
571 | return CTK_PAGE_ORIENTATION_REVERSE_PORTRAIT; |
572 | |
573 | if (strcmp (val, "reverse_landscape") == 0) |
574 | return CTK_PAGE_ORIENTATION_REVERSE_LANDSCAPE; |
575 | |
576 | return CTK_PAGE_ORIENTATION_PORTRAIT; |
577 | } |
578 | |
579 | /** |
580 | * ctk_print_settings_set_orientation: |
581 | * @settings: a #CtkPrintSettings |
582 | * @orientation: a page orientation |
583 | * |
584 | * Sets the value of %CTK_PRINT_SETTINGS_ORIENTATION. |
585 | * |
586 | * Since: 2.10 |
587 | */ |
588 | void |
589 | ctk_print_settings_set_orientation (CtkPrintSettings *settings, |
590 | CtkPageOrientation orientation) |
591 | { |
592 | const gchar *val; |
593 | |
594 | switch (orientation) |
595 | { |
596 | case CTK_PAGE_ORIENTATION_LANDSCAPE: |
597 | val = "landscape"; |
598 | break; |
599 | default: |
600 | case CTK_PAGE_ORIENTATION_PORTRAIT: |
601 | val = "portrait"; |
602 | break; |
603 | case CTK_PAGE_ORIENTATION_REVERSE_LANDSCAPE: |
604 | val = "reverse_landscape"; |
605 | break; |
606 | case CTK_PAGE_ORIENTATION_REVERSE_PORTRAIT: |
607 | val = "reverse_portrait"; |
608 | break; |
609 | } |
610 | ctk_print_settings_set (settings, CTK_PRINT_SETTINGS_ORIENTATION"orientation", val); |
611 | } |
612 | |
613 | /** |
614 | * ctk_print_settings_get_paper_size: |
615 | * @settings: a #CtkPrintSettings |
616 | * |
617 | * Gets the value of %CTK_PRINT_SETTINGS_PAPER_FORMAT, |
618 | * converted to a #CtkPaperSize. |
619 | * |
620 | * Returns: the paper size |
621 | * |
622 | * Since: 2.10 |
623 | */ |
624 | CtkPaperSize * |
625 | ctk_print_settings_get_paper_size (CtkPrintSettings *settings) |
626 | { |
627 | const gchar *val; |
628 | const gchar *name; |
629 | gdouble w, h; |
630 | |
631 | val = ctk_print_settings_get (settings, CTK_PRINT_SETTINGS_PAPER_FORMAT"paper-format"); |
632 | if (val == NULL((void*)0)) |
633 | return NULL((void*)0); |
634 | |
635 | if (g_str_has_prefix (val, "custom-")(__builtin_constant_p ("custom-")? __extension__ ({ const char * const __str = (val); const char * const __prefix = ("custom-" ); gboolean __result = (0); if (__str == ((void*)0) || __prefix == ((void*)0)) __result = (g_str_has_prefix) (__str, __prefix ); else { const size_t __str_len = strlen (((__str) + !(__str ))); const size_t __prefix_len = strlen (((__prefix) + !(__prefix ))); if (__str_len >= __prefix_len) __result = memcmp (((__str ) + !(__str)), ((__prefix) + !(__prefix)), __prefix_len) == 0 ; } __result; }) : (g_str_has_prefix) (val, "custom-") )) |
636 | { |
637 | name = val + strlen ("custom-"); |
638 | w = ctk_print_settings_get_paper_width (settings, CTK_UNIT_MM); |
639 | h = ctk_print_settings_get_paper_height (settings, CTK_UNIT_MM); |
640 | return ctk_paper_size_new_custom (name, name, w, h, CTK_UNIT_MM); |
641 | } |
642 | |
643 | return ctk_paper_size_new (val); |
644 | } |
645 | |
646 | /** |
647 | * ctk_print_settings_set_paper_size: |
648 | * @settings: a #CtkPrintSettings |
649 | * @paper_size: a paper size |
650 | * |
651 | * Sets the value of %CTK_PRINT_SETTINGS_PAPER_FORMAT, |
652 | * %CTK_PRINT_SETTINGS_PAPER_WIDTH and |
653 | * %CTK_PRINT_SETTINGS_PAPER_HEIGHT. |
654 | * |
655 | * Since: 2.10 |
656 | */ |
657 | void |
658 | ctk_print_settings_set_paper_size (CtkPrintSettings *settings, |
659 | CtkPaperSize *paper_size) |
660 | { |
661 | gchar *custom_name; |
662 | |
663 | if (paper_size == NULL((void*)0)) |
664 | { |
665 | ctk_print_settings_set (settings, CTK_PRINT_SETTINGS_PAPER_FORMAT"paper-format", NULL((void*)0)); |
666 | ctk_print_settings_set (settings, CTK_PRINT_SETTINGS_PAPER_WIDTH"paper-width", NULL((void*)0)); |
667 | ctk_print_settings_set (settings, CTK_PRINT_SETTINGS_PAPER_HEIGHT"paper-height", NULL((void*)0)); |
668 | } |
669 | else if (ctk_paper_size_is_custom (paper_size)) |
670 | { |
671 | custom_name = g_strdup_printf ("custom-%s", |
672 | ctk_paper_size_get_name (paper_size)); |
673 | ctk_print_settings_set (settings, CTK_PRINT_SETTINGS_PAPER_FORMAT"paper-format", custom_name); |
674 | g_free (custom_name); |
675 | ctk_print_settings_set_paper_width (settings, |
676 | ctk_paper_size_get_width (paper_size, |
677 | CTK_UNIT_MM), |
678 | CTK_UNIT_MM); |
679 | ctk_print_settings_set_paper_height (settings, |
680 | ctk_paper_size_get_height (paper_size, |
681 | CTK_UNIT_MM), |
682 | CTK_UNIT_MM); |
683 | } |
684 | else |
685 | ctk_print_settings_set (settings, CTK_PRINT_SETTINGS_PAPER_FORMAT"paper-format", |
686 | ctk_paper_size_get_name (paper_size)); |
687 | } |
688 | |
689 | /** |
690 | * ctk_print_settings_get_paper_width: |
691 | * @settings: a #CtkPrintSettings |
692 | * @unit: the unit for the return value |
693 | * |
694 | * Gets the value of %CTK_PRINT_SETTINGS_PAPER_WIDTH, |
695 | * converted to @unit. |
696 | * |
697 | * Returns: the paper width, in units of @unit |
698 | * |
699 | * Since: 2.10 |
700 | */ |
701 | gdouble |
702 | ctk_print_settings_get_paper_width (CtkPrintSettings *settings, |
703 | CtkUnit unit) |
704 | { |
705 | return ctk_print_settings_get_length (settings, CTK_PRINT_SETTINGS_PAPER_WIDTH"paper-width", unit); |
706 | } |
707 | |
708 | /** |
709 | * ctk_print_settings_set_paper_width: |
710 | * @settings: a #CtkPrintSettings |
711 | * @width: the paper width |
712 | * @unit: the units of @width |
713 | * |
714 | * Sets the value of %CTK_PRINT_SETTINGS_PAPER_WIDTH. |
715 | * |
716 | * Since: 2.10 |
717 | */ |
718 | void |
719 | ctk_print_settings_set_paper_width (CtkPrintSettings *settings, |
720 | gdouble width, |
721 | CtkUnit unit) |
722 | { |
723 | ctk_print_settings_set_length (settings, CTK_PRINT_SETTINGS_PAPER_WIDTH"paper-width", width, unit); |
724 | } |
725 | |
726 | /** |
727 | * ctk_print_settings_get_paper_height: |
728 | * @settings: a #CtkPrintSettings |
729 | * @unit: the unit for the return value |
730 | * |
731 | * Gets the value of %CTK_PRINT_SETTINGS_PAPER_HEIGHT, |
732 | * converted to @unit. |
733 | * |
734 | * Returns: the paper height, in units of @unit |
735 | * |
736 | * Since: 2.10 |
737 | */ |
738 | gdouble |
739 | ctk_print_settings_get_paper_height (CtkPrintSettings *settings, |
740 | CtkUnit unit) |
741 | { |
742 | return ctk_print_settings_get_length (settings, |
743 | CTK_PRINT_SETTINGS_PAPER_HEIGHT"paper-height", |
744 | unit); |
745 | } |
746 | |
747 | /** |
748 | * ctk_print_settings_set_paper_height: |
749 | * @settings: a #CtkPrintSettings |
750 | * @height: the paper height |
751 | * @unit: the units of @height |
752 | * |
753 | * Sets the value of %CTK_PRINT_SETTINGS_PAPER_HEIGHT. |
754 | * |
755 | * Since: 2.10 |
756 | */ |
757 | void |
758 | ctk_print_settings_set_paper_height (CtkPrintSettings *settings, |
759 | gdouble height, |
760 | CtkUnit unit) |
761 | { |
762 | ctk_print_settings_set_length (settings, |
763 | CTK_PRINT_SETTINGS_PAPER_HEIGHT"paper-height", |
764 | height, unit); |
765 | } |
766 | |
767 | /** |
768 | * ctk_print_settings_get_use_color: |
769 | * @settings: a #CtkPrintSettings |
770 | * |
771 | * Gets the value of %CTK_PRINT_SETTINGS_USE_COLOR. |
772 | * |
773 | * Returns: whether to use color |
774 | * |
775 | * Since: 2.10 |
776 | */ |
777 | gboolean |
778 | ctk_print_settings_get_use_color (CtkPrintSettings *settings) |
779 | { |
780 | return ctk_print_settings_get_bool_with_default (settings, |
781 | CTK_PRINT_SETTINGS_USE_COLOR"use-color", |
782 | TRUE(!(0))); |
783 | } |
784 | |
785 | /** |
786 | * ctk_print_settings_set_use_color: |
787 | * @settings: a #CtkPrintSettings |
788 | * @use_color: whether to use color |
789 | * |
790 | * Sets the value of %CTK_PRINT_SETTINGS_USE_COLOR. |
791 | * |
792 | * Since: 2.10 |
793 | */ |
794 | void |
795 | ctk_print_settings_set_use_color (CtkPrintSettings *settings, |
796 | gboolean use_color) |
797 | { |
798 | ctk_print_settings_set_bool (settings, |
799 | CTK_PRINT_SETTINGS_USE_COLOR"use-color", |
800 | use_color); |
801 | } |
802 | |
803 | /** |
804 | * ctk_print_settings_get_collate: |
805 | * @settings: a #CtkPrintSettings |
806 | * |
807 | * Gets the value of %CTK_PRINT_SETTINGS_COLLATE. |
808 | * |
809 | * Returns: whether to collate the printed pages |
810 | * |
811 | * Since: 2.10 |
812 | */ |
813 | gboolean |
814 | ctk_print_settings_get_collate (CtkPrintSettings *settings) |
815 | { |
816 | return ctk_print_settings_get_bool_with_default (settings, |
817 | CTK_PRINT_SETTINGS_COLLATE"collate", |
818 | TRUE(!(0))); |
819 | } |
820 | |
821 | /** |
822 | * ctk_print_settings_set_collate: |
823 | * @settings: a #CtkPrintSettings |
824 | * @collate: whether to collate the output |
825 | * |
826 | * Sets the value of %CTK_PRINT_SETTINGS_COLLATE. |
827 | * |
828 | * Since: 2.10 |
829 | */ |
830 | void |
831 | ctk_print_settings_set_collate (CtkPrintSettings *settings, |
832 | gboolean collate) |
833 | { |
834 | ctk_print_settings_set_bool (settings, |
835 | CTK_PRINT_SETTINGS_COLLATE"collate", |
836 | collate); |
837 | } |
838 | |
839 | /** |
840 | * ctk_print_settings_get_reverse: |
841 | * @settings: a #CtkPrintSettings |
842 | * |
843 | * Gets the value of %CTK_PRINT_SETTINGS_REVERSE. |
844 | * |
845 | * Returns: whether to reverse the order of the printed pages |
846 | * |
847 | * Since: 2.10 |
848 | */ |
849 | gboolean |
850 | ctk_print_settings_get_reverse (CtkPrintSettings *settings) |
851 | { |
852 | return ctk_print_settings_get_bool (settings, |
853 | CTK_PRINT_SETTINGS_REVERSE"reverse"); |
854 | } |
855 | |
856 | /** |
857 | * ctk_print_settings_set_reverse: |
858 | * @settings: a #CtkPrintSettings |
859 | * @reverse: whether to reverse the output |
860 | * |
861 | * Sets the value of %CTK_PRINT_SETTINGS_REVERSE. |
862 | * |
863 | * Since: 2.10 |
864 | */ |
865 | void |
866 | ctk_print_settings_set_reverse (CtkPrintSettings *settings, |
867 | gboolean reverse) |
868 | { |
869 | ctk_print_settings_set_bool (settings, |
870 | CTK_PRINT_SETTINGS_REVERSE"reverse", |
871 | reverse); |
872 | } |
873 | |
874 | /** |
875 | * ctk_print_settings_get_duplex: |
876 | * @settings: a #CtkPrintSettings |
877 | * |
878 | * Gets the value of %CTK_PRINT_SETTINGS_DUPLEX. |
879 | * |
880 | * Returns: whether to print the output in duplex. |
881 | * |
882 | * Since: 2.10 |
883 | */ |
884 | CtkPrintDuplex |
885 | ctk_print_settings_get_duplex (CtkPrintSettings *settings) |
886 | { |
887 | const gchar *val; |
888 | |
889 | val = ctk_print_settings_get (settings, CTK_PRINT_SETTINGS_DUPLEX"duplex"); |
890 | |
891 | if (val == NULL((void*)0) || (strcmp (val, "simplex") == 0)) |
892 | return CTK_PRINT_DUPLEX_SIMPLEX; |
893 | |
894 | if (strcmp (val, "horizontal") == 0) |
895 | return CTK_PRINT_DUPLEX_HORIZONTAL; |
896 | |
897 | if (strcmp (val, "vertical") == 0) |
898 | return CTK_PRINT_DUPLEX_VERTICAL; |
899 | |
900 | return CTK_PRINT_DUPLEX_SIMPLEX; |
901 | } |
902 | |
903 | /** |
904 | * ctk_print_settings_set_duplex: |
905 | * @settings: a #CtkPrintSettings |
906 | * @duplex: a #CtkPrintDuplex value |
907 | * |
908 | * Sets the value of %CTK_PRINT_SETTINGS_DUPLEX. |
909 | * |
910 | * Since: 2.10 |
911 | */ |
912 | void |
913 | ctk_print_settings_set_duplex (CtkPrintSettings *settings, |
914 | CtkPrintDuplex duplex) |
915 | { |
916 | const gchar *str; |
917 | |
918 | switch (duplex) |
919 | { |
920 | default: |
921 | case CTK_PRINT_DUPLEX_SIMPLEX: |
922 | str = "simplex"; |
923 | break; |
924 | case CTK_PRINT_DUPLEX_HORIZONTAL: |
925 | str = "horizontal"; |
926 | break; |
927 | case CTK_PRINT_DUPLEX_VERTICAL: |
928 | str = "vertical"; |
929 | break; |
930 | } |
931 | |
932 | ctk_print_settings_set (settings, CTK_PRINT_SETTINGS_DUPLEX"duplex", str); |
933 | } |
934 | |
935 | /** |
936 | * ctk_print_settings_get_quality: |
937 | * @settings: a #CtkPrintSettings |
938 | * |
939 | * Gets the value of %CTK_PRINT_SETTINGS_QUALITY. |
940 | * |
941 | * Returns: the print quality |
942 | * |
943 | * Since: 2.10 |
944 | */ |
945 | CtkPrintQuality |
946 | ctk_print_settings_get_quality (CtkPrintSettings *settings) |
947 | { |
948 | const gchar *val; |
949 | |
950 | val = ctk_print_settings_get (settings, CTK_PRINT_SETTINGS_QUALITY"quality"); |
951 | |
952 | if (val == NULL((void*)0) || (strcmp (val, "normal") == 0)) |
953 | return CTK_PRINT_QUALITY_NORMAL; |
954 | |
955 | if (strcmp (val, "high") == 0) |
956 | return CTK_PRINT_QUALITY_HIGH; |
957 | |
958 | if (strcmp (val, "low") == 0) |
959 | return CTK_PRINT_QUALITY_LOW; |
960 | |
961 | if (strcmp (val, "draft") == 0) |
962 | return CTK_PRINT_QUALITY_DRAFT; |
963 | |
964 | return CTK_PRINT_QUALITY_NORMAL; |
965 | } |
966 | |
967 | /** |
968 | * ctk_print_settings_set_quality: |
969 | * @settings: a #CtkPrintSettings |
970 | * @quality: a #CtkPrintQuality value |
971 | * |
972 | * Sets the value of %CTK_PRINT_SETTINGS_QUALITY. |
973 | * |
974 | * Since: 2.10 |
975 | */ |
976 | void |
977 | ctk_print_settings_set_quality (CtkPrintSettings *settings, |
978 | CtkPrintQuality quality) |
979 | { |
980 | const gchar *str; |
981 | |
982 | switch (quality) |
983 | { |
984 | default: |
985 | case CTK_PRINT_QUALITY_NORMAL: |
986 | str = "normal"; |
987 | break; |
988 | case CTK_PRINT_QUALITY_HIGH: |
989 | str = "high"; |
990 | break; |
991 | case CTK_PRINT_QUALITY_LOW: |
992 | str = "low"; |
993 | break; |
994 | case CTK_PRINT_QUALITY_DRAFT: |
995 | str = "draft"; |
996 | break; |
997 | } |
998 | |
999 | ctk_print_settings_set (settings, CTK_PRINT_SETTINGS_QUALITY"quality", str); |
1000 | } |
1001 | |
1002 | /** |
1003 | * ctk_print_settings_get_page_set: |
1004 | * @settings: a #CtkPrintSettings |
1005 | * |
1006 | * Gets the value of %CTK_PRINT_SETTINGS_PAGE_SET. |
1007 | * |
1008 | * Returns: the set of pages to print |
1009 | * |
1010 | * Since: 2.10 |
1011 | */ |
1012 | CtkPageSet |
1013 | ctk_print_settings_get_page_set (CtkPrintSettings *settings) |
1014 | { |
1015 | const gchar *val; |
1016 | |
1017 | val = ctk_print_settings_get (settings, CTK_PRINT_SETTINGS_PAGE_SET"page-set"); |
1018 | |
1019 | if (val == NULL((void*)0) || (strcmp (val, "all") == 0)) |
1020 | return CTK_PAGE_SET_ALL; |
1021 | |
1022 | if (strcmp (val, "even") == 0) |
1023 | return CTK_PAGE_SET_EVEN; |
1024 | |
1025 | if (strcmp (val, "odd") == 0) |
1026 | return CTK_PAGE_SET_ODD; |
1027 | |
1028 | return CTK_PAGE_SET_ALL; |
1029 | } |
1030 | |
1031 | /** |
1032 | * ctk_print_settings_set_page_set: |
1033 | * @settings: a #CtkPrintSettings |
1034 | * @page_set: a #CtkPageSet value |
1035 | * |
1036 | * Sets the value of %CTK_PRINT_SETTINGS_PAGE_SET. |
1037 | * |
1038 | * Since: 2.10 |
1039 | */ |
1040 | void |
1041 | ctk_print_settings_set_page_set (CtkPrintSettings *settings, |
1042 | CtkPageSet page_set) |
1043 | { |
1044 | const gchar *str; |
1045 | |
1046 | switch (page_set) |
1047 | { |
1048 | default: |
1049 | case CTK_PAGE_SET_ALL: |
1050 | str = "all"; |
1051 | break; |
1052 | case CTK_PAGE_SET_EVEN: |
1053 | str = "even"; |
1054 | break; |
1055 | case CTK_PAGE_SET_ODD: |
1056 | str = "odd"; |
1057 | break; |
1058 | } |
1059 | |
1060 | ctk_print_settings_set (settings, CTK_PRINT_SETTINGS_PAGE_SET"page-set", str); |
1061 | } |
1062 | |
1063 | /** |
1064 | * ctk_print_settings_get_number_up_layout: |
1065 | * @settings: a #CtkPrintSettings |
1066 | * |
1067 | * Gets the value of %CTK_PRINT_SETTINGS_NUMBER_UP_LAYOUT. |
1068 | * |
1069 | * Returns: layout of page in number-up mode |
1070 | * |
1071 | * Since: 2.14 |
1072 | */ |
1073 | CtkNumberUpLayout |
1074 | ctk_print_settings_get_number_up_layout (CtkPrintSettings *settings) |
1075 | { |
1076 | CtkNumberUpLayout layout; |
1077 | CtkTextDirection text_direction; |
1078 | GEnumClass *enum_class; |
1079 | GEnumValue *enum_value; |
1080 | const gchar *val; |
1081 | |
1082 | g_return_val_if_fail (CTK_IS_PRINT_SETTINGS (settings), CTK_NUMBER_UP_LAYOUT_LEFT_TO_RIGHT_TOP_TO_BOTTOM)do { if (((((__extension__ ({ GTypeInstance *__inst = (GTypeInstance *) ((settings)); GType __t = ((ctk_print_settings_get_type () )); gboolean __r; if (!__inst) __r = (0); else if (__inst-> g_class && __inst->g_class->g_type == __t) __r = (!(0)); else __r = g_type_check_instance_is_a (__inst, __t); __r; })))))) { } else { g_return_if_fail_warning ("Ctk", ((const char*) (__func__)), "CTK_IS_PRINT_SETTINGS (settings)"); return (CTK_NUMBER_UP_LAYOUT_LEFT_TO_RIGHT_TOP_TO_BOTTOM); } } while (0); |
1083 | |
1084 | val = ctk_print_settings_get (settings, CTK_PRINT_SETTINGS_NUMBER_UP_LAYOUT"number-up-layout"); |
1085 | text_direction = ctk_widget_get_default_direction (); |
1086 | |
1087 | if (text_direction == CTK_TEXT_DIR_LTR) |
1088 | layout = CTK_NUMBER_UP_LAYOUT_LEFT_TO_RIGHT_TOP_TO_BOTTOM; |
1089 | else |
1090 | layout = CTK_NUMBER_UP_LAYOUT_RIGHT_TO_LEFT_TOP_TO_BOTTOM; |
1091 | |
1092 | if (val == NULL((void*)0)) |
1093 | return layout; |
1094 | |
1095 | enum_class = g_type_class_ref (CTK_TYPE_NUMBER_UP_LAYOUT(ctk_number_up_layout_get_type ())); |
1096 | enum_value = g_enum_get_value_by_nick (enum_class, val); |
1097 | if (enum_value) |
1098 | layout = enum_value->value; |
1099 | g_type_class_unref (enum_class); |
1100 | |
1101 | return layout; |
1102 | } |
1103 | |
1104 | /** |
1105 | * ctk_print_settings_set_number_up_layout: |
1106 | * @settings: a #CtkPrintSettings |
1107 | * @number_up_layout: a #CtkNumberUpLayout value |
1108 | * |
1109 | * Sets the value of %CTK_PRINT_SETTINGS_NUMBER_UP_LAYOUT. |
1110 | * |
1111 | * Since: 2.14 |
1112 | */ |
1113 | void |
1114 | ctk_print_settings_set_number_up_layout (CtkPrintSettings *settings, |
1115 | CtkNumberUpLayout number_up_layout) |
1116 | { |
1117 | GEnumClass *enum_class; |
1118 | GEnumValue *enum_value; |
1119 | |
1120 | g_return_if_fail (CTK_IS_PRINT_SETTINGS (settings))do { if (((((__extension__ ({ GTypeInstance *__inst = (GTypeInstance *) ((settings)); GType __t = ((ctk_print_settings_get_type () )); gboolean __r; if (!__inst) __r = (0); else if (__inst-> g_class && __inst->g_class->g_type == __t) __r = (!(0)); else __r = g_type_check_instance_is_a (__inst, __t); __r; })))))) { } else { g_return_if_fail_warning ("Ctk", ((const char*) (__func__)), "CTK_IS_PRINT_SETTINGS (settings)"); return ; } } while (0); |
1121 | |
1122 | enum_class = g_type_class_ref (CTK_TYPE_NUMBER_UP_LAYOUT(ctk_number_up_layout_get_type ())); |
1123 | enum_value = g_enum_get_value (enum_class, number_up_layout); |
1124 | g_return_if_fail (enum_value != NULL)do { if ((enum_value != ((void*)0))) { } else { g_return_if_fail_warning ("Ctk", ((const char*) (__func__)), "enum_value != NULL"); return ; } } while (0); |
1125 | |
1126 | ctk_print_settings_set (settings, CTK_PRINT_SETTINGS_NUMBER_UP_LAYOUT"number-up-layout", enum_value->value_nick); |
1127 | g_type_class_unref (enum_class); |
1128 | } |
1129 | |
1130 | /** |
1131 | * ctk_print_settings_get_n_copies: |
1132 | * @settings: a #CtkPrintSettings |
1133 | * |
1134 | * Gets the value of %CTK_PRINT_SETTINGS_N_COPIES. |
1135 | * |
1136 | * Returns: the number of copies to print |
1137 | * |
1138 | * Since: 2.10 |
1139 | */ |
1140 | gint |
1141 | ctk_print_settings_get_n_copies (CtkPrintSettings *settings) |
1142 | { |
1143 | return ctk_print_settings_get_int_with_default (settings, CTK_PRINT_SETTINGS_N_COPIES"n-copies", 1); |
1144 | } |
1145 | |
1146 | /** |
1147 | * ctk_print_settings_set_n_copies: |
1148 | * @settings: a #CtkPrintSettings |
1149 | * @num_copies: the number of copies |
1150 | * |
1151 | * Sets the value of %CTK_PRINT_SETTINGS_N_COPIES. |
1152 | * |
1153 | * Since: 2.10 |
1154 | */ |
1155 | void |
1156 | ctk_print_settings_set_n_copies (CtkPrintSettings *settings, |
1157 | gint num_copies) |
1158 | { |
1159 | ctk_print_settings_set_int (settings, CTK_PRINT_SETTINGS_N_COPIES"n-copies", |
1160 | num_copies); |
1161 | } |
1162 | |
1163 | /** |
1164 | * ctk_print_settings_get_number_up: |
1165 | * @settings: a #CtkPrintSettings |
1166 | * |
1167 | * Gets the value of %CTK_PRINT_SETTINGS_NUMBER_UP. |
1168 | * |
1169 | * Returns: the number of pages per sheet |
1170 | * |
1171 | * Since: 2.10 |
1172 | */ |
1173 | gint |
1174 | ctk_print_settings_get_number_up (CtkPrintSettings *settings) |
1175 | { |
1176 | return ctk_print_settings_get_int_with_default (settings, CTK_PRINT_SETTINGS_NUMBER_UP"number-up", 1); |
1177 | } |
1178 | |
1179 | /** |
1180 | * ctk_print_settings_set_number_up: |
1181 | * @settings: a #CtkPrintSettings |
1182 | * @number_up: the number of pages per sheet |
1183 | * |
1184 | * Sets the value of %CTK_PRINT_SETTINGS_NUMBER_UP. |
1185 | * |
1186 | * Since: 2.10 |
1187 | */ |
1188 | void |
1189 | ctk_print_settings_set_number_up (CtkPrintSettings *settings, |
1190 | gint number_up) |
1191 | { |
1192 | ctk_print_settings_set_int (settings, CTK_PRINT_SETTINGS_NUMBER_UP"number-up", |
1193 | number_up); |
1194 | } |
1195 | |
1196 | /** |
1197 | * ctk_print_settings_get_resolution: |
1198 | * @settings: a #CtkPrintSettings |
1199 | * |
1200 | * Gets the value of %CTK_PRINT_SETTINGS_RESOLUTION. |
1201 | * |
1202 | * Returns: the resolution in dpi |
1203 | * |
1204 | * Since: 2.10 |
1205 | */ |
1206 | gint |
1207 | ctk_print_settings_get_resolution (CtkPrintSettings *settings) |
1208 | { |
1209 | return ctk_print_settings_get_int_with_default (settings, CTK_PRINT_SETTINGS_RESOLUTION"resolution", 300); |
1210 | } |
1211 | |
1212 | /** |
1213 | * ctk_print_settings_set_resolution: |
1214 | * @settings: a #CtkPrintSettings |
1215 | * @resolution: the resolution in dpi |
1216 | * |
1217 | * Sets the values of %CTK_PRINT_SETTINGS_RESOLUTION, |
1218 | * %CTK_PRINT_SETTINGS_RESOLUTION_X and |
1219 | * %CTK_PRINT_SETTINGS_RESOLUTION_Y. |
1220 | * |
1221 | * Since: 2.10 |
1222 | */ |
1223 | void |
1224 | ctk_print_settings_set_resolution (CtkPrintSettings *settings, |
1225 | gint resolution) |
1226 | { |
1227 | ctk_print_settings_set_int (settings, CTK_PRINT_SETTINGS_RESOLUTION"resolution", |
1228 | resolution); |
1229 | ctk_print_settings_set_int (settings, CTK_PRINT_SETTINGS_RESOLUTION_X"resolution-x", |
1230 | resolution); |
1231 | ctk_print_settings_set_int (settings, CTK_PRINT_SETTINGS_RESOLUTION_Y"resolution-y", |
1232 | resolution); |
1233 | } |
1234 | |
1235 | /** |
1236 | * ctk_print_settings_get_resolution_x: |
1237 | * @settings: a #CtkPrintSettings |
1238 | * |
1239 | * Gets the value of %CTK_PRINT_SETTINGS_RESOLUTION_X. |
1240 | * |
1241 | * Returns: the horizontal resolution in dpi |
1242 | * |
1243 | * Since: 2.16 |
1244 | */ |
1245 | gint |
1246 | ctk_print_settings_get_resolution_x (CtkPrintSettings *settings) |
1247 | { |
1248 | return ctk_print_settings_get_int_with_default (settings, CTK_PRINT_SETTINGS_RESOLUTION_X"resolution-x", 300); |
1249 | } |
1250 | |
1251 | /** |
1252 | * ctk_print_settings_get_resolution_y: |
1253 | * @settings: a #CtkPrintSettings |
1254 | * |
1255 | * Gets the value of %CTK_PRINT_SETTINGS_RESOLUTION_Y. |
1256 | * |
1257 | * Returns: the vertical resolution in dpi |
1258 | * |
1259 | * Since: 2.16 |
1260 | */ |
1261 | gint |
1262 | ctk_print_settings_get_resolution_y (CtkPrintSettings *settings) |
1263 | { |
1264 | return ctk_print_settings_get_int_with_default (settings, CTK_PRINT_SETTINGS_RESOLUTION_Y"resolution-y", 300); |
1265 | } |
1266 | |
1267 | /** |
1268 | * ctk_print_settings_set_resolution_xy: |
1269 | * @settings: a #CtkPrintSettings |
1270 | * @resolution_x: the horizontal resolution in dpi |
1271 | * @resolution_y: the vertical resolution in dpi |
1272 | * |
1273 | * Sets the values of %CTK_PRINT_SETTINGS_RESOLUTION, |
1274 | * %CTK_PRINT_SETTINGS_RESOLUTION_X and |
1275 | * %CTK_PRINT_SETTINGS_RESOLUTION_Y. |
1276 | * |
1277 | * Since: 2.16 |
1278 | */ |
1279 | void |
1280 | ctk_print_settings_set_resolution_xy (CtkPrintSettings *settings, |
1281 | gint resolution_x, |
1282 | gint resolution_y) |
1283 | { |
1284 | ctk_print_settings_set_int (settings, CTK_PRINT_SETTINGS_RESOLUTION_X"resolution-x", |
1285 | resolution_x); |
1286 | ctk_print_settings_set_int (settings, CTK_PRINT_SETTINGS_RESOLUTION_Y"resolution-y", |
1287 | resolution_y); |
1288 | ctk_print_settings_set_int (settings, CTK_PRINT_SETTINGS_RESOLUTION"resolution", |
1289 | resolution_x); |
1290 | } |
1291 | |
1292 | /** |
1293 | * ctk_print_settings_get_printer_lpi: |
1294 | * @settings: a #CtkPrintSettings |
1295 | * |
1296 | * Gets the value of %CTK_PRINT_SETTINGS_PRINTER_LPI. |
1297 | * |
1298 | * Returns: the resolution in lpi (lines per inch) |
1299 | * |
1300 | * Since: 2.16 |
1301 | */ |
1302 | gdouble |
1303 | ctk_print_settings_get_printer_lpi (CtkPrintSettings *settings) |
1304 | { |
1305 | return ctk_print_settings_get_double_with_default (settings, CTK_PRINT_SETTINGS_PRINTER_LPI"printer-lpi", 150.0); |
1306 | } |
1307 | |
1308 | /** |
1309 | * ctk_print_settings_set_printer_lpi: |
1310 | * @settings: a #CtkPrintSettings |
1311 | * @lpi: the resolution in lpi (lines per inch) |
1312 | * |
1313 | * Sets the value of %CTK_PRINT_SETTINGS_PRINTER_LPI. |
1314 | * |
1315 | * Since: 2.16 |
1316 | */ |
1317 | void |
1318 | ctk_print_settings_set_printer_lpi (CtkPrintSettings *settings, |
1319 | gdouble lpi) |
1320 | { |
1321 | ctk_print_settings_set_double (settings, CTK_PRINT_SETTINGS_PRINTER_LPI"printer-lpi", |
1322 | lpi); |
1323 | } |
1324 | |
1325 | /** |
1326 | * ctk_print_settings_get_scale: |
1327 | * @settings: a #CtkPrintSettings |
1328 | * |
1329 | * Gets the value of %CTK_PRINT_SETTINGS_SCALE. |
1330 | * |
1331 | * Returns: the scale in percent |
1332 | * |
1333 | * Since: 2.10 |
1334 | */ |
1335 | gdouble |
1336 | ctk_print_settings_get_scale (CtkPrintSettings *settings) |
1337 | { |
1338 | return ctk_print_settings_get_double_with_default (settings, |
1339 | CTK_PRINT_SETTINGS_SCALE"scale", |
1340 | 100.0); |
1341 | } |
1342 | |
1343 | /** |
1344 | * ctk_print_settings_set_scale: |
1345 | * @settings: a #CtkPrintSettings |
1346 | * @scale: the scale in percent |
1347 | * |
1348 | * Sets the value of %CTK_PRINT_SETTINGS_SCALE. |
1349 | * |
1350 | * Since: 2.10 |
1351 | */ |
1352 | void |
1353 | ctk_print_settings_set_scale (CtkPrintSettings *settings, |
1354 | gdouble scale) |
1355 | { |
1356 | ctk_print_settings_set_double (settings, CTK_PRINT_SETTINGS_SCALE"scale", |
1357 | scale); |
1358 | } |
1359 | |
1360 | /** |
1361 | * ctk_print_settings_get_print_pages: |
1362 | * @settings: a #CtkPrintSettings |
1363 | * |
1364 | * Gets the value of %CTK_PRINT_SETTINGS_PRINT_PAGES. |
1365 | * |
1366 | * Returns: which pages to print |
1367 | * |
1368 | * Since: 2.10 |
1369 | */ |
1370 | CtkPrintPages |
1371 | ctk_print_settings_get_print_pages (CtkPrintSettings *settings) |
1372 | { |
1373 | const gchar *val; |
1374 | |
1375 | val = ctk_print_settings_get (settings, CTK_PRINT_SETTINGS_PRINT_PAGES"print-pages"); |
1376 | |
1377 | if (val == NULL((void*)0) || (strcmp (val, "all") == 0)) |
1378 | return CTK_PRINT_PAGES_ALL; |
1379 | |
1380 | if (strcmp (val, "selection") == 0) |
1381 | return CTK_PRINT_PAGES_SELECTION; |
1382 | |
1383 | if (strcmp (val, "current") == 0) |
1384 | return CTK_PRINT_PAGES_CURRENT; |
1385 | |
1386 | if (strcmp (val, "ranges") == 0) |
1387 | return CTK_PRINT_PAGES_RANGES; |
1388 | |
1389 | return CTK_PRINT_PAGES_ALL; |
1390 | } |
1391 | |
1392 | /** |
1393 | * ctk_print_settings_set_print_pages: |
1394 | * @settings: a #CtkPrintSettings |
1395 | * @pages: a #CtkPrintPages value |
1396 | * |
1397 | * Sets the value of %CTK_PRINT_SETTINGS_PRINT_PAGES. |
1398 | * |
1399 | * Since: 2.10 |
1400 | */ |
1401 | void |
1402 | ctk_print_settings_set_print_pages (CtkPrintSettings *settings, |
1403 | CtkPrintPages pages) |
1404 | { |
1405 | const gchar *str; |
1406 | |
1407 | switch (pages) |
1408 | { |
1409 | default: |
1410 | case CTK_PRINT_PAGES_ALL: |
1411 | str = "all"; |
1412 | break; |
1413 | case CTK_PRINT_PAGES_CURRENT: |
1414 | str = "current"; |
1415 | break; |
1416 | case CTK_PRINT_PAGES_SELECTION: |
1417 | str = "selection"; |
1418 | break; |
1419 | case CTK_PRINT_PAGES_RANGES: |
1420 | str = "ranges"; |
1421 | break; |
1422 | } |
1423 | |
1424 | ctk_print_settings_set (settings, CTK_PRINT_SETTINGS_PRINT_PAGES"print-pages", str); |
1425 | } |
1426 | |
1427 | /** |
1428 | * ctk_print_settings_get_page_ranges: |
1429 | * @settings: a #CtkPrintSettings |
1430 | * @num_ranges: (out): return location for the length of the returned array |
1431 | * |
1432 | * Gets the value of %CTK_PRINT_SETTINGS_PAGE_RANGES. |
1433 | * |
1434 | * Returns: (array length=num_ranges) (transfer full): an array |
1435 | * of #CtkPageRanges. Use g_free() to free the array when |
1436 | * it is no longer needed. |
1437 | * |
1438 | * Since: 2.10 |
1439 | */ |
1440 | CtkPageRange * |
1441 | ctk_print_settings_get_page_ranges (CtkPrintSettings *settings, |
1442 | gint *num_ranges) |
1443 | { |
1444 | const gchar *val; |
1445 | gchar **range_strs; |
1446 | CtkPageRange *ranges; |
1447 | gint i, n; |
1448 | |
1449 | val = ctk_print_settings_get (settings, CTK_PRINT_SETTINGS_PAGE_RANGES"page-ranges"); |
1450 | |
1451 | if (val == NULL((void*)0)) |
1452 | { |
1453 | *num_ranges = 0; |
1454 | return NULL((void*)0); |
1455 | } |
1456 | |
1457 | range_strs = g_strsplit (val, ",", 0); |
1458 | |
1459 | for (i = 0; range_strs[i] != NULL((void*)0); i++) |
1460 | ; |
1461 | |
1462 | n = i; |
1463 | |
1464 | ranges = g_new0 (CtkPageRange, n)((CtkPageRange *) g_malloc0_n ((n), sizeof (CtkPageRange))); |
1465 | |
1466 | for (i = 0; i < n; i++) |
1467 | { |
1468 | gint start, end; |
1469 | gchar *str; |
1470 | |
1471 | start = (gint)strtol (range_strs[i], &str, 10); |
1472 | end = start; |
1473 | |
1474 | if (*str == '-') |
1475 | { |
1476 | str++; |
1477 | end = (gint)strtol (str, NULL((void*)0), 10); |
1478 | } |
1479 | |
1480 | ranges[i].start = start; |
1481 | ranges[i].end = end; |
1482 | } |
1483 | |
1484 | g_strfreev (range_strs); |
1485 | |
1486 | *num_ranges = n; |
1487 | return ranges; |
1488 | } |
1489 | |
1490 | /** |
1491 | * ctk_print_settings_set_page_ranges: |
1492 | * @settings: a #CtkPrintSettings |
1493 | * @page_ranges: (array length=num_ranges): an array of #CtkPageRanges |
1494 | * @num_ranges: the length of @page_ranges |
1495 | * |
1496 | * Sets the value of %CTK_PRINT_SETTINGS_PAGE_RANGES. |
1497 | * |
1498 | * Since: 2.10 |
1499 | */ |
1500 | void |
1501 | ctk_print_settings_set_page_ranges (CtkPrintSettings *settings, |
1502 | CtkPageRange *page_ranges, |
1503 | gint num_ranges) |
1504 | { |
1505 | GString *s; |
1506 | gint i; |
1507 | |
1508 | s = g_string_new (""); |
1509 | |
1510 | for (i = 0; i < num_ranges; i++) |
1511 | { |
1512 | if (page_ranges[i].start == page_ranges[i].end) |
1513 | g_string_append_printf (s, "%d", page_ranges[i].start); |
1514 | else |
1515 | g_string_append_printf (s, "%d-%d", |
1516 | page_ranges[i].start, |
1517 | page_ranges[i].end); |
1518 | if (i < num_ranges - 1) |
1519 | g_string_append (s, ",")(__builtin_constant_p (",") ? __extension__ ({ const char * const __val = (","); g_string_append_len_inline (s, __val, (__val != ((void*)0)) ? (gssize) strlen (((__val) + !(__val))) : (gssize ) -1); }) : g_string_append_len_inline (s, ",", (gssize) -1)); |
1520 | } |
1521 | |
1522 | |
1523 | ctk_print_settings_set (settings, CTK_PRINT_SETTINGS_PAGE_RANGES"page-ranges", |
1524 | s->str); |
1525 | |
1526 | g_string_free (s, TRUE)(__builtin_constant_p ((!(0))) ? (((!(0))) ? (g_string_free) ( (s), ((!(0)))) : g_string_free_and_steal (s)) : (g_string_free ) ((s), ((!(0))))); |
1527 | } |
1528 | |
1529 | /** |
1530 | * ctk_print_settings_get_default_source: |
1531 | * @settings: a #CtkPrintSettings |
1532 | * |
1533 | * Gets the value of %CTK_PRINT_SETTINGS_DEFAULT_SOURCE. |
1534 | * |
1535 | * Returns: the default source |
1536 | * |
1537 | * Since: 2.10 |
1538 | */ |
1539 | const gchar * |
1540 | ctk_print_settings_get_default_source (CtkPrintSettings *settings) |
1541 | { |
1542 | return ctk_print_settings_get (settings, CTK_PRINT_SETTINGS_DEFAULT_SOURCE"default-source"); |
1543 | } |
1544 | |
1545 | /** |
1546 | * ctk_print_settings_set_default_source: |
1547 | * @settings: a #CtkPrintSettings |
1548 | * @default_source: the default source |
1549 | * |
1550 | * Sets the value of %CTK_PRINT_SETTINGS_DEFAULT_SOURCE. |
1551 | * |
1552 | * Since: 2.10 |
1553 | */ |
1554 | void |
1555 | ctk_print_settings_set_default_source (CtkPrintSettings *settings, |
1556 | const gchar *default_source) |
1557 | { |
1558 | ctk_print_settings_set (settings, CTK_PRINT_SETTINGS_DEFAULT_SOURCE"default-source", default_source); |
1559 | } |
1560 | |
1561 | /** |
1562 | * ctk_print_settings_get_media_type: |
1563 | * @settings: a #CtkPrintSettings |
1564 | * |
1565 | * Gets the value of %CTK_PRINT_SETTINGS_MEDIA_TYPE. |
1566 | * |
1567 | * The set of media types is defined in PWG 5101.1-2002 PWG. |
1568 | * |
1569 | * Returns: the media type |
1570 | * |
1571 | * Since: 2.10 |
1572 | */ |
1573 | const gchar * |
1574 | ctk_print_settings_get_media_type (CtkPrintSettings *settings) |
1575 | { |
1576 | return ctk_print_settings_get (settings, CTK_PRINT_SETTINGS_MEDIA_TYPE"media-type"); |
1577 | } |
1578 | |
1579 | /** |
1580 | * ctk_print_settings_set_media_type: |
1581 | * @settings: a #CtkPrintSettings |
1582 | * @media_type: the media type |
1583 | * |
1584 | * Sets the value of %CTK_PRINT_SETTINGS_MEDIA_TYPE. |
1585 | * |
1586 | * The set of media types is defined in PWG 5101.1-2002 PWG. |
1587 | * |
1588 | * Since: 2.10 |
1589 | */ |
1590 | void |
1591 | ctk_print_settings_set_media_type (CtkPrintSettings *settings, |
1592 | const gchar *media_type) |
1593 | { |
1594 | ctk_print_settings_set (settings, CTK_PRINT_SETTINGS_MEDIA_TYPE"media-type", media_type); |
1595 | } |
1596 | |
1597 | /** |
1598 | * ctk_print_settings_get_dither: |
1599 | * @settings: a #CtkPrintSettings |
1600 | * |
1601 | * Gets the value of %CTK_PRINT_SETTINGS_DITHER. |
1602 | * |
1603 | * Returns: the dithering that is used |
1604 | * |
1605 | * Since: 2.10 |
1606 | */ |
1607 | const gchar * |
1608 | ctk_print_settings_get_dither (CtkPrintSettings *settings) |
1609 | { |
1610 | return ctk_print_settings_get (settings, CTK_PRINT_SETTINGS_DITHER"dither"); |
1611 | } |
1612 | |
1613 | /** |
1614 | * ctk_print_settings_set_dither: |
1615 | * @settings: a #CtkPrintSettings |
1616 | * @dither: the dithering that is used |
1617 | * |
1618 | * Sets the value of %CTK_PRINT_SETTINGS_DITHER. |
1619 | * |
1620 | * Since: 2.10 |
1621 | */ |
1622 | void |
1623 | ctk_print_settings_set_dither (CtkPrintSettings *settings, |
1624 | const gchar *dither) |
1625 | { |
1626 | ctk_print_settings_set (settings, CTK_PRINT_SETTINGS_DITHER"dither", dither); |
1627 | } |
1628 | |
1629 | /** |
1630 | * ctk_print_settings_get_finishings: |
1631 | * @settings: a #CtkPrintSettings |
1632 | * |
1633 | * Gets the value of %CTK_PRINT_SETTINGS_FINISHINGS. |
1634 | * |
1635 | * Returns: the finishings |
1636 | * |
1637 | * Since: 2.10 |
1638 | */ |
1639 | const gchar * |
1640 | ctk_print_settings_get_finishings (CtkPrintSettings *settings) |
1641 | { |
1642 | return ctk_print_settings_get (settings, CTK_PRINT_SETTINGS_FINISHINGS"finishings"); |
1643 | } |
1644 | |
1645 | /** |
1646 | * ctk_print_settings_set_finishings: |
1647 | * @settings: a #CtkPrintSettings |
1648 | * @finishings: the finishings |
1649 | * |
1650 | * Sets the value of %CTK_PRINT_SETTINGS_FINISHINGS. |
1651 | * |
1652 | * Since: 2.10 |
1653 | */ |
1654 | void |
1655 | ctk_print_settings_set_finishings (CtkPrintSettings *settings, |
1656 | const gchar *finishings) |
1657 | { |
1658 | ctk_print_settings_set (settings, CTK_PRINT_SETTINGS_FINISHINGS"finishings", finishings); |
1659 | } |
1660 | |
1661 | /** |
1662 | * ctk_print_settings_get_output_bin: |
1663 | * @settings: a #CtkPrintSettings |
1664 | * |
1665 | * Gets the value of %CTK_PRINT_SETTINGS_OUTPUT_BIN. |
1666 | * |
1667 | * Returns: the output bin |
1668 | * |
1669 | * Since: 2.10 |
1670 | */ |
1671 | const gchar * |
1672 | ctk_print_settings_get_output_bin (CtkPrintSettings *settings) |
1673 | { |
1674 | return ctk_print_settings_get (settings, CTK_PRINT_SETTINGS_OUTPUT_BIN"output-bin"); |
1675 | } |
1676 | |
1677 | /** |
1678 | * ctk_print_settings_set_output_bin: |
1679 | * @settings: a #CtkPrintSettings |
1680 | * @output_bin: the output bin |
1681 | * |
1682 | * Sets the value of %CTK_PRINT_SETTINGS_OUTPUT_BIN. |
1683 | * |
1684 | * Since: 2.10 |
1685 | */ |
1686 | void |
1687 | ctk_print_settings_set_output_bin (CtkPrintSettings *settings, |
1688 | const gchar *output_bin) |
1689 | { |
1690 | ctk_print_settings_set (settings, CTK_PRINT_SETTINGS_OUTPUT_BIN"output-bin", output_bin); |
1691 | } |
1692 | |
1693 | /** |
1694 | * ctk_print_settings_load_file: |
1695 | * @settings: a #CtkPrintSettings |
1696 | * @file_name: (type filename): the filename to read the settings from |
1697 | * @error: (allow-none): return location for errors, or %NULL |
1698 | * |
1699 | * Reads the print settings from @file_name. If the file could not be loaded |
1700 | * then error is set to either a #GFileError or #GKeyFileError. |
1701 | * See ctk_print_settings_to_file(). |
1702 | * |
1703 | * Returns: %TRUE on success |
1704 | * |
1705 | * Since: 2.14 |
1706 | */ |
1707 | gboolean |
1708 | ctk_print_settings_load_file (CtkPrintSettings *settings, |
1709 | const gchar *file_name, |
1710 | GError **error) |
1711 | { |
1712 | gboolean retval = FALSE(0); |
1713 | GKeyFile *key_file; |
1714 | |
1715 | g_return_val_if_fail (CTK_IS_PRINT_SETTINGS (settings), FALSE)do { if (((((__extension__ ({ GTypeInstance *__inst = (GTypeInstance *) ((settings)); GType __t = ((ctk_print_settings_get_type () )); gboolean __r; if (!__inst) __r = (0); else if (__inst-> g_class && __inst->g_class->g_type == __t) __r = (!(0)); else __r = g_type_check_instance_is_a (__inst, __t); __r; })))))) { } else { g_return_if_fail_warning ("Ctk", ((const char*) (__func__)), "CTK_IS_PRINT_SETTINGS (settings)"); return ((0)); } } while (0); |
1716 | g_return_val_if_fail (file_name != NULL, FALSE)do { if ((file_name != ((void*)0))) { } else { g_return_if_fail_warning ("Ctk", ((const char*) (__func__)), "file_name != NULL"); return ((0)); } } while (0); |
1717 | |
1718 | key_file = g_key_file_new (); |
1719 | |
1720 | if (g_key_file_load_from_file (key_file, file_name, 0, error) && |
1721 | ctk_print_settings_load_key_file (settings, key_file, NULL((void*)0), error)) |
1722 | retval = TRUE(!(0)); |
1723 | |
1724 | g_key_file_free (key_file); |
1725 | |
1726 | return retval; |
1727 | } |
1728 | |
1729 | /** |
1730 | * ctk_print_settings_new_from_file: |
1731 | * @file_name: (type filename): the filename to read the settings from |
1732 | * @error: (allow-none): return location for errors, or %NULL |
1733 | * |
1734 | * Reads the print settings from @file_name. Returns a new #CtkPrintSettings |
1735 | * object with the restored settings, or %NULL if an error occurred. If the |
1736 | * file could not be loaded then error is set to either a #GFileError or |
1737 | * #GKeyFileError. See ctk_print_settings_to_file(). |
1738 | * |
1739 | * Returns: the restored #CtkPrintSettings |
1740 | * |
1741 | * Since: 2.12 |
1742 | */ |
1743 | CtkPrintSettings * |
1744 | ctk_print_settings_new_from_file (const gchar *file_name, |
1745 | GError **error) |
1746 | { |
1747 | CtkPrintSettings *settings = ctk_print_settings_new (); |
1748 | |
1749 | if (!ctk_print_settings_load_file (settings, file_name, error)) |
1750 | { |
1751 | g_object_unref (settings); |
1752 | settings = NULL((void*)0); |
1753 | } |
1754 | |
1755 | return settings; |
1756 | } |
1757 | |
1758 | /** |
1759 | * ctk_print_settings_load_key_file: |
1760 | * @settings: a #CtkPrintSettings |
1761 | * @key_file: the #GKeyFile to retrieve the settings from |
1762 | * @group_name: (allow-none): the name of the group to use, or %NULL to use the default |
1763 | * “Print Settings” |
1764 | * @error: (allow-none): return location for errors, or %NULL |
1765 | * |
1766 | * Reads the print settings from the group @group_name in @key_file. If the |
1767 | * file could not be loaded then error is set to either a #GFileError or |
1768 | * #GKeyFileError. |
1769 | * |
1770 | * Returns: %TRUE on success |
1771 | * |
1772 | * Since: 2.14 |
1773 | */ |
1774 | gboolean |
1775 | ctk_print_settings_load_key_file (CtkPrintSettings *settings, |
1776 | GKeyFile *key_file, |
1777 | const gchar *group_name, |
1778 | GError **error) |
1779 | { |
1780 | gchar **keys; |
1781 | gsize n_keys, i; |
1782 | GError *err = NULL((void*)0); |
1783 | |
1784 | g_return_val_if_fail (CTK_IS_PRINT_SETTINGS (settings), FALSE)do { if (((((__extension__ ({ GTypeInstance *__inst = (GTypeInstance *) ((settings)); GType __t = ((ctk_print_settings_get_type () )); gboolean __r; if (!__inst) __r = (0); else if (__inst-> g_class && __inst->g_class->g_type == __t) __r = (!(0)); else __r = g_type_check_instance_is_a (__inst, __t); __r; })))))) { } else { g_return_if_fail_warning ("Ctk", ((const char*) (__func__)), "CTK_IS_PRINT_SETTINGS (settings)"); return ((0)); } } while (0); |
1785 | g_return_val_if_fail (key_file != NULL, FALSE)do { if ((key_file != ((void*)0))) { } else { g_return_if_fail_warning ("Ctk", ((const char*) (__func__)), "key_file != NULL"); return ((0)); } } while (0); |
1786 | |
1787 | if (!group_name) |
1788 | group_name = KEYFILE_GROUP_NAME"Print Settings"; |
1789 | |
1790 | keys = g_key_file_get_keys (key_file, |
1791 | group_name, |
1792 | &n_keys, |
1793 | &err); |
1794 | if (err != NULL((void*)0)) |
1795 | { |
1796 | g_propagate_error (error, err); |
1797 | return FALSE(0); |
1798 | } |
1799 | |
1800 | for (i = 0 ; i < n_keys; ++i) |
1801 | { |
1802 | gchar *value; |
1803 | |
1804 | value = g_key_file_get_string (key_file, |
1805 | group_name, |
1806 | keys[i], |
1807 | NULL((void*)0)); |
1808 | if (!value) |
1809 | continue; |
1810 | |
1811 | ctk_print_settings_set (settings, keys[i], value); |
1812 | g_free (value); |
1813 | } |
1814 | |
1815 | g_strfreev (keys); |
1816 | |
1817 | return TRUE(!(0)); |
1818 | } |
1819 | |
1820 | /** |
1821 | * ctk_print_settings_new_from_key_file: |
1822 | * @key_file: the #GKeyFile to retrieve the settings from |
1823 | * @group_name: (allow-none): the name of the group to use, or %NULL to use |
1824 | * the default “Print Settings” |
1825 | * @error: (allow-none): return location for errors, or %NULL |
1826 | * |
1827 | * Reads the print settings from the group @group_name in @key_file. Returns a |
1828 | * new #CtkPrintSettings object with the restored settings, or %NULL if an |
1829 | * error occurred. If the file could not be loaded then error is set to either |
1830 | * a #GFileError or #GKeyFileError. |
1831 | * |
1832 | * Returns: the restored #CtkPrintSettings |
1833 | * |
1834 | * Since: 2.12 |
1835 | */ |
1836 | CtkPrintSettings * |
1837 | ctk_print_settings_new_from_key_file (GKeyFile *key_file, |
1838 | const gchar *group_name, |
1839 | GError **error) |
1840 | { |
1841 | CtkPrintSettings *settings = ctk_print_settings_new (); |
1842 | |
1843 | if (!ctk_print_settings_load_key_file (settings, key_file, |
1844 | group_name, error)) |
1845 | { |
1846 | g_object_unref (settings); |
1847 | settings = NULL((void*)0); |
1848 | } |
1849 | |
1850 | return settings; |
1851 | } |
1852 | |
1853 | /** |
1854 | * ctk_print_settings_to_file: |
1855 | * @settings: a #CtkPrintSettings |
1856 | * @file_name: (type filename): the file to save to |
1857 | * @error: (allow-none): return location for errors, or %NULL |
1858 | * |
1859 | * This function saves the print settings from @settings to @file_name. If the |
1860 | * file could not be loaded then error is set to either a #GFileError or |
1861 | * #GKeyFileError. |
1862 | * |
1863 | * Returns: %TRUE on success |
1864 | * |
1865 | * Since: 2.12 |
1866 | */ |
1867 | gboolean |
1868 | ctk_print_settings_to_file (CtkPrintSettings *settings, |
1869 | const gchar *file_name, |
1870 | GError **error) |
1871 | { |
1872 | GKeyFile *key_file; |
1873 | gboolean retval = FALSE(0); |
1874 | char *data = NULL((void*)0); |
1875 | gsize len; |
1876 | GError *err = NULL((void*)0); |
1877 | |
1878 | g_return_val_if_fail (CTK_IS_PRINT_SETTINGS (settings), FALSE)do { if (((((__extension__ ({ GTypeInstance *__inst = (GTypeInstance *) ((settings)); GType __t = ((ctk_print_settings_get_type () )); gboolean __r; if (!__inst) __r = (0); else if (__inst-> g_class && __inst->g_class->g_type == __t) __r = (!(0)); else __r = g_type_check_instance_is_a (__inst, __t); __r; })))))) { } else { g_return_if_fail_warning ("Ctk", ((const char*) (__func__)), "CTK_IS_PRINT_SETTINGS (settings)"); return ((0)); } } while (0); |
1879 | g_return_val_if_fail (file_name != NULL, FALSE)do { if ((file_name != ((void*)0))) { } else { g_return_if_fail_warning ("Ctk", ((const char*) (__func__)), "file_name != NULL"); return ((0)); } } while (0); |
1880 | |
1881 | key_file = g_key_file_new (); |
1882 | ctk_print_settings_to_key_file (settings, key_file, NULL((void*)0)); |
1883 | |
1884 | data = g_key_file_to_data (key_file, &len, &err); |
1885 | if (!data) |
1886 | goto out; |
1887 | |
1888 | retval = g_file_set_contents (file_name, data, len, &err); |
1889 | |
1890 | out: |
1891 | if (err != NULL((void*)0)) |
1892 | g_propagate_error (error, err); |
1893 | |
1894 | g_key_file_free (key_file); |
1895 | g_free (data); |
1896 | |
1897 | return retval; |
1898 | } |
1899 | |
1900 | typedef struct { |
1901 | GKeyFile *key_file; |
1902 | const gchar *group_name; |
1903 | } SettingsData; |
1904 | |
1905 | static void |
1906 | add_value_to_key_file (const gchar *key, |
1907 | const gchar *value, |
1908 | SettingsData *data) |
1909 | { |
1910 | g_key_file_set_string (data->key_file, data->group_name, key, value); |
1911 | } |
1912 | |
1913 | /** |
1914 | * ctk_print_settings_to_key_file: |
1915 | * @settings: a #CtkPrintSettings |
1916 | * @key_file: the #GKeyFile to save the print settings to |
1917 | * @group_name: (nullable): the group to add the settings to in @key_file, or |
1918 | * %NULL to use the default “Print Settings” |
1919 | * |
1920 | * This function adds the print settings from @settings to @key_file. |
1921 | * |
1922 | * Since: 2.12 |
1923 | */ |
1924 | void |
1925 | ctk_print_settings_to_key_file (CtkPrintSettings *settings, |
1926 | GKeyFile *key_file, |
1927 | const gchar *group_name) |
1928 | { |
1929 | SettingsData data; |
1930 | |
1931 | g_return_if_fail (CTK_IS_PRINT_SETTINGS (settings))do { if (((((__extension__ ({ GTypeInstance *__inst = (GTypeInstance *) ((settings)); GType __t = ((ctk_print_settings_get_type () )); gboolean __r; if (!__inst) __r = (0); else if (__inst-> g_class && __inst->g_class->g_type == __t) __r = (!(0)); else __r = g_type_check_instance_is_a (__inst, __t); __r; })))))) { } else { g_return_if_fail_warning ("Ctk", ((const char*) (__func__)), "CTK_IS_PRINT_SETTINGS (settings)"); return ; } } while (0); |
1932 | g_return_if_fail (key_file != NULL)do { if ((key_file != ((void*)0))) { } else { g_return_if_fail_warning ("Ctk", ((const char*) (__func__)), "key_file != NULL"); return ; } } while (0); |
1933 | |
1934 | if (!group_name) |
1935 | group_name = KEYFILE_GROUP_NAME"Print Settings"; |
1936 | |
1937 | data.key_file = key_file; |
1938 | data.group_name = group_name; |
1939 | |
1940 | ctk_print_settings_foreach (settings, |
1941 | (CtkPrintSettingsFunc) add_value_to_key_file, |
1942 | &data); |
1943 | } |
1944 | |
1945 | static void |
1946 | add_to_variant (const gchar *key, |
1947 | const gchar *value, |
1948 | gpointer data) |
1949 | { |
1950 | GVariantBuilder *builder = data; |
1951 | g_variant_builder_add (builder, "{sv}", key, g_variant_new_string (value)); |
1952 | } |
1953 | |
1954 | /** |
1955 | * ctk_print_settings_to_gvariant: |
1956 | * @settings: a #CtkPrintSettings |
1957 | * |
1958 | * Serialize print settings to an a{sv} variant. |
1959 | * |
1960 | * Returns: (transfer none): a new, floating, #GVariant |
1961 | * |
1962 | * Since: 3.22 |
1963 | */ |
1964 | GVariant * |
1965 | ctk_print_settings_to_gvariant (CtkPrintSettings *settings) |
1966 | { |
1967 | GVariantBuilder builder; |
1968 | |
1969 | g_variant_builder_init (&builder, G_VARIANT_TYPE_VARDICT((const GVariantType *) "a{sv}")); |
1970 | ctk_print_settings_foreach (settings, add_to_variant, &builder); |
1971 | |
1972 | return g_variant_builder_end (&builder); |
1973 | } |
1974 | |
1975 | /** |
1976 | * ctk_print_settings_new_from_gvariant: |
1977 | * @variant: an a{sv} #GVariant |
1978 | * |
1979 | * Deserialize print settings from an a{sv} variant in |
1980 | * the format produced by ctk_print_settings_to_gvariant(). |
1981 | * |
1982 | * Returns: (transfer full): a new #CtkPrintSettings object |
1983 | * |
1984 | * Since: 3.22 |
1985 | */ |
1986 | CtkPrintSettings * |
1987 | ctk_print_settings_new_from_gvariant (GVariant *variant) |
1988 | { |
1989 | CtkPrintSettings *settings; |
1990 | int i; |
1991 | |
1992 | g_return_val_if_fail (g_variant_is_of_type (variant, G_VARIANT_TYPE_VARDICT), NULL)do { if ((g_variant_is_of_type (variant, ((const GVariantType *) "a{sv}")))) { } else { g_return_if_fail_warning ("Ctk", ( (const char*) (__func__)), "g_variant_is_of_type (variant, G_VARIANT_TYPE_VARDICT)" ); return (((void*)0)); } } while (0); |
1993 | |
1994 | settings = ctk_print_settings_new (); |
1995 | |
1996 | for (i = 0; i < g_variant_n_children (variant); i++) |
1997 | { |
1998 | const char *key; |
1999 | GVariant *v; |
2000 | |
2001 | g_variant_get_child (variant, i, "{&sv}", &key, &v); |
2002 | if (g_variant_is_of_type (v, G_VARIANT_TYPE_STRING((const GVariantType *) "s"))) |
Casting a non-structure type to a structure type and accessing a field can lead to memory access errors or data corruption | |
2003 | ctk_print_settings_set (settings, key, g_variant_get_string (v, NULL((void*)0))); |
2004 | g_variant_unref (v); |
2005 | } |
2006 | |
2007 | return settings; |
2008 | } |