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

Added win create functions for chat and private chat

This commit is contained in:
James Booth 2014-12-10 22:34:33 +00:00
parent 9ba5a576ba
commit 8e46b9e75b
5 changed files with 79 additions and 2 deletions

View File

@ -333,7 +333,7 @@ _ui_incoming_msg(const char * const barejid, const char * const message, GTimeVa
ProfWin *window = wins_get_by_recipient(barejid); ProfWin *window = wins_get_by_recipient(barejid);
if (window == NULL) { if (window == NULL) {
window = wins_new(barejid, WIN_CHAT); window = wins_new_chat(barejid);
#ifdef HAVE_LIBOTR #ifdef HAVE_LIBOTR
if (otr_is_secure(barejid)) { if (otr_is_secure(barejid)) {
window->wins.chat.is_otr = TRUE; 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); ProfWin *window = wins_get_by_recipient(fulljid);
if (window == NULL) { if (window == NULL) {
window = wins_new(fulljid, WIN_PRIVATE); window = wins_new_private(fulljid);
} }
int num = wins_get_num(window); int num = wins_get_num(window);

View File

@ -73,6 +73,56 @@ win_occpuants_cols(void)
return CEILING( (((double)cols) / 100) * occupants_win_percent); 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* ProfWin*
win_create(const char * const title, win_type_t type) win_create(const char * const title, win_type_t type)
{ {

View File

@ -111,6 +111,9 @@ typedef struct prof_win_t {
} ProfWin; } ProfWin;
ProfWin* win_create(const char * const title, win_type_t type); 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_free(ProfWin *window);
void win_update_virtual(ProfWin *window); void win_update_virtual(ProfWin *window);
void win_move_to_end(ProfWin *window); void win_move_to_end(ProfWin *window);

View File

@ -266,6 +266,28 @@ wins_new(const char * const from, win_type_t type)
return new; 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 int
wins_get_total_unread(void) wins_get_total_unread(void)
{ {

View File

@ -50,6 +50,8 @@ void wins_close_by_num(int i);
void wins_clear_current(void); void wins_clear_current(void);
gboolean wins_is_current(ProfWin *window); gboolean wins_is_current(ProfWin *window);
ProfWin * wins_new(const char * const from, win_type_t type); 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); int wins_get_total_unread(void);
void wins_resize_all(void); void wins_resize_all(void);
GSList * wins_get_chat_recipients(void); GSList * wins_get_chat_recipients(void);