diff -r 60647bc63acc -r 8019461267d9 pidgin/gtkconv.c
--- a/pidgin/gtkconv.c Sat Sep 15 03:17:46 2012 -0400
+++ b/pidgin/gtkconv.c Sat Sep 15 03:46:04 2012 -0400
@@ -150,9 +150,8 @@
#define MIN_BRIGHTNESS_CONTRAST 75
#define MIN_COLOR_CONTRAST 200
-#define NUM_NICK_COLORS 220
-static GdkColor *nick_colors = NULL;
-static guint nbr_nick_colors;
+#define NICK_COLOR_GENERATE_COUNT 220
+static GArray *generated_nick_colors = NULL;
/* These probably won't conflict with any WebKit values. */
#define PIDGIN_DRAG_BLIST_NODE (1337)
@@ -208,7 +207,7 @@
static void update_typing_icon(PidginConversation *gtkconv);
static void update_typing_message(PidginConversation *gtkconv, const char *message);
gboolean pidgin_conv_has_focus(PurpleConversation *conv);
-static GdkColor* generate_nick_colors(guint *numcolors, GdkColor background);
+static GArray* generate_nick_colors(guint numcolors, GdkColor background);
static gboolean color_is_visible(GdkColor foreground, GdkColor background, int color_contrast, int brightness_contrast);
static GtkTextTag *get_buddy_tag(PurpleConversation *conv, const char *who, PurpleMessageFlags flag, gboolean create);
static void pidgin_conv_update_fields(PurpleConversation *conv, PidginConvFields fields);
@@ -227,7 +226,7 @@
GtkStyle *style = gtk_widget_get_style(gtkconv->webview);
float scale;
- col = nick_colors[g_str_hash(name) % nbr_nick_colors];
+ 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)));
@@ -5790,6 +5789,7 @@
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) {
@@ -5887,9 +5887,13 @@
else
pidgin_conv_placement_place(gtkconv);
- if (nick_colors == NULL) {
- nbr_nick_colors = NUM_NICK_COLORS;
- nick_colors = generate_nick_colors(&nbr_nick_colors, 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)
@@ -6005,6 +6009,8 @@
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);
@@ -6315,6 +6321,10 @@
} else if (g_str_has_prefix(cur, "%sender%")) {
replace = alias;
+ } else if (g_str_has_prefix(cur, "%senderColor%")) {
+ const GdkColor *color = get_nick_color(PIDGIN_CONVERSATION(conv), name);
+ replace = freeval = g_strdup_printf("#%02x%02x%02x", (color->red >> 8), (color->green >> 8), (color->blue >> 8));
+
} else if (g_str_has_prefix(cur, "%service%")) {
replace = purple_account_get_protocol_name(purple_conversation_get_account(conv));
@@ -7404,15 +7414,28 @@
const char *topic = gtkconv->u.chat->topic_text
? gtk_entry_get_text(GTK_ENTRY(gtkconv->u.chat->topic_text))
: NULL;
- char *esc = NULL, *tmp;
- esc = topic ? g_markup_escape_text(topic, -1) : NULL;
- tmp = g_markup_escape_text(purple_conversation_get_title(conv), -1);
- markup = g_strdup_printf("%s%s%s",
- tmp, esc && *esc ? "\n" : "",
+ const char *title = purple_conversation_get_title(conv);
+ const char *name = purple_conversation_get_name(conv);
+
+ char *topic_esc, *unaliased, *unaliased_esc, *title_esc;
+
+ topic_esc = topic ? g_markup_escape_text(topic, -1) : NULL;
+ unaliased = g_utf8_collate(title, name) ? g_strdup_printf("(%s)", name) : NULL;
+ unaliased_esc = unaliased ? g_markup_escape_text(unaliased, -1) : NULL;
+ title_esc = g_markup_escape_text(title, -1);
+
+ markup = g_strdup_printf("%s%s%s%s%s",
+ title_esc,
+ unaliased_esc ? " " : "",
+ unaliased_esc ? unaliased_esc : "",
+ topic_esc && *topic_esc ? "\n" : "",
pidgin_get_dim_grey_string(gtkconv->infopane),
- esc ? esc : "");
- g_free(tmp);
- g_free(esc);
+ topic_esc ? topic_esc : "");
+
+ g_free(title_esc);
+ g_free(topic_esc);
+ g_free(unaliased);
+ g_free(unaliased_esc);
}
gtk_list_store_set(gtkconv->infopane_model, &(gtkconv->infopane_iter),
CONV_TEXT_COLUMN, markup, -1);
@@ -10093,12 +10116,12 @@
void
pidgin_conv_window_destroy(PidginWindow *win)
{
- PidginConversation *gtkconv;
- GList *iter;
-
if (win->gtkconvs) {
- for (iter = win->gtkconvs; iter != NULL; iter = iter->next) {
- gtkconv = iter->data;
+ GList *iter = win->gtkconvs;
+ while (iter)
+ {
+ PidginConversation *gtkconv = iter->data;
+ iter = iter->next;
close_conv_cb(NULL, gtkconv);
}
return;
@@ -10938,12 +10961,11 @@
}
-static GdkColor*
-generate_nick_colors(guint *color_count, GdkColor background)
-{
- guint numcolors = *color_count;
+static GArray*
+generate_nick_colors(guint numcolors, GdkColor background)
+{
guint i = 0, j = 0;
- GdkColor *colors = g_new(GdkColor, numcolors);
+ GArray *colors = g_array_new(FALSE, FALSE, sizeof(GdkColor));
GdkColor nick_highlight;
GdkColor send_color;
time_t breakout_time;
@@ -10967,7 +10989,7 @@
color_is_visible(color, nick_highlight, MIN_COLOR_CONTRAST / 2, 0) &&
color_is_visible(color, send_color, MIN_COLOR_CONTRAST / 4, 0))
{
- colors[i] = color;
+ g_array_append_val(colors, color);
i++;
}
j++;
@@ -10986,17 +11008,13 @@
color_is_visible(color, nick_highlight, MIN_COLOR_CONTRAST / 2, 0) &&
color_is_visible(color, send_color, MIN_COLOR_CONTRAST / 4, 0))
{
- colors[i] = color;
+ g_array_append_val(colors, color);
i++;
}
}
if (i < numcolors) {
- GdkColor *c = colors;
purple_debug_warning("gtkconv", "Unable to generate enough random colors before timeout. %u colors found.\n", i);
- colors = g_memdup(c, i * sizeof(GdkColor));
- g_free(c);
- *color_count = i;
}
return colors;