diff --git a/src/app/city.js b/src/app/city.js
index 1804443db95f0cf69f22fb8b19ac7d4e1476814a..9800e84f44622ea4fc7b46a19a6f906adfece0da 100644
--- a/src/app/city.js
+++ b/src/app/city.js
@@ -189,7 +189,7 @@ export const WeatherWidget = GObject.registerClass({
update(info) {
this._info = info;
- const label = Util.getNameAndCountry(info.location);
+ const label = Util.getCityAndStateAndCountry(info.location);
this._placesButton.set_label(label.join(', '));
this._worldView.refilter();
diff --git a/src/app/locationRow.js b/src/app/locationRow.js
index 87a528f0a11dad2cb1d1600cd88554f918fca109..b2286204ecad0d80b20438496a6245bdf5fcd5f3 100644
--- a/src/app/locationRow.js
+++ b/src/app/locationRow.js
@@ -5,9 +5,9 @@ import GLib from 'gi://GLib';
export const LocationRow = GObject.registerClass({
CssName: 'WeatherLocationRow',
Template: GLib.Uri.resolve_relative(import.meta.url, './locationRow.ui', 0),
- InternalChildren: ['label', 'countryLabel', 'labelContainer', 'locationIcon', 'currentIcon'],
+ InternalChildren: ['label', 'stateLabel', 'countryLabel', 'labelContainer', 'locationIcon', 'currentIcon'],
}, class LocationRow extends Gtk.Widget {
- constructor({ name, countryName, isSelected = false, isCurrentLocation = false }) {
+ constructor({ name, stateName, countryName, isSelected = false, isCurrentLocation = false }) {
super({ widthRequest: 320 });
Object.assign(this.layoutManager, {
@@ -15,6 +15,7 @@ export const LocationRow = GObject.registerClass({
});
this.name = name;
+ this.stateName = stateName ?? '';
this.countryName = countryName ?? '';
this.isSelected = isSelected;
this.isCurrentLocation = isCurrentLocation;
@@ -24,6 +25,10 @@ export const LocationRow = GObject.registerClass({
this._label.label = name;
}
+ set stateName(name) {
+ this._stateLabel.label = name;
+ }
+
set countryName(name) {
this._countryLabel.label = name;
}
diff --git a/src/app/locationRow.ui b/src/app/locationRow.ui
index dcc1d38d5343240c79604ea71e5db8a8d9925c8e..9af4160866d9e8fa202e2d89aeb552a53e0281f4 100644
--- a/src/app/locationRow.ui
+++ b/src/app/locationRow.ui
@@ -19,6 +19,17 @@
+
+
+
-
\ No newline at end of file
+
diff --git a/src/app/world.js b/src/app/world.js
index 16f5c27646a07b982129e0f985cced952c4b1074..bd655d30d6236fb1908d0114e94b869944bfbaf0 100644
--- a/src/app/world.js
+++ b/src/app/world.js
@@ -130,13 +130,13 @@ export class WorldContentView extends Gtk.Popover {
}
_buildLocation(model, info) {
- if (!info) return new LocationRow({ name: '', countryName: '' });;
+ if (!info) return new LocationRow({ name: '', stateName: '', countryName: '' });;
let location = info.location;
- const [name, countryName = ''] = Util.getNameAndCountry(location);
+ const [name, stateName = '', countryName = ''] = Util.getCityAndStateAndCountry(location);
- const grid = new LocationRow({ name, countryName, isSelected: model.isSelectedLocation(info), isCurrentLocation: model.isCurrentLocation(info) });
+ const grid = new LocationRow({ name, stateName, countryName, isSelected: model.isSelectedLocation(info), isCurrentLocation: model.isCurrentLocation(info) });
const row = new Gtk.ListBoxRow({ child: grid });
row._info = info;
return row;
diff --git a/src/misc/util.js b/src/misc/util.js
index 5ff9e312c58b132394408cae34001c05a04c7ceb..6412af55c6ed998e1a483d93ddad1195afa75811 100644
--- a/src/misc/util.js
+++ b/src/misc/util.js
@@ -192,6 +192,44 @@ function getNameAndCountry(location) {
return [location.get_name()];
}
+/**
+ * Get city, state and country name for the provided location.
+ *
+ * GWeather.Location Documentation: https://gnome.pages.gitlab.gnome.org/libgweather/class.Location.html
+ *
+ * @param {Object} GWeather.Location
+ *
+ * @return {[String, String, String]} City, State, Country
+ */
+function getCityAndStateAndCountry(location) {
+ let cityName, stateName, countryName;
+
+ cityName = location.get_name();
+
+ let state = location.get_parent();
+ while (state && state.get_level() > GWeather.LocationLevel.ADM1) {
+ state = state.get_parent();
+ }
+
+ if (state) {
+ stateName = state.get_name();
+ } else {
+ stateName = "";
+ }
+
+ let country = location.get_parent();
+ while (country && country.get_level() > GWeather.LocationLevel.COUNTRY)
+ country = country.get_parent();
+
+ if (country) {
+ countryName = country.get_name();
+ } else {
+ countryName = "";
+ }
+
+ return [cityName, stateName, countryName];
+}
+
export {
loadUI,
formatTemperature,
@@ -211,5 +249,6 @@ export {
easeOutCubic,
getEnabledProviders,
getWeatherConditions,
- getNameAndCountry
-}
\ No newline at end of file
+ getNameAndCountry,
+ getCityAndStateAndCountry
+}