--- a/libpurple/account.c Tue May 23 00:18:04 2023 -0500
+++ b/libpurple/account.c Tue May 23 00:21:15 2023 -0500
@@ -111,6 +111,8 @@
static guint signals[N_SIGNALS] = {0, };
@@ -418,6 +420,23 @@
+purple_account_connection_state_cb(GObject *obj, + G_GNUC_UNUSED GParamSpec *pspec, + PurpleAccount *account = data; + PurpleConnection *connection = PURPLE_CONNECTION(obj); + PurpleConnectionState state = PURPLE_CONNECTION_STATE_DISCONNECTED; + state = purple_connection_get_state(connection); + if(state == PURPLE_CONNECTION_STATE_CONNECTED) { + g_signal_emit(account, signals[SIG_CONNECTED], 0); + } else if(state == PURPLE_CONNECTION_STATE_DISCONNECTED) { + g_signal_emit(account, signals[SIG_DISCONNECTED], 0); /******************************************************************************
*****************************************************************************/
@@ -927,6 +946,48 @@
+ * PurpleAccount::connected: + * @account: The account instance. + * This is emitted when the [property@Account:connection]'s + * [property@Connection:state] has changed to + * %PURPLE_CONNECTION_STATE_CONNECTED. + signals[SIG_CONNECTED] = g_signal_new_class_handler( + G_OBJECT_CLASS_TYPE(klass), + * PurpleAccount::disconnected: + * @account: The account instance. + * This is emitted when the [property@Account:connection]'s + * [property@Connection:state] has changed to + * %PURPLE_CONNECTION_STATE_DISCONNECTED. + signals[SIG_DISCONNECTED] = g_signal_new_class_handler( + G_OBJECT_CLASS_TYPE(klass), /******************************************************************************
@@ -1223,9 +1284,34 @@
purple_account_set_connection(PurpleAccount *account, PurpleConnection *gc) {
g_return_if_fail(PURPLE_IS_ACCOUNT(account));
+ /* If we got the same pointer, bail. */ + if(account->gc == gc) { + /* Remove our old signal handler. */ + if(PURPLE_IS_CONNECTION(account->gc)) { + g_signal_handlers_disconnect_by_func(account->gc, + purple_account_connection_state_cb, if(g_set_object(&account->gc, gc)) {
+ if(PURPLE_IS_CONNECTION(account->gc)) { + g_signal_connect(account->gc, "notify::state", + G_CALLBACK(purple_account_connection_state_cb), g_object_notify_by_pspec(G_OBJECT(account),
properties[PROP_CONNECTION]);
+ /* If the set didn't work, restore our old signal. */ + if(PURPLE_IS_CONNECTION(account->gc)) { + g_signal_connect(account->gc, "notify::state", + G_CALLBACK(purple_account_connection_state_cb),