[polari/wip/fmuellner/combined-gsoc: 54/136] work so far, part 2



commit 2b24facc68a4cd73f0a6b6c220eedf709316d71a
Author: raresv <rares visalom gmail com>
Date:   Sun Jun 19 20:23:58 2016 +0300

    work so far, part 2

 data/resources/user-details.ui |   26 +++++++-----
 src/chatView.js                |   85 +++++++++++++++++++++++-----------------
 src/userList.js                |   76 +++++++++++++++++++++++-------------
 3 files changed, 114 insertions(+), 73 deletions(-)
---
diff --git a/data/resources/user-details.ui b/data/resources/user-details.ui
index c10dd16..72e0cb0 100644
--- a/data/resources/user-details.ui
+++ b/data/resources/user-details.ui
@@ -3,11 +3,12 @@
   <template class="Gjs_UserDetails" parent="GtkFrame">
     <property name="visible">True</property>
     <property name="hexpand">True</property>
+    <property name="shadow-type">none</property>
     <child>
       <object class="GtkBox" id="box">
         <property name="orientation">vertical</property>
-        <property name="spacing">6</property>
-        <property name="margin">6</property>
+        <property name="spacing">2</property>
+        <property name="margin">5</property>
         <property name="visible">True</property>
         <child>
           <object class="GtkBox" id="spinnerBox">
@@ -40,6 +41,7 @@
                 <property name="icon-name">document-open-recent-symbolic</property>
                 <property name="visible">True</property>
                 <property name="halign">start</property>
+                <property name="margin-left">0</property>
               </object>
               <packing>
                 <property name="width">1</property>
@@ -54,7 +56,7 @@
                 <property name="halign">start</property>
                 <property name="use-markup">True</property>
                 <property name="visible">True</property>
-                <property name="margin-start">17</property>
+                <property name="margin-start">20</property>
               </object>
               <packing>
                 <property name="top-attach">0</property>
@@ -68,6 +70,7 @@
                 <property name="wrap">True</property>
                 <property name="hexpand">True</property>
                 <property name="visible">True</property>
+                <property name="hexpand">True</property>
               </object>
               <packing>
                 <property name="top-attach">0</property>
@@ -79,6 +82,7 @@
                 <property name="icon-name">avatar-default-symbolic</property>
                 <property name="visible">True</property>
                 <property name="halign">start</property>
+                <property name="margin-left">0</property>
               </object>
               <packing>
                 <property name="width">1</property>
@@ -91,7 +95,8 @@
                 <property name="ellipsize">end</property>
                 <property name="halign">start</property>
                 <property name="visible">True</property>
-                <property name="margin-start">17</property>
+                <property name="margin-start">20</property>
+                <property name="hexpand">True</property>
               </object>
               <packing>
                 <property name="width">2</property>
@@ -104,24 +109,25 @@
         <child>
           <object class="GtkSeparator" id="separator">
             <property name="visible">True</property>
-            <property name="margin-top">10</property>
+            <property name="margin-top">7</property>
           </object>
         </child>
         <child>
           <object class="GtkModelButton" id="messageButton">
-            <property name="label" translatable="yes">Message</property>
-            <property name="halign">start</property>
+            <property name="text" translatable="yes">Message</property>
+            <property name="halign">fill</property>
             <property name="hexpand">True</property>
             <property name="visible">True</property>
-            <property name="no-show-all">False</property>
+            <property name="no-show-all">True</property>
           </object>
         </child>
         <child>
           <object class="GtkModelButton" id="pastActivityButton">
-            <property name="label" translatable="yes">View Past Activity</property>
-            <property name="halign">start</property>
+            <property name="text" translatable="yes">View Past Activity</property>
+            <property name="halign">fill</property>
             <property name="hexpand">True</property>
             <property name="visible">True</property>
+            <property name="no-show-all">True</property>
           </object>
         </child>
       </object>
diff --git a/src/chatView.js b/src/chatView.js
index 2bbc488..0f5400c 100644
--- a/src/chatView.js
+++ b/src/chatView.js
@@ -16,7 +16,7 @@ const PasteManager = imports.pasteManager;
 const Signals = imports.signals;
 const Utils = imports.utils;
 const UserTracker = imports.userTracker;
-const userList = imports.userList;
+const UserList = imports.userList;
 
 const MAX_NICK_CHARS = 8;
 const IGNORE_STATUS_TIME = 5;
@@ -1260,51 +1260,64 @@ const ChatView = new Lang.Class({
 
     _createNickTag: function(name) {
         let tag = new ButtonTag({ name: name });
-        tag._popover = new userList.UserPopover({ relative_to: this._view });
-        tag.connect('clicked', Lang.bind(this,
-            function() {
-                let view = this._view;
-                let event = Gtk.get_current_event();
-                let [, eventX, eventY] = event.get_coords();
-                let [x, y] = view.window_to_buffer_coords(Gtk.TextWindowType.WIDGET,
+        tag._popover = new UserList.UserPopover({ relative_to: this._view, margin: 0 });
+        tag.connect('clicked', Lang.bind(this, this._onNickTagClicked));
+        return tag;
+    },
+
+    _onNickTagClicked: function(tag) {
+        let view = this._view;
+        let event = Gtk.get_current_event();
+        let [, eventX, eventY] = event.get_coords();
+        let [x, y] = view.window_to_buffer_coords(Gtk.TextWindowType.WIDGET,
                                                           eventX, eventY);
-                let [inside, start] = view.get_iter_at_location(x, y);
-                let end = start.copy();
+        let [inside, start] = view.get_iter_at_location(x, y);
+        let end = start.copy();
 
-                start.backward_to_tag_toggle(tag);
-                end.forward_to_tag_toggle(tag);
+        if (!start.starts_tag(tag))
+            start.backward_to_tag_toggle(tag);
 
-                //log(view.get_buffer().get_slice(start, end, false));
+        if (!end.ends_tag(tag))
+            end.forward_to_tag_toggle(tag);
 
-                let rect1 = view.get_iter_location(start);
-                let rect2 = view.get_iter_location(end);
+        let rect1 = view.get_iter_location(start);
+        let rect2 = view.get_iter_location(end);
 
-                [rect1.x, rect1.y] = view.buffer_to_window_coords(Gtk.TextWindowType.WIDGET, rect1.x, 
rect1.y);
-                [rect2.x, rect2.y] = view.buffer_to_window_coords(Gtk.TextWindowType.WIDGET, rect2.x, 
rect2.y);
-                rect1.width = rect2.x - rect1.x;
-                rect1.height = rect2.y - rect1.y;
+        [rect1.x, rect1.y] = view.buffer_to_window_coords(Gtk.TextWindowType.WIDGET, rect1.x, rect1.y);
+        [rect2.x, rect2.y] = view.buffer_to_window_coords(Gtk.TextWindowType.WIDGET, rect2.x, rect2.y);
+        rect1.width = rect2.x - rect1.x;
+        rect1.height = rect2.y - rect1.y;
 
-                //TODO: special chars?
-                let actualNickName = view.get_buffer().get_slice(start, end, false);
+        //TODO: special chars?
+        let actualNickName = view.get_buffer().get_slice(start, end, false);
 
-                tag._popover.fallbackNick = actualNickName;
+        tag._popover.fallbackNick = actualNickName;
 
-                for (let i = 0; i < tag._contacts.length; i++) {
-                    //log(tag._contacts[i].alias);
-                    if (actualNickName == tag._contacts[i].alias) {
-                        if (!tag._popover.user) {
-                            tag._popover.user = tag._contacts[i];
-                        }
-                        else if (tag._popover.user != tag._contacts[i]) {
-                            tag._popover.user = tag._contacts[i];
-                        }
-                    }
+        let contactFound = false;
+        for (let i = 0; i < tag._contacts.length; i++) {
+            if (actualNickName == tag._contacts[i].alias) {
+                if (!tag._popover.user) {
+                    tag._popover.user = tag._contacts[i];
+                    contactFound = true;
+                    break;
+                }
+                else if (tag._popover.user != tag._contacts[i]) {
+                    tag._popover.user = tag._contacts[i];
+                    contactFound = true;
+                    break;
                 }
+            }
+        }
 
-                tag._popover.pointing_to = rect1;
-                tag._popover.show_all();
-            }));
-        return tag;
+        if (!contactFound) {
+            //tag._popover.user = null;
+            if (tag._contacts[0]) {
+                tag._popover.user = tag._contacts[0];
+            }
+        }
+
+        tag._popover.pointing_to = rect1;
+        tag._popover.show();
     },
 
     _createUrlTag: function(url) {
diff --git a/src/userList.js b/src/userList.js
index 1848df5..f70e85a 100644
--- a/src/userList.js
+++ b/src/userList.js
@@ -121,20 +121,29 @@ const UserDetails = new Lang.Class({
     _init: function(params) {
         this._expanded = false;
 
-        this.parent();
+        this.parent(params);
 
         this._messageButton.connect('clicked',
                                     Lang.bind(this, this._onMessageButtonClicked));
-        //this._user.connection.connect('notify::self-contact',
-        //                              Lang.bind(this, this._updateButtonVisibility));
+
         this._updateButtonVisibility();
         this._detailsGrid.hide();
     },
 
     set user(user) {
+        if (this._user == user)
+            return;
+
+        if (this._user)
+            this._user.connection.disconnect(this._selfContactChangedId);
+        this._selfContactChangedId = 0;
+
         this._user = user;
-        this._user.connection.connect('notify::self-contact',
-                                      Lang.bind(this, this._updateButtonVisibility));
+
+        if (this._user)
+            this._selfContactChangedId = this._user.connection.connect('notify::self-contact',
+                                                    Lang.bind(this, this._updateButtonVisibility));
+
         this._updateButtonVisibility();
     },
 
@@ -162,6 +171,12 @@ const UserDetails = new Lang.Class({
         this.notify('expanded');
     },
 
+    clearPrevUserAndDetails: function() {
+        this.user = null;
+        this._fullnameLabel.label = '';
+        this._lastLabel.label = '';
+    },
+
     _expand: function() {
         let prevDetails = this._fullnameLabel.label != '';
         this._detailsGrid.visible = prevDetails;
@@ -173,7 +188,7 @@ const UserDetails = new Lang.Class({
         if (this._user)
             this._user.request_contact_info_async(this._cancellable,
                                               Lang.bind(this, this._onContactInfoReady));
-        //TODO: else use this._falbackNick to quert tracker
+        //TODO: else use this._falbackNick to query tracker
     },
 
     _unexpand: function() {
@@ -260,13 +275,13 @@ const UserDetails = new Lang.Class({
 
     _updateButtonVisibility: function() {
         if (!this._user) {
-            this._messageButton.visible = false;
+            this._messageButton.sensitive = false;
 
             return;
         }
 
-        let visible = this._user != this._user.connection.self_contact;
-        this._messageButton.visible = visible;
+        let active = this._user != this._user.connection.self_contact;
+        this._messageButton.sensitive = active;
     }
 });
 
@@ -278,21 +293,24 @@ const UserPopover = new Lang.Class({
         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 });
-        //this._userDetails = new UserDetails();
+        this._statusLabel = new Gtk.Label({ halign: Gtk.Align.START, margin_left: 5, margin_bottom: 3 });
+        this._userDetails = new UserDetails();
+        this.bind_property('visible', this._userDetails, 'expanded', 0);
 
         this._vbox = new Gtk.Box({ orientation: Gtk.Orientation.VERTICAL });
         this._vbox.add(this._nickLabel);
         this._vbox.add(this._statusLabel);
-        //this._vbox.add(this._userDetails);
+        this._vbox.add(this._userDetails);
 
         this.add(this._vbox);
+
+        this._vbox.show_all();
     },
 
     set user(user) {
-        this._user  = user;
+        this._user = user;
 
-        this._populateUserPopover();
+        this._updateContents();
     },
 
     get user() {
@@ -302,28 +320,32 @@ const UserPopover = new Lang.Class({
     set fallbackNick(fallbackNick) {
         this._fallbackNick = fallbackNick;
 
-        this._populateUserPopover();
+        this._updateContents();
     },
 
-    _populateUserPopover: function() {
-        this._nickLabel.set_label(this._user ? this._user.alias : this._fallbackNick);
-        this._statusLabel.set_label(this._user ? "ONLINE" : "OFFLINE");
-
+    _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._userDetails)
-            this._userDetails.destroy();
-
-        this._userDetails = new UserDetails();
+        if (this._user) {
+            let context = this._statusLabel.get_style_context();
+            context.set_state(Gtk.StateFlags.LINK);
+            context.save();
+            this._statusLabel.sensitive = true;
+        }
+        else {
+            this._statusLabel.sensitive = false;
+        }
 
         if (this._user) {
             this._userDetails.user = this._user;
         }
+        else {
+            this._userDetails.clearPrevUserAndDetails();
+        }
 
         this._userDetails.fallbackNick = this._fallbackNick;
-
-        this.bind_property('visible', this._userDetails, 'expanded', 0);
-
-        this._vbox.add(this._userDetails);
     }
 });
 


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