Tue, 07 May 2024 23:06:04 -0500
Prepare for reparenting PurpleAccount
The idea of having PurpleAccount subclass PurpleContactInfo had some issues.
First, the server side id isn't known at account creation time which means we
had to generate a local one and then throw that away when we knew the server
side id. This technically worked, but breaks the current idea for serialization
which is one of the big reasons why this has to change.
This is the first step in reparenting it to GObject and having a property that
has the protocol specific contact info. The idea is that we can update all of
the consumers to call these methods and once that's done we can go ahead and do
the reparenting without breaking anything.
Testing Done:
Had the turtles do their thing and connected some accounts without issue.
Reviewed at https://reviews.imfreedom.org/r/3157/
| libpurple/purpleaccount.c | file | annotate | diff | comparison | revisions | |
| libpurple/purpleaccount.h | file | annotate | diff | comparison | revisions |
--- a/libpurple/purpleaccount.c Tue May 07 23:01:07 2024 -0500 +++ b/libpurple/purpleaccount.c Tue May 07 23:06:04 2024 -0500 @@ -86,6 +86,9 @@ enum { PROP_0, + PROP_ID, + PROP_USERNAME, + PROP_CONTACT_INFO, PROP_REQUIRE_PASSWORD, PROP_ENABLED, PROP_CONNECTION, @@ -114,6 +117,13 @@ * Helpers *****************************************************************************/ static void +purple_account_set_id(PurpleAccount *account, const char *id) { + g_return_if_fail(PURPLE_IS_ACCOUNT(account)); + + purple_contact_info_set_id(PURPLE_CONTACT_INFO(account), id); +} + +static void purple_account_free_notify_settings(PurpleAccount *account) { g_return_if_fail(PURPLE_IS_ACCOUNT(account)); @@ -598,39 +608,44 @@ PurpleAccount *account = PURPLE_ACCOUNT(obj); switch(param_id) { - case PROP_REQUIRE_PASSWORD: - purple_account_set_require_password(account, - g_value_get_boolean(value)); - break; - case PROP_ENABLED: - purple_account_set_enabled(account, g_value_get_boolean(value)); - break; - case PROP_CONNECTION: - purple_account_set_connection(account, g_value_get_object(value)); - break; - case PROP_PROTOCOL_ID: - purple_account_set_protocol_id(account, g_value_get_string(value)); - break; - case PROP_USER_INFO: - purple_account_set_user_info(account, g_value_get_string(value)); - break; - case PROP_BUDDY_ICON_PATH: - purple_account_set_buddy_icon_path(account, - g_value_get_string(value)); - break; - case PROP_REMEMBER_PASSWORD: - purple_account_set_remember_password(account, - g_value_get_boolean(value)); - break; - case PROP_PROXY_INFO: - 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)); - break; - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID(obj, param_id, pspec); - break; + case PROP_ID: + purple_account_set_id(account, g_value_get_string(value)); + break; + case PROP_USERNAME: + purple_account_set_username(account, g_value_get_string(value)); + break; + case PROP_REQUIRE_PASSWORD: + purple_account_set_require_password(account, + g_value_get_boolean(value)); + break; + case PROP_ENABLED: + purple_account_set_enabled(account, g_value_get_boolean(value)); + break; + case PROP_CONNECTION: + purple_account_set_connection(account, g_value_get_object(value)); + break; + case PROP_PROTOCOL_ID: + purple_account_set_protocol_id(account, g_value_get_string(value)); + break; + case PROP_USER_INFO: + purple_account_set_user_info(account, g_value_get_string(value)); + break; + case PROP_BUDDY_ICON_PATH: + purple_account_set_buddy_icon_path(account, g_value_get_string(value)); + break; + case PROP_REMEMBER_PASSWORD: + purple_account_set_remember_password(account, + g_value_get_boolean(value)); + break; + case PROP_PROXY_INFO: + 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)); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID(obj, param_id, pspec); + break; } } @@ -641,42 +656,50 @@ PurpleAccount *account = PURPLE_ACCOUNT(obj); switch(param_id) { - case PROP_REQUIRE_PASSWORD: - g_value_set_boolean(value, - purple_account_get_require_password(account)); - break; - case PROP_ENABLED: - g_value_set_boolean(value, purple_account_get_enabled(account)); - break; - case PROP_CONNECTION: - g_value_set_object(value, purple_account_get_connection(account)); - break; - case PROP_PROTOCOL_ID: - g_value_set_string(value, purple_account_get_protocol_id(account)); - break; - case PROP_USER_INFO: - g_value_set_string(value, purple_account_get_user_info(account)); - break; - case PROP_BUDDY_ICON_PATH: - g_value_set_string(value, - purple_account_get_buddy_icon_path(account)); - break; - case PROP_REMEMBER_PASSWORD: - g_value_set_boolean(value, - purple_account_get_remember_password(account)); - break; - case PROP_PROXY_INFO: - 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)); - break; - case PROP_CONNECTED: - g_value_set_boolean(value, purple_account_is_connected(account)); - break; - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID(obj, param_id, pspec); - break; + case PROP_ID: + g_value_set_string(value, purple_account_get_id(account)); + break; + case PROP_USERNAME: + g_value_set_string(value, purple_account_get_username(account)); + break; + case PROP_CONTACT_INFO: + g_value_set_object(value, purple_account_get_contact_info(account)); + break; + case PROP_REQUIRE_PASSWORD: + g_value_set_boolean(value, + purple_account_get_require_password(account)); + break; + case PROP_ENABLED: + g_value_set_boolean(value, purple_account_get_enabled(account)); + break; + case PROP_CONNECTION: + g_value_set_object(value, purple_account_get_connection(account)); + break; + case PROP_PROTOCOL_ID: + g_value_set_string(value, purple_account_get_protocol_id(account)); + break; + case PROP_USER_INFO: + g_value_set_string(value, purple_account_get_user_info(account)); + break; + case PROP_BUDDY_ICON_PATH: + g_value_set_string(value, purple_account_get_buddy_icon_path(account)); + break; + case PROP_REMEMBER_PASSWORD: + g_value_set_boolean(value, + purple_account_get_remember_password(account)); + break; + case PROP_PROXY_INFO: + 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)); + break; + case PROP_CONNECTED: + g_value_set_boolean(value, purple_account_is_connected(account)); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID(obj, param_id, pspec); + break; } } @@ -761,6 +784,45 @@ obj_class->set_property = purple_account_set_property; /** + * PurpleAccount:id: + * + * The unique identifier for the account. + * + * Since: 3.0 + */ + properties[PROP_ID] = g_param_spec_string( + "id", "id", + "A unique identifier for the account.", + NULL, + G_PARAM_READWRITE | G_PARAM_CONSTRUCT | G_PARAM_STATIC_STRINGS); + + /** + * PurpleAccount:username: + * + * The username for the account. + * + * Since: 3.0 + */ + properties[PROP_USERNAME] = g_param_spec_string( + "username", "username", + "The username for the account.", + NULL, + G_PARAM_READWRITE | G_PARAM_CONSTRUCT | G_PARAM_STATIC_STRINGS); + + /** + * PurpleAccount:contact-info: + * + * The [class@ContactInfo] for the account. + * + * Since: 3.0 + */ + properties[PROP_CONTACT_INFO] = g_param_spec_object( + "contact-info", "contact-info", + "The contact info for the account.", + PURPLE_TYPE_CONTACT_INFO, + G_PARAM_READABLE | G_PARAM_STATIC_STRINGS); + + /** * PurpleAccount:require-password: * * Whether or not this account should require a password. This is only used @@ -1001,6 +1063,34 @@ NULL); } +const char * +purple_account_get_id(PurpleAccount *account) { + g_return_val_if_fail(PURPLE_IS_ACCOUNT(account), NULL); + + return purple_contact_info_get_id(PURPLE_CONTACT_INFO(account)); +} + +const char * +purple_account_get_username(PurpleAccount *account) { + g_return_val_if_fail(PURPLE_IS_ACCOUNT(account), NULL); + + return purple_contact_info_get_username(PURPLE_CONTACT_INFO(account)); +} + +void +purple_account_set_username(PurpleAccount *account, const char *username) { + g_return_if_fail(PURPLE_IS_ACCOUNT(account)); + + purple_contact_info_set_username(PURPLE_CONTACT_INFO(account), username); +} + +PurpleContactInfo * +purple_account_get_contact_info(PurpleAccount *account) { + g_return_val_if_fail(PURPLE_IS_ACCOUNT(account), NULL); + + return PURPLE_CONTACT_INFO(account); +} + void purple_account_connect(PurpleAccount *account) {
--- a/libpurple/purpleaccount.h Tue May 07 23:01:07 2024 -0500 +++ b/libpurple/purpleaccount.h Tue May 07 23:06:04 2024 -0500 @@ -72,6 +72,57 @@ PurpleAccount *purple_account_new(const char *username, const char *protocol_id); /** + * purple_account_get_id: + * @account: The instance. + * + * Gets the id of @account. + * + * Returns: The id of @account. + * + * Since: 3.0 + */ +PURPLE_AVAILABLE_IN_3_0 +const char *purple_account_get_id(PurpleAccount *account); + +/** + * purple_account_get_username: + * @account: The instance. + * + * Gets the username for @account. + * + * Returns: The username. + * + * Since: 2.0 + */ +PURPLE_AVAILABLE_IN_2_0 +const char *purple_account_get_username(PurpleAccount *account); + +/** + * purple_account_set_username: + * @account: The instance. + * @username: (nullable): The new username. + * + * Sets the username of @account to @username. + * + * Since: 2.0 + */ +PURPLE_AVAILABLE_IN_2_0 +void purple_account_set_username(PurpleAccount *account, const char *username); + +/** + * purple_account_get_contact_info: + * @account: The instance. + * + * Gets the [class@ContactInfo] for @account. + * + * Returns: (transfer none): The contact info for @account. + * + * Since: 3.0 + */ +PURPLE_AVAILABLE_IN_3_0 +PurpleContactInfo *purple_account_get_contact_info(PurpleAccount *account); + +/** * purple_account_connect: * @account: The account to connect to. *