# HG changeset patch # User Sadrul Habib Chowdhury # Date 1154062039 0 # Node ID 06f75fb84a781481a745da645142b4075c9ecb28 # Parent 44c5c6d8023968e1ff4878f06961816caf002a2f [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 diff -r 44c5c6d80239 -r 06f75fb84a78 console/libgnt/Makefile.am --- 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 diff -r 44c5c6d80239 -r 06f75fb84a78 console/libgnt/gntcolors.c --- 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 #include "gntcolors.h" +#include + +#include +#include + 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); +} + diff -r 44c5c6d80239 -r 06f75fb84a78 console/libgnt/gntcolors.h --- 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 + 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 diff -r 44c5c6d80239 -r 06f75fb84a78 console/libgnt/gntmain.c --- 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 @@ -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); diff -r 44c5c6d80239 -r 06f75fb84a78 console/libgnt/gntrc.sample --- /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 diff -r 44c5c6d80239 -r 06f75fb84a78 console/libgnt/gntstyle.c --- /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 +} + diff -r 44c5c6d80239 -r 06f75fb84a78 console/libgnt/gntstyle.h --- /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); +