diff options
author | James Booth <boothj5@gmail.com> | 2014-05-24 20:46:03 +0100 |
---|---|---|
committer | James Booth <boothj5@gmail.com> | 2014-05-24 20:46:03 +0100 |
commit | eb0f0dd96b368424a1f2344d23c67c1e8934aae4 (patch) | |
tree | 64bb48f605fc9b0e67e05470246e3d0403f2fe9a /src | |
parent | 8e14946aada9708c2c20c6e512ee7b0cf5767689 (diff) | |
download | profani-tty-eb0f0dd96b368424a1f2344d23c67c1e8934aae4.tar.gz |
Added settings for message notifications in current window
Diffstat (limited to 'src')
-rw-r--r-- | src/command/command.c | 50 | ||||
-rw-r--r-- | src/command/commands.c | 45 | ||||
-rw-r--r-- | src/config/preferences.c | 8 | ||||
-rw-r--r-- | src/config/preferences.h | 2 | ||||
-rw-r--r-- | src/ui/console.c | 12 | ||||
-rw-r--r-- | src/ui/core.c | 21 |
6 files changed, 107 insertions, 31 deletions
diff --git a/src/command/command.c b/src/command/command.c index e264f0a1..ee5635a6 100644 --- a/src/command/command.c +++ b/src/command/command.c @@ -469,14 +469,18 @@ static struct cmd_t command_defs[] = { "/notify", cmd_notify, parse_args, 2, 3, &cons_notify_setting, - { "/notify [type value]", "Control various desktop noficiations.", - { "/notify [type value]", - "--------------------", + { "/notify [type value]|[type setting value]", "Control various desktop noficiations.", + { "/notify [type value]|[type setting value]", + "-----------------------------------------", "Settings for various desktop notifications where type is one of:", "message : Notificaitons for regular messages.", " : on|off", + "message current : Whether messages in the current window trigger notifications.", + " : on|off", "room : Notificaitons for chat room messages.", " : on|off|mention", + "room current : Whether chat room messages in the current window trigger notifications.", + " : on|off", "remind : Notification reminders of unread messages.", " : where value is the reminder period in seconds,", " : use 0 to disable.", @@ -487,12 +491,13 @@ static struct cmd_t command_defs[] = "sub : Notifications for subscription requests.", " : on|off", "", - "Example : /notify message on (enable message notifications)", - "Example : /notify room mention (enable chat room notifications only on mention)", - "Example : /notify remind 10 (remind every 10 seconds)", - "Example : /notify remind 0 (switch off reminders)", - "Example : /notify typing on (enable typing notifications)", - "Example : /notify invite on (enable chat room invite notifications)", + "Example : /notify message on (enable message notifications)", + "Example : /notify room mention (enable chat room notifications only on mention)", + "Example : /notify room current off (disable room message notifications when window visible)", + "Example : /notify remind 10 (remind every 10 seconds)", + "Example : /notify remind 0 (switch off reminders)", + "Example : /notify typing on (enable typing notifications)", + "Example : /notify invite on (enable chat room invite notifications)", NULL } } }, { "/flash", @@ -878,6 +883,7 @@ static Autocomplete who_ac; static Autocomplete help_ac; static Autocomplete notify_ac; static Autocomplete notify_room_ac; +static Autocomplete notify_message_ac; static Autocomplete prefs_ac; static Autocomplete sub_ac; static Autocomplete log_ac; @@ -974,10 +980,16 @@ cmd_init(void) autocomplete_add(notify_ac, "invite"); autocomplete_add(notify_ac, "sub"); + notify_message_ac = autocomplete_new(); + autocomplete_add(notify_message_ac, "on"); + autocomplete_add(notify_message_ac, "off"); + autocomplete_add(notify_message_ac, "current"); + notify_room_ac = autocomplete_new(); autocomplete_add(notify_room_ac, "on"); autocomplete_add(notify_room_ac, "off"); autocomplete_add(notify_room_ac, "mention"); + autocomplete_add(notify_room_ac, "current"); sub_ac = autocomplete_new(); autocomplete_add(sub_ac, "request"); @@ -1153,6 +1165,7 @@ cmd_uninit(void) autocomplete_free(who_ac); autocomplete_free(help_ac); autocomplete_free(notify_ac); + autocomplete_free(notify_message_ac); autocomplete_free(notify_room_ac); autocomplete_free(sub_ac); autocomplete_free(titlebar_ac); @@ -1266,6 +1279,7 @@ cmd_reset_autocomplete() presence_reset_sub_request_search(); autocomplete_reset(help_ac); autocomplete_reset(notify_ac); + autocomplete_reset(notify_message_ac); autocomplete_reset(notify_room_ac); autocomplete_reset(sub_ac); @@ -1782,13 +1796,27 @@ _notify_autocomplete(char *input, int *size) int i = 0; char *result = NULL; + result = autocomplete_param_with_func(input, size, "/notify room current", prefs_autocomplete_boolean_choice); + if (result != NULL) { + return result; + } + + result = autocomplete_param_with_func(input, size, "/notify message current", prefs_autocomplete_boolean_choice); + if (result != NULL) { + return result; + } + result = autocomplete_param_with_ac(input, size, "/notify room", notify_room_ac); if (result != NULL) { return result; } - gchar *boolean_choices[] = { "/notify message", "/notify typing", - "/notify invite", "/notify sub" }; + result = autocomplete_param_with_ac(input, size, "/notify message", notify_message_ac); + if (result != NULL) { + return result; + } + + gchar *boolean_choices[] = { "/notify typing", "/notify invite", "/notify sub" }; for (i = 0; i < ARRAY_SIZE(boolean_choices); i++) { result = autocomplete_param_with_func(input, size, boolean_choices[i], prefs_autocomplete_boolean_choice); diff --git a/src/command/commands.c b/src/command/commands.c index dcfc8a1e..e81c4e66 100644 --- a/src/command/commands.c +++ b/src/command/commands.c @@ -2195,7 +2195,6 @@ gboolean cmd_notify(gchar **args, struct cmd_help_t help) { char *kind = args[0]; - char *value = args[1]; // bad kind if ((strcmp(kind, "message") != 0) && (strcmp(kind, "typing") != 0) && @@ -2205,37 +2204,57 @@ cmd_notify(gchar **args, struct cmd_help_t help) // set message setting } else if (strcmp(kind, "message") == 0) { - if (strcmp(value, "on") == 0) { + if (strcmp(args[1], "on") == 0) { cons_show("Message notifications enabled."); prefs_set_boolean(PREF_NOTIFY_MESSAGE, TRUE); - } else if (strcmp(value, "off") == 0) { + } else if (strcmp(args[1], "off") == 0) { cons_show("Message notifications disabled."); prefs_set_boolean(PREF_NOTIFY_MESSAGE, FALSE); + } else if (strcmp(args[1], "current") == 0) { + if (g_strcmp0(args[2], "on") == 0) { + cons_show("Current window messages notifications enabled."); + prefs_set_boolean(PREF_NOTIFY_MESSAGE_CURRENT, TRUE); + } else if (g_strcmp0(args[2], "off") == 0) { + cons_show("Current window messages notifications disabled."); + prefs_set_boolean(PREF_NOTIFY_MESSAGE_CURRENT, FALSE); + } else { + cons_show("Usage: /notify message current on|off"); + } } else { cons_show("Usage: /notify message on|off"); } // set room setting } else if (strcmp(kind, "room") == 0) { - if (strcmp(value, "on") == 0) { + if (strcmp(args[1], "on") == 0) { cons_show("Chat room notifications enabled."); prefs_set_string(PREF_NOTIFY_ROOM, "on"); - } else if (strcmp(value, "off") == 0) { + } else if (strcmp(args[1], "off") == 0) { cons_show("Chat room notifications disabled."); prefs_set_string(PREF_NOTIFY_ROOM, "off"); - } else if (strcmp(value, "mention") == 0) { + } else if (strcmp(args[1], "mention") == 0) { cons_show("Chat room notifications enable on mention."); prefs_set_string(PREF_NOTIFY_ROOM, "mention"); + } else if (strcmp(args[1], "current") == 0) { + if (g_strcmp0(args[2], "on") == 0) { + cons_show("Current window chat room messages notifications enabled."); + prefs_set_boolean(PREF_NOTIFY_ROOM_CURRENT, TRUE); + } else if (g_strcmp0(args[2], "off") == 0) { + cons_show("Current window chat room messages notifications disabled."); + prefs_set_boolean(PREF_NOTIFY_ROOM_CURRENT, FALSE); + } else { + cons_show("Usage: /notify room current on|off"); + } } else { cons_show("Usage: /notify room on|off|mention"); } // set typing setting } else if (strcmp(kind, "typing") == 0) { - if (strcmp(value, "on") == 0) { + if (strcmp(args[1], "on") == 0) { cons_show("Typing notifications enabled."); prefs_set_boolean(PREF_NOTIFY_TYPING, TRUE); - } else if (strcmp(value, "off") == 0) { + } else if (strcmp(args[1], "off") == 0) { cons_show("Typing notifications disabled."); prefs_set_boolean(PREF_NOTIFY_TYPING, FALSE); } else { @@ -2244,10 +2263,10 @@ cmd_notify(gchar **args, struct cmd_help_t help) // set invite setting } else if (strcmp(kind, "invite") == 0) { - if (strcmp(value, "on") == 0) { + if (strcmp(args[1], "on") == 0) { cons_show("Chat room invite notifications enabled."); prefs_set_boolean(PREF_NOTIFY_INVITE, TRUE); - } else if (strcmp(value, "off") == 0) { + } else if (strcmp(args[1], "off") == 0) { cons_show("Chat room invite notifications disabled."); prefs_set_boolean(PREF_NOTIFY_INVITE, FALSE); } else { @@ -2256,10 +2275,10 @@ cmd_notify(gchar **args, struct cmd_help_t help) // set subscription setting } else if (strcmp(kind, "sub") == 0) { - if (strcmp(value, "on") == 0) { + if (strcmp(args[1], "on") == 0) { cons_show("Subscription notifications enabled."); prefs_set_boolean(PREF_NOTIFY_SUB, TRUE); - } else if (strcmp(value, "off") == 0) { + } else if (strcmp(args[1], "off") == 0) { cons_show("Subscription notifications disabled."); prefs_set_boolean(PREF_NOTIFY_SUB, FALSE); } else { @@ -2268,7 +2287,7 @@ cmd_notify(gchar **args, struct cmd_help_t help) // set remind setting } else if (strcmp(kind, "remind") == 0) { - gint period = atoi(value); + gint period = atoi(args[1]); prefs_set_notify_remind(period); if (period == 0) { cons_show("Message reminders disabled."); diff --git a/src/config/preferences.c b/src/config/preferences.c index 900a68af..eb32d558 100644 --- a/src/config/preferences.c +++ b/src/config/preferences.c @@ -401,7 +401,9 @@ _get_group(preference_t pref) return PREF_GROUP_CHATSTATES; case PREF_NOTIFY_TYPING: case PREF_NOTIFY_MESSAGE: + case PREF_NOTIFY_MESSAGE_CURRENT: case PREF_NOTIFY_ROOM: + case PREF_NOTIFY_ROOM_CURRENT: case PREF_NOTIFY_INVITE: case PREF_NOTIFY_SUB: return PREF_GROUP_NOTIFICATIONS; @@ -464,8 +466,12 @@ _get_key(preference_t pref) return "typing"; case PREF_NOTIFY_MESSAGE: return "message"; + case PREF_NOTIFY_MESSAGE_CURRENT: + return "message.current"; case PREF_NOTIFY_ROOM: return "room"; + case PREF_NOTIFY_ROOM_CURRENT: + return "room.current"; case PREF_NOTIFY_INVITE: return "invite"; case PREF_NOTIFY_SUB: @@ -507,6 +513,8 @@ _get_default_boolean(preference_t pref) case PREF_AUTOAWAY_CHECK: case PREF_LOG_ROTATE: case PREF_LOG_SHARED: + case PREF_NOTIFY_MESSAGE_CURRENT: + case PREF_NOTIFY_ROOM_CURRENT: return TRUE; default: return FALSE; diff --git a/src/config/preferences.h b/src/config/preferences.h index e5d54d8a..75a4c576 100644 --- a/src/config/preferences.h +++ b/src/config/preferences.h @@ -53,7 +53,9 @@ typedef enum { PREF_OUTTYPE, PREF_NOTIFY_TYPING, PREF_NOTIFY_MESSAGE, + PREF_NOTIFY_MESSAGE_CURRENT, PREF_NOTIFY_ROOM, + PREF_NOTIFY_ROOM_CURRENT, PREF_NOTIFY_INVITE, PREF_NOTIFY_SUB, PREF_CHLOG, diff --git a/src/ui/console.c b/src/ui/console.c index 16a12e35..1afd0a49 100644 --- a/src/ui/console.c +++ b/src/ui/console.c @@ -1163,8 +1163,18 @@ _cons_notify_setting(void) 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"); + char *room_setting = prefs_get_string(PREF_NOTIFY_ROOM); - cons_show ("Chat room messages (/notify room) : %s", room_setting); + cons_show ("Room messages (/notify room) : %s", room_setting); + + 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_TYPING)) cons_show("Composing (/notify typing) : ON"); diff --git a/src/ui/core.c b/src/ui/core.c index c5e17803..8f554f5b 100644 --- a/src/ui/core.c +++ b/src/ui/core.c @@ -370,8 +370,12 @@ _ui_incoming_msg(const char * const from, const char * const message, if (prefs_get_boolean(PREF_BEEP)) beep(); - if (prefs_get_boolean(PREF_NOTIFY_MESSAGE)) - notify_message(display_from, ui_index); + if (prefs_get_boolean(PREF_NOTIFY_MESSAGE)) { + gboolean is_current = wins_is_current(window); + if ( !is_current || (is_current && prefs_get_boolean(PREF_NOTIFY_MESSAGE_CURRENT)) ) { + notify_message(display_from, ui_index); + } + } free(display_from); @@ -1696,8 +1700,9 @@ _ui_room_message(const char * const room_jid, const char * const nick, if (prefs_get_boolean(PREF_BEEP)) { beep(); } - char *room_setting = prefs_get_string(PREF_NOTIFY_ROOM); + gboolean notify = FALSE; + char *room_setting = prefs_get_string(PREF_NOTIFY_ROOM); if (g_strcmp0(room_setting, "on") == 0) { notify = TRUE; } @@ -1710,10 +1715,14 @@ _ui_room_message(const char * const room_jid, const char * const nick, g_free(message_lower); g_free(nick_lower); } + if (notify) { - Jid *jidp = jid_create(room_jid); - notify_room_message(nick, jidp->localpart, ui_index); - jid_destroy(jidp); + gboolean is_current = wins_is_current(window); + if ( !is_current || (is_current && prefs_get_boolean(PREF_NOTIFY_ROOM_CURRENT)) ) { + Jid *jidp = jid_create(room_jid); + notify_room_message(nick, jidp->localpart, ui_index); + jid_destroy(jidp); + } } } |