1 // This file was generated by gir (https://github.com/gtk-rs/gir) 2 // from gir-files (https://github.com/gtk-rs/gir-files) 3 // DO NOT EDIT 4 5 use crate::AsyncResult; 6 use crate::Cancellable; 7 use glib::object::IsA; 8 use glib::object::ObjectType as ObjectType_; 9 use glib::signal::connect_raw; 10 use glib::signal::SignalHandlerId; 11 use glib::translate::*; 12 use std::boxed::Box as Box_; 13 use std::fmt; 14 use std::mem::transmute; 15 16 glib::wrapper! { 17 #[doc(alias = "GTask")] 18 pub struct Task(Object<ffi::GTask, ffi::GTaskClass>) @implements AsyncResult; 19 20 match fn { 21 type_ => || ffi::g_task_get_type(), 22 } 23 } 24 25 impl Task { 26 //#[doc(alias = "g_task_attach_source")] 27 //pub fn attach_source<P: Fn() -> bool + 'static>(&self, source: &glib::Source, callback: P) { 28 // unsafe { TODO: call ffi:g_task_attach_source() } 29 //} 30 31 #[doc(alias = "g_task_get_cancellable")] 32 #[doc(alias = "get_cancellable")] cancellable(&self) -> Cancellable33 pub fn cancellable(&self) -> Cancellable { 34 unsafe { from_glib_none(ffi::g_task_get_cancellable(self.to_glib_none().0)) } 35 } 36 37 #[doc(alias = "g_task_get_check_cancellable")] 38 #[doc(alias = "get_check_cancellable")] is_check_cancellable(&self) -> bool39 pub fn is_check_cancellable(&self) -> bool { 40 unsafe { from_glib(ffi::g_task_get_check_cancellable(self.to_glib_none().0)) } 41 } 42 43 #[doc(alias = "g_task_get_completed")] 44 #[doc(alias = "get_completed")] is_completed(&self) -> bool45 pub fn is_completed(&self) -> bool { 46 unsafe { from_glib(ffi::g_task_get_completed(self.to_glib_none().0)) } 47 } 48 49 #[doc(alias = "g_task_get_context")] 50 #[doc(alias = "get_context")] context(&self) -> glib::MainContext51 pub fn context(&self) -> glib::MainContext { 52 unsafe { from_glib_none(ffi::g_task_get_context(self.to_glib_none().0)) } 53 } 54 55 #[cfg(any(feature = "v2_60", feature = "dox"))] 56 #[cfg_attr(feature = "dox", doc(cfg(feature = "v2_60")))] 57 #[doc(alias = "g_task_get_name")] 58 #[doc(alias = "get_name")] name(&self) -> Option<glib::GString>59 pub fn name(&self) -> Option<glib::GString> { 60 unsafe { from_glib_none(ffi::g_task_get_name(self.to_glib_none().0)) } 61 } 62 63 #[doc(alias = "g_task_get_return_on_cancel")] 64 #[doc(alias = "get_return_on_cancel")] is_return_on_cancel(&self) -> bool65 pub fn is_return_on_cancel(&self) -> bool { 66 unsafe { from_glib(ffi::g_task_get_return_on_cancel(self.to_glib_none().0)) } 67 } 68 69 //#[doc(alias = "g_task_get_source_tag")] 70 //#[doc(alias = "get_source_tag")] 71 //pub fn source_tag(&self) -> /*Unimplemented*/Option<Fundamental: Pointer> { 72 // unsafe { TODO: call ffi:g_task_get_source_tag() } 73 //} 74 75 #[doc(alias = "g_task_had_error")] had_error(&self) -> bool76 pub fn had_error(&self) -> bool { 77 unsafe { from_glib(ffi::g_task_had_error(self.to_glib_none().0)) } 78 } 79 80 #[doc(alias = "g_task_return_error_if_cancelled")] return_error_if_cancelled(&self) -> bool81 pub fn return_error_if_cancelled(&self) -> bool { 82 unsafe { from_glib(ffi::g_task_return_error_if_cancelled(self.to_glib_none().0)) } 83 } 84 85 //#[doc(alias = "g_task_return_new_error")] 86 //pub fn return_new_error(&self, domain: glib::Quark, code: i32, format: &str, : /*Unknown conversion*//*Unimplemented*/Fundamental: VarArgs) { 87 // unsafe { TODO: call ffi:g_task_return_new_error() } 88 //} 89 90 //#[doc(alias = "g_task_run_in_thread_sync")] 91 //pub fn run_in_thread_sync(&self, task_func: /*Unimplemented*/FnOnce(&Task, &glib::Object, /*Unimplemented*/Option<Fundamental: Pointer>, Option<&Cancellable>)) { 92 // unsafe { TODO: call ffi:g_task_run_in_thread_sync() } 93 //} 94 95 #[doc(alias = "g_task_set_check_cancellable")] set_check_cancellable(&self, check_cancellable: bool)96 pub fn set_check_cancellable(&self, check_cancellable: bool) { 97 unsafe { 98 ffi::g_task_set_check_cancellable(self.to_glib_none().0, check_cancellable.into_glib()); 99 } 100 } 101 102 #[cfg(any(feature = "v2_60", feature = "dox"))] 103 #[cfg_attr(feature = "dox", doc(cfg(feature = "v2_60")))] 104 #[doc(alias = "g_task_set_name")] set_name(&self, name: Option<&str>)105 pub fn set_name(&self, name: Option<&str>) { 106 unsafe { 107 ffi::g_task_set_name(self.to_glib_none().0, name.to_glib_none().0); 108 } 109 } 110 111 #[doc(alias = "g_task_set_return_on_cancel")] set_return_on_cancel(&self, return_on_cancel: bool) -> bool112 pub fn set_return_on_cancel(&self, return_on_cancel: bool) -> bool { 113 unsafe { 114 from_glib(ffi::g_task_set_return_on_cancel( 115 self.to_glib_none().0, 116 return_on_cancel.into_glib(), 117 )) 118 } 119 } 120 121 //#[doc(alias = "g_task_set_source_tag")] 122 //pub fn set_source_tag(&self, source_tag: /*Unimplemented*/Option<Fundamental: Pointer>) { 123 // unsafe { TODO: call ffi:g_task_set_source_tag() } 124 //} 125 126 #[doc(alias = "g_task_is_valid")] is_valid<P: IsA<AsyncResult>, Q: IsA<glib::Object>>( result: &P, source_object: Option<&Q>, ) -> bool127 pub fn is_valid<P: IsA<AsyncResult>, Q: IsA<glib::Object>>( 128 result: &P, 129 source_object: Option<&Q>, 130 ) -> bool { 131 unsafe { 132 from_glib(ffi::g_task_is_valid( 133 result.as_ref().to_glib_none().0, 134 source_object.map(|p| p.as_ref()).to_glib_none().0, 135 )) 136 } 137 } 138 139 //#[doc(alias = "g_task_report_error")] 140 //pub fn report_error<P: FnOnce(Result<(), glib::Error>) + 'static>(source_object: Option<&glib::Object>, callback: P, source_tag: /*Unimplemented*/Option<Fundamental: Pointer>, error: &mut glib::Error) { 141 // unsafe { TODO: call ffi:g_task_report_error() } 142 //} 143 144 //#[doc(alias = "g_task_report_new_error")] 145 //pub fn report_new_error<P: FnOnce(Result<(), glib::Error>) + 'static>(source_object: Option<&glib::Object>, callback: P, source_tag: /*Unimplemented*/Option<Fundamental: Pointer>, domain: glib::Quark, code: i32, format: &str, : /*Unknown conversion*//*Unimplemented*/Fundamental: VarArgs) { 146 // unsafe { TODO: call ffi:g_task_report_new_error() } 147 //} 148 149 #[doc(alias = "completed")] connect_completed_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId150 pub fn connect_completed_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId { 151 unsafe extern "C" fn notify_completed_trampoline<F: Fn(&Task) + 'static>( 152 this: *mut ffi::GTask, 153 _param_spec: glib::ffi::gpointer, 154 f: glib::ffi::gpointer, 155 ) { 156 let f: &F = &*(f as *const F); 157 f(&from_glib_borrow(this)) 158 } 159 unsafe { 160 let f: Box_<F> = Box_::new(f); 161 connect_raw( 162 self.as_ptr() as *mut _, 163 b"notify::completed\0".as_ptr() as *const _, 164 Some(transmute::<_, unsafe extern "C" fn()>( 165 notify_completed_trampoline::<F> as *const (), 166 )), 167 Box_::into_raw(f), 168 ) 169 } 170 } 171 } 172 173 impl fmt::Display for Task { fmt(&self, f: &mut fmt::Formatter) -> fmt::Result174 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { 175 f.write_str("Task") 176 } 177 } 178