1
0
mirror of https://github.com/profanity-im/profanity.git synced 2024-12-04 14:46:46 -05:00

Refactored setting window recipient

This commit is contained in:
James Booth 2014-01-11 18:06:46 +00:00
parent d189f7ea43
commit bf494b1b07
2 changed files with 30 additions and 32 deletions

View File

@ -501,6 +501,24 @@ _ui_close_read_wins(void)
return count; return count;
} }
GString *
_get_recipient_string(ProfWin *window)
{
GString *result = g_string_new("");
PContact contact = roster_get_contact(window->from);
if (contact != NULL) {
if (p_contact_name(contact) != NULL) {
g_string_append(result, p_contact_name(contact));
} else {
g_string_append(result, window->from);
}
} else {
g_string_append(result, window->from);
}
return result;
}
static void static void
_ui_switch_win(const int i) _ui_switch_win(const int i)
{ {
@ -517,16 +535,9 @@ _ui_switch_win(const int i)
status_bar_current(1); status_bar_current(1);
status_bar_active(1); status_bar_active(1);
} else { } else {
PContact contact = roster_get_contact(new_current->from); GString *recipient_str = _get_recipient_string(new_current);
if (contact != NULL) { title_bar_set_recipient(recipient_str->str);
if (p_contact_name(contact) != NULL) { g_string_free(recipient_str, TRUE);
title_bar_set_recipient(p_contact_name(contact));
} else {
title_bar_set_recipient(new_current->from);
}
} else {
title_bar_set_recipient(new_current->from);
}
title_bar_draw(); title_bar_draw();
status_bar_current(i); status_bar_current(i);
status_bar_active(i); status_bar_active(i);
@ -551,16 +562,9 @@ _ui_next_win(void)
status_bar_current(1); status_bar_current(1);
status_bar_active(1); status_bar_active(1);
} else { } else {
PContact contact = roster_get_contact(new_current->from); GString *recipient_str = _get_recipient_string(new_current);
if (contact != NULL) { title_bar_set_recipient(recipient_str->str);
if (p_contact_name(contact) != NULL) { g_string_free(recipient_str, TRUE);
title_bar_set_recipient(p_contact_name(contact));
} else {
title_bar_set_recipient(new_current->from);
}
} else {
title_bar_set_recipient(new_current->from);
}
title_bar_draw(); title_bar_draw();
status_bar_current(i); status_bar_current(i);
status_bar_active(i); status_bar_active(i);
@ -584,16 +588,9 @@ _ui_previous_win(void)
status_bar_current(1); status_bar_current(1);
status_bar_active(1); status_bar_active(1);
} else { } else {
PContact contact = roster_get_contact(new_current->from); GString *recipient_str = _get_recipient_string(new_current);
if (contact != NULL) { title_bar_set_recipient(recipient_str->str);
if (p_contact_name(contact) != NULL) { g_string_free(recipient_str, TRUE);
title_bar_set_recipient(p_contact_name(contact));
} else {
title_bar_set_recipient(new_current->from);
}
} else {
title_bar_set_recipient(new_current->from);
}
title_bar_draw(); title_bar_draw();
status_bar_current(i); status_bar_current(i);
status_bar_active(i); status_bar_active(i);

View File

@ -29,7 +29,7 @@
static WINDOW *title_bar; static WINDOW *title_bar;
static char *current_title = NULL; static char *current_title = NULL;
static const char *recipient = NULL; static char *recipient = NULL;
static GTimer *typing_elapsed; static GTimer *typing_elapsed;
static int dirty; static int dirty;
static contact_presence_t current_status; static contact_presence_t current_status;
@ -132,7 +132,8 @@ _title_bar_set_recipient(const char * const from)
g_timer_destroy(typing_elapsed); g_timer_destroy(typing_elapsed);
typing_elapsed = NULL; typing_elapsed = NULL;
} }
recipient = from; free(recipient);
recipient = strdup(from);
if (current_title != NULL) { if (current_title != NULL) {
free(current_title); free(current_title);