[polari/wip/raresv/userTrackerAndPopoversRebase: 3/24] userDetails: rename user-list-details.ui into user-details.ui and redesigned it (further changes wil



commit 4af73a52e019bc5f11e32b446435bec7806768cf
Author: raresv <rares visalom gmail com>
Date:   Wed Aug 3 13:13:18 2016 +0300

    userDetails: rename user-list-details.ui into user-details.ui and redesigned it (further changes will 
come in the future)
    
    userDetails: fix style issues, cleanup and refactor
    _populateUserPopover() into _updateContents().
    
    userDetails: fix style issues in the .ui file.
    
    userDetails: add user icon and make it visible. Fix the use of the expanded property so that the popover 
would update itself. Update messageButton visibility.

 data/org.gnome.Polari.data.gresource.xml |    2 +-
 data/resources/user-details.ui           |  145 ++++++++++++++++++++++++++++
 data/resources/user-list-details.ui      |   89 -----------------
 po/POTFILES.in                           |    2 +-
 src/userList.js                          |  153 ++++++++++++++++++++++++++---
 5 files changed, 284 insertions(+), 107 deletions(-)
---
diff --git a/data/org.gnome.Polari.data.gresource.xml b/data/org.gnome.Polari.data.gresource.xml
index 542288e..65ee61b 100644
--- a/data/org.gnome.Polari.data.gresource.xml
+++ b/data/org.gnome.Polari.data.gresource.xml
@@ -12,6 +12,6 @@
     <file alias="ui/main-window.ui" preprocess="xml-stripblanks">resources/main-window.ui</file>
     <file alias="ui/room-list-header.ui" preprocess="xml-stripblanks">resources/room-list-header.ui</file>
     <file alias="ui/room-list-row.ui" preprocess="xml-stripblanks">resources/room-list-row.ui</file>
-    <file alias="ui/user-list-details.ui" preprocess="xml-stripblanks">resources/user-list-details.ui</file>
+    <file alias="ui/user-details.ui" preprocess="xml-stripblanks">resources/user-details.ui</file>
   </gresource>
 </gresources>
diff --git a/data/resources/user-details.ui b/data/resources/user-details.ui
new file mode 100644
index 0000000..7d15f33
--- /dev/null
+++ b/data/resources/user-details.ui
@@ -0,0 +1,145 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<interface>
+  <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">2</property>
+        <property name="margin">9</property>
+        <property name="visible">True</property>
+        <child>
+          <object class="GtkBox" id="spinnerBox">
+            <property name="spacing">6</property>
+            <property name="margin">12</property>
+            <property name="hexpand">True</property>
+            <property name="halign">center</property>
+            <property name="visible">True</property>
+            <child>
+              <object class="GtkSpinner" id="spinner">
+                <property name="visible">True</property>
+              </object>
+            </child>
+            <child>
+              <object class="GtkLabel" id="label1">
+                <property name="label" translatable="yes">Loading details</property>
+                <property name="visible">True</property>
+              </object>
+            </child>
+          </object>
+        </child>
+        <child>
+          <object class="GtkGrid" id="detailsGrid">
+            <property name="row-spacing">6</property>
+            <property name="column-spacing">6</property>
+            <property name="hexpand">True</property>
+            <property name="visible">True</property>
+            <child>
+              <object class="GtkImage">
+                <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>
+                <property name="top-attach">0</property>
+                <property name="left-attach">0</property>
+              </packing>
+            </child>
+            <child>
+              <object class="GtkLabel" id="lastHeader">
+                <property name="label" translatable="yes">Last Activity:</property>
+                <property name="valign">start</property>
+                <property name="halign">start</property>
+                <property name="use-markup">True</property>
+                <property name="visible">True</property>
+                <property name="margin-start">20</property>
+                <style>
+                  <class name="dim-label" />
+                </style>
+              </object>
+              <packing>
+                <property name="top-attach">0</property>
+                <property name="left-attach">0</property>
+              </packing>
+            </child>
+            <child>
+              <object class="GtkLabel" id="lastLabel">
+                <property name="valign">end</property>
+                <property name="use-markup">True</property>
+                <property name="wrap">True</property>
+                <property name="hexpand">True</property>
+                <property name="visible">True</property>
+                <property name="hexpand">True</property>
+                <style>
+                  <class name="dim-label" />
+                </style>
+              </object>
+              <packing>
+                <property name="top-attach">0</property>
+                <property name="left-attach">1</property>
+              </packing>
+            </child>
+            <child>
+              <object class="GtkImage" id="userIcon">
+                <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>
+                <property name="top-attach">1</property>
+                <property name="left-attach">0</property>
+              </packing>
+            </child>
+            <child>
+              <object class="GtkLabel" id="fullnameLabel">
+                <property name="ellipsize">end</property>
+                <property name="halign">start</property>
+                <property name="visible">True</property>
+                <property name="margin-start">20</property>
+                <property name="hexpand">True</property>
+                <style>
+                  <class name="dim-label" />
+                </style>
+              </object>
+              <packing>
+                <property name="width">2</property>
+                <property name="top-attach">1</property>
+                <property name="left-attach">0</property>
+              </packing>
+            </child>
+          </object>
+        </child>
+        <child>
+          <object class="GtkSeparator" id="separator">
+            <property name="visible">True</property>
+            <property name="margin-top">7</property>
+          </object>
+        </child>
+        <child>
+          <object class="GtkModelButton" id="messageButton">
+            <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">True</property>
+          </object>
+        </child>
+        <child>
+          <object class="GtkModelButton" id="pastActivityButton">
+            <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>
+    </child>
+  </template>
+</interface>
diff --git a/po/POTFILES.in b/po/POTFILES.in
index c011eeb..617311a 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -9,7 +9,7 @@ data/resources/join-room-dialog.ui
 data/resources/main-window.ui
 data/resources/menus.ui
 data/resources/room-list-header.ui
-data/resources/user-list-details.ui
+data/resources/user-details.ui
 src/application.js
 src/appNotifications.js
 src/chatView.js
diff --git a/src/userList.js b/src/userList.js
index 6009c1d..5b3e876 100644
--- a/src/userList.js
+++ b/src/userList.js
@@ -99,17 +99,20 @@ const UserListPopover = new Lang.Class({
     }
 });
 
-const UserListDetails = new Lang.Class({
-    Name: 'UserListDetails',
+const UserDetails = new Lang.Class({
+    Name: 'UserDetails',
     Extends: Gtk.Frame,
-    Template: 'resource:///org/gnome/Polari/ui/user-list-details.ui',
+    Template: 'resource:///org/gnome/Polari/ui/user-details.ui',
     InternalChildren: ['spinnerBox',
                        'spinner',
                        'detailsGrid',
+                       'userIcon',
                        'fullnameLabel',
                        'lastHeader',
                        'lastLabel',
-                       'messageButton'],
+                       'separator',
+                       'messageButton',
+                       'pastActivityButton'],
     Properties: { 'expanded': GObject.ParamSpec.boolean('expanded',
                                                         'expanded',
                                                         'expanded',
@@ -117,21 +120,45 @@ const UserListDetails = new Lang.Class({
                                                         false)},
 
     _init: function(params) {
-        this._user = params.user;
-        delete params.user;
-
         this._expanded = false;
 
         this.parent(params);
 
         this._messageButton.connect('clicked',
-                                    Lang.bind(this, this._onButtonClicked));
-        this._user.connection.connect('notify::self-contact',
-                                      Lang.bind(this, this._updateButtonVisibility));
+                                    Lang.bind(this, this._onMessageButtonClicked));
+
         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;
+
+        if (this._user)
+            this._selfContactChangedId = this._user.connection.connect('notify::self-contact',
+                                                    Lang.bind(this, this._updateButtonVisibility));
+
+        if (this.expanded) {
+            this.expanded = false;
+            this.expanded = true;
+        }
+
+        this._updateButtonVisibility();
+    },
+
+    set fallbackNick(fallbackNick) {
+        this._fallbackNick = fallbackNick;
+
+        this._updateButtonVisibility();
+    },
+
     get expanded() {
         return this._expanded;
     },
@@ -150,6 +177,12 @@ const UserListDetails = 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;
@@ -157,8 +190,11 @@ const UserListDetails = new Lang.Class({
         this._spinner.start();
 
         this._cancellable = new Gio.Cancellable();
-        this._user.request_contact_info_async(this._cancellable,
+
+        if (this._user)
+            this._user.request_contact_info_async(this._cancellable,
                                               Lang.bind(this, this._onContactInfoReady));
+        //TODO: else use this._falbackNick to query tracker
     },
 
     _unexpand: function() {
@@ -213,6 +249,7 @@ const UserListDetails = new Lang.Class({
             fn = this._user.alias;
 
         this._fullnameLabel.label = fn;
+        this._userIcon.visible = true;
 
         if (last) {
             this._lastHeader.label = '<small>' + _("Last Activity:") + '</small>';
@@ -225,12 +262,16 @@ const UserListDetails = new Lang.Class({
             this._lastLabel.hide();
         }
 
+        this._revealDetails();
+    },
+
+    _revealDetails: function() {
         this._spinner.stop();
         this._spinnerBox.hide();
         this._detailsGrid.show();
     },
 
-    _onButtonClicked: function() {
+    _onMessageButtonClicked: function() {
         let account = this._user.connection.get_account();
 
         let app = Gio.Application.get_default();
@@ -244,8 +285,85 @@ const UserListDetails = new Lang.Class({
     },
 
     _updateButtonVisibility: function() {
-        let visible = this._user != this._user.connection.self_contact;
-        this._messageButton.visible = visible;
+        if (!this._user) {
+            this._messageButton.sensitive = false;
+
+            return;
+        }
+
+        //let active = this._user != this._user.connection.self_contact;
+        //this._messageButton.sensitive = active;
+        if (this._user == this._user.connection.self_contact) {
+            this._messageButton.visible = false;
+            this._messageButton.sensitive = true; //does this even make sense?
+        } else {
+            this._messageButton.visible = true;
+            this._messageButton.sensitive = true;
+        }
+    }
+});
+
+const UserPopover = new Lang.Class({
+    Name: 'UserPopover',
+    Extends: Gtk.Popover,
+
+    _init: function(params) {
+        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._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.add(this._vbox);
+
+        this._vbox.show_all();
+    },
+
+    set user(user) {
+        this._user = user;
+
+        this._updateContents();
+    },
+
+    get user() {
+        return this._user;
+    },
+
+    set fallbackNick(fallbackNick) {
+        this._fallbackNick = fallbackNick;
+
+        this._updateContents();
+    },
+
+    _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) {
+            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;
     }
 });
 
@@ -291,7 +409,7 @@ const UserListRow = new Lang.Class({
         let hbox = new Gtk.Box({ margin: 4, spacing: 4 });
         this._arrow = new Gtk.Arrow({ arrow_type: Gtk.ArrowType.RIGHT,
                                       no_show_all: true });
-        hbox.add(new Gtk.Image({ icon_name: 'avatar-default-symbolic' }));
+        //hbox.add(new Gtk.Image({ icon_name: 'avatar-default-symbolic' }));
         this._label = new Gtk.Label({ label: this._user.alias,
                                       halign: Gtk.Align.START,
                                       hexpand: true,
@@ -312,7 +430,10 @@ const UserListRow = new Lang.Class({
         if (this._revealer.get_child())
             return;
 
-        let details = new UserListDetails({ user: this._user })
+        //let details = new UserDetails({ user: this._user });
+        let details = new UserDetails();
+        details.user = this._user;
+
         this._revealer.bind_property('reveal-child', details, 'expanded', 0);
 
         this._revealer.add(details);


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