[gnome-shell/wip/fmuellner/notification-redux: 72/88] dateMenu: Show indicator for unacknowledged messages



commit 051c735b78a16fc2746be3530e8b52f926575315
Author: Florian Müllner <fmuellner gnome org>
Date:   Sat Feb 14 03:17:16 2015 +0100

    dateMenu: Show indicator for unacknowledged messages

 js/ui/dateMenu.js |   52 +++++++++++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 51 insertions(+), 1 deletions(-)
---
diff --git a/js/ui/dateMenu.js b/js/ui/dateMenu.js
index 9aac855..c28b6a4 100644
--- a/js/ui/dateMenu.js
+++ b/js/ui/dateMenu.js
@@ -206,6 +206,44 @@ const WorldClocksSection = new Lang.Class({
     }
 });
 
+const MessagesIndicator = new Lang.Class({
+    Name: 'MessagesIndicator',
+
+    _init: function() {
+        this.actor = new St.Label({ text: '⚫', visible: false, y_expand: true,
+                                    y_align: Clutter.ActorAlign.CENTER });
+
+        this._sources = [];
+
+        Main.messageTray.connect('source-added', Lang.bind(this, this._onSourceAdded));
+        Main.messageTray.connect('source-removed', Lang.bind(this, this._onSourceRemoved));
+
+        let sources = Main.messageTray.getSources();
+        sources.forEach(Lang.bind(this, function(source) { this._onSourceAdded(null, source); }));
+    },
+
+    _onSourceAdded: function(tray, source) {
+        source.connect('count-updated', Lang.bind(this, this._updateCount));
+        this._sources.push(source);
+        this._updateCount();
+    },
+
+    _onSourceRemoved: function(tray, source) {
+        this._sources.splice(this._sources.indexOf(source), 1);
+        this._updateCount();
+    },
+
+    _updateCount: function() {
+        let count = 0;
+        this._sources.forEach(Lang.bind(this,
+            function(source) {
+                count += source.unseenCount;
+            }));
+
+        this.actor.visible = (count > 0);
+    }
+});
+
 const FreezableBinLayout = new Lang.Class({
     Name: 'FreezableBinLayout',
     Extends: Clutter.BinLayout,
@@ -255,10 +293,22 @@ const DateMenuButton = new Lang.Class({
         this.parent(menuAlignment);
 
         this._clockDisplay = new St.Label({ y_align: Clutter.ActorAlign.CENTER });
+        this._indicator = new MessagesIndicator();
+
+        let pad = new St.Label();
+        this._indicator.actor.bind_property('visible', pad, 'visible', 0);
+        this._indicator.actor.bind_property('width', pad, 'width', 0);
+
+        let box = new St.BoxLayout();
+        box.add_actor(pad);
+        box.add_actor(this._clockDisplay);
+        box.add_actor(this._indicator.actor);
+
         this.actor.label_actor = this._clockDisplay;
-        this.actor.add_actor(this._clockDisplay);
+        this.actor.add_actor(box);
         this.actor.add_style_class_name ('clock-display');
 
+
         let layout = new FreezableBinLayout();
         let bin = new St.Widget({ layout_manager: layout });
         this.menu.box.add_child(bin);


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