diff options
author | James Booth <boothj5@gmail.com> | 2015-04-30 22:10:03 +0100 |
---|---|---|
committer | James Booth <boothj5@gmail.com> | 2015-04-30 22:10:03 +0100 |
commit | a3a4b6267b02d69761e64403aa131553c946fa96 (patch) | |
tree | d2e34fad4f0252a18e64022340c092de5de08704 | |
parent | 7730674f457a490c89d9a607988889296c2f2d27 (diff) | |
parent | d68fb25ddef2f30c9d17991aa5d1d0e2a36d8386 (diff) | |
download | profani-tty-a3a4b6267b02d69761e64403aa131553c946fa96.tar.gz |
Merge branch 'master' into pgp
-rw-r--r-- | Makefile.am | 1 | ||||
-rw-r--r-- | src/command/commands.c | 24 | ||||
-rw-r--r-- | src/ui/core.c | 104 | ||||
-rw-r--r-- | src/ui/inputwin.c | 32 | ||||
-rw-r--r-- | src/ui/ui.h | 3 | ||||
-rw-r--r-- | src/ui/windows.c | 8 | ||||
-rw-r--r-- | tests/test_cmd_win.c | 41 | ||||
-rw-r--r-- | tests/test_cmd_win.h | 2 | ||||
-rw-r--r-- | tests/testsuite.c | 4 | ||||
-rw-r--r-- | tests/ui/stub_ui.c | 12 |
10 files changed, 77 insertions, 154 deletions
diff --git a/Makefile.am b/Makefile.am index 4f7f2c3d..6b59da17 100644 --- a/Makefile.am +++ b/Makefile.am @@ -82,7 +82,6 @@ tests_sources = \ tests/test_cmd_roster.c tests/test_cmd_roster.h \ tests/test_cmd_statuses.c tests/test_cmd_statuses.h \ tests/test_cmd_sub.c tests/test_cmd_sub.h \ - tests/test_cmd_win.c tests/test_cmd_win.h \ tests/test_cmd_disconnect.c tests/test_cmd_disconnect.h \ tests/test_common.c tests/test_common.h \ tests/test_contact.c tests/test_contact.h \ diff --git a/src/command/commands.c b/src/command/commands.c index 150ee364..51c6ceb4 100644 --- a/src/command/commands.c +++ b/src/command/commands.c @@ -733,10 +733,16 @@ gboolean cmd_win(gchar **args, struct cmd_help_t help) { int num = atoi(args[0]); - gboolean switched = ui_switch_win_num(num); - if (switched == FALSE) { + + ProfWin *window = wins_get_by_num(num); + if (!window) { cons_show("Window %d does not exist.", num); + } else { + if (!wins_is_current(window)) { + ui_ev_focus_win(window); + } } + return TRUE; } @@ -2464,12 +2470,11 @@ cmd_form(gchar **args, struct cmd_help_t help) cmd_autocomplete_remove_form_fields(confwin->form); } wins_close_current(); - ProfWin *current = (ProfWin*)wins_get_muc(confwin->roomjid); - if (current == NULL) { - current = wins_get_console(); + ProfWin *new_current = (ProfWin*)wins_get_muc(confwin->roomjid); + if (!new_current) { + new_current = wins_get_console(); } - int num = wins_get_num(current); - ui_switch_win_num(num); + ui_ev_focus_win(new_current); } return TRUE; @@ -2775,9 +2780,8 @@ cmd_room(gchar **args, struct cmd_help_t help) if (g_strcmp0(args[0], "config") == 0) { ProfMucConfWin *confwin = wins_get_muc_conf(mucwin->roomjid); - if (confwin != NULL) { - num = wins_get_num(window); - ui_switch_win_num(num); + if (confwin) { + ui_ev_focus_win((ProfWin*)confwin); } else { iq_request_room_config_form(mucwin->roomjid); } diff --git a/src/ui/core.c b/src/ui/core.c index 59144223..22cf1168 100644 --- a/src/ui/core.c +++ b/src/ui/core.c @@ -865,45 +865,32 @@ ui_win_has_unsaved_form(int num) } } -gboolean -ui_switch_win(ProfWin *win) +void +ui_switch_win(ProfWin *window) { - int num = wins_get_num(win); - return ui_switch_win_num(num); -} + assert(window != NULL); -gboolean -ui_switch_win_num(const int i) -{ - ProfWin *window = wins_get_by_num(i); - if (window) { - ProfWin *old_current = wins_get_current(); - if (old_current->type == WIN_MUC_CONFIG) { - ProfMucConfWin *confwin = (ProfMucConfWin*)old_current; - cmd_autocomplete_remove_form_fields(confwin->form); - } + ProfWin *old_current = wins_get_current(); + if (old_current->type == WIN_MUC_CONFIG) { + ProfMucConfWin *confwin = (ProfMucConfWin*)old_current; + cmd_autocomplete_remove_form_fields(confwin->form); + } - ProfWin *new_current = wins_get_by_num(i); - if (new_current->type == WIN_MUC_CONFIG) { - ProfMucConfWin *confwin = (ProfMucConfWin*)new_current; - cmd_autocomplete_add_form_fields(confwin->form); - } + if (window->type == WIN_MUC_CONFIG) { + ProfMucConfWin *confwin = (ProfMucConfWin*)window; + cmd_autocomplete_add_form_fields(confwin->form); + } - wins_set_current_by_num(i); + int i = wins_get_num(window); + wins_set_current_by_num(i); - if (i == 1) { - title_bar_console(); - status_bar_current(1); - status_bar_active(1); - } else { - title_bar_switch(); - status_bar_current(i); - status_bar_active(i); - } - return TRUE; + if (i == 1) { + title_bar_console(); } else { - return FALSE; + title_bar_switch(); } + status_bar_current(i); + status_bar_active(i); } void @@ -1358,34 +1345,25 @@ void ui_new_private_win(const char * const fulljid) { ProfWin *window = (ProfWin*)wins_get_private(fulljid); - int num = 0; - - // create new window - if (window == NULL) { + if (!window) { window = wins_new_private(fulljid); - num = wins_get_num(window); - } else { - num = wins_get_num(window); } - - ui_switch_win_num(num); + ui_switch_win(window); } void ui_create_xmlconsole_win(void) { ProfWin *window = wins_new_xmlconsole(); - int num = wins_get_num(window); - ui_switch_win_num(num); + ui_switch_win(window); } void ui_open_xmlconsole_win(void) { ProfXMLWin *xmlwin = wins_get_xmlconsole(); - if (xmlwin != NULL) { - int num = wins_get_num((ProfWin*)xmlwin); - ui_switch_win_num(num); + if (xmlwin) { + ui_switch_win((ProfWin*)xmlwin); } } @@ -1452,30 +1430,19 @@ void ui_outgoing_private_msg(const char * const fulljid, const char * const message) { ProfWin *window = (ProfWin*)wins_get_private(fulljid); - int num = 0; - - // create new window - if (window == NULL) { + if (!window) { window = wins_new_private(fulljid); - num = wins_get_num(window); - - // use existing window - } else { - num = wins_get_num(window); } win_print(window, '-', NULL, 0, THEME_TEXT_ME, "me", message); - ui_switch_win_num(num); + ui_switch_win(window); } void ui_room_join(const char * const roomjid, gboolean focus) { ProfWin *window = (ProfWin*)wins_get_muc(roomjid); - int num = 0; - - // create new window - if (window == NULL) { + if (!window) { window = wins_new_muc(roomjid); } @@ -1493,11 +1460,11 @@ ui_room_join(const char * const roomjid, gboolean focus) } win_print(window, '!', NULL, NO_DATE, THEME_ROOMINFO, "", ""); - num = wins_get_num(window); if (focus) { - ui_switch_win_num(num); + ui_switch_win(window); } else { + int num = wins_get_num(window); status_bar_active(num); ProfWin *console = wins_get_console(); char *nick = muc_nick(roomjid); @@ -1509,8 +1476,7 @@ void ui_switch_to_room(const char * const roomjid) { ProfWin *window = (ProfWin*)wins_get_muc(roomjid); - int num = wins_get_num(window); - ui_switch_win_num(num); + ui_switch_win(window); } void @@ -2682,9 +2648,7 @@ ui_handle_room_configuration(const char * const roomjid, DataForm *form) ProfMucConfWin *confwin = (ProfMucConfWin*)window; assert(confwin->memcheck == PROFCONFWIN_MEMCHECK); - int num = wins_get_num(window); - ui_switch_win_num(num); - + ui_switch_win(window); ui_show_form(confwin); win_print(window, '-', NULL, 0, 0, "", ""); @@ -2739,11 +2703,11 @@ ui_handle_room_config_submit_result(const char * const roomjid) } if (muc_window) { - int num = wins_get_num(muc_window); - ui_switch_win_num(num); + ui_switch_win((ProfWin*)muc_window); win_print(muc_window, '!', NULL, 0, THEME_ROOMINFO, "", "Room configuration successful"); } else { - ui_switch_win_num(1); + ProfWin *console = wins_get_console(); + ui_switch_win(console); cons_show("Room configuration successful: %s", roomjid); } } else { diff --git a/src/ui/inputwin.c b/src/ui/inputwin.c index 935fd4ce..6cfbde47 100644 --- a/src/ui/inputwin.c +++ b/src/ui/inputwin.c @@ -63,6 +63,7 @@ #include "ui/statusbar.h" #include "ui/inputwin.h" #include "ui/windows.h" +#include "event/ui_events.h" #include "xmpp/xmpp.h" static WINDOW *inp_win; @@ -449,73 +450,84 @@ _inp_rl_tab_handler(int count, int key) return 0; } +static void +_go_to_win(int i) +{ + ProfWin *window = wins_get_by_num(i); + if (window) { + if (!wins_is_current(window)) { + ui_ev_focus_win(window); + } + } +} + static int _inp_rl_win1_handler(int count, int key) { - ui_switch_win_num(1); + _go_to_win(1); return 0; } static int _inp_rl_win2_handler(int count, int key) { - ui_switch_win_num(2); + _go_to_win(2); return 0; } static int _inp_rl_win3_handler(int count, int key) { - ui_switch_win_num(3); + _go_to_win(3); return 0; } static int _inp_rl_win4_handler(int count, int key) { - ui_switch_win_num(4); + _go_to_win(4); return 0; } static int _inp_rl_win5_handler(int count, int key) { - ui_switch_win_num(5); + _go_to_win(5); return 0; } static int _inp_rl_win6_handler(int count, int key) { - ui_switch_win_num(6); + _go_to_win(6); return 0; } static int _inp_rl_win7_handler(int count, int key) { - ui_switch_win_num(7); + _go_to_win(7); return 0; } static int _inp_rl_win8_handler(int count, int key) { - ui_switch_win_num(8); + _go_to_win(8); return 0; } static int _inp_rl_win9_handler(int count, int key) { - ui_switch_win_num(9); + _go_to_win(9); return 0; } static int _inp_rl_win0_handler(int count, int key) { - ui_switch_win_num(0); + _go_to_win(0); return 0; } diff --git a/src/ui/ui.h b/src/ui/ui.h index e42505bc..529e0f92 100644 --- a/src/ui/ui.h +++ b/src/ui/ui.h @@ -59,8 +59,7 @@ void ui_close(void); void ui_redraw(void); void ui_resize(void); GSList* ui_get_chat_recipients(void); -gboolean ui_switch_win_num(const int i); -gboolean ui_switch_win(ProfWin *win); +void ui_switch_win(ProfWin *window); void ui_next_win(void); void ui_previous_win(void); void ui_sigwinch_handler(int sig); diff --git a/src/ui/windows.c b/src/ui/windows.c index 269bea1d..4cc0fef7 100644 --- a/src/ui/windows.c +++ b/src/ui/windows.c @@ -644,6 +644,7 @@ gboolean wins_swap(int source_win, int target_win) { ProfWin *source = g_hash_table_lookup(windows, GINT_TO_POINTER(source_win)); + ProfWin *console = wins_get_console(); if (source) { ProfWin *target = g_hash_table_lookup(windows, GINT_TO_POINTER(target_win)); @@ -660,7 +661,7 @@ wins_swap(int source_win, int target_win) } if (wins_get_current_num() == source_win) { wins_set_current_by_num(target_win); - ui_switch_win_num(1); + ui_switch_win(console); } return TRUE; @@ -681,7 +682,7 @@ wins_swap(int source_win, int target_win) status_bar_active(source_win); } if ((wins_get_current_num() == source_win) || (wins_get_current_num() == target_win)) { - ui_switch_win_num(1); + ui_switch_win(console); } return TRUE; } @@ -740,7 +741,8 @@ wins_tidy(void) windows = new_windows; current = 1; - ui_switch_win_num(1); + ProfWin *console = wins_get_console(); + ui_switch_win(console); g_list_free(keys); return TRUE; } else { diff --git a/tests/test_cmd_win.c b/tests/test_cmd_win.c deleted file mode 100644 index 7ad01c49..00000000 --- a/tests/test_cmd_win.c +++ /dev/null @@ -1,41 +0,0 @@ -#include <stdarg.h> -#include <stddef.h> -#include <setjmp.h> -#include <cmocka.h> -#include <stdlib.h> -#include <glib.h> - -#include "ui/ui.h" -#include "ui/stub_ui.h" - -#include "command/commands.h" - -void cmd_win_shows_message_when_win_doesnt_exist(void **state) -{ - CommandHelp *help = malloc(sizeof(CommandHelp)); - gchar *args[] = { "3", NULL }; - - expect_value(ui_switch_win_num, i, 3); - will_return(ui_switch_win_num, FALSE); - - expect_cons_show("Window 3 does not exist."); - - gboolean result = cmd_win(args, *help); - assert_true(result); - - free(help); -} - -void cmd_win_switches_to_given_win_when_exists(void **state) -{ - CommandHelp *help = malloc(sizeof(CommandHelp)); - gchar *args[] = { "12", NULL }; - - expect_value(ui_switch_win_num, i, 12); - will_return(ui_switch_win_num, TRUE); - - gboolean result = cmd_win(args, *help); - assert_true(result); - - free(help); -} diff --git a/tests/test_cmd_win.h b/tests/test_cmd_win.h deleted file mode 100644 index a0f61a6b..00000000 --- a/tests/test_cmd_win.h +++ /dev/null @@ -1,2 +0,0 @@ -void cmd_win_shows_message_when_win_doesnt_exist(void **state); -void cmd_win_switches_to_given_win_when_exists(void **state); diff --git a/tests/testsuite.c b/tests/testsuite.c index 15682d1f..b4ce1c0a 100644 --- a/tests/testsuite.c +++ b/tests/testsuite.c @@ -31,7 +31,6 @@ #include "test_cmd_join.h" #include "test_muc.h" #include "test_cmd_roster.h" -#include "test_cmd_win.h" #include "test_cmd_disconnect.h" #include "test_form.h" @@ -586,9 +585,6 @@ int main(int argc, char* argv[]) { unit_test(cmd_roster_clearnick_shows_message_when_no_contact_exists), unit_test(cmd_roster_clearnick_sends_name_change_request_with_empty_nick), - unit_test(cmd_win_shows_message_when_win_doesnt_exist), - unit_test(cmd_win_switches_to_given_win_when_exists), - unit_test(get_form_type_field_returns_null_no_fields), unit_test(get_form_type_field_returns_null_when_not_present), unit_test(get_form_type_field_returns_value_when_present), diff --git a/tests/ui/stub_ui.c b/tests/ui/stub_ui.c index 16933e5d..1f812781 100644 --- a/tests/ui/stub_ui.c +++ b/tests/ui/stub_ui.c @@ -64,17 +64,7 @@ GSList* ui_get_chat_recipients(void) return NULL; } -gboolean ui_switch_win(ProfWin *win) -{ - return FALSE; -} - -gboolean ui_switch_win_num(const int i) -{ - check_expected(i); - return (gboolean)mock(); - return FALSE; -} +void ui_switch_win(ProfWin *win) {} void ui_next_win(void) {} void ui_previous_win(void) {} |