diff options
author | Michael Vetter <jubalh@iodoru.org> | 2023-04-10 20:21:06 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-04-10 20:21:06 +0200 |
commit | e3beac414eefede6ef09069b6f0ad783505676e3 (patch) | |
tree | 792b446d55b5a2a9a306816b3a399326643132b6 | |
parent | 54cf152130fe7829740a20780533ca2c8d957135 (diff) | |
parent | 7d290b04d50c59075d7cd6efa0650f7b8b9d4c77 (diff) | |
download | profani-tty-e3beac414eefede6ef09069b6f0ad783505676e3.tar.gz |
Merge pull request #1817 from H3rnand3zzz/feature/full-jid
JID Display in Titlebar and Fix
-rw-r--r-- | src/command/cmd_defs.c | 4 | ||||
-rw-r--r-- | src/ui/statusbar.c | 52 | ||||
-rw-r--r-- | src/ui/window.c | 26 |
3 files changed, 57 insertions, 25 deletions
diff --git a/src/command/cmd_defs.c b/src/command/cmd_defs.c index b985464f..574b9656 100644 --- a/src/command/cmd_defs.c +++ b/src/command/cmd_defs.c @@ -1260,8 +1260,8 @@ static const struct cmd_t command_defs[] = { { "show tls", "Show or hide TLS indicator in the titlebar." }, { "show encwarn", "Enable or disable the unencrypted warning message in the titlebar." }, { "show resource", "Show or hide the current resource in the titlebar." }, - { "show name", "In case of a MUC. Show the MUC name in the titlebar." }, - { "show jid", "In case of a MUC. Show the JID in the titlebar." }) + { "show name", "Show the nickname or MUC name in the titlebar." }, + { "show jid", "Show the JID in the titlebar." }) CMD_EXAMPLES( "/titlebar up", "/titlebar show tls", diff --git a/src/ui/statusbar.c b/src/ui/statusbar.c index 38d28c31..08ecdcd7 100644 --- a/src/ui/statusbar.c +++ b/src/ui/statusbar.c @@ -182,10 +182,7 @@ status_bar_inactive(const int win) void _create_tab(const int win, win_type_t wintype, char* identifier, gboolean highlight) { - int true_win = win; - if (true_win == 0) { - true_win = 10; - } + int true_win = win == 0 ? 10 : win; StatusBarTab* tab = malloc(sizeof(StatusBarTab)); tab->identifier = strdup(identifier); @@ -198,11 +195,12 @@ _create_tab(const int win, win_type_t wintype, char* identifier, gboolean highli if (roster_exists()) { 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) { + const char* pcontact_name = contact ? p_contact_name(contact) : NULL; + auto_char char* pref = prefs_get_string(PREF_STATUSBAR_CHAT); + if (g_strcmp0("user", pref) == 0) { + if (pcontact_name) { + tab->display_name = strdup(pcontact_name); + } else { Jid* jidp = jid_create(tab->identifier); if (jidp) { tab->display_name = jidp->localpart != NULL ? strdup(jidp->localpart) : strdup(jidp->barejid); @@ -210,10 +208,9 @@ _create_tab(const int win, win_type_t wintype, char* identifier, gboolean highli } else { tab->display_name = strdup(tab->identifier); } - } else { - tab->display_name = strdup(tab->identifier); } - g_free(pref); + } else { + tab->display_name = strdup(tab->identifier); } } @@ -518,12 +515,17 @@ _status_bar_draw_maintext(int pos) const char* maintext = NULL; auto_jid Jid* jidp = NULL; auto_char char* self = prefs_get_string(PREF_STATUSBAR_SELF); + if (statusbar->prompt) { mvwprintw(statusbar_win, 0, pos, "%s", statusbar->prompt); return utf8_display_len(statusbar->prompt); - } else if (g_strcmp0(self, "off") == 0) { + } + + if (g_strcmp0(self, "off") == 0) { return pos; - } else if (statusbar->fulljid) { + } + + if (statusbar->fulljid) { jidp = jid_create(statusbar->fulljid); if (g_strcmp0(self, "user") == 0) { maintext = jidp->localpart; @@ -538,6 +540,28 @@ _status_bar_draw_maintext(int pos) return pos; } + if (statusbar->fulljid) { + auto_char char* pref = prefs_get_string(PREF_STATUSBAR_SELF); + + if (g_strcmp0(pref, "off") == 0) { + return pos; + } + if (g_strcmp0(pref, "user") == 0) { + Jid* jidp = jid_create(statusbar->fulljid); + mvwprintw(statusbar_win, 0, pos, "%s", jidp->localpart); + jid_destroy(jidp); + return pos; + } + if (g_strcmp0(pref, "barejid") == 0) { + Jid* jidp = jid_create(statusbar->fulljid); + mvwprintw(statusbar_win, 0, pos, "%s", jidp->barejid); + jid_destroy(jidp); + return pos; + } + + mvwprintw(statusbar_win, 0, pos, "%s", statusbar->fulljid); + } + gboolean actlist_tabmode = _tabmode_is_actlist(); auto_gchar gchar* maintext_ = NULL; if (actlist_tabmode) { diff --git a/src/ui/window.c b/src/ui/window.c index c1d5edf3..e5b90f7b 100644 --- a/src/ui/window.c +++ b/src/ui/window.c @@ -312,18 +312,26 @@ win_get_title(ProfWin* window) { ProfChatWin* chatwin = (ProfChatWin*)window; assert(chatwin->memcheck == PROFCHATWIN_MEMCHECK); + + gboolean show_titlebar_jid = prefs_get_boolean(PREF_TITLEBAR_MUC_TITLE_JID); + gboolean show_titlebar_name = prefs_get_boolean(PREF_TITLEBAR_MUC_TITLE_NAME); jabber_conn_status_t conn_status = connection_get_status(); - if (conn_status == JABBER_CONNECTED) { - PContact contact = roster_get_contact(chatwin->barejid); - if (contact) { - const char* name = p_contact_name_or_jid(contact); - return strdup(name); - } else { - return strdup(chatwin->barejid); - } - } else { + + if (conn_status != JABBER_CONNECTED || !show_titlebar_name) { return strdup(chatwin->barejid); } + PContact contact = roster_get_contact(chatwin->barejid); + if (!contact) { + return strdup(chatwin->barejid); + } + const char* name = p_contact_name(contact); + if (name == NULL) { + return strdup(chatwin->barejid); + } + if (show_titlebar_jid) { + return g_strdup_printf("%s <%s>", name, chatwin->barejid); + } + return g_strdup_printf("%s", name); } case WIN_MUC: { |