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