gtk4/auto/print_job.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::{
6 ffi, NumberUpLayout, PageRange, PageSet, PageSetup, PrintPages, PrintSettings, PrintStatus,
7 Printer,
8};
9use glib::{
10 object::ObjectType as _,
11 prelude::*,
12 signal::{connect_raw, SignalHandlerId},
13 translate::*,
14};
15use std::boxed::Box as Box_;
16
17glib::wrapper! {
18 /// A [`PrintJob`][crate::PrintJob] object represents a job that is sent to a printer.
19 ///
20 /// You only need to deal directly with print jobs if you use the
21 /// non-portable [`PrintUnixDialog`][crate::PrintUnixDialog] API.
22 ///
23 /// Use [`surface()`][Self::surface()] to obtain the cairo surface
24 /// onto which the pages must be drawn. Use [`send()`][Self::send()]
25 /// to send the finished job to the printer. If you don’t use cairo
26 /// [`PrintJob`][crate::PrintJob] also supports printing of manually generated PostScript,
27 /// via [`set_source_file()`][Self::set_source_file()].
28 ///
29 /// ## Properties
30 ///
31 ///
32 /// #### `page-setup`
33 /// Page setup.
34 ///
35 /// Readable | Writeable | Construct Only
36 ///
37 ///
38 /// #### `printer`
39 /// The printer to send the job to.
40 ///
41 /// Readable | Writeable | Construct Only
42 ///
43 ///
44 /// #### `settings`
45 /// Printer settings.
46 ///
47 /// Readable | Writeable | Construct Only
48 ///
49 ///
50 /// #### `title`
51 /// The title of the print job.
52 ///
53 /// Readable | Writeable | Construct Only
54 ///
55 ///
56 /// #### `track-print-status`
57 /// [`true`] if the print job will continue to emit status-changed
58 /// signals after the print data has been setn to the printer.
59 ///
60 /// Readable | Writeable
61 ///
62 /// ## Signals
63 ///
64 ///
65 /// #### `status-changed`
66 /// Emitted when the status of a job changes.
67 ///
68 /// The signal handler can use [`PrintJob::status()`][crate::PrintJob::status()]
69 /// to obtain the new status.
70 ///
71 ///
72 ///
73 /// # Implements
74 ///
75 /// [`trait@glib::ObjectExt`]
76 #[doc(alias = "GtkPrintJob")]
77 pub struct PrintJob(Object<ffi::GtkPrintJob>);
78
79 match fn {
80 type_ => || ffi::gtk_print_job_get_type(),
81 }
82}
83
84impl PrintJob {
85 /// Creates a new [`PrintJob`][crate::PrintJob].
86 /// ## `title`
87 /// the job title
88 /// ## `printer`
89 /// a [`Printer`][crate::Printer]
90 /// ## `settings`
91 /// a [`PrintSettings`][crate::PrintSettings]
92 /// ## `page_setup`
93 /// a [`PageSetup`][crate::PageSetup]
94 ///
95 /// # Returns
96 ///
97 /// a new [`PrintJob`][crate::PrintJob]
98 #[doc(alias = "gtk_print_job_new")]
99 pub fn new(
100 title: &str,
101 printer: &Printer,
102 settings: &PrintSettings,
103 page_setup: &PageSetup,
104 ) -> PrintJob {
105 skip_assert_initialized!();
106 unsafe {
107 from_glib_full(ffi::gtk_print_job_new(
108 title.to_glib_none().0,
109 printer.to_glib_none().0,
110 settings.to_glib_none().0,
111 page_setup.to_glib_none().0,
112 ))
113 }
114 }
115
116 /// Gets whether this job is printed collated.
117 ///
118 /// # Returns
119 ///
120 /// whether the job is printed collated
121 #[doc(alias = "gtk_print_job_get_collate")]
122 #[doc(alias = "get_collate")]
123 pub fn is_collate(&self) -> bool {
124 unsafe { from_glib(ffi::gtk_print_job_get_collate(self.to_glib_none().0)) }
125 }
126
127 /// Gets the n-up setting for this job.
128 ///
129 /// # Returns
130 ///
131 /// the n-up setting
132 #[doc(alias = "gtk_print_job_get_n_up")]
133 #[doc(alias = "get_n_up")]
134 pub fn n_up(&self) -> u32 {
135 unsafe { ffi::gtk_print_job_get_n_up(self.to_glib_none().0) }
136 }
137
138 /// Gets the n-up layout setting for this job.
139 ///
140 /// # Returns
141 ///
142 /// the n-up layout
143 #[doc(alias = "gtk_print_job_get_n_up_layout")]
144 #[doc(alias = "get_n_up_layout")]
145 pub fn n_up_layout(&self) -> NumberUpLayout {
146 unsafe { from_glib(ffi::gtk_print_job_get_n_up_layout(self.to_glib_none().0)) }
147 }
148
149 /// Gets the number of copies of this job.
150 ///
151 /// # Returns
152 ///
153 /// the number of copies
154 #[doc(alias = "gtk_print_job_get_num_copies")]
155 #[doc(alias = "get_num_copies")]
156 pub fn num_copies(&self) -> i32 {
157 unsafe { ffi::gtk_print_job_get_num_copies(self.to_glib_none().0) }
158 }
159
160 /// Gets the page ranges for this job.
161 ///
162 /// # Returns
163 ///
164 /// a pointer to an
165 /// array of [`PageRange`][crate::PageRange] structs
166 #[doc(alias = "gtk_print_job_get_page_ranges")]
167 #[doc(alias = "get_page_ranges")]
168 pub fn page_ranges(&self) -> Vec<PageRange> {
169 unsafe {
170 let mut n_ranges = std::mem::MaybeUninit::uninit();
171 let ret = FromGlibContainer::from_glib_none_num(
172 ffi::gtk_print_job_get_page_ranges(self.to_glib_none().0, n_ranges.as_mut_ptr()),
173 n_ranges.assume_init() as _,
174 );
175 ret
176 }
177 }
178
179 /// Gets the [`PageSet`][crate::PageSet] setting for this job.
180 ///
181 /// # Returns
182 ///
183 /// the [`PageSet`][crate::PageSet] setting
184 #[doc(alias = "gtk_print_job_get_page_set")]
185 #[doc(alias = "get_page_set")]
186 pub fn page_set(&self) -> PageSet {
187 unsafe { from_glib(ffi::gtk_print_job_get_page_set(self.to_glib_none().0)) }
188 }
189
190 /// Gets the [`PrintPages`][crate::PrintPages] setting for this job.
191 ///
192 /// # Returns
193 ///
194 /// the [`PrintPages`][crate::PrintPages] setting
195 #[doc(alias = "gtk_print_job_get_pages")]
196 #[doc(alias = "get_pages")]
197 pub fn pages(&self) -> PrintPages {
198 unsafe { from_glib(ffi::gtk_print_job_get_pages(self.to_glib_none().0)) }
199 }
200
201 /// Gets the [`Printer`][crate::Printer] of the print job.
202 ///
203 /// # Returns
204 ///
205 /// the printer of @self
206 #[doc(alias = "gtk_print_job_get_printer")]
207 #[doc(alias = "get_printer")]
208 pub fn printer(&self) -> Printer {
209 unsafe { from_glib_none(ffi::gtk_print_job_get_printer(self.to_glib_none().0)) }
210 }
211
212 /// Gets whether this job is printed reversed.
213 ///
214 /// # Returns
215 ///
216 /// whether the job is printed reversed.
217 #[doc(alias = "gtk_print_job_get_reverse")]
218 #[doc(alias = "get_reverse")]
219 pub fn is_reverse(&self) -> bool {
220 unsafe { from_glib(ffi::gtk_print_job_get_reverse(self.to_glib_none().0)) }
221 }
222
223 /// Gets whether the job is printed rotated.
224 ///
225 /// # Returns
226 ///
227 /// whether the job is printed rotated
228 #[doc(alias = "gtk_print_job_get_rotate")]
229 #[doc(alias = "get_rotate")]
230 pub fn is_rotate(&self) -> bool {
231 unsafe { from_glib(ffi::gtk_print_job_get_rotate(self.to_glib_none().0)) }
232 }
233
234 /// Gets the scale for this job.
235 ///
236 /// # Returns
237 ///
238 /// the scale
239 #[doc(alias = "gtk_print_job_get_scale")]
240 #[doc(alias = "get_scale")]
241 pub fn scale(&self) -> f64 {
242 unsafe { ffi::gtk_print_job_get_scale(self.to_glib_none().0) }
243 }
244
245 /// Gets the [`PrintSettings`][crate::PrintSettings] of the print job.
246 ///
247 /// # Returns
248 ///
249 /// the settings of @self
250 #[doc(alias = "gtk_print_job_get_settings")]
251 #[doc(alias = "get_settings")]
252 pub fn settings(&self) -> PrintSettings {
253 unsafe { from_glib_none(ffi::gtk_print_job_get_settings(self.to_glib_none().0)) }
254 }
255
256 /// Gets the status of the print job.
257 ///
258 /// # Returns
259 ///
260 /// the status of @self
261 #[doc(alias = "gtk_print_job_get_status")]
262 #[doc(alias = "get_status")]
263 pub fn status(&self) -> PrintStatus {
264 unsafe { from_glib(ffi::gtk_print_job_get_status(self.to_glib_none().0)) }
265 }
266
267 /// Gets a cairo surface onto which the pages of
268 /// the print job should be rendered.
269 ///
270 /// # Returns
271 ///
272 /// the cairo surface of @self
273 #[doc(alias = "gtk_print_job_get_surface")]
274 #[doc(alias = "get_surface")]
275 pub fn surface(&self) -> Result<cairo::Surface, glib::Error> {
276 unsafe {
277 let mut error = std::ptr::null_mut();
278 let ret = ffi::gtk_print_job_get_surface(self.to_glib_none().0, &mut error);
279 if error.is_null() {
280 Ok(from_glib_none(ret))
281 } else {
282 Err(from_glib_full(error))
283 }
284 }
285 }
286
287 /// Gets the job title.
288 ///
289 /// # Returns
290 ///
291 /// the title of @self
292 #[doc(alias = "gtk_print_job_get_title")]
293 #[doc(alias = "get_title")]
294 pub fn title(&self) -> glib::GString {
295 unsafe { from_glib_none(ffi::gtk_print_job_get_title(self.to_glib_none().0)) }
296 }
297
298 /// Returns whether jobs will be tracked after printing.
299 ///
300 /// For details, see [`set_track_print_status()`][Self::set_track_print_status()].
301 ///
302 /// # Returns
303 ///
304 /// [`true`] if print job status will be reported after printing
305 #[doc(alias = "gtk_print_job_get_track_print_status")]
306 #[doc(alias = "get_track_print_status")]
307 #[doc(alias = "track-print-status")]
308 pub fn tracks_print_status(&self) -> bool {
309 unsafe {
310 from_glib(ffi::gtk_print_job_get_track_print_status(
311 self.to_glib_none().0,
312 ))
313 }
314 }
315
316 /// Sets whether this job is printed collated.
317 /// ## `collate`
318 /// whether the job is printed collated
319 #[doc(alias = "gtk_print_job_set_collate")]
320 pub fn set_collate(&self, collate: bool) {
321 unsafe {
322 ffi::gtk_print_job_set_collate(self.to_glib_none().0, collate.into_glib());
323 }
324 }
325
326 /// Sets the n-up setting for this job.
327 /// ## `n_up`
328 /// the n-up value
329 #[doc(alias = "gtk_print_job_set_n_up")]
330 pub fn set_n_up(&self, n_up: u32) {
331 unsafe {
332 ffi::gtk_print_job_set_n_up(self.to_glib_none().0, n_up);
333 }
334 }
335
336 /// Sets the n-up layout setting for this job.
337 /// ## `layout`
338 /// the n-up layout setting
339 #[doc(alias = "gtk_print_job_set_n_up_layout")]
340 pub fn set_n_up_layout(&self, layout: NumberUpLayout) {
341 unsafe {
342 ffi::gtk_print_job_set_n_up_layout(self.to_glib_none().0, layout.into_glib());
343 }
344 }
345
346 /// Sets the number of copies for this job.
347 /// ## `num_copies`
348 /// the number of copies
349 #[doc(alias = "gtk_print_job_set_num_copies")]
350 pub fn set_num_copies(&self, num_copies: i32) {
351 unsafe {
352 ffi::gtk_print_job_set_num_copies(self.to_glib_none().0, num_copies);
353 }
354 }
355
356 /// Sets the page ranges for this job.
357 /// ## `ranges`
358 /// pointer to an array of
359 /// [`PageRange`][crate::PageRange] structs
360 #[doc(alias = "gtk_print_job_set_page_ranges")]
361 pub fn set_page_ranges(&self, ranges: &[PageRange]) {
362 let n_ranges = ranges.len() as _;
363 unsafe {
364 ffi::gtk_print_job_set_page_ranges(
365 self.to_glib_none().0,
366 ranges.to_glib_full(),
367 n_ranges,
368 );
369 }
370 }
371
372 /// Sets the [`PageSet`][crate::PageSet] setting for this job.
373 /// ## `page_set`
374 /// a [`PageSet`][crate::PageSet] setting
375 #[doc(alias = "gtk_print_job_set_page_set")]
376 pub fn set_page_set(&self, page_set: PageSet) {
377 unsafe {
378 ffi::gtk_print_job_set_page_set(self.to_glib_none().0, page_set.into_glib());
379 }
380 }
381
382 /// Sets the [`PrintPages`][crate::PrintPages] setting for this job.
383 /// ## `pages`
384 /// the [`PrintPages`][crate::PrintPages] setting
385 #[doc(alias = "gtk_print_job_set_pages")]
386 pub fn set_pages(&self, pages: PrintPages) {
387 unsafe {
388 ffi::gtk_print_job_set_pages(self.to_glib_none().0, pages.into_glib());
389 }
390 }
391
392 /// Sets whether this job is printed reversed.
393 /// ## `reverse`
394 /// whether the job is printed reversed
395 #[doc(alias = "gtk_print_job_set_reverse")]
396 pub fn set_reverse(&self, reverse: bool) {
397 unsafe {
398 ffi::gtk_print_job_set_reverse(self.to_glib_none().0, reverse.into_glib());
399 }
400 }
401
402 /// Sets whether this job is printed rotated.
403 /// ## `rotate`
404 /// whether to print rotated
405 #[doc(alias = "gtk_print_job_set_rotate")]
406 pub fn set_rotate(&self, rotate: bool) {
407 unsafe {
408 ffi::gtk_print_job_set_rotate(self.to_glib_none().0, rotate.into_glib());
409 }
410 }
411
412 /// Sets the scale for this job.
413 ///
414 /// 1.0 means unscaled.
415 /// ## `scale`
416 /// the scale
417 #[doc(alias = "gtk_print_job_set_scale")]
418 pub fn set_scale(&self, scale: f64) {
419 unsafe {
420 ffi::gtk_print_job_set_scale(self.to_glib_none().0, scale);
421 }
422 }
423
424 /// Make the [`PrintJob`][crate::PrintJob] send an existing document to the
425 /// printing system.
426 ///
427 /// The file can be in any format understood by the platforms
428 /// printing system (typically PostScript, but on many platforms
429 /// PDF may work too). See [`Printer::accepts_pdf()`][crate::Printer::accepts_pdf()] and
430 /// [`Printer::accepts_ps()`][crate::Printer::accepts_ps()].
431 ///
432 /// This is similar to [`set_source_file()`][Self::set_source_file()],
433 /// but takes expects an open file descriptor for the file,
434 /// instead of a filename.
435 /// ## `fd`
436 /// a file descriptor
437 ///
438 /// # Returns
439 ///
440 /// [`false`] if an error occurred
441 #[doc(alias = "gtk_print_job_set_source_fd")]
442 pub fn set_source_fd(&self, fd: i32) -> Result<(), glib::Error> {
443 unsafe {
444 let mut error = std::ptr::null_mut();
445 let is_ok = ffi::gtk_print_job_set_source_fd(self.to_glib_none().0, fd, &mut error);
446 debug_assert_eq!(is_ok == glib::ffi::GFALSE, !error.is_null());
447 if error.is_null() {
448 Ok(())
449 } else {
450 Err(from_glib_full(error))
451 }
452 }
453 }
454
455 /// Make the [`PrintJob`][crate::PrintJob] send an existing document to the
456 /// printing system.
457 ///
458 /// The file can be in any format understood by the platforms
459 /// printing system (typically PostScript, but on many platforms
460 /// PDF may work too). See [`Printer::accepts_pdf()`][crate::Printer::accepts_pdf()] and
461 /// [`Printer::accepts_ps()`][crate::Printer::accepts_ps()].
462 /// ## `filename`
463 /// the file to be printed
464 ///
465 /// # Returns
466 ///
467 /// [`false`] if an error occurred
468 #[doc(alias = "gtk_print_job_set_source_file")]
469 pub fn set_source_file(
470 &self,
471 filename: impl AsRef<std::path::Path>,
472 ) -> Result<(), glib::Error> {
473 unsafe {
474 let mut error = std::ptr::null_mut();
475 let is_ok = ffi::gtk_print_job_set_source_file(
476 self.to_glib_none().0,
477 filename.as_ref().to_glib_none().0,
478 &mut error,
479 );
480 debug_assert_eq!(is_ok == glib::ffi::GFALSE, !error.is_null());
481 if error.is_null() {
482 Ok(())
483 } else {
484 Err(from_glib_full(error))
485 }
486 }
487 }
488
489 /// If track_status is [`true`], the print job will try to continue report
490 /// on the status of the print job in the printer queues and printer.
491 ///
492 /// This can allow your application to show things like “out of paper”
493 /// issues, and when the print job actually reaches the printer.
494 ///
495 /// This function is often implemented using some form of polling,
496 /// so it should not be enabled unless needed.
497 /// ## `track_status`
498 /// [`true`] to track status after printing
499 #[doc(alias = "gtk_print_job_set_track_print_status")]
500 #[doc(alias = "track-print-status")]
501 pub fn set_track_print_status(&self, track_status: bool) {
502 unsafe {
503 ffi::gtk_print_job_set_track_print_status(
504 self.to_glib_none().0,
505 track_status.into_glib(),
506 );
507 }
508 }
509
510 /// Page setup.
511 #[doc(alias = "page-setup")]
512 pub fn page_setup(&self) -> Option<PageSetup> {
513 ObjectExt::property(self, "page-setup")
514 }
515
516 /// Emitted when the status of a job changes.
517 ///
518 /// The signal handler can use [`status()`][Self::status()]
519 /// to obtain the new status.
520 #[doc(alias = "status-changed")]
521 pub fn connect_status_changed<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
522 unsafe extern "C" fn status_changed_trampoline<F: Fn(&PrintJob) + 'static>(
523 this: *mut ffi::GtkPrintJob,
524 f: glib::ffi::gpointer,
525 ) {
526 let f: &F = &*(f as *const F);
527 f(&from_glib_borrow(this))
528 }
529 unsafe {
530 let f: Box_<F> = Box_::new(f);
531 connect_raw(
532 self.as_ptr() as *mut _,
533 b"status-changed\0".as_ptr() as *const _,
534 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
535 status_changed_trampoline::<F> as *const (),
536 )),
537 Box_::into_raw(f),
538 )
539 }
540 }
541
542 #[doc(alias = "track-print-status")]
543 pub fn connect_track_print_status_notify<F: Fn(&Self) + 'static>(
544 &self,
545 f: F,
546 ) -> SignalHandlerId {
547 unsafe extern "C" fn notify_track_print_status_trampoline<F: Fn(&PrintJob) + 'static>(
548 this: *mut ffi::GtkPrintJob,
549 _param_spec: glib::ffi::gpointer,
550 f: glib::ffi::gpointer,
551 ) {
552 let f: &F = &*(f as *const F);
553 f(&from_glib_borrow(this))
554 }
555 unsafe {
556 let f: Box_<F> = Box_::new(f);
557 connect_raw(
558 self.as_ptr() as *mut _,
559 b"notify::track-print-status\0".as_ptr() as *const _,
560 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
561 notify_track_print_status_trampoline::<F> as *const (),
562 )),
563 Box_::into_raw(f),
564 )
565 }
566 }
567}