[libgweather/ebassi/issue-161] location: Add getter for time zone name
- From: Emmanuele Bassi <ebassi src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libgweather/ebassi/issue-161] location: Add getter for time zone name
- Date: Thu, 13 Jan 2022 02:58:00 +0000 (UTC)
commit d801ca3b3b6b1cf80203baec454a9f6dc4ae7083
Author: Emmanuele Bassi <ebassi gnome org>
Date: Thu Jan 13 02:41:02 2022 +0000
location: Add getter for time zone name
When I removed GWeatherTimezone I inadvertedly missed the only
functionality that the type provided on top of GTimeZone, and that
is: the ability to retrieve the human readable, localised name of the
time zone bound to a location. That information does not exist in the
time zone database as parsed by GLib, but it is available in GWeather's
location database. This means we need to retrieve the time zone reference
from the location's database, just like we do for
gweather_location_get_timezone(), and from that reference we retrieve the
localised string with the time zone name.
The old GWeather-3 API allowed retrieving the name for any given
GWeatherTimezone, but since all time zones are bound to a location, we can
skip that particular aspect of the API.
Fixes: #161
libgweather/gweather-location.c | 43 +++++++++++++++++++++++++++++++++++++++++
libgweather/gweather-location.h | 2 ++
2 files changed, 45 insertions(+)
---
diff --git a/libgweather/gweather-location.c b/libgweather/gweather-location.c
index 0ad5adcf..da0971e0 100644
--- a/libgweather/gweather-location.c
+++ b/libgweather/gweather-location.c
@@ -1063,6 +1063,49 @@ gweather_location_get_timezone_str (GWeatherLocation *loc)
return NULL;
}
+/**
+ * gweather_location_get_timezone_name:
+ * @loc: the location to query
+ *
+ * Retrieves the human readable, localized name of the timezone available
+ * at the given location, if any.
+ *
+ * Returns: (transfer none) (nullable): the human readable name of the
+ * location's timezone
+ */
+const char *
+gweather_location_get_timezone_name (GWeatherLocation *loc)
+{
+ g_autoptr (GWeatherLocation) s = NULL;
+
+ g_return_val_if_fail (GWEATHER_IS_LOCATION (loc), NULL);
+
+ ITER_UP (loc, s) {
+ if (s->db && IDX_VALID (s->tz_hint_idx)) {
+ DbWorldTimezonesEntryRef entry_ref =
+ db_world_timezones_get_at (s->db->timezones_ref,
+ s->tz_hint_idx);
+ DbTimezoneRef ref = db_world_timezones_entry_get_value (entry_ref);
+ DbI18nRef tz_name = db_timezone_get_name (ref);
+
+ const char *name = EMPTY_TO_NULL (db_i18n_get_str (tz_name));
+ const char *msgctxt = EMPTY_TO_NULL (db_i18n_get_msgctxt (tz_name));
+
+ if (name != NULL) {
+ if (msgctxt != NULL) {
+ return g_dpgettext2 (LOCATIONS_GETTEXT_PACKAGE,
+ msgctxt,
+ name);
+ } else {
+ return g_dgettext (LOCATIONS_GETTEXT_PACKAGE, name);
+ }
+ }
+ }
+ }
+
+ return NULL;
+}
+
static void
add_timezones (GWeatherLocation *loc,
GPtrArray *zones)
diff --git a/libgweather/gweather-location.h b/libgweather/gweather-location.h
index 4e33a108..dc6f9bf7 100644
--- a/libgweather/gweather-location.h
+++ b/libgweather/gweather-location.h
@@ -147,6 +147,8 @@ GTimeZone * gweather_location_get_timezone (GWeatherLocatio
GWEATHER_AVAILABLE_IN_ALL
const char * gweather_location_get_timezone_str (GWeatherLocation *loc);
GWEATHER_AVAILABLE_IN_ALL
+const char * gweather_location_get_timezone_name (GWeatherLocation *loc);
+GWEATHER_AVAILABLE_IN_ALL
GTimeZone ** gweather_location_get_timezones (GWeatherLocation *loc);
GWEATHER_AVAILABLE_IN_ALL
void gweather_location_free_timezones (GWeatherLocation *loc,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]