about summary refs log tree commit diff stats
path: root/src/ui/notifier.c
diff options
context:
space:
mode:
authorJames Booth <boothj5@gmail.com>2015-01-15 00:42:40 +0000
committerJames Booth <boothj5@gmail.com>2015-01-15 00:42:40 +0000
commit0007e3569e446429e09ec5bffd645512b62d0db8 (patch)
tree8c06d3a1f0b68e2b98a6cbdb7bb07fd12108a399 /src/ui/notifier.c
parenta1bbe07b4b4bf7f6a8e3800f128333cef8b0b759 (diff)
downloadprofani-tty-0007e3569e446429e09ec5bffd645512b62d0db8.tar.gz
Moved remimder notification code out of main loop
Diffstat (limited to 'src/ui/notifier.c')
-rw-r--r--src/ui/notifier.c78
1 files changed, 47 insertions, 31 deletions
diff --git a/src/ui/notifier.c b/src/ui/notifier.c
index ff93443f..7ca8f705 100644
--- a/src/ui/notifier.c
+++ b/src/ui/notifier.c
@@ -48,10 +48,19 @@
 #include "log.h"
 #include "muc.h"
 #include "ui/ui.h"
+#include "config/preferences.h"
 
 static void _notify(const char * const message, int timeout,
     const char * const category);
 
+static GTimer *remind_timer;
+
+void
+notifier_initialise(void)
+{
+    remind_timer = g_timer_new();
+}
+
 void
 notifier_uninit(void)
 {
@@ -60,6 +69,7 @@ notifier_uninit(void)
         notify_uninit();
     }
 #endif
+    g_timer_destroy(remind_timer);
 }
 
 void
@@ -128,46 +138,52 @@ notify_subscription(const char * const from)
 void
 notify_remind(void)
 {
-    gint unread = ui_unread();
-    gint open = muc_invites_count();
-    gint subs = presence_sub_request_count();
+    gdouble elapsed = g_timer_elapsed(remind_timer, NULL);
+    gint remind_period = prefs_get_notify_remind();
+    if (remind_period > 0 && elapsed >= remind_period) {
+        gint unread = ui_unread();
+        gint open = muc_invites_count();
+        gint subs = presence_sub_request_count();
 
-    GString *text = g_string_new("");
+        GString *text = g_string_new("");
 
-    if (unread > 0) {
-        if (unread == 1) {
-            g_string_append(text, "1 unread message");
-        } else {
-            g_string_append_printf(text, "%d unread messages", unread);
-        }
-
-    }
-    if (open > 0) {
         if (unread > 0) {
-            g_string_append(text, "\n");
+            if (unread == 1) {
+                g_string_append(text, "1 unread message");
+            } else {
+                g_string_append_printf(text, "%d unread messages", unread);
+            }
+
         }
-        if (open == 1) {
-            g_string_append(text, "1 room invite");
-        } else {
-            g_string_append_printf(text, "%d room invites", open);
+        if (open > 0) {
+            if (unread > 0) {
+                g_string_append(text, "\n");
+            }
+            if (open == 1) {
+                g_string_append(text, "1 room invite");
+            } else {
+                g_string_append_printf(text, "%d room invites", open);
+            }
         }
-    }
-    if (subs > 0) {
-        if ((unread > 0) || (open > 0)) {
-            g_string_append(text, "\n");
+        if (subs > 0) {
+            if ((unread > 0) || (open > 0)) {
+                g_string_append(text, "\n");
+            }
+            if (subs == 1) {
+                g_string_append(text, "1 subscription request");
+            } else {
+                g_string_append_printf(text, "%d subscription requests", subs);
+            }
         }
-        if (subs == 1) {
-            g_string_append(text, "1 subscription request");
-        } else {
-            g_string_append_printf(text, "%d subscription requests", subs);
+
+        if ((unread > 0) || (open > 0) || (subs > 0)) {
+            _notify(text->str, 5000, "Incoming message");
         }
-    }
 
-    if ((unread > 0) || (open > 0) || (subs > 0)) {
-        _notify(text->str, 5000, "Incoming message");
-    }
+        g_string_free(text, TRUE);
 
-    g_string_free(text, TRUE);
+        g_timer_start(remind_timer);
+    }
 }
 
 static void