Tue, 28 Jan 2025 10:53:46 -0600
Add a name property to Purple.Account
This allows the libpurple user to name accounts to whatever they want. That
means they can do stuff like "Work 1", "Customer 2", "testing", etc.
The intent here is to use this instead of the "username (protocol)" method
that we've used historically.
Testing Done:
Ran the unit tests under valgrind and called in the turtles.
Bugs closed: PIDGIN-18029
Reviewed at https://reviews.imfreedom.org/r/3788/
--- a/libpurple/purpleaccount.c Wed Jan 22 22:41:16 2025 -0600 +++ b/libpurple/purpleaccount.c Tue Jan 28 10:53:46 2025 -0600 @@ -54,6 +54,7 @@ GObject parent; char *id; + char *name; char *username; PurpleContactInfo *contact_info; @@ -90,6 +91,7 @@ enum { PROP_0, PROP_ID, + PROP_NAME, PROP_USERNAME, PROP_CONTACT_INFO, PROP_REQUIRE_PASSWORD, @@ -625,6 +627,9 @@ case PROP_ID: purple_account_set_id(account, g_value_get_string(value)); break; + case PROP_NAME: + purple_account_set_name(account, g_value_get_string(value)); + break; case PROP_USERNAME: purple_account_set_username(account, g_value_get_string(value)); break; @@ -676,6 +681,9 @@ case PROP_ID: g_value_set_string(value, purple_account_get_id(account)); break; + case PROP_NAME: + g_value_set_string(value, purple_account_get_name(account)); + break; case PROP_USERNAME: g_value_set_string(value, purple_account_get_username(account)); break; @@ -756,6 +764,7 @@ purple_account_free_notify_settings(account); g_clear_pointer(&account->id, g_free); + g_clear_pointer(&account->name, g_free); g_clear_pointer(&account->username, g_free); g_clear_object(&account->contact_info); @@ -796,6 +805,21 @@ G_PARAM_READWRITE | G_PARAM_CONSTRUCT | G_PARAM_STATIC_STRINGS); /** + * PurpleAccount:name: + * + * The user supplied name of the account. + * + * This is used by user interfaces to help the user determine which account + * is which. + * + * Since: 3.0 + */ + properties[PROP_NAME] = g_param_spec_string( + "name", NULL, NULL, + NULL, + G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS); + + /** * PurpleAccount:username: * * The username for the account. @@ -1805,3 +1829,20 @@ purple_account_equal(PurpleAccount *a, PurpleAccount *b) { return purple_account_compare(a, b) == 0; } + +const char * +purple_account_get_name(PurpleAccount *account) { + g_return_val_if_fail(PURPLE_IS_ACCOUNT(account), NULL); + + return account->name; +} + +void +purple_account_set_name(PurpleAccount *account, const char *name) { + g_return_if_fail(PURPLE_IS_ACCOUNT(account)); + g_return_if_fail(!purple_strempty(name)); + + if(g_set_str(&account->name, name)) { + g_object_notify_by_pspec(G_OBJECT(account), properties[PROP_NAME]); + } +}
--- a/libpurple/purpleaccount.h Wed Jan 22 22:41:16 2025 -0600 +++ b/libpurple/purpleaccount.h Tue Jan 28 10:53:46 2025 -0600 @@ -694,6 +694,29 @@ PURPLE_AVAILABLE_IN_3_0 gboolean purple_account_equal(PurpleAccount *a, PurpleAccount *b); +/** + * purple_account_get_name: + * + * Gets the user supplied name for an account. + * + * Returns: The name of the account. + * + * Since: 3.0 + */ +PURPLE_AVAILABLE_IN_3_0 +const char *purple_account_get_name(PurpleAccount *account); + +/** + * purple_account_set_name: + * @name: the new name + * + * Sets the user supplied name of an account. + * + * Since: 3.0 + */ +PURPLE_AVAILABLE_IN_3_0 +void purple_account_set_name(PurpleAccount *account, const char *name); + G_END_DECLS #endif /* PURPLE_ACCOUNT_H */
--- a/libpurple/tests/test_account.c Wed Jan 22 22:41:16 2025 -0600 +++ b/libpurple/tests/test_account.c Tue Jan 28 10:53:46 2025 -0600 @@ -115,6 +115,7 @@ PurpleProxyInfo *proxy_info = NULL; PurpleProxyInfo *proxy_info1 = NULL; char *id = NULL; + char *name = NULL; char *username = NULL; char *user_info; char *buddy_icon_path; @@ -131,6 +132,7 @@ "buddy-icon-path", "buddy-icon-path1", "enabled", TRUE, "id", "id1", + "name", "Test Account 1", "protocol-id", "protocol-id1", "proxy-info", proxy_info, "remember-password", TRUE, @@ -149,6 +151,7 @@ "contact-info", &contact_info, "enabled", &enabled, "id", &id, + "name", &name, "protocol-id", &protocol_id, "proxy-info", &proxy_info1, "remember-password", &remember_password, @@ -172,6 +175,9 @@ g_assert_cmpstr(id, ==, "id1"); g_clear_pointer(&id, g_free); + g_assert_cmpstr(name, ==, "Test Account 1"); + g_clear_pointer(&name, g_free); + g_assert_cmpstr(protocol_id, ==, "protocol-id1"); g_clear_pointer(&protocol_id, g_free);