1use crate::ffi;
7use glib::{
8 object::ObjectType as _,
9 prelude::*,
10 signal::{connect_raw, SignalHandlerId},
11 translate::*,
12};
13use std::{boxed::Box as Box_, pin::Pin};
14
15glib::wrapper! {
16 #[doc(alias = "PanelSaveDelegate")]
17 pub struct SaveDelegate(Object<ffi::PanelSaveDelegate, ffi::PanelSaveDelegateClass>);
18
19 match fn {
20 type_ => || ffi::panel_save_delegate_get_type(),
21 }
22}
23
24impl SaveDelegate {
25 pub const NONE: Option<&'static SaveDelegate> = None;
26
27 #[doc(alias = "panel_save_delegate_new")]
28 pub fn new() -> SaveDelegate {
29 assert_initialized_main_thread!();
30 unsafe { from_glib_full(ffi::panel_save_delegate_new()) }
31 }
32
33 pub fn builder() -> SaveDelegateBuilder {
38 SaveDelegateBuilder::new()
39 }
40}
41
42impl Default for SaveDelegate {
43 fn default() -> Self {
44 Self::new()
45 }
46}
47
48#[must_use = "The builder must be built to be used"]
53pub struct SaveDelegateBuilder {
54 builder: glib::object::ObjectBuilder<'static, SaveDelegate>,
55}
56
57impl SaveDelegateBuilder {
58 fn new() -> Self {
59 Self {
60 builder: glib::object::Object::builder(),
61 }
62 }
63
64 pub fn icon(self, icon: &impl IsA<gio::Icon>) -> Self {
65 Self {
66 builder: self.builder.property("icon", icon.clone().upcast()),
67 }
68 }
69
70 pub fn icon_name(self, icon_name: impl Into<glib::GString>) -> Self {
71 Self {
72 builder: self.builder.property("icon-name", icon_name.into()),
73 }
74 }
75
76 pub fn is_draft(self, is_draft: bool) -> Self {
77 Self {
78 builder: self.builder.property("is-draft", is_draft),
79 }
80 }
81
82 pub fn progress(self, progress: f64) -> Self {
83 Self {
84 builder: self.builder.property("progress", progress),
85 }
86 }
87
88 pub fn subtitle(self, subtitle: impl Into<glib::GString>) -> Self {
89 Self {
90 builder: self.builder.property("subtitle", subtitle.into()),
91 }
92 }
93
94 pub fn title(self, title: impl Into<glib::GString>) -> Self {
95 Self {
96 builder: self.builder.property("title", title.into()),
97 }
98 }
99
100 #[must_use = "Building the object from the builder is usually expensive and is not expected to have side effects"]
103 pub fn build(self) -> SaveDelegate {
104 assert_initialized_main_thread!();
105 self.builder.build()
106 }
107}
108
109pub trait SaveDelegateExt: IsA<SaveDelegate> + 'static {
110 #[doc(alias = "panel_save_delegate_close")]
111 fn close(&self) {
112 unsafe {
113 ffi::panel_save_delegate_close(self.as_ref().to_glib_none().0);
114 }
115 }
116
117 #[doc(alias = "panel_save_delegate_discard")]
118 fn discard(&self) {
119 unsafe {
120 ffi::panel_save_delegate_discard(self.as_ref().to_glib_none().0);
121 }
122 }
123
124 #[doc(alias = "panel_save_delegate_get_icon")]
125 #[doc(alias = "get_icon")]
126 fn icon(&self) -> Option<gio::Icon> {
127 unsafe {
128 from_glib_none(ffi::panel_save_delegate_get_icon(
129 self.as_ref().to_glib_none().0,
130 ))
131 }
132 }
133
134 #[doc(alias = "panel_save_delegate_get_icon_name")]
135 #[doc(alias = "get_icon_name")]
136 #[doc(alias = "icon-name")]
137 fn icon_name(&self) -> Option<glib::GString> {
138 unsafe {
139 from_glib_none(ffi::panel_save_delegate_get_icon_name(
140 self.as_ref().to_glib_none().0,
141 ))
142 }
143 }
144
145 #[doc(alias = "panel_save_delegate_get_is_draft")]
146 #[doc(alias = "get_is_draft")]
147 #[doc(alias = "is-draft")]
148 fn is_draft(&self) -> bool {
149 unsafe {
150 from_glib(ffi::panel_save_delegate_get_is_draft(
151 self.as_ref().to_glib_none().0,
152 ))
153 }
154 }
155
156 #[doc(alias = "panel_save_delegate_get_progress")]
157 #[doc(alias = "get_progress")]
158 fn progress(&self) -> f64 {
159 unsafe { ffi::panel_save_delegate_get_progress(self.as_ref().to_glib_none().0) }
160 }
161
162 #[doc(alias = "panel_save_delegate_get_subtitle")]
163 #[doc(alias = "get_subtitle")]
164 fn subtitle(&self) -> Option<glib::GString> {
165 unsafe {
166 from_glib_none(ffi::panel_save_delegate_get_subtitle(
167 self.as_ref().to_glib_none().0,
168 ))
169 }
170 }
171
172 #[doc(alias = "panel_save_delegate_get_title")]
173 #[doc(alias = "get_title")]
174 fn title(&self) -> Option<glib::GString> {
175 unsafe {
176 from_glib_none(ffi::panel_save_delegate_get_title(
177 self.as_ref().to_glib_none().0,
178 ))
179 }
180 }
181
182 #[doc(alias = "panel_save_delegate_save_async")]
183 fn save_async<P: FnOnce(Result<(), glib::Error>) + 'static>(
184 &self,
185 cancellable: Option<&impl IsA<gio::Cancellable>>,
186 callback: P,
187 ) {
188 let main_context = glib::MainContext::ref_thread_default();
189 let is_main_context_owner = main_context.is_owner();
190 let has_acquired_main_context = (!is_main_context_owner)
191 .then(|| main_context.acquire().ok())
192 .flatten();
193 assert!(
194 is_main_context_owner || has_acquired_main_context.is_some(),
195 "Async operations only allowed if the thread is owning the MainContext"
196 );
197
198 let user_data: Box_<glib::thread_guard::ThreadGuard<P>> =
199 Box_::new(glib::thread_guard::ThreadGuard::new(callback));
200 unsafe extern "C" fn save_async_trampoline<P: FnOnce(Result<(), glib::Error>) + 'static>(
201 _source_object: *mut glib::gobject_ffi::GObject,
202 res: *mut gio::ffi::GAsyncResult,
203 user_data: glib::ffi::gpointer,
204 ) {
205 let mut error = std::ptr::null_mut();
206 ffi::panel_save_delegate_save_finish(_source_object as *mut _, res, &mut error);
207 let result = if error.is_null() {
208 Ok(())
209 } else {
210 Err(from_glib_full(error))
211 };
212 let callback: Box_<glib::thread_guard::ThreadGuard<P>> =
213 Box_::from_raw(user_data as *mut _);
214 let callback: P = callback.into_inner();
215 callback(result);
216 }
217 let callback = save_async_trampoline::<P>;
218 unsafe {
219 ffi::panel_save_delegate_save_async(
220 self.as_ref().to_glib_none().0,
221 cancellable.map(|p| p.as_ref()).to_glib_none().0,
222 Some(callback),
223 Box_::into_raw(user_data) as *mut _,
224 );
225 }
226 }
227
228 fn save_future(
229 &self,
230 ) -> Pin<Box_<dyn std::future::Future<Output = Result<(), glib::Error>> + 'static>> {
231 Box_::pin(gio::GioFuture::new(self, move |obj, cancellable, send| {
232 obj.save_async(Some(cancellable), move |res| {
233 send.resolve(res);
234 });
235 }))
236 }
237
238 #[doc(alias = "panel_save_delegate_set_icon")]
239 #[doc(alias = "icon")]
240 fn set_icon(&self, icon: Option<&impl IsA<gio::Icon>>) {
241 unsafe {
242 ffi::panel_save_delegate_set_icon(
243 self.as_ref().to_glib_none().0,
244 icon.map(|p| p.as_ref()).to_glib_none().0,
245 );
246 }
247 }
248
249 #[doc(alias = "panel_save_delegate_set_icon_name")]
250 #[doc(alias = "icon-name")]
251 fn set_icon_name(&self, icon: Option<&str>) {
252 unsafe {
253 ffi::panel_save_delegate_set_icon_name(
254 self.as_ref().to_glib_none().0,
255 icon.to_glib_none().0,
256 );
257 }
258 }
259
260 #[doc(alias = "panel_save_delegate_set_is_draft")]
261 #[doc(alias = "is-draft")]
262 fn set_is_draft(&self, is_draft: bool) {
263 unsafe {
264 ffi::panel_save_delegate_set_is_draft(
265 self.as_ref().to_glib_none().0,
266 is_draft.into_glib(),
267 );
268 }
269 }
270
271 #[doc(alias = "panel_save_delegate_set_progress")]
272 #[doc(alias = "progress")]
273 fn set_progress(&self, progress: f64) {
274 unsafe {
275 ffi::panel_save_delegate_set_progress(self.as_ref().to_glib_none().0, progress);
276 }
277 }
278
279 #[doc(alias = "panel_save_delegate_set_subtitle")]
280 #[doc(alias = "subtitle")]
281 fn set_subtitle(&self, subtitle: Option<&str>) {
282 unsafe {
283 ffi::panel_save_delegate_set_subtitle(
284 self.as_ref().to_glib_none().0,
285 subtitle.to_glib_none().0,
286 );
287 }
288 }
289
290 #[doc(alias = "panel_save_delegate_set_title")]
291 #[doc(alias = "title")]
292 fn set_title(&self, title: Option<&str>) {
293 unsafe {
294 ffi::panel_save_delegate_set_title(
295 self.as_ref().to_glib_none().0,
296 title.to_glib_none().0,
297 );
298 }
299 }
300
301 #[doc(alias = "close")]
302 fn connect_close<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
303 unsafe extern "C" fn close_trampoline<P: IsA<SaveDelegate>, F: Fn(&P) + 'static>(
304 this: *mut ffi::PanelSaveDelegate,
305 f: glib::ffi::gpointer,
306 ) {
307 let f: &F = &*(f as *const F);
308 f(SaveDelegate::from_glib_borrow(this).unsafe_cast_ref())
309 }
310 unsafe {
311 let f: Box_<F> = Box_::new(f);
312 connect_raw(
313 self.as_ptr() as *mut _,
314 c"close".as_ptr() as *const _,
315 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
316 close_trampoline::<Self, F> as *const (),
317 )),
318 Box_::into_raw(f),
319 )
320 }
321 }
322
323 #[doc(alias = "discard")]
324 fn connect_discard<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
325 unsafe extern "C" fn discard_trampoline<P: IsA<SaveDelegate>, F: Fn(&P) + 'static>(
326 this: *mut ffi::PanelSaveDelegate,
327 f: glib::ffi::gpointer,
328 ) {
329 let f: &F = &*(f as *const F);
330 f(SaveDelegate::from_glib_borrow(this).unsafe_cast_ref())
331 }
332 unsafe {
333 let f: Box_<F> = Box_::new(f);
334 connect_raw(
335 self.as_ptr() as *mut _,
336 c"discard".as_ptr() as *const _,
337 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
338 discard_trampoline::<Self, F> as *const (),
339 )),
340 Box_::into_raw(f),
341 )
342 }
343 }
344
345 #[doc(alias = "icon")]
346 fn connect_icon_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
347 unsafe extern "C" fn notify_icon_trampoline<P: IsA<SaveDelegate>, F: Fn(&P) + 'static>(
348 this: *mut ffi::PanelSaveDelegate,
349 _param_spec: glib::ffi::gpointer,
350 f: glib::ffi::gpointer,
351 ) {
352 let f: &F = &*(f as *const F);
353 f(SaveDelegate::from_glib_borrow(this).unsafe_cast_ref())
354 }
355 unsafe {
356 let f: Box_<F> = Box_::new(f);
357 connect_raw(
358 self.as_ptr() as *mut _,
359 c"notify::icon".as_ptr() as *const _,
360 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
361 notify_icon_trampoline::<Self, F> as *const (),
362 )),
363 Box_::into_raw(f),
364 )
365 }
366 }
367
368 #[doc(alias = "icon-name")]
369 fn connect_icon_name_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
370 unsafe extern "C" fn notify_icon_name_trampoline<
371 P: IsA<SaveDelegate>,
372 F: Fn(&P) + 'static,
373 >(
374 this: *mut ffi::PanelSaveDelegate,
375 _param_spec: glib::ffi::gpointer,
376 f: glib::ffi::gpointer,
377 ) {
378 let f: &F = &*(f as *const F);
379 f(SaveDelegate::from_glib_borrow(this).unsafe_cast_ref())
380 }
381 unsafe {
382 let f: Box_<F> = Box_::new(f);
383 connect_raw(
384 self.as_ptr() as *mut _,
385 c"notify::icon-name".as_ptr() as *const _,
386 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
387 notify_icon_name_trampoline::<Self, F> as *const (),
388 )),
389 Box_::into_raw(f),
390 )
391 }
392 }
393
394 #[doc(alias = "is-draft")]
395 fn connect_is_draft_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
396 unsafe extern "C" fn notify_is_draft_trampoline<
397 P: IsA<SaveDelegate>,
398 F: Fn(&P) + 'static,
399 >(
400 this: *mut ffi::PanelSaveDelegate,
401 _param_spec: glib::ffi::gpointer,
402 f: glib::ffi::gpointer,
403 ) {
404 let f: &F = &*(f as *const F);
405 f(SaveDelegate::from_glib_borrow(this).unsafe_cast_ref())
406 }
407 unsafe {
408 let f: Box_<F> = Box_::new(f);
409 connect_raw(
410 self.as_ptr() as *mut _,
411 c"notify::is-draft".as_ptr() as *const _,
412 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
413 notify_is_draft_trampoline::<Self, F> as *const (),
414 )),
415 Box_::into_raw(f),
416 )
417 }
418 }
419
420 #[doc(alias = "progress")]
421 fn connect_progress_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
422 unsafe extern "C" fn notify_progress_trampoline<
423 P: IsA<SaveDelegate>,
424 F: Fn(&P) + 'static,
425 >(
426 this: *mut ffi::PanelSaveDelegate,
427 _param_spec: glib::ffi::gpointer,
428 f: glib::ffi::gpointer,
429 ) {
430 let f: &F = &*(f as *const F);
431 f(SaveDelegate::from_glib_borrow(this).unsafe_cast_ref())
432 }
433 unsafe {
434 let f: Box_<F> = Box_::new(f);
435 connect_raw(
436 self.as_ptr() as *mut _,
437 c"notify::progress".as_ptr() as *const _,
438 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
439 notify_progress_trampoline::<Self, F> as *const (),
440 )),
441 Box_::into_raw(f),
442 )
443 }
444 }
445
446 #[doc(alias = "subtitle")]
447 fn connect_subtitle_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
448 unsafe extern "C" fn notify_subtitle_trampoline<
449 P: IsA<SaveDelegate>,
450 F: Fn(&P) + 'static,
451 >(
452 this: *mut ffi::PanelSaveDelegate,
453 _param_spec: glib::ffi::gpointer,
454 f: glib::ffi::gpointer,
455 ) {
456 let f: &F = &*(f as *const F);
457 f(SaveDelegate::from_glib_borrow(this).unsafe_cast_ref())
458 }
459 unsafe {
460 let f: Box_<F> = Box_::new(f);
461 connect_raw(
462 self.as_ptr() as *mut _,
463 c"notify::subtitle".as_ptr() as *const _,
464 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
465 notify_subtitle_trampoline::<Self, F> as *const (),
466 )),
467 Box_::into_raw(f),
468 )
469 }
470 }
471
472 #[doc(alias = "title")]
473 fn connect_title_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
474 unsafe extern "C" fn notify_title_trampoline<P: IsA<SaveDelegate>, F: Fn(&P) + 'static>(
475 this: *mut ffi::PanelSaveDelegate,
476 _param_spec: glib::ffi::gpointer,
477 f: glib::ffi::gpointer,
478 ) {
479 let f: &F = &*(f as *const F);
480 f(SaveDelegate::from_glib_borrow(this).unsafe_cast_ref())
481 }
482 unsafe {
483 let f: Box_<F> = Box_::new(f);
484 connect_raw(
485 self.as_ptr() as *mut _,
486 c"notify::title".as_ptr() as *const _,
487 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
488 notify_title_trampoline::<Self, F> as *const (),
489 )),
490 Box_::into_raw(f),
491 )
492 }
493 }
494}
495
496impl<O: IsA<SaveDelegate>> SaveDelegateExt for O {}