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 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415
#![allow(unused_variables)] use crate::prelude::*; use glib::signal::SignalHandlerId; use std::{boxed::Box as Box_, cell::RefCell, fmt}; #[derive(Clone, Debug)] pub struct PushActionProps { pub name: Option<String>, // pub parameter_type: GVariantType, pub enabled: bool, pub state_set: bool, // pub state: GVariant, pub display_name: Option<String>, pub icon: Option<String>, } #[derive(Clone, Debug)] pub struct PushAction { props: RefCell<PushActionProps>, } impl PushAction { pub fn new() -> PushAction { // assert_initialized_main_thread!(); // unsafe { from_glib_full(ffi::action_new()) } unimplemented!() } pub fn new_full( name: &str, display_name: &str, activated_cb: Option<Box_<dyn FnOnce(&PushAction) + 'static>>, ) -> PushAction { // assert_initialized_main_thread!(); // let activated_cb_data: Box_<Option<Box_<dyn FnOnce(&Action) + 'static>>> = // Box_::new(activated_cb); // unsafe extern "C" fn activated_cb_func( // action: *mut ffi::Action, // user_data: glib_sys::gpointer, // ) { // let action = from_glib_borrow(action); // let callback: Box_<Option<Box_<dyn FnOnce(&Action) + 'static>>> = // Box_::from_raw(user_data as *mut _); // let callback = (*callback).expect("cannot get closure..."); // callback(&action) // } // let activated_cb = if activated_cb_data.is_some() { // Some(activated_cb_func as _) // } else { // None // }; // let super_callback0: Box_<Option<Box_<dyn FnOnce(&Action) + 'static>>> = activated_cb_data; // unsafe { // from_glib_full(ffi::action_new_full( // name.to_glib_none().0, // display_name.to_glib_none().0, // activated_cb, // Box_::into_raw(super_callback0) as *mut _, // )) // } unimplemented!() } pub fn new_stateful( name: &str, parameter_type: Option<&glib::VariantTy>, state: &glib::Variant, ) -> PushAction { // assert_initialized_main_thread!(); // unsafe { // from_glib_none(ffi::action_new_stateful( // name.to_glib_none().0, // parameter_type.to_glib_none().0, // state.to_glib_none().0, // )) // } unimplemented!() } pub fn with_parameter(name: &str, parameter_type: Option<&glib::VariantTy>) -> PushAction { // assert_initialized_main_thread!(); // unsafe { // from_glib_none(ffi::action_new_with_parameter( // name.to_glib_none().0, // parameter_type.to_glib_none().0, // )) // } unimplemented!() } } impl Default for PushAction { fn default() -> Self { Self::new() } } impl Object for PushAction {} impl Is<PushAction> for PushAction {} impl AsRef<PushAction> for PushAction { fn as_ref(&self) -> &PushAction { self } } pub trait PushActionExt: 'static { /// get_active: /// @action: A #Action /// /// Get the value of the active property /// /// Returns: #true if the action is active /// fn get_active(&self) -> bool; /// get_display_name: /// @action: A #Action /// /// Get the display name of the action /// /// Returns: display-name of the action, owned by Action /// fn get_display_name(&self) -> Option<String>; /// get_icon: /// @action: A #Action /// /// Get the icon of the action /// /// Returns: icon of the action, owned by Action /// fn get_icon(&self) -> Option<String>; /// get_name: /// @action: A #Action /// /// Get the name of the action /// /// Returns: name of the action, owned by Action /// fn get_name(&self) -> Option<String>; /// set_active: /// @action: A #Action /// @active: the value to set /// /// Set the value of the active property /// fn set_active(&self, active: bool); /// set_display_name: /// @action: A #Action /// @name: new display name to set /// /// Set the name of the action to display to the user /// fn set_display_name(&self, name: &str); /// set_icon: /// @action: A #Action /// @name: new icon to set /// /// The icon to be used in a visual representation of an action. /// fn set_icon(&self, name: &str); /// set_name: /// @action: A #Action /// @name: new name to set /// /// Set the name of the action /// fn set_name(&self, name: &str); fn connect_activate<F: Fn(&Self, Option<&glib::Variant>) + 'static>( &self, f: F, ) -> SignalHandlerId; fn connect_property_display_name_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId; fn connect_property_icon_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId; } impl<O: Is<PushAction>> PushActionExt for O { /// get_active: /// @action: A #PushAction /// /// Get the value of the active property /// /// Returns: #true if the action is active /// fn get_active(&self) -> bool { let action = self.as_ref(); action.props.borrow().enabled } /// get_display_name: /// @action: A #PushAction /// /// Get the display name of the action /// /// Returns: display-name of the action, owned by PushAction /// fn get_display_name(&self) -> Option<String> { let action = self.as_ref(); action.props.borrow().display_name.clone() } /// get_icon: /// @action: A #PushAction /// /// Get the icon of the action /// /// Returns: icon of the action, owned by PushAction /// fn get_icon(&self) -> Option<String> { let action = self.as_ref(); action.props.borrow().icon.clone() } /// get_name: /// @action: A #PushAction /// /// Get the name of the action /// /// Returns: name of the action, owned by PushAction /// fn get_name(&self) -> Option<String> { let action = self.as_ref(); action.props.borrow().name.clone() } /// set_active: /// @action: A #PushAction /// @active: the value to set /// /// Set the value of the active property /// fn set_active(&self, active: bool) { let action = self.as_ref(); let mut props = action.props.borrow_mut(); if props.enabled != active { props.enabled = active; // g_object_notify(G_OBJECT(action), "active"); } } /// set_display_name: /// @action: A #PushAction /// @name: new display name to set /// /// Set the name of the action to display to the user /// fn set_display_name(&self, name: &str) { let action = self.as_ref(); let mut props = action.props.borrow_mut(); match &props.display_name { Some(display_name) => { if display_name.as_str() != name { props.display_name = Some(name.into()); // g_object_notify (G_OBJECT (action), "display-name"); } } None => { props.display_name = Some(name.into()); // g_object_notify (G_OBJECT (action), "display-name"); } } } /// set_icon: /// @action: A #PushAction /// @name: new icon to set /// /// The icon to be used in a visual representation of an action. /// fn set_icon(&self, name: &str) { let action = self.as_ref(); let mut props = action.props.borrow_mut(); match &props.icon { Some(icon) => { if icon.as_str() != name { props.icon = Some(name.into()); // g_object_notify (G_OBJECT (action), "icon"); } } None => { props.icon = Some(name.into()); // g_object_notify (G_OBJECT (action), "icon"); } } } /// set_name: /// @action: A #PushAction /// @name: new name to set /// /// Set the name of the action /// fn set_name(&self, name: &str) { let action = self.as_ref(); let mut props = action.props.borrow_mut(); match &props.name { Some(name) => { if name.as_str() != name { props.name = Some(name.into()); // g_object_notify (G_OBJECT (action), "name"); } } None => { props.name = Some(name.into()); // g_object_notify (G_OBJECT (action), "name"); } } } fn connect_activate<F: Fn(&Self, Option<&glib::Variant>) + 'static>( &self, f: F, ) -> SignalHandlerId { // unsafe extern "C" fn activate_trampoline<P, F: Fn(&P, Option<&glib::Variant>) + 'static>( // this: *mut ffi::Action, // parameter: *mut glib_sys::GVariant, // f: glib_sys::gpointer, // ) where // P: Is<Action>, // { // let f: &F = &*(f as *const F); // f( // &Action::from_glib_borrow(this).unsafe_cast_ref(), // Option::<glib::Variant>::from_glib_borrow(parameter) // .as_ref() // .as_ref(), // ) // } // unsafe { // let f: Box_<F> = Box_::new(f); // connect_raw( // self.as_ptr() as *mut _, // b"activate\0".as_ptr() as *const _, // Some(transmute::<_, unsafe extern "C" fn()>( // activate_trampoline::<Self, F> as *const (), // )), // Box_::into_raw(f), // ) // } unimplemented!() } fn connect_property_display_name_notify<F: Fn(&Self) + 'static>( &self, f: F, ) -> SignalHandlerId { // unsafe extern "C" fn notify_display_name_trampoline<P, F: Fn(&P) + 'static>( // this: *mut ffi::Action, // _param_spec: glib_sys::gpointer, // f: glib_sys::gpointer, // ) where // P: Is<Action>, // { // let f: &F = &*(f as *const F); // f(&Action::from_glib_borrow(this).unsafe_cast_ref()) // } // unsafe { // let f: Box_<F> = Box_::new(f); // connect_raw( // self.as_ptr() as *mut _, // b"notify::display-name\0".as_ptr() as *const _, // Some(transmute::<_, unsafe extern "C" fn()>( // notify_display_name_trampoline::<Self, F> as *const (), // )), // Box_::into_raw(f), // ) // } unimplemented!() } fn connect_property_icon_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId { // unsafe extern "C" fn notify_icon_trampoline<P, F: Fn(&P) + 'static>( // this: *mut ffi::Action, // _param_spec: glib_sys::gpointer, // f: glib_sys::gpointer, // ) where // P: Is<Action>, // { // let f: &F = &*(f as *const F); // f(&Action::from_glib_borrow(this).unsafe_cast_ref()) // } // unsafe { // let f: Box_<F> = Box_::new(f); // connect_raw( // self.as_ptr() as *mut _, // b"notify::icon\0".as_ptr() as *const _, // Some(transmute::<_, unsafe extern "C" fn()>( // notify_icon_trampoline::<Self, F> as *const (), // )), // Box_::into_raw(f), // ) // } unimplemented!() } } impl fmt::Display for PushAction { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { write!(f, "PushAction") } }