Skip to main content

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::{PageSetup, PaperSize, PrintCapabilities, ffi};
6use glib::{
7    object::ObjectType as _,
8    prelude::*,
9    signal::{SignalHandlerId, connect_raw},
10    translate::*,
11};
12use std::boxed::Box as Box_;
13
14glib::wrapper! {
15    /// 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            unsafe {
473                let f: &F = &*(f as *const F);
474                f(&from_glib_borrow(this), from_glib(success))
475            }
476        }
477        unsafe {
478            let f: Box_<F> = Box_::new(f);
479            connect_raw(
480                self.as_ptr() as *mut _,
481                c"details-acquired".as_ptr() as *const _,
482                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
483                    details_acquired_trampoline::<F> as *const (),
484                )),
485                Box_::into_raw(f),
486            )
487        }
488    }
489
490    #[doc(alias = "accepting-jobs")]
491    pub fn connect_accepting_jobs_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
492        unsafe extern "C" fn notify_accepting_jobs_trampoline<F: Fn(&Printer) + 'static>(
493            this: *mut ffi::GtkPrinter,
494            _param_spec: glib::ffi::gpointer,
495            f: glib::ffi::gpointer,
496        ) {
497            unsafe {
498                let f: &F = &*(f as *const F);
499                f(&from_glib_borrow(this))
500            }
501        }
502        unsafe {
503            let f: Box_<F> = Box_::new(f);
504            connect_raw(
505                self.as_ptr() as *mut _,
506                c"notify::accepting-jobs".as_ptr() as *const _,
507                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
508                    notify_accepting_jobs_trampoline::<F> as *const (),
509                )),
510                Box_::into_raw(f),
511            )
512        }
513    }
514
515    #[doc(alias = "icon-name")]
516    pub fn connect_icon_name_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
517        unsafe extern "C" fn notify_icon_name_trampoline<F: Fn(&Printer) + 'static>(
518            this: *mut ffi::GtkPrinter,
519            _param_spec: glib::ffi::gpointer,
520            f: glib::ffi::gpointer,
521        ) {
522            unsafe {
523                let f: &F = &*(f as *const F);
524                f(&from_glib_borrow(this))
525            }
526        }
527        unsafe {
528            let f: Box_<F> = Box_::new(f);
529            connect_raw(
530                self.as_ptr() as *mut _,
531                c"notify::icon-name".as_ptr() as *const _,
532                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
533                    notify_icon_name_trampoline::<F> as *const (),
534                )),
535                Box_::into_raw(f),
536            )
537        }
538    }
539
540    #[doc(alias = "job-count")]
541    pub fn connect_job_count_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
542        unsafe extern "C" fn notify_job_count_trampoline<F: Fn(&Printer) + 'static>(
543            this: *mut ffi::GtkPrinter,
544            _param_spec: glib::ffi::gpointer,
545            f: glib::ffi::gpointer,
546        ) {
547            unsafe {
548                let f: &F = &*(f as *const F);
549                f(&from_glib_borrow(this))
550            }
551        }
552        unsafe {
553            let f: Box_<F> = Box_::new(f);
554            connect_raw(
555                self.as_ptr() as *mut _,
556                c"notify::job-count".as_ptr() as *const _,
557                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
558                    notify_job_count_trampoline::<F> as *const (),
559                )),
560                Box_::into_raw(f),
561            )
562        }
563    }
564
565    #[doc(alias = "location")]
566    pub fn connect_location_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
567        unsafe extern "C" fn notify_location_trampoline<F: Fn(&Printer) + 'static>(
568            this: *mut ffi::GtkPrinter,
569            _param_spec: glib::ffi::gpointer,
570            f: glib::ffi::gpointer,
571        ) {
572            unsafe {
573                let f: &F = &*(f as *const F);
574                f(&from_glib_borrow(this))
575            }
576        }
577        unsafe {
578            let f: Box_<F> = Box_::new(f);
579            connect_raw(
580                self.as_ptr() as *mut _,
581                c"notify::location".as_ptr() as *const _,
582                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
583                    notify_location_trampoline::<F> as *const (),
584                )),
585                Box_::into_raw(f),
586            )
587        }
588    }
589
590    #[doc(alias = "paused")]
591    pub fn connect_paused_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
592        unsafe extern "C" fn notify_paused_trampoline<F: Fn(&Printer) + 'static>(
593            this: *mut ffi::GtkPrinter,
594            _param_spec: glib::ffi::gpointer,
595            f: glib::ffi::gpointer,
596        ) {
597            unsafe {
598                let f: &F = &*(f as *const F);
599                f(&from_glib_borrow(this))
600            }
601        }
602        unsafe {
603            let f: Box_<F> = Box_::new(f);
604            connect_raw(
605                self.as_ptr() as *mut _,
606                c"notify::paused".as_ptr() as *const _,
607                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
608                    notify_paused_trampoline::<F> as *const (),
609                )),
610                Box_::into_raw(f),
611            )
612        }
613    }
614
615    #[doc(alias = "state-message")]
616    pub fn connect_state_message_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
617        unsafe extern "C" fn notify_state_message_trampoline<F: Fn(&Printer) + 'static>(
618            this: *mut ffi::GtkPrinter,
619            _param_spec: glib::ffi::gpointer,
620            f: glib::ffi::gpointer,
621        ) {
622            unsafe {
623                let f: &F = &*(f as *const F);
624                f(&from_glib_borrow(this))
625            }
626        }
627        unsafe {
628            let f: Box_<F> = Box_::new(f);
629            connect_raw(
630                self.as_ptr() as *mut _,
631                c"notify::state-message".as_ptr() as *const _,
632                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
633                    notify_state_message_trampoline::<F> as *const (),
634                )),
635                Box_::into_raw(f),
636            )
637        }
638    }
639}
640
641impl std::fmt::Display for Printer {
642    #[inline]
643    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
644        f.write_str(&self.name())
645    }
646}