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
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
// 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 glib::object::Cast;
use glib::object::IsA;
use glib::signal::connect_raw;
use glib::signal::SignalHandlerId;
use glib::translate::*;
use std::boxed::Box as Box_;
use std::fmt;
use std::mem::transmute;

glib::wrapper! {
    /// [`ActionGroup`][crate::ActionGroup] represents a group of actions. Actions can be used to
    /// expose functionality in a structured way, either from one part of a
    /// program to another, or to the outside world. Action groups are often
    /// used together with a [`MenuModel`][crate::MenuModel] that provides additional
    /// representation data for displaying the actions to the user, e.g. in
    /// a menu.
    ///
    /// The main way to interact with the actions in a GActionGroup is to
    /// activate them with [`ActionGroupExt::activate_action()`][crate::prelude::ActionGroupExt::activate_action()]. Activating an
    /// action may require a [`glib::Variant`][crate::glib::Variant] parameter. The required type of the
    /// parameter can be inquired with [`ActionGroupExt::action_parameter_type()`][crate::prelude::ActionGroupExt::action_parameter_type()].
    /// Actions may be disabled, see [`ActionGroupExt::is_action_enabled()`][crate::prelude::ActionGroupExt::is_action_enabled()].
    /// Activating a disabled action has no effect.
    ///
    /// Actions may optionally have a state in the form of a [`glib::Variant`][crate::glib::Variant]. The
    /// current state of an action can be inquired with
    /// [`ActionGroupExt::action_state()`][crate::prelude::ActionGroupExt::action_state()]. Activating a stateful action may
    /// change its state, but it is also possible to set the state by calling
    /// [`ActionGroupExt::change_action_state()`][crate::prelude::ActionGroupExt::change_action_state()].
    ///
    /// As typical example, consider a text editing application which has an
    /// option to change the current font to 'bold'. A good way to represent
    /// this would be a stateful action, with a boolean state. Activating the
    /// action would toggle the state.
    ///
    /// Each action in the group has a unique name (which is a string). All
    /// method calls, except [`ActionGroupExt::list_actions()`][crate::prelude::ActionGroupExt::list_actions()] take the name of
    /// an action as an argument.
    ///
    /// The [`ActionGroup`][crate::ActionGroup] API is meant to be the 'public' API to the action
    /// group. The calls here are exactly the interaction that 'external
    /// forces' (eg: UI, incoming D-Bus messages, etc.) are supposed to have
    /// with actions. 'Internal' APIs (ie: ones meant only to be accessed by
    /// the action group implementation) are found on subclasses. This is
    /// why you will find - for example - [`ActionGroupExt::is_action_enabled()`][crate::prelude::ActionGroupExt::is_action_enabled()]
    /// but not an equivalent `set()` call.
    ///
    /// Signals are emitted on the action group in response to state changes
    /// on individual actions.
    ///
    /// Implementations of [`ActionGroup`][crate::ActionGroup] should provide implementations for
    /// the virtual functions [`ActionGroupExt::list_actions()`][crate::prelude::ActionGroupExt::list_actions()] and
    /// `g_action_group_query_action()`. The other virtual functions should
    /// not be implemented - their "wrappers" are actually implemented with
    /// calls to `g_action_group_query_action()`.
    ///
    /// # Implements
    ///
    /// [`ActionGroupExt`][trait@crate::prelude::ActionGroupExt]
    #[doc(alias = "GActionGroup")]
    pub struct ActionGroup(Interface<ffi::GActionGroup, ffi::GActionGroupInterface>);

    match fn {
        type_ => || ffi::g_action_group_get_type(),
    }
}

impl ActionGroup {
    pub const NONE: Option<&'static ActionGroup> = None;
}

/// Trait containing all [`struct@ActionGroup`] methods.
///
/// # Implementors
///
/// [`ActionGroup`][struct@crate::ActionGroup], [`Application`][struct@crate::Application], [`DBusActionGroup`][struct@crate::DBusActionGroup], [`RemoteActionGroup`][struct@crate::RemoteActionGroup], [`SimpleActionGroup`][struct@crate::SimpleActionGroup]
pub trait ActionGroupExt: 'static {
    /// Emits the `signal::ActionGroup::action-added` signal on `self`.
    ///
    /// This function should only be called by [`ActionGroup`][crate::ActionGroup] implementations.
    /// ## `action_name`
    /// the name of an action in the group
    #[doc(alias = "g_action_group_action_added")]
    fn action_added(&self, action_name: &str);

    /// Emits the `signal::ActionGroup::action-enabled-changed` signal on `self`.
    ///
    /// This function should only be called by [`ActionGroup`][crate::ActionGroup] implementations.
    /// ## `action_name`
    /// the name of an action in the group
    /// ## `enabled`
    /// whether or not the action is now enabled
    #[doc(alias = "g_action_group_action_enabled_changed")]
    fn action_enabled_changed(&self, action_name: &str, enabled: bool);

    /// Emits the `signal::ActionGroup::action-removed` signal on `self`.
    ///
    /// This function should only be called by [`ActionGroup`][crate::ActionGroup] implementations.
    /// ## `action_name`
    /// the name of an action in the group
    #[doc(alias = "g_action_group_action_removed")]
    fn action_removed(&self, action_name: &str);

    /// Emits the `signal::ActionGroup::action-state-changed` signal on `self`.
    ///
    /// This function should only be called by [`ActionGroup`][crate::ActionGroup] implementations.
    /// ## `action_name`
    /// the name of an action in the group
    /// ## `state`
    /// the new state of the named action
    #[doc(alias = "g_action_group_action_state_changed")]
    fn action_state_changed(&self, action_name: &str, state: &glib::Variant);

    /// Activate the named action within `self`.
    ///
    /// If the action is expecting a parameter, then the correct type of
    /// parameter must be given as `parameter`. If the action is expecting no
    /// parameters then `parameter` must be [`None`]. See
    /// [`action_parameter_type()`][Self::action_parameter_type()].
    ///
    /// If the [`ActionGroup`][crate::ActionGroup] implementation supports asynchronous remote
    /// activation over D-Bus, this call may return before the relevant
    /// D-Bus traffic has been sent, or any replies have been received. In
    /// order to block on such asynchronous activation calls,
    /// [`DBusConnection::flush()`][crate::DBusConnection::flush()] should be called prior to the code, which
    /// depends on the result of the action activation. Without flushing
    /// the D-Bus connection, there is no guarantee that the action would
    /// have been activated.
    ///
    /// The following code which runs in a remote app instance, shows an
    /// example of a "quit" action being activated on the primary app
    /// instance over D-Bus. Here [`DBusConnection::flush()`][crate::DBusConnection::flush()] is called
    /// before ``exit()``. Without [`DBusConnection::flush()`][crate::DBusConnection::flush()], the "quit" action
    /// may fail to be activated on the primary instance.
    ///
    ///
    ///
    /// **⚠️ The following code is in C ⚠️**
    ///
    /// ```C
    /// // call "quit" action on primary instance
    /// g_action_group_activate_action (G_ACTION_GROUP (app), "quit", NULL);
    ///
    /// // make sure the action is activated now
    /// g_dbus_connection_flush (...);
    ///
    /// g_debug ("application has been terminated. exiting.");
    ///
    /// exit (0);
    /// ```
    /// ## `action_name`
    /// the name of the action to activate
    /// ## `parameter`
    /// parameters to the activation
    #[doc(alias = "g_action_group_activate_action")]
    fn activate_action(&self, action_name: &str, parameter: Option<&glib::Variant>);

    /// Request for the state of the named action within `self` to be
    /// changed to `value`.
    ///
    /// The action must be stateful and `value` must be of the correct type.
    /// See [`action_state_type()`][Self::action_state_type()].
    ///
    /// This call merely requests a change. The action may refuse to change
    /// its state or may change its state to something other than `value`.
    /// See [`action_state_hint()`][Self::action_state_hint()].
    ///
    /// If the `value` GVariant is floating, it is consumed.
    /// ## `action_name`
    /// the name of the action to request the change on
    /// ## `value`
    /// the new state
    #[doc(alias = "g_action_group_change_action_state")]
    fn change_action_state(&self, action_name: &str, value: &glib::Variant);

    /// Checks if the named action within `self` is currently enabled.
    ///
    /// An action must be enabled in order to be activated or in order to
    /// have its state changed from outside callers.
    /// ## `action_name`
    /// the name of the action to query
    ///
    /// # Returns
    ///
    /// whether or not the action is currently enabled
    #[doc(alias = "g_action_group_get_action_enabled")]
    #[doc(alias = "get_action_enabled")]
    fn is_action_enabled(&self, action_name: &str) -> bool;

    /// Queries the type of the parameter that must be given when activating
    /// the named action within `self`.
    ///
    /// When activating the action using [`activate_action()`][Self::activate_action()],
    /// the [`glib::Variant`][crate::glib::Variant] given to that function must be of the type returned
    /// by this function.
    ///
    /// In the case that this function returns [`None`], you must not give any
    /// [`glib::Variant`][crate::glib::Variant], but [`None`] instead.
    ///
    /// The parameter type of a particular action will never change but it is
    /// possible for an action to be removed and for a new action to be added
    /// with the same name but a different parameter type.
    /// ## `action_name`
    /// the name of the action to query
    ///
    /// # Returns
    ///
    /// the parameter type
    #[doc(alias = "g_action_group_get_action_parameter_type")]
    #[doc(alias = "get_action_parameter_type")]
    fn action_parameter_type(&self, action_name: &str) -> Option<glib::VariantType>;

    /// Queries the current state of the named action within `self`.
    ///
    /// If the action is not stateful then [`None`] will be returned. If the
    /// action is stateful then the type of the return value is the type
    /// given by [`action_state_type()`][Self::action_state_type()].
    ///
    /// The return value (if non-[`None`]) should be freed with
    /// `g_variant_unref()` when it is no longer required.
    /// ## `action_name`
    /// the name of the action to query
    ///
    /// # Returns
    ///
    /// the current state of the action
    #[doc(alias = "g_action_group_get_action_state")]
    #[doc(alias = "get_action_state")]
    fn action_state(&self, action_name: &str) -> Option<glib::Variant>;

    /// Requests a hint about the valid range of values for the state of the
    /// named action within `self`.
    ///
    /// If [`None`] is returned it either means that the action is not stateful
    /// or that there is no hint about the valid range of values for the
    /// state of the action.
    ///
    /// If a [`glib::Variant`][crate::glib::Variant] array is returned then each item in the array is a
    /// possible value for the state. If a [`glib::Variant`][crate::glib::Variant] pair (ie: two-tuple) is
    /// returned then the tuple specifies the inclusive lower and upper bound
    /// of valid values for the state.
    ///
    /// In any case, the information is merely a hint. It may be possible to
    /// have a state value outside of the hinted range and setting a value
    /// within the range may fail.
    ///
    /// The return value (if non-[`None`]) should be freed with
    /// `g_variant_unref()` when it is no longer required.
    /// ## `action_name`
    /// the name of the action to query
    ///
    /// # Returns
    ///
    /// the state range hint
    #[doc(alias = "g_action_group_get_action_state_hint")]
    #[doc(alias = "get_action_state_hint")]
    fn action_state_hint(&self, action_name: &str) -> Option<glib::Variant>;

    /// Queries the type of the state of the named action within
    /// `self`.
    ///
    /// If the action is stateful then this function returns the
    /// [`glib::VariantType`][crate::glib::VariantType] of the state. All calls to
    /// [`change_action_state()`][Self::change_action_state()] must give a [`glib::Variant`][crate::glib::Variant] of this
    /// type and [`action_state()`][Self::action_state()] will return a [`glib::Variant`][crate::glib::Variant]
    /// of the same type.
    ///
    /// If the action is not stateful then this function will return [`None`].
    /// In that case, [`action_state()`][Self::action_state()] will return [`None`]
    /// and you must not call [`change_action_state()`][Self::change_action_state()].
    ///
    /// The state type of a particular action will never change but it is
    /// possible for an action to be removed and for a new action to be added
    /// with the same name but a different state type.
    /// ## `action_name`
    /// the name of the action to query
    ///
    /// # Returns
    ///
    /// the state type, if the action is stateful
    #[doc(alias = "g_action_group_get_action_state_type")]
    #[doc(alias = "get_action_state_type")]
    fn action_state_type(&self, action_name: &str) -> Option<glib::VariantType>;

    /// Checks if the named action exists within `self`.
    /// ## `action_name`
    /// the name of the action to check for
    ///
    /// # Returns
    ///
    /// whether the named action exists
    #[doc(alias = "g_action_group_has_action")]
    fn has_action(&self, action_name: &str) -> bool;

    /// Lists the actions contained within `self`.
    ///
    /// The caller is responsible for freeing the list with `g_strfreev()` when
    /// it is no longer required.
    ///
    /// # Returns
    ///
    /// a [`None`]-terminated array of the names of the
    /// actions in the group
    #[doc(alias = "g_action_group_list_actions")]
    fn list_actions(&self) -> Vec<glib::GString>;

    /// Signals that a new action was just added to the group.
    /// This signal is emitted after the action has been added
    /// and is now visible.
    /// ## `action_name`
    /// the name of the action in `action_group`
    #[doc(alias = "action-added")]
    fn connect_action_added<F: Fn(&Self, &str) + 'static>(
        &self,
        detail: Option<&str>,
        f: F,
    ) -> SignalHandlerId;

    /// Signals that the enabled status of the named action has changed.
    /// ## `action_name`
    /// the name of the action in `action_group`
    /// ## `enabled`
    /// whether the action is enabled or not
    #[doc(alias = "action-enabled-changed")]
    fn connect_action_enabled_changed<F: Fn(&Self, &str, bool) + 'static>(
        &self,
        detail: Option<&str>,
        f: F,
    ) -> SignalHandlerId;

    /// Signals that an action is just about to be removed from the group.
    /// This signal is emitted before the action is removed, so the action
    /// is still visible and can be queried from the signal handler.
    /// ## `action_name`
    /// the name of the action in `action_group`
    #[doc(alias = "action-removed")]
    fn connect_action_removed<F: Fn(&Self, &str) + 'static>(
        &self,
        detail: Option<&str>,
        f: F,
    ) -> SignalHandlerId;

    /// Signals that the state of the named action has changed.
    /// ## `action_name`
    /// the name of the action in `action_group`
    /// ## `value`
    /// the new value of the state
    #[doc(alias = "action-state-changed")]
    fn connect_action_state_changed<F: Fn(&Self, &str, &glib::Variant) + 'static>(
        &self,
        detail: Option<&str>,
        f: F,
    ) -> SignalHandlerId;
}

impl<O: IsA<ActionGroup>> ActionGroupExt for O {
    fn action_added(&self, action_name: &str) {
        unsafe {
            ffi::g_action_group_action_added(
                self.as_ref().to_glib_none().0,
                action_name.to_glib_none().0,
            );
        }
    }

    fn action_enabled_changed(&self, action_name: &str, enabled: bool) {
        unsafe {
            ffi::g_action_group_action_enabled_changed(
                self.as_ref().to_glib_none().0,
                action_name.to_glib_none().0,
                enabled.into_glib(),
            );
        }
    }

    fn action_removed(&self, action_name: &str) {
        unsafe {
            ffi::g_action_group_action_removed(
                self.as_ref().to_glib_none().0,
                action_name.to_glib_none().0,
            );
        }
    }

    fn action_state_changed(&self, action_name: &str, state: &glib::Variant) {
        unsafe {
            ffi::g_action_group_action_state_changed(
                self.as_ref().to_glib_none().0,
                action_name.to_glib_none().0,
                state.to_glib_none().0,
            );
        }
    }

    fn activate_action(&self, action_name: &str, parameter: Option<&glib::Variant>) {
        unsafe {
            ffi::g_action_group_activate_action(
                self.as_ref().to_glib_none().0,
                action_name.to_glib_none().0,
                parameter.to_glib_none().0,
            );
        }
    }

    fn change_action_state(&self, action_name: &str, value: &glib::Variant) {
        unsafe {
            ffi::g_action_group_change_action_state(
                self.as_ref().to_glib_none().0,
                action_name.to_glib_none().0,
                value.to_glib_none().0,
            );
        }
    }

    fn is_action_enabled(&self, action_name: &str) -> bool {
        unsafe {
            from_glib(ffi::g_action_group_get_action_enabled(
                self.as_ref().to_glib_none().0,
                action_name.to_glib_none().0,
            ))
        }
    }

    fn action_parameter_type(&self, action_name: &str) -> Option<glib::VariantType> {
        unsafe {
            from_glib_none(ffi::g_action_group_get_action_parameter_type(
                self.as_ref().to_glib_none().0,
                action_name.to_glib_none().0,
            ))
        }
    }

    fn action_state(&self, action_name: &str) -> Option<glib::Variant> {
        unsafe {
            from_glib_full(ffi::g_action_group_get_action_state(
                self.as_ref().to_glib_none().0,
                action_name.to_glib_none().0,
            ))
        }
    }

    fn action_state_hint(&self, action_name: &str) -> Option<glib::Variant> {
        unsafe {
            from_glib_full(ffi::g_action_group_get_action_state_hint(
                self.as_ref().to_glib_none().0,
                action_name.to_glib_none().0,
            ))
        }
    }

    fn action_state_type(&self, action_name: &str) -> Option<glib::VariantType> {
        unsafe {
            from_glib_none(ffi::g_action_group_get_action_state_type(
                self.as_ref().to_glib_none().0,
                action_name.to_glib_none().0,
            ))
        }
    }

    fn has_action(&self, action_name: &str) -> bool {
        unsafe {
            from_glib(ffi::g_action_group_has_action(
                self.as_ref().to_glib_none().0,
                action_name.to_glib_none().0,
            ))
        }
    }

    fn list_actions(&self) -> Vec<glib::GString> {
        unsafe {
            FromGlibPtrContainer::from_glib_full(ffi::g_action_group_list_actions(
                self.as_ref().to_glib_none().0,
            ))
        }
    }

    fn connect_action_added<F: Fn(&Self, &str) + 'static>(
        &self,
        detail: Option<&str>,
        f: F,
    ) -> SignalHandlerId {
        unsafe extern "C" fn action_added_trampoline<
            P: IsA<ActionGroup>,
            F: Fn(&P, &str) + 'static,
        >(
            this: *mut ffi::GActionGroup,
            action_name: *mut libc::c_char,
            f: glib::ffi::gpointer,
        ) {
            let f: &F = &*(f as *const F);
            f(
                ActionGroup::from_glib_borrow(this).unsafe_cast_ref(),
                &glib::GString::from_glib_borrow(action_name),
            )
        }
        unsafe {
            let f: Box_<F> = Box_::new(f);
            let detailed_signal_name = detail.map(|name| format!("action-added::{}\0", name));
            let signal_name: &[u8] = detailed_signal_name
                .as_ref()
                .map_or(&b"action-added\0"[..], |n| n.as_bytes());
            connect_raw(
                self.as_ptr() as *mut _,
                signal_name.as_ptr() as *const _,
                Some(transmute::<_, unsafe extern "C" fn()>(
                    action_added_trampoline::<Self, F> as *const (),
                )),
                Box_::into_raw(f),
            )
        }
    }

    fn connect_action_enabled_changed<F: Fn(&Self, &str, bool) + 'static>(
        &self,
        detail: Option<&str>,
        f: F,
    ) -> SignalHandlerId {
        unsafe extern "C" fn action_enabled_changed_trampoline<
            P: IsA<ActionGroup>,
            F: Fn(&P, &str, bool) + 'static,
        >(
            this: *mut ffi::GActionGroup,
            action_name: *mut libc::c_char,
            enabled: glib::ffi::gboolean,
            f: glib::ffi::gpointer,
        ) {
            let f: &F = &*(f as *const F);
            f(
                ActionGroup::from_glib_borrow(this).unsafe_cast_ref(),
                &glib::GString::from_glib_borrow(action_name),
                from_glib(enabled),
            )
        }
        unsafe {
            let f: Box_<F> = Box_::new(f);
            let detailed_signal_name =
                detail.map(|name| format!("action-enabled-changed::{}\0", name));
            let signal_name: &[u8] = detailed_signal_name
                .as_ref()
                .map_or(&b"action-enabled-changed\0"[..], |n| n.as_bytes());
            connect_raw(
                self.as_ptr() as *mut _,
                signal_name.as_ptr() as *const _,
                Some(transmute::<_, unsafe extern "C" fn()>(
                    action_enabled_changed_trampoline::<Self, F> as *const (),
                )),
                Box_::into_raw(f),
            )
        }
    }

    fn connect_action_removed<F: Fn(&Self, &str) + 'static>(
        &self,
        detail: Option<&str>,
        f: F,
    ) -> SignalHandlerId {
        unsafe extern "C" fn action_removed_trampoline<
            P: IsA<ActionGroup>,
            F: Fn(&P, &str) + 'static,
        >(
            this: *mut ffi::GActionGroup,
            action_name: *mut libc::c_char,
            f: glib::ffi::gpointer,
        ) {
            let f: &F = &*(f as *const F);
            f(
                ActionGroup::from_glib_borrow(this).unsafe_cast_ref(),
                &glib::GString::from_glib_borrow(action_name),
            )
        }
        unsafe {
            let f: Box_<F> = Box_::new(f);
            let detailed_signal_name = detail.map(|name| format!("action-removed::{}\0", name));
            let signal_name: &[u8] = detailed_signal_name
                .as_ref()
                .map_or(&b"action-removed\0"[..], |n| n.as_bytes());
            connect_raw(
                self.as_ptr() as *mut _,
                signal_name.as_ptr() as *const _,
                Some(transmute::<_, unsafe extern "C" fn()>(
                    action_removed_trampoline::<Self, F> as *const (),
                )),
                Box_::into_raw(f),
            )
        }
    }

    fn connect_action_state_changed<F: Fn(&Self, &str, &glib::Variant) + 'static>(
        &self,
        detail: Option<&str>,
        f: F,
    ) -> SignalHandlerId {
        unsafe extern "C" fn action_state_changed_trampoline<
            P: IsA<ActionGroup>,
            F: Fn(&P, &str, &glib::Variant) + 'static,
        >(
            this: *mut ffi::GActionGroup,
            action_name: *mut libc::c_char,
            value: *mut glib::ffi::GVariant,
            f: glib::ffi::gpointer,
        ) {
            let f: &F = &*(f as *const F);
            f(
                ActionGroup::from_glib_borrow(this).unsafe_cast_ref(),
                &glib::GString::from_glib_borrow(action_name),
                &from_glib_borrow(value),
            )
        }
        unsafe {
            let f: Box_<F> = Box_::new(f);
            let detailed_signal_name =
                detail.map(|name| format!("action-state-changed::{}\0", name));
            let signal_name: &[u8] = detailed_signal_name
                .as_ref()
                .map_or(&b"action-state-changed\0"[..], |n| n.as_bytes());
            connect_raw(
                self.as_ptr() as *mut _,
                signal_name.as_ptr() as *const _,
                Some(transmute::<_, unsafe extern "C" fn()>(
                    action_state_changed_trampoline::<Self, F> as *const (),
                )),
                Box_::into_raw(f),
            )
        }
    }
}

impl fmt::Display for ActionGroup {
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
        f.write_str("ActionGroup")
    }
}