--- a/doc/reference/pidgin/pidgin-docs.xml Mon Jun 14 04:11:01 2021 -0500
+++ b/doc/reference/pidgin/pidgin-docs.xml Mon Jun 14 22:18:20 2021 -0500
@@ -58,6 +58,7 @@
<xi:include href="xml/pidginavatar.xml" />
<xi:include href="xml/pidgincellrendererexpander.xml" />
<xi:include href="xml/pidginclosebutton.xml" />
+ <xi:include href="xml/pidgincolor.xml" /> <xi:include href="xml/pidgincontactcompletion.xml" />
<xi:include href="xml/pidgincontactlist.xml" />
<xi:include href="xml/pidginconversationwindow.xml" />
--- a/libpurple/purplemessage.c Mon Jun 14 04:11:01 2021 -0500
+++ b/libpurple/purplemessage.c Mon Jun 14 22:18:20 2021 -0500
@@ -39,6 +39,7 @@
+ gchar *author_name_color; @@ -56,6 +57,7 @@
+ PROP_AUTHOR_NAME_COLOR, @@ -198,6 +200,8 @@
* The account specific identifier of the message.
properties[PROP_ID] = g_param_spec_uint(
@@ -209,6 +213,8 @@
* The author of the message.
properties[PROP_AUTHOR] = g_param_spec_string(
@@ -217,9 +223,24 @@
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
+ * PurpleMessage::author-name-color: + * The hex color for the author's name. + properties[PROP_AUTHOR_NAME_COLOR] = g_param_spec_string( + "author-name-color", "author-name-color", + "The hex color to display the author's name with", + G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS); * PurpleMessage::author-alias:
* The alias of the author.
properties[PROP_AUTHOR_ALIAS] = g_param_spec_string(
"author-alias", "Author's alias",
@@ -231,6 +252,8 @@
* PurpleMessage::recipient:
* The recipient of the message.
properties[PROP_RECIPIENT] = g_param_spec_string(
"recipient", "Recipient",
@@ -242,6 +265,8 @@
* PurpleMessage::content:
* The contents of the message.
properties[PROP_CONTENTS] = g_param_spec_string(
@@ -253,6 +278,8 @@
* PurpleMessage::content-type:
* The content-type of the message.
properties[PROP_CONTENT_TYPE] = g_param_spec_enum(
"content-type", "content-type",
@@ -264,6 +291,8 @@
* PurpleMessage::timestamp:
* The timestamp of the message.
properties[PROP_TIMESTAMP] = g_param_spec_boxed(
"timestamp", "timestamp",
@@ -275,6 +304,8 @@
* The #PurpleMessageFlags for the message.
properties[PROP_FLAGS] = g_param_spec_flags(
@@ -383,6 +414,26 @@
+purple_message_set_author_name_color(PurpleMessage *message, + g_return_if_fail(PURPLE_IS_MESSAGE(message)); + g_free(message->author_name_color); + message->author_name_color = g_strdup(color); + g_object_notify_by_pspec(G_OBJECT(message), + properties[PROP_AUTHOR_NAME_COLOR]); +purple_message_get_author_name_color(PurpleMessage *message) { + g_return_val_if_fail(PURPLE_IS_MESSAGE(message), NULL); + return message->author_name_color; purple_message_set_recipient(PurpleMessage *message, const gchar *recipient) {
g_return_if_fail(PURPLE_IS_MESSAGE(message));
--- a/libpurple/purplemessage.h Mon Jun 14 04:11:01 2021 -0500
+++ b/libpurple/purplemessage.h Mon Jun 14 22:18:20 2021 -0500
@@ -200,6 +200,32 @@
const gchar *purple_message_get_author(PurpleMessage *message);
+ * purple_message_set_author_name_color: + * @message: The #PurpleMessage instance. + * @color: The hex color code for the author of @message. + * Sets the author's name color of @message to @color. This is the color that + * will be used to display the author's name in a user interface. The user + * interface might not use this exact color, as it might need to adapt for + * contrast or limits on the number of colors. +void purple_message_set_author_name_color(PurpleMessage *message, const gchar *color); + * purple_message_get_author_name_color: + * @message: The #PurpleMessage instance. + * Gets the author's name color for @message. + * Returns: (transfer none): The hex color for the author of @message's name. +const gchar *purple_message_get_author_name_color(PurpleMessage *message); * purple_message_set_recipient:
* @message: The #PurpleMessage instance.
* @recipient: The name of the recipient.
--- a/pidgin/gtkconv.c Mon Jun 14 04:11:01 2021 -0500
+++ b/pidgin/gtkconv.c Mon Jun 14 22:18:20 2021 -0500
@@ -52,6 +52,7 @@
#include "pidginavatar.h"
#include "pidginclosebutton.h"
+#include "pidgincolor.h" #include "pidginconversationwindow.h"
#include "pidgingdkpixbuf.h"
@@ -168,54 +169,6 @@
static gboolean pidgin_conv_xy_to_right_infopane(PidginConvWindow *win, int x, int y);
- * @name: The name or text to get a color for.
- * @color: (out): The return address for a #GdkRGBA that will recieve the
- * This function is based heavily on the implementation that gajim uses from
- * python-nbxmpp in nbxmpp.util.text_to_color. However, we don't have an
- * implementation of HSL let alone HSLuv, so we're using HSV which is why
- * the value is 1.0 instead of a luminance of 0.5.
- * Currently there is no caching as GCache is deprecated and writing a fast LRU
- * in glib is going to take a bit of finesse. Also we'll need to figure out how
- * to scale to ginormous Twitch channels which will constantly break the cache.
-get_nick_color(const gchar *name, GdkRGBA *color) {
- GChecksum *checksum = NULL;
- gsize digest_len = sizeof(digest);
- gdouble hue = 0, red = 0, green = 0, blue = 0;
- pidgin_style_context_get_background_color(&background);
- /* hash the string and get the first 2 bytes of the digest */
- checksum = g_checksum_new(G_CHECKSUM_SHA1);
- g_checksum_update(checksum, (const guchar *)name, -1);
- g_checksum_get_digest(checksum, digest, &digest_len);
- g_checksum_free(checksum);
- /* Calculate the hue based on the digest. We need a value between 0 and 1
- * so we divide the value by 65535 which is the maximum value for 2 bytes.
- hue = (digest[0] << 8 | digest[1]) / 65535.0;
- /* Get the rgb values for the hue at full saturation and value. */
- gtk_hsv_to_rgb(hue, 1.0, 1.0, &red, &green, &blue);
- /* Finally calculate the color summing 20% of the inverted background color
- * with 80% of the color.
- color->red = (0.2 * (1 - background.red)) + (0.8 * red);
- color->green = (0.2 * (1 - background.green)) + (0.8 * green);
- color->blue = (0.2 * (1 - background.blue)) + (0.8 * blue);
get_conversation_blist_node(PurpleConversation *conv)
@@ -2730,7 +2683,7 @@
alias_key = g_utf8_collate_key(tmp, -1);
- get_nick_color(name, &color);
+ pidgin_color_calculate_for_text(name, &color); gtk_list_store_insert_with_values(ls, &iter,
--- a/pidgin/meson.build Mon Jun 14 04:11:01 2021 -0500
+++ b/pidgin/meson.build Mon Jun 14 22:18:20 2021 -0500
@@ -38,6 +38,7 @@
'pidgincellrendererexpander.c',
'pidgincontactcompletion.c',
'pidginconversationwindow.c',
@@ -108,6 +109,7 @@
'pidgincellrendererexpander.h',
'pidgincontactcompletion.h',
'pidginconversationwindow.h',
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/pidgin/pidgincolor.c Mon Jun 14 22:18:20 2021 -0500
@@ -0,0 +1,63 @@
+ * Pidgin - Internet Messenger + * Copyright (C) Pidgin Developers <devel@pidgin.im> + * Pidgin is the legal property of its developers, whose names are too numerous + * to list here. Please refer to the COPYRIGHT file distributed with this + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * You should have received a copy of the GNU General Public License + * along with this library; if not, see <https://www.gnu.org/licenses/>. +#include "pidgincolor.h" +#include "pidginstylecontext.h" +/****************************************************************************** + *****************************************************************************/ +pidgin_color_calculate_for_text(const gchar *text, GdkRGBA *color) { + GChecksum *checksum = NULL; + gsize digest_len = sizeof(digest); + gdouble hue = 0, red = 0, green = 0, blue = 0; + g_return_if_fail(color != NULL); + pidgin_style_context_get_background_color(&background); + /* hash the string and get the first 2 bytes of the digest */ + checksum = g_checksum_new(G_CHECKSUM_SHA1); + g_checksum_update(checksum, (const guchar *)text, -1); + g_checksum_get_digest(checksum, digest, &digest_len); + g_checksum_free(checksum); + /* Calculate the hue based on the digest. We need a value between 0 and 1 + * so we divide the value by 65535 which is the maximum value for 2 bytes. + hue = (digest[0] << 8 | digest[1]) / 65535.0; + /* Get the rgb values for the hue at full saturation and value. */ + gtk_hsv_to_rgb(hue, 1.0, 1.0, &red, &green, &blue); + /* Finally calculate the color summing 20% of the inverted background color + * with 80% of the color. + color->red = (0.2 * (1 - background.red)) + (0.8 * red); + color->green = (0.2 * (1 - background.green)) + (0.8 * green); + color->blue = (0.2 * (1 - background.blue)) + (0.8 * blue); --- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/pidgin/pidgincolor.h Mon Jun 14 22:18:20 2021 -0500
@@ -0,0 +1,64 @@
+ * Pidgin - Internet Messenger + * Copyright (C) Pidgin Developers <devel@pidgin.im> + * Pidgin is the legal property of its developers, whose names are too numerous + * to list here. Please refer to the COPYRIGHT file distributed with this + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * You should have received a copy of the GNU General Public License + * along with this library; if not, see <https://www.gnu.org/licenses/>. +#if !defined(PIDGIN_GLOBAL_HEADER_INSIDE) && !defined(PIDGIN_COMPILATION) +# error "only <pidgin.h> may be included directly" + * @section_id: pidgin-color + * @short_description: Color related API + * A collection of API to help with color. + * pidgin_color_calculate_for_text: + * @text: The text to calculate a color for. + * @color: (out): The return address for a #GdkRGBA that will recieve the + * This function is based heavily on the implementation that gajim uses from + * python-nbxmpp in nbxmpp.util.text_to_color. However, we don't have an + * implementation of HSL let alone HSLuv, so we're using HSV which is why + * the value is 1.0 instead of a luminance of 0.5. + * Currently there is no caching as GCache is deprecated and writing a fast LRU + * in glib is going to take a bit of finesse. Also we'll need to figure out how + * to scale to ginormous Twitch channels which will constantly bust the cache. +void pidgin_color_calculate_for_text(const gchar *text, GdkRGBA *color); +#endif /* PIDGIN_COLOR_H */ --- a/pidgin/pidginmessage.c Mon Jun 14 04:11:01 2021 -0500
+++ b/pidgin/pidginmessage.c Mon Jun 14 22:18:20 2021 -0500
@@ -1,4 +1,6 @@
+ * Pidgin - Internet Messenger + * Copyright (C) Pidgin Developers <devel@pidgin.im> * Pidgin is the legal property of its developers, whose names are too numerous
* to list here. Please refer to the COPYRIGHT file distributed with this
@@ -15,13 +17,13 @@
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
+ * along with this program; if not, see <https://www.gnu.org/licenses/>. #include "pidginmessage.h"
#include "pidginattachment.h"
+#include "pidgincolor.h" @@ -42,6 +44,7 @@
+ PROP_AUTHOR_NAME_COLOR, @@ -58,6 +61,32 @@
+pidgin_message_parse_author_name_color(PidginMessage *message) { + const gchar *color = NULL; + ret = g_new0(GdkRGBA, 1); + color = purple_message_get_author_name_color(message->message); + if(color != NULL && gdk_rgba_parse(ret, color)) { + const gchar *author = purple_message_get_author_alias(message->message); + author = purple_message_get_author(message->message); + pidgin_color_calculate_for_text(author, ret); /******************************************************************************
* TalkatuMessage Implementation
*****************************************************************************/
@@ -168,11 +197,14 @@
- G_IMPLEMENT_INTERFACE(TALKATU_TYPE_MESSAGE, pidgin_message_talkatu_message_init)
+ G_IMPLEMENT_INTERFACE(TALKATU_TYPE_MESSAGE, + pidgin_message_talkatu_message_init) -pidgin_message_get_property(GObject *obj, guint param_id, GValue *value, GParamSpec *pspec) {
+pidgin_message_get_property(GObject *obj, guint param_id, GValue *value, PidginMessage *message = PIDGIN_MESSAGE(obj);
@@ -186,13 +218,20 @@
g_value_set_enum(value, TALKATU_CONTENT_TYPE_PLAIN);
- g_value_set_string(value, purple_message_get_author(message->message));
+ g_value_set_string(value, + purple_message_get_author(message->message)); + case PROP_AUTHOR_NAME_COLOR: + g_value_take_boxed(value, + pidgin_message_parse_author_name_color(message)); - g_value_set_string(value, purple_message_get_contents(message->message));
+ g_value_set_string(value, + purple_message_get_contents(message->message)); - g_value_set_boxed(value, purple_message_get_timestamp(message->message));
+ g_value_set_boxed(value, + purple_message_get_timestamp(message->message)); g_value_set_boolean(value, FALSE);
@@ -204,7 +243,9 @@
-pidgin_message_set_property(GObject *obj, guint param_id, const GValue *value, GParamSpec *pspec) {
+pidgin_message_set_property(GObject *obj, guint param_id, const GValue *value, PidginMessage *message = PIDGIN_MESSAGE(obj);
@@ -215,6 +256,7 @@
+ case PROP_AUTHOR_NAME_COLOR: /* we don't allow settings these */
@@ -258,8 +300,11 @@
/* add our overridden properties */
g_object_class_override_property(obj_class, PROP_ID, "id");
g_object_class_override_property(obj_class, PROP_TIMESTAMP, "timestamp");
- g_object_class_override_property(obj_class, PROP_CONTENT_TYPE, "content-type");
+ g_object_class_override_property(obj_class, PROP_CONTENT_TYPE, g_object_class_override_property(obj_class, PROP_AUTHOR, "author");
+ g_object_class_override_property(obj_class, PROP_AUTHOR_NAME_COLOR, g_object_class_override_property(obj_class, PROP_CONTENTS, "contents");
g_object_class_override_property(obj_class, PROP_EDITED, "edited");
--- a/pidgin/pidginmessage.h Mon Jun 14 04:11:01 2021 -0500
+++ b/pidgin/pidginmessage.h Mon Jun 14 22:18:20 2021 -0500
@@ -1,5 +1,6 @@
+ * Pidgin - Internet Messenger + * Copyright (C) Pidgin Developers <devel@pidgin.im> * Pidgin is the legal property of its developers, whose names are too numerous
* to list here. Please refer to the COPYRIGHT file distributed with this
@@ -31,6 +32,8 @@
* @section_id: pidgin-pidginmessage
* @short_description: <filename>pidginmessage.h</filename>
* @title: Pidgin Message API
+ * #PidginMessage maps a #PurpleMessage to a #TalkatuMessage. --- a/po/POTFILES.in Mon Jun 14 04:11:01 2021 -0500
+++ b/po/POTFILES.in Mon Jun 14 22:18:20 2021 -0500
@@ -349,6 +349,7 @@
pidgin/pidgincellrendererexpander.c
pidgin/pidginclosebutton.c
pidgin/pidgincontactcompletion.c
pidgin/pidgincontactlist.c