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
// This file was generated by gir (https://github.com/gtk-rs/gir)
// from gir-files (https://github.com/gtk-rs/gir-files)
// DO NOT EDIT

use Error;
#[cfg(feature = "futures")]
use futures::future;
use gio;
use gio_sys;
use glib::GString;
use glib::object::Cast;
use glib::object::IsA;
use glib::signal::SignalHandlerId;
use glib::signal::connect_raw;
use glib::translate::*;
use glib_sys;
use goa_sys;
use gobject_sys;
use std::boxed::Box as Box_;
use std::fmt;
use std::mem;
use std::mem::transmute;
use std::ptr;

glib_wrapper! {
    pub struct OAuthBased(Interface<goa_sys::GoaOAuthBased>);

    match fn {
        get_type => || goa_sys::goa_oauth_based_get_type(),
    }
}

impl OAuthBased {
    //pub fn interface_info() -> /*Ignored*/Option<gio::DBusInterfaceInfo> {
    //    unsafe { TODO: call goa_sys:goa_oauth_based_interface_info() }
    //}

    //pub fn override_properties(klass: /*Ignored*/&mut glib::ObjectClass, property_id_begin: u32) -> u32 {
    //    unsafe { TODO: call goa_sys:goa_oauth_based_override_properties() }
    //}
}

pub const NONE_OAUTH_BASED: Option<&OAuthBased> = None;

pub trait OAuthBasedExt: 'static {
    fn call_get_access_token<P: IsA<gio::Cancellable>, Q: FnOnce(Result<(GString, GString, i32), Error>) + Send + 'static>(&self, cancellable: Option<&P>, callback: Q);

    #[cfg(feature = "futures")]
    fn call_get_access_token_future(&self) -> Box_<dyn future::Future<Output = Result<(GString, GString, i32), Error>> + std::marker::Unpin>;

    fn call_get_access_token_sync<P: IsA<gio::Cancellable>>(&self, cancellable: Option<&P>) -> Result<(GString, GString, i32), Error>;

    //fn complete_get_access_token(&self, invocation: /*Ignored*/&gio::DBusMethodInvocation, access_token: &str, access_token_secret: &str, expires_in: i32);

    fn dup_consumer_key(&self) -> Option<GString>;

    fn dup_consumer_secret(&self) -> Option<GString>;

    fn get_consumer_key(&self) -> Option<GString>;

    fn get_consumer_secret(&self) -> Option<GString>;

    fn set_consumer_key(&self, value: &str);

    fn set_consumer_secret(&self, value: &str);

    //fn connect_handle_get_access_token<Unsupported or ignored types>(&self, f: F) -> SignalHandlerId;

    fn connect_property_consumer_key_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId;

    fn connect_property_consumer_secret_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId;
}

impl<O: IsA<OAuthBased>> OAuthBasedExt for O {
    fn call_get_access_token<P: IsA<gio::Cancellable>, Q: FnOnce(Result<(GString, GString, i32), Error>) + Send + 'static>(&self, cancellable: Option<&P>, callback: Q) {
        let user_data: Box<Q> = Box::new(callback);
        unsafe extern "C" fn call_get_access_token_trampoline<Q: FnOnce(Result<(GString, GString, i32), Error>) + Send + 'static>(_source_object: *mut gobject_sys::GObject, res: *mut gio_sys::GAsyncResult, user_data: glib_sys::gpointer) {
            let mut error = ptr::null_mut();
            let mut out_access_token = ptr::null_mut();
            let mut out_access_token_secret = ptr::null_mut();
            let mut out_expires_in = mem::MaybeUninit::uninit();
            let _ = goa_sys::goa_oauth_based_call_get_access_token_finish(_source_object as *mut _, &mut out_access_token, &mut out_access_token_secret, out_expires_in.as_mut_ptr(), res, &mut error);
            let out_expires_in = out_expires_in.assume_init();
            let result = if error.is_null() { Ok((from_glib_full(out_access_token), from_glib_full(out_access_token_secret), out_expires_in)) } else { Err(from_glib_full(error)) };
            let callback: Box<Q> = Box::from_raw(user_data as *mut _);
            callback(result);
        }
        let callback = call_get_access_token_trampoline::<Q>;
        unsafe {
            goa_sys::goa_oauth_based_call_get_access_token(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 _);
        }
    }

    #[cfg(feature = "futures")]
    fn call_get_access_token_future(&self) -> Box_<dyn future::Future<Output = Result<(GString, GString, i32), Error>> + std::marker::Unpin> {
        use gio::GioFuture;
        use fragile::Fragile;

        GioFuture::new(self, move |obj, send| {
            let cancellable = gio::Cancellable::new();
            let send = Fragile::new(send);
            obj.call_get_access_token(
                Some(&cancellable),
                move |res| {
                    let _ = send.into_inner().send(res);
                },
            );

            cancellable
        })
    }

    fn call_get_access_token_sync<P: IsA<gio::Cancellable>>(&self, cancellable: Option<&P>) -> Result<(GString, GString, i32), Error> {
        unsafe {
            let mut out_access_token = ptr::null_mut();
            let mut out_access_token_secret = ptr::null_mut();
            let mut out_expires_in = mem::MaybeUninit::uninit();
            let mut error = ptr::null_mut();
            let _ = goa_sys::goa_oauth_based_call_get_access_token_sync(self.as_ref().to_glib_none().0, &mut out_access_token, &mut out_access_token_secret, out_expires_in.as_mut_ptr(), cancellable.map(|p| p.as_ref()).to_glib_none().0, &mut error);
            let out_expires_in = out_expires_in.assume_init();
            if error.is_null() { Ok((from_glib_full(out_access_token), from_glib_full(out_access_token_secret), out_expires_in)) } else { Err(from_glib_full(error)) }
        }
    }

    //fn complete_get_access_token(&self, invocation: /*Ignored*/&gio::DBusMethodInvocation, access_token: &str, access_token_secret: &str, expires_in: i32) {
    //    unsafe { TODO: call goa_sys:goa_oauth_based_complete_get_access_token() }
    //}

    fn dup_consumer_key(&self) -> Option<GString> {
        unsafe {
            from_glib_full(goa_sys::goa_oauth_based_dup_consumer_key(self.as_ref().to_glib_none().0))
        }
    }

    fn dup_consumer_secret(&self) -> Option<GString> {
        unsafe {
            from_glib_full(goa_sys::goa_oauth_based_dup_consumer_secret(self.as_ref().to_glib_none().0))
        }
    }

    fn get_consumer_key(&self) -> Option<GString> {
        unsafe {
            from_glib_none(goa_sys::goa_oauth_based_get_consumer_key(self.as_ref().to_glib_none().0))
        }
    }

    fn get_consumer_secret(&self) -> Option<GString> {
        unsafe {
            from_glib_none(goa_sys::goa_oauth_based_get_consumer_secret(self.as_ref().to_glib_none().0))
        }
    }

    fn set_consumer_key(&self, value: &str) {
        unsafe {
            goa_sys::goa_oauth_based_set_consumer_key(self.as_ref().to_glib_none().0, value.to_glib_none().0);
        }
    }

    fn set_consumer_secret(&self, value: &str) {
        unsafe {
            goa_sys::goa_oauth_based_set_consumer_secret(self.as_ref().to_glib_none().0, value.to_glib_none().0);
        }
    }

    //fn connect_handle_get_access_token<Unsupported or ignored types>(&self, f: F) -> SignalHandlerId {
    //    Ignored invocation: Gio.DBusMethodInvocation
    //}

    fn connect_property_consumer_key_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
        unsafe extern "C" fn notify_consumer_key_trampoline<P, F: Fn(&P) + 'static>(this: *mut goa_sys::GoaOAuthBased, _param_spec: glib_sys::gpointer, f: glib_sys::gpointer)
            where P: IsA<OAuthBased>
        {
            let f: &F = &*(f as *const F);
            f(&OAuthBased::from_glib_borrow(this).unsafe_cast())
        }
        unsafe {
            let f: Box_<F> = Box_::new(f);
            connect_raw(self.as_ptr() as *mut _, b"notify::consumer-key\0".as_ptr() as *const _,
                Some(transmute(notify_consumer_key_trampoline::<Self, F> as usize)), Box_::into_raw(f))
        }
    }

    fn connect_property_consumer_secret_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
        unsafe extern "C" fn notify_consumer_secret_trampoline<P, F: Fn(&P) + 'static>(this: *mut goa_sys::GoaOAuthBased, _param_spec: glib_sys::gpointer, f: glib_sys::gpointer)
            where P: IsA<OAuthBased>
        {
            let f: &F = &*(f as *const F);
            f(&OAuthBased::from_glib_borrow(this).unsafe_cast())
        }
        unsafe {
            let f: Box_<F> = Box_::new(f);
            connect_raw(self.as_ptr() as *mut _, b"notify::consumer-secret\0".as_ptr() as *const _,
                Some(transmute(notify_consumer_secret_trampoline::<Self, F> as usize)), Box_::into_raw(f))
        }
    }
}

impl fmt::Display for OAuthBased {
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
        write!(f, "OAuthBased")
    }
}