From c8eaaa0ce918064a4009f706baac4a975999fc3f Mon Sep 17 00:00:00 2001 From: James Booth Date: Mon, 4 May 2015 01:31:27 +0100 Subject: [PATCH] Added ui_ev_new_private_win to ui events --- src/command/commands.c | 14 +++++++++----- src/event/client_events.c | 6 +++--- src/event/client_events.h | 2 +- src/event/ui_events.c | 6 ++++++ src/event/ui_events.h | 1 + src/ui/core.c | 19 +++++-------------- src/ui/ui.h | 4 ++-- tests/ui/stub_ui.c | 8 ++++++-- 8 files changed, 33 insertions(+), 27 deletions(-) diff --git a/src/command/commands.c b/src/command/commands.c index 21acc413..dfabc4f0 100644 --- a/src/command/commands.c +++ b/src/command/commands.c @@ -116,7 +116,7 @@ cmd_execute_default(const char * inp) case WIN_PRIVATE: { ProfPrivateWin *privatewin = wins_get_current_private(); - cl_ev_send_priv_msg(privatewin->fulljid, inp); + cl_ev_send_priv_msg(privatewin, inp); break; } case WIN_MUC: @@ -1310,10 +1310,14 @@ cmd_msg(gchar **args, struct cmd_help_t help) g_string_append(full_jid, "/"); g_string_append(full_jid, usr); + ProfPrivateWin *privwin = wins_get_private(full_jid->str); + if (!privwin) { + privwin = ui_ev_new_private_win(full_jid->str); + } + ui_ev_focus_win((ProfWin*)privwin); + if (msg) { - cl_ev_send_priv_msg(full_jid->str, msg); - } else { - ui_new_private_win(full_jid->str); + cl_ev_send_priv_msg(privwin, msg); } g_string_free(full_jid, TRUE); @@ -3149,7 +3153,7 @@ cmd_tiny(gchar **args, struct cmd_help_t help) case WIN_PRIVATE: { ProfPrivateWin *privatewin = wins_get_current_private(); - cl_ev_send_priv_msg(privatewin->fulljid, tiny); + cl_ev_send_priv_msg(privatewin, tiny); break; } case WIN_MUC: diff --git a/src/event/client_events.c b/src/event/client_events.c index 167dfac7..db8f6497 100644 --- a/src/event/client_events.c +++ b/src/event/client_events.c @@ -82,8 +82,8 @@ cl_ev_send_muc_msg(ProfMucWin *mucwin, const char * const msg) } void -cl_ev_send_priv_msg(const char * const fulljid, const char * const msg) +cl_ev_send_priv_msg(ProfPrivateWin *privwin, const char * const msg) { - message_send_private(fulljid, msg); - ui_outgoing_private_msg(fulljid, msg); + message_send_private(privwin->fulljid, msg); + ui_outgoing_private_msg(privwin, msg); } \ No newline at end of file diff --git a/src/event/client_events.h b/src/event/client_events.h index 3685cb2d..a7ecc583 100644 --- a/src/event/client_events.h +++ b/src/event/client_events.h @@ -40,6 +40,6 @@ jabber_conn_status_t cl_ev_connect_account(ProfAccount *account); void cl_ev_send_msg(ProfChatWin *chatwin, const char * const msg); void cl_ev_send_muc_msg(ProfMucWin *mucwin, const char * const msg); -void cl_ev_send_priv_msg(const char * const fulljid, const char * const msg); +void cl_ev_send_priv_msg(ProfPrivateWin *privwin, const char * const msg); #endif \ No newline at end of file diff --git a/src/event/ui_events.c b/src/event/ui_events.c index bebffc07..ff1d7273 100644 --- a/src/event/ui_events.c +++ b/src/event/ui_events.c @@ -47,4 +47,10 @@ ProfChatWin* ui_ev_new_chat_win(const char * const barejid) { return ui_new_chat_win(barejid); +} + +ProfPrivateWin* +ui_ev_new_private_win(const char * const fulljid) +{ + return ui_new_private_win(fulljid); } \ No newline at end of file diff --git a/src/event/ui_events.h b/src/event/ui_events.h index b7075e61..3f7fed02 100644 --- a/src/event/ui_events.h +++ b/src/event/ui_events.h @@ -37,5 +37,6 @@ void ui_ev_focus_win(ProfWin *win); ProfChatWin* ui_ev_new_chat_win(const char * const barejid); +ProfPrivateWin* ui_ev_new_private_win(const char * const fulljid); #endif \ No newline at end of file diff --git a/src/ui/core.c b/src/ui/core.c index b4cef52d..8c4d4644 100644 --- a/src/ui/core.c +++ b/src/ui/core.c @@ -1273,14 +1273,11 @@ ui_recipient_gone(const char * const barejid, const char * const resource) } } -void +ProfPrivateWin* ui_new_private_win(const char * const fulljid) { - ProfWin *window = (ProfWin*)wins_get_private(fulljid); - if (!window) { - window = wins_new_private(fulljid); - } - ui_ev_focus_win(window); + ProfWin *window = wins_new_private(fulljid); + return (ProfPrivateWin*)window; } void @@ -1357,15 +1354,9 @@ ui_outgoing_chat_msg_carbon(const char * const barejid, const char * const messa } void -ui_outgoing_private_msg(const char * const fulljid, const char * const message) +ui_outgoing_private_msg(ProfPrivateWin *privwin, const char * const message) { - ProfWin *window = (ProfWin*)wins_get_private(fulljid); - if (!window) { - window = wins_new_private(fulljid); - } - - win_print(window, '-', NULL, 0, THEME_TEXT_ME, "me", message); - ui_ev_focus_win(window); + win_print((ProfWin*)privwin, '-', NULL, 0, THEME_TEXT_ME, "me", message); } void diff --git a/src/ui/ui.h b/src/ui/ui.h index 212ed451..c98d45e8 100644 --- a/src/ui/ui.h +++ b/src/ui/ui.h @@ -84,7 +84,7 @@ 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_private_win(const char * const fulljid); +ProfPrivateWin* ui_new_private_win(const char * const fulljid); ProfChatWin* 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); @@ -122,7 +122,7 @@ void ui_recipient_gone(const char * const barejid, const char * const resource); void ui_outgoing_chat_msg(ProfChatWin *chatwin, const char * const message, char *id); void ui_outgoing_chat_msg_carbon(const char * const barejid, const char * const message); -void ui_outgoing_private_msg(const char * const fulljid, const char * const message); +void ui_outgoing_private_msg(ProfPrivateWin *privwin, const char * const message); void ui_room_join(const char * const roomjid, gboolean focus); void ui_switch_to_room(const char * const roomjid); diff --git a/tests/ui/stub_ui.c b/tests/ui/stub_ui.c index ac5fe7c9..c23723e1 100644 --- a/tests/ui/stub_ui.c +++ b/tests/ui/stub_ui.c @@ -91,7 +91,11 @@ unsigned long ui_get_idle_time(void) } void ui_reset_idle_time(void) {} -void ui_new_private_win(const char * const fulljid) {} +ProfPrivateWin* ui_new_private_win(const char * const fulljid) +{ + return NULL; +} + ProfChatWin* ui_new_chat_win(const char * const barejid) { return NULL; @@ -192,7 +196,7 @@ void ui_recipient_gone(const char * const barejid, const char * const resource) void ui_outgoing_chat_msg(ProfChatWin *chatwin, const char * const message, char *id) {} void ui_outgoing_chat_msg_carbon(const char * const barejid, const char * const message) {} -void ui_outgoing_private_msg(const char * const fulljid, const char * const message) {} +void ui_outgoing_private_msg(ProfPrivateWin *privwin, const char * const message) {} void ui_room_join(const char * const roomjid, gboolean focus) {} void ui_switch_to_room(const char * const roomjid) {}