Coverage Report

Created: 2025-07-11 07:03

/src/rauc/subprojects/glib-2.76.5/gio/gactiongroup.c
Line
Count
Source (jump to first uncovered line)
1
/*
2
 * Copyright © 2010 Codethink Limited
3
 *
4
 * SPDX-License-Identifier: LGPL-2.1-or-later
5
 *
6
 * This library is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU Lesser General Public
8
 * License as published by the Free Software Foundation; either
9
 * version 2.1 of the License, or (at your option) any later version.
10
 *
11
 * This library is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14
 * Lesser General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU Lesser General
17
 * Public License along with this library; if not, see <http://www.gnu.org/licenses/>.
18
 *
19
 * Authors: Ryan Lortie <desrt@desrt.ca>
20
 */
21
22
#include "config.h"
23
#include "gactiongroup.h"
24
#include "gaction.h"
25
#include "glibintl.h"
26
#include "gmarshal-internal.h"
27
28
/**
29
 * SECTION:gactiongroup
30
 * @title: GActionGroup
31
 * @short_description: A group of actions
32
 * @include: gio/gio.h
33
 * @see_also: #GAction
34
 *
35
 * #GActionGroup represents a group of actions. Actions can be used to
36
 * expose functionality in a structured way, either from one part of a
37
 * program to another, or to the outside world. Action groups are often
38
 * used together with a #GMenuModel that provides additional
39
 * representation data for displaying the actions to the user, e.g. in
40
 * a menu.
41
 *
42
 * The main way to interact with the actions in a GActionGroup is to
43
 * activate them with g_action_group_activate_action(). Activating an
44
 * action may require a #GVariant parameter. The required type of the
45
 * parameter can be inquired with g_action_group_get_action_parameter_type().
46
 * Actions may be disabled, see g_action_group_get_action_enabled().
47
 * Activating a disabled action has no effect.
48
 *
49
 * Actions may optionally have a state in the form of a #GVariant. The
50
 * current state of an action can be inquired with
51
 * g_action_group_get_action_state(). Activating a stateful action may
52
 * change its state, but it is also possible to set the state by calling
53
 * g_action_group_change_action_state().
54
 *
55
 * As typical example, consider a text editing application which has an
56
 * option to change the current font to 'bold'. A good way to represent
57
 * this would be a stateful action, with a boolean state. Activating the
58
 * action would toggle the state.
59
 *
60
 * Each action in the group has a unique name (which is a string).  All
61
 * method calls, except g_action_group_list_actions() take the name of
62
 * an action as an argument.
63
 *
64
 * The #GActionGroup API is meant to be the 'public' API to the action
65
 * group.  The calls here are exactly the interaction that 'external
66
 * forces' (eg: UI, incoming D-Bus messages, etc.) are supposed to have
67
 * with actions.  'Internal' APIs (ie: ones meant only to be accessed by
68
 * the action group implementation) are found on subclasses.  This is
69
 * why you will find - for example - g_action_group_get_action_enabled()
70
 * but not an equivalent set() call.
71
 *
72
 * Signals are emitted on the action group in response to state changes
73
 * on individual actions.
74
 *
75
 * Implementations of #GActionGroup should provide implementations for
76
 * the virtual functions g_action_group_list_actions() and
77
 * g_action_group_query_action().  The other virtual functions should
78
 * not be implemented - their "wrappers" are actually implemented with
79
 * calls to g_action_group_query_action().
80
 */
81
82
/**
83
 * GActionGroup:
84
 *
85
 * #GActionGroup is an opaque data structure and can only be accessed
86
 * using the following functions.
87
 **/
88
89
/**
90
 * GActionGroupInterface:
91
 * @has_action: the virtual function pointer for g_action_group_has_action()
92
 * @list_actions: the virtual function pointer for g_action_group_list_actions()
93
 * @get_action_parameter_type: the virtual function pointer for g_action_group_get_action_parameter_type()
94
 * @get_action_state_type: the virtual function pointer for g_action_group_get_action_state_type()
95
 * @get_action_state_hint: the virtual function pointer for g_action_group_get_action_state_hint()
96
 * @get_action_enabled: the virtual function pointer for g_action_group_get_action_enabled()
97
 * @get_action_state: the virtual function pointer for g_action_group_get_action_state()
98
 * @change_action_state: the virtual function pointer for g_action_group_change_action_state()
99
 * @query_action: the virtual function pointer for g_action_group_query_action()
100
 * @activate_action: the virtual function pointer for g_action_group_activate_action()
101
 * @change_action_state: the virtual function pointer for g_action_group_change_action_state()
102
 * @action_added: the class closure for the #GActionGroup::action-added signal
103
 * @action_removed: the class closure for the #GActionGroup::action-removed signal
104
 * @action_enabled_changed: the class closure for the #GActionGroup::action-enabled-changed signal
105
 * @action_state_changed: the class closure for the #GActionGroup::action-enabled-changed signal
106
 *
107
 * The virtual function table for #GActionGroup.
108
 *
109
 * Since: 2.28
110
 **/
111
112
G_DEFINE_INTERFACE (GActionGroup, g_action_group, G_TYPE_OBJECT)
113
114
enum
115
{
116
  SIGNAL_ACTION_ADDED,
117
  SIGNAL_ACTION_REMOVED,
118
  SIGNAL_ACTION_ENABLED_CHANGED,
119
  SIGNAL_ACTION_STATE_CHANGED,
120
  NR_SIGNALS
121
};
122
123
static guint g_action_group_signals[NR_SIGNALS];
124
125
static gboolean
126
g_action_group_real_has_action (GActionGroup *action_group,
127
                                const gchar  *action_name)
128
0
{
129
0
  return g_action_group_query_action (action_group, action_name, NULL, NULL, NULL, NULL, NULL);
130
0
}
131
132
static gboolean
133
g_action_group_real_get_action_enabled (GActionGroup *action_group,
134
                                        const gchar  *action_name)
135
0
{
136
0
  gboolean enabled = FALSE;
137
138
0
  g_action_group_query_action (action_group, action_name, &enabled, NULL, NULL, NULL, NULL);
139
140
0
  return enabled;
141
0
}
142
143
static const GVariantType *
144
g_action_group_real_get_action_parameter_type (GActionGroup *action_group,
145
                                               const gchar  *action_name)
146
0
{
147
0
  const GVariantType *type = NULL;
148
149
0
  g_action_group_query_action (action_group, action_name, NULL, &type, NULL, NULL, NULL);
150
151
0
  return type;
152
0
}
153
154
static const GVariantType *
155
g_action_group_real_get_action_state_type (GActionGroup *action_group,
156
                                           const gchar  *action_name)
157
0
{
158
0
  const GVariantType *type = NULL;
159
160
0
  g_action_group_query_action (action_group, action_name, NULL, NULL, &type, NULL, NULL);
161
162
0
  return type;
163
0
}
164
165
static GVariant *
166
g_action_group_real_get_action_state_hint (GActionGroup *action_group,
167
                                           const gchar  *action_name)
168
0
{
169
0
  GVariant *hint = NULL;
170
171
0
  g_action_group_query_action (action_group, action_name, NULL, NULL, NULL, &hint, NULL);
172
173
0
  return hint;
174
0
}
175
176
static GVariant *
177
g_action_group_real_get_action_state (GActionGroup *action_group,
178
                                      const gchar  *action_name)
179
0
{
180
0
  GVariant *state = NULL;
181
182
0
  g_action_group_query_action (action_group, action_name, NULL, NULL, NULL, NULL, &state);
183
184
0
  return state;
185
0
}
186
187
static gboolean
188
g_action_group_real_query_action (GActionGroup        *action_group,
189
                                  const gchar         *action_name,
190
                                  gboolean            *enabled,
191
                                  const GVariantType **parameter_type,
192
                                  const GVariantType **state_type,
193
                                  GVariant           **state_hint,
194
                                  GVariant           **state)
195
0
{
196
0
  GActionGroupInterface *iface = G_ACTION_GROUP_GET_IFACE (action_group);
197
198
  /* we expect implementations to override this method, but we also
199
   * allow for implementations that existed before this method was
200
   * introduced to override the individual accessors instead.
201
   *
202
   * detect the case that neither has happened and report it.
203
   */
204
0
  if G_UNLIKELY (iface->has_action == g_action_group_real_has_action ||
205
0
                 iface->get_action_enabled == g_action_group_real_get_action_enabled ||
206
0
                 iface->get_action_parameter_type == g_action_group_real_get_action_parameter_type ||
207
0
                 iface->get_action_state_type == g_action_group_real_get_action_state_type ||
208
0
                 iface->get_action_state_hint == g_action_group_real_get_action_state_hint ||
209
0
                 iface->get_action_state == g_action_group_real_get_action_state)
210
0
    {
211
0
      g_critical ("Class '%s' implements GActionGroup interface without overriding "
212
0
                  "query_action() method -- bailing out to avoid infinite recursion.",
213
0
                  G_OBJECT_TYPE_NAME (action_group));
214
0
      return FALSE;
215
0
    }
216
217
0
  if (!(* iface->has_action) (action_group, action_name))
218
0
    return FALSE;
219
220
0
  if (enabled != NULL)
221
0
    *enabled = (* iface->get_action_enabled) (action_group, action_name);
222
223
0
  if (parameter_type != NULL)
224
0
    *parameter_type = (* iface->get_action_parameter_type) (action_group, action_name);
225
226
0
  if (state_type != NULL)
227
0
    *state_type = (* iface->get_action_state_type) (action_group, action_name);
228
229
0
  if (state_hint != NULL)
230
0
    *state_hint = (* iface->get_action_state_hint) (action_group, action_name);
231
232
0
  if (state != NULL)
233
0
    *state = (* iface->get_action_state) (action_group, action_name);
234
235
0
  return TRUE;
236
0
}
237
238
static void
239
g_action_group_default_init (GActionGroupInterface *iface)
240
0
{
241
0
  iface->has_action = g_action_group_real_has_action;
242
0
  iface->get_action_enabled = g_action_group_real_get_action_enabled;
243
0
  iface->get_action_parameter_type = g_action_group_real_get_action_parameter_type;
244
0
  iface->get_action_state_type = g_action_group_real_get_action_state_type;
245
0
  iface->get_action_state_hint = g_action_group_real_get_action_state_hint;
246
0
  iface->get_action_state = g_action_group_real_get_action_state;
247
0
  iface->query_action = g_action_group_real_query_action;
248
249
  /**
250
   * GActionGroup::action-added:
251
   * @action_group: the #GActionGroup that changed
252
   * @action_name: the name of the action in @action_group
253
   *
254
   * Signals that a new action was just added to the group.
255
   * This signal is emitted after the action has been added
256
   * and is now visible.
257
   *
258
   * Since: 2.28
259
   **/
260
0
  g_action_group_signals[SIGNAL_ACTION_ADDED] =
261
0
    g_signal_new (I_("action-added"),
262
0
                  G_TYPE_ACTION_GROUP,
263
0
                  G_SIGNAL_RUN_LAST | G_SIGNAL_DETAILED,
264
0
                  G_STRUCT_OFFSET (GActionGroupInterface, action_added),
265
0
                  NULL, NULL,
266
0
                  NULL,
267
0
                  G_TYPE_NONE, 1,
268
0
                  G_TYPE_STRING);
269
270
  /**
271
   * GActionGroup::action-removed:
272
   * @action_group: the #GActionGroup that changed
273
   * @action_name: the name of the action in @action_group
274
   *
275
   * Signals that an action is just about to be removed from the group.
276
   * This signal is emitted before the action is removed, so the action
277
   * is still visible and can be queried from the signal handler.
278
   *
279
   * Since: 2.28
280
   **/
281
0
  g_action_group_signals[SIGNAL_ACTION_REMOVED] =
282
0
    g_signal_new (I_("action-removed"),
283
0
                  G_TYPE_ACTION_GROUP,
284
0
                  G_SIGNAL_RUN_LAST | G_SIGNAL_DETAILED,
285
0
                  G_STRUCT_OFFSET (GActionGroupInterface, action_removed),
286
0
                  NULL, NULL,
287
0
                  NULL,
288
0
                  G_TYPE_NONE, 1,
289
0
                  G_TYPE_STRING);
290
291
292
  /**
293
   * GActionGroup::action-enabled-changed:
294
   * @action_group: the #GActionGroup that changed
295
   * @action_name: the name of the action in @action_group
296
   * @enabled: whether the action is enabled or not
297
   *
298
   * Signals that the enabled status of the named action has changed.
299
   *
300
   * Since: 2.28
301
   **/
302
0
  g_action_group_signals[SIGNAL_ACTION_ENABLED_CHANGED] =
303
0
    g_signal_new (I_("action-enabled-changed"),
304
0
                  G_TYPE_ACTION_GROUP,
305
0
                  G_SIGNAL_RUN_LAST | G_SIGNAL_DETAILED,
306
0
                  G_STRUCT_OFFSET (GActionGroupInterface,
307
0
                                   action_enabled_changed),
308
0
                  NULL, NULL,
309
0
                  _g_cclosure_marshal_VOID__STRING_BOOLEAN,
310
0
                  G_TYPE_NONE, 2,
311
0
                  G_TYPE_STRING,
312
0
                  G_TYPE_BOOLEAN);
313
0
  g_signal_set_va_marshaller (g_action_group_signals[SIGNAL_ACTION_ENABLED_CHANGED],
314
0
                              G_TYPE_FROM_INTERFACE (iface),
315
0
                              _g_cclosure_marshal_VOID__STRING_BOOLEANv);
316
317
  /**
318
   * GActionGroup::action-state-changed:
319
   * @action_group: the #GActionGroup that changed
320
   * @action_name: the name of the action in @action_group
321
   * @value: the new value of the state
322
   *
323
   * Signals that the state of the named action has changed.
324
   *
325
   * Since: 2.28
326
   **/
327
0
  g_action_group_signals[SIGNAL_ACTION_STATE_CHANGED] =
328
0
    g_signal_new (I_("action-state-changed"),
329
0
                  G_TYPE_ACTION_GROUP,
330
0
                  G_SIGNAL_RUN_LAST |
331
0
                  G_SIGNAL_DETAILED |
332
0
                  G_SIGNAL_MUST_COLLECT,
333
0
                  G_STRUCT_OFFSET (GActionGroupInterface,
334
0
                                   action_state_changed),
335
0
                  NULL, NULL,
336
0
                  _g_cclosure_marshal_VOID__STRING_VARIANT,
337
0
                  G_TYPE_NONE, 2,
338
0
                  G_TYPE_STRING,
339
0
                  G_TYPE_VARIANT);
340
0
  g_signal_set_va_marshaller (g_action_group_signals[SIGNAL_ACTION_STATE_CHANGED],
341
0
                              G_TYPE_FROM_INTERFACE (iface),
342
0
                              _g_cclosure_marshal_VOID__STRING_VARIANTv);
343
0
}
344
345
/**
346
 * g_action_group_list_actions:
347
 * @action_group: a #GActionGroup
348
 *
349
 * Lists the actions contained within @action_group.
350
 *
351
 * The caller is responsible for freeing the list with g_strfreev() when
352
 * it is no longer required.
353
 *
354
 * Returns: (transfer full): a %NULL-terminated array of the names of the
355
 * actions in the group
356
 *
357
 * Since: 2.28
358
 **/
359
gchar **
360
g_action_group_list_actions (GActionGroup *action_group)
361
0
{
362
0
  g_return_val_if_fail (G_IS_ACTION_GROUP (action_group), NULL);
363
364
0
  return G_ACTION_GROUP_GET_IFACE (action_group)
365
0
    ->list_actions (action_group);
366
0
}
367
368
/**
369
 * g_action_group_has_action:
370
 * @action_group: a #GActionGroup
371
 * @action_name: the name of the action to check for
372
 *
373
 * Checks if the named action exists within @action_group.
374
 *
375
 * Returns: whether the named action exists
376
 *
377
 * Since: 2.28
378
 **/
379
gboolean
380
g_action_group_has_action (GActionGroup *action_group,
381
                           const gchar  *action_name)
382
0
{
383
0
  g_return_val_if_fail (G_IS_ACTION_GROUP (action_group), FALSE);
384
385
0
  return G_ACTION_GROUP_GET_IFACE (action_group)
386
0
    ->has_action (action_group, action_name);
387
0
}
388
389
/**
390
 * g_action_group_get_action_parameter_type:
391
 * @action_group: a #GActionGroup
392
 * @action_name: the name of the action to query
393
 *
394
 * Queries the type of the parameter that must be given when activating
395
 * the named action within @action_group.
396
 *
397
 * When activating the action using g_action_group_activate_action(),
398
 * the #GVariant given to that function must be of the type returned
399
 * by this function.
400
 *
401
 * In the case that this function returns %NULL, you must not give any
402
 * #GVariant, but %NULL instead.
403
 *
404
 * The parameter type of a particular action will never change but it is
405
 * possible for an action to be removed and for a new action to be added
406
 * with the same name but a different parameter type.
407
 *
408
 * Returns: (nullable): the parameter type
409
 *
410
 * Since: 2.28
411
 **/
412
const GVariantType *
413
g_action_group_get_action_parameter_type (GActionGroup *action_group,
414
                                          const gchar  *action_name)
415
0
{
416
0
  g_return_val_if_fail (G_IS_ACTION_GROUP (action_group), NULL);
417
418
0
  return G_ACTION_GROUP_GET_IFACE (action_group)
419
0
    ->get_action_parameter_type (action_group, action_name);
420
0
}
421
422
/**
423
 * g_action_group_get_action_state_type:
424
 * @action_group: a #GActionGroup
425
 * @action_name: the name of the action to query
426
 *
427
 * Queries the type of the state of the named action within
428
 * @action_group.
429
 *
430
 * If the action is stateful then this function returns the
431
 * #GVariantType of the state.  All calls to
432
 * g_action_group_change_action_state() must give a #GVariant of this
433
 * type and g_action_group_get_action_state() will return a #GVariant
434
 * of the same type.
435
 *
436
 * If the action is not stateful then this function will return %NULL.
437
 * In that case, g_action_group_get_action_state() will return %NULL
438
 * and you must not call g_action_group_change_action_state().
439
 *
440
 * The state type of a particular action will never change but it is
441
 * possible for an action to be removed and for a new action to be added
442
 * with the same name but a different state type.
443
 *
444
 * Returns: (nullable): the state type, if the action is stateful
445
 *
446
 * Since: 2.28
447
 **/
448
const GVariantType *
449
g_action_group_get_action_state_type (GActionGroup *action_group,
450
                                      const gchar  *action_name)
451
0
{
452
0
  g_return_val_if_fail (G_IS_ACTION_GROUP (action_group), NULL);
453
454
0
  return G_ACTION_GROUP_GET_IFACE (action_group)
455
0
    ->get_action_state_type (action_group, action_name);
456
0
}
457
458
/**
459
 * g_action_group_get_action_state_hint:
460
 * @action_group: a #GActionGroup
461
 * @action_name: the name of the action to query
462
 *
463
 * Requests a hint about the valid range of values for the state of the
464
 * named action within @action_group.
465
 *
466
 * If %NULL is returned it either means that the action is not stateful
467
 * or that there is no hint about the valid range of values for the
468
 * state of the action.
469
 *
470
 * If a #GVariant array is returned then each item in the array is a
471
 * possible value for the state.  If a #GVariant pair (ie: two-tuple) is
472
 * returned then the tuple specifies the inclusive lower and upper bound
473
 * of valid values for the state.
474
 *
475
 * In any case, the information is merely a hint.  It may be possible to
476
 * have a state value outside of the hinted range and setting a value
477
 * within the range may fail.
478
 *
479
 * The return value (if non-%NULL) should be freed with
480
 * g_variant_unref() when it is no longer required.
481
 *
482
 * Returns: (nullable) (transfer full): the state range hint
483
 *
484
 * Since: 2.28
485
 **/
486
GVariant *
487
g_action_group_get_action_state_hint (GActionGroup *action_group,
488
                                      const gchar  *action_name)
489
0
{
490
0
  g_return_val_if_fail (G_IS_ACTION_GROUP (action_group), NULL);
491
492
0
  return G_ACTION_GROUP_GET_IFACE (action_group)
493
0
    ->get_action_state_hint (action_group, action_name);
494
0
}
495
496
/**
497
 * g_action_group_get_action_enabled:
498
 * @action_group: a #GActionGroup
499
 * @action_name: the name of the action to query
500
 *
501
 * Checks if the named action within @action_group is currently enabled.
502
 *
503
 * An action must be enabled in order to be activated or in order to
504
 * have its state changed from outside callers.
505
 *
506
 * Returns: whether or not the action is currently enabled
507
 *
508
 * Since: 2.28
509
 **/
510
gboolean
511
g_action_group_get_action_enabled (GActionGroup *action_group,
512
                                   const gchar  *action_name)
513
0
{
514
0
  g_return_val_if_fail (G_IS_ACTION_GROUP (action_group), FALSE);
515
516
0
  return G_ACTION_GROUP_GET_IFACE (action_group)
517
0
    ->get_action_enabled (action_group, action_name);
518
0
}
519
520
/**
521
 * g_action_group_get_action_state:
522
 * @action_group: a #GActionGroup
523
 * @action_name: the name of the action to query
524
 *
525
 * Queries the current state of the named action within @action_group.
526
 *
527
 * If the action is not stateful then %NULL will be returned.  If the
528
 * action is stateful then the type of the return value is the type
529
 * given by g_action_group_get_action_state_type().
530
 *
531
 * The return value (if non-%NULL) should be freed with
532
 * g_variant_unref() when it is no longer required.
533
 *
534
 * Returns: (nullable) (transfer full): the current state of the action
535
 *
536
 * Since: 2.28
537
 **/
538
GVariant *
539
g_action_group_get_action_state (GActionGroup *action_group,
540
                                 const gchar  *action_name)
541
0
{
542
0
  g_return_val_if_fail (G_IS_ACTION_GROUP (action_group), NULL);
543
544
0
  return G_ACTION_GROUP_GET_IFACE (action_group)
545
0
    ->get_action_state (action_group, action_name);
546
0
}
547
548
/**
549
 * g_action_group_change_action_state:
550
 * @action_group: a #GActionGroup
551
 * @action_name: the name of the action to request the change on
552
 * @value: the new state
553
 *
554
 * Request for the state of the named action within @action_group to be
555
 * changed to @value.
556
 *
557
 * The action must be stateful and @value must be of the correct type.
558
 * See g_action_group_get_action_state_type().
559
 *
560
 * This call merely requests a change.  The action may refuse to change
561
 * its state or may change its state to something other than @value.
562
 * See g_action_group_get_action_state_hint().
563
 *
564
 * If the @value GVariant is floating, it is consumed.
565
 *
566
 * Since: 2.28
567
 **/
568
void
569
g_action_group_change_action_state (GActionGroup *action_group,
570
                                    const gchar  *action_name,
571
                                    GVariant     *value)
572
0
{
573
0
  g_return_if_fail (G_IS_ACTION_GROUP (action_group));
574
0
  g_return_if_fail (action_name != NULL);
575
0
  g_return_if_fail (value != NULL);
576
577
0
  G_ACTION_GROUP_GET_IFACE (action_group)
578
0
    ->change_action_state (action_group, action_name, value);
579
0
}
580
581
/**
582
 * g_action_group_activate_action:
583
 * @action_group: a #GActionGroup
584
 * @action_name: the name of the action to activate
585
 * @parameter: (nullable): parameters to the activation
586
 *
587
 * Activate the named action within @action_group.
588
 *
589
 * If the action is expecting a parameter, then the correct type of
590
 * parameter must be given as @parameter.  If the action is expecting no
591
 * parameters then @parameter must be %NULL.  See
592
 * g_action_group_get_action_parameter_type().
593
 *
594
 * If the #GActionGroup implementation supports asynchronous remote
595
 * activation over D-Bus, this call may return before the relevant
596
 * D-Bus traffic has been sent, or any replies have been received. In
597
 * order to block on such asynchronous activation calls,
598
 * g_dbus_connection_flush() should be called prior to the code, which
599
 * depends on the result of the action activation. Without flushing
600
 * the D-Bus connection, there is no guarantee that the action would
601
 * have been activated.
602
 *
603
 * The following code which runs in a remote app instance, shows an
604
 * example of a "quit" action being activated on the primary app
605
 * instance over D-Bus. Here g_dbus_connection_flush() is called
606
 * before `exit()`. Without g_dbus_connection_flush(), the "quit" action
607
 * may fail to be activated on the primary instance.
608
 *
609
 * |[<!-- language="C" -->
610
 * // call "quit" action on primary instance
611
 * g_action_group_activate_action (G_ACTION_GROUP (app), "quit", NULL);
612
 *
613
 * // make sure the action is activated now
614
 * g_dbus_connection_flush (...);
615
 *
616
 * g_debug ("application has been terminated. exiting.");
617
 *
618
 * exit (0);
619
 * ]|
620
 *
621
 * Since: 2.28
622
 **/
623
void
624
g_action_group_activate_action (GActionGroup *action_group,
625
                                const gchar  *action_name,
626
                                GVariant     *parameter)
627
0
{
628
0
  g_return_if_fail (G_IS_ACTION_GROUP (action_group));
629
0
  g_return_if_fail (action_name != NULL);
630
631
0
  G_ACTION_GROUP_GET_IFACE (action_group)
632
0
    ->activate_action (action_group, action_name, parameter);
633
0
}
634
635
/**
636
 * g_action_group_action_added:
637
 * @action_group: a #GActionGroup
638
 * @action_name: the name of an action in the group
639
 *
640
 * Emits the #GActionGroup::action-added signal on @action_group.
641
 *
642
 * This function should only be called by #GActionGroup implementations.
643
 *
644
 * Since: 2.28
645
 **/
646
void
647
g_action_group_action_added (GActionGroup *action_group,
648
                             const gchar  *action_name)
649
0
{
650
0
  g_return_if_fail (G_IS_ACTION_GROUP (action_group));
651
0
  g_return_if_fail (action_name != NULL);
652
653
0
  g_signal_emit (action_group,
654
0
                 g_action_group_signals[SIGNAL_ACTION_ADDED],
655
0
                 g_quark_try_string (action_name),
656
0
                 action_name);
657
0
}
658
659
/**
660
 * g_action_group_action_removed:
661
 * @action_group: a #GActionGroup
662
 * @action_name: the name of an action in the group
663
 *
664
 * Emits the #GActionGroup::action-removed signal on @action_group.
665
 *
666
 * This function should only be called by #GActionGroup implementations.
667
 *
668
 * Since: 2.28
669
 **/
670
void
671
g_action_group_action_removed (GActionGroup *action_group,
672
                               const gchar  *action_name)
673
0
{
674
0
  g_return_if_fail (G_IS_ACTION_GROUP (action_group));
675
0
  g_return_if_fail (action_name != NULL);
676
677
0
  g_signal_emit (action_group,
678
0
                 g_action_group_signals[SIGNAL_ACTION_REMOVED],
679
0
                 g_quark_try_string (action_name),
680
0
                 action_name);
681
0
}
682
683
/**
684
 * g_action_group_action_enabled_changed:
685
 * @action_group: a #GActionGroup
686
 * @action_name: the name of an action in the group
687
 * @enabled: whether or not the action is now enabled
688
 *
689
 * Emits the #GActionGroup::action-enabled-changed signal on @action_group.
690
 *
691
 * This function should only be called by #GActionGroup implementations.
692
 *
693
 * Since: 2.28
694
 **/
695
void
696
g_action_group_action_enabled_changed (GActionGroup *action_group,
697
                                       const gchar  *action_name,
698
                                       gboolean      enabled)
699
0
{
700
0
  g_return_if_fail (G_IS_ACTION_GROUP (action_group));
701
0
  g_return_if_fail (action_name != NULL);
702
703
0
  enabled = !!enabled;
704
705
0
  g_signal_emit (action_group,
706
0
                 g_action_group_signals[SIGNAL_ACTION_ENABLED_CHANGED],
707
0
                 g_quark_try_string (action_name),
708
0
                 action_name,
709
0
                 enabled);
710
0
}
711
712
/**
713
 * g_action_group_action_state_changed:
714
 * @action_group: a #GActionGroup
715
 * @action_name: the name of an action in the group
716
 * @state: the new state of the named action
717
 *
718
 * Emits the #GActionGroup::action-state-changed signal on @action_group.
719
 *
720
 * This function should only be called by #GActionGroup implementations.
721
 *
722
 * Since: 2.28
723
 **/
724
void
725
g_action_group_action_state_changed (GActionGroup *action_group,
726
                                     const gchar  *action_name,
727
                                     GVariant     *state)
728
0
{
729
0
  g_return_if_fail (G_IS_ACTION_GROUP (action_group));
730
0
  g_return_if_fail (action_name != NULL);
731
732
0
  g_signal_emit (action_group,
733
0
                 g_action_group_signals[SIGNAL_ACTION_STATE_CHANGED],
734
0
                 g_quark_try_string (action_name),
735
0
                 action_name,
736
0
                 state);
737
0
}
738
739
/**
740
 * g_action_group_query_action:
741
 * @action_group: a #GActionGroup
742
 * @action_name: the name of an action in the group
743
 * @enabled: (out): if the action is presently enabled
744
 * @parameter_type: (out) (transfer none) (optional): the parameter type, or %NULL if none needed
745
 * @state_type: (out) (transfer none) (optional): the state type, or %NULL if stateless
746
 * @state_hint: (out) (optional): the state hint, or %NULL if none
747
 * @state: (out) (optional): the current state, or %NULL if stateless
748
 *
749
 * Queries all aspects of the named action within an @action_group.
750
 *
751
 * This function acquires the information available from
752
 * g_action_group_has_action(), g_action_group_get_action_enabled(),
753
 * g_action_group_get_action_parameter_type(),
754
 * g_action_group_get_action_state_type(),
755
 * g_action_group_get_action_state_hint() and
756
 * g_action_group_get_action_state() with a single function call.
757
 *
758
 * This provides two main benefits.
759
 *
760
 * The first is the improvement in efficiency that comes with not having
761
 * to perform repeated lookups of the action in order to discover
762
 * different things about it.  The second is that implementing
763
 * #GActionGroup can now be done by only overriding this one virtual
764
 * function.
765
 *
766
 * The interface provides a default implementation of this function that
767
 * calls the individual functions, as required, to fetch the
768
 * information.  The interface also provides default implementations of
769
 * those functions that call this function.  All implementations,
770
 * therefore, must override either this function or all of the others.
771
 *
772
 * If the action exists, %TRUE is returned and any of the requested
773
 * fields (as indicated by having a non-%NULL reference passed in) are
774
 * filled.  If the action doesn't exist, %FALSE is returned and the
775
 * fields may or may not have been modified.
776
 *
777
 * Returns: %TRUE if the action exists, else %FALSE
778
 *
779
 * Since: 2.32
780
 **/
781
gboolean
782
g_action_group_query_action (GActionGroup        *action_group,
783
                             const gchar         *action_name,
784
                             gboolean            *enabled,
785
                             const GVariantType **parameter_type,
786
                             const GVariantType **state_type,
787
                             GVariant           **state_hint,
788
                             GVariant           **state)
789
0
{
790
0
  return G_ACTION_GROUP_GET_IFACE (action_group)
791
0
    ->query_action (action_group, action_name, enabled, parameter_type, state_type, state_hint, state);
792
0
}