[polari/wip/fmuellner/combined-gsoc: 37/137] nicee!



commit 6284ef4a06cd5b80bc043b0903ef04432cfa67ea
Author: Kunaal Jain <kunaalus gmail com>
Date:   Tue Jul 19 02:55:10 2016 +0530

    nicee!

 data/resources/main-window.ui |    2 +-
 src/application.js            |    4 +-
 src/mainWindow.js             |    5 +-
 src/resultList.js             |   10 +++-
 src/resultStack.js            |  149 +++++------------------------------------
 src/resultView.js             |  116 ++++++++++++++++++++++++++++----
 6 files changed, 136 insertions(+), 150 deletions(-)
---
diff --git a/data/resources/main-window.ui b/data/resources/main-window.ui
index 18ca70d..f8f76af 100644
--- a/data/resources/main-window.ui
+++ b/data/resources/main-window.ui
@@ -309,7 +309,7 @@
                       </packing>
                     </child>
                     <child>
-                        <object class="Gjs_ResultView" id="resultscroll">
+                        <object class="Gjs_ResultStack" id="resultscroll">
                             <property name="visible">True</property>
                         </object>
                         <packing>
diff --git a/src/application.js b/src/application.js
index dd07e31..9d19de7 100644
--- a/src/application.js
+++ b/src/application.js
@@ -118,7 +118,9 @@ const Application = new Lang.Class({
             accels: ['<Alt><Shift>Up', '<Primary><Shift>Page_Up']},
           { name: 'search-terms',
             parameter_type: GLib.VariantType.new('s'),
-            state: GLib.Variant.new('s', '') }
+            state: GLib.Variant.new('s', '') },
+          { name: 'active-result-changed',
+            parameter_type: GLib.VariantType.new('(sus)') }
         ];
         actionEntries.forEach(Lang.bind(this,
             function(actionEntry) {
diff --git a/src/mainWindow.js b/src/mainWindow.js
index 5930664..803fbf9 100644
--- a/src/mainWindow.js
+++ b/src/mainWindow.js
@@ -21,6 +21,7 @@ const Pango = imports.gi.Pango;
 const ChatView = imports.chatView;
 const ResultList = imports.resultList;
 const ResultView = imports.resultView;
+const ResultStack = imports.resultStack;
 
 const CONFIGURE_TIMEOUT = 100; /* ms */
 
@@ -251,11 +252,11 @@ const MainWindow = new Lang.Class({
                 this._searchisActive = !this._searchisActive;
             }));
 
-        this._results.connect('row-activated', Lang.bind(this, this._rowactivated));
+        // this._results.connect('row-activated', Lang.bind(this, this._rowactivated));
         this._resultStack = this._resultscroll._view;
         print(this._resultStack);
         print(this._resultscroll);
-        this._resultscroll.connect('edge-reached', Lang.bind(this, this._onScroll));
+        // this._resultscroll.connect('edge-reached', Lang.bind(this, this._onScroll));
 
         //test
         this._logManager = LogManager.getDefault();
diff --git a/src/resultList.js b/src/resultList.js
index 7ebe122..3a9d7ab 100644
--- a/src/resultList.js
+++ b/src/resultList.js
@@ -170,6 +170,14 @@ const ResultList = new Lang.Class({
         this._cancellable  = new Gio.Cancellable();
     },
 
+    vfunc_row_selected: function(row) {
+        if(!row) return;
+        let rowSelectedAction = this._app.lookup_action('active-result-changed');
+        rowSelectedAction.activate(new GLib.Variant('(sus)', [row.uid, row.timestamp, row.channel]));
+        // if (row)
+        //     row.selected();
+    },
+
     _handleSearchChanged: function(group, actionName, value) {
         let text = value.deep_unpack();
 
@@ -200,7 +208,7 @@ const ResultList = new Lang.Class({
             row = this._widgetMap[uid];
             for (let j = 0; j < this._keywords.length; j++) {
                 // log(this._keywords[j]);
-                index = Math.min(index, message.indexOf(this._keywords[j]));
+            //    index = Math.min(index, message.indexOf(this._keywords[j]));
             //    message = message.replace( new RegExp( "(" + this._keywords[j] + ")" , 'gi' ),"<span 
font_weight='bold'>$1</span>");
                 // print(message);
             }
diff --git a/src/resultStack.js b/src/resultStack.js
index 5af34a2..3caff88 100644
--- a/src/resultStack.js
+++ b/src/resultStack.js
@@ -5,157 +5,44 @@ const Gtk = imports.gi.Gtk;
 
 const AccountsMonitor = imports.accountsMonitor;
 const ChatroomManager = imports.chatroomManager;
-const ChatView = imports.chatView;
-const EntryArea = imports.entryArea;
+const ResultView = imports.resultView;
 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._results = {};
 
-        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._app = Gio.Application.get_default();
+        this._activeResultAction = this._app.lookup_action('active-result-changed');
+        this._activeResultAction.connect('activate',
+                                          Lang.bind(this, this._activeResultChanged));
 
-        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._results[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];
+    _resultAdded: function(uid, timestamp, channel) {
+        this._addView(uid, new ResultView.ResultView(uid, timestamp, channel));
     },
 
-    _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();
+    _resultRemoved: function(row) {
+        this._results[row.uid].destroy();
+        delete this._results[row.uid];
     },
 
-    set inputSensitive(sensitive) {
-        this._entryArea.sensitive = sensitive;
+    _activeResultChanged: function(action, parameter) {
+        let [uid, timestamp, channel] = parameter.deep_unpack();
+        print(uid);
+        if(!this._results[uid])
+            this._resultAdded(uid, timestamp, channel);
+        this.set_visible_child_name(uid);
     }
 });
diff --git a/src/resultView.js b/src/resultView.js
index 3af9004..a1ae504 100644
--- a/src/resultView.js
+++ b/src/resultView.js
@@ -139,7 +139,7 @@ const ResultView = new Lang.Class({
     Name: 'ResultView',
     Extends: Gtk.ScrolledWindow,
 
-    _init: function() {
+    _init: function(uid, timestamp, channel) {
         //this.parent();
         print("HELLO");
         this.parent({ hscrollbar_policy: Gtk.PolicyType.NEVER, vexpand: true });
@@ -153,6 +153,9 @@ const ResultView = new Lang.Class({
         this.add(this._view);
         this.show_all();
 
+        this._logManager = LogManager.getDefault();
+        this._cancellable  = new Gio.Cancellable();
+
         this._active = false;
         this._toplevelFocus = false;
         this._fetchingBacklog = false;
@@ -172,6 +175,7 @@ const ResultView = new Lang.Class({
         this.connect('screen-changed',
                      Lang.bind(this, this._updateIndent));
         this.connect('scroll-event', Lang.bind(this, this._onScroll));
+        // this.connect('edge-reached', Lang.bind(this, this._onEdgeReached));
 
         this.vadjustment.connect('changed',
                                  Lang.bind(this, this._updateScroll));
@@ -187,7 +191,81 @@ const ResultView = new Lang.Class({
         this._scrollBottom = adj.upper - adj.page_size;
 
         this._hoverCursor = Gdk.Cursor.new(Gdk.CursorType.HAND1);
-
+        this._rowactivated(channel, timestamp);
+    },
+
+    _rowactivated: function(channel, timestamp) {
+        this._cancellable.cancel();
+        this._cancellable.reset();
+        let sparql = (
+            'select nie:plainTextContent(?msg) as ?message ' +
+            '       if (nmo:from(?msg) = nco:default-contact-me,' +
+            '           "%s", nco:nickname(nmo:from(?msg))) as ?sender ' +
+            // FIXME: how do we handle the "real" message type?
+            '       %d as ?messageType ' +
+            '       ?timestamp ' +
+            '{ ?msg a nmo:IMMessage; ' +
+            '       nie:contentCreated ?timestamp; ' +
+            '       nmo:communicationChannel ?chan . ' +
+            'BIND( ?timestamp - %s as ?timediff ) . ' +
+            // FIXME: filter by account
+            '  filter (nie:title (?chan) = "%s" && ?timediff >= 0) ' +
+            '} order by asc (?timediff)'
+        ).format(channel,
+                 Tp.ChannelTextMessageType.NORMAL,
+                 timestamp,
+                 channel);
+        log(sparql);
+        let sparql1 = (
+            'select nie:plainTextContent(?msg) as ?message ' +
+            '       if (nmo:from(?msg) = nco:default-contact-me,' +
+            '           "%s", nco:nickname(nmo:from(?msg))) as ?sender ' +
+            // FIXME: how do we handle the "real" message type?
+            '       %d as ?messageType ' +
+            '       ?timestamp ' +
+            '{ ?msg a nmo:IMMessage; ' +
+            '       nie:contentCreated ?timestamp; ' +
+            '       nmo:communicationChannel ?chan . ' +
+            'BIND( %s - ?timestamp as ?timediff ) . ' +
+            // FIXME: filter by account
+            '  filter (nie:title (?chan) = "%s" && ?timediff > 0) ' +
+            '} order by asc (?timediff)'
+        ).format(channel,
+                 Tp.ChannelTextMessageType.NORMAL,
+                 timestamp,
+                 channel);
+        // let logManager = LogManager.getDefault();
+        // this._logWalker = logManager.walkEvents(row,
+        //                                         row.channel);
+        //
+        // this._fetchingBacklog = true;
+        // this._logWalker.getEvents(10,
+        //                           Lang.bind(this, this._onLogEventsReady));
+        // this._logManager.query(sparql,this._cancellable,Lang.bind(this, this._onLogEventsReady));
+        // this._logManager.query(sparql1,this._cancellable,Lang.bind(this, this._onLogEventsReady1));
+        let buffer = this._view.get_buffer();
+        let iter = buffer.get_end_iter();
+        buffer.set_text("",-1);
+        this._endQuery = new LogManager.GenericQuery(this._logManager._connection, 20);
+        this._endQuery.run(sparql,this._cancellable,Lang.bind(this, this._onLogEventsReady1));
+        log("!");
+        this._startQuery = new LogManager.GenericQuery(this._logManager._connection, 20);
+        // Mainloop.timeout_add(500, Lang.bind(this,
+        //     function() {
+        //         query.run(sparql1,this._cancellable,Lang.bind(this, this._onLogEventsReady1));
+        //         return GLib.SOURCE_REMOVE;
+        //     }));
+        this._startQuery.run(sparql1,this._cancellable,Lang.bind(this, this._onLogEventsReady));
+        //print(this._endQuery.isClosed());
+
+        // Mainloop.timeout_add(5000, Lang.bind(this,
+        //     function() {
+        //         query.next(200,this._cancellable,Lang.bind(this, this._onLogEventsReady1));
+        //     }));
+        // query.next(20,this._cancellable,Lang.bind(this, this._onLogEventsReady1));
+
+        //this._resultStack.buffer.insert(iter,row._content_label.label, -1);
+        // this._resultStack.label = row._content_label.label;
     },
 
     _createTags: function() {
@@ -473,14 +551,19 @@ const ResultView = new Lang.Class({
 
     _onScroll: function(w, event) {
         let [hasDir, dir] = event.get_scroll_direction();
-        if (hasDir && dir != Gdk.ScrollDirection.UP)
+        if (hasDir && (dir != Gdk.ScrollDirection.UP || dir != Gdk.ScrollDirection.DOWN) )
             return Gdk.EVENT_PROPAGATE;
 
         let [hasDeltas, dx, dy] = event.get_scroll_deltas();
-        if (hasDeltas && dy >= 0)
-            return Gdk.EVENT_PROPAGATE;
+        // print(dx, dy);
+        if (hasDeltas)
+            this._fetchBacklog();
+        // if (dir == Gdk.ScrollDirection.UP )
+        //     print("UP");
+        // else if (dir == Gdk.ScrollDirection.DOWN)
+        //     print("DOWN");
 
-        return this._fetchBacklog();
+        //return this._fetchBacklog();
     },
 
     _onKeyPress: function(w, event) {
@@ -510,8 +593,8 @@ const ResultView = new Lang.Class({
     },
 
     _fetchBacklog: function() {
-        if (this.vadjustment.value != 0 ||
-            this._logWalker.isEnd())
+        if (this.vadjustment.value != 0 &&
+            this.vadjustment.value != this._scrollBottom)
             return Gdk.EVENT_PROPAGATE;
 
         if (this._fetchingBacklog)
@@ -519,12 +602,17 @@ const ResultView = new Lang.Class({
 
         this._fetchingBacklog = true;
         this._showLoadingIndicator();
-        Mainloop.timeout_add(500, Lang.bind(this,
-            function() {
-                this._logWalker.getEvents(NUM_LOG_EVENTS,
-                                          Lang.bind(this, this._onLogEventsReady));
-                return GLib.SOURCE_REMOVE;
-            }));
+
+        if (this.vadjustment.value == 0)
+            Mainloop.timeout_add(500, Lang.bind(this,
+                function() {
+                    this._startQuery.next(10,this._cancellable,Lang.bind(this, this._onLogEventsReady));
+                }));
+        else
+            Mainloop.timeout_add(500, Lang.bind(this,
+                function() {
+                    this._endQuery.next(10,this._cancellable,Lang.bind(this, this._onLogEventsReady1));
+                }));
         return Gdk.EVENT_STOP;
     },
 


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