[blam] Show notification on update



commit 10abd08e47e70624378d0a82c209d6b1aa76e452
Author: Carlos Martín Nieto <carlos cmartin tk>
Date:   Sun Jun 6 00:49:20 2010 +0200

    Show notification on update
    
    Whenever the update queue becomes empty, there are unread posts
    and the window isn't the active one, show a notification with the
    number of unread posts.

 src/ChannelCollection.cs  |    7 +++++++
 src/Makefile.am           |    1 +
 src/UnreadNotification.cs |   30 ++++++++++++++++++++++++++++++
 3 files changed, 38 insertions(+), 0 deletions(-)
---
diff --git a/src/ChannelCollection.cs b/src/ChannelCollection.cs
index 7484bc4..6008836 100644
--- a/src/ChannelCollection.cs
+++ b/src/ChannelCollection.cs
@@ -339,6 +339,13 @@ namespace Imendio.Blam {
 		    }	
 
 		    new MainloopEmitter (this.ChannelRefreshFinished, channel).Emit ();
+#if ENABLE_NOTIFY
+            /* Make sure we have something to say and the user isn't watching us */
+            if(mQueue.Count == 0 &&
+                    NrOfUnreadItems != 0 && mainWindow.IsActive == false){
+                UnreadNotification.NotifyUnreadPosts(NrOfUnreadItems);
+            }
+#endif
 		} catch (InvalidOperationException) {
 		    break;
 		}
diff --git a/src/Makefile.am b/src/Makefile.am
index 4ac7584..cfbb0bd 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -47,6 +47,7 @@ endif
 
 if ENABLE_NOTIFY
 FLAGS += -define:ENABLE_NOTIFY
+BLAM_CSFILES += UnreadNotification.cs
 ASSEMBLIES += $(NOTIFY_LIBS)
 endif
 
diff --git a/src/UnreadNotification.cs b/src/UnreadNotification.cs
new file mode 100644
index 0000000..1fb062d
--- /dev/null
+++ b/src/UnreadNotification.cs
@@ -0,0 +1,30 @@
+using Mono.Unix;
+using System;
+using Notifications;
+
+namespace Imendio.Blam
+{
+    public class UnreadNotification
+    {
+
+        static Notification note = new Notification();
+
+        public UnreadNotification()
+        {
+            note = new Notification();
+        }
+
+        public static void NotifyUnreadPosts(int unread)
+        {
+            /* Same as for the tray icon tooltip */
+            String str = string.Format (Catalog.GetPluralString ("{0} unread item", "{0} unread items", unread),
+                                             unread);
+
+            note.IconName = "blam";
+            note.Summary = Catalog.GetString("Feeds refreshed");
+            note.Body = str;
+            note.Urgency = Urgency.Normal;
+            note.Show();
+        }
+    }
+}



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]