about summary refs log tree commit diff stats
path: root/src/config
diff options
context:
space:
mode:
authorJames Booth <boothj5@gmail.com>2014-11-16 21:56:19 +0000
committerJames Booth <boothj5@gmail.com>2014-11-16 21:56:19 +0000
commit976e5aac0a9905dbaa8f150ed7107011b9f87373 (patch)
treea243735eb2e4c51a9cf016d3493dc6e1f2d84791 /src/config
parented4391ec8a3190769917358e4fa68106c9e9891d (diff)
downloadprofani-tty-976e5aac0a9905dbaa8f150ed7107011b9f87373.tar.gz
Added support for bold theme settings
Diffstat (limited to 'src/config')
-rw-r--r--src/config/theme.c143
-rw-r--r--src/config/theme.h5
2 files changed, 93 insertions, 55 deletions
diff --git a/src/config/theme.c b/src/config/theme.c
index fb0894a8..f71859fe 100644
--- a/src/config/theme.c
+++ b/src/config/theme.c
@@ -50,6 +50,7 @@
 
 static GString *theme_loc;
 static GKeyFile *theme;
+static GHashTable *bold_items;
 
 struct colour_string_t {
     char *str;
@@ -117,11 +118,12 @@ static struct colours_t {
         NCURSES_COLOR_T otrended;
         NCURSES_COLOR_T otrtrusted;
         NCURSES_COLOR_T otruntrusted;
+        NCURSES_COLOR_T rosterheader;
+        NCURSES_COLOR_T occupantsheader;
 } colour_prefs;
 
 static NCURSES_COLOR_T _lookup_colour(const char * const colour);
-static void _set_colour(gchar *val, NCURSES_COLOR_T *pref,
-    NCURSES_COLOR_T def);
+static void _set_colour(gchar *val, NCURSES_COLOR_T *pref, NCURSES_COLOR_T def, theme_item_t theme_item);
 static void _load_colours(void);
 static gchar * _get_themes_dir(void);
 void _theme_list_dir(const gchar * const dir, GSList **result);
@@ -190,6 +192,9 @@ theme_close(void)
     if (theme_loc != NULL) {
         g_string_free(theme_loc, TRUE);
     }
+    if (bold_items) {
+        g_hash_table_destroy(bold_items);
+    }
 }
 
 void
@@ -255,6 +260,10 @@ theme_init_colours(void)
     init_pair(41, colour_prefs.otrended, colour_prefs.bkgnd);
     init_pair(42, colour_prefs.otrtrusted, colour_prefs.bkgnd);
     init_pair(43, colour_prefs.otruntrusted, colour_prefs.bkgnd);
+
+    // subwin headers
+    init_pair(44, colour_prefs.rosterheader, colour_prefs.bkgnd);
+    init_pair(45, colour_prefs.occupantsheader, colour_prefs.bkgnd);
 }
 
 static NCURSES_COLOR_T
@@ -271,13 +280,19 @@ _lookup_colour(const char * const colour)
 }
 
 static void
-_set_colour(gchar *val, NCURSES_COLOR_T *pref,
-    NCURSES_COLOR_T def)
+_set_colour(gchar *val, NCURSES_COLOR_T *pref, NCURSES_COLOR_T def, theme_item_t theme_item)
 {
     if(!val) {
         *pref = def;
     } else {
-        NCURSES_COLOR_T col = _lookup_colour(val);
+        gchar *true_val = val;
+        if (g_str_has_prefix(val, "bold_")) {
+            true_val = &val[5];
+            if (theme_item != THEME_NONE) {
+                g_hash_table_insert(bold_items, GINT_TO_POINTER(theme_item), GINT_TO_POINTER(theme_item));
+            }
+        }
+        NCURSES_COLOR_T col = _lookup_colour(true_val);
         if (col == -99) {
             *pref = def;
         } else {
@@ -289,189 +304,202 @@ _set_colour(gchar *val, NCURSES_COLOR_T *pref,
 static void
 _load_colours(void)
 {
+    if (bold_items) {
+        g_hash_table_destroy(bold_items);
+    }
+    bold_items = g_hash_table_new(g_direct_hash, g_direct_equal);
+
     gchar *bkgnd_val = g_key_file_get_string(theme, "colours", "bkgnd", NULL);
-    _set_colour(bkgnd_val, &colour_prefs.bkgnd, -1);
+    _set_colour(bkgnd_val, &colour_prefs.bkgnd, -1, THEME_NONE);
     g_free(bkgnd_val);
 
     gchar *titlebar_val = g_key_file_get_string(theme, "colours", "titlebar", NULL);
-    _set_colour(titlebar_val, &colour_prefs.titlebar, COLOR_BLUE);
+    _set_colour(titlebar_val, &colour_prefs.titlebar, COLOR_BLUE, THEME_NONE);
     g_free(titlebar_val);
 
     gchar *statusbar_val = g_key_file_get_string(theme, "colours", "statusbar", NULL);
-    _set_colour(statusbar_val, &colour_prefs.statusbar, COLOR_BLUE);
+    _set_colour(statusbar_val, &colour_prefs.statusbar, COLOR_BLUE, THEME_NONE);
     g_free(statusbar_val);
 
     gchar *titlebartext_val = g_key_file_get_string(theme, "colours", "titlebar.text", NULL);
-    _set_colour(titlebartext_val, &colour_prefs.titlebartext, COLOR_WHITE);
+    _set_colour(titlebartext_val, &colour_prefs.titlebartext, COLOR_WHITE, THEME_TITLE_TEXT);
     g_free(titlebartext_val);
 
     gchar *titlebarbrackets_val = g_key_file_get_string(theme, "colours", "titlebar.brackets", NULL);
-    _set_colour(titlebarbrackets_val, &colour_prefs.titlebarbrackets, COLOR_CYAN);
+    _set_colour(titlebarbrackets_val, &colour_prefs.titlebarbrackets, COLOR_CYAN, THEME_TITLE_BRACKET);
     g_free(titlebarbrackets_val);
 
     gchar *titlebarunencrypted_val = g_key_file_get_string(theme, "colours", "titlebar.unencrypted", NULL);
-    _set_colour(titlebarunencrypted_val, &colour_prefs.titlebarunencrypted, COLOR_RED);
+    _set_colour(titlebarunencrypted_val, &colour_prefs.titlebarunencrypted, COLOR_RED, THEME_TITLE_UNENCRYPTED);
     g_free(titlebarunencrypted_val);
 
     gchar *titlebarencrypted_val = g_key_file_get_string(theme, "colours", "titlebar.encrypted", NULL);
-    _set_colour(titlebarencrypted_val, &colour_prefs.titlebarencrypted, COLOR_WHITE);
+    _set_colour(titlebarencrypted_val, &colour_prefs.titlebarencrypted, COLOR_WHITE, THEME_TITLE_ENCRYPTED);
     g_free(titlebarencrypted_val);
 
     gchar *titlebaruntrusted_val = g_key_file_get_string(theme, "colours", "titlebar.untrusted", NULL);
-    _set_colour(titlebaruntrusted_val, &colour_prefs.titlebaruntrusted, COLOR_YELLOW);
+    _set_colour(titlebaruntrusted_val, &colour_prefs.titlebaruntrusted, COLOR_YELLOW, THEME_TITLE_UNTRUSTED);
     g_free(titlebaruntrusted_val);
 
     gchar *titlebartrusted_val = g_key_file_get_string(theme, "colours", "titlebar.trusted", NULL);
-    _set_colour(titlebartrusted_val, &colour_prefs.titlebartrusted, COLOR_WHITE);
+    _set_colour(titlebartrusted_val, &colour_prefs.titlebartrusted, COLOR_WHITE, THEME_TITLE_TRUSTED);
     g_free(titlebartrusted_val);
 
     gchar *titlebaronline_val = g_key_file_get_string(theme, "colours", "titlebar.online", NULL);
-    _set_colour(titlebaronline_val, &colour_prefs.titlebaronline, COLOR_WHITE);
+    _set_colour(titlebaronline_val, &colour_prefs.titlebaronline, COLOR_WHITE, THEME_TITLE_ONLINE);
     g_free(titlebaronline_val);
 
     gchar *titlebaroffline_val = g_key_file_get_string(theme, "colours", "titlebar.offline", NULL);
-    _set_colour(titlebaroffline_val, &colour_prefs.titlebaroffline, COLOR_WHITE);
+    _set_colour(titlebaroffline_val, &colour_prefs.titlebaroffline, COLOR_WHITE, THEME_TITLE_OFFLINE);
     g_free(titlebaroffline_val);
 
     gchar *titlebaraway_val = g_key_file_get_string(theme, "colours", "titlebar.away", NULL);
-    _set_colour(titlebaraway_val, &colour_prefs.titlebaraway, COLOR_WHITE);
+    _set_colour(titlebaraway_val, &colour_prefs.titlebaraway, COLOR_WHITE, THEME_TITLE_AWAY);
     g_free(titlebaraway_val);
 
     gchar *titlebarchat_val = g_key_file_get_string(theme, "colours", "titlebar.chat", NULL);
-    _set_colour(titlebarchat_val, &colour_prefs.titlebarchat, COLOR_WHITE);
+    _set_colour(titlebarchat_val, &colour_prefs.titlebarchat, COLOR_WHITE, THEME_TITLE_CHAT);
     g_free(titlebarchat_val);
 
     gchar *titlebardnd_val = g_key_file_get_string(theme, "colours", "titlebar.dnd", NULL);
-    _set_colour(titlebardnd_val, &colour_prefs.titlebardnd, COLOR_WHITE);
+    _set_colour(titlebardnd_val, &colour_prefs.titlebardnd, COLOR_WHITE, THEME_TITLE_DND);
     g_free(titlebardnd_val);
 
     gchar *titlebarxa_val = g_key_file_get_string(theme, "colours", "titlebar.xa", NULL);
-    _set_colour(titlebarxa_val, &colour_prefs.titlebarxa, COLOR_WHITE);
+    _set_colour(titlebarxa_val, &colour_prefs.titlebarxa, COLOR_WHITE, THEME_TITLE_XA);
     g_free(titlebarxa_val);
 
     gchar *statusbartext_val = g_key_file_get_string(theme, "colours", "statusbar.text", NULL);
-    _set_colour(statusbartext_val, &colour_prefs.statusbartext, COLOR_WHITE);
+    _set_colour(statusbartext_val, &colour_prefs.statusbartext, COLOR_WHITE, THEME_STATUS_TEXT);
     g_free(statusbartext_val);
 
     gchar *statusbarbrackets_val = g_key_file_get_string(theme, "colours", "statusbar.brackets", NULL);
-    _set_colour(statusbarbrackets_val, &colour_prefs.statusbarbrackets, COLOR_CYAN);
+    _set_colour(statusbarbrackets_val, &colour_prefs.statusbarbrackets, COLOR_CYAN, THEME_STATUS_BRACKET);
     g_free(statusbarbrackets_val);
 
     gchar *statusbaractive_val = g_key_file_get_string(theme, "colours", "statusbar.active", NULL);
-    _set_colour(statusbaractive_val, &colour_prefs.statusbaractive, COLOR_CYAN);
+    _set_colour(statusbaractive_val, &colour_prefs.statusbaractive, COLOR_CYAN, THEME_STATUS_ACTIVE);
     g_free(statusbaractive_val);
 
     gchar *statusbarnew_val = g_key_file_get_string(theme, "colours", "statusbar.new", NULL);
-    _set_colour(statusbarnew_val, &colour_prefs.statusbarnew, COLOR_WHITE);
+    _set_colour(statusbarnew_val, &colour_prefs.statusbarnew, COLOR_WHITE, THEME_STATUS_NEW);
     g_free(statusbarnew_val);
 
     gchar *maintext_val = g_key_file_get_string(theme, "colours", "main.text", NULL);
-    _set_colour(maintext_val, &colour_prefs.maintext, COLOR_WHITE);
+    _set_colour(maintext_val, &colour_prefs.maintext, COLOR_WHITE, THEME_TEXT);
     g_free(maintext_val);
 
     gchar *maintextme_val = g_key_file_get_string(theme, "colours", "main.text.me", NULL);
-    _set_colour(maintextme_val, &colour_prefs.maintextme, COLOR_WHITE);
+    _set_colour(maintextme_val, &colour_prefs.maintextme, COLOR_WHITE, THEME_TEXT_ME);
     g_free(maintextme_val);
 
     gchar *maintextthem_val = g_key_file_get_string(theme, "colours", "main.text.them", NULL);
-    _set_colour(maintextthem_val, &colour_prefs.maintextthem, COLOR_WHITE);
+    _set_colour(maintextthem_val, &colour_prefs.maintextthem, COLOR_WHITE, THEME_TEXT_THEM);
     g_free(maintextthem_val);
 
     gchar *splashtext_val = g_key_file_get_string(theme, "colours", "main.splash", NULL);
-    _set_colour(splashtext_val, &colour_prefs.splashtext, COLOR_CYAN);
+    _set_colour(splashtext_val, &colour_prefs.splashtext, COLOR_CYAN, THEME_SPLASH);
     g_free(splashtext_val);
 
     gchar *inputtext_val = g_key_file_get_string(theme, "colours", "input.text", NULL);
-    _set_colour(inputtext_val, &colour_prefs.inputtext, COLOR_WHITE);
+    _set_colour(inputtext_val, &colour_prefs.inputtext, COLOR_WHITE, THEME_INPUT_TEXT);
     g_free(inputtext_val);
 
     gchar *timetext_val = g_key_file_get_string(theme, "colours", "main.time", NULL);
-    _set_colour(timetext_val, &colour_prefs.timetext, COLOR_WHITE);
+    _set_colour(timetext_val, &colour_prefs.timetext, COLOR_WHITE, THEME_TIME);
     g_free(timetext_val);
 
     gchar *subscribed_val = g_key_file_get_string(theme, "colours", "subscribed", NULL);
-    _set_colour(subscribed_val, &colour_prefs.subscribed, COLOR_GREEN);
+    _set_colour(subscribed_val, &colour_prefs.subscribed, COLOR_GREEN, THEME_SUBSCRIBED);
     g_free(subscribed_val);
 
     gchar *unsubscribed_val = g_key_file_get_string(theme, "colours", "unsubscribed", NULL);
-    _set_colour(unsubscribed_val, &colour_prefs.unsubscribed, COLOR_RED);
+    _set_colour(unsubscribed_val, &colour_prefs.unsubscribed, COLOR_RED, THEME_UNSUBSCRIBED);
     g_free(unsubscribed_val);
 
     gchar *otrstartedtrusted_val = g_key_file_get_string(theme, "colours", "otr.started.trusted", NULL);
-    _set_colour(otrstartedtrusted_val, &colour_prefs.otrstartedtrusted, COLOR_GREEN);
+    _set_colour(otrstartedtrusted_val, &colour_prefs.otrstartedtrusted, COLOR_GREEN, THEME_OTR_STARTED_TRUSTED);
     g_free(otrstartedtrusted_val);
 
     gchar *otrstarteduntrusted_val = g_key_file_get_string(theme, "colours", "otr.started.untrusted", NULL);
-    _set_colour(otrstarteduntrusted_val, &colour_prefs.otrstarteduntrusted, COLOR_YELLOW);
+    _set_colour(otrstarteduntrusted_val, &colour_prefs.otrstarteduntrusted, COLOR_YELLOW, THEME_OTR_STARTED_UNTRUSTED);
     g_free(otrstarteduntrusted_val);
 
     gchar *otrended_val = g_key_file_get_string(theme, "colours", "otr.ended", NULL);
-    _set_colour(otrended_val, &colour_prefs.otrended, COLOR_RED);
+    _set_colour(otrended_val, &colour_prefs.otrended, COLOR_RED, THEME_OTR_ENDED);
     g_free(otrended_val);
 
     gchar *otrtrusted_val = g_key_file_get_string(theme, "colours", "otr.trusted", NULL);
-    _set_colour(otrtrusted_val, &colour_prefs.otrtrusted, COLOR_GREEN);
+    _set_colour(otrtrusted_val, &colour_prefs.otrtrusted, COLOR_GREEN, THEME_OTR_TRUSTED);
     g_free(otrtrusted_val);
 
     gchar *otruntrusted_val = g_key_file_get_string(theme, "colours", "otr.untrusted", NULL);
-    _set_colour(otruntrusted_val, &colour_prefs.otruntrusted, COLOR_YELLOW);
+    _set_colour(otruntrusted_val, &colour_prefs.otruntrusted, COLOR_YELLOW, THEME_OTR_UNTRUSTED);
     g_free(otruntrusted_val);
 
     gchar *online_val = g_key_file_get_string(theme, "colours", "online", NULL);
-    _set_colour(online_val, &colour_prefs.online, COLOR_GREEN);
+    _set_colour(online_val, &colour_prefs.online, COLOR_GREEN, THEME_ONLINE);
     g_free(online_val);
 
     gchar *away_val = g_key_file_get_string(theme, "colours", "away", NULL);
-    _set_colour(away_val, &colour_prefs.away, COLOR_CYAN);
+    _set_colour(away_val, &colour_prefs.away, COLOR_CYAN, THEME_AWAY);
     g_free(away_val);
 
     gchar *chat_val = g_key_file_get_string(theme, "colours", "chat", NULL);
-    _set_colour(chat_val, &colour_prefs.chat, COLOR_GREEN);
+    _set_colour(chat_val, &colour_prefs.chat, COLOR_GREEN, THEME_CHAT);
     g_free(chat_val);
 
     gchar *dnd_val = g_key_file_get_string(theme, "colours", "dnd", NULL);
-    _set_colour(dnd_val, &colour_prefs.dnd, COLOR_RED);
+    _set_colour(dnd_val, &colour_prefs.dnd, COLOR_RED, THEME_DND);
     g_free(dnd_val);
 
     gchar *xa_val = g_key_file_get_string(theme, "colours", "xa", NULL);
-    _set_colour(xa_val, &colour_prefs.xa, COLOR_CYAN);
+    _set_colour(xa_val, &colour_prefs.xa, COLOR_CYAN, THEME_XA);
     g_free(xa_val);
 
     gchar *offline_val = g_key_file_get_string(theme, "colours", "offline", NULL);
-    _set_colour(offline_val, &colour_prefs.offline, COLOR_RED);
+    _set_colour(offline_val, &colour_prefs.offline, COLOR_RED, THEME_OFFLINE);
     g_free(offline_val);
 
     gchar *typing_val = g_key_file_get_string(theme, "colours", "typing", NULL);
-    _set_colour(typing_val, &colour_prefs.typing, COLOR_YELLOW);
+    _set_colour(typing_val, &colour_prefs.typing, COLOR_YELLOW, THEME_TYPING);
     g_free(typing_val);
 
     gchar *gone_val = g_key_file_get_string(theme, "colours", "gone", NULL);
-    _set_colour(gone_val, &colour_prefs.gone, COLOR_RED);
+    _set_colour(gone_val, &colour_prefs.gone, COLOR_RED, THEME_GONE);
     g_free(gone_val);
 
     gchar *error_val = g_key_file_get_string(theme, "colours", "error", NULL);
-    _set_colour(error_val, &colour_prefs.error, COLOR_RED);
+    _set_colour(error_val, &colour_prefs.error, COLOR_RED, THEME_ERROR);
     g_free(error_val);
 
     gchar *incoming_val = g_key_file_get_string(theme, "colours", "incoming", NULL);
-    _set_colour(incoming_val, &colour_prefs.incoming, COLOR_YELLOW);
+    _set_colour(incoming_val, &colour_prefs.incoming, COLOR_YELLOW, THEME_INCOMING);
     g_free(incoming_val);
 
     gchar *roominfo_val = g_key_file_get_string(theme, "colours", "roominfo", NULL);
-    _set_colour(roominfo_val, &colour_prefs.roominfo, COLOR_YELLOW);
+    _set_colour(roominfo_val, &colour_prefs.roominfo, COLOR_YELLOW, THEME_ROOMINFO);
     g_free(roominfo_val);
 
     gchar *roommention_val = g_key_file_get_string(theme, "colours", "roommention", NULL);
-    _set_colour(roommention_val, &colour_prefs.roommention, COLOR_YELLOW);
+    _set_colour(roommention_val, &colour_prefs.roommention, COLOR_YELLOW, THEME_ROOMMENTION);
     g_free(roommention_val);
 
     gchar *me_val = g_key_file_get_string(theme, "colours", "me", NULL);
-    _set_colour(me_val, &colour_prefs.me, COLOR_YELLOW);
+    _set_colour(me_val, &colour_prefs.me, COLOR_YELLOW, THEME_ME);
     g_free(me_val);
 
     gchar *them_val = g_key_file_get_string(theme, "colours", "them", NULL);
-    _set_colour(them_val, &colour_prefs.them, COLOR_GREEN);
+    _set_colour(them_val, &colour_prefs.them, COLOR_GREEN, THEME_THEM);
     g_free(them_val);
+
+    gchar *rosterheader_val = g_key_file_get_string(theme, "colours", "roster.header", NULL);
+    _set_colour(rosterheader_val, &colour_prefs.rosterheader, COLOR_YELLOW, THEME_ROSTER_HEADER);
+    g_free(rosterheader_val);
+
+    gchar *occupantsheader_val = g_key_file_get_string(theme, "colours", "occupants.header", NULL);
+    _set_colour(occupantsheader_val, &colour_prefs.occupantsheader, COLOR_YELLOW, THEME_OCCUPANTS_HEADER);
+    g_free(occupantsheader_val);
 }
 
 static gchar *
@@ -579,8 +607,15 @@ theme_attrs(theme_item_t attrs)
     case THEME_OTR_ENDED:              result = COLOR_PAIR(41); break;
     case THEME_OTR_TRUSTED:            result = COLOR_PAIR(42); break;
     case THEME_OTR_UNTRUSTED:          result = COLOR_PAIR(43); break;
-    default:                            break;
+    case THEME_ROSTER_HEADER:          result = COLOR_PAIR(44); break;
+    case THEME_OCCUPANTS_HEADER:       result = COLOR_PAIR(45); break;
+    default:                           break;
     }
 
-    return result;
-}
+    if (g_hash_table_lookup(bold_items, GINT_TO_POINTER(attrs))) {
+        return result | A_BOLD;
+    } else {
+        return result;
+
+    }
+}
\ No newline at end of file
diff --git a/src/config/theme.h b/src/config/theme.h
index 5bc923ab..ebd963b1 100644
--- a/src/config/theme.h
+++ b/src/config/theme.h
@@ -87,7 +87,10 @@ typedef enum {
     THEME_OTR_STARTED_UNTRUSTED,
     THEME_OTR_ENDED,
     THEME_OTR_TRUSTED,
-    THEME_OTR_UNTRUSTED
+    THEME_OTR_UNTRUSTED,
+    THEME_OCCUPANTS_HEADER,
+    THEME_ROSTER_HEADER,
+    THEME_NONE
 } theme_item_t;
 
 void theme_init(const char * const theme_name);