pidgin/pidgin

Add a color property to PurpleContactInfo

17 months ago, Gary Kramlich
9da6ba6eba5d
Parents aaf28c77ff60
Children 9ad66abc9356
Add a color property to PurpleContactInfo

Testing Done:
Ran the unit tests

Reviewed at https://reviews.imfreedom.org/r/2136/
--- 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 @@
gchar *username;
gchar *display_name;
gchar *alias;
+ gchar *color;
GdkPixbuf *avatar;
@@ -45,6 +46,7 @@
PROP_USERNAME,
PROP_DISPLAY_NAME,
PROP_ALIAS,
+ PROP_COLOR,
PROP_AVATAR,
PROP_PRESENCE,
PROP_TAGS,
@@ -80,6 +82,9 @@
case PROP_ALIAS:
g_value_set_string(value, purple_contact_info_get_alias(info));
break;
+ case PROP_COLOR:
+ g_value_set_string(value, purple_contact_info_get_color(info));
+ break;
case PROP_AVATAR:
g_value_set_object(value, purple_contact_info_get_avatar(info));
break;
@@ -121,6 +126,9 @@
case PROP_ALIAS:
purple_contact_info_set_alias(info, g_value_get_string(value));
break;
+ case PROP_COLOR:
+ purple_contact_info_set_color(info, g_value_get_string(value));
+ break;
case PROP_AVATAR:
purple_contact_info_set_avatar(info, g_value_get_object(value));
break;
@@ -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.
+ *
+ * Since: 3.0.0
+ */
+ properties[PROP_COLOR] = g_param_spec_string(
+ "color", "color",
+ "The color to use when rendering the contact.",
+ NULL,
+ 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]);
}
+const char *
+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);
+
+ return priv->color;
+}
+
+void
+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)) {
+ g_free(priv->color);
+ priv->color = g_strdup(color);
+
+ g_object_notify_by_pspec(G_OBJECT(info), properties[PROP_COLOR]);
+ }
+}
+
GdkPixbuf *
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:
+ * @info: The instance.
+ *
+ * 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.
+ *
+ * Since: 3.0.0
+ */
+const char *purple_contact_info_get_color(PurpleContactInfo *info);
+
+/**
+ * purple_contact_info_set_color:
+ * @info: The instance.
+ * @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.
+ *
+ * Since: 3.0.0
+ */
+void purple_contact_info_set_color(PurpleContactInfo *info, const char *color);
+
+/**
* purple_contact_info_get_avatar:
* @info: The instance.
*
--- 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 *username = NULL;
gchar *display_name = NULL;
gchar *alias = NULL;
+ gchar *color = NULL;
avatar = gdk_pixbuf_new(GDK_COLORSPACE_RGB, FALSE, 8, 1, 1);
person = purple_person_new();
@@ -64,6 +65,7 @@
"username", "username",
"display-name", "display-name",
"alias", "alias",
+ "color", "#e9c636",
"avatar", avatar,
"person", person,
"permission", PURPLE_CONTACT_INFO_PERMISSION_ALLOW,
@@ -75,6 +77,7 @@
"username", &username,
"display-name", &display_name,
"alias", &alias,
+ "color", &color,
"avatar", &avatar1,
"presence", &presence1,
"tags", &tags,
@@ -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);
g_assert_nonnull(tags);
@@ -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);
g_clear_object(&tags);