im.pidgin.pidgin: 01e2986fe6e826268c0b6533d70889232bf86dea

wabz at pidgin.im wabz at pidgin.im
Thu Nov 29 22:20:45 EST 2007


-----------------------------------------------------------------
Revision: 01e2986fe6e826268c0b6533d70889232bf86dea
Ancestor: 290bf55eb4f0f08c0d1ccfafb202ebc2d44cf565
Author: wabz at pidgin.im
Date: 2007-11-30T03:17:07
Branch: im.pidgin.pidgin

Modified files:
        doc/finch.1.in finch/gntblist.c finch/libgnt/gntcolors.c
        finch/libgnt/gntcolors.h finch/libgnt/gntstyle.c
        finch/libgnt/gntstyle.h finch/libgnt/gnttree.c
        finch/libgnt/gnttree.h

ChangeLog: 

Add support for colour in gnttreerows, and colourise the blist. Fixes #1490

-------------- next part --------------
============================================================
--- doc/finch.1.in	98618babb3e4d970895e70b45bd1c162a07b808b
+++ doc/finch.1.in	33fa40a729dd634ed7c147b8bdc82b1c04de9175
@@ -135,6 +135,18 @@ A sample file looks like:
 .TP
 A sample file looks like:
 .br
+[Finch]
+.br
+online-color: green; black
+.br
+away-color: blue; black
+.br
+idle-color: gray; black
+.br
+offline-color: red; black
+.br
+#See below for details on color
+.br
 [general]
 .br
 shadow = 0
============================================================
--- finch/gntblist.c	3842be2433fb0f8c62af0b6cba2b3bf349509a9d
+++ finch/gntblist.c	7bf883ace177505998b169a9181edfe7de0b757b
@@ -27,6 +27,7 @@
 
 #include <account.h>
 #include <blist.h>
+#include <curses.h>
 #include <notify.h>
 #include <request.h>
 #include <savedstatuses.h>
@@ -37,6 +38,7 @@
 #include "debug.h"
 
 #include "gntbox.h"
+#include "gntcolors.h"
 #include "gntcombobox.h"
 #include "gntentry.h"
 #include "gntft.h"
@@ -46,6 +48,7 @@
 #include "gntmenuitem.h"
 #include "gntmenuitemcheck.h"
 #include "gntpounce.h"
+#include "gntstyle.h"
 #include "gnttree.h"
 #include "gntutils.h"
 #include "gntwindow.h"
@@ -124,6 +127,11 @@ static int blist_node_compare_log(Purple
 static int blist_node_compare_status(PurpleBlistNode *n1, PurpleBlistNode *n2);
 static int blist_node_compare_log(PurpleBlistNode *n1, PurpleBlistNode *n2);
 
+static int color_available;
+static int color_away;
+static int color_offline;
+static int color_idle;
+
 static gboolean
 is_contact_online(PurpleContact *contact)
 {
@@ -615,12 +623,20 @@ add_buddy(PurpleBuddy *buddy, FinchBlist
 	node->ui_data = gnt_tree_add_row_after(GNT_TREE(ggblist->tree), buddy,
 				gnt_tree_create_row(GNT_TREE(ggblist->tree), get_display_name(node)),
 				contact, NULL);
+
 	if (purple_presence_is_idle(purple_buddy_get_presence(buddy))) {
-		gnt_tree_set_row_flags(GNT_TREE(ggblist->tree), buddy, GNT_TEXT_FLAG_DIM);
-		gnt_tree_set_row_flags(GNT_TREE(ggblist->tree), contact, GNT_TEXT_FLAG_DIM);
-	} else {
-		gnt_tree_set_row_flags(GNT_TREE(ggblist->tree), buddy, 0);
-		gnt_tree_set_row_flags(GNT_TREE(ggblist->tree), contact, 0);
+		gnt_tree_set_row_color(GNT_TREE(ggblist->tree), buddy, color_idle);
+		gnt_tree_set_row_color(GNT_TREE(ggblist->tree), contact, color_idle);
+	} else if (purple_presence_is_available(purple_buddy_get_presence(buddy)) && color_available) {
+		gnt_tree_set_row_color(GNT_TREE(ggblist->tree), buddy, color_available);
+		gnt_tree_set_row_color(GNT_TREE(ggblist->tree), contact, color_available);
+	} else if (purple_presence_is_online(purple_buddy_get_presence(buddy)) &&
+			!purple_presence_is_available(purple_buddy_get_presence(buddy)) && color_away) {
+		gnt_tree_set_row_color(GNT_TREE(ggblist->tree), buddy, color_away);
+		gnt_tree_set_row_color(GNT_TREE(ggblist->tree), contact, color_away);
+	} else if (!purple_presence_is_online(purple_buddy_get_presence(buddy)) && color_offline) {
+		gnt_tree_set_row_color(GNT_TREE(ggblist->tree), buddy, color_offline);
+		gnt_tree_set_row_color(GNT_TREE(ggblist->tree), contact, color_offline);
 	}
 }
 
@@ -1557,18 +1573,33 @@ update_buddy_display(PurpleBuddy *buddy,
 		draw_tooltip(ggblist);
 
 	if (purple_presence_is_idle(purple_buddy_get_presence(buddy))) {
-		gnt_tree_set_row_flags(GNT_TREE(ggblist->tree), buddy, bflag | GNT_TEXT_FLAG_DIM);
+		gnt_tree_set_row_color(GNT_TREE(ggblist->tree), buddy, color_idle);
+		gnt_tree_set_row_color(GNT_TREE(ggblist->tree), contact, color_idle);
 		if (buddy == purple_contact_get_priority_buddy(contact))
-			gnt_tree_set_row_flags(GNT_TREE(ggblist->tree), contact, cflag | GNT_TEXT_FLAG_DIM);
-		else
-			update_buddy_display(purple_contact_get_priority_buddy(contact), ggblist);
-	} else {
-		gnt_tree_set_row_flags(GNT_TREE(ggblist->tree), buddy, bflag);
+			gnt_tree_set_row_color(GNT_TREE(ggblist->tree), contact, color_idle);
+	} else if (purple_presence_is_available(purple_buddy_get_presence(buddy)) && color_available) {
+		gnt_tree_set_row_color(GNT_TREE(ggblist->tree), buddy, color_available);
+		gnt_tree_set_row_color(GNT_TREE(ggblist->tree), contact, color_available);
 		if (buddy == purple_contact_get_priority_buddy(contact))
-			gnt_tree_set_row_flags(GNT_TREE(ggblist->tree), contact, cflag);
-		else
+			gnt_tree_set_row_color(GNT_TREE(ggblist->tree), contact, color_available);
+	} else if (purple_presence_is_online(purple_buddy_get_presence(buddy)) &&
+			!purple_presence_is_available(purple_buddy_get_presence(buddy)) && color_away) {
+		gnt_tree_set_row_color(GNT_TREE(ggblist->tree), buddy, color_away);
+		gnt_tree_set_row_color(GNT_TREE(ggblist->tree), contact, color_away);
+		if (buddy == purple_contact_get_priority_buddy(contact))
+			gnt_tree_set_row_color(GNT_TREE(ggblist->tree), contact, color_away);
+	} else if (!purple_presence_is_online(purple_buddy_get_presence(buddy)) && color_offline) {
+		gnt_tree_set_row_color(GNT_TREE(ggblist->tree), buddy, color_offline);
+		gnt_tree_set_row_color(GNT_TREE(ggblist->tree), contact, color_offline);
+		if (buddy == purple_contact_get_priority_buddy(contact))
+			gnt_tree_set_row_color(GNT_TREE(ggblist->tree), contact, color_offline);
+	}
+	gnt_tree_set_row_flags(GNT_TREE(ggblist->tree), buddy, bflag);
+	if (buddy == purple_contact_get_priority_buddy(contact))
+		gnt_tree_set_row_flags(GNT_TREE(ggblist->tree), contact, cflag);
+
+	if (buddy != purple_contact_get_priority_buddy(contact))
 			update_buddy_display(purple_contact_get_priority_buddy(contact), ggblist);
-	}
 }
 
 static void
@@ -1736,8 +1767,43 @@ redraw_blist(const char *name, PurplePre
 	draw_tooltip(ggblist);
 }
 
+static int
+get_color(char *key)
+{
+#if GLIB_CHECK_VERSION(2,6,0)
+	int fg = 0, bg = 0;
+	gsize n;
+	char **vals;
+	vals = gnt_style_get_string_list(NULL, key, &n);
+	if (vals && n == 2) {
+		fg = gnt_colors_get_color(vals[0]);
+		bg = gnt_colors_get_color(vals[1]);
+		return gnt_color_add_pair(fg, bg);
+	}
+	return 0;
+#else
+	return 0;
+#endif
+}
+
 void finch_blist_init()
 {
+	short fg, bg;
+	if (has_colors()) {
+		pair_content(GNT_COLOR_NORMAL, &fg, &bg);
+		color_available = get_color("color-available");
+		if (!color_available)
+			color_available = gnt_color_add_pair(COLOR_GREEN, bg);
+		color_away = get_color("color-away");
+		if (!color_away)
+			color_away = gnt_color_add_pair(COLOR_BLUE, bg);
+		color_idle = get_color("color-idle");
+		if (!color_idle)
+			color_idle = gnt_color_add_pair(COLOR_CYAN, bg);
+		color_offline = get_color("color-offline");
+		if (!color_offline)
+			color_offline = gnt_color_add_pair(COLOR_RED, bg);
+	}
 	purple_prefs_add_none(PREF_ROOT);
 	purple_prefs_add_none(PREF_ROOT "/size");
 	purple_prefs_add_int(PREF_ROOT "/size/width", 20);
@@ -2550,4 +2616,3 @@ void finch_blist_set_size(int width, int
 {
 	gnt_widget_set_size(ggblist->window, width, height);
 }
-
============================================================
--- finch/libgnt/gntcolors.c	aa0b5937604bbcfcfd9460f69438dda542a77040
+++ finch/libgnt/gntcolors.c	4a67c539e7fbdec118d41961202a6958250d48dc
@@ -33,6 +33,7 @@ static gboolean hascolors;
 #include <string.h>
 
 static gboolean hascolors;
+static int custom_type = GNT_COLORS;
 static struct
 {
 	short r, g, b;
@@ -137,8 +138,8 @@ gnt_uninit_colors()
 }
 
 #if GLIB_CHECK_VERSION(2,6,0)
-static int
-get_color(char *key)
+int
+gnt_colors_get_color(char *key)
 {
 	int color;
 	gboolean custom = can_use_custom_color();
@@ -196,7 +197,7 @@ void gnt_colors_parse(GKeyFile *kfile)
 				int color = -1;
 
 				key = g_ascii_strdown(key, -1);
-				color = get_color(key);
+				color = gnt_colors_get_color(key);
 				g_free(key);
 				if (color == -1)
 					continue;
@@ -237,8 +238,8 @@ void gnt_color_pairs_parse(GKeyFile *kfi
 			GntColorType type = 0;
 			gchar *fgc = g_ascii_strdown(list[0], -1);
 			gchar *bgc = g_ascii_strdown(list[1], -1);
-			int fg = get_color(fgc);
-			int bg = get_color(bgc);
+			int fg = gnt_colors_get_color(fgc);
+			int bg = gnt_colors_get_color(bgc);
 			g_free(fgc);
 			g_free(bgc);
 			if (fg == -1 || bg == -1)
@@ -287,3 +288,8 @@ int gnt_color_pair(int pair)
 		  pair == GNT_COLOR_TITLE_D || pair == GNT_COLOR_DISABLED) ? 0 : A_STANDOUT));
 }
 
+int gnt_color_add_pair(int fg, int bg)
+{
+	init_pair(custom_type, fg, bg);
+	return custom_type++;
+}
============================================================
--- finch/libgnt/gntcolors.h	88522160b8d7b8de2cddfa9afa9146cf9db1b156
+++ finch/libgnt/gntcolors.h	e051954444eb603747d58dc883820d816edb57e2
@@ -86,6 +86,16 @@ void gnt_color_pairs_parse(GKeyFile *kfi
  */
 void gnt_color_pairs_parse(GKeyFile *kfile);
 
+/**
+ * Parse a string color
+ *
+ * @param kfile The string value
+ *
+ * @return A color
+ *
+ * @since 2.3.1 (gnt), 2.3.1 (pidgin)
+ */
+int gnt_colors_get_color(char *key);
 #endif
 
 /**
@@ -101,4 +111,15 @@ int gnt_color_pair(int color);
  */
 int gnt_color_pair(int color);
 
+/**
+ * Adds a color definition
+ *
+ * @param fg   Foreground
+ * @param bg   Background
+ *
+ * @return  A color pair
+ *
+ * @since 2.3.1
+ */
+int gnt_color_add_pair(int fg, int bg);
 #endif
============================================================
--- finch/libgnt/gntstyle.c	fb571513e427095d908a9872fe1f4a7a851a1530
+++ finch/libgnt/gntstyle.c	b41472476767b5735b597c60dcc002b9a008ce60
@@ -59,6 +59,21 @@ char *gnt_style_get_from_name(const char
 #endif
 }
 
+char **gnt_style_get_string_list(const char *group, const char *key, gsize *length)
+{
+#if GLIB_CHECK_VERSION(2,6,0)
+	const char *prg = g_get_prgname();
+	if ((group == NULL || *group == '\0') && prg &&
+			g_key_file_has_group(gkfile, prg))
+		group = prg;
+	if (!group)
+		group = "general";
+	return g_key_file_get_string_list(gkfile, group, key, length, NULL);
+#else
+	return NULL;
+#endif
+}
+
 gboolean gnt_style_get_bool(GntStyle style, gboolean def)
 {
 	const char * str;
============================================================
--- finch/libgnt/gntstyle.h	977a504f8692f07fe75dbe8e22480c639897b873
+++ finch/libgnt/gntstyle.h	ff5c4fa89e5784532c873567a90d7258f51ee5d1
@@ -65,6 +65,20 @@ char *gnt_style_get_from_name(const char
 char *gnt_style_get_from_name(const char *group, const char *key);
 
 /**
+ * Get the value of a preference in ~/.gntrc.
+ *
+ * @param group   The name of the group in the keyfile. If @c NULL, the prgname
+ *                will be used first, if available. Otherwise, "general" will be used.
+ * @param key     The key
+ * @param length  Return location for the number of strings returned, or NULL
+ *
+ * @return        NULL terminated string array. The array should be freed with g_strfreev().
+ *
+ * @since 2.3.1 (gnt), 2.3.1 (pidgin)
+ */
+char **gnt_style_get_string_list(const char *group, const char *key, gsize *length);
+
+/**
  * Parse a boolean preference. For example, if 'value' is "false" (ignoring case)
  * or "0", the return value will be @c FALSE, otherwise @c TRUE.
  *
============================================================
--- finch/libgnt/gnttree.c	167add2780137d49085ed34142dfde5c3d267103
+++ finch/libgnt/gnttree.c	84f9a986284da48d5d3d87498ff3a8d215474b01
@@ -75,6 +75,7 @@ struct _GntTreeRow
 	                               If choice is true, then child will be NULL */
 	gboolean isselected;
 	GntTextFormatFlags flags;
+	int color;
 
 	GntTreeRow *parent;
 	GntTreeRow *child;
@@ -522,9 +523,14 @@ redraw_tree(GntTree *tree)
 		else
 		{
 			if (flags & GNT_TEXT_FLAG_DIM)
-				attr |= (A_DIM | gnt_color_pair(GNT_COLOR_DISABLED));
+				if (row->color)
+					attr |= (A_DIM | gnt_color_pair(row->color));
+				else
+					attr |= (A_DIM | gnt_color_pair(GNT_COLOR_DISABLED));
 			else if (flags & GNT_TEXT_FLAG_HIGHLIGHT)
 				attr |= (A_DIM | gnt_color_pair(GNT_COLOR_HIGHLIGHT));
+			else if (row->color)
+				attr |= gnt_color_pair(row->color);
 			else
 				attr |= gnt_color_pair(GNT_COLOR_NORMAL);
 		}
@@ -1559,6 +1565,16 @@ void gnt_tree_set_row_flags(GntTree *tre
 	redraw_tree(tree);	/* XXX: It shouldn't be necessary to redraw the whole darned tree */
 }
 
+void gnt_tree_set_row_color(GntTree *tree, void *key, int color)
+{
+	GntTreeRow *row = g_hash_table_lookup(tree->hash, key);
+	if (!row || row->color == color)
+		return;
+
+	row->color = color;
+	redraw_tree(tree);
+}
+
 void gnt_tree_set_selected(GntTree *tree , void *key)
 {
 	int dist;
============================================================
--- finch/libgnt/gnttree.h	27b8f58d2e218303d30a49310dc15160e45cf341
+++ finch/libgnt/gnttree.h	0c53c1bcdc96ff3b6885decc53b92aa1a72dba81
@@ -325,6 +325,15 @@ void gnt_tree_set_row_flags(GntTree *tre
 void gnt_tree_set_row_flags(GntTree *tree, void *key, GntTextFormatFlags flags);
 
 /**
+ * Set color for the text in a row in the tree.
+ *
+ * @param tree   The tree
+ * @param key    The key for the row
+ * @param color  The color
+ */
+void gnt_tree_set_row_color(GntTree *, void *, int);
+
+/**
  * Select a row.
  *
  * @param tree  The tree


More information about the Commits mailing list