[libgweather/ebassi/no-more-timezones: 7/9] Remove GWeatherTimezone
- From: Emmanuele Bassi <ebassi src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libgweather/ebassi/no-more-timezones: 7/9] Remove GWeatherTimezone
- Date: Tue, 23 Nov 2021 12:30:12 +0000 (UTC)
commit fedefd99fd2c6f6a2515dddaf72b43d05210af98
Author: Emmanuele Bassi <ebassi gnome org>
Date: Mon Nov 22 21:42:29 2021 +0000
Remove GWeatherTimezone
GWeatherTimezone can be replaced by GTimeZone, which has been available
since GLib 2.26.
libgweather/gweather-enum-types.c.tmpl | 1 -
libgweather/gweather-location.c | 59 ++++--
libgweather/gweather-location.h | 8 +-
libgweather/gweather-private.c | 2 +-
libgweather/gweather-private.h | 6 +-
libgweather/gweather-timezone.c | 374 ---------------------------------
libgweather/gweather-timezone.h | 47 -----
libgweather/gweather.h | 1 -
libgweather/meson.build | 2 -
libgweather/tests/timezones.c | 12 +-
10 files changed, 53 insertions(+), 459 deletions(-)
---
diff --git a/libgweather/gweather-enum-types.c.tmpl b/libgweather/gweather-enum-types.c.tmpl
index a429bc55..36d34a70 100644
--- a/libgweather/gweather-enum-types.c.tmpl
+++ b/libgweather/gweather-enum-types.c.tmpl
@@ -6,7 +6,6 @@
#include "gweather-enums.h"
#include "gweather-info.h"
#include "gweather-location.h"
-#include "gweather-timezone.h"
/*** END file-header ***/
/*** BEGIN file-production ***/
diff --git a/libgweather/gweather-location.c b/libgweather/gweather-location.c
index 19d42269..3a174c53 100644
--- a/libgweather/gweather-location.c
+++ b/libgweather/gweather-location.c
@@ -9,7 +9,6 @@
#include "gweather-location.h"
#include "gweather-private.h"
-#include "gweather-timezone.h"
#include <geocode-glib/geocode-glib.h>
#include <glib/gi18n-lib.h>
@@ -44,7 +43,7 @@ gweather_location_finalize (GObject *gobject)
g_free (self->_country_code);
g_free (self->_station_code);
- g_clear_pointer (&self->_timezone, gweather_timezone_unref);
+ g_clear_pointer (&self->_timezone, g_time_zone_unref);
G_OBJECT_CLASS (gweather_location_parent_class)->finalize (gobject);
}
@@ -170,7 +169,28 @@ gweather_location_new_full (GWeatherLocationLevel level,
}
static void
-add_timezones (GWeatherLocation *loc, GPtrArray *zones);
+add_timezones (GWeatherLocation *loc,
+ GPtrArray *zones);
+
+static GTimeZone *
+timezone_ref_for_idx (GWeatherDb *db,
+ guint16 idx)
+{
+ DbWorldTimezonesEntryRef ref;
+ const char *id;
+
+ g_assert (db);
+ g_assert (idx < db->timezones->len);
+
+ GTimeZone *zone = g_ptr_array_index (db->timezones, idx);
+ if (zone != NULL)
+ return g_time_zone_ref (zone);
+
+ ref = db_world_timezones_get_at (db->timezones_ref, idx);
+ id = db_world_timezones_entry_get_key (ref);
+
+ return g_time_zone_new_identifier (id);
+}
static GWeatherLocation *
location_ref_for_idx (GWeatherDb *db,
@@ -657,7 +677,7 @@ find_nearest_city (GWeatherLocation *location,
* This restriction may be lifted in a future version.
*
* Note that this function does not check if (@lat, @lon) fall inside
- * @loc, or are in the same region and timezone as the return value.
+ * @loc, or are in the same region and time zone as the return value.
*
* Returns: (transfer full): the city closest to (@lat, @lon), in the
* region or administrative district of @loc.
@@ -965,7 +985,7 @@ gweather_location_get_country (GWeatherLocation *loc)
*
* Return value: (transfer none) (nullable): the location's timezone
**/
-GWeatherTimezone *
+GTimeZone *
gweather_location_get_timezone (GWeatherLocation *loc)
{
g_autoptr (GWeatherLocation) s = NULL;
@@ -979,9 +999,11 @@ gweather_location_get_timezone (GWeatherLocation *loc)
if (!IDX_VALID (s->tz_hint_idx))
continue;
- loc->_timezone = _gweather_timezone_ref_for_idx (s->db, s->tz_hint_idx);
+ loc->_timezone = timezone_ref_for_idx (s->db, s->tz_hint_idx);
+
return loc->_timezone;
}
+
return NULL;
}
@@ -1003,7 +1025,7 @@ gweather_location_get_timezone_str (GWeatherLocation *loc)
ITER_UP (loc, s) {
if (s->_timezone)
- return gweather_timezone_get_tzid (s->_timezone);
+ return g_time_zone_get_identifier (s->_timezone);
if (s->db && IDX_VALID (s->tz_hint_idx)) {
return db_world_timezones_entry_get_key (db_world_timezones_get_at (s->db->timezones_ref,
s->tz_hint_idx));
@@ -1014,10 +1036,9 @@ gweather_location_get_timezone_str (GWeatherLocation *loc)
}
static void
-add_timezones (GWeatherLocation *loc, GPtrArray *zones)
+add_timezones (GWeatherLocation *loc,
+ GPtrArray *zones)
{
- gsize i;
-
/* NOTE: Only DB backed locations can have timezones */
if (loc->db && IDX_VALID (loc->db_idx)) {
DbArrayofuint16Ref ref;
@@ -1025,11 +1046,13 @@ add_timezones (GWeatherLocation *loc, GPtrArray *zones)
ref = db_location_get_timezones (loc->ref);
len = db_arrayofuint16_get_length (ref);
- for (i = 0; i < len; i++)
- g_ptr_array_add (zones,
- _gweather_timezone_ref_for_idx (loc->db,
- db_arrayofuint16_get_at (ref, i)));
+ for (gsize i = 0; i < len; i++) {
+ guint16 tz_idx = db_arrayofuint16_get_at (ref, i);
+
+ g_ptr_array_add (zones, timezone_ref_for_idx (loc->db, tz_idx));
+ }
}
+
if (loc->level < GWEATHER_LOCATION_COUNTRY) {
g_autoptr (GWeatherLocation) child = NULL;
@@ -1050,7 +1073,7 @@ add_timezones (GWeatherLocation *loc, GPtrArray *zones)
* Return value: (transfer full) (array zero-terminated=1): the timezones
* associated with the location
**/
-GWeatherTimezone **
+GTimeZone **
gweather_location_get_timezones (GWeatherLocation *loc)
{
g_return_val_if_fail (GWEATHER_IS_LOCATION (loc), NULL);
@@ -1059,7 +1082,7 @@ gweather_location_get_timezones (GWeatherLocation *loc)
add_timezones (loc, zones);
g_ptr_array_add (zones, NULL);
- return (GWeatherTimezone **) g_ptr_array_free (zones, FALSE);
+ return (GTimeZone **) g_ptr_array_free (zones, FALSE);
}
/**
@@ -1073,13 +1096,13 @@ gweather_location_get_timezones (GWeatherLocation *loc)
*/
void
gweather_location_free_timezones (GWeatherLocation *loc,
- GWeatherTimezone **zones)
+ GTimeZone **zones)
{
g_return_if_fail (GWEATHER_IS_LOCATION (loc));
g_return_if_fail (zones != NULL);
for (int i = 0; zones[i]; i++)
- gweather_timezone_unref (zones[i]);
+ g_time_zone_unref (zones[i]);
g_free (zones);
}
diff --git a/libgweather/gweather-location.h b/libgweather/gweather-location.h
index 37d02219..dedd6c87 100644
--- a/libgweather/gweather-location.h
+++ b/libgweather/gweather-location.h
@@ -11,7 +11,7 @@
#endif
#include <gio/gio.h>
-#include <libgweather/gweather-timezone.h>
+#include <libgweather/gweather-version.h>
G_BEGIN_DECLS
@@ -141,14 +141,14 @@ GWeatherLocation * gweather_location_detect_nearest_city_finish (GAsyncR
GWEATHER_AVAILABLE_IN_ALL
const char * gweather_location_get_country (GWeatherLocation *loc);
GWEATHER_AVAILABLE_IN_ALL
-GWeatherTimezone * gweather_location_get_timezone (GWeatherLocation *loc);
+GTimeZone * gweather_location_get_timezone (GWeatherLocation *loc);
GWEATHER_AVAILABLE_IN_ALL
const char * gweather_location_get_timezone_str (GWeatherLocation *loc);
GWEATHER_AVAILABLE_IN_ALL
-GWeatherTimezone ** gweather_location_get_timezones (GWeatherLocation *loc);
+GTimeZone ** gweather_location_get_timezones (GWeatherLocation *loc);
GWEATHER_AVAILABLE_IN_ALL
void gweather_location_free_timezones (GWeatherLocation *loc,
- GWeatherTimezone **zones);
+ GTimeZone **zones);
GWEATHER_AVAILABLE_IN_ALL
const char * gweather_location_get_code (GWeatherLocation *loc);
GWEATHER_AVAILABLE_IN_ALL
diff --git a/libgweather/gweather-private.c b/libgweather/gweather-private.c
index bf5087ca..d1110cd0 100644
--- a/libgweather/gweather-private.c
+++ b/libgweather/gweather-private.c
@@ -33,7 +33,7 @@ _gweather_location_reset_world (void)
if (G_UNLIKELY (g_ptr_array_index (world_db->timezones, i) != NULL)) {
g_warning ("Timezone with index %li and tzid %s is still referenced!",
i,
- gweather_timezone_get_tzid (g_ptr_array_index (world_db->timezones, i)));
+ g_time_zone_get_identifier (g_ptr_array_index (world_db->timezones, i)));
g_assert_not_reached ();
}
}
diff --git a/libgweather/gweather-private.h b/libgweather/gweather-private.h
index 51c0216e..bb973a8a 100644
--- a/libgweather/gweather-private.h
+++ b/libgweather/gweather-private.h
@@ -58,7 +58,7 @@ struct _GWeatherLocation {
GWeatherLocation *_parent;
GWeatherLocation **_children;
- GWeatherTimezone *_timezone;
+ GTimeZone *_timezone;
GWeatherLocationLevel level;
char *_country_code;
guint16 tz_hint_idx;
@@ -88,10 +88,6 @@ void
_gweather_location_update_weather_location (GWeatherLocation *gloc,
WeatherLocation *loc);
-GWeatherTimezone *
-_gweather_timezone_ref_for_idx (GWeatherDb *db,
- guint idx);
-
void
gweather_location_ensure_world (void);
diff --git a/libgweather/gweather.h b/libgweather/gweather.h
index 6fe1f399..7a1a0da7 100644
--- a/libgweather/gweather.h
+++ b/libgweather/gweather.h
@@ -13,6 +13,5 @@
#include <libgweather/gweather-enum-types.h>
#include <libgweather/gweather-info.h>
#include <libgweather/gweather-location.h>
-#include <libgweather/gweather-timezone.h>
#undef IN_GWEATHER_H
diff --git a/libgweather/meson.build b/libgweather/meson.build
index 92f4c812..b5d0b4d4 100644
--- a/libgweather/meson.build
+++ b/libgweather/meson.build
@@ -136,7 +136,6 @@ deps_libgweather = [
gweather_headers = [
'gweather-info.h',
'gweather-location.h',
- 'gweather-timezone.h',
'gweather-enums.h'
]
@@ -155,7 +154,6 @@ gweather_c_sources = [
'gweather.c',
'gweather-info.c',
'gweather-location.c',
- 'gweather-timezone.c',
]
gweather_priv_sources = [
diff --git a/libgweather/tests/timezones.c b/libgweather/tests/timezones.c
index 98a1da21..5475c223 100644
--- a/libgweather/tests/timezones.c
+++ b/libgweather/tests/timezones.c
@@ -115,13 +115,13 @@ test_named_timezones_deserialized (void)
list = get_list_from_configuration (world, CONFIGURATION, 3);
for (l = list; l != NULL; l = l->next) {
GWeatherLocation *loc = l->data;
- GWeatherTimezone *tz;
+ GTimeZone *tz;
const char *tzid;
tz = gweather_location_get_timezone (loc);
g_assert_nonnull (tz);
- tzid = gweather_timezone_get_tzid (tz);
+ tzid = g_time_zone_get_identifier (tz);
g_assert_nonnull (tzid);
g_object_unref (loc);
@@ -137,12 +137,12 @@ test_named_timezones_deserialized (void)
static void
test_timezone (GWeatherLocation *location)
{
- g_autoptr (GWeatherTimezone) gtz = NULL;
+ g_autoptr (GTimeZone) gtz = NULL;
const char *tz;
tz = gweather_location_get_timezone_str (location);
if (!tz) {
- GWeatherTimezone **tzs;
+ GTimeZone **tzs;
tzs = gweather_location_get_timezones (location);
g_assert_nonnull (tzs);
@@ -158,8 +158,8 @@ test_timezone (GWeatherLocation *location)
return;
}
- gtz = gweather_timezone_get_by_tzid (tz);
- if (!gtz) {
+ gtz = g_time_zone_new_identifier (tz);
+ if (gtz == NULL) {
g_test_message ("Location '%s' has invalid timezone '%s'\n",
gweather_location_get_name (location),
tz);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]