diff options
author | Bastien Nocera <hadess@hadess.net> | 2021-01-11 14:23:04 +0100 |
---|---|---|
committer | Bastien Nocera <hadess@hadess.net> | 2021-01-12 10:44:44 +0100 |
commit | da3b4de921fcb1ef17d2b5b226ad9e4772f41e5e (patch) | |
tree | a9bf684954b360eeea328e7019cc89f906e05486 /libgweather | |
parent | 8c8d515fb55fa898b77cdd2694ff0faca0c08938 (diff) | |
download | libgweather-da3b4de921fcb1ef17d2b5b226ad9e4772f41e5e.tar.gz |
gweather: Remove intermediate private struct for GWeatherInfo
Diffstat (limited to 'libgweather')
-rw-r--r-- | libgweather/gweather-private.h | 5 | ||||
-rw-r--r-- | libgweather/gweather-weather.c | 531 | ||||
-rw-r--r-- | libgweather/gweather-weather.h | 21 | ||||
-rw-r--r-- | libgweather/test_metar.c | 14 | ||||
-rw-r--r-- | libgweather/test_sun_moon.c | 27 | ||||
-rw-r--r-- | libgweather/weather-iwin.c | 43 | ||||
-rw-r--r-- | libgweather/weather-metar.c | 118 | ||||
-rw-r--r-- | libgweather/weather-metno.c | 48 | ||||
-rw-r--r-- | libgweather/weather-moon.c | 22 | ||||
-rw-r--r-- | libgweather/weather-owm.c | 40 | ||||
-rw-r--r-- | libgweather/weather-sun.c | 51 |
11 files changed, 387 insertions, 533 deletions
diff --git a/libgweather/gweather-private.h b/libgweather/gweather-private.h index 9ada322..5f18e91 100644 --- a/libgweather/gweather-private.h +++ b/libgweather/gweather-private.h @@ -110,9 +110,10 @@ typedef gdouble GWeatherPressure; typedef gdouble GWeatherVisibility; typedef time_t GWeatherUpdate; -struct _GWeatherInfoPrivate { - GWeatherProvider providers; +struct _GWeatherInfo { + GObject parent_instance; + GWeatherProvider providers; GSettings *settings; gboolean valid; diff --git a/libgweather/gweather-weather.c b/libgweather/gweather-weather.c index a57e228..87aab72 100644 --- a/libgweather/gweather-weather.c +++ b/libgweather/gweather-weather.c @@ -62,6 +62,8 @@ #define RADAR_KEY "radar" #define DEFAULT_LOCATION "default-location" +#include "gweather-private.h" + enum { PROP_0, PROP_LOCATION, @@ -309,7 +311,7 @@ gweather_conditions_to_string (GWeatherConditions *cond) static gboolean requests_init (GWeatherInfo *info) { - if (info->priv->requests_pending) + if (info->requests_pending) return FALSE; return TRUE; @@ -319,7 +321,7 @@ void _gweather_info_begin_request (GWeatherInfo *info, SoupMessage *message) { - info->priv->requests_pending = g_slist_prepend (info->priv->requests_pending, message); + info->requests_pending = g_slist_prepend (info->requests_pending, message); g_object_ref (message); } @@ -327,20 +329,20 @@ 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; + dest->hasHumidity = src->hasHumidity; + dest->update = src->update; + dest->current_time = src->current_time; + dest->sky = src->sky; + dest->cond = src->cond; + dest->temp = src->temp; + dest->temp_min = src->temp_min; + dest->temp_max = src->temp_max; + dest->dew = src->dew; + dest->humidity = src->humidity; + dest->wind = src->wind; + dest->windspeed = src->windspeed; + dest->pressure = src->pressure; + dest->visibility = src->visibility; } static void @@ -349,18 +351,18 @@ fixup_current_conditions (GWeatherInfo *info) GWeatherInfo *first_forecast; /* Current conditions already available */ - if (info->priv->update != 0) { + if (info->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 (!info->forecast_list || + !info->forecast_list->data) { g_debug ("No forecast list available, not fixing up"); return; } - first_forecast = info->priv->forecast_list->data; + first_forecast = info->forecast_list->data; /* Add current conditions from forecast if close enough */ - if (first_forecast->priv->update - time(NULL) > 60 * 60) { + if (first_forecast->update - time(NULL) > 60 * 60) { g_debug ("Forecast is too far in the future, ignoring"); return; } @@ -373,15 +375,15 @@ void _gweather_info_request_done (GWeatherInfo *info, SoupMessage *message) { - info->priv->requests_pending = g_slist_remove (info->priv->requests_pending, message); + info->requests_pending = g_slist_remove (info->requests_pending, message); g_object_ref (message); - if (info->priv->requests_pending == NULL) { + if (info->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 (info->requests_pending)); } } @@ -392,8 +394,8 @@ free_forecast_list (GWeatherInfo *info) if (!info) return; - g_slist_free_full (info->priv->forecast_list, g_object_unref); - info->priv->forecast_list = NULL; + g_slist_free_full (info->forecast_list, g_object_unref); + info->forecast_list = NULL; } /* Relative humidity computation - thanks to <Olof.Oberg@modopaper.modogroup.com> @@ -439,14 +441,14 @@ 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); + gdouble temp = info->temp; + gdouble wind = WINDSPEED_KNOTS_TO_MPH (info->windspeed); gdouble apparent = -1000.; - gdouble dew = info->priv->dew; + gdouble dew = info->dew; gdouble humidity; - if (info->priv->hasHumidity) - humidity = info->priv->humidity; + if (info->hasHumidity) + humidity = info->humidity; else humidity = calc_humidity (temp, dew); @@ -528,43 +530,41 @@ calc_apparent (GWeatherInfo *info) static void gweather_info_reset (GWeatherInfo *info) { - GWeatherInfoPrivate *priv = info->priv; - - g_free (priv->forecast_attribution); - priv->forecast_attribution = NULL; + g_free (info->forecast_attribution); + info->forecast_attribution = NULL; free_forecast_list (info); - if (priv->radar != NULL) { - g_object_unref (priv->radar); - priv->radar = NULL; + if (info->radar != NULL) { + g_object_unref (info->radar); + info->radar = NULL; } - priv->update = 0; - priv->current_time = time(NULL); - priv->sky = -1; - priv->cond.significant = FALSE; - priv->cond.phenomenon = GWEATHER_PHENOMENON_NONE; - priv->cond.qualifier = GWEATHER_QUALIFIER_NONE; - priv->temp = -1000.0; - priv->tempMinMaxValid = FALSE; - priv->temp_min = -1000.0; - priv->temp_max = -1000.0; - priv->dew = -1000.0; - priv->humidity = -1.0; - priv->wind = -1; - priv->windspeed = -1; - priv->pressure = -1.0; - priv->visibility = -1.0; - priv->sunriseValid = FALSE; - priv->sunsetValid = FALSE; - priv->moonValid = FALSE; - priv->sunrise = 0; - priv->sunset = 0; - priv->moonphase = 0; - priv->moonlatitude = 0; - priv->forecast_list = NULL; - priv->radar = NULL; + info->update = 0; + info->current_time = time(NULL); + info->sky = -1; + info->cond.significant = FALSE; + info->cond.phenomenon = GWEATHER_PHENOMENON_NONE; + info->cond.qualifier = GWEATHER_QUALIFIER_NONE; + info->temp = -1000.0; + info->tempMinMaxValid = FALSE; + info->temp_min = -1000.0; + info->temp_max = -1000.0; + info->dew = -1000.0; + info->humidity = -1.0; + info->wind = -1; + info->windspeed = -1; + info->pressure = -1.0; + info->visibility = -1.0; + info->sunriseValid = FALSE; + info->sunsetValid = FALSE; + info->moonValid = FALSE; + info->sunrise = 0; + info->sunset = 0; + info->moonphase = 0; + info->moonlatitude = 0; + info->forecast_list = NULL; + info->radar = NULL; } static void @@ -572,33 +572,27 @@ settings_changed_cb (GSettings *settings, const char *key, GWeatherInfo *info) { - GWeatherInfoPrivate *priv = info->priv; - /* Only emit the signal if no network requests are pending. Otherwise just wait for the update that will happen at the end */ - if (priv->requests_pending == NULL) + if (info->requests_pending == NULL) g_signal_emit (info, gweather_info_signals[SIGNAL_UPDATED], 0); } void gweather_info_init (GWeatherInfo *info) { - GWeatherInfoPrivate *priv; + info->providers = GWEATHER_PROVIDER_METAR | GWEATHER_PROVIDER_IWIN; + info->settings = g_settings_new ("org.gnome.GWeather"); - priv = info->priv = G_TYPE_INSTANCE_GET_PRIVATE (info, GWEATHER_TYPE_INFO, GWeatherInfoPrivate); - - priv->providers = GWEATHER_PROVIDER_METAR | GWEATHER_PROVIDER_IWIN; - priv->settings = g_settings_new ("org.gnome.GWeather"); - - g_signal_connect_object (priv->settings, "changed", + g_signal_connect_object (info->settings, "changed", G_CALLBACK (settings_changed_cb), info, 0); - priv->radar_url = g_settings_get_string (priv->settings, RADAR_KEY); - if (g_strcmp0 (priv->radar_url, "") == 0) { - g_free (priv->radar_url); - priv->radar_url = NULL; + info->radar_url = g_settings_get_string (info->settings, RADAR_KEY); + if (g_strcmp0 (info->radar_url, "") == 0) { + g_free (info->radar_url); + info->radar_url = NULL; } gweather_info_reset (info); @@ -701,7 +695,6 @@ gweather_info_store_cache (void) void gweather_info_update (GWeatherInfo *info) { - GWeatherInfoPrivate *priv = info->priv; gboolean ok; /* Update in progress */ @@ -710,27 +703,27 @@ gweather_info_update (GWeatherInfo *info) gweather_info_reset (info); - if (!priv->session) - priv->session = ref_session (); + if (!info->session) + info->session = ref_session (); - if (priv->providers & GWEATHER_PROVIDER_METAR) + if (info->providers & GWEATHER_PROVIDER_METAR) metar_start_open (info); ok = FALSE; /* Try national forecast services first */ - if (priv->providers & GWEATHER_PROVIDER_IWIN) + if (info->providers & GWEATHER_PROVIDER_IWIN) ok = iwin_start_open (info); if (ok) return; /* Try met.no next */ - if (priv->providers & GWEATHER_PROVIDER_MET_NO) + if (info->providers & GWEATHER_PROVIDER_MET_NO) ok = metno_start_open (info); if (ok) return; /* Try OpenWeatherMap next */ - if (priv->providers & GWEATHER_PROVIDER_OWM) + if (info->providers & GWEATHER_PROVIDER_OWM) owm_start_open (info); } @@ -742,40 +735,39 @@ gweather_info_abort (GWeatherInfo *info) g_return_if_fail (GWEATHER_IS_INFO (info)); - if (info->priv->session == NULL) { - g_assert (info->priv->requests_pending == NULL); + if (info->session == NULL) { + g_assert (info->requests_pending == NULL); return; } - list = info->priv->requests_pending; + list = info->requests_pending; /* to block updated signals */ - info->priv->requests_pending = &dummy; + info->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 (info->session, iter->data, SOUP_STATUS_CANCELLED); g_slist_free (list); - info->priv->requests_pending = NULL; + info->requests_pending = NULL; } static void gweather_info_dispose (GObject *object) { GWeatherInfo *info = GWEATHER_INFO (object); - GWeatherInfoPrivate *priv = info->priv; gweather_info_abort (info); - g_clear_object (&priv->session); + g_clear_object (&info->session); free_forecast_list (info); - if (priv->radar != NULL) { - g_object_unref (priv->radar); - priv->radar = NULL; + if (info->radar != NULL) { + g_object_unref (info->radar); + info->radar = NULL; } - priv->valid = FALSE; + info->valid = FALSE; G_OBJECT_CLASS (gweather_info_parent_class)->dispose (object); } @@ -784,18 +776,17 @@ static void gweather_info_finalize (GObject *object) { GWeatherInfo *info = GWEATHER_INFO (object); - GWeatherInfoPrivate *priv = info->priv; - _weather_location_free (&priv->location); - g_clear_object (&priv->settings); + _weather_location_free (&info->location); + g_clear_object (&info->settings); - if (priv->glocation) - gweather_location_unref (priv->glocation); + if (info->glocation) + gweather_location_unref (info->glocation); - g_free (priv->radar_url); - priv->radar_url = NULL; + g_free (info->radar_url); + info->radar_url = NULL; - g_free (priv->forecast_attribution); + g_free (info->forecast_attribution); G_OBJECT_CLASS (gweather_info_parent_class)->finalize (object); } @@ -804,21 +795,21 @@ gboolean gweather_info_is_valid (GWeatherInfo *info) { g_return_val_if_fail (GWEATHER_IS_INFO (info), FALSE); - return info->priv->valid; + return info->valid; } gboolean gweather_info_network_error (GWeatherInfo *info) { g_return_val_if_fail (GWEATHER_IS_INFO (info), FALSE); - return info->priv->network_error; + return info->network_error; } const GWeatherLocation * gweather_info_get_location (GWeatherInfo *info) { g_return_val_if_fail (GWEATHER_IS_INFO (info), NULL); - return info->priv->glocation; + return info->glocation; } gchar * @@ -826,7 +817,7 @@ gweather_info_get_location_name (GWeatherInfo *info) { g_return_val_if_fail (GWEATHER_IS_INFO (info), NULL); - return g_strdup(info->priv->location.name); + return g_strdup(info->location.name); } gchar * @@ -836,11 +827,11 @@ gweather_info_get_update (GWeatherInfo *info) g_return_val_if_fail (GWEATHER_IS_INFO (info), NULL); - if (!info->priv->valid) + if (!info->valid) return g_strdup ("-"); - if (info->priv->update != 0) { - GDateTime *now = g_date_time_new_from_unix_local (info->priv->update); + if (info->update != 0) { + GDateTime *now = g_date_time_new_from_unix_local (info->update); out = g_date_time_format (now, _("%a, %b %d / %H∶%M")); if (!out) @@ -857,20 +848,20 @@ gchar * gweather_info_get_sky (GWeatherInfo *info) { g_return_val_if_fail (GWEATHER_IS_INFO (info), NULL); - if (!info->priv->valid) + if (!info->valid) return g_strdup("-"); - if (info->priv->sky < 0) + if (info->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 (info->sky)); } gchar * gweather_info_get_conditions (GWeatherInfo *info) { g_return_val_if_fail (GWEATHER_IS_INFO (info), NULL); - if (!info->priv->valid) + if (!info->valid) return g_strdup("-"); - return g_strdup(gweather_conditions_to_string (&info->priv->cond)); + return g_strdup(gweather_conditions_to_string (&info->cond)); } static gboolean @@ -976,71 +967,60 @@ temperature_string (gfloat temp_f, GWeatherTemperatureUnit to_unit, gboolean wan gchar * gweather_info_get_temp (GWeatherInfo *info) { - GWeatherInfoPrivate *priv; - g_return_val_if_fail (GWEATHER_IS_INFO (info), NULL); - priv = info->priv; - if (!priv->valid) + if (!info->valid) return g_strdup("-"); - if (priv->temp < -500.0) + if (info->temp < -500.0) return g_strdup(C_("temperature", "Unknown")); - return temperature_string (priv->temp, g_settings_get_enum (priv->settings, TEMPERATURE_UNIT), FALSE); + return temperature_string (info->temp, g_settings_get_enum (info->settings, TEMPERATURE_UNIT), FALSE); } gchar * gweather_info_get_temp_min (GWeatherInfo *info) { - GWeatherInfoPrivate *priv; - g_return_val_if_fail (GWEATHER_IS_INFO (info), NULL); - priv = info->priv; - if (!priv->valid || !priv->tempMinMaxValid) + if (!info->valid || !info->tempMinMaxValid) return g_strdup("-"); - if (priv->temp_min < -500.0) + if (info->temp_min < -500.0) return g_strdup(C_("temperature", "Unknown")); - return temperature_string (priv->temp_min, g_settings_get_enum (priv->settings, TEMPERATURE_UNIT), FALSE); + return temperature_string (info->temp_min, g_settings_get_enum (info->settings, TEMPERATURE_UNIT), FALSE); } gchar * gweather_info_get_temp_max (GWeatherInfo *info) { - GWeatherInfoPrivate *priv; - g_return_val_if_fail (GWEATHER_IS_INFO (info), NULL); - priv = info->priv; - if (!priv->valid || !priv->tempMinMaxValid) + if (!info->valid || !info->tempMinMaxValid) return g_strdup("-"); - if (priv->temp_max < -500.0) + if (info->temp_max < -500.0) return g_strdup(C_("temperature", "Unknown")); - return temperature_string (priv->temp_max, g_settings_get_enum (priv->settings, TEMPERATURE_UNIT), FALSE); + return temperature_string (info->temp_max, g_settings_get_enum (info->settings, TEMPERATURE_UNIT), FALSE); } gchar * gweather_info_get_dew (GWeatherInfo *info) { - GWeatherInfoPrivate *priv; gdouble dew; g_return_val_if_fail (GWEATHER_IS_INFO (info), NULL); - priv = info->priv; - if (!priv->valid) + if (!info->valid) return g_strdup("-"); - if (priv->hasHumidity) - dew = calc_dew (priv->temp, priv->humidity); + if (info->hasHumidity) + dew = calc_dew (info->temp, info->humidity); else - dew = priv->dew; + dew = info->dew; if (dew < -500.0) return g_strdup(C_("dew", "Unknown")); - return temperature_string (priv->dew, g_settings_get_enum (priv->settings, TEMPERATURE_UNIT), FALSE); + return temperature_string (info->dew, g_settings_get_enum (info->settings, TEMPERATURE_UNIT), FALSE); } gchar * @@ -1050,13 +1030,13 @@ gweather_info_get_humidity (GWeatherInfo *info) g_return_val_if_fail (GWEATHER_IS_INFO (info), NULL); - if (!info->priv->valid) + if (!info->valid) return g_strdup("-"); - if (info->priv->hasHumidity) - humidity = info->priv->humidity; + if (info->hasHumidity) + humidity = info->humidity; else - humidity = calc_humidity (info->priv->temp, info->priv->dew); + humidity = calc_humidity (info->temp, info->dew); if (humidity < 0.0) return g_strdup(C_("humidity", "Unknown")); @@ -1067,20 +1047,18 @@ gweather_info_get_humidity (GWeatherInfo *info) gchar * gweather_info_get_apparent (GWeatherInfo *info) { - GWeatherInfoPrivate *priv; gdouble apparent; g_return_val_if_fail (GWEATHER_IS_INFO (info), NULL); - priv = info->priv; - if (!priv->valid) + if (!info->valid) return g_strdup("-"); apparent = calc_apparent (info); if (apparent < -500.0) return g_strdup(C_("temperature", "Unknown")); - return temperature_string (apparent, g_settings_get_enum (priv->settings, TEMPERATURE_UNIT), FALSE); + return temperature_string (apparent, g_settings_get_enum (info->settings, TEMPERATURE_UNIT), FALSE); } static GWeatherSpeedUnit @@ -1133,26 +1111,22 @@ windspeed_string (gfloat knots, GWeatherSpeedUnit to_unit) gchar * gweather_info_get_wind (GWeatherInfo *info) { - GWeatherInfoPrivate *priv; - g_return_val_if_fail (GWEATHER_IS_INFO (info), NULL); - priv = info->priv; - - if (!priv->valid) + if (!info->valid) return g_strdup("-"); - if (priv->windspeed < 0.0 || priv->wind < 0) + if (info->windspeed < 0.0 || info->wind < 0) return g_strdup(C_("wind speed", "Unknown")); - if (priv->windspeed == 0.00) { + if (info->windspeed == 0.00) { return g_strdup(_("Calm")); } else { gchar *speed_string; gchar *wind_string; - speed_string = windspeed_string (priv->windspeed, g_settings_get_enum (priv->settings, SPEED_UNIT)); + speed_string = windspeed_string (info->windspeed, g_settings_get_enum (info->settings, SPEED_UNIT)); /* TRANSLATOR: This is 'wind direction' / 'wind speed' */ - wind_string = g_strdup_printf (_("%s / %s"), gweather_wind_direction_to_string (priv->wind), speed_string); + wind_string = g_strdup_printf (_("%s / %s"), gweather_wind_direction_to_string (info->wind), speed_string); g_free (speed_string); return wind_string; @@ -1178,38 +1152,35 @@ pressure_unit_to_real (GWeatherPressureUnit unit) gchar * gweather_info_get_pressure (GWeatherInfo *info) { - GWeatherInfoPrivate *priv; GWeatherPressureUnit unit; g_return_val_if_fail (GWEATHER_IS_INFO (info), NULL); - priv = info->priv; - - if (!priv->valid) + if (!info->valid) return g_strdup("-"); - if (priv->pressure < 0.0) + if (info->pressure < 0.0) return g_strdup(C_("pressure", "Unknown")); - unit = pressure_unit_to_real (g_settings_get_enum (priv->settings, PRESSURE_UNIT)); + unit = pressure_unit_to_real (g_settings_get_enum (info->settings, PRESSURE_UNIT)); switch (unit) { case GWEATHER_PRESSURE_UNIT_INCH_HG: /* TRANSLATOR: This is pressure in inches of mercury */ - return g_strdup_printf(_("%.2f inHg"), priv->pressure); + return g_strdup_printf(_("%.2f inHg"), info->pressure); case GWEATHER_PRESSURE_UNIT_MM_HG: /* TRANSLATOR: This is pressure in millimeters of mercury */ - return g_strdup_printf(_("%.1f mmHg"), PRESSURE_INCH_TO_MM (priv->pressure)); + return g_strdup_printf(_("%.1f mmHg"), PRESSURE_INCH_TO_MM (info->pressure)); case GWEATHER_PRESSURE_UNIT_KPA: /* TRANSLATOR: This is pressure in kiloPascals */ - return g_strdup_printf(_("%.2f kPa"), PRESSURE_INCH_TO_KPA (priv->pressure)); + return g_strdup_printf(_("%.2f kPa"), PRESSURE_INCH_TO_KPA (info->pressure)); case GWEATHER_PRESSURE_UNIT_HPA: /* TRANSLATOR: This is pressure in hectoPascals */ - return g_strdup_printf(_("%.2f hPa"), PRESSURE_INCH_TO_HPA (priv->pressure)); + return g_strdup_printf(_("%.2f hPa"), PRESSURE_INCH_TO_HPA (info->pressure)); case GWEATHER_PRESSURE_UNIT_MB: /* TRANSLATOR: This is pressure in millibars */ - return g_strdup_printf(_("%.2f mb"), PRESSURE_INCH_TO_MB (priv->pressure)); + return g_strdup_printf(_("%.2f mb"), PRESSURE_INCH_TO_MB (info->pressure)); case GWEATHER_PRESSURE_UNIT_ATM: /* TRANSLATOR: This is pressure in atmospheres */ - return g_strdup_printf(_("%.3f atm"), PRESSURE_INCH_TO_ATM (priv->pressure)); + return g_strdup_printf(_("%.3f atm"), PRESSURE_INCH_TO_ATM (info->pressure)); case GWEATHER_PRESSURE_UNIT_INVALID: case GWEATHER_PRESSURE_UNIT_DEFAULT: @@ -1238,28 +1209,26 @@ distance_unit_to_real (GWeatherDistanceUnit unit) gchar * gweather_info_get_visibility (GWeatherInfo *info) { - GWeatherInfoPrivate *priv; GWeatherDistanceUnit unit; g_return_val_if_fail (GWEATHER_IS_INFO (info), NULL); - priv = info->priv; - if (!priv->valid) + if (!info->valid) return g_strdup ("-"); - if (priv->visibility < 0.0) + if (info->visibility < 0.0) return g_strdup (C_("visibility", "Unknown")); - unit = distance_unit_to_real (g_settings_get_enum (priv->settings, DISTANCE_UNIT)); + unit = distance_unit_to_real (g_settings_get_enum (info->settings, DISTANCE_UNIT)); switch (unit) { case GWEATHER_DISTANCE_UNIT_MILES: /* TRANSLATOR: This is the visibility in miles */ - return g_strdup_printf (_("%.1f miles"), priv->visibility); + return g_strdup_printf (_("%.1f miles"), info->visibility); case GWEATHER_DISTANCE_UNIT_KM: /* TRANSLATOR: This is the visibility in kilometers */ - return g_strdup_printf (_("%.1f km"), VISIBILITY_SM_TO_KM (priv->visibility)); + return g_strdup_printf (_("%.1f km"), VISIBILITY_SM_TO_KM (info->visibility)); case GWEATHER_DISTANCE_UNIT_METERS: /* TRANSLATOR: This is the visibility in meters */ - return g_strdup_printf (_("%.0fm"), VISIBILITY_SM_TO_M (priv->visibility)); + return g_strdup_printf (_("%.0fm"), VISIBILITY_SM_TO_M (info->visibility)); case GWEATHER_DISTANCE_UNIT_INVALID: case GWEATHER_DISTANCE_UNIT_DEFAULT: @@ -1272,20 +1241,17 @@ gweather_info_get_visibility (GWeatherInfo *info) gchar * gweather_info_get_sunrise (GWeatherInfo *info) { - GWeatherInfoPrivate *priv; 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) + if (!info->sunriseValid) return g_strdup ("-"); - sunrise = g_date_time_new_from_unix_local (priv->sunrise); + sunrise = g_date_time_new_from_unix_local (info->sunrise); buf = g_date_time_format (sunrise, _("%H∶%M")); if (!buf) @@ -1298,20 +1264,17 @@ gweather_info_get_sunrise (GWeatherInfo *info) gchar * gweather_info_get_sunset (GWeatherInfo *info) { - GWeatherInfoPrivate *priv; 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) + if (!info->sunsetValid) return g_strdup ("-"); - sunset = g_date_time_new_from_unix_local (priv->sunset); + sunset = g_date_time_new_from_unix_local (info->sunset); buf = g_date_time_format (sunset, _("%H∶%M")); if (!buf) buf = g_strdup ("-"); @@ -1335,10 +1298,10 @@ gweather_info_get_forecast_list (GWeatherInfo *info) { g_return_val_if_fail (GWEATHER_IS_INFO (info), NULL); - if (!info->priv->valid) + if (!info->valid) return NULL; - return info->priv->forecast_list; + return info->forecast_list; } /** @@ -1351,7 +1314,7 @@ GdkPixbufAnimation * gweather_info_get_radar (GWeatherInfo *info) { g_return_val_if_fail (GWEATHER_IS_INFO (info), NULL); - return info->priv->radar; + return info->radar; } /** @@ -1371,22 +1334,18 @@ gweather_info_get_attribution (GWeatherInfo *info) { g_return_val_if_fail (GWEATHER_IS_INFO (info), NULL); - return info->priv->forecast_attribution; + return info->forecast_attribution; } gchar * gweather_info_get_temp_summary (GWeatherInfo *info) { - GWeatherInfoPrivate *priv; - g_return_val_if_fail (GWEATHER_IS_INFO (info), NULL); - priv = info->priv; - - if (!priv->valid || priv->temp < -500.0) + if (!info->valid || info->temp < -500.0) return g_strdup ("--"); - return temperature_string (priv->temp, g_settings_get_enum (priv->settings, TEMPERATURE_UNIT), TRUE); + return temperature_string (info->temp, g_settings_get_enum (info->settings, TEMPERATURE_UNIT), TRUE); } /** @@ -1403,7 +1362,7 @@ gweather_info_get_weather_summary (GWeatherInfo *info) g_return_val_if_fail (GWEATHER_IS_INFO (info), NULL); - if (!info->priv->valid) + if (!info->valid) return g_strdup (_("Retrieval failed")); buf = gweather_info_get_conditions (info); if (g_str_equal (buf, "-")) { @@ -1432,39 +1391,33 @@ gweather_info_get_weather_summary (GWeatherInfo *info) gboolean gweather_info_is_daytime (GWeatherInfo *info) { - GWeatherInfoPrivate *priv; 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) + if (info->polarNight) return FALSE; - if (priv->midnightSun) + if (info->midnightSun) return TRUE; - current_time = priv->current_time; - return ( !priv->sunriseValid || (current_time >= priv->sunrise) ) && - ( !priv->sunsetValid || (current_time < priv->sunset) ); + current_time = info->current_time; + return ( !info->sunriseValid || (current_time >= info->sunrise) ) && + ( !info->sunsetValid || (current_time < info->sunset) ); } const gchar * gweather_info_get_icon_name (GWeatherInfo *info) { - GWeatherInfoPrivate *priv; 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; + cond = info->cond; + sky = info->sky; if (cond.significant) { if (cond.phenomenon != GWEATHER_PHENOMENON_NONE && @@ -1540,17 +1493,14 @@ gweather_info_get_icon_name (GWeatherInfo *info) const gchar * gweather_info_get_symbolic_icon_name (GWeatherInfo *info) { - GWeatherInfoPrivate *priv; 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; + cond = info->cond; + sky = info->sky; if (cond.significant) { if (cond.phenomenon != GWEATHER_PHENOMENON_NONE && @@ -1791,13 +1741,13 @@ gweather_info_get_value_sky (GWeatherInfo *info, GWeatherSky *sky) g_return_val_if_fail (GWEATHER_IS_INFO (info), FALSE); g_return_val_if_fail (sky != NULL, FALSE); - if (!info->priv->valid) + if (!info->valid) return FALSE; - if (info->priv->sky <= GWEATHER_SKY_INVALID || info->priv->sky >= GWEATHER_SKY_LAST) + if (info->sky <= GWEATHER_SKY_INVALID || info->sky >= GWEATHER_SKY_LAST) return FALSE; - *sky = info->priv->sky; + *sky = info->sky; return TRUE; } @@ -1814,28 +1764,24 @@ gweather_info_get_value_sky (GWeatherInfo *info, GWeatherSky *sky) gboolean gweather_info_get_value_conditions (GWeatherInfo *info, GWeatherConditionPhenomenon *phenomenon, GWeatherConditionQualifier *qualifier) { - GWeatherInfoPrivate *priv; - 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) + if (!info->valid) return FALSE; - if (!priv->cond.significant) + if (!info->cond.significant) return FALSE; - if (!(priv->cond.phenomenon > GWEATHER_PHENOMENON_INVALID && - priv->cond.phenomenon < GWEATHER_PHENOMENON_LAST && - priv->cond.qualifier > GWEATHER_QUALIFIER_INVALID && - priv->cond.qualifier < GWEATHER_QUALIFIER_LAST)) + if (!(info->cond.phenomenon > GWEATHER_PHENOMENON_INVALID && + info->cond.phenomenon < GWEATHER_PHENOMENON_LAST && + info->cond.qualifier > GWEATHER_QUALIFIER_INVALID && + info->cond.qualifier < GWEATHER_QUALIFIER_LAST)) return FALSE; - *phenomenon = priv->cond.phenomenon; - *qualifier = priv->cond.qualifier; + *phenomenon = info->cond.phenomenon; + *qualifier = info->cond.qualifier; return TRUE; } @@ -1854,10 +1800,10 @@ gweather_info_get_value_temp (GWeatherInfo *info, GWeatherTemperatureUnit unit, g_return_val_if_fail (GWEATHER_IS_INFO (info), FALSE); g_return_val_if_fail (value != NULL, FALSE); - if (!info->priv->valid) + if (!info->valid) return FALSE; - return temperature_value (info->priv->temp, unit, value, info->priv->settings); + return temperature_value (info->temp, unit, value, info->settings); } /** @@ -1871,17 +1817,13 @@ gweather_info_get_value_temp (GWeatherInfo *info, GWeatherTemperatureUnit unit, gboolean gweather_info_get_value_temp_min (GWeatherInfo *info, GWeatherTemperatureUnit unit, gdouble *value) { - GWeatherInfoPrivate *priv; - 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) + if (!info->valid || !info->tempMinMaxValid) return FALSE; - return temperature_value (priv->temp_min, unit, value, priv->settings); + return temperature_value (info->temp_min, unit, value, info->settings); } /** @@ -1895,17 +1837,13 @@ 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; - 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) + if (!info->valid || !info->tempMinMaxValid) return FALSE; - return temperature_value (priv->temp_max, unit, value, priv->settings); + return temperature_value (info->temp_max, unit, value, info->settings); } /** @@ -1924,15 +1862,15 @@ gweather_info_get_value_dew (GWeatherInfo *info, GWeatherTemperatureUnit unit, g g_return_val_if_fail (GWEATHER_IS_INFO (info), FALSE); g_return_val_if_fail (value != NULL, FALSE); - if (!info->priv->valid) + if (!info->valid) return FALSE; - if (info->priv->hasHumidity) - dew = calc_dew (info->priv->temp, info->priv->humidity); + if (info->hasHumidity) + dew = calc_dew (info->temp, info->humidity); else - dew = info->priv->dew; + dew = info->dew; - return temperature_value (dew, unit, value, info->priv->settings); + return temperature_value (dew, unit, value, info->settings); } /** @@ -1949,10 +1887,10 @@ gweather_info_get_value_apparent (GWeatherInfo *info, GWeatherTemperatureUnit un g_return_val_if_fail (GWEATHER_IS_INFO (info), FALSE); g_return_val_if_fail (value != NULL, FALSE); - if (!info->priv->valid) + if (!info->valid) return FALSE; - return temperature_value (calc_apparent (info), unit, value, info->priv->settings); + return temperature_value (calc_apparent (info), unit, value, info->settings); } /** @@ -1970,10 +1908,10 @@ gweather_info_get_value_update (GWeatherInfo *info, time_t *value) g_return_val_if_fail (GWEATHER_IS_INFO (info), FALSE); g_return_val_if_fail (value != NULL, FALSE); - if (!info->priv->valid) + if (!info->valid) return FALSE; - *value = info->priv->update; + *value = info->update; return TRUE; } @@ -1993,10 +1931,10 @@ gweather_info_get_value_sunrise (GWeatherInfo *info, time_t *value) _gweather_info_ensure_sun (info); - if (!info->priv->sunriseValid) + if (!info->sunriseValid) return FALSE; - *value = info->priv->sunrise; + *value = info->sunrise; return TRUE; } @@ -2016,10 +1954,10 @@ gweather_info_get_value_sunset (GWeatherInfo *info, time_t *value) _gweather_info_ensure_sun (info); - if (!info->priv->sunsetValid) + if (!info->sunsetValid) return FALSE; - *value = info->priv->sunset; + *value = info->sunset; return TRUE; } @@ -2043,11 +1981,11 @@ gweather_info_get_value_moonphase (GWeatherInfo *info, _gweather_info_ensure_moon (info); - if (!info->priv->moonValid) + if (!info->moonValid) return FALSE; - *value = info->priv->moonphase; - *lat = info->priv->moonlatitude; + *value = info->moonphase; + *lat = info->moonlatitude; return TRUE; } @@ -2067,23 +2005,20 @@ gweather_info_get_value_wind (GWeatherInfo *info, gdouble *speed, GWeatherWindDirection *direction) { - GWeatherInfoPrivate *priv; 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) + if (!info->valid) return FALSE; - if (priv->windspeed < 0.0 || priv->wind <= GWEATHER_WIND_INVALID || priv->wind >= GWEATHER_WIND_LAST) + if (info->windspeed < 0.0 || info->wind <= GWEATHER_WIND_INVALID || info->wind >= GWEATHER_WIND_LAST) return FALSE; - res = speed_value (priv->windspeed, unit, speed, priv->settings); - *direction = priv->wind; + res = speed_value (info->windspeed, unit, speed, info->settings); + *direction = info->wind; return res; } @@ -2104,10 +2039,10 @@ gweather_info_get_value_pressure (GWeatherInfo *info, g_return_val_if_fail (GWEATHER_IS_INFO (info), FALSE); g_return_val_if_fail (value != NULL, FALSE); - if (!info->priv->valid) + if (!info->valid) return FALSE; - return pressure_value (info->priv->pressure, unit, value, info->priv->settings); + return pressure_value (info->pressure, unit, value, info->settings); } /** @@ -2126,37 +2061,36 @@ gweather_info_get_value_visibility (GWeatherInfo *info, g_return_val_if_fail (GWEATHER_IS_INFO (info), FALSE); g_return_val_if_fail (value != NULL, FALSE); - if (!info->priv->valid) + if (!info->valid) return FALSE; - return distance_value (info->priv->visibility, unit, value, info->priv->settings); + return distance_value (info->visibility, unit, value, info->settings); } static void gweather_info_set_location_internal (GWeatherInfo *info, GWeatherLocation *location) { - GWeatherInfoPrivate *priv = info->priv; GVariant *default_loc = NULL; const gchar *name = NULL; gboolean latlon_override = FALSE; gdouble lat, lon; - if (priv->glocation == location) + if (info->glocation == location) return; - if (priv->glocation) - gweather_location_unref (priv->glocation); + if (info->glocation) + gweather_location_unref (info->glocation); - priv->glocation = location; + info->glocation = location; - if (priv->glocation) { + if (info->glocation) { gweather_location_ref (location); } else { g_autoptr(GWeatherLocation) world = NULL; const gchar *station_code; - default_loc = g_settings_get_value (priv->settings, DEFAULT_LOCATION); + default_loc = g_settings_get_value (info->settings, DEFAULT_LOCATION); g_variant_get (default_loc, "(&s&sm(dd))", &name, &station_code, &latlon_override, &lat, &lon); @@ -2164,24 +2098,24 @@ gweather_info_set_location_internal (GWeatherInfo *info, name = NULL; world = gweather_location_get_world (); - priv->glocation = gweather_location_find_by_station_code (world, station_code); + info->glocation = gweather_location_find_by_station_code (world, station_code); } - if (priv->glocation) { - _weather_location_free (&priv->location); - _gweather_location_update_weather_location (priv->glocation, - &priv->location); + if (info->glocation) { + _weather_location_free (&info->location); + _gweather_location_update_weather_location (info->glocation, + &info->location); } if (name) { - g_free (priv->location.name); - priv->location.name = g_strdup (name); + g_free (info->location.name); + info->location.name = g_strdup (name); } if (latlon_override) { - priv->location.latlon_valid = TRUE; - priv->location.latitude = DEGREES_TO_RADIANS (lat); - priv->location.longitude = DEGREES_TO_RADIANS (lon); + info->location.latlon_valid = TRUE; + info->location.latitude = DEGREES_TO_RADIANS (lat); + info->location.longitude = DEGREES_TO_RADIANS (lon); } if (default_loc) @@ -2213,7 +2147,7 @@ gweather_info_get_enabled_providers (GWeatherInfo *info) g_return_val_if_fail (GWEATHER_IS_INFO (info), GWEATHER_PROVIDER_NONE); - return info->priv->providers; + return info->providers; } void @@ -2222,10 +2156,10 @@ gweather_info_set_enabled_providers (GWeatherInfo *info, { g_return_if_fail (GWEATHER_IS_INFO (info)); - if (info->priv->providers == providers) + if (info->providers == providers) return; - info->priv->providers = providers; + info->providers = providers; gweather_info_abort (info); gweather_info_update (info); @@ -2260,14 +2194,13 @@ gweather_info_get_property (GObject *object, GParamSpec *pspec) { GWeatherInfo *self = GWEATHER_INFO (object); - GWeatherInfoPrivate *priv = self->priv; switch (property_id) { case PROP_LOCATION: - g_value_set_boxed (value, priv->glocation); + g_value_set_boxed (value, self->glocation); break; case PROP_ENABLED_PROVIDERS: - g_value_set_flags (value, priv->providers); + g_value_set_flags (value, self->providers); break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); @@ -2280,8 +2213,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; @@ -2313,7 +2244,7 @@ gweather_info_class_init (GWeatherInfoClass *klass) gweather_info_signals[SIGNAL_UPDATED] = g_signal_new ("updated", GWEATHER_TYPE_INFO, G_SIGNAL_RUN_FIRST, - G_STRUCT_OFFSET (GWeatherInfoClass, updated), + 0, NULL, /* accumulator */ NULL, /* accu_data */ g_cclosure_marshal_VOID__VOID, @@ -2348,6 +2279,6 @@ gweather_info_new (GWeatherLocation *location) GWeatherInfo * _gweather_info_new_clone (GWeatherInfo *other) { - return g_object_new (GWEATHER_TYPE_INFO, "location", other->priv->glocation, NULL); + return g_object_new (GWEATHER_TYPE_INFO, "location", other->glocation, NULL); } diff --git a/libgweather/gweather-weather.h b/libgweather/gweather-weather.h index 9e112df..af82a6d 100644 --- a/libgweather/gweather-weather.h +++ b/libgweather/gweather-weather.h @@ -49,25 +49,11 @@ 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 ()) +G_DECLARE_FINAL_TYPE(GWeatherInfo, gweather_info, GWEATHER, INFO, GObject) struct _GWeatherInfoClass { + /*< private >*/ GObjectClass parent_class; @@ -75,7 +61,6 @@ struct _GWeatherInfoClass { void (*updated) (GWeatherInfo *info); }; -GType gweather_info_get_type (void) G_GNUC_CONST; GWeatherInfo * gweather_info_new (GWeatherLocation *location); void gweather_info_update (GWeatherInfo *info); void gweather_info_abort (GWeatherInfo *info); diff --git a/libgweather/test_metar.c b/libgweather/test_metar.c index 46ff76d..c36c86b 100644 --- a/libgweather/test_metar.c +++ b/libgweather/test_metar.c @@ -20,14 +20,14 @@ static void print_info (GWeatherInfo *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", info->location.code); } else { - g_warning ("Failed to parse weather for %s", info->priv->location.code); + g_warning ("Failed to parse weather for %s", info->location.code); return; } printf ("Returned info:\n"); - printf (" update: %s", ctime (&info->priv->update)); + printf (" update: %s", ctime (&info->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)); @@ -79,9 +79,9 @@ 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 (); + info->location.code = g_strdup (code); + info->location.latlon_valid = TRUE; + info->session = soup_session_new (); g_signal_connect (G_OBJECT (info), "updated", G_CALLBACK (weather_updated_cb), loop); @@ -111,7 +111,7 @@ main (int argc, char **argv) /* a bit hackish... */ info = g_object_new (GWEATHER_TYPE_INFO, NULL); - info->priv->valid = 1; + info->valid = 1; metar_parse (buf, info); print_info (info); } diff --git a/libgweather/test_sun_moon.c b/libgweather/test_sun_moon.c index 33cada1..87401bf 100644 --- a/libgweather/test_sun_moon.c +++ b/libgweather/test_sun_moon.c @@ -8,13 +8,13 @@ #include <string.h> #include <time.h> +#include "gweather-weather.h" #include "gweather-private.h" int main (int argc, char **argv) { GWeatherInfo *info; - GWeatherInfoPrivate *priv; GOptionContext* context; GError* error = NULL; gdouble latitude, longitude; @@ -49,19 +49,18 @@ main (int argc, char **argv) } info = g_object_new (GWEATHER_TYPE_INFO, NULL); - priv = info->priv; - priv->location.latitude = DEGREES_TO_RADIANS(latitude); - priv->location.longitude = DEGREES_TO_RADIANS(longitude); - priv->location.latlon_valid = TRUE; - priv->valid = TRUE; + info->location.latitude = DEGREES_TO_RADIANS(latitude); + info->location.longitude = DEGREES_TO_RADIANS(longitude); + info->location.latlon_valid = TRUE; + info->valid = TRUE; if (gtime != NULL) { // printf(" gtime=%s\n", gtime); g_date_set_parse(&gdate, gtime); g_date_to_struct_tm(&gdate, &tm); - priv->current_time = mktime(&tm); + info->current_time = mktime(&tm); } else { - priv->current_time = time(NULL); + info->current_time = time(NULL); } _gweather_info_ensure_sun (info); @@ -70,15 +69,15 @@ main (int argc, char **argv) printf (" Latitude %7.3f %c Longitude %7.3f %c for %s All times UTC\n", fabs(latitude), (latitude >= 0. ? 'N' : 'S'), fabs(longitude), (longitude >= 0. ? 'E' : 'W'), - asctime(gmtime(&priv->current_time))); + asctime(gmtime(&info->current_time))); printf("daytime: %s\n", gweather_info_is_daytime(info) ? "yes" : "no"); printf("sunrise: %s", - (priv->sunriseValid ? ctime(&priv->sunrise) : "(invalid)\n")); + (info->sunriseValid ? ctime(&info->sunrise) : "(invalid)\n")); printf("sunset: %s", - (priv->sunsetValid ? ctime(&priv->sunset) : "(invalid)\n")); - if (priv->moonValid) { - printf("moonphase: %g\n", priv->moonphase); - printf("moonlat: %g\n", priv->moonlatitude); + (info->sunsetValid ? ctime(&info->sunset) : "(invalid)\n")); + if (info->moonValid) { + printf("moonphase: %g\n", info->moonphase); + printf("moonlat: %g\n", info->moonlatitude); if (gweather_info_get_upcoming_moonphases(info, phases)) { printf(" New: %s", asctime(gmtime(&phases[0]))); diff --git a/libgweather/weather-iwin.c b/libgweather/weather-iwin.c index f6c7f2c..e011530 100644 --- a/libgweather/weather-iwin.c +++ b/libgweather/weather-iwin.c @@ -134,7 +134,7 @@ 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]; + nfo->current_time = nfo->update = update_times[i]; if (nfo) res = g_slist_append (res, nfo); @@ -153,27 +153,26 @@ 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; xmlChar *val = xmlNodeGetContent (c); /* can pass some values as <value xsi:nil="true"/> */ if (!val || !*val) { if (is_max) - priv->temp_max = priv->temp_min; + nfo->temp_max = nfo->temp_min; else - priv->temp_min = priv->temp_max; + nfo->temp_min = nfo->temp_max; } else { if (is_max) - priv->temp_max = atof ((const char *)val); + nfo->temp_max = atof ((const char *)val); else - priv->temp_min = atof ((const char *)val); + nfo->temp_min = atof ((const char *)val); } if (val) xmlFree (val); - priv->tempMinMaxValid = priv->tempMinMaxValid || (priv->temp_max > -999.0 && priv->temp_min > -999.0); - priv->valid = priv->tempMinMaxValid; + nfo->tempMinMaxValid = nfo->tempMinMaxValid || (nfo->temp_max > -999.0 && nfo->temp_min > -999.0); + nfo->valid = nfo->tempMinMaxValid; at = at->next; } @@ -185,7 +184,6 @@ 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; xmlChar *val = xmlGetProp (c, XC "weather-summary"); if (val && nfo) { @@ -236,19 +234,19 @@ parseForecastXml (const char *buff, GWeatherInfo *master_info) { "Snow", GWEATHER_SKY_SCATTERED } }; - priv->valid = TRUE; + nfo->valid = TRUE; for (i = 0; i < G_N_ELEMENTS (ph_list); i++) { if (strstr ((const char *)val, ph_list [i].name)) { - priv->cond.significant = TRUE; - priv->cond.phenomenon = ph_list [i].ph; + nfo->cond.significant = TRUE; + nfo->cond.phenomenon = ph_list [i].ph; break; } } for (i = 0; i < G_N_ELEMENTS (sky_list); i++) { if (strstr ((const char *)val, sky_list [i].name)) { - priv->sky = sky_list [i].sky; + nfo->sky = sky_list [i].sky; break; } } @@ -271,9 +269,8 @@ 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; - if (!nfo || !priv->valid) { + if (!nfo || !nfo->valid) { if (r->data) g_object_unref (r->data); @@ -281,8 +278,8 @@ parseForecastXml (const char *buff, GWeatherInfo *master_info) } else { have_any = TRUE; - if (priv->tempMinMaxValid) - priv->temp = (priv->temp_min + priv->temp_max) / 2.0; + if (nfo->tempMinMaxValid) + nfo->temp = (nfo->temp_min + nfo->temp_max) / 2.0; } } @@ -315,7 +312,6 @@ static void iwin_finish (SoupSession *session, SoupMessage *msg, gpointer data) { GWeatherInfo *info; - GWeatherInfoPrivate *priv; WeatherLocation *loc; if (!SOUP_STATUS_IS_SUCCESSFUL (msg->status_code)) { @@ -332,13 +328,12 @@ iwin_finish (SoupSession *session, SoupMessage *msg, gpointer data) } info = data; - priv = info->priv; - loc = &priv->location; + loc = &info->location; g_debug ("iwin data for %s", loc->zone); g_debug ("%s", msg->response_body->data); - priv->forecast_list = parseForecastXml (msg->response_body->data, info); + info->forecast_list = parseForecastXml (msg->response_body->data, info); _gweather_info_request_done (info, msg); } @@ -347,7 +342,6 @@ iwin_finish (SoupSession *session, SoupMessage *msg, gpointer data) gboolean iwin_start_open (GWeatherInfo *info) { - GWeatherInfoPrivate *priv; gchar *url; WeatherLocation *loc; SoupMessage *msg; @@ -358,8 +352,7 @@ iwin_start_open (GWeatherInfo *info) g_assert (info != NULL); - priv = info->priv; - loc = &priv->location; + loc = &info->location; /* No zone (or -) means no weather information from national offices. We don't actually use zone, but it's a good indicator of a US location. @@ -384,7 +377,7 @@ iwin_start_open (GWeatherInfo *info) g_debug ("iwin_start_open, requesting: %s", url); msg = soup_message_new ("GET", url); _gweather_info_begin_request (info, msg); - soup_session_queue_message (priv->session, msg, iwin_finish, info); + soup_session_queue_message (info->session, msg, iwin_finish, info); g_free (url); diff --git a/libgweather/weather-metar.c b/libgweather/weather-metar.c index e1ff70e..ec88a87 100644 --- a/libgweather/weather-metar.c +++ b/libgweather/weather-metar.c @@ -77,13 +77,12 @@ metar_tok_time (gchar *tokp, GWeatherInfo *info) g_debug ("metar_tok_time: %s", tokp); sscanf (tokp, "%2u%2u%2u", &day, &hr, &min); - info->priv->update = make_time (day, hr, min); + info->update = make_time (day, hr, min); } static void metar_tok_wind (gchar *tokp, GWeatherInfo *info) { - GWeatherInfoPrivate *priv; gchar sdir[4], sspd[4], sgust[4]; gint dir, spd = -1; gchar *gustp; @@ -91,8 +90,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); @@ -112,106 +109,100 @@ metar_tok_wind (gchar *tokp, GWeatherInfo *info) } if (!strcmp (tokp, "MPS")) - priv->windspeed = WINDSPEED_MS_TO_KNOTS ((GWeatherWindSpeed)spd); + info->windspeed = WINDSPEED_MS_TO_KNOTS ((GWeatherWindSpeed)spd); else - priv->windspeed = (GWeatherWindSpeed)spd; + info->windspeed = (GWeatherWindSpeed)spd; if ((349 <= dir) || (dir <= 11)) - priv->wind = GWEATHER_WIND_N; + info->wind = GWEATHER_WIND_N; else if ((12 <= dir) && (dir <= 33)) - priv->wind = GWEATHER_WIND_NNE; + info->wind = GWEATHER_WIND_NNE; else if ((34 <= dir) && (dir <= 56)) - priv->wind = GWEATHER_WIND_NE; + info->wind = GWEATHER_WIND_NE; else if ((57 <= dir) && (dir <= 78)) - priv->wind = GWEATHER_WIND_ENE; + info->wind = GWEATHER_WIND_ENE; else if ((79 <= dir) && (dir <= 101)) - priv->wind = GWEATHER_WIND_E; + info->wind = GWEATHER_WIND_E; else if ((102 <= dir) && (dir <= 123)) - priv->wind = GWEATHER_WIND_ESE; + info->wind = GWEATHER_WIND_ESE; else if ((124 <= dir) && (dir <= 146)) - priv->wind = GWEATHER_WIND_SE; + info->wind = GWEATHER_WIND_SE; else if ((147 <= dir) && (dir <= 168)) - priv->wind = GWEATHER_WIND_SSE; + info->wind = GWEATHER_WIND_SSE; else if ((169 <= dir) && (dir <= 191)) - priv->wind = GWEATHER_WIND_S; + info->wind = GWEATHER_WIND_S; else if ((192 <= dir) && (dir <= 213)) - priv->wind = GWEATHER_WIND_SSW; + info->wind = GWEATHER_WIND_SSW; else if ((214 <= dir) && (dir <= 236)) - priv->wind = GWEATHER_WIND_SW; + info->wind = GWEATHER_WIND_SW; else if ((237 <= dir) && (dir <= 258)) - priv->wind = GWEATHER_WIND_WSW; + info->wind = GWEATHER_WIND_WSW; else if ((259 <= dir) && (dir <= 281)) - priv->wind = GWEATHER_WIND_W; + info->wind = GWEATHER_WIND_W; else if ((282 <= dir) && (dir <= 303)) - priv->wind = GWEATHER_WIND_WNW; + info->wind = GWEATHER_WIND_WNW; else if ((304 <= dir) && (dir <= 326)) - priv->wind = GWEATHER_WIND_NW; + info->wind = GWEATHER_WIND_NW; else if ((327 <= dir) && (dir <= 348)) - priv->wind = GWEATHER_WIND_NNW; + info->wind = GWEATHER_WIND_NNW; } static void metar_tok_vis (gchar *tokp, GWeatherInfo *info) { - GWeatherInfoPrivate *priv; 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")) { // "Ceiling And Visibility OK": visibility >= 10 KM - priv->visibility=10000. / VISIBILITY_SM_TO_M (1.); - priv->sky = GWEATHER_SKY_CLEAR; + info->visibility=10000. / VISIBILITY_SM_TO_M (1.); + info->sky = GWEATHER_SKY_CLEAR; } else if (0 != (pend = strstr (tokp, "SM"))) { // US observation: field ends with "SM" pfrac = strchr (tokp, '/'); if (pfrac) { if (*tokp == 'M') { - priv->visibility = 0.001; + info->visibility = 0.001; } else { num = (*(pfrac - 1) - '0'); strncpy (sval, pfrac + 1, pend - pfrac - 1); den = atoi (sval); - priv->visibility = + info->visibility = ((GWeatherVisibility)num / ((GWeatherVisibility)den)); psp = strchr (tokp, ' '); if (psp) { *psp = '\0'; val = atoi (tokp); - priv->visibility += (GWeatherVisibility)val; + info->visibility += (GWeatherVisibility)val; } } } else { strncpy (sval, tokp, pend - tokp); val = atoi (sval); - priv->visibility = (GWeatherVisibility)val; + info->visibility = (GWeatherVisibility)val; } } else { // International observation: NNNN(DD NNNNDD)? // For now: use only the minimum visibility and ignore its direction strncpy (sval, tokp, strspn (tokp, CONST_DIGITS)); val = atoi (sval); - priv->visibility = (GWeatherVisibility)val / VISIBILITY_SM_TO_M (1.); + info->visibility = (GWeatherVisibility)val / VISIBILITY_SM_TO_M (1.); } } static void metar_tok_cloud (gchar *tokp, GWeatherInfo *info) { - GWeatherInfoPrivate *priv; 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) { @@ -220,27 +211,25 @@ metar_tok_cloud (gchar *tokp, GWeatherInfo *info) } if (!strcmp (stype, "CLR")) { - priv->sky = GWEATHER_SKY_CLEAR; + info->sky = GWEATHER_SKY_CLEAR; } else if (!strcmp (stype, "SKC")) { - priv->sky = GWEATHER_SKY_CLEAR; + info->sky = GWEATHER_SKY_CLEAR; } else if (!strcmp (stype, "NSC")) { - priv->sky = GWEATHER_SKY_CLEAR; + info->sky = GWEATHER_SKY_CLEAR; } else if (!strcmp (stype, "BKN")) { - priv->sky = GWEATHER_SKY_BROKEN; + info->sky = GWEATHER_SKY_BROKEN; } else if (!strcmp (stype, "SCT")) { - priv->sky = GWEATHER_SKY_SCATTERED; + info->sky = GWEATHER_SKY_SCATTERED; } else if (!strcmp (stype, "FEW")) { - priv->sky = GWEATHER_SKY_FEW; + info->sky = GWEATHER_SKY_FEW; } else if (!strcmp (stype, "OVC")) { - priv->sky = GWEATHER_SKY_OVERCAST; + info->sky = GWEATHER_SKY_OVERCAST; } } static void metar_tok_pres (gchar *tokp, GWeatherInfo *info) { - GWeatherInfoPrivate *priv = info->priv; - g_debug ("metar_tok_pres: %s", tokp); if (*tokp == 'A') { @@ -255,7 +244,7 @@ metar_tok_pres (gchar *tokp, GWeatherInfo *info) sfract[2] = 0; fract = atoi (sfract); - priv->pressure = (GWeatherPressure)intg + (((GWeatherPressure)fract)/100.0); + info->pressure = (GWeatherPressure)intg + (((GWeatherPressure)fract)/100.0); } else { /* *tokp == 'Q' */ gchar spres[5]; gint pres; @@ -264,32 +253,29 @@ metar_tok_pres (gchar *tokp, GWeatherInfo *info) spres[4] = 0; pres = atoi (spres); - priv->pressure = PRESSURE_MBAR_TO_INCH ((GWeatherPressure)pres); + info->pressure = PRESSURE_MBAR_TO_INCH ((GWeatherPressure)pres); } } static void metar_tok_temp (gchar *tokp, GWeatherInfo *info) { - GWeatherInfoPrivate *priv; gchar *ptemp, *pdew, *psep; g_debug ("metar_tok_temp: %s", tokp); - priv = info->priv; - psep = strchr (tokp, '/'); *psep = 0; ptemp = tokp; pdew = psep + 1; - priv->temp = (*ptemp == 'M') ? TEMP_C_TO_F (-atoi (ptemp + 1)) + info->temp = (*ptemp == 'M') ? TEMP_C_TO_F (-atoi (ptemp + 1)) : TEMP_C_TO_F (atoi (ptemp)); if (*pdew) { - priv->dew = (*pdew == 'M') ? TEMP_C_TO_F (-atoi (pdew + 1)) + info->dew = (*pdew == 'M') ? TEMP_C_TO_F (-atoi (pdew + 1)) : TEMP_C_TO_F (atoi (pdew)); } else { - priv->dew = -1000.0; + info->dew = -1000.0; } } @@ -342,15 +328,12 @@ condition_more_important (GWeatherConditions *which, static void metar_tok_cond (gchar *tokp, GWeatherInfo *info) { - GWeatherInfoPrivate *priv; 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 */ @@ -455,8 +438,8 @@ metar_tok_cond (gchar *tokp, GWeatherInfo *info) if ((new_cond.qualifier != GWEATHER_QUALIFIER_NONE) || (new_cond.phenomenon != GWEATHER_PHENOMENON_NONE)) new_cond.significant = TRUE; - if (condition_more_important (&new_cond, &priv->cond)) - priv->cond = new_cond; + if (condition_more_important (&new_cond, &info->cond)) + info->cond = new_cond; } #define TIME_RE_STR "([0-9]{6})Z" @@ -578,7 +561,6 @@ static void metar_finish (SoupSession *session, SoupMessage *msg, gpointer data) { GWeatherInfo *info; - GWeatherInfoPrivate *priv; WeatherLocation *loc; const gchar *p, *eoln; gchar *searchkey, *metar; @@ -593,7 +575,7 @@ metar_finish (SoupSession *session, SoupMessage *msg, gpointer data) info = data; if (SOUP_STATUS_IS_TRANSPORT_ERROR (msg->status_code)) { - info->priv->network_error = TRUE; + info->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"), @@ -605,8 +587,7 @@ metar_finish (SoupSession *session, SoupMessage *msg, gpointer data) } info = data; - priv = info->priv; - loc = &priv->location; + loc = &info->location; g_debug ("METAR data for %s", loc->code); g_debug ("%s", msg->response_body->data); @@ -632,7 +613,7 @@ metar_finish (SoupSession *session, SoupMessage *msg, gpointer data) * most likely it is a wifi hotspot login page. Call that a * network error. */ - priv->network_error = TRUE; + info->network_error = TRUE; g_debug ("Response to query for %s did not come from correct server", loc->code); } else { g_debug ("Failed to parse METAR for %s", loc->code); @@ -640,8 +621,8 @@ metar_finish (SoupSession *session, SoupMessage *msg, gpointer data) g_free (searchkey); - if (!priv->valid) - priv->valid = success; + if (!info->valid) + info->valid = success; _gweather_info_request_done (info, msg); } @@ -649,16 +630,13 @@ metar_finish (SoupSession *session, SoupMessage *msg, gpointer data) void metar_start_open (GWeatherInfo *info) { - GWeatherInfoPrivate *priv; WeatherLocation *loc; SoupMessage *msg; g_return_if_fail (info != NULL); - priv = info->priv; - - priv->valid = priv->network_error = FALSE; - loc = &priv->location; + info->valid = info->network_error = FALSE; + loc = &info->location; if (!loc->latlon_valid) return; @@ -675,5 +653,5 @@ metar_start_open (GWeatherInfo *info) "stationString", loc->code, NULL); _gweather_info_begin_request (info, msg); - soup_session_queue_message (priv->session, msg, metar_finish, info); + soup_session_queue_message (info->session, msg, metar_finish, info); } diff --git a/libgweather/weather-metno.c b/libgweather/weather-metno.c index 594fd23..1206be4 100644 --- a/libgweather/weather-metno.c +++ b/libgweather/weather-metno.c @@ -172,15 +172,14 @@ read_symbol (GWeatherInfo *info, { xmlChar *val; MetnoSymbol* symbol; - GWeatherInfoPrivate *priv = info->priv; val = xmlGetProp (node, XC("number")); symbol = symbol_search (strtol ((char*) val, NULL, 0)); if (symbol != NULL) { - priv->valid = TRUE; - priv->sky = symbol->sky; - priv->cond = symbol->condition; + info->valid = TRUE; + info->sky = symbol->sky; + info->cond = symbol->condition; } xmlFree (val); } @@ -200,7 +199,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; + info->wind = wind_directions[i].direction; xmlFree (val); return; } @@ -220,7 +219,7 @@ read_wind_speed (GWeatherInfo *info, return; mps = g_ascii_strtod ((char*) val, NULL); - info->priv->windspeed = WINDSPEED_MS_TO_KNOTS (mps); + info->windspeed = WINDSPEED_MS_TO_KNOTS (mps); xmlFree (val); } @@ -236,7 +235,7 @@ read_temperature (GWeatherInfo *info, return; celsius = g_ascii_strtod ((char*) val, NULL); - info->priv->temp = TEMP_C_TO_F (celsius); + info->temp = TEMP_C_TO_F (celsius); xmlFree (val); } @@ -252,7 +251,7 @@ read_pressure (GWeatherInfo *info, return; hpa = g_ascii_strtod ((char*) val, NULL); - info->priv->pressure = PRESSURE_MBAR_TO_INCH (hpa); + info->pressure = PRESSURE_MBAR_TO_INCH (hpa); xmlFree (val); } @@ -268,8 +267,8 @@ read_humidity (GWeatherInfo *info, return; percent = g_ascii_strtod ((char*) val, NULL); - info->priv->humidity = percent; - info->priv->hasHumidity = TRUE; + info->humidity = percent; + info->hasHumidity = TRUE; xmlFree (val); } @@ -307,14 +306,11 @@ static void parse_forecast_xml_new (GWeatherInfo *master_info, SoupMessageBody *body) { - GWeatherInfoPrivate *priv; xmlDocPtr doc; xmlXPathContextPtr xpath_ctx; xmlXPathObjectPtr xpath_result; int i; - priv = master_info->priv; - doc = xmlParseMemory (body->data, body->length); if (!doc) return; @@ -335,11 +331,11 @@ parse_forecast_xml_new (GWeatherInfo *master_info, node = xpath_result->nodesetval->nodeTab[i]; val = xmlGetProp (node, XC("from")); - from_time = date_to_time_t (val, priv->location.tz_hint); + from_time = date_to_time_t (val, master_info->location.tz_hint); xmlFree (val); val = xmlGetProp (node, XC("to")); - to_time = date_to_time_t (val, priv->location.tz_hint); + to_time = date_to_time_t (val, master_info->location.tz_hint); xmlFree (val); /* New API has forecast in a list of "master" elements @@ -352,7 +348,7 @@ 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->current_time = info->update = from_time; for (location = node->children; location && location->type != XML_ELEMENT_NODE; @@ -371,7 +367,7 @@ parse_forecast_xml_new (GWeatherInfo *master_info, fill_info_from_node (info, location); } - priv->forecast_list = g_slist_append (priv->forecast_list, info); + info->forecast_list = g_slist_append (info->forecast_list, info); } } @@ -383,7 +379,7 @@ parse_forecast_xml_new (GWeatherInfo *master_info, That's very nice of them! */ - priv->forecast_attribution = g_strdup(_("Weather data from the <a href=\"https://www.met.no/\">Norwegian Meteorological Institute</a>.")); + master_info->forecast_attribution = g_strdup(_("Weather data from the <a href=\"https://www.met.no/\">Norwegian Meteorological Institute</a>.")); out: xmlXPathFreeContext (xpath_ctx); @@ -396,7 +392,6 @@ metno_finish_new (SoupSession *session, gpointer user_data) { GWeatherInfo *info; - GWeatherInfoPrivate *priv; WeatherLocation *loc; guint num_forecasts; @@ -414,16 +409,15 @@ metno_finish_new (SoupSession *session, } info = user_data; - priv = info->priv; - loc = &priv->location; + loc = &info->location; g_debug ("metno data for %lf, %lf", loc->latitude, loc->longitude); g_debug ("%s", msg->response_body->data); parse_forecast_xml_new (info, msg->response_body); - num_forecasts = g_slist_length (priv->forecast_list); + num_forecasts = g_slist_length (info->forecast_list); g_debug ("metno parsed %d forecast infos", num_forecasts); - if (!priv->valid) - priv->valid = (num_forecasts > 0); + if (!info->valid) + info->valid = (num_forecasts > 0); _gweather_info_request_done (info, msg); } @@ -431,15 +425,13 @@ metno_finish_new (SoupSession *session, gboolean metno_start_open (GWeatherInfo *info) { - GWeatherInfoPrivate *priv; gchar *url; SoupMessage *message; WeatherLocation *loc; g_autofree char *latstr = NULL; g_autofree char *lonstr = NULL; - priv = info->priv; - loc = &priv->location; + loc = &info->location; if (!loc->latlon_valid) return FALSE; @@ -454,7 +446,7 @@ metno_start_open (GWeatherInfo *info) message = soup_message_new ("GET", url); _gweather_info_begin_request (info, message); - soup_session_queue_message (priv->session, message, metno_finish_new, info); + soup_session_queue_message (info->session, message, metno_finish_new, info); g_free (url); diff --git a/libgweather/weather-moon.c b/libgweather/weather-moon.c index 41f8570..898fdb7 100644 --- a/libgweather/weather-moon.c +++ b/libgweather/weather-moon.c @@ -137,17 +137,13 @@ calc_moon_internal (time_t update, gdouble *moonphase, gdouble *moonlatitude) void _gweather_info_ensure_moon (GWeatherInfo *info) { - GWeatherInfoPrivate *priv; - - priv = info->priv; - - if (!info->priv->location.latlon_valid) + if (!info->location.latlon_valid) return; - if (!priv->moonValid) - priv->moonValid = calc_moon_internal (priv->current_time, - &priv->moonphase, - &priv->moonlatitude); + if (!info->moonValid) + info->moonValid = calc_moon_internal (info->current_time, + &info->moonphase, + &info->moonlatitude); } /* @@ -162,7 +158,6 @@ _gweather_info_ensure_moon (GWeatherInfo *info) static gboolean calc_moon_phases (GWeatherInfo *info, time_t *phases) { - GWeatherInfoPrivate *priv; time_t tmp_update; gdouble tmp_moonphase; gdouble tmp_moonlatitude; @@ -174,18 +169,17 @@ calc_moon_phases (GWeatherInfo *info, time_t *phases) _gweather_info_ensure_moon (info); - priv = info->priv; ptime = phases; for (idx = 0; idx < 4; idx++) { - tmp_update = priv->current_time; - tmp_moonphase = priv->moonphase; + tmp_update = info->current_time; + tmp_moonphase = info->moonphase; /* * First estimate on how far the moon needs to advance * to get to the required phase */ - advance = (idx * 90.) - priv->moonphase; + advance = (idx * 90.) - info->moonphase; if (advance < 0.) advance += 360.; diff --git a/libgweather/weather-owm.c b/libgweather/weather-owm.c index a537a21..2663f60 100644 --- a/libgweather/weather-owm.c +++ b/libgweather/weather-owm.c @@ -174,7 +174,6 @@ read_symbol (GWeatherInfo *info, xmlNodePtr node) { xmlChar *val; - GWeatherInfoPrivate *priv = info->priv; struct owm_symbol *obj, ref; val = xmlGetProp (node, XC("number")); @@ -190,9 +189,9 @@ read_symbol (GWeatherInfo *info, return; } - priv->valid = TRUE; - priv->sky = obj->sky; - priv->cond = obj->condition; + info->valid = TRUE; + info->sky = obj->sky; + info->cond = obj->condition; } static inline void @@ -208,7 +207,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; + info->wind = wind_directions[i].direction; xmlFree (val); return; } @@ -228,7 +227,7 @@ read_wind_speed (GWeatherInfo *info, return; mps = g_ascii_strtod ((char*) val, NULL); - info->priv->windspeed = WINDSPEED_MS_TO_KNOTS (mps); + info->windspeed = WINDSPEED_MS_TO_KNOTS (mps); xmlFree (val); } @@ -252,7 +251,7 @@ read_temperature (GWeatherInfo *info, return; celsius = g_ascii_strtod ((char*) val, NULL); - info->priv->temp = TEMP_C_TO_F (celsius); + info->temp = TEMP_C_TO_F (celsius); xmlFree (val); } @@ -277,7 +276,7 @@ read_pressure (GWeatherInfo *info, return; hpa = g_ascii_strtod ((char*) val, NULL); - info->priv->pressure = PRESSURE_MBAR_TO_INCH (hpa); + info->pressure = PRESSURE_MBAR_TO_INCH (hpa); xmlFree (val); } @@ -301,8 +300,8 @@ read_humidity (GWeatherInfo *info, return; percent = g_ascii_strtod ((char*) val, NULL); - info->priv->humidity = percent; - info->priv->hasHumidity = TRUE; + info->humidity = percent; + info->hasHumidity = TRUE; xmlFree (val); } @@ -341,16 +340,14 @@ make_info_from_node (GWeatherInfo *master_info, xmlNodePtr node) { GWeatherInfo *info; - GWeatherInfoPrivate *priv; xmlChar *val; g_return_val_if_fail (node->type == XML_ELEMENT_NODE, NULL); info = _gweather_info_new_clone (master_info); - priv = info->priv; val = xmlGetProp (node, XC("from")); - priv->current_time = priv->update = date_to_time_t (val, info->priv->location.tz_hint); + info->current_time = info->update = date_to_time_t (val, info->location.tz_hint); xmlFree (val); fill_info_from_node (info, node); @@ -362,14 +359,11 @@ static void parse_forecast_xml (GWeatherInfo *master_info, SoupMessageBody *body) { - GWeatherInfoPrivate *priv; xmlDocPtr doc; xmlXPathContextPtr xpath_ctx; xmlXPathObjectPtr xpath_result; int i; - priv = master_info->priv; - doc = xmlParseMemory (body->data, body->length); if (!doc) return; @@ -387,7 +381,7 @@ parse_forecast_xml (GWeatherInfo *master_info, node = xpath_result->nodesetval->nodeTab[i]; info = make_info_from_node (master_info, node); - priv->forecast_list = g_slist_append (priv->forecast_list, info); + info->forecast_list = g_slist_append (info->forecast_list, info); } xmlXPathFreeObject (xpath_result); @@ -396,7 +390,7 @@ parse_forecast_xml (GWeatherInfo *master_info, if (!xpath_result || xpath_result->type != XPATH_NODESET) goto out; - priv->forecast_attribution = g_strdup(_("Weather data from the <a href=\"https://openweathermap.org\">Open Weather Map project</a>")); + master_info->forecast_attribution = g_strdup(_("Weather data from the <a href=\"https://openweathermap.org\">Open Weather Map project</a>")); out: if (xpath_result) @@ -411,7 +405,6 @@ owm_finish (SoupSession *session, gpointer user_data) { GWeatherInfo *info; - GWeatherInfoPrivate *priv; WeatherLocation *loc; if (!SOUP_STATUS_IS_SUCCESSFUL (msg->status_code)) { @@ -428,8 +421,7 @@ owm_finish (SoupSession *session, } info = user_data; - priv = info->priv; - loc = &priv->location; + loc = &info->location; g_debug ("owm data for %lf, %lf", loc->latitude, loc->longitude); g_debug ("%s", msg->response_body->data); @@ -440,15 +432,13 @@ owm_finish (SoupSession *session, gboolean owm_start_open (GWeatherInfo *info) { - GWeatherInfoPrivate *priv; gchar *url; SoupMessage *message; WeatherLocation *loc; g_autofree char *latstr = NULL; g_autofree char *lonstr = NULL; - priv = info->priv; - loc = &priv->location; + loc = &info->location; if (!loc->latlon_valid) return FALSE; @@ -472,7 +462,7 @@ owm_start_open (GWeatherInfo *info) message = soup_message_new ("GET", url); _gweather_info_begin_request (info, message); - soup_session_queue_message (priv->session, message, owm_finish, info); + soup_session_queue_message (info->session, message, owm_finish, info); g_free (url); diff --git a/libgweather/weather-sun.c b/libgweather/weather-sun.c index 936b958..22b80b4 100644 --- a/libgweather/weather-sun.c +++ b/libgweather/weather-sun.c @@ -160,7 +160,6 @@ t0 (time_t date) static gboolean calc_sun (GWeatherInfo *info, time_t t) { - GWeatherInfoPrivate *priv; gdouble obsLat; gdouble obsLon; time_t gm_midn; @@ -175,9 +174,8 @@ 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; + obsLat = info->location.latitude; + obsLon = info->location.longitude; gm_midn = t - (t % 86400); gm_hoff = floor ((RADIANS_TO_DEGREES (obsLon) + 7.5) / 15.); lcl_midn = gm_midn - 3600. * gm_hoff; @@ -203,12 +201,12 @@ calc_sun (GWeatherInfo *info, time_t t) */ decl_midn = MIN(decl1,decl2); decl_noon = (decl1+decl2)/2.; - priv->midnightSun = + info->midnightSun = (obsLat > (M_PI/2.-decl_midn)) || (obsLat < (-M_PI/2.-decl_midn)); - priv->polarNight = + info->polarNight = (obsLat > (M_PI/2.+decl_noon)) || (obsLat < (-M_PI/2.+decl_noon)); - if (priv->midnightSun || priv->polarNight) { - priv->sunriseValid = priv->sunsetValid = FALSE; + if (info->midnightSun || info->polarNight) { + info->sunriseValid = info->sunsetValid = FALSE; return FALSE; } @@ -221,7 +219,7 @@ calc_sun (GWeatherInfo *info, time_t t) /* TODO: include calculations for regions near the poles. */ if (isnan(rise1) || isnan(rise2)) { - priv->sunriseValid = priv->sunsetValid = FALSE; + info->sunriseValid = info->sunsetValid = FALSE; return FALSE; } @@ -272,32 +270,28 @@ calc_sun (GWeatherInfo *info, time_t t) rise1 += 24; else if (rise1 >= 24.) rise1 -= 24.; - priv->sunriseValid = ((rise1 >= 0.) && (rise1 < 24.)); - priv->sunrise = (rise1 * 3600.) + lcl_midn; + info->sunriseValid = ((rise1 >= 0.) && (rise1 < 24.)); + info->sunrise = (rise1 * 3600.) + lcl_midn; set1 = (set1 + dt - tt) * 0.9972695661; if (set1 < 0.) set1 += 24; else if (set1 >= 24.) set1 -= 24.; - priv->sunsetValid = ((set1 >= 0.) && (set1 < 24.)); - priv->sunset = (set1 * 3600.) + lcl_midn; + info->sunsetValid = ((set1 >= 0.) && (set1 < 24.)); + info->sunset = (set1 * 3600.) + lcl_midn; - return (priv->sunriseValid || priv->sunsetValid); + return (info->sunriseValid || info->sunsetValid); } void _gweather_info_ensure_sun (GWeatherInfo *info) { - GWeatherInfoPrivate *priv; - - priv = info->priv; - - if (!info->priv->location.latlon_valid) + if (!info->location.latlon_valid) return; - if (!priv->sunriseValid && !priv->sunsetValid) - calc_sun (info, priv->current_time); + if (!info->sunriseValid && !info->sunsetValid) + calc_sun (info, info->current_time); } /** @@ -315,9 +309,6 @@ gweather_info_next_sun_event (GWeatherInfo *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); @@ -331,11 +322,11 @@ gweather_info_next_sun_event (GWeatherInfo *info) ltm.tm_mday++; nxtEvent = mktime (<m); - if (priv->sunsetValid && - (priv->sunset > now) && (priv->sunset < nxtEvent)) - nxtEvent = priv->sunset; - if (priv->sunriseValid && - (priv->sunrise > now) && (priv->sunrise < nxtEvent)) - nxtEvent = priv->sunrise; + if (info->sunsetValid && + (info->sunset > now) && (info->sunset < nxtEvent)) + nxtEvent = info->sunset; + if (info->sunriseValid && + (info->sunrise > now) && (info->sunrise < nxtEvent)) + nxtEvent = info->sunrise; return (gint)(nxtEvent - now); } |