[gnome-weather] SearchProvider: hook up LaunchSearch



commit 60c70887af247803dc82987f21a878221e0481c1
Author: Giovanni Campagna <gcampagna src gnome org>
Date:   Fri Mar 6 19:07:56 2015 -0800

    SearchProvider: hook up LaunchSearch
    
    By showing the default search view prefilled with the search
    terms.
    
    Otherwise the user might be wondering why clicking in the search
    icon in the shell does nothing.

 src/app/main.js               |   15 +++++++++++-
 src/app/window.js             |   45 ++++++++++++++++++++++++++++------------
 src/service/searchProvider.js |    4 ++-
 src/shared/world.js           |    4 +++
 4 files changed, 51 insertions(+), 17 deletions(-)
---
diff --git a/src/app/main.js b/src/app/main.js
index 653c41e..9fcde7a 100644
--- a/src/app/main.js
+++ b/src/app/main.js
@@ -64,6 +64,13 @@ const Application = new Lang.Class({
         win.showInfo(info, false);
     },
 
+    _onShowSearch: function(action, parameter) {
+        let text = parameter.deep_unpack();
+        let win = this._createWindow();
+
+        win.showSearch(text);
+    },
+
     _initAppMenu: function() {
         let builder = new Gtk.Builder();
         builder.add_from_resource('/org/gnome/Weather/Application/app-menu.ui');
@@ -100,7 +107,10 @@ const Application = new Lang.Class({
                             activate: this._onQuit },
                           { name: 'show-location',
                             activate: this._onShowLocation,
-                            parameter_type: new GLib.VariantType('v') }]);
+                            parameter_type: new GLib.VariantType('v') },
+                          { name: 'show-search',
+                            activate: this._onShowSearch,
+                            parameter_type: new GLib.VariantType('s') }]);
 
         let gwSettings = new Gio.Settings({ schema_id: 'org.gnome.GWeather' });
         this.add_action(gwSettings.create_action('temperature-unit'));
@@ -141,7 +151,8 @@ const Application = new Lang.Class({
     },
 
     vfunc_activate: function() {
-        this._createWindow();
+        let win = this._createWindow();
+        win.showDefault();
     },
 
     vfunc_shutdown: function() {
diff --git a/src/app/window.js b/src/app/window.js
index 78007b2..945a33d 100644
--- a/src/app/window.js
+++ b/src/app/window.js
@@ -68,10 +68,10 @@ const MainWindow = new Lang.Class({
 
         this._model = this._worldView.model;
 
-        let initialGrid = builder.get_object('initial-grid');
+        this._searchView = builder.get_object('initial-grid');
 
-        let initialGridLocEntry = builder.get_object('initial-grid-location-entry');
-        initialGridLocEntry.connect('notify::location', Lang.bind(this, this._initialLocationChanged));
+        this._searchEntry = builder.get_object('initial-grid-location-entry');
+        this._searchEntry.connect('notify::location', Lang.bind(this, this._searchLocationChanged));
 
         let placesButton = builder.get_object('places-button');
         this._pageWidgets[Page.CITY].push(placesButton);
@@ -87,24 +87,20 @@ const MainWindow = new Lang.Class({
                                                 vexpand: true });
         this._stack.add(this._cityView);
 
-        this._stack.set_visible_child(initialGrid);
+        this._stack.set_visible_child(this._searchView);
 
         this.add(grid);
         grid.show_all();
 
         for (let i = 0; i < this._pageWidgets[Page.CITY].length; i++)
             this._pageWidgets[Page.CITY][i].hide();
-
-        let autoLocation = this.application.currentLocationController.autoLocation;
-        if (!autoLocation)
-            this.showInfo(this._model.getRecent(), false);
     },
 
     update: function() {
         this._cityView.update();
     },
 
-    _initialLocationChanged: function(entry) {
+    _searchLocationChanged: function(entry) {
         if (entry.location) {
             let info = this._model.addNewLocation(entry.location, false);
             this.showInfo(info, false);
@@ -148,8 +144,23 @@ const MainWindow = new Lang.Class({
         this._header.subtitle = subtitle;
     },
 
-    showSearch: function() {
+    showDefault: function() {
+        let clc = this.application.currentLocationController;
+        let autoLocation = clc.autoLocation;
+        let currentLocation = clc.currentLocation;
+        if (currentLocation)
+            this.showInfo(this._model.getCurrentLocation(), false);
+        else if (!autoLocation)
+            this.showInfo(this._model.getRecent(), false);
+    },
+
+    showSearch: function(text) {
+        this._cityView.disconnectClock();
+        this._stack.set_visible_child(this._searchView);
         this._goToPage(Page.SEARCH);
+        this._searchEntry.text = text;
+        if (text.length > 0)
+            this._searchEntry.get_completion().complete();
     },
 
     showInfo: function(info, isCurrentLocation) {
@@ -157,12 +168,18 @@ const MainWindow = new Lang.Class({
             return;
 
         /*
-         * Only show location updates if we have no loaded info or if we are
-         * currently showing the previous current location.
+         * Only show location updates if we have no loaded info and no
+         * search text or if we are currently showing the previous
+         * current location.
          */
         if (isCurrentLocation) {
-            if (this._cityView.info && !this._cityView.info._isCurrentLocation)
-                return;
+            if (this._currentPage == Page.CITY) {
+                if (!this._cityView.info._isCurrentLocation)
+                    return;
+            } else if (this._currentPage == Page.SEARCH) {
+                if (this._searchEntry.text.length > 0)
+                    return;
+            }
         }
 
         this.currentInfo = info;
diff --git a/src/service/searchProvider.js b/src/service/searchProvider.js
index 2fb8021..bf8c1fd 100644
--- a/src/service/searchProvider.js
+++ b/src/service/searchProvider.js
@@ -243,6 +243,8 @@ const SearchProvider = new Lang.Class({
     },
 
     LaunchSearch: function(terms, timestamp) {
-        // not implemented
+        this._app.hold();
+
+        this._activateAction('show-search', new GLib.Variant('s', terms.join(' ')), timestamp);
     },
 });
diff --git a/src/shared/world.js b/src/shared/world.js
index b8bdfa1..7d1caec 100644
--- a/src/shared/world.js
+++ b/src/shared/world.js
@@ -72,6 +72,10 @@ const WorldModel = new Lang.Class({
         return this._infoList[index];
     },
 
+    getCurrentLocation: function() {
+        return this._currentLocationInfo;
+    },
+
     currentLocationChanged: function(location) {
         if (!location)
             return;


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