gtk4/auto/
printer.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::{ffi, PageSetup, PaperSize, PrintCapabilities};
6use glib::{
7    object::ObjectType as _,
8    prelude::*,
9    signal::{connect_raw, SignalHandlerId},
10    translate::*,
11};
12use std::boxed::Box as Box_;
13
14glib::wrapper! {
15    /// A [`Printer`][crate::Printer] object represents a printer.
16    ///
17    /// You only need to deal directly with printers if you use the
18    /// non-portable [`PrintUnixDialog`][crate::PrintUnixDialog] API.
19    ///
20    /// A [`Printer`][crate::Printer] allows to get status information about the printer,
21    /// such as its description, its location, the number of queued jobs,
22    /// etc. Most importantly, a [`Printer`][crate::Printer] object can be used to create
23    /// a [`PrintJob`][crate::PrintJob] object, which lets you print to the printer.
24    ///
25    /// ## Properties
26    ///
27    ///
28    /// #### `accepting-jobs`
29    ///  [`true`] if the printer is accepting jobs.
30    ///
31    /// Readable
32    ///
33    ///
34    /// #### `accepts-pdf`
35    ///  [`true`] if this printer can accept PDF.
36    ///
37    /// Readable | Writeable | Construct Only
38    ///
39    ///
40    /// #### `accepts-ps`
41    ///  [`true`] if this printer can accept PostScript.
42    ///
43    /// Readable | Writeable | Construct Only
44    ///
45    ///
46    /// #### `icon-name`
47    ///  Icon name to use for the printer.
48    ///
49    /// Readable
50    ///
51    ///
52    /// #### `is-virtual`
53    ///  [`false`] if this represents a real hardware device.
54    ///
55    /// Readable | Writeable | Construct Only
56    ///
57    ///
58    /// #### `job-count`
59    ///  Number of jobs queued in the printer.
60    ///
61    /// Readable
62    ///
63    ///
64    /// #### `location`
65    ///  Information about the location of the printer.
66    ///
67    /// Readable
68    ///
69    ///
70    /// #### `name`
71    ///  The name of the printer.
72    ///
73    /// Readable | Writeable | Construct Only
74    ///
75    ///
76    /// #### `paused`
77    ///  [`true`] if this printer is paused.
78    ///
79    /// A paused printer still accepts jobs, but it does
80    /// not print them.
81    ///
82    /// Readable
83    ///
84    ///
85    /// #### `state-message`
86    ///  String giving the current status of the printer.
87    ///
88    /// Readable
89    ///
90    /// ## Signals
91    ///
92    ///
93    /// #### `details-acquired`
94    ///  Emitted in response to a request for detailed information
95    /// about a printer from the print backend.
96    ///
97    /// The @success parameter indicates if the information was
98    /// actually obtained.
99    ///
100    ///
101    ///
102    /// # Implements
103    ///
104    /// [`trait@glib::ObjectExt`]
105    #[doc(alias = "GtkPrinter")]
106    pub struct Printer(Object<ffi::GtkPrinter>);
107
108    match fn {
109        type_ => || ffi::gtk_printer_get_type(),
110    }
111}
112
113impl Printer {
114    /// Returns whether the printer accepts input in
115    /// PDF format.
116    ///
117    /// # Returns
118    ///
119    /// [`true`] if @self accepts PDF
120    #[doc(alias = "gtk_printer_accepts_pdf")]
121    #[doc(alias = "accepts-pdf")]
122    pub fn accepts_pdf(&self) -> bool {
123        unsafe { from_glib(ffi::gtk_printer_accepts_pdf(self.to_glib_none().0)) }
124    }
125
126    /// Returns whether the printer accepts input in
127    /// PostScript format.
128    ///
129    /// # Returns
130    ///
131    /// [`true`] if @self accepts PostScript
132    #[doc(alias = "gtk_printer_accepts_ps")]
133    #[doc(alias = "accepts-ps")]
134    pub fn accepts_ps(&self) -> bool {
135        unsafe { from_glib(ffi::gtk_printer_accepts_ps(self.to_glib_none().0)) }
136    }
137
138    #[doc(alias = "gtk_printer_compare")]
139    pub fn compare(&self, b: &Printer) -> i32 {
140        unsafe { ffi::gtk_printer_compare(self.to_glib_none().0, b.to_glib_none().0) }
141    }
142
143    /// Returns the printer’s capabilities.
144    ///
145    /// This is useful when you’re using [`PrintUnixDialog`][crate::PrintUnixDialog]’s
146    /// manual-capabilities setting and need to know which settings
147    /// the printer can handle and which you must handle yourself.
148    ///
149    /// This will return 0 unless the printer’s details are
150    /// available, see [`has_details()`][Self::has_details()] and
151    /// [`request_details()`][Self::request_details()].
152    ///
153    /// # Returns
154    ///
155    /// the printer’s capabilities
156    #[doc(alias = "gtk_printer_get_capabilities")]
157    #[doc(alias = "get_capabilities")]
158    pub fn capabilities(&self) -> PrintCapabilities {
159        unsafe { from_glib(ffi::gtk_printer_get_capabilities(self.to_glib_none().0)) }
160    }
161
162    /// Returns default page size of @self.
163    ///
164    /// # Returns
165    ///
166    /// a newly allocated [`PageSetup`][crate::PageSetup] with default page size
167    ///   of the printer.
168    #[doc(alias = "gtk_printer_get_default_page_size")]
169    #[doc(alias = "get_default_page_size")]
170    pub fn default_page_size(&self) -> PageSetup {
171        unsafe {
172            from_glib_full(ffi::gtk_printer_get_default_page_size(
173                self.to_glib_none().0,
174            ))
175        }
176    }
177
178    /// Gets the description of the printer.
179    ///
180    /// # Returns
181    ///
182    /// the description of @self
183    #[doc(alias = "gtk_printer_get_description")]
184    #[doc(alias = "get_description")]
185    pub fn description(&self) -> glib::GString {
186        unsafe { from_glib_none(ffi::gtk_printer_get_description(self.to_glib_none().0)) }
187    }
188
189    /// Retrieve the hard margins of @self.
190    ///
191    /// These are the margins that define the area at the borders
192    /// of the paper that the printer cannot print to.
193    ///
194    /// Note: This will not succeed unless the printer’s details are
195    /// available, see [`has_details()`][Self::has_details()] and
196    /// [`request_details()`][Self::request_details()].
197    ///
198    /// # Returns
199    ///
200    /// [`true`] iff the hard margins were retrieved
201    ///
202    /// ## `top`
203    /// a location to store the top margin in
204    ///
205    /// ## `bottom`
206    /// a location to store the bottom margin in
207    ///
208    /// ## `left`
209    /// a location to store the left margin in
210    ///
211    /// ## `right`
212    /// a location to store the right margin in
213    #[doc(alias = "gtk_printer_get_hard_margins")]
214    #[doc(alias = "get_hard_margins")]
215    pub fn hard_margins(&self) -> Option<(f64, f64, f64, f64)> {
216        unsafe {
217            let mut top = std::mem::MaybeUninit::uninit();
218            let mut bottom = std::mem::MaybeUninit::uninit();
219            let mut left = std::mem::MaybeUninit::uninit();
220            let mut right = std::mem::MaybeUninit::uninit();
221            let ret = from_glib(ffi::gtk_printer_get_hard_margins(
222                self.to_glib_none().0,
223                top.as_mut_ptr(),
224                bottom.as_mut_ptr(),
225                left.as_mut_ptr(),
226                right.as_mut_ptr(),
227            ));
228            if ret {
229                Some((
230                    top.assume_init(),
231                    bottom.assume_init(),
232                    left.assume_init(),
233                    right.assume_init(),
234                ))
235            } else {
236                None
237            }
238        }
239    }
240
241    /// Retrieve the hard margins of @self for @paper_size.
242    ///
243    /// These are the margins that define the area at the borders
244    /// of the paper that the printer cannot print to.
245    ///
246    /// Note: This will not succeed unless the printer’s details are
247    /// available, see [`has_details()`][Self::has_details()] and
248    /// [`request_details()`][Self::request_details()].
249    /// ## `paper_size`
250    /// a [`PaperSize`][crate::PaperSize]
251    ///
252    /// # Returns
253    ///
254    /// [`true`] iff the hard margins were retrieved
255    ///
256    /// ## `top`
257    /// a location to store the top margin in
258    ///
259    /// ## `bottom`
260    /// a location to store the bottom margin in
261    ///
262    /// ## `left`
263    /// a location to store the left margin in
264    ///
265    /// ## `right`
266    /// a location to store the right margin in
267    #[doc(alias = "gtk_printer_get_hard_margins_for_paper_size")]
268    #[doc(alias = "get_hard_margins_for_paper_size")]
269    pub fn hard_margins_for_paper_size(
270        &self,
271        paper_size: &mut PaperSize,
272    ) -> Option<(f64, f64, f64, f64)> {
273        unsafe {
274            let mut top = std::mem::MaybeUninit::uninit();
275            let mut bottom = std::mem::MaybeUninit::uninit();
276            let mut left = std::mem::MaybeUninit::uninit();
277            let mut right = std::mem::MaybeUninit::uninit();
278            let ret = from_glib(ffi::gtk_printer_get_hard_margins_for_paper_size(
279                self.to_glib_none().0,
280                paper_size.to_glib_none_mut().0,
281                top.as_mut_ptr(),
282                bottom.as_mut_ptr(),
283                left.as_mut_ptr(),
284                right.as_mut_ptr(),
285            ));
286            if ret {
287                Some((
288                    top.assume_init(),
289                    bottom.assume_init(),
290                    left.assume_init(),
291                    right.assume_init(),
292                ))
293            } else {
294                None
295            }
296        }
297    }
298
299    /// Gets the name of the icon to use for the printer.
300    ///
301    /// # Returns
302    ///
303    /// the icon name for @self
304    #[doc(alias = "gtk_printer_get_icon_name")]
305    #[doc(alias = "get_icon_name")]
306    #[doc(alias = "icon-name")]
307    pub fn icon_name(&self) -> glib::GString {
308        unsafe { from_glib_none(ffi::gtk_printer_get_icon_name(self.to_glib_none().0)) }
309    }
310
311    /// Gets the number of jobs currently queued on the printer.
312    ///
313    /// # Returns
314    ///
315    /// the number of jobs on @self
316    #[doc(alias = "gtk_printer_get_job_count")]
317    #[doc(alias = "get_job_count")]
318    #[doc(alias = "job-count")]
319    pub fn job_count(&self) -> i32 {
320        unsafe { ffi::gtk_printer_get_job_count(self.to_glib_none().0) }
321    }
322
323    /// Returns a description of the location of the printer.
324    ///
325    /// # Returns
326    ///
327    /// the location of @self
328    #[doc(alias = "gtk_printer_get_location")]
329    #[doc(alias = "get_location")]
330    pub fn location(&self) -> glib::GString {
331        unsafe { from_glib_none(ffi::gtk_printer_get_location(self.to_glib_none().0)) }
332    }
333
334    /// Returns the name of the printer.
335    ///
336    /// # Returns
337    ///
338    /// the name of @self
339    #[doc(alias = "gtk_printer_get_name")]
340    #[doc(alias = "get_name")]
341    pub fn name(&self) -> glib::GString {
342        unsafe { from_glib_none(ffi::gtk_printer_get_name(self.to_glib_none().0)) }
343    }
344
345    /// Returns the state message describing the current state
346    /// of the printer.
347    ///
348    /// # Returns
349    ///
350    /// the state message of @self
351    #[doc(alias = "gtk_printer_get_state_message")]
352    #[doc(alias = "get_state_message")]
353    #[doc(alias = "state-message")]
354    pub fn state_message(&self) -> glib::GString {
355        unsafe { from_glib_none(ffi::gtk_printer_get_state_message(self.to_glib_none().0)) }
356    }
357
358    /// Returns whether the printer details are available.
359    ///
360    /// # Returns
361    ///
362    /// [`true`] if @self details are available
363    #[doc(alias = "gtk_printer_has_details")]
364    pub fn has_details(&self) -> bool {
365        unsafe { from_glib(ffi::gtk_printer_has_details(self.to_glib_none().0)) }
366    }
367
368    /// Returns whether the printer is accepting jobs
369    ///
370    /// # Returns
371    ///
372    /// [`true`] if @self is accepting jobs
373    #[doc(alias = "gtk_printer_is_accepting_jobs")]
374    #[doc(alias = "accepting-jobs")]
375    pub fn is_accepting_jobs(&self) -> bool {
376        unsafe { from_glib(ffi::gtk_printer_is_accepting_jobs(self.to_glib_none().0)) }
377    }
378
379    /// Returns whether the printer is currently active (i.e.
380    /// accepts new jobs).
381    ///
382    /// # Returns
383    ///
384    /// [`true`] if @self is active
385    #[doc(alias = "gtk_printer_is_active")]
386    pub fn is_active(&self) -> bool {
387        unsafe { from_glib(ffi::gtk_printer_is_active(self.to_glib_none().0)) }
388    }
389
390    /// Returns whether the printer is the default printer.
391    ///
392    /// # Returns
393    ///
394    /// [`true`] if @self is the default
395    #[doc(alias = "gtk_printer_is_default")]
396    pub fn is_default(&self) -> bool {
397        unsafe { from_glib(ffi::gtk_printer_is_default(self.to_glib_none().0)) }
398    }
399
400    /// Returns whether the printer is currently paused.
401    ///
402    /// A paused printer still accepts jobs, but it is not
403    /// printing them.
404    ///
405    /// # Returns
406    ///
407    /// [`true`] if @self is paused
408    #[doc(alias = "gtk_printer_is_paused")]
409    #[doc(alias = "paused")]
410    pub fn is_paused(&self) -> bool {
411        unsafe { from_glib(ffi::gtk_printer_is_paused(self.to_glib_none().0)) }
412    }
413
414    /// Returns whether the printer is virtual (i.e. does not
415    /// represent actual printer hardware, but something like
416    /// a CUPS class).
417    ///
418    /// # Returns
419    ///
420    /// [`true`] if @self is virtual
421    #[doc(alias = "gtk_printer_is_virtual")]
422    #[doc(alias = "is-virtual")]
423    pub fn is_virtual(&self) -> bool {
424        unsafe { from_glib(ffi::gtk_printer_is_virtual(self.to_glib_none().0)) }
425    }
426
427    /// Lists all the paper sizes @self supports.
428    ///
429    /// This will return and empty list unless the printer’s details
430    /// are available, see [`has_details()`][Self::has_details()] and
431    /// [`request_details()`][Self::request_details()].
432    ///
433    /// # Returns
434    ///
435    /// a newly
436    ///   allocated list of newly allocated [`PageSetup`][crate::PageSetup]s.
437    #[doc(alias = "gtk_printer_list_papers")]
438    pub fn list_papers(&self) -> Vec<PageSetup> {
439        unsafe {
440            FromGlibPtrContainer::from_glib_full(ffi::gtk_printer_list_papers(
441                self.to_glib_none().0,
442            ))
443        }
444    }
445
446    /// Requests the printer details.
447    ///
448    /// When the details are available, the
449    /// [`details-acquired`][struct@crate::Printer#details-acquired] signal
450    /// will be emitted on @self.
451    #[doc(alias = "gtk_printer_request_details")]
452    pub fn request_details(&self) {
453        unsafe {
454            ffi::gtk_printer_request_details(self.to_glib_none().0);
455        }
456    }
457
458    /// Emitted in response to a request for detailed information
459    /// about a printer from the print backend.
460    ///
461    /// The @success parameter indicates if the information was
462    /// actually obtained.
463    /// ## `success`
464    /// [`true`] if the details were successfully acquired
465    #[doc(alias = "details-acquired")]
466    pub fn connect_details_acquired<F: Fn(&Self, bool) + 'static>(&self, f: F) -> SignalHandlerId {
467        unsafe extern "C" fn details_acquired_trampoline<F: Fn(&Printer, bool) + 'static>(
468            this: *mut ffi::GtkPrinter,
469            success: glib::ffi::gboolean,
470            f: glib::ffi::gpointer,
471        ) {
472            let f: &F = &*(f as *const F);
473            f(&from_glib_borrow(this), from_glib(success))
474        }
475        unsafe {
476            let f: Box_<F> = Box_::new(f);
477            connect_raw(
478                self.as_ptr() as *mut _,
479                b"details-acquired\0".as_ptr() as *const _,
480                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
481                    details_acquired_trampoline::<F> as *const (),
482                )),
483                Box_::into_raw(f),
484            )
485        }
486    }
487
488    #[doc(alias = "accepting-jobs")]
489    pub fn connect_accepting_jobs_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
490        unsafe extern "C" fn notify_accepting_jobs_trampoline<F: Fn(&Printer) + 'static>(
491            this: *mut ffi::GtkPrinter,
492            _param_spec: glib::ffi::gpointer,
493            f: glib::ffi::gpointer,
494        ) {
495            let f: &F = &*(f as *const F);
496            f(&from_glib_borrow(this))
497        }
498        unsafe {
499            let f: Box_<F> = Box_::new(f);
500            connect_raw(
501                self.as_ptr() as *mut _,
502                b"notify::accepting-jobs\0".as_ptr() as *const _,
503                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
504                    notify_accepting_jobs_trampoline::<F> as *const (),
505                )),
506                Box_::into_raw(f),
507            )
508        }
509    }
510
511    #[doc(alias = "icon-name")]
512    pub fn connect_icon_name_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
513        unsafe extern "C" fn notify_icon_name_trampoline<F: Fn(&Printer) + 'static>(
514            this: *mut ffi::GtkPrinter,
515            _param_spec: glib::ffi::gpointer,
516            f: glib::ffi::gpointer,
517        ) {
518            let f: &F = &*(f as *const F);
519            f(&from_glib_borrow(this))
520        }
521        unsafe {
522            let f: Box_<F> = Box_::new(f);
523            connect_raw(
524                self.as_ptr() as *mut _,
525                b"notify::icon-name\0".as_ptr() as *const _,
526                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
527                    notify_icon_name_trampoline::<F> as *const (),
528                )),
529                Box_::into_raw(f),
530            )
531        }
532    }
533
534    #[doc(alias = "job-count")]
535    pub fn connect_job_count_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
536        unsafe extern "C" fn notify_job_count_trampoline<F: Fn(&Printer) + 'static>(
537            this: *mut ffi::GtkPrinter,
538            _param_spec: glib::ffi::gpointer,
539            f: glib::ffi::gpointer,
540        ) {
541            let f: &F = &*(f as *const F);
542            f(&from_glib_borrow(this))
543        }
544        unsafe {
545            let f: Box_<F> = Box_::new(f);
546            connect_raw(
547                self.as_ptr() as *mut _,
548                b"notify::job-count\0".as_ptr() as *const _,
549                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
550                    notify_job_count_trampoline::<F> as *const (),
551                )),
552                Box_::into_raw(f),
553            )
554        }
555    }
556
557    #[doc(alias = "location")]
558    pub fn connect_location_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
559        unsafe extern "C" fn notify_location_trampoline<F: Fn(&Printer) + 'static>(
560            this: *mut ffi::GtkPrinter,
561            _param_spec: glib::ffi::gpointer,
562            f: glib::ffi::gpointer,
563        ) {
564            let f: &F = &*(f as *const F);
565            f(&from_glib_borrow(this))
566        }
567        unsafe {
568            let f: Box_<F> = Box_::new(f);
569            connect_raw(
570                self.as_ptr() as *mut _,
571                b"notify::location\0".as_ptr() as *const _,
572                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
573                    notify_location_trampoline::<F> as *const (),
574                )),
575                Box_::into_raw(f),
576            )
577        }
578    }
579
580    #[doc(alias = "paused")]
581    pub fn connect_paused_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
582        unsafe extern "C" fn notify_paused_trampoline<F: Fn(&Printer) + 'static>(
583            this: *mut ffi::GtkPrinter,
584            _param_spec: glib::ffi::gpointer,
585            f: glib::ffi::gpointer,
586        ) {
587            let f: &F = &*(f as *const F);
588            f(&from_glib_borrow(this))
589        }
590        unsafe {
591            let f: Box_<F> = Box_::new(f);
592            connect_raw(
593                self.as_ptr() as *mut _,
594                b"notify::paused\0".as_ptr() as *const _,
595                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
596                    notify_paused_trampoline::<F> as *const (),
597                )),
598                Box_::into_raw(f),
599            )
600        }
601    }
602
603    #[doc(alias = "state-message")]
604    pub fn connect_state_message_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
605        unsafe extern "C" fn notify_state_message_trampoline<F: Fn(&Printer) + 'static>(
606            this: *mut ffi::GtkPrinter,
607            _param_spec: glib::ffi::gpointer,
608            f: glib::ffi::gpointer,
609        ) {
610            let f: &F = &*(f as *const F);
611            f(&from_glib_borrow(this))
612        }
613        unsafe {
614            let f: Box_<F> = Box_::new(f);
615            connect_raw(
616                self.as_ptr() as *mut _,
617                b"notify::state-message\0".as_ptr() as *const _,
618                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
619                    notify_state_message_trampoline::<F> as *const (),
620                )),
621                Box_::into_raw(f),
622            )
623        }
624    }
625}
626
627impl std::fmt::Display for Printer {
628    #[inline]
629    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
630        f.write_str(&self.name())
631    }
632}