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")]
16 pub struct Printer(Object<ffi::GtkPrinter>);
17
18 match fn {
19 type_ => || ffi::gtk_printer_get_type(),
20 }
21}
22
23impl Printer {
24 #[doc(alias = "gtk_printer_accepts_pdf")]
25 #[doc(alias = "accepts-pdf")]
26 pub fn accepts_pdf(&self) -> bool {
27 unsafe { from_glib(ffi::gtk_printer_accepts_pdf(self.to_glib_none().0)) }
28 }
29
30 #[doc(alias = "gtk_printer_accepts_ps")]
31 #[doc(alias = "accepts-ps")]
32 pub fn accepts_ps(&self) -> bool {
33 unsafe { from_glib(ffi::gtk_printer_accepts_ps(self.to_glib_none().0)) }
34 }
35
36 #[doc(alias = "gtk_printer_compare")]
37 pub fn compare(&self, b: &Printer) -> i32 {
38 unsafe { ffi::gtk_printer_compare(self.to_glib_none().0, b.to_glib_none().0) }
39 }
40
41 #[doc(alias = "gtk_printer_get_capabilities")]
42 #[doc(alias = "get_capabilities")]
43 pub fn capabilities(&self) -> PrintCapabilities {
44 unsafe { from_glib(ffi::gtk_printer_get_capabilities(self.to_glib_none().0)) }
45 }
46
47 #[doc(alias = "gtk_printer_get_default_page_size")]
48 #[doc(alias = "get_default_page_size")]
49 pub fn default_page_size(&self) -> PageSetup {
50 unsafe {
51 from_glib_full(ffi::gtk_printer_get_default_page_size(
52 self.to_glib_none().0,
53 ))
54 }
55 }
56
57 #[doc(alias = "gtk_printer_get_description")]
58 #[doc(alias = "get_description")]
59 pub fn description(&self) -> glib::GString {
60 unsafe { from_glib_none(ffi::gtk_printer_get_description(self.to_glib_none().0)) }
61 }
62
63 #[doc(alias = "gtk_printer_get_hard_margins")]
64 #[doc(alias = "get_hard_margins")]
65 pub fn hard_margins(&self) -> Option<(f64, f64, f64, f64)> {
66 unsafe {
67 let mut top = std::mem::MaybeUninit::uninit();
68 let mut bottom = std::mem::MaybeUninit::uninit();
69 let mut left = std::mem::MaybeUninit::uninit();
70 let mut right = std::mem::MaybeUninit::uninit();
71 let ret = from_glib(ffi::gtk_printer_get_hard_margins(
72 self.to_glib_none().0,
73 top.as_mut_ptr(),
74 bottom.as_mut_ptr(),
75 left.as_mut_ptr(),
76 right.as_mut_ptr(),
77 ));
78 if ret {
79 Some((
80 top.assume_init(),
81 bottom.assume_init(),
82 left.assume_init(),
83 right.assume_init(),
84 ))
85 } else {
86 None
87 }
88 }
89 }
90
91 #[doc(alias = "gtk_printer_get_hard_margins_for_paper_size")]
92 #[doc(alias = "get_hard_margins_for_paper_size")]
93 pub fn hard_margins_for_paper_size(
94 &self,
95 paper_size: &mut PaperSize,
96 ) -> Option<(f64, f64, f64, f64)> {
97 unsafe {
98 let mut top = std::mem::MaybeUninit::uninit();
99 let mut bottom = std::mem::MaybeUninit::uninit();
100 let mut left = std::mem::MaybeUninit::uninit();
101 let mut right = std::mem::MaybeUninit::uninit();
102 let ret = from_glib(ffi::gtk_printer_get_hard_margins_for_paper_size(
103 self.to_glib_none().0,
104 paper_size.to_glib_none_mut().0,
105 top.as_mut_ptr(),
106 bottom.as_mut_ptr(),
107 left.as_mut_ptr(),
108 right.as_mut_ptr(),
109 ));
110 if ret {
111 Some((
112 top.assume_init(),
113 bottom.assume_init(),
114 left.assume_init(),
115 right.assume_init(),
116 ))
117 } else {
118 None
119 }
120 }
121 }
122
123 #[doc(alias = "gtk_printer_get_icon_name")]
124 #[doc(alias = "get_icon_name")]
125 #[doc(alias = "icon-name")]
126 pub fn icon_name(&self) -> glib::GString {
127 unsafe { from_glib_none(ffi::gtk_printer_get_icon_name(self.to_glib_none().0)) }
128 }
129
130 #[doc(alias = "gtk_printer_get_job_count")]
131 #[doc(alias = "get_job_count")]
132 #[doc(alias = "job-count")]
133 pub fn job_count(&self) -> i32 {
134 unsafe { ffi::gtk_printer_get_job_count(self.to_glib_none().0) }
135 }
136
137 #[doc(alias = "gtk_printer_get_location")]
138 #[doc(alias = "get_location")]
139 pub fn location(&self) -> glib::GString {
140 unsafe { from_glib_none(ffi::gtk_printer_get_location(self.to_glib_none().0)) }
141 }
142
143 #[doc(alias = "gtk_printer_get_name")]
144 #[doc(alias = "get_name")]
145 pub fn name(&self) -> glib::GString {
146 unsafe { from_glib_none(ffi::gtk_printer_get_name(self.to_glib_none().0)) }
147 }
148
149 #[doc(alias = "gtk_printer_get_state_message")]
150 #[doc(alias = "get_state_message")]
151 #[doc(alias = "state-message")]
152 pub fn state_message(&self) -> glib::GString {
153 unsafe { from_glib_none(ffi::gtk_printer_get_state_message(self.to_glib_none().0)) }
154 }
155
156 #[doc(alias = "gtk_printer_has_details")]
157 pub fn has_details(&self) -> bool {
158 unsafe { from_glib(ffi::gtk_printer_has_details(self.to_glib_none().0)) }
159 }
160
161 #[doc(alias = "gtk_printer_is_accepting_jobs")]
162 #[doc(alias = "accepting-jobs")]
163 pub fn is_accepting_jobs(&self) -> bool {
164 unsafe { from_glib(ffi::gtk_printer_is_accepting_jobs(self.to_glib_none().0)) }
165 }
166
167 #[doc(alias = "gtk_printer_is_active")]
168 pub fn is_active(&self) -> bool {
169 unsafe { from_glib(ffi::gtk_printer_is_active(self.to_glib_none().0)) }
170 }
171
172 #[doc(alias = "gtk_printer_is_default")]
173 pub fn is_default(&self) -> bool {
174 unsafe { from_glib(ffi::gtk_printer_is_default(self.to_glib_none().0)) }
175 }
176
177 #[doc(alias = "gtk_printer_is_paused")]
178 #[doc(alias = "paused")]
179 pub fn is_paused(&self) -> bool {
180 unsafe { from_glib(ffi::gtk_printer_is_paused(self.to_glib_none().0)) }
181 }
182
183 #[doc(alias = "gtk_printer_is_virtual")]
184 #[doc(alias = "is-virtual")]
185 pub fn is_virtual(&self) -> bool {
186 unsafe { from_glib(ffi::gtk_printer_is_virtual(self.to_glib_none().0)) }
187 }
188
189 #[doc(alias = "gtk_printer_list_papers")]
190 pub fn list_papers(&self) -> Vec<PageSetup> {
191 unsafe {
192 FromGlibPtrContainer::from_glib_full(ffi::gtk_printer_list_papers(
193 self.to_glib_none().0,
194 ))
195 }
196 }
197
198 #[doc(alias = "gtk_printer_request_details")]
199 pub fn request_details(&self) {
200 unsafe {
201 ffi::gtk_printer_request_details(self.to_glib_none().0);
202 }
203 }
204
205 #[doc(alias = "details-acquired")]
206 pub fn connect_details_acquired<F: Fn(&Self, bool) + 'static>(&self, f: F) -> SignalHandlerId {
207 unsafe extern "C" fn details_acquired_trampoline<F: Fn(&Printer, bool) + 'static>(
208 this: *mut ffi::GtkPrinter,
209 success: glib::ffi::gboolean,
210 f: glib::ffi::gpointer,
211 ) {
212 let f: &F = &*(f as *const F);
213 f(&from_glib_borrow(this), from_glib(success))
214 }
215 unsafe {
216 let f: Box_<F> = Box_::new(f);
217 connect_raw(
218 self.as_ptr() as *mut _,
219 c"details-acquired".as_ptr() as *const _,
220 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
221 details_acquired_trampoline::<F> as *const (),
222 )),
223 Box_::into_raw(f),
224 )
225 }
226 }
227
228 #[doc(alias = "accepting-jobs")]
229 pub fn connect_accepting_jobs_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
230 unsafe extern "C" fn notify_accepting_jobs_trampoline<F: Fn(&Printer) + 'static>(
231 this: *mut ffi::GtkPrinter,
232 _param_spec: glib::ffi::gpointer,
233 f: glib::ffi::gpointer,
234 ) {
235 let f: &F = &*(f as *const F);
236 f(&from_glib_borrow(this))
237 }
238 unsafe {
239 let f: Box_<F> = Box_::new(f);
240 connect_raw(
241 self.as_ptr() as *mut _,
242 c"notify::accepting-jobs".as_ptr() as *const _,
243 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
244 notify_accepting_jobs_trampoline::<F> as *const (),
245 )),
246 Box_::into_raw(f),
247 )
248 }
249 }
250
251 #[doc(alias = "icon-name")]
252 pub fn connect_icon_name_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
253 unsafe extern "C" fn notify_icon_name_trampoline<F: Fn(&Printer) + 'static>(
254 this: *mut ffi::GtkPrinter,
255 _param_spec: glib::ffi::gpointer,
256 f: glib::ffi::gpointer,
257 ) {
258 let f: &F = &*(f as *const F);
259 f(&from_glib_borrow(this))
260 }
261 unsafe {
262 let f: Box_<F> = Box_::new(f);
263 connect_raw(
264 self.as_ptr() as *mut _,
265 c"notify::icon-name".as_ptr() as *const _,
266 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
267 notify_icon_name_trampoline::<F> as *const (),
268 )),
269 Box_::into_raw(f),
270 )
271 }
272 }
273
274 #[doc(alias = "job-count")]
275 pub fn connect_job_count_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
276 unsafe extern "C" fn notify_job_count_trampoline<F: Fn(&Printer) + 'static>(
277 this: *mut ffi::GtkPrinter,
278 _param_spec: glib::ffi::gpointer,
279 f: glib::ffi::gpointer,
280 ) {
281 let f: &F = &*(f as *const F);
282 f(&from_glib_borrow(this))
283 }
284 unsafe {
285 let f: Box_<F> = Box_::new(f);
286 connect_raw(
287 self.as_ptr() as *mut _,
288 c"notify::job-count".as_ptr() as *const _,
289 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
290 notify_job_count_trampoline::<F> as *const (),
291 )),
292 Box_::into_raw(f),
293 )
294 }
295 }
296
297 #[doc(alias = "location")]
298 pub fn connect_location_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
299 unsafe extern "C" fn notify_location_trampoline<F: Fn(&Printer) + 'static>(
300 this: *mut ffi::GtkPrinter,
301 _param_spec: glib::ffi::gpointer,
302 f: glib::ffi::gpointer,
303 ) {
304 let f: &F = &*(f as *const F);
305 f(&from_glib_borrow(this))
306 }
307 unsafe {
308 let f: Box_<F> = Box_::new(f);
309 connect_raw(
310 self.as_ptr() as *mut _,
311 c"notify::location".as_ptr() as *const _,
312 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
313 notify_location_trampoline::<F> as *const (),
314 )),
315 Box_::into_raw(f),
316 )
317 }
318 }
319
320 #[doc(alias = "paused")]
321 pub fn connect_paused_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
322 unsafe extern "C" fn notify_paused_trampoline<F: Fn(&Printer) + 'static>(
323 this: *mut ffi::GtkPrinter,
324 _param_spec: glib::ffi::gpointer,
325 f: glib::ffi::gpointer,
326 ) {
327 let f: &F = &*(f as *const F);
328 f(&from_glib_borrow(this))
329 }
330 unsafe {
331 let f: Box_<F> = Box_::new(f);
332 connect_raw(
333 self.as_ptr() as *mut _,
334 c"notify::paused".as_ptr() as *const _,
335 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
336 notify_paused_trampoline::<F> as *const (),
337 )),
338 Box_::into_raw(f),
339 )
340 }
341 }
342
343 #[doc(alias = "state-message")]
344 pub fn connect_state_message_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
345 unsafe extern "C" fn notify_state_message_trampoline<F: Fn(&Printer) + 'static>(
346 this: *mut ffi::GtkPrinter,
347 _param_spec: glib::ffi::gpointer,
348 f: glib::ffi::gpointer,
349 ) {
350 let f: &F = &*(f as *const F);
351 f(&from_glib_borrow(this))
352 }
353 unsafe {
354 let f: Box_<F> = Box_::new(f);
355 connect_raw(
356 self.as_ptr() as *mut _,
357 c"notify::state-message".as_ptr() as *const _,
358 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
359 notify_state_message_trampoline::<F> as *const (),
360 )),
361 Box_::into_raw(f),
362 )
363 }
364 }
365}
366
367impl std::fmt::Display for Printer {
368 #[inline]
369 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
370 f.write_str(&self.name())
371 }
372}