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")]
113 pub struct SaveDelegate(Object<ffi::PanelSaveDelegate, ffi::PanelSaveDelegateClass>);
114
115 match fn {
116 type_ => || ffi::panel_save_delegate_get_type(),
117 }
118}
119
120impl SaveDelegate {
121 pub const NONE: Option<&'static SaveDelegate> = None;
122
123 #[doc(alias = "panel_save_delegate_new")]
129 pub fn new() -> SaveDelegate {
130 assert_initialized_main_thread!();
131 unsafe { from_glib_full(ffi::panel_save_delegate_new()) }
132 }
133
134 pub fn builder() -> SaveDelegateBuilder {
139 SaveDelegateBuilder::new()
140 }
141}
142
143impl Default for SaveDelegate {
144 fn default() -> Self {
145 Self::new()
146 }
147}
148
149#[must_use = "The builder must be built to be used"]
154pub struct SaveDelegateBuilder {
155 builder: glib::object::ObjectBuilder<'static, SaveDelegate>,
156}
157
158impl SaveDelegateBuilder {
159 fn new() -> Self {
160 Self {
161 builder: glib::object::Object::builder(),
162 }
163 }
164
165 pub fn icon(self, icon: &impl IsA<gio::Icon>) -> Self {
172 Self {
173 builder: self.builder.property("icon", icon.clone().upcast()),
174 }
175 }
176
177 pub fn icon_name(self, icon_name: impl Into<glib::GString>) -> Self {
184 Self {
185 builder: self.builder.property("icon-name", icon_name.into()),
186 }
187 }
188
189 pub fn is_draft(self, is_draft: bool) -> Self {
192 Self {
193 builder: self.builder.property("is-draft", is_draft),
194 }
195 }
196
197 pub fn progress(self, progress: f64) -> Self {
200 Self {
201 builder: self.builder.property("progress", progress),
202 }
203 }
204
205 pub fn subtitle(self, subtitle: impl Into<glib::GString>) -> Self {
209 Self {
210 builder: self.builder.property("subtitle", subtitle.into()),
211 }
212 }
213
214 pub fn title(self, title: impl Into<glib::GString>) -> Self {
218 Self {
219 builder: self.builder.property("title", title.into()),
220 }
221 }
222
223 #[must_use = "Building the object from the builder is usually expensive and is not expected to have side effects"]
226 pub fn build(self) -> SaveDelegate {
227 assert_initialized_main_thread!();
228 self.builder.build()
229 }
230}
231
232pub trait SaveDelegateExt: IsA<SaveDelegate> + 'static {
238 #[doc(alias = "panel_save_delegate_close")]
239 fn close(&self) {
240 unsafe {
241 ffi::panel_save_delegate_close(self.as_ref().to_glib_none().0);
242 }
243 }
244
245 #[doc(alias = "panel_save_delegate_discard")]
246 fn discard(&self) {
247 unsafe {
248 ffi::panel_save_delegate_discard(self.as_ref().to_glib_none().0);
249 }
250 }
251
252 #[doc(alias = "panel_save_delegate_get_icon")]
258 #[doc(alias = "get_icon")]
259 fn icon(&self) -> Option<gio::Icon> {
260 unsafe {
261 from_glib_none(ffi::panel_save_delegate_get_icon(
262 self.as_ref().to_glib_none().0,
263 ))
264 }
265 }
266
267 #[doc(alias = "panel_save_delegate_get_icon_name")]
273 #[doc(alias = "get_icon_name")]
274 #[doc(alias = "icon-name")]
275 fn icon_name(&self) -> Option<glib::GString> {
276 unsafe {
277 from_glib_none(ffi::panel_save_delegate_get_icon_name(
278 self.as_ref().to_glib_none().0,
279 ))
280 }
281 }
282
283 #[doc(alias = "panel_save_delegate_get_is_draft")]
284 #[doc(alias = "get_is_draft")]
285 #[doc(alias = "is-draft")]
286 fn is_draft(&self) -> bool {
287 unsafe {
288 from_glib(ffi::panel_save_delegate_get_is_draft(
289 self.as_ref().to_glib_none().0,
290 ))
291 }
292 }
293
294 #[doc(alias = "panel_save_delegate_get_progress")]
295 #[doc(alias = "get_progress")]
296 fn progress(&self) -> f64 {
297 unsafe { ffi::panel_save_delegate_get_progress(self.as_ref().to_glib_none().0) }
298 }
299
300 #[doc(alias = "panel_save_delegate_get_subtitle")]
306 #[doc(alias = "get_subtitle")]
307 fn subtitle(&self) -> Option<glib::GString> {
308 unsafe {
309 from_glib_none(ffi::panel_save_delegate_get_subtitle(
310 self.as_ref().to_glib_none().0,
311 ))
312 }
313 }
314
315 #[doc(alias = "panel_save_delegate_get_title")]
321 #[doc(alias = "get_title")]
322 fn title(&self) -> Option<glib::GString> {
323 unsafe {
324 from_glib_none(ffi::panel_save_delegate_get_title(
325 self.as_ref().to_glib_none().0,
326 ))
327 }
328 }
329
330 #[doc(alias = "panel_save_delegate_save_async")]
331 fn save_async<P: FnOnce(Result<(), glib::Error>) + 'static>(
332 &self,
333 cancellable: Option<&impl IsA<gio::Cancellable>>,
334 callback: P,
335 ) {
336 let main_context = glib::MainContext::ref_thread_default();
337 let is_main_context_owner = main_context.is_owner();
338 let has_acquired_main_context = (!is_main_context_owner)
339 .then(|| main_context.acquire().ok())
340 .flatten();
341 assert!(
342 is_main_context_owner || has_acquired_main_context.is_some(),
343 "Async operations only allowed if the thread is owning the MainContext"
344 );
345
346 let user_data: Box_<glib::thread_guard::ThreadGuard<P>> =
347 Box_::new(glib::thread_guard::ThreadGuard::new(callback));
348 unsafe extern "C" fn save_async_trampoline<P: FnOnce(Result<(), glib::Error>) + 'static>(
349 _source_object: *mut glib::gobject_ffi::GObject,
350 res: *mut gio::ffi::GAsyncResult,
351 user_data: glib::ffi::gpointer,
352 ) {
353 let mut error = std::ptr::null_mut();
354 ffi::panel_save_delegate_save_finish(_source_object as *mut _, res, &mut error);
355 let result = if error.is_null() {
356 Ok(())
357 } else {
358 Err(from_glib_full(error))
359 };
360 let callback: Box_<glib::thread_guard::ThreadGuard<P>> =
361 Box_::from_raw(user_data as *mut _);
362 let callback: P = callback.into_inner();
363 callback(result);
364 }
365 let callback = save_async_trampoline::<P>;
366 unsafe {
367 ffi::panel_save_delegate_save_async(
368 self.as_ref().to_glib_none().0,
369 cancellable.map(|p| p.as_ref()).to_glib_none().0,
370 Some(callback),
371 Box_::into_raw(user_data) as *mut _,
372 );
373 }
374 }
375
376 fn save_future(
377 &self,
378 ) -> Pin<Box_<dyn std::future::Future<Output = Result<(), glib::Error>> + 'static>> {
379 Box_::pin(gio::GioFuture::new(self, move |obj, cancellable, send| {
380 obj.save_async(Some(cancellable), move |res| {
381 send.resolve(res);
382 });
383 }))
384 }
385
386 #[doc(alias = "panel_save_delegate_set_icon")]
390 #[doc(alias = "icon")]
391 fn set_icon(&self, icon: Option<&impl IsA<gio::Icon>>) {
392 unsafe {
393 ffi::panel_save_delegate_set_icon(
394 self.as_ref().to_glib_none().0,
395 icon.map(|p| p.as_ref()).to_glib_none().0,
396 );
397 }
398 }
399
400 #[doc(alias = "panel_save_delegate_set_icon_name")]
404 #[doc(alias = "icon-name")]
405 fn set_icon_name(&self, icon: Option<&str>) {
406 unsafe {
407 ffi::panel_save_delegate_set_icon_name(
408 self.as_ref().to_glib_none().0,
409 icon.to_glib_none().0,
410 );
411 }
412 }
413
414 #[doc(alias = "panel_save_delegate_set_is_draft")]
415 #[doc(alias = "is-draft")]
416 fn set_is_draft(&self, is_draft: bool) {
417 unsafe {
418 ffi::panel_save_delegate_set_is_draft(
419 self.as_ref().to_glib_none().0,
420 is_draft.into_glib(),
421 );
422 }
423 }
424
425 #[doc(alias = "panel_save_delegate_set_progress")]
426 #[doc(alias = "progress")]
427 fn set_progress(&self, progress: f64) {
428 unsafe {
429 ffi::panel_save_delegate_set_progress(self.as_ref().to_glib_none().0, progress);
430 }
431 }
432
433 #[doc(alias = "panel_save_delegate_set_subtitle")]
437 #[doc(alias = "subtitle")]
438 fn set_subtitle(&self, subtitle: Option<&str>) {
439 unsafe {
440 ffi::panel_save_delegate_set_subtitle(
441 self.as_ref().to_glib_none().0,
442 subtitle.to_glib_none().0,
443 );
444 }
445 }
446
447 #[doc(alias = "panel_save_delegate_set_title")]
451 #[doc(alias = "title")]
452 fn set_title(&self, title: Option<&str>) {
453 unsafe {
454 ffi::panel_save_delegate_set_title(
455 self.as_ref().to_glib_none().0,
456 title.to_glib_none().0,
457 );
458 }
459 }
460
461 #[doc(alias = "close")]
469 fn connect_close<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
470 unsafe extern "C" fn close_trampoline<P: IsA<SaveDelegate>, F: Fn(&P) + 'static>(
471 this: *mut ffi::PanelSaveDelegate,
472 f: glib::ffi::gpointer,
473 ) {
474 let f: &F = &*(f as *const F);
475 f(SaveDelegate::from_glib_borrow(this).unsafe_cast_ref())
476 }
477 unsafe {
478 let f: Box_<F> = Box_::new(f);
479 connect_raw(
480 self.as_ptr() as *mut _,
481 c"close".as_ptr() as *const _,
482 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
483 close_trampoline::<Self, F> as *const (),
484 )),
485 Box_::into_raw(f),
486 )
487 }
488 }
489
490 #[doc(alias = "discard")]
497 fn connect_discard<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
498 unsafe extern "C" fn discard_trampoline<P: IsA<SaveDelegate>, F: Fn(&P) + 'static>(
499 this: *mut ffi::PanelSaveDelegate,
500 f: glib::ffi::gpointer,
501 ) {
502 let f: &F = &*(f as *const F);
503 f(SaveDelegate::from_glib_borrow(this).unsafe_cast_ref())
504 }
505 unsafe {
506 let f: Box_<F> = Box_::new(f);
507 connect_raw(
508 self.as_ptr() as *mut _,
509 c"discard".as_ptr() as *const _,
510 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
511 discard_trampoline::<Self, F> as *const (),
512 )),
513 Box_::into_raw(f),
514 )
515 }
516 }
517
518 #[doc(alias = "icon")]
519 fn connect_icon_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
520 unsafe extern "C" fn notify_icon_trampoline<P: IsA<SaveDelegate>, F: Fn(&P) + 'static>(
521 this: *mut ffi::PanelSaveDelegate,
522 _param_spec: glib::ffi::gpointer,
523 f: glib::ffi::gpointer,
524 ) {
525 let f: &F = &*(f as *const F);
526 f(SaveDelegate::from_glib_borrow(this).unsafe_cast_ref())
527 }
528 unsafe {
529 let f: Box_<F> = Box_::new(f);
530 connect_raw(
531 self.as_ptr() as *mut _,
532 c"notify::icon".as_ptr() as *const _,
533 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
534 notify_icon_trampoline::<Self, F> as *const (),
535 )),
536 Box_::into_raw(f),
537 )
538 }
539 }
540
541 #[doc(alias = "icon-name")]
542 fn connect_icon_name_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
543 unsafe extern "C" fn notify_icon_name_trampoline<
544 P: IsA<SaveDelegate>,
545 F: Fn(&P) + 'static,
546 >(
547 this: *mut ffi::PanelSaveDelegate,
548 _param_spec: glib::ffi::gpointer,
549 f: glib::ffi::gpointer,
550 ) {
551 let f: &F = &*(f as *const F);
552 f(SaveDelegate::from_glib_borrow(this).unsafe_cast_ref())
553 }
554 unsafe {
555 let f: Box_<F> = Box_::new(f);
556 connect_raw(
557 self.as_ptr() as *mut _,
558 c"notify::icon-name".as_ptr() as *const _,
559 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
560 notify_icon_name_trampoline::<Self, F> as *const (),
561 )),
562 Box_::into_raw(f),
563 )
564 }
565 }
566
567 #[doc(alias = "is-draft")]
568 fn connect_is_draft_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
569 unsafe extern "C" fn notify_is_draft_trampoline<
570 P: IsA<SaveDelegate>,
571 F: Fn(&P) + 'static,
572 >(
573 this: *mut ffi::PanelSaveDelegate,
574 _param_spec: glib::ffi::gpointer,
575 f: glib::ffi::gpointer,
576 ) {
577 let f: &F = &*(f as *const F);
578 f(SaveDelegate::from_glib_borrow(this).unsafe_cast_ref())
579 }
580 unsafe {
581 let f: Box_<F> = Box_::new(f);
582 connect_raw(
583 self.as_ptr() as *mut _,
584 c"notify::is-draft".as_ptr() as *const _,
585 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
586 notify_is_draft_trampoline::<Self, F> as *const (),
587 )),
588 Box_::into_raw(f),
589 )
590 }
591 }
592
593 #[doc(alias = "progress")]
594 fn connect_progress_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
595 unsafe extern "C" fn notify_progress_trampoline<
596 P: IsA<SaveDelegate>,
597 F: Fn(&P) + 'static,
598 >(
599 this: *mut ffi::PanelSaveDelegate,
600 _param_spec: glib::ffi::gpointer,
601 f: glib::ffi::gpointer,
602 ) {
603 let f: &F = &*(f as *const F);
604 f(SaveDelegate::from_glib_borrow(this).unsafe_cast_ref())
605 }
606 unsafe {
607 let f: Box_<F> = Box_::new(f);
608 connect_raw(
609 self.as_ptr() as *mut _,
610 c"notify::progress".as_ptr() as *const _,
611 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
612 notify_progress_trampoline::<Self, F> as *const (),
613 )),
614 Box_::into_raw(f),
615 )
616 }
617 }
618
619 #[doc(alias = "subtitle")]
620 fn connect_subtitle_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
621 unsafe extern "C" fn notify_subtitle_trampoline<
622 P: IsA<SaveDelegate>,
623 F: Fn(&P) + 'static,
624 >(
625 this: *mut ffi::PanelSaveDelegate,
626 _param_spec: glib::ffi::gpointer,
627 f: glib::ffi::gpointer,
628 ) {
629 let f: &F = &*(f as *const F);
630 f(SaveDelegate::from_glib_borrow(this).unsafe_cast_ref())
631 }
632 unsafe {
633 let f: Box_<F> = Box_::new(f);
634 connect_raw(
635 self.as_ptr() as *mut _,
636 c"notify::subtitle".as_ptr() as *const _,
637 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
638 notify_subtitle_trampoline::<Self, F> as *const (),
639 )),
640 Box_::into_raw(f),
641 )
642 }
643 }
644
645 #[doc(alias = "title")]
646 fn connect_title_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
647 unsafe extern "C" fn notify_title_trampoline<P: IsA<SaveDelegate>, F: Fn(&P) + 'static>(
648 this: *mut ffi::PanelSaveDelegate,
649 _param_spec: glib::ffi::gpointer,
650 f: glib::ffi::gpointer,
651 ) {
652 let f: &F = &*(f as *const F);
653 f(SaveDelegate::from_glib_borrow(this).unsafe_cast_ref())
654 }
655 unsafe {
656 let f: Box_<F> = Box_::new(f);
657 connect_raw(
658 self.as_ptr() as *mut _,
659 c"notify::title".as_ptr() as *const _,
660 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
661 notify_title_trampoline::<Self, F> as *const (),
662 )),
663 Box_::into_raw(f),
664 )
665 }
666 }
667}
668
669impl<O: IsA<SaveDelegate>> SaveDelegateExt for O {}