/pidgin/main: 215f0b668ac6: now loads the SenderColors.txt file ...
Nathan Walp
nwalp at pidgin.im
Mon Sep 10 16:37:23 EDT 2012
Changeset: 215f0b668ac699173a293af57192b58f362c2af5
Author: Nathan Walp <nwalp at pidgin.im>
Date: 2012-09-10 16:30 -0400
Branch: default
URL: http://hg.pidgin.im/pidgin/main/rev/215f0b668ac6
Description:
now loads the SenderColors.txt file from the theme if it exists, otherwise falls back to the built-in runtime-generated list
diffstat:
pidgin/gtkconv-theme.c | 45 +++++++++++++++++++++++++++++++++++++++++++++
pidgin/gtkconv-theme.h | 9 +++++++++
pidgin/gtkconv.c | 16 ++++++++++++----
pidgin/gtkconv.h | 1 +
4 files changed, 67 insertions(+), 4 deletions(-)
diffs (150 lines):
diff --git a/pidgin/gtkconv-theme.c b/pidgin/gtkconv-theme.c
--- a/pidgin/gtkconv-theme.c
+++ b/pidgin/gtkconv-theme.c
@@ -66,6 +66,8 @@ typedef struct {
char *incoming_next_context_html;
char *outgoing_next_context_html;
char *basestyle_css;
+
+ GArray *nick_colors;
} PidginConvThemePrivate;
/******************************************************************************
@@ -498,6 +500,8 @@ pidgin_conv_theme_finalize(GObject *obj)
}
g_free(priv->variant);
+ g_array_unref(priv->nick_colors);
+
parent_class->finalize(obj);
}
@@ -749,3 +753,44 @@ pidgin_conversation_theme_get_css_path(P
}
}
+GArray *
+pidgin_conversation_theme_get_nick_colors(PidginConvTheme *theme)
+{
+ PidginConvThemePrivate *priv;
+ const char *dir;
+
+ g_return_val_if_fail(theme != NULL, NULL);
+
+ priv = PIDGIN_CONV_THEME_GET_PRIVATE(theme);
+
+ dir = purple_theme_get_dir(PURPLE_THEME(theme));
+ if (NULL == priv->nick_colors)
+ {
+ char *file = g_build_filename(dir, "Contents", "Resources", "Incoming", "SenderColors.txt", NULL);
+ char *contents;
+ priv->nick_colors = g_array_new(FALSE, FALSE, sizeof(GdkColor));
+ if (g_file_get_contents(file, &contents, NULL, NULL)) {
+ int i;
+ gchar ** color_strings = g_strsplit_set(contents, "\r\n:", -1);
+
+ for(i=0; color_strings[i]; i++)
+ {
+ GdkColor color;
+ if(gdk_color_parse(color_strings[i], &color))
+ {
+ g_array_append_val(priv->nick_colors, color);
+ }
+ }
+
+ g_strfreev(color_strings);
+ g_free(contents);
+ }
+ g_free(file);
+ }
+
+ if(priv->nick_colors->len)
+ return g_array_ref(priv->nick_colors);
+ else
+ return NULL;
+}
+
diff --git a/pidgin/gtkconv-theme.h b/pidgin/gtkconv-theme.h
--- a/pidgin/gtkconv-theme.h
+++ b/pidgin/gtkconv-theme.h
@@ -191,6 +191,15 @@ char *pidgin_conversation_theme_get_temp
*/
char *pidgin_conversation_theme_get_css_path(PidginConvTheme *theme);
+/**
+ * Get (and reference) the array of nick colors
+ *
+ * @param theme The conversation theme
+ *
+ * @return Pointer to GArray of nick colors, or NULL if no colors in theme
+ */
+GArray *pidgin_conversation_theme_get_nick_colors(PidginConvTheme *theme);
+
G_END_DECLS
#endif /* PIDGIN_CONV_THEME_H */
diff --git a/pidgin/gtkconv.c b/pidgin/gtkconv.c
--- a/pidgin/gtkconv.c
+++ b/pidgin/gtkconv.c
@@ -151,7 +151,7 @@ enum {
#define MIN_COLOR_CONTRAST 200
#define NICK_COLOR_GENERATE_COUNT 220
-static GArray *nick_colors = NULL;
+static GArray *generated_nick_colors = NULL;
/* These probably won't conflict with any WebKit values. */
#define PIDGIN_DRAG_BLIST_NODE (1337)
@@ -226,7 +226,7 @@ static const GdkColor *get_nick_color(Pi
GtkStyle *style = gtk_widget_get_style(gtkconv->webview);
float scale;
- col = g_array_index(nick_colors, GdkColor, g_str_hash(name) % nick_colors->len);
+ col = g_array_index(gtkconv->nick_colors, GdkColor, g_str_hash(name) % gtkconv->nick_colors->len);
scale = ((1-(LUMINANCE(style->base[GTK_STATE_NORMAL]) / LUMINANCE(style->white))) *
(LUMINANCE(style->white)/MAX(MAX(col.red, col.blue), col.green)));
@@ -5787,6 +5787,7 @@ private_gtkconv_new(PurpleConversation *
gtkconv->theme = PIDGIN_CONV_THEME(g_object_ref(theme));
gtkconv->last_flags = 0;
+
if (conv_type == PURPLE_CONV_TYPE_IM) {
gtkconv->u.im = g_malloc0(sizeof(PidginImPane));
} else if (conv_type == PURPLE_CONV_TYPE_CHAT) {
@@ -5884,8 +5885,13 @@ private_gtkconv_new(PurpleConversation *
else
pidgin_conv_placement_place(gtkconv);
- if (nick_colors == NULL) {
- nick_colors = generate_nick_colors(NICK_COLOR_GENERATE_COUNT, gtk_widget_get_style(gtkconv->webview)->base[GTK_STATE_NORMAL]);
+ if (generated_nick_colors == NULL) {
+ generated_nick_colors = generate_nick_colors(NICK_COLOR_GENERATE_COUNT, gtk_widget_get_style(gtkconv->webview)->base[GTK_STATE_NORMAL]);
+ }
+
+ if(NULL == (gtkconv->nick_colors = pidgin_conversation_theme_get_nick_colors(gtkconv->theme)))
+ {
+ gtkconv->nick_colors = g_array_ref(generated_nick_colors);
}
if (purple_conversation_get_features(conv) & PURPLE_CONNECTION_ALLOW_CUSTOM_SMILEY)
@@ -6001,6 +6007,8 @@ pidgin_conv_destroy(PurpleConversation *
g_source_remove(gtkconv->attach.timer);
}
+ g_array_unref(gtkconv->nick_colors);
+
g_object_disconnect(G_OBJECT(gtkconv->theme), "any_signal::notify",
conv_variant_changed_cb, gtkconv, NULL);
g_object_unref(gtkconv->theme);
diff --git a/pidgin/gtkconv.h b/pidgin/gtkconv.h
--- a/pidgin/gtkconv.h
+++ b/pidgin/gtkconv.h
@@ -101,6 +101,7 @@ struct _PidginConversation
GtkWidget *menu_tabby;
PidginConvTheme *theme;
+ GArray *nick_colors;
PurpleMessageFlags last_flags;
GtkWidget *webview;
GtkWidget *entry;
More information about the Commits
mailing list