pidgin/pidgin

Use PurpleAccountManager added/removed signals

20 months ago, Elliott Sales de Andrade
3bc9948e9f3c
Parents ebe4ff278b02
Children 5ae15cfc1bee
Use PurpleAccountManager added/removed signals

Testing Done:
Opened Pidgin and made sure there were no warnings about objects not existing in time for the new signal connections.

Opened XMPP console and saw that the drop down updated when an XMPP account was added/removed.

Reviewed at https://reviews.imfreedom.org/r/1913/
--- a/ChangeLog.API Sun Oct 09 00:41:50 2022 -0500
+++ b/ChangeLog.API Sun Oct 09 01:48:50 2022 -0500
@@ -944,6 +944,7 @@
* pidgin_cell_renderer_expander_new
* pidgin_check_if_dir
* pidgin_clear_cursor
+ * pidgin_connection_get_handle
* PidginConversation.sg
* PidginConvPlacementFunc
* pidgin_conv_get_tab_at_xy
--- a/finch/gntaccount.c Sun Oct 09 00:41:50 2022 -0500
+++ b/finch/gntaccount.c Sun Oct 09 01:48:50 2022 -0500
@@ -255,9 +255,9 @@
}
}
- /* In case of a new account, the 'Accounts' window is updated from the account-added
- * callback. In case of changes in an existing account, we need to explicitly do it
- * here.
+ /* In case of a new account, the 'Accounts' window is updated from the
+ * 'added' callback. In case of changes in an existing account, we need to
+ * explicitly do it here.
*/
if (dialog->account != NULL && accounts.window) {
gnt_tree_change_text(GNT_TREE(accounts.tree), dialog->account,
@@ -861,7 +861,8 @@
}
static void
-account_added_callback(PurpleAccount *account)
+account_added_callback(G_GNUC_UNUSED PurpleAccountManager *manager,
+ PurpleAccount *account, G_GNUC_UNUSED gpointer data)
{
if (accounts.window == NULL)
return;
@@ -870,7 +871,8 @@
}
static void
-account_removed_callback(PurpleAccount *account)
+account_removed_callback(G_GNUC_UNUSED PurpleAccountManager *manager,
+ PurpleAccount *account, G_GNUC_UNUSED gpointer data)
{
if (accounts.window == NULL)
return;
@@ -890,22 +892,23 @@
void finch_accounts_init()
{
PurpleAccountManager *manager = NULL;
+ gpointer account_handle = NULL;
GList *iter;
- purple_signal_connect(purple_accounts_get_handle(), "account-added",
- finch_accounts_get_handle(), G_CALLBACK(account_added_callback),
- NULL);
- purple_signal_connect(purple_accounts_get_handle(), "account-removed",
- finch_accounts_get_handle(), G_CALLBACK(account_removed_callback),
- NULL);
- purple_signal_connect(purple_accounts_get_handle(), "account-disabled",
+ manager = purple_account_manager_get_default();
+ account_handle = purple_accounts_get_handle();
+
+ g_signal_connect(manager, "added", G_CALLBACK(account_added_callback),
+ NULL);
+ g_signal_connect(manager, "removed", G_CALLBACK(account_removed_callback),
+ NULL);
+ purple_signal_connect(account_handle, "account-disabled",
finch_accounts_get_handle(),
G_CALLBACK(account_abled_cb), GINT_TO_POINTER(FALSE));
- purple_signal_connect(purple_accounts_get_handle(), "account-enabled",
+ purple_signal_connect(account_handle, "account-enabled",
finch_accounts_get_handle(),
G_CALLBACK(account_abled_cb), GINT_TO_POINTER(TRUE));
- manager = purple_account_manager_get_default();
iter = purple_account_manager_get_all(manager);
if (iter) {
for (; iter; iter = iter->next) {
--- a/finch/gntconn.c Sun Oct 09 00:41:50 2022 -0500
+++ b/finch/gntconn.c Sun Oct 09 01:48:50 2022 -0500
@@ -108,19 +108,12 @@
}
static void
-account_removed_cb(PurpleAccount *account, gpointer user_data)
+account_removed_cb(G_GNUC_UNUSED PurpleAccountManager *manager,
+ PurpleAccount *account, G_GNUC_UNUSED gpointer data)
{
g_hash_table_remove(hash, account);
}
-static void *
-finch_connection_get_handle(void)
-{
- static int handle;
-
- return &handle;
-}
-
static PurpleConnectionUiOps ops = {
.report_disconnect = finch_connection_report_disconnect,
};
@@ -132,17 +125,21 @@
void finch_connections_init()
{
+ PurpleAccountManager *manager = purple_account_manager_get_default();
+
hash = g_hash_table_new_full(
g_direct_hash, g_direct_equal,
NULL, free_auto_recon);
- purple_signal_connect(purple_accounts_get_handle(), "account-removed",
- finch_connection_get_handle(),
- G_CALLBACK(account_removed_cb), NULL);
+ g_signal_connect(manager, "removed", G_CALLBACK(account_removed_cb), NULL);
}
void finch_connections_uninit()
{
- purple_signals_disconnect_by_handle(finch_connection_get_handle());
+ PurpleAccountManager *manager = purple_account_manager_get_default();
+
+ g_signal_handlers_disconnect_by_func(manager,
+ G_CALLBACK(account_removed_cb), NULL);
+
g_hash_table_destroy(hash);
}
--- a/libpurple/savedstatuses.c Sun Oct 09 00:41:50 2022 -0500
+++ b/libpurple/savedstatuses.c Sun Oct 09 01:48:50 2022 -0500
@@ -683,8 +683,9 @@
* exist for this account.
*/
static void
-purple_savedstatus_unset_all_substatuses(PurpleAccount *account,
- gpointer user_data)
+purple_savedstatus_unset_all_substatuses(G_GNUC_UNUSED PurpleAccountManager *manager,
+ PurpleAccount *account,
+ G_GNUC_UNUSED gpointer data)
{
g_return_if_fail(account != NULL);
@@ -1204,6 +1205,7 @@
void
purple_savedstatuses_init(void)
{
+ PurpleAccountManager *manager = purple_account_manager_get_default();
void *handle = purple_savedstatuses_get_handle();
creation_times = g_hash_table_new(g_direct_hash, g_direct_equal);
@@ -1240,15 +1242,15 @@
purple_marshal_VOID__POINTER, G_TYPE_NONE, 1,
PURPLE_TYPE_SAVEDSTATUS);
- purple_signal_connect(purple_accounts_get_handle(), "account-removed",
- handle,
- G_CALLBACK(purple_savedstatus_unset_all_substatuses),
- NULL);
+ g_signal_connect(manager, "removed",
+ G_CALLBACK(purple_savedstatus_unset_all_substatuses),
+ NULL);
}
void
purple_savedstatuses_uninit(void)
{
+ PurpleAccountManager *manager = purple_account_manager_get_default();
gpointer handle = purple_savedstatuses_get_handle();
remove_old_transient_statuses();
@@ -1266,6 +1268,9 @@
g_hash_table_destroy(creation_times);
creation_times = NULL;
+ g_signal_handlers_disconnect_by_func(manager,
+ G_CALLBACK(purple_savedstatus_unset_all_substatuses),
+ NULL);
purple_signals_unregister_by_instance(handle);
purple_signals_disconnect_by_handle(handle);
}
--- a/pidgin/gtkconn.c Sun Oct 09 00:41:50 2022 -0500
+++ b/pidgin/gtkconn.c Sun Oct 09 01:48:50 2022 -0500
@@ -179,7 +179,8 @@
}
static void
-account_removed_cb(PurpleAccount *account, gpointer user_data)
+account_removed_cb(G_GNUC_UNUSED PurpleAccountManager *manager,
+ PurpleAccount *account, G_GNUC_UNUSED gpointer data)
{
g_hash_table_remove(auto_reconns, account);
}
@@ -189,30 +190,25 @@
* GTK connection glue
**************************************************************************/
-void *
-pidgin_connection_get_handle(void)
-{
- static int handle;
-
- return &handle;
-}
-
void
pidgin_connection_init(void)
{
+ PurpleAccountManager *manager = purple_account_manager_get_default();
+
auto_reconns = g_hash_table_new_full(
g_direct_hash, g_direct_equal,
NULL, free_auto_recon);
- purple_signal_connect(purple_accounts_get_handle(), "account-removed",
- pidgin_connection_get_handle(),
- G_CALLBACK(account_removed_cb), NULL);
+ g_signal_connect(manager, "removed", G_CALLBACK(account_removed_cb), NULL);
}
void
pidgin_connection_uninit(void)
{
- purple_signals_disconnect_by_handle(pidgin_connection_get_handle());
+ PurpleAccountManager *manager = purple_account_manager_get_default();
+
+ g_signal_handlers_disconnect_by_func(manager,
+ G_CALLBACK(account_removed_cb), NULL);
g_hash_table_destroy(auto_reconns);
}
--- a/pidgin/gtkconn.h Sun Oct 09 00:41:50 2022 -0500
+++ b/pidgin/gtkconn.h Sun Oct 09 01:48:50 2022 -0500
@@ -42,15 +42,6 @@
PurpleConnectionUiOps *pidgin_connections_get_ui_ops(void);
/**
- * pidgin_connection_get_handle:
- *
- * Returns the GTK connection handle.
- *
- * Returns: The handle to the GTK connection system.
- */
-void *pidgin_connection_get_handle(void);
-
-/**
* pidgin_connection_init:
*
* Initializes the GTK connection system.
--- a/pidgin/gtkutils.c Sun Oct 09 00:41:50 2022 -0500
+++ b/pidgin/gtkutils.c Sun Oct 09 01:48:50 2022 -0500
@@ -364,24 +364,49 @@
}
static void
-buddyname_autocomplete_destroyed_cb(GtkWidget *widget, gpointer data)
+repopulate_autocomplete(gpointer something, gpointer data)
{
- g_free(data);
- purple_signals_disconnect_by_handle(widget);
+ add_completion_list(data);
+}
+
+static void
+autocomplete_account_added_cb(G_GNUC_UNUSED PurpleAccountManager *manager,
+ G_GNUC_UNUSED PurpleAccount *account,
+ gpointer data)
+{
+ add_completion_list(data);
}
static void
-repopulate_autocomplete(gpointer something, gpointer data)
+autocomplete_account_removed_cb(G_GNUC_UNUSED PurpleAccountManager *manager,
+ G_GNUC_UNUSED PurpleAccount *account,
+ gpointer data)
{
add_completion_list(data);
}
+static void
+buddyname_autocomplete_destroyed_cb(GtkWidget *widget, gpointer data)
+{
+ PurpleAccountManager *manager = purple_account_manager_get_default();
+
+ purple_signals_disconnect_by_handle(widget);
+
+ g_signal_handlers_disconnect_by_func(manager,
+ G_CALLBACK(autocomplete_account_added_cb), data);
+ g_signal_handlers_disconnect_by_func(manager,
+ G_CALLBACK(autocomplete_account_removed_cb), data);
+
+ g_free(data);
+}
+
void
pidgin_setup_screenname_autocomplete(
GtkWidget *entry, GtkWidget *chooser,
PidginFilterBuddyCompletionEntryFunc filter_func, gpointer user_data)
{
PidginCompletionData *data;
+ PurpleAccountManager *manager = NULL;
/*
* Store the displayed completion value, the buddy name, the UTF-8
@@ -434,10 +459,11 @@
purple_signal_connect(purple_connections_get_handle(), "signed-off", entry,
G_CALLBACK(repopulate_autocomplete), data);
- purple_signal_connect(purple_accounts_get_handle(), "account-added", entry,
- G_CALLBACK(repopulate_autocomplete), data);
- purple_signal_connect(purple_accounts_get_handle(), "account-removed", entry,
- G_CALLBACK(repopulate_autocomplete), data);
+ manager = purple_account_manager_get_default();
+ g_signal_connect(manager, "added",
+ G_CALLBACK(autocomplete_account_added_cb), data);
+ g_signal_connect(manager, "removed",
+ G_CALLBACK(autocomplete_account_removed_cb), data);
g_signal_connect(G_OBJECT(entry), "destroy", G_CALLBACK(buddyname_autocomplete_destroyed_cb), data);
}
--- a/pidgin/pidginaccountstore.c Sun Oct 09 00:41:50 2022 -0500
+++ b/pidgin/pidginaccountstore.c Sun Oct 09 01:48:50 2022 -0500
@@ -79,16 +79,6 @@
}
static void
-pidgin_account_store_add_accounts(PidginAccountStore *store) {
- PurpleAccountManager *manager = NULL;
-
- manager = purple_account_manager_get_default();
- purple_account_manager_foreach(manager,
- pidgin_account_store_add_account_helper,
- store);
-}
-
-static void
pidgin_account_store_remove_account(PidginAccountStore *store,
PurpleAccount *account)
{
@@ -126,14 +116,16 @@
* Callbacks
*****************************************************************************/
static void
-pidgin_account_store_account_added_cb(PurpleAccount *account,
+pidgin_account_store_account_added_cb(G_GNUC_UNUSED PurpleAccountManager *manager,
+ PurpleAccount *account,
gpointer data)
{
pidgin_account_store_add_account(PIDGIN_ACCOUNT_STORE(data), account);
}
static void
-pidgin_account_store_account_removed_cb(PurpleAccount *account,
+pidgin_account_store_account_removed_cb(G_GNUC_UNUSED PurpleAccountManager *manager,
+ PurpleAccount *account,
gpointer data)
{
pidgin_account_store_remove_account(PIDGIN_ACCOUNT_STORE(data), account);
@@ -146,7 +138,7 @@
static void
pidgin_account_store_init(PidginAccountStore *store) {
- gpointer accounts_handle = NULL;
+ PurpleAccountManager *manager = NULL;
GType types[PIDGIN_ACCOUNT_STORE_N_COLUMNS] = {
PURPLE_TYPE_ACCOUNT,
G_TYPE_STRING,
@@ -160,16 +152,18 @@
);
/* add the known accounts */
- pidgin_account_store_add_accounts(store);
+ manager = purple_account_manager_get_default();
+ purple_account_manager_foreach(manager,
+ pidgin_account_store_add_account_helper,
+ store);
/* add the signal handlers to dynamically add/remove accounts */
- accounts_handle = purple_accounts_get_handle();
- purple_signal_connect(accounts_handle, "account-added", store,
- G_CALLBACK(pidgin_account_store_account_added_cb),
- store);
- purple_signal_connect(accounts_handle, "account-removed", store,
- G_CALLBACK(pidgin_account_store_account_removed_cb),
- store);
+ g_signal_connect_object(manager, "added",
+ G_CALLBACK(pidgin_account_store_account_added_cb),
+ store, 0);
+ g_signal_connect_object(manager, "removed",
+ G_CALLBACK(pidgin_account_store_account_removed_cb),
+ store, 0);
}
static void