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 | Writable | Construct Only
38    ///
39    ///
40    /// #### `accepts-ps`
41    ///  [`true`] if this printer can accept PostScript.
42    ///
43    /// Readable | Writable | 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 | Writable | 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 | Writable | 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    /// s details are
144    /// available, see [`has_details()`][Self::has_details()] and
145    /// [`request_details()`][Self::request_details()].
146    ///
147    /// # Returns
148    ///
149    /// s capabilities
150    #[doc(alias = "gtk_printer_get_capabilities")]
151    #[doc(alias = "get_capabilities")]
152    pub fn capabilities(&self) -> PrintCapabilities {
153        unsafe { from_glib(ffi::gtk_printer_get_capabilities(self.to_glib_none().0)) }
154    }
155
156    /// Returns default page size of @self.
157    ///
158    /// # Returns
159    ///
160    /// a newly allocated [`PageSetup`][crate::PageSetup] with default page size
161    ///   of the printer.
162    #[doc(alias = "gtk_printer_get_default_page_size")]
163    #[doc(alias = "get_default_page_size")]
164    pub fn default_page_size(&self) -> PageSetup {
165        unsafe {
166            from_glib_full(ffi::gtk_printer_get_default_page_size(
167                self.to_glib_none().0,
168            ))
169        }
170    }
171
172    /// Gets the description of the printer.
173    ///
174    /// # Returns
175    ///
176    /// the description of @self
177    #[doc(alias = "gtk_printer_get_description")]
178    #[doc(alias = "get_description")]
179    pub fn description(&self) -> glib::GString {
180        unsafe { from_glib_none(ffi::gtk_printer_get_description(self.to_glib_none().0)) }
181    }
182
183    /// s details are
184    /// available, see [`has_details()`][Self::has_details()] and
185    /// [`request_details()`][Self::request_details()].
186    ///
187    /// # Returns
188    ///
189    /// [`true`] iff the hard margins were retrieved
190    ///
191    /// ## `top`
192    /// a location to store the top margin in
193    ///
194    /// ## `bottom`
195    /// a location to store the bottom margin in
196    ///
197    /// ## `left`
198    /// a location to store the left margin in
199    ///
200    /// ## `right`
201    /// a location to store the right margin in
202    #[doc(alias = "gtk_printer_get_hard_margins")]
203    #[doc(alias = "get_hard_margins")]
204    pub fn hard_margins(&self) -> Option<(f64, f64, f64, f64)> {
205        unsafe {
206            let mut top = std::mem::MaybeUninit::uninit();
207            let mut bottom = std::mem::MaybeUninit::uninit();
208            let mut left = std::mem::MaybeUninit::uninit();
209            let mut right = std::mem::MaybeUninit::uninit();
210            let ret = from_glib(ffi::gtk_printer_get_hard_margins(
211                self.to_glib_none().0,
212                top.as_mut_ptr(),
213                bottom.as_mut_ptr(),
214                left.as_mut_ptr(),
215                right.as_mut_ptr(),
216            ));
217            if ret {
218                Some((
219                    top.assume_init(),
220                    bottom.assume_init(),
221                    left.assume_init(),
222                    right.assume_init(),
223                ))
224            } else {
225                None
226            }
227        }
228    }
229
230    /// s details are
231    /// available, see [`has_details()`][Self::has_details()] and
232    /// [`request_details()`][Self::request_details()].
233    /// ## `paper_size`
234    /// a [`PaperSize`][crate::PaperSize]
235    ///
236    /// # Returns
237    ///
238    /// [`true`] iff the hard margins were retrieved
239    ///
240    /// ## `top`
241    /// a location to store the top margin in
242    ///
243    /// ## `bottom`
244    /// a location to store the bottom margin in
245    ///
246    /// ## `left`
247    /// a location to store the left margin in
248    ///
249    /// ## `right`
250    /// a location to store the right margin in
251    #[doc(alias = "gtk_printer_get_hard_margins_for_paper_size")]
252    #[doc(alias = "get_hard_margins_for_paper_size")]
253    pub fn hard_margins_for_paper_size(
254        &self,
255        paper_size: &mut PaperSize,
256    ) -> Option<(f64, f64, f64, f64)> {
257        unsafe {
258            let mut top = std::mem::MaybeUninit::uninit();
259            let mut bottom = std::mem::MaybeUninit::uninit();
260            let mut left = std::mem::MaybeUninit::uninit();
261            let mut right = std::mem::MaybeUninit::uninit();
262            let ret = from_glib(ffi::gtk_printer_get_hard_margins_for_paper_size(
263                self.to_glib_none().0,
264                paper_size.to_glib_none_mut().0,
265                top.as_mut_ptr(),
266                bottom.as_mut_ptr(),
267                left.as_mut_ptr(),
268                right.as_mut_ptr(),
269            ));
270            if ret {
271                Some((
272                    top.assume_init(),
273                    bottom.assume_init(),
274                    left.assume_init(),
275                    right.assume_init(),
276                ))
277            } else {
278                None
279            }
280        }
281    }
282
283    /// Gets the name of the icon to use for the printer.
284    ///
285    /// # Returns
286    ///
287    /// the icon name for @self
288    #[doc(alias = "gtk_printer_get_icon_name")]
289    #[doc(alias = "get_icon_name")]
290    #[doc(alias = "icon-name")]
291    pub fn icon_name(&self) -> glib::GString {
292        unsafe { from_glib_none(ffi::gtk_printer_get_icon_name(self.to_glib_none().0)) }
293    }
294
295    /// Gets the number of jobs currently queued on the printer.
296    ///
297    /// # Returns
298    ///
299    /// the number of jobs on @self
300    #[doc(alias = "gtk_printer_get_job_count")]
301    #[doc(alias = "get_job_count")]
302    #[doc(alias = "job-count")]
303    pub fn job_count(&self) -> i32 {
304        unsafe { ffi::gtk_printer_get_job_count(self.to_glib_none().0) }
305    }
306
307    /// Returns a description of the location of the printer.
308    ///
309    /// # Returns
310    ///
311    /// the location of @self
312    #[doc(alias = "gtk_printer_get_location")]
313    #[doc(alias = "get_location")]
314    pub fn location(&self) -> glib::GString {
315        unsafe { from_glib_none(ffi::gtk_printer_get_location(self.to_glib_none().0)) }
316    }
317
318    /// Returns the name of the printer.
319    ///
320    /// # Returns
321    ///
322    /// the name of @self
323    #[doc(alias = "gtk_printer_get_name")]
324    #[doc(alias = "get_name")]
325    pub fn name(&self) -> glib::GString {
326        unsafe { from_glib_none(ffi::gtk_printer_get_name(self.to_glib_none().0)) }
327    }
328
329    /// Returns the state message describing the current state
330    /// of the printer.
331    ///
332    /// # Returns
333    ///
334    /// the state message of @self
335    #[doc(alias = "gtk_printer_get_state_message")]
336    #[doc(alias = "get_state_message")]
337    #[doc(alias = "state-message")]
338    pub fn state_message(&self) -> glib::GString {
339        unsafe { from_glib_none(ffi::gtk_printer_get_state_message(self.to_glib_none().0)) }
340    }
341
342    /// Returns whether the printer details are available.
343    ///
344    /// # Returns
345    ///
346    /// [`true`] if @self details are available
347    #[doc(alias = "gtk_printer_has_details")]
348    pub fn has_details(&self) -> bool {
349        unsafe { from_glib(ffi::gtk_printer_has_details(self.to_glib_none().0)) }
350    }
351
352    /// Returns whether the printer is accepting jobs
353    ///
354    /// # Returns
355    ///
356    /// [`true`] if @self is accepting jobs
357    #[doc(alias = "gtk_printer_is_accepting_jobs")]
358    #[doc(alias = "accepting-jobs")]
359    pub fn is_accepting_jobs(&self) -> bool {
360        unsafe { from_glib(ffi::gtk_printer_is_accepting_jobs(self.to_glib_none().0)) }
361    }
362
363    /// Returns whether the printer is currently active (i.e.
364    /// accepts new jobs).
365    ///
366    /// # Returns
367    ///
368    /// [`true`] if @self is active
369    #[doc(alias = "gtk_printer_is_active")]
370    pub fn is_active(&self) -> bool {
371        unsafe { from_glib(ffi::gtk_printer_is_active(self.to_glib_none().0)) }
372    }
373
374    /// Returns whether the printer is the default printer.
375    ///
376    /// # Returns
377    ///
378    /// [`true`] if @self is the default
379    #[doc(alias = "gtk_printer_is_default")]
380    pub fn is_default(&self) -> bool {
381        unsafe { from_glib(ffi::gtk_printer_is_default(self.to_glib_none().0)) }
382    }
383
384    /// Returns whether the printer is currently paused.
385    ///
386    /// A paused printer still accepts jobs, but it is not
387    /// printing them.
388    ///
389    /// # Returns
390    ///
391    /// [`true`] if @self is paused
392    #[doc(alias = "gtk_printer_is_paused")]
393    #[doc(alias = "paused")]
394    pub fn is_paused(&self) -> bool {
395        unsafe { from_glib(ffi::gtk_printer_is_paused(self.to_glib_none().0)) }
396    }
397
398    /// Returns whether the printer is virtual (i.e. does not
399    /// represent actual printer hardware, but something like
400    /// a CUPS class).
401    ///
402    /// # Returns
403    ///
404    /// [`true`] if @self is virtual
405    #[doc(alias = "gtk_printer_is_virtual")]
406    #[doc(alias = "is-virtual")]
407    pub fn is_virtual(&self) -> bool {
408        unsafe { from_glib(ffi::gtk_printer_is_virtual(self.to_glib_none().0)) }
409    }
410
411    /// s details
412    /// are available, see [`has_details()`][Self::has_details()] and
413    /// [`request_details()`][Self::request_details()].
414    ///
415    /// # Returns
416    ///
417    /// a newly
418    ///   allocated list of newly allocated [`PageSetup`][crate::PageSetup]s.
419    #[doc(alias = "gtk_printer_list_papers")]
420    pub fn list_papers(&self) -> Vec<PageSetup> {
421        unsafe {
422            FromGlibPtrContainer::from_glib_full(ffi::gtk_printer_list_papers(
423                self.to_glib_none().0,
424            ))
425        }
426    }
427
428    /// Requests the printer details.
429    ///
430    /// When the details are available, the
431    /// [`details-acquired`][struct@crate::Printer#details-acquired] signal
432    /// will be emitted on @self.
433    #[doc(alias = "gtk_printer_request_details")]
434    pub fn request_details(&self) {
435        unsafe {
436            ffi::gtk_printer_request_details(self.to_glib_none().0);
437        }
438    }
439
440    /// Emitted in response to a request for detailed information
441    /// about a printer from the print backend.
442    ///
443    /// The @success parameter indicates if the information was
444    /// actually obtained.
445    /// ## `success`
446    /// [`true`] if the details were successfully acquired
447    #[doc(alias = "details-acquired")]
448    pub fn connect_details_acquired<F: Fn(&Self, bool) + 'static>(&self, f: F) -> SignalHandlerId {
449        unsafe extern "C" fn details_acquired_trampoline<F: Fn(&Printer, bool) + 'static>(
450            this: *mut ffi::GtkPrinter,
451            success: glib::ffi::gboolean,
452            f: glib::ffi::gpointer,
453        ) {
454            unsafe {
455                let f: &F = &*(f as *const F);
456                f(&from_glib_borrow(this), from_glib(success))
457            }
458        }
459        unsafe {
460            let f: Box_<F> = Box_::new(f);
461            connect_raw(
462                self.as_ptr() as *mut _,
463                c"details-acquired".as_ptr(),
464                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
465                    details_acquired_trampoline::<F> as *const (),
466                )),
467                Box_::into_raw(f),
468            )
469        }
470    }
471
472    #[doc(alias = "accepting-jobs")]
473    pub fn connect_accepting_jobs_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
474        unsafe extern "C" fn notify_accepting_jobs_trampoline<F: Fn(&Printer) + 'static>(
475            this: *mut ffi::GtkPrinter,
476            _param_spec: glib::ffi::gpointer,
477            f: glib::ffi::gpointer,
478        ) {
479            unsafe {
480                let f: &F = &*(f as *const F);
481                f(&from_glib_borrow(this))
482            }
483        }
484        unsafe {
485            let f: Box_<F> = Box_::new(f);
486            connect_raw(
487                self.as_ptr() as *mut _,
488                c"notify::accepting-jobs".as_ptr(),
489                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
490                    notify_accepting_jobs_trampoline::<F> as *const (),
491                )),
492                Box_::into_raw(f),
493            )
494        }
495    }
496
497    #[doc(alias = "icon-name")]
498    pub fn connect_icon_name_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
499        unsafe extern "C" fn notify_icon_name_trampoline<F: Fn(&Printer) + 'static>(
500            this: *mut ffi::GtkPrinter,
501            _param_spec: glib::ffi::gpointer,
502            f: glib::ffi::gpointer,
503        ) {
504            unsafe {
505                let f: &F = &*(f as *const F);
506                f(&from_glib_borrow(this))
507            }
508        }
509        unsafe {
510            let f: Box_<F> = Box_::new(f);
511            connect_raw(
512                self.as_ptr() as *mut _,
513                c"notify::icon-name".as_ptr(),
514                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
515                    notify_icon_name_trampoline::<F> as *const (),
516                )),
517                Box_::into_raw(f),
518            )
519        }
520    }
521
522    #[doc(alias = "job-count")]
523    pub fn connect_job_count_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
524        unsafe extern "C" fn notify_job_count_trampoline<F: Fn(&Printer) + 'static>(
525            this: *mut ffi::GtkPrinter,
526            _param_spec: glib::ffi::gpointer,
527            f: glib::ffi::gpointer,
528        ) {
529            unsafe {
530                let f: &F = &*(f as *const F);
531                f(&from_glib_borrow(this))
532            }
533        }
534        unsafe {
535            let f: Box_<F> = Box_::new(f);
536            connect_raw(
537                self.as_ptr() as *mut _,
538                c"notify::job-count".as_ptr(),
539                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
540                    notify_job_count_trampoline::<F> as *const (),
541                )),
542                Box_::into_raw(f),
543            )
544        }
545    }
546
547    #[doc(alias = "location")]
548    pub fn connect_location_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
549        unsafe extern "C" fn notify_location_trampoline<F: Fn(&Printer) + 'static>(
550            this: *mut ffi::GtkPrinter,
551            _param_spec: glib::ffi::gpointer,
552            f: glib::ffi::gpointer,
553        ) {
554            unsafe {
555                let f: &F = &*(f as *const F);
556                f(&from_glib_borrow(this))
557            }
558        }
559        unsafe {
560            let f: Box_<F> = Box_::new(f);
561            connect_raw(
562                self.as_ptr() as *mut _,
563                c"notify::location".as_ptr(),
564                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
565                    notify_location_trampoline::<F> as *const (),
566                )),
567                Box_::into_raw(f),
568            )
569        }
570    }
571
572    #[doc(alias = "paused")]
573    pub fn connect_paused_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
574        unsafe extern "C" fn notify_paused_trampoline<F: Fn(&Printer) + 'static>(
575            this: *mut ffi::GtkPrinter,
576            _param_spec: glib::ffi::gpointer,
577            f: glib::ffi::gpointer,
578        ) {
579            unsafe {
580                let f: &F = &*(f as *const F);
581                f(&from_glib_borrow(this))
582            }
583        }
584        unsafe {
585            let f: Box_<F> = Box_::new(f);
586            connect_raw(
587                self.as_ptr() as *mut _,
588                c"notify::paused".as_ptr(),
589                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
590                    notify_paused_trampoline::<F> as *const (),
591                )),
592                Box_::into_raw(f),
593            )
594        }
595    }
596
597    #[doc(alias = "state-message")]
598    pub fn connect_state_message_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
599        unsafe extern "C" fn notify_state_message_trampoline<F: Fn(&Printer) + 'static>(
600            this: *mut ffi::GtkPrinter,
601            _param_spec: glib::ffi::gpointer,
602            f: glib::ffi::gpointer,
603        ) {
604            unsafe {
605                let f: &F = &*(f as *const F);
606                f(&from_glib_borrow(this))
607            }
608        }
609        unsafe {
610            let f: Box_<F> = Box_::new(f);
611            connect_raw(
612                self.as_ptr() as *mut _,
613                c"notify::state-message".as_ptr(),
614                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
615                    notify_state_message_trampoline::<F> as *const (),
616                )),
617                Box_::into_raw(f),
618            )
619        }
620    }
621}
622
623impl std::fmt::Display for Printer {
624    #[inline]
625    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
626        f.write_str(&self.name())
627    }
628}