[libgweather/benzea/pre-variant-backend-cleanups: 5/8] location-entry: Limit location searching to selected top node



commit 5624310ee93a8e7af407a5f5832638f456726d96
Author: Benjamin Berg <bberg redhat com>
Date:   Sun Apr 26 21:44:46 2020 +0200

    location-entry: Limit location searching to selected top node
    
    The top node may not be the a world node. So use the private top node
    instead and only try to do a country code based lookup if the top node
    is actually of level WORLD.

 libgweather/gweather-location-entry.c | 14 +++++++++-----
 1 file changed, 9 insertions(+), 5 deletions(-)
---
diff --git a/libgweather/gweather-location-entry.c b/libgweather/gweather-location-entry.c
index 6f5e7573..221a0f93 100644
--- a/libgweather/gweather-location-entry.c
+++ b/libgweather/gweather-location-entry.c
@@ -700,7 +700,11 @@ match_selected (GtkEntryCompletion *completion,
                GtkTreeIter        *iter,
                gpointer            entry)
 {
-    if (model != ((GWeatherLocationEntry *)entry)->priv->model) {
+    GWeatherLocationEntryPrivate *priv;
+
+    priv = ((GWeatherLocationEntry *)entry)->priv;
+
+    if (model != priv->model) {
        GeocodePlace *place;
        char *display_name;
        GeocodeLocation *loc;
@@ -714,10 +718,10 @@ match_selected (GtkEntryCompletion *completion,
                            -1);
 
        country_code = geocode_place_get_country_code (place);
-       if (country_code != NULL)
-           scope = gweather_location_find_by_country_code (gweather_location_get_world (), country_code);
-       else
-           scope = gweather_location_get_world ();
+       if (country_code != NULL && gweather_location_get_level (priv->top) == GWEATHER_LOCATION_WORLD)
+           scope = gweather_location_find_by_country_code (priv->top, country_code);
+       if (!scope)
+           scope = priv->top;
 
        loc = geocode_place_get_location (place);
        location = gweather_location_find_nearest_city (scope, geocode_location_get_latitude (loc), 
geocode_location_get_longitude (loc));


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