1use 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 #[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 #[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 #[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 #[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 #[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 #[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 #[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 #[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 #[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 #[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 #[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 #[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 #[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 #[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 #[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 #[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 #[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 #[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 #[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 #[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 #[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 #[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}