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