Mon, 14 Oct 2024 20:26:55 -0500
Deprecate Purple.Account:error for Purple.Account:error-info
This is the first step in updating Purple.Account:error to be a GLib.Error.
Testing Done:
Called in the turtles.
Bugs closed: PIDGIN-17980
Reviewed at https://reviews.imfreedom.org/r/3569/
--- a/libpurple/accounts.c Mon Oct 14 00:51:46 2024 -0500 +++ b/libpurple/accounts.c Mon Oct 14 20:26:55 2024 -0500 @@ -302,7 +302,7 @@ (description != NULL) ? description : ""); g_free(description); - purple_account_set_error(account, current_error); + purple_account_set_error_info(account, current_error); } static PurpleAccount *
--- a/libpurple/purpleaccount.c Mon Oct 14 00:51:46 2024 -0500 +++ b/libpurple/purpleaccount.c Mon Oct 14 20:26:55 2024 -0500 @@ -76,7 +76,7 @@ PurplePresence *presence; - PurpleConnectionErrorInfo *error; + PurpleConnectionErrorInfo *error_info; PurpleNotification *error_notification; } PurpleAccountPrivate; @@ -99,6 +99,7 @@ PROP_REMEMBER_PASSWORD, PROP_PROXY_INFO, PROP_ERROR, + PROP_ERROR_INFO, PROP_CONNECTED, N_PROPERTIES, }; @@ -194,7 +195,7 @@ message); g_clear_error(&error); - purple_account_set_error(account, error_info); + purple_account_set_error_info(account, error_info); } /* Finally remove our reference to the connection. */ @@ -394,7 +395,7 @@ info = purple_connection_error_info_new(PURPLE_CONNECTION_ERROR_NETWORK_ERROR, error_message); - purple_account_set_error(account, info); + purple_account_set_error_info(account, info); g_clear_error(&error); @@ -590,7 +591,7 @@ purple_xmlnode_insert_child(node, child); } - child = current_error_to_xmlnode(account->error); + child = current_error_to_xmlnode(account->error_info); purple_xmlnode_insert_child(node, child); return node; @@ -641,7 +642,8 @@ purple_account_set_proxy_info(account, g_value_get_object(value)); break; case PROP_ERROR: - purple_account_set_error(account, g_value_get_boxed(value)); + case PROP_ERROR_INFO: + purple_account_set_error_info(account, g_value_get_boxed(value)); break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID(obj, param_id, pspec); @@ -692,7 +694,8 @@ g_value_set_object(value, purple_account_get_proxy_info(account)); break; case PROP_ERROR: - g_value_set_boxed(value, purple_account_get_error(account)); + case PROP_ERROR_INFO: + g_value_set_boxed(value, purple_account_get_error_info(account)); break; case PROP_CONNECTED: g_value_set_boolean(value, purple_account_is_connected(account)); @@ -761,7 +764,7 @@ g_clear_object(&account->proxy_info); - g_clear_pointer(&account->error, purple_connection_error_info_free); + g_clear_pointer(&account->error_info, purple_connection_error_info_free); g_clear_object(&account->error_notification); g_free(account->user_info); @@ -938,6 +941,23 @@ properties[PROP_ERROR] = g_param_spec_boxed( "error", NULL, NULL, PURPLE_TYPE_CONNECTION_ERROR_INFO, + G_PARAM_READWRITE | G_PARAM_DEPRECATED | G_PARAM_STATIC_STRINGS); + + /** + * PurpleAccount:error-info: + * + * The [type@GLib.Error] of the account. This is set when an account enters + * an error state and is automatically cleared when a connection attempt is + * made. + * + * Setting this will not disconnect an account, but this will be set when + * there is a connection failure. + * + * Since: 3.0 + */ + properties[PROP_ERROR_INFO] = g_param_spec_boxed( + "error-info", NULL, NULL, + PURPLE_TYPE_CONNECTION_ERROR_INFO, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS); /** @@ -1091,7 +1111,7 @@ g_return_if_fail(PURPLE_IS_ACCOUNT(account)); - purple_account_set_error(account, NULL); + purple_account_set_error_info(account, NULL); if(!purple_account_get_enabled(account)) { purple_debug_info("account", @@ -1578,24 +1598,40 @@ purple_account_get_error(PurpleAccount *account) { g_return_val_if_fail(PURPLE_IS_ACCOUNT(account), NULL); - return account->error; + return purple_account_get_error_info(account); +} + +const PurpleConnectionErrorInfo * +purple_account_get_error_info(PurpleAccount *account) { + g_return_val_if_fail(PURPLE_IS_ACCOUNT(account), NULL); + + return account->error_info; } void purple_account_set_error(PurpleAccount *account, PurpleConnectionErrorInfo *info) { + g_return_if_fail(PURPLE_IS_ACCOUNT(account)); + + purple_account_set_error_info(account, info); +} + +void +purple_account_set_error_info(PurpleAccount *account, + PurpleConnectionErrorInfo *info) +{ PurpleNotificationManager *manager = NULL; g_return_if_fail(PURPLE_IS_ACCOUNT(account)); - if(info == account->error) { + if(info == account->error_info) { return; } - g_clear_pointer(&account->error, + g_clear_pointer(&account->error_info, purple_connection_error_info_free); - account->error = info; + account->error_info = info; manager = purple_notification_manager_get_default();
--- a/libpurple/purpleaccount.h Mon Oct 14 00:51:46 2024 -0500 +++ b/libpurple/purpleaccount.h Mon Oct 14 20:26:55 2024 -0500 @@ -546,6 +546,23 @@ /** * purple_account_get_error: + * @account: The instance. + * + * Get the error from @account. + * + * This will be set to the error that caused the account to be disconnected, or + * %NULL if the account was disconnected without an error or is currently + * connected. + * + * Returns: (transfer none): The error or %NULL if there is no current error. + * + * Since: 3.0 + */ +PURPLE_DEPRECATED_FOR(purple_account_get_error_info) +const PurpleConnectionErrorInfo *purple_account_get_error(PurpleAccount *account); + +/** + * purple_account_get_error_info: * @account: The account whose error should be retrieved. * * Get the error that caused the account to be disconnected, or %NULL if the @@ -559,7 +576,7 @@ * Since: 3.0 */ PURPLE_AVAILABLE_IN_3_0 -const PurpleConnectionErrorInfo *purple_account_get_error(PurpleAccount *account); +const PurpleConnectionErrorInfo *purple_account_get_error_info(PurpleAccount *account); /** * purple_account_set_error: @@ -574,8 +591,24 @@ * * Since: 3.0 */ +PURPLE_DEPRECATED_FOR(purple_account_set_error_info) +void purple_account_set_error(PurpleAccount *account, PurpleConnectionErrorInfo *info); + +/** + * purple_account_set_error_info: + * @account: The account whose error should be set. + * @info: (nullable) (transfer full): The [struct@Purple.ConnectionErrorInfo] + * to set. + * + * Sets the error of @account to @info. Note that setting this won't disconnect + * the account. This is intended to be called by libpurple when there is a + * connection failure, when invalid settings are entered in an account editor, + * or similar situations. + * + * Since: 3.0 + */ PURPLE_AVAILABLE_IN_3_0 -void purple_account_set_error(PurpleAccount *account, PurpleConnectionErrorInfo *info); +void purple_account_set_error_info(PurpleAccount *account, PurpleConnectionErrorInfo *info); /** * purple_account_set_require_password:
--- a/libpurple/purpleaccountmanager.c Mon Oct 14 00:51:46 2024 -0500 +++ b/libpurple/purpleaccountmanager.c Mon Oct 14 20:26:55 2024 -0500 @@ -543,7 +543,7 @@ /* Clearing the error ensures that account-error-changed is emitted, * which is the end of the guarantee that the error's pointer is valid. */ - purple_account_set_error(account, NULL); + purple_account_set_error_info(account, NULL); g_signal_emit(manager, signals[SIG_REMOVED], 0, account);
--- a/libpurple/purplenotificationconnectionerror.c Mon Oct 14 00:51:46 2024 -0500 +++ b/libpurple/purplenotificationconnectionerror.c Mon Oct 14 20:26:55 2024 -0500 @@ -60,7 +60,7 @@ const char *subtitle = NULL; account = purple_notification_get_account(notification); - error = purple_account_get_error(account); + error = purple_account_get_error_info(account); protocol = purple_account_get_protocol(account); if(PURPLE_IS_PROTOCOL(protocol)) {