[polari/wip/fmuellner/combined-gsoc: 20/103] initial right side



commit 8d9de310114d5b8eea9ff0fcdbe5b04ad003513f
Author: Kunaal Jain <kunaalus gmail com>
Date:   Sun Jul 3 01:30:23 2016 +0530

    initial right side

 data/resources/main-window.ui          |   31 +++++-
 src/logManager.js                      |    2 +-
 src/mainWindow.js                      |   40 +++++++-
 src/org.gnome.Polari.src.gresource.xml |    1 +
 src/resultStack.js                     |  161 ++++++++++++++++++++++++++++++++
 5 files changed, 226 insertions(+), 9 deletions(-)
---
diff --git a/data/resources/main-window.ui b/data/resources/main-window.ui
index 6b6b3ad..ff2b673 100644
--- a/data/resources/main-window.ui
+++ b/data/resources/main-window.ui
@@ -294,11 +294,32 @@
             <property name="visible">True</property>
             <property name="vexpand">True</property>
             <child>
-              <object class="Gjs_RoomStack" id="roomStack">
-                <property name="visible">True</property>
-                <property name="homogeneous">True</property>
-                <property name="transition-type">crossfade</property>
-              </object>
+                <object class="GtkStack" id="mainStack1">
+                  <property name="visible">True</property>
+                  <property name="transition-type">slide-left-right</property>
+                  <property name="hexpand">true</property>
+                    <child>
+                      <object class="Gjs_RoomStack" id="roomStack">
+                        <property name="visible">True</property>
+                        <property name="homogeneous">True</property>
+                        <property name="transition-type">crossfade</property>
+                      </object>
+                      <packing>
+                        <property name="name">room</property>
+                      </packing>
+                    </child>
+                    <child>
+                      <object class="GtkTextView" id="resultStack">
+                        <property name="visible">True</property>
+                        <!-- <property name="use-markup">true</property> -->
+                        <!-- <property name="homogeneous">True</property> -->
+                        <!-- <property name="transition-type">crossfade</property> -->
+                      </object>
+                      <packing>
+                        <property name="name">result</property>
+                     </packing>
+                    </child>
+                </object>
             </child>
           </object>
         </child>
diff --git a/src/logManager.js b/src/logManager.js
index 6c0c48a..f7436f6 100644
--- a/src/logManager.js
+++ b/src/logManager.js
@@ -156,7 +156,7 @@ const LogWalker = new Lang.Class({
     getEvents: function(numEvents, callback) {
         if (!this._query) {
             this._query = new GenericQuery(this._connection, numEvents);
-
+            print(this._account.nickname);
             let sparql = (
                 'select nie:plainTextContent(?msg) as ?message ' +
                 '       if (nmo:from(?msg) = nco:default-contact-me,' +
diff --git a/src/mainWindow.js b/src/mainWindow.js
index 5d5878c..9882565 100644
--- a/src/mainWindow.js
+++ b/src/mainWindow.js
@@ -14,6 +14,7 @@ const Lang = imports.lang;
 const Mainloop = imports.mainloop;
 const RoomList = imports.roomList;
 const RoomStack = imports.roomStack;
+//const ResultStack = imports.resultStack;
 const UserList = imports.userList;
 const Utils = imports.utils;
 const Pango = imports.gi.Pango;
@@ -107,7 +108,9 @@ const MainWindow = new Lang.Class({
                        'overlay',
                        'roomStack',
                        'mainStack',
-                       'results'],
+                       'results',
+                       'mainStack1',
+                       'resultStack'],
     Properties: {
         subtitle: GObject.ParamSpec.string('subtitle',
                                            'subtitle',
@@ -236,13 +239,19 @@ const MainWindow = new Lang.Class({
         this._search_active_button.connect(
             'toggled',
             Lang.bind(this, function() {
-                if (this._mainStack.visible_child_name == 'image')
+                if (this._mainStack.visible_child_name == 'image') {
                     this._mainStack.visible_child_name = 'roomList';
-                else
+                    this._mainStack1.visible_child_name = 'room';
+                }
+                else {
                     this._mainStack.visible_child_name = 'image';
+                    this._mainStack1.visible_child_name = 'result';
+                }
                 this._searchisActive = !this._searchisActive;
             }));
 
+        this._results.connect('row-activated', Lang.bind(this, this._rowactivated));
+
         //test
         this._logManager = LogManager.getDefault();
         let query = "select ?text as ?mms where { ?msg a nmo:IMMessage; nie:plainTextContent ?text. ?msg 
nmo:communicationChannel ?channel. ?channel nie:title '#tracker'. ?msg nmo:from ?contact. ?contact 
nco:nickname 'bijan' . ?msg fts:match 'wonderful' }"
@@ -264,6 +273,29 @@ const MainWindow = new Lang.Class({
         this.show_all();
     },
 
+    _rowactivated: function(box, row) {
+        let logManager = LogManager.getDefault();
+        this._logWalker = logManager.walkEvents(row,
+                                                row.channel);
+
+        this._fetchingBacklog = true;
+        this._logWalker.getEvents(10,
+                                  Lang.bind(this, this._onLogEventsReady));
+        let buffer = this._resultStack.get_buffer();
+        let iter = buffer.get_end_iter();
+        //this._resultStack.buffer.insert(iter,row._content_label.label, -1);
+        // this._resultStack.label = row._content_label.label;
+    },
+
+    _onLogEventsReady: function(events) {
+        for (let i = 0; i < events.length; i++) {
+            let buffer = this._resultStack.get_buffer();
+            let iter = buffer.get_end_iter();
+            this._resultStack.buffer.insert(iter,events[i].message, -1);
+            this._resultStack.buffer.insert(iter,'\n', -1);
+        }
+    },
+
     _Log: function(events) {
         log(events);
         let widgetMap = {};
@@ -292,6 +324,8 @@ const MainWindow = new Lang.Class({
                 row._source_name.label = channel.substring(1);
                 row._short_time_label.label = this._formatTimestamp(time);
                 row.uid = events[i].id;
+                row.channel = channel;
+                row.nickname = channel;
                 widgetMap[uid] = row;
             }
             row._content_label.label = message;
diff --git a/src/org.gnome.Polari.src.gresource.xml b/src/org.gnome.Polari.src.gresource.xml
index d11ce42..78da23f 100644
--- a/src/org.gnome.Polari.src.gresource.xml
+++ b/src/org.gnome.Polari.src.gresource.xml
@@ -18,6 +18,7 @@
     <file>resultList.js</file>
     <file>roomList.js</file>
     <file>roomStack.js</file>
+    <file>resultStack.js</file>
     <file>tabCompletion.js</file>
     <file>userList.js</file>
     <file>utils.js</file>
diff --git a/src/resultStack.js b/src/resultStack.js
new file mode 100644
index 0000000..5af34a2
--- /dev/null
+++ b/src/resultStack.js
@@ -0,0 +1,161 @@
+const Gio = imports.gi.Gio;
+const GLib = imports.gi.GLib;
+const GObject = imports.gi.GObject;
+const Gtk = imports.gi.Gtk;
+
+const AccountsMonitor = imports.accountsMonitor;
+const ChatroomManager = imports.chatroomManager;
+const ChatView = imports.chatView;
+const EntryArea = imports.entryArea;
+const Lang = imports.lang;
+
+const ResultStack = new Lang.Class({
+    Name: 'ResultStack',
+    Extends: Gtk.Stack,
+    Properties: {
+        'entry-area-height': GObject.ParamSpec.uint('entry-area-height',
+                                                    'entry-area-height',
+                                                    'entry-area-height',
+                                                    GObject.ParamFlags.READABLE,
+                                                    0, GLib.MAXUINT32, 0)
+    },
+
+    _init: function(params) {
+        this.parent(params);
+
+        this._sizeGroup = new Gtk.SizeGroup({ mode: Gtk.SizeGroupMode.VERTICAL });
+        this._rooms = {};
+
+        this._roomManager = 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));
+        this._roomManager.connect('active-state-changed',
+                                  Lang.bind(this, this._updateSensitivity));
+
+        this.add_named(new ChatPlaceholder(this._sizeGroup), 'placeholder');
+
+        this._entryAreaHeight = 0;
+        this._sizeGroup.get_widgets()[0].connect('size-allocate', Lang.bind(this,
+            function(w, rect) {
+                this._entryAreaHeight = rect.height - 1;
+                this.notify('entry-area-height');
+            }));
+    },
+
+    get entry_area_height() {
+        return this._entryAreaHeight;
+    },
+
+    _addView: function(id, view) {
+        this._rooms[id] = view;
+        this.add_named(view, id);
+    },
+
+    _roomAdded: function(roomManager, room) {
+        this._addView(room.id, new RoomView(room, this._sizeGroup));
+    },
+
+    _roomRemoved: function(roomManager, room) {
+        this._rooms[room.id].destroy();
+        delete this._rooms[room.id];
+    },
+
+    _activeRoomChanged: function(manager, room) {
+        this.set_visible_child_name(room ? room.id : 'placeholder');
+    },
+
+    _updateSensitivity: function() {
+        let room = this._roomManager.getActiveRoom();
+        if (!room)
+            return;
+        let sensitive = room && room.channel;
+        this._rooms[room.id].inputSensitive = sensitive;
+    }
+});
+
+const ChatPlaceholder = new Lang.Class({
+    Name: 'ChatPlaceholder',
+    Extends: Gtk.Overlay,
+
+    _init: function(sizeGroup) {
+        this._accountsMonitor = AccountsMonitor.getDefault();
+
+        let image = new Gtk.Image({ icon_name: 'org.gnome.Polari-symbolic',
+                                      pixel_size: 96, halign: Gtk.Align.END,
+                                      margin_end: 14 });
+
+        let title = new Gtk.Label({ use_markup: true, halign: Gtk.Align.START,
+                                    margin_start: 14 });
+        title.label = '<span letter_spacing="4500">%s</span>'.format(_("Polari"));
+        title.get_style_context().add_class('polari-background-title');
+
+        let description = new Gtk.Label({ label: _("Join a room using the + button."),
+                                          halign: Gtk.Align.CENTER, wrap: true,
+                                          margin_top: 24, use_markup: true });
+        description.get_style_context().add_class('polari-background-description');
+
+        let inputPlaceholder = new Gtk.Box({ valign: Gtk.Align.END });
+        sizeGroup.add_widget(inputPlaceholder);
+
+        this.parent();
+        let grid = new Gtk.Grid({ column_homogeneous: true, can_focus: false,
+                                  column_spacing: 18, hexpand: true, vexpand: true,
+                                  valign: Gtk.Align.CENTER });
+        grid.get_style_context().add_class('polari-background');
+        grid.attach(image, 0, 0, 1, 1);
+        grid.attach(title, 1, 0, 1, 1);
+        grid.attach(description, 0, 1, 2, 1);
+        this.add(grid);
+        this.add_overlay(inputPlaceholder);
+        this.show_all();
+    }
+});
+
+const RoomView = new Lang.Class({
+    Name: 'RoomView',
+    Extends: Gtk.Box,
+
+    _init: function(room, sizeGroup) {
+        this.parent({ orientation: Gtk.Orientation.VERTICAL });
+
+        // Delay mapping until shown, see
+        // https://bugzilla.gnome.org/show_bug.cgi?id=766737
+        this.set_child_visible(false);
+
+        this._view = new ChatView.ChatView(room);
+        this.add(this._view);
+
+        this._entryArea = new EntryArea.EntryArea({ room: room,
+                                                    sensitive: false });
+        this.add(this._entryArea);
+
+        this._view.bind_property('max-nick-chars',
+                                 this._entryArea, 'max-nick-chars',
+                                 GObject.BindingFlags.SYNC_CREATE);
+        sizeGroup.add_widget(this._entryArea);
+
+        this._view.connect('text-dropped', Lang.bind(this,
+            function(view, text) {
+               this._entryArea.pasteText(text, text.split('\n').length);
+            }));
+        this._view.connect('image-dropped', Lang.bind(this,
+            function(view, image) {
+               this._entryArea.pasteImage(image);
+            }));
+        this._view.connect('file-dropped', Lang.bind(this,
+            function(view, file) {
+               this._entryArea.pasteFile(file);
+            }));
+
+        this.show_all();
+    },
+
+    set inputSensitive(sensitive) {
+        this._entryArea.sensitive = sensitive;
+    }
+});


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