use crate::ffi;
use glib::{
object::ObjectType as _,
prelude::*,
signal::{connect_raw, SignalHandlerId},
translate::*,
};
use std::{boxed::Box as Box_, pin::Pin};
glib::wrapper! {
#[doc(alias = "PanelSaveDelegate")]
pub struct SaveDelegate(Object<ffi::PanelSaveDelegate, ffi::PanelSaveDelegateClass>);
match fn {
type_ => || ffi::panel_save_delegate_get_type(),
}
}
impl SaveDelegate {
pub const NONE: Option<&'static SaveDelegate> = None;
#[doc(alias = "panel_save_delegate_new")]
pub fn new() -> SaveDelegate {
assert_initialized_main_thread!();
unsafe { from_glib_full(ffi::panel_save_delegate_new()) }
}
pub fn builder() -> SaveDelegateBuilder {
SaveDelegateBuilder::new()
}
}
impl Default for SaveDelegate {
fn default() -> Self {
Self::new()
}
}
#[must_use = "The builder must be built to be used"]
pub struct SaveDelegateBuilder {
builder: glib::object::ObjectBuilder<'static, SaveDelegate>,
}
impl SaveDelegateBuilder {
fn new() -> Self {
Self {
builder: glib::object::Object::builder(),
}
}
pub fn icon(self, icon: &impl IsA<gio::Icon>) -> Self {
Self {
builder: self.builder.property("icon", icon.clone().upcast()),
}
}
pub fn icon_name(self, icon_name: impl Into<glib::GString>) -> Self {
Self {
builder: self.builder.property("icon-name", icon_name.into()),
}
}
pub fn is_draft(self, is_draft: bool) -> Self {
Self {
builder: self.builder.property("is-draft", is_draft),
}
}
pub fn progress(self, progress: f64) -> Self {
Self {
builder: self.builder.property("progress", progress),
}
}
pub fn subtitle(self, subtitle: impl Into<glib::GString>) -> Self {
Self {
builder: self.builder.property("subtitle", subtitle.into()),
}
}
pub fn title(self, title: impl Into<glib::GString>) -> Self {
Self {
builder: self.builder.property("title", title.into()),
}
}
#[must_use = "Building the object from the builder is usually expensive and is not expected to have side effects"]
pub fn build(self) -> SaveDelegate {
assert_initialized_main_thread!();
self.builder.build()
}
}
pub trait SaveDelegateExt: IsA<SaveDelegate> + 'static {
#[doc(alias = "panel_save_delegate_close")]
fn close(&self) {
unsafe {
ffi::panel_save_delegate_close(self.as_ref().to_glib_none().0);
}
}
#[doc(alias = "panel_save_delegate_discard")]
fn discard(&self) {
unsafe {
ffi::panel_save_delegate_discard(self.as_ref().to_glib_none().0);
}
}
#[doc(alias = "panel_save_delegate_get_icon")]
#[doc(alias = "get_icon")]
fn icon(&self) -> Option<gio::Icon> {
unsafe {
from_glib_none(ffi::panel_save_delegate_get_icon(
self.as_ref().to_glib_none().0,
))
}
}
#[doc(alias = "panel_save_delegate_get_icon_name")]
#[doc(alias = "get_icon_name")]
#[doc(alias = "icon-name")]
fn icon_name(&self) -> Option<glib::GString> {
unsafe {
from_glib_none(ffi::panel_save_delegate_get_icon_name(
self.as_ref().to_glib_none().0,
))
}
}
#[doc(alias = "panel_save_delegate_get_is_draft")]
#[doc(alias = "get_is_draft")]
#[doc(alias = "is-draft")]
fn is_draft(&self) -> bool {
unsafe {
from_glib(ffi::panel_save_delegate_get_is_draft(
self.as_ref().to_glib_none().0,
))
}
}
#[doc(alias = "panel_save_delegate_get_progress")]
#[doc(alias = "get_progress")]
fn progress(&self) -> f64 {
unsafe { ffi::panel_save_delegate_get_progress(self.as_ref().to_glib_none().0) }
}
#[doc(alias = "panel_save_delegate_get_subtitle")]
#[doc(alias = "get_subtitle")]
fn subtitle(&self) -> Option<glib::GString> {
unsafe {
from_glib_none(ffi::panel_save_delegate_get_subtitle(
self.as_ref().to_glib_none().0,
))
}
}
#[doc(alias = "panel_save_delegate_get_title")]
#[doc(alias = "get_title")]
fn title(&self) -> Option<glib::GString> {
unsafe {
from_glib_none(ffi::panel_save_delegate_get_title(
self.as_ref().to_glib_none().0,
))
}
}
#[doc(alias = "panel_save_delegate_save_async")]
fn save_async<P: FnOnce(Result<(), glib::Error>) + 'static>(
&self,
cancellable: Option<&impl IsA<gio::Cancellable>>,
callback: P,
) {
let main_context = glib::MainContext::ref_thread_default();
let is_main_context_owner = main_context.is_owner();
let has_acquired_main_context = (!is_main_context_owner)
.then(|| main_context.acquire().ok())
.flatten();
assert!(
is_main_context_owner || has_acquired_main_context.is_some(),
"Async operations only allowed if the thread is owning the MainContext"
);
let user_data: Box_<glib::thread_guard::ThreadGuard<P>> =
Box_::new(glib::thread_guard::ThreadGuard::new(callback));
unsafe extern "C" fn save_async_trampoline<P: FnOnce(Result<(), glib::Error>) + 'static>(
_source_object: *mut glib::gobject_ffi::GObject,
res: *mut gio::ffi::GAsyncResult,
user_data: glib::ffi::gpointer,
) {
unsafe {
let mut error = std::ptr::null_mut();
ffi::panel_save_delegate_save_finish(_source_object as *mut _, res, &mut error);
let result = if error.is_null() {
Ok(())
} else {
Err(from_glib_full(error))
};
let callback: Box_<glib::thread_guard::ThreadGuard<P>> =
Box_::from_raw(user_data as *mut _);
let callback: P = callback.into_inner();
callback(result);
}
}
let callback = save_async_trampoline::<P>;
unsafe {
ffi::panel_save_delegate_save_async(
self.as_ref().to_glib_none().0,
cancellable.map(|p| p.as_ref()).to_glib_none().0,
Some(callback),
Box_::into_raw(user_data) as *mut _,
);
}
}
fn save_future(
&self,
) -> Pin<Box_<dyn std::future::Future<Output = Result<(), glib::Error>> + 'static>> {
Box_::pin(gio::GioFuture::new(self, move |obj, cancellable, send| {
obj.save_async(Some(cancellable), move |res| {
send.resolve(res);
});
}))
}
#[doc(alias = "panel_save_delegate_set_icon")]
#[doc(alias = "icon")]
fn set_icon(&self, icon: Option<&impl IsA<gio::Icon>>) {
unsafe {
ffi::panel_save_delegate_set_icon(
self.as_ref().to_glib_none().0,
icon.map(|p| p.as_ref()).to_glib_none().0,
);
}
}
#[doc(alias = "panel_save_delegate_set_icon_name")]
#[doc(alias = "icon-name")]
fn set_icon_name(&self, icon: Option<&str>) {
unsafe {
ffi::panel_save_delegate_set_icon_name(
self.as_ref().to_glib_none().0,
icon.to_glib_none().0,
);
}
}
#[doc(alias = "panel_save_delegate_set_is_draft")]
#[doc(alias = "is-draft")]
fn set_is_draft(&self, is_draft: bool) {
unsafe {
ffi::panel_save_delegate_set_is_draft(
self.as_ref().to_glib_none().0,
is_draft.into_glib(),
);
}
}
#[doc(alias = "panel_save_delegate_set_progress")]
#[doc(alias = "progress")]
fn set_progress(&self, progress: f64) {
unsafe {
ffi::panel_save_delegate_set_progress(self.as_ref().to_glib_none().0, progress);
}
}
#[doc(alias = "panel_save_delegate_set_subtitle")]
#[doc(alias = "subtitle")]
fn set_subtitle(&self, subtitle: Option<&str>) {
unsafe {
ffi::panel_save_delegate_set_subtitle(
self.as_ref().to_glib_none().0,
subtitle.to_glib_none().0,
);
}
}
#[doc(alias = "panel_save_delegate_set_title")]
#[doc(alias = "title")]
fn set_title(&self, title: Option<&str>) {
unsafe {
ffi::panel_save_delegate_set_title(
self.as_ref().to_glib_none().0,
title.to_glib_none().0,
);
}
}
#[doc(alias = "close")]
fn connect_close<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
unsafe extern "C" fn close_trampoline<P: IsA<SaveDelegate>, F: Fn(&P) + 'static>(
this: *mut ffi::PanelSaveDelegate,
f: glib::ffi::gpointer,
) {
unsafe {
let f: &F = &*(f as *const F);
f(SaveDelegate::from_glib_borrow(this).unsafe_cast_ref())
}
}
unsafe {
let f: Box_<F> = Box_::new(f);
connect_raw(
self.as_ptr() as *mut _,
c"close".as_ptr(),
Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
close_trampoline::<Self, F> as *const (),
)),
Box_::into_raw(f),
)
}
}
#[doc(alias = "discard")]
fn connect_discard<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
unsafe extern "C" fn discard_trampoline<P: IsA<SaveDelegate>, F: Fn(&P) + 'static>(
this: *mut ffi::PanelSaveDelegate,
f: glib::ffi::gpointer,
) {
unsafe {
let f: &F = &*(f as *const F);
f(SaveDelegate::from_glib_borrow(this).unsafe_cast_ref())
}
}
unsafe {
let f: Box_<F> = Box_::new(f);
connect_raw(
self.as_ptr() as *mut _,
c"discard".as_ptr(),
Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
discard_trampoline::<Self, F> as *const (),
)),
Box_::into_raw(f),
)
}
}
#[doc(alias = "icon")]
fn connect_icon_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
unsafe extern "C" fn notify_icon_trampoline<P: IsA<SaveDelegate>, F: Fn(&P) + 'static>(
this: *mut ffi::PanelSaveDelegate,
_param_spec: glib::ffi::gpointer,
f: glib::ffi::gpointer,
) {
unsafe {
let f: &F = &*(f as *const F);
f(SaveDelegate::from_glib_borrow(this).unsafe_cast_ref())
}
}
unsafe {
let f: Box_<F> = Box_::new(f);
connect_raw(
self.as_ptr() as *mut _,
c"notify::icon".as_ptr(),
Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
notify_icon_trampoline::<Self, F> as *const (),
)),
Box_::into_raw(f),
)
}
}
#[doc(alias = "icon-name")]
fn connect_icon_name_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
unsafe extern "C" fn notify_icon_name_trampoline<
P: IsA<SaveDelegate>,
F: Fn(&P) + 'static,
>(
this: *mut ffi::PanelSaveDelegate,
_param_spec: glib::ffi::gpointer,
f: glib::ffi::gpointer,
) {
unsafe {
let f: &F = &*(f as *const F);
f(SaveDelegate::from_glib_borrow(this).unsafe_cast_ref())
}
}
unsafe {
let f: Box_<F> = Box_::new(f);
connect_raw(
self.as_ptr() as *mut _,
c"notify::icon-name".as_ptr(),
Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
notify_icon_name_trampoline::<Self, F> as *const (),
)),
Box_::into_raw(f),
)
}
}
#[doc(alias = "is-draft")]
fn connect_is_draft_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
unsafe extern "C" fn notify_is_draft_trampoline<
P: IsA<SaveDelegate>,
F: Fn(&P) + 'static,
>(
this: *mut ffi::PanelSaveDelegate,
_param_spec: glib::ffi::gpointer,
f: glib::ffi::gpointer,
) {
unsafe {
let f: &F = &*(f as *const F);
f(SaveDelegate::from_glib_borrow(this).unsafe_cast_ref())
}
}
unsafe {
let f: Box_<F> = Box_::new(f);
connect_raw(
self.as_ptr() as *mut _,
c"notify::is-draft".as_ptr(),
Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
notify_is_draft_trampoline::<Self, F> as *const (),
)),
Box_::into_raw(f),
)
}
}
#[doc(alias = "progress")]
fn connect_progress_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
unsafe extern "C" fn notify_progress_trampoline<
P: IsA<SaveDelegate>,
F: Fn(&P) + 'static,
>(
this: *mut ffi::PanelSaveDelegate,
_param_spec: glib::ffi::gpointer,
f: glib::ffi::gpointer,
) {
unsafe {
let f: &F = &*(f as *const F);
f(SaveDelegate::from_glib_borrow(this).unsafe_cast_ref())
}
}
unsafe {
let f: Box_<F> = Box_::new(f);
connect_raw(
self.as_ptr() as *mut _,
c"notify::progress".as_ptr(),
Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
notify_progress_trampoline::<Self, F> as *const (),
)),
Box_::into_raw(f),
)
}
}
#[doc(alias = "subtitle")]
fn connect_subtitle_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
unsafe extern "C" fn notify_subtitle_trampoline<
P: IsA<SaveDelegate>,
F: Fn(&P) + 'static,
>(
this: *mut ffi::PanelSaveDelegate,
_param_spec: glib::ffi::gpointer,
f: glib::ffi::gpointer,
) {
unsafe {
let f: &F = &*(f as *const F);
f(SaveDelegate::from_glib_borrow(this).unsafe_cast_ref())
}
}
unsafe {
let f: Box_<F> = Box_::new(f);
connect_raw(
self.as_ptr() as *mut _,
c"notify::subtitle".as_ptr(),
Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
notify_subtitle_trampoline::<Self, F> as *const (),
)),
Box_::into_raw(f),
)
}
}
#[doc(alias = "title")]
fn connect_title_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
unsafe extern "C" fn notify_title_trampoline<P: IsA<SaveDelegate>, F: Fn(&P) + 'static>(
this: *mut ffi::PanelSaveDelegate,
_param_spec: glib::ffi::gpointer,
f: glib::ffi::gpointer,
) {
unsafe {
let f: &F = &*(f as *const F);
f(SaveDelegate::from_glib_borrow(this).unsafe_cast_ref())
}
}
unsafe {
let f: Box_<F> = Box_::new(f);
connect_raw(
self.as_ptr() as *mut _,
c"notify::title".as_ptr(),
Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
notify_title_trampoline::<Self, F> as *const (),
)),
Box_::into_raw(f),
)
}
}
}
impl<O: IsA<SaveDelegate>> SaveDelegateExt for O {}