[polari/wip/fmuellner/combined-gsoc: 37/136] update



commit bc8f72732d8585d95660e78b166371a418d458fa
Author: Kunaal Jain <kunaalus gmail com>
Date:   Mon Jul 18 13:06:30 2016 +0530

    update

 data/resources/main-window.ui |    2 +-
 src/application.js            |    5 +-
 src/mainWindow.js             |   23 +++--
 src/resultList.js             |  246 ++++++++++++++++++++++++++++++++++++++++-
 4 files changed, 262 insertions(+), 14 deletions(-)
---
diff --git a/data/resources/main-window.ui b/data/resources/main-window.ui
index 3e2a7ea..18ca70d 100644
--- a/data/resources/main-window.ui
+++ b/data/resources/main-window.ui
@@ -265,7 +265,7 @@
                     <property name="vexpand">True</property>
                     <property name="hexpand">True</property>
                     <child>
-                  <object class="GtkListBox" id="results">
+                  <object class="Gjs_ResultList" id="results">
                     <property name="visible">True</property>
                     <property name="selection-mode">browse</property>
                         <style>
diff --git a/src/application.js b/src/application.js
index b98389b..dd07e31 100644
--- a/src/application.js
+++ b/src/application.js
@@ -115,7 +115,10 @@ const Application = new Lang.Class({
           { name: 'next-pending-room',
             accels: ['<Alt><Shift>Down', '<Primary><Shift>Page_Down']},
           { name: 'previous-pending-room',
-            accels: ['<Alt><Shift>Up', '<Primary><Shift>Page_Up']}
+            accels: ['<Alt><Shift>Up', '<Primary><Shift>Page_Up']},
+          { name: 'search-terms',
+            parameter_type: GLib.VariantType.new('s'),
+            state: GLib.Variant.new('s', '') }
         ];
         actionEntries.forEach(Lang.bind(this,
             function(actionEntry) {
diff --git a/src/mainWindow.js b/src/mainWindow.js
index d19f242..5930664 100644
--- a/src/mainWindow.js
+++ b/src/mainWindow.js
@@ -216,13 +216,13 @@ const MainWindow = new Lang.Class({
         this._keywords = [];
         this._cancellable  = new Gio.Cancellable();
         this._widgetMap = {};
-        Utils.initActions(this,
-                         [
-                          { name: 'search-active',
-                            activate: this._toggleSearch,
-                            parameter_type: new GLib.VariantType('b'),
-                            state: new GLib.Variant('b', false) }
-                         ]);
+        // Utils.initActions(this,
+        //                  [
+        //                   { name: 'search-active',
+        //                     activate: this._toggleSearch,
+        //                     parameter_type: new GLib.VariantType('b'),
+        //                     state: new GLib.Variant('b', false) }
+        //                  ]);
         this.bind_property('search-active', this._search_active_button, 'active',
                            GObject.BindingFlags.SYNC_CREATE |
                            GObject.BindingFlags.BIDIRECTIONAL);
@@ -330,10 +330,10 @@ const MainWindow = new Lang.Class({
         let buffer = this._resultStack.get_buffer();
         let iter = buffer.get_end_iter();
         buffer.set_text("",-1);
-        this._endQuery = new LogManager.GenericQuery(this._logManager._connection, 25);
+        this._endQuery = new LogManager.GenericQuery(this._logManager._connection, 10);
         this._endQuery.run(sparql,this._cancellable,Lang.bind(this, this._onLogEventsReady));
         log("!");
-        this._startQuery = new LogManager.GenericQuery(this._logManager._connection, 25);
+        this._startQuery = new LogManager.GenericQuery(this._logManager._connection, 15);
         // Mainloop.timeout_add(500, Lang.bind(this,
         //     function() {
         //         query.run(sparql1,this._cancellable,Lang.bind(this, this._onLogEventsReady1));
@@ -467,6 +467,11 @@ const MainWindow = new Lang.Class({
     },
 
     _handleSearchChanged: function(entry) {
+        let text = entry.get_text().replace(/^\s+|\s+$/g, '');
+        let app = this.application;
+        let action = app.lookup_action('search-terms');
+        action.change_state(GLib.Variant.new('s', text));
+        return;
         this._cancellable.cancel();
         this._cancellable.reset();
 //         if(text!='' && this._searchActive) {
diff --git a/src/resultList.js b/src/resultList.js
index 3110162..7ebe122 100644
--- a/src/resultList.js
+++ b/src/resultList.js
@@ -6,6 +6,7 @@ const Gtk = imports.gi.Gtk;
 const Pango = imports.gi.Pango;
 const Tp = imports.gi.TelepathyGLib;
 
+const LogManager = imports.logManager;
 const AccountsMonitor = imports.accountsMonitor;
 const ChatroomManager = imports.chatroomManager;
 const Lang = imports.lang;
@@ -16,10 +17,15 @@ const ResultRow = new Lang.Class({
     Template: 'resource:///org/gnome/Polari/ui/result-list-row.ui',
     InternalChildren: ['box1', 'source_name', 'short_time_label', 'content_label'],
 
-    _init: function(message, uid) {
+    _init: function(event) {
         this.parent();
-
-        this._uid = uid;
+        this._source_name.label = event.chan.substring(1);
+        this._short_time_label.label = this._formatTimestamp(event.timestamp);
+        this.uid = event.id;
+        this.channel = event.chan;
+        this.nickname = event.chan;
+        this.timestamp = event.timestamp;
+        this.rawmessage = event.mms;
 
         // this._icon.gicon = room.icon;
         // this._icon.visible = room.icon != null;
@@ -62,5 +68,239 @@ const ResultRow = new Lang.Class({
         // this._showPopover();
 
         return Gdk.EVENT_STOP;
+    },
+
+    _formatTimestamp: function(timestamp) {
+        let date = GLib.DateTime.new_from_unix_local(timestamp);
+        let now = GLib.DateTime.new_now_local();
+
+        // 00:01 actually, just to be safe
+        let todayMidnight = GLib.DateTime.new_local(now.get_year(),
+                                                    now.get_month(),
+                                                    now.get_day_of_month(),
+                                                    0, 1, 0);
+        let dateMidnight = GLib.DateTime.new_local(date.get_year(),
+                                                   date.get_month(),
+                                                   date.get_day_of_month(),
+                                                   0, 1, 0);
+        let daysAgo = todayMidnight.difference(dateMidnight) / GLib.TIME_SPAN_DAY;
+
+        let format;
+        let desktopSettings = new Gio.Settings({ schema_id: 'org.gnome.desktop.interface' });
+        let clockFormat = desktopSettings.get_string('clock-format');
+        let hasAmPm = date.format('%p') != '';
+
+        if (clockFormat == '24h' || !hasAmPm) {
+            if(daysAgo < 1) { // today
+                /* Translators: Time in 24h format */
+                format = _("%H\u2236%M");
+            } else if(daysAgo <2) { // yesterday
+                /* Translators: this is the word "Yesterday" followed by a
+                 time string in 24h format. i.e. "Yesterday, 14:30" */
+                // xgettext:no-c-format
+                format = _("Yesterday, %H\u2236%M");
+            } else if (daysAgo < 7) { // this week
+                /* Translators: this is the week day name followed by a time
+                 string in 24h format. i.e. "Monday, 14:30" */
+                // xgettext:no-c-format
+                format = _("%A, %H\u2236%M");
+            } else if (date.get_year() == now.get_year()) { // this year
+                /* Translators: this is the month name and day number
+                 followed by a time string in 24h format.
+                 i.e. "May 25, 14:30" */
+                // xgettext:no-c-format
+                format = _("%B %d, %H\u2236%M");
+            } else { // before this year
+                /* Translators: this is the month name, day number, year
+                 number followed by a time string in 24h format.
+                 i.e. "May 25 2012, 14:30" */
+                // xgettext:no-c-format
+                format = _("%B %d %Y, %H\u2236%M");
+            }
+        } else {
+            if(daysAgo < 1) { // today
+                /* Translators: Time in 12h format */
+                format = _("%l\u2236%M %p");
+            } else if(daysAgo <2) { // yesterday
+                /* Translators: this is the word "Yesterday" followed by a
+                 time string in 12h format. i.e. "Yesterday, 2:30 pm" */
+                // xgettext:no-c-format
+                format = _("Yesterday, %l\u2236%M %p");
+            } else if (daysAgo < 7) { // this week
+                /* Translators: this is the week day name followed by a time
+                 string in 12h format. i.e. "Monday, 2:30 pm" */
+                // xgettext:no-c-format
+                format = _("%A, %l\u2236%M %p");
+            } else if (date.get_year() == now.get_year()) { // this year
+                /* Translators: this is the month name and day number
+                 followed by a time string in 12h format.
+                 i.e. "May 25, 2:30 pm" */
+                // xgettext:no-c-format
+                format = _("%B %d, %l\u2236%M %p");
+            } else { // before this year
+                /* Translators: this is the month name, day number, year
+                 number followed by a time string in 12h format.
+                 i.e. "May 25 2012, 2:30 pm"*/
+                // xgettext:no-c-format
+                format = _("%B %d %Y, %l\u2236%M %p");
+            }
+        }
+
+        return date.format(format);
+    }
+});
+
+const ResultList = new Lang.Class({
+    Name: 'ResultList',
+    Extends: Gtk.ListBox,
+
+    _init: function(params) {
+        this.parent(params);
+        this._app = Gio.Application.get_default();
+        this._logManager = LogManager.getDefault();
+
+        //this.connect('row-activated', Lang.bind(this, this._rowactivated));
+        this._resultRows = {};
+        this._widgetMap = {};
+        //this._keywordsAction = app.lookup_action('search-terms');
+        this._app.connect('action-state-changed::search-terms', Lang.bind(this,
+                          this._handleSearchChanged));
+
+        this._keywords = [];
+        this._cancellable  = new Gio.Cancellable();
+    },
+
+    _handleSearchChanged: function(group, actionName, value) {
+        let text = value.deep_unpack();
+
+        if(text == '') return;
+
+        this._cancellable.cancel();
+        this._cancellable.reset();
+
+        this._keywords = text == '' ? [] : text.split(/\s+/);
+        log(text);
+        let query = ('select ?text as ?mms ?msg as ?id ?chan as ?chan ?timestamp as ?timestamp ' +
+                      'where { ?msg a nmo:IMMessage . ?msg nie:plainTextContent ?text . ?msg fts:match "%s*" 
. ' +
+                      '?msg nmo:communicationChannel ?channel. ?channel nie:title ?chan. ' +
+                      '?msg nie:contentCreated ?timestamp }'
+                     ).format(text);
+        log(query);
+        this._logManager.query(query,this._cancellable,Lang.bind(this, this._handleResults));
+    },
+
+    _handleResults: function(events) {
+        log(events.length);
+        let widgetMap = {};
+        let markup_message = '';
+        for (let i = 0; i < events.length; i++) {
+            let message = GLib.markup_escape_text(events[i].mms, -1);
+            let uid = events[i].id;
+            let row;
+            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]));
+            //    message = message.replace( new RegExp( "(" + this._keywords[j] + ")" , 'gi' ),"<span 
font_weight='bold'>$1</span>");
+                // print(message);
+            }
+
+            if (row) {
+                widgetMap[uid] = row;
+                this.remove(row);
+            } else {
+                row = new ResultRow(events[i]);
+                widgetMap[uid] = row;
+            }
+            row._content_label.label = message;
+        }
+
+        this._widgetMap = widgetMap;
+
+        this.foreach(r => { r.destroy(); })
+
+        for (let i = 0; i < events.length; i++) {
+            let row = this._widgetMap[events[i].id];
+            this.add(row);
+        }
+    },
+
+    _formatTimestamp: function(timestamp) {
+        let date = GLib.DateTime.new_from_unix_local(timestamp);
+        let now = GLib.DateTime.new_now_local();
+
+        // 00:01 actually, just to be safe
+        let todayMidnight = GLib.DateTime.new_local(now.get_year(),
+                                                    now.get_month(),
+                                                    now.get_day_of_month(),
+                                                    0, 1, 0);
+        let dateMidnight = GLib.DateTime.new_local(date.get_year(),
+                                                   date.get_month(),
+                                                   date.get_day_of_month(),
+                                                   0, 1, 0);
+        let daysAgo = todayMidnight.difference(dateMidnight) / GLib.TIME_SPAN_DAY;
+
+        let format;
+        let desktopSettings = new Gio.Settings({ schema_id: 'org.gnome.desktop.interface' });
+        let clockFormat = desktopSettings.get_string('clock-format');
+        let hasAmPm = date.format('%p') != '';
+
+        if (clockFormat == '24h' || !hasAmPm) {
+            if(daysAgo < 1) { // today
+                /* Translators: Time in 24h format */
+                format = _("%H\u2236%M");
+            } else if(daysAgo <2) { // yesterday
+                /* Translators: this is the word "Yesterday" followed by a
+                 time string in 24h format. i.e. "Yesterday, 14:30" */
+                // xgettext:no-c-format
+                format = _("Yesterday, %H\u2236%M");
+            } else if (daysAgo < 7) { // this week
+                /* Translators: this is the week day name followed by a time
+                 string in 24h format. i.e. "Monday, 14:30" */
+                // xgettext:no-c-format
+                format = _("%A, %H\u2236%M");
+            } else if (date.get_year() == now.get_year()) { // this year
+                /* Translators: this is the month name and day number
+                 followed by a time string in 24h format.
+                 i.e. "May 25, 14:30" */
+                // xgettext:no-c-format
+                format = _("%B %d, %H\u2236%M");
+            } else { // before this year
+                /* Translators: this is the month name, day number, year
+                 number followed by a time string in 24h format.
+                 i.e. "May 25 2012, 14:30" */
+                // xgettext:no-c-format
+                format = _("%B %d %Y, %H\u2236%M");
+            }
+        } else {
+            if(daysAgo < 1) { // today
+                /* Translators: Time in 12h format */
+                format = _("%l\u2236%M %p");
+            } else if(daysAgo <2) { // yesterday
+                /* Translators: this is the word "Yesterday" followed by a
+                 time string in 12h format. i.e. "Yesterday, 2:30 pm" */
+                // xgettext:no-c-format
+                format = _("Yesterday, %l\u2236%M %p");
+            } else if (daysAgo < 7) { // this week
+                /* Translators: this is the week day name followed by a time
+                 string in 12h format. i.e. "Monday, 2:30 pm" */
+                // xgettext:no-c-format
+                format = _("%A, %l\u2236%M %p");
+            } else if (date.get_year() == now.get_year()) { // this year
+                /* Translators: this is the month name and day number
+                 followed by a time string in 12h format.
+                 i.e. "May 25, 2:30 pm" */
+                // xgettext:no-c-format
+                format = _("%B %d, %l\u2236%M %p");
+            } else { // before this year
+                /* Translators: this is the month name, day number, year
+                 number followed by a time string in 12h format.
+                 i.e. "May 25 2012, 2:30 pm"*/
+                // xgettext:no-c-format
+                format = _("%B %d %Y, %l\u2236%M %p");
+            }
+        }
+
+        return date.format(format);
     }
 });
diff --git a/src/searchManager.js b/src/searchManager.js
new file mode 100644
index 0000000..e69de29


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