This repository was archived by the owner on Mar 1, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
add generated action interface #10
Merged
Merged
Changes from all commits
Commits
Show all changes
41 commits
Select commit
Hold shift + click to select a range
ba2fbc5
add generated action interface
vhdirk b5c5f62
regenerate
vhdirk 8d98d7e
regenerate
vhdirk 0cca102
regenerate
vhdirk 6dbde18
regenerate
vhdirk 1d7e28b
regenerate
vhdirk 78bf080
regenerate
vhdirk 9bd5cf6
regenerate
vhdirk 05c3fa0
regenerate
vhdirk 37ce756
regenerate
vhdirk 6636cdd
regenerate
vhdirk 7449416
regenerate (with content spliced from external file)
vhdirk b0b95ca
regenerate
vhdirk f95bc9b
regenerate
vhdirk ef34802
regenerate
vhdirk 6864579
Implement minimal test for the GAction interface
sdroege 098d616
regenerate
vhdirk e95da27
regenerate
vhdirk 6c05000
rebase on master
vhdirk 4ceca27
wip: proper test for gaction
vhdirk 70ffb58
add gaction to glib_wrapper list
vhdirk 2a306dc
wip: beef up gaction test
vhdirk d40cea4
fix simpleaction unit test
vhdirk 7f2258d
extend simpleaction unit test some more
vhdirk aac248a
wip: simpleaction test
vhdirk 318448a
wip: simpleaction test
vhdirk f16ac62
invert did_run assertion
vhdirk c4ee724
invert get_property(enabled) assertion
vhdirk 081094a
wip: ownership of pointers
vhdirk ae4f36b
fix argument for activate signal
vhdirk 6555dfc
regenerate
vhdirk ba0ac33
is this a good way to implement those free functions?
vhdirk 058d458
second try for destroy function
vhdirk d9aedf1
regenerate
vhdirk ca2a3ab
regenerate
vhdirk 254a53a
regenerate
vhdirk 961a40b
Fix lib after removal of 'free' module
vhdirk 95ced4c
remove new GParamSpec properties for now
vhdirk d976bfb
regenerate
vhdirk 500da22
regenerate
vhdirk 0bc5673
regenerate
vhdirk File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,271 @@ | ||
// This file was generated by gir (https://github.com/gtk-rs/gir @ 3733792+) | ||
// from gir-files (https://github.com/gtk-rs/gir-files @ 47c69e6) | ||
// DO NOT EDIT | ||
|
||
#[allow(unused_imports)] | ||
use libc::{c_int, c_char, c_uchar, c_float, c_uint, c_double, | ||
c_short, c_ushort, c_long, c_ulong, | ||
c_void, size_t, ssize_t, intptr_t, uintptr_t, time_t, FILE}; | ||
|
||
#[allow(unused_imports)] | ||
use glib_ffi::{gboolean, gconstpointer, gpointer, GType}; | ||
|
||
#[cfg(any(feature = "v2_38", feature = "dox"))] | ||
use Error; | ||
use gio; | ||
use gio_ffi; | ||
use glib; | ||
use glib::object::Downcast; | ||
use glib::object::IsA; | ||
use glib::signal::SignalHandlerId; | ||
use glib::signal::connect; | ||
use glib::translate::*; | ||
use glib_ffi; | ||
use gobject_ffi; | ||
use std::boxed::Box as Box_; | ||
use std::mem; | ||
use std::mem::transmute; | ||
use std::ptr; | ||
|
||
use gobject_subclass::anyimpl::*; | ||
use gobject_subclass::object::*; | ||
|
||
|
||
pub trait ActionImpl: AnyImpl + 'static { | ||
|
||
fn activate(&self, action: &gio::Action, parameter: Option<&glib::Variant>); | ||
|
||
fn change_state(&self, action: &gio::Action, value: &glib::Variant); | ||
|
||
fn get_enabled(&self, action: &gio::Action) -> bool; | ||
|
||
fn get_name(&self, action: &gio::Action) -> Option<String>; | ||
|
||
fn get_parameter_type(&self, action: &gio::Action) -> Option<glib::VariantType>; | ||
|
||
fn get_state(&self, action: &gio::Action) -> Option<glib::Variant>; | ||
|
||
fn get_state_hint(&self, action: &gio::Action) -> Option<glib::Variant>; | ||
|
||
fn get_state_type(&self, action: &gio::Action) -> Option<glib::VariantType>; | ||
|
||
} | ||
|
||
any_impl!(ActionImpl); | ||
|
||
pub trait ActionImplStatic<T: ObjectType>: 'static { | ||
fn get_impl<'a>(&self, imp: &'a T::ImplType) -> &'a ActionImpl; | ||
} | ||
|
||
struct ActionStatic<T: ObjectType>{ | ||
imp_static: *const ActionImplStatic<T> | ||
} | ||
|
||
|
||
unsafe extern "C" fn action_activate<T: ObjectType> | ||
(gptr: *mut gio_ffi::GAction, parameter: *mut glib_ffi::GVariant) | ||
{ | ||
floating_reference_guard!(gptr); | ||
let klass = &**(gptr as *const *const ClassStruct<T>); | ||
let interface_static = klass.get_interface_static(gio_ffi::g_action_get_type()) | ||
as *const ActionStatic<T>; | ||
let instance = &*(gptr as *const T::InstanceStructType); | ||
let imp = instance.get_impl(); | ||
let imp = (*(*interface_static).imp_static).get_impl(imp); | ||
let wrap = from_glib_borrow(gptr); | ||
imp.activate(&wrap, (if parameter.is_null() { None } else { Some(from_glib_borrow(parameter)) }).as_ref()); | ||
} | ||
|
||
unsafe extern "C" fn action_change_state<T: ObjectType> | ||
(gptr: *mut gio_ffi::GAction, value: *mut glib_ffi::GVariant) | ||
{ | ||
floating_reference_guard!(gptr); | ||
let klass = &**(gptr as *const *const ClassStruct<T>); | ||
let interface_static = klass.get_interface_static(gio_ffi::g_action_get_type()) | ||
as *const ActionStatic<T>; | ||
let instance = &*(gptr as *const T::InstanceStructType); | ||
let imp = instance.get_impl(); | ||
let imp = (*(*interface_static).imp_static).get_impl(imp); | ||
let wrap = from_glib_borrow(gptr); | ||
imp.change_state(&wrap, &from_glib_none(value)); | ||
} | ||
|
||
unsafe extern "C" fn action_get_enabled<T: ObjectType> | ||
(gptr: *mut gio_ffi::GAction) -> gboolean | ||
{ | ||
floating_reference_guard!(gptr); | ||
let klass = &**(gptr as *const *const ClassStruct<T>); | ||
let interface_static = klass.get_interface_static(gio_ffi::g_action_get_type()) | ||
as *const ActionStatic<T>; | ||
let instance = &*(gptr as *const T::InstanceStructType); | ||
let imp = instance.get_impl(); | ||
let imp = (*(*interface_static).imp_static).get_impl(imp); | ||
let wrap = from_glib_borrow(gptr); | ||
let rs_ret = imp.get_enabled(&wrap); | ||
rs_ret.to_glib() | ||
} | ||
|
||
unsafe extern "C" fn action_get_name<T: ObjectType> | ||
(gptr: *mut gio_ffi::GAction) -> *const c_char | ||
{ | ||
floating_reference_guard!(gptr); | ||
let klass = &**(gptr as *const *const ClassStruct<T>); | ||
let interface_static = klass.get_interface_static(gio_ffi::g_action_get_type()) | ||
as *const ActionStatic<T>; | ||
let instance = &*(gptr as *const T::InstanceStructType); | ||
let imp = instance.get_impl(); | ||
let imp = (*(*interface_static).imp_static).get_impl(imp); | ||
let wrap = from_glib_borrow(gptr); | ||
let rs_ret = imp.get_name(&wrap); | ||
|
||
match rs_ret { | ||
Some(t_ret) => { | ||
let ret = t_ret.to_glib_full(); | ||
unsafe extern "C" fn destroy_ret(p: glib_ffi::gpointer){ | ||
String::from_glib_full(p as *const c_char); | ||
}; | ||
gobject_ffi::g_object_set_qdata_full(gptr as *mut gobject_ffi::GObject, | ||
glib_ffi::g_quark_from_string("rs_action_get_name_ret".to_glib_none().0), | ||
ret as *mut c_void, | ||
Some(destroy_ret) | ||
); | ||
ret | ||
}, | ||
None => ptr::null() | ||
} | ||
} | ||
|
||
unsafe extern "C" fn action_get_parameter_type<T: ObjectType> | ||
(gptr: *mut gio_ffi::GAction) -> *const glib_ffi::GVariantType | ||
{ | ||
floating_reference_guard!(gptr); | ||
let klass = &**(gptr as *const *const ClassStruct<T>); | ||
let interface_static = klass.get_interface_static(gio_ffi::g_action_get_type()) | ||
as *const ActionStatic<T>; | ||
let instance = &*(gptr as *const T::InstanceStructType); | ||
let imp = instance.get_impl(); | ||
let imp = (*(*interface_static).imp_static).get_impl(imp); | ||
let wrap = from_glib_borrow(gptr); | ||
let rs_ret = imp.get_parameter_type(&wrap); | ||
|
||
match rs_ret { | ||
Some(t_ret) => { | ||
let ret = t_ret.to_glib_full(); | ||
unsafe extern "C" fn destroy_ret(p: glib_ffi::gpointer){ | ||
glib::VariantType::from_glib_full(p as *const glib_ffi::GVariantType); | ||
}; | ||
gobject_ffi::g_object_set_qdata_full(gptr as *mut gobject_ffi::GObject, | ||
glib_ffi::g_quark_from_string("rs_action_get_parameter_type_ret".to_glib_none().0), | ||
ret as *mut c_void, | ||
Some(destroy_ret) | ||
); | ||
ret | ||
}, | ||
None => ptr::null() | ||
} | ||
} | ||
|
||
unsafe extern "C" fn action_get_state<T: ObjectType> | ||
(gptr: *mut gio_ffi::GAction) -> *mut glib_ffi::GVariant | ||
{ | ||
floating_reference_guard!(gptr); | ||
let klass = &**(gptr as *const *const ClassStruct<T>); | ||
let interface_static = klass.get_interface_static(gio_ffi::g_action_get_type()) | ||
as *const ActionStatic<T>; | ||
let instance = &*(gptr as *const T::InstanceStructType); | ||
let imp = instance.get_impl(); | ||
let imp = (*(*interface_static).imp_static).get_impl(imp); | ||
let wrap = from_glib_borrow(gptr); | ||
let rs_ret = imp.get_state(&wrap); | ||
match rs_ret { Some(t_ret) => t_ret.to_glib_full(), None => ptr::null_mut()} | ||
} | ||
|
||
unsafe extern "C" fn action_get_state_hint<T: ObjectType> | ||
(gptr: *mut gio_ffi::GAction) -> *mut glib_ffi::GVariant | ||
{ | ||
floating_reference_guard!(gptr); | ||
let klass = &**(gptr as *const *const ClassStruct<T>); | ||
let interface_static = klass.get_interface_static(gio_ffi::g_action_get_type()) | ||
as *const ActionStatic<T>; | ||
let instance = &*(gptr as *const T::InstanceStructType); | ||
let imp = instance.get_impl(); | ||
let imp = (*(*interface_static).imp_static).get_impl(imp); | ||
let wrap = from_glib_borrow(gptr); | ||
let rs_ret = imp.get_state_hint(&wrap); | ||
match rs_ret { Some(t_ret) => t_ret.to_glib_full(), None => ptr::null_mut()} | ||
} | ||
|
||
unsafe extern "C" fn action_get_state_type<T: ObjectType> | ||
(gptr: *mut gio_ffi::GAction) -> *const glib_ffi::GVariantType | ||
{ | ||
floating_reference_guard!(gptr); | ||
let klass = &**(gptr as *const *const ClassStruct<T>); | ||
let interface_static = klass.get_interface_static(gio_ffi::g_action_get_type()) | ||
as *const ActionStatic<T>; | ||
let instance = &*(gptr as *const T::InstanceStructType); | ||
let imp = instance.get_impl(); | ||
let imp = (*(*interface_static).imp_static).get_impl(imp); | ||
let wrap = from_glib_borrow(gptr); | ||
let rs_ret = imp.get_state_type(&wrap); | ||
|
||
match rs_ret { | ||
Some(t_ret) => { | ||
let ret = t_ret.to_glib_full(); | ||
unsafe extern "C" fn destroy_ret(p: glib_ffi::gpointer){ | ||
glib::VariantType::from_glib_full(p as *const glib_ffi::GVariantType); | ||
}; | ||
gobject_ffi::g_object_set_qdata_full(gptr as *mut gobject_ffi::GObject, | ||
glib_ffi::g_quark_from_string("rs_action_get_state_type_ret".to_glib_none().0), | ||
ret as *mut c_void, | ||
Some(destroy_ret) | ||
); | ||
ret | ||
}, | ||
None => ptr::null() | ||
} | ||
} | ||
|
||
unsafe extern "C" fn action_init<T: ObjectType>( | ||
iface: glib_ffi::gpointer, | ||
iface_data: glib_ffi::gpointer | ||
) { | ||
let action_iface = &mut *(iface as *mut gio_ffi::GActionInterface); | ||
let iface_type = (*(iface as *const gobject_ffi::GTypeInterface)).g_type; | ||
let type_ = (*(iface as *const gobject_ffi::GTypeInterface)).g_instance_type; | ||
let klass = &mut *(gobject_ffi::g_type_class_ref(type_) as *mut ClassStruct<T>); | ||
let interfaces_static = &mut *(klass.interfaces_static as *mut Vec<_>); | ||
interfaces_static.push((iface_type, iface_data)); | ||
action_iface.activate = Some(action_activate::<T>); | ||
action_iface.change_state = Some(action_change_state::<T>); | ||
action_iface.get_enabled = Some(action_get_enabled::<T>); | ||
action_iface.get_name = Some(action_get_name::<T>); | ||
action_iface.get_parameter_type = Some(action_get_parameter_type::<T>); | ||
action_iface.get_state = Some(action_get_state::<T>); | ||
action_iface.get_state_hint = Some(action_get_state_hint::<T>); | ||
action_iface.get_state_type = Some(action_get_state_type::<T>); | ||
} | ||
|
||
pub fn register_action<T: ObjectType, I: ActionImplStatic<T>>( | ||
_: &TypeInitToken, | ||
type_: glib::Type, | ||
imp: &I, | ||
) { | ||
|
||
unsafe { | ||
let imp = imp as &ActionImplStatic<T> as *const ActionImplStatic<T>; | ||
let interface_static = Box::new(ActionStatic { | ||
imp_static: imp, | ||
}); | ||
let iface_info = gobject_ffi::GInterfaceInfo { | ||
interface_init: Some(action_init::<T>), | ||
interface_finalize: None, | ||
interface_data: Box::into_raw(interface_static) as glib_ffi::gpointer, | ||
}; | ||
gobject_ffi::g_type_add_interface_static( | ||
type_.to_glib(), | ||
gio_ffi::g_action_get_type(), | ||
&iface_info, | ||
); | ||
} | ||
|
||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,8 @@ | ||
// This file was generated by gir (https://github.com/gtk-rs/gir @ cf72ed8+) | ||
// This file was generated by gir (https://github.com/gtk-rs/gir @ 3733792+) | ||
// from gir-files (https://github.com/gtk-rs/gir-files @ 47c69e6) | ||
// DO NOT EDIT | ||
|
||
|
||
pub mod action; | ||
|
||
pub mod application; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,3 +12,4 @@ extern crate gobject_subclass; | |
|
||
mod auto; | ||
pub use auto::application; | ||
pub use auto::action; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also needs to be
ObjectImpl
. The docs say thatGAction requires GObject
(this should also be machine-readable from the gir file)Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
True. For interfaces I did not expect there to be requirements as such
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This does pose a problem though.
ObjectImpl
is generic over T, butActionImpl
isn't?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, could we make it generic over
T
or does that break everything then?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It'll probably break a lot, but I don't see any other option? Though I'm not sure what traits
T
should be bound to.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would have to be bound to
ObjectImpl
. Let's worry about that in a separate PR