pidgin/pidgin

Parents bfd6a61974ac
Children dbc5c2d601ab
Manage the room list action's state based on whether the online accounts support the room list interface.
--- a/pidgin/gtkblist.c Mon Apr 06 23:35:44 2020 -0500
+++ b/pidgin/gtkblist.c Tue Apr 07 00:16:27 2020 -0500
@@ -4327,53 +4327,6 @@
gtknode->row = NULL;
}
-static const char *require_connection[] =
-{
- "/BList/BuddiesMenu/JoinAChat",
-};
-
-static const int require_connection_size = sizeof(require_connection)
- / sizeof(*require_connection);
-
-/*
- * Rebuild dynamic menus and make menu items sensitive/insensitive
- * where appropriate.
- */
-static void
-update_menu_bar(PidginBuddyList *gtkblist)
-{
- GtkAction *action;
- gboolean sensitive;
- int i;
-
- g_return_if_fail(gtkblist != NULL);
-
- sensitive = (purple_connections_get_all() != NULL);
-
- for (i = 0; i < require_connection_size; i++)
- {
- action = gtk_ui_manager_get_action(gtkblist->ui, require_connection[i]);
- gtk_action_set_sensitive(action, sensitive);
- }
-
- action = gtk_ui_manager_get_action(gtkblist->ui, "/BList/BuddiesMenu/JoinAChat");
- gtk_action_set_sensitive(action, pidgin_blist_joinchat_is_showable());
-
- action = gtk_ui_manager_get_action(gtkblist->ui, "/BList/BuddiesMenu/AddChat");
- gtk_action_set_sensitive(action, pidgin_blist_joinchat_is_showable());
-
- action = gtk_ui_manager_get_action(gtkblist->ui, "/BList/ToolsMenu/RoomList");
- gtk_action_set_sensitive(action, pidgin_roomlist_is_showable());
-}
-
-static void
-sign_on_off_cb(PurpleConnection *gc, PurpleBuddyList *blist)
-{
- PidginBuddyList *gtkblist = PIDGIN_BUDDY_LIST(blist);
-
- update_menu_bar(gtkblist);
-}
-
static void
unseen_conv_menu(GdkEvent *event)
{
@@ -4719,7 +4672,6 @@
return;
pidgin_blist_select_notebook_page(gtkblist);
- update_menu_bar(gtkblist);
}
static void
@@ -5746,7 +5698,6 @@
gtk_widget_show(gtkblist->statusbox);
/* Update some dynamic things */
- update_menu_bar(gtkblist);
pidgin_blist_update_sort_methods();
/* OK... let's show this bad boy. */
@@ -5797,12 +5748,6 @@
purple_signal_connect(handle, "account-modified", gtkblist,
PURPLE_CALLBACK(account_modified), gtkblist);
- handle = purple_connections_get_handle();
- purple_signal_connect(handle, "signed-on", gtkblist,
- PURPLE_CALLBACK(sign_on_off_cb), list);
- purple_signal_connect(handle, "signed-off", gtkblist,
- PURPLE_CALLBACK(sign_on_off_cb), list);
-
handle = purple_conversations_get_handle();
purple_signal_connect(handle, "conversation-updated", gtkblist,
PURPLE_CALLBACK(conversation_updated_cb),
--- a/pidgin/pidginactiongroup.c Mon Apr 06 23:35:44 2020 -0500
+++ b/pidgin/pidginactiongroup.c Tue Apr 07 00:16:27 2020 -0500
@@ -61,6 +61,9 @@
static const gchar *pidgin_action_group_chat_actions[] = {
PIDGIN_ACTION_ADD_CHAT,
PIDGIN_ACTION_JOIN_CHAT,
+};
+
+static const gchar *pidgin_action_group_room_list_actions[] = {
PIDGIN_ACTION_ROOM_LIST,
};
@@ -194,7 +197,38 @@
purple_prefs_connect_callback(group, pref_name, callback, group);
}
-/**< private >
+/*< private >
+ * pidgin_action_group_actions_set_enable:
+ * @group: The #PidginActionGroup instance.
+ * @actions: The action names.
+ * @n_actions: The number of @actions.
+ * @enabled: Whether or not to enable the actions.
+ *
+ * Sets the enabled property of the the named actions to @enabled.
+ */
+static void
+pidgin_action_group_actions_set_enable(PidginActionGroup *group,
+ const gchar *const *actions,
+ gint n_actions,
+ gboolean enabled)
+{
+ gint i = 0;
+
+ for(i = 0; i < n_actions; i++) {
+ GAction *action = NULL;
+ const gchar *name = actions[i];
+
+ action = g_action_map_lookup_action(G_ACTION_MAP(group), name);
+
+ if(action != NULL) {
+ g_simple_action_set_enabled(G_SIMPLE_ACTION(action), enabled);
+ } else {
+ g_warning("Failed to find action named %s", name);
+ }
+ }
+}
+
+/*< private >
* pidgin_action_group_online_actions_set_enable:
* @group: The #PidginActionGroup instance.
* @enabled: %TRUE to enable the actions, %FALSE to disable them.
@@ -205,20 +239,12 @@
pidgin_action_group_online_actions_set_enable(PidginActionGroup *group,
gboolean enabled)
{
- gint i = 0;
-
- for(i = 0; i < G_N_ELEMENTS(pidgin_action_group_online_actions); i++) {
- GAction *action = NULL;
- const gchar *name = pidgin_action_group_online_actions[i];
+ gint n_actions = G_N_ELEMENTS(pidgin_action_group_online_actions);
- action = g_action_map_lookup_action(G_ACTION_MAP(group), name);
-
- if(action != NULL) {
- g_simple_action_set_enabled(G_SIMPLE_ACTION(action), enabled);
- } else {
- g_warning("Failed to find action named %s", name);
- }
- }
+ pidgin_action_group_actions_set_enable(group,
+ pidgin_action_group_online_actions,
+ n_actions,
+ enabled);
}
/*< private >
@@ -232,20 +258,32 @@
pidgin_action_group_chat_actions_set_enable(PidginActionGroup *group,
gboolean enabled)
{
- gint i = 0;
+ gint n_actions = G_N_ELEMENTS(pidgin_action_group_chat_actions);
- for(i = 0; i < G_N_ELEMENTS(pidgin_action_group_chat_actions); i++) {
- GAction *action = NULL;
- const gchar *name = pidgin_action_group_chat_actions[i];
+ pidgin_action_group_actions_set_enable(group,
+ pidgin_action_group_chat_actions,
+ n_actions,
+ enabled);
+}
- action = g_action_map_lookup_action(G_ACTION_MAP(group), name);
+/*< private >
+ * pidgin_action_group_room_list_actions_set_enable:
+ * @group: The #PidginActionGroup instance.
+ * @enabled: Whether or not to enable/disable the actions.
+ *
+ * Sets the enabled state of the room list specific actions to the value of
+ * @enabled.
+ */
+static void
+pidgin_action_group_room_list_actions_set_enable(PidginActionGroup *group,
+ gboolean enabled)
+{
+ gint n_actions = G_N_ELEMENTS(pidgin_action_group_room_list_actions);
- if(action != NULL) {
- g_simple_action_set_enabled(G_SIMPLE_ACTION(action), enabled);
- } else {
- g_warning("Failed to find action named %s", name);
- }
- }
+ pidgin_action_group_actions_set_enable(group,
+ pidgin_action_group_room_list_actions,
+ n_actions,
+ enabled);
}
/******************************************************************************
@@ -265,9 +303,10 @@
static void
pidgin_action_group_signed_on_cb(PurpleAccount *account, gpointer data) {
+ PidginActionGroup *group = PIDGIN_ACTION_GROUP(data);
PurpleProtocol *protocol = NULL;
const gchar *protocol_id = NULL;
- gboolean should_enable = FALSE;
+ gboolean should_enable_chat = FALSE, should_enable_room_list = FALSE;
protocol_id = purple_account_get_protocol_id(account);
protocol = purple_protocols_find(protocol_id);
@@ -276,16 +315,24 @@
* state unless the newly connected account implements the chat interface,
* which would cause a state change.
*/
- should_enable = PURPLE_PROTOCOL_IMPLEMENTS(protocol, CHAT, info);
- if(should_enable) {
- pidgin_action_group_chat_actions_set_enable(PIDGIN_ACTION_GROUP(data),
- TRUE);
+ should_enable_chat = PURPLE_PROTOCOL_IMPLEMENTS(protocol, CHAT, info);
+ if(should_enable_chat) {
+ pidgin_action_group_chat_actions_set_enable(group, TRUE);
+ }
+
+ /* likewise, for the room list, we only care about enabling in this
+ * handler.
+ */
+ should_enable_room_list = PURPLE_PROTOCOL_IMPLEMENTS(protocol, ROOMLIST,
+ get_list);
+ if(should_enable_room_list) {
+ pidgin_action_group_room_list_actions_set_enable(group, TRUE);
}
}
static void
pidgin_action_group_signed_off_cb(PurpleAccount *account, gpointer data) {
- gboolean should_disable = TRUE;
+ gboolean should_disable_chat = TRUE, should_disable_room_list = TRUE;
GList *connections = NULL, *l = NULL;
/* walk through all the connections, looking for online ones that implement
@@ -304,19 +351,32 @@
}
protocol = purple_connection_get_protocol(connection);
+
+ /* check if the protocol implements the chat interface */
if(PURPLE_PROTOCOL_IMPLEMENTS(protocol, CHAT, info)) {
- /* if the protocol implements the chat interface, we know we need
- * to keep it enabled, so we can bail about at this point.
- */
- should_disable = FALSE;
+ should_disable_chat = FALSE;
+ }
+
+ /* check if the protocol implement the room list interface */
+ if(PURPLE_PROTOCOL_IMPLEMENTS(protocol, ROOMLIST, get_list)) {
+ should_disable_room_list = FALSE;
+ }
+
+ /* if we can't disable both, we can bail out of the loop */
+ if(!should_disable_chat && !should_disable_room_list) {
break;
}
}
- if(should_disable) {
+ if(should_disable_chat) {
pidgin_action_group_chat_actions_set_enable(PIDGIN_ACTION_GROUP(data),
FALSE);
}
+
+ if(should_disable_room_list) {
+ pidgin_action_group_room_list_actions_set_enable(PIDGIN_ACTION_GROUP(data),
+ FALSE);
+ }
}
/******************************************************************************
@@ -738,6 +798,7 @@
*/
pidgin_action_group_online_actions_set_enable(group, FALSE);
pidgin_action_group_chat_actions_set_enable(group, FALSE);
+ pidgin_action_group_room_list_actions_set_enable(group, FALSE);
/* connect to the online and offline signals in purple connections. This
* is used to toggle states of actions that require being online.