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