diff options
-rw-r--r-- | src/command/cmd_funcs.c | 132 | ||||
-rw-r--r-- | src/ui/core.c | 15 | ||||
-rw-r--r-- | src/ui/ui.h | 1 | ||||
-rw-r--r-- | tests/unittests/test_cmd_otr.c | 4 | ||||
-rw-r--r-- | tests/unittests/ui/stub_ui.c | 16 | ||||
-rw-r--r-- | tests/unittests/ui/stub_ui.h | 2 |
6 files changed, 82 insertions, 88 deletions
diff --git a/src/command/cmd_funcs.c b/src/command/cmd_funcs.c index d052d77f..84cc7943 100644 --- a/src/command/cmd_funcs.c +++ b/src/command/cmd_funcs.c @@ -1156,17 +1156,17 @@ cmd_sub(ProfWin *window, const char *const command, gchar **args) PContact contact = roster_get_contact(jidp->barejid); if ((contact == NULL) || (p_contact_subscription(contact) == NULL)) { if (window->type == WIN_CHAT) { - ui_current_print_line("No subscription information for %s.", jidp->barejid); + win_println(window, THEME_DEFAULT, '-', "No subscription information for %s.", jidp->barejid); } else { cons_show("No subscription information for %s.", jidp->barejid); } } else { if (window->type == WIN_CHAT) { if (p_contact_pending_out(contact)) { - ui_current_print_line("%s subscription status: %s, request pending.", + win_println(window, THEME_DEFAULT, '-', "%s subscription status: %s, request pending.", jidp->barejid, p_contact_subscription(contact)); } else { - ui_current_print_line("%s subscription status: %s.", jidp->barejid, + win_println(window, THEME_DEFAULT, '-', "%s subscription status: %s.", jidp->barejid, p_contact_subscription(contact)); } } else { @@ -1382,7 +1382,7 @@ cmd_close(ProfWin *window, const char *const command, gchar **args) // check for unsaved form if (ui_win_has_unsaved_form(index)) { - ui_current_print_line("You have unsaved changes, use /form submit or /form cancel"); + win_println(window, THEME_DEFAULT, '-', "You have unsaved changes, use /form submit or /form cancel"); return TRUE; } @@ -1417,7 +1417,7 @@ cmd_close(ProfWin *window, const char *const command, gchar **args) // check for unsaved form if (ui_win_has_unsaved_form(index)) { - ui_current_print_line("You have unsaved changes, use /form submit or /form cancel"); + win_println(window, THEME_DEFAULT, '-', "You have unsaved changes, use /form submit or /form cancel"); return TRUE; } @@ -2078,7 +2078,7 @@ cmd_msg(ProfWin *window, const char *const command, gchar **args) g_string_free(full_jid, TRUE); } else { - ui_current_print_line("No such participant \"%s\" in room.", usr); + win_println(window, THEME_DEFAULT, '-', "No such participant \"%s\" in room.", usr); } return TRUE; @@ -3111,12 +3111,12 @@ cmd_status(ProfWin *window, const char *const command, gchar **args) win_println(window, THEME_DEFAULT, '-', "No such participant \"%s\" in room.", usr); } } else { - ui_current_print_line("You must specify a nickname."); + win_println(window, THEME_DEFAULT, '-', "You must specify a nickname."); } break; case WIN_CHAT: if (usr) { - ui_current_print_line("No parameter required when in chat."); + win_println(window, THEME_DEFAULT, '-', "No parameter required when in chat."); } else { ProfChatWin *chatwin = (ProfChatWin*)window; assert(chatwin->memcheck == PROFCHATWIN_MEMCHECK); @@ -3130,7 +3130,7 @@ cmd_status(ProfWin *window, const char *const command, gchar **args) break; case WIN_PRIVATE: if (usr) { - ui_current_print_line("No parameter required when in chat."); + win_println(window, THEME_DEFAULT, '-', "No parameter required when in chat."); } else { ProfPrivateWin *privatewin = (ProfPrivateWin*)window; assert(privatewin->memcheck == PROFPRIVATEWIN_MEMCHECK); @@ -3184,7 +3184,7 @@ cmd_info(ProfWin *window, const char *const command, gchar **args) if (occupant) { win_show_occupant_info(window, mucwin->roomjid, occupant); } else { - ui_current_print_line("No such occupant \"%s\" in room.", usr); + win_println(window, THEME_DEFAULT, '-', "No such occupant \"%s\" in room.", usr); } } else { ProfMucWin *mucwin = (ProfMucWin*)window; @@ -3196,7 +3196,7 @@ cmd_info(ProfWin *window, const char *const command, gchar **args) break; case WIN_CHAT: if (usr) { - ui_current_print_line("No parameter required when in chat."); + win_println(window, THEME_DEFAULT, '-', "No parameter required when in chat."); } else { ProfChatWin *chatwin = (ProfChatWin*)window; assert(chatwin->memcheck == PROFCHATWIN_MEMCHECK); @@ -3210,7 +3210,7 @@ cmd_info(ProfWin *window, const char *const command, gchar **args) break; case WIN_PRIVATE: if (usr) { - ui_current_print_line("No parameter required when in chat."); + win_println(window, THEME_DEFAULT, '-', "No parameter required when in chat."); } else { ProfPrivateWin *privatewin = (ProfPrivateWin*)window; assert(privatewin->memcheck == PROFPRIVATEWIN_MEMCHECK); @@ -3573,7 +3573,7 @@ cmd_form_field(ProfWin *window, char *tag, gchar **args) DataForm *form = confwin->form; if (form) { if (!form_tag_exists(form, tag)) { - ui_current_print_line("Form does not contain a field with tag %s", tag); + win_println(window, THEME_DEFAULT, '-', "Form does not contain a field with tag %s", tag); return TRUE; } @@ -3589,16 +3589,16 @@ cmd_form_field(ProfWin *window, char *tag, gchar **args) value = args[0]; if (g_strcmp0(value, "on") == 0) { form_set_value(form, tag, "1"); - ui_current_print_line("Field updated..."); + win_println(window, THEME_DEFAULT, '-', "Field updated..."); mucconfwin_show_form_field(confwin, form, tag); } else if (g_strcmp0(value, "off") == 0) { form_set_value(form, tag, "0"); - ui_current_print_line("Field updated..."); + win_println(window, THEME_DEFAULT, '-', "Field updated..."); mucconfwin_show_form_field(confwin, form, tag); } else { - ui_current_print_line("Invalid command, usage:"); + win_println(window, THEME_DEFAULT, '-', "Invalid command, usage:"); mucconfwin_field_help(confwin, tag); - ui_current_print_line(""); + win_println(window, THEME_DEFAULT, '-', ""); } break; @@ -3607,24 +3607,24 @@ cmd_form_field(ProfWin *window, char *tag, gchar **args) case FIELD_JID_SINGLE: value = args[0]; if (value == NULL) { - ui_current_print_line("Invalid command, usage:"); + win_println(window, THEME_DEFAULT, '-', "Invalid command, usage:"); mucconfwin_field_help(confwin, tag); - ui_current_print_line(""); + win_println(window, THEME_DEFAULT, '-', ""); } else { form_set_value(form, tag, value); - ui_current_print_line("Field updated..."); + win_println(window, THEME_DEFAULT, '-', "Field updated..."); mucconfwin_show_form_field(confwin, form, tag); } break; case FIELD_LIST_SINGLE: value = args[0]; if ((value == NULL) || !form_field_contains_option(form, tag, value)) { - ui_current_print_line("Invalid command, usage:"); + win_println(window, THEME_DEFAULT, '-', "Invalid command, usage:"); mucconfwin_field_help(confwin, tag); - ui_current_print_line(""); + win_println(window, THEME_DEFAULT, '-', ""); } else { form_set_value(form, tag, value); - ui_current_print_line("Field updated..."); + win_println(window, THEME_DEFAULT, '-', "Field updated..."); mucconfwin_show_form_field(confwin, form, tag); } break; @@ -3635,51 +3635,51 @@ cmd_form_field(ProfWin *window, char *tag, gchar **args) value = args[1]; } if ((g_strcmp0(cmd, "add") != 0) && (g_strcmp0(cmd, "remove"))) { - ui_current_print_line("Invalid command, usage:"); + win_println(window, THEME_DEFAULT, '-', "Invalid command, usage:"); mucconfwin_field_help(confwin, tag); - ui_current_print_line(""); + win_println(window, THEME_DEFAULT, '-', ""); break; } if (value == NULL) { - ui_current_print_line("Invalid command, usage:"); + win_println(window, THEME_DEFAULT, '-', "Invalid command, usage:"); mucconfwin_field_help(confwin, tag); - ui_current_print_line(""); + win_println(window, THEME_DEFAULT, '-', ""); break; } if (g_strcmp0(cmd, "add") == 0) { form_add_value(form, tag, value); - ui_current_print_line("Field updated..."); + win_println(window, THEME_DEFAULT, '-', "Field updated..."); mucconfwin_show_form_field(confwin, form, tag); break; } if (g_strcmp0(args[0], "remove") == 0) { if (!g_str_has_prefix(value, "val")) { - ui_current_print_line("Invalid command, usage:"); + win_println(window, THEME_DEFAULT, '-', "Invalid command, usage:"); mucconfwin_field_help(confwin, tag); - ui_current_print_line(""); + win_println(window, THEME_DEFAULT, '-', ""); break; } if (strlen(value) < 4) { - ui_current_print_line("Invalid command, usage:"); + win_println(window, THEME_DEFAULT, '-', "Invalid command, usage:"); mucconfwin_field_help(confwin, tag); - ui_current_print_line(""); + win_println(window, THEME_DEFAULT, '-', ""); break; } int index = strtol(&value[3], NULL, 10); if ((index < 1) || (index > form_get_value_count(form, tag))) { - ui_current_print_line("Invalid command, usage:"); + win_println(window, THEME_DEFAULT, '-', "Invalid command, usage:"); mucconfwin_field_help(confwin, tag); - ui_current_print_line(""); + win_println(window, THEME_DEFAULT, '-', ""); break; } removed = form_remove_text_multi_value(form, tag, index); if (removed) { - ui_current_print_line("Field updated..."); + win_println(window, THEME_DEFAULT, '-', "Field updated..."); mucconfwin_show_form_field(confwin, form, tag); } else { - ui_current_print_line("Could not remove %s from %s", value, tag); + win_println(window, THEME_DEFAULT, '-', "Could not remove %s from %s", value, tag); } } break; @@ -3689,15 +3689,15 @@ cmd_form_field(ProfWin *window, char *tag, gchar **args) value = args[1]; } if ((g_strcmp0(cmd, "add") != 0) && (g_strcmp0(cmd, "remove"))) { - ui_current_print_line("Invalid command, usage:"); + win_println(window, THEME_DEFAULT, '-', "Invalid command, usage:"); mucconfwin_field_help(confwin, tag); - ui_current_print_line(""); + win_println(window, THEME_DEFAULT, '-', ""); break; } if (value == NULL) { - ui_current_print_line("Invalid command, usage:"); + win_println(window, THEME_DEFAULT, '-', "Invalid command, usage:"); mucconfwin_field_help(confwin, tag); - ui_current_print_line(""); + win_println(window, THEME_DEFAULT, '-', ""); break; } if (g_strcmp0(args[0], "add") == 0) { @@ -3705,15 +3705,15 @@ cmd_form_field(ProfWin *window, char *tag, gchar **args) if (valid) { added = form_add_unique_value(form, tag, value); if (added) { - ui_current_print_line("Field updated..."); + win_println(window, THEME_DEFAULT, '-', "Field updated..."); mucconfwin_show_form_field(confwin, form, tag); } else { - ui_current_print_line("Value %s already selected for %s", value, tag); + win_println(window, THEME_DEFAULT, '-', "Value %s already selected for %s", value, tag); } } else { - ui_current_print_line("Invalid command, usage:"); + win_println(window, THEME_DEFAULT, '-', "Invalid command, usage:"); mucconfwin_field_help(confwin, tag); - ui_current_print_line(""); + win_println(window, THEME_DEFAULT, '-', ""); } break; } @@ -3722,15 +3722,15 @@ cmd_form_field(ProfWin *window, char *tag, gchar **args) if (valid == TRUE) { removed = form_remove_value(form, tag, value); if (removed) { - ui_current_print_line("Field updated..."); + win_println(window, THEME_DEFAULT, '-', "Field updated..."); mucconfwin_show_form_field(confwin, form, tag); } else { - ui_current_print_line("Value %s is not currently set for %s", value, tag); + win_println(window, THEME_DEFAULT, '-', "Value %s is not currently set for %s", value, tag); } } else { - ui_current_print_line("Invalid command, usage:"); + win_println(window, THEME_DEFAULT, '-', "Invalid command, usage:"); mucconfwin_field_help(confwin, tag); - ui_current_print_line(""); + win_println(window, THEME_DEFAULT, '-', ""); } } break; @@ -3740,34 +3740,34 @@ cmd_form_field(ProfWin *window, char *tag, gchar **args) value = args[1]; } if ((g_strcmp0(cmd, "add") != 0) && (g_strcmp0(cmd, "remove"))) { - ui_current_print_line("Invalid command, usage:"); + win_println(window, THEME_DEFAULT, '-', "Invalid command, usage:"); mucconfwin_field_help(confwin, tag); - ui_current_print_line(""); + win_println(window, THEME_DEFAULT, '-', ""); break; } if (value == NULL) { - ui_current_print_line("Invalid command, usage:"); + win_println(window, THEME_DEFAULT, '-', "Invalid command, usage:"); mucconfwin_field_help(confwin, tag); - ui_current_print_line(""); + win_println(window, THEME_DEFAULT, '-', ""); break; } if (g_strcmp0(args[0], "add") == 0) { added = form_add_unique_value(form, tag, value); if (added) { - ui_current_print_line("Field updated..."); + win_println(window, THEME_DEFAULT, '-', "Field updated..."); mucconfwin_show_form_field(confwin, form, tag); } else { - ui_current_print_line("JID %s already exists in %s", value, tag); + win_println(window, THEME_DEFAULT, '-', "JID %s already exists in %s", value, tag); } break; } if (g_strcmp0(args[0], "remove") == 0) { removed = form_remove_value(form, tag, value); if (removed) { - ui_current_print_line("Field updated..."); + win_println(window, THEME_DEFAULT, '-', "Field updated..."); mucconfwin_show_form_field(confwin, form, tag); } else { - ui_current_print_line("Field %s does not contain %s", tag, value); + win_println(window, THEME_DEFAULT, '-', "Field %s does not contain %s", tag, value); } } break; @@ -3827,7 +3827,7 @@ cmd_form(ProfWin *window, const char *const command, gchar **args) ui_show_lines((ProfWin*) confwin, help_text); } - ui_current_print_line(""); + win_println(window, THEME_DEFAULT, '-', ""); return TRUE; } @@ -6700,7 +6700,7 @@ cmd_otr_theirfp(ProfWin *window, const char *const command, gchar **args) } if (window->type != WIN_CHAT) { - ui_current_print_line("You must be in a regular chat window to view a recipient's fingerprint."); + win_println(window, THEME_DEFAULT, '-', "You must be in a regular chat window to view a recipient's fingerprint."); return TRUE; } @@ -6772,7 +6772,7 @@ cmd_otr_start(ProfWin *window, const char *const command, gchar **args) // no recipient, use current chat } else { if (window->type != WIN_CHAT) { - ui_current_print_line("You must be in a regular chat window to start an OTR session."); + win_println(window, THEME_DEFAULT, '-', "You must be in a regular chat window to start an OTR session."); return TRUE; } @@ -6814,7 +6814,7 @@ cmd_otr_end(ProfWin *window, const char *const command, gchar **args) } if (window->type != WIN_CHAT) { - ui_current_print_line("You must be in a regular chat window to use OTR."); + win_println(window, THEME_DEFAULT, '-', "You must be in a regular chat window to use OTR."); return TRUE; } @@ -6844,7 +6844,7 @@ cmd_otr_trust(ProfWin *window, const char *const command, gchar **args) } if (window->type != WIN_CHAT) { - ui_current_print_line("You must be in an OTR session to trust a recipient."); + win_println(window, THEME_DEFAULT, '-', "You must be in an OTR session to trust a recipient."); return TRUE; } @@ -6874,7 +6874,7 @@ cmd_otr_untrust(ProfWin *window, const char *const command, gchar **args) } if (window->type != WIN_CHAT) { - ui_current_print_line("You must be in an OTR session to untrust a recipient."); + win_println(window, THEME_DEFAULT, '-', "You must be in an OTR session to untrust a recipient."); return TRUE; } @@ -6904,7 +6904,7 @@ cmd_otr_secret(ProfWin *window, const char *const command, gchar **args) } if (window->type != WIN_CHAT) { - ui_current_print_line("You must be in an OTR session to trust a recipient."); + win_println(window, THEME_DEFAULT, '-', "You must be in an OTR session to trust a recipient."); return TRUE; } @@ -6946,7 +6946,7 @@ cmd_otr_question(ProfWin *window, const char *const command, gchar **args) } if (window->type != WIN_CHAT) { - ui_current_print_line("You must be in an OTR session to trust a recipient."); + win_println(window, THEME_DEFAULT, '-', "You must be in an OTR session to trust a recipient."); return TRUE; } @@ -6975,7 +6975,7 @@ cmd_otr_answer(ProfWin *window, const char *const command, gchar **args) } if (window->type != WIN_CHAT) { - ui_current_print_line("You must be in an OTR session to trust a recipient."); + win_println(window, THEME_DEFAULT, '-', "You must be in an OTR session to trust a recipient."); return TRUE; } @@ -7097,7 +7097,7 @@ _cmd_execute_default(ProfWin *window, const char *inp) jabber_conn_status_t status = connection_get_status(); if (status != JABBER_CONNECTED) { - ui_current_print_line("You are not currently connected."); + win_println(window, THEME_DEFAULT, '-', "You are not currently connected."); return TRUE; } diff --git a/src/ui/core.c b/src/ui/core.c index 5b5d8d2a..a72423e4 100644 --- a/src/ui/core.c +++ b/src/ui/core.c @@ -467,7 +467,7 @@ ui_invalid_command_usage(const char *const cmd, void (*setting_func)(void)) cons_show(msg->str); ProfWin *current = wins_get_current(); if (current->type == WIN_CHAT) { - ui_current_print_line(msg->str); + win_println(current, THEME_DEFAULT, '-', "%s", msg->str); } } @@ -732,19 +732,6 @@ ui_prune_wins(void) } void -ui_current_print_line(const char *const msg, ...) -{ - ProfWin *window = wins_get_current(); - va_list arg; - va_start(arg, msg); - GString *fmt_msg = g_string_new(NULL); - g_string_vprintf(fmt_msg, msg, arg); - win_println(window, THEME_DEFAULT, '-', "%s", fmt_msg->str); - va_end(arg); - g_string_free(fmt_msg, TRUE); -} - -void ui_current_print_formatted_line(const char show_char, int attrs, const char *const msg, ...) { ProfWin *current = wins_get_current(); diff --git a/src/ui/ui.h b/src/ui/ui.h index ddcf884c..5a8a09ae 100644 --- a/src/ui/ui.h +++ b/src/ui/ui.h @@ -75,7 +75,6 @@ void ui_print_system_msg_from_recipient(const char *const barejid, const char *m void ui_close_connected_win(int index); int ui_close_all_wins(void); int ui_close_read_wins(void); -void ui_current_print_line(const char *const msg, ...); void ui_current_print_formatted_line(const char show_char, int attrs, const char *const msg, ...); void ui_close_win(int index); int ui_win_unread(int index); diff --git a/tests/unittests/test_cmd_otr.c b/tests/unittests/test_cmd_otr.c index c1a46fc1..088b8baa 100644 --- a/tests/unittests/test_cmd_otr.c +++ b/tests/unittests/test_cmd_otr.c @@ -250,7 +250,7 @@ test_cmd_otr_theirfp_from_wintype(win_type_t wintype) will_return(connection_get_status, JABBER_CONNECTED); - expect_ui_current_print_line("You must be in a regular chat window to view a recipient's fingerprint."); + expect_win_println("You must be in a regular chat window to view a recipient's fingerprint."); gboolean result = cmd_otr_theirfp(&window, CMD_OTR, args); @@ -333,7 +333,7 @@ test_cmd_otr_start_from_wintype(win_type_t wintype) will_return(connection_get_status, JABBER_CONNECTED); - expect_ui_current_print_line("You must be in a regular chat window to start an OTR session."); + expect_win_println("You must be in a regular chat window to start an OTR session."); gboolean result = cmd_otr_start(&window, CMD_OTR, args); assert_true(result); diff --git a/tests/unittests/ui/stub_ui.c b/tests/unittests/ui/stub_ui.c index c93f08fd..da253774 100644 --- a/tests/unittests/ui/stub_ui.c +++ b/tests/unittests/ui/stub_ui.c @@ -43,9 +43,9 @@ expect_any_cons_show_error(void) } void -expect_ui_current_print_line(char *message) +expect_win_println(char *message) { - expect_string(ui_current_print_line, output, message); + expect_string(win_println, output, message); } void @@ -517,9 +517,17 @@ void win_hide_subwin(ProfWin *window) {} void win_show_subwin(ProfWin *window) {} void win_refresh_without_subwin(ProfWin *window) {} void win_refresh_with_subwin(ProfWin *window) {} -void win_printf(ProfWin *window, const char show_char, int pad_indent, GDateTime *timestamp, int flags, theme_item_t theme_item, const char * const from, const char * const message, ...) {} + +void win_println(ProfWin *window, theme_item_t theme, const char ch, const char *const message, ...) +{ + va_list args; + va_start(args, message); + vsnprintf(output, sizeof(output), message, args); + check_expected(output); + va_end(args); +} + void win_print(ProfWin *window, theme_item_t theme_item, const char ch, const char *const message, ...) {} -void win_println(ProfWin *window, theme_item_t theme_item, const char ch, const char *const message, ...) {} void win_appendln(ProfWin *window, theme_item_t theme_item, const char *const message, ...) {} char* win_get_title(ProfWin *window) diff --git a/tests/unittests/ui/stub_ui.h b/tests/unittests/ui/stub_ui.h index d4488c4b..a1b94478 100644 --- a/tests/unittests/ui/stub_ui.h +++ b/tests/unittests/ui/stub_ui.h @@ -2,5 +2,5 @@ void expect_cons_show(char *expected); void expect_any_cons_show(void); void expect_cons_show_error(char *expected); void expect_any_cons_show_error(void); -void expect_ui_current_print_line(char *message); void expect_ui_current_print_formatted_line(char show_char, int attrs, char *message); +void expect_win_println(char *message); |