pidgin/pidgin

Parents c3fc77a3c015
Children 53fa03701534
Add support for the author-name-color property to PidginMessage and wire it up in PurpleMessage as well

Testing Done:
Joined a chat and verified names were colored properly as well as in im's.

Reviewed at https://reviews.imfreedom.org/r/744/
--- 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 @@
guint id;
gchar *author;
+ gchar *author_name_color;
gchar *author_alias;
gchar *recipient;
@@ -56,6 +57,7 @@
PROP_ID,
PROP_AUTHOR,
PROP_AUTHOR_ALIAS,
+ PROP_AUTHOR_NAME_COLOR,
PROP_RECIPIENT,
PROP_CONTENTS,
PROP_CONTENT_TYPE,
@@ -198,6 +200,8 @@
* PurpleMessage::id:
*
* The account specific identifier of the message.
+ *
+ * Since: 3.0.0
*/
properties[PROP_ID] = g_param_spec_uint(
"id", "ID",
@@ -209,6 +213,8 @@
* PurpleMessage::author:
*
* The author of the message.
+ *
+ * Since: 3.0.0
*/
properties[PROP_AUTHOR] = g_param_spec_string(
"author", "Author",
@@ -217,9 +223,24 @@
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
/**
+ * PurpleMessage::author-name-color:
+ *
+ * The hex color for the author's name.
+ *
+ * Since: 3.0.0
+ */
+ 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",
+ NULL,
+ G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
+
+ /**
* PurpleMessage::author-alias:
*
* The alias of the author.
+ *
+ * Since: 3.0.0
*/
properties[PROP_AUTHOR_ALIAS] = g_param_spec_string(
"author-alias", "Author's alias",
@@ -231,6 +252,8 @@
* PurpleMessage::recipient:
*
* The recipient of the message.
+ *
+ * Since: 3.0.0
*/
properties[PROP_RECIPIENT] = g_param_spec_string(
"recipient", "Recipient",
@@ -242,6 +265,8 @@
* PurpleMessage::content:
*
* The contents of the message.
+ *
+ * Since: 3.0.0
*/
properties[PROP_CONTENTS] = g_param_spec_string(
"contents", "Contents",
@@ -253,6 +278,8 @@
* PurpleMessage::content-type:
*
* The content-type of the message.
+ *
+ * Since: 3.0.0
*/
properties[PROP_CONTENT_TYPE] = g_param_spec_enum(
"content-type", "content-type",
@@ -264,6 +291,8 @@
* PurpleMessage::timestamp:
*
* The timestamp of the message.
+ *
+ * Since: 3.0.0
*/
properties[PROP_TIMESTAMP] = g_param_spec_boxed(
"timestamp", "timestamp",
@@ -275,6 +304,8 @@
* PurpleMessage::flags:
*
* The #PurpleMessageFlags for the message.
+ *
+ * Since: 3.0.0
*/
properties[PROP_FLAGS] = g_param_spec_flags(
"flags", "Flags",
@@ -383,6 +414,26 @@
}
void
+purple_message_set_author_name_color(PurpleMessage *message,
+ const gchar *color)
+{
+ 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]);
+}
+
+const gchar *
+purple_message_get_author_name_color(PurpleMessage *message) {
+ g_return_val_if_fail(PURPLE_IS_MESSAGE(message), NULL);
+
+ return message->author_name_color;
+}
+
+void
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.
+ *
+ * Since: 3.0.0
+ */
+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.
+ *
+ * Since: 3.0.0
+ */
+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 "gtkutils.h"
#include "pidginavatar.h"
#include "pidginclosebutton.h"
+#include "pidgincolor.h"
#include "pidginconversationwindow.h"
#include "pidgincore.h"
#include "pidgingdkpixbuf.h"
@@ -168,54 +169,6 @@
int width, int height);
static gboolean pidgin_conv_xy_to_right_infopane(PidginConvWindow *win, int x, int y);
-/*<private>
- * get_nick_color:
- * @name: The name or text to get a color for.
- * @color: (out): The return address for a #GdkRGBA that will recieve the
- * color.
- *
- * 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.
- */
-static void
-get_nick_color(const gchar *name, GdkRGBA *color) {
- GdkRGBA background;
- GChecksum *checksum = NULL;
- guchar digest[20];
- 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);
- color->alpha = 1.0;
-}
-
static PurpleBlistNode *
get_conversation_blist_node(PurpleConversation *conv)
{
@@ -2730,7 +2683,7 @@
alias_key = g_utf8_collate_key(tmp, -1);
g_free(tmp);
- 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 @@
'pidginavatar.c',
'pidgincellrendererexpander.c',
'pidginclosebutton.c',
+ 'pidgincolor.c',
'pidgincommands.c',
'pidgincontactcompletion.c',
'pidginconversationwindow.c',
@@ -108,6 +109,7 @@
'pidginavatar.h',
'pidgincellrendererexpander.h',
'pidginclosebutton.h',
+ 'pidgincolor.h',
'pidgincontactcompletion.h',
'pidginconversationwindow.h',
'pidgincontactlist.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
+ * source distribution.
+ *
+ * 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"
+
+/******************************************************************************
+ * Public API
+ *****************************************************************************/
+void
+pidgin_color_calculate_for_text(const gchar *text, GdkRGBA *color) {
+ GdkRGBA background;
+ GChecksum *checksum = NULL;
+ guchar digest[20];
+ 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);
+ color->alpha = 1.0;
+}
--- /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
+ * source distribution.
+ *
+ * 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"
+#endif
+
+/**
+ * SECTION:pidgincolor
+ * @section_id: pidgin-color
+ * @short_description: Color related API
+ * @title: Color API
+ *
+ * A collection of API to help with color.
+ */
+
+#ifndef PIDGIN_COLOR_H
+#define PIDGIN_COLOR_H
+
+#include <gtk/gtk.h>
+
+G_BEGIN_DECLS
+
+/**
+ * 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
+ * color.
+ *
+ * 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.
+ *
+ * Since: 3.0.0
+ */
+void pidgin_color_calculate_for_text(const gchar *text, GdkRGBA *color);
+
+G_END_DECLS
+
+#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
+/*
+ * 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"
struct _PidginMessage {
GObject parent;
@@ -42,6 +44,7 @@
PROP_ID = N_PROPERTIES,
PROP_CONTENT_TYPE,
PROP_AUTHOR,
+ PROP_AUTHOR_NAME_COLOR,
PROP_CONTENTS,
PROP_TIMESTAMP,
PROP_EDITED,
@@ -58,6 +61,32 @@
}
}
+static GdkRGBA *
+pidgin_message_parse_author_name_color(PidginMessage *message) {
+ GdkRGBA *ret = NULL;
+ const gchar *color = NULL;
+ gboolean set = FALSE;
+
+ ret = g_new0(GdkRGBA, 1);
+
+ color = purple_message_get_author_name_color(message->message);
+ if(color != NULL && gdk_rgba_parse(ret, color)) {
+ set = TRUE;
+ }
+
+ if(!set) {
+ const gchar *author = purple_message_get_author_alias(message->message);
+
+ if(author == NULL) {
+ author = purple_message_get_author(message->message);
+ }
+
+ pidgin_color_calculate_for_text(author, ret);
+ }
+
+ return ret;
+}
+
/******************************************************************************
* TalkatuMessage Implementation
*****************************************************************************/
@@ -168,11 +197,14 @@
pidgin_message,
G_TYPE_OBJECT,
0,
- G_IMPLEMENT_INTERFACE(TALKATU_TYPE_MESSAGE, pidgin_message_talkatu_message_init)
+ G_IMPLEMENT_INTERFACE(TALKATU_TYPE_MESSAGE,
+ pidgin_message_talkatu_message_init)
);
static void
-pidgin_message_get_property(GObject *obj, guint param_id, GValue *value, GParamSpec *pspec) {
+pidgin_message_get_property(GObject *obj, guint param_id, GValue *value,
+ GParamSpec *pspec)
+{
PidginMessage *message = PIDGIN_MESSAGE(obj);
switch(param_id) {
@@ -186,13 +218,20 @@
g_value_set_enum(value, TALKATU_CONTENT_TYPE_PLAIN);
break;
case PROP_AUTHOR:
- g_value_set_string(value, purple_message_get_author(message->message));
+ g_value_set_string(value,
+ purple_message_get_author(message->message));
+ break;
+ case PROP_AUTHOR_NAME_COLOR:
+ g_value_take_boxed(value,
+ pidgin_message_parse_author_name_color(message));
break;
case PROP_CONTENTS:
- g_value_set_string(value, purple_message_get_contents(message->message));
+ g_value_set_string(value,
+ purple_message_get_contents(message->message));
break;
case PROP_TIMESTAMP:
- g_value_set_boxed(value, purple_message_get_timestamp(message->message));
+ g_value_set_boxed(value,
+ purple_message_get_timestamp(message->message));
break;
case PROP_EDITED:
g_value_set_boolean(value, FALSE);
@@ -204,7 +243,9 @@
}
static void
-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,
+ GParamSpec *pspec)
+{
PidginMessage *message = PIDGIN_MESSAGE(obj);
switch(param_id) {
@@ -215,6 +256,7 @@
case PROP_CONTENT_TYPE:
case PROP_TIMESTAMP:
case PROP_AUTHOR:
+ case PROP_AUTHOR_NAME_COLOR:
case PROP_CONTENTS:
case PROP_EDITED:
/* 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,
+ "content-type");
g_object_class_override_property(obj_class, PROP_AUTHOR, "author");
+ g_object_class_override_property(obj_class, PROP_AUTHOR_NAME_COLOR,
+ "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
+ * 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.
*/
#include <purple.h>
--- 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/pidgin.c
pidgin/pidgincellrendererexpander.c
pidgin/pidginclosebutton.c
+pidgin/pidgincolor.c
pidgin/pidgincommands.c
pidgin/pidgincontactcompletion.c
pidgin/pidgincontactlist.c