Skip to main content

gio/subclass/
action_group.rs

1// Take a look at the license at the top of the repository in the LICENSE file.
2
3use std::{mem, ptr, sync::OnceLock};
4
5use glib::{GString, Quark, Variant, VariantType, prelude::*, subclass::prelude::*, translate::*};
6
7use crate::{ActionGroup, ffi};
8
9pub trait ActionGroupImpl: ObjectImpl + ObjectSubclass<Type: IsA<ActionGroup>> {
10    fn action_added(&self, action_name: &str) {
11        self.parent_action_added(action_name);
12    }
13
14    fn action_enabled_changed(&self, action_name: &str, enabled: bool) {
15        self.parent_action_enabled_changed(action_name, enabled);
16    }
17
18    fn action_removed(&self, action_name: &str) {
19        self.parent_action_removed(action_name);
20    }
21
22    fn action_state_changed(&self, action_name: &str, state: &Variant) {
23        self.parent_action_state_changed(action_name, state);
24    }
25
26    fn activate_action(&self, action_name: &str, parameter: Option<&Variant>) {
27        self.parent_activate_action(action_name, parameter);
28    }
29
30    fn change_action_state(&self, action_name: &str, value: &Variant) {
31        self.parent_change_action_state(action_name, value)
32    }
33
34    #[doc(alias = "get_action_enabled")]
35    fn action_is_enabled(&self, action_name: &str) -> bool {
36        self.parent_action_is_enabled(action_name)
37    }
38
39    #[doc(alias = "get_action_parameter_type")]
40    fn action_parameter_type(&self, action_name: &str) -> Option<VariantType> {
41        self.parent_action_parameter_type(action_name)
42    }
43
44    #[doc(alias = "get_action_state")]
45    fn action_state(&self, action_name: &str) -> Option<Variant> {
46        self.parent_action_state(action_name)
47    }
48
49    #[doc(alias = "get_action_state_hint")]
50    fn action_state_hint(&self, action_name: &str) -> Option<Variant> {
51        self.parent_action_state_hint(action_name)
52    }
53
54    #[doc(alias = "get_action_state_type")]
55    fn action_state_type(&self, action_name: &str) -> Option<VariantType> {
56        self.parent_action_state_type(action_name)
57    }
58
59    fn has_action(&self, action_name: &str) -> bool {
60        self.parent_has_action(action_name)
61    }
62
63    fn list_actions(&self) -> Vec<String>;
64    fn query_action(
65        &self,
66        action_name: &str,
67    ) -> Option<(
68        bool,
69        Option<VariantType>,
70        Option<VariantType>,
71        Option<Variant>,
72        Option<Variant>,
73    )>;
74}
75
76pub trait ActionGroupImplExt: ActionGroupImpl {
77    fn parent_action_added(&self, action_name: &str) {
78        unsafe {
79            let type_data = Self::type_data();
80            let parent_iface = type_data.as_ref().parent_interface::<ActionGroup>()
81                as *const ffi::GActionGroupInterface;
82
83            if let Some(func) = (*parent_iface).action_added {
84                func(
85                    self.obj().unsafe_cast_ref::<ActionGroup>().to_glib_none().0,
86                    action_name.to_glib_none().0,
87                );
88            }
89        }
90    }
91
92    fn parent_action_enabled_changed(&self, action_name: &str, enabled: bool) {
93        unsafe {
94            let type_data = Self::type_data();
95            let parent_iface = type_data.as_ref().parent_interface::<ActionGroup>()
96                as *const ffi::GActionGroupInterface;
97
98            if let Some(func) = (*parent_iface).action_enabled_changed {
99                func(
100                    self.obj().unsafe_cast_ref::<ActionGroup>().to_glib_none().0,
101                    action_name.to_glib_none().0,
102                    enabled.into_glib(),
103                );
104            }
105        }
106    }
107
108    fn parent_action_removed(&self, action_name: &str) {
109        unsafe {
110            let type_data = Self::type_data();
111            let parent_iface = type_data.as_ref().parent_interface::<ActionGroup>()
112                as *const ffi::GActionGroupInterface;
113
114            if let Some(func) = (*parent_iface).action_removed {
115                func(
116                    self.obj().unsafe_cast_ref::<ActionGroup>().to_glib_none().0,
117                    action_name.to_glib_none().0,
118                );
119            }
120        }
121    }
122
123    fn parent_action_state_changed(&self, action_name: &str, state: &Variant) {
124        unsafe {
125            let type_data = Self::type_data();
126            let parent_iface = type_data.as_ref().parent_interface::<ActionGroup>()
127                as *const ffi::GActionGroupInterface;
128
129            if let Some(func) = (*parent_iface).action_state_changed {
130                func(
131                    self.obj().unsafe_cast_ref::<ActionGroup>().to_glib_none().0,
132                    action_name.to_glib_none().0,
133                    state.to_glib_none().0,
134                );
135            }
136        }
137    }
138
139    fn parent_activate_action(&self, action_name: &str, parameter: Option<&Variant>) {
140        unsafe {
141            let type_data = Self::type_data();
142            let parent_iface = type_data.as_ref().parent_interface::<ActionGroup>()
143                as *const ffi::GActionGroupInterface;
144
145            let func = (*parent_iface)
146                .activate_action
147                .expect("no parent \"activate_action\" implementation");
148            func(
149                self.obj().unsafe_cast_ref::<ActionGroup>().to_glib_none().0,
150                action_name.to_glib_none().0,
151                parameter.to_glib_none().0,
152            );
153        }
154    }
155
156    fn parent_change_action_state(&self, action_name: &str, value: &Variant) {
157        unsafe {
158            let type_data = Self::type_data();
159            let parent_iface = type_data.as_ref().parent_interface::<ActionGroup>()
160                as *const ffi::GActionGroupInterface;
161
162            let func = (*parent_iface)
163                .change_action_state
164                .expect("no parent \"change_action_state\" implementation");
165            func(
166                self.obj().unsafe_cast_ref::<ActionGroup>().to_glib_none().0,
167                action_name.to_glib_none().0,
168                value.to_glib_none().0,
169            );
170        }
171    }
172
173    fn parent_action_is_enabled(&self, action_name: &str) -> bool {
174        unsafe {
175            let type_data = Self::type_data();
176            let parent_iface = type_data.as_ref().parent_interface::<ActionGroup>()
177                as *const ffi::GActionGroupInterface;
178
179            let func = (*parent_iface)
180                .get_action_enabled
181                .expect("no parent \"action_is_enabled\" implementation");
182            let ret = func(
183                self.obj().unsafe_cast_ref::<ActionGroup>().to_glib_none().0,
184                action_name.to_glib_none().0,
185            );
186            from_glib(ret)
187        }
188    }
189
190    fn parent_action_parameter_type(&self, action_name: &str) -> Option<VariantType> {
191        unsafe {
192            let type_data = Self::type_data();
193            let parent_iface = type_data.as_ref().parent_interface::<ActionGroup>()
194                as *const ffi::GActionGroupInterface;
195
196            let func = (*parent_iface)
197                .get_action_parameter_type
198                .expect("no parent \"get_action_parameter_type\" implementation");
199            let ret = func(
200                self.obj().unsafe_cast_ref::<ActionGroup>().to_glib_none().0,
201                action_name.to_glib_none().0,
202            );
203            from_glib_none(ret)
204        }
205    }
206
207    fn parent_action_state(&self, action_name: &str) -> Option<Variant> {
208        unsafe {
209            let type_data = Self::type_data();
210            let parent_iface = type_data.as_ref().parent_interface::<ActionGroup>()
211                as *const ffi::GActionGroupInterface;
212
213            let func = (*parent_iface)
214                .get_action_state
215                .expect("no parent \"get_action_state\" implementation");
216            let ret = func(
217                self.obj().unsafe_cast_ref::<ActionGroup>().to_glib_none().0,
218                action_name.to_glib_none().0,
219            );
220            from_glib_none(ret)
221        }
222    }
223
224    fn parent_action_state_hint(&self, action_name: &str) -> Option<Variant> {
225        unsafe {
226            let type_data = Self::type_data();
227            let parent_iface = type_data.as_ref().parent_interface::<ActionGroup>()
228                as *const ffi::GActionGroupInterface;
229
230            let func = (*parent_iface)
231                .get_action_state_hint
232                .expect("no parent \"get_action_state_hint\" implementation");
233            let ret = func(
234                self.obj().unsafe_cast_ref::<ActionGroup>().to_glib_none().0,
235                action_name.to_glib_none().0,
236            );
237            from_glib_none(ret)
238        }
239    }
240
241    fn parent_action_state_type(&self, action_name: &str) -> Option<VariantType> {
242        unsafe {
243            let type_data = Self::type_data();
244            let parent_iface = type_data.as_ref().parent_interface::<ActionGroup>()
245                as *const ffi::GActionGroupInterface;
246
247            let func = (*parent_iface)
248                .get_action_state_type
249                .expect("no parent \"get_action_state_type\" implementation");
250            let ret = func(
251                self.obj().unsafe_cast_ref::<ActionGroup>().to_glib_none().0,
252                action_name.to_glib_none().0,
253            );
254            from_glib_none(ret)
255        }
256    }
257
258    fn parent_has_action(&self, action_name: &str) -> bool {
259        unsafe {
260            let type_data = Self::type_data();
261            let parent_iface = type_data.as_ref().parent_interface::<ActionGroup>()
262                as *const ffi::GActionGroupInterface;
263
264            let func = (*parent_iface)
265                .has_action
266                .expect("no parent \"has_action\" implementation");
267            let ret = func(
268                self.obj().unsafe_cast_ref::<ActionGroup>().to_glib_none().0,
269                action_name.to_glib_none().0,
270            );
271            from_glib(ret)
272        }
273    }
274
275    fn parent_list_actions(&self) -> Vec<String> {
276        unsafe {
277            let type_data = Self::type_data();
278            let parent_iface = type_data.as_ref().parent_interface::<ActionGroup>()
279                as *const ffi::GActionGroupInterface;
280
281            let func = (*parent_iface)
282                .list_actions
283                .expect("no parent \"list_actions\" implementation");
284            let ret = func(self.obj().unsafe_cast_ref::<ActionGroup>().to_glib_none().0);
285            FromGlibPtrContainer::from_glib_none(ret)
286        }
287    }
288
289    fn parent_query_action(
290        &self,
291        action_name: &str,
292    ) -> Option<(
293        bool,
294        Option<VariantType>,
295        Option<VariantType>,
296        Option<Variant>,
297        Option<Variant>,
298    )> {
299        unsafe {
300            let type_data = Self::type_data();
301            let parent_iface = type_data.as_ref().parent_interface::<ActionGroup>()
302                as *const ffi::GActionGroupInterface;
303
304            let func = (*parent_iface)
305                .query_action
306                .expect("no parent \"query_action\" implementation");
307
308            let mut enabled = mem::MaybeUninit::uninit();
309            let mut parameter_type = ptr::null();
310            let mut state_type = ptr::null();
311            let mut state_hint = ptr::null_mut();
312            let mut state = ptr::null_mut();
313
314            let ret: bool = from_glib(func(
315                self.obj().unsafe_cast_ref::<ActionGroup>().to_glib_none().0,
316                action_name.to_glib_none().0,
317                enabled.as_mut_ptr(),
318                &mut parameter_type,
319                &mut state_type,
320                &mut state_hint,
321                &mut state,
322            ));
323
324            if !ret {
325                None
326            } else {
327                Some((
328                    from_glib(enabled.assume_init()),
329                    from_glib_none(parameter_type),
330                    from_glib_none(state_type),
331                    from_glib_none(state_hint),
332                    from_glib_none(state),
333                ))
334            }
335        }
336    }
337}
338
339impl<T: ActionGroupImpl> ActionGroupImplExt for T {}
340
341unsafe impl<T: ActionGroupImpl> IsImplementable<T> for ActionGroup {
342    fn interface_init(iface: &mut glib::Interface<Self>) {
343        let iface = iface.as_mut();
344
345        iface.action_added = Some(action_group_action_added::<T>);
346        iface.action_enabled_changed = Some(action_group_action_enabled_changed::<T>);
347        iface.action_removed = Some(action_group_action_removed::<T>);
348        iface.action_state_changed = Some(action_group_action_state_changed::<T>);
349        iface.activate_action = Some(action_group_activate_action::<T>);
350        iface.change_action_state = Some(action_group_change_action_state::<T>);
351        iface.get_action_enabled = Some(action_group_get_action_enabled::<T>);
352        iface.get_action_parameter_type = Some(action_group_get_action_parameter_type::<T>);
353        iface.get_action_state = Some(action_group_get_action_state::<T>);
354        iface.get_action_state_hint = Some(action_group_get_action_state_hint::<T>);
355        iface.get_action_state_type = Some(action_group_get_action_state_type::<T>);
356        iface.has_action = Some(action_group_has_action::<T>);
357        iface.list_actions = Some(action_group_list_actions::<T>);
358        iface.query_action = Some(action_group_query_action::<T>);
359    }
360}
361
362unsafe extern "C" fn action_group_has_action<T: ActionGroupImpl>(
363    action_group: *mut ffi::GActionGroup,
364    action_nameptr: *const libc::c_char,
365) -> glib::ffi::gboolean {
366    unsafe {
367        let instance = &*(action_group as *mut T::Instance);
368        let action_name = GString::from_glib_borrow(action_nameptr);
369        let imp = instance.imp();
370
371        imp.has_action(&action_name).into_glib()
372    }
373}
374
375unsafe extern "C" fn action_group_get_action_enabled<T: ActionGroupImpl>(
376    action_group: *mut ffi::GActionGroup,
377    action_nameptr: *const libc::c_char,
378) -> glib::ffi::gboolean {
379    unsafe {
380        let instance = &*(action_group as *mut T::Instance);
381        let imp = instance.imp();
382        let action_name = GString::from_glib_borrow(action_nameptr);
383
384        imp.action_is_enabled(&action_name).into_glib()
385    }
386}
387
388// rustdoc-stripper-ignore-next
389/// Struct to hold a pointer and free it on `Drop::drop`
390struct PtrHolder<T, F: Fn(*mut T) + 'static>(*mut T, F);
391
392impl<T, F: Fn(*mut T) + 'static> Drop for PtrHolder<T, F> {
393    fn drop(&mut self) {
394        (self.1)(self.0)
395    }
396}
397
398unsafe extern "C" fn action_group_get_action_parameter_type<T: ActionGroupImpl>(
399    action_group: *mut ffi::GActionGroup,
400    action_nameptr: *const libc::c_char,
401) -> *const glib::ffi::GVariantType {
402    unsafe {
403        let instance = &*(action_group as *mut T::Instance);
404        let imp = instance.imp();
405        let action_name = GString::from_glib_borrow(action_nameptr);
406        let wrap = from_glib_borrow::<_, ActionGroup>(action_group);
407
408        let ret = imp.action_parameter_type(&action_name);
409
410        if let Some(param_type) = ret {
411            let parameter_type_quark = {
412                static QUARK: OnceLock<Quark> = OnceLock::new();
413                *QUARK.get_or_init(|| {
414                    Quark::from_str("gtk-rs-subclass-action-group-get-action-parameter")
415                })
416            };
417            let param_type = param_type.into_glib_ptr();
418            wrap.set_qdata(
419                parameter_type_quark,
420                PtrHolder(param_type, |ptr| glib::ffi::g_free(ptr as *mut _)),
421            );
422            param_type
423        } else {
424            ptr::null()
425        }
426    }
427}
428
429unsafe extern "C" fn action_group_get_action_state_type<T: ActionGroupImpl>(
430    action_group: *mut ffi::GActionGroup,
431    action_nameptr: *const libc::c_char,
432) -> *const glib::ffi::GVariantType {
433    unsafe {
434        let instance = &*(action_group as *mut T::Instance);
435        let imp = instance.imp();
436        let action_name = GString::from_glib_borrow(action_nameptr);
437
438        let ret = imp.action_state_type(&action_name);
439
440        if let Some(state_type) = ret {
441            let instance = imp.obj();
442            let state_type_quark = {
443                static QUARK: OnceLock<Quark> = OnceLock::new();
444                *QUARK.get_or_init(|| {
445                    Quark::from_str("gtk-rs-subclass-action-group-get-action-state-type")
446                })
447            };
448            let state_type = state_type.into_glib_ptr();
449            instance.set_qdata(
450                state_type_quark,
451                PtrHolder(state_type, |ptr| glib::ffi::g_free(ptr as *mut _)),
452            );
453            state_type
454        } else {
455            ptr::null()
456        }
457    }
458}
459
460unsafe extern "C" fn action_group_get_action_state_hint<T: ActionGroupImpl>(
461    action_group: *mut ffi::GActionGroup,
462    action_nameptr: *const libc::c_char,
463) -> *mut glib::ffi::GVariant {
464    unsafe {
465        let instance = &*(action_group as *mut T::Instance);
466        let imp = instance.imp();
467        let action_name = GString::from_glib_borrow(action_nameptr);
468
469        let ret = imp.action_state_hint(&action_name);
470        if let Some(state_hint) = ret {
471            let instance = imp.obj();
472            let state_hint_quark = {
473                static QUARK: OnceLock<Quark> = OnceLock::new();
474                *QUARK.get_or_init(|| {
475                    Quark::from_str("gtk-rs-subclass-action-group-get-action-state-hint")
476                })
477            };
478            let state_hint_ptr = state_hint.into_glib_ptr();
479            instance.set_qdata(
480                state_hint_quark,
481                PtrHolder(state_hint_ptr, |ptr| glib::ffi::g_variant_unref(ptr)),
482            );
483            state_hint_ptr
484        } else {
485            ptr::null_mut()
486        }
487    }
488}
489
490unsafe extern "C" fn action_group_get_action_state<T: ActionGroupImpl>(
491    action_group: *mut ffi::GActionGroup,
492    action_nameptr: *const libc::c_char,
493) -> *mut glib::ffi::GVariant {
494    unsafe {
495        let instance = &*(action_group as *mut T::Instance);
496        let imp = instance.imp();
497        let action_name = GString::from_glib_borrow(action_nameptr);
498
499        let ret = imp.action_state(&action_name);
500        if let Some(state) = ret {
501            let instance = imp.obj();
502            let state_quark = {
503                static QUARK: OnceLock<Quark> = OnceLock::new();
504                *QUARK.get_or_init(|| {
505                    Quark::from_str("gtk-rs-subclass-action-group-get-action-state")
506                })
507            };
508            let state_ptr = state.into_glib_ptr();
509            instance.set_qdata(
510                state_quark,
511                PtrHolder(state_ptr, |ptr| glib::ffi::g_variant_unref(ptr)),
512            );
513            state_ptr
514        } else {
515            ptr::null_mut()
516        }
517    }
518}
519
520unsafe extern "C" fn action_group_change_action_state<T: ActionGroupImpl>(
521    action_group: *mut ffi::GActionGroup,
522    action_nameptr: *const libc::c_char,
523    stateptr: *mut glib::ffi::GVariant,
524) {
525    unsafe {
526        let instance = &*(action_group as *mut T::Instance);
527        let imp = instance.imp();
528        let action_name = GString::from_glib_borrow(action_nameptr);
529        let state = Variant::from_glib_borrow(stateptr);
530
531        imp.change_action_state(&action_name, &state)
532    }
533}
534
535unsafe extern "C" fn action_group_activate_action<T: ActionGroupImpl>(
536    action_group: *mut ffi::GActionGroup,
537    action_nameptr: *const libc::c_char,
538    parameterptr: *mut glib::ffi::GVariant,
539) {
540    unsafe {
541        let instance = &*(action_group as *mut T::Instance);
542        let imp = instance.imp();
543        let action_name = GString::from_glib_borrow(action_nameptr);
544        let param: Borrowed<Option<Variant>> = from_glib_borrow(parameterptr);
545
546        imp.activate_action(&action_name, param.as_ref().as_ref())
547    }
548}
549
550unsafe extern "C" fn action_group_action_added<T: ActionGroupImpl>(
551    action_group: *mut ffi::GActionGroup,
552    action_nameptr: *const libc::c_char,
553) {
554    unsafe {
555        let instance = &*(action_group as *mut T::Instance);
556        let imp = instance.imp();
557        let action_name = GString::from_glib_borrow(action_nameptr);
558
559        imp.action_added(&action_name)
560    }
561}
562
563unsafe extern "C" fn action_group_action_removed<T: ActionGroupImpl>(
564    action_group: *mut ffi::GActionGroup,
565    action_nameptr: *const libc::c_char,
566) {
567    unsafe {
568        let instance = &*(action_group as *mut T::Instance);
569        let imp = instance.imp();
570        let action_name = GString::from_glib_borrow(action_nameptr);
571
572        imp.action_removed(&action_name)
573    }
574}
575
576unsafe extern "C" fn action_group_action_enabled_changed<T: ActionGroupImpl>(
577    action_group: *mut ffi::GActionGroup,
578    action_nameptr: *const libc::c_char,
579    enabled: glib::ffi::gboolean,
580) {
581    unsafe {
582        let instance = &*(action_group as *mut T::Instance);
583        let imp = instance.imp();
584        let action_name = GString::from_glib_borrow(action_nameptr);
585
586        imp.action_enabled_changed(&action_name, from_glib(enabled))
587    }
588}
589
590unsafe extern "C" fn action_group_action_state_changed<T: ActionGroupImpl>(
591    action_group: *mut ffi::GActionGroup,
592    action_nameptr: *const libc::c_char,
593    stateptr: *mut glib::ffi::GVariant,
594) {
595    unsafe {
596        let instance = &*(action_group as *mut T::Instance);
597        let imp = instance.imp();
598        let action_name = GString::from_glib_borrow(action_nameptr);
599        let state = Variant::from_glib_borrow(stateptr);
600
601        imp.action_state_changed(&action_name, &state)
602    }
603}
604
605unsafe extern "C" fn action_group_list_actions<T: ActionGroupImpl>(
606    action_group: *mut ffi::GActionGroup,
607) -> *mut *mut libc::c_char {
608    unsafe {
609        let instance = &*(action_group as *mut T::Instance);
610        let imp = instance.imp();
611
612        let actions = imp.list_actions();
613
614        {
615            let instance = imp.obj();
616            let actions_quark = {
617                static QUARK: OnceLock<Quark> = OnceLock::new();
618                *QUARK.get_or_init(|| Quark::from_str("gtk-rs-subclass-action-group-list-actions"))
619            };
620            let actionsptr = actions.to_glib_full();
621            instance.set_qdata(actions_quark, actionsptr);
622            actionsptr
623        }
624    }
625}
626
627unsafe extern "C" fn action_group_query_action<T: ActionGroupImpl>(
628    action_group: *mut ffi::GActionGroup,
629    action_nameptr: *const libc::c_char,
630    enabled: *mut glib::ffi::gboolean,
631    parameter_type: *mut *const glib::ffi::GVariantType,
632    state_type: *mut *const glib::ffi::GVariantType,
633    state_hint: *mut *mut glib::ffi::GVariant,
634    state: *mut *mut glib::ffi::GVariant,
635) -> glib::ffi::gboolean {
636    unsafe {
637        let instance = &*(action_group as *mut T::Instance);
638        let imp = instance.imp();
639        let action_name = GString::from_glib_borrow(action_nameptr);
640
641        let ret = imp.query_action(&action_name);
642        if let Some((rs_enabled, rs_parameter_type, rs_state_type, rs_state_hint, rs_state)) = ret {
643            let instance = imp.obj();
644
645            if !enabled.is_null() {
646                *enabled = rs_enabled.into_glib();
647            }
648            if !parameter_type.is_null() {
649                if let Some(rs_parameter_type) = rs_parameter_type {
650                    let param_type_quark = {
651                        static QUARK: OnceLock<Quark> = OnceLock::new();
652                        *QUARK.get_or_init(|| {
653                            Quark::from_str(
654                                "gtk-rs-subclass-action-group-query-action-parameter-type",
655                            )
656                        })
657                    };
658                    let ret = rs_parameter_type.into_glib_ptr();
659                    instance.set_qdata(
660                        param_type_quark,
661                        PtrHolder(ret, |ptr| glib::ffi::g_free(ptr as *mut _)),
662                    );
663                    *parameter_type = ret;
664                } else {
665                    *parameter_type = ptr::null_mut();
666                }
667            }
668            if !state_type.is_null() {
669                if let Some(rs_state_type) = rs_state_type {
670                    let state_type_quark = {
671                        static QUARK: OnceLock<Quark> = OnceLock::new();
672                        *QUARK.get_or_init(|| {
673                            Quark::from_str("gtk-rs-subclass-action-group-query-action-state-type")
674                        })
675                    };
676                    let ret = rs_state_type.into_glib_ptr();
677                    instance.set_qdata(
678                        state_type_quark,
679                        PtrHolder(ret, |ptr| glib::ffi::g_free(ptr as *mut _)),
680                    );
681                    *state_type = ret;
682                } else {
683                    *state_type = ptr::null_mut();
684                }
685            }
686            if !state_hint.is_null() {
687                if let Some(rs_state_hint) = rs_state_hint {
688                    let state_hint_quark = {
689                        static QUARK: OnceLock<Quark> = OnceLock::new();
690                        *QUARK.get_or_init(|| {
691                            Quark::from_str("gtk-rs-subclass-action-group-query-action-state-hint")
692                        })
693                    };
694                    let ret = rs_state_hint.into_glib_ptr();
695                    instance.set_qdata(
696                        state_hint_quark,
697                        PtrHolder(ret, |ptr| glib::ffi::g_variant_unref(ptr)),
698                    );
699                    *state_hint = ret;
700                } else {
701                    *state_hint = ptr::null_mut();
702                }
703            }
704            if !state.is_null() {
705                if let Some(rs_state) = rs_state {
706                    let state_quark = {
707                        static QUARK: OnceLock<Quark> = OnceLock::new();
708                        *QUARK.get_or_init(|| {
709                            Quark::from_str("gtk-rs-subclass-action-group-query-action-state")
710                        })
711                    };
712                    let ret = rs_state.into_glib_ptr();
713                    instance.set_qdata(
714                        state_quark,
715                        PtrHolder(ret, |ptr| glib::ffi::g_variant_unref(ptr)),
716                    );
717                    *state = ret;
718                } else {
719                    *state = ptr::null_mut();
720                }
721            }
722            true
723        } else {
724            false
725        }
726        .into_glib()
727    }
728}