rewtguy/pidgin

5c78f6c9a36b
Parents 275aa03d1b41
Children 3bd059ab9eb4
Implement mute sounds to prove out the action state code
--- a/pidgin/gtkblist.c Fri Mar 27 07:02:54 2020 -0500
+++ b/pidgin/gtkblist.c Fri Mar 27 07:03:16 2020 -0500
@@ -790,11 +790,6 @@
}
}
-static void gtk_blist_show_onlinehelp_cb(void)
-{
- purple_notify_uri(NULL, PURPLE_WEBSITE "documentation");
-}
-
static void
do_join_chat(PidginChatData *data)
{
@@ -2060,21 +2055,6 @@
pidgin_clear_cursor(gtkblist->window);
}
-static void pidgin_blist_mute_sounds_cb(GtkToggleAction *item, gpointer data)
-{
- purple_prefs_set_bool(PIDGIN_PREFS_ROOT "/sound/mute",
- gtk_toggle_action_get_active(item));
-}
-
-
-static void
-pidgin_blist_mute_pref_cb(const char *name, PurplePrefType type,
- gconstpointer value, gpointer data)
-{
- gtk_toggle_action_set_active(GTK_TOGGLE_ACTION(gtk_ui_manager_get_action(gtkblist->ui,
- "/BList/ToolsMenu/MuteSounds")), (gboolean)GPOINTER_TO_INT(value));
-}
-
static void
pidgin_blist_sound_method_pref_cb(const char *name, PurplePrefType type,
gconstpointer value, gpointer data)
@@ -3625,9 +3605,6 @@
{ "ShowBuddyDetails", NULL, N_("Buddy _Details"), NULL, NULL, G_CALLBACK(pidgin_blist_buddy_details_cb), FALSE },
{ "ShowIdleTimes", NULL, N_("Idle _Times"), NULL, NULL, G_CALLBACK(pidgin_blist_show_idle_time_cb), FALSE },
{ "ShowProtocolIcons", NULL, N_("_Protocol Icons"), NULL, NULL, G_CALLBACK(pidgin_blist_show_protocol_icons_cb), FALSE },
-
- /* Tools menu */
- { "MuteSounds", NULL, N_("Mute _Sounds"), NULL, NULL, G_CALLBACK(pidgin_blist_mute_sounds_cb), FALSE },
};
static const char *blist_menu =
@@ -3654,7 +3631,6 @@
"<menu action='ToolsMenu'>"
"<menuitem action='SetMood'/>"
"<separator/>"
- "<menuitem action='MuteSounds'/>"
"<placeholder name='PluginActions'/>"
"</menu>"
"</menubar>"
@@ -5909,9 +5885,6 @@
gtk_toggle_action_set_active(GTK_TOGGLE_ACTION(gtk_ui_manager_get_action(gtkblist->ui, "/BList/BuddiesMenu/ShowMenu/ShowEmptyGroups")),
purple_prefs_get_bool(PIDGIN_PREFS_ROOT "/blist/show_empty_groups"));
- gtk_toggle_action_set_active(GTK_TOGGLE_ACTION(gtk_ui_manager_get_action(gtkblist->ui, "/BList/ToolsMenu/MuteSounds")),
- purple_prefs_get_bool(PIDGIN_PREFS_ROOT "/sound/mute"));
-
gtk_toggle_action_set_active(GTK_TOGGLE_ACTION(gtk_ui_manager_get_action(gtkblist->ui, "/BList/BuddiesMenu/ShowMenu/ShowBuddyDetails")),
purple_prefs_get_bool(PIDGIN_PREFS_ROOT "/blist/show_buddy_icons"));
@@ -5958,8 +5931,6 @@
_prefs_change_sort_method, NULL);
/* menus */
- purple_prefs_connect_callback(handle, PIDGIN_PREFS_ROOT "/sound/mute",
- pidgin_blist_mute_pref_cb, NULL);
purple_prefs_connect_callback(handle, PIDGIN_PREFS_ROOT "/sound/method",
pidgin_blist_sound_method_pref_cb, NULL);
--- a/pidgin/pidginactiongroup.c Fri Mar 27 07:02:54 2020 -0500
+++ b/pidgin/pidginactiongroup.c Fri Mar 27 07:03:16 2020 -0500
@@ -43,6 +43,88 @@
};
/******************************************************************************
+ * Helpers
+ *****************************************************************************/
+
+/*<private>
+ * pidgin_action_group_bool_pref_handler:
+ * @group: The #PidginActionGroup instance.
+ * @action_name: The name of the action to update.
+ * @value: The value of the preference.
+ *
+ * Changes the state of the action named @action_name to match @value.
+ *
+ * This function is meant to be called from a #PurplePrefCallback function as
+ * there isn't a good way to have a #PurplePrefCallback with multiple items in
+ * the data parameter without leaking them forever.
+ */
+static void
+pidgin_action_group_bool_pref_handler(PidginActionGroup *group,
+ const gchar *action_name,
+ gboolean value)
+{
+ GAction *action = NULL;
+
+ action = g_action_map_lookup_action(G_ACTION_MAP(group), action_name);
+ if(action != NULL) {
+ g_simple_action_set_state(G_SIMPLE_ACTION(action),
+ g_variant_new_boolean(value));
+ }
+}
+
+/*<private
+ * pidgin_action_group_setup_bool:
+ * @group: The #PidginActionGroup instance.
+ * @action_name: The name of the action to setup.
+ * @pref_name: The name of the preference that @action_name is tied to.
+ * @callback: (scope call): A #PurplePrefCallback to call when the preference
+ * is changed.
+ *
+ * Initializes the boolean action named @action_name to the value of @pref_name
+ * and setups up a preference change callback to @callback to maintain the
+ * state of the action.
+ */
+static void
+pidgin_action_group_setup_bool(PidginActionGroup *group,
+ const gchar *action_name,
+ const gchar *pref_name,
+ PurplePrefCallback callback)
+{
+ GAction *action = NULL;
+ gboolean value = FALSE;
+
+ /* find the action, if we can't find it, bail */
+ action = g_action_map_lookup_action(G_ACTION_MAP(group), action_name);
+ g_return_if_fail(action != NULL);
+
+ /* get the value of the preference */
+ value = purple_prefs_get_bool(pref_name);
+
+ /* change the state of the action to match the preference value. */
+ g_action_change_state(action, g_variant_new_boolean(value));
+
+ /* finally add a preference callback to update the state based on the
+ * preference.
+ */
+ purple_prefs_connect_callback(group, pref_name, callback, group);
+}
+
+/******************************************************************************
+ * Preference Callbacks
+ *****************************************************************************/
+static void
+pidgin_action_group_mute_sounds_callback(const gchar *name,
+ PurplePrefType type,
+ gconstpointer value,
+ gpointer data)
+{
+ PidginActionGroup *group = PIDGIN_ACTION_GROUP(data);
+
+ pidgin_action_group_bool_pref_handler(group, PIDGIN_ACTION_MUTE_SOUNDS,
+ (gboolean)GPOINTER_TO_INT(value));
+}
+
+/******************************************************************************
* Action Callbacks
*****************************************************************************/
static void
@@ -110,6 +192,14 @@
}
static void
+pidgin_action_group_mute_sounds(GSimpleAction *action, GVariant *value,
+ gpointer data)
+{
+ purple_prefs_set_bool(PIDGIN_PREFS_ROOT "/sound/mute",
+ g_variant_get_boolean(value));
+}
+
+static void
pidgin_action_group_new_message(GSimpleAction *simple, GVariant *parameter,
gpointer data)
{
@@ -213,6 +303,10 @@
.name = PIDGIN_ACTION_MANAGE_ACCOUNTS,
.activate = pidgin_action_group_manage_accounts,
}, {
+ .name = PIDGIN_ACTION_MUTE_SOUNDS,
+ .state = "false",
+ .change_state = pidgin_action_group_mute_sounds,
+ }, {
.name = PIDGIN_ACTION_NEW_MESSAGE,
.activate = pidgin_action_group_new_message,
}, {
@@ -244,6 +338,13 @@
g_action_map_add_action_entries(G_ACTION_MAP(group), entries,
G_N_ELEMENTS(entries), NULL);
+
+ /* now add some handlers for preference changes and set actions to the
+ * correct value.
+ */
+ pidgin_action_group_setup_bool(group, PIDGIN_ACTION_MUTE_SOUNDS,
+ PIDGIN_PREFS_ROOT "/sound/mute",
+ pidgin_action_group_mute_sounds_callback);
};
static void
--- a/pidgin/pidginactiongroup.h Fri Mar 27 07:02:54 2020 -0500
+++ b/pidgin/pidginactiongroup.h Fri Mar 27 07:03:16 2020 -0500
@@ -82,12 +82,19 @@
/**
* PIDGIN_ACTION_MANAGE_ACCOUNTS:
*
- * A constatnt that preresents the manage-accounts action to displays the
+ * A constatnt that represents the manage-accounts action to displays the
* manage accounts window.
*/
#define PIDGIN_ACTION_MANAGE_ACCOUNTS ("manage-accounts")
/**
+ * PIDGIN_ACTION_MUTE_SOUNDS:
+ *
+ * A constatnt that represents the mute-sounds action.
+ */
+#define PIDGIN_ACTION_MUTE_SOUNDS ("mute-sounds")
+
+/**
* PIDGIN_ACTION_NEW_MESSAGE:
*
* A constant that represents the new-message action.