1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
// This file was generated by gir (https://github.com/gtk-rs/gir)
// from gir-files (https://github.com/gtk-rs/gir-files)
// from webkit-gir-files
// DO NOT EDIT

use crate::{ffi, PrintOperationResponse, WebView};
use glib::{
    prelude::*,
    signal::{connect_raw, SignalHandlerId},
    translate::*,
};
use std::boxed::Box as Box_;

glib::wrapper! {
    /// Controls a print operation.
    ///
    /// A #WebKitPrintOperation controls a print operation in WebKit. With
    /// a similar API to #GtkPrintOperation, it lets you set the print
    /// settings with webkit_print_operation_set_print_settings() or
    /// display the print dialog with webkit_print_operation_run_dialog().
    ///
    /// ## Properties
    ///
    ///
    /// #### `page-setup`
    ///  The initial #GtkPageSetup for the print operation.
    ///
    /// Readable | Writeable
    ///
    ///
    /// #### `print-settings`
    ///  The initial #GtkPrintSettings for the print operation.
    ///
    /// Readable | Writeable
    ///
    ///
    /// #### `web-view`
    ///  The #WebKitWebView that will be printed.
    ///
    /// Readable | Writeable | Construct Only
    ///
    /// ## Signals
    ///
    ///
    /// #### `failed`
    ///  Emitted when an error occurs while printing. The given @error, of the domain
    /// `WEBKIT_PRINT_ERROR`, contains further details of the failure.
    /// The #WebKitPrintOperation::finished signal is emitted after this one.
    ///
    ///
    ///
    ///
    /// #### `finished`
    ///  Emitted when the print operation has finished doing everything
    /// required for printing.
    ///
    ///
    #[doc(alias = "WebKitPrintOperation")]
    pub struct PrintOperation(Object<ffi::WebKitPrintOperation, ffi::WebKitPrintOperationClass>);

    match fn {
        type_ => || ffi::webkit_print_operation_get_type(),
    }
}

impl PrintOperation {
    /// Create a new #WebKitPrintOperation to print @web_view contents.
    /// ## `web_view`
    /// a #WebKitWebView
    ///
    /// # Returns
    ///
    /// a new #WebKitPrintOperation.
    #[doc(alias = "webkit_print_operation_new")]
    pub fn new(web_view: &impl IsA<WebView>) -> PrintOperation {
        skip_assert_initialized!();
        unsafe {
            from_glib_full(ffi::webkit_print_operation_new(
                web_view.as_ref().to_glib_none().0,
            ))
        }
    }

    // rustdoc-stripper-ignore-next
    /// Creates a new builder-pattern struct instance to construct [`PrintOperation`] objects.
    ///
    /// This method returns an instance of [`PrintOperationBuilder`](crate::builders::PrintOperationBuilder) which can be used to create [`PrintOperation`] objects.
    pub fn builder() -> PrintOperationBuilder {
        PrintOperationBuilder::new()
    }

    /// Return the current page setup of @self.
    ///
    /// It returns [`None`] until
    /// either webkit_print_operation_set_page_setup() or webkit_print_operation_run_dialog()
    /// have been called.
    ///
    /// # Returns
    ///
    /// the current #GtkPageSetup of @self.
    #[doc(alias = "webkit_print_operation_get_page_setup")]
    #[doc(alias = "get_page_setup")]
    #[doc(alias = "page-setup")]
    pub fn page_setup(&self) -> Option<gtk::PageSetup> {
        unsafe {
            from_glib_none(ffi::webkit_print_operation_get_page_setup(
                self.to_glib_none().0,
            ))
        }
    }

    /// Return the current print settings of @self.
    ///
    /// It returns [`None`] until
    /// either webkit_print_operation_set_print_settings() or webkit_print_operation_run_dialog()
    /// have been called.
    ///
    /// # Returns
    ///
    /// the current #GtkPrintSettings of @self.
    #[doc(alias = "webkit_print_operation_get_print_settings")]
    #[doc(alias = "get_print_settings")]
    #[doc(alias = "print-settings")]
    pub fn print_settings(&self) -> Option<gtk::PrintSettings> {
        unsafe {
            from_glib_none(ffi::webkit_print_operation_get_print_settings(
                self.to_glib_none().0,
            ))
        }
    }

    /// Start a print operation using current print settings and page setup.
    ///
    /// Start a print operation using current print settings and page setup
    /// without showing the print dialog. If either print settings or page setup
    /// are not set with webkit_print_operation_set_print_settings() and
    /// webkit_print_operation_set_page_setup(), the default options will be used
    /// and the print job will be sent to the default printer.
    /// The #WebKitPrintOperation::finished signal is emitted when the printing
    /// operation finishes. If an error occurs while printing the signal
    /// #WebKitPrintOperation::failed is emitted before #WebKitPrintOperation::finished.
    ///
    /// If the app is running in a sandbox, this function only works if printing to
    /// a file that is in a location accessible to the sandbox, usually acquired
    /// through the File Chooser portal. This function will not work for physical
    /// printers when running in a sandbox.
    #[doc(alias = "webkit_print_operation_print")]
    pub fn print(&self) {
        unsafe {
            ffi::webkit_print_operation_print(self.to_glib_none().0);
        }
    }

    /// Run the print dialog and start printing.
    ///
    /// Run the print dialog and start printing using the options selected by
    /// the user. This method returns when the print dialog is closed.
    /// If the print dialog is cancelled [`PrintOperationResponse::Cancel`][crate::PrintOperationResponse::Cancel]
    /// is returned. If the user clicks on the print button, [`PrintOperationResponse::Print`][crate::PrintOperationResponse::Print]
    /// is returned and the print operation starts. In this case, the #WebKitPrintOperation::finished
    /// signal is emitted when the operation finishes. If an error occurs while printing, the signal
    /// #WebKitPrintOperation::failed is emitted before #WebKitPrintOperation::finished.
    /// If the print dialog is not cancelled current print settings and page setup of @self
    /// are updated with options selected by the user when Print button is pressed in print dialog.
    /// You can get the updated print settings and page setup by calling
    /// webkit_print_operation_get_print_settings() and webkit_print_operation_get_page_setup()
    /// after this method.
    /// ## `parent`
    /// transient parent of the print dialog
    ///
    /// # Returns
    ///
    /// the #WebKitPrintOperationResponse of the print dialog
    #[doc(alias = "webkit_print_operation_run_dialog")]
    pub fn run_dialog(&self, parent: Option<&impl IsA<gtk::Window>>) -> PrintOperationResponse {
        unsafe {
            from_glib(ffi::webkit_print_operation_run_dialog(
                self.to_glib_none().0,
                parent.map(|p| p.as_ref()).to_glib_none().0,
            ))
        }
    }

    /// Set the current page setup of @self.
    ///
    /// Current page setup is used for the
    /// initial values of the print dialog when webkit_print_operation_run_dialog() is called.
    /// ## `page_setup`
    /// a #GtkPageSetup to set
    #[doc(alias = "webkit_print_operation_set_page_setup")]
    #[doc(alias = "page-setup")]
    pub fn set_page_setup(&self, page_setup: &gtk::PageSetup) {
        unsafe {
            ffi::webkit_print_operation_set_page_setup(
                self.to_glib_none().0,
                page_setup.to_glib_none().0,
            );
        }
    }

    /// Set the current print settings of @self.
    ///
    /// Set the current print settings of @self. Current print settings are used for
    /// the initial values of the print dialog when webkit_print_operation_run_dialog() is called.
    /// ## `print_settings`
    /// a #GtkPrintSettings to set
    #[doc(alias = "webkit_print_operation_set_print_settings")]
    #[doc(alias = "print-settings")]
    pub fn set_print_settings(&self, print_settings: &gtk::PrintSettings) {
        unsafe {
            ffi::webkit_print_operation_set_print_settings(
                self.to_glib_none().0,
                print_settings.to_glib_none().0,
            );
        }
    }

    /// The #WebKitWebView that will be printed.
    #[doc(alias = "web-view")]
    pub fn web_view(&self) -> Option<WebView> {
        ObjectExt::property(self, "web-view")
    }

    /// Emitted when an error occurs while printing. The given @error, of the domain
    /// `WEBKIT_PRINT_ERROR`, contains further details of the failure.
    /// The #WebKitPrintOperation::finished signal is emitted after this one.
    /// ## `error`
    /// the #GError that was triggered
    #[doc(alias = "failed")]
    pub fn connect_failed<F: Fn(&Self, &glib::Error) + 'static>(&self, f: F) -> SignalHandlerId {
        unsafe extern "C" fn failed_trampoline<F: Fn(&PrintOperation, &glib::Error) + 'static>(
            this: *mut ffi::WebKitPrintOperation,
            error: *mut glib::ffi::GError,
            f: glib::ffi::gpointer,
        ) {
            let f: &F = &*(f as *const F);
            f(&from_glib_borrow(this), &from_glib_borrow(error))
        }
        unsafe {
            let f: Box_<F> = Box_::new(f);
            connect_raw(
                self.as_ptr() as *mut _,
                b"failed\0".as_ptr() as *const _,
                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
                    failed_trampoline::<F> as *const (),
                )),
                Box_::into_raw(f),
            )
        }
    }

    /// Emitted when the print operation has finished doing everything
    /// required for printing.
    #[doc(alias = "finished")]
    pub fn connect_finished<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
        unsafe extern "C" fn finished_trampoline<F: Fn(&PrintOperation) + 'static>(
            this: *mut ffi::WebKitPrintOperation,
            f: glib::ffi::gpointer,
        ) {
            let f: &F = &*(f as *const F);
            f(&from_glib_borrow(this))
        }
        unsafe {
            let f: Box_<F> = Box_::new(f);
            connect_raw(
                self.as_ptr() as *mut _,
                b"finished\0".as_ptr() as *const _,
                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
                    finished_trampoline::<F> as *const (),
                )),
                Box_::into_raw(f),
            )
        }
    }

    #[doc(alias = "page-setup")]
    pub fn connect_page_setup_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
        unsafe extern "C" fn notify_page_setup_trampoline<F: Fn(&PrintOperation) + 'static>(
            this: *mut ffi::WebKitPrintOperation,
            _param_spec: glib::ffi::gpointer,
            f: glib::ffi::gpointer,
        ) {
            let f: &F = &*(f as *const F);
            f(&from_glib_borrow(this))
        }
        unsafe {
            let f: Box_<F> = Box_::new(f);
            connect_raw(
                self.as_ptr() as *mut _,
                b"notify::page-setup\0".as_ptr() as *const _,
                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
                    notify_page_setup_trampoline::<F> as *const (),
                )),
                Box_::into_raw(f),
            )
        }
    }

    #[doc(alias = "print-settings")]
    pub fn connect_print_settings_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
        unsafe extern "C" fn notify_print_settings_trampoline<F: Fn(&PrintOperation) + 'static>(
            this: *mut ffi::WebKitPrintOperation,
            _param_spec: glib::ffi::gpointer,
            f: glib::ffi::gpointer,
        ) {
            let f: &F = &*(f as *const F);
            f(&from_glib_borrow(this))
        }
        unsafe {
            let f: Box_<F> = Box_::new(f);
            connect_raw(
                self.as_ptr() as *mut _,
                b"notify::print-settings\0".as_ptr() as *const _,
                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
                    notify_print_settings_trampoline::<F> as *const (),
                )),
                Box_::into_raw(f),
            )
        }
    }
}

impl Default for PrintOperation {
    fn default() -> Self {
        glib::object::Object::new::<Self>()
    }
}

// rustdoc-stripper-ignore-next
/// A [builder-pattern] type to construct [`PrintOperation`] objects.
///
/// [builder-pattern]: https://doc.rust-lang.org/1.0.0/style/ownership/builders.html
#[must_use = "The builder must be built to be used"]
pub struct PrintOperationBuilder {
    builder: glib::object::ObjectBuilder<'static, PrintOperation>,
}

impl PrintOperationBuilder {
    fn new() -> Self {
        Self {
            builder: glib::object::Object::builder(),
        }
    }

    /// The initial #GtkPageSetup for the print operation.
    pub fn page_setup(self, page_setup: &gtk::PageSetup) -> Self {
        Self {
            builder: self.builder.property("page-setup", page_setup.clone()),
        }
    }

    /// The initial #GtkPrintSettings for the print operation.
    pub fn print_settings(self, print_settings: &gtk::PrintSettings) -> Self {
        Self {
            builder: self
                .builder
                .property("print-settings", print_settings.clone()),
        }
    }

    /// The #WebKitWebView that will be printed.
    pub fn web_view(self, web_view: &impl IsA<WebView>) -> Self {
        Self {
            builder: self.builder.property("web-view", web_view.clone().upcast()),
        }
    }

    // rustdoc-stripper-ignore-next
    /// Build the [`PrintOperation`].
    #[must_use = "Building the object from the builder is usually expensive and is not expected to have side effects"]
    pub fn build(self) -> PrintOperation {
        self.builder.build()
    }
}