gtk4/
print_job.rs

1// Take a look at the license at the top of the repository in the LICENSE file.
2
3use std::boxed::Box as Box_;
4
5use glib::translate::*;
6
7use crate::{ffi, PrintJob};
8
9impl PrintJob {
10    /// Sends the print job off to the printer.
11    /// ## `callback`
12    /// function
13    ///   to call when the job completes or an error occurs
14    #[doc(alias = "gtk_print_job_send")]
15    pub fn send<P: Fn(&PrintJob, Result<(), glib::Error>) + 'static>(&self, callback: P) {
16        let callback_data: Box_<P> = Box_::new(callback);
17        unsafe extern "C" fn callback_func<P: Fn(&PrintJob, Result<(), glib::Error>) + 'static>(
18            print_job: *mut ffi::GtkPrintJob,
19            user_data: glib::ffi::gpointer,
20            error: *const glib::ffi::GError,
21        ) {
22            let print_job = from_glib_borrow(print_job);
23            let result = if error.is_null() {
24                Ok(())
25            } else {
26                Err(from_glib_none(error))
27            };
28            let callback: &P = &*(user_data as *mut _);
29            (*callback)(&print_job, result);
30        }
31        let callback = Some(callback_func::<P> as _);
32        unsafe extern "C" fn dnotify_func<P>(data: glib::ffi::gpointer) {
33            let _callback: Box_<P> = Box_::from_raw(data as *mut _);
34        }
35        let destroy_call3 = Some(dnotify_func::<P> as _);
36        let super_callback0: Box_<P> = callback_data;
37        unsafe {
38            ffi::gtk_print_job_send(
39                self.to_glib_none().0,
40                callback,
41                Box_::into_raw(super_callback0) as *mut _,
42                destroy_call3,
43            );
44        }
45    }
46}