From b79d77409fe3d7f342055dd2826b3f51f797613e Mon Sep 17 00:00:00 2001 From: James Booth Date: Mon, 23 Nov 2015 23:43:53 +0000 Subject: [PATCH 01/13] Added notify triggers WIP --- src/command/command.c | 62 ++++++++++++++++++++++++++++++++-------- src/command/commands.c | 48 +++++++++++++++++++++++++++++++ src/config/preferences.c | 6 ++++ src/config/preferences.h | 2 ++ src/ui/console.c | 10 +++++++ 5 files changed, 116 insertions(+), 12 deletions(-) diff --git a/src/command/command.c b/src/command/command.c index bc2ee121..3ef41ecb 100644 --- a/src/command/command.c +++ b/src/command/command.c @@ -1054,7 +1054,7 @@ static struct cmd_t command_defs[] = }, { "/notify", - cmd_notify, parse_args, 2, 3, &cons_notify_setting, + cmd_notify, parse_args_with_freetext, 2, 4, &cons_notify_setting, CMD_TAGS( CMD_TAG_UI, CMD_TAG_CHAT, @@ -1063,9 +1063,17 @@ static struct cmd_t command_defs[] = "/notify message on|off", "/notify message current on|off", "/notify message text on|off", + "/notify message trigger add ", + "/notify message trigger remove ", + "/notify message trigger list", + "/notify message trigger on|off", "/notify room on|off|mention", "/notify room current on|off", "/notify room text on|off", + "/notify room trigger add ", + "/notify room trigger remove ", + "/notify room trigger list", + "/notify room trigger on|off", "/notify remind ", "/notify typing on|off", "/notify typing current on|off", @@ -1074,17 +1082,25 @@ static struct cmd_t command_defs[] = CMD_DESC( "Settings for various kinds of desktop notifications.") CMD_ARGS( - { "message on|off", "Notifications for regular chat messages." }, - { "message current on|off", "Whether messages in the current window trigger notifications." }, - { "message text on|off", "Show message text in regular message notifications." }, - { "room on|off|mention", "Notifications for chat room messages, mention triggers notifications only when your nick is mentioned." }, - { "room current on|off", "Whether chat room messages in the current window trigger notifications." }, - { "room text on|off", "Show message text in chat room message notifications." }, - { "remind ", "Notification reminder period for unread messages, use 0 to disable." }, - { "typing on|off", "Notifications when contacts are typing." }, - { "typing current on|off", "Whether typing notifications are triggered for the current window." }, - { "invite on|off", "Notifications for chat room invites." }, - { "sub on|off", "Notifications for subscription requests." }) + { "message on|off", "Notifications for regular chat messages." }, + { "message current on|off", "Whether messages in the current window trigger notifications." }, + { "message text on|off", "Show message text in regular message notifications." }, + { "message trigger add ", "Notify when specified text included in regular chat message." }, + { "message trigger remove ", "Remove regular chat notification for specified text." }, + { "message trigger list", "List all regular chat custom text notifications." }, + { "message trigger on|off", "Enable or disable all regular chat custom text notifications." }, + { "room on|off|mention", "Notifications for chat room messages, mention triggers notifications only when your nick is mentioned." }, + { "room current on|off", "Whether chat room messages in the current window trigger notifications." }, + { "room text on|off", "Show message text in chat room message notifications." }, + { "room trigger add ", "Notify when specified text included in regular chat message." }, + { "room trigger remove ", "Remove regular chat notification for specified text." }, + { "room trigger list", "List all regular chat custom text notifications." }, + { "room trigger on|off", "Enable or disable all regular chat custom text notifications." }, + { "remind ", "Notification reminder period for unread messages, use 0 to disable." }, + { "typing on|off", "Notifications when contacts are typing." }, + { "typing current on|off", "Whether typing notifications are triggered for the current window." }, + { "invite on|off", "Notifications for chat room invites." }, + { "sub on|off", "Notifications for subscription requests." }) CMD_EXAMPLES( "/notify message on", "/notify message text on", @@ -1777,6 +1793,7 @@ static Autocomplete notify_ac; static Autocomplete notify_room_ac; static Autocomplete notify_message_ac; static Autocomplete notify_typing_ac; +static Autocomplete notify_trigger_ac; static Autocomplete prefs_ac; static Autocomplete sub_ac; static Autocomplete log_ac; @@ -1915,6 +1932,7 @@ cmd_init(void) autocomplete_add(notify_message_ac, "off"); autocomplete_add(notify_message_ac, "current"); autocomplete_add(notify_message_ac, "text"); + autocomplete_add(notify_message_ac, "trigger"); notify_room_ac = autocomplete_new(); autocomplete_add(notify_room_ac, "on"); @@ -1922,12 +1940,20 @@ cmd_init(void) autocomplete_add(notify_room_ac, "mention"); autocomplete_add(notify_room_ac, "current"); autocomplete_add(notify_room_ac, "text"); + autocomplete_add(notify_room_ac, "trigger"); notify_typing_ac = autocomplete_new(); autocomplete_add(notify_typing_ac, "on"); autocomplete_add(notify_typing_ac, "off"); autocomplete_add(notify_typing_ac, "current"); + notify_trigger_ac = autocomplete_new(); + autocomplete_add(notify_trigger_ac, "add"); + autocomplete_add(notify_trigger_ac, "remove"); + autocomplete_add(notify_trigger_ac, "list"); + autocomplete_add(notify_trigger_ac, "on"); + autocomplete_add(notify_trigger_ac, "off"); + sub_ac = autocomplete_new(); autocomplete_add(sub_ac, "request"); autocomplete_add(sub_ac, "allow"); @@ -2324,6 +2350,7 @@ cmd_uninit(void) autocomplete_free(notify_message_ac); autocomplete_free(notify_room_ac); autocomplete_free(notify_typing_ac); + autocomplete_free(notify_trigger_ac); autocomplete_free(sub_ac); autocomplete_free(titlebar_ac); autocomplete_free(log_ac); @@ -2510,6 +2537,7 @@ cmd_reset_autocomplete(ProfWin *window) autocomplete_reset(notify_message_ac); autocomplete_reset(notify_room_ac); autocomplete_reset(notify_typing_ac); + autocomplete_reset(notify_trigger_ac); autocomplete_reset(sub_ac); autocomplete_reset(who_room_ac); @@ -3127,11 +3155,21 @@ _notify_autocomplete(ProfWin *window, const char *const input) return result; } + result = autocomplete_param_with_ac(input, "/notify room trigger", notify_trigger_ac, TRUE); + if (result) { + return result; + } + result = autocomplete_param_with_func(input, "/notify message current", prefs_autocomplete_boolean_choice); if (result) { return result; } + result = autocomplete_param_with_ac(input, "/notify message trigger", notify_trigger_ac, TRUE); + if (result) { + return result; + } + result = autocomplete_param_with_func(input, "/notify typing current", prefs_autocomplete_boolean_choice); if (result) { return result; diff --git a/src/command/commands.c b/src/command/commands.c index c17dca43..ec30c2a8 100644 --- a/src/command/commands.c +++ b/src/command/commands.c @@ -4207,6 +4207,30 @@ cmd_notify(ProfWin *window, const char *const command, gchar **args) } else { cons_show("Usage: /notify message text on|off"); } + } else if (g_strcmp0(args[1], "trigger") == 0) { + if (g_strcmp0(args[2], "add") == 0) { + if (!args[3]) { + cons_bad_cmd_usage(command); + } else { + cons_show("Adding trigger: %s", args[3]); + } + } else if (g_strcmp0(args[2], "remove") == 0) { + if (!args[3]) { + cons_bad_cmd_usage(command); + } else { + cons_show("Removing trigger: %s", args[3]); + } + } else if (g_strcmp0(args[2], "list") == 0) { + cons_show("Listing triggers"); + } else if (g_strcmp0(args[2], "on") == 0) { + cons_show("Enabling message triggers"); + prefs_set_boolean(PREF_NOTIFY_MESSAGE_TRIGGER, TRUE); + } else if (g_strcmp0(args[2], "off") == 0) { + cons_show("Disabling message triggers"); + prefs_set_boolean(PREF_NOTIFY_MESSAGE_TRIGGER, FALSE); + } else { + cons_bad_cmd_usage(command); + } } else { cons_show("Usage: /notify message on|off"); } @@ -4242,6 +4266,30 @@ cmd_notify(ProfWin *window, const char *const command, gchar **args) } else { cons_show("Usage: /notify room text on|off"); } + } else if (g_strcmp0(args[1], "trigger") == 0) { + if (g_strcmp0(args[2], "add") == 0) { + if (!args[3]) { + cons_bad_cmd_usage(command); + } else { + cons_show("Adding trigger: %s", args[3]); + } + } else if (g_strcmp0(args[2], "remove") == 0) { + if (!args[3]) { + cons_bad_cmd_usage(command); + } else { + cons_show("Removing trigger: %s", args[3]); + } + } else if (g_strcmp0(args[2], "list") == 0) { + cons_show("Listing triggers"); + } else if (g_strcmp0(args[2], "on") == 0) { + cons_show("Enabling room triggers"); + prefs_set_boolean(PREF_NOTIFY_ROOM_TRIGGER, TRUE); + } else if (g_strcmp0(args[2], "off") == 0) { + cons_show("Disabling room triggers"); + prefs_set_boolean(PREF_NOTIFY_ROOM_TRIGGER, FALSE); + } else { + cons_bad_cmd_usage(command); + } } else { cons_show("Usage: /notify room on|off|mention"); } diff --git a/src/config/preferences.c b/src/config/preferences.c index 07985efc..15def391 100644 --- a/src/config/preferences.c +++ b/src/config/preferences.c @@ -782,9 +782,11 @@ _get_group(preference_t pref) case PREF_NOTIFY_MESSAGE: case PREF_NOTIFY_MESSAGE_CURRENT: case PREF_NOTIFY_MESSAGE_TEXT: + case PREF_NOTIFY_MESSAGE_TRIGGER: case PREF_NOTIFY_ROOM: case PREF_NOTIFY_ROOM_CURRENT: case PREF_NOTIFY_ROOM_TEXT: + case PREF_NOTIFY_ROOM_TRIGGER: case PREF_NOTIFY_INVITE: case PREF_NOTIFY_SUB: return PREF_GROUP_NOTIFICATIONS; @@ -875,12 +877,16 @@ _get_key(preference_t pref) return "message.current"; case PREF_NOTIFY_MESSAGE_TEXT: return "message.text"; + case PREF_NOTIFY_MESSAGE_TRIGGER: + return "message.trigger"; case PREF_NOTIFY_ROOM: return "room"; case PREF_NOTIFY_ROOM_CURRENT: return "room.current"; case PREF_NOTIFY_ROOM_TEXT: return "room.text"; + case PREF_NOTIFY_ROOM_TRIGGER: + return "room.trigger"; case PREF_NOTIFY_INVITE: return "invite"; case PREF_NOTIFY_SUB: diff --git a/src/config/preferences.h b/src/config/preferences.h index 607a1abe..dd495a1b 100644 --- a/src/config/preferences.h +++ b/src/config/preferences.h @@ -96,9 +96,11 @@ typedef enum { PREF_NOTIFY_MESSAGE, PREF_NOTIFY_MESSAGE_CURRENT, PREF_NOTIFY_MESSAGE_TEXT, + PREF_NOTIFY_MESSAGE_TRIGGER, PREF_NOTIFY_ROOM, PREF_NOTIFY_ROOM_CURRENT, PREF_NOTIFY_ROOM_TEXT, + PREF_NOTIFY_ROOM_TRIGGER, PREF_NOTIFY_INVITE, PREF_NOTIFY_SUB, PREF_CHLOG, diff --git a/src/ui/console.c b/src/ui/console.c index 6aa706c5..066ea32c 100644 --- a/src/ui/console.c +++ b/src/ui/console.c @@ -1339,6 +1339,11 @@ cons_notify_setting(void) else cons_show("Messages text (/notify message) : OFF"); + if (prefs_get_boolean(PREF_NOTIFY_MESSAGE_TRIGGER)) + cons_show("Messages trigger (/notify message) : ON"); + else + cons_show("Messages trigger (/notify message) : OFF"); + char *room_setting = prefs_get_string(PREF_NOTIFY_ROOM); if (g_strcmp0(room_setting, "on") == 0) { cons_show ("Room messages (/notify room) : ON"); @@ -1359,6 +1364,11 @@ cons_notify_setting(void) else cons_show("Room text (/notify room) : OFF"); + if (prefs_get_boolean(PREF_NOTIFY_ROOM_TRIGGER)) + cons_show("Room trigger (/notify room) : ON"); + else + cons_show("Room trigger (/notify room) : OFF"); + if (prefs_get_boolean(PREF_NOTIFY_TYPING)) cons_show("Composing (/notify typing) : ON"); else From a488d944d259f19330e23cca619bb7c9c4b65689 Mon Sep 17 00:00:00 2001 From: James Booth Date: Tue, 24 Nov 2015 00:38:33 +0000 Subject: [PATCH 02/13] Added functions to manage custom notification triggers --- src/command/commands.c | 62 +++++++++++++++++++++++++++++------ src/config/preferences.c | 71 ++++++++++++++++++++++++++++++++++++++++ src/config/preferences.h | 7 ++++ 3 files changed, 130 insertions(+), 10 deletions(-) diff --git a/src/command/commands.c b/src/command/commands.c index ec30c2a8..3f8a0145 100644 --- a/src/command/commands.c +++ b/src/command/commands.c @@ -4212,21 +4212,42 @@ cmd_notify(ProfWin *window, const char *const command, gchar **args) if (!args[3]) { cons_bad_cmd_usage(command); } else { - cons_show("Adding trigger: %s", args[3]); + gboolean res = prefs_add_msg_notify_trigger(args[3]); + if (res) { + cons_show("Adding message notification trigger: %s", args[3]); + } else { + cons_show("Message notification trigger already exists: %s", args[3]); + } } } else if (g_strcmp0(args[2], "remove") == 0) { if (!args[3]) { cons_bad_cmd_usage(command); } else { - cons_show("Removing trigger: %s", args[3]); + gboolean res = prefs_remove_msg_notify_trigger(args[3]); + if (res) { + cons_show("Removing message notification trigger: %s", args[3]); + } else { + cons_show("Message notification trigger does not exist: %s", args[3]); + } } } else if (g_strcmp0(args[2], "list") == 0) { - cons_show("Listing triggers"); + GList *triggers = prefs_get_msg_notify_triggers(); + GList *curr = triggers; + if (curr) { + cons_show("Message notification triggers:"); + } else { + cons_show("No message notification triggers"); + } + while (curr) { + cons_show(" %s", curr->data); + curr = g_list_next(curr); + } + g_list_free_full(triggers, free); } else if (g_strcmp0(args[2], "on") == 0) { - cons_show("Enabling message triggers"); + cons_show("Enabling message notification triggers"); prefs_set_boolean(PREF_NOTIFY_MESSAGE_TRIGGER, TRUE); } else if (g_strcmp0(args[2], "off") == 0) { - cons_show("Disabling message triggers"); + cons_show("Disabling message notification triggers"); prefs_set_boolean(PREF_NOTIFY_MESSAGE_TRIGGER, FALSE); } else { cons_bad_cmd_usage(command); @@ -4271,21 +4292,42 @@ cmd_notify(ProfWin *window, const char *const command, gchar **args) if (!args[3]) { cons_bad_cmd_usage(command); } else { - cons_show("Adding trigger: %s", args[3]); + gboolean res = prefs_add_room_notify_trigger(args[3]); + if (res) { + cons_show("Adding room notification trigger: %s", args[3]); + } else { + cons_show("Room notification trigger already exists: %s", args[3]); + } } } else if (g_strcmp0(args[2], "remove") == 0) { if (!args[3]) { cons_bad_cmd_usage(command); } else { - cons_show("Removing trigger: %s", args[3]); + gboolean res = prefs_remove_room_notify_trigger(args[3]); + if (res) { + cons_show("Removing room notification trigger: %s", args[3]); + } else { + cons_show("Room notification trigger does not exist: %s", args[3]); + } } } else if (g_strcmp0(args[2], "list") == 0) { - cons_show("Listing triggers"); + GList *triggers = prefs_get_room_notify_triggers(); + GList *curr = triggers; + if (curr) { + cons_show("Room notification triggers:"); + } else { + cons_show("No room notification triggers"); + } + while (curr) { + cons_show(" %s", curr->data); + curr = g_list_next(curr); + } + g_list_free_full(triggers, free); } else if (g_strcmp0(args[2], "on") == 0) { - cons_show("Enabling room triggers"); + cons_show("Enabling room notification triggers"); prefs_set_boolean(PREF_NOTIFY_ROOM_TRIGGER, TRUE); } else if (g_strcmp0(args[2], "off") == 0) { - cons_show("Disabling room triggers"); + cons_show("Disabling room notification triggers"); prefs_set_boolean(PREF_NOTIFY_ROOM_TRIGGER, FALSE); } else { cons_bad_cmd_usage(command); diff --git a/src/config/preferences.c b/src/config/preferences.c index 15def391..a3d9276a 100644 --- a/src/config/preferences.c +++ b/src/config/preferences.c @@ -45,6 +45,7 @@ #include "log.h" #include "preferences.h" #include "tools/autocomplete.h" +#include "config/conflists.h" // preference groups refer to the sections in .profrc, for example [ui] #define PREF_GROUP_LOGGING "logging" @@ -606,6 +607,76 @@ prefs_set_roster_presence_indent(gint value) _save_prefs(); } +gboolean +prefs_add_msg_notify_trigger(const char * const text) +{ + gboolean res = conf_string_list_add(prefs, PREF_GROUP_NOTIFICATIONS, "message.trigger.list", text); + _save_prefs(); + + return res; +} + +gboolean +prefs_remove_msg_notify_trigger(const char * const text) +{ + gboolean res = conf_string_list_remove(prefs, PREF_GROUP_NOTIFICATIONS, "message.trigger.list", text); + _save_prefs(); + + return res; +} + +GList* +prefs_get_msg_notify_triggers(void) +{ + GList *result = NULL; + gsize len = 0; + gchar **triggers = g_key_file_get_string_list(prefs, PREF_GROUP_NOTIFICATIONS, "message.trigger.list", &len, NULL); + + int i; + for (i = 0; i < len; i++) { + result = g_list_append(result, strdup(triggers[i])); + } + + g_strfreev(triggers); + + return result; +} + +gboolean +prefs_add_room_notify_trigger(const char * const text) +{ + gboolean res = conf_string_list_add(prefs, PREF_GROUP_NOTIFICATIONS, "room.trigger.list", text); + _save_prefs(); + + return res; +} + +gboolean +prefs_remove_room_notify_trigger(const char * const text) +{ + gboolean res = conf_string_list_remove(prefs, PREF_GROUP_NOTIFICATIONS, "room.trigger.list", text); + _save_prefs(); + + return res; +} + +GList* +prefs_get_room_notify_triggers(void) +{ + GList *result = NULL; + gsize len = 0; + gchar **triggers = g_key_file_get_string_list(prefs, PREF_GROUP_NOTIFICATIONS, "room.trigger.list", &len, NULL); + + int i; + for (i = 0; i < len; i++) { + result = g_list_append(result, strdup(triggers[i])); + } + + g_strfreev(triggers); + + return result; +} + gboolean prefs_add_alias(const char *const name, const char *const value) { diff --git a/src/config/preferences.h b/src/config/preferences.h index dd495a1b..acf62ddb 100644 --- a/src/config/preferences.h +++ b/src/config/preferences.h @@ -194,6 +194,13 @@ char* prefs_get_alias(const char *const name); GList* prefs_get_aliases(void); void prefs_free_aliases(GList *aliases); +gboolean prefs_add_msg_notify_trigger(const char * const text); +gboolean prefs_add_room_notify_trigger(const char * const text); +gboolean prefs_remove_msg_notify_trigger(const char * const text); +gboolean prefs_remove_room_notify_trigger(const char * const text); +GList* prefs_get_msg_notify_triggers(void); +GList* prefs_get_room_notify_triggers(void); + gboolean prefs_get_boolean(preference_t pref); void prefs_set_boolean(preference_t pref, gboolean value); char* prefs_get_string(preference_t pref); From 00a735ece58421a6d4d3f7a161684b033aea828a Mon Sep 17 00:00:00 2001 From: James Booth Date: Tue, 24 Nov 2015 01:34:06 +0000 Subject: [PATCH 03/13] Added autocompleters for notify trigger removal --- src/command/command.c | 12 ++++++++ src/config/preferences.c | 63 ++++++++++++++++++++++++++++++++++++++++ src/config/preferences.h | 6 ++++ 3 files changed, 81 insertions(+) diff --git a/src/command/command.c b/src/command/command.c index 3ef41ecb..225d8d01 100644 --- a/src/command/command.c +++ b/src/command/command.c @@ -2636,6 +2636,8 @@ cmd_reset_autocomplete(ProfWin *window) } bookmark_autocomplete_reset(); + prefs_reset_message_trigger_ac(); + prefs_reset_room_trigger_ac(); } gboolean @@ -3150,6 +3152,16 @@ _notify_autocomplete(ProfWin *window, const char *const input) int i = 0; char *result = NULL; + result = autocomplete_param_with_func(input, "/notify message trigger remove", prefs_autocomplete_message_trigger); + if (result) { + return result; + } + + result = autocomplete_param_with_func(input, "/notify room trigger remove", prefs_autocomplete_room_trigger); + if (result) { + return result; + } + result = autocomplete_param_with_func(input, "/notify room current", prefs_autocomplete_boolean_choice); if (result) { return result; diff --git a/src/config/preferences.c b/src/config/preferences.c index a3d9276a..2051e66b 100644 --- a/src/config/preferences.c +++ b/src/config/preferences.c @@ -65,6 +65,8 @@ static GKeyFile *prefs; gint log_maxsize = 0; static Autocomplete boolean_choice_ac; +static Autocomplete message_trigger_ac; +static Autocomplete room_trigger_ac; static void _save_prefs(void); static gchar* _get_preferences_file(void); @@ -133,12 +135,33 @@ prefs_load(void) boolean_choice_ac = autocomplete_new(); autocomplete_add(boolean_choice_ac, "on"); autocomplete_add(boolean_choice_ac, "off"); + + message_trigger_ac = autocomplete_new(); + gsize len = 0; + gchar **triggers = g_key_file_get_string_list(prefs, PREF_GROUP_NOTIFICATIONS, "message.trigger.list", &len, NULL); + + int i; + for (i = 0; i < len; i++) { + autocomplete_add(message_trigger_ac, triggers[i]); + } + g_strfreev(triggers); + + room_trigger_ac = autocomplete_new(); + len = 0; + triggers = g_key_file_get_string_list(prefs, PREF_GROUP_NOTIFICATIONS, "room.trigger.list", &len, NULL); + + for (i = 0; i < len; i++) { + autocomplete_add(room_trigger_ac, triggers[i]); + } + g_strfreev(triggers); } void prefs_close(void) { autocomplete_free(boolean_choice_ac); + autocomplete_free(message_trigger_ac); + autocomplete_free(room_trigger_ac); g_key_file_free(prefs); prefs = NULL; } @@ -155,6 +178,30 @@ prefs_reset_boolean_choice(void) autocomplete_reset(boolean_choice_ac); } +char* +prefs_autocomplete_message_trigger(const char *const prefix) +{ + return autocomplete_complete(message_trigger_ac, prefix, TRUE); +} + +void +prefs_reset_message_trigger_ac(void) +{ + autocomplete_reset(message_trigger_ac); +} + +char* +prefs_autocomplete_room_trigger(const char *const prefix) +{ + return autocomplete_complete(room_trigger_ac, prefix, TRUE); +} + +void +prefs_reset_room_trigger_ac(void) +{ + autocomplete_reset(room_trigger_ac); +} + gboolean prefs_get_boolean(preference_t pref) { @@ -613,6 +660,10 @@ prefs_add_msg_notify_trigger(const char * const text) gboolean res = conf_string_list_add(prefs, PREF_GROUP_NOTIFICATIONS, "message.trigger.list", text); _save_prefs(); + if (res) { + autocomplete_add(message_trigger_ac, text); + } + return res; } @@ -622,6 +673,10 @@ prefs_remove_msg_notify_trigger(const char * const text) gboolean res = conf_string_list_remove(prefs, PREF_GROUP_NOTIFICATIONS, "message.trigger.list", text); _save_prefs(); + if (res) { + autocomplete_remove(message_trigger_ac, text); + } + return res; } @@ -648,6 +703,10 @@ prefs_add_room_notify_trigger(const char * const text) gboolean res = conf_string_list_add(prefs, PREF_GROUP_NOTIFICATIONS, "room.trigger.list", text); _save_prefs(); + if (res) { + autocomplete_add(room_trigger_ac, text); + } + return res; } @@ -657,6 +716,10 @@ prefs_remove_room_notify_trigger(const char * const text) gboolean res = conf_string_list_remove(prefs, PREF_GROUP_NOTIFICATIONS, "room.trigger.list", text); _save_prefs(); + if (res) { + autocomplete_remove(room_trigger_ac, text); + } + return res; } diff --git a/src/config/preferences.h b/src/config/preferences.h index acf62ddb..9038591d 100644 --- a/src/config/preferences.h +++ b/src/config/preferences.h @@ -135,9 +135,15 @@ void prefs_close(void); char* prefs_find_login(char *prefix); void prefs_reset_login_search(void); + char* prefs_autocomplete_boolean_choice(const char *const prefix); void prefs_reset_boolean_choice(void); +char* prefs_autocomplete_message_trigger(const char *const prefix); +void prefs_reset_message_trigger_ac(void); +char* prefs_autocomplete_room_trigger(const char *const prefix); +void prefs_reset_room_trigger_ac(void); + gint prefs_get_gone(void); void prefs_set_gone(gint value); From 9c8b137a515e90f55606177c75847493fa02f556 Mon Sep 17 00:00:00 2001 From: James Booth Date: Tue, 24 Nov 2015 23:03:52 +0000 Subject: [PATCH 04/13] Tidy regular chat and room notifications --- src/config/preferences.c | 41 ++++++++++++++++++++++++++++++++ src/config/preferences.h | 3 +++ src/ui/chatwin.c | 28 ++++++++++++++++++++-- src/ui/mucwin.c | 45 ++++++++++++------------------------ src/ui/notifier.c | 35 +++++++++++----------------- src/ui/privwin.c | 28 ++++++++++++++++++++-- src/ui/ui.h | 6 ++--- tests/unittests/ui/stub_ui.c | 2 +- 8 files changed, 128 insertions(+), 60 deletions(-) diff --git a/src/config/preferences.c b/src/config/preferences.c index 2051e66b..205d47df 100644 --- a/src/config/preferences.c +++ b/src/config/preferences.c @@ -202,6 +202,47 @@ prefs_reset_room_trigger_ac(void) autocomplete_reset(room_trigger_ac); } +gboolean +prefs_get_notify_chat(gboolean current_win) +{ + gboolean notify_message = prefs_get_boolean(PREF_NOTIFY_MESSAGE); + gboolean notify_window = FALSE; + + if (!current_win || (current_win && prefs_get_boolean(PREF_NOTIFY_MESSAGE_CURRENT)) ) { + notify_window = TRUE; + } + + return (notify_message && notify_window); +} + +gboolean +prefs_get_notify_room(gboolean current_win, const char *const nick, const char *const message) +{ + gboolean notify_message = FALSE; + gboolean notify_window = FALSE; + + char *room_setting = prefs_get_string(PREF_NOTIFY_ROOM); + if (g_strcmp0(room_setting, "on") == 0) { + notify_message = TRUE; + } + if (g_strcmp0(room_setting, "mention") == 0) { + char *message_lower = g_utf8_strdown(message, -1); + char *nick_lower = g_utf8_strdown(nick, -1); + if (g_strrstr(message_lower, nick_lower)) { + notify_message = TRUE; + } + g_free(message_lower); + g_free(nick_lower); + } + prefs_free_string(room_setting); + + if (!current_win || (current_win && prefs_get_boolean(PREF_NOTIFY_ROOM_CURRENT)) ) { + notify_window = TRUE; + } + + return (notify_message && notify_window); +} + gboolean prefs_get_boolean(preference_t pref) { diff --git a/src/config/preferences.h b/src/config/preferences.h index 9038591d..face1811 100644 --- a/src/config/preferences.h +++ b/src/config/preferences.h @@ -213,4 +213,7 @@ char* prefs_get_string(preference_t pref); void prefs_free_string(char *pref); void prefs_set_string(preference_t pref, char *value); +gboolean prefs_get_notify_chat(gboolean current_win); +gboolean prefs_get_notify_room(gboolean current_win, const char *const nick, const char *const message); + #endif diff --git a/src/ui/chatwin.c b/src/ui/chatwin.c index c34cc1fc..2efe82e1 100644 --- a/src/ui/chatwin.c +++ b/src/ui/chatwin.c @@ -274,8 +274,32 @@ chatwin_incoming_msg(ProfChatWin *chatwin, const char *const resource, const cha beep(); } - if (prefs_get_boolean(PREF_NOTIFY_MESSAGE)) { - notify_message(window, display_name, message); + if (!prefs_get_boolean(PREF_NOTIFY_MESSAGE)) { + free(display_name); + return; + } + + gboolean notify = FALSE; + + gboolean is_current = wins_is_current(window); + if (!is_current || (is_current && prefs_get_boolean(PREF_NOTIFY_MESSAGE_CURRENT)) ) { + notify = TRUE; + } + + if (!notify) { + free(display_name); + return; + } + + int ui_index = num; + if (ui_index == 10) { + ui_index = 0; + } + + if (prefs_get_boolean(PREF_NOTIFY_MESSAGE_TEXT)) { + notify_message(display_name, ui_index, message); + } else { + notify_message(display_name, ui_index, NULL); } free(display_name); diff --git a/src/ui/mucwin.c b/src/ui/mucwin.c index 58fef4d1..aa825d16 100644 --- a/src/ui/mucwin.c +++ b/src/ui/mucwin.c @@ -390,11 +390,6 @@ mucwin_message(ProfMucWin *mucwin, const char *const nick, const char *const mes mucwin->unread++; } - int ui_index = num; - if (ui_index == 10) { - ui_index = 0; - } - // don't notify self messages if (strcmp(nick, my_nick) == 0) { return; @@ -404,34 +399,24 @@ mucwin_message(ProfMucWin *mucwin, const char *const nick, const char *const mes beep(); } - gboolean notify = FALSE; - char *room_setting = prefs_get_string(PREF_NOTIFY_ROOM); - if (g_strcmp0(room_setting, "on") == 0) { - notify = TRUE; + gboolean is_current = wins_is_current(window); + gboolean notify = prefs_get_notify_room(is_current, my_nick, message); + if (!notify) { + return; } - if (g_strcmp0(room_setting, "mention") == 0) { - char *message_lower = g_utf8_strdown(message, -1); - char *nick_lower = g_utf8_strdown(nick, -1); - if (g_strrstr(message_lower, nick_lower)) { - notify = TRUE; - } - g_free(message_lower); - g_free(nick_lower); - } - prefs_free_string(room_setting); - if (notify) { - gboolean is_current = wins_is_current(window); - if ( !is_current || (is_current && prefs_get_boolean(PREF_NOTIFY_ROOM_CURRENT)) ) { - Jid *jidp = jid_create(mucwin->roomjid); - if (prefs_get_boolean(PREF_NOTIFY_ROOM_TEXT)) { - notify_room_message(nick, jidp->localpart, ui_index, message); - } else { - notify_room_message(nick, jidp->localpart, ui_index, NULL); - } - jid_destroy(jidp); - } + Jid *jidp = jid_create(mucwin->roomjid); + int ui_index = num; + if (ui_index == 10) { + ui_index = 0; } + + if (prefs_get_boolean(PREF_NOTIFY_ROOM_TEXT)) { + notify_room_message(nick, jidp->localpart, ui_index, message); + } else { + notify_room_message(nick, jidp->localpart, ui_index, NULL); + } + jid_destroy(jidp); } void diff --git a/src/ui/notifier.c b/src/ui/notifier.c index 9127b1e7..c0861009 100644 --- a/src/ui/notifier.c +++ b/src/ui/notifier.c @@ -73,17 +73,16 @@ notifier_uninit(void) } void -notify_typing(const char *const handle) +notify_typing(const char *const name) { - char message[strlen(handle) + 1 + 11]; - sprintf(message, "%s: typing...", handle); + char message[strlen(name) + 1 + 11]; + sprintf(message, "%s: typing...", name); _notify(message, 10000, "Incoming message"); } void -notify_invite(const char *const from, const char *const room, - const char *const reason) +notify_invite(const char *const from, const char *const room, const char *const reason) { GString *message = g_string_new("Room invite\nfrom: "); g_string_append(message, from); @@ -99,32 +98,24 @@ notify_invite(const char *const from, const char *const room, } void -notify_message(ProfWin *window, const char *const name, const char *const text) +notify_message(const char *const name, int win, const char *const text) { - int num = wins_get_num(window); - if (num == 10) { - num = 0; + GString *message = g_string_new(""); + g_string_append_printf(message, "%s (win %d)", name, win); + if (text) { + g_string_append_printf(message, "\n%s", text); } - gboolean is_current = wins_is_current(window); - if (!is_current || (is_current && prefs_get_boolean(PREF_NOTIFY_MESSAGE_CURRENT)) ) { - GString *message = g_string_new(""); - g_string_append_printf(message, "%s (win %d)", name, num); + _notify(message->str, 10000, "incoming message"); - if (prefs_get_boolean(PREF_NOTIFY_MESSAGE_TEXT) && text) { - g_string_append_printf(message, "\n%s", text); - } - - _notify(message->str, 10000, "incoming message"); - g_string_free(message, TRUE); - } + g_string_free(message, TRUE); } void -notify_room_message(const char *const handle, const char *const room, int win, const char *const text) +notify_room_message(const char *const nick, const char *const room, int win, const char *const text) { GString *message = g_string_new(""); - g_string_append_printf(message, "%s in %s (win %d)", handle, room, win); + g_string_append_printf(message, "%s in %s (win %d)", nick, room, win); if (text) { g_string_append_printf(message, "\n%s", text); } diff --git a/src/ui/privwin.c b/src/ui/privwin.c index 6031a2c0..10ce1dbe 100644 --- a/src/ui/privwin.c +++ b/src/ui/privwin.c @@ -75,8 +75,32 @@ privwin_incoming_msg(ProfPrivateWin *privatewin, const char *const message, GDat beep(); } - if (prefs_get_boolean(PREF_NOTIFY_MESSAGE)) { - notify_message(window, display_from, message); + if (!prefs_get_boolean(PREF_NOTIFY_MESSAGE)) { + free(display_from); + return; + } + + gboolean notify = FALSE; + + gboolean is_current = wins_is_current(window); + if (!is_current || (is_current && prefs_get_boolean(PREF_NOTIFY_MESSAGE_CURRENT)) ) { + notify = TRUE; + } + + if (!notify) { + free(display_from); + return; + } + + int ui_index = num; + if (ui_index == 10) { + ui_index = 0; + } + + if (prefs_get_boolean(PREF_NOTIFY_MESSAGE_TEXT)) { + notify_message(display_from, ui_index, message); + } else { + notify_message(display_from, ui_index, NULL); } free(display_from); diff --git a/src/ui/ui.h b/src/ui/ui.h index 032a1161..3cc40001 100644 --- a/src/ui/ui.h +++ b/src/ui/ui.h @@ -339,9 +339,9 @@ void win_clear(ProfWin *window); // desktop notifications void notifier_initialise(void); void notifier_uninit(void); -void notify_typing(const char *const handle); -void notify_message(ProfWin *window, const char *const name, const char *const text); -void notify_room_message(const char *const handle, const char *const room, int win, const char *const text); +void notify_typing(const char *const name); +void notify_message(const char *const name, int win, const char *const text); +void notify_room_message(const char *const nick, const char *const room, int win, const char *const text); void notify_remind(void); void notify_invite(const char *const from, const char *const room, const char *const reason); void notify_subscription(const char *const from); diff --git a/tests/unittests/ui/stub_ui.c b/tests/unittests/ui/stub_ui.c index 084b36be..4cab2ea9 100644 --- a/tests/unittests/ui/stub_ui.c +++ b/tests/unittests/ui/stub_ui.c @@ -514,7 +514,7 @@ void win_clear(ProfWin *window) {} void notifier_uninit(void) {} void notify_typing(const char * const handle) {} -void notify_message(ProfWin *window, const char * const name, const char * const text) {} +void notify_message(const char *const name, int win, const char *const text) {} void notify_room_message(const char * const handle, const char * const room, int win, const char * const text) {} void notify_remind(void) {} From b9794361f7eb59052b8662284ca11b18bb3187dc Mon Sep 17 00:00:00 2001 From: James Booth Date: Wed, 25 Nov 2015 01:42:27 +0000 Subject: [PATCH 05/13] Implemented regular chat notify triggers --- src/config/preferences.c | 40 +++++++++++++++++++++++++++++++++++++--- src/config/preferences.h | 2 +- src/ui/chatwin.c | 12 +----------- 3 files changed, 39 insertions(+), 15 deletions(-) diff --git a/src/config/preferences.c b/src/config/preferences.c index 205d47df..d8ddd159 100644 --- a/src/config/preferences.c +++ b/src/config/preferences.c @@ -202,17 +202,51 @@ prefs_reset_room_trigger_ac(void) autocomplete_reset(room_trigger_ac); } + + gboolean -prefs_get_notify_chat(gboolean current_win) +prefs_get_notify_chat(gboolean current_win, const char *const message) { gboolean notify_message = prefs_get_boolean(PREF_NOTIFY_MESSAGE); - gboolean notify_window = FALSE; + gboolean notify_trigger = prefs_get_boolean(PREF_NOTIFY_MESSAGE_TRIGGER); + gboolean trigger_found = FALSE; + if (notify_trigger) { + char *message_lower = g_utf8_strdown(message, -1); + gsize len = 0; + gchar **triggers = g_key_file_get_string_list(prefs, PREF_GROUP_NOTIFICATIONS, "message.trigger.list", &len, NULL); + int i; + for (i = 0; i < len; i++) { + char *trigger_lower = g_utf8_strdown(triggers[i], -1); + if (g_strrstr(message_lower, trigger_lower)) { + trigger_found = TRUE; + g_free(trigger_lower); + break; + } + g_free(trigger_lower); + } + g_strfreev(triggers); + g_free(message_lower); + } + + gboolean notify_window = FALSE; if (!current_win || (current_win && prefs_get_boolean(PREF_NOTIFY_MESSAGE_CURRENT)) ) { notify_window = TRUE; } - return (notify_message && notify_window); + if (!notify_window) { + return FALSE; + } + + if (notify_message) { + return TRUE; + } + + if (notify_trigger && trigger_found) { + return TRUE; + } + + return FALSE; } gboolean diff --git a/src/config/preferences.h b/src/config/preferences.h index face1811..603ba30c 100644 --- a/src/config/preferences.h +++ b/src/config/preferences.h @@ -213,7 +213,7 @@ char* prefs_get_string(preference_t pref); void prefs_free_string(char *pref); void prefs_set_string(preference_t pref, char *value); -gboolean prefs_get_notify_chat(gboolean current_win); +gboolean prefs_get_notify_chat(gboolean current_win, const char *const message); gboolean prefs_get_notify_room(gboolean current_win, const char *const nick, const char *const message); #endif diff --git a/src/ui/chatwin.c b/src/ui/chatwin.c index 2efe82e1..f9bbedde 100644 --- a/src/ui/chatwin.c +++ b/src/ui/chatwin.c @@ -274,18 +274,8 @@ chatwin_incoming_msg(ProfChatWin *chatwin, const char *const resource, const cha beep(); } - if (!prefs_get_boolean(PREF_NOTIFY_MESSAGE)) { - free(display_name); - return; - } - - gboolean notify = FALSE; - gboolean is_current = wins_is_current(window); - if (!is_current || (is_current && prefs_get_boolean(PREF_NOTIFY_MESSAGE_CURRENT)) ) { - notify = TRUE; - } - + gboolean notify = prefs_get_notify_chat(is_current, message); if (!notify) { free(display_name); return; From 20e63e364b45894d481a35e019602183255e3496 Mon Sep 17 00:00:00 2001 From: James Booth Date: Wed, 25 Nov 2015 21:24:21 +0000 Subject: [PATCH 06/13] Finished basic /notify triggers --- src/command/command.c | 13 +++- src/command/commands.c | 19 ++++-- src/config/preferences.c | 135 ++++++++++++++++++++++++++------------- src/config/preferences.h | 5 +- src/ui/console.c | 34 +++++----- 5 files changed, 134 insertions(+), 72 deletions(-) diff --git a/src/command/command.c b/src/command/command.c index 547b5275..b52952b7 100644 --- a/src/command/command.c +++ b/src/command/command.c @@ -1067,7 +1067,8 @@ static struct cmd_t command_defs[] = "/notify message trigger remove ", "/notify message trigger list", "/notify message trigger on|off", - "/notify room on|off|mention", + "/notify room on|off", + "/notify room mention on|off", "/notify room current on|off", "/notify room text on|off", "/notify room trigger add ", @@ -1089,7 +1090,8 @@ static struct cmd_t command_defs[] = { "message trigger remove ", "Remove regular chat notification for specified text." }, { "message trigger list", "List all regular chat custom text notifications." }, { "message trigger on|off", "Enable or disable all regular chat custom text notifications." }, - { "room on|off|mention", "Notifications for chat room messages, mention triggers notifications only when your nick is mentioned." }, + { "room on|off", "Notifications for chat room messages, mention triggers notifications only when your nick is mentioned." }, + { "room mention on|off", "Notifications for chat room messages when your nick is mentioned." }, { "room current on|off", "Whether chat room messages in the current window trigger notifications." }, { "room text on|off", "Show message text in chat room message notifications." }, { "room trigger add ", "Notify when specified text included in regular chat message." }, @@ -1104,7 +1106,7 @@ static struct cmd_t command_defs[] = CMD_EXAMPLES( "/notify message on", "/notify message text on", - "/notify room mention", + "/notify room mention on", "/notify room current off", "/notify room text off", "/notify remind 10", @@ -3206,6 +3208,11 @@ _notify_autocomplete(ProfWin *window, const char *const input) return result; } + result = autocomplete_param_with_func(input, "/notify room mention", prefs_autocomplete_boolean_choice); + if (result) { + return result; + } + result = autocomplete_param_with_func(input, "/notify message text", prefs_autocomplete_boolean_choice); if (result) { return result; diff --git a/src/command/commands.c b/src/command/commands.c index 9bc7bdad..7146c68e 100644 --- a/src/command/commands.c +++ b/src/command/commands.c @@ -4354,14 +4354,21 @@ cmd_notify(ProfWin *window, const char *const command, gchar **args) // set room setting } else if (strcmp(kind, "room") == 0) { if (strcmp(args[1], "on") == 0) { - cons_show("Chat room notifications enabled."); - prefs_set_string(PREF_NOTIFY_ROOM, "on"); + cons_show("Room notifications enabled."); + prefs_set_boolean(PREF_NOTIFY_ROOM, TRUE); } else if (strcmp(args[1], "off") == 0) { - cons_show("Chat room notifications disabled."); - prefs_set_string(PREF_NOTIFY_ROOM, "off"); + cons_show("Room notifications disabled."); + prefs_set_boolean(PREF_NOTIFY_ROOM, FALSE); } else if (strcmp(args[1], "mention") == 0) { - cons_show("Chat room notifications enabled on mention."); - prefs_set_string(PREF_NOTIFY_ROOM, "mention"); + if (strcmp(args[2], "on") == 0) { + cons_show("Room notifications with mention enabled."); + prefs_set_boolean(PREF_NOTIFY_ROOM_MENTION, TRUE); + } else if (strcmp(args[2], "off") == 0) { + cons_show("Room notifications with mention disabled."); + prefs_set_boolean(PREF_NOTIFY_ROOM_MENTION, FALSE); + } else { + cons_show("Usage: /notify room mention on|off"); + } } else if (strcmp(args[1], "current") == 0) { if (g_strcmp0(args[2], "on") == 0) { cons_show("Current window chat room message notifications enabled."); diff --git a/src/config/preferences.c b/src/config/preferences.c index d8ddd159..fa371cf0 100644 --- a/src/config/preferences.c +++ b/src/config/preferences.c @@ -130,6 +130,19 @@ prefs_load(void) prefs_free_string(time); } + // move pre 0.4.8 notify settings + if (g_key_file_has_key(prefs, PREF_GROUP_NOTIFICATIONS, "room", NULL)) { + char *value = g_key_file_get_string(prefs, PREF_GROUP_NOTIFICATIONS, "room", NULL); + if (g_strcmp0(value, "on") == 0) { + g_key_file_set_boolean(prefs, PREF_GROUP_NOTIFICATIONS, "room", TRUE); + } else if (g_strcmp0(value, "off") == 0) { + g_key_file_set_boolean(prefs, PREF_GROUP_NOTIFICATIONS, "room", FALSE); + } else if (g_strcmp0(value, "mention") == 0) { + g_key_file_set_boolean(prefs, PREF_GROUP_NOTIFICATIONS, "room", FALSE); + g_key_file_set_boolean(prefs, PREF_GROUP_NOTIFICATIONS, "room.mention", TRUE); + } + } + _save_prefs(); boolean_choice_ac = autocomplete_new(); @@ -207,42 +220,43 @@ prefs_reset_room_trigger_ac(void) gboolean prefs_get_notify_chat(gboolean current_win, const char *const message) { - gboolean notify_message = prefs_get_boolean(PREF_NOTIFY_MESSAGE); - - gboolean notify_trigger = prefs_get_boolean(PREF_NOTIFY_MESSAGE_TRIGGER); - gboolean trigger_found = FALSE; - if (notify_trigger) { - char *message_lower = g_utf8_strdown(message, -1); - gsize len = 0; - gchar **triggers = g_key_file_get_string_list(prefs, PREF_GROUP_NOTIFICATIONS, "message.trigger.list", &len, NULL); - int i; - for (i = 0; i < len; i++) { - char *trigger_lower = g_utf8_strdown(triggers[i], -1); - if (g_strrstr(message_lower, trigger_lower)) { - trigger_found = TRUE; - g_free(trigger_lower); - break; - } - g_free(trigger_lower); - } - g_strfreev(triggers); - g_free(message_lower); - } - + gboolean notify_current = prefs_get_boolean(PREF_NOTIFY_MESSAGE_CURRENT); gboolean notify_window = FALSE; - if (!current_win || (current_win && prefs_get_boolean(PREF_NOTIFY_MESSAGE_CURRENT)) ) { + if (!current_win || (current_win && notify_current) ) { notify_window = TRUE; } - if (!notify_window) { return FALSE; } + gboolean notify_message = prefs_get_boolean(PREF_NOTIFY_MESSAGE); if (notify_message) { return TRUE; } - if (notify_trigger && trigger_found) { + gboolean notify_trigger = prefs_get_boolean(PREF_NOTIFY_MESSAGE_TRIGGER); + if (!notify_trigger) { + return FALSE; + } + + gboolean trigger_found = FALSE; + char *message_lower = g_utf8_strdown(message, -1); + gsize len = 0; + gchar **triggers = g_key_file_get_string_list(prefs, PREF_GROUP_NOTIFICATIONS, "message.trigger.list", &len, NULL); + int i; + for (i = 0; i < len; i++) { + char *trigger_lower = g_utf8_strdown(triggers[i], -1); + if (g_strrstr(message_lower, trigger_lower)) { + trigger_found = TRUE; + g_free(trigger_lower); + break; + } + g_free(trigger_lower); + } + g_strfreev(triggers); + g_free(message_lower); + + if (trigger_found) { return TRUE; } @@ -252,29 +266,60 @@ prefs_get_notify_chat(gboolean current_win, const char *const message) gboolean prefs_get_notify_room(gboolean current_win, const char *const nick, const char *const message) { - gboolean notify_message = FALSE; + gboolean notify_current = prefs_get_boolean(PREF_NOTIFY_ROOM_CURRENT); gboolean notify_window = FALSE; - - char *room_setting = prefs_get_string(PREF_NOTIFY_ROOM); - if (g_strcmp0(room_setting, "on") == 0) { - notify_message = TRUE; + if (!current_win || (current_win && notify_current) ) { + notify_window = TRUE; } - if (g_strcmp0(room_setting, "mention") == 0) { + if (!notify_window) { + return FALSE; + } + + gboolean notify_room = prefs_get_boolean(PREF_NOTIFY_ROOM); + if (notify_room) { + return TRUE; + } + + gboolean notify_mention = prefs_get_boolean(PREF_NOTIFY_ROOM_MENTION); + if (notify_mention) { char *message_lower = g_utf8_strdown(message, -1); char *nick_lower = g_utf8_strdown(nick, -1); if (g_strrstr(message_lower, nick_lower)) { - notify_message = TRUE; + g_free(message_lower); + g_free(nick_lower); + return TRUE; } g_free(message_lower); g_free(nick_lower); } - prefs_free_string(room_setting); - if (!current_win || (current_win && prefs_get_boolean(PREF_NOTIFY_ROOM_CURRENT)) ) { - notify_window = TRUE; + gboolean notify_trigger = prefs_get_boolean(PREF_NOTIFY_ROOM_TRIGGER); + if (!notify_trigger) { + return FALSE; } - return (notify_message && notify_window); + gboolean trigger_found = FALSE; + char *message_lower = g_utf8_strdown(message, -1); + gsize len = 0; + gchar **triggers = g_key_file_get_string_list(prefs, PREF_GROUP_NOTIFICATIONS, "room.trigger.list", &len, NULL); + int i; + for (i = 0; i < len; i++) { + char *trigger_lower = g_utf8_strdown(triggers[i], -1); + if (g_strrstr(message_lower, trigger_lower)) { + trigger_found = TRUE; + g_free(trigger_lower); + break; + } + g_free(trigger_lower); + } + g_strfreev(triggers); + g_free(message_lower); + + if (trigger_found) { + return TRUE; + } + + return FALSE; } gboolean @@ -989,13 +1034,14 @@ _get_group(preference_t pref) case PREF_NOTIFY_TYPING: case PREF_NOTIFY_TYPING_CURRENT: case PREF_NOTIFY_MESSAGE: + case PREF_NOTIFY_MESSAGE_TRIGGER: case PREF_NOTIFY_MESSAGE_CURRENT: case PREF_NOTIFY_MESSAGE_TEXT: - case PREF_NOTIFY_MESSAGE_TRIGGER: case PREF_NOTIFY_ROOM: + case PREF_NOTIFY_ROOM_MENTION: + case PREF_NOTIFY_ROOM_TRIGGER: case PREF_NOTIFY_ROOM_CURRENT: case PREF_NOTIFY_ROOM_TEXT: - case PREF_NOTIFY_ROOM_TRIGGER: case PREF_NOTIFY_INVITE: case PREF_NOTIFY_SUB: return PREF_GROUP_NOTIFICATIONS; @@ -1082,20 +1128,22 @@ _get_key(preference_t pref) return "typing.current"; case PREF_NOTIFY_MESSAGE: return "message"; + case PREF_NOTIFY_MESSAGE_TRIGGER: + return "message.trigger"; case PREF_NOTIFY_MESSAGE_CURRENT: return "message.current"; case PREF_NOTIFY_MESSAGE_TEXT: return "message.text"; - case PREF_NOTIFY_MESSAGE_TRIGGER: - return "message.trigger"; case PREF_NOTIFY_ROOM: return "room"; + case PREF_NOTIFY_ROOM_TRIGGER: + return "room.trigger"; + case PREF_NOTIFY_ROOM_MENTION: + return "room.mention"; case PREF_NOTIFY_ROOM_CURRENT: return "room.current"; case PREF_NOTIFY_ROOM_TEXT: return "room.text"; - case PREF_NOTIFY_ROOM_TRIGGER: - return "room.trigger"; case PREF_NOTIFY_INVITE: return "invite"; case PREF_NOTIFY_SUB: @@ -1204,6 +1252,7 @@ _get_default_boolean(preference_t pref) case PREF_LOG_SHARED: case PREF_NOTIFY_MESSAGE: case PREF_NOTIFY_MESSAGE_CURRENT: + case PREF_NOTIFY_ROOM: case PREF_NOTIFY_ROOM_CURRENT: case PREF_NOTIFY_TYPING: case PREF_NOTIFY_TYPING_CURRENT: @@ -1241,8 +1290,6 @@ _get_default_string(preference_t pref) { case PREF_AUTOAWAY_MODE: return "off"; - case PREF_NOTIFY_ROOM: - return "on"; case PREF_OTR_LOG: return "redact"; case PREF_OTR_POLICY: diff --git a/src/config/preferences.h b/src/config/preferences.h index 603ba30c..56c87d92 100644 --- a/src/config/preferences.h +++ b/src/config/preferences.h @@ -94,13 +94,14 @@ typedef enum { PREF_NOTIFY_TYPING, PREF_NOTIFY_TYPING_CURRENT, PREF_NOTIFY_MESSAGE, + PREF_NOTIFY_MESSAGE_TRIGGER, PREF_NOTIFY_MESSAGE_CURRENT, PREF_NOTIFY_MESSAGE_TEXT, - PREF_NOTIFY_MESSAGE_TRIGGER, PREF_NOTIFY_ROOM, + PREF_NOTIFY_ROOM_MENTION, + PREF_NOTIFY_ROOM_TRIGGER, PREF_NOTIFY_ROOM_CURRENT, PREF_NOTIFY_ROOM_TEXT, - PREF_NOTIFY_ROOM_TRIGGER, PREF_NOTIFY_INVITE, PREF_NOTIFY_SUB, PREF_CHLOG, diff --git a/src/ui/console.c b/src/ui/console.c index 066ea32c..6081d56a 100644 --- a/src/ui/console.c +++ b/src/ui/console.c @@ -1329,6 +1329,11 @@ cons_notify_setting(void) else cons_show("Messages (/notify message) : OFF"); + if (prefs_get_boolean(PREF_NOTIFY_MESSAGE_TRIGGER)) + cons_show("Messages trigger (/notify message) : ON"); + else + cons_show("Messages trigger (/notify message) : OFF"); + if (prefs_get_boolean(PREF_NOTIFY_MESSAGE_CURRENT)) cons_show("Messages current (/notify message) : ON"); else @@ -1339,20 +1344,20 @@ cons_notify_setting(void) else cons_show("Messages text (/notify message) : OFF"); - if (prefs_get_boolean(PREF_NOTIFY_MESSAGE_TRIGGER)) - cons_show("Messages trigger (/notify message) : ON"); + if (prefs_get_boolean(PREF_NOTIFY_ROOM)) + cons_show("Room messages (/notify room) : ON"); else - cons_show("Messages trigger (/notify message) : OFF"); + cons_show("Room messages (/notify room) : OFF"); - char *room_setting = prefs_get_string(PREF_NOTIFY_ROOM); - if (g_strcmp0(room_setting, "on") == 0) { - cons_show ("Room messages (/notify room) : ON"); - } else if (g_strcmp0(room_setting, "off") == 0) { - cons_show ("Room messages (/notify room) : OFF"); - } else { - cons_show ("Room messages (/notify room) : %s", room_setting); - } - prefs_free_string(room_setting); + if (prefs_get_boolean(PREF_NOTIFY_ROOM_MENTION)) + cons_show("Room mention (/notify room) : ON"); + else + cons_show("Room mention (/notify room) : OFF"); + + if (prefs_get_boolean(PREF_NOTIFY_ROOM_TRIGGER)) + cons_show("Room trigger (/notify room) : ON"); + else + cons_show("Room trigger (/notify room) : OFF"); if (prefs_get_boolean(PREF_NOTIFY_ROOM_CURRENT)) cons_show("Room current (/notify room) : ON"); @@ -1364,11 +1369,6 @@ cons_notify_setting(void) else cons_show("Room text (/notify room) : OFF"); - if (prefs_get_boolean(PREF_NOTIFY_ROOM_TRIGGER)) - cons_show("Room trigger (/notify room) : ON"); - else - cons_show("Room trigger (/notify room) : OFF"); - if (prefs_get_boolean(PREF_NOTIFY_TYPING)) cons_show("Composing (/notify typing) : ON"); else From d3389db2336544b6f611ef03d7eb390ab4f7d295 Mon Sep 17 00:00:00 2001 From: James Booth Date: Wed, 25 Nov 2015 22:08:33 +0000 Subject: [PATCH 07/13] Only show reminder notifications when notifications are enabled --- src/ui/chatwin.c | 8 ++++++-- src/ui/mucwin.c | 8 ++++++-- src/ui/notifier.c | 5 +++-- src/ui/privwin.c | 18 ++++++------------ src/ui/ui.h | 1 + src/ui/win_types.h | 3 +++ src/ui/window.c | 23 +++++++++++++++++++++++ src/window_list.c | 20 ++++++++++++++++++++ src/window_list.h | 1 + tests/unittests/ui/stub_ui.c | 4 ++++ 10 files changed, 73 insertions(+), 18 deletions(-) diff --git a/src/ui/chatwin.c b/src/ui/chatwin.c index f9bbedde..c8cee66b 100644 --- a/src/ui/chatwin.c +++ b/src/ui/chatwin.c @@ -239,6 +239,9 @@ chatwin_incoming_msg(ProfChatWin *chatwin, const char *const resource, const cha char *display_name = roster_get_msg_display_name(chatwin->barejid, resource); + gboolean is_current = wins_is_current(window); + gboolean notify = prefs_get_notify_chat(is_current, message); + // currently viewing chat window with sender if (wins_is_current(window)) { win_print_incoming_message(window, timestamp, display_name, message, enc_mode); @@ -255,6 +258,9 @@ chatwin_incoming_msg(ProfChatWin *chatwin, const char *const resource, const cha } chatwin->unread++; + if (notify) { + chatwin->notify = TRUE; + } if (prefs_get_boolean(PREF_CHLOG) && prefs_get_boolean(PREF_HISTORY)) { _chatwin_history(chatwin, chatwin->barejid); } @@ -274,8 +280,6 @@ chatwin_incoming_msg(ProfChatWin *chatwin, const char *const resource, const cha beep(); } - gboolean is_current = wins_is_current(window); - gboolean notify = prefs_get_notify_chat(is_current, message); if (!notify) { free(display_name); return; diff --git a/src/ui/mucwin.c b/src/ui/mucwin.c index aa825d16..82b74e1b 100644 --- a/src/ui/mucwin.c +++ b/src/ui/mucwin.c @@ -374,6 +374,9 @@ mucwin_message(ProfMucWin *mucwin, const char *const nick, const char *const mes win_print(window, '-', 0, NULL, 0, THEME_TEXT_ME, nick, message); } + gboolean is_current = wins_is_current(window); + gboolean notify = prefs_get_notify_room(is_current, my_nick, message); + // currently in groupchat window if (wins_is_current(window)) { status_bar_active(num); @@ -388,6 +391,9 @@ mucwin_message(ProfMucWin *mucwin, const char *const nick, const char *const mes } mucwin->unread++; + if (notify) { + mucwin->notify = TRUE; + } } // don't notify self messages @@ -399,8 +405,6 @@ mucwin_message(ProfMucWin *mucwin, const char *const nick, const char *const mes beep(); } - gboolean is_current = wins_is_current(window); - gboolean notify = prefs_get_notify_room(is_current, my_nick, message); if (!notify) { return; } diff --git a/src/ui/notifier.c b/src/ui/notifier.c index c0861009..9a185e38 100644 --- a/src/ui/notifier.c +++ b/src/ui/notifier.c @@ -140,13 +140,14 @@ notify_remind(void) gdouble elapsed = g_timer_elapsed(remind_timer, NULL); gint remind_period = prefs_get_notify_remind(); if (remind_period > 0 && elapsed >= remind_period) { + gboolean notify = wins_get_notify(); gint unread = wins_get_total_unread(); gint open = muc_invites_count(); gint subs = presence_sub_request_count(); GString *text = g_string_new(""); - if (unread > 0) { + if (notify && unread > 0) { if (unread == 1) { g_string_append(text, "1 unread message"); } else { @@ -175,7 +176,7 @@ notify_remind(void) } } - if ((unread > 0) || (open > 0) || (subs > 0)) { + if ((notify && unread > 0) || (open > 0) || (subs > 0)) { _notify(text->str, 5000, "Incoming message"); } diff --git a/src/ui/privwin.c b/src/ui/privwin.c index 10ce1dbe..67bad379 100644 --- a/src/ui/privwin.c +++ b/src/ui/privwin.c @@ -53,6 +53,9 @@ privwin_incoming_msg(ProfPrivateWin *privatewin, const char *const message, GDat char *display_from = get_nick_from_full_jid(privatewin->fulljid); + gboolean is_current = wins_is_current(window); + gboolean notify = prefs_get_notify_chat(is_current, message); + // currently viewing chat window with sender if (wins_is_current(window)) { win_print_incoming_message(window, timestamp, display_from, message, PROF_MSG_PLAIN); @@ -62,6 +65,9 @@ privwin_incoming_msg(ProfPrivateWin *privatewin, const char *const message, GDat // not currently viewing chat window with sender } else { privatewin->unread++; + if (notify) { + privatewin->notify = TRUE; + } status_bar_new(num); cons_show_incoming_message(display_from, num); win_print_incoming_message(window, timestamp, display_from, message, PROF_MSG_PLAIN); @@ -75,18 +81,6 @@ privwin_incoming_msg(ProfPrivateWin *privatewin, const char *const message, GDat beep(); } - if (!prefs_get_boolean(PREF_NOTIFY_MESSAGE)) { - free(display_from); - return; - } - - gboolean notify = FALSE; - - gboolean is_current = wins_is_current(window); - if (!is_current || (is_current && prefs_get_boolean(PREF_NOTIFY_MESSAGE_CURRENT)) ) { - notify = TRUE; - } - if (!notify) { free(display_from); return; diff --git a/src/ui/ui.h b/src/ui/ui.h index 3cc40001..458255f1 100644 --- a/src/ui/ui.h +++ b/src/ui/ui.h @@ -319,6 +319,7 @@ ProfWin* win_create_muc_config(const char *const title, DataForm *form); ProfWin* win_create_private(const char *const fulljid); void win_update_virtual(ProfWin *window); void win_free(ProfWin *window); +gboolean win_notify(ProfWin *window); int win_unread(ProfWin *window); void win_resize(ProfWin *window); void win_hide_subwin(ProfWin *window); diff --git a/src/ui/win_types.h b/src/ui/win_types.h index bace4537..94901957 100644 --- a/src/ui/win_types.h +++ b/src/ui/win_types.h @@ -102,6 +102,7 @@ typedef struct prof_chat_win_t { ProfWin window; char *barejid; int unread; + gboolean notify; ChatState *state; gboolean is_otr; gboolean otr_is_trusted; @@ -116,6 +117,7 @@ typedef struct prof_muc_win_t { ProfWin window; char *roomjid; int unread; + gboolean notify; gboolean showjid; unsigned long memcheck; } ProfMucWin; @@ -131,6 +133,7 @@ typedef struct prof_private_win_t { ProfWin window; char *fulljid; int unread; + gboolean notify; unsigned long memcheck; } ProfPrivateWin; diff --git a/src/ui/window.c b/src/ui/window.c index 9317f3b8..d6500a67 100644 --- a/src/ui/window.c +++ b/src/ui/window.c @@ -141,6 +141,7 @@ win_create_chat(const char *const barejid) new_win->pgp_send = FALSE; new_win->history_shown = FALSE; new_win->unread = 0; + new_win->notify = FALSE; new_win->state = chat_state_new(); new_win->memcheck = PROFCHATWIN_MEMCHECK; @@ -180,6 +181,7 @@ win_create_muc(const char *const roomjid) new_win->roomjid = strdup(roomjid); new_win->unread = 0; + new_win->notify = FALSE; if (prefs_get_boolean(PREF_OCCUPANTS_JID)) { new_win->showjid = TRUE; } else { @@ -215,6 +217,7 @@ win_create_private(const char *const fulljid) new_win->fulljid = strdup(fulljid); new_win->unread = 0; + new_win->notify = FALSE; new_win->memcheck = PROFPRIVATEWIN_MEMCHECK; @@ -1245,6 +1248,26 @@ win_has_active_subwin(ProfWin *window) } } +gboolean +win_notify(ProfWin *window) +{ + if (window->type == WIN_CHAT) { + ProfChatWin *chatwin = (ProfChatWin*) window; + assert(chatwin->memcheck == PROFCHATWIN_MEMCHECK); + return chatwin->notify; + } else if (window->type == WIN_MUC) { + ProfMucWin *mucwin = (ProfMucWin*) window; + assert(mucwin->memcheck == PROFMUCWIN_MEMCHECK); + return mucwin->notify; + } else if (window->type == WIN_PRIVATE) { + ProfPrivateWin *privatewin = (ProfPrivateWin*) window; + assert(privatewin->memcheck == PROFPRIVATEWIN_MEMCHECK); + return privatewin->notify; + } else { + return FALSE; + } +} + int win_unread(ProfWin *window) { diff --git a/src/window_list.c b/src/window_list.c index 46da0e75..14bf6ea5 100644 --- a/src/window_list.c +++ b/src/window_list.c @@ -189,13 +189,16 @@ wins_set_current_by_num(int i) ProfChatWin *chatwin = (ProfChatWin*) window; assert(chatwin->memcheck == PROFCHATWIN_MEMCHECK); chatwin->unread = 0; + chatwin->notify = FALSE; } else if (window->type == WIN_MUC) { ProfMucWin *mucwin = (ProfMucWin*) window; assert(mucwin->memcheck == PROFMUCWIN_MEMCHECK); mucwin->unread = 0; + mucwin->notify = FALSE; } else if (window->type == WIN_PRIVATE) { ProfPrivateWin *privatewin = (ProfPrivateWin*) window; privatewin->unread = 0; + privatewin->notify = FALSE; } } } @@ -382,6 +385,23 @@ wins_new_private(const char *const fulljid) return newwin; } +gboolean +wins_get_notify(void) +{ + GList *values = g_hash_table_get_values(windows); + GList *curr = values; + + while (curr) { + ProfWin *window = curr->data; + if (win_notify(window)) { + g_list_free(values); + return TRUE; + } + curr = g_list_next(curr); + } + return FALSE; +} + int wins_get_total_unread(void) { diff --git a/src/window_list.h b/src/window_list.h index 4b7dca8c..4cf4e5f8 100644 --- a/src/window_list.h +++ b/src/window_list.h @@ -67,6 +67,7 @@ int wins_get_current_num(void); void wins_close_current(void); void wins_close_by_num(int i); gboolean wins_is_current(ProfWin *window); +gboolean wins_get_notify(void); int wins_get_total_unread(void); void wins_resize_all(void); GSList* wins_get_chat_recipients(void); diff --git a/tests/unittests/ui/stub_ui.c b/tests/unittests/ui/stub_ui.c index 4cab2ea9..37d49d4d 100644 --- a/tests/unittests/ui/stub_ui.c +++ b/tests/unittests/ui/stub_ui.c @@ -486,6 +486,10 @@ ProfWin* win_create_private(const char * const fulljid) void win_update_virtual(ProfWin *window) {} void win_free(ProfWin *window) {} +gboolean win_notify(ProfWin *window) +{ + return TRUE; +} int win_unread(ProfWin *window) { return 0; From 60305de0d979bc09669ab1215d3642e2daa5f045 Mon Sep 17 00:00:00 2001 From: James Booth Date: Sat, 28 Nov 2015 00:15:53 +0000 Subject: [PATCH 08/13] Added room specific notify settings --- src/command/command.c | 72 +++++++--------- src/command/commands.c | 176 ++++++++++++++++++++++++++++++++++----- src/config/preferences.c | 169 +++++++++++++++++++++++++++---------- src/config/preferences.h | 15 +++- src/ui/chatwin.c | 2 +- src/ui/mucwin.c | 2 +- src/ui/privwin.c | 2 +- 7 files changed, 328 insertions(+), 110 deletions(-) diff --git a/src/command/command.c b/src/command/command.c index b52952b7..456bfe6c 100644 --- a/src/command/command.c +++ b/src/command/command.c @@ -1054,7 +1054,7 @@ static struct cmd_t command_defs[] = }, { "/notify", - cmd_notify, parse_args_with_freetext, 2, 4, &cons_notify_setting, + cmd_notify, parse_args_with_freetext, 0, 4, NULL, CMD_TAGS( CMD_TAG_UI, CMD_TAG_CHAT, @@ -1075,6 +1075,9 @@ static struct cmd_t command_defs[] = "/notify room trigger remove ", "/notify room trigger list", "/notify room trigger on|off", + "/notify on|off", + "/notify mention on|off", + "/notify trigger on|off" "/notify remind ", "/notify typing on|off", "/notify typing current on|off", @@ -1084,20 +1087,23 @@ static struct cmd_t command_defs[] = "Settings for various kinds of desktop notifications.") CMD_ARGS( { "message on|off", "Notifications for regular chat messages." }, - { "message current on|off", "Whether messages in the current window trigger notifications." }, + { "message current on|off", "Whether to show regular chat message notifications when the window is focussed." }, { "message text on|off", "Show message text in regular message notifications." }, { "message trigger add ", "Notify when specified text included in regular chat message." }, { "message trigger remove ", "Remove regular chat notification for specified text." }, { "message trigger list", "List all regular chat custom text notifications." }, - { "message trigger on|off", "Enable or disable all regular chat custom text notifications." }, - { "room on|off", "Notifications for chat room messages, mention triggers notifications only when your nick is mentioned." }, - { "room mention on|off", "Notifications for chat room messages when your nick is mentioned." }, - { "room current on|off", "Whether chat room messages in the current window trigger notifications." }, + { "message trigger on|off", "Enable or disable all regular chat notification triggers." }, + { "room on|off", "Notifications for all chat room messages, 'mention' only notifies when your nick is mentioned." }, + { "room mention on|off", "Notifications for all chat room messages when your nick is mentioned." }, + { "room current on|off", "Whether to show all chat room messages notifications when the window is focussed." }, { "room text on|off", "Show message text in chat room message notifications." }, - { "room trigger add ", "Notify when specified text included in regular chat message." }, - { "room trigger remove ", "Remove regular chat notification for specified text." }, - { "room trigger list", "List all regular chat custom text notifications." }, - { "room trigger on|off", "Enable or disable all regular chat custom text notifications." }, + { "room trigger add ", "Notify when specified text included in all chat room messages." }, + { "room trigger remove ", "Remove chat room notification trigger." }, + { "room trigger list", "List all chat room triggers." }, + { "room trigger on|off", "Enable or disable all chat room notification triggers." }, + { "on|off", "Notifications for the current chat room." }, + { "mention on|off", "Override the global 'mention' setting for the current chat room." }, + { "trigger on|off", "Override the global 'trigger' setting for the current chat room." }, { "remind ", "Notification reminder period for unread messages, use 0 to disable." }, { "typing on|off", "Notifications when contacts are typing." }, { "typing current on|off", "Whether typing notifications are triggered for the current window." }, @@ -1942,6 +1948,10 @@ cmd_init(void) autocomplete_add(notify_ac, "remind"); autocomplete_add(notify_ac, "invite"); autocomplete_add(notify_ac, "sub"); + autocomplete_add(notify_ac, "on"); + autocomplete_add(notify_ac, "off"); + autocomplete_add(notify_ac, "mention"); + autocomplete_add(notify_ac, "trigger"); notify_message_ac = autocomplete_new(); autocomplete_add(notify_message_ac, "on"); @@ -3178,9 +3188,14 @@ _notify_autocomplete(ProfWin *window, const char *const input) return result; } - result = autocomplete_param_with_func(input, "/notify room current", prefs_autocomplete_boolean_choice); - if (result) { - return result; + gchar *boolean_choices1[] = { "/notify room current", "/notify message current", "/notify typing current", + "/notify room text", "/notify room mention", "/notify message text" }; + for (i = 0; i < ARRAY_SIZE(boolean_choices1); i++) { + result = autocomplete_param_with_func(input, boolean_choices1[i], + prefs_autocomplete_boolean_choice); + if (result) { + return result; + } } result = autocomplete_param_with_ac(input, "/notify room trigger", notify_trigger_ac, TRUE); @@ -3188,36 +3203,11 @@ _notify_autocomplete(ProfWin *window, const char *const input) return result; } - result = autocomplete_param_with_func(input, "/notify message current", prefs_autocomplete_boolean_choice); - if (result) { - return result; - } - result = autocomplete_param_with_ac(input, "/notify message trigger", notify_trigger_ac, TRUE); if (result) { return result; } - result = autocomplete_param_with_func(input, "/notify typing current", prefs_autocomplete_boolean_choice); - if (result) { - return result; - } - - result = autocomplete_param_with_func(input, "/notify room text", prefs_autocomplete_boolean_choice); - if (result) { - return result; - } - - result = autocomplete_param_with_func(input, "/notify room mention", prefs_autocomplete_boolean_choice); - if (result) { - return result; - } - - result = autocomplete_param_with_func(input, "/notify message text", prefs_autocomplete_boolean_choice); - if (result) { - return result; - } - result = autocomplete_param_with_ac(input, "/notify room", notify_room_ac, TRUE); if (result) { return result; @@ -3233,9 +3223,9 @@ _notify_autocomplete(ProfWin *window, const char *const input) return result; } - gchar *boolean_choices[] = { "/notify invite", "/notify sub" }; - for (i = 0; i < ARRAY_SIZE(boolean_choices); i++) { - result = autocomplete_param_with_func(input, boolean_choices[i], + gchar *boolean_choices2[] = { "/notify invite", "/notify sub", "/notify mention", "/notify trigger"}; + for (i = 0; i < ARRAY_SIZE(boolean_choices2); i++) { + result = autocomplete_param_with_func(input, boolean_choices2[i], prefs_autocomplete_boolean_choice); if (result) { return result; diff --git a/src/command/commands.c b/src/command/commands.c index b87cf1f5..f3c21cd4 100644 --- a/src/command/commands.c +++ b/src/command/commands.c @@ -4266,16 +4266,48 @@ cmd_gone(ProfWin *window, const char *const command, gchar **args) gboolean cmd_notify(ProfWin *window, const char *const command, gchar **args) { - char *kind = args[0]; + if (!args[0]) { + ProfWin *current = wins_get_current(); + if (current->type == WIN_MUC) { + ProfMucWin *mucwin = (ProfMucWin *)current; + gboolean has_notify = prefs_has_room_notify(mucwin->roomjid); + gboolean has_notify_mention = prefs_has_room_notify_mention(mucwin->roomjid); + gboolean has_notify_trigger = prefs_has_room_notify_trigger(mucwin->roomjid); - // bad kind - if ((strcmp(kind, "message") != 0) && (strcmp(kind, "typing") != 0) && - (strcmp(kind, "remind") != 0) && (strcmp(kind, "invite") != 0) && - (strcmp(kind, "sub") != 0) && (strcmp(kind, "room") != 0)) { - cons_bad_cmd_usage(command); + if (!has_notify && !has_notify_mention && !has_notify_trigger) { + win_vprintln_ch(window, '!', "No notification settings for %s", mucwin->roomjid); + } else { + win_vprintln_ch(window, '!', "Notification settings for %s", mucwin->roomjid); + if (has_notify) { + if (prefs_get_room_notify(mucwin->roomjid)) { + win_vprintln_ch(window, '!', " All: ON"); + } else { + win_vprintln_ch(window, '!', " All: OFF"); + } + } + if (has_notify_mention) { + if (prefs_get_room_notify_mention(mucwin->roomjid)) { + win_vprintln_ch(window, '!', " Mention: ON"); + } else { + win_vprintln_ch(window, '!', " Mention: OFF"); + } + } + if (has_notify_trigger) { + if (prefs_get_room_notify_trigger(mucwin->roomjid)) { + win_vprintln_ch(window, '!', " Triggers: ON"); + } else { + win_vprintln_ch(window, '!', " Triggers: OFF"); + } + } + } + } else { + cons_notify_setting(); + } + return TRUE; + } - // set message setting - } else if (strcmp(kind, "message") == 0) { + // message settings + if (strcmp(args[0], "message") == 0) { if (strcmp(args[1], "on") == 0) { cons_show("Message notifications enabled."); prefs_set_boolean(PREF_NOTIFY_MESSAGE, TRUE); @@ -4351,8 +4383,8 @@ cmd_notify(ProfWin *window, const char *const command, gchar **args) cons_show("Usage: /notify message on|off"); } - // set room setting - } else if (strcmp(kind, "room") == 0) { + // chat room settings + } else if (strcmp(args[0], "room") == 0) { if (strcmp(args[1], "on") == 0) { cons_show("Room notifications enabled."); prefs_set_boolean(PREF_NOTIFY_ROOM, TRUE); @@ -4438,8 +4470,8 @@ cmd_notify(ProfWin *window, const char *const command, gchar **args) cons_show("Usage: /notify room on|off|mention"); } - // set typing setting - } else if (strcmp(kind, "typing") == 0) { + // typing settings + } else if (strcmp(args[0], "typing") == 0) { if (strcmp(args[1], "on") == 0) { cons_show("Typing notifications enabled."); prefs_set_boolean(PREF_NOTIFY_TYPING, TRUE); @@ -4460,8 +4492,8 @@ cmd_notify(ProfWin *window, const char *const command, gchar **args) cons_show("Usage: /notify typing on|off"); } - // set invite setting - } else if (strcmp(kind, "invite") == 0) { + // invite settings + } else if (strcmp(args[0], "invite") == 0) { if (strcmp(args[1], "on") == 0) { cons_show("Chat room invite notifications enabled."); prefs_set_boolean(PREF_NOTIFY_INVITE, TRUE); @@ -4472,8 +4504,8 @@ cmd_notify(ProfWin *window, const char *const command, gchar **args) cons_show("Usage: /notify invite on|off"); } - // set subscription setting - } else if (strcmp(kind, "sub") == 0) { + // subscription settings + } else if (strcmp(args[0], "sub") == 0) { if (strcmp(args[1], "on") == 0) { cons_show("Subscription notifications enabled."); prefs_set_boolean(PREF_NOTIFY_SUB, TRUE); @@ -4484,8 +4516,8 @@ cmd_notify(ProfWin *window, const char *const command, gchar **args) cons_show("Usage: /notify sub on|off"); } - // set remind setting - } else if (strcmp(kind, "remind") == 0) { + // remind settings + } else if (strcmp(args[0], "remind") == 0) { gint period = atoi(args[1]); prefs_set_notify_remind(period); if (period == 0) { @@ -4496,8 +4528,114 @@ cmd_notify(ProfWin *window, const char *const command, gchar **args) cons_show("Message reminder period set to %d seconds.", period); } + // current chat room settings + } else if (g_strcmp0(args[0], "on") == 0) { + jabber_conn_status_t conn_status = jabber_get_connection_status(); + + if (conn_status != JABBER_CONNECTED) { + cons_show("You are not currenlty connected."); + } else { + ProfWin *window = wins_get_current(); + if (window->type != WIN_MUC) { + cons_show("You must be in a chat room."); + } else { + ProfMucWin *mucwin = (ProfMucWin*)window; + prefs_set_room_notify(mucwin->roomjid, TRUE); + win_vprintln_ch(window, '!', "Notifications enabled for %s", mucwin->roomjid); + } + } + } else if (g_strcmp0(args[0], "off") == 0) { + jabber_conn_status_t conn_status = jabber_get_connection_status(); + + if (conn_status != JABBER_CONNECTED) { + cons_show("You are not currenlty connected."); + } else { + ProfWin *window = wins_get_current(); + if (window->type != WIN_MUC) { + cons_show("You must be in a chat room."); + } else { + ProfMucWin *mucwin = (ProfMucWin*)window; + prefs_set_room_notify(mucwin->roomjid, FALSE); + win_vprintln_ch(window, '!', "Notifications disabled for %s", mucwin->roomjid); + } + } + } else if (g_strcmp0(args[0], "mention") == 0) { + jabber_conn_status_t conn_status = jabber_get_connection_status(); + + if (conn_status != JABBER_CONNECTED) { + cons_show("You are not currenlty connected."); + } else { + if (g_strcmp0(args[1], "on") == 0) { + ProfWin *window = wins_get_current(); + if (window->type != WIN_MUC) { + cons_show("You must be in a chat room."); + } else { + ProfMucWin *mucwin = (ProfMucWin*)window; + prefs_set_room_notify_mention(mucwin->roomjid, TRUE); + win_vprintln_ch(window, '!', "Mention notifications enabled for %s", mucwin->roomjid); + } + } else if (g_strcmp0(args[1], "off") == 0) { + ProfWin *window = wins_get_current(); + if (window->type != WIN_MUC) { + cons_show("You must be in a chat rooms."); + } else { + ProfMucWin *mucwin = (ProfMucWin*)window; + prefs_set_room_notify_mention(mucwin->roomjid, FALSE); + win_vprintln_ch(window, '!', "Mention notifications disabled for %s", mucwin->roomjid); + } + } else { + cons_bad_cmd_usage(command); + } + } + } else if (g_strcmp0(args[0], "trigger") == 0) { + jabber_conn_status_t conn_status = jabber_get_connection_status(); + + if (conn_status != JABBER_CONNECTED) { + cons_show("You are not currenlty connected."); + } else { + if (g_strcmp0(args[1], "on") == 0) { + ProfWin *window = wins_get_current(); + if (window->type != WIN_MUC) { + cons_show("You must be in a chat room."); + } else { + ProfMucWin *mucwin = (ProfMucWin*)window; + prefs_set_room_notify_trigger(mucwin->roomjid, TRUE); + win_vprintln_ch(window, '!', "Custom trigger notifications enabled for %s", mucwin->roomjid); + } + } else if (g_strcmp0(args[1], "off") == 0) { + ProfWin *window = wins_get_current(); + if (window->type != WIN_MUC) { + cons_show("You must be in a chat rooms."); + } else { + ProfMucWin *mucwin = (ProfMucWin*)window; + prefs_set_room_notify_trigger(mucwin->roomjid, FALSE); + win_vprintln_ch(window, '!', "Custom trigger notifications disabled for %s", mucwin->roomjid); + } + } else { + cons_bad_cmd_usage(command); + } + } + } else if (g_strcmp0(args[0], "reset") == 0) { + jabber_conn_status_t conn_status = jabber_get_connection_status(); + + if (conn_status != JABBER_CONNECTED) { + cons_show("You are not currenlty connected."); + } else { + ProfWin *window = wins_get_current(); + if (window->type != WIN_MUC) { + cons_show("You must be in a chat room."); + } else { + ProfMucWin *mucwin = (ProfMucWin*)window; + gboolean res = prefs_reset_room_notify(mucwin->roomjid); + if (res) { + win_vprintln_ch(window, '!', "Notification settings set to global defaults for %s", mucwin->roomjid); + } else { + win_vprintln_ch(window, '!', "No custom notification settings for %s", mucwin->roomjid); + } + } + } } else { - cons_show("Unknown command: %s.", kind); + cons_bad_cmd_usage(command); } return TRUE; diff --git a/src/config/preferences.c b/src/config/preferences.c index fa371cf0..3afead41 100644 --- a/src/config/preferences.c +++ b/src/config/preferences.c @@ -215,10 +215,8 @@ prefs_reset_room_trigger_ac(void) autocomplete_reset(room_trigger_ac); } - - gboolean -prefs_get_notify_chat(gboolean current_win, const char *const message) +prefs_do_chat_notify(gboolean current_win, const char *const message) { gboolean notify_current = prefs_get_boolean(PREF_NOTIFY_MESSAGE_CURRENT); gboolean notify_window = FALSE; @@ -235,36 +233,35 @@ prefs_get_notify_chat(gboolean current_win, const char *const message) } gboolean notify_trigger = prefs_get_boolean(PREF_NOTIFY_MESSAGE_TRIGGER); - if (!notify_trigger) { - return FALSE; - } - - gboolean trigger_found = FALSE; - char *message_lower = g_utf8_strdown(message, -1); - gsize len = 0; - gchar **triggers = g_key_file_get_string_list(prefs, PREF_GROUP_NOTIFICATIONS, "message.trigger.list", &len, NULL); - int i; - for (i = 0; i < len; i++) { - char *trigger_lower = g_utf8_strdown(triggers[i], -1); - if (g_strrstr(message_lower, trigger_lower)) { - trigger_found = TRUE; + if (notify_trigger) { + gboolean trigger_found = FALSE; + char *message_lower = g_utf8_strdown(message, -1); + gsize len = 0; + gchar **triggers = g_key_file_get_string_list(prefs, PREF_GROUP_NOTIFICATIONS, "message.trigger.list", &len, NULL); + int i; + for (i = 0; i < len; i++) { + char *trigger_lower = g_utf8_strdown(triggers[i], -1); + if (g_strrstr(message_lower, trigger_lower)) { + trigger_found = TRUE; + g_free(trigger_lower); + break; + } g_free(trigger_lower); - break; } - g_free(trigger_lower); - } - g_strfreev(triggers); - g_free(message_lower); + g_strfreev(triggers); + g_free(message_lower); - if (trigger_found) { - return TRUE; + if (trigger_found) { + return TRUE; + } } return FALSE; } gboolean -prefs_get_notify_room(gboolean current_win, const char *const nick, const char *const message) +prefs_do_room_notify(gboolean current_win, const char *const roomjid, const char *const nick, + const char *const message) { gboolean notify_current = prefs_get_boolean(PREF_NOTIFY_ROOM_CURRENT); gboolean notify_window = FALSE; @@ -275,12 +272,22 @@ prefs_get_notify_room(gboolean current_win, const char *const nick, const char * return FALSE; } - gboolean notify_room = prefs_get_boolean(PREF_NOTIFY_ROOM); + gboolean notify_room = FALSE; + if (g_key_file_has_key(prefs, roomjid, "notify", NULL)) { + notify_room = g_key_file_get_boolean(prefs, roomjid, "notify", NULL); + } else { + notify_room = prefs_get_boolean(PREF_NOTIFY_ROOM); + } if (notify_room) { return TRUE; } - gboolean notify_mention = prefs_get_boolean(PREF_NOTIFY_ROOM_MENTION); + gboolean notify_mention = FALSE; + if (g_key_file_has_key(prefs, roomjid, "notify.mention", NULL)) { + notify_mention = g_key_file_get_boolean(prefs, roomjid, "notify.mention", NULL); + } else { + notify_mention = prefs_get_boolean(PREF_NOTIFY_ROOM_MENTION); + } if (notify_mention) { char *message_lower = g_utf8_strdown(message, -1); char *nick_lower = g_utf8_strdown(nick, -1); @@ -293,29 +300,101 @@ prefs_get_notify_room(gboolean current_win, const char *const nick, const char * g_free(nick_lower); } - gboolean notify_trigger = prefs_get_boolean(PREF_NOTIFY_ROOM_TRIGGER); - if (!notify_trigger) { - return FALSE; + gboolean notify_trigger = FALSE; + if (g_key_file_has_key(prefs, roomjid, "notify.trigger", NULL)) { + notify_trigger = g_key_file_get_boolean(prefs, roomjid, "notify.trigger", NULL); + } else { + notify_trigger = prefs_get_boolean(PREF_NOTIFY_ROOM_TRIGGER); } - - gboolean trigger_found = FALSE; - char *message_lower = g_utf8_strdown(message, -1); - gsize len = 0; - gchar **triggers = g_key_file_get_string_list(prefs, PREF_GROUP_NOTIFICATIONS, "room.trigger.list", &len, NULL); - int i; - for (i = 0; i < len; i++) { - char *trigger_lower = g_utf8_strdown(triggers[i], -1); - if (g_strrstr(message_lower, trigger_lower)) { - trigger_found = TRUE; + if (notify_trigger) { + gboolean trigger_found = FALSE; + char *message_lower = g_utf8_strdown(message, -1); + gsize len = 0; + gchar **triggers = g_key_file_get_string_list(prefs, PREF_GROUP_NOTIFICATIONS, "room.trigger.list", &len, NULL); + int i; + for (i = 0; i < len; i++) { + char *trigger_lower = g_utf8_strdown(triggers[i], -1); + if (g_strrstr(message_lower, trigger_lower)) { + trigger_found = TRUE; + g_free(trigger_lower); + break; + } g_free(trigger_lower); - break; } - g_free(trigger_lower); - } - g_strfreev(triggers); - g_free(message_lower); + g_strfreev(triggers); + g_free(message_lower); - if (trigger_found) { + if (trigger_found) { + return TRUE; + } + } + + return FALSE; +} + +void +prefs_set_room_notify(const char *const roomjid, gboolean value) +{ + g_key_file_set_boolean(prefs, roomjid, "notify", value); + _save_prefs(); +} + +void +prefs_set_room_notify_mention(const char *const roomjid, gboolean value) +{ + g_key_file_set_boolean(prefs, roomjid, "notify.mention", value); + _save_prefs(); +} + +void +prefs_set_room_notify_trigger(const char *const roomjid, gboolean value) +{ + g_key_file_set_boolean(prefs, roomjid, "notify.trigger", value); + _save_prefs(); +} + +gboolean +prefs_has_room_notify(const char *const roomjid) +{ + return g_key_file_has_key(prefs, roomjid, "notify", NULL); +} + +gboolean +prefs_has_room_notify_mention(const char *const roomjid) +{ + return g_key_file_has_key(prefs, roomjid, "notify.mention", NULL); +} + +gboolean +prefs_has_room_notify_trigger(const char *const roomjid) +{ + return g_key_file_has_key(prefs, roomjid, "notify.trigger", NULL); +} + +gboolean +prefs_get_room_notify(const char *const roomjid) +{ + return g_key_file_get_boolean(prefs, roomjid, "notify", NULL); +} + +gboolean +prefs_get_room_notify_mention(const char *const roomjid) +{ + return g_key_file_get_boolean(prefs, roomjid, "notify.mention", NULL); +} + +gboolean +prefs_get_room_notify_trigger(const char *const roomjid) +{ + return g_key_file_get_boolean(prefs, roomjid, "notify.trigger", NULL); +} + +gboolean +prefs_reset_room_notify(const char *const roomjid) +{ + if (g_key_file_has_group(prefs, roomjid)) { + g_key_file_remove_group(prefs, roomjid, NULL); + _save_prefs(); return TRUE; } diff --git a/src/config/preferences.h b/src/config/preferences.h index 56c87d92..41fde88f 100644 --- a/src/config/preferences.h +++ b/src/config/preferences.h @@ -214,7 +214,18 @@ char* prefs_get_string(preference_t pref); void prefs_free_string(char *pref); void prefs_set_string(preference_t pref, char *value); -gboolean prefs_get_notify_chat(gboolean current_win, const char *const message); -gboolean prefs_get_notify_room(gboolean current_win, const char *const nick, const char *const message); +gboolean prefs_do_chat_notify(gboolean current_win, const char *const message); +gboolean prefs_do_room_notify(gboolean current_win, const char *const roomjid, const char *const nick, const char *const message); + +void prefs_set_room_notify(const char *const roomjid, gboolean value); +void prefs_set_room_notify_mention(const char *const roomjid, gboolean value); +void prefs_set_room_notify_trigger(const char *const roomjid, gboolean value); +gboolean prefs_reset_room_notify(const char *const roomjid); +gboolean prefs_has_room_notify(const char *const roomjid); +gboolean prefs_has_room_notify_mention(const char *const roomjid); +gboolean prefs_has_room_notify_trigger(const char *const roomjid); +gboolean prefs_get_room_notify(const char *const roomjid); +gboolean prefs_get_room_notify_mention(const char *const roomjid); +gboolean prefs_get_room_notify_trigger(const char *const roomjid); #endif diff --git a/src/ui/chatwin.c b/src/ui/chatwin.c index c8cee66b..84e4a40a 100644 --- a/src/ui/chatwin.c +++ b/src/ui/chatwin.c @@ -240,7 +240,7 @@ chatwin_incoming_msg(ProfChatWin *chatwin, const char *const resource, const cha char *display_name = roster_get_msg_display_name(chatwin->barejid, resource); gboolean is_current = wins_is_current(window); - gboolean notify = prefs_get_notify_chat(is_current, message); + gboolean notify = prefs_do_chat_notify(is_current, message); // currently viewing chat window with sender if (wins_is_current(window)) { diff --git a/src/ui/mucwin.c b/src/ui/mucwin.c index 82b74e1b..097e9589 100644 --- a/src/ui/mucwin.c +++ b/src/ui/mucwin.c @@ -375,7 +375,7 @@ mucwin_message(ProfMucWin *mucwin, const char *const nick, const char *const mes } gboolean is_current = wins_is_current(window); - gboolean notify = prefs_get_notify_room(is_current, my_nick, message); + gboolean notify = prefs_do_room_notify(is_current, mucwin->roomjid, my_nick, message); // currently in groupchat window if (wins_is_current(window)) { diff --git a/src/ui/privwin.c b/src/ui/privwin.c index 67bad379..06e89ce3 100644 --- a/src/ui/privwin.c +++ b/src/ui/privwin.c @@ -54,7 +54,7 @@ privwin_incoming_msg(ProfPrivateWin *privatewin, const char *const message, GDat char *display_from = get_nick_from_full_jid(privatewin->fulljid); gboolean is_current = wins_is_current(window); - gboolean notify = prefs_get_notify_chat(is_current, message); + gboolean notify = prefs_do_chat_notify(is_current, message); // currently viewing chat window with sender if (wins_is_current(window)) { From 2fc984e6735b7d76e7332e5192c1a80758015494 Mon Sep 17 00:00:00 2001 From: James Booth Date: Sat, 28 Nov 2015 23:43:02 +0000 Subject: [PATCH 09/13] Removed regular chat message triggers --- src/command/command.c | 22 +-------- src/command/commands.c | 47 ------------------- src/config/preferences.c | 99 ++-------------------------------------- src/config/preferences.h | 6 --- src/ui/console.c | 5 -- 5 files changed, 5 insertions(+), 174 deletions(-) diff --git a/src/command/command.c b/src/command/command.c index 456bfe6c..6f60b3ac 100644 --- a/src/command/command.c +++ b/src/command/command.c @@ -1063,10 +1063,6 @@ static struct cmd_t command_defs[] = "/notify message on|off", "/notify message current on|off", "/notify message text on|off", - "/notify message trigger add ", - "/notify message trigger remove ", - "/notify message trigger list", - "/notify message trigger on|off", "/notify room on|off", "/notify room mention on|off", "/notify room current on|off", @@ -1089,10 +1085,6 @@ static struct cmd_t command_defs[] = { "message on|off", "Notifications for regular chat messages." }, { "message current on|off", "Whether to show regular chat message notifications when the window is focussed." }, { "message text on|off", "Show message text in regular message notifications." }, - { "message trigger add ", "Notify when specified text included in regular chat message." }, - { "message trigger remove ", "Remove regular chat notification for specified text." }, - { "message trigger list", "List all regular chat custom text notifications." }, - { "message trigger on|off", "Enable or disable all regular chat notification triggers." }, { "room on|off", "Notifications for all chat room messages, 'mention' only notifies when your nick is mentioned." }, { "room mention on|off", "Notifications for all chat room messages when your nick is mentioned." }, { "room current on|off", "Whether to show all chat room messages notifications when the window is focussed." }, @@ -1113,6 +1105,8 @@ static struct cmd_t command_defs[] = "/notify message on", "/notify message text on", "/notify room mention on", + "/notify room trigger add beer", + "/notify room trigger on", "/notify room current off", "/notify room text off", "/notify remind 10", @@ -1958,7 +1952,6 @@ cmd_init(void) autocomplete_add(notify_message_ac, "off"); autocomplete_add(notify_message_ac, "current"); autocomplete_add(notify_message_ac, "text"); - autocomplete_add(notify_message_ac, "trigger"); notify_room_ac = autocomplete_new(); autocomplete_add(notify_room_ac, "on"); @@ -2662,7 +2655,6 @@ cmd_reset_autocomplete(ProfWin *window) } bookmark_autocomplete_reset(); - prefs_reset_message_trigger_ac(); prefs_reset_room_trigger_ac(); } @@ -3178,11 +3170,6 @@ _notify_autocomplete(ProfWin *window, const char *const input) int i = 0; char *result = NULL; - result = autocomplete_param_with_func(input, "/notify message trigger remove", prefs_autocomplete_message_trigger); - if (result) { - return result; - } - result = autocomplete_param_with_func(input, "/notify room trigger remove", prefs_autocomplete_room_trigger); if (result) { return result; @@ -3203,11 +3190,6 @@ _notify_autocomplete(ProfWin *window, const char *const input) return result; } - result = autocomplete_param_with_ac(input, "/notify message trigger", notify_trigger_ac, TRUE); - if (result) { - return result; - } - result = autocomplete_param_with_ac(input, "/notify room", notify_room_ac, TRUE); if (result) { return result; diff --git a/src/command/commands.c b/src/command/commands.c index f3c21cd4..4ac170e4 100644 --- a/src/command/commands.c +++ b/src/command/commands.c @@ -4334,53 +4334,6 @@ cmd_notify(ProfWin *window, const char *const command, gchar **args) } else { cons_show("Usage: /notify message text on|off"); } - } else if (g_strcmp0(args[1], "trigger") == 0) { - if (g_strcmp0(args[2], "add") == 0) { - if (!args[3]) { - cons_bad_cmd_usage(command); - } else { - gboolean res = prefs_add_msg_notify_trigger(args[3]); - if (res) { - cons_show("Adding message notification trigger: %s", args[3]); - } else { - cons_show("Message notification trigger already exists: %s", args[3]); - } - } - } else if (g_strcmp0(args[2], "remove") == 0) { - if (!args[3]) { - cons_bad_cmd_usage(command); - } else { - gboolean res = prefs_remove_msg_notify_trigger(args[3]); - if (res) { - cons_show("Removing message notification trigger: %s", args[3]); - } else { - cons_show("Message notification trigger does not exist: %s", args[3]); - } - } - } else if (g_strcmp0(args[2], "list") == 0) { - GList *triggers = prefs_get_msg_notify_triggers(); - GList *curr = triggers; - if (curr) { - cons_show("Message notification triggers:"); - } else { - cons_show("No message notification triggers"); - } - while (curr) { - cons_show(" %s", curr->data); - curr = g_list_next(curr); - } - g_list_free_full(triggers, free); - } else if (g_strcmp0(args[2], "on") == 0) { - cons_show("Enabling message notification triggers"); - prefs_set_boolean(PREF_NOTIFY_MESSAGE_TRIGGER, TRUE); - } else if (g_strcmp0(args[2], "off") == 0) { - cons_show("Disabling message notification triggers"); - prefs_set_boolean(PREF_NOTIFY_MESSAGE_TRIGGER, FALSE); - } else { - cons_bad_cmd_usage(command); - } - } else { - cons_show("Usage: /notify message on|off"); } // chat room settings diff --git a/src/config/preferences.c b/src/config/preferences.c index 3afead41..839ab5e6 100644 --- a/src/config/preferences.c +++ b/src/config/preferences.c @@ -65,7 +65,6 @@ static GKeyFile *prefs; gint log_maxsize = 0; static Autocomplete boolean_choice_ac; -static Autocomplete message_trigger_ac; static Autocomplete room_trigger_ac; static void _save_prefs(void); @@ -149,20 +148,11 @@ prefs_load(void) autocomplete_add(boolean_choice_ac, "on"); autocomplete_add(boolean_choice_ac, "off"); - message_trigger_ac = autocomplete_new(); - gsize len = 0; - gchar **triggers = g_key_file_get_string_list(prefs, PREF_GROUP_NOTIFICATIONS, "message.trigger.list", &len, NULL); - - int i; - for (i = 0; i < len; i++) { - autocomplete_add(message_trigger_ac, triggers[i]); - } - g_strfreev(triggers); - room_trigger_ac = autocomplete_new(); - len = 0; - triggers = g_key_file_get_string_list(prefs, PREF_GROUP_NOTIFICATIONS, "room.trigger.list", &len, NULL); + gsize len = 0; + gchar **triggers = g_key_file_get_string_list(prefs, PREF_GROUP_NOTIFICATIONS, "room.trigger.list", &len, NULL); + int i = 0; for (i = 0; i < len; i++) { autocomplete_add(room_trigger_ac, triggers[i]); } @@ -173,7 +163,6 @@ void prefs_close(void) { autocomplete_free(boolean_choice_ac); - autocomplete_free(message_trigger_ac); autocomplete_free(room_trigger_ac); g_key_file_free(prefs); prefs = NULL; @@ -191,18 +180,6 @@ prefs_reset_boolean_choice(void) autocomplete_reset(boolean_choice_ac); } -char* -prefs_autocomplete_message_trigger(const char *const prefix) -{ - return autocomplete_complete(message_trigger_ac, prefix, TRUE); -} - -void -prefs_reset_message_trigger_ac(void) -{ - autocomplete_reset(message_trigger_ac); -} - char* prefs_autocomplete_room_trigger(const char *const prefix) { @@ -232,30 +209,6 @@ prefs_do_chat_notify(gboolean current_win, const char *const message) return TRUE; } - gboolean notify_trigger = prefs_get_boolean(PREF_NOTIFY_MESSAGE_TRIGGER); - if (notify_trigger) { - gboolean trigger_found = FALSE; - char *message_lower = g_utf8_strdown(message, -1); - gsize len = 0; - gchar **triggers = g_key_file_get_string_list(prefs, PREF_GROUP_NOTIFICATIONS, "message.trigger.list", &len, NULL); - int i; - for (i = 0; i < len; i++) { - char *trigger_lower = g_utf8_strdown(triggers[i], -1); - if (g_strrstr(message_lower, trigger_lower)) { - trigger_found = TRUE; - g_free(trigger_lower); - break; - } - g_free(trigger_lower); - } - g_strfreev(triggers); - g_free(message_lower); - - if (trigger_found) { - return TRUE; - } - } - return FALSE; } @@ -853,49 +806,6 @@ prefs_set_roster_presence_indent(gint value) _save_prefs(); } -gboolean -prefs_add_msg_notify_trigger(const char * const text) -{ - gboolean res = conf_string_list_add(prefs, PREF_GROUP_NOTIFICATIONS, "message.trigger.list", text); - _save_prefs(); - - if (res) { - autocomplete_add(message_trigger_ac, text); - } - - return res; -} - -gboolean -prefs_remove_msg_notify_trigger(const char * const text) -{ - gboolean res = conf_string_list_remove(prefs, PREF_GROUP_NOTIFICATIONS, "message.trigger.list", text); - _save_prefs(); - - if (res) { - autocomplete_remove(message_trigger_ac, text); - } - - return res; -} - -GList* -prefs_get_msg_notify_triggers(void) -{ - GList *result = NULL; - gsize len = 0; - gchar **triggers = g_key_file_get_string_list(prefs, PREF_GROUP_NOTIFICATIONS, "message.trigger.list", &len, NULL); - - int i; - for (i = 0; i < len; i++) { - result = g_list_append(result, strdup(triggers[i])); - } - - g_strfreev(triggers); - - return result; -} - gboolean prefs_add_room_notify_trigger(const char * const text) { @@ -1113,7 +1023,6 @@ _get_group(preference_t pref) case PREF_NOTIFY_TYPING: case PREF_NOTIFY_TYPING_CURRENT: case PREF_NOTIFY_MESSAGE: - case PREF_NOTIFY_MESSAGE_TRIGGER: case PREF_NOTIFY_MESSAGE_CURRENT: case PREF_NOTIFY_MESSAGE_TEXT: case PREF_NOTIFY_ROOM: @@ -1207,8 +1116,6 @@ _get_key(preference_t pref) return "typing.current"; case PREF_NOTIFY_MESSAGE: return "message"; - case PREF_NOTIFY_MESSAGE_TRIGGER: - return "message.trigger"; case PREF_NOTIFY_MESSAGE_CURRENT: return "message.current"; case PREF_NOTIFY_MESSAGE_TEXT: diff --git a/src/config/preferences.h b/src/config/preferences.h index 41fde88f..6c2451a6 100644 --- a/src/config/preferences.h +++ b/src/config/preferences.h @@ -94,7 +94,6 @@ typedef enum { PREF_NOTIFY_TYPING, PREF_NOTIFY_TYPING_CURRENT, PREF_NOTIFY_MESSAGE, - PREF_NOTIFY_MESSAGE_TRIGGER, PREF_NOTIFY_MESSAGE_CURRENT, PREF_NOTIFY_MESSAGE_TEXT, PREF_NOTIFY_ROOM, @@ -140,8 +139,6 @@ void prefs_reset_login_search(void); char* prefs_autocomplete_boolean_choice(const char *const prefix); void prefs_reset_boolean_choice(void); -char* prefs_autocomplete_message_trigger(const char *const prefix); -void prefs_reset_message_trigger_ac(void); char* prefs_autocomplete_room_trigger(const char *const prefix); void prefs_reset_room_trigger_ac(void); @@ -201,11 +198,8 @@ char* prefs_get_alias(const char *const name); GList* prefs_get_aliases(void); void prefs_free_aliases(GList *aliases); -gboolean prefs_add_msg_notify_trigger(const char * const text); gboolean prefs_add_room_notify_trigger(const char * const text); -gboolean prefs_remove_msg_notify_trigger(const char * const text); gboolean prefs_remove_room_notify_trigger(const char * const text); -GList* prefs_get_msg_notify_triggers(void); GList* prefs_get_room_notify_triggers(void); gboolean prefs_get_boolean(preference_t pref); diff --git a/src/ui/console.c b/src/ui/console.c index 6081d56a..5532dfe1 100644 --- a/src/ui/console.c +++ b/src/ui/console.c @@ -1329,11 +1329,6 @@ cons_notify_setting(void) else cons_show("Messages (/notify message) : OFF"); - if (prefs_get_boolean(PREF_NOTIFY_MESSAGE_TRIGGER)) - cons_show("Messages trigger (/notify message) : ON"); - else - cons_show("Messages trigger (/notify message) : OFF"); - if (prefs_get_boolean(PREF_NOTIFY_MESSAGE_CURRENT)) cons_show("Messages current (/notify message) : ON"); else From 04ad003e111a0433373bd3b2a06c727e119b407a Mon Sep 17 00:00:00 2001 From: James Booth Date: Sat, 28 Nov 2015 23:47:08 +0000 Subject: [PATCH 10/13] Added /notify reset to autocompletion --- src/command/command.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/command/command.c b/src/command/command.c index 6f60b3ac..0b5124e4 100644 --- a/src/command/command.c +++ b/src/command/command.c @@ -1074,6 +1074,7 @@ static struct cmd_t command_defs[] = "/notify on|off", "/notify mention on|off", "/notify trigger on|off" + "/notify reset" "/notify remind ", "/notify typing on|off", "/notify typing current on|off", @@ -1946,6 +1947,7 @@ cmd_init(void) autocomplete_add(notify_ac, "off"); autocomplete_add(notify_ac, "mention"); autocomplete_add(notify_ac, "trigger"); + autocomplete_add(notify_ac, "reset"); notify_message_ac = autocomplete_new(); autocomplete_add(notify_message_ac, "on"); From 3fbee4023e763cb696027ef68d80b91ffcce94e7 Mon Sep 17 00:00:00 2001 From: James Booth Date: Sun, 29 Nov 2015 00:08:49 +0000 Subject: [PATCH 11/13] Renamed /notify message -> /notify chat --- src/command/command.c | 84 ++++++++++++----------- src/command/commands.c | 44 ++++++------ src/config/preferences.c | 20 +++--- src/config/preferences.h | 6 +- src/ui/chatwin.c | 2 +- src/ui/console.c | 141 ++++++++++++++++++++------------------- src/ui/privwin.c | 2 +- 7 files changed, 149 insertions(+), 150 deletions(-) diff --git a/src/command/command.c b/src/command/command.c index 0b5124e4..6ca09b82 100644 --- a/src/command/command.c +++ b/src/command/command.c @@ -1060,9 +1060,9 @@ static struct cmd_t command_defs[] = CMD_TAG_CHAT, CMD_TAG_GROUPCHAT) CMD_SYN( - "/notify message on|off", - "/notify message current on|off", - "/notify message text on|off", + "/notify chat on|off", + "/notify chat current on|off", + "/notify chat text on|off", "/notify room on|off", "/notify room mention on|off", "/notify room current on|off", @@ -1073,8 +1073,8 @@ static struct cmd_t command_defs[] = "/notify room trigger on|off", "/notify on|off", "/notify mention on|off", - "/notify trigger on|off" - "/notify reset" + "/notify trigger on|off", + "/notify reset", "/notify remind ", "/notify typing on|off", "/notify typing current on|off", @@ -1083,34 +1083,34 @@ static struct cmd_t command_defs[] = CMD_DESC( "Settings for various kinds of desktop notifications.") CMD_ARGS( - { "message on|off", "Notifications for regular chat messages." }, - { "message current on|off", "Whether to show regular chat message notifications when the window is focussed." }, - { "message text on|off", "Show message text in regular message notifications." }, - { "room on|off", "Notifications for all chat room messages, 'mention' only notifies when your nick is mentioned." }, - { "room mention on|off", "Notifications for all chat room messages when your nick is mentioned." }, - { "room current on|off", "Whether to show all chat room messages notifications when the window is focussed." }, - { "room text on|off", "Show message text in chat room message notifications." }, - { "room trigger add ", "Notify when specified text included in all chat room messages." }, - { "room trigger remove ", "Remove chat room notification trigger." }, - { "room trigger list", "List all chat room triggers." }, - { "room trigger on|off", "Enable or disable all chat room notification triggers." }, - { "on|off", "Notifications for the current chat room." }, - { "mention on|off", "Override the global 'mention' setting for the current chat room." }, - { "trigger on|off", "Override the global 'trigger' setting for the current chat room." }, - { "remind ", "Notification reminder period for unread messages, use 0 to disable." }, - { "typing on|off", "Notifications when contacts are typing." }, - { "typing current on|off", "Whether typing notifications are triggered for the current window." }, - { "invite on|off", "Notifications for chat room invites." }, - { "sub on|off", "Notifications for subscription requests." }) + { "chat on|off", "Notifications for regular chat messages." }, + { "chat current on|off", "Whether to show regular chat message notifications when the window is focussed." }, + { "chat text on|off", "Show message text in regular message notifications." }, + { "room on|off", "Notifications for all chat room messages, 'mention' only notifies when your nick is mentioned." }, + { "room mention on|off", "Notifications for all chat room messages when your nick is mentioned." }, + { "room current on|off", "Whether to show all chat room messages notifications when the window is focussed." }, + { "room text on|off", "Show message text in chat room message notifications." }, + { "room trigger add ", "Notify when specified text included in all chat room messages." }, + { "room trigger remove ", "Remove chat room notification trigger." }, + { "room trigger list", "List all chat room triggers." }, + { "room trigger on|off", "Enable or disable all chat room notification triggers." }, + { "on|off", "Override the global message setting for the current chat room." }, + { "mention on|off", "Override the global 'mention' setting for the current chat room." }, + { "trigger on|off", "Override the global 'trigger' setting for the current chat room." }, + { "remind ", "Notification reminder period for unread messages, use 0 to disable." }, + { "typing on|off", "Notifications when contacts are typing." }, + { "typing current on|off", "Whether typing notifications are triggered for the current window." }, + { "invite on|off", "Notifications for chat room invites." }, + { "sub on|off", "Notifications for subscription requests." }) CMD_EXAMPLES( - "/notify message on", - "/notify message text on", + "/notify chat on", + "/notify chat text on", "/notify room mention on", "/notify room trigger add beer", "/notify room trigger on", "/notify room current off", "/notify room text off", - "/notify remind 10", + "/notify remind 60", "/notify typing on", "/notify invite on") }, @@ -1807,8 +1807,8 @@ static Autocomplete who_roster_ac; static Autocomplete help_ac; static Autocomplete help_commands_ac; static Autocomplete notify_ac; +static Autocomplete notify_chat_ac; static Autocomplete notify_room_ac; -static Autocomplete notify_message_ac; static Autocomplete notify_typing_ac; static Autocomplete notify_trigger_ac; static Autocomplete prefs_ac; @@ -1937,7 +1937,7 @@ cmd_init(void) autocomplete_add(prefs_ac, "pgp"); notify_ac = autocomplete_new(); - autocomplete_add(notify_ac, "message"); + autocomplete_add(notify_ac, "chat"); autocomplete_add(notify_ac, "room"); autocomplete_add(notify_ac, "typing"); autocomplete_add(notify_ac, "remind"); @@ -1949,11 +1949,11 @@ cmd_init(void) autocomplete_add(notify_ac, "trigger"); autocomplete_add(notify_ac, "reset"); - notify_message_ac = autocomplete_new(); - autocomplete_add(notify_message_ac, "on"); - autocomplete_add(notify_message_ac, "off"); - autocomplete_add(notify_message_ac, "current"); - autocomplete_add(notify_message_ac, "text"); + notify_chat_ac = autocomplete_new(); + autocomplete_add(notify_chat_ac, "on"); + autocomplete_add(notify_chat_ac, "off"); + autocomplete_add(notify_chat_ac, "current"); + autocomplete_add(notify_chat_ac, "text"); notify_room_ac = autocomplete_new(); autocomplete_add(notify_room_ac, "on"); @@ -2368,7 +2368,7 @@ cmd_uninit(void) autocomplete_free(help_ac); autocomplete_free(help_commands_ac); autocomplete_free(notify_ac); - autocomplete_free(notify_message_ac); + autocomplete_free(notify_chat_ac); autocomplete_free(notify_room_ac); autocomplete_free(notify_typing_ac); autocomplete_free(notify_trigger_ac); @@ -2555,7 +2555,7 @@ cmd_reset_autocomplete(ProfWin *window) autocomplete_reset(help_ac); autocomplete_reset(help_commands_ac); autocomplete_reset(notify_ac); - autocomplete_reset(notify_message_ac); + autocomplete_reset(notify_chat_ac); autocomplete_reset(notify_room_ac); autocomplete_reset(notify_typing_ac); autocomplete_reset(notify_trigger_ac); @@ -3177,11 +3177,10 @@ _notify_autocomplete(ProfWin *window, const char *const input) return result; } - gchar *boolean_choices1[] = { "/notify room current", "/notify message current", "/notify typing current", - "/notify room text", "/notify room mention", "/notify message text" }; + gchar *boolean_choices1[] = { "/notify room current", "/notify chat current", "/notify typing current", + "/notify room text", "/notify room mention", "/notify chat text" }; for (i = 0; i < ARRAY_SIZE(boolean_choices1); i++) { - result = autocomplete_param_with_func(input, boolean_choices1[i], - prefs_autocomplete_boolean_choice); + result = autocomplete_param_with_func(input, boolean_choices1[i], prefs_autocomplete_boolean_choice); if (result) { return result; } @@ -3197,7 +3196,7 @@ _notify_autocomplete(ProfWin *window, const char *const input) return result; } - result = autocomplete_param_with_ac(input, "/notify message", notify_message_ac, TRUE); + result = autocomplete_param_with_ac(input, "/notify chat", notify_chat_ac, TRUE); if (result) { return result; } @@ -3209,8 +3208,7 @@ _notify_autocomplete(ProfWin *window, const char *const input) gchar *boolean_choices2[] = { "/notify invite", "/notify sub", "/notify mention", "/notify trigger"}; for (i = 0; i < ARRAY_SIZE(boolean_choices2); i++) { - result = autocomplete_param_with_func(input, boolean_choices2[i], - prefs_autocomplete_boolean_choice); + result = autocomplete_param_with_func(input, boolean_choices2[i], prefs_autocomplete_boolean_choice); if (result) { return result; } diff --git a/src/command/commands.c b/src/command/commands.c index 4ac170e4..00c96793 100644 --- a/src/command/commands.c +++ b/src/command/commands.c @@ -4280,23 +4280,23 @@ cmd_notify(ProfWin *window, const char *const command, gchar **args) win_vprintln_ch(window, '!', "Notification settings for %s", mucwin->roomjid); if (has_notify) { if (prefs_get_room_notify(mucwin->roomjid)) { - win_vprintln_ch(window, '!', " All: ON"); + win_vprintln_ch(window, '!', " Message : ON"); } else { - win_vprintln_ch(window, '!', " All: OFF"); + win_vprintln_ch(window, '!', " Message : OFF"); } } if (has_notify_mention) { if (prefs_get_room_notify_mention(mucwin->roomjid)) { - win_vprintln_ch(window, '!', " Mention: ON"); + win_vprintln_ch(window, '!', " Mention : ON"); } else { - win_vprintln_ch(window, '!', " Mention: OFF"); + win_vprintln_ch(window, '!', " Mention : OFF"); } } if (has_notify_trigger) { if (prefs_get_room_notify_trigger(mucwin->roomjid)) { - win_vprintln_ch(window, '!', " Triggers: ON"); + win_vprintln_ch(window, '!', " Triggers : ON"); } else { - win_vprintln_ch(window, '!', " Triggers: OFF"); + win_vprintln_ch(window, '!', " Triggers : OFF"); } } } @@ -4306,33 +4306,33 @@ cmd_notify(ProfWin *window, const char *const command, gchar **args) return TRUE; } - // message settings - if (strcmp(args[0], "message") == 0) { + // chat settings + if (strcmp(args[0], "chat") == 0) { if (strcmp(args[1], "on") == 0) { - cons_show("Message notifications enabled."); - prefs_set_boolean(PREF_NOTIFY_MESSAGE, TRUE); + cons_show("Chat notifications enabled."); + prefs_set_boolean(PREF_NOTIFY_CHAT, TRUE); } else if (strcmp(args[1], "off") == 0) { - cons_show("Message notifications disabled."); - prefs_set_boolean(PREF_NOTIFY_MESSAGE, FALSE); + cons_show("Chat notifications disabled."); + prefs_set_boolean(PREF_NOTIFY_CHAT, FALSE); } else if (strcmp(args[1], "current") == 0) { if (g_strcmp0(args[2], "on") == 0) { - cons_show("Current window message notifications enabled."); - prefs_set_boolean(PREF_NOTIFY_MESSAGE_CURRENT, TRUE); + cons_show("Current window chat notifications enabled."); + prefs_set_boolean(PREF_NOTIFY_CHAT_CURRENT, TRUE); } else if (g_strcmp0(args[2], "off") == 0) { - cons_show("Current window message notifications disabled."); - prefs_set_boolean(PREF_NOTIFY_MESSAGE_CURRENT, FALSE); + cons_show("Current window chat notifications disabled."); + prefs_set_boolean(PREF_NOTIFY_CHAT_CURRENT, FALSE); } else { - cons_show("Usage: /notify message current on|off"); + cons_show("Usage: /notify chat current on|off"); } } else if (strcmp(args[1], "text") == 0) { if (g_strcmp0(args[2], "on") == 0) { - cons_show("Showing text in message notifications enabled."); - prefs_set_boolean(PREF_NOTIFY_MESSAGE_TEXT, TRUE); + cons_show("Showing text in chat notifications enabled."); + prefs_set_boolean(PREF_NOTIFY_CHAT_TEXT, TRUE); } else if (g_strcmp0(args[2], "off") == 0) { - cons_show("Showing text in message notifications disabled."); - prefs_set_boolean(PREF_NOTIFY_MESSAGE_TEXT, FALSE); + cons_show("Showing text in chat notifications disabled."); + prefs_set_boolean(PREF_NOTIFY_CHAT_TEXT, FALSE); } else { - cons_show("Usage: /notify message text on|off"); + cons_show("Usage: /notify chat text on|off"); } } diff --git a/src/config/preferences.c b/src/config/preferences.c index 839ab5e6..a343f611 100644 --- a/src/config/preferences.c +++ b/src/config/preferences.c @@ -195,7 +195,7 @@ prefs_reset_room_trigger_ac(void) gboolean prefs_do_chat_notify(gboolean current_win, const char *const message) { - gboolean notify_current = prefs_get_boolean(PREF_NOTIFY_MESSAGE_CURRENT); + gboolean notify_current = prefs_get_boolean(PREF_NOTIFY_CHAT_CURRENT); gboolean notify_window = FALSE; if (!current_win || (current_win && notify_current) ) { notify_window = TRUE; @@ -204,7 +204,7 @@ prefs_do_chat_notify(gboolean current_win, const char *const message) return FALSE; } - gboolean notify_message = prefs_get_boolean(PREF_NOTIFY_MESSAGE); + gboolean notify_message = prefs_get_boolean(PREF_NOTIFY_CHAT); if (notify_message) { return TRUE; } @@ -1022,9 +1022,9 @@ _get_group(preference_t pref) return PREF_GROUP_CHATSTATES; case PREF_NOTIFY_TYPING: case PREF_NOTIFY_TYPING_CURRENT: - case PREF_NOTIFY_MESSAGE: - case PREF_NOTIFY_MESSAGE_CURRENT: - case PREF_NOTIFY_MESSAGE_TEXT: + case PREF_NOTIFY_CHAT: + case PREF_NOTIFY_CHAT_CURRENT: + case PREF_NOTIFY_CHAT_TEXT: case PREF_NOTIFY_ROOM: case PREF_NOTIFY_ROOM_MENTION: case PREF_NOTIFY_ROOM_TRIGGER: @@ -1114,11 +1114,11 @@ _get_key(preference_t pref) return "typing"; case PREF_NOTIFY_TYPING_CURRENT: return "typing.current"; - case PREF_NOTIFY_MESSAGE: + case PREF_NOTIFY_CHAT: return "message"; - case PREF_NOTIFY_MESSAGE_CURRENT: + case PREF_NOTIFY_CHAT_CURRENT: return "message.current"; - case PREF_NOTIFY_MESSAGE_TEXT: + case PREF_NOTIFY_CHAT_TEXT: return "message.text"; case PREF_NOTIFY_ROOM: return "room"; @@ -1236,8 +1236,8 @@ _get_default_boolean(preference_t pref) case PREF_AUTOAWAY_CHECK: case PREF_LOG_ROTATE: case PREF_LOG_SHARED: - case PREF_NOTIFY_MESSAGE: - case PREF_NOTIFY_MESSAGE_CURRENT: + case PREF_NOTIFY_CHAT: + case PREF_NOTIFY_CHAT_CURRENT: case PREF_NOTIFY_ROOM: case PREF_NOTIFY_ROOM_CURRENT: case PREF_NOTIFY_TYPING: diff --git a/src/config/preferences.h b/src/config/preferences.h index 6c2451a6..b2411906 100644 --- a/src/config/preferences.h +++ b/src/config/preferences.h @@ -93,9 +93,9 @@ typedef enum { PREF_OUTTYPE, PREF_NOTIFY_TYPING, PREF_NOTIFY_TYPING_CURRENT, - PREF_NOTIFY_MESSAGE, - PREF_NOTIFY_MESSAGE_CURRENT, - PREF_NOTIFY_MESSAGE_TEXT, + PREF_NOTIFY_CHAT, + PREF_NOTIFY_CHAT_CURRENT, + PREF_NOTIFY_CHAT_TEXT, PREF_NOTIFY_ROOM, PREF_NOTIFY_ROOM_MENTION, PREF_NOTIFY_ROOM_TRIGGER, diff --git a/src/ui/chatwin.c b/src/ui/chatwin.c index 84e4a40a..2875256d 100644 --- a/src/ui/chatwin.c +++ b/src/ui/chatwin.c @@ -290,7 +290,7 @@ chatwin_incoming_msg(ProfChatWin *chatwin, const char *const resource, const cha ui_index = 0; } - if (prefs_get_boolean(PREF_NOTIFY_MESSAGE_TEXT)) { + if (prefs_get_boolean(PREF_NOTIFY_CHAT_TEXT)) { notify_message(display_name, ui_index, message); } else { notify_message(display_name, ui_index, NULL); diff --git a/src/ui/console.c b/src/ui/console.c index 5532dfe1..775fa671 100644 --- a/src/ui/console.c +++ b/src/ui/console.c @@ -1323,77 +1323,78 @@ cons_show_ui_prefs(void) void cons_notify_setting(void) { - if (is_notify_enabled()) { - if (prefs_get_boolean(PREF_NOTIFY_MESSAGE)) - cons_show("Messages (/notify message) : ON"); - else - cons_show("Messages (/notify message) : OFF"); - - if (prefs_get_boolean(PREF_NOTIFY_MESSAGE_CURRENT)) - cons_show("Messages current (/notify message) : ON"); - else - cons_show("Messages current (/notify message) : OFF"); - - if (prefs_get_boolean(PREF_NOTIFY_MESSAGE_TEXT)) - cons_show("Messages text (/notify message) : ON"); - else - cons_show("Messages text (/notify message) : OFF"); - - if (prefs_get_boolean(PREF_NOTIFY_ROOM)) - cons_show("Room messages (/notify room) : ON"); - else - cons_show("Room messages (/notify room) : OFF"); - - if (prefs_get_boolean(PREF_NOTIFY_ROOM_MENTION)) - cons_show("Room mention (/notify room) : ON"); - else - cons_show("Room mention (/notify room) : OFF"); - - if (prefs_get_boolean(PREF_NOTIFY_ROOM_TRIGGER)) - cons_show("Room trigger (/notify room) : ON"); - else - cons_show("Room trigger (/notify room) : OFF"); - - if (prefs_get_boolean(PREF_NOTIFY_ROOM_CURRENT)) - cons_show("Room current (/notify room) : ON"); - else - cons_show("Room current (/notify room) : OFF"); - - if (prefs_get_boolean(PREF_NOTIFY_ROOM_TEXT)) - cons_show("Room text (/notify room) : ON"); - else - cons_show("Room text (/notify room) : OFF"); - - if (prefs_get_boolean(PREF_NOTIFY_TYPING)) - cons_show("Composing (/notify typing) : ON"); - else - cons_show("Composing (/notify typing) : OFF"); - - if (prefs_get_boolean(PREF_NOTIFY_TYPING_CURRENT)) - cons_show("Composing current (/notify typing) : ON"); - else - cons_show("Composing current (/notify typing) : OFF"); - - if (prefs_get_boolean(PREF_NOTIFY_INVITE)) - cons_show("Room invites (/notify invite) : ON"); - else - cons_show("Room invites (/notify invite) : OFF"); - - if (prefs_get_boolean(PREF_NOTIFY_SUB)) - cons_show("Subscription requests (/notify sub) : ON"); - else - cons_show("Subscription requests (/notify sub) : OFF"); - - gint remind_period = prefs_get_notify_remind(); - if (remind_period == 0) { - cons_show("Reminder period (/notify remind) : OFF"); - } else if (remind_period == 1) { - cons_show("Reminder period (/notify remind) : 1 second"); - } else { - cons_show("Reminder period (/notify remind) : %d seconds", remind_period); - } - } else { + if (!is_notify_enabled()) { cons_show("Notification support was not included in this build."); + return; + } + + if (prefs_get_boolean(PREF_NOTIFY_CHAT)) + cons_show("Chat message (/notify chat) : ON"); + else + cons_show("Chat message (/notify chat) : OFF"); + + if (prefs_get_boolean(PREF_NOTIFY_CHAT_CURRENT)) + cons_show("Chat current (/notify chat) : ON"); + else + cons_show("Chat current (/notify chat) : OFF"); + + if (prefs_get_boolean(PREF_NOTIFY_CHAT_TEXT)) + cons_show("Chat text (/notify chat) : ON"); + else + cons_show("Chat text (/notify chat) : OFF"); + + if (prefs_get_boolean(PREF_NOTIFY_ROOM)) + cons_show("Room message (/notify room) : ON"); + else + cons_show("Room message (/notify room) : OFF"); + + if (prefs_get_boolean(PREF_NOTIFY_ROOM_MENTION)) + cons_show("Room mention (/notify room) : ON"); + else + cons_show("Room mention (/notify room) : OFF"); + + if (prefs_get_boolean(PREF_NOTIFY_ROOM_TRIGGER)) + cons_show("Room trigger (/notify room) : ON"); + else + cons_show("Room trigger (/notify room) : OFF"); + + if (prefs_get_boolean(PREF_NOTIFY_ROOM_CURRENT)) + cons_show("Room current (/notify room) : ON"); + else + cons_show("Room current (/notify room) : OFF"); + + if (prefs_get_boolean(PREF_NOTIFY_ROOM_TEXT)) + cons_show("Room text (/notify room) : ON"); + else + cons_show("Room text (/notify room) : OFF"); + + if (prefs_get_boolean(PREF_NOTIFY_TYPING)) + cons_show("Composing (/notify typing) : ON"); + else + cons_show("Composing (/notify typing) : OFF"); + + if (prefs_get_boolean(PREF_NOTIFY_TYPING_CURRENT)) + cons_show("Composing current (/notify typing) : ON"); + else + cons_show("Composing current (/notify typing) : OFF"); + + if (prefs_get_boolean(PREF_NOTIFY_INVITE)) + cons_show("Room invites (/notify invite) : ON"); + else + cons_show("Room invites (/notify invite) : OFF"); + + if (prefs_get_boolean(PREF_NOTIFY_SUB)) + cons_show("Subscription requests (/notify sub) : ON"); + else + cons_show("Subscription requests (/notify sub) : OFF"); + + gint remind_period = prefs_get_notify_remind(); + if (remind_period == 0) { + cons_show("Reminder period (/notify remind) : OFF"); + } else if (remind_period == 1) { + cons_show("Reminder period (/notify remind) : 1 second"); + } else { + cons_show("Reminder period (/notify remind) : %d seconds", remind_period); } } diff --git a/src/ui/privwin.c b/src/ui/privwin.c index 06e89ce3..204335bd 100644 --- a/src/ui/privwin.c +++ b/src/ui/privwin.c @@ -91,7 +91,7 @@ privwin_incoming_msg(ProfPrivateWin *privatewin, const char *const message, GDat ui_index = 0; } - if (prefs_get_boolean(PREF_NOTIFY_MESSAGE_TEXT)) { + if (prefs_get_boolean(PREF_NOTIFY_CHAT_TEXT)) { notify_message(display_from, ui_index, message); } else { notify_message(display_from, ui_index, NULL); From cadaf73148d5aad7f9372c6e750c45e51a5f2161 Mon Sep 17 00:00:00 2001 From: James Booth Date: Sun, 29 Nov 2015 00:16:00 +0000 Subject: [PATCH 12/13] Fixed functional tests --- tests/functionaltests/proftest.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/functionaltests/proftest.c b/tests/functionaltests/proftest.c index e3c80501..15848856 100644 --- a/tests/functionaltests/proftest.c +++ b/tests/functionaltests/proftest.c @@ -166,8 +166,8 @@ init_prof_test(void **state) assert_true(prof_output_exact("Input blocking set to 5 milliseconds")); prof_input("/inpblock dynamic off"); assert_true(prof_output_exact("Dynamic input blocking disabled")); - prof_input("/notify message off"); - assert_true(prof_output_exact("Message notifications disabled")); + prof_input("/notify chat off"); + assert_true(prof_output_exact("Chat notifications disabled")); prof_input("/wrap off"); assert_true(prof_output_exact("Word wrap disabled")); prof_input("/roster hide"); From b4046638471be84bab462f3af5987db5f4ffe9c8 Mon Sep 17 00:00:00 2001 From: James Booth Date: Sun, 29 Nov 2015 00:34:53 +0000 Subject: [PATCH 13/13] Tidied output for /notify command --- src/command/commands.c | 134 +++++++++++++++++++++++------------------ 1 file changed, 77 insertions(+), 57 deletions(-) diff --git a/src/command/commands.c b/src/command/commands.c index 00c96793..042fbb1c 100644 --- a/src/command/commands.c +++ b/src/command/commands.c @@ -4269,52 +4269,68 @@ cmd_notify(ProfWin *window, const char *const command, gchar **args) if (!args[0]) { ProfWin *current = wins_get_current(); if (current->type == WIN_MUC) { + win_println(current, 0, ""); ProfMucWin *mucwin = (ProfMucWin *)current; - gboolean has_notify = prefs_has_room_notify(mucwin->roomjid); - gboolean has_notify_mention = prefs_has_room_notify_mention(mucwin->roomjid); - gboolean has_notify_trigger = prefs_has_room_notify_trigger(mucwin->roomjid); - if (!has_notify && !has_notify_mention && !has_notify_trigger) { - win_vprintln_ch(window, '!', "No notification settings for %s", mucwin->roomjid); + win_vprintln_ch(window, '!', "Notification settings for %s:", mucwin->roomjid); + if (prefs_has_room_notify(mucwin->roomjid)) { + if (prefs_get_room_notify(mucwin->roomjid)) { + win_vprintln_ch(window, '!', " Message : ON"); + } else { + win_vprintln_ch(window, '!', " Message : OFF"); + } } else { - win_vprintln_ch(window, '!', "Notification settings for %s", mucwin->roomjid); - if (has_notify) { - if (prefs_get_room_notify(mucwin->roomjid)) { - win_vprintln_ch(window, '!', " Message : ON"); - } else { - win_vprintln_ch(window, '!', " Message : OFF"); - } - } - if (has_notify_mention) { - if (prefs_get_room_notify_mention(mucwin->roomjid)) { - win_vprintln_ch(window, '!', " Mention : ON"); - } else { - win_vprintln_ch(window, '!', " Mention : OFF"); - } - } - if (has_notify_trigger) { - if (prefs_get_room_notify_trigger(mucwin->roomjid)) { - win_vprintln_ch(window, '!', " Triggers : ON"); - } else { - win_vprintln_ch(window, '!', " Triggers : OFF"); - } + if (prefs_get_boolean(PREF_NOTIFY_ROOM)) { + win_vprintln_ch(window, '!', " Message : ON (global setting)"); + } else { + win_vprintln_ch(window, '!', " Message : OFF (global setting)"); } } + if (prefs_has_room_notify_mention(mucwin->roomjid)) { + if (prefs_get_room_notify_mention(mucwin->roomjid)) { + win_vprintln_ch(window, '!', " Mention : ON"); + } else { + win_vprintln_ch(window, '!', " Mention : OFF"); + } + } else { + if (prefs_get_boolean(PREF_NOTIFY_ROOM_MENTION)) { + win_vprintln_ch(window, '!', " Mention : ON (global setting)"); + } else { + win_vprintln_ch(window, '!', " Mention : OFF (global setting)"); + } + } + if (prefs_has_room_notify_trigger(mucwin->roomjid)) { + if (prefs_get_room_notify_trigger(mucwin->roomjid)) { + win_vprintln_ch(window, '!', " Triggers : ON"); + } else { + win_vprintln_ch(window, '!', " Triggers : OFF"); + } + } else { + if (prefs_get_boolean(PREF_NOTIFY_ROOM_TRIGGER)) { + win_vprintln_ch(window, '!', " Triggers : ON (global setting)"); + } else { + win_vprintln_ch(window, '!', " Triggers : OFF (global setting)"); + } + } + win_println(current, 0, ""); } else { + cons_show(""); cons_notify_setting(); + cons_bad_cmd_usage(command); + } return TRUE; } // chat settings - if (strcmp(args[0], "chat") == 0) { - if (strcmp(args[1], "on") == 0) { + if (g_strcmp0(args[0], "chat") == 0) { + if (g_strcmp0(args[1], "on") == 0) { cons_show("Chat notifications enabled."); prefs_set_boolean(PREF_NOTIFY_CHAT, TRUE); - } else if (strcmp(args[1], "off") == 0) { + } else if (g_strcmp0(args[1], "off") == 0) { cons_show("Chat notifications disabled."); prefs_set_boolean(PREF_NOTIFY_CHAT, FALSE); - } else if (strcmp(args[1], "current") == 0) { + } else if (g_strcmp0(args[1], "current") == 0) { if (g_strcmp0(args[2], "on") == 0) { cons_show("Current window chat notifications enabled."); prefs_set_boolean(PREF_NOTIFY_CHAT_CURRENT, TRUE); @@ -4324,7 +4340,7 @@ cmd_notify(ProfWin *window, const char *const command, gchar **args) } else { cons_show("Usage: /notify chat current on|off"); } - } else if (strcmp(args[1], "text") == 0) { + } else if (g_strcmp0(args[1], "text") == 0) { if (g_strcmp0(args[2], "on") == 0) { cons_show("Showing text in chat notifications enabled."); prefs_set_boolean(PREF_NOTIFY_CHAT_TEXT, TRUE); @@ -4337,24 +4353,24 @@ cmd_notify(ProfWin *window, const char *const command, gchar **args) } // chat room settings - } else if (strcmp(args[0], "room") == 0) { - if (strcmp(args[1], "on") == 0) { + } else if (g_strcmp0(args[0], "room") == 0) { + if (g_strcmp0(args[1], "on") == 0) { cons_show("Room notifications enabled."); prefs_set_boolean(PREF_NOTIFY_ROOM, TRUE); - } else if (strcmp(args[1], "off") == 0) { + } else if (g_strcmp0(args[1], "off") == 0) { cons_show("Room notifications disabled."); prefs_set_boolean(PREF_NOTIFY_ROOM, FALSE); - } else if (strcmp(args[1], "mention") == 0) { - if (strcmp(args[2], "on") == 0) { + } else if (g_strcmp0(args[1], "mention") == 0) { + if (g_strcmp0(args[2], "on") == 0) { cons_show("Room notifications with mention enabled."); prefs_set_boolean(PREF_NOTIFY_ROOM_MENTION, TRUE); - } else if (strcmp(args[2], "off") == 0) { + } else if (g_strcmp0(args[2], "off") == 0) { cons_show("Room notifications with mention disabled."); prefs_set_boolean(PREF_NOTIFY_ROOM_MENTION, FALSE); } else { cons_show("Usage: /notify room mention on|off"); } - } else if (strcmp(args[1], "current") == 0) { + } else if (g_strcmp0(args[1], "current") == 0) { if (g_strcmp0(args[2], "on") == 0) { cons_show("Current window chat room message notifications enabled."); prefs_set_boolean(PREF_NOTIFY_ROOM_CURRENT, TRUE); @@ -4364,7 +4380,7 @@ cmd_notify(ProfWin *window, const char *const command, gchar **args) } else { cons_show("Usage: /notify room current on|off"); } - } else if (strcmp(args[1], "text") == 0) { + } else if (g_strcmp0(args[1], "text") == 0) { if (g_strcmp0(args[2], "on") == 0) { cons_show("Showing text in chat room message notifications enabled."); prefs_set_boolean(PREF_NOTIFY_ROOM_TEXT, TRUE); @@ -4424,14 +4440,14 @@ cmd_notify(ProfWin *window, const char *const command, gchar **args) } // typing settings - } else if (strcmp(args[0], "typing") == 0) { - if (strcmp(args[1], "on") == 0) { + } else if (g_strcmp0(args[0], "typing") == 0) { + if (g_strcmp0(args[1], "on") == 0) { cons_show("Typing notifications enabled."); prefs_set_boolean(PREF_NOTIFY_TYPING, TRUE); - } else if (strcmp(args[1], "off") == 0) { + } else if (g_strcmp0(args[1], "off") == 0) { cons_show("Typing notifications disabled."); prefs_set_boolean(PREF_NOTIFY_TYPING, FALSE); - } else if (strcmp(args[1], "current") == 0) { + } else if (g_strcmp0(args[1], "current") == 0) { if (g_strcmp0(args[2], "on") == 0) { cons_show("Current window typing notifications enabled."); prefs_set_boolean(PREF_NOTIFY_TYPING_CURRENT, TRUE); @@ -4446,11 +4462,11 @@ cmd_notify(ProfWin *window, const char *const command, gchar **args) } // invite settings - } else if (strcmp(args[0], "invite") == 0) { - if (strcmp(args[1], "on") == 0) { + } else if (g_strcmp0(args[0], "invite") == 0) { + if (g_strcmp0(args[1], "on") == 0) { cons_show("Chat room invite notifications enabled."); prefs_set_boolean(PREF_NOTIFY_INVITE, TRUE); - } else if (strcmp(args[1], "off") == 0) { + } else if (g_strcmp0(args[1], "off") == 0) { cons_show("Chat room invite notifications disabled."); prefs_set_boolean(PREF_NOTIFY_INVITE, FALSE); } else { @@ -4458,11 +4474,11 @@ cmd_notify(ProfWin *window, const char *const command, gchar **args) } // subscription settings - } else if (strcmp(args[0], "sub") == 0) { - if (strcmp(args[1], "on") == 0) { + } else if (g_strcmp0(args[0], "sub") == 0) { + if (g_strcmp0(args[1], "on") == 0) { cons_show("Subscription notifications enabled."); prefs_set_boolean(PREF_NOTIFY_SUB, TRUE); - } else if (strcmp(args[1], "off") == 0) { + } else if (g_strcmp0(args[1], "off") == 0) { cons_show("Subscription notifications disabled."); prefs_set_boolean(PREF_NOTIFY_SUB, FALSE); } else { @@ -4470,15 +4486,19 @@ cmd_notify(ProfWin *window, const char *const command, gchar **args) } // remind settings - } else if (strcmp(args[0], "remind") == 0) { - gint period = atoi(args[1]); - prefs_set_notify_remind(period); - if (period == 0) { - cons_show("Message reminders disabled."); - } else if (period == 1) { - cons_show("Message reminder period set to 1 second."); + } else if (g_strcmp0(args[0], "remind") == 0) { + if (!args[1]) { + cons_bad_cmd_usage(command); } else { - cons_show("Message reminder period set to %d seconds.", period); + gint period = atoi(args[1]); + prefs_set_notify_remind(period); + if (period == 0) { + cons_show("Message reminders disabled."); + } else if (period == 1) { + cons_show("Message reminder period set to 1 second."); + } else { + cons_show("Message reminder period set to %d seconds.", period); + } } // current chat room settings