diff options
author | James Booth <boothj5@gmail.com> | 2014-12-15 00:28:28 +0000 |
---|---|---|
committer | James Booth <boothj5@gmail.com> | 2014-12-15 00:28:28 +0000 |
commit | 070547a7ffbae5c1527a4ff7b5c36ad4e2b629b4 (patch) | |
tree | 85076d7afc87785185f067b78eaa1eb0a1804cb8 /src/ui | |
parent | 3cef4e1db4e10b0bf31e5a0447875f7a090c4a67 (diff) | |
download | profani-tty-070547a7ffbae5c1527a4ff7b5c36ad4e2b629b4.tar.gz |
Added window specific creation functions
Diffstat (limited to 'src/ui')
-rw-r--r-- | src/ui/core.c | 24 | ||||
-rw-r--r-- | src/ui/ui.h | 2 | ||||
-rw-r--r-- | src/ui/window.c | 128 | ||||
-rw-r--r-- | src/ui/window.h | 5 | ||||
-rw-r--r-- | src/ui/windows.c | 30 | ||||
-rw-r--r-- | src/ui/windows.h | 10 |
6 files changed, 136 insertions, 63 deletions
diff --git a/src/ui/core.c b/src/ui/core.c index 82ff5283..c6616c91 100644 --- a/src/ui/core.c +++ b/src/ui/core.c @@ -931,11 +931,11 @@ _ui_next_win(void) } static void -_ui_gone_secure(const char * const recipient, gboolean trusted) +_ui_gone_secure(const char * const barejid, gboolean trusted) { - ProfWin *window = wins_get_by_recipient(recipient); + ProfWin *window = wins_get_by_recipient(barejid); if (window == NULL) { - window = wins_new(recipient, WIN_CHAT); + window = wins_new_chat(barejid); } if (window->type != WIN_CHAT) { @@ -964,7 +964,7 @@ _ui_gone_secure(const char * const recipient, gboolean trusted) if (ui_index == 10) { ui_index = 0; } - cons_show("%s started an OTR session (%d).", recipient, ui_index); + cons_show("%s started an OTR session (%d).", barejid, ui_index); cons_alert(); } } @@ -1380,9 +1380,9 @@ _ui_new_chat_win(const char * const to) Jid *jid = jid_create(to); if (muc_active(jid->barejid)) { - window = wins_new(to, WIN_PRIVATE); + window = wins_new_private(to); } else { - window = wins_new(to, WIN_CHAT); + window = wins_new_chat(to); } jid_destroy(jid); @@ -1409,7 +1409,7 @@ _ui_new_chat_win(const char * const to) static void _ui_create_xmlconsole_win(void) { - ProfWin *window = wins_new("XML Console", WIN_XML); + ProfWin *window = wins_new_xmlconsole(); int num = wins_get_num(window); ui_switch_win(num); } @@ -1437,9 +1437,9 @@ _ui_outgoing_msg(const char * const from, const char * const to, Jid *jid = jid_create(to); if (muc_active(jid->barejid)) { - window = wins_new(to, WIN_PRIVATE); + window = wins_new_private(to); } else { - window = wins_new(to, WIN_CHAT); + window = wins_new_chat(to); #ifdef HAVE_LIBOTR if (otr_is_secure(to)) { window->wins.chat.is_otr = TRUE; @@ -1479,7 +1479,7 @@ _ui_room_join(const char * const room, gboolean focus) // create new window if (window == NULL) { - window = wins_new(room, WIN_MUC); + window = wins_new_muc(room); } char *nick = muc_nick(room); @@ -2715,11 +2715,9 @@ _ui_handle_room_configuration(const char * const room, DataForm *form) { GString *title = g_string_new(room); g_string_append(title, " config"); - ProfWin *window = wins_new(title->str, WIN_MUC_CONFIG); + ProfWin *window = wins_new_muc_config(title->str, form); g_string_free(title, TRUE); - window->wins.conf.form = form; - int num = wins_get_num(window); ui_switch_win(num); diff --git a/src/ui/ui.h b/src/ui/ui.h index f7a870f9..da43a5e1 100644 --- a/src/ui/ui.h +++ b/src/ui/ui.h @@ -70,7 +70,7 @@ gboolean (*ui_switch_win)(const int i); void (*ui_next_win)(void); void (*ui_previous_win)(void); -void (*ui_gone_secure)(const char * const recipient, gboolean trusted); +void (*ui_gone_secure)(const char * const barejid, gboolean trusted); void (*ui_gone_insecure)(const char * const recipient); void (*ui_trust)(const char * const recipient); void (*ui_untrust)(const char * const recipient); diff --git a/src/ui/window.c b/src/ui/window.c index 0728674f..90c819e5 100644 --- a/src/ui/window.c +++ b/src/ui/window.c @@ -51,6 +51,9 @@ #include "ui/window.h" #include "xmpp/xmpp.h" +#define CONS_WIN_TITLE "_cons" +#define XML_WIN_TITLE "XML Console" + #define CEILING(X) (X-(int)(X) > 0 ? (int)(X+1) : (int)(X)) static void _win_print(ProfWin *window, const char show_char, GDateTime *time, @@ -74,6 +77,30 @@ win_occpuants_cols(void) } ProfWin* +win_create_console(void) +{ + ProfWin *new_win = malloc(sizeof(ProfWin)); + int cols = getmaxx(stdscr); + + new_win->type = WIN_CONSOLE; + + new_win->win = newpad(PAD_SIZE, (cols)); + wbkgd(new_win->win, theme_attrs(THEME_TEXT)); + new_win->wins.cons.subwin = NULL; + new_win->wins.cons.sub_y_pos = 0; + + new_win->from = strdup(CONS_WIN_TITLE); + 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_chat(const char * const barejid) { ProfWin *new_win = malloc(sizeof(ProfWin)); @@ -101,6 +128,62 @@ win_create_chat(const char * const barejid) } ProfWin* +win_create_muc(const char * const roomjid) +{ + ProfWin *new_win = malloc(sizeof(ProfWin)); + int cols = getmaxx(stdscr); + + new_win->type = WIN_MUC; + + if (prefs_get_boolean(PREF_OCCUPANTS)) { + int subwin_cols = win_occpuants_cols(); + new_win->win = newpad(PAD_SIZE, cols - subwin_cols); + wbkgd(new_win->win, theme_attrs(THEME_TEXT)); + new_win->wins.muc.subwin = newpad(PAD_SIZE, subwin_cols);; + wbkgd(new_win->wins.muc.subwin, theme_attrs(THEME_TEXT)); + } else { + new_win->win = newpad(PAD_SIZE, (cols)); + wbkgd(new_win->win, theme_attrs(THEME_TEXT)); + new_win->wins.muc.subwin = NULL; + } + new_win->wins.muc.sub_y_pos = 0; + + new_win->from = strdup(roomjid); + 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_muc_config(const char * const title, DataForm *form) +{ + ProfWin *new_win = malloc(sizeof(ProfWin)); + int cols = getmaxx(stdscr); + + new_win->type = WIN_MUC_CONFIG; + + new_win->win = newpad(PAD_SIZE, (cols)); + wbkgd(new_win->win, theme_attrs(THEME_TEXT)); + + new_win->wins.conf.form = form; + + new_win->from = strdup(title); + 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_private(const char * const fulljid) { ProfWin *new_win = malloc(sizeof(ProfWin)); @@ -124,57 +207,22 @@ win_create_private(const char * const fulljid) } ProfWin* -win_create(const char * const title, win_type_t type) +win_create_xmlconsole(void) { ProfWin *new_win = malloc(sizeof(ProfWin)); int cols = getmaxx(stdscr); - new_win->type = type; + new_win->type = WIN_XML; - switch (new_win->type) { - case WIN_CONSOLE: - new_win->win = newpad(PAD_SIZE, (cols)); - wbkgd(new_win->win, theme_attrs(THEME_TEXT)); - new_win->wins.cons.subwin = NULL; - new_win->wins.cons.sub_y_pos = 0; - break; - case WIN_MUC: - if (prefs_get_boolean(PREF_OCCUPANTS)) { - int subwin_cols = win_occpuants_cols(); - new_win->win = newpad(PAD_SIZE, cols - subwin_cols); - wbkgd(new_win->win, theme_attrs(THEME_TEXT)); - new_win->wins.muc.subwin = newpad(PAD_SIZE, subwin_cols);; - wbkgd(new_win->wins.muc.subwin, theme_attrs(THEME_TEXT)); - } else { - new_win->win = newpad(PAD_SIZE, (cols)); - wbkgd(new_win->win, theme_attrs(THEME_TEXT)); - new_win->wins.muc.subwin = NULL; - } - new_win->wins.muc.sub_y_pos = 0; - break; - default: - new_win->win = newpad(PAD_SIZE, (cols)); - wbkgd(new_win->win, theme_attrs(THEME_TEXT)); - break; - } - - if (new_win->type == WIN_MUC_CONFIG) { - new_win->wins.conf.form = NULL; - } + new_win->win = newpad(PAD_SIZE, (cols)); + wbkgd(new_win->win, theme_attrs(THEME_TEXT)); - new_win->from = strdup(title); + new_win->from = strdup(XML_WIN_TITLE); new_win->buffer = buffer_create(); new_win->y_pos = 0; new_win->paged = 0; new_win->unread = 0; - if (new_win->type == WIN_CHAT) { - 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; diff --git a/src/ui/window.h b/src/ui/window.h index c68546fc..65dcb4f7 100644 --- a/src/ui/window.h +++ b/src/ui/window.h @@ -110,9 +110,12 @@ typedef struct prof_win_t { } wins; } ProfWin; -ProfWin* win_create(const char * const title, win_type_t type); +ProfWin* win_create_console(void); ProfWin* win_create_chat(const char * const barejid); +ProfWin* win_create_muc(const char * const roomjid); +ProfWin* win_create_muc_config(const char * const title, DataForm *form); ProfWin* win_create_private(const char * const fulljid); +ProfWin* win_create_xmlconsole(void); void win_free(ProfWin *window); void win_update_virtual(ProfWin *window); diff --git a/src/ui/windows.c b/src/ui/windows.c index a9d8228f..6d7e1f50 100644 --- a/src/ui/windows.c +++ b/src/ui/windows.c @@ -52,8 +52,6 @@ #include "ui/window.h" #include "ui/windows.h" -#define CONS_WIN_TITLE "_cons" - static GHashTable *windows; static int current; static int max_cols; @@ -65,7 +63,7 @@ wins_init(void) (GDestroyNotify)win_free); max_cols = getmaxx(stdscr); - ProfWin *console = win_create(CONS_WIN_TITLE, WIN_CONSOLE); + ProfWin *console = win_create_console(); g_hash_table_insert(windows, GINT_TO_POINTER(1), console); current = 1; @@ -256,11 +254,11 @@ wins_is_current(ProfWin *window) } ProfWin * -wins_new(const char * const from, win_type_t type) +wins_new_xmlconsole(void) { GList *keys = g_hash_table_get_keys(windows); int result = get_next_available_win_num(keys); - ProfWin *new = win_create(from, type); + ProfWin *new = win_create_xmlconsole(); g_hash_table_insert(windows, GINT_TO_POINTER(result), new); g_list_free(keys); return new; @@ -278,6 +276,28 @@ wins_new_chat(const char * const barejid) } ProfWin * +wins_new_muc(const char * const roomjid) +{ + GList *keys = g_hash_table_get_keys(windows); + int result = get_next_available_win_num(keys); + ProfWin *new = win_create_muc(roomjid); + g_hash_table_insert(windows, GINT_TO_POINTER(result), new); + g_list_free(keys); + return new; +} + +ProfWin * +wins_new_muc_config(const char * const title, DataForm *form) +{ + GList *keys = g_hash_table_get_keys(windows); + int result = get_next_available_win_num(keys); + ProfWin *new = win_create_muc_config(title, form); + 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); diff --git a/src/ui/windows.h b/src/ui/windows.h index 15210119..6d90c655 100644 --- a/src/ui/windows.h +++ b/src/ui/windows.h @@ -36,6 +36,13 @@ #define UI_WINDOWS_H void wins_init(void); + +ProfWin * wins_new_xmlconsole(void); +ProfWin * wins_new_chat(const char * const barejid); +ProfWin * wins_new_muc(const char * const roomjid); +ProfWin * wins_new_muc_config(const char * const title, DataForm *form); +ProfWin * wins_new_private(const char * const fulljid); + ProfWin * wins_get_console(void); ProfWin * wins_get_current(void); void wins_set_current_by_num(int i); @@ -49,9 +56,6 @@ void wins_close_current(void); 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); |