about summary refs log tree commit diff stats
path: root/src/command
diff options
context:
space:
mode:
authorJames Booth <boothj5@gmail.com>2013-04-27 23:46:49 +0100
committerJames Booth <boothj5@gmail.com>2013-04-27 23:46:49 +0100
commit441422ddc8db540c4b3b058d3cc584246cd4f198 (patch)
tree4b2327545f5e3c52ede894eb86fd4140995941de /src/command
parent04c6f2d7b0b29cff753eb08b33bb81ce2d27a60b (diff)
downloadprofani-tty-441422ddc8db540c4b3b058d3cc584246cd4f198.tar.gz
Added desktop notification option for subscription requests
closes #166
Diffstat (limited to 'src/command')
-rw-r--r--src/command/command.c47
1 files changed, 46 insertions, 1 deletions
diff --git a/src/command/command.c b/src/command/command.c
index 46e56d4a..6e1b97d0 100644
--- a/src/command/command.c
+++ b/src/command/command.c
@@ -522,6 +522,9 @@ static struct cmd_t setting_commands[] =
           "invite  : Notifications for chat room invites.",
           "        : on|off",
           "",
+          "sub     : Notifications for subscription requests.",
+          "        : on|off",
+          "",
           "Example : /notify message on (enable message notifications)",
           "Example : /notify remind 10  (remind every 10 seconds)",
           "Example : /notify remind 0   (switch off reminders)",
@@ -807,6 +810,7 @@ cmd_init(void)
     autocomplete_add(notify_ac, strdup("typing"));
     autocomplete_add(notify_ac, strdup("remind"));
     autocomplete_add(notify_ac, strdup("invite"));
+    autocomplete_add(notify_ac, strdup("sub"));
     autocomplete_add(notify_ac, strdup("status"));
 
     sub_ac = autocomplete_new();
@@ -2513,7 +2517,8 @@ _cmd_set_notify(gchar **args, struct cmd_help_t help)
 
     // bad kind
     if ((strcmp(kind, "message") != 0) && (strcmp(kind, "typing") != 0) &&
-            (strcmp(kind, "remind") != 0) && (strcmp(kind, "invite") != 0)) {
+            (strcmp(kind, "remind") != 0) && (strcmp(kind, "invite") != 0) &&
+            (strcmp(kind, "sub") != 0)) {
         cons_show("Usage: %s", help.usage);
 
     // set message setting
@@ -2552,6 +2557,18 @@ _cmd_set_notify(gchar **args, struct cmd_help_t help)
             cons_show("Usage: /notify invite on|off");
         }
 
+    // set subscription setting
+    } else if (strcmp(kind, "sub") == 0) {
+        if (strcmp(value, "on") == 0) {
+            cons_show("Subscription notifications enabled.");
+            prefs_set_boolean(PREF_NOTIFY_SUB, TRUE);
+        } else if (strcmp(value, "off") == 0) {
+            cons_show("Subscription notifications disabled.");
+            prefs_set_boolean(PREF_NOTIFY_SUB, FALSE);
+        } else {
+            cons_show("Usage: /notify sub on|off");
+        }
+
     // set remind setting
     } else if (strcmp(kind, "remind") == 0) {
         gint period = atoi(value);
@@ -3008,6 +3025,34 @@ _notify_autocomplete(char *input, int *size)
             free(auto_msg);
             free(found);
         }
+    } else if ((strncmp(input, "/notify invite ", 15) == 0) && (*size > 15)) {
+        for(i = 15; i < *size; i++) {
+            inp_cpy[i-15] = input[i];
+        }
+        inp_cpy[(*size) - 15] = '\0';
+        found = prefs_autocomplete_boolean_choice(inp_cpy);
+        if (found != NULL) {
+            auto_msg = (char *) malloc((15 + (strlen(found) + 1)) * sizeof(char));
+            strcpy(auto_msg, "/notify invite ");
+            strcat(auto_msg, found);
+            inp_replace_input(input, auto_msg, size);
+            free(auto_msg);
+            free(found);
+        }
+    } else if ((strncmp(input, "/notify sub ", 12) == 0) && (*size > 12)) {
+        for(i = 12; i < *size; i++) {
+            inp_cpy[i-12] = input[i];
+        }
+        inp_cpy[(*size) - 12] = '\0';
+        found = prefs_autocomplete_boolean_choice(inp_cpy);
+        if (found != NULL) {
+            auto_msg = (char *) malloc((12 + (strlen(found) + 1)) * sizeof(char));
+            strcpy(auto_msg, "/notify sub ");
+            strcat(auto_msg, found);
+            inp_replace_input(input, auto_msg, size);
+            free(auto_msg);
+            free(found);
+        }
     } else if ((strncmp(input, "/notify ", 8) == 0) && (*size > 8)) {
         _parameter_autocomplete_with_ac(input, size, "/notify", notify_ac);
     }