[gnome-maps/wip/completion: 3/3] Add cancellable to geocode search



commit cb6f852f7b1b5cbb88fc58e27116e718a5e194e4
Author: Jonas Danielsson <jonas threetimestwo org>
Date:   Tue Dec 2 01:26:33 2014 -0500

    Add cancellable to geocode search
    
    https://bugzilla.gnome.org/show_bug.cgi?id=739036

 src/geocodeService.js |    4 ++--
 src/placeEntry.js     |    7 ++++++-
 2 files changed, 8 insertions(+), 3 deletions(-)
---
diff --git a/src/geocodeService.js b/src/geocodeService.js
index e5e1df1..6b6e919 100644
--- a/src/geocodeService.js
+++ b/src/geocodeService.js
@@ -32,7 +32,7 @@ const GeocodeService = new Lang.Class({
 
     _init: function() { },
 
-    search: function(string, bbox, callback) {
+    search: function(string, bbox, cancellable, callback) {
         let answerCount = Application.settings.get('max-search-results');
         let forward     = Geocode.Forward.new_for_string(string);
 
@@ -46,7 +46,7 @@ const GeocodeService = new Lang.Class({
         }
         forward.bounded = false;
         forward.set_answer_count(answerCount);
-        forward.search_async(null, function(forward, res) {
+        forward.search_async(cancellable, function(forward, res) {
             try {
                 let places = forward.search_finish(res);
                 callback(places);
diff --git a/src/placeEntry.js b/src/placeEntry.js
index 814ed73..461a01a 100644
--- a/src/placeEntry.js
+++ b/src/placeEntry.js
@@ -24,6 +24,7 @@
 const GLib = imports.gi.GLib;
 const GObject = imports.gi.GObject;
 const Geocode = imports.gi.GeocodeGlib;
+const Gio = imports.gi.Gio;
 const Gtk = imports.gi.Gtk;
 const Lang = imports.lang;
 
@@ -105,6 +106,9 @@ const PlaceEntry = new Lang.Class({
         this._popover = this._createPopover(numVisible, maxChars);
         this.connect('activate', this._onActivate.bind(this));
         this.connect('changed', (function() {
+            if (this._cancellable)
+                this._cancellable.cancel();
+
             if (this.text.length === 0) {
                 this._popover.hide();
                 this.place = null;
@@ -211,7 +215,8 @@ const PlaceEntry = new Lang.Class({
         let bbox = this._mapView.view.get_bounding_box();
 
         this._popover.showSpinner();
-        Application.geocodeService.search(this.text, bbox, (function(places) {
+        this._cancellable = new Gio.Cancellable();
+        Application.geocodeService.search(this.text, bbox, this._cancellable, (function(places) {
             if (!places) {
                 this.place = null;
                 this._popover.hide();


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