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