about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorJames Booth <boothj5@gmail.com>2015-11-25 21:24:21 +0000
committerJames Booth <boothj5@gmail.com>2015-11-25 21:24:21 +0000
commit20e63e364b45894d481a35e019602183255e3496 (patch)
treef1b2c069d797f5749e5f22c512f369573e182650
parentb9794361f7eb59052b8662284ca11b18bb3187dc (diff)
downloadprofani-tty-20e63e364b45894d481a35e019602183255e3496.tar.gz
Finished basic /notify triggers
-rw-r--r--src/command/command.c13
-rw-r--r--src/command/commands.c19
-rw-r--r--src/config/preferences.c133
-rw-r--r--src/config/preferences.h5
-rw-r--r--src/ui/console.c34
5 files changed, 133 insertions, 71 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 <text>",
             "/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 <text>",
@@ -1089,7 +1090,8 @@ static struct cmd_t command_defs[] =
             { "message trigger remove <text>",  "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 <text>",        "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;
+    if (!current_win || (current_win && notify_current) ) {
+        notify_window = TRUE;
+    }
+    if (!notify_window) {
+        return FALSE;
+    }
 
-    char *room_setting = prefs_get_string(PREF_NOTIFY_ROOM);
-    if (g_strcmp0(room_setting, "on") == 0) {
-        notify_message = TRUE;
+    gboolean notify_room = prefs_get_boolean(PREF_NOTIFY_ROOM);
+    if (notify_room) {
+        return TRUE;
     }
-    if (g_strcmp0(room_setting, "mention") == 0) {
+
+    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;
+    }
+
+    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);
 
-    return (notify_message && notify_window);
+    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