diff --git a/src/ui/core.c b/src/ui/core.c index 234d8f8e..4014f53e 100644 --- a/src/ui/core.c +++ b/src/ui/core.c @@ -333,7 +333,7 @@ _ui_incoming_msg(const char * const barejid, const char * const message, GTimeVa ProfWin *window = wins_get_by_recipient(barejid); if (window == NULL) { - window = wins_new(barejid, WIN_CHAT); + window = wins_new_chat(barejid); #ifdef HAVE_LIBOTR if (otr_is_secure(barejid)) { window->wins.chat.is_otr = TRUE; @@ -406,7 +406,7 @@ _ui_incoming_private_msg(const char * const fulljid, const char * const message, ProfWin *window = wins_get_by_recipient(fulljid); if (window == NULL) { - window = wins_new(fulljid, WIN_PRIVATE); + window = wins_new_private(fulljid); } int num = wins_get_num(window); diff --git a/src/ui/window.c b/src/ui/window.c index 8a6cc18d..0728674f 100644 --- a/src/ui/window.c +++ b/src/ui/window.c @@ -73,6 +73,56 @@ win_occpuants_cols(void) return CEILING( (((double)cols) / 100) * occupants_win_percent); } +ProfWin* +win_create_chat(const char * const barejid) +{ + ProfWin *new_win = malloc(sizeof(ProfWin)); + int cols = getmaxx(stdscr); + + new_win->type = WIN_CHAT; + + new_win->win = newpad(PAD_SIZE, (cols)); + wbkgd(new_win->win, theme_attrs(THEME_TEXT)); + + new_win->from = strdup(barejid); + new_win->buffer = buffer_create(); + new_win->y_pos = 0; + new_win->paged = 0; + new_win->unread = 0; + + new_win->wins.chat.resource = NULL; + new_win->wins.chat.is_otr = FALSE; + new_win->wins.chat.is_trusted = FALSE; + new_win->wins.chat.history_shown = FALSE; + + scrollok(new_win->win, TRUE); + + return new_win; +} + +ProfWin* +win_create_private(const char * const fulljid) +{ + ProfWin *new_win = malloc(sizeof(ProfWin)); + int cols = getmaxx(stdscr); + + new_win->type = WIN_PRIVATE; + + new_win->win = newpad(PAD_SIZE, (cols)); + wbkgd(new_win->win, theme_attrs(THEME_TEXT)); + + new_win->from = strdup(fulljid); + new_win->buffer = buffer_create(); + new_win->y_pos = 0; + new_win->paged = 0; + new_win->unread = 0; + + scrollok(new_win->win, TRUE); + + return new_win; + +} + ProfWin* win_create(const char * const title, win_type_t type) { diff --git a/src/ui/window.h b/src/ui/window.h index 4f855e39..c68546fc 100644 --- a/src/ui/window.h +++ b/src/ui/window.h @@ -111,6 +111,9 @@ typedef struct prof_win_t { } ProfWin; ProfWin* win_create(const char * const title, win_type_t type); +ProfWin* win_create_chat(const char * const barejid); +ProfWin* win_create_private(const char * const fulljid); + void win_free(ProfWin *window); void win_update_virtual(ProfWin *window); void win_move_to_end(ProfWin *window); diff --git a/src/ui/windows.c b/src/ui/windows.c index ca7bad36..a9d8228f 100644 --- a/src/ui/windows.c +++ b/src/ui/windows.c @@ -266,6 +266,28 @@ wins_new(const char * const from, win_type_t type) return new; } +ProfWin * +wins_new_chat(const char * const barejid) +{ + GList *keys = g_hash_table_get_keys(windows); + int result = get_next_available_win_num(keys); + ProfWin *new = win_create_chat(barejid); + g_hash_table_insert(windows, GINT_TO_POINTER(result), new); + g_list_free(keys); + return new; +} + +ProfWin * +wins_new_private(const char * const fulljid) +{ + GList *keys = g_hash_table_get_keys(windows); + int result = get_next_available_win_num(keys); + ProfWin *new = win_create_private(fulljid); + g_hash_table_insert(windows, GINT_TO_POINTER(result), new); + g_list_free(keys); + return new; +} + int wins_get_total_unread(void) { diff --git a/src/ui/windows.h b/src/ui/windows.h index 0b72ee0e..15210119 100644 --- a/src/ui/windows.h +++ b/src/ui/windows.h @@ -50,6 +50,8 @@ void wins_close_by_num(int i); void wins_clear_current(void); gboolean wins_is_current(ProfWin *window); ProfWin * wins_new(const char * const from, win_type_t type); +ProfWin * wins_new_chat(const char * const barejid); +ProfWin * wins_new_private(const char * const fulljid); int wins_get_total_unread(void); void wins_resize_all(void); GSList * wins_get_chat_recipients(void);