changeset 14004:06f75fb84a78

[gaim-migrate @ 16589] Add a configure file (~/.gntrc) for gnt to configure its looks. This is available only for GLib 2.6 and above. Currently, it only allows changing the colors (r;g;b -- each in [0, 1000]) and color-groups. I have added gntrc.sample as an example. committer: Tailor Script <tailor@pidgin.im>
author Sadrul Habib Chowdhury <imadil@gmail.com>
date Fri, 28 Jul 2006 04:47:19 +0000
parents 44c5c6d80239
children d856c2ec93ca
files console/libgnt/Makefile.am console/libgnt/gntcolors.c console/libgnt/gntcolors.h console/libgnt/gntmain.c console/libgnt/gntrc.sample console/libgnt/gntstyle.c console/libgnt/gntstyle.h
diffstat 7 files changed, 190 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/console/libgnt/Makefile.am	Thu Jul 27 20:11:55 2006 +0000
+++ b/console/libgnt/Makefile.am	Fri Jul 28 04:47:19 2006 +0000
@@ -14,6 +14,7 @@
 	gntlabel.c \
 	gntline.c \
 	gntmarshal.c \
+	gntstyle.c \
 	gnttextview.c \
 	gnttree.c \
 	gntmain.c
@@ -30,6 +31,7 @@
 	gntlabel.h \
 	gntline.h \
 	gntmarshal.h \
+	gntstyle.h \
 	gnttextview.h \
 	gnttree.h \
 	gnt.h
--- a/console/libgnt/gntcolors.c	Thu Jul 27 20:11:55 2006 +0000
+++ b/console/libgnt/gntcolors.c	Fri Jul 28 04:47:19 2006 +0000
@@ -1,6 +1,11 @@
 #include <ncursesw/ncurses.h>
 #include "gntcolors.h"
 
+#include <glib.h>
+
+#include <stdlib.h>
+#include <string.h>
+
 static struct
 {
 	short r, g, b;
@@ -75,3 +80,125 @@
 	restore_colors();
 }
 
+static int
+get_color(char *key)
+{
+	int color;
+
+	key = g_strstrip(key);
+
+	if (strcmp(key, "black") == 0)
+		color = GNT_COLOR_BLACK;
+	else if (strcmp(key, "red") == 0)
+		color = GNT_COLOR_RED;
+	else if (strcmp(key, "green") == 0)
+		color = GNT_COLOR_GREEN;
+	else if (strcmp(key, "blue") == 0)
+		color = GNT_COLOR_BLUE;
+	else if (strcmp(key, "white") == 0)
+		color = GNT_COLOR_WHITE;
+	else if (strcmp(key, "gray") == 0)
+		color = GNT_COLOR_GRAY;
+	else if (strcmp(key, "darkgray") == 0)
+		color = GNT_COLOR_DARK_GRAY;
+	else
+		color = -1;
+	return color;
+}
+
+void gnt_colors_parse(GKeyFile *kfile)
+{
+	GError *error = NULL;
+	gsize nkeys;
+	char **keys = g_key_file_get_keys(kfile, "colors", &nkeys, &error);
+
+	if (error)
+	{
+		/* XXX: some error happened. */
+		g_error_free(error);
+	}
+	else
+	{
+		while (nkeys--)
+		{
+			gsize len;
+			char *key = keys[nkeys];
+			char **list = g_key_file_get_string_list(kfile, "colors", key, &len, NULL);
+			if (len == 3)
+			{
+				int r = atoi(list[0]);
+				int g = atoi(list[1]);
+				int b = atoi(list[2]);
+				int color = -1;
+
+				g_ascii_strdown(key, -1);
+				color = get_color(key);
+				if (color == -1)
+					continue;
+
+				init_color(color, r, g, b);
+			}
+			g_strfreev(list);
+		}
+
+		g_strfreev(keys);
+	}
+
+	gnt_color_pairs_parse(kfile);
+}
+
+void gnt_color_pairs_parse(GKeyFile *kfile)
+{
+	GError *error = NULL;
+	gsize nkeys;
+	char **keys = g_key_file_get_keys(kfile, "colorpairs", &nkeys, &error);
+
+	if (error)
+	{
+		/* XXX: some error happened. */
+		g_error_free(error);
+		return;
+	}
+
+	while (nkeys--)
+	{
+		gsize len;
+		char *key = keys[nkeys];
+		char **list = g_key_file_get_string_list(kfile, "colorpairs", key, &len, NULL);
+		if (len == 2)
+		{
+			GntColorType type = 0;
+			int fg = get_color(g_ascii_strdown(list[0], -1));
+			int bg = get_color(g_ascii_strdown(list[1], -1));
+			if (fg == -1 || bg == -1)
+				continue;
+
+			g_ascii_strdown(key, -1);
+
+			if (strcmp(key, "normal") == 0)
+				type = GNT_COLOR_NORMAL;
+			else if (strcmp(key, "highlight") == 0)
+				type = GNT_COLOR_HIGHLIGHT;
+			else if (strcmp(key, "highlightd") == 0)
+				type = GNT_COLOR_HIGHLIGHT_D;
+			else if (strcmp(key, "shadow") == 0)
+				type = GNT_COLOR_SHADOW;
+			else if (strcmp(key, "title") == 0)
+				type = GNT_COLOR_TITLE;
+			else if (strcmp(key, "titled") == 0)
+				type = GNT_COLOR_TITLE_D;
+			else if (strcmp(key, "text") == 0)
+				type = GNT_COLOR_TEXT_NORMAL;
+			else if (strcmp(key, "disabled") == 0)
+				type = GNT_COLOR_DISABLED;
+			else
+				continue;
+
+			init_pair(type, fg, bg);
+		}
+		g_strfreev(list);
+	}
+
+	g_strfreev(keys);
+}
+
--- a/console/libgnt/gntcolors.h	Thu Jul 27 20:11:55 2006 +0000
+++ b/console/libgnt/gntcolors.h	Fri Jul 28 04:47:19 2006 +0000
@@ -1,6 +1,8 @@
 #ifndef GNT_COLORS_H
 #define GNT_COLORS_H
 
+#include <glib.h>
+
 typedef enum
 {
 	GNT_COLOR_NORMAL = 1,
@@ -34,4 +36,8 @@
 
 void gnt_uninit_colors();
 
+void gnt_colors_parse(GKeyFile *kfile);
+
+void gnt_color_pairs_parse(GKeyFile *kfile);
+
 #endif
--- a/console/libgnt/gntmain.c	Thu Jul 27 20:11:55 2006 +0000
+++ b/console/libgnt/gntmain.c	Fri Jul 28 04:47:19 2006 +0000
@@ -2,8 +2,9 @@
 
 #include "gnt.h"
 #include "gntbox.h"
+#include "gntcolors.h"
 #include "gntkeys.h"
-#include "gntcolors.h"
+#include "gntstyle.h"
 #include "gnttree.h"
 
 #include <stdio.h>
@@ -57,6 +58,8 @@
 
 	if (lock_focus_list)
 		return;
+	if (g_list_find(g_list_first(focus_list), widget))
+		return;
 
 	if (focus_list)
 		w = focus_list->data;
@@ -525,6 +528,7 @@
 void gnt_init()
 {
 	static GIOChannel *channel = NULL;
+	char *filename;
 	
 	if (channel)
 		return;
@@ -548,6 +552,10 @@
 	initscr();
 	gnt_init_colors();
 
+	filename = g_build_filename(g_get_home_dir(), ".gntrc", NULL);
+	gnt_style_read_configure_file(filename);
+	g_free(filename);
+
 	X_MIN = 0;
 	Y_MIN = 0;
 	X_MAX = getmaxx(stdscr);
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/console/libgnt/gntrc.sample	Fri Jul 28 04:47:19 2006 +0000
@@ -0,0 +1,21 @@
+[general]
+shadow = 0
+
+[colors]
+black = 0; 0; 0
+red = 1000; 0; 0
+green = 0; 1000; 0
+blue = 250; 250; 700
+white = 1000; 1000; 1000
+gray = 700; 700; 700
+darkgray = 256; 256; 256
+
+[colorpairs]
+normal = black; white
+highlight = white; blue
+highlightd = black; gray
+shadow = black; darkgray
+title = white; blue
+titled = white; gray
+text = white; blue
+disabled = gray; white
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/console/libgnt/gntstyle.c	Fri Jul 28 04:47:19 2006 +0000
@@ -0,0 +1,21 @@
+#include "gntstyle.h"
+#include "gntcolors.h"
+
+void gnt_style_read_configure_file(const char *filename)
+{
+#if GLIB_CHECK_VERSION(2,6,0)
+	GKeyFile *kfile = g_key_file_new();
+	GError *error = NULL;
+
+	if (!g_key_file_load_from_file(kfile, filename, G_KEY_FILE_NONE, &error))
+	{
+		/* XXX: Print the error or something */
+		g_error_free(error);
+		return;
+	}
+	gnt_colors_parse(kfile);
+
+	g_key_file_free(kfile);
+#endif
+}
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/console/libgnt/gntstyle.h	Fri Jul 28 04:47:19 2006 +0000
@@ -0,0 +1,4 @@
+#include "gnt.h"
+
+void gnt_style_read_configure_file(const char *filename);
+