qulogic/talkatu

d8b7f2b0a9b4
Added new method talkatu_action_group_get_action_activated
--- a/talkatu/talkatuactiongroup.c Fri Sep 28 15:54:43 2018 -0500
+++ b/talkatu/talkatuactiongroup.c Thu Oct 11 23:01:57 2018 -0500
@@ -633,6 +633,46 @@
}
/**
+ * talkatu_action_group_get_action_activated:
+ * @ag: The #TalkatuActionGroup instance.
+ * @name: The name of the action to check.
+ *
+ * Returns that state of the action named @name. If @name doesn't exist or is
+ * not a toggle action, FALSE is returned.
+ *
+ * Returns: Whether or not @name is toggled.
+ */
+gboolean
+talkatu_action_group_get_action_activated(TalkatuActionGroup *ag, const gchar *name) {
+ GVariant *state = NULL;
+ const GVariantType *state_type = NULL;
+ gboolean enabled = FALSE;
+
+ g_return_val_if_fail(TALKATU_IS_ACTION_GROUP(ag), FALSE);
+ g_return_val_if_fail(name != NULL, FALSE);
+
+ g_action_group_query_action(
+ G_ACTION_GROUP(ag),
+ name,
+ &enabled,
+ NULL,
+ &state_type,
+ NULL,
+ &state
+ );
+
+ if(state_type == NULL) {
+ return FALSE;
+ }
+
+ if(g_variant_type_equal(state_type, G_VARIANT_TYPE_BOOLEAN)) {
+ return g_variant_get_boolean(state);
+ }
+
+ return FALSE;
+}
+
+/**
* talkatu_action_group_get_activated_formats:
* @ag: The #TalkatuActionGroup instance.
*
@@ -650,28 +690,8 @@
actions = g_action_group_list_actions(G_ACTION_GROUP(ag));
for(action = actions; *action != NULL; action++) {
- GVariant *state = NULL;
- const GVariantType *state_type = NULL;
- gboolean enabled = FALSE;
-
- g_action_group_query_action(
- G_ACTION_GROUP(ag),
- *action,
- &enabled,
- NULL,
- &state_type,
- NULL,
- &state
- );
-
- if(state_type == NULL) {
- continue;
- }
-
- if(g_variant_type_equal(state_type, G_VARIANT_TYPE_BOOLEAN)) {
- if(g_variant_get_boolean(state)) {
- activated = g_slist_prepend(activated, g_strdup(*action));
- }
+ if(talkatu_action_group_get_action_activated(ag, *action)) {
+ activated = g_slist_prepend(activated, g_strdup(*action));
}
}
g_strfreev(actions);
--- a/talkatu/talkatuactiongroup.h Fri Sep 28 15:54:43 2018 -0500
+++ b/talkatu/talkatuactiongroup.h Thu Oct 11 23:01:57 2018 -0500
@@ -82,6 +82,7 @@
const gchar *talkatu_action_name_for_tag_name(const gchar *tag_name);
void talkatu_action_group_activate_format(TalkatuActionGroup *ag, const gchar *format_name);
+gboolean talkatu_action_group_get_action_activated(TalkatuActionGroup *ag, const gchar *name);
gchar **talkatu_action_group_get_activated_formats(TalkatuActionGroup *ag);
G_END_DECLS