From 2c003dd2e1a1fb956de6ed58c073e5b9d1cc5f3c Mon Sep 17 00:00:00 2001 From: Artjom Vejsel Date: Tue, 29 Mar 2022 20:34:34 +0300 Subject: [PATCH 1/4] add /stamp command command allow override standard stamps of incoming and outgoing messages --- src/command/cmd_defs.c | 24 +++++++++++++++++++ src/command/cmd_funcs.c | 51 ++++++++++++++++++++++++++++++++++++++++ src/command/cmd_funcs.h | 1 + src/config/preferences.c | 10 ++++++++ src/config/preferences.h | 2 ++ src/ui/window.c | 5 ++-- src/xmpp/roster_list.c | 6 +++++ 7 files changed, 97 insertions(+), 2 deletions(-) diff --git a/src/command/cmd_defs.c b/src/command/cmd_defs.c index 24d4a737..db42be1c 100644 --- a/src/command/cmd_defs.c +++ b/src/command/cmd_defs.c @@ -2411,6 +2411,30 @@ static struct cmd_t command_defs[] = { "/color own off") }, + { "/stamp", + parse_args, 0, 2, NULL, + CMD_NOSUBFUNCS + CMD_MAINFUNC(cmd_stamp) + CMD_TAGS( + CMD_TAG_UI) + CMD_SYN( + "/stamp outgoing ", + "/stamp incoming ", + "/stamp unset outgoing|incoming") + CMD_DESC( + "Set chat window stamp values. " + "Current format of single log-line in the chat window next: \" \" " + "where is \"me:\" for incoming messages or \"username@server/resource\" for outcoming messages. " + "This command allows to change value.") + CMD_ARGS( + { "outgoing", "Set outgoing messages stamp" }, + { "incoming", "Set incoming stamp"}, + { "unset outgoing|incoming", "unset stamp"}) + CMD_EXAMPLES( + "/stamp outgoing -->", + "/stamp incoming <--") + }, + { "/avatar", parse_args, 2, 2, NULL, CMD_NOSUBFUNCS diff --git a/src/command/cmd_funcs.c b/src/command/cmd_funcs.c index 685369c4..39fc087a 100644 --- a/src/command/cmd_funcs.c +++ b/src/command/cmd_funcs.c @@ -9019,6 +9019,57 @@ cmd_paste(ProfWin* window, const char* const command, gchar** args) return TRUE; } +gboolean +cmd_stamp(ProfWin* window, const char* const command, gchar** args) +{ + if (g_strv_length(args) == 0) { + char* def = prefs_get_string(PREF_OUTGOING_STR); + if (def) { + cons_show("The outgoing stamp is: %s", def); + free(def); + } else { + cons_show("No outgoing stamp."); + } + def = prefs_get_string(PREF_INCOMING_STR); + if (def) { + cons_show("The incoming stamp is: %s", def); + free(def); + } else { + cons_show("No incoming stamp."); + } + return TRUE; + } + + if (g_strv_length(args) == 1) { + cons_show("Wrong usage: need a parameter."); + return TRUE; + } + + if (g_strv_length(args) == 2) { + if (g_strcmp0(args[0], "outgoing") == 0) { + prefs_set_string(PREF_OUTGOING_STR, args[1]); + cons_show("Outgoing stamp set to: %s", args[1]); + } else if (g_strcmp0(args[0], "incoming") == 0) { + prefs_set_string(PREF_INCOMING_STR, args[1]); + cons_show("Incoming stamp set to: %s", args[1]); + } else if (g_strcmp0(args[0], "unset") == 0) { + if (g_strcmp0(args[1], "incoming") == 0) { + prefs_set_string(PREF_INCOMING_STR, NULL); + cons_show("Incoming stamp unset"); + } else if (g_strcmp0(args[1], "outgoing") == 0) { + prefs_set_string(PREF_OUTGOING_STR, NULL); + cons_show("Outgoing stamp unset"); + } else { + cons_bad_cmd_usage(command); + } + } else { + cons_bad_cmd_usage(command); + } + } + + return TRUE; +} + gboolean cmd_color(ProfWin* window, const char* const command, gchar** args) { diff --git a/src/command/cmd_funcs.h b/src/command/cmd_funcs.h index f4cbe0bf..41074720 100644 --- a/src/command/cmd_funcs.h +++ b/src/command/cmd_funcs.h @@ -250,5 +250,6 @@ gboolean cmd_correct_editor(ProfWin* window, const char* const command, gchar** gboolean cmd_silence(ProfWin* window, const char* const command, gchar** args); gboolean cmd_register(ProfWin* window, const char* const command, gchar** args); gboolean cmd_mood(ProfWin* window, const char* const command, gchar** args); +gboolean cmd_stamp(ProfWin* window, const char* const command, gchar** args); #endif diff --git a/src/config/preferences.c b/src/config/preferences.c index 358c5fbf..8914c65e 100644 --- a/src/config/preferences.c +++ b/src/config/preferences.c @@ -1817,6 +1817,8 @@ _get_group(preference_t pref) case PREF_TITLEBAR_MUC_TITLE_NAME: case PREF_SLASH_GUARD: case PREF_COMPOSE_EDITOR: + case PREF_OUTGOING_STR: + case PREF_INCOMING_STR: return PREF_GROUP_UI; case PREF_STATES: case PREF_OUTTYPE: @@ -2144,6 +2146,10 @@ _get_key(preference_t pref) return "compose.editor"; case PREF_SILENCE_NON_ROSTER: return "silence.incoming.nonroster"; + case PREF_OUTGOING_STR: + return "stamp.outgoing"; + case PREF_INCOMING_STR: + return "stamp.incoming"; default: return NULL; } @@ -2281,6 +2287,10 @@ _get_default_string(preference_t pref) gchar* editor = getenv("EDITOR"); return editor ? editor : "vim"; } + case PREF_OUTGOING_STR: + return "me:"; + case PREF_INCOMING_STR: + return NULL; case PREF_URL_SAVE_CMD: return NULL; // Default to built-in method. default: diff --git a/src/config/preferences.h b/src/config/preferences.h index 25fc16ad..2bfceb9b 100644 --- a/src/config/preferences.h +++ b/src/config/preferences.h @@ -176,6 +176,8 @@ typedef enum { PREF_URL_SAVE_CMD, PREF_COMPOSE_EDITOR, PREF_SILENCE_NON_ROSTER, + PREF_OUTGOING_STR, + PREF_INCOMING_STR, } preference_t; typedef struct prof_alias_t diff --git a/src/ui/window.c b/src/ui/window.c index 7952497c..227ed07d 100644 --- a/src/ui/window.c +++ b/src/ui/window.c @@ -1248,7 +1248,8 @@ win_print_outgoing(ProfWin* window, const char* show_char, const char* const id, if (replace_id) { _win_correct(window, message, id, replace_id, myjid); } else { - _win_printf(window, show_char, 0, timestamp, 0, THEME_TEXT_ME, "me", myjid, id, "%s", message); + char* outgoing_str = prefs_get_string(PREF_OUTGOING_STR); + _win_printf(window, show_char, 0, timestamp, 0, THEME_TEXT_ME, outgoing_str, myjid, id, "%s", message); } inp_nonblocking(TRUE); @@ -1599,7 +1600,7 @@ _win_print_internal(ProfWin* window, const char* show_char, int pad_indent, GDat offset = 4; me_message = TRUE; } else { - wprintw(window->layout->win, "%s: ", from); + wprintw(window->layout->win, "%s ", from); wattroff(window->layout->win, colour); } } diff --git a/src/xmpp/roster_list.c b/src/xmpp/roster_list.c index 9d7ac427..5ecff145 100644 --- a/src/xmpp/roster_list.c +++ b/src/xmpp/roster_list.c @@ -199,6 +199,12 @@ roster_get_msg_display_name(const char* const barejid, const char* const resourc { assert(roster != NULL); + char* incoming_str = prefs_get_string(PREF_INCOMING_STR); + + if (incoming_str) { + return incoming_str; + } + GString* result = g_string_new(""); PContact contact = roster_get_contact(barejid); From 69a8fdec95c1aef1345972f66e07277510a50983 Mon Sep 17 00:00:00 2001 From: Michael Vetter Date: Thu, 28 Apr 2022 19:26:59 +0200 Subject: [PATCH 2/4] Rewrite stamp help --- src/command/cmd_defs.c | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/src/command/cmd_defs.c b/src/command/cmd_defs.c index db42be1c..0d4a3b19 100644 --- a/src/command/cmd_defs.c +++ b/src/command/cmd_defs.c @@ -2417,22 +2417,20 @@ static struct cmd_t command_defs[] = { CMD_MAINFUNC(cmd_stamp) CMD_TAGS( CMD_TAG_UI) - CMD_SYN( - "/stamp outgoing ", + CMD_SYN("/stamp outgoing ", "/stamp incoming ", "/stamp unset outgoing|incoming") - CMD_DESC( - "Set chat window stamp values. " - "Current format of single log-line in the chat window next: \" \" " - "where is \"me:\" for incoming messages or \"username@server/resource\" for outcoming messages. " - "This command allows to change value.") - CMD_ARGS( - { "outgoing", "Set outgoing messages stamp" }, - { "incoming", "Set incoming stamp"}, - { "unset outgoing|incoming", "unset stamp"}) + CMD_DESC("Set chat window stamp. " + "The format of line in the chat window is: \" \" " + "where is \"me:\" for incoming messages or \"username@server/resource\" for outgoing messages. " + "This command allows to change value.") + CMD_ARGS({ "outgoing", "Set outgoing stamp" }, + { "incoming", "Set incoming stamp"}, + { "unset outgoing|incoming", "Use the defaults"}) CMD_EXAMPLES( "/stamp outgoing -->", - "/stamp incoming <--") + "/stamp incoming <--", + "/stamp unset incoming") }, { "/avatar", From 6c5d983f134ae32eeecb1dd7011e9c955b1bf541 Mon Sep 17 00:00:00 2001 From: Michael Vetter Date: Thu, 28 Apr 2022 19:29:27 +0200 Subject: [PATCH 3/4] Rename stamp preference variable PREF_INCOMING_STR -> PREF_INCOMING_STAMP PREF_OUTGOING_STR -> PREF_OUTGOING_STAMP --- src/command/cmd_funcs.c | 12 ++++++------ src/config/preferences.c | 12 ++++++------ src/config/preferences.h | 4 ++-- src/ui/window.c | 2 +- src/xmpp/roster_list.c | 2 +- 5 files changed, 16 insertions(+), 16 deletions(-) diff --git a/src/command/cmd_funcs.c b/src/command/cmd_funcs.c index 39fc087a..b007a2a1 100644 --- a/src/command/cmd_funcs.c +++ b/src/command/cmd_funcs.c @@ -9023,14 +9023,14 @@ gboolean cmd_stamp(ProfWin* window, const char* const command, gchar** args) { if (g_strv_length(args) == 0) { - char* def = prefs_get_string(PREF_OUTGOING_STR); + char* def = prefs_get_string(PREF_OUTGOING_STAMP); if (def) { cons_show("The outgoing stamp is: %s", def); free(def); } else { cons_show("No outgoing stamp."); } - def = prefs_get_string(PREF_INCOMING_STR); + def = prefs_get_string(PREF_INCOMING_STAMP); if (def) { cons_show("The incoming stamp is: %s", def); free(def); @@ -9047,17 +9047,17 @@ cmd_stamp(ProfWin* window, const char* const command, gchar** args) if (g_strv_length(args) == 2) { if (g_strcmp0(args[0], "outgoing") == 0) { - prefs_set_string(PREF_OUTGOING_STR, args[1]); + prefs_set_string(PREF_OUTGOING_STAMP, args[1]); cons_show("Outgoing stamp set to: %s", args[1]); } else if (g_strcmp0(args[0], "incoming") == 0) { - prefs_set_string(PREF_INCOMING_STR, args[1]); + prefs_set_string(PREF_INCOMING_STAMP, args[1]); cons_show("Incoming stamp set to: %s", args[1]); } else if (g_strcmp0(args[0], "unset") == 0) { if (g_strcmp0(args[1], "incoming") == 0) { - prefs_set_string(PREF_INCOMING_STR, NULL); + prefs_set_string(PREF_INCOMING_STAMP, NULL); cons_show("Incoming stamp unset"); } else if (g_strcmp0(args[1], "outgoing") == 0) { - prefs_set_string(PREF_OUTGOING_STR, NULL); + prefs_set_string(PREF_OUTGOING_STAMP, NULL); cons_show("Outgoing stamp unset"); } else { cons_bad_cmd_usage(command); diff --git a/src/config/preferences.c b/src/config/preferences.c index 8914c65e..ec536762 100644 --- a/src/config/preferences.c +++ b/src/config/preferences.c @@ -1817,8 +1817,8 @@ _get_group(preference_t pref) case PREF_TITLEBAR_MUC_TITLE_NAME: case PREF_SLASH_GUARD: case PREF_COMPOSE_EDITOR: - case PREF_OUTGOING_STR: - case PREF_INCOMING_STR: + case PREF_OUTGOING_STAMP: + case PREF_INCOMING_STAMP: return PREF_GROUP_UI; case PREF_STATES: case PREF_OUTTYPE: @@ -2146,9 +2146,9 @@ _get_key(preference_t pref) return "compose.editor"; case PREF_SILENCE_NON_ROSTER: return "silence.incoming.nonroster"; - case PREF_OUTGOING_STR: + case PREF_OUTGOING_STAMP: return "stamp.outgoing"; - case PREF_INCOMING_STR: + case PREF_INCOMING_STAMP: return "stamp.incoming"; default: return NULL; @@ -2287,9 +2287,9 @@ _get_default_string(preference_t pref) gchar* editor = getenv("EDITOR"); return editor ? editor : "vim"; } - case PREF_OUTGOING_STR: + case PREF_OUTGOING_STAMP: return "me:"; - case PREF_INCOMING_STR: + case PREF_INCOMING_STAMP: return NULL; case PREF_URL_SAVE_CMD: return NULL; // Default to built-in method. diff --git a/src/config/preferences.h b/src/config/preferences.h index 2bfceb9b..6c8ad125 100644 --- a/src/config/preferences.h +++ b/src/config/preferences.h @@ -176,8 +176,8 @@ typedef enum { PREF_URL_SAVE_CMD, PREF_COMPOSE_EDITOR, PREF_SILENCE_NON_ROSTER, - PREF_OUTGOING_STR, - PREF_INCOMING_STR, + PREF_OUTGOING_STAMP, + PREF_INCOMING_STAMP, } preference_t; typedef struct prof_alias_t diff --git a/src/ui/window.c b/src/ui/window.c index 227ed07d..4283d61a 100644 --- a/src/ui/window.c +++ b/src/ui/window.c @@ -1248,7 +1248,7 @@ win_print_outgoing(ProfWin* window, const char* show_char, const char* const id, if (replace_id) { _win_correct(window, message, id, replace_id, myjid); } else { - char* outgoing_str = prefs_get_string(PREF_OUTGOING_STR); + char* outgoing_str = prefs_get_string(PREF_OUTGOING_STAMP); _win_printf(window, show_char, 0, timestamp, 0, THEME_TEXT_ME, outgoing_str, myjid, id, "%s", message); } diff --git a/src/xmpp/roster_list.c b/src/xmpp/roster_list.c index 5ecff145..a06c44c9 100644 --- a/src/xmpp/roster_list.c +++ b/src/xmpp/roster_list.c @@ -199,7 +199,7 @@ roster_get_msg_display_name(const char* const barejid, const char* const resourc { assert(roster != NULL); - char* incoming_str = prefs_get_string(PREF_INCOMING_STR); + char* incoming_str = prefs_get_string(PREF_INCOMING_STAMP); if (incoming_str) { return incoming_str; From 0dd0193ebaf1e016a2cfbaec9acdcc93c62e692a Mon Sep 17 00:00:00 2001 From: Michael Vetter Date: Thu, 28 Apr 2022 19:31:27 +0200 Subject: [PATCH 4/4] use more standard replies when setting stamp --- src/command/cmd_funcs.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/command/cmd_funcs.c b/src/command/cmd_funcs.c index b007a2a1..f8dc151a 100644 --- a/src/command/cmd_funcs.c +++ b/src/command/cmd_funcs.c @@ -9028,20 +9028,20 @@ cmd_stamp(ProfWin* window, const char* const command, gchar** args) cons_show("The outgoing stamp is: %s", def); free(def); } else { - cons_show("No outgoing stamp."); + cons_show("The default outgoing stamp is used."); } def = prefs_get_string(PREF_INCOMING_STAMP); if (def) { cons_show("The incoming stamp is: %s", def); free(def); } else { - cons_show("No incoming stamp."); + cons_show("The default incoming stamp is used."); } return TRUE; } if (g_strv_length(args) == 1) { - cons_show("Wrong usage: need a parameter."); + cons_bad_cmd_usage(command); return TRUE; }