--- a/libpurple/purplecontactinfo.c Tue Dec 13 02:46:09 2022 -0600
+++ b/libpurple/purplecontactinfo.c Tue Dec 13 02:59:06 2022 -0600
@@ -27,6 +27,7 @@
@@ -45,6 +46,7 @@
@@ -80,6 +82,9 @@
g_value_set_string(value, purple_contact_info_get_alias(info));
+ g_value_set_string(value, purple_contact_info_get_color(info)); g_value_set_object(value, purple_contact_info_get_avatar(info));
@@ -121,6 +126,9 @@
purple_contact_info_set_alias(info, g_value_get_string(value));
+ purple_contact_info_set_color(info, g_value_get_string(value)); purple_contact_info_set_avatar(info, g_value_get_object(value));
@@ -257,6 +265,22 @@
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
+ * PurpleContactInfo:color: + * The color for this contact. This is an RGB hex code that user interfaces + * can use when rendering the contact. This may also be controlled via a + * protocol plugin in the event that the protocol allows people to set a + * highlight/branding color. + properties[PROP_COLOR] = g_param_spec_string( + "The color to use when rendering the contact.", + G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS); * PurpleContactInfo:avatar:
* The avatar for this contact. This is typically controlled by the protocol
@@ -442,6 +466,33 @@
g_object_notify_by_pspec(G_OBJECT(info), properties[PROP_ALIAS]);
+purple_contact_info_get_color(PurpleContactInfo *info) { + PurpleContactInfoPrivate *priv = NULL; + g_return_val_if_fail(PURPLE_IS_CONTACT_INFO(info), NULL); + priv = purple_contact_info_get_instance_private(info); +purple_contact_info_set_color(PurpleContactInfo *info, const char *color) { + PurpleContactInfoPrivate *priv = NULL; + g_return_if_fail(PURPLE_IS_CONTACT_INFO(info)); + priv = purple_contact_info_get_instance_private(info); + if(!purple_strequal(priv->color, color)) { + priv->color = g_strdup(color); + g_object_notify_by_pspec(G_OBJECT(info), properties[PROP_COLOR]); purple_contact_info_get_avatar(PurpleContactInfo *info) {
PurpleContactInfoPrivate *priv = NULL;
--- a/libpurple/purplecontactinfo.h Tue Dec 13 02:46:09 2022 -0600
+++ b/libpurple/purplecontactinfo.h Tue Dec 13 02:59:06 2022 -0600
@@ -203,6 +203,34 @@
void purple_contact_info_set_alias(PurpleContactInfo *info, const gchar *alias);
+ * purple_contact_info_get_color: + * Gets the color that should be used to render this contact info. This is a + * RGB hex code in a string format. + * Returns: The RGB hex code. +const char *purple_contact_info_get_color(PurpleContactInfo *info); + * purple_contact_info_set_color: + * @color: The RGB hex code to set. + * Sets the color to use when rendering @info to @color. + * @color should start with a `#` and have a valid number of hex digits + * following it. Different user interfaces may be able to handle additional + * precision, but using `#RRGGBB` will have the highest compatibility. +void purple_contact_info_set_color(PurpleContactInfo *info, const char *color); * purple_contact_info_get_avatar:
--- a/libpurple/tests/test_contact_info.c Tue Dec 13 02:46:09 2022 -0600
+++ b/libpurple/tests/test_contact_info.c Tue Dec 13 02:59:06 2022 -0600
@@ -50,6 +50,7 @@
gchar *display_name = NULL;
avatar = gdk_pixbuf_new(GDK_COLORSPACE_RGB, FALSE, 8, 1, 1);
person = purple_person_new();
@@ -64,6 +65,7 @@
"display-name", "display-name",
"permission", PURPLE_CONTACT_INFO_PERMISSION_ALLOW,
@@ -75,6 +77,7 @@
"display-name", &display_name,
@@ -87,6 +90,7 @@
g_assert_cmpstr(username, ==, "username");
g_assert_cmpstr(display_name, ==, "display-name");
g_assert_cmpstr(alias, ==, "alias");
+ g_assert_cmpstr(color, ==, "#e9c636"); g_assert_true(avatar1 == avatar);
g_assert_nonnull(presence1);
@@ -98,6 +102,7 @@
g_clear_pointer(&username, g_free);
g_clear_pointer(&display_name, g_free);
g_clear_pointer(&alias, g_free);
+ g_clear_pointer(&color, g_free); g_clear_object(&avatar1);
g_clear_object(&presence1);