diff options
author | Michael Vetter <jubalh@iodoru.org> | 2019-06-04 14:50:25 +0200 |
---|---|---|
committer | Michael Vetter <jubalh@iodoru.org> | 2019-06-04 14:50:25 +0200 |
commit | 2d00444702661d7f5b989b2a7556aafeab4309fd (patch) | |
tree | e6ba7cf70e671efab30f6091a6032932eff888f0 /src | |
parent | ea62c3f29366f0f7b4b47bf0e52ee34882c33897 (diff) | |
download | profani-tty-2d00444702661d7f5b989b2a7556aafeab4309fd.tar.gz |
statusbar: reduce duplicate code
status_bar_new() and status_bar_active() are almost identical. Let's use one helper function to not duplicate code. I thought about renaming both functions into one and adding another parameter but didn't come up with a good name for the function that clearly describes what it does. So staying with current names + helper functions.
Diffstat (limited to 'src')
-rw-r--r-- | src/ui/statusbar.c | 41 |
1 files changed, 9 insertions, 32 deletions
diff --git a/src/ui/statusbar.c b/src/ui/statusbar.c index 46320a04..4570be50 100644 --- a/src/ui/statusbar.c +++ b/src/ui/statusbar.c @@ -173,7 +173,7 @@ status_bar_inactive(const int win) } void -status_bar_active(const int win, win_type_t wintype, char *identifier) +_create_tab(const int win, win_type_t wintype, char *identifier, gboolean highlight) { int true_win = win; if (true_win == 0) { @@ -182,7 +182,7 @@ status_bar_active(const int win, win_type_t wintype, char *identifier) StatusBarTab *tab = malloc(sizeof(StatusBarTab)); tab->identifier = strdup(identifier); - tab->highlight = FALSE; + tab->highlight = highlight; tab->window_type = wintype; tab->display_name = NULL; @@ -208,38 +208,15 @@ status_bar_active(const int win, win_type_t wintype, char *identifier) } void -status_bar_new(const int win, win_type_t wintype, char* identifier) +status_bar_active(const int win, win_type_t wintype, char *identifier) { - int true_win = win; - if (true_win == 0) { - true_win = 10; - } - - StatusBarTab *tab = malloc(sizeof(StatusBarTab)); - tab->identifier = strdup(identifier); - tab->highlight = TRUE; - tab->window_type = wintype; - tab->display_name = NULL; - - if (tab->window_type == WIN_CHAT) { - PContact contact = roster_get_contact(tab->identifier); - if (contact && p_contact_name(contact)) { - tab->display_name = strdup(p_contact_name(contact)); - } else { - char *pref = prefs_get_string(PREF_STATUSBAR_CHAT); - if (g_strcmp0("user", pref) == 0) { - Jid *jidp = jid_create(tab->identifier); - tab->display_name = strdup(jidp->localpart); - jid_destroy(jidp); - } else { - tab->display_name = strdup(tab->identifier); - } - } - } - - g_hash_table_replace(statusbar->tabs, GINT_TO_POINTER(true_win), tab); + _create_tab(win, wintype, identifier, FALSE); +} - status_bar_draw(); +void +status_bar_new(const int win, win_type_t wintype, char* identifier) +{ + _create_tab(win, wintype, identifier, TRUE); } void |