Skip to main content

gtk/auto/
print_settings.rs

1// This file was generated by gir (https://github.com/gtk-rs/gir)
2// from gir-files (https://github.com/gtk-rs/gir-files)
3// DO NOT EDIT
4
5use crate::{
6    NumberUpLayout, PageOrientation, PageRange, PageSet, PaperSize, PrintDuplex, PrintPages,
7    PrintQuality, Unit,
8};
9use glib::translate::*;
10use std::{fmt, mem, ptr};
11
12glib::wrapper! {
13    /// A GtkPrintSettings object represents the settings of a print dialog in
14    /// a system-independent way. The main use for this object is that once
15    /// you’ve printed you can get a settings object that represents the settings
16    /// the user chose, and the next time you print you can pass that object in so
17    /// that the user doesn’t have to re-set all his settings.
18    ///
19    /// Its also possible to enumerate the settings so that you can easily save
20    /// the settings for the next time your app runs, or even store them in a
21    /// document. The predefined keys try to use shared values as much as possible
22    /// so that moving such a document between systems still works.
23    ///
24    /// Printing support was added in GTK+ 2.10.
25    ///
26    /// # Implements
27    ///
28    /// [`trait@glib::ObjectExt`]
29    #[doc(alias = "GtkPrintSettings")]
30    pub struct PrintSettings(Object<ffi::GtkPrintSettings>);
31
32    match fn {
33        type_ => || ffi::gtk_print_settings_get_type(),
34    }
35}
36
37impl PrintSettings {
38    /// Creates a new [`PrintSettings`][crate::PrintSettings] object.
39    ///
40    /// # Returns
41    ///
42    /// a new [`PrintSettings`][crate::PrintSettings] object
43    #[doc(alias = "gtk_print_settings_new")]
44    pub fn new() -> PrintSettings {
45        assert_initialized_main_thread!();
46        unsafe { from_glib_full(ffi::gtk_print_settings_new()) }
47    }
48
49    /// Reads the print settings from `file_name`. Returns a new [`PrintSettings`][crate::PrintSettings]
50    /// object with the restored settings, or [`None`] if an error occurred. If the
51    /// file could not be loaded then error is set to either a `GFileError` or
52    /// `GKeyFileError`. See [`to_file()`][Self::to_file()].
53    /// ## `file_name`
54    /// the filename to read the settings from
55    ///
56    /// # Returns
57    ///
58    /// the restored [`PrintSettings`][crate::PrintSettings]
59    #[doc(alias = "gtk_print_settings_new_from_file")]
60    #[doc(alias = "new_from_file")]
61    pub fn from_file(file_name: impl AsRef<std::path::Path>) -> Result<PrintSettings, glib::Error> {
62        assert_initialized_main_thread!();
63        unsafe {
64            let mut error = ptr::null_mut();
65            let ret = ffi::gtk_print_settings_new_from_file(
66                file_name.as_ref().to_glib_none().0,
67                &mut error,
68            );
69            if error.is_null() {
70                Ok(from_glib_full(ret))
71            } else {
72                Err(from_glib_full(error))
73            }
74        }
75    }
76
77    /// Deserialize print settings from an a{sv} variant in
78    /// the format produced by [`to_gvariant()`][Self::to_gvariant()].
79    /// ## `variant`
80    /// an a{sv} [`glib::Variant`][struct@crate::glib::Variant]
81    ///
82    /// # Returns
83    ///
84    /// a new [`PrintSettings`][crate::PrintSettings] object
85    #[doc(alias = "gtk_print_settings_new_from_gvariant")]
86    #[doc(alias = "new_from_gvariant")]
87    pub fn from_gvariant(variant: &glib::Variant) -> PrintSettings {
88        assert_initialized_main_thread!();
89        unsafe {
90            from_glib_full(ffi::gtk_print_settings_new_from_gvariant(
91                variant.to_glib_none().0,
92            ))
93        }
94    }
95
96    /// Reads the print settings from the group `group_name` in `key_file`. Returns a
97    /// new [`PrintSettings`][crate::PrintSettings] object with the restored settings, or [`None`] if an
98    /// error occurred. If the file could not be loaded then error is set to either
99    /// a `GFileError` or `GKeyFileError`.
100    /// ## `key_file`
101    /// the [`glib::KeyFile`][crate::glib::KeyFile] to retrieve the settings from
102    /// ## `group_name`
103    /// the name of the group to use, or [`None`] to use
104    ///  the default “Print Settings”
105    ///
106    /// # Returns
107    ///
108    /// the restored [`PrintSettings`][crate::PrintSettings]
109    #[doc(alias = "gtk_print_settings_new_from_key_file")]
110    #[doc(alias = "new_from_key_file")]
111    pub fn from_key_file(
112        key_file: &glib::KeyFile,
113        group_name: Option<&str>,
114    ) -> Result<PrintSettings, glib::Error> {
115        assert_initialized_main_thread!();
116        unsafe {
117            let mut error = ptr::null_mut();
118            let ret = ffi::gtk_print_settings_new_from_key_file(
119                key_file.to_glib_none().0,
120                group_name.to_glib_none().0,
121                &mut error,
122            );
123            if error.is_null() {
124                Ok(from_glib_full(ret))
125            } else {
126                Err(from_glib_full(error))
127            }
128        }
129    }
130
131    #[doc(alias = "gtk_print_settings_copy")]
132    #[must_use]
133    pub fn copy(&self) -> Option<PrintSettings> {
134        unsafe { from_glib_full(ffi::gtk_print_settings_copy(self.to_glib_none().0)) }
135    }
136
137    /// Calls `func` for each key-value pair of `self`.
138    /// ## `func`
139    /// the function to call
140    #[doc(alias = "gtk_print_settings_foreach")]
141    pub fn foreach<P: FnMut(&str, &str)>(&self, func: P) {
142        let func_data: P = func;
143        unsafe extern "C" fn func_func<P: FnMut(&str, &str)>(
144            key: *const libc::c_char,
145            value: *const libc::c_char,
146            user_data: glib::ffi::gpointer,
147        ) {
148            let key: Borrowed<glib::GString> = from_glib_borrow(key);
149            let value: Borrowed<glib::GString> = from_glib_borrow(value);
150            let callback: *mut P = user_data as *const _ as usize as *mut P;
151            (*callback)(key.as_str(), value.as_str())
152        }
153        let func = Some(func_func::<P> as _);
154        let super_callback0: &P = &func_data;
155        unsafe {
156            ffi::gtk_print_settings_foreach(
157                self.to_glib_none().0,
158                func,
159                super_callback0 as *const _ as usize as *mut _,
160            );
161        }
162    }
163
164    /// Looks up the string value associated with `key`.
165    /// ## `key`
166    /// a key
167    ///
168    /// # Returns
169    ///
170    /// the string value for `key`
171    #[doc(alias = "gtk_print_settings_get")]
172    pub fn get(&self, key: &str) -> Option<glib::GString> {
173        unsafe {
174            from_glib_none(ffi::gtk_print_settings_get(
175                self.to_glib_none().0,
176                key.to_glib_none().0,
177            ))
178        }
179    }
180
181    /// Returns the boolean represented by the value
182    /// that is associated with `key`.
183    ///
184    /// The string “true” represents [`true`], any other
185    /// string [`false`].
186    /// ## `key`
187    /// a key
188    ///
189    /// # Returns
190    ///
191    /// [`true`], if `key` maps to a true value.
192    #[doc(alias = "gtk_print_settings_get_bool")]
193    #[doc(alias = "get_bool")]
194    pub fn bool(&self, key: &str) -> bool {
195        unsafe {
196            from_glib(ffi::gtk_print_settings_get_bool(
197                self.to_glib_none().0,
198                key.to_glib_none().0,
199            ))
200        }
201    }
202
203    /// Gets the value of [`PRINT_SETTINGS_COLLATE`][crate::PRINT_SETTINGS_COLLATE].
204    ///
205    /// # Returns
206    ///
207    /// whether to collate the printed pages
208    #[doc(alias = "gtk_print_settings_get_collate")]
209    #[doc(alias = "get_collate")]
210    pub fn is_collate(&self) -> bool {
211        unsafe { from_glib(ffi::gtk_print_settings_get_collate(self.to_glib_none().0)) }
212    }
213
214    /// Gets the value of [`PRINT_SETTINGS_DEFAULT_SOURCE`][crate::PRINT_SETTINGS_DEFAULT_SOURCE].
215    ///
216    /// # Returns
217    ///
218    /// the default source
219    #[doc(alias = "gtk_print_settings_get_default_source")]
220    #[doc(alias = "get_default_source")]
221    pub fn default_source(&self) -> Option<glib::GString> {
222        unsafe {
223            from_glib_none(ffi::gtk_print_settings_get_default_source(
224                self.to_glib_none().0,
225            ))
226        }
227    }
228
229    /// Gets the value of [`PRINT_SETTINGS_DITHER`][crate::PRINT_SETTINGS_DITHER].
230    ///
231    /// # Returns
232    ///
233    /// the dithering that is used
234    #[doc(alias = "gtk_print_settings_get_dither")]
235    #[doc(alias = "get_dither")]
236    pub fn dither(&self) -> Option<glib::GString> {
237        unsafe { from_glib_none(ffi::gtk_print_settings_get_dither(self.to_glib_none().0)) }
238    }
239
240    /// Returns the double value associated with `key`, or 0.
241    /// ## `key`
242    /// a key
243    ///
244    /// # Returns
245    ///
246    /// the double value of `key`
247    #[doc(alias = "gtk_print_settings_get_double")]
248    #[doc(alias = "get_double")]
249    pub fn double(&self, key: &str) -> f64 {
250        unsafe { ffi::gtk_print_settings_get_double(self.to_glib_none().0, key.to_glib_none().0) }
251    }
252
253    /// Returns the floating point number represented by
254    /// the value that is associated with `key`, or `default_val`
255    /// if the value does not represent a floating point number.
256    ///
257    /// Floating point numbers are parsed with `g_ascii_strtod()`.
258    /// ## `key`
259    /// a key
260    /// ## `def`
261    /// the default value
262    ///
263    /// # Returns
264    ///
265    /// the floating point number associated with `key`
266    #[doc(alias = "gtk_print_settings_get_double_with_default")]
267    #[doc(alias = "get_double_with_default")]
268    pub fn double_with_default(&self, key: &str, def: f64) -> f64 {
269        unsafe {
270            ffi::gtk_print_settings_get_double_with_default(
271                self.to_glib_none().0,
272                key.to_glib_none().0,
273                def,
274            )
275        }
276    }
277
278    /// Gets the value of [`PRINT_SETTINGS_DUPLEX`][crate::PRINT_SETTINGS_DUPLEX].
279    ///
280    /// # Returns
281    ///
282    /// whether to print the output in duplex.
283    #[doc(alias = "gtk_print_settings_get_duplex")]
284    #[doc(alias = "get_duplex")]
285    pub fn duplex(&self) -> PrintDuplex {
286        unsafe { from_glib(ffi::gtk_print_settings_get_duplex(self.to_glib_none().0)) }
287    }
288
289    /// Gets the value of [`PRINT_SETTINGS_FINISHINGS`][crate::PRINT_SETTINGS_FINISHINGS].
290    ///
291    /// # Returns
292    ///
293    /// the finishings
294    #[doc(alias = "gtk_print_settings_get_finishings")]
295    #[doc(alias = "get_finishings")]
296    pub fn finishings(&self) -> Option<glib::GString> {
297        unsafe {
298            from_glib_none(ffi::gtk_print_settings_get_finishings(
299                self.to_glib_none().0,
300            ))
301        }
302    }
303
304    /// Returns the integer value of `key`, or 0.
305    /// ## `key`
306    /// a key
307    ///
308    /// # Returns
309    ///
310    /// the integer value of `key`
311    #[doc(alias = "gtk_print_settings_get_int")]
312    #[doc(alias = "get_int")]
313    pub fn int(&self, key: &str) -> i32 {
314        unsafe { ffi::gtk_print_settings_get_int(self.to_glib_none().0, key.to_glib_none().0) }
315    }
316
317    /// Returns the value of `key`, interpreted as
318    /// an integer, or the default value.
319    /// ## `key`
320    /// a key
321    /// ## `def`
322    /// the default value
323    ///
324    /// # Returns
325    ///
326    /// the integer value of `key`
327    #[doc(alias = "gtk_print_settings_get_int_with_default")]
328    #[doc(alias = "get_int_with_default")]
329    pub fn int_with_default(&self, key: &str, def: i32) -> i32 {
330        unsafe {
331            ffi::gtk_print_settings_get_int_with_default(
332                self.to_glib_none().0,
333                key.to_glib_none().0,
334                def,
335            )
336        }
337    }
338
339    /// Returns the value associated with `key`, interpreted
340    /// as a length. The returned value is converted to `units`.
341    /// ## `key`
342    /// a key
343    /// ## `unit`
344    /// the unit of the return value
345    ///
346    /// # Returns
347    ///
348    /// the length value of `key`, converted to `unit`
349    #[doc(alias = "gtk_print_settings_get_length")]
350    #[doc(alias = "get_length")]
351    pub fn length(&self, key: &str, unit: Unit) -> f64 {
352        unsafe {
353            ffi::gtk_print_settings_get_length(
354                self.to_glib_none().0,
355                key.to_glib_none().0,
356                unit.into_glib(),
357            )
358        }
359    }
360
361    /// Gets the value of [`PRINT_SETTINGS_MEDIA_TYPE`][crate::PRINT_SETTINGS_MEDIA_TYPE].
362    ///
363    /// The set of media types is defined in PWG 5101.1-2002 PWG.
364    ///
365    /// # Returns
366    ///
367    /// the media type
368    #[doc(alias = "gtk_print_settings_get_media_type")]
369    #[doc(alias = "get_media_type")]
370    pub fn media_type(&self) -> Option<glib::GString> {
371        unsafe {
372            from_glib_none(ffi::gtk_print_settings_get_media_type(
373                self.to_glib_none().0,
374            ))
375        }
376    }
377
378    /// Gets the value of [`PRINT_SETTINGS_N_COPIES`][crate::PRINT_SETTINGS_N_COPIES].
379    ///
380    /// # Returns
381    ///
382    /// the number of copies to print
383    #[doc(alias = "gtk_print_settings_get_n_copies")]
384    #[doc(alias = "get_n_copies")]
385    pub fn n_copies(&self) -> i32 {
386        unsafe { ffi::gtk_print_settings_get_n_copies(self.to_glib_none().0) }
387    }
388
389    /// Gets the value of [`PRINT_SETTINGS_NUMBER_UP`][crate::PRINT_SETTINGS_NUMBER_UP].
390    ///
391    /// # Returns
392    ///
393    /// the number of pages per sheet
394    #[doc(alias = "gtk_print_settings_get_number_up")]
395    #[doc(alias = "get_number_up")]
396    pub fn number_up(&self) -> i32 {
397        unsafe { ffi::gtk_print_settings_get_number_up(self.to_glib_none().0) }
398    }
399
400    /// Gets the value of [`PRINT_SETTINGS_NUMBER_UP_LAYOUT`][crate::PRINT_SETTINGS_NUMBER_UP_LAYOUT].
401    ///
402    /// # Returns
403    ///
404    /// layout of page in number-up mode
405    #[doc(alias = "gtk_print_settings_get_number_up_layout")]
406    #[doc(alias = "get_number_up_layout")]
407    pub fn number_up_layout(&self) -> NumberUpLayout {
408        unsafe {
409            from_glib(ffi::gtk_print_settings_get_number_up_layout(
410                self.to_glib_none().0,
411            ))
412        }
413    }
414
415    /// Get the value of [`PRINT_SETTINGS_ORIENTATION`][crate::PRINT_SETTINGS_ORIENTATION],
416    /// converted to a [`PageOrientation`][crate::PageOrientation].
417    ///
418    /// # Returns
419    ///
420    /// the orientation
421    #[doc(alias = "gtk_print_settings_get_orientation")]
422    #[doc(alias = "get_orientation")]
423    pub fn orientation(&self) -> PageOrientation {
424        unsafe {
425            from_glib(ffi::gtk_print_settings_get_orientation(
426                self.to_glib_none().0,
427            ))
428        }
429    }
430
431    /// Gets the value of [`PRINT_SETTINGS_OUTPUT_BIN`][crate::PRINT_SETTINGS_OUTPUT_BIN].
432    ///
433    /// # Returns
434    ///
435    /// the output bin
436    #[doc(alias = "gtk_print_settings_get_output_bin")]
437    #[doc(alias = "get_output_bin")]
438    pub fn output_bin(&self) -> Option<glib::GString> {
439        unsafe {
440            from_glib_none(ffi::gtk_print_settings_get_output_bin(
441                self.to_glib_none().0,
442            ))
443        }
444    }
445
446    /// Gets the value of [`PRINT_SETTINGS_PAGE_RANGES`][crate::PRINT_SETTINGS_PAGE_RANGES].
447    ///
448    /// # Returns
449    ///
450    /// an array
451    ///  of `GtkPageRanges`. Use `g_free()` to free the array when
452    ///  it is no longer needed.
453    #[doc(alias = "gtk_print_settings_get_page_ranges")]
454    #[doc(alias = "get_page_ranges")]
455    pub fn page_ranges(&self) -> Vec<PageRange> {
456        unsafe {
457            let mut num_ranges = mem::MaybeUninit::uninit();
458            let ret = FromGlibContainer::from_glib_full_num(
459                ffi::gtk_print_settings_get_page_ranges(
460                    self.to_glib_none().0,
461                    num_ranges.as_mut_ptr(),
462                ),
463                num_ranges.assume_init() as _,
464            );
465            ret
466        }
467    }
468
469    /// Gets the value of [`PRINT_SETTINGS_PAGE_SET`][crate::PRINT_SETTINGS_PAGE_SET].
470    ///
471    /// # Returns
472    ///
473    /// the set of pages to print
474    #[doc(alias = "gtk_print_settings_get_page_set")]
475    #[doc(alias = "get_page_set")]
476    pub fn page_set(&self) -> PageSet {
477        unsafe { from_glib(ffi::gtk_print_settings_get_page_set(self.to_glib_none().0)) }
478    }
479
480    /// Gets the value of [`PRINT_SETTINGS_PAPER_HEIGHT`][crate::PRINT_SETTINGS_PAPER_HEIGHT],
481    /// converted to `unit`.
482    /// ## `unit`
483    /// the unit for the return value
484    ///
485    /// # Returns
486    ///
487    /// the paper height, in units of `unit`
488    #[doc(alias = "gtk_print_settings_get_paper_height")]
489    #[doc(alias = "get_paper_height")]
490    pub fn paper_height(&self, unit: Unit) -> f64 {
491        unsafe { ffi::gtk_print_settings_get_paper_height(self.to_glib_none().0, unit.into_glib()) }
492    }
493
494    /// Gets the value of [`PRINT_SETTINGS_PAPER_FORMAT`][crate::PRINT_SETTINGS_PAPER_FORMAT],
495    /// converted to a [`PaperSize`][crate::PaperSize].
496    ///
497    /// # Returns
498    ///
499    /// the paper size
500    #[doc(alias = "gtk_print_settings_get_paper_size")]
501    #[doc(alias = "get_paper_size")]
502    pub fn paper_size(&self) -> PaperSize {
503        unsafe {
504            from_glib_full(ffi::gtk_print_settings_get_paper_size(
505                self.to_glib_none().0,
506            ))
507        }
508    }
509
510    /// Gets the value of [`PRINT_SETTINGS_PAPER_WIDTH`][crate::PRINT_SETTINGS_PAPER_WIDTH],
511    /// converted to `unit`.
512    /// ## `unit`
513    /// the unit for the return value
514    ///
515    /// # Returns
516    ///
517    /// the paper width, in units of `unit`
518    #[doc(alias = "gtk_print_settings_get_paper_width")]
519    #[doc(alias = "get_paper_width")]
520    pub fn paper_width(&self, unit: Unit) -> f64 {
521        unsafe { ffi::gtk_print_settings_get_paper_width(self.to_glib_none().0, unit.into_glib()) }
522    }
523
524    /// Gets the value of [`PRINT_SETTINGS_PRINT_PAGES`][crate::PRINT_SETTINGS_PRINT_PAGES].
525    ///
526    /// # Returns
527    ///
528    /// which pages to print
529    #[doc(alias = "gtk_print_settings_get_print_pages")]
530    #[doc(alias = "get_print_pages")]
531    pub fn print_pages(&self) -> PrintPages {
532        unsafe {
533            from_glib(ffi::gtk_print_settings_get_print_pages(
534                self.to_glib_none().0,
535            ))
536        }
537    }
538
539    /// Convenience function to obtain the value of
540    /// [`PRINT_SETTINGS_PRINTER`][crate::PRINT_SETTINGS_PRINTER].
541    ///
542    /// # Returns
543    ///
544    /// the printer name
545    #[doc(alias = "gtk_print_settings_get_printer")]
546    #[doc(alias = "get_printer")]
547    pub fn printer(&self) -> Option<glib::GString> {
548        unsafe { from_glib_none(ffi::gtk_print_settings_get_printer(self.to_glib_none().0)) }
549    }
550
551    /// Gets the value of [`PRINT_SETTINGS_PRINTER_LPI`][crate::PRINT_SETTINGS_PRINTER_LPI].
552    ///
553    /// # Returns
554    ///
555    /// the resolution in lpi (lines per inch)
556    #[doc(alias = "gtk_print_settings_get_printer_lpi")]
557    #[doc(alias = "get_printer_lpi")]
558    pub fn printer_lpi(&self) -> f64 {
559        unsafe { ffi::gtk_print_settings_get_printer_lpi(self.to_glib_none().0) }
560    }
561
562    /// Gets the value of [`PRINT_SETTINGS_QUALITY`][crate::PRINT_SETTINGS_QUALITY].
563    ///
564    /// # Returns
565    ///
566    /// the print quality
567    #[doc(alias = "gtk_print_settings_get_quality")]
568    #[doc(alias = "get_quality")]
569    pub fn quality(&self) -> PrintQuality {
570        unsafe { from_glib(ffi::gtk_print_settings_get_quality(self.to_glib_none().0)) }
571    }
572
573    /// Gets the value of [`PRINT_SETTINGS_RESOLUTION`][crate::PRINT_SETTINGS_RESOLUTION].
574    ///
575    /// # Returns
576    ///
577    /// the resolution in dpi
578    #[doc(alias = "gtk_print_settings_get_resolution")]
579    #[doc(alias = "get_resolution")]
580    pub fn resolution(&self) -> i32 {
581        unsafe { ffi::gtk_print_settings_get_resolution(self.to_glib_none().0) }
582    }
583
584    /// Gets the value of [`PRINT_SETTINGS_RESOLUTION_X`][crate::PRINT_SETTINGS_RESOLUTION_X].
585    ///
586    /// # Returns
587    ///
588    /// the horizontal resolution in dpi
589    #[doc(alias = "gtk_print_settings_get_resolution_x")]
590    #[doc(alias = "get_resolution_x")]
591    pub fn resolution_x(&self) -> i32 {
592        unsafe { ffi::gtk_print_settings_get_resolution_x(self.to_glib_none().0) }
593    }
594
595    /// Gets the value of [`PRINT_SETTINGS_RESOLUTION_Y`][crate::PRINT_SETTINGS_RESOLUTION_Y].
596    ///
597    /// # Returns
598    ///
599    /// the vertical resolution in dpi
600    #[doc(alias = "gtk_print_settings_get_resolution_y")]
601    #[doc(alias = "get_resolution_y")]
602    pub fn resolution_y(&self) -> i32 {
603        unsafe { ffi::gtk_print_settings_get_resolution_y(self.to_glib_none().0) }
604    }
605
606    /// Gets the value of [`PRINT_SETTINGS_REVERSE`][crate::PRINT_SETTINGS_REVERSE].
607    ///
608    /// # Returns
609    ///
610    /// whether to reverse the order of the printed pages
611    #[doc(alias = "gtk_print_settings_get_reverse")]
612    #[doc(alias = "get_reverse")]
613    pub fn is_reverse(&self) -> bool {
614        unsafe { from_glib(ffi::gtk_print_settings_get_reverse(self.to_glib_none().0)) }
615    }
616
617    /// Gets the value of [`PRINT_SETTINGS_SCALE`][crate::PRINT_SETTINGS_SCALE].
618    ///
619    /// # Returns
620    ///
621    /// the scale in percent
622    #[doc(alias = "gtk_print_settings_get_scale")]
623    #[doc(alias = "get_scale")]
624    pub fn scale(&self) -> f64 {
625        unsafe { ffi::gtk_print_settings_get_scale(self.to_glib_none().0) }
626    }
627
628    /// Gets the value of [`PRINT_SETTINGS_USE_COLOR`][crate::PRINT_SETTINGS_USE_COLOR].
629    ///
630    /// # Returns
631    ///
632    /// whether to use color
633    #[doc(alias = "gtk_print_settings_get_use_color")]
634    #[doc(alias = "get_use_color")]
635    pub fn uses_color(&self) -> bool {
636        unsafe { from_glib(ffi::gtk_print_settings_get_use_color(self.to_glib_none().0)) }
637    }
638
639    /// Returns [`true`], if a value is associated with `key`.
640    /// ## `key`
641    /// a key
642    ///
643    /// # Returns
644    ///
645    /// [`true`], if `key` has a value
646    #[doc(alias = "gtk_print_settings_has_key")]
647    pub fn has_key(&self, key: &str) -> bool {
648        unsafe {
649            from_glib(ffi::gtk_print_settings_has_key(
650                self.to_glib_none().0,
651                key.to_glib_none().0,
652            ))
653        }
654    }
655
656    /// Reads the print settings from `file_name`. If the file could not be loaded
657    /// then error is set to either a `GFileError` or `GKeyFileError`.
658    /// See [`to_file()`][Self::to_file()].
659    /// ## `file_name`
660    /// the filename to read the settings from
661    ///
662    /// # Returns
663    ///
664    /// [`true`] on success
665    #[doc(alias = "gtk_print_settings_load_file")]
666    pub fn load_file(&self, file_name: impl AsRef<std::path::Path>) -> Result<(), glib::Error> {
667        unsafe {
668            let mut error = ptr::null_mut();
669            let is_ok = ffi::gtk_print_settings_load_file(
670                self.to_glib_none().0,
671                file_name.as_ref().to_glib_none().0,
672                &mut error,
673            );
674            debug_assert_eq!(is_ok == glib::ffi::GFALSE, !error.is_null());
675            if error.is_null() {
676                Ok(())
677            } else {
678                Err(from_glib_full(error))
679            }
680        }
681    }
682
683    /// Reads the print settings from the group `group_name` in `key_file`. If the
684    /// file could not be loaded then error is set to either a `GFileError` or
685    /// `GKeyFileError`.
686    /// ## `key_file`
687    /// the [`glib::KeyFile`][crate::glib::KeyFile] to retrieve the settings from
688    /// ## `group_name`
689    /// the name of the group to use, or [`None`] to use the default
690    ///  “Print Settings”
691    ///
692    /// # Returns
693    ///
694    /// [`true`] on success
695    #[doc(alias = "gtk_print_settings_load_key_file")]
696    pub fn load_key_file(
697        &self,
698        key_file: &glib::KeyFile,
699        group_name: Option<&str>,
700    ) -> Result<(), glib::Error> {
701        unsafe {
702            let mut error = ptr::null_mut();
703            let is_ok = ffi::gtk_print_settings_load_key_file(
704                self.to_glib_none().0,
705                key_file.to_glib_none().0,
706                group_name.to_glib_none().0,
707                &mut error,
708            );
709            debug_assert_eq!(is_ok == glib::ffi::GFALSE, !error.is_null());
710            if error.is_null() {
711                Ok(())
712            } else {
713                Err(from_glib_full(error))
714            }
715        }
716    }
717
718    /// Associates `value` with `key`.
719    /// ## `key`
720    /// a key
721    /// ## `value`
722    /// a string value, or [`None`]
723    #[doc(alias = "gtk_print_settings_set")]
724    pub fn set(&self, key: &str, value: Option<&str>) {
725        unsafe {
726            ffi::gtk_print_settings_set(
727                self.to_glib_none().0,
728                key.to_glib_none().0,
729                value.to_glib_none().0,
730            );
731        }
732    }
733
734    /// Sets `key` to a boolean value.
735    /// ## `key`
736    /// a key
737    /// ## `value`
738    /// a boolean
739    #[doc(alias = "gtk_print_settings_set_bool")]
740    pub fn set_bool(&self, key: &str, value: bool) {
741        unsafe {
742            ffi::gtk_print_settings_set_bool(
743                self.to_glib_none().0,
744                key.to_glib_none().0,
745                value.into_glib(),
746            );
747        }
748    }
749
750    /// Sets the value of [`PRINT_SETTINGS_COLLATE`][crate::PRINT_SETTINGS_COLLATE].
751    /// ## `collate`
752    /// whether to collate the output
753    #[doc(alias = "gtk_print_settings_set_collate")]
754    pub fn set_collate(&self, collate: bool) {
755        unsafe {
756            ffi::gtk_print_settings_set_collate(self.to_glib_none().0, collate.into_glib());
757        }
758    }
759
760    /// Sets the value of [`PRINT_SETTINGS_DEFAULT_SOURCE`][crate::PRINT_SETTINGS_DEFAULT_SOURCE].
761    /// ## `default_source`
762    /// the default source
763    #[doc(alias = "gtk_print_settings_set_default_source")]
764    pub fn set_default_source(&self, default_source: &str) {
765        unsafe {
766            ffi::gtk_print_settings_set_default_source(
767                self.to_glib_none().0,
768                default_source.to_glib_none().0,
769            );
770        }
771    }
772
773    /// Sets the value of [`PRINT_SETTINGS_DITHER`][crate::PRINT_SETTINGS_DITHER].
774    /// ## `dither`
775    /// the dithering that is used
776    #[doc(alias = "gtk_print_settings_set_dither")]
777    pub fn set_dither(&self, dither: &str) {
778        unsafe {
779            ffi::gtk_print_settings_set_dither(self.to_glib_none().0, dither.to_glib_none().0);
780        }
781    }
782
783    /// Sets `key` to a double value.
784    /// ## `key`
785    /// a key
786    /// ## `value`
787    /// a double value
788    #[doc(alias = "gtk_print_settings_set_double")]
789    pub fn set_double(&self, key: &str, value: f64) {
790        unsafe {
791            ffi::gtk_print_settings_set_double(self.to_glib_none().0, key.to_glib_none().0, value);
792        }
793    }
794
795    /// Sets the value of [`PRINT_SETTINGS_DUPLEX`][crate::PRINT_SETTINGS_DUPLEX].
796    /// ## `duplex`
797    /// a [`PrintDuplex`][crate::PrintDuplex] value
798    #[doc(alias = "gtk_print_settings_set_duplex")]
799    pub fn set_duplex(&self, duplex: PrintDuplex) {
800        unsafe {
801            ffi::gtk_print_settings_set_duplex(self.to_glib_none().0, duplex.into_glib());
802        }
803    }
804
805    /// Sets the value of [`PRINT_SETTINGS_FINISHINGS`][crate::PRINT_SETTINGS_FINISHINGS].
806    /// ## `finishings`
807    /// the finishings
808    #[doc(alias = "gtk_print_settings_set_finishings")]
809    pub fn set_finishings(&self, finishings: &str) {
810        unsafe {
811            ffi::gtk_print_settings_set_finishings(
812                self.to_glib_none().0,
813                finishings.to_glib_none().0,
814            );
815        }
816    }
817
818    /// Sets `key` to an integer value.
819    /// ## `key`
820    /// a key
821    /// ## `value`
822    /// an integer
823    #[doc(alias = "gtk_print_settings_set_int")]
824    pub fn set_int(&self, key: &str, value: i32) {
825        unsafe {
826            ffi::gtk_print_settings_set_int(self.to_glib_none().0, key.to_glib_none().0, value);
827        }
828    }
829
830    /// Associates a length in units of `unit` with `key`.
831    /// ## `key`
832    /// a key
833    /// ## `value`
834    /// a length
835    /// ## `unit`
836    /// the unit of `length`
837    #[doc(alias = "gtk_print_settings_set_length")]
838    pub fn set_length(&self, key: &str, value: f64, unit: Unit) {
839        unsafe {
840            ffi::gtk_print_settings_set_length(
841                self.to_glib_none().0,
842                key.to_glib_none().0,
843                value,
844                unit.into_glib(),
845            );
846        }
847    }
848
849    /// Sets the value of [`PRINT_SETTINGS_MEDIA_TYPE`][crate::PRINT_SETTINGS_MEDIA_TYPE].
850    ///
851    /// The set of media types is defined in PWG 5101.1-2002 PWG.
852    /// ## `media_type`
853    /// the media type
854    #[doc(alias = "gtk_print_settings_set_media_type")]
855    pub fn set_media_type(&self, media_type: &str) {
856        unsafe {
857            ffi::gtk_print_settings_set_media_type(
858                self.to_glib_none().0,
859                media_type.to_glib_none().0,
860            );
861        }
862    }
863
864    /// Sets the value of [`PRINT_SETTINGS_N_COPIES`][crate::PRINT_SETTINGS_N_COPIES].
865    /// ## `num_copies`
866    /// the number of copies
867    #[doc(alias = "gtk_print_settings_set_n_copies")]
868    pub fn set_n_copies(&self, num_copies: i32) {
869        unsafe {
870            ffi::gtk_print_settings_set_n_copies(self.to_glib_none().0, num_copies);
871        }
872    }
873
874    /// Sets the value of [`PRINT_SETTINGS_NUMBER_UP`][crate::PRINT_SETTINGS_NUMBER_UP].
875    /// ## `number_up`
876    /// the number of pages per sheet
877    #[doc(alias = "gtk_print_settings_set_number_up")]
878    pub fn set_number_up(&self, number_up: i32) {
879        unsafe {
880            ffi::gtk_print_settings_set_number_up(self.to_glib_none().0, number_up);
881        }
882    }
883
884    /// Sets the value of [`PRINT_SETTINGS_NUMBER_UP_LAYOUT`][crate::PRINT_SETTINGS_NUMBER_UP_LAYOUT].
885    /// ## `number_up_layout`
886    /// a [`NumberUpLayout`][crate::NumberUpLayout] value
887    #[doc(alias = "gtk_print_settings_set_number_up_layout")]
888    pub fn set_number_up_layout(&self, number_up_layout: NumberUpLayout) {
889        unsafe {
890            ffi::gtk_print_settings_set_number_up_layout(
891                self.to_glib_none().0,
892                number_up_layout.into_glib(),
893            );
894        }
895    }
896
897    /// Sets the value of [`PRINT_SETTINGS_ORIENTATION`][crate::PRINT_SETTINGS_ORIENTATION].
898    /// ## `orientation`
899    /// a page orientation
900    #[doc(alias = "gtk_print_settings_set_orientation")]
901    pub fn set_orientation(&self, orientation: PageOrientation) {
902        unsafe {
903            ffi::gtk_print_settings_set_orientation(self.to_glib_none().0, orientation.into_glib());
904        }
905    }
906
907    /// Sets the value of [`PRINT_SETTINGS_OUTPUT_BIN`][crate::PRINT_SETTINGS_OUTPUT_BIN].
908    /// ## `output_bin`
909    /// the output bin
910    #[doc(alias = "gtk_print_settings_set_output_bin")]
911    pub fn set_output_bin(&self, output_bin: &str) {
912        unsafe {
913            ffi::gtk_print_settings_set_output_bin(
914                self.to_glib_none().0,
915                output_bin.to_glib_none().0,
916            );
917        }
918    }
919
920    /// Sets the value of [`PRINT_SETTINGS_PAGE_SET`][crate::PRINT_SETTINGS_PAGE_SET].
921    /// ## `page_set`
922    /// a [`PageSet`][crate::PageSet] value
923    #[doc(alias = "gtk_print_settings_set_page_set")]
924    pub fn set_page_set(&self, page_set: PageSet) {
925        unsafe {
926            ffi::gtk_print_settings_set_page_set(self.to_glib_none().0, page_set.into_glib());
927        }
928    }
929
930    /// Sets the value of [`PRINT_SETTINGS_PAPER_HEIGHT`][crate::PRINT_SETTINGS_PAPER_HEIGHT].
931    /// ## `height`
932    /// the paper height
933    /// ## `unit`
934    /// the units of `height`
935    #[doc(alias = "gtk_print_settings_set_paper_height")]
936    pub fn set_paper_height(&self, height: f64, unit: Unit) {
937        unsafe {
938            ffi::gtk_print_settings_set_paper_height(
939                self.to_glib_none().0,
940                height,
941                unit.into_glib(),
942            );
943        }
944    }
945
946    /// Sets the value of [`PRINT_SETTINGS_PAPER_FORMAT`][crate::PRINT_SETTINGS_PAPER_FORMAT],
947    /// [`PRINT_SETTINGS_PAPER_WIDTH`][crate::PRINT_SETTINGS_PAPER_WIDTH] and
948    /// [`PRINT_SETTINGS_PAPER_HEIGHT`][crate::PRINT_SETTINGS_PAPER_HEIGHT].
949    /// ## `paper_size`
950    /// a paper size
951    #[doc(alias = "gtk_print_settings_set_paper_size")]
952    pub fn set_paper_size(&self, paper_size: &PaperSize) {
953        unsafe {
954            ffi::gtk_print_settings_set_paper_size(
955                self.to_glib_none().0,
956                mut_override(paper_size.to_glib_none().0),
957            );
958        }
959    }
960
961    /// Sets the value of [`PRINT_SETTINGS_PAPER_WIDTH`][crate::PRINT_SETTINGS_PAPER_WIDTH].
962    /// ## `width`
963    /// the paper width
964    /// ## `unit`
965    /// the units of `width`
966    #[doc(alias = "gtk_print_settings_set_paper_width")]
967    pub fn set_paper_width(&self, width: f64, unit: Unit) {
968        unsafe {
969            ffi::gtk_print_settings_set_paper_width(self.to_glib_none().0, width, unit.into_glib());
970        }
971    }
972
973    /// Sets the value of [`PRINT_SETTINGS_PRINT_PAGES`][crate::PRINT_SETTINGS_PRINT_PAGES].
974    /// ## `pages`
975    /// a [`PrintPages`][crate::PrintPages] value
976    #[doc(alias = "gtk_print_settings_set_print_pages")]
977    pub fn set_print_pages(&self, pages: PrintPages) {
978        unsafe {
979            ffi::gtk_print_settings_set_print_pages(self.to_glib_none().0, pages.into_glib());
980        }
981    }
982
983    /// Convenience function to set [`PRINT_SETTINGS_PRINTER`][crate::PRINT_SETTINGS_PRINTER]
984    /// to `printer`.
985    /// ## `printer`
986    /// the printer name
987    #[doc(alias = "gtk_print_settings_set_printer")]
988    pub fn set_printer(&self, printer: &str) {
989        unsafe {
990            ffi::gtk_print_settings_set_printer(self.to_glib_none().0, printer.to_glib_none().0);
991        }
992    }
993
994    /// Sets the value of [`PRINT_SETTINGS_PRINTER_LPI`][crate::PRINT_SETTINGS_PRINTER_LPI].
995    /// ## `lpi`
996    /// the resolution in lpi (lines per inch)
997    #[doc(alias = "gtk_print_settings_set_printer_lpi")]
998    pub fn set_printer_lpi(&self, lpi: f64) {
999        unsafe {
1000            ffi::gtk_print_settings_set_printer_lpi(self.to_glib_none().0, lpi);
1001        }
1002    }
1003
1004    /// Sets the value of [`PRINT_SETTINGS_QUALITY`][crate::PRINT_SETTINGS_QUALITY].
1005    /// ## `quality`
1006    /// a [`PrintQuality`][crate::PrintQuality] value
1007    #[doc(alias = "gtk_print_settings_set_quality")]
1008    pub fn set_quality(&self, quality: PrintQuality) {
1009        unsafe {
1010            ffi::gtk_print_settings_set_quality(self.to_glib_none().0, quality.into_glib());
1011        }
1012    }
1013
1014    /// Sets the values of [`PRINT_SETTINGS_RESOLUTION`][crate::PRINT_SETTINGS_RESOLUTION],
1015    /// [`PRINT_SETTINGS_RESOLUTION_X`][crate::PRINT_SETTINGS_RESOLUTION_X] and
1016    /// [`PRINT_SETTINGS_RESOLUTION_Y`][crate::PRINT_SETTINGS_RESOLUTION_Y].
1017    /// ## `resolution`
1018    /// the resolution in dpi
1019    #[doc(alias = "gtk_print_settings_set_resolution")]
1020    pub fn set_resolution(&self, resolution: i32) {
1021        unsafe {
1022            ffi::gtk_print_settings_set_resolution(self.to_glib_none().0, resolution);
1023        }
1024    }
1025
1026    /// Sets the values of [`PRINT_SETTINGS_RESOLUTION`][crate::PRINT_SETTINGS_RESOLUTION],
1027    /// [`PRINT_SETTINGS_RESOLUTION_X`][crate::PRINT_SETTINGS_RESOLUTION_X] and
1028    /// [`PRINT_SETTINGS_RESOLUTION_Y`][crate::PRINT_SETTINGS_RESOLUTION_Y].
1029    /// ## `resolution_x`
1030    /// the horizontal resolution in dpi
1031    /// ## `resolution_y`
1032    /// the vertical resolution in dpi
1033    #[doc(alias = "gtk_print_settings_set_resolution_xy")]
1034    pub fn set_resolution_xy(&self, resolution_x: i32, resolution_y: i32) {
1035        unsafe {
1036            ffi::gtk_print_settings_set_resolution_xy(
1037                self.to_glib_none().0,
1038                resolution_x,
1039                resolution_y,
1040            );
1041        }
1042    }
1043
1044    /// Sets the value of [`PRINT_SETTINGS_REVERSE`][crate::PRINT_SETTINGS_REVERSE].
1045    /// ## `reverse`
1046    /// whether to reverse the output
1047    #[doc(alias = "gtk_print_settings_set_reverse")]
1048    pub fn set_reverse(&self, reverse: bool) {
1049        unsafe {
1050            ffi::gtk_print_settings_set_reverse(self.to_glib_none().0, reverse.into_glib());
1051        }
1052    }
1053
1054    /// Sets the value of [`PRINT_SETTINGS_SCALE`][crate::PRINT_SETTINGS_SCALE].
1055    /// ## `scale`
1056    /// the scale in percent
1057    #[doc(alias = "gtk_print_settings_set_scale")]
1058    pub fn set_scale(&self, scale: f64) {
1059        unsafe {
1060            ffi::gtk_print_settings_set_scale(self.to_glib_none().0, scale);
1061        }
1062    }
1063
1064    /// Sets the value of [`PRINT_SETTINGS_USE_COLOR`][crate::PRINT_SETTINGS_USE_COLOR].
1065    /// ## `use_color`
1066    /// whether to use color
1067    #[doc(alias = "gtk_print_settings_set_use_color")]
1068    pub fn set_use_color(&self, use_color: bool) {
1069        unsafe {
1070            ffi::gtk_print_settings_set_use_color(self.to_glib_none().0, use_color.into_glib());
1071        }
1072    }
1073
1074    /// This function saves the print settings from `self` to `file_name`. If the
1075    /// file could not be loaded then error is set to either a `GFileError` or
1076    /// `GKeyFileError`.
1077    /// ## `file_name`
1078    /// the file to save to
1079    ///
1080    /// # Returns
1081    ///
1082    /// [`true`] on success
1083    #[doc(alias = "gtk_print_settings_to_file")]
1084    pub fn to_file(&self, file_name: impl AsRef<std::path::Path>) -> Result<(), glib::Error> {
1085        unsafe {
1086            let mut error = ptr::null_mut();
1087            let is_ok = ffi::gtk_print_settings_to_file(
1088                self.to_glib_none().0,
1089                file_name.as_ref().to_glib_none().0,
1090                &mut error,
1091            );
1092            debug_assert_eq!(is_ok == glib::ffi::GFALSE, !error.is_null());
1093            if error.is_null() {
1094                Ok(())
1095            } else {
1096                Err(from_glib_full(error))
1097            }
1098        }
1099    }
1100
1101    /// Serialize print settings to an a{sv} variant.
1102    ///
1103    /// # Returns
1104    ///
1105    /// a new, floating, [`glib::Variant`][struct@crate::glib::Variant]
1106    #[doc(alias = "gtk_print_settings_to_gvariant")]
1107    pub fn to_gvariant(&self) -> Option<glib::Variant> {
1108        unsafe { from_glib_none(ffi::gtk_print_settings_to_gvariant(self.to_glib_none().0)) }
1109    }
1110
1111    /// This function adds the print settings from `self` to `key_file`.
1112    /// ## `key_file`
1113    /// the [`glib::KeyFile`][crate::glib::KeyFile] to save the print settings to
1114    /// ## `group_name`
1115    /// the group to add the settings to in `key_file`, or
1116    ///  [`None`] to use the default “Print Settings”
1117    #[doc(alias = "gtk_print_settings_to_key_file")]
1118    pub fn to_key_file(&self, key_file: &glib::KeyFile, group_name: Option<&str>) {
1119        unsafe {
1120            ffi::gtk_print_settings_to_key_file(
1121                self.to_glib_none().0,
1122                key_file.to_glib_none().0,
1123                group_name.to_glib_none().0,
1124            );
1125        }
1126    }
1127
1128    /// Removes any value associated with `key`.
1129    /// This has the same effect as setting the value to [`None`].
1130    /// ## `key`
1131    /// a key
1132    #[doc(alias = "gtk_print_settings_unset")]
1133    pub fn unset(&self, key: &str) {
1134        unsafe {
1135            ffi::gtk_print_settings_unset(self.to_glib_none().0, key.to_glib_none().0);
1136        }
1137    }
1138}
1139
1140impl Default for PrintSettings {
1141    fn default() -> Self {
1142        Self::new()
1143    }
1144}
1145
1146impl fmt::Display for PrintSettings {
1147    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
1148        f.write_str("PrintSettings")
1149    }
1150}