From 5ede33a3b65dcb29ea39d23f6973edd7f379d200 Mon Sep 17 00:00:00 2001 From: James Booth Date: Sun, 16 Oct 2016 19:33:27 +0100 Subject: [PATCH 01/14] Add boothj5_laptop theme --- themes/boothj5_laptop | 144 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 144 insertions(+) create mode 100644 themes/boothj5_laptop diff --git a/themes/boothj5_laptop b/themes/boothj5_laptop new file mode 100644 index 00000000..ba220708 --- /dev/null +++ b/themes/boothj5_laptop @@ -0,0 +1,144 @@ +[colours] +bkgnd=default +titlebar=blue +titlebar.text=bold_white +titlebar.brackets=bold_white +titlebar.unencrypted=bold_red +titlebar.encrypted=bold_white +titlebar.untrusted=bold_yellow +titlebar.trusted=bold_white +titlebar.online=bold_green +titlebar.offline=bold_red +titlebar.away=bold_cyan +titlebar.xa=bold_cyan +titlebar.dnd=bold_red +titlebar.chat=bold_green +statusbar=blue +statusbar.text=bold_white +statusbar.brackets=bold_white +statusbar.active=bold_cyan +statusbar.new=bold_white +main.text=white +main.text.me=cyan +main.text.them=bold_white +main.splash=bold_red +main.time=yellow +input.text=bold_green +subscribed=green +unsubscribed=red +otr.started.trusted=green +otr.started.untrusted=yellow +otr.ended=red +otr.trusted=green +otr.untrusted=yellow +online=green +away=cyan +chat=white +dnd=magenta +xa=blue +offline=red +incoming=bold_yellow +mention=bold_cyan +trigger=bold_blue +typing=yellow +gone=red +error=red +roominfo=yellow +roommention=bold_white +roommention.term=bold_cyan +roomtrigger=bold_white +roomtrigger.term=bold_blue +me=blue +them=bold_green +roster.header=bold_yellow +roster.chat=white +roster.online=green +roster.away=cyan +roster.xa=blue +roster.dnd=magenta +roster.offline=red +roster.chat.active=white +roster.online.active=green +roster.away.active=cyan +roster.xa.active=blue +roster.dnd.active=magenta +roster.offline.active=red +roster.chat.unread=bold_white +roster.online.unread=bold_green +roster.away.unread=bold_cyan +roster.xa.unread=bold_blue +roster.dnd.unread=bold_magenta +roster.offline.unread=bold_red +roster.room=green +roster.room.unread=bold_green +roster.room.mention=bold_cyan +roster.room.trigger=bold_blue +occupants.header=bold_yellow +receipt.sent=bold_black + +[ui] +beep=false +flash=false +splash=true +wrap=true +time.console=%H:%M:%S +time.chat=%d/%m/%y %H:%M:%S +time.muc=%d/%m/%y %H:%M:%S +time.mucconfig=off +time.private=%d/%m/%y %H:%M:%S +time.xml=%H:%M:%S +time.statusbar=%H:%M:%S +time.lastactivity=%d/%m/%y %H:%M:%S +privileges=true +presence=true +intype=true +enc.warn=true +resource.title=true +resource.message=true +statuses.console=none +statuses.chat=none +statuses.muc=none +roster=true +roster.offline=false +roster.empty=false +roster.by=group +roster.order=presence +roster.unread=after +roster.priority=false +roster.size=30 +roster.wrap=true +roster.header.char=@ +roster.contact.indent=1 +roster.resource=true +roster.resource.char=/ +roster.resource.indent=1 +roster.resource.join=true +roster.presence=true +roster.presence.indent=-1 +roster.status=true +roster.contacts=true +roster.unsubscribed=true +roster.rooms=true +roster.rooms.order=name +roster.rooms.unread=after +roster.rooms.pos=last +roster.rooms.by=none +roster.rooms.private.char=/ +roster.private=room +roster.count=unread +roster.count.zero=false +occupants=true +occupants.size=15 +occupants.jid=false +wins.autotidy=true +otr.char=@ +pgp.char=% +tls.show=true +console.muc=first +console.chat=all +console.private=all +titlebar.position=1 +mainwin.position=2 +statusbar.position=3 +inputwin.position=4 + From 7e6e6296f1af3dd38fbece54cdc4562bd5196680 Mon Sep 17 00:00:00 2001 From: James Booth Date: Sun, 16 Oct 2016 19:37:23 +0100 Subject: [PATCH 02/14] Update boothj5_laptop theme --- themes/boothj5_laptop | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/themes/boothj5_laptop b/themes/boothj5_laptop index ba220708..f1da2d1d 100644 --- a/themes/boothj5_laptop +++ b/themes/boothj5_laptop @@ -82,10 +82,10 @@ flash=false splash=true wrap=true time.console=%H:%M:%S -time.chat=%d/%m/%y %H:%M:%S -time.muc=%d/%m/%y %H:%M:%S +time.chat=%H:%M:%S +time.muc=%H:%M:%S time.mucconfig=off -time.private=%d/%m/%y %H:%M:%S +time.private=%H:%M:%S time.xml=%H:%M:%S time.statusbar=%H:%M:%S time.lastactivity=%d/%m/%y %H:%M:%S From 651541d7ec4abcb2306968cd06f26236152a64b7 Mon Sep 17 00:00:00 2001 From: James Booth Date: Sun, 16 Oct 2016 19:40:43 +0100 Subject: [PATCH 03/14] Rename buffer functions --- src/ui/buffer.c | 6 +++--- src/ui/buffer.h | 6 +++--- src/ui/window.c | 32 ++++++++++++++++---------------- 3 files changed, 22 insertions(+), 22 deletions(-) diff --git a/src/ui/buffer.c b/src/ui/buffer.c index 09f53beb..b55ebf3a 100644 --- a/src/ui/buffer.c +++ b/src/ui/buffer.c @@ -79,7 +79,7 @@ buffer_free(ProfBuff buffer) } void -buffer_push(ProfBuff buffer, const char show_char, int pad_indent, GDateTime *time, +buffer_append(ProfBuff buffer, const char show_char, int pad_indent, GDateTime *time, int flags, theme_item_t theme_item, const char *const from, const char *const message, DeliveryReceipt *receipt) { ProfBuffEntry *e = malloc(sizeof(struct prof_buff_entry_t)); @@ -119,14 +119,14 @@ buffer_mark_received(ProfBuff buffer, const char *const id) } ProfBuffEntry* -buffer_yield_entry(ProfBuff buffer, int entry) +buffer_get_entry(ProfBuff buffer, int entry) { GSList *node = g_slist_nth(buffer->entries, entry); return node->data; } ProfBuffEntry* -buffer_yield_entry_by_id(ProfBuff buffer, const char *const id) +buffer_get_entry_by_id(ProfBuff buffer, const char *const id) { GSList *entries = buffer->entries; while (entries) { diff --git a/src/ui/buffer.h b/src/ui/buffer.h index 19b7bfb7..a191aa45 100644 --- a/src/ui/buffer.h +++ b/src/ui/buffer.h @@ -60,11 +60,11 @@ typedef struct prof_buff_t *ProfBuff; ProfBuff buffer_create(); void buffer_free(ProfBuff buffer); -void buffer_push(ProfBuff buffer, const char show_char, int pad_indent, GDateTime *time, int flags, theme_item_t theme_item, +void buffer_append(ProfBuff buffer, const char show_char, int pad_indent, GDateTime *time, int flags, theme_item_t theme_item, const char *const from, const char *const message, DeliveryReceipt *receipt); int buffer_size(ProfBuff buffer); -ProfBuffEntry* buffer_yield_entry(ProfBuff buffer, int entry); -ProfBuffEntry* buffer_yield_entry_by_id(ProfBuff buffer, const char *const id); +ProfBuffEntry* buffer_get_entry(ProfBuff buffer, int entry); +ProfBuffEntry* buffer_get_entry_by_id(ProfBuff buffer, const char *const id); gboolean buffer_mark_received(ProfBuff buffer, const char *const id); #endif diff --git a/src/ui/window.c b/src/ui/window.c index 595d6852..1a7dc6bd 100644 --- a/src/ui/window.c +++ b/src/ui/window.c @@ -1026,7 +1026,7 @@ win_println_them_message(ProfWin *window, const char *const them, const char *co GString *fmt_msg = g_string_new(NULL); g_string_vprintf(fmt_msg, message, arg); - buffer_push(window->layout->buffer, '-', 0, timestamp, NO_ME, THEME_TEXT_THEM, them, fmt_msg->str, NULL); + buffer_append(window->layout->buffer, '-', 0, timestamp, NO_ME, THEME_TEXT_THEM, them, fmt_msg->str, NULL); _win_print(window, '-', 0, timestamp, NO_ME, THEME_TEXT_THEM, them, fmt_msg->str, NULL); inp_nonblocking(TRUE); @@ -1046,7 +1046,7 @@ win_println_me_message(ProfWin *window, const char *const me, const char *const GString *fmt_msg = g_string_new(NULL); g_string_vprintf(fmt_msg, message, arg); - buffer_push(window->layout->buffer, '-', 0, timestamp, 0, THEME_TEXT_ME, me, fmt_msg->str, NULL); + buffer_append(window->layout->buffer, '-', 0, timestamp, 0, THEME_TEXT_ME, me, fmt_msg->str, NULL); _win_print(window, '-', 0, timestamp, 0, THEME_TEXT_ME, me, fmt_msg->str, NULL); inp_nonblocking(TRUE); @@ -1066,7 +1066,7 @@ win_print_outgoing(ProfWin *window, const char ch, const char *const message, .. GString *fmt_msg = g_string_new(NULL); g_string_vprintf(fmt_msg, message, arg); - buffer_push(window->layout->buffer, ch, 0, timestamp, 0, THEME_TEXT_ME, "me", fmt_msg->str, NULL); + buffer_append(window->layout->buffer, ch, 0, timestamp, 0, THEME_TEXT_ME, "me", fmt_msg->str, NULL); _win_print(window, ch, 0, timestamp, 0, THEME_TEXT_ME, "me", fmt_msg->str, NULL); inp_nonblocking(TRUE); @@ -1086,7 +1086,7 @@ win_print_history(ProfWin *window, GDateTime *timestamp, const char *const messa GString *fmt_msg = g_string_new(NULL); g_string_vprintf(fmt_msg, message, arg); - buffer_push(window->layout->buffer, '-', 0, timestamp, NO_COLOUR_DATE, THEME_DEFAULT, "", fmt_msg->str, NULL); + buffer_append(window->layout->buffer, '-', 0, timestamp, NO_COLOUR_DATE, THEME_DEFAULT, "", fmt_msg->str, NULL); _win_print(window, '-', 0, timestamp, NO_COLOUR_DATE, THEME_DEFAULT, "", fmt_msg->str, NULL); inp_nonblocking(TRUE); @@ -1106,7 +1106,7 @@ win_print(ProfWin *window, theme_item_t theme_item, const char ch, const char *c GString *fmt_msg = g_string_new(NULL); g_string_vprintf(fmt_msg, message, arg); - buffer_push(window->layout->buffer, ch, 0, timestamp, NO_EOL, theme_item, "", fmt_msg->str, NULL); + buffer_append(window->layout->buffer, ch, 0, timestamp, NO_EOL, theme_item, "", fmt_msg->str, NULL); _win_print(window, ch, 0, timestamp, NO_EOL, theme_item, "", fmt_msg->str, NULL); inp_nonblocking(TRUE); @@ -1126,7 +1126,7 @@ win_println(ProfWin *window, theme_item_t theme_item, const char ch, const char GString *fmt_msg = g_string_new(NULL); g_string_vprintf(fmt_msg, message, arg); - buffer_push(window->layout->buffer, ch, 0, timestamp, 0, theme_item, "", fmt_msg->str, NULL); + buffer_append(window->layout->buffer, ch, 0, timestamp, 0, theme_item, "", fmt_msg->str, NULL); _win_print(window, ch, 0, timestamp, 0, theme_item, "", fmt_msg->str, NULL); inp_nonblocking(TRUE); @@ -1146,7 +1146,7 @@ win_println_indent(ProfWin *window, int pad, const char *const message, ...) GString *fmt_msg = g_string_new(NULL); g_string_vprintf(fmt_msg, message, arg); - buffer_push(window->layout->buffer, '-', pad, timestamp, 0, THEME_DEFAULT, "", fmt_msg->str, NULL); + buffer_append(window->layout->buffer, '-', pad, timestamp, 0, THEME_DEFAULT, "", fmt_msg->str, NULL); _win_print(window, '-', pad, timestamp, 0, THEME_DEFAULT, "", fmt_msg->str, NULL); inp_nonblocking(TRUE); @@ -1166,7 +1166,7 @@ win_append(ProfWin *window, theme_item_t theme_item, const char *const message, GString *fmt_msg = g_string_new(NULL); g_string_vprintf(fmt_msg, message, arg); - buffer_push(window->layout->buffer, '-', 0, timestamp, NO_DATE | NO_EOL, theme_item, "", fmt_msg->str, NULL); + buffer_append(window->layout->buffer, '-', 0, timestamp, NO_DATE | NO_EOL, theme_item, "", fmt_msg->str, NULL); _win_print(window, '-', 0, timestamp, NO_DATE | NO_EOL, theme_item, "", fmt_msg->str, NULL); inp_nonblocking(TRUE); @@ -1186,7 +1186,7 @@ win_appendln(ProfWin *window, theme_item_t theme_item, const char *const message GString *fmt_msg = g_string_new(NULL); g_string_vprintf(fmt_msg, message, arg); - buffer_push(window->layout->buffer, '-', 0, timestamp, NO_DATE, theme_item, "", fmt_msg->str, NULL); + buffer_append(window->layout->buffer, '-', 0, timestamp, NO_DATE, theme_item, "", fmt_msg->str, NULL); _win_print(window, '-', 0, timestamp, NO_DATE, theme_item, "", fmt_msg->str, NULL); inp_nonblocking(TRUE); @@ -1206,7 +1206,7 @@ win_append_highlight(ProfWin *window, theme_item_t theme_item, const char *const GString *fmt_msg = g_string_new(NULL); g_string_vprintf(fmt_msg, message, arg); - buffer_push(window->layout->buffer, '-', 0, timestamp, NO_DATE | NO_ME | NO_EOL, theme_item, "", fmt_msg->str, NULL); + buffer_append(window->layout->buffer, '-', 0, timestamp, NO_DATE | NO_ME | NO_EOL, theme_item, "", fmt_msg->str, NULL); _win_print(window, '-', 0, timestamp, NO_DATE | NO_ME | NO_EOL, theme_item, "", fmt_msg->str, NULL); inp_nonblocking(TRUE); @@ -1226,7 +1226,7 @@ win_appendln_highlight(ProfWin *window, theme_item_t theme_item, const char *con GString *fmt_msg = g_string_new(NULL); g_string_vprintf(fmt_msg, message, arg); - buffer_push(window->layout->buffer, '-', 0, timestamp, NO_DATE | NO_ME, theme_item, "", fmt_msg->str, NULL); + buffer_append(window->layout->buffer, '-', 0, timestamp, NO_DATE | NO_ME, theme_item, "", fmt_msg->str, NULL); _win_print(window, '-', 0, timestamp, NO_DATE | NO_ME, theme_item, "", fmt_msg->str, NULL); inp_nonblocking(TRUE); @@ -1252,7 +1252,7 @@ win_print_with_receipt(ProfWin *window, const char show_char, const char *const receipt->id = strdup(id); receipt->received = FALSE; - buffer_push(window->layout->buffer, show_char, 0, time, 0, THEME_TEXT_ME, from, message, receipt); + buffer_append(window->layout->buffer, show_char, 0, time, 0, THEME_TEXT_ME, from, message, receipt); _win_print(window, show_char, 0, time, 0, THEME_TEXT_ME, from, message, receipt); // TODO: cross-reference.. this should be replaced by a real event-based system inp_nonblocking(TRUE); @@ -1271,7 +1271,7 @@ win_mark_received(ProfWin *window, const char *const id) void win_update_entry_message(ProfWin *window, const char *const id, const char *const message) { - ProfBuffEntry *entry = buffer_yield_entry_by_id(window->layout->buffer, id); + ProfBuffEntry *entry = buffer_get_entry_by_id(window->layout->buffer, id); if (entry) { free(entry->message); entry->message = strdup(message); @@ -1282,7 +1282,7 @@ win_update_entry_message(ProfWin *window, const char *const id, const char *cons void win_update_entry_theme(ProfWin *window, const char *const id, theme_item_t theme_item) { - ProfBuffEntry *entry = buffer_yield_entry_by_id(window->layout->buffer, id); + ProfBuffEntry *entry = buffer_get_entry_by_id(window->layout->buffer, id); if (entry) { entry->theme_item = theme_item; win_redraw(window); @@ -1310,7 +1310,7 @@ _win_printf(ProfWin *window, const char show_char, int pad_indent, GDateTime *ti GString *fmt_msg = g_string_new(NULL); g_string_vprintf(fmt_msg, message, arg); - buffer_push(window->layout->buffer, show_char, pad_indent, timestamp, flags, theme_item, from, fmt_msg->str, NULL); + buffer_append(window->layout->buffer, show_char, pad_indent, timestamp, flags, theme_item, from, fmt_msg->str, NULL); _win_print(window, show_char, pad_indent, timestamp, flags, theme_item, from, fmt_msg->str, NULL); inp_nonblocking(TRUE); @@ -1576,7 +1576,7 @@ win_redraw(ProfWin *window) size = buffer_size(window->layout->buffer); for (i = 0; i < size; i++) { - ProfBuffEntry *e = buffer_yield_entry(window->layout->buffer, i); + ProfBuffEntry *e = buffer_get_entry(window->layout->buffer, i); _win_print(window, e->show_char, e->pad_indent, e->time, e->flags, e->theme_item, e->from, e->message, e->receipt); } } From 2032978ff6490f56a64947730b0647e0a3a7cfd0 Mon Sep 17 00:00:00 2001 From: James Booth Date: Sun, 16 Oct 2016 19:45:06 +0100 Subject: [PATCH 04/14] Remove cons_show_time --- src/ui/console.c | 7 ------- src/ui/ui.h | 1 - 2 files changed, 8 deletions(-) diff --git a/src/ui/console.c b/src/ui/console.c index ff80750e..3602d972 100644 --- a/src/ui/console.c +++ b/src/ui/console.c @@ -63,13 +63,6 @@ static void _cons_splash_logo(void); void _show_roster_contacts(GSList *list, gboolean show_groups); -void -cons_show_time(void) -{ - ProfWin *console = wins_get_console(); - win_print(console, THEME_DEFAULT, '-', ""); -} - void cons_show_word(const char *const word) { diff --git a/src/ui/ui.h b/src/ui/ui.h index 55f21eea..af0e0715 100644 --- a/src/ui/ui.h +++ b/src/ui/ui.h @@ -246,7 +246,6 @@ void cons_show_otr_prefs(void); void cons_show_pgp_prefs(void); void cons_show_account(ProfAccount *account); void cons_debug(const char *const msg, ...); -void cons_show_time(void); void cons_show_word(const char *const word); void cons_show_error(const char *const cmd, ...); void cons_show_contacts(GSList *list); From 721dd050dfa8c742bf2736d97fdae41967866f20 Mon Sep 17 00:00:00 2001 From: James Booth Date: Sun, 16 Oct 2016 19:48:41 +0100 Subject: [PATCH 05/14] Remove cons_show_word --- src/ui/console.c | 7 ------- src/ui/ui.h | 1 - 2 files changed, 8 deletions(-) diff --git a/src/ui/console.c b/src/ui/console.c index 3602d972..c990f69b 100644 --- a/src/ui/console.c +++ b/src/ui/console.c @@ -63,13 +63,6 @@ static void _cons_splash_logo(void); void _show_roster_contacts(GSList *list, gboolean show_groups); -void -cons_show_word(const char *const word) -{ - ProfWin *console = wins_get_console(); - win_append(console, THEME_DEFAULT, "%s", word); -} - void cons_debug(const char *const msg, ...) { diff --git a/src/ui/ui.h b/src/ui/ui.h index af0e0715..e681456a 100644 --- a/src/ui/ui.h +++ b/src/ui/ui.h @@ -246,7 +246,6 @@ void cons_show_otr_prefs(void); void cons_show_pgp_prefs(void); void cons_show_account(ProfAccount *account); void cons_debug(const char *const msg, ...); -void cons_show_word(const char *const word); void cons_show_error(const char *const cmd, ...); void cons_show_contacts(GSList *list); void cons_show_roster(GSList *list); From 8fd9f9e2011aa400c1265ea5bd0d71377506afcb Mon Sep 17 00:00:00 2001 From: James Booth Date: Sun, 16 Oct 2016 19:51:56 +0100 Subject: [PATCH 06/14] Remove unused function prototype --- src/ui/ui.h | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/ui/ui.h b/src/ui/ui.h index e681456a..1a692fd8 100644 --- a/src/ui/ui.h +++ b/src/ui/ui.h @@ -260,8 +260,6 @@ void cons_show_scripts(GSList *scripts); void cons_show_script(const char *const script, GSList *commands); void cons_show_aliases(GList *aliases); void cons_show_login_success(ProfAccount *account, gboolean secured); -void cons_show_software_version(const char *const jid, const char *const presence, const char *const name, - const char *const version, const char *const os); void cons_show_account_list(gchar **accounts); void cons_show_room_list(GSList *room, const char *const conference_node); void cons_show_bookmarks(const GList *list); From 257d2d4f4f0ab048dd1444d346b931401e7f1a27 Mon Sep 17 00:00:00 2001 From: James Booth Date: Sun, 16 Oct 2016 20:12:49 +0100 Subject: [PATCH 07/14] Remove unused function prototypes --- src/ui/ui.h | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/ui/ui.h b/src/ui/ui.h index 1a692fd8..ddcf884c 100644 --- a/src/ui/ui.h +++ b/src/ui/ui.h @@ -120,10 +120,8 @@ void ui_prune_wins(void); void ui_auto_away(char *message, gint time, resource_presence_t res_presence); void ui_handle_login_account_success(ProfAccount *account, gboolean secured); void ui_update_presence(const resource_presence_t resource_presence, const char *const message, const char *const show); -void ui_write(char *line, int offset); void ui_invalid_command_usage(const char *const cmd, void (*setting_func)(void)); gboolean ui_win_has_unsaved_form(int num); -void ui_inp_history_append(char *inp); // Chat window ProfChatWin* chatwin_new(const char *const barejid); From 769e71b17b32235b3efd0a05c94709f3f6e0a4d8 Mon Sep 17 00:00:00 2001 From: James Booth Date: Sun, 16 Oct 2016 21:45:48 +0100 Subject: [PATCH 08/14] Remove ui_current_print_line --- src/command/cmd_funcs.c | 132 ++++++++++++++++----------------- src/ui/core.c | 15 +--- src/ui/ui.h | 1 - tests/unittests/test_cmd_otr.c | 4 +- tests/unittests/ui/stub_ui.c | 16 +++- 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); } } @@ -731,19 +731,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, ...) { 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); From 333403d2e5c54039d84578c94dfe777ebf7d08d0 Mon Sep 17 00:00:00 2001 From: James Booth Date: Sun, 16 Oct 2016 22:13:49 +0100 Subject: [PATCH 09/14] Remove ui_current_print_formatted_line --- src/command/cmd_funcs.c | 56 +++++++++++++++++----------------- src/ui/core.c | 13 -------- src/ui/ui.h | 1 - tests/unittests/test_cmd_otr.c | 12 ++++---- tests/unittests/ui/stub_ui.c | 8 ----- tests/unittests/ui/stub_ui.h | 1 - 6 files changed, 34 insertions(+), 57 deletions(-) diff --git a/src/command/cmd_funcs.c b/src/command/cmd_funcs.c index 84cc7943..c045a627 100644 --- a/src/command/cmd_funcs.c +++ b/src/command/cmd_funcs.c @@ -4333,9 +4333,9 @@ cmd_bookmark(ProfWin *window, const char *const command, gchar **args) char *password = muc_password(mucwin->roomjid); gboolean added = bookmark_add(mucwin->roomjid, nick, password, "on"); if (added) { - ui_current_print_formatted_line('!', 0, "Bookmark added for %s.", mucwin->roomjid); + win_println(window, THEME_DEFAULT, '!', "Bookmark added for %s.", mucwin->roomjid); } else { - ui_current_print_formatted_line('!', 0, "Bookmark already exists for %s.", mucwin->roomjid); + win_println(window, THEME_DEFAULT, '!', "Bookmark already exists for %s.", mucwin->roomjid); } return TRUE; } @@ -4345,9 +4345,9 @@ cmd_bookmark(ProfWin *window, const char *const command, gchar **args) assert(mucwin->memcheck == PROFMUCWIN_MEMCHECK); gboolean removed = bookmark_remove(mucwin->roomjid); if (removed) { - ui_current_print_formatted_line('!', 0, "Bookmark removed for %s.", mucwin->roomjid); + win_println(window, THEME_DEFAULT, '!', "Bookmark removed for %s.", mucwin->roomjid); } else { - ui_current_print_formatted_line('!', 0, "Bookmark does not exist for %s.", mucwin->roomjid); + win_println(window, THEME_DEFAULT, '!', "Bookmark does not exist for %s.", mucwin->roomjid); } return TRUE; } @@ -6480,19 +6480,19 @@ cmd_pgp(ProfWin *window, const char *const command, gchar **args) } if (chatwin->is_otr) { - ui_current_print_formatted_line('!', 0, "You must end the OTR session to start PGP encryption."); + win_println(window, THEME_DEFAULT, '!', "You must end the OTR session to start PGP encryption."); return TRUE; } if (chatwin->pgp_send) { - ui_current_print_formatted_line('!', 0, "You have already started PGP encryption."); + win_println(window, THEME_DEFAULT, '!', "You have already started PGP encryption."); return TRUE; } ProfAccount *account = accounts_get_account(session_get_account_name()); char *err_str = NULL; if (!p_gpg_valid_key(account->pgp_keyid, &err_str)) { - ui_current_print_formatted_line('!', 0, "Invalid PGP key ID %s: %s, cannot start PGP encryption.", account->pgp_keyid, err_str); + win_println(window, THEME_DEFAULT, '!', "Invalid PGP key ID %s: %s, cannot start PGP encryption.", account->pgp_keyid, err_str); free(err_str); account_free(account); return TRUE; @@ -6501,12 +6501,12 @@ cmd_pgp(ProfWin *window, const char *const command, gchar **args) account_free(account); if (!p_gpg_available(chatwin->barejid)) { - ui_current_print_formatted_line('!', 0, "No PGP key found for %s.", chatwin->barejid); + win_println(window, THEME_DEFAULT, '!', "No PGP key found for %s.", chatwin->barejid); return TRUE; } chatwin->pgp_send = TRUE; - ui_current_print_formatted_line('!', 0, "PGP encryption enabled."); + win_println(window, THEME_DEFAULT, '!', "PGP encryption enabled."); return TRUE; } @@ -6524,12 +6524,12 @@ cmd_pgp(ProfWin *window, const char *const command, gchar **args) ProfChatWin *chatwin = (ProfChatWin*)window; if (chatwin->pgp_send == FALSE) { - ui_current_print_formatted_line('!', 0, "PGP encryption is not currently enabled."); + win_println(window, THEME_DEFAULT, '!', "PGP encryption is not currently enabled."); return TRUE; } chatwin->pgp_send = FALSE; - ui_current_print_formatted_line('!', 0, "PGP encryption disabled."); + win_println(window, THEME_DEFAULT, '!', "PGP encryption disabled."); return TRUE; } @@ -6676,12 +6676,12 @@ cmd_otr_myfp(ProfWin *window, const char *const command, gchar **args) } if (!otr_key_loaded()) { - ui_current_print_formatted_line('!', 0, "You have not generated or loaded a private key, use '/otr gen'"); + win_println(window, THEME_DEFAULT, '!', "You have not generated or loaded a private key, use '/otr gen'"); return TRUE; } char *fingerprint = otr_get_my_fingerprint(); - ui_current_print_formatted_line('!', 0, "Your OTR fingerprint: %s", fingerprint); + win_println(window, THEME_DEFAULT, '!', "Your OTR fingerprint: %s", fingerprint); free(fingerprint); return TRUE; #else @@ -6707,12 +6707,12 @@ cmd_otr_theirfp(ProfWin *window, const char *const command, gchar **args) ProfChatWin *chatwin = (ProfChatWin*)window; assert(chatwin->memcheck == PROFCHATWIN_MEMCHECK); if (chatwin->is_otr == FALSE) { - ui_current_print_formatted_line('!', 0, "You are not currently in an OTR session."); + win_println(window, THEME_DEFAULT, '!', "You are not currently in an OTR session."); return TRUE; } char *fingerprint = otr_get_their_fingerprint(chatwin->barejid); - ui_current_print_formatted_line('!', 0, "%s's OTR fingerprint: %s", chatwin->barejid, fingerprint); + win_println(window, THEME_DEFAULT, '!', "%s's OTR fingerprint: %s", chatwin->barejid, fingerprint); free(fingerprint); return TRUE; #else @@ -6745,17 +6745,17 @@ cmd_otr_start(ProfWin *window, const char *const command, gchar **args) ui_focus_win((ProfWin*)chatwin); if (chatwin->pgp_send) { - ui_current_print_formatted_line('!', 0, "You must disable PGP encryption before starting an OTR session."); + win_println(window, THEME_DEFAULT, '!', "You must disable PGP encryption before starting an OTR session."); return TRUE; } if (chatwin->is_otr) { - ui_current_print_formatted_line('!', 0, "You are already in an OTR session."); + win_println(window, THEME_DEFAULT, '!', "You are already in an OTR session."); return TRUE; } if (!otr_key_loaded()) { - ui_current_print_formatted_line('!', 0, "You have not generated or loaded a private key, use '/otr gen'"); + win_println(window, THEME_DEFAULT, '!', "You have not generated or loaded a private key, use '/otr gen'"); return TRUE; } @@ -6779,17 +6779,17 @@ cmd_otr_start(ProfWin *window, const char *const command, gchar **args) ProfChatWin *chatwin = (ProfChatWin*)window; assert(chatwin->memcheck == PROFCHATWIN_MEMCHECK); if (chatwin->pgp_send) { - ui_current_print_formatted_line('!', 0, "You must disable PGP encryption before starting an OTR session."); + win_println(window, THEME_DEFAULT, '!', "You must disable PGP encryption before starting an OTR session."); return TRUE; } if (chatwin->is_otr) { - ui_current_print_formatted_line('!', 0, "You are already in an OTR session."); + win_println(window, THEME_DEFAULT, '!', "You are already in an OTR session."); return TRUE; } if (!otr_key_loaded()) { - ui_current_print_formatted_line('!', 0, "You have not generated or loaded a private key, use '/otr gen'"); + win_println(window, THEME_DEFAULT, '!', "You have not generated or loaded a private key, use '/otr gen'"); return TRUE; } @@ -6821,7 +6821,7 @@ cmd_otr_end(ProfWin *window, const char *const command, gchar **args) ProfChatWin *chatwin = (ProfChatWin*)window; assert(chatwin->memcheck == PROFCHATWIN_MEMCHECK); if (chatwin->is_otr == FALSE) { - ui_current_print_formatted_line('!', 0, "You are not currently in an OTR session."); + win_println(window, THEME_DEFAULT, '!', "You are not currently in an OTR session."); return TRUE; } @@ -6851,7 +6851,7 @@ cmd_otr_trust(ProfWin *window, const char *const command, gchar **args) ProfChatWin *chatwin = (ProfChatWin*)window; assert(chatwin->memcheck == PROFCHATWIN_MEMCHECK); if (chatwin->is_otr == FALSE) { - ui_current_print_formatted_line('!', 0, "You are not currently in an OTR session."); + win_println(window, THEME_DEFAULT, '!', "You are not currently in an OTR session."); return TRUE; } @@ -6881,7 +6881,7 @@ cmd_otr_untrust(ProfWin *window, const char *const command, gchar **args) ProfChatWin *chatwin = (ProfChatWin*)window; assert(chatwin->memcheck == PROFCHATWIN_MEMCHECK); if (chatwin->is_otr == FALSE) { - ui_current_print_formatted_line('!', 0, "You are not currently in an OTR session."); + win_println(window, THEME_DEFAULT, '!', "You are not currently in an OTR session."); return TRUE; } @@ -6911,7 +6911,7 @@ cmd_otr_secret(ProfWin *window, const char *const command, gchar **args) ProfChatWin *chatwin = (ProfChatWin*)window; assert(chatwin->memcheck == PROFCHATWIN_MEMCHECK); if (chatwin->is_otr == FALSE) { - ui_current_print_formatted_line('!', 0, "You are not currently in an OTR session."); + win_println(window, THEME_DEFAULT, '!', "You are not currently in an OTR session."); return TRUE; } @@ -6953,7 +6953,7 @@ cmd_otr_question(ProfWin *window, const char *const command, gchar **args) ProfChatWin *chatwin = (ProfChatWin*)window; assert(chatwin->memcheck == PROFCHATWIN_MEMCHECK); if (chatwin->is_otr == FALSE) { - ui_current_print_formatted_line('!', 0, "You are not currently in an OTR session."); + win_println(window, THEME_DEFAULT, '!', "You are not currently in an OTR session."); return TRUE; } @@ -6982,7 +6982,7 @@ cmd_otr_answer(ProfWin *window, const char *const command, gchar **args) ProfChatWin *chatwin = (ProfChatWin*)window; assert(chatwin->memcheck == PROFCHATWIN_MEMCHECK); if (chatwin->is_otr == FALSE) { - ui_current_print_formatted_line('!', 0, "You are not currently in an OTR session."); + win_println(window, THEME_DEFAULT, '!', "You are not currently in an OTR session."); return TRUE; } @@ -7014,7 +7014,7 @@ _cmd_execute(ProfWin *window, const char *const command, const char *const inp) gboolean result = FALSE; gchar **args = parse_args_with_freetext(inp, 1, 2, &result); if (!result) { - ui_current_print_formatted_line('!', 0, "Invalid command, see /form help"); + win_println(window, THEME_DEFAULT, '!', "Invalid command, see /form help"); result = TRUE; } else { gchar **tokens = g_strsplit(inp, " ", 2); diff --git a/src/ui/core.c b/src/ui/core.c index a72423e4..62cf3a02 100644 --- a/src/ui/core.c +++ b/src/ui/core.c @@ -731,19 +731,6 @@ ui_prune_wins(void) } } -void -ui_current_print_formatted_line(const char show_char, int attrs, const char *const msg, ...) -{ - ProfWin *current = 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(current, attrs, show_char, "%s", fmt_msg->str); - va_end(arg); - g_string_free(fmt_msg, TRUE); -} - void ui_print_system_msg_from_recipient(const char *const barejid, const char *message) { diff --git a/src/ui/ui.h b/src/ui/ui.h index 5a8a09ae..44d87966 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_formatted_line(const char show_char, int attrs, const char *const msg, ...); void ui_close_win(int index); int ui_win_unread(int index); char* ui_ask_password(void); diff --git a/tests/unittests/test_cmd_otr.c b/tests/unittests/test_cmd_otr.c index 088b8baa..314a64b2 100644 --- a/tests/unittests/test_cmd_otr.c +++ b/tests/unittests/test_cmd_otr.c @@ -216,7 +216,7 @@ void cmd_otr_myfp_shows_message_when_no_key(void **state) will_return(connection_get_status, JABBER_CONNECTED); will_return(otr_key_loaded, FALSE); - expect_ui_current_print_formatted_line('!', 0, "You have not generated or loaded a private key, use '/otr gen'"); + expect_win_println("You have not generated or loaded a private key, use '/otr gen'"); gboolean result = cmd_otr_myfp(NULL, CMD_OTR, args); assert_true(result); @@ -233,7 +233,7 @@ void cmd_otr_myfp_shows_my_fingerprint(void **state) will_return(otr_key_loaded, TRUE); will_return(otr_get_my_fingerprint, strdup(fingerprint)); - expect_ui_current_print_formatted_line('!', 0, message->str); + expect_win_println(message->str); gboolean result = cmd_otr_myfp(NULL, CMD_OTR, args); assert_true(result); @@ -286,7 +286,7 @@ void cmd_otr_theirfp_shows_message_when_non_otr_chat_window(void **state) will_return(connection_get_status, JABBER_CONNECTED); - expect_ui_current_print_formatted_line('!', 0, "You are not currently in an OTR session."); + expect_win_println("You are not currently in an OTR session."); gboolean result = cmd_otr_theirfp((ProfWin*)&chatwin, CMD_OTR, args); @@ -316,7 +316,7 @@ void cmd_otr_theirfp_shows_fingerprint(void **state) expect_string(otr_get_their_fingerprint, recipient, recipient); will_return(otr_get_their_fingerprint, strdup(fingerprint)); - expect_ui_current_print_formatted_line('!', 0, message->str); + expect_win_println(message->str); gboolean result = cmd_otr_theirfp((ProfWin*)&chatwin, CMD_OTR, args); assert_true(result); @@ -370,7 +370,7 @@ void cmd_otr_start_shows_message_when_already_started(void **state) chatwin.pgp_send = FALSE; chatwin.is_otr = TRUE; - expect_ui_current_print_formatted_line('!', 0, "You are already in an OTR session."); + expect_win_println("You are already in an OTR session."); gboolean result = cmd_otr_start((ProfWin*)&chatwin, CMD_OTR, args); assert_true(result); @@ -393,7 +393,7 @@ void cmd_otr_start_shows_message_when_no_key(void **state) chatwin.pgp_send = FALSE; chatwin.is_otr = FALSE; - expect_ui_current_print_formatted_line('!', 0, "You have not generated or loaded a private key, use '/otr gen'"); + expect_win_println("You have not generated or loaded a private key, use '/otr gen'"); gboolean result = cmd_otr_start((ProfWin*)&chatwin, CMD_OTR, args); assert_true(result); diff --git a/tests/unittests/ui/stub_ui.c b/tests/unittests/ui/stub_ui.c index da253774..e4f56c85 100644 --- a/tests/unittests/ui/stub_ui.c +++ b/tests/unittests/ui/stub_ui.c @@ -48,14 +48,6 @@ expect_win_println(char *message) expect_string(win_println, output, message); } -void -expect_ui_current_print_formatted_line(char show_char, int attrs, char *message) -{ - expect_value(ui_current_print_formatted_line, show_char, show_char); - expect_value(ui_current_print_formatted_line, attrs, attrs); - expect_string(ui_current_print_formatted_line, output, message); -} - // stubs void ui_init(void) {} diff --git a/tests/unittests/ui/stub_ui.h b/tests/unittests/ui/stub_ui.h index a1b94478..635f719e 100644 --- a/tests/unittests/ui/stub_ui.h +++ b/tests/unittests/ui/stub_ui.h @@ -2,5 +2,4 @@ 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_formatted_line(char show_char, int attrs, char *message); void expect_win_println(char *message); From 503e0ae38ee70497ffc5cd90a4443ca87cd468f6 Mon Sep 17 00:00:00 2001 From: James Booth Date: Sun, 16 Oct 2016 22:20:36 +0100 Subject: [PATCH 10/14] Fix time.xmlconsole in themes --- themes/bios | 2 +- themes/boothj5 | 2 +- themes/boothj5_laptop | 2 +- themes/boothj5_slack | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/themes/bios b/themes/bios index 3d524652..80ac885f 100644 --- a/themes/bios +++ b/themes/bios @@ -86,7 +86,7 @@ time.chat=%d/%m/%y %H:%M:%S time.muc=%d/%m/%y %H:%M:%S time.mucconfig=off time.private=%d/%m/%y %H:%M:%S -time.xml=%H:%M:%S +time.xmlconsole=%H:%M:%S time.statusbar=%H:%M:%S time.lastactivity=%d/%m/%y %H:%M:%S privileges=true diff --git a/themes/boothj5 b/themes/boothj5 index fc7c8b8a..a0da10c5 100644 --- a/themes/boothj5 +++ b/themes/boothj5 @@ -86,7 +86,7 @@ time.chat=%d/%m/%y %H:%M:%S time.muc=%d/%m/%y %H:%M:%S time.mucconfig=off time.private=%d/%m/%y %H:%M:%S -time.xml=%H:%M:%S +time.xmlconsole=%H:%M:%S time.statusbar=%H:%M:%S time.lastactivity=%d/%m/%y %H:%M:%S privileges=true diff --git a/themes/boothj5_laptop b/themes/boothj5_laptop index f1da2d1d..8c5a9a26 100644 --- a/themes/boothj5_laptop +++ b/themes/boothj5_laptop @@ -86,7 +86,7 @@ time.chat=%H:%M:%S time.muc=%H:%M:%S time.mucconfig=off time.private=%H:%M:%S -time.xml=%H:%M:%S +time.xmlconsole=%H:%M:%S time.statusbar=%H:%M:%S time.lastactivity=%d/%m/%y %H:%M:%S privileges=true diff --git a/themes/boothj5_slack b/themes/boothj5_slack index 2c306598..b372df77 100644 --- a/themes/boothj5_slack +++ b/themes/boothj5_slack @@ -86,7 +86,7 @@ time.chat=%d/%m/%y %H:%M:%S time.muc=%d/%m/%y %H:%M:%S time.mucconfig=off time.private=%d/%m/%y %H:%M:%S -time.xml=%H:%M:%S +time.xmlconsole=%H:%M:%S time.statusbar=%H:%M:%S time.lastactivity=%d/%m/%y %H:%M:%S privileges=false From 04e0a533812e1daba8d535f841894508c2a52447 Mon Sep 17 00:00:00 2001 From: James Booth Date: Sun, 16 Oct 2016 22:34:27 +0100 Subject: [PATCH 11/14] Remove unused functions --- src/ui/core.c | 18 ------------------ 1 file changed, 18 deletions(-) diff --git a/src/ui/core.c b/src/ui/core.c index 62cf3a02..8078d7b7 100644 --- a/src/ui/core.c +++ b/src/ui/core.c @@ -1289,21 +1289,3 @@ ui_show_software_version(const char *const jid, const char *const presence, win_println(window, THEME_DEFAULT, '-', "OS : %s", os); } } - -void -ui_status_bar_inactive(const int win) -{ - status_bar_inactive(win); -} - -void -ui_status_bar_active(const int win) -{ - status_bar_active(win); -} - -void -ui_status_bar_new(const int win) -{ - status_bar_new(win); -} From 3671dbb57609020a72f294a7b652c18cb6bad8cd Mon Sep 17 00:00:00 2001 From: James Booth Date: Sun, 16 Oct 2016 22:48:39 +0100 Subject: [PATCH 12/14] Update theme boothj5_laptop --- themes/boothj5_laptop | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/themes/boothj5_laptop b/themes/boothj5_laptop index 8c5a9a26..20bfc39c 100644 --- a/themes/boothj5_laptop +++ b/themes/boothj5_laptop @@ -81,12 +81,12 @@ beep=false flash=false splash=true wrap=true -time.console=%H:%M:%S +time.console=off time.chat=%H:%M:%S time.muc=%H:%M:%S time.mucconfig=off time.private=%H:%M:%S -time.xmlconsole=%H:%M:%S +time.xmlconsole=off time.statusbar=%H:%M:%S time.lastactivity=%d/%m/%y %H:%M:%S privileges=true From 0e1df8c5429dddca23d3701de8518a3870297717 Mon Sep 17 00:00:00 2001 From: James Booth Date: Sun, 16 Oct 2016 22:56:52 +0100 Subject: [PATCH 13/14] Update theme boothj5_laptop --- themes/boothj5_laptop | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/themes/boothj5_laptop b/themes/boothj5_laptop index 20bfc39c..86339c1e 100644 --- a/themes/boothj5_laptop +++ b/themes/boothj5_laptop @@ -81,7 +81,7 @@ beep=false flash=false splash=true wrap=true -time.console=off +time.console=%H:%M:%S time.chat=%H:%M:%S time.muc=%H:%M:%S time.mucconfig=off From 5b464f4cb0de55daa39fa202819e79d113945e6c Mon Sep 17 00:00:00 2001 From: James Booth Date: Mon, 17 Oct 2016 23:48:03 +0100 Subject: [PATCH 14/14] Add /tls certpath default issue #871 --- src/command/cmd_ac.c | 1 + src/command/cmd_defs.c | 2 ++ src/command/cmd_funcs.c | 10 +++++++--- src/config/preferences.c | 39 +++++++++++++++++++++++++++++++++++++++ src/config/preferences.h | 2 ++ src/xmpp/connection.c | 4 ++-- 6 files changed, 53 insertions(+), 5 deletions(-) diff --git a/src/command/cmd_ac.c b/src/command/cmd_ac.c index 6d87a5d8..2d3209d5 100644 --- a/src/command/cmd_ac.c +++ b/src/command/cmd_ac.c @@ -683,6 +683,7 @@ cmd_ac_init(void) tls_certpath_ac = autocomplete_new(); autocomplete_add(tls_certpath_ac, "set"); autocomplete_add(tls_certpath_ac, "clear"); + autocomplete_add(tls_certpath_ac, "default"); script_ac = autocomplete_new(); autocomplete_add(script_ac, "run"); diff --git a/src/command/cmd_defs.c b/src/command/cmd_defs.c index f8d8c2ff..34400ae3 100644 --- a/src/command/cmd_defs.c +++ b/src/command/cmd_defs.c @@ -200,6 +200,7 @@ static struct cmd_t command_defs[] = "/tls certpath", "/tls certpath set ", "/tls certpath clear", + "/tls certpath default", "/tls show on|off") CMD_DESC( "Handle TLS certificates. ") @@ -215,6 +216,7 @@ static struct cmd_t command_defs[] = { "certpath", "Show the trusted certificate path." }, { "certpath set ", "Specify filesystem path containing trusted certificates." }, { "certpath clear", "Clear the trusted certificate path." }, + { "certpath default", "Use default system certificate path, if it can be found." }, { "show on|off", "Show or hide the TLS indicator in the titlebar." }) CMD_NOEXAMPLES }, diff --git a/src/command/cmd_funcs.c b/src/command/cmd_funcs.c index c045a627..35ae3119 100644 --- a/src/command/cmd_funcs.c +++ b/src/command/cmd_funcs.c @@ -171,14 +171,18 @@ cmd_tls_certpath(ProfWin *window, const char *const command, gchar **args) } return TRUE; } else if (g_strcmp0(args[1], "clear") == 0) { - prefs_set_string(PREF_TLS_CERTPATH, NULL); + prefs_set_string(PREF_TLS_CERTPATH, "none"); cons_show("Certificate path cleared"); return TRUE; + } else if (g_strcmp0(args[1], "default") == 0) { + prefs_set_string(PREF_TLS_CERTPATH, NULL); + cons_show("Certificate path defaulted to finding system certpath."); + return TRUE; } else if (args[1] == NULL) { - char *path = prefs_get_string(PREF_TLS_CERTPATH); + char *path = prefs_get_tls_certpath(); if (path) { cons_show("Trusted certificate path: %s", path); - prefs_free_string(path); + free(path); } else { cons_show("No trusted certificate path set."); } diff --git a/src/config/preferences.c b/src/config/preferences.c index f6f73995..4eed12ff 100644 --- a/src/config/preferences.c +++ b/src/config/preferences.c @@ -460,6 +460,45 @@ prefs_set_string(preference_t pref, char *value) _save_prefs(); } +char* +prefs_get_tls_certpath(void) +{ + const char *group = _get_group(PREF_TLS_CERTPATH); + const char *key = _get_key(PREF_TLS_CERTPATH); + + char *setting = g_key_file_get_string(prefs, group, key, NULL); + + if (g_strcmp0(setting, "none") == 0) { + prefs_free_string(setting); + return NULL; + } + + if (setting == NULL) { + if (g_file_test("/etc/ssl/certs", G_FILE_TEST_IS_DIR)) { + return strdup("/etc/ssl/certs"); + } + if (g_file_test("/etc/pki/tls/certs", G_FILE_TEST_IS_DIR)) { + return strdup("/etc/pki/tls/certs"); + } + if (g_file_test("/etc/ssl", G_FILE_TEST_IS_DIR)) { + return strdup("/etc/ssl"); + } + if (g_file_test("/etc/pki/tls", G_FILE_TEST_IS_DIR)) { + return strdup("/etc/pki/tls"); + } + if (g_file_test("/system/etc/security/cacerts", G_FILE_TEST_IS_DIR)) { + return strdup("/system/etc/security/cacerts"); + } + + return NULL; + } + + char *result = strdup(setting); + prefs_free_string(setting); + + return result; +} + gint prefs_get_gone(void) { diff --git a/src/config/preferences.h b/src/config/preferences.h index e0ac7442..72385de5 100644 --- a/src/config/preferences.h +++ b/src/config/preferences.h @@ -266,6 +266,8 @@ char* prefs_get_string(preference_t pref); void prefs_free_string(char *pref); void prefs_set_string(preference_t pref, char *value); +char* prefs_get_tls_certpath(void); + gboolean prefs_do_chat_notify(gboolean current_win); gboolean prefs_do_room_notify(gboolean current_win, const char *const roomjid, const char *const mynick, const char *const theirnick, const char *const message, gboolean mention, gboolean trigger_found); diff --git a/src/xmpp/connection.c b/src/xmpp/connection.c index 70ca12b0..304d984d 100644 --- a/src/xmpp/connection.c +++ b/src/xmpp/connection.c @@ -160,11 +160,11 @@ connection_connect(const char *const fulljid, const char *const passwd, const ch } #ifdef HAVE_LIBMESODE - char *cert_path = prefs_get_string(PREF_TLS_CERTPATH); + char *cert_path = prefs_get_tls_certpath(); if (cert_path) { xmpp_conn_tlscert_path(conn.xmpp_conn, cert_path); + free(cert_path); } - prefs_free_string(cert_path); int connect_status = xmpp_connect_client( conn.xmpp_conn,