From: <sa...@us...> - 2006-07-28 04:47:28
|
Revision: 16589 Author: sadrul Date: 2006-07-27 21:47:19 -0700 (Thu, 27 Jul 2006) ViewCVS: http://svn.sourceforge.net/gaim/?rev=16589&view=rev Log Message: ----------- 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. Modified Paths: -------------- trunk/console/libgnt/Makefile.am trunk/console/libgnt/gntcolors.c trunk/console/libgnt/gntcolors.h trunk/console/libgnt/gntmain.c Added Paths: ----------- trunk/console/libgnt/gntrc.sample trunk/console/libgnt/gntstyle.c trunk/console/libgnt/gntstyle.h Modified: trunk/console/libgnt/Makefile.am =================================================================== --- trunk/console/libgnt/Makefile.am 2006-07-27 20:11:55 UTC (rev 16588) +++ trunk/console/libgnt/Makefile.am 2006-07-28 04:47:19 UTC (rev 16589) @@ -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 Modified: trunk/console/libgnt/gntcolors.c =================================================================== --- trunk/console/libgnt/gntcolors.c 2006-07-27 20:11:55 UTC (rev 16588) +++ trunk/console/libgnt/gntcolors.c 2006-07-28 04:47:19 UTC (rev 16589) @@ -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); +} + Modified: trunk/console/libgnt/gntcolors.h =================================================================== --- trunk/console/libgnt/gntcolors.h 2006-07-27 20:11:55 UTC (rev 16588) +++ trunk/console/libgnt/gntcolors.h 2006-07-28 04:47:19 UTC (rev 16589) @@ -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 Modified: trunk/console/libgnt/gntmain.c =================================================================== --- trunk/console/libgnt/gntmain.c 2006-07-27 20:11:55 UTC (rev 16588) +++ trunk/console/libgnt/gntmain.c 2006-07-28 04:47:19 UTC (rev 16589) @@ -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); Added: trunk/console/libgnt/gntrc.sample =================================================================== --- trunk/console/libgnt/gntrc.sample (rev 0) +++ trunk/console/libgnt/gntrc.sample 2006-07-28 04:47:19 UTC (rev 16589) @@ -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 Property changes on: trunk/console/libgnt/gntrc.sample ___________________________________________________________________ Name: svn:mime-type + text/plain Name: svn:eol-style + native Added: trunk/console/libgnt/gntstyle.c =================================================================== --- trunk/console/libgnt/gntstyle.c (rev 0) +++ trunk/console/libgnt/gntstyle.c 2006-07-28 04:47:19 UTC (rev 16589) @@ -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 +} + Property changes on: trunk/console/libgnt/gntstyle.c ___________________________________________________________________ Name: svn:mime-type + text/plain Name: svn:eol-style + native Added: trunk/console/libgnt/gntstyle.h =================================================================== --- trunk/console/libgnt/gntstyle.h (rev 0) +++ trunk/console/libgnt/gntstyle.h 2006-07-28 04:47:19 UTC (rev 16589) @@ -0,0 +1,4 @@ +#include "gnt.h" + +void gnt_style_read_configure_file(const char *filename); + Property changes on: trunk/console/libgnt/gntstyle.h ___________________________________________________________________ Name: svn:mime-type + text/plain Name: svn:eol-style + native This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |