From 486d2e049584c9626ecf26f722cb5101ec9a250a Mon Sep 17 00:00:00 2001 From: James Booth Date: Sun, 1 Nov 2015 19:26:31 +0000 Subject: [PATCH 1/5] Removed ui_xmlconsole_exists --- src/command/commands.c | 7 +++-- src/ui/core.c | 56 +++++++++++++++--------------------- src/ui/ui.h | 1 - tests/unittests/ui/stub_ui.c | 4 --- 4 files changed, 27 insertions(+), 41 deletions(-) diff --git a/src/command/commands.c b/src/command/commands.c index 5da5f3f8..037ec453 100644 --- a/src/command/commands.c +++ b/src/command/commands.c @@ -4397,10 +4397,11 @@ cmd_vercheck(ProfWin *window, const char *const command, gchar **args) gboolean cmd_xmlconsole(ProfWin *window, const char *const command, gchar **args) { - if (!ui_xmlconsole_exists()) { - ui_create_xmlconsole_win(); - } else { + ProfXMLWin *xmlwin = wins_get_xmlconsole(); + if (xmlwin) { ui_open_xmlconsole_win(); + } else { + ui_create_xmlconsole_win(); } return TRUE; diff --git a/src/ui/core.c b/src/ui/core.c index f5b365be..340d54d5 100644 --- a/src/ui/core.c +++ b/src/ui/core.c @@ -222,33 +222,39 @@ ui_load_colours(void) } } -gboolean -ui_xmlconsole_exists(void) +void +ui_create_xmlconsole_win(void) +{ + ProfWin *window = wins_new_xmlconsole(); + ui_switch_win(window); +} + +void +ui_open_xmlconsole_win(void) { ProfXMLWin *xmlwin = wins_get_xmlconsole(); if (xmlwin) { - return TRUE; - } else { - return FALSE; + ui_switch_win((ProfWin*)xmlwin); } } void ui_handle_stanza(const char *const msg) { - if (ui_xmlconsole_exists()) { - ProfXMLWin *xmlconsole = wins_get_xmlconsole(); - ProfWin *window = (ProfWin*) xmlconsole; + ProfXMLWin *xmlwin = wins_get_xmlconsole(); + if (!xmlwin) { + return; + } - if (g_str_has_prefix(msg, "SENT:")) { - win_print(window, '-', 0, NULL, 0, 0, "", "SENT:"); - win_print(window, '-', 0, NULL, 0, THEME_ONLINE, "", &msg[6]); - win_print(window, '-', 0, NULL, 0, THEME_ONLINE, "", ""); - } else if (g_str_has_prefix(msg, "RECV:")) { - win_print(window, '-', 0, NULL, 0, 0, "", "RECV:"); - win_print(window, '-', 0, NULL, 0, THEME_AWAY, "", &msg[6]); - win_print(window, '-', 0, NULL, 0, THEME_AWAY, "", ""); - } + ProfWin *window = (ProfWin*)xmlwin; + if (g_str_has_prefix(msg, "SENT:")) { + win_print(window, '-', 0, NULL, 0, 0, "", "SENT:"); + win_print(window, '-', 0, NULL, 0, THEME_ONLINE, "", &msg[6]); + win_print(window, '-', 0, NULL, 0, THEME_ONLINE, "", ""); + } else if (g_str_has_prefix(msg, "RECV:")) { + win_print(window, '-', 0, NULL, 0, 0, "", "RECV:"); + win_print(window, '-', 0, NULL, 0, THEME_AWAY, "", &msg[6]); + win_print(window, '-', 0, NULL, 0, THEME_AWAY, "", ""); } } @@ -897,22 +903,6 @@ ui_new_private_win(const char *const fulljid) return (ProfPrivateWin*)window; } -void -ui_create_xmlconsole_win(void) -{ - ProfWin *window = wins_new_xmlconsole(); - ui_switch_win(window); -} - -void -ui_open_xmlconsole_win(void) -{ - ProfXMLWin *xmlwin = wins_get_xmlconsole(); - if (xmlwin) { - ui_switch_win((ProfWin*)xmlwin); - } -} - void ui_outgoing_private_msg(ProfPrivateWin *privwin, const char *const message) { diff --git a/src/ui/ui.h b/src/ui/ui.h index 5ea836c5..909e9d5d 100644 --- a/src/ui/ui.h +++ b/src/ui/ui.h @@ -189,7 +189,6 @@ void ui_statusbar_new(const int win); void ui_write(char *line, int offset); void ui_invalid_command_usage(const char *const cmd, void (*setting_func)(void)); void ui_create_xmlconsole_win(void); -gboolean ui_xmlconsole_exists(void); void ui_open_xmlconsole_win(void); gboolean ui_win_has_unsaved_form(int num); void ui_inp_history_append(char *inp); diff --git a/tests/unittests/ui/stub_ui.c b/tests/unittests/ui/stub_ui.c index eaba66fc..08fa9191 100644 --- a/tests/unittests/ui/stub_ui.c +++ b/tests/unittests/ui/stub_ui.c @@ -321,10 +321,6 @@ void ui_inp_history_append(char *inp) {} void ui_invalid_command_usage(const char * const usage, void (*setting_func)(void)) {} void ui_create_xmlconsole_win(void) {} -gboolean ui_xmlconsole_exists(void) -{ - return FALSE; -} void ui_open_xmlconsole_win(void) {} From 9eae20298fe6bfa67fb8b9eae26fce727d582480 Mon Sep 17 00:00:00 2001 From: James Booth Date: Sun, 1 Nov 2015 19:29:59 +0000 Subject: [PATCH 2/5] Removed ui_create_xmlconsole_win() --- src/command/commands.c | 3 ++- src/ui/core.c | 7 ------- src/ui/ui.h | 1 - tests/unittests/ui/stub_ui.c | 2 -- 4 files changed, 2 insertions(+), 11 deletions(-) diff --git a/src/command/commands.c b/src/command/commands.c index 037ec453..e5dd5ef6 100644 --- a/src/command/commands.c +++ b/src/command/commands.c @@ -4401,7 +4401,8 @@ cmd_xmlconsole(ProfWin *window, const char *const command, gchar **args) if (xmlwin) { ui_open_xmlconsole_win(); } else { - ui_create_xmlconsole_win(); + ProfWin *window = wins_new_xmlconsole(); + ui_switch_win(window); } return TRUE; diff --git a/src/ui/core.c b/src/ui/core.c index 340d54d5..50a8f148 100644 --- a/src/ui/core.c +++ b/src/ui/core.c @@ -222,13 +222,6 @@ ui_load_colours(void) } } -void -ui_create_xmlconsole_win(void) -{ - ProfWin *window = wins_new_xmlconsole(); - ui_switch_win(window); -} - void ui_open_xmlconsole_win(void) { diff --git a/src/ui/ui.h b/src/ui/ui.h index 909e9d5d..a38124c8 100644 --- a/src/ui/ui.h +++ b/src/ui/ui.h @@ -188,7 +188,6 @@ void ui_update_presence(const resource_presence_t resource_presence, const char void ui_statusbar_new(const int win); void ui_write(char *line, int offset); void ui_invalid_command_usage(const char *const cmd, void (*setting_func)(void)); -void ui_create_xmlconsole_win(void); void ui_open_xmlconsole_win(void); gboolean ui_win_has_unsaved_form(int num); void ui_inp_history_append(char *inp); diff --git a/tests/unittests/ui/stub_ui.c b/tests/unittests/ui/stub_ui.c index 08fa9191..5244f8b7 100644 --- a/tests/unittests/ui/stub_ui.c +++ b/tests/unittests/ui/stub_ui.c @@ -320,8 +320,6 @@ void ui_inp_history_append(char *inp) {} void ui_invalid_command_usage(const char * const usage, void (*setting_func)(void)) {} -void ui_create_xmlconsole_win(void) {} - void ui_open_xmlconsole_win(void) {} gboolean ui_win_has_unsaved_form(int num) From 7e386fbf005a9c990d288750c336db8e981eaee1 Mon Sep 17 00:00:00 2001 From: James Booth Date: Sun, 1 Nov 2015 19:33:01 +0000 Subject: [PATCH 3/5] Removed ui_open_xmlconsole_win() --- src/command/commands.c | 2 +- src/ui/core.c | 9 --------- src/ui/ui.h | 1 - tests/unittests/ui/stub_ui.c | 2 -- 4 files changed, 1 insertion(+), 13 deletions(-) diff --git a/src/command/commands.c b/src/command/commands.c index e5dd5ef6..d8408937 100644 --- a/src/command/commands.c +++ b/src/command/commands.c @@ -4399,7 +4399,7 @@ cmd_xmlconsole(ProfWin *window, const char *const command, gchar **args) { ProfXMLWin *xmlwin = wins_get_xmlconsole(); if (xmlwin) { - ui_open_xmlconsole_win(); + ui_switch_win((ProfWin*)xmlwin); } else { ProfWin *window = wins_new_xmlconsole(); ui_switch_win(window); diff --git a/src/ui/core.c b/src/ui/core.c index 50a8f148..f8c8b7c6 100644 --- a/src/ui/core.c +++ b/src/ui/core.c @@ -222,15 +222,6 @@ ui_load_colours(void) } } -void -ui_open_xmlconsole_win(void) -{ - ProfXMLWin *xmlwin = wins_get_xmlconsole(); - if (xmlwin) { - ui_switch_win((ProfWin*)xmlwin); - } -} - void ui_handle_stanza(const char *const msg) { diff --git a/src/ui/ui.h b/src/ui/ui.h index a38124c8..9f7cf46a 100644 --- a/src/ui/ui.h +++ b/src/ui/ui.h @@ -188,7 +188,6 @@ void ui_update_presence(const resource_presence_t resource_presence, const char void ui_statusbar_new(const int win); void ui_write(char *line, int offset); void ui_invalid_command_usage(const char *const cmd, void (*setting_func)(void)); -void ui_open_xmlconsole_win(void); gboolean ui_win_has_unsaved_form(int num); void ui_inp_history_append(char *inp); diff --git a/tests/unittests/ui/stub_ui.c b/tests/unittests/ui/stub_ui.c index 5244f8b7..b397db86 100644 --- a/tests/unittests/ui/stub_ui.c +++ b/tests/unittests/ui/stub_ui.c @@ -320,8 +320,6 @@ void ui_inp_history_append(char *inp) {} void ui_invalid_command_usage(const char * const usage, void (*setting_func)(void)) {} -void ui_open_xmlconsole_win(void) {} - gboolean ui_win_has_unsaved_form(int num) { return FALSE; From db4bcd3e6d6efa9bae1d85b327a9f0318177555f Mon Sep 17 00:00:00 2001 From: James Booth Date: Sun, 1 Nov 2015 19:39:36 +0000 Subject: [PATCH 4/5] Added xmlwin module --- Makefile.am | 1 + src/event/server_events.c | 2 +- src/ui/core.c | 20 ------------- src/ui/ui.h | 4 ++- src/ui/xmlwin.c | 56 ++++++++++++++++++++++++++++++++++++ tests/unittests/ui/stub_ui.c | 2 +- 6 files changed, 62 insertions(+), 23 deletions(-) create mode 100644 src/ui/xmlwin.c diff --git a/Makefile.am b/Makefile.am index a00ff6d3..487db256 100644 --- a/Makefile.am +++ b/Makefile.am @@ -24,6 +24,7 @@ core_sources = \ src/ui/rosterwin.c src/ui/occupantswin.c \ src/ui/buffer.c src/ui/buffer.h \ src/ui/chatwin.c \ + src/ui/xmlwin.c \ src/command/command.h src/command/command.c \ src/command/commands.h src/command/commands.c \ src/tools/parser.c \ diff --git a/src/event/server_events.c b/src/event/server_events.c index aea6a4ea..37db7cec 100644 --- a/src/event/server_events.c +++ b/src/event/server_events.c @@ -521,7 +521,7 @@ sv_ev_roster_update(const char *const barejid, const char *const name, void sv_ev_xmpp_stanza(const char *const msg) { - ui_handle_stanza(msg); + xmlwin_show(msg); } void diff --git a/src/ui/core.c b/src/ui/core.c index f8c8b7c6..d50f1c3d 100644 --- a/src/ui/core.c +++ b/src/ui/core.c @@ -222,26 +222,6 @@ ui_load_colours(void) } } -void -ui_handle_stanza(const char *const msg) -{ - ProfXMLWin *xmlwin = wins_get_xmlconsole(); - if (!xmlwin) { - return; - } - - ProfWin *window = (ProfWin*)xmlwin; - if (g_str_has_prefix(msg, "SENT:")) { - win_print(window, '-', 0, NULL, 0, 0, "", "SENT:"); - win_print(window, '-', 0, NULL, 0, THEME_ONLINE, "", &msg[6]); - win_print(window, '-', 0, NULL, 0, THEME_ONLINE, "", ""); - } else if (g_str_has_prefix(msg, "RECV:")) { - win_print(window, '-', 0, NULL, 0, 0, "", "RECV:"); - win_print(window, '-', 0, NULL, 0, THEME_AWAY, "", &msg[6]); - win_print(window, '-', 0, NULL, 0, THEME_AWAY, "", ""); - } -} - void ui_contact_online(char *barejid, Resource *resource, GDateTime *last_activity) { diff --git a/src/ui/ui.h b/src/ui/ui.h index 9f7cf46a..6520358a 100644 --- a/src/ui/ui.h +++ b/src/ui/ui.h @@ -85,7 +85,6 @@ int ui_win_unread(int index); char* ui_ask_password(void); char* ui_get_line(void); char* ui_ask_pgp_passphrase(const char *hint, int prev_fail); -void ui_handle_stanza(const char *const msg); void ui_contact_online(char *barejid, Resource *resource, GDateTime *last_activity); void ui_contact_typing(const char *const barejid, const char *const resource); void ui_incoming_private_msg(const char *const fulljid, const char *const message, GDateTime *timestamp); @@ -209,6 +208,9 @@ void chatwin_otr_untrust(ProfChatWin *chatwin); void chatwin_otr_smp_event(ProfChatWin *chatwin, prof_otr_smp_event_t event, void *data); #endif +// xml console +void xmlwin_show(const char *const msg); + // Input window char* inp_readline(void); void inp_nonblocking(gboolean reset); diff --git a/src/ui/xmlwin.c b/src/ui/xmlwin.c new file mode 100644 index 00000000..d793fd05 --- /dev/null +++ b/src/ui/xmlwin.c @@ -0,0 +1,56 @@ +/* + * xmlwin.c + * + * Copyright (C) 2012 - 2015 James Booth + * + * This file is part of Profanity. + * + * Profanity is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Profanity is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Profanity. If not, see . + * + * In addition, as a special exception, the copyright holders give permission to + * link the code of portions of this program with the OpenSSL library under + * certain conditions as described in each individual source file, and + * distribute linked combinations including the two. + * + * You must obey the GNU General Public License in all respects for all of the + * code used other than OpenSSL. If you modify file(s) with this exception, you + * may extend this exception to your version of the file(s), but you are not + * obligated to do so. If you do not wish to do so, delete this exception + * statement from your version. If you delete this exception statement from all + * source files in the program, then also delete it here. + * + */ + +#include "ui/win_types.h" +#include "window_list.h" + +void +xmlwin_show(const char *const msg) +{ + ProfXMLWin *xmlwin = wins_get_xmlconsole(); + if (!xmlwin) { + return; + } + + ProfWin *window = (ProfWin*)xmlwin; + if (g_str_has_prefix(msg, "SENT:")) { + win_print(window, '-', 0, NULL, 0, 0, "", "SENT:"); + win_print(window, '-', 0, NULL, 0, THEME_ONLINE, "", &msg[6]); + win_print(window, '-', 0, NULL, 0, THEME_ONLINE, "", ""); + } else if (g_str_has_prefix(msg, "RECV:")) { + win_print(window, '-', 0, NULL, 0, 0, "", "RECV:"); + win_print(window, '-', 0, NULL, 0, THEME_AWAY, "", &msg[6]); + win_print(window, '-', 0, NULL, 0, THEME_AWAY, "", ""); + } +} diff --git a/tests/unittests/ui/stub_ui.c b/tests/unittests/ui/stub_ui.c index b397db86..03142652 100644 --- a/tests/unittests/ui/stub_ui.c +++ b/tests/unittests/ui/stub_ui.c @@ -165,7 +165,7 @@ char *ui_get_line(void) return NULL; } -void ui_handle_stanza(const char * const msg) {} +void xmlwin_show(const char * const msg) {} // ui events void ui_contact_online(char *barejid, Resource *resource, GDateTime *last_activity) From aa59cf98b8b696d0b912a6e165eaa21270165891 Mon Sep 17 00:00:00 2001 From: James Booth Date: Sun, 1 Nov 2015 19:45:35 +0000 Subject: [PATCH 5/5] xmlwin_show takes window as argument --- src/event/server_events.c | 5 ++++- src/ui/ui.h | 2 +- src/ui/xmlwin.c | 9 ++++----- tests/unittests/ui/stub_ui.c | 2 +- 4 files changed, 10 insertions(+), 8 deletions(-) diff --git a/src/event/server_events.c b/src/event/server_events.c index 37db7cec..bfac6ddd 100644 --- a/src/event/server_events.c +++ b/src/event/server_events.c @@ -521,7 +521,10 @@ sv_ev_roster_update(const char *const barejid, const char *const name, void sv_ev_xmpp_stanza(const char *const msg) { - xmlwin_show(msg); + ProfXMLWin *xmlwin = wins_get_xmlconsole(); + if (xmlwin) { + xmlwin_show(xmlwin, msg); + } } void diff --git a/src/ui/ui.h b/src/ui/ui.h index 6520358a..52389a11 100644 --- a/src/ui/ui.h +++ b/src/ui/ui.h @@ -209,7 +209,7 @@ void chatwin_otr_smp_event(ProfChatWin *chatwin, prof_otr_smp_event_t event, voi #endif // xml console -void xmlwin_show(const char *const msg); +void xmlwin_show(ProfXMLWin *xmlwin, const char *const msg); // Input window char* inp_readline(void); diff --git a/src/ui/xmlwin.c b/src/ui/xmlwin.c index d793fd05..31921390 100644 --- a/src/ui/xmlwin.c +++ b/src/ui/xmlwin.c @@ -32,16 +32,15 @@ * */ +#include + #include "ui/win_types.h" #include "window_list.h" void -xmlwin_show(const char *const msg) +xmlwin_show(ProfXMLWin *xmlwin, const char *const msg) { - ProfXMLWin *xmlwin = wins_get_xmlconsole(); - if (!xmlwin) { - return; - } + assert(xmlwin != NULL); ProfWin *window = (ProfWin*)xmlwin; if (g_str_has_prefix(msg, "SENT:")) { diff --git a/tests/unittests/ui/stub_ui.c b/tests/unittests/ui/stub_ui.c index 03142652..d146341a 100644 --- a/tests/unittests/ui/stub_ui.c +++ b/tests/unittests/ui/stub_ui.c @@ -165,7 +165,7 @@ char *ui_get_line(void) return NULL; } -void xmlwin_show(const char * const msg) {} +void xmlwin_show(ProfXMLWin *xmlwin, const char * const msg) {} // ui events void ui_contact_online(char *barejid, Resource *resource, GDateTime *last_activity)