about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorJames Booth <boothj5@gmail.com>2015-04-21 23:35:37 +0100
committerJames Booth <boothj5@gmail.com>2015-04-21 23:35:37 +0100
commitbc445ccdfb0f8e210e793925e120b01bd0d9b918 (patch)
tree72c6fe466ed140cac3f04def74d88fdba20d54b4
parentebca38e22483ec7054596a8ecf0bdccd85e76e0a (diff)
parent88739d5c59022b4d1f1b67da3128cb4a3266ecf9 (diff)
downloadprofani-tty-bc445ccdfb0f8e210e793925e120b01bd0d9b918.tar.gz
Merge branch 'master' into pgp
-rw-r--r--src/command/commands.c21
-rw-r--r--src/event/client_events.c13
-rw-r--r--src/event/client_events.h3
-rw-r--r--src/ui/core.c80
-rw-r--r--src/ui/inputwin.c20
-rw-r--r--src/ui/ui.h5
-rw-r--r--src/ui/windows.c6
-rw-r--r--tests/test_cmd_win.c8
-rw-r--r--tests/ui/stub_ui.c13
9 files changed, 102 insertions, 67 deletions
diff --git a/src/command/commands.c b/src/command/commands.c
index d6750c68..8e657f30 100644
--- a/src/command/commands.c
+++ b/src/command/commands.c
@@ -749,7 +749,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);
     }
@@ -1358,7 +1358,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));
@@ -2478,7 +2484,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;
@@ -2786,7 +2792,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);
         }
@@ -4246,7 +4252,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 {
diff --git a/tests/test_cmd_win.c b/tests/test_cmd_win.c
index bc19ebf3..7ad01c49 100644
--- a/tests/test_cmd_win.c
+++ b/tests/test_cmd_win.c
@@ -15,8 +15,8 @@ void cmd_win_shows_message_when_win_doesnt_exist(void **state)
     CommandHelp *help = malloc(sizeof(CommandHelp));
     gchar *args[] = { "3", NULL };
 
-    expect_value(ui_switch_win, i, 3);
-    will_return(ui_switch_win, FALSE);
+    expect_value(ui_switch_win_num, i, 3);
+    will_return(ui_switch_win_num, FALSE);
 
     expect_cons_show("Window 3 does not exist.");
 
@@ -31,8 +31,8 @@ void cmd_win_switches_to_given_win_when_exists(void **state)
     CommandHelp *help = malloc(sizeof(CommandHelp));
     gchar *args[] = { "12", NULL };
 
-    expect_value(ui_switch_win, i, 12);
-    will_return(ui_switch_win, TRUE);
+    expect_value(ui_switch_win_num, i, 12);
+    will_return(ui_switch_win_num, TRUE);
 
     gboolean result = cmd_win(args, *help);
     assert_true(result);
diff --git a/tests/ui/stub_ui.c b/tests/ui/stub_ui.c
index d7fdeb0a..54faa50a 100644
--- a/tests/ui/stub_ui.c
+++ b/tests/ui/stub_ui.c
@@ -64,7 +64,12 @@ GSList* ui_get_chat_recipients(void)
     return NULL;
 }
 
-gboolean ui_switch_win(const int i)
+gboolean ui_switch_win(ProfWin *win)
+{
+    return FALSE;
+}
+
+gboolean ui_switch_win_num(const int i)
 {
     check_expected(i);
     return (gboolean)mock();
@@ -99,8 +104,12 @@ 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)
+{
+    return NULL;
+}
+
 void ui_print_system_msg_from_recipient(const char * const barejid, const char *message) {}
 gint ui_unread(void)
 {