about summary refs log tree commit diff stats
path: root/src
diff options
context:
space:
mode:
authorJames Booth <boothj5@gmail.com>2014-04-15 13:16:32 +0100
committerJames Booth <boothj5@gmail.com>2014-04-15 13:16:32 +0100
commite6e0a13e8935e6e87190bf4255c8ed313fd6afc2 (patch)
tree651adebfe4a07cf38a80442bc2302ff98af8a773 /src
parentbf185d9907f3dd6e6ec2f5c1b55a40fdccea6b9f (diff)
downloadprofani-tty-e6e0a13e8935e6e87190bf4255c8ed313fd6afc2.tar.gz
Added XML Console window
Diffstat (limited to 'src')
-rw-r--r--src/command/command.c10
-rw-r--r--src/command/commands.c12
-rw-r--r--src/command/commands.h1
-rw-r--r--src/ui/core.c38
-rw-r--r--src/ui/ui.h4
-rw-r--r--src/ui/window.h3
-rw-r--r--src/ui/windows.c41
-rw-r--r--src/ui/windows.h2
8 files changed, 100 insertions, 11 deletions
diff --git a/src/command/command.c b/src/command/command.c
index 5175a16b..3520535b 100644
--- a/src/command/command.c
+++ b/src/command/command.c
@@ -789,6 +789,14 @@ static struct cmd_t command_defs[] =
           "The default is 'all' for all windows.",
           NULL } } },
 
+    { "/xmlconsole",
+        cmd_xmlconsole, parse_args, 0, 0, NULL,
+        { "/xmlconsole", "Open the XML console",
+        { "/xmlconsole",
+          "-----------",
+          "Open the XML console to view incoming and outgoing XMPP traffic.",
+          NULL } } },
+
     { "/away",
         cmd_away, parse_args_with_freetext, 0, 1, NULL,
         { "/away [msg]", "Set status to away.",
@@ -1937,4 +1945,4 @@ _account_autocomplete(char *input, int *size)
 
     found = autocomplete_param_with_ac(input, size, "/account", account_ac);
     return found;
-}
\ No newline at end of file
+}
diff --git a/src/command/commands.c b/src/command/commands.c
index 1a05de4e..8e026b50 100644
--- a/src/command/commands.c
+++ b/src/command/commands.c
@@ -2444,6 +2444,18 @@ cmd_vercheck(gchar **args, struct cmd_help_t help)
 }
 
 gboolean
+cmd_xmlconsole(gchar **args, struct cmd_help_t help)
+{
+    if (!ui_xmlconsole_exists()) {
+        ui_create_xmlconsole_win();
+    } else {
+        ui_open_xmlconsole_win();
+    }
+
+    return TRUE;
+}
+
+gboolean
 cmd_flash(gchar **args, struct cmd_help_t help)
 {
     return _cmd_set_boolean_preference(args[0], help,
diff --git a/src/command/commands.h b/src/command/commands.h
index fa1afbff..59fd8b27 100644
--- a/src/command/commands.h
+++ b/src/command/commands.h
@@ -110,5 +110,6 @@ gboolean cmd_win(gchar **args, struct cmd_help_t help);
 gboolean cmd_wins(gchar **args, struct cmd_help_t help);
 gboolean cmd_xa(gchar **args, struct cmd_help_t help);
 gboolean cmd_alias(gchar **args, struct cmd_help_t help);
+gboolean cmd_xmlconsole(gchar **args, struct cmd_help_t help);
 
 #endif
diff --git a/src/ui/core.c b/src/ui/core.c
index 48999319..f80c6ad2 100644
--- a/src/ui/core.c
+++ b/src/ui/core.c
@@ -219,18 +219,28 @@ _ui_duck_exists(void)
     return wins_duck_exists();
 }
 
+static gboolean
+_ui_xmlconsole_exists(void)
+{
+    return wins_xmlconsole_exists();
+}
+
 static void
 _ui_handle_stanza(const char * const msg)
 {
-    ProfWin *console = wins_get_console();
-    if (g_str_has_prefix(msg, "SENT:")) {
-        win_vprint_line(console, '!', COLOUR_ONLINE, "<- %s", &msg[6]);
-    } else if (g_str_has_prefix(msg, "RECV:")) {
-        win_vprint_line(console, '!', COLOUR_AWAY, "-> %s", &msg[6]);
-    }
-    win_update_virtual(console);
-    if (wins_is_current(console)) {
-        ui_current_page_off();
+    if (ui_xmlconsole_exists()) {
+        ProfWin *xmlconsole = wins_get_xmlconsole();
+	    
+        if (g_str_has_prefix(msg, "SENT:")) {
+	    win_vprint_line(xmlconsole, '!', COLOUR_ONLINE, "<- %s", &msg[6]);
+	} else if (g_str_has_prefix(msg, "RECV:")) {
+	    win_vprint_line(xmlconsole, '!', COLOUR_AWAY, "-> %s", &msg[6]);
+	}
+
+	win_update_virtual(xmlconsole);
+	if (wins_is_current(xmlconsole)) {
+	    ui_current_page_off();
+	}
     }
 }
 
@@ -1118,6 +1128,14 @@ _ui_create_duck_win(void)
 }
 
 static void
+_ui_create_xmlconsole_win(void)
+{
+    ProfWin *window = wins_new("XML Console", WIN_XML);
+    int num = wins_get_num(window);
+    ui_switch_win(num);
+}
+
+static void
 _ui_open_duck_win(void)
 {
     ProfWin *window = wins_get_by_recipient("DuckDuckGo search");
@@ -1939,4 +1957,6 @@ ui_init_module(void)
     ui_replace_input = _ui_replace_input;
     ui_invalid_command_usage = _ui_invalid_command_usage;
     ui_handle_stanza = _ui_handle_stanza;
+    ui_create_xmlconsole_win = _ui_create_xmlconsole_win;
+    ui_xmlconsole_exists = _ui_xmlconsole_exists;
 }
diff --git a/src/ui/ui.h b/src/ui/ui.h
index 43f2d5ed..a93cc3d0 100644
--- a/src/ui/ui.h
+++ b/src/ui/ui.h
@@ -163,6 +163,10 @@ void (*ui_replace_input)(char *input, const char * const new_input, int *size);
 
 void (*ui_invalid_command_usage)(const char * const usage, void (**setting_func)(void));
 
+void (*ui_create_xmlconsole_win)(void);
+gboolean (*ui_xmlconsole_exists)(void);
+void (*ui_open_xmlconsole_win)(void);
+
 // console window actions
 void (*cons_show)(const char * const msg, ...);
 void (*cons_about)(void);
diff --git a/src/ui/window.h b/src/ui/window.h
index 4bd37447..874e6307 100644
--- a/src/ui/window.h
+++ b/src/ui/window.h
@@ -41,7 +41,8 @@ typedef enum {
     WIN_CHAT,
     WIN_MUC,
     WIN_PRIVATE,
-    WIN_DUCK
+    WIN_DUCK,
+    WIN_XML
 } win_type_t;
 
 typedef struct prof_win_t {
diff --git a/src/ui/windows.c b/src/ui/windows.c
index 75691f0d..82659be5 100644
--- a/src/ui/windows.c
+++ b/src/ui/windows.c
@@ -297,6 +297,38 @@ wins_duck_exists(void)
     return FALSE;
 }
 
+gboolean
+wins_xmlconsole_exists(void)
+{
+    GList *values = g_hash_table_get_values(windows);
+    GList *curr = values;
+
+    while (curr != NULL) {
+        ProfWin *window = curr->data;
+        if (window->type == WIN_XML)
+            return TRUE;
+        curr = g_list_next(curr);
+    }
+
+    return FALSE;
+}
+
+ProfWin *
+wins_get_xmlconsole(void)
+{
+    GList *values = g_hash_table_get_values(windows);
+    GList *curr = values;
+
+    while (curr != NULL) {
+        ProfWin *window = curr->data;
+        if (window->type == WIN_XML)
+            return window;
+        curr = g_list_next(curr);
+    }
+
+    return NULL;
+}
+
 GSList *
 wins_get_chat_recipients(void)
 {
@@ -428,6 +460,7 @@ wins_create_summary(void)
         GString *priv_string;
         GString *muc_string;
         GString *duck_string;
+        GString *xml_string;
 
         switch (window->type)
         {
@@ -501,6 +534,14 @@ wins_create_summary(void)
 
                 break;
 
+            case WIN_XML:
+                xml_string = g_string_new("");
+                g_string_printf(xml_string, "%d: XML console", ui_index);
+                result = g_slist_append(result, strdup(xml_string->str));
+                g_string_free(xml_string, TRUE);
+
+                break;
+
             default:
                 break;
         }
diff --git a/src/ui/windows.h b/src/ui/windows.h
index f8dec429..cbe219df 100644
--- a/src/ui/windows.h
+++ b/src/ui/windows.h
@@ -48,5 +48,7 @@ gboolean wins_tidy(void);
 GSList * wins_create_summary(void);
 void wins_destroy(void);
 GList * wins_get_nums(void);
+gboolean wins_xmlconsole_exists(void);
+ProfWin * wins_get_xmlconsole(void);
 
 #endif