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