about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorJames Booth <boothj5@gmail.com>2014-05-24 22:14:26 +0100
committerJames Booth <boothj5@gmail.com>2014-05-24 22:14:26 +0100
commitb36fbe413a4a95c1ae75b99ca5d8cbde709bad6f (patch)
tree10cd01af29e671e79116ddd09b426d582aa11a1e
parentb25b3f318036e6b14d52fef5a4f418a36d9b5a64 (diff)
downloadprofani-tty-b36fbe413a4a95c1ae75b99ca5d8cbde709bad6f.tar.gz
Added settings to show message text in notifications
-rw-r--r--src/command/command.c18
-rw-r--r--src/command/commands.c20
-rw-r--r--src/config/preferences.c6
-rw-r--r--src/config/preferences.h2
-rw-r--r--src/ui/console.c10
-rw-r--r--src/ui/core.c12
-rw-r--r--src/ui/notifier.c29
-rw-r--r--src/ui/ui.h4
8 files changed, 85 insertions, 16 deletions
diff --git a/src/command/command.c b/src/command/command.c
index 9fb8a820..5556fd7c 100644
--- a/src/command/command.c
+++ b/src/command/command.c
@@ -477,10 +477,14 @@ static struct cmd_t command_defs[] =
           "                : on|off",
           "message current : Whether messages in the current window trigger notifications.",
           "                : on|off",
+          "message text    : Show message text in message 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",
+          "room text       : Show message test in chat room message notifications.",
+          "                : on|off",
           "remind          : Notification reminders of unread messages.",
           "                : where value is the reminder period in seconds,",
           "                : use 0 to disable.",
@@ -494,8 +498,10 @@ static struct cmd_t command_defs[] =
           "                : on|off",
           "",
           "Example : /notify message on        (enable message notifications)",
+          "Example : /notify message text on   (show message text in 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 room text off     (do not show message text in chat room notifications)",
           "Example : /notify remind 10         (remind every 10 seconds)",
           "Example : /notify remind 0          (switch off reminders)",
           "Example : /notify typing on         (enable typing notifications)",
@@ -987,12 +993,14 @@ cmd_init(void)
     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_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");
+    autocomplete_add(notify_room_ac, "text");
 
     notify_typing_ac = autocomplete_new();
     autocomplete_add(notify_typing_ac, "on");
@@ -1821,6 +1829,16 @@ _notify_autocomplete(char *input, int *size)
         return result;
     }
 
+    result = autocomplete_param_with_func(input, size, "/notify room text", prefs_autocomplete_boolean_choice);
+    if (result != NULL) {
+        return result;
+    }
+
+    result = autocomplete_param_with_func(input, size, "/notify message text", 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;
diff --git a/src/command/commands.c b/src/command/commands.c
index c64b3883..75da4fa3 100644
--- a/src/command/commands.c
+++ b/src/command/commands.c
@@ -2220,6 +2220,16 @@ cmd_notify(gchar **args, struct cmd_help_t help)
             } else {
                 cons_show("Usage: /notify message 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);
+            } else if (g_strcmp0(args[2], "off") == 0) {
+                cons_show("Showing text in message notifications disabled.");
+                prefs_set_boolean(PREF_NOTIFY_MESSAGE_TEXT, FALSE);
+            } else {
+                cons_show("Usage: /notify message text on|off");
+            }
         } else {
             cons_show("Usage: /notify message on|off");
         }
@@ -2245,6 +2255,16 @@ cmd_notify(gchar **args, struct cmd_help_t help)
             } else {
                 cons_show("Usage: /notify room current on|off");
             }
+        } else if (strcmp(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);
+            } else if (g_strcmp0(args[2], "off") == 0) {
+                cons_show("Showing text in chat room message notifications disabled.");
+                prefs_set_boolean(PREF_NOTIFY_ROOM_TEXT, FALSE);
+            } else {
+                cons_show("Usage: /notify room text on|off");
+            }
         } else {
             cons_show("Usage: /notify room on|off|mention");
         }
diff --git a/src/config/preferences.c b/src/config/preferences.c
index c5dd75b7..32473848 100644
--- a/src/config/preferences.c
+++ b/src/config/preferences.c
@@ -403,8 +403,10 @@ _get_group(preference_t pref)
         case PREF_NOTIFY_TYPING_CURRENT:
         case PREF_NOTIFY_MESSAGE:
         case PREF_NOTIFY_MESSAGE_CURRENT:
+        case PREF_NOTIFY_MESSAGE_TEXT:
         case PREF_NOTIFY_ROOM:
         case PREF_NOTIFY_ROOM_CURRENT:
+        case PREF_NOTIFY_ROOM_TEXT:
         case PREF_NOTIFY_INVITE:
         case PREF_NOTIFY_SUB:
             return PREF_GROUP_NOTIFICATIONS;
@@ -471,10 +473,14 @@ _get_key(preference_t pref)
             return "message";
         case PREF_NOTIFY_MESSAGE_CURRENT:
             return "message.current";
+        case PREF_NOTIFY_MESSAGE_TEXT:
+            return "message.text";
         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_INVITE:
             return "invite";
         case PREF_NOTIFY_SUB:
diff --git a/src/config/preferences.h b/src/config/preferences.h
index 66d0d41c..3de860d2 100644
--- a/src/config/preferences.h
+++ b/src/config/preferences.h
@@ -55,8 +55,10 @@ typedef enum {
     PREF_NOTIFY_TYPING_CURRENT,
     PREF_NOTIFY_MESSAGE,
     PREF_NOTIFY_MESSAGE_CURRENT,
+    PREF_NOTIFY_MESSAGE_TEXT,
     PREF_NOTIFY_ROOM,
     PREF_NOTIFY_ROOM_CURRENT,
+    PREF_NOTIFY_ROOM_TEXT,
     PREF_NOTIFY_INVITE,
     PREF_NOTIFY_SUB,
     PREF_CHLOG,
diff --git a/src/ui/console.c b/src/ui/console.c
index e7ca07a1..e5a070f5 100644
--- a/src/ui/console.c
+++ b/src/ui/console.c
@@ -1168,6 +1168,11 @@ _cons_notify_setting(void)
     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");
+
     char *room_setting = prefs_get_string(PREF_NOTIFY_ROOM);
     cons_show    ("Room messages (/notify room)        : %s", room_setting);
 
@@ -1176,6 +1181,11 @@ _cons_notify_setting(void)
     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
diff --git a/src/ui/core.c b/src/ui/core.c
index 7b3190ed..8f946d68 100644
--- a/src/ui/core.c
+++ b/src/ui/core.c
@@ -376,7 +376,11 @@ _ui_incoming_msg(const char * const from, const char * const message,
     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);
+            if (prefs_get_boolean(PREF_NOTIFY_MESSAGE_TEXT)) {
+                notify_message(display_from, ui_index, message);
+            } else {
+                notify_message(display_from, ui_index, NULL);
+            }
         }
     }
 
@@ -1723,7 +1727,11 @@ _ui_room_message(const char * const room_jid, const char * const nick,
             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);
+                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);
             }
         }
diff --git a/src/ui/notifier.c b/src/ui/notifier.c
index e36edf69..778487e2 100644
--- a/src/ui/notifier.c
+++ b/src/ui/notifier.c
@@ -85,25 +85,31 @@ _notify_invite(const char * const from, const char * const room,
 }
 
 static void
-_notify_message(const char * const handle, int win)
+_notify_message(const char * const handle, int win, const char * const text)
 {
-    char message[strlen(handle) + 1 + 14];
-    sprintf(message, "%s: message (%d).", handle, win);
+    GString *message = g_string_new("");
+    g_string_append_printf(message, "%s (win %d)", handle, win);
+    if (text != NULL) {
+        g_string_append_printf(message, "\n%s", text);
+    }
+
+    _notify(message->str, 10000, "incoming message");
 
-    _notify(message, 10000, "incoming message");
+    g_string_free(message, TRUE);
 }
 
 static void
-_notify_room_message(const char * const handle, const char * const room, int win)
+_notify_room_message(const char * const handle, const char * const room, int win, const char * const text)
 {
-    GString *text = g_string_new("");
-
-    g_string_append_printf(text, "Room: %s\n", room);
-    g_string_append_printf(text, "%s: message (%d).", handle, win);
+    GString *message = g_string_new("");
+    g_string_append_printf(message, "%s in %s (win %d)", handle, room, win);
+    if (text != NULL) {
+        g_string_append_printf(message, "\n%s", text);
+    }
 
-    _notify(text->str, 10000, "incoming message");
+    _notify(message->str, 10000, "incoming message");
 
-    g_string_free(text, TRUE);
+    g_string_free(message, TRUE);
 }
 
 static void
@@ -165,7 +171,6 @@ _notify(const char * const message, int timeout,
     const char * const category)
 {
 #ifdef HAVE_LIBNOTIFY
-
     if (notify_is_initted()) {
         NotifyNotification *notification;
         notification = notify_notification_new("Profanity", message, NULL);
diff --git a/src/ui/ui.h b/src/ui/ui.h
index 32bb782a..559af82d 100644
--- a/src/ui/ui.h
+++ b/src/ui/ui.h
@@ -260,9 +260,9 @@ void (*notifier_init)(void);
 void (*notifier_uninit)(void);
 
 void (*notify_typing)(const char * const handle);
-void (*notify_message)(const char * const handle, int win);
+void (*notify_message)(const char * const handle, int win, const char * const text);
 void (*notify_room_message)(const char * const handle, const char * const room,
-    int win);
+    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);