[glib/application] lots of action...
- From: Ryan Lortie <ryanl src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glib/application] lots of action...
- Date: Mon, 16 Aug 2010 03:18:31 +0000 (UTC)
commit ae4cc6c065dbec7c779386c162d012eae4e94c21
Author: Ryan Lortie <desrt desrt ca>
Date: Sun Aug 15 23:17:59 2010 -0400
lots of action...
gio/Makefile.am | 26 ++-
gio/gaction.h | 12 +-
gio/gactiongroup.c | 372 ++++++++++++++++++++++++++++++
gio/gactiongroup.h | 161 +++++++++++++
gio/gactiongrouparray.c | 571 ++++++++++++++++++++++++++++++++++++++++++++++
gio/gactiongrouparray.h | 98 ++++++++
gio/gio-marshal.list | 1 +
gio/gio.h | 4 +
gio/giotypes.h | 3 +
gio/gsimpleactiongroup.c | 380 ++++++++++++++++++++++++++++++
gio/gsimpleactiongroup.h | 98 ++++++++
11 files changed, 1718 insertions(+), 8 deletions(-)
---
diff --git a/gio/Makefile.am b/gio/Makefile.am
index 53a482b..2fa2f09 100644
--- a/gio/Makefile.am
+++ b/gio/Makefile.am
@@ -109,6 +109,24 @@ gdbus_sources = \
gdbusserver.h gdbusserver.c \
$(NULL)
+application_headers = \
+ gaction.h \
+ gactiongroup.h \
+ gactiongrouparray.h \
+ gsimpleactiongroup.h \
+ gapplication.h \
+ gapplicationcommandline.h
+
+application_sources = \
+ gaction.c \
+ gactiongroup.c \
+ gactiongrouparray.c \
+ gsimpleactiongroup.c \
+ gapplication.c \
+ gapplicationcommandline.c \
+ gapplicationimpl-dbus-interface.h \
+ gapplicationimpl-dbus-interface.c
+
settings_headers = \
gsettingsbackend.h \
gsettings.h
@@ -260,12 +278,6 @@ SUBDIRS += tests
libgio_2_0_la_SOURCES = \
gappinfo.c \
- gaction.c \
- gapplicationimpl-dbus-interface.h \
- gapplicationimpl-dbus-interface.c \
- gapplicationcommandline.c\
- gapplication.c \
- gapplication.h \
gasynchelper.c \
gasynchelper.h \
gasyncinitable.c \
@@ -364,6 +376,7 @@ libgio_2_0_la_SOURCES = \
$(appinfo_sources) \
$(unix_sources) \
$(win32_sources) \
+ $(application_sources) \
$(settings_sources) \
$(gdbus_sources) \
$(local_sources) \
@@ -497,6 +510,7 @@ gio_headers = \
gvolumemonitor.h \
gzlibcompressor.h \
gzlibdecompressor.h \
+ $(application_headers) \
$(settings_headers) \
$(gdbus_headers) \
$(NULL)
diff --git a/gio/gaction.h b/gio/gaction.h
index 6a8b953..1798416 100644
--- a/gio/gaction.h
+++ b/gio/gaction.h
@@ -73,8 +73,16 @@ struct _GActionClass
GObjectClass parent_class;
/*< public >*/
- void (* activate) (GAction *action,
- GVariant *parameter);
+ void (* activate) (GAction *action,
+ GVariant *parameter);
+
+ /*< signals >*/
+ void (* enabled_changed) (GAction *action,
+ gboolean enabled);
+ void (* state_changed) (GAction *action,
+ GVariant *value);
+ void (* state_range_changed) (GAction *action,
+ GVariant *value);
/*< private >*/
gpointer padding[12];
diff --git a/gio/gactiongroup.c b/gio/gactiongroup.c
new file mode 100644
index 0000000..dd462ff
--- /dev/null
+++ b/gio/gactiongroup.c
@@ -0,0 +1,372 @@
+/*
+ * Copyright © 2010 Codethink Limited
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published
+ * by the Free Software Foundation; either version 2 of the licence or (at
+ * your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General
+ * Public License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place, Suite 330,
+ * Boston, MA 02111-1307, USA.
+ *
+ * Authors: Ryan Lortie <desrt desrt ca>
+ */
+
+#include "gactiongroup.h"
+#include "gio-marshal.h"
+
+G_DEFINE_TYPE (GActionGroup, g_action_group, G_TYPE_ACTION_GROUP)
+
+enum
+{
+ SIGNAL_ACTION_ADDED,
+ SIGNAL_ACTION_REMOVED,
+ SIGNAL_ACTION_ENABLED_CHANGED,
+ SIGNAL_ACTION_STATE_CHANGED,
+ NR_SIGNALS
+};
+
+static guint g_action_group_signals[NR_SIGNALS];
+
+static void
+g_action_group_init (GActionGroup *action_group)
+{
+}
+
+static void
+g_action_group_class_init (GActionGroupClass *class)
+{
+ g_action_group_signals[SIGNAL_ACTION_ADDED] =
+ g_signal_new ("action-added",
+ G_TYPE_ACTION_GROUP, G_SIGNAL_RUN_LAST,
+ G_STRUCT_OFFSET (GActionGroupClass, action_added),
+ NULL, NULL, g_cclosure_marshal_VOID__STRING,
+ G_TYPE_NONE, 1, G_TYPE_STRING);
+
+ g_action_group_signals[SIGNAL_ACTION_REMOVED] =
+ g_signal_new ("action-removed",
+ G_TYPE_ACTION_GROUP, G_SIGNAL_RUN_LAST,
+ G_STRUCT_OFFSET (GActionGroupClass, action_removed),
+ NULL, NULL, g_cclosure_marshal_VOID__STRING,
+ G_TYPE_NONE, 1, G_TYPE_STRING);
+
+
+ g_action_group_signals[SIGNAL_ACTION_ENABLED_CHANGED] =
+ g_signal_new ("action-enabled-changed",
+ G_TYPE_ACTION_GROUP, G_SIGNAL_RUN_LAST,
+ G_STRUCT_OFFSET (GActionGroupClass, action_enabled_changed),
+ NULL, NULL, _gio_marshal_VOID__STRING_BOOLEAN,
+ G_TYPE_NONE, 2, G_TYPE_STRING);
+
+ g_action_group_signals[SIGNAL_ACTION_STATE_CHANGED] =
+ g_signal_new ("action-state-changed",
+ G_TYPE_ACTION_GROUP, G_SIGNAL_RUN_LAST,
+ G_STRUCT_OFFSET (GActionGroupClass, action_state_changed),
+ NULL, NULL, _gio_marshal_VOID__STRING_VARIANT,
+ G_TYPE_NONE, 1, G_TYPE_STRING);
+
+}
+
+/**
+ * g_action_group_has_action:
+ * @action_group: a #GActionGroup
+ * Returns: a list of the actions in the group
+ *
+ * Lists the actions contained within @action_group.
+ *
+ * The caller is responsible for freeing the list with g_strfreev() when
+ * it is no longer required.
+ **/
+gchar **
+g_action_group_list_actions (GActionGroup *action_group)
+{
+ return G_ACTION_GROUP_GET_CLASS (action_group)
+ ->list_actions (action_group);
+}
+
+/**
+ * g_action_group_has_action:
+ * @action_group: a #GActionGroup
+ * @action_name: the name of the action to check for
+ * Returns: whether the named action exists
+ *
+ * Checks if the named action exists within @action_group.
+ **/
+gboolean
+g_action_group_has_action (GActionGroup *action_group,
+ const gchar *action_name)
+{
+ return G_ACTION_GROUP_GET_CLASS (action_group)
+ ->has_action (action_group, action_name);
+}
+
+/**
+ * g_action_group_get_parameter_type:
+ * @action_group: a #GActionGroup
+ * @action_name: the name of the action to query
+ * Returns: (allow-none): the parameter type
+ *
+ * Queries the type of the parameter that must be given when activating
+ * the named action within @action_group.
+ *
+ * When activating the action using g_action_group_activate(), the
+ * #GVariant given to that function must be of the type returned by this
+ * function.
+ *
+ * In the case that this function returns %NULL, you must not give any
+ * #GVariant, but %NULL instead.
+ *
+ * Since: 2.26
+ **/
+const GVariantType *
+g_action_group_get_parameter_type (GActionGroup *action_group,
+ const gchar *action_name)
+{
+ return G_ACTION_GROUP_GET_CLASS (action_group)
+ ->get_parameter_type (action_group, action_name);
+}
+
+/**
+ * g_action_group_get_state_type:
+ * @action_group: a #GActionGroup
+ * @action_name: the name of the action to query
+ * Returns: (allow-none): the state type, if the action is stateful
+ *
+ * Queries the type of the state of the named action within
+ * @action_group.
+ *
+ * If the action is stateful then this function returns the
+ * #GVariantType of the state. All calls to g_action_group_set_state()
+ * must give a #GVariant of this type and g_action_group_get_state()
+ * will return a #GVariant of the same type.
+ *
+ * If the action is not stateful then this function will return %NULL.
+ * In that case, g_action_group_get_state() will return %NULL and you
+ * must not call g_action_group_set_state().
+ *
+ * Since: 2.26
+ **/
+ const GVariantType *
+g_action_group_get_state_type (GActionGroup *action_group,
+ const gchar *action_name)
+{
+ return G_ACTION_GROUP_GET_CLASS (action_group)
+ ->get_state_type (action_group, action_name);
+}
+
+/**
+ * g_action_group_get_state_range:
+ * @action_group: a #GActionGroup
+ * @action_name: the name of the action to query
+ * Returns: (allow-none): the state range hint
+ *
+ * Requests a hint about the valid range of values for the state of the
+ * named action within @action_group.
+ *
+ * If %NULL 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 #GVariant array is returned then each item in the array is a
+ * possible value for the state. If a #GVariant 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.
+ *
+ * Since: 2.26
+ **/
+GVariant *
+g_action_group_get_state_range (GActionGroup *action_group,
+ const gchar *action_name)
+{
+ return G_ACTION_GROUP_GET_CLASS (action_group)
+ ->get_state_range (action_group, action_name);
+}
+
+/**
+ * g_action_group_get_enabled:
+ * @action_group: a #GActionGroup
+ * @action_name: the name of the action to query
+ * Returns: whether or not the action is currently enabled
+ *
+ * Checks if the named action within @action_group is currently enabled.
+ *
+ * An action must be enabled in order to be activated or in order to
+ * have its state changed from outside callers.
+ *
+ * Since: 2.26
+ **/
+gboolean
+g_action_group_get_enabled (GActionGroup *action_group,
+ const gchar *action_name)
+{
+ return G_ACTION_GROUP_GET_CLASS (action_group)
+ ->get_enabled (action_group, action_name);
+}
+
+/**
+ * g_action_group_get_state:
+ * @action_group: a #GActionGroup
+ * @action_name: the name of the action to query
+ * Returns: (allow-none): the current state of the action
+ *
+ * Queries the current state of the named action within @action_group.
+ *
+ * If the action is not stateful then %NULL will be returned. If the
+ * action is stateful then the type of the return value is the type
+ * given by g_action_group_get_state_type().
+ *
+ * Since: 2.26
+ **/
+GVariant *
+g_action_group_get_state (GActionGroup *action_group,
+ const gchar *action_name)
+{
+ return G_ACTION_GROUP_GET_CLASS (action_group)
+ ->get_state (action_group, action_name);
+}
+
+/**
+ * g_action_group_set_state:
+ * @action_group: a #GActionGroup
+ * @action_name: the name of the action to request the change on
+ * @value: the new state
+ *
+ * Request for the state of the named action within @action_group to be
+ * changed to @value.
+ *
+ * The action must be stateful and @value must be of the correct type.
+ * See g_action_group_get_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 g_action_group_get_state_range().
+ *
+ * Since: 2.26
+ **/
+void
+g_action_group_set_state (GActionGroup *action_group,
+ const gchar *action_name,
+ GVariant *value)
+{
+ G_ACTION_GROUP_GET_CLASS (action_group)
+ ->set_state (action_group, action_name, value);
+}
+
+/**
+ * g_action_group_activate:
+ * @action_group: a #GActionGroup
+ * @action_name: the name of the action to activate
+ * @parameter: (allow-none): parameters to the activation
+ *
+ * Activate the named action within @action_group.
+ *
+ * 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 %NULL. See
+ * g_action_group_get_parameter_type().
+ *
+ * Since: 2.26
+ **/
+void
+g_action_group_activate (GActionGroup *action_group,
+ const gchar *action_name,
+ GVariant *parameter)
+{
+ G_ACTION_GROUP_GET_CLASS (action_group)
+ ->activate (action_group, action_name, parameter);
+}
+
+/**
+ * g_action_group_action_added:
+ * @action_group: a #GActionGroup
+ * @action_name: the name of an action in the group
+ *
+ * Emits the "action-added" signal on @action_group.
+ *
+ * This function should only be called by #GActionGroup implementations.
+ *
+ * Since: 2.26
+ **/
+void
+g_action_group_action_added (GActionGroup *action_group,
+ const gchar *action_name)
+{
+ g_signal_emit (action_group,
+ g_action_group_signals[SIGNAL_ACTION_ADDED],
+ g_quark_try_string (action_name), action_name);
+}
+
+/**
+ * g_action_group_action_removed:
+ * @action_group: a #GActionGroup
+ * @action_name: the name of an action in the group
+ *
+ * Emits the "action-removed" signal on @action_group.
+ *
+ * This function should only be called by #GActionGroup implementations.
+ *
+ * Since: 2.26
+ **/
+void
+g_action_group_action_removed (GActionGroup *action_group,
+ const gchar *action_name)
+{
+ g_signal_emit (action_group,
+ g_action_group_signals[SIGNAL_ACTION_REMOVED],
+ g_quark_try_string (action_name), action_name);
+}
+
+/**
+ * g_action_group_action_enabled_changed:
+ * @action_group: a #GActionGroup
+ * @action_name: the name of an action in the group
+ * @enabled: whether or not the action is now enabled
+ *
+ * Emits the "action-enabled-changed" signal on @action_group.
+ *
+ * This function should only be called by #GActionGroup implementations.
+ *
+ * Since: 2.26
+ **/
+void
+g_action_group_action_enabled_changed (GActionGroup *action_group,
+ const gchar *action_name,
+ gboolean enabled)
+{
+ g_signal_emit (action_group,
+ g_action_group_signals[SIGNAL_ACTION_ENABLED_CHANGED],
+ g_quark_try_string (action_name), action_name);
+}
+
+/**
+ * g_action_group_action_state_changed:
+ * @action_group: a #GActionGroup
+ * @action_name: the name of an action in the group
+ * @state: the new state of the named action
+ *
+ * Emits the "action-state-changed" signal on @action_group.
+ *
+ * This function should only be called by #GActionGroup implementations.
+ *
+ * Since: 2.26
+ **/
+void
+g_action_group_action_state_changed (GActionGroup *action_group,
+ const gchar *action_name,
+ GVariant *state)
+{
+ g_signal_emit (action_group,
+ g_action_group_signals[SIGNAL_ACTION_STATE_CHANGED],
+ g_quark_try_string (action_name), action_name);
+}
diff --git a/gio/gactiongroup.h b/gio/gactiongroup.h
new file mode 100644
index 0000000..c8af01f
--- /dev/null
+++ b/gio/gactiongroup.h
@@ -0,0 +1,161 @@
+/*
+ * Copyright © 2010 Codethink Limited
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published
+ * by the Free Software Foundation; either version 2 of the licence or (at
+ * your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General
+ * Public License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place, Suite 330,
+ * Boston, MA 02111-1307, USA.
+ *
+ * Authors: Ryan Lortie <desrt desrt ca>
+ */
+
+#if !defined (__GIO_GIO_H_INSIDE__) && !defined (GIO_COMPILATION)
+#error "Only <gio/gio.h> can be included directly."
+#endif
+
+#ifndef __G_ACTION_GROUP_H__
+#define __G_ACTION_GROUP_H__
+
+#include <gio/giotypes.h>
+
+G_BEGIN_DECLS
+
+#define G_TYPE_ACTION_GROUP (g_action_group_get_type ())
+#define G_ACTION_GROUP(inst) (G_TYPE_CHECK_INSTANCE_CAST ((inst), \
+ G_TYPE_ACTION_GROUP, GActionGroup))
+#define G_ACTION_GROUP_CLASS(class) (G_TYPE_CHECK_CLASS_CAST ((class), \
+ G_TYPE_ACTION_GROUP, GActionGroupClass))
+#define G_IS_ACTION_GROUP(inst) (G_TYPE_CHECK_INSTANCE_TYPE ((inst), G_TYPE_ACTION))
+#define G_IS_ACTION_GROUP_CLASS(class) (G_TYPE_CHECK_CLASS_TYPE ((class), G_TYPE_ACTION))
+#define G_ACTION_GROUP_GET_CLASS(inst) (G_TYPE_INSTANCE_GET_CLASS ((inst), \
+ G_TYPE_ACTION_GROUP, GActionGroupClass))
+
+typedef struct _GActionGroupPrivate GActionGroupPrivate;
+typedef struct _GActionGroupClass GActionGroupClass;
+
+/**
+ * GActionGroup:
+ *
+ * The <structname>GActionGroup</structname> structure contains private
+ * data and should only be accessed using the provided API
+ *
+ * Since: 2.26
+ */
+struct _GActionGroup
+{
+ /*< private >*/
+ GObject parent_instance;
+
+ GActionGroupPrivate *priv;
+};
+
+/**
+ * GActionGroupClass:
+ *
+ * The <structname>GActionGroupClass</structname> structure contains
+ * private data only
+ *
+ * Since: 2.26
+ */
+struct _GActionGroupClass
+{
+ /*< private >*/
+ GObjectClass parent_class;
+
+ /*< public >*/
+ gchar ** (* list_actions) (GActionGroup *action_group);
+
+ gboolean (* has_action) (GActionGroup *action_group,
+ const gchar *action_name);
+
+ const GVariantType * (* get_parameter_type) (GActionGroup *action_group,
+ const gchar *action_name);
+
+ const GVariantType * (* get_state_type) (GActionGroup *action_group,
+ const gchar *action_name);
+
+ GVariant * (* get_state_range) (GActionGroup *action_group,
+ const gchar *action_name);
+
+ gboolean (* get_enabled) (GActionGroup *action_group,
+ const gchar *action_name);
+
+ GVariant * (* get_state) (GActionGroup *action_group,
+ const gchar *action_name);
+
+ void (* set_state) (GActionGroup *action_group,
+ const gchar *action_name,
+ GVariant *value);
+
+ void (* activate) (GActionGroup *action_group,
+ const gchar *action_name,
+ GVariant *parameter);
+
+ /*< signals >*/
+ void (* action_added) (GActionGroup *action_group,
+ const gchar *action_name);
+ void (* action_removed) (GActionGroup *action_group,
+ const gchar *action_name);
+ void (* action_enabled_changed) (GActionGroup *action_group,
+ const gchar *action_name,
+ gboolean enabled);
+ void (* action_state_changed) (GActionGroup *action_group,
+ const gchar *action_name,
+ GVariant *value);
+
+ /*< private >*/
+ gpointer padding[12];
+};
+
+GType g_action_group_get_type (void) G_GNUC_CONST;
+
+gchar ** g_action_group_list_actions (GActionGroup *action_group);
+gboolean g_action_group_has_action (GActionGroup *action_group,
+ const gchar *action_name);
+
+const GVariantType * g_action_group_get_parameter_type (GActionGroup *action_group,
+ const gchar *action_name);
+const GVariantType * g_action_group_get_state_type (GActionGroup *action_group,
+ const gchar *action_name);
+GVariant * g_action_group_get_state_range (GActionGroup *action_group,
+ const gchar *action_name);
+
+gboolean g_action_group_get_enabled (GActionGroup *action_group,
+ const gchar *action_name);
+
+GVariant * g_action_group_get_state (GActionGroup *action_group,
+ const gchar *action_name);
+void g_action_group_set_state (GActionGroup *action_group,
+ const gchar *action_name,
+ GVariant *value);
+
+void g_action_group_activate (GActionGroup *action_group,
+ const gchar *action_name,
+ GVariant *parameter);
+
+/* signals */
+void g_action_group_action_added (GActionGroup *action_group,
+ const gchar *action_name);
+void g_action_group_action_removed (GActionGroup *action_group,
+ const gchar *action_name);
+void g_action_group_action_enabled_changed (GActionGroup *action_group,
+ const gchar *action_name,
+ gboolean enabled);
+
+void g_action_group_action_state_changed (GActionGroup *action_group,
+ const gchar *action_name,
+ GVariant *state);
+
+G_END_DECLS
+
+#endif /* __G_ACTION_GROUP_H__ */
diff --git a/gio/gactiongrouparray.c b/gio/gactiongrouparray.c
new file mode 100644
index 0000000..0d583be
--- /dev/null
+++ b/gio/gactiongrouparray.c
@@ -0,0 +1,571 @@
+/*
+ * Copyright © 2010 Codethink Limited
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published
+ * by the Free Software Foundation; either version 2 of the licence or (at
+ * your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General
+ * Public License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place, Suite 330,
+ * Boston, MA 02111-1307, USA.
+ *
+ * Authors: Ryan Lortie <desrt desrt ca>
+ */
+
+#include "gactiongrouparray.h"
+#include "gaction.h"
+
+struct _GActionGroupArrayPrivate
+{
+ GHashTable *table; /* string -> GActionGroup */
+
+ GActionGroup **groups;
+ gint n_groups;
+};
+
+G_DEFINE_TYPE (GActionGroupArray, g_action_group_array, G_TYPE_ACTION_GROUP)
+
+static gchar **
+g_action_group_array_list_actions (GActionGroup *group)
+{
+ GActionGroupArray *array = G_ACTION_GROUP_ARRAY (group);
+ GHashTableIter iter;
+ gint n, i = 0;
+ gchar **keys;
+ gpointer key;
+
+ n = g_hash_table_size (array->priv->table);
+ keys = g_new (gchar *, n + 1);
+
+ g_hash_table_iter_init (&iter, array->priv->table);
+ while (g_hash_table_iter_next (&iter, &key, NULL))
+ keys[i++] = g_strdup (key);
+ g_assert_cmpint (i, ==, n);
+ keys[n] = NULL;
+
+ return keys;
+}
+
+static gboolean
+g_action_group_array_has_action (GActionGroup *group,
+ const gchar *action_name)
+{
+ GActionGroupArray *array = G_ACTION_GROUP_ARRAY (group);
+
+ return g_hash_table_lookup (array->priv->table, action_name) != NULL;
+}
+
+static const GVariantType *
+g_action_group_array_get_parameter_type (GActionGroup *group,
+ const gchar *action_name)
+{
+ GActionGroupArray *array = G_ACTION_GROUP_ARRAY (group);
+ GActionGroup *action_group;
+
+ action_group = g_hash_table_lookup (array->priv->table, action_name);
+
+ if (action_group == NULL)
+ return NULL;
+
+ return g_action_group_get_parameter_type (action_group, action_name);
+}
+
+static const GVariantType *
+g_action_group_array_get_state_type (GActionGroup *group,
+ const gchar *action_name)
+{
+ GActionGroupArray *array = G_ACTION_GROUP_ARRAY (group);
+ GActionGroup *action_group;
+
+ action_group = g_hash_table_lookup (array->priv->table, action_name);
+
+ if (action_group == NULL)
+ return NULL;
+
+ return g_action_group_get_state_type (action_group, action_name);
+}
+
+static GVariant *
+g_action_group_array_get_state_range (GActionGroup *group,
+ const gchar *action_name)
+{
+ GActionGroupArray *array = G_ACTION_GROUP_ARRAY (group);
+ GActionGroup *action_group;
+
+ action_group = g_hash_table_lookup (array->priv->table, action_name);
+
+ if (action_group == NULL)
+ return NULL;
+
+ return g_action_group_get_state_range (action_group, action_name);
+}
+
+static gboolean
+g_action_group_array_get_enabled (GActionGroup *group,
+ const gchar *action_name)
+{
+ GActionGroupArray *array = G_ACTION_GROUP_ARRAY (group);
+ GActionGroup *action_group;
+
+ action_group = g_hash_table_lookup (array->priv->table, action_name);
+
+ if (action_group == NULL)
+ return FALSE;
+
+ return g_action_group_get_enabled (action_group, action_name);
+}
+
+static GVariant *
+g_action_group_array_get_state (GActionGroup *group,
+ const gchar *action_name)
+{
+ GActionGroupArray *array = G_ACTION_GROUP_ARRAY (group);
+ GActionGroup *action_group;
+
+ action_group = g_hash_table_lookup (array->priv->table, action_name);
+
+ if (action_group == NULL)
+ return NULL;
+
+ return g_action_group_get_state (action_group, action_name);
+}
+
+static void
+g_action_group_array_set_state (GActionGroup *group,
+ const gchar *action_name,
+ GVariant *value)
+{
+ GActionGroupArray *array = G_ACTION_GROUP_ARRAY (group);
+ GActionGroup *action_group;
+
+ action_group = g_hash_table_lookup (array->priv->table, action_name);
+
+ if (action_group == NULL)
+ return;
+
+ return g_action_group_set_state (action_group, action_name, value);
+}
+
+static void
+g_action_group_array_activate (GActionGroup *group,
+ const gchar *action_name,
+ GVariant *parameter)
+{
+ GActionGroupArray *array = G_ACTION_GROUP_ARRAY (group);
+ GActionGroup *action_group;
+
+ action_group = g_hash_table_lookup (array->priv->table, action_name);
+
+ if (action_group == NULL)
+ return;
+
+ return g_action_group_activate (action_group, action_name, parameter);
+}
+
+static void
+action_added (GActionGroup *group,
+ const gchar *action_name,
+ gpointer user_data)
+{
+ GActionGroupArray *array = user_data;
+ GActionGroup *old_group;
+
+ old_group = g_hash_table_lookup (array->priv->table, action_name);
+
+ if (group == old_group)
+ /* already exists as itself... */
+ g_warning ("'%s' emits 'action-added' on already-existing action '%s'",
+ G_OBJECT_TYPE_NAME (group), action_name);
+
+ else if (group == NULL)
+ /* doesn't exist yet: definitely add it. */
+ {
+ g_hash_table_insert (array->priv->table, g_strdup (action_name), group);
+ g_action_group_action_added (G_ACTION_GROUP (array), action_name);
+ }
+
+ else
+ /* already exists, in another group. check who wins. */
+ {
+ gint i;
+
+ /* the winner is the first one in the array. */
+ for (i = 0; i < array->priv->n_groups; i++)
+ if (array->priv->groups[i] == group)
+ /* found the adding group first: change it up. */
+ {
+ g_action_group_action_removed (G_ACTION_GROUP (array),
+ action_name);
+ g_hash_table_insert (array->priv->table,
+ g_strdup (action_name), group);
+ g_action_group_action_added (G_ACTION_GROUP (array),
+ action_name);
+ return;
+ }
+
+ else if (array->priv->groups[i] == old_group)
+ /* found old group first: do nothing. */
+ return;
+
+ /* both groups should be in the array, so it's
+ * double-impossible to be here.
+ */
+ g_assert_not_reached ();
+ }
+}
+
+static void
+action_removed (GActionGroup *group,
+ const gchar *action_name,
+ gpointer user_data)
+{
+ GActionGroupArray *array = user_data;
+ GActionGroup *old_group;
+
+ old_group = g_hash_table_lookup (array->priv->table, action_name);
+
+ /* only handle the remove if this group held this action.
+ * ie: don't drop an action that another group is responsible for.
+ */
+ if (old_group == NULL)
+ g_warning ("'%s' emits 'action-removed' on non-existent action '%s'",
+ G_OBJECT_TYPE_NAME (group), action_name);
+
+ else if (group == old_group)
+ {
+ gint i;
+
+ g_action_group_action_removed (G_ACTION_GROUP (array), action_name);
+ g_hash_table_remove (array->priv->table, g_strdup (action_name));
+
+ /* check if any other of our groups have it and re-add it.
+ *
+ * note: even if we re-find the action, the parameter/state type
+ * might have changed so it's important that we did the
+ * 'remove' above.
+ */
+ for (i = 0; i < array->priv->n_groups; i++)
+ if (array->priv->groups[i] != group &&
+ g_action_group_has_action (array->priv->groups[i], action_name))
+ {
+ g_hash_table_insert (array->priv->table,
+ g_strdup (action_name),
+ array->priv->groups[i]);
+ g_action_group_action_added (G_ACTION_GROUP (array),
+ action_name);
+
+ return;
+ }
+
+ /* nothing found? too bad... */
+ }
+}
+
+static void
+action_enabled_changed (GActionGroup *group,
+ const gchar *action_name,
+ gboolean enabled,
+ gpointer user_data)
+{
+ GActionGroupArray *array = user_data;
+
+ if (g_hash_table_lookup (array->priv->table, action_name) == group)
+ g_action_group_action_enabled_changed (user_data, action_name, enabled);
+}
+
+static void
+action_state_changed (GActionGroup *group,
+ const gchar *action_name,
+ GVariant *value,
+ gpointer user_data)
+{
+ GActionGroupArray *array = user_data;
+
+ if (g_hash_table_lookup (array->priv->table, action_name) == group)
+ g_action_group_action_state_changed (user_data, action_name, value);
+}
+
+static void
+g_action_group_array_disconnect (GActionGroupArray *array,
+ GActionGroup *group)
+{
+ g_signal_handlers_disconnect_by_func (group, action_added, array);
+ g_signal_handlers_disconnect_by_func (group, action_removed, array);
+ g_signal_handlers_disconnect_by_func (group, action_enabled_changed, array);
+ g_signal_handlers_disconnect_by_func (group, action_state_changed, array);
+}
+
+static void
+g_action_group_array_finalize (GObject *object)
+{
+ GActionGroupArray *array = G_ACTION_GROUP_ARRAY (object);
+ gint i;
+
+ for (i = 0; i < array->priv->n_groups; i++)
+ {
+ g_action_group_array_disconnect (array, array->priv->groups[i]);
+ g_object_unref (array->priv->groups[i]);
+ }
+
+ g_hash_table_unref (array->priv->table);
+ g_free (array->priv->groups);
+
+ G_OBJECT_CLASS (g_action_group_array_parent_class)
+ ->finalize (object);
+}
+
+static void
+g_action_group_array_init (GActionGroupArray *array)
+{
+ array->priv = G_TYPE_INSTANCE_GET_PRIVATE (array,
+ G_TYPE_ACTION_GROUP_ARRAY,
+ GActionGroupArrayPrivate);
+ array->priv->table = g_hash_table_new_full (g_str_hash, g_str_equal,
+ g_free, g_object_unref);
+}
+
+static void
+g_action_group_array_class_init (GActionGroupArrayClass *class)
+{
+ GActionGroupClass *group_class = G_ACTION_GROUP_CLASS (class);
+ GObjectClass *object_class = G_OBJECT_CLASS (class);
+
+ object_class->finalize = g_action_group_array_finalize;
+
+ group_class->list_actions = g_action_group_array_list_actions;
+ group_class->has_action = g_action_group_array_has_action;
+ group_class->get_parameter_type = g_action_group_array_get_parameter_type;
+ group_class->get_state_type = g_action_group_array_get_state_type;
+ group_class->get_state_range = g_action_group_array_get_state_range;
+ group_class->get_enabled = g_action_group_array_get_enabled;
+ group_class->get_state = g_action_group_array_get_state;
+ group_class->set_state = g_action_group_array_set_state;
+ group_class->activate = g_action_group_array_activate;
+
+ g_type_class_add_private (class, sizeof (GActionGroupArrayPrivate));
+}
+
+/**
+ * g_action_group_array_new:
+ * Returns: a new #GActionGroupArray
+ *
+ * Creates a new, empty, #GActionGroupArray.
+ **/
+GActionGroupArray *
+g_action_group_array_new (void)
+{
+ return g_object_new (G_TYPE_ACTION_GROUP_ARRAY, NULL);
+}
+
+/**
+ * g_action_group_array_index:
+ * @array: a #GActionGroupArray
+ * @action_name: the name of an action
+ * Returns: (transfer none): a #GActionGroup, or %NULL
+ *
+ * Looks up the action with the name @action_name in the group.
+ *
+ * If no such action exists, returns %NULL.
+ **/
+GActionGroup *
+g_action_group_array_lookup (GActionGroupArray *array,
+ const gchar *action_name)
+{
+ g_return_val_if_fail (G_IS_ACTION_GROUP_ARRAY (array), NULL);
+
+ return g_hash_table_lookup (array->priv->table, action_name);
+}
+
+/**
+ * g_action_group_array_get_length:
+ * @array: a #GActionGroupArray
+ * Returns: the length of @array
+ *
+ * Returns the number of action groups currently held within @array.
+ *
+ * Since: 2.26
+ **/
+gint
+g_action_group_array_get_length (GActionGroupArray *array)
+{
+ g_return_val_if_fail (G_IS_ACTION_GROUP_ARRAY (array), 0);
+
+ return array->priv->n_groups;
+}
+
+/**
+ * g_action_group_array_index:
+ * @array: a #GActionGroupArray
+ * @index_: the index within the array
+ * Returns (transfer none): a #GActionGroup
+ *
+ * Gets the #GActionGroup at position @index_ within @array.
+ *
+ * @index_ must be a valid index into the array. See
+ * g_action_group_array_get_length().
+ *
+ * Since: 2.26
+ **/
+GActionGroup *
+g_action_group_array_index (GActionGroupArray *array,
+ gint index_)
+{
+ g_return_val_if_fail (G_IS_ACTION_GROUP_ARRAY (array), NULL);
+ g_return_val_if_fail (0 <= index_ && index_ < array->priv->n_groups, NULL);
+
+ return array->priv->groups[index_];
+}
+
+/**
+ * g_action_group_array_insert:
+ * @array: a #GActionGroupArray
+ * @index_: the index at which to insert, or -1
+ * @group: the #GActionGroup to add
+ *
+ * Adds a #GActionGroup to @array.
+ *
+ * @group must not already be a member of the array.
+ *
+ * If @index_ is negative or otherwise out of range, @group is appended
+ * to the end of the array.
+ *
+ * In the event that two groups in the array have an action with the
+ * same name then the action within the group appearing at the lower
+ * index in the array has precedence.
+ *
+ * The array takes its own reference on @group. "action-added" signals
+ * are emitted for each action in @group that isn't shadowed by an
+ * action in another group that comes first in the array.
+ *
+ * Since: 2.26
+ **/
+void
+g_action_group_array_insert (GActionGroupArray *array,
+ gint index_,
+ GActionGroup *group)
+{
+ gchar **actions;
+ gint i;
+
+ g_return_if_fail (G_IS_ACTION_GROUP_ARRAY (array));
+ g_return_if_fail (G_IS_ACTION_GROUP (group));
+
+ if (index_ < 0 || index_ > array->priv->n_groups)
+ index_ = array->priv->n_groups;
+
+ for (i = 0; i < array->priv->n_groups; i++)
+ g_return_if_fail (group == array->priv->groups[i]);
+
+ /* insert into the array */
+ array->priv->groups = g_renew (GActionGroup *,
+ array->priv->groups,
+ ++array->priv->n_groups);
+
+ for (i = array->priv->n_groups - 1; i > index_; i--)
+ array->priv->groups[i] = array->priv->groups[i - 1];
+
+ array->priv->groups[index_] = g_object_ref (group);
+
+ /* watch for changes */
+ g_signal_connect (group, "action-added",
+ G_CALLBACK (action_added), array);
+ g_signal_connect (group, "action-removed",
+ G_CALLBACK (action_removed), array);
+ g_signal_connect (group, "action-enabled-changed",
+ G_CALLBACK (action_enabled_changed), array);
+ g_signal_connect (group, "action-state-changed",
+ G_CALLBACK (action_state_changed), array);
+
+ /* add existing actions */
+ actions = g_action_group_list_actions (group);
+
+ for (i = 0; actions[i]; i++)
+ action_added (group, actions[i], array);
+
+ g_strfreev (actions);
+}
+
+/**
+ * g_action_group_array_remove:
+ * @array: a #GActionGroupArray
+ * @index_: the index to remove
+ *
+ * Drops the action group at the given index from @array.
+ *
+ * @index_ must be a valid index into the array. See
+ * g_action_group_array_get_length().
+ *
+ * If you do not know the index, see
+ * g_action_group_array_remove_group().
+ *
+ * Since: 2.26
+ **/
+void
+g_action_group_array_remove (GActionGroupArray *array,
+ gint index_)
+{
+ GActionGroup *group;
+ gchar **actions;
+ gint i;
+
+ g_return_if_fail (G_IS_ACTION_GROUP_ARRAY (array));
+ g_return_if_fail (0 <= index_ && index_ < array->priv->n_groups);
+
+ group = array->priv->groups[index_];
+
+ /* remove existing actions */
+ actions = g_action_group_list_actions (group);
+
+ for (i = 0; actions[i]; i++)
+ action_added (group, actions[i], array);
+
+ g_strfreev (actions);
+
+ /* disconnect signals */
+ g_action_group_array_disconnect (array, group);
+
+ /* drop from array, don't bother with the g_renew... */
+ array->priv->n_groups--;
+ for (i = index_; i < array->priv->n_groups; i++)
+ array->priv->groups[i] = array->priv->groups[i + 1];
+
+ g_object_unref (group);
+}
+
+/**
+ * g_action_group_array_remove_group:
+ * @array: a #GActionGroupArray
+ * @group: the #GActionGroup to remove
+ *
+ * Drops @group from @array.
+ *
+ * If @group is not in @array, this function does nothing.
+ *
+ * This function is an alternative to g_action_group_array_remove() that
+ * spares you from searching for the correct index.
+ *
+ * Since: 2.26
+ **/
+void
+g_action_group_array_remove_group (GActionGroupArray *array,
+ GActionGroup *group)
+{
+ gint i;
+
+ g_return_if_fail (G_IS_ACTION_GROUP_ARRAY (array));
+ g_return_if_fail (G_IS_ACTION_GROUP (group));
+
+ for (i = 0; i < array->priv->n_groups; i++)
+ if (group == array->priv->groups[i])
+ {
+ g_action_group_array_remove (array, i);
+ break;
+ }
+}
diff --git a/gio/gactiongrouparray.h b/gio/gactiongrouparray.h
new file mode 100644
index 0000000..54e8c4c
--- /dev/null
+++ b/gio/gactiongrouparray.h
@@ -0,0 +1,98 @@
+/*
+ * Copyright © 2010 Codethink Limited
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published
+ * by the Free Software Foundation; either version 2 of the licence or (at
+ * your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General
+ * Public License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place, Suite 330,
+ * Boston, MA 02111-1307, USA.
+ *
+ * Authors: Ryan Lortie <desrt desrt ca>
+ */
+
+#if !defined (__GIO_GIO_H_INSIDE__) && !defined (GIO_COMPILATION)
+#error "Only <gio/gio.h> can be included directly."
+#endif
+
+#ifndef __G_ACTION_GROUP_ARRAY_H__
+#define __G_ACTION_GROUP_ARRAY_H__
+
+#include "gactiongroup.h"
+
+G_BEGIN_DECLS
+
+#define G_TYPE_ACTION_GROUP_ARRAY (g_action_group_array_get_type ())
+#define G_ACTION_GROUP_ARRAY(inst) (G_TYPE_CHECK_INSTANCE_CAST ((inst), \
+ G_TYPE_ACTION_GROUP_ARRAY, GActionGroupArray))
+#define G_ACTION_GROUP_ARRAY_CLASS(class) (G_TYPE_CHECK_CLASS_CAST ((class), \
+ G_TYPE_ACTION_GROUP_ARRAY, GActionGroupArrayClass))
+#define G_IS_ACTION_GROUP_ARRAY(inst) (G_TYPE_CHECK_INSTANCE_TYPE ((inst), G_TYPE_ACTION))
+#define G_IS_ACTION_GROUP_ARRAY_CLASS(class) (G_TYPE_CHECK_CLASS_TYPE ((class), G_TYPE_ACTION))
+#define G_ACTION_GROUP_ARRAY_GET_CLASS(inst) (G_TYPE_INSTANCE_GET_CLASS ((inst), \
+ G_TYPE_ACTION_GROUP_ARRAY, GActionGroupArrayClass))
+
+typedef struct _GActionGroupArrayPrivate GActionGroupArrayPrivate;
+typedef struct _GActionGroupArrayClass GActionGroupArrayClass;
+
+/**
+ * GActionGroupArray:
+ *
+ * The <structname>GActionGroupArray</structname> structure contains private
+ * data and should only be accessed using the provided API
+ *
+ * Since: 2.26
+ */
+struct _GActionGroupArray
+{
+ /*< private >*/
+ GActionGroup parent_instance;
+
+ GActionGroupArrayPrivate *priv;
+};
+
+/**
+ * GActionGroupArrayClass:
+ *
+ * The <structname>GActionGroupArrayClass</structname> structure contains
+ * private data only
+ *
+ * Since: 2.26
+ */
+struct _GActionGroupArrayClass
+{
+ /*< private >*/
+ GActionGroupClass parent_class;
+
+ /*< private >*/
+ gpointer padding[12];
+};
+
+GType g_action_group_array_get_type (void) G_GNUC_CONST;
+
+GActionGroupArray * g_action_group_array_new (void);
+
+GActionGroup * g_action_group_array_index (GActionGroupArray *array,
+ gint index_);
+
+void g_action_group_array_insert (GActionGroupArray *array,
+ gint index_,
+ GActionGroup *group);
+
+void g_action_group_array_remove (GActionGroupArray *array,
+ gint index_);
+
+void g_action_group_array_remove_group (GActionGroupArray *array,
+ GActionGroup *group);
+
+G_END_DECLS
+
+#endif /* __G_ACTION_GROUP_ARRAY_H__ */
diff --git a/gio/gio-marshal.list b/gio/gio-marshal.list
index 4db6b19..ec69fed 100644
--- a/gio/gio-marshal.list
+++ b/gio/gio-marshal.list
@@ -20,4 +20,5 @@ VOID:VARIANT,BOXED
VOID:STRING,STRING,VARIANT
VOID:POINTER,INT,STRING
VOID:STRING,VARIANT
+VOID:STRING,BOOL
INT:OBJECT
diff --git a/gio/gio.h b/gio/gio.h
index 8cbdc0c..5101d2e 100644
--- a/gio/gio.h
+++ b/gio/gio.h
@@ -29,6 +29,10 @@
#include <gio/gappinfo.h>
#include <gio/gaction.h>
+#include <gio/gactiongroup.h>
+#include <gio/gsimpleactiongroup.h>
+#include <gio/gactiongrouparray.h>
+#include <gio/gapplicationcommandline.h>
#include <gio/gapplication.h>
#include <gio/gasyncinitable.h>
#include <gio/gasyncresult.h>
diff --git a/gio/giotypes.h b/gio/giotypes.h
index 8394e8e..b8c1d10 100644
--- a/gio/giotypes.h
+++ b/gio/giotypes.h
@@ -47,6 +47,9 @@ typedef struct _GSimplePermission GSimplePermission;
typedef struct _GZlibCompressor GZlibCompressor;
typedef struct _GZlibDecompressor GZlibDecompressor;
+typedef struct _GActionGroupArray GActionGroupArray;
+typedef struct _GSimpleActionGroup GSimpleActionGroup;
+typedef struct _GActionGroup GActionGroup;
typedef struct _GAction GAction;
typedef struct _GApplication GApplication;
typedef struct _GApplicationCommandLine GApplicationCommandLine;
diff --git a/gio/gsimpleactiongroup.c b/gio/gsimpleactiongroup.c
new file mode 100644
index 0000000..26dba8c
--- /dev/null
+++ b/gio/gsimpleactiongroup.c
@@ -0,0 +1,380 @@
+/*
+ * Copyright © 2010 Codethink Limited
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published
+ * by the Free Software Foundation; either version 2 of the licence or (at
+ * your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General
+ * Public License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place, Suite 330,
+ * Boston, MA 02111-1307, USA.
+ *
+ * Authors: Ryan Lortie <desrt desrt ca>
+ */
+
+#include "gsimpleactiongroup.h"
+#include "gaction.h"
+
+struct _GSimpleActionGroupPrivate
+{
+ GHashTable *table; /* string -> GAction */
+};
+
+G_DEFINE_TYPE (GSimpleActionGroup, g_simple_action_group, G_TYPE_ACTION_GROUP)
+
+static gchar **
+g_simple_action_group_list_actions (GActionGroup *group)
+{
+ GSimpleActionGroup *simple = G_SIMPLE_ACTION_GROUP (group);
+ GHashTableIter iter;
+ gint n, i = 0;
+ gchar **keys;
+ gpointer key;
+
+ n = g_hash_table_size (simple->priv->table);
+ keys = g_new (gchar *, n + 1);
+
+ g_hash_table_iter_init (&iter, simple->priv->table);
+ while (g_hash_table_iter_next (&iter, &key, NULL))
+ keys[i++] = g_strdup (key);
+ g_assert_cmpint (i, ==, n);
+ keys[n] = NULL;
+
+ return keys;
+}
+
+static gboolean
+g_simple_action_group_has_action (GActionGroup *group,
+ const gchar *action_name)
+{
+ GSimpleActionGroup *simple = G_SIMPLE_ACTION_GROUP (group);
+
+ return g_hash_table_lookup (simple->priv->table, action_name) != NULL;
+}
+
+static const GVariantType *
+g_simple_action_group_get_parameter_type (GActionGroup *group,
+ const gchar *action_name)
+{
+ GSimpleActionGroup *simple = G_SIMPLE_ACTION_GROUP (group);
+ GAction *action;
+
+ action = g_hash_table_lookup (simple->priv->table, action_name);
+
+ if (action == NULL)
+ return NULL;
+
+ return g_action_get_parameter_type (action);
+}
+
+static const GVariantType *
+g_simple_action_group_get_state_type (GActionGroup *group,
+ const gchar *action_name)
+{
+ GSimpleActionGroup *simple = G_SIMPLE_ACTION_GROUP (group);
+ GAction *action;
+
+ action = g_hash_table_lookup (simple->priv->table, action_name);
+
+ if (action == NULL)
+ return NULL;
+
+ return g_action_get_state_type (action);
+}
+
+static GVariant *
+g_simple_action_group_get_state_range (GActionGroup *group,
+ const gchar *action_name)
+{
+ GSimpleActionGroup *simple = G_SIMPLE_ACTION_GROUP (group);
+ GAction *action;
+
+ action = g_hash_table_lookup (simple->priv->table, action_name);
+
+ if (action == NULL)
+ return NULL;
+
+ return g_action_get_state_range (action);
+}
+
+static gboolean
+g_simple_action_group_get_enabled (GActionGroup *group,
+ const gchar *action_name)
+{
+ GSimpleActionGroup *simple = G_SIMPLE_ACTION_GROUP (group);
+ GAction *action;
+
+ action = g_hash_table_lookup (simple->priv->table, action_name);
+
+ if (action == NULL)
+ return FALSE;
+
+ return g_action_get_enabled (action);
+}
+
+static GVariant *
+g_simple_action_group_get_state (GActionGroup *group,
+ const gchar *action_name)
+{
+ GSimpleActionGroup *simple = G_SIMPLE_ACTION_GROUP (group);
+ GAction *action;
+
+ action = g_hash_table_lookup (simple->priv->table, action_name);
+
+ if (action == NULL)
+ return NULL;
+
+ return g_action_get_state (action);
+}
+
+static void
+g_simple_action_group_set_state (GActionGroup *group,
+ const gchar *action_name,
+ GVariant *value)
+{
+ GSimpleActionGroup *simple = G_SIMPLE_ACTION_GROUP (group);
+ GAction *action;
+
+ action = g_hash_table_lookup (simple->priv->table, action_name);
+
+ if (action == NULL)
+ return;
+
+ return g_action_set_state (action, value);
+}
+
+static void
+g_simple_action_group_activate (GActionGroup *group,
+ const gchar *action_name,
+ GVariant *parameter)
+{
+ GSimpleActionGroup *simple = G_SIMPLE_ACTION_GROUP (group);
+ GAction *action;
+
+ action = g_hash_table_lookup (simple->priv->table, action_name);
+
+ if (action == NULL)
+ return;
+
+ return g_action_activate (action, parameter);
+}
+
+static void
+action_enabled_changed (GAction *action,
+ gboolean enabled,
+ gpointer user_data)
+{
+ g_action_group_action_enabled_changed (user_data,
+ g_action_get_name (action),
+ enabled);
+}
+
+static void
+action_state_changed (GAction *action,
+ GVariant *value,
+ gpointer user_data)
+{
+ g_action_group_action_state_changed (user_data,
+ g_action_get_name (action),
+ value);
+}
+
+static void
+g_simple_action_group_disconnect (gpointer key,
+ gpointer value,
+ gpointer user_data)
+{
+ g_signal_handlers_disconnect_by_func (value, action_enabled_changed,
+ user_data);
+ g_signal_handlers_disconnect_by_func (value, action_state_changed,
+ user_data);
+}
+
+static void
+g_simple_action_group_finalize (GObject *object)
+{
+ GSimpleActionGroup *simple = G_SIMPLE_ACTION_GROUP (object);
+
+ g_hash_table_foreach (simple->priv->table,
+ g_simple_action_group_disconnect,
+ simple);
+ g_hash_table_unref (simple->priv->table);
+
+ G_OBJECT_CLASS (g_simple_action_group_parent_class)
+ ->finalize (object);
+}
+
+static void
+g_simple_action_group_init (GSimpleActionGroup *simple)
+{
+ simple->priv = G_TYPE_INSTANCE_GET_PRIVATE (simple,
+ G_TYPE_SIMPLE_ACTION_GROUP,
+ GSimpleActionGroupPrivate);
+ simple->priv->table = g_hash_table_new_full (g_str_hash, g_str_equal,
+ g_free, g_object_unref);
+}
+
+static void
+g_simple_action_group_class_init (GSimpleActionGroupClass *class)
+{
+ GActionGroupClass *group_class = G_ACTION_GROUP_CLASS (class);
+ GObjectClass *object_class = G_OBJECT_CLASS (class);
+
+ object_class->finalize = g_simple_action_group_finalize;
+
+ group_class->list_actions = g_simple_action_group_list_actions;
+ group_class->has_action = g_simple_action_group_has_action;
+ group_class->get_parameter_type = g_simple_action_group_get_parameter_type;
+ group_class->get_state_type = g_simple_action_group_get_state_type;
+ group_class->get_state_range = g_simple_action_group_get_state_range;
+ group_class->get_enabled = g_simple_action_group_get_enabled;
+ group_class->get_state = g_simple_action_group_get_state;
+ group_class->set_state = g_simple_action_group_set_state;
+ group_class->activate = g_simple_action_group_activate;
+
+ g_type_class_add_private (class, sizeof (GSimpleActionGroupPrivate));
+}
+
+/**
+ * g_simple_action_group_new:
+ * Returns: a new #GSimpleActionGroup
+ *
+ * Creates a new, empty, #GSimpleActionGroup.
+ **/
+GSimpleActionGroup *
+g_simple_action_group_new (void)
+{
+ return g_object_new (G_TYPE_SIMPLE_ACTION_GROUP, NULL);
+}
+
+/**
+ * g_simple_action_group_lookup:
+ * @simple: a #GSimpleActionGroup
+ * @action_name: the name of an action
+ * Returns: (transfer none): a #GAction, or %NULL
+ *
+ * Looks up the action with the name @action_name in the group.
+ *
+ * If no such action exists, returns %NULL.
+ **/
+GAction *
+g_simple_action_group_lookup (GSimpleActionGroup *simple,
+ const gchar *action_name)
+{
+ g_return_val_if_fail (G_IS_SIMPLE_ACTION_GROUP (simple), NULL);
+
+ return g_hash_table_lookup (simple->priv->table, action_name);
+}
+
+/**
+ * g_simple_action_group_insert:
+ * @simple: a #GSimpleActionGroup
+ * @action: a #GAction
+ *
+ * Adds an action to the action group.
+ *
+ * If the action group already contains an action with the same name as
+ * @action then the old action is dropped from the group.
+ *
+ * The action group takes its own reference on @action.
+ **/
+void
+g_simple_action_group_insert (GSimpleActionGroup *simple,
+ GAction *action)
+{
+ const gchar *action_name;
+ GAction *old_action;
+
+ g_return_if_fail (G_IS_SIMPLE_ACTION_GROUP (simple));
+ g_return_if_fail (G_IS_ACTION (action));
+
+ action_name = g_action_get_name (action);
+ old_action = g_hash_table_lookup (simple->priv->table, action_name);
+
+ if (old_action != action)
+ {
+ if (old_action != NULL)
+ {
+ g_action_group_action_removed (G_ACTION_GROUP (simple),
+ action_name);
+ g_simple_action_group_disconnect (NULL, old_action, simple);
+ }
+
+ g_signal_connect (action, "enabled-changed",
+ G_CALLBACK (action_enabled_changed), simple);
+
+ if (g_action_get_state_type (action) != NULL)
+ g_signal_connect (action, "state-changed",
+ G_CALLBACK (action_state_changed), simple);
+
+ g_hash_table_insert (simple->priv->table,
+ g_strdup (action_name),
+ g_object_ref (action));
+
+ g_action_group_action_added (G_ACTION_GROUP (simple), action_name);
+ }
+}
+
+/**
+ * g_simple_action_group_remove:
+ * @simple: a #GSimpleActionGroup
+ * @action_name: the name of the action
+ *
+ * Removes the named action from the action group.
+ *
+ * If no action of this name is in the group then nothing happens.
+ **/
+void
+g_simple_action_group_remove (GSimpleActionGroup *simple,
+ const gchar *action_name)
+{
+ GAction *action;
+
+ g_return_if_fail (G_IS_SIMPLE_ACTION_GROUP (simple));
+
+ action = g_hash_table_lookup (simple->priv->table, action_name);
+
+ if (action != NULL)
+ {
+ g_action_group_action_removed (G_ACTION_GROUP (simple), action_name);
+ g_simple_action_group_disconnect (NULL, action, simple);
+ g_hash_table_remove (simple->priv->table, action_name);
+ }
+}
+
+/**
+ * g_simple_action_group_set_enabled:
+ * @simple: a #GSimpleActionGroup
+ * @action_name: the name of an action
+ * @enabled: if the action should be enabled
+ *
+ * Sets an action in the group as being enabled or not.
+ *
+ * This is a convenience function, equivalent to calling
+ * g_simple_action_group_lookup() and using g_action_set_enabled() on
+ * the result.
+ *
+ * If no action named @action_name exists then this function does
+ * nothing.
+ **/
+void
+g_simple_action_group_set_enabled (GSimpleActionGroup *simple,
+ const gchar *action_name,
+ gboolean enabled)
+{
+ GAction *action;
+
+ g_return_if_fail (G_IS_SIMPLE_ACTION_GROUP (simple));
+
+ action = g_hash_table_lookup (simple->priv->table, action_name);
+
+ if (action != NULL)
+ g_action_set_enabled (action, enabled);
+}
diff --git a/gio/gsimpleactiongroup.h b/gio/gsimpleactiongroup.h
new file mode 100644
index 0000000..52c3c5f
--- /dev/null
+++ b/gio/gsimpleactiongroup.h
@@ -0,0 +1,98 @@
+/*
+ * Copyright © 2010 Codethink Limited
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published
+ * by the Free Software Foundation; either version 2 of the licence or (at
+ * your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General
+ * Public License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place, Suite 330,
+ * Boston, MA 02111-1307, USA.
+ *
+ * Authors: Ryan Lortie <desrt desrt ca>
+ */
+
+#if !defined (__GIO_GIO_H_INSIDE__) && !defined (GIO_COMPILATION)
+#error "Only <gio/gio.h> can be included directly."
+#endif
+
+#ifndef __G_SIMPLE_ACTION_GROUP_H__
+#define __G_SIMPLE_ACTION_GROUP_H__
+
+#include "gactiongroup.h"
+
+G_BEGIN_DECLS
+
+#define G_TYPE_SIMPLE_ACTION_GROUP (g_simple_action_group_get_type ())
+#define G_SIMPLE_ACTION_GROUP(inst) (G_TYPE_CHECK_INSTANCE_CAST ((inst), \
+ G_TYPE_SIMPLE_ACTION_GROUP, GSimpleActionGroup))
+#define G_SIMPLE_ACTION_GROUP_CLASS(class) (G_TYPE_CHECK_CLASS_CAST ((class), \
+ G_TYPE_SIMPLE_ACTION_GROUP, GSimpleActionGroupClass))
+#define G_IS_SIMPLE_ACTION_GROUP(inst) (G_TYPE_CHECK_INSTANCE_TYPE ((inst), G_TYPE_ACTION))
+#define G_IS_SIMPLE_ACTION_GROUP_CLASS(class) (G_TYPE_CHECK_CLASS_TYPE ((class), G_TYPE_ACTION))
+#define G_SIMPLE_ACTION_GROUP_GET_CLASS(inst) (G_TYPE_INSTANCE_GET_CLASS ((inst), \
+ G_TYPE_SIMPLE_ACTION_GROUP, GSimpleActionGroupClass))
+
+typedef struct _GSimpleActionGroupPrivate GSimpleActionGroupPrivate;
+typedef struct _GSimpleActionGroupClass GSimpleActionGroupClass;
+
+/**
+ * GSimpleActionGroup:
+ *
+ * The <structname>GSimpleActionGroup</structname> structure contains private
+ * data and should only be accessed using the provided API
+ *
+ * Since: 2.26
+ */
+struct _GSimpleActionGroup
+{
+ /*< private >*/
+ GActionGroup parent_instance;
+
+ GSimpleActionGroupPrivate *priv;
+};
+
+/**
+ * GSimpleActionGroupClass:
+ *
+ * The <structname>GSimpleActionGroupClass</structname> structure contains
+ * private data only
+ *
+ * Since: 2.26
+ */
+struct _GSimpleActionGroupClass
+{
+ /*< private >*/
+ GActionGroupClass parent_class;
+
+ /*< private >*/
+ gpointer padding[12];
+};
+
+GType g_simple_action_group_get_type (void) G_GNUC_CONST;
+
+GSimpleActionGroup * g_simple_action_group_new (void);
+
+GAction * g_simple_action_group_lookup (GSimpleActionGroup *simple,
+ const gchar *action_name);
+
+void g_simple_action_group_insert (GSimpleActionGroup *simple,
+ GAction *action);
+
+void g_simple_action_group_remove (GSimpleActionGroup *simple,
+ const gchar *action_name);
+
+void g_simple_action_group_set_enabled (GSimpleActionGroup *simple,
+ const gchar *action_name,
+ gboolean enabled);
+
+G_END_DECLS
+
+#endif /* __G_SIMPLE_ACTION_GROUP_H__ */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]