about summary refs log tree commit diff stats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/command/commands.c62
-rw-r--r--src/config/preferences.c71
-rw-r--r--src/config/preferences.h7
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"
@@ -607,6 +608,76 @@ prefs_set_roster_presence_indent(gint value)
 }
 
 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)
 {
     if (g_key_file_has_key(prefs, PREF_GROUP_ALIAS, name, NULL)) {
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);