[polari/user-list-update: 2/6] userList: Add UserListSidebar class



commit c1a3fa072650b4f536d59cf4ba04d9b2b7874c02
Author: Florian Müllner <fmuellner gnome org>
Date:   Wed Oct 2 23:46:41 2013 +0200

    userList: Add UserListSidebar class

 data/resources/main-window.ui |   13 +---------
 src/mainWindow.js             |   17 ++++----------
 src/userList.js               |   49 +++++++++++++++++++++++++++++++++++++++++
 3 files changed, 56 insertions(+), 23 deletions(-)
---
diff --git a/data/resources/main-window.ui b/data/resources/main-window.ui
index cb3df3d..3164755 100644
--- a/data/resources/main-window.ui
+++ b/data/resources/main-window.ui
@@ -283,7 +283,7 @@
                     <property name="hexpand">False</property>
                     <property name="transition_type">slide-left</property>
                     <child>
-                      <object class="PolariFixedSizeFrame" id="frame2">
+                      <object class="PolariFixedSizeFrame" id="user_list_sidebar">
                         <property name="visible">True</property>
                         <property name="hexpand">False</property>
                         <property name="width">200</property>
@@ -293,16 +293,7 @@
                           <class name="polari-user-list"/>
                         </style>
                         <child>
-                          <object class="GtkStack" id="user_list_stack">
-                            <property name="visible">True</property>
-                            <property name="can_focus">True</property>
-                            <property name="hexpand">True</property>
-                            <property name="halign">fill</property>
-                            <property name="transition_type">crossfade</property>
-                            <child>
-                              <placeholder/>
-                            </child>
-                          </object>
+                          <placeholder/>
                         </child>
                       </object>
                     </child>
diff --git a/src/mainWindow.js b/src/mainWindow.js
index d784922..e65ef16 100644
--- a/src/mainWindow.js
+++ b/src/mainWindow.js
@@ -76,7 +76,9 @@ const MainWindow = new Lang.Class({
         this._roomList = new RoomList.RoomList();
         scroll.add(this._roomList.widget);
 
-        this._userListStack = builder.get_object('user_list_stack');
+        let sidebar = builder.get_object('user_list_sidebar');
+        this._userListSidebar = new UserList.UserListSidebar();
+        sidebar.add(this._userListSidebar.widget);
 
         let revealer = builder.get_object('user_list_revealer');
         app.connect('action-state-changed::user-list', Lang.bind(this,
@@ -236,24 +238,16 @@ const MainWindow = new Lang.Class({
 
 
     _roomAdded: function(roomManager, room) {
-        let userList;
         let chatView = new ChatView.ChatView(room);
+        this._rooms[room.id] = chatView;
 
-        if (room.channel.handle_type == Tp.HandleType.ROOM)
-            userList = new UserList.UserList(room);
-        else
-            userList = { widget: new Gtk.Label() };
-
-        this._rooms[room.id] = [chatView, userList];
-
-        this._userListStack.add_named(userList.widget, room.id);
         this._chatStack.add_named(chatView.widget, room.id);
 
         this._revealer.reveal_child = roomManager.roomCount > 0;
     },
 
     _roomRemoved: function(roomManager, room) {
-        this._rooms[room.id].forEach(function(w) { w.widget.destroy(); });
+        this._rooms[room.id].widget.destroy();
         delete this._rooms[room.id];
 
         this._revealer.reveal_child = roomManager.roomCount > 0;
@@ -290,7 +284,6 @@ const MainWindow = new Lang.Class({
                                                             this._updateNick));
 
         this._chatStack.set_visible_child_name(this._room.id);
-        this._userListStack.set_visible_child_name(this._room.id);
     },
 
     _setNick: function(nick) {
diff --git a/src/userList.js b/src/userList.js
index 7c442ef..6b8d21e 100644
--- a/src/userList.js
+++ b/src/userList.js
@@ -1,9 +1,58 @@
 const Gdk = imports.gi.Gdk;
 const Gtk = imports.gi.Gtk;
 const Pango = imports.gi.Pango;
+const Tp = imports.gi.TelepathyGLib;
 
+const ChatroomManager = imports.chatroomManager;
 const Lang = imports.lang;
 
+const UserListSidebar = new Lang.Class({
+    Name: 'UserListSidebar',
+
+    _init: function() {
+        this._createWidget();
+
+        this._rooms = {};
+
+        this._roomManager = new ChatroomManager.getDefault();
+        this._roomManager.connect('room-added',
+                                  Lang.bind(this, this._roomAdded));
+        this._roomManager.connect('room-removed',
+                                  Lang.bind(this, this._roomRemoved));
+        this._roomManager.connect('active-changed',
+                                  Lang.bind(this, this._activeRoomChanged));
+    },
+
+    _createWidget: function() {
+        this.widget = new Gtk.Stack({ hexpand: true, visible: true });
+        this.widget.transition_type = Gtk.StackTransitionType.CROSSFADE;
+    },
+
+    _roomAdded: function(roomManager, room) {
+        if (room.channel.handle_type != Tp.HandleType.ROOM)
+            return;
+
+        let userList = new UserList(room);
+        this._rooms[room.id] = userList;
+
+        this.widget.add_named(userList.widget, room.id);
+    },
+
+    _roomRemoved: function(roomManager, room) {
+        if (!this._rooms[room.id])
+            return;
+        this._rooms[room.id].widget.destroy();
+        delete this._rooms[room.id];
+    },
+
+    _activeRoomChanged: function(manager, room) {
+        if (!room || !this._rooms[room.id])
+            return;
+        this.widget.set_visible_child_name(room.id);
+    },
+
+});
+
 const UserList = new Lang.Class({
     Name: 'UserList',
 


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