qulogic/libgnt

Parents 06a58097b8f5
Children c33fe24b1e08
Add support for colour in gnttreerows, and colourise the blist. Fixes #1490
  • +11 -5
    gntcolors.c
  • +21 -0
    gntcolors.h
  • +15 -0
    gntstyle.c
  • +14 -0
    gntstyle.h
  • +17 -1
    gnttree.c
  • +9 -0
    gnttree.h
  • --- a/gntcolors.c Wed Nov 28 03:52:27 2007 +0000
    +++ b/gntcolors.c Fri Nov 30 03:17:07 2007 +0000
    @@ -33,6 +33,7 @@
    #include <string.h>
    static gboolean hascolors;
    +static int custom_type = GNT_COLORS;
    static struct
    {
    short r, g, b;
    @@ -137,8 +138,8 @@
    }
    #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 @@
    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 @@
    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 @@
    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++;
    +}
    --- a/gntcolors.h Wed Nov 28 03:52:27 2007 +0000
    +++ b/gntcolors.h Fri Nov 30 03:17:07 2007 +0000
    @@ -86,6 +86,16 @@
    */
    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);
    +/**
    + * 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
    --- a/gntstyle.c Wed Nov 28 03:52:27 2007 +0000
    +++ b/gntstyle.c Fri Nov 30 03:17:07 2007 +0000
    @@ -59,6 +59,21 @@
    #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;
    --- a/gntstyle.h Wed Nov 28 03:52:27 2007 +0000
    +++ b/gntstyle.h Fri Nov 30 03:17:07 2007 +0000
    @@ -65,6 +65,20 @@
    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.
    *
    --- a/gnttree.c Wed Nov 28 03:52:27 2007 +0000
    +++ b/gnttree.c Fri Nov 30 03:17:07 2007 +0000
    @@ -75,6 +75,7 @@
    If choice is true, then child will be NULL */
    gboolean isselected;
    GntTextFormatFlags flags;
    + int color;
    GntTreeRow *parent;
    GntTreeRow *child;
    @@ -522,9 +523,14 @@
    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 @@
    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;
    --- a/gnttree.h Wed Nov 28 03:52:27 2007 +0000
    +++ b/gnttree.h Fri Nov 30 03:17:07 2007 +0000
    @@ -325,6 +325,15 @@
    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