From db4bcd3e6d6efa9bae1d85b327a9f0318177555f Mon Sep 17 00:00:00 2001 From: James Booth Date: Sun, 1 Nov 2015 19:39:36 +0000 Subject: [PATCH] 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)