[gnome-clocks] Stop using gweather_location_get_children
- From: Bilal Elmoussaoui <bilelmoussaoui src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-clocks] Stop using gweather_location_get_children
- Date: Fri, 7 Jan 2022 17:23:44 +0000 (UTC)
commit 1a07a835d132a1e2e98102578c7262cece4ccfcb
Author: Maximiliano Sandoval R <msandova gnome org>
Date: Mon Dec 13 15:02:59 2021 +0100
Stop using gweather_location_get_children
See
https://gnome.pages.gitlab.gnome.org/libgweather/migrating-3to4.html#stop-using-gweather_location_get_children.
src/geocoding.vala | 44 +++++++++++++++++++++---------------------
src/search-provider.vala | 33 +++++++++++++++----------------
src/world-location-dialog.vala | 16 ++++++++-------
3 files changed, 47 insertions(+), 46 deletions(-)
---
diff --git a/src/geocoding.vala b/src/geocoding.vala
index c2b38200..42f94a31 100644
--- a/src/geocoding.vala
+++ b/src/geocoding.vala
@@ -102,28 +102,28 @@ public class Info : Object {
}
}
- // TODO GTK 4
- // var locations = location.get_children ();
- // for (int i = 0; i < locations.length; i++) {
- // if (locations[i].get_level () == GWeather.LocationLevel.CITY) {
- // if (locations[i].has_coords ()) {
- // double latitude, longitude, distance;
- //
- // locations[i].get_coords (out latitude, out longitude);
- // distance = get_distance (((GClue.Location) geo_location).latitude,
- // ((GClue.Location) geo_location).longitude,
- // latitude,
- // longitude);
- //
- // if (distance < minimal_distance) {
- // found_location = locations[i];
- // minimal_distance = distance;
- // }
- // }
- // }
- //
- // yield search_locations (locations[i]);
- // }
+ var loc = location.next_child (null);
+ while (loc != null) {
+ if (loc.get_level () == GWeather.LocationLevel.CITY) {
+ if (loc.has_coords ()) {
+ double latitude, longitude, distance;
+
+ loc.get_coords (out latitude, out longitude);
+ distance = get_distance (((GClue.Location) geo_location).latitude,
+ ((GClue.Location) geo_location).longitude,
+ latitude,
+ longitude);
+
+ if (distance < minimal_distance) {
+ found_location = loc;
+ minimal_distance = distance;
+ }
+ }
+ }
+
+ yield search_locations (loc);
+ loc = location.next_child (loc);
+ }
}
public bool is_location_similar (GWeather.Location location) {
diff --git a/src/search-provider.vala b/src/search-provider.vala
index 31b4bd36..7494fcf1 100644
--- a/src/search-provider.vala
+++ b/src/search-provider.vala
@@ -75,18 +75,18 @@ public class SearchProvider : Object {
private async void search_locations_recurse (GWeather.Location location, string[] normalized_terms,
GenericArray<GWeather.Location> matches) {
- // TODO GTK 4
- // var locations = location.get_children ();
- // foreach (var child_location in locations) {
- // var level = child_location.get_level ();
- // if (level == CITY || level == NAMED_TIMEZONE) {
- // if (location_matches (child_location, normalized_terms)) {
- // matches.add (child_location);
- // }
- // }
- //
- // yield search_locations_recurse (child_location, normalized_terms, matches);
- // }
+ var loc = location.next_child (null);
+ while (loc != null) {
+ var level = loc.get_level ();
+ if (level == CITY || level == NAMED_TIMEZONE) {
+ if (location_matches (loc, normalized_terms)) {
+ matches.add (loc);
+ }
+ }
+
+ yield search_locations_recurse (loc, normalized_terms, matches);
+ loc = location.next_child (loc);
+ }
}
private async string[] search_locations (string[] normalized_terms) {
@@ -104,11 +104,10 @@ public class SearchProvider : Object {
string[] result = {};
matches.foreach ((location) => {
// FIXME: Avoid cities without children locations
- // TODO GTK 4
- // if (location.get_level () == GWeather.LocationLevel.CITY &&
- // location.get_children ().length == 0) {
- // return;
- // }
+ if (location.get_level () == GWeather.LocationLevel.CITY &&
+ location.next_child (null) == null) {
+ return;
+ }
// HACK: the search provider interface does not currently allow variants as result IDs
result += serialize_location (location);
});
diff --git a/src/world-location-dialog.vala b/src/world-location-dialog.vala
index b4859918..aefdf9ef 100644
--- a/src/world-location-dialog.vala
+++ b/src/world-location-dialog.vala
@@ -174,13 +174,15 @@ private class LocationDialog : Gtk.Window {
default:
break;
}
- // TODO GTK 4
- // foreach (var child in location.get_children ()) {
- // query_locations (child, search);
- // if (locations.get_n_items () >= RESULT_COUNT_LIMIT) {
- // return;
- // }
- // }
+
+ var loc = location.next_child (null);
+ while (loc != null) {
+ query_locations (loc, search);
+ if (locations.get_n_items () >= RESULT_COUNT_LIMIT) {
+ return;
+ }
+ loc = location.next_child (loc);
+ }
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]