From 88739d5c59022b4d1f1b67da3128cb4a3266ecf9 Mon Sep 17 00:00:00 2001 From: James Booth Date: Tue, 21 Apr 2015 23:28:52 +0100 Subject: Moved new chat win events to client events module --- src/command/commands.c | 21 ++++++++++--- src/event/client_events.c | 13 ++++++++ src/event/client_events.h | 3 ++ src/ui/core.c | 80 +++++++++++++++++++++++------------------------ src/ui/inputwin.c | 20 ++++++------ src/ui/ui.h | 5 +-- src/ui/windows.c | 6 ++-- 7 files changed, 87 insertions(+), 61 deletions(-) (limited to 'src') diff --git a/src/command/commands.c b/src/command/commands.c index 0febccd8..713cd0ef 100644 --- a/src/command/commands.c +++ b/src/command/commands.c @@ -738,7 +738,7 @@ gboolean cmd_win(gchar **args, struct cmd_help_t help) { int num = atoi(args[0]); - gboolean switched = ui_switch_win(num); + gboolean switched = ui_switch_win_num(num); if (switched == FALSE) { cons_show("Window %d does not exist.", num); } @@ -1347,7 +1347,13 @@ cmd_msg(gchar **args, struct cmd_help_t help) client_send_msg(barejid, msg); return TRUE; } else { - ui_new_chat_win(barejid); + ProfWin *window = (ProfWin*)wins_get_chat(barejid); + if (window) { + client_focus_win(window); + } else { + client_new_chat_win(barejid); + } + #ifdef HAVE_LIBOTR if (otr_is_secure(barejid)) { ui_gone_secure(barejid, otr_is_trusted(barejid)); @@ -2467,7 +2473,7 @@ cmd_form(gchar **args, struct cmd_help_t help) current = wins_get_console(); } int num = wins_get_num(current); - ui_switch_win(num); + ui_switch_win_num(num); } return TRUE; @@ -2775,7 +2781,7 @@ cmd_room(gchar **args, struct cmd_help_t help) if (confwin != NULL) { num = wins_get_num(window); - ui_switch_win(num); + ui_switch_win_num(num); } else { iq_request_room_config_form(mucwin->roomjid); } @@ -4180,7 +4186,12 @@ cmd_otr(gchar **args, struct cmd_help_t help) barejid = contact; } - ui_new_chat_win(barejid); + ProfWin *window = (ProfWin*)wins_get_chat(barejid); + if (window) { + client_focus_win(window); + } else { + client_new_chat_win(barejid); + } if (ui_current_win_is_otr()) { ui_current_print_formatted_line('!', 0, "You are already in an OTR session."); diff --git a/src/event/client_events.c b/src/event/client_events.c index 615010e5..c580f700 100644 --- a/src/event/client_events.c +++ b/src/event/client_events.c @@ -96,4 +96,17 @@ client_send_priv_msg(const char * const fulljid, const char * const msg) { message_send_private(fulljid, msg); ui_outgoing_private_msg(fulljid, msg); +} + +void +client_focus_win(ProfWin *win) +{ + ui_switch_win(win); +} + +void +client_new_chat_win(const char * const barejid) +{ + ProfWin *win = ui_new_chat_win(barejid); + ui_switch_win(win); } \ No newline at end of file diff --git a/src/event/client_events.h b/src/event/client_events.h index e0ae3959..41764e73 100644 --- a/src/event/client_events.h +++ b/src/event/client_events.h @@ -39,4 +39,7 @@ void client_send_msg(const char * const barejid, const char * const msg); void client_send_muc_msg(const char * const roomjid, const char * const msg); void client_send_priv_msg(const char * const fulljid, const char * const msg); +void client_focus_win(ProfWin *win); +void client_new_chat_win(const char * const barejid); + #endif \ No newline at end of file diff --git a/src/ui/core.c b/src/ui/core.c index 9f8ac806..78faff18 100644 --- a/src/ui/core.c +++ b/src/ui/core.c @@ -878,7 +878,14 @@ ui_win_has_unsaved_form(int num) } gboolean -ui_switch_win(const int i) +ui_switch_win(ProfWin *win) +{ + int num = wins_get_num(win); + return ui_switch_win_num(num); +} + +gboolean +ui_switch_win_num(const int i) { if (ui_win_exists(i)) { ProfWin *old_current = wins_get_current(); @@ -1358,53 +1365,45 @@ ui_recipient_gone(const char * const barejid, const char * const resource) } } -void -ui_new_private_win(const char * const fulljid) +ProfWin* +ui_new_chat_win(const char * const barejid) { - ProfWin *window = (ProfWin*)wins_get_private(fulljid); - int num = 0; + ProfWin* window = wins_new_chat(barejid); - // create new window - if (window == NULL) { - window = wins_new_private(fulljid); - num = wins_get_num(window); - } else { - num = wins_get_num(window); + int num = wins_get_num(window); + + if (prefs_get_boolean(PREF_CHLOG) && prefs_get_boolean(PREF_HISTORY)) { + _win_show_history(num, barejid); + } + + // if the contact is offline, show a message + PContact contact = roster_get_contact(barejid); + if (contact != NULL) { + if (strcmp(p_contact_presence(contact), "offline") == 0) { + const char * const show = p_contact_presence(contact); + const char * const status = p_contact_status(contact); + win_show_status_string(window, barejid, show, status, NULL, "--", "offline"); + } } - ui_switch_win(num); + return window; } void -ui_new_chat_win(const char * const barejid) +ui_new_private_win(const char * const fulljid) { - ProfWin *window = (ProfWin*)wins_get_chat(barejid); + ProfWin *window = (ProfWin*)wins_get_private(fulljid); int num = 0; // create new window if (window == NULL) { - window = wins_new_chat(barejid); - + window = wins_new_private(fulljid); num = wins_get_num(window); - - if (prefs_get_boolean(PREF_CHLOG) && prefs_get_boolean(PREF_HISTORY)) { - _win_show_history(num, barejid); - } - - // if the contact is offline, show a message - PContact contact = roster_get_contact(barejid); - if (contact != NULL) { - if (strcmp(p_contact_presence(contact), "offline") == 0) { - const char * const show = p_contact_presence(contact); - const char * const status = p_contact_status(contact); - win_show_status_string(window, barejid, show, status, NULL, "--", "offline"); - } - } } else { num = wins_get_num(window); } - ui_switch_win(num); + ui_switch_win_num(num); } void @@ -1412,7 +1411,7 @@ ui_create_xmlconsole_win(void) { ProfWin *window = wins_new_xmlconsole(); int num = wins_get_num(window); - ui_switch_win(num); + ui_switch_win_num(num); } void @@ -1421,7 +1420,7 @@ ui_open_xmlconsole_win(void) ProfXMLWin *xmlwin = wins_get_xmlconsole(); if (xmlwin != NULL) { int num = wins_get_num((ProfWin*)xmlwin); - ui_switch_win(num); + ui_switch_win_num(num); } } @@ -1467,7 +1466,7 @@ ui_outgoing_chat_msg(const char * const barejid, const char * const message, cha } else { win_print(window, '-', NULL, 0, THEME_TEXT_ME, "me", message); } - ui_switch_win(num); + ui_switch_win_num(num); } void @@ -1528,7 +1527,7 @@ ui_outgoing_private_msg(const char * const fulljid, const char * const message) } win_print(window, '-', NULL, 0, THEME_TEXT_ME, "me", message); - ui_switch_win(num); + ui_switch_win_num(num); } void @@ -1559,7 +1558,7 @@ ui_room_join(const char * const roomjid, gboolean focus) num = wins_get_num(window); if (focus) { - ui_switch_win(num); + ui_switch_win_num(num); } else { status_bar_active(num); ProfWin *console = wins_get_console(); @@ -1573,8 +1572,7 @@ ui_switch_to_room(const char * const roomjid) { ProfWin *window = (ProfWin*)wins_get_muc(roomjid); int num = wins_get_num(window); - num = wins_get_num(window); - ui_switch_win(num); + ui_switch_win_num(num); } void @@ -2747,7 +2745,7 @@ ui_handle_room_configuration(const char * const roomjid, DataForm *form) assert(confwin->memcheck == PROFCONFWIN_MEMCHECK); int num = wins_get_num(window); - ui_switch_win(num); + ui_switch_win_num(num); ui_show_form(confwin); @@ -2804,10 +2802,10 @@ ui_handle_room_config_submit_result(const char * const roomjid) if (muc_window) { int num = wins_get_num(muc_window); - ui_switch_win(num); + ui_switch_win_num(num); win_print(muc_window, '!', NULL, 0, THEME_ROOMINFO, "", "Room configuration successful"); } else { - ui_switch_win(1); + ui_switch_win_num(1); cons_show("Room configuration successful: %s", roomjid); } } else { diff --git a/src/ui/inputwin.c b/src/ui/inputwin.c index f55be0f1..935fd4ce 100644 --- a/src/ui/inputwin.c +++ b/src/ui/inputwin.c @@ -452,70 +452,70 @@ _inp_rl_tab_handler(int count, int key) static int _inp_rl_win1_handler(int count, int key) { - ui_switch_win(1); + ui_switch_win_num(1); return 0; } static int _inp_rl_win2_handler(int count, int key) { - ui_switch_win(2); + ui_switch_win_num(2); return 0; } static int _inp_rl_win3_handler(int count, int key) { - ui_switch_win(3); + ui_switch_win_num(3); return 0; } static int _inp_rl_win4_handler(int count, int key) { - ui_switch_win(4); + ui_switch_win_num(4); return 0; } static int _inp_rl_win5_handler(int count, int key) { - ui_switch_win(5); + ui_switch_win_num(5); return 0; } static int _inp_rl_win6_handler(int count, int key) { - ui_switch_win(6); + ui_switch_win_num(6); return 0; } static int _inp_rl_win7_handler(int count, int key) { - ui_switch_win(7); + ui_switch_win_num(7); return 0; } static int _inp_rl_win8_handler(int count, int key) { - ui_switch_win(8); + ui_switch_win_num(8); return 0; } static int _inp_rl_win9_handler(int count, int key) { - ui_switch_win(9); + ui_switch_win_num(9); return 0; } static int _inp_rl_win0_handler(int count, int key) { - ui_switch_win(0); + ui_switch_win_num(0); return 0; } diff --git a/src/ui/ui.h b/src/ui/ui.h index fc1485ff..d5e9c28c 100644 --- a/src/ui/ui.h +++ b/src/ui/ui.h @@ -59,7 +59,8 @@ void ui_close(void); void ui_redraw(void); void ui_resize(void); GSList* ui_get_chat_recipients(void); -gboolean ui_switch_win(const int i); +gboolean ui_switch_win_num(const int i); +gboolean ui_switch_win(ProfWin *win); void ui_next_win(void); void ui_previous_win(void); void ui_sigwinch_handler(int sig); @@ -86,8 +87,8 @@ void ui_handle_otr_error(const char * const barejid, const char * const message) unsigned long ui_get_idle_time(void); void ui_reset_idle_time(void); -void ui_new_chat_win(const char * const barejid); void ui_new_private_win(const char * const fulljid); +ProfWin* ui_new_chat_win(const char * const barejid); void ui_print_system_msg_from_recipient(const char * const barejid, const char *message); gint ui_unread(void); void ui_close_connected_win(int index); diff --git a/src/ui/windows.c b/src/ui/windows.c index 993a51c1..269bea1d 100644 --- a/src/ui/windows.c +++ b/src/ui/windows.c @@ -660,7 +660,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(1); + ui_switch_win_num(1); } return TRUE; @@ -681,7 +681,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(1); + ui_switch_win_num(1); } return TRUE; } @@ -740,7 +740,7 @@ wins_tidy(void) windows = new_windows; current = 1; - ui_switch_win(1); + ui_switch_win_num(1); g_list_free(keys); return TRUE; } else { -- cgit 1.4.1-2-gfad0