[polari/wip/raresv/userTrackerAndPopoversRebase: 8/24] userPopover: fix nickLabel and statusLabel margins and add the 'subtitle' class to the context (it w



commit 6dee16ed3574c58e337bbd99b22649eaf5c22d4f
Author: raresv <rares visalom gmail com>
Date:   Wed Aug 3 18:40:48 2016 +0300

    userPopover: fix nickLabel and statusLabel margins and add the 'subtitle' class to the context (it will 
be removed later). Add fallbackNick getter.
    userPopover: add nick-popover-status css class for the status label. (will be removed in the future)
    userPopover: restyle the popover and add the logic necessary for the notifyButton.

 data/resources/application.css |    4 ++
 src/userList.js                |   86 ++++++++++++++++++++++++++++++++++-----
 2 files changed, 79 insertions(+), 11 deletions(-)
---
diff --git a/data/resources/application.css b/data/resources/application.css
index 7a11efd..8968630 100644
--- a/data/resources/application.css
+++ b/data/resources/application.css
@@ -142,3 +142,7 @@
 
 /* the following adds a border on top of the inputbar when users scroll up */
 .polari-chat-view > undershoot.bottom { border-bottom: 1px solid @borders; }
+
+.nick-popover-status {
+    font-size: 10px;
+}
diff --git a/src/userList.js b/src/userList.js
index 8595c0f..f87b46d 100644
--- a/src/userList.js
+++ b/src/userList.js
@@ -319,16 +319,40 @@ const UserPopover = new Lang.Class({
     Extends: Gtk.Popover,
 
     _init: function(params) {
+        this._room = params.room;
+        delete params.room;
+
         this.parent(params);
 
-        this._nickLabel = new Gtk.Label({ halign: Gtk.Align.START, margin_left: 5 });
-        this._statusLabel = new Gtk.Label({ halign: Gtk.Align.START, margin_left: 5, margin_bottom: 3 });
+        this._chatroomManager = ChatroomManager.getDefault();
+
+        this._nickLabel = new Gtk.Label({ halign: Gtk.Align.START, margin_top: 0 });
+        this._statusLabel = new Gtk.Label({ halign: Gtk.Align.START, margin_bottom: 0 });
+
+        this._headervbox = new Gtk.Box({ orientation: Gtk.Orientation.VERTICAL, halign: Gtk.Align.FILL });
+        this._headervbox.add(this._nickLabel);
+        this._headervbox.add(this._statusLabel);
+
+        this._hbox = new Gtk.Box({ orientation: Gtk.Orientation.HORIZONTAL, halign: Gtk.Align.FILL, margin: 
9 });
+        this._hbox.add(this._headervbox);
+
+        this._notifyButton = new Gtk.Button({ image: new Gtk.Image({ icon_name: 'alarm-symbolic' }), halign: 
Gtk.Align.END, hexpand: true });
+        this._notifyButton.connect('clicked',
+                                    Lang.bind(this, this._onNotifyButtonClicked));
+        this._hbox.add(this._notifyButton);
+
+
         this._userDetails = new UserDetails();
         this.bind_property('visible', this._userDetails, 'expanded', 0);
 
+        let context = this._statusLabel.get_style_context();
+        context.add_class('nick-popover-status');
+        //context.save();
+
         this._vbox = new Gtk.Box({ orientation: Gtk.Orientation.VERTICAL });
-        this._vbox.add(this._nickLabel);
-        this._vbox.add(this._statusLabel);
+        //this._vbox.add(this._nickLabel);
+        //this._vbox.add(this._statusLabel);
+        this._vbox.add(this._hbox);
         this._vbox.add(this._userDetails);
 
         this.add(this._vbox);
@@ -352,29 +376,69 @@ const UserPopover = new Lang.Class({
         this._updateContents();
     },
 
+    get fallbackNick() {
+        return this._fallbackNick;
+    },
+
     _updateContents: function() {
-        //this._nickLabel.set_label(this._user ? this._user.alias : this._fallbackNick);
         this._nickLabel.set_label(this._fallbackNick);
         this._statusLabel.set_label(this._user ? "Online" : "Offline");
 
         if (this._user) {
+            this._userDetails.user = this._user;
+
             let context = this._statusLabel.get_style_context();
             context.set_state(Gtk.StateFlags.LINK);
             context.save();
+
             this._statusLabel.sensitive = true;
+            //this._notifyButton.visible = false;
+            //this._updateNotifyButton();
         }
         else {
+            this._userDetails.clearPrevUserAndDetails();
+
             this._statusLabel.sensitive = false;
-        }
 
-        if (this._user) {
-            this._userDetails.user = this._user;
-        }
-        else {
-            this._userDetails.clearPrevUserAndDetails();
+            /*if (!this._chatroomManager.isUserWatched(this._fallbackNick, 
this._room.account.get_display_name()))
+                this._notifyButton.visible = true;
+            else
+                this._notifyButton.sensitive = false;*/
+            //this._updateNotifyButton();
         }
 
+        this._updateNotifyButton();
+
         this._userDetails.fallbackNick = this._fallbackNick;
+    },
+
+    _onNotifyButtonClicked: function() {
+        if (!this._chatroomManager.isUserWatched(this._fallbackNick, this._room.account.get_display_name())) 
{
+            this._chatroomManager.addToWatchlist(this._fallbackNick, this._room.account.get_display_name());
+            //this._notifyButton.sensitive = false;
+            this._updateNotifyButton();
+        }
+    },
+
+    _updateNotifyButton: function() {
+        if (!this._chatroomManager.isUserWatched(this._fallbackNick, this._room.account.get_display_name()))
+            if (this._user) {
+                this._notifyButton.visible = false;
+                this._notifyButton.sensitive = true;
+            }
+            else {
+                this._notifyButton.visible = true;
+                this._notifyButton.sensitive = true;
+            }
+        else
+            if (this._user) {
+                this._notifyButton.visible = false;
+                this._notifyButton.sensitive = true;
+            }
+            else {
+                this._notifyButton.visibile = true;
+                this._notifyButton.sensitive = false;
+            }
     }
 });
 


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