[libgweather/wip/tintou/modern-code: 2/5] weather: declare GWeatherInfo using G_DECLARE_DERIVABLE_TYPE macro
- From: Corentin Noël <corentinnoel src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libgweather/wip/tintou/modern-code: 2/5] weather: declare GWeatherInfo using G_DECLARE_DERIVABLE_TYPE macro
- Date: Wed, 7 Oct 2020 14:36:52 +0000 (UTC)
commit 735b8a5cf029863c4748e707c60284fba8c1337b
Author: Corentin Noël <corentin noel collabora com>
Date: Wed Oct 7 15:52:04 2020 +0200
weather: declare GWeatherInfo using G_DECLARE_DERIVABLE_TYPE macro
This allows to use g_autoptr with GWeatherInfo and hides the defines.
The priv field is also removed from GWeatherInfo itself.
libgweather/gweather-private.h | 7 +-
libgweather/gweather-weather.c | 349 +++++++++++++++++++++++------------------
libgweather/gweather-weather.h | 22 +--
libgweather/test_metar.c | 19 ++-
libgweather/test_sun_moon.c | 2 +-
libgweather/weather-iwin.c | 14 +-
libgweather/weather-metar.c | 38 ++---
libgweather/weather-moon.c | 9 +-
libgweather/weather-owm.c | 36 ++---
libgweather/weather-sun.c | 13 +-
libgweather/weather-yrno.c | 32 ++--
11 files changed, 275 insertions(+), 266 deletions(-)
---
diff --git a/libgweather/gweather-private.h b/libgweather/gweather-private.h
index 925abd87..8d9d1687 100644
--- a/libgweather/gweather-private.h
+++ b/libgweather/gweather-private.h
@@ -83,7 +83,7 @@ typedef gdouble GWeatherPressure;
typedef gdouble GWeatherVisibility;
typedef time_t GWeatherUpdate;
-struct _GWeatherInfoPrivate {
+typedef struct _GWeatherInfoPrivate {
GWeatherProvider providers;
GSettings *settings;
@@ -131,7 +131,7 @@ struct _GWeatherInfoPrivate {
GdkPixbufAnimation *radar;
SoupSession *session;
GSList *requests_pending;
-};
+} GWeatherInfoPrivate;
/* Values common to the parsing source files */
@@ -196,13 +196,14 @@ void ecl2equ (gdouble t,
gdouble *ra,
gdouble *decl);
gdouble sunEclipLongitude (time_t t);
-
void _gweather_info_ensure_sun (GWeatherInfo *info);
void _gweather_info_ensure_moon (GWeatherInfo *info);
void free_forecast_list (GWeatherInfo *info);
GWeatherInfo *_gweather_info_new_clone (GWeatherInfo *info);
+GWEATHER_EXTERN
+GWeatherInfoPrivate *_gweather_info_get_instance_private (GWeatherInfo *info);
#endif /* __WEATHER_PRIV_H_ */
diff --git a/libgweather/gweather-weather.c b/libgweather/gweather-weather.c
index 5f9230c9..f3a1331b 100644
--- a/libgweather/gweather-weather.c
+++ b/libgweather/gweather-weather.c
@@ -76,7 +76,7 @@ enum {
static guint gweather_info_signals[SIGNAL_LAST];
-G_DEFINE_TYPE (GWeatherInfo, gweather_info, G_TYPE_OBJECT);
+G_DEFINE_TYPE_WITH_PRIVATE (GWeatherInfo, gweather_info, G_TYPE_OBJECT)
void
_gweather_gettext_init (void)
@@ -309,7 +309,9 @@ gweather_conditions_to_string (GWeatherConditions *cond)
static gboolean
requests_init (GWeatherInfo *info)
{
- if (info->priv->requests_pending)
+ GWeatherInfoPrivate *priv = gweather_info_get_instance_private (info);
+
+ if (priv->requests_pending)
return FALSE;
return TRUE;
@@ -319,48 +321,55 @@ void
_gweather_info_begin_request (GWeatherInfo *info,
SoupMessage *message)
{
- info->priv->requests_pending = g_slist_prepend (info->priv->requests_pending, message);
- g_object_ref (message);
+ GWeatherInfoPrivate *priv = gweather_info_get_instance_private (info);
+
+ priv->requests_pending = g_slist_prepend (priv->requests_pending, g_object_ref (message));
}
static void
copy_weather_data (GWeatherInfo *src,
GWeatherInfo *dest)
{
- dest->priv->hasHumidity = src->priv->hasHumidity;
- dest->priv->update = src->priv->update;
- dest->priv->current_time = src->priv->current_time;
- dest->priv->sky = src->priv->sky;
- dest->priv->cond = src->priv->cond;
- dest->priv->temp = src->priv->temp;
- dest->priv->temp_min = src->priv->temp_min;
- dest->priv->temp_max = src->priv->temp_max;
- dest->priv->dew = src->priv->dew;
- dest->priv->humidity = src->priv->humidity;
- dest->priv->wind = src->priv->wind;
- dest->priv->windspeed = src->priv->windspeed;
- dest->priv->pressure = src->priv->pressure;
- dest->priv->visibility = src->priv->visibility;
+ GWeatherInfoPrivate *src_priv = gweather_info_get_instance_private (src);
+ GWeatherInfoPrivate *dest_priv = gweather_info_get_instance_private (dest);
+
+ dest_priv->hasHumidity = src_priv->hasHumidity;
+ dest_priv->update = src_priv->update;
+ dest_priv->current_time = src_priv->current_time;
+ dest_priv->sky = src_priv->sky;
+ dest_priv->cond = src_priv->cond;
+ dest_priv->temp = src_priv->temp;
+ dest_priv->temp_min = src_priv->temp_min;
+ dest_priv->temp_max = src_priv->temp_max;
+ dest_priv->dew = src_priv->dew;
+ dest_priv->humidity = src_priv->humidity;
+ dest_priv->wind = src_priv->wind;
+ dest_priv->windspeed = src_priv->windspeed;
+ dest_priv->pressure = src_priv->pressure;
+ dest_priv->visibility = src_priv->visibility;
}
static void
fixup_current_conditions (GWeatherInfo *info)
{
+ GWeatherInfoPrivate *priv = gweather_info_get_instance_private (info);
GWeatherInfo *first_forecast;
+ GWeatherInfoPrivate *first_forecast_priv;
/* Current conditions already available */
- if (info->priv->update != 0) {
+ if (priv->update != 0) {
g_debug ("Not fixing up current conditions, already valid");
return;
- } else if (!info->priv->forecast_list ||
- !info->priv->forecast_list->data) {
+ } else if (!priv->forecast_list ||
+ !priv->forecast_list->data) {
g_debug ("No forecast list available, not fixing up");
return;
}
- first_forecast = info->priv->forecast_list->data;
+ first_forecast = priv->forecast_list->data;
+ first_forecast_priv = gweather_info_get_instance_private (first_forecast);
/* Add current conditions from forecast if close enough */
- if (first_forecast->priv->update - time(NULL) > 60 * 60) {
+ if (first_forecast_priv->update - time(NULL) > 60 * 60) {
g_debug ("Forecast is too far in the future, ignoring");
return;
}
@@ -373,15 +382,17 @@ void
_gweather_info_request_done (GWeatherInfo *info,
SoupMessage *message)
{
- info->priv->requests_pending = g_slist_remove (info->priv->requests_pending, message);
- g_object_ref (message);
+ GWeatherInfoPrivate *priv = gweather_info_get_instance_private (info);
+
+ priv->requests_pending = g_slist_remove (priv->requests_pending, message);
+ g_object_unref (message);
- if (info->priv->requests_pending == NULL) {
+ if (priv->requests_pending == NULL) {
fixup_current_conditions (info);
g_signal_emit (info, gweather_info_signals[SIGNAL_UPDATED], 0);
} else {
g_debug ("Not emitting 'updated' as there are still %d requests pending",
- g_slist_length (info->priv->requests_pending));
+ g_slist_length (priv->requests_pending));
}
}
@@ -389,11 +400,13 @@ _gweather_info_request_done (GWeatherInfo *info,
void
free_forecast_list (GWeatherInfo *info)
{
+ GWeatherInfoPrivate *priv = gweather_info_get_instance_private (info);
+
if (!info)
return;
- g_slist_free_full (info->priv->forecast_list, g_object_unref);
- info->priv->forecast_list = NULL;
+ g_slist_free_full (priv->forecast_list, g_object_unref);
+ priv->forecast_list = NULL;
}
/* Relative humidity computation - thanks to <Olof Oberg modopaper modogroup com>
@@ -439,14 +452,15 @@ calc_humidity (gdouble temp, gdouble dewp)
static inline gdouble
calc_apparent (GWeatherInfo *info)
{
- gdouble temp = info->priv->temp;
- gdouble wind = WINDSPEED_KNOTS_TO_MPH (info->priv->windspeed);
+ GWeatherInfoPrivate *priv = gweather_info_get_instance_private (info);
+ gdouble temp = priv->temp;
+ gdouble wind = WINDSPEED_KNOTS_TO_MPH (priv->windspeed);
gdouble apparent = -1000.;
- gdouble dew = info->priv->dew;
+ gdouble dew = priv->dew;
gdouble humidity;
- if (info->priv->hasHumidity)
- humidity = info->priv->humidity;
+ if (priv->hasHumidity)
+ humidity = priv->humidity;
else
humidity = calc_humidity (temp, dew);
@@ -528,17 +542,13 @@ calc_apparent (GWeatherInfo *info)
static void
gweather_info_reset (GWeatherInfo *info)
{
- GWeatherInfoPrivate *priv = info->priv;
+ GWeatherInfoPrivate *priv = gweather_info_get_instance_private (info);
- g_free (priv->forecast_attribution);
- priv->forecast_attribution = NULL;
+ g_clear_pointer (&priv->forecast_attribution, g_free);
free_forecast_list (info);
- if (priv->radar != NULL) {
- g_object_unref (priv->radar);
- priv->radar = NULL;
- }
+ g_clear_object (&priv->radar);
priv->update = 0;
priv->current_time = time(NULL);
@@ -572,7 +582,7 @@ settings_changed_cb (GSettings *settings,
const char *key,
GWeatherInfo *info)
{
- GWeatherInfoPrivate *priv = info->priv;
+ GWeatherInfoPrivate *priv = gweather_info_get_instance_private (info);
/* Only emit the signal if no network requests are pending.
Otherwise just wait for the update that will happen at
@@ -585,9 +595,7 @@ settings_changed_cb (GSettings *settings,
void
gweather_info_init (GWeatherInfo *info)
{
- GWeatherInfoPrivate *priv;
-
- priv = info->priv = G_TYPE_INSTANCE_GET_PRIVATE (info, GWEATHER_TYPE_INFO, GWeatherInfoPrivate);
+ GWeatherInfoPrivate *priv = gweather_info_get_instance_private (info);
priv->providers = GWEATHER_PROVIDER_METAR | GWEATHER_PROVIDER_IWIN;
priv->settings = g_settings_new ("org.gnome.GWeather");
@@ -701,7 +709,7 @@ gweather_info_store_cache (void)
void
gweather_info_update (GWeatherInfo *info)
{
- GWeatherInfoPrivate *priv = info->priv;
+ GWeatherInfoPrivate *priv = gweather_info_get_instance_private (info);
gboolean ok;
/* Update in progress */
@@ -737,32 +745,33 @@ gweather_info_update (GWeatherInfo *info)
void
gweather_info_abort (GWeatherInfo *info)
{
+ GWeatherInfoPrivate *priv = gweather_info_get_instance_private (info);
GSList *list, *iter;
GSList dummy = { NULL, NULL };
g_return_if_fail (GWEATHER_IS_INFO (info));
- if (info->priv->session == NULL) {
- g_assert (info->priv->requests_pending == NULL);
+ if (priv->session == NULL) {
+ g_assert (priv->requests_pending == NULL);
return;
}
- list = info->priv->requests_pending;
+ list = priv->requests_pending;
/* to block updated signals */
- info->priv->requests_pending = &dummy;
+ priv->requests_pending = &dummy;
for (iter = list; iter; iter = iter->next)
- soup_session_cancel_message (info->priv->session, iter->data, SOUP_STATUS_CANCELLED);
+ soup_session_cancel_message (priv->session, iter->data, SOUP_STATUS_CANCELLED);
g_slist_free (list);
- info->priv->requests_pending = NULL;
+ priv->requests_pending = NULL;
}
static void
gweather_info_dispose (GObject *object)
{
GWeatherInfo *info = GWEATHER_INFO (object);
- GWeatherInfoPrivate *priv = info->priv;
+ GWeatherInfoPrivate *priv = gweather_info_get_instance_private (info);
gweather_info_abort (info);
@@ -784,7 +793,7 @@ static void
gweather_info_finalize (GObject *object)
{
GWeatherInfo *info = GWEATHER_INFO (object);
- GWeatherInfoPrivate *priv = info->priv;
+ GWeatherInfoPrivate *priv = gweather_info_get_instance_private (info);
_weather_location_free (&priv->location);
g_clear_object (&priv->settings);
@@ -803,44 +812,56 @@ gweather_info_finalize (GObject *object)
gboolean
gweather_info_is_valid (GWeatherInfo *info)
{
+ GWeatherInfoPrivate *priv = gweather_info_get_instance_private (info);
+
g_return_val_if_fail (GWEATHER_IS_INFO (info), FALSE);
- return info->priv->valid;
+
+ return priv->valid;
}
gboolean
gweather_info_network_error (GWeatherInfo *info)
{
+ GWeatherInfoPrivate *priv = gweather_info_get_instance_private (info);
+
g_return_val_if_fail (GWEATHER_IS_INFO (info), FALSE);
- return info->priv->network_error;
+
+ return priv->network_error;
}
const GWeatherLocation *
gweather_info_get_location (GWeatherInfo *info)
{
+ GWeatherInfoPrivate *priv = gweather_info_get_instance_private (info);
+
g_return_val_if_fail (GWEATHER_IS_INFO (info), NULL);
- return info->priv->glocation;
+
+ return priv->glocation;
}
gchar *
gweather_info_get_location_name (GWeatherInfo *info)
{
+ GWeatherInfoPrivate *priv = gweather_info_get_instance_private (info);
+
g_return_val_if_fail (GWEATHER_IS_INFO (info), NULL);
- return g_strdup(info->priv->location.name);
+ return g_strdup(priv->location.name);
}
gchar *
gweather_info_get_update (GWeatherInfo *info)
{
+ GWeatherInfoPrivate *priv = gweather_info_get_instance_private (info);
char *out;
g_return_val_if_fail (GWEATHER_IS_INFO (info), NULL);
- if (!info->priv->valid)
+ if (!priv->valid)
return g_strdup ("-");
- if (info->priv->update != 0) {
- GDateTime *now = g_date_time_new_from_unix_local (info->priv->update);
+ if (priv->update != 0) {
+ GDateTime *now = g_date_time_new_from_unix_local (priv->update);
out = g_date_time_format (now, _("%a, %b %d / %H∶%M"));
if (!out)
@@ -856,21 +877,30 @@ gweather_info_get_update (GWeatherInfo *info)
gchar *
gweather_info_get_sky (GWeatherInfo *info)
{
+ GWeatherInfoPrivate *priv = gweather_info_get_instance_private (info);
+
g_return_val_if_fail (GWEATHER_IS_INFO (info), NULL);
- if (!info->priv->valid)
+
+ if (!priv->valid)
return g_strdup("-");
- if (info->priv->sky < 0)
+
+ if (priv->sky < 0)
return g_strdup(C_("sky conditions", "Unknown"));
- return g_strdup(gweather_sky_to_string (info->priv->sky));
+
+ return g_strdup(gweather_sky_to_string (priv->sky));
}
gchar *
gweather_info_get_conditions (GWeatherInfo *info)
{
+ GWeatherInfoPrivate *priv = gweather_info_get_instance_private (info);
+
g_return_val_if_fail (GWEATHER_IS_INFO (info), NULL);
- if (!info->priv->valid)
+
+ if (!priv->valid)
return g_strdup("-");
- return g_strdup(gweather_conditions_to_string (&info->priv->cond));
+
+ return g_strdup(gweather_conditions_to_string (&priv->cond));
}
static gboolean
@@ -976,10 +1006,9 @@ temperature_string (gfloat temp_f, GWeatherTemperatureUnit to_unit, gboolean wan
gchar *
gweather_info_get_temp (GWeatherInfo *info)
{
- GWeatherInfoPrivate *priv;
+ GWeatherInfoPrivate *priv = gweather_info_get_instance_private (info);
g_return_val_if_fail (GWEATHER_IS_INFO (info), NULL);
- priv = info->priv;
if (!priv->valid)
return g_strdup("-");
@@ -992,10 +1021,9 @@ gweather_info_get_temp (GWeatherInfo *info)
gchar *
gweather_info_get_temp_min (GWeatherInfo *info)
{
- GWeatherInfoPrivate *priv;
+ GWeatherInfoPrivate *priv = gweather_info_get_instance_private (info);
g_return_val_if_fail (GWEATHER_IS_INFO (info), NULL);
- priv = info->priv;
if (!priv->valid || !priv->tempMinMaxValid)
return g_strdup("-");
@@ -1008,10 +1036,9 @@ gweather_info_get_temp_min (GWeatherInfo *info)
gchar *
gweather_info_get_temp_max (GWeatherInfo *info)
{
- GWeatherInfoPrivate *priv;
+ GWeatherInfoPrivate *priv = gweather_info_get_instance_private (info);
g_return_val_if_fail (GWEATHER_IS_INFO (info), NULL);
- priv = info->priv;
if (!priv->valid || !priv->tempMinMaxValid)
return g_strdup("-");
@@ -1024,11 +1051,10 @@ gweather_info_get_temp_max (GWeatherInfo *info)
gchar *
gweather_info_get_dew (GWeatherInfo *info)
{
- GWeatherInfoPrivate *priv;
+ GWeatherInfoPrivate *priv = gweather_info_get_instance_private (info);
gdouble dew;
g_return_val_if_fail (GWEATHER_IS_INFO (info), NULL);
- priv = info->priv;
if (!priv->valid)
return g_strdup("-");
@@ -1046,17 +1072,18 @@ gweather_info_get_dew (GWeatherInfo *info)
gchar *
gweather_info_get_humidity (GWeatherInfo *info)
{
+ GWeatherInfoPrivate *priv = gweather_info_get_instance_private (info);
gdouble humidity;
g_return_val_if_fail (GWEATHER_IS_INFO (info), NULL);
- if (!info->priv->valid)
+ if (!priv->valid)
return g_strdup("-");
- if (info->priv->hasHumidity)
- humidity = info->priv->humidity;
+ if (priv->hasHumidity)
+ humidity = priv->humidity;
else
- humidity = calc_humidity (info->priv->temp, info->priv->dew);
+ humidity = calc_humidity (priv->temp, priv->dew);
if (humidity < 0.0)
return g_strdup(C_("humidity", "Unknown"));
@@ -1067,11 +1094,10 @@ gweather_info_get_humidity (GWeatherInfo *info)
gchar *
gweather_info_get_apparent (GWeatherInfo *info)
{
- GWeatherInfoPrivate *priv;
+ GWeatherInfoPrivate *priv = gweather_info_get_instance_private (info);
gdouble apparent;
g_return_val_if_fail (GWEATHER_IS_INFO (info), NULL);
- priv = info->priv;
if (!priv->valid)
return g_strdup("-");
@@ -1133,12 +1159,10 @@ windspeed_string (gfloat knots, GWeatherSpeedUnit to_unit)
gchar *
gweather_info_get_wind (GWeatherInfo *info)
{
- GWeatherInfoPrivate *priv;
+ GWeatherInfoPrivate *priv = gweather_info_get_instance_private (info);
g_return_val_if_fail (GWEATHER_IS_INFO (info), NULL);
- priv = info->priv;
-
if (!priv->valid)
return g_strdup("-");
if (priv->windspeed < 0.0 || priv->wind < 0)
@@ -1178,13 +1202,11 @@ pressure_unit_to_real (GWeatherPressureUnit unit)
gchar *
gweather_info_get_pressure (GWeatherInfo *info)
{
- GWeatherInfoPrivate *priv;
+ GWeatherInfoPrivate *priv = gweather_info_get_instance_private (info);
GWeatherPressureUnit unit;
g_return_val_if_fail (GWEATHER_IS_INFO (info), NULL);
- priv = info->priv;
-
if (!priv->valid)
return g_strdup("-");
if (priv->pressure < 0.0)
@@ -1238,11 +1260,10 @@ distance_unit_to_real (GWeatherDistanceUnit unit)
gchar *
gweather_info_get_visibility (GWeatherInfo *info)
{
- GWeatherInfoPrivate *priv;
+ GWeatherInfoPrivate *priv = gweather_info_get_instance_private (info);
GWeatherDistanceUnit unit;
g_return_val_if_fail (GWEATHER_IS_INFO (info), NULL);
- priv = info->priv;
if (!priv->valid)
return g_strdup ("-");
@@ -1272,14 +1293,12 @@ gweather_info_get_visibility (GWeatherInfo *info)
gchar *
gweather_info_get_sunrise (GWeatherInfo *info)
{
- GWeatherInfoPrivate *priv;
+ GWeatherInfoPrivate *priv = gweather_info_get_instance_private (info);
GDateTime *sunrise;
gchar *buf;
g_return_val_if_fail (GWEATHER_IS_INFO (info), NULL);
- priv = info->priv;
-
_gweather_info_ensure_sun (info);
if (!priv->sunriseValid)
@@ -1298,14 +1317,12 @@ gweather_info_get_sunrise (GWeatherInfo *info)
gchar *
gweather_info_get_sunset (GWeatherInfo *info)
{
- GWeatherInfoPrivate *priv;
+ GWeatherInfoPrivate *priv = gweather_info_get_instance_private (info);
GDateTime *sunset;
gchar *buf;
g_return_val_if_fail (GWEATHER_IS_INFO (info), NULL);
- priv = info->priv;
-
_gweather_info_ensure_sun (info);
if (!priv->sunsetValid)
@@ -1333,12 +1350,14 @@ gweather_info_get_sunset (GWeatherInfo *info)
GSList *
gweather_info_get_forecast_list (GWeatherInfo *info)
{
+ GWeatherInfoPrivate *priv = gweather_info_get_instance_private (info);
+
g_return_val_if_fail (GWEATHER_IS_INFO (info), NULL);
- if (!info->priv->valid)
+ if (!priv->valid)
return NULL;
- return info->priv->forecast_list;
+ return priv->forecast_list;
}
/**
@@ -1350,8 +1369,11 @@ gweather_info_get_forecast_list (GWeatherInfo *info)
GdkPixbufAnimation *
gweather_info_get_radar (GWeatherInfo *info)
{
+ GWeatherInfoPrivate *priv = gweather_info_get_instance_private (info);
+
g_return_val_if_fail (GWEATHER_IS_INFO (info), NULL);
- return info->priv->radar;
+
+ return priv->radar;
}
/**
@@ -1369,20 +1391,20 @@ gweather_info_get_radar (GWeatherInfo *info)
const gchar *
gweather_info_get_attribution (GWeatherInfo *info)
{
+ GWeatherInfoPrivate *priv = gweather_info_get_instance_private (info);
+
g_return_val_if_fail (GWEATHER_IS_INFO (info), NULL);
- return info->priv->forecast_attribution;
+ return priv->forecast_attribution;
}
gchar *
gweather_info_get_temp_summary (GWeatherInfo *info)
{
- GWeatherInfoPrivate *priv;
+ GWeatherInfoPrivate *priv = gweather_info_get_instance_private (info);
g_return_val_if_fail (GWEATHER_IS_INFO (info), NULL);
- priv = info->priv;
-
if (!priv->valid || priv->temp < -500.0)
return g_strdup ("--");
@@ -1398,12 +1420,13 @@ gweather_info_get_temp_summary (GWeatherInfo *info)
gchar *
gweather_info_get_weather_summary (GWeatherInfo *info)
{
+ GWeatherInfoPrivate *priv = gweather_info_get_instance_private (info);
gchar *buf;
gchar *out;
g_return_val_if_fail (GWEATHER_IS_INFO (info), NULL);
- if (!info->priv->valid)
+ if (!priv->valid)
return g_strdup (_("Retrieval failed"));
buf = gweather_info_get_conditions (info);
if (g_str_equal (buf, "-")) {
@@ -1432,13 +1455,11 @@ gweather_info_get_weather_summary (GWeatherInfo *info)
gboolean
gweather_info_is_daytime (GWeatherInfo *info)
{
- GWeatherInfoPrivate *priv;
+ GWeatherInfoPrivate *priv = gweather_info_get_instance_private (info);
time_t current_time;
g_return_val_if_fail (GWEATHER_IS_INFO (info), FALSE);
- priv = info->priv;
-
_gweather_info_ensure_sun (info);
if (priv->polarNight)
@@ -1454,15 +1475,13 @@ gweather_info_is_daytime (GWeatherInfo *info)
const gchar *
gweather_info_get_icon_name (GWeatherInfo *info)
{
- GWeatherInfoPrivate *priv;
+ GWeatherInfoPrivate *priv = gweather_info_get_instance_private (info);
GWeatherConditions cond;
GWeatherSky sky;
gboolean daytime;
g_return_val_if_fail (GWEATHER_IS_INFO (info), NULL);
- priv = info->priv;
-
cond = priv->cond;
sky = priv->sky;
@@ -1540,15 +1559,13 @@ gweather_info_get_icon_name (GWeatherInfo *info)
const gchar *
gweather_info_get_symbolic_icon_name (GWeatherInfo *info)
{
- GWeatherInfoPrivate *priv;
+ GWeatherInfoPrivate *priv = gweather_info_get_instance_private (info);
GWeatherConditions cond;
GWeatherSky sky;
gboolean daytime;
g_return_val_if_fail (GWEATHER_IS_INFO (info), NULL);
- priv = info->priv;
-
cond = priv->cond;
sky = priv->sky;
@@ -1788,16 +1805,18 @@ distance_value (gdouble miles,
gboolean
gweather_info_get_value_sky (GWeatherInfo *info, GWeatherSky *sky)
{
+ GWeatherInfoPrivate *priv = gweather_info_get_instance_private (info);
+
g_return_val_if_fail (GWEATHER_IS_INFO (info), FALSE);
g_return_val_if_fail (sky != NULL, FALSE);
- if (!info->priv->valid)
+ if (!priv->valid)
return FALSE;
- if (info->priv->sky <= GWEATHER_SKY_INVALID || info->priv->sky >= GWEATHER_SKY_LAST)
+ if (priv->sky <= GWEATHER_SKY_INVALID || priv->sky >= GWEATHER_SKY_LAST)
return FALSE;
- *sky = info->priv->sky;
+ *sky = priv->sky;
return TRUE;
}
@@ -1814,14 +1833,12 @@ gweather_info_get_value_sky (GWeatherInfo *info, GWeatherSky *sky)
gboolean
gweather_info_get_value_conditions (GWeatherInfo *info, GWeatherConditionPhenomenon *phenomenon,
GWeatherConditionQualifier *qualifier)
{
- GWeatherInfoPrivate *priv;
+ GWeatherInfoPrivate *priv = gweather_info_get_instance_private (info);
g_return_val_if_fail (GWEATHER_IS_INFO (info), FALSE);
g_return_val_if_fail (phenomenon != NULL, FALSE);
g_return_val_if_fail (qualifier != NULL, FALSE);
- priv = info->priv;
-
if (!priv->valid)
return FALSE;
@@ -1851,13 +1868,15 @@ gweather_info_get_value_conditions (GWeatherInfo *info, GWeatherConditionPhenome
gboolean
gweather_info_get_value_temp (GWeatherInfo *info, GWeatherTemperatureUnit unit, gdouble *value)
{
+ GWeatherInfoPrivate *priv = gweather_info_get_instance_private (info);
+
g_return_val_if_fail (GWEATHER_IS_INFO (info), FALSE);
g_return_val_if_fail (value != NULL, FALSE);
- if (!info->priv->valid)
+ if (!priv->valid)
return FALSE;
- return temperature_value (info->priv->temp, unit, value, info->priv->settings);
+ return temperature_value (priv->temp, unit, value, priv->settings);
}
/**
@@ -1871,13 +1890,11 @@ gweather_info_get_value_temp (GWeatherInfo *info, GWeatherTemperatureUnit unit,
gboolean
gweather_info_get_value_temp_min (GWeatherInfo *info, GWeatherTemperatureUnit unit, gdouble *value)
{
- GWeatherInfoPrivate *priv;
+ GWeatherInfoPrivate *priv = gweather_info_get_instance_private (info);
g_return_val_if_fail (GWEATHER_IS_INFO (info), FALSE);
g_return_val_if_fail (value != NULL, FALSE);
- priv = info->priv;
-
if (!priv->valid || !priv->tempMinMaxValid)
return FALSE;
@@ -1895,13 +1912,11 @@ gweather_info_get_value_temp_min (GWeatherInfo *info, GWeatherTemperatureUnit un
gboolean
gweather_info_get_value_temp_max (GWeatherInfo *info, GWeatherTemperatureUnit unit, gdouble *value)
{
- GWeatherInfoPrivate *priv;
+ GWeatherInfoPrivate *priv = gweather_info_get_instance_private (info);
g_return_val_if_fail (GWEATHER_IS_INFO (info), FALSE);
g_return_val_if_fail (value != NULL, FALSE);
- priv = info->priv;
-
if (!priv->valid || !priv->tempMinMaxValid)
return FALSE;
@@ -1919,20 +1934,21 @@ gweather_info_get_value_temp_max (GWeatherInfo *info, GWeatherTemperatureUnit un
gboolean
gweather_info_get_value_dew (GWeatherInfo *info, GWeatherTemperatureUnit unit, gdouble *value)
{
+ GWeatherInfoPrivate *priv = gweather_info_get_instance_private (info);
gdouble dew;
g_return_val_if_fail (GWEATHER_IS_INFO (info), FALSE);
g_return_val_if_fail (value != NULL, FALSE);
- if (!info->priv->valid)
+ if (!priv->valid)
return FALSE;
- if (info->priv->hasHumidity)
- dew = calc_dew (info->priv->temp, info->priv->humidity);
+ if (priv->hasHumidity)
+ dew = calc_dew (priv->temp, priv->humidity);
else
- dew = info->priv->dew;
+ dew = priv->dew;
- return temperature_value (dew, unit, value, info->priv->settings);
+ return temperature_value (dew, unit, value, priv->settings);
}
/**
@@ -1946,13 +1962,15 @@ gweather_info_get_value_dew (GWeatherInfo *info, GWeatherTemperatureUnit unit, g
gboolean
gweather_info_get_value_apparent (GWeatherInfo *info, GWeatherTemperatureUnit unit, gdouble *value)
{
+ GWeatherInfoPrivate *priv = gweather_info_get_instance_private (info);
+
g_return_val_if_fail (GWEATHER_IS_INFO (info), FALSE);
g_return_val_if_fail (value != NULL, FALSE);
- if (!info->priv->valid)
+ if (!priv->valid)
return FALSE;
- return temperature_value (calc_apparent (info), unit, value, info->priv->settings);
+ return temperature_value (calc_apparent (info), unit, value, priv->settings);
}
/**
@@ -1967,13 +1985,15 @@ gweather_info_get_value_apparent (GWeatherInfo *info, GWeatherTemperatureUnit un
gboolean
gweather_info_get_value_update (GWeatherInfo *info, time_t *value)
{
+ GWeatherInfoPrivate *priv = gweather_info_get_instance_private (info);
+
g_return_val_if_fail (GWEATHER_IS_INFO (info), FALSE);
g_return_val_if_fail (value != NULL, FALSE);
- if (!info->priv->valid)
+ if (!priv->valid)
return FALSE;
- *value = info->priv->update;
+ *value = priv->update;
return TRUE;
}
@@ -1988,15 +2008,17 @@ gweather_info_get_value_update (GWeatherInfo *info, time_t *value)
gboolean
gweather_info_get_value_sunrise (GWeatherInfo *info, time_t *value)
{
+ GWeatherInfoPrivate *priv = gweather_info_get_instance_private (info);
+
g_return_val_if_fail (GWEATHER_IS_INFO (info), FALSE);
g_return_val_if_fail (value != NULL, FALSE);
_gweather_info_ensure_sun (info);
- if (!info->priv->sunriseValid)
+ if (!priv->sunriseValid)
return FALSE;
- *value = info->priv->sunrise;
+ *value = priv->sunrise;
return TRUE;
}
@@ -2011,15 +2033,17 @@ gweather_info_get_value_sunrise (GWeatherInfo *info, time_t *value)
gboolean
gweather_info_get_value_sunset (GWeatherInfo *info, time_t *value)
{
+ GWeatherInfoPrivate *priv = gweather_info_get_instance_private (info);
+
g_return_val_if_fail (GWEATHER_IS_INFO (info), FALSE);
g_return_val_if_fail (value != NULL, FALSE);
_gweather_info_ensure_sun (info);
- if (!info->priv->sunsetValid)
+ if (!priv->sunsetValid)
return FALSE;
- *value = info->priv->sunset;
+ *value = priv->sunset;
return TRUE;
}
@@ -2037,17 +2061,19 @@ gweather_info_get_value_moonphase (GWeatherInfo *info,
GWeatherMoonPhase *value,
GWeatherMoonLatitude *lat)
{
+ GWeatherInfoPrivate *priv = gweather_info_get_instance_private (info);
+
g_return_val_if_fail (GWEATHER_IS_INFO (info), FALSE);
g_return_val_if_fail (value != NULL, FALSE);
g_return_val_if_fail (lat != NULL, FALSE);
_gweather_info_ensure_moon (info);
- if (!info->priv->moonValid)
+ if (!priv->moonValid)
return FALSE;
- *value = info->priv->moonphase;
- *lat = info->priv->moonlatitude;
+ *value = priv->moonphase;
+ *lat = priv->moonlatitude;
return TRUE;
}
@@ -2067,15 +2093,13 @@ gweather_info_get_value_wind (GWeatherInfo *info,
gdouble *speed,
GWeatherWindDirection *direction)
{
- GWeatherInfoPrivate *priv;
+ GWeatherInfoPrivate *priv = gweather_info_get_instance_private (info);
gboolean res = FALSE;
g_return_val_if_fail (GWEATHER_IS_INFO (info), FALSE);
g_return_val_if_fail (speed != NULL, FALSE);
g_return_val_if_fail (direction != NULL, FALSE);
- priv = info->priv;
-
if (!priv->valid)
return FALSE;
@@ -2101,13 +2125,15 @@ gweather_info_get_value_pressure (GWeatherInfo *info,
GWeatherPressureUnit unit,
gdouble *value)
{
+ GWeatherInfoPrivate *priv = gweather_info_get_instance_private (info);
+
g_return_val_if_fail (GWEATHER_IS_INFO (info), FALSE);
g_return_val_if_fail (value != NULL, FALSE);
- if (!info->priv->valid)
+ if (!priv->valid)
return FALSE;
- return pressure_value (info->priv->pressure, unit, value, info->priv->settings);
+ return pressure_value (priv->pressure, unit, value, priv->settings);
}
/**
@@ -2123,20 +2149,22 @@ gweather_info_get_value_visibility (GWeatherInfo *info,
GWeatherDistanceUnit unit,
gdouble *value)
{
+ GWeatherInfoPrivate *priv = gweather_info_get_instance_private (info);
+
g_return_val_if_fail (GWEATHER_IS_INFO (info), FALSE);
g_return_val_if_fail (value != NULL, FALSE);
- if (!info->priv->valid)
+ if (!priv->valid)
return FALSE;
- return distance_value (info->priv->visibility, unit, value, info->priv->settings);
+ return distance_value (priv->visibility, unit, value, priv->settings);
}
static void
gweather_info_set_location_internal (GWeatherInfo *info,
GWeatherLocation *location)
{
- GWeatherInfoPrivate *priv = info->priv;
+ GWeatherInfoPrivate *priv = gweather_info_get_instance_private (info);
GVariant *default_loc = NULL;
const gchar *name = NULL;
gboolean latlon_override = FALSE;
@@ -2212,22 +2240,26 @@ gweather_info_set_location (GWeatherInfo *info,
GWeatherProvider
gweather_info_get_enabled_providers (GWeatherInfo *info)
{
+ GWeatherInfoPrivate *priv = gweather_info_get_instance_private (info);
+
g_return_val_if_fail (GWEATHER_IS_INFO (info),
GWEATHER_PROVIDER_NONE);
- return info->priv->providers;
+ return priv->providers;
}
void
gweather_info_set_enabled_providers (GWeatherInfo *info,
GWeatherProvider providers)
{
+ GWeatherInfoPrivate *priv = gweather_info_get_instance_private (info);
+
g_return_if_fail (GWEATHER_IS_INFO (info));
- if (info->priv->providers == providers)
+ if (priv->providers == providers)
return;
- info->priv->providers = providers;
+ priv->providers = providers;
gweather_info_abort (info);
gweather_info_update (info);
@@ -2262,7 +2294,7 @@ gweather_info_get_property (GObject *object,
GParamSpec *pspec)
{
GWeatherInfo *self = GWEATHER_INFO (object);
- GWeatherInfoPrivate *priv = self->priv;
+ GWeatherInfoPrivate *priv = gweather_info_get_instance_private (self);
switch (property_id) {
case PROP_LOCATION:
@@ -2282,8 +2314,6 @@ gweather_info_class_init (GWeatherInfoClass *klass)
GParamSpec *pspec;
GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
- g_type_class_add_private (klass, sizeof(GWeatherInfoPrivate));
-
gobject_class->dispose = gweather_info_dispose;
gobject_class->finalize = gweather_info_finalize;
gobject_class->set_property = gweather_info_set_property;
@@ -2350,6 +2380,13 @@ gweather_info_new (GWeatherLocation *location)
GWeatherInfo *
_gweather_info_new_clone (GWeatherInfo *other)
{
- return g_object_new (GWEATHER_TYPE_INFO, "location", other->priv->glocation, NULL);
+ GWeatherInfoPrivate *priv = gweather_info_get_instance_private (other);
+
+ return g_object_new (GWEATHER_TYPE_INFO, "location", priv->glocation, NULL);
}
+GWeatherInfoPrivate *
+_gweather_info_get_instance_private (GWeatherInfo *info)
+{
+ return gweather_info_get_instance_private (info);
+}
diff --git a/libgweather/gweather-weather.h b/libgweather/gweather-weather.h
index 1a800d06..10b492f1 100644
--- a/libgweather/gweather-weather.h
+++ b/libgweather/gweather-weather.h
@@ -49,23 +49,9 @@ typedef enum { /*< flags, underscore_name=gweather_provider >*/
GWEATHER_PROVIDER_ALL = 31
} GWeatherProvider;
-typedef struct _GWeatherInfo GWeatherInfo;
-typedef struct _GWeatherInfoClass GWeatherInfoClass;
-typedef struct _GWeatherInfoPrivate GWeatherInfoPrivate;
-
-#define GWEATHER_TYPE_INFO (gweather_info_get_type ())
-#define GWEATHER_INFO(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GWEATHER_TYPE_INFO,
GWeatherInfo))
-#define GWEATHER_IS_INFO(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GWEATHER_TYPE_INFO))
-#define GWEATHER_INFO_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GWEATHER_TYPE_INFO,
GWeatherInfoClass))
-#define GWEATHER_IS_INFO_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GWEATHER_TYPE_INFO))
-#define GWEATHER_INFO_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GWEATHER_TYPE_INFO,
GWeatherInfoClass))
-
-struct _GWeatherInfo {
- /*< private >*/
- GObject parent_instance;
-
- GWeatherInfoPrivate *priv;
-};
+#define GWEATHER_TYPE_INFO (gweather_info_get_type ())
+GWEATHER_EXTERN
+G_DECLARE_DERIVABLE_TYPE (GWeatherInfo, gweather_info, GWEATHER, INFO, GObject)
struct _GWeatherInfoClass {
/*< private >*/
@@ -75,8 +61,6 @@ struct _GWeatherInfoClass {
void (*updated) (GWeatherInfo *info);
};
-GWEATHER_EXTERN
-GType gweather_info_get_type (void) G_GNUC_CONST;
GWEATHER_EXTERN
GWeatherInfo * gweather_info_new (GWeatherLocation *location);
GWEATHER_EXTERN
diff --git a/libgweather/test_metar.c b/libgweather/test_metar.c
index 46ff76d6..9dd6de96 100644
--- a/libgweather/test_metar.c
+++ b/libgweather/test_metar.c
@@ -19,15 +19,17 @@
static void
print_info (GWeatherInfo *info)
{
+ GWeatherInfoPrivate *priv = _gweather_info_get_instance_private (info);
+
if (gweather_info_is_valid (info)) {
- g_message ("Weather updated successfully for %s", info->priv->location.code);
+ g_message ("Weather updated successfully for %s", priv->location.code);
} else {
- g_warning ("Failed to parse weather for %s", info->priv->location.code);
+ g_warning ("Failed to parse weather for %s", priv->location.code);
return;
}
printf ("Returned info:\n");
- printf (" update: %s", ctime (&info->priv->update));
+ printf (" update: %s", ctime (&priv->update));
printf (" sky: %s\n", gweather_info_get_sky (info));
printf (" cond: %s\n", gweather_info_get_conditions (info));
printf (" temp: %s\n", gweather_info_get_temp (info));
@@ -63,6 +65,7 @@ main (int argc, char **argv)
char buf[BUFLEN];
int len;
GWeatherInfo *info;
+ GWeatherInfoPrivate *priv;
context = g_option_context_new ("- test libgweather metar parser");
g_option_context_add_main_entries (context, entries, NULL);
@@ -79,9 +82,10 @@ main (int argc, char **argv)
loop = g_main_loop_new (NULL, TRUE);
info = g_object_new (GWEATHER_TYPE_INFO, NULL);
- info->priv->location.code = g_strdup (code);
- info->priv->location.latlon_valid = TRUE;
- info->priv->session = soup_session_new ();
+ priv = _gweather_info_get_instance_private (info);
+ priv->location.code = g_strdup (code);
+ priv->location.latlon_valid = TRUE;
+ priv->session = soup_session_new ();
g_signal_connect (G_OBJECT (info), "updated",
G_CALLBACK (weather_updated_cb), loop);
@@ -111,7 +115,8 @@ main (int argc, char **argv)
/* a bit hackish... */
info = g_object_new (GWEATHER_TYPE_INFO, NULL);
- info->priv->valid = 1;
+ priv = _gweather_info_get_instance_private (info);
+ priv->valid = 1;
metar_parse (buf, info);
print_info (info);
}
diff --git a/libgweather/test_sun_moon.c b/libgweather/test_sun_moon.c
index 33cada14..dcbba8ec 100644
--- a/libgweather/test_sun_moon.c
+++ b/libgweather/test_sun_moon.c
@@ -49,7 +49,7 @@ main (int argc, char **argv)
}
info = g_object_new (GWEATHER_TYPE_INFO, NULL);
- priv = info->priv;
+ priv = _gweather_info_get_instance_private (info);
priv->location.latitude = DEGREES_TO_RADIANS(latitude);
priv->location.longitude = DEGREES_TO_RADIANS(longitude);
priv->location.latlon_valid = TRUE;
diff --git a/libgweather/weather-iwin.c b/libgweather/weather-iwin.c
index e19ba506..838c7a40 100644
--- a/libgweather/weather-iwin.c
+++ b/libgweather/weather-iwin.c
@@ -134,7 +134,8 @@ parseForecastXml (const char *buff, GWeatherInfo *master_info)
for (i = 0; i < 7; i++) {
GWeatherInfo *nfo = _gweather_info_new_clone (master_info);
- nfo->priv->current_time = nfo->priv->update = update_times[i];
+ GWeatherInfoPrivate *priv = _gweather_info_get_instance_private (nfo);
+ priv->current_time = priv->update = update_times[i];
if (nfo)
res = g_slist_append (res, nfo);
@@ -153,7 +154,7 @@ parseForecastXml (const char *buff, GWeatherInfo *master_info)
for (c = p->children; c && at; c = c->next) {
if (isElem (c, "value")) {
GWeatherInfo *nfo = (GWeatherInfo *)at->data;
- GWeatherInfoPrivate *priv = nfo->priv;
+ GWeatherInfoPrivate *priv = _gweather_info_get_instance_private (nfo);
xmlChar *val = xmlNodeGetContent (c);
/* can pass some values as <value xsi:nil="true"/> */
@@ -185,7 +186,7 @@ parseForecastXml (const char *buff, GWeatherInfo *master_info)
for (c = p->children; c && at; c = c->next) {
if (c->name && isElem (c, "weather-conditions")) {
GWeatherInfo *nfo = at->data;
- GWeatherInfoPrivate *priv = nfo->priv;
+ GWeatherInfoPrivate *priv = _gweather_info_get_instance_private (nfo);
xmlChar *val = xmlGetProp (c, XC "weather-summary");
if (val && nfo) {
@@ -271,7 +272,7 @@ parseForecastXml (const char *buff, GWeatherInfo *master_info)
They should be all valid or all invalid. */
for (r = res; r; r = r->next) {
GWeatherInfo *nfo = r->data;
- GWeatherInfoPrivate *priv = nfo->priv;
+ GWeatherInfoPrivate *priv = _gweather_info_get_instance_private (nfo);
if (!nfo || !priv->valid) {
if (r->data)
@@ -332,7 +333,7 @@ iwin_finish (SoupSession *session, SoupMessage *msg, gpointer data)
}
info = data;
- priv = info->priv;
+ priv = _gweather_info_get_instance_private (info);
loc = &priv->location;
g_debug ("iwin data for %s", loc->zone);
@@ -347,7 +348,7 @@ iwin_finish (SoupSession *session, SoupMessage *msg, gpointer data)
gboolean
iwin_start_open (GWeatherInfo *info)
{
- GWeatherInfoPrivate *priv;
+ GWeatherInfoPrivate *priv = _gweather_info_get_instance_private (info);
gchar *url;
WeatherLocation *loc;
SoupMessage *msg;
@@ -357,7 +358,6 @@ iwin_start_open (GWeatherInfo *info)
g_assert (info != NULL);
- priv = info->priv;
loc = &priv->location;
/* No zone (or -) means no weather information from national offices.
diff --git a/libgweather/weather-metar.c b/libgweather/weather-metar.c
index e1ff70ee..4552667a 100644
--- a/libgweather/weather-metar.c
+++ b/libgweather/weather-metar.c
@@ -72,18 +72,19 @@ make_time (gint utcDate, gint utcHour, gint utcMin)
static void
metar_tok_time (gchar *tokp, GWeatherInfo *info)
{
+ GWeatherInfoPrivate *priv = _gweather_info_get_instance_private (info);
gint day, hr, min;
g_debug ("metar_tok_time: %s", tokp);
sscanf (tokp, "%2u%2u%2u", &day, &hr, &min);
- info->priv->update = make_time (day, hr, min);
+ priv->update = make_time (day, hr, min);
}
static void
metar_tok_wind (gchar *tokp, GWeatherInfo *info)
{
- GWeatherInfoPrivate *priv;
+ GWeatherInfoPrivate *priv = _gweather_info_get_instance_private (info);
gchar sdir[4], sspd[4], sgust[4];
gint dir, spd = -1;
gchar *gustp;
@@ -91,8 +92,6 @@ metar_tok_wind (gchar *tokp, GWeatherInfo *info)
g_debug ("metar_tok_wind: %s", tokp);
- priv = info->priv;
-
strncpy (sdir, tokp, 3);
sdir[3] = 0;
dir = (!strcmp (sdir, "VRB")) ? -1 : atoi (sdir);
@@ -153,15 +152,13 @@ metar_tok_wind (gchar *tokp, GWeatherInfo *info)
static void
metar_tok_vis (gchar *tokp, GWeatherInfo *info)
{
- GWeatherInfoPrivate *priv;
+ GWeatherInfoPrivate *priv = _gweather_info_get_instance_private (info);
gchar *pfrac, *pend, *psp;
gchar sval[6];
gint num, den, val;
g_debug ("metar_tok_vis: %s", tokp);
- priv = info->priv;
-
memset (sval, 0, sizeof (sval));
if (!strcmp (tokp,"CAVOK")) {
@@ -205,13 +202,11 @@ metar_tok_vis (gchar *tokp, GWeatherInfo *info)
static void
metar_tok_cloud (gchar *tokp, GWeatherInfo *info)
{
- GWeatherInfoPrivate *priv;
+ GWeatherInfoPrivate *priv = _gweather_info_get_instance_private (info);
gchar stype[4], salt[4];
g_debug ("metar_tok_cloud: %s", tokp);
- priv = info->priv;
-
strncpy (stype, tokp, 3);
stype[3] = 0;
if (strlen (tokp) == 6) {
@@ -239,7 +234,7 @@ metar_tok_cloud (gchar *tokp, GWeatherInfo *info)
static void
metar_tok_pres (gchar *tokp, GWeatherInfo *info)
{
- GWeatherInfoPrivate *priv = info->priv;
+ GWeatherInfoPrivate *priv = _gweather_info_get_instance_private (info);
g_debug ("metar_tok_pres: %s", tokp);
@@ -271,13 +266,11 @@ metar_tok_pres (gchar *tokp, GWeatherInfo *info)
static void
metar_tok_temp (gchar *tokp, GWeatherInfo *info)
{
- GWeatherInfoPrivate *priv;
+ GWeatherInfoPrivate *priv = _gweather_info_get_instance_private (info);
gchar *ptemp, *pdew, *psep;
g_debug ("metar_tok_temp: %s", tokp);
- priv = info->priv;
-
psep = strchr (tokp, '/');
*psep = 0;
ptemp = tokp;
@@ -342,15 +335,13 @@ condition_more_important (GWeatherConditions *which,
static void
metar_tok_cond (gchar *tokp, GWeatherInfo *info)
{
- GWeatherInfoPrivate *priv;
+ GWeatherInfoPrivate *priv = _gweather_info_get_instance_private (info);
GWeatherConditions new_cond;
gchar squal[3], sphen[4];
gchar *pphen;
g_debug ("metar_tok_cond: %s", tokp);
- priv = info->priv;
-
if ((strlen (tokp) > 3) && ((*tokp == '+') || (*tokp == '-')))
++tokp; /* FIX */
@@ -577,8 +568,8 @@ metar_parse (gchar *metar, GWeatherInfo *info)
static void
metar_finish (SoupSession *session, SoupMessage *msg, gpointer data)
{
- GWeatherInfo *info;
- GWeatherInfoPrivate *priv;
+ GWeatherInfo *info = data;
+ GWeatherInfoPrivate *priv = _gweather_info_get_instance_private (info);
WeatherLocation *loc;
const gchar *p, *eoln;
gchar *searchkey, *metar;
@@ -591,9 +582,8 @@ metar_finish (SoupSession *session, SoupMessage *msg, gpointer data)
return;
}
- info = data;
if (SOUP_STATUS_IS_TRANSPORT_ERROR (msg->status_code)) {
- info->priv->network_error = TRUE;
+ priv->network_error = TRUE;
} else {
/* Translators: %d is an error code, and %s the error string */
g_warning (_("Failed to get METAR data: %d %s.\n"),
@@ -604,8 +594,6 @@ metar_finish (SoupSession *session, SoupMessage *msg, gpointer data)
return;
}
- info = data;
- priv = info->priv;
loc = &priv->location;
g_debug ("METAR data for %s", loc->code);
@@ -649,14 +637,12 @@ metar_finish (SoupSession *session, SoupMessage *msg, gpointer data)
void
metar_start_open (GWeatherInfo *info)
{
- GWeatherInfoPrivate *priv;
+ GWeatherInfoPrivate *priv = _gweather_info_get_instance_private (info);
WeatherLocation *loc;
SoupMessage *msg;
g_return_if_fail (info != NULL);
- priv = info->priv;
-
priv->valid = priv->network_error = FALSE;
loc = &priv->location;
diff --git a/libgweather/weather-moon.c b/libgweather/weather-moon.c
index 41f85709..ff23da0b 100644
--- a/libgweather/weather-moon.c
+++ b/libgweather/weather-moon.c
@@ -137,11 +137,9 @@ calc_moon_internal (time_t update, gdouble *moonphase, gdouble *moonlatitude)
void
_gweather_info_ensure_moon (GWeatherInfo *info)
{
- GWeatherInfoPrivate *priv;
+ GWeatherInfoPrivate *priv = _gweather_info_get_instance_private (info);
- priv = info->priv;
-
- if (!info->priv->location.latlon_valid)
+ if (!priv->location.latlon_valid)
return;
if (!priv->moonValid)
@@ -162,7 +160,7 @@ _gweather_info_ensure_moon (GWeatherInfo *info)
static gboolean
calc_moon_phases (GWeatherInfo *info, time_t *phases)
{
- GWeatherInfoPrivate *priv;
+ GWeatherInfoPrivate *priv = _gweather_info_get_instance_private (info);
time_t tmp_update;
gdouble tmp_moonphase;
gdouble tmp_moonlatitude;
@@ -174,7 +172,6 @@ calc_moon_phases (GWeatherInfo *info, time_t *phases)
_gweather_info_ensure_moon (info);
- priv = info->priv;
ptime = phases;
for (idx = 0; idx < 4; idx++) {
diff --git a/libgweather/weather-owm.c b/libgweather/weather-owm.c
index e91eb3b6..890a6155 100644
--- a/libgweather/weather-owm.c
+++ b/libgweather/weather-owm.c
@@ -174,7 +174,7 @@ read_symbol (GWeatherInfo *info,
xmlNodePtr node)
{
xmlChar *val;
- GWeatherInfoPrivate *priv = info->priv;
+ GWeatherInfoPrivate *priv = _gweather_info_get_instance_private (info);
struct owm_symbol *obj, ref;
val = xmlGetProp (node, XC("number"));
@@ -198,6 +198,7 @@ static inline void
read_wind_direction (GWeatherInfo *info,
xmlNodePtr node)
{
+ GWeatherInfoPrivate *priv = _gweather_info_get_instance_private (info);
xmlChar *val;
unsigned int i;
@@ -207,7 +208,7 @@ read_wind_direction (GWeatherInfo *info,
for (i = 0; i < G_N_ELEMENTS (wind_directions); i++) {
if (strcmp ((char*) val, wind_directions[i].name) == 0) {
- info->priv->wind = wind_directions[i].direction;
+ priv->wind = wind_directions[i].direction;
return;
}
}
@@ -217,6 +218,7 @@ static inline void
read_wind_speed (GWeatherInfo *info,
xmlNodePtr node)
{
+ GWeatherInfoPrivate *priv = _gweather_info_get_instance_private (info);
xmlChar *val;
double mps;
@@ -225,13 +227,14 @@ read_wind_speed (GWeatherInfo *info,
return;
mps = g_ascii_strtod ((char*) val, NULL);
- info->priv->windspeed = WINDSPEED_MS_TO_KNOTS (mps);
+ priv->windspeed = WINDSPEED_MS_TO_KNOTS (mps);
}
static inline void
read_temperature (GWeatherInfo *info,
xmlNodePtr node)
{
+ GWeatherInfoPrivate *priv = _gweather_info_get_instance_private (info);
xmlChar *unit;
xmlChar *val;
double celsius;
@@ -245,13 +248,14 @@ read_temperature (GWeatherInfo *info,
return;
celsius = g_ascii_strtod ((char*) val, NULL);
- info->priv->temp = TEMP_C_TO_F (celsius);
+ priv->temp = TEMP_C_TO_F (celsius);
}
static inline void
read_pressure (GWeatherInfo *info,
xmlNodePtr node)
{
+ GWeatherInfoPrivate *priv = _gweather_info_get_instance_private (info);
xmlChar *unit;
xmlChar *val;
double hpa;
@@ -266,13 +270,14 @@ read_pressure (GWeatherInfo *info,
return;
hpa = g_ascii_strtod ((char*) val, NULL);
- info->priv->pressure = PRESSURE_MBAR_TO_INCH (hpa);
+ priv->pressure = PRESSURE_MBAR_TO_INCH (hpa);
}
static inline void
read_humidity (GWeatherInfo *info,
xmlNodePtr node)
{
+ GWeatherInfoPrivate *priv = _gweather_info_get_instance_private (info);
xmlChar *unit;
xmlChar *val;
double percent;
@@ -286,8 +291,8 @@ read_humidity (GWeatherInfo *info,
return;
percent = g_ascii_strtod ((char*) val, NULL);
- info->priv->humidity = percent;
- info->priv->hasHumidity = TRUE;
+ priv->humidity = percent;
+ priv->hasHumidity = TRUE;
}
static inline void
@@ -331,10 +336,10 @@ make_info_from_node (GWeatherInfo *master_info,
g_return_val_if_fail (node->type == XML_ELEMENT_NODE, NULL);
info = _gweather_info_new_clone (master_info);
- priv = info->priv;
+ priv = _gweather_info_get_instance_private (info);
val = xmlGetProp (node, XC("from"));
- priv->current_time = priv->update = date_to_time_t (val, info->priv->location.tz_hint);
+ priv->current_time = priv->update = date_to_time_t (val, priv->location.tz_hint);
xmlFree (val);
fill_info_from_node (info, node);
@@ -346,14 +351,12 @@ static void
parse_forecast_xml (GWeatherInfo *master_info,
SoupMessageBody *body)
{
- GWeatherInfoPrivate *priv;
+ GWeatherInfoPrivate *priv = _gweather_info_get_instance_private (master_info);
xmlDocPtr doc;
xmlXPathContextPtr xpath_ctx;
xmlXPathObjectPtr xpath_result;
int i;
- priv = master_info->priv;
-
doc = xmlParseMemory (body->data, body->length);
if (!doc)
return;
@@ -394,8 +397,8 @@ owm_finish (SoupSession *session,
SoupMessage *msg,
gpointer user_data)
{
- GWeatherInfo *info;
- GWeatherInfoPrivate *priv;
+ GWeatherInfo *info = user_data;
+ GWeatherInfoPrivate *priv = _gweather_info_get_instance_private (info);
WeatherLocation *loc;
if (!SOUP_STATUS_IS_SUCCESSFUL (msg->status_code)) {
@@ -411,8 +414,6 @@ owm_finish (SoupSession *session,
return;
}
- info = user_data;
- priv = info->priv;
loc = &priv->location;
g_debug ("owm data for %lf, %lf", loc->latitude, loc->longitude);
g_debug ("%s", msg->response_body->data);
@@ -424,13 +425,12 @@ owm_finish (SoupSession *session,
gboolean
owm_start_open (GWeatherInfo *info)
{
- GWeatherInfoPrivate *priv;
+ GWeatherInfoPrivate *priv = _gweather_info_get_instance_private (info);
gchar *url;
SoupMessage *message;
WeatherLocation *loc;
gchar latstr[G_ASCII_DTOSTR_BUF_SIZE], lonstr[G_ASCII_DTOSTR_BUF_SIZE];
- priv = info->priv;
loc = &priv->location;
if (!loc->latlon_valid)
diff --git a/libgweather/weather-sun.c b/libgweather/weather-sun.c
index 936b958f..cd4f51da 100644
--- a/libgweather/weather-sun.c
+++ b/libgweather/weather-sun.c
@@ -160,7 +160,7 @@ t0 (time_t date)
static gboolean
calc_sun (GWeatherInfo *info, time_t t)
{
- GWeatherInfoPrivate *priv;
+ GWeatherInfoPrivate *priv = _gweather_info_get_instance_private (info);
gdouble obsLat;
gdouble obsLon;
time_t gm_midn;
@@ -175,7 +175,6 @@ calc_sun (GWeatherInfo *info, time_t t)
gdouble x, u, dt;
/* Approximate preceding local midnight at observer's longitude */
- priv = info->priv;
obsLat = priv->location.latitude;
obsLon = priv->location.longitude;
gm_midn = t - (t % 86400);
@@ -289,11 +288,9 @@ calc_sun (GWeatherInfo *info, time_t t)
void
_gweather_info_ensure_sun (GWeatherInfo *info)
{
- GWeatherInfoPrivate *priv;
+ GWeatherInfoPrivate *priv = _gweather_info_get_instance_private (info);
- priv = info->priv;
-
- if (!info->priv->location.latlon_valid)
+ if (!priv->location.latlon_valid)
return;
if (!priv->sunriseValid && !priv->sunsetValid)
@@ -312,12 +309,10 @@ _gweather_info_ensure_sun (GWeatherInfo *info)
gint
gweather_info_next_sun_event (GWeatherInfo *info)
{
+ GWeatherInfoPrivate *priv = _gweather_info_get_instance_private (info);
time_t now = time (NULL);
struct tm ltm;
time_t nxtEvent;
- GWeatherInfoPrivate *priv;
-
- priv = info->priv;
g_return_val_if_fail (info != NULL, -1);
diff --git a/libgweather/weather-yrno.c b/libgweather/weather-yrno.c
index b9e2e3e2..c5180294 100644
--- a/libgweather/weather-yrno.c
+++ b/libgweather/weather-yrno.c
@@ -170,9 +170,9 @@ static inline void
read_symbol (GWeatherInfo *info,
xmlNodePtr node)
{
+ GWeatherInfoPrivate *priv = _gweather_info_get_instance_private (info);
xmlChar *val;
YrnoSymbol* symbol;
- GWeatherInfoPrivate *priv = info->priv;
val = xmlGetProp (node, XC("number"));
@@ -189,6 +189,7 @@ static inline void
read_wind_direction (GWeatherInfo *info,
xmlNodePtr node)
{
+ GWeatherInfoPrivate *priv = _gweather_info_get_instance_private (info);
xmlChar *val;
unsigned int i;
@@ -200,7 +201,7 @@ read_wind_direction (GWeatherInfo *info,
for (i = 0; i < G_N_ELEMENTS (wind_directions); i++) {
if (strcmp ((char*) val, wind_directions[i].name) == 0) {
- info->priv->wind = wind_directions[i].direction;
+ priv->wind = wind_directions[i].direction;
xmlFree (val);
return;
}
@@ -212,6 +213,7 @@ static inline void
read_wind_speed (GWeatherInfo *info,
xmlNodePtr node)
{
+ GWeatherInfoPrivate *priv = _gweather_info_get_instance_private (info);
xmlChar *val;
double mps;
@@ -220,7 +222,7 @@ read_wind_speed (GWeatherInfo *info,
return;
mps = g_ascii_strtod ((char*) val, NULL);
- info->priv->windspeed = WINDSPEED_MS_TO_KNOTS (mps);
+ priv->windspeed = WINDSPEED_MS_TO_KNOTS (mps);
xmlFree (val);
}
@@ -228,6 +230,7 @@ static inline void
read_temperature (GWeatherInfo *info,
xmlNodePtr node)
{
+ GWeatherInfoPrivate *priv = _gweather_info_get_instance_private (info);
xmlChar *val;
double celsius;
@@ -236,7 +239,7 @@ read_temperature (GWeatherInfo *info,
return;
celsius = g_ascii_strtod ((char*) val, NULL);
- info->priv->temp = TEMP_C_TO_F (celsius);
+ priv->temp = TEMP_C_TO_F (celsius);
xmlFree (val);
}
@@ -244,6 +247,7 @@ static inline void
read_pressure (GWeatherInfo *info,
xmlNodePtr node)
{
+ GWeatherInfoPrivate *priv = _gweather_info_get_instance_private (info);
xmlChar *val;
double hpa;
@@ -252,7 +256,7 @@ read_pressure (GWeatherInfo *info,
return;
hpa = g_ascii_strtod ((char*) val, NULL);
- info->priv->pressure = PRESSURE_MBAR_TO_INCH (hpa);
+ priv->pressure = PRESSURE_MBAR_TO_INCH (hpa);
xmlFree (val);
}
@@ -260,6 +264,7 @@ static inline void
read_humidity (GWeatherInfo *info,
xmlNodePtr node)
{
+ GWeatherInfoPrivate *priv = _gweather_info_get_instance_private (info);
xmlChar *val;
double percent;
@@ -268,8 +273,8 @@ read_humidity (GWeatherInfo *info,
return;
percent = g_ascii_strtod ((char*) val, NULL);
- info->priv->humidity = percent;
- info->priv->hasHumidity = TRUE;
+ priv->humidity = percent;
+ priv->hasHumidity = TRUE;
xmlFree (val);
}
@@ -307,14 +312,12 @@ static void
parse_forecast_xml_new (GWeatherInfo *master_info,
SoupMessageBody *body)
{
- GWeatherInfoPrivate *priv;
+ GWeatherInfoPrivate *priv = _gweather_info_get_instance_private (master_info);
xmlDocPtr doc;
xmlXPathContextPtr xpath_ctx;
xmlXPathObjectPtr xpath_result;
int i;
- priv = master_info->priv;
-
doc = xmlParseMemory (body->data, body->length);
if (!doc)
return;
@@ -328,6 +331,7 @@ parse_forecast_xml_new (GWeatherInfo *master_info,
for (i = 0; i < xpath_result->nodesetval->nodeNr; i++) {
xmlNodePtr node;
GWeatherInfo *info;
+ GWeatherInfoPrivate *info_priv;
xmlChar *val;
time_t from_time, to_time;
xmlNode *location;
@@ -352,7 +356,8 @@ parse_forecast_xml_new (GWeatherInfo *master_info,
*/
if (from_time == to_time) {
info = _gweather_info_new_clone (master_info);
- info->priv->current_time = info->priv->update = from_time;
+ info_priv = _gweather_info_get_instance_private (info);
+ info_priv->current_time = info_priv->update = from_time;
for (location = node->children;
location && location->type != XML_ELEMENT_NODE;
@@ -414,7 +419,7 @@ yrno_finish_new (SoupSession *session,
}
info = user_data;
- priv = info->priv;
+ priv = _gweather_info_get_instance_private (info);
loc = &priv->location;
g_debug ("yrno data for %lf, %lf", loc->latitude, loc->longitude);
g_debug ("%s", msg->response_body->data);
@@ -431,13 +436,12 @@ yrno_finish_new (SoupSession *session,
gboolean
yrno_start_open (GWeatherInfo *info)
{
- GWeatherInfoPrivate *priv;
+ GWeatherInfoPrivate *priv = _gweather_info_get_instance_private (info);
gchar *url;
SoupMessage *message;
WeatherLocation *loc;
gchar latstr[G_ASCII_DTOSTR_BUF_SIZE], lonstr[G_ASCII_DTOSTR_BUF_SIZE];
- priv = info->priv;
loc = &priv->location;
if (!loc->latlon_valid)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]