[libgweather/clang-format: 2/5] Reformat the code using clang-format
- From: Emmanuele Bassi <ebassi src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libgweather/clang-format: 2/5] Reformat the code using clang-format
- Date: Sat, 16 Oct 2021 23:40:37 +0000 (UTC)
commit 9d4a5f224ad75cc9c2811b0bc9753dfb510df889
Author: Emmanuele Bassi <ebassi gnome org>
Date: Sat Oct 16 23:52:05 2021 +0100
Reformat the code using clang-format
While it would be very nice to keep our artisanal, locally sourced,
hand-crafted coding style, our time is better spent trying to fix issues
and implement features, instead of doing coding style reviews. In order
to have our CI pipeline in charge of keeping and checking the coding
style of this project, we need to have a consistent baseline.
This consistency pass also gets rid of all the tabs, so we have that
going for us.
libgweather/gweather-location.c | 927 ++++++++++++-------------
libgweather/gweather-private.c | 16 +-
libgweather/gweather-timezone.c | 144 ++--
libgweather/gweather-weather.c | 1240 +++++++++++++++++-----------------
libgweather/tests/test_libgweather.c | 337 ++++-----
libgweather/tools/test_metar.c | 59 +-
libgweather/tools/test_sun_moon.c | 92 ++-
libgweather/tools/test_weather.c | 36 +-
libgweather/weather-iwin.c | 109 +--
libgweather/weather-metar.c | 212 +++---
libgweather/weather-metno.c | 328 ++++-----
libgweather/weather-moon.c | 126 ++--
libgweather/weather-owm.c | 271 ++++----
libgweather/weather-sun.c | 135 ++--
14 files changed, 2014 insertions(+), 2018 deletions(-)
---
diff --git a/libgweather/gweather-location.c b/libgweather/gweather-location.c
index bccb80c7..e064fc72 100644
--- a/libgweather/gweather-location.c
+++ b/libgweather/gweather-location.c
@@ -11,12 +11,12 @@
#include "gweather-private.h"
#include "gweather-timezone.h"
-#include <string.h>
-#include <math.h>
-#include <locale.h>
+#include <geocode-glib/geocode-glib.h>
#include <glib/gi18n-lib.h>
#include <libxml/xmlreader.h>
-#include <geocode-glib/geocode-glib.h>
+#include <locale.h>
+#include <math.h>
+#include <string.h>
/* This is the precision of coordinates in the database */
#define EPSILON 0.000001
@@ -25,8 +25,8 @@
* airport to a city, see also test_distance() */
#define AIRPORT_MAX_DISTANCE 100.0
-static inline GWeatherLocation*
-_iter_up(GWeatherLocation *loc)
+static inline GWeatherLocation *
+_iter_up (GWeatherLocation *loc)
{
GWeatherLocation *tmp;
@@ -34,7 +34,7 @@ _iter_up(GWeatherLocation *loc)
gweather_location_unref (loc);
return tmp;
}
-#define ITER_UP(start, _p) for ((_p) = gweather_location_ref (start); (_p); (_p) = _iter_up(_p))
+#define ITER_UP(start, _p) for ((_p) = gweather_location_ref (start); (_p); (_p) = _iter_up (_p))
static GWeatherLocation *
location_new (GWeatherLocationLevel level)
@@ -51,12 +51,13 @@ location_new (GWeatherLocationLevel level)
return loc;
}
-static void add_timezones (GWeatherLocation *loc, GPtrArray *zones);
+static void
+add_timezones (GWeatherLocation *loc, GPtrArray *zones);
static GWeatherLocation *
-location_ref_for_idx (GWeatherDb *db,
- guint16 idx,
- GWeatherLocation *nearest_of)
+location_ref_for_idx (GWeatherDb *db,
+ guint16 idx,
+ GWeatherLocation *nearest_of)
{
GWeatherLocation *loc;
DbLocationRef ref;
@@ -66,10 +67,10 @@ location_ref_for_idx (GWeatherDb *db,
/* nearest copies are cached by the parent */
if (!nearest_of) {
- loc = g_ptr_array_index (db->locations, idx);
- if (loc) {
- return gweather_location_ref (loc);
- }
+ loc = g_ptr_array_index (db->locations, idx);
+ if (loc) {
+ return gweather_location_ref (loc);
+ }
}
ref = db_arrayof_location_get_at (db->locations_ref, idx);
@@ -80,15 +81,15 @@ location_ref_for_idx (GWeatherDb *db,
/* Override parent information for "nearest" copies. */
if (nearest_of)
- loc->parent_idx = nearest_of->db_idx;
+ loc->parent_idx = nearest_of->db_idx;
else
- loc->parent_idx = db_location_get_parent (ref);
+ loc->parent_idx = db_location_get_parent (ref);
loc->tz_hint_idx = db_location_get_tz_hint (ref);
loc->latitude = db_coordinate_get_lat (db_location_get_coordinates (ref));
loc->longitude = db_coordinate_get_lon (db_location_get_coordinates (ref));
- loc->latlon_valid = isfinite(loc->latitude) && isfinite(loc->longitude);
+ loc->latlon_valid = isfinite (loc->latitude) && isfinite (loc->longitude);
/* Note, we used to sort locations by distance (for cities) and name;
* Distance sorting is done in the variant already,
@@ -98,7 +99,7 @@ location_ref_for_idx (GWeatherDb *db,
* Implicit "nearest" copies do not have a weak reference, they simply
* belong to the parent. */
if (!nearest_of)
- g_ptr_array_index (db->locations, idx) = loc;
+ g_ptr_array_index (db->locations, idx) = loc;
return loc;
}
@@ -108,25 +109,27 @@ static GWeatherDb *world_db;
void
_gweather_location_reset_world (void)
{
- gsize i;
-
- g_return_if_fail (world_db != NULL);
-
- /* At this point, we had a leak if the caches are not completely empty. */
- for (i = 0; i < world_db->locations->len; i++) {
- if (G_UNLIKELY (g_ptr_array_index (world_db->locations, i) != NULL)) {
- g_warning ("Location with index %li and name %s is still referenced!",
- i, gweather_location_get_name (g_ptr_array_index (world_db->locations,
i)));
- g_assert_not_reached ();
- }
- }
- for (i = 0; i < world_db->timezones->len; i++) {
- if (G_UNLIKELY (g_ptr_array_index (world_db->timezones, i) != NULL)) {
- g_warning ("Timezone with index %li and tzid %s is still referenced!",
- i, gweather_timezone_get_tzid (g_ptr_array_index (world_db->timezones,
i)));
- g_assert_not_reached ();
- }
- }
+ gsize i;
+
+ g_return_if_fail (world_db != NULL);
+
+ /* At this point, we had a leak if the caches are not completely empty. */
+ for (i = 0; i < world_db->locations->len; i++) {
+ if (G_UNLIKELY (g_ptr_array_index (world_db->locations, i) != NULL)) {
+ g_warning ("Location with index %li and name %s is still referenced!",
+ i,
+ gweather_location_get_name (g_ptr_array_index (world_db->locations, i)));
+ g_assert_not_reached ();
+ }
+ }
+ for (i = 0; i < world_db->timezones->len; i++) {
+ if (G_UNLIKELY (g_ptr_array_index (world_db->timezones, i) != NULL)) {
+ g_warning ("Timezone with index %li and tzid %s is still referenced!",
+ i,
+ gweather_timezone_get_tzid (g_ptr_array_index (world_db->timezones, i)));
+ g_assert_not_reached ();
+ }
+ }
}
G_DEFINE_BOXED_TYPE (GWeatherLocation, gweather_location, gweather_location_ref, gweather_location_unref)
@@ -146,9 +149,9 @@ GWeatherLocation *
gweather_location_get_world (void)
{
if (world_db == NULL) {
- g_autoptr(GError) error = NULL;
+ g_autoptr (GError) error = NULL;
g_autofree char *filename = NULL;
- g_autoptr(GMappedFile) map;
+ g_autoptr (GMappedFile) map;
const char *locations_path;
time_t now;
struct tm tm;
@@ -157,50 +160,50 @@ gweather_location_get_world (void)
if (locations_path != NULL) {
filename = g_strdup (locations_path);
if (!g_file_test (filename, G_FILE_TEST_IS_REGULAR)) {
- g_warning ("User specified database %s does not exist", filename);
- g_clear_pointer (&filename, g_free);
- }
+ g_warning ("User specified database %s does not exist", filename);
+ g_clear_pointer (&filename, g_free);
+ }
}
if (filename == NULL) {
- filename = g_build_filename (GWEATHER_BIN_LOCATION_DIR, "Locations.bin", NULL);
+ filename = g_build_filename (GWEATHER_BIN_LOCATION_DIR, "Locations.bin", NULL);
}
- map = g_mapped_file_new (filename, FALSE, &error);
- if (map == NULL) {
- g_critical ("Failed to open database %s: %s", filename, error->message);
- return NULL;
- }
+ map = g_mapped_file_new (filename, FALSE, &error);
+ if (map == NULL) {
+ g_critical ("Failed to open database %s: %s", filename, error->message);
+ return NULL;
+ }
- world_db = g_new0 (GWeatherDb, 1);
- world_db->world = db_world_from_data (g_mapped_file_get_contents (map), g_mapped_file_get_length
(map));
- /* This is GWthDB01 */
- if (db_world_get_magic (world_db->world) != 0x5747687442443130) {
- g_free (world_db);
- return NULL;
- }
+ world_db = g_new0 (GWeatherDb, 1);
+ world_db->world = db_world_from_data (g_mapped_file_get_contents (map), g_mapped_file_get_length
(map));
+ /* This is GWthDB01 */
+ if (db_world_get_magic (world_db->world) != 0x5747687442443130) {
+ g_free (world_db);
+ return NULL;
+ }
- world_db->map = g_steal_pointer (&map);
+ world_db->map = g_steal_pointer (&map);
- world_db->locations_ref = db_world_get_locations (world_db->world);
- world_db->timezones_ref = db_world_get_timezones (world_db->world);
+ world_db->locations_ref = db_world_get_locations (world_db->world);
+ world_db->timezones_ref = db_world_get_timezones (world_db->world);
- world_db->locations = g_ptr_array_new ();
- world_db->timezones = g_ptr_array_new ();
+ world_db->locations = g_ptr_array_new ();
+ world_db->timezones = g_ptr_array_new ();
- g_ptr_array_set_size (world_db->locations, db_arrayof_location_get_length (world_db->locations_ref));
- g_ptr_array_set_size (world_db->timezones, db_world_timezones_get_length (world_db->timezones_ref));
+ g_ptr_array_set_size (world_db->locations, db_arrayof_location_get_length (world_db->locations_ref));
+ g_ptr_array_set_size (world_db->timezones, db_world_timezones_get_length (world_db->timezones_ref));
- /* Get timestamps for the start and end of this year.
+ /* Get timestamps for the start and end of this year.
* This is used to parse timezone information. */
- now = time (NULL);
- tm = *gmtime (&now);
- tm.tm_mon = 0;
- tm.tm_mday = 1;
- tm.tm_hour = tm.tm_min = tm.tm_sec = 0;
- world_db->year_start = mktime (&tm);
- tm.tm_year++;
- world_db->year_end = mktime (&tm);
+ now = time (NULL);
+ tm = *gmtime (&now);
+ tm.tm_mon = 0;
+ tm.tm_mday = 1;
+ tm.tm_hour = tm.tm_min = tm.tm_sec = 0;
+ world_db->year_start = mktime (&tm);
+ tm.tm_year++;
+ world_db->year_end = mktime (&tm);
}
return location_ref_for_idx (world_db, 0, NULL);
@@ -241,7 +244,7 @@ gweather_location_unref (GWeatherLocation *loc)
int i;
if (--loc->ref_count)
- return;
+ return;
/* Remove weak reference from DB object; but only if it points to us.
* It may point elsewhere if we are an implicit nearest child. */
@@ -256,10 +259,10 @@ gweather_location_unref (GWeatherLocation *loc)
g_free (loc->_station_code);
if (loc->_children) {
- for (i = 0; loc->_children[i]; i++) {
- gweather_location_unref (loc->_children[i]);
- }
- g_free (loc->_children);
+ for (i = 0; loc->_children[i]; i++) {
+ gweather_location_unref (loc->_children[i]);
+ }
+ g_free (loc->_children);
}
g_clear_pointer (&loc->_parent, gweather_location_unref);
@@ -282,24 +285,25 @@ gweather_location_get_name (GWeatherLocation *loc)
g_return_val_if_fail (loc != NULL, NULL);
if (loc->_local_name)
- return loc->_local_name;
+ return loc->_local_name;
if (loc->db && IDX_VALID (loc->db_idx)) {
- const char *english_name;
- const char *msgctxt;
- english_name = EMPTY_TO_NULL (db_i18n_get_str (db_location_get_name (loc->ref)));
- msgctxt = EMPTY_TO_NULL (db_i18n_get_msgctxt (db_location_get_name (loc->ref)));
-
- if (msgctxt) {
- loc->_local_name = g_strdup (g_dpgettext2 (LOCATIONS_GETTEXT_PACKAGE,
- msgctxt, english_name));
- } else {
- loc->_local_name = g_strdup (g_dgettext (LOCATIONS_GETTEXT_PACKAGE,
+ const char *english_name;
+ const char *msgctxt;
+ english_name = EMPTY_TO_NULL (db_i18n_get_str (db_location_get_name (loc->ref)));
+ msgctxt = EMPTY_TO_NULL (db_i18n_get_msgctxt (db_location_get_name (loc->ref)));
+
+ if (msgctxt) {
+ loc->_local_name = g_strdup (g_dpgettext2 (LOCATIONS_GETTEXT_PACKAGE,
+ msgctxt,
+ english_name));
+ } else {
+ loc->_local_name = g_strdup (g_dgettext (LOCATIONS_GETTEXT_PACKAGE,
english_name));
- }
- return loc->_local_name;
+ }
+ return loc->_local_name;
} else {
- return NULL;
+ return NULL;
}
}
@@ -329,7 +333,7 @@ gweather_location_get_sort_name (GWeatherLocation *loc)
local_name = gweather_location_get_name (loc);
if (!local_name)
- return NULL;
+ return NULL;
normalized = g_utf8_normalize (local_name, -1, G_NORMALIZE_ALL);
loc->_local_sort_name = g_utf8_casefold (normalized, -1);
@@ -351,7 +355,7 @@ gweather_location_get_english_name (GWeatherLocation *loc)
g_return_val_if_fail (loc != NULL, NULL);
if (loc->_english_name)
- return loc->_english_name;
+ return loc->_english_name;
if (loc->db && IDX_VALID (loc->db_idx))
return EMPTY_TO_NULL (db_i18n_get_str (db_location_get_name (loc->ref)));
@@ -380,11 +384,11 @@ gweather_location_get_english_sort_name (GWeatherLocation *loc)
g_return_val_if_fail (loc != NULL, NULL);
if (loc->_english_sort_name)
- return loc->_english_sort_name;
+ return loc->_english_sort_name;
english_name = gweather_location_get_english_name (loc);
if (!english_name)
- return NULL;
+ return NULL;
normalized = g_utf8_normalize (english_name, -1, G_NORMALIZE_ALL);
loc->_english_sort_name = g_utf8_casefold (normalized, -1);
@@ -421,24 +425,24 @@ const char *
gweather_location_level_to_string (GWeatherLocationLevel level)
{
switch (level) {
- case GWEATHER_LOCATION_WORLD:
- return "world";
- case GWEATHER_LOCATION_REGION:
- return "region";
- case GWEATHER_LOCATION_COUNTRY:
- return "country";
- case GWEATHER_LOCATION_ADM1:
- return "adm1";
- case GWEATHER_LOCATION_CITY:
- return "city";
- case GWEATHER_LOCATION_WEATHER_STATION:
- return "station";
- case GWEATHER_LOCATION_DETACHED:
- return "detached";
- case GWEATHER_LOCATION_NAMED_TIMEZONE:
- return "named-timezone";
- default:
- g_assert_not_reached();
+ case GWEATHER_LOCATION_WORLD:
+ return "world";
+ case GWEATHER_LOCATION_REGION:
+ return "region";
+ case GWEATHER_LOCATION_COUNTRY:
+ return "country";
+ case GWEATHER_LOCATION_ADM1:
+ return "adm1";
+ case GWEATHER_LOCATION_CITY:
+ return "city";
+ case GWEATHER_LOCATION_WEATHER_STATION:
+ return "station";
+ case GWEATHER_LOCATION_DETACHED:
+ return "detached";
+ case GWEATHER_LOCATION_NAMED_TIMEZONE:
+ return "named-timezone";
+ default:
+ g_assert_not_reached ();
}
return NULL;
@@ -458,18 +462,18 @@ gweather_location_get_parent (GWeatherLocation *loc)
g_return_val_if_fail (loc != NULL, NULL);
if (loc->_parent)
- return gweather_location_ref (loc->_parent);
+ return gweather_location_ref (loc->_parent);
if (loc->level == GWEATHER_LOCATION_WORLD)
- return NULL;
+ return NULL;
/* No database or root object */
- if (!loc->db || !IDX_VALID(loc->db_idx))
- return NULL;
+ if (!loc->db || !IDX_VALID (loc->db_idx))
+ return NULL;
/* Note: We cannot use db_location_get_parent here in case this is an
* implicit nearest copy! */
- g_assert (IDX_VALID(loc->parent_idx) && loc->parent_idx != loc->db_idx);
+ g_assert (IDX_VALID (loc->parent_idx) && loc->parent_idx != loc->db_idx);
return location_ref_for_idx (loc->db, loc->parent_idx, NULL);
}
@@ -496,10 +500,10 @@ gweather_location_get_parent (GWeatherLocation *loc)
* Returns: (transfer full) (nullable): The next child, if one exists
**/
GWeatherLocation *
-gweather_location_next_child (GWeatherLocation *loc,
- GWeatherLocation *_child)
+gweather_location_next_child (GWeatherLocation *loc,
+ GWeatherLocation *_child)
{
- g_autoptr(GWeatherLocation) child = _child;
+ g_autoptr (GWeatherLocation) child = _child;
DbArrayofuint16Ref children_ref;
gsize length;
gsize next_idx;
@@ -509,68 +513,67 @@ gweather_location_next_child (GWeatherLocation *loc,
/* Easy case, just look up the child and grab the next one. */
if (loc->_children) {
- if (child == NULL) {
- if (loc->_children[0])
- return gweather_location_ref (loc->_children[0]);
- else
- return NULL;
- }
-
- for (i = 0; loc->_children[i]; i++) {
- if (loc->_children[i] == child) {
- if (loc->_children[i + 1])
- return gweather_location_ref (loc->_children[i + 1]);
- else
- return NULL;
- }
- }
-
- goto invalid_child;
+ if (child == NULL) {
+ if (loc->_children[0])
+ return gweather_location_ref (loc->_children[0]);
+ else
+ return NULL;
+ }
+
+ for (i = 0; loc->_children[i]; i++) {
+ if (loc->_children[i] == child) {
+ if (loc->_children[i + 1])
+ return gweather_location_ref (loc->_children[i + 1]);
+ else
+ return NULL;
+ }
+ }
+
+ goto invalid_child;
}
/* If we have a magic nearest child, iterate over that. */
if (!g_getenv ("LIBGWEATHER_LOCATIONS_NO_NEAREST") &&
- IDX_VALID (db_location_get_nearest (loc->ref))) {
- if (child && (!child->db || !IDX_VALID (child->db_idx) || child->parent_idx != loc->db_idx))
- goto invalid_child;
-
- if (child)
- return NULL;
- else
- return location_ref_for_idx (loc->db, db_location_get_nearest (loc->ref), loc);
+ IDX_VALID (db_location_get_nearest (loc->ref))) {
+ if (child && (!child->db || !IDX_VALID (child->db_idx) || child->parent_idx != loc->db_idx))
+ goto invalid_child;
+
+ if (child)
+ return NULL;
+ else
+ return location_ref_for_idx (loc->db, db_location_get_nearest (loc->ref), loc);
}
if (!loc->db || !IDX_VALID (loc->db_idx)) {
- if (child)
- goto invalid_child;
+ if (child)
+ goto invalid_child;
- return NULL;
+ return NULL;
}
children_ref = db_location_get_children (loc->ref);
length = db_arrayofuint16_get_length (children_ref);
if (!child) {
- next_idx = 0;
+ next_idx = 0;
} else {
- /* Find child index in DB. */
- for (i = 0; i < length; i++) {
- if (child->db_idx == db_arrayofuint16_get_at (children_ref, i))
- break;
- }
-
- if (i == length)
- goto invalid_child;
- next_idx = i + 1;
+ /* Find child index in DB. */
+ for (i = 0; i < length; i++) {
+ if (child->db_idx == db_arrayofuint16_get_at (children_ref, i))
+ break;
+ }
+
+ if (i == length)
+ goto invalid_child;
+ next_idx = i + 1;
}
if (next_idx == length)
- return NULL;
+ return NULL;
else
- return location_ref_for_idx (loc->db,
- db_arrayofuint16_get_at (children_ref, next_idx),
- NULL);
-
+ return location_ref_for_idx (loc->db,
+ db_arrayofuint16_get_at (children_ref, next_idx),
+ NULL);
invalid_child:
g_critical ("%s: Passed child %p is not a child of the given location %p", G_STRFUNC, loc, child);
@@ -578,18 +581,18 @@ invalid_child:
}
static void
-foreach_city (GWeatherLocation *loc,
- GFunc callback,
- gpointer user_data,
- const char *country_code,
+foreach_city (GWeatherLocation *loc,
+ GFunc callback,
+ gpointer user_data,
+ const char *country_code,
GWeatherFilterFunc func,
- gpointer user_data_func)
+ gpointer user_data_func)
{
- if (country_code) {
- const char *loc_country_code = gweather_location_get_country(loc);
- if (loc_country_code && (g_strcmp0 (loc_country_code, country_code) != 0))
- return;
- }
+ if (country_code) {
+ const char *loc_country_code = gweather_location_get_country (loc);
+ if (loc_country_code && (g_strcmp0 (loc_country_code, country_code) != 0))
+ return;
+ }
if (func) {
if (!func (loc, user_data_func))
@@ -599,21 +602,23 @@ foreach_city (GWeatherLocation *loc,
if (loc->level == GWEATHER_LOCATION_CITY) {
callback (loc, user_data);
} else {
- g_autoptr(GWeatherLocation) child = NULL;
+ g_autoptr (GWeatherLocation) child = NULL;
- while ((child = gweather_location_next_child (loc, child)))
- foreach_city (child, callback, user_data, country_code, func, user_data_func);
+ while ((child = gweather_location_next_child (loc, child)))
+ foreach_city (child, callback, user_data, country_code, func, user_data_func);
}
}
-struct FindNearestCityData {
+struct FindNearestCityData
+{
double latitude;
double longitude;
GWeatherLocation *location;
double distance;
};
-struct ArgData {
+struct ArgData
+{
double latitude;
double longitude;
GWeatherLocation *location;
@@ -623,8 +628,7 @@ struct ArgData {
typedef struct ArgData ArgData;
static double
-location_distance (double lat1, double long1,
- double lat2, double long2)
+location_distance (double lat1, double long1, double lat2, double long2)
{
/* average radius of the earth in km */
static const double radius = 6372.795;
@@ -633,21 +637,22 @@ location_distance (double lat1, double long1,
return 0.0;
return acos (cos (lat1) * cos (lat2) * cos (long1 - long2) +
- sin (lat1) * sin (lat2)) * radius;
+ sin (lat1) * sin (lat2)) *
+ radius;
}
static void
find_nearest_city (GWeatherLocation *location,
- gpointer user_data) {
+ gpointer user_data)
+{
struct FindNearestCityData *data = user_data;
- double distance = location_distance (location->latitude, location->longitude,
- data->latitude, data->longitude);
+ double distance = location_distance (location->latitude, location->longitude, data->latitude,
data->longitude);
if (data->location == NULL || data->distance > distance) {
- g_clear_pointer (&data->location, gweather_location_unref);
- data->location = gweather_location_ref (location);
- data->distance = distance;
+ g_clear_pointer (&data->location, gweather_location_unref);
+ data->location = gweather_location_ref (location);
+ data->distance = distance;
}
}
@@ -671,10 +676,10 @@ find_nearest_city (GWeatherLocation *location,
*/
GWeatherLocation *
gweather_location_find_nearest_city (GWeatherLocation *loc,
- double lat,
- double lon)
+ double lat,
+ double lon)
{
- g_autoptr(GWeatherLocation) world = NULL;
+ g_autoptr (GWeatherLocation) world = NULL;
/* The data set really isn't too big. Don't concern ourselves
* with a proper nearest neighbors search. Instead, just do
* an O(n) search. */
@@ -683,7 +688,7 @@ gweather_location_find_nearest_city (GWeatherLocation *loc,
g_return_val_if_fail (loc == NULL || loc->level < GWEATHER_LOCATION_CITY, NULL);
if (loc == NULL)
- loc = world = gweather_location_get_world ();
+ loc = world = gweather_location_get_world ();
lat = lat * M_PI / 180.0;
lon = lon * M_PI / 180.0;
@@ -721,21 +726,22 @@ gweather_location_find_nearest_city (GWeatherLocation *loc,
* region or administrative district of @loc with validation of filter function.
*/
GWeatherLocation *
-gweather_location_find_nearest_city_full (GWeatherLocation *loc,
- double lat,
- double lon,
- GWeatherFilterFunc func,
- gpointer user_data,
- GDestroyNotify destroy)
+gweather_location_find_nearest_city_full (GWeatherLocation *loc,
+ double lat,
+ double lon,
+ GWeatherFilterFunc func,
+ gpointer user_data,
+ GDestroyNotify destroy)
{
- g_autoptr(GWeatherLocation) world = NULL;
+ g_autoptr (GWeatherLocation) world = NULL;
/* The data set really isn't too big. Don't concern ourselves
* with a proper nearest neighbors search. Instead, just do
* an O(n) search. */
struct FindNearestCityData data;
g_return_val_if_fail (loc == NULL || loc->level < GWEATHER_LOCATION_CITY ||
- loc->level == GWEATHER_LOCATION_NAMED_TIMEZONE, NULL);
+ loc->level == GWEATHER_LOCATION_NAMED_TIMEZONE,
+ NULL);
if (loc == NULL)
loc = world = gweather_location_get_world ();
@@ -756,9 +762,9 @@ gweather_location_find_nearest_city_full (GWeatherLocation *loc,
}
static void
-_got_place (GObject *source_object,
- GAsyncResult *result,
- gpointer user_data)
+_got_place (GObject *source_object,
+ GAsyncResult *result,
+ gpointer user_data)
{
ArgData *info = (user_data);
GTask *task = info->task;
@@ -769,7 +775,7 @@ _got_place (GObject *source_object,
place = geocode_reverse_resolve_finish (GEOCODE_REVERSE (source_object), result, &error);
if (place == NULL) {
- g_task_return_error (task, error);
+ g_task_return_error (task, error);
g_slice_free (ArgData, info);
g_object_unref (task);
return;
@@ -786,12 +792,12 @@ _got_place (GObject *source_object,
g_slice_free (ArgData, info);
if (data.location == NULL) {
- g_task_return_pointer (task, NULL, NULL);
+ g_task_return_pointer (task, NULL, NULL);
} else {
GWeatherLocation *location;
- location = _gweather_location_new_detached(data.location, geocode_place_get_town (place), TRUE,
data.latitude, data.longitude);
+ location = _gweather_location_new_detached (data.location, geocode_place_get_town (place), TRUE,
data.latitude, data.longitude);
- g_task_return_pointer (task, location, (GDestroyNotify)gweather_location_unref);
+ g_task_return_pointer (task, location, (GDestroyNotify) gweather_location_unref);
}
g_object_unref (task);
@@ -813,21 +819,21 @@ _got_place (GObject *source_object,
* This restriction may be lifted in a future version.
*/
void
-gweather_location_detect_nearest_city (GWeatherLocation *loc,
- double lat,
- double lon,
- GCancellable *cancellable,
- GAsyncReadyCallback callback,
- gpointer user_data)
+gweather_location_detect_nearest_city (GWeatherLocation *loc,
+ double lat,
+ double lon,
+ GCancellable *cancellable,
+ GAsyncReadyCallback callback,
+ gpointer user_data)
{
- g_autoptr(GWeatherLocation) world = NULL;
+ g_autoptr (GWeatherLocation) world = NULL;
ArgData *data;
GeocodeLocation *location;
GeocodeReverse *reverse;
GTask *task;
g_return_if_fail (loc == NULL || loc->level < GWEATHER_LOCATION_CITY ||
- loc->level == GWEATHER_LOCATION_NAMED_TIMEZONE);
+ loc->level == GWEATHER_LOCATION_NAMED_TIMEZONE);
if (loc == NULL)
loc = world = gweather_location_get_world ();
@@ -862,8 +868,8 @@ gweather_location_detect_nearest_city_finish (GAsyncResult *result, GError **err
GTask *task;
g_return_val_if_fail (g_task_is_valid (result,
- NULL),
- NULL);
+ NULL),
+ NULL);
task = G_TASK (result);
return g_task_propagate_pointer (task, error);
@@ -895,7 +901,8 @@ gweather_location_has_coords (GWeatherLocation *loc)
**/
void
gweather_location_get_coords (GWeatherLocation *loc,
- double *latitude, double *longitude)
+ double *latitude,
+ double *longitude)
{
//g_return_if_fail (loc->latlon_valid);
g_return_if_fail (loc != NULL);
@@ -924,8 +931,7 @@ gweather_location_get_distance (GWeatherLocation *loc, GWeatherLocation *loc2)
g_return_val_if_fail (loc->latlon_valid, G_MAXDOUBLE);
g_return_val_if_fail (loc2->latlon_valid, G_MAXDOUBLE);
- return location_distance (loc->latitude, loc->longitude,
- loc2->latitude, loc2->longitude);
+ return location_distance (loc->latitude, loc->longitude, loc2->latitude, loc2->longitude);
}
/**
@@ -941,19 +947,19 @@ gweather_location_get_distance (GWeatherLocation *loc, GWeatherLocation *loc2)
const char *
gweather_location_get_country (GWeatherLocation *loc)
{
- g_autoptr(GWeatherLocation) s = NULL;
+ g_autoptr (GWeatherLocation) s = NULL;
g_return_val_if_fail (loc != NULL, NULL);
- ITER_UP(loc, s) {
- if (s->_country_code)
- return s->_country_code;
+ ITER_UP (loc, s) {
+ if (s->_country_code)
+ return s->_country_code;
- if (s->db && IDX_VALID(s->db_idx)) {
- const char *country_code;
- country_code = EMPTY_TO_NULL (db_location_get_country_code (s->ref));
- if (country_code)
- return country_code;
- }
+ if (s->db && IDX_VALID (s->db_idx)) {
+ const char *country_code;
+ country_code = EMPTY_TO_NULL (db_location_get_country_code (s->ref));
+ if (country_code)
+ return country_code;
+ }
}
return NULL;
}
@@ -969,19 +975,19 @@ gweather_location_get_country (GWeatherLocation *loc)
GWeatherTimezone *
gweather_location_get_timezone (GWeatherLocation *loc)
{
- g_autoptr(GWeatherLocation) s = NULL;
+ g_autoptr (GWeatherLocation) s = NULL;
g_return_val_if_fail (loc != NULL, NULL);
if (loc->_timezone)
- return loc->_timezone;
+ return loc->_timezone;
- ITER_UP(loc, s) {
- if (!IDX_VALID (s->tz_hint_idx))
- continue;
+ ITER_UP (loc, s) {
+ if (!IDX_VALID (s->tz_hint_idx))
+ continue;
- loc->_timezone = _gweather_timezone_ref_for_idx (s->db, s->tz_hint_idx);
- return loc->_timezone;
+ loc->_timezone = _gweather_timezone_ref_for_idx (s->db, s->tz_hint_idx);
+ return loc->_timezone;
}
return NULL;
}
@@ -998,17 +1004,17 @@ gweather_location_get_timezone (GWeatherLocation *loc)
const char *
gweather_location_get_timezone_str (GWeatherLocation *loc)
{
- g_autoptr(GWeatherLocation) s = NULL;
+ g_autoptr (GWeatherLocation) s = NULL;
g_return_val_if_fail (loc != NULL, NULL);
- ITER_UP(loc, s) {
- if (s->_timezone)
- return gweather_timezone_get_tzid (s->_timezone);
+ ITER_UP (loc, s) {
+ if (s->_timezone)
+ return gweather_timezone_get_tzid (s->_timezone);
- if (s->db && IDX_VALID(s->tz_hint_idx)) {
- return db_world_timezones_entry_get_key (db_world_timezones_get_at (s->db->timezones_ref,
s->tz_hint_idx));
- }
+ if (s->db && IDX_VALID (s->tz_hint_idx)) {
+ return db_world_timezones_entry_get_key (db_world_timezones_get_at (s->db->timezones_ref,
s->tz_hint_idx));
+ }
}
return NULL;
@@ -1021,21 +1027,21 @@ add_timezones (GWeatherLocation *loc, GPtrArray *zones)
/* NOTE: Only DB backed locations can have timezones */
if (loc->db && IDX_VALID (loc->db_idx)) {
- DbArrayofuint16Ref ref;
- gsize len;
-
- ref = db_location_get_timezones (loc->ref);
- len = db_arrayofuint16_get_length (ref);
- for (i = 0; i < len; i++)
- g_ptr_array_add (zones,
- _gweather_timezone_ref_for_idx (loc->db,
- db_arrayofuint16_get_at (ref, i)));
+ DbArrayofuint16Ref ref;
+ gsize len;
+
+ ref = db_location_get_timezones (loc->ref);
+ len = db_arrayofuint16_get_length (ref);
+ for (i = 0; i < len; i++)
+ g_ptr_array_add (zones,
+ _gweather_timezone_ref_for_idx (loc->db,
+ db_arrayofuint16_get_at (ref, i)));
}
if (loc->level < GWEATHER_LOCATION_COUNTRY) {
- g_autoptr(GWeatherLocation) child = NULL;
+ g_autoptr (GWeatherLocation) child = NULL;
- while ((child = gweather_location_next_child (loc, child)))
- add_timezones (child, zones);
+ while ((child = gweather_location_next_child (loc, child)))
+ add_timezones (child, zones);
}
}
@@ -1061,7 +1067,7 @@ gweather_location_get_timezones (GWeatherLocation *loc)
zones = g_ptr_array_new ();
add_timezones (loc, zones);
g_ptr_array_add (zones, NULL);
- return (GWeatherTimezone **)g_ptr_array_free (zones, FALSE);
+ return (GWeatherTimezone **) g_ptr_array_free (zones, FALSE);
}
/**
@@ -1073,8 +1079,8 @@ gweather_location_get_timezones (GWeatherLocation *loc)
* gweather_location_get_timezones().
**/
void
-gweather_location_free_timezones (GWeatherLocation *loc,
- GWeatherTimezone **zones)
+gweather_location_free_timezones (GWeatherLocation *loc,
+ GWeatherTimezone **zones)
{
int i;
@@ -1082,7 +1088,7 @@ gweather_location_free_timezones (GWeatherLocation *loc,
g_return_if_fail (zones != NULL);
for (i = 0; zones[i]; i++)
- gweather_timezone_unref (zones[i]);
+ gweather_timezone_unref (zones[i]);
g_free (zones);
}
@@ -1100,10 +1106,10 @@ gweather_location_get_code (GWeatherLocation *loc)
{
g_return_val_if_fail (loc != NULL, NULL);
if (loc->_station_code)
- return loc->_station_code;
+ return loc->_station_code;
- if (loc->db && IDX_VALID(loc->db_idx)) {
- return EMPTY_TO_NULL (db_location_get_metar_code (loc->ref));
+ if (loc->db && IDX_VALID (loc->db_idx)) {
+ return EMPTY_TO_NULL (db_location_get_metar_code (loc->ref));
}
return NULL;
@@ -1130,14 +1136,14 @@ gweather_location_get_city_name (GWeatherLocation *loc)
loc->level == GWEATHER_LOCATION_DETACHED) {
return g_strdup (gweather_location_get_name (loc));
} else {
- g_autoptr(GWeatherLocation) parent = NULL;
- parent = gweather_location_get_parent (loc);
-
- if (loc->level == GWEATHER_LOCATION_WEATHER_STATION &&
- parent &&
- parent->level == GWEATHER_LOCATION_CITY) {
- return g_strdup (gweather_location_get_name (parent));
- }
+ g_autoptr (GWeatherLocation) parent = NULL;
+ parent = gweather_location_get_parent (loc);
+
+ if (loc->level == GWEATHER_LOCATION_WEATHER_STATION &&
+ parent &&
+ parent->level == GWEATHER_LOCATION_CITY) {
+ return g_strdup (gweather_location_get_name (parent));
+ }
}
return NULL;
@@ -1160,13 +1166,13 @@ gweather_location_get_city_name (GWeatherLocation *loc)
char *
gweather_location_get_country_name (GWeatherLocation *loc)
{
- g_autoptr(GWeatherLocation) country = NULL;
+ g_autoptr (GWeatherLocation) country = NULL;
g_return_val_if_fail (loc != NULL, NULL);
- ITER_UP(loc, country) {
- if (country->level == GWEATHER_LOCATION_COUNTRY)
- return g_strdup (gweather_location_get_name (country));
+ ITER_UP (loc, country) {
+ if (country->level == GWEATHER_LOCATION_COUNTRY)
+ return g_strdup (gweather_location_get_name (country));
}
return NULL;
@@ -1174,41 +1180,41 @@ gweather_location_get_country_name (GWeatherLocation *loc)
void
_gweather_location_update_weather_location (GWeatherLocation *gloc,
- WeatherLocation *loc)
+ WeatherLocation *loc)
{
char *code = NULL, *zone = NULL, *radar = NULL, *tz_hint = NULL;
gboolean latlon_valid = FALSE;
gdouble lat = DBL_MAX, lon = DBL_MAX;
- g_autoptr(GWeatherLocation) start = NULL;
- g_autoptr(GWeatherLocation) l = NULL;
+ g_autoptr (GWeatherLocation) start = NULL;
+ g_autoptr (GWeatherLocation) l = NULL;
if (gloc->level == GWEATHER_LOCATION_CITY) {
- GWeatherLocation *first_child;
- first_child = gweather_location_next_child (gloc, NULL);
+ GWeatherLocation *first_child;
+ first_child = gweather_location_next_child (gloc, NULL);
- if (first_child)
- start = first_child;
+ if (first_child)
+ start = first_child;
}
if (!start)
- start = gweather_location_ref (gloc);
-
- ITER_UP(start, l) {
- if (!code)
- code = g_strdup (gweather_location_get_code (l));
- if (!zone && l->db && IDX_VALID(l->db_idx))
- zone = g_strdup (EMPTY_TO_NULL (db_location_get_forecast_zone (l->ref)));
- if (!radar && l->db && IDX_VALID(l->db_idx))
- radar = g_strdup (EMPTY_TO_NULL (db_location_get_radar (l->ref)));
- if (!tz_hint && l->db && IDX_VALID(l->tz_hint_idx))
- tz_hint = g_strdup (db_world_timezones_entry_get_key (db_world_timezones_get_at
(l->db->timezones_ref, l->tz_hint_idx)));
- if (!latlon_valid) {
- lat = l->latitude;
- lon = l->longitude;
- latlon_valid = l->latlon_valid;
- }
-
- if (code && zone && radar && tz_hint && latlon_valid)
- break;
+ start = gweather_location_ref (gloc);
+
+ ITER_UP (start, l) {
+ if (!code)
+ code = g_strdup (gweather_location_get_code (l));
+ if (!zone && l->db && IDX_VALID (l->db_idx))
+ zone = g_strdup (EMPTY_TO_NULL (db_location_get_forecast_zone (l->ref)));
+ if (!radar && l->db && IDX_VALID (l->db_idx))
+ radar = g_strdup (EMPTY_TO_NULL (db_location_get_radar (l->ref)));
+ if (!tz_hint && l->db && IDX_VALID (l->tz_hint_idx))
+ tz_hint = g_strdup (db_world_timezones_entry_get_key (db_world_timezones_get_at
(l->db->timezones_ref, l->tz_hint_idx)));
+ if (!latlon_valid) {
+ lat = l->latitude;
+ lon = l->longitude;
+ latlon_valid = l->latlon_valid;
+ }
+
+ if (code && zone && radar && tz_hint && latlon_valid)
+ break;
}
loc->name = g_strdup (gweather_location_get_name (gloc)),
@@ -1243,17 +1249,17 @@ _gweather_location_update_weather_location (GWeatherLocation *gloc,
*/
GWeatherLocation *
gweather_location_find_by_station_code (GWeatherLocation *world,
- const gchar *station_code)
+ const gchar *station_code)
{
DbWorldLocByMetarRef loc_by_metar;
guint16 idx;
if (!world->db)
- return NULL;
+ return NULL;
loc_by_metar = db_world_get_loc_by_metar (world->db->world);
if (!db_world_loc_by_metar_lookup (loc_by_metar, station_code, NULL, &idx))
- return NULL;
+ return NULL;
return location_ref_for_idx (world->db, idx, NULL);
}
@@ -1272,17 +1278,17 @@ gweather_location_find_by_station_code (GWeatherLocation *world,
*/
GWeatherLocation *
gweather_location_find_by_country_code (GWeatherLocation *world,
- const gchar *country_code)
+ const gchar *country_code)
{
DbWorldLocByCountryRef loc_by_country;
guint16 idx;
if (!world->db)
- return NULL;
+ return NULL;
loc_by_country = db_world_get_loc_by_country (world->db->world);
if (!db_world_loc_by_country_lookup (loc_by_country, country_code, NULL, &idx))
- return NULL;
+ return NULL;
return location_ref_for_idx (world->db, idx, NULL);
}
@@ -1307,49 +1313,49 @@ gweather_location_find_by_country_code (GWeatherLocation *world,
*/
gboolean
gweather_location_equal (GWeatherLocation *one,
- GWeatherLocation *two)
+ GWeatherLocation *two)
{
- g_autoptr(GWeatherLocation) p1 = NULL, p2 = NULL;
+ g_autoptr (GWeatherLocation) p1 = NULL, p2 = NULL;
int level;
if (one == two)
- return TRUE;
+ return TRUE;
p1 = gweather_location_get_parent (one);
p2 = gweather_location_get_parent (two);
if (one->level != two->level &&
- one->level != GWEATHER_LOCATION_DETACHED &&
- two->level != GWEATHER_LOCATION_DETACHED)
- return FALSE;
+ one->level != GWEATHER_LOCATION_DETACHED &&
+ two->level != GWEATHER_LOCATION_DETACHED)
+ return FALSE;
level = one->level;
if (level == GWEATHER_LOCATION_DETACHED)
- level = two->level;
+ level = two->level;
if (level == GWEATHER_LOCATION_COUNTRY)
- return g_strcmp0 (gweather_location_get_country (one),
- gweather_location_get_country (two));
+ return g_strcmp0 (gweather_location_get_country (one),
+ gweather_location_get_country (two));
if (level == GWEATHER_LOCATION_ADM1) {
- if (g_strcmp0 (gweather_location_get_english_sort_name (one), gweather_location_get_english_sort_name
(two)) != 0)
- return FALSE;
+ if (g_strcmp0 (gweather_location_get_english_sort_name (one),
gweather_location_get_english_sort_name (two)) != 0)
+ return FALSE;
- return p1 && p2 &&
- gweather_location_equal (p1, p2);
+ return p1 && p2 &&
+ gweather_location_equal (p1, p2);
}
if (g_strcmp0 (gweather_location_get_code (one),
gweather_location_get_code (two)) != 0)
- return FALSE;
+ return FALSE;
if (one->level != GWEATHER_LOCATION_DETACHED &&
- two->level != GWEATHER_LOCATION_DETACHED &&
- !gweather_location_equal (p1, p2))
- return FALSE;
+ two->level != GWEATHER_LOCATION_DETACHED &&
+ !gweather_location_equal (p1, p2))
+ return FALSE;
- return ABS(one->latitude - two->latitude) < EPSILON &&
- ABS(one->longitude - two->longitude) < EPSILON;
+ return ABS (one->latitude - two->latitude) < EPSILON &&
+ ABS (one->longitude - two->longitude) < EPSILON;
}
/* ------------------- serialization ------------------------------- */
@@ -1359,8 +1365,8 @@ gweather_location_equal (GWeatherLocation *one,
static GVariant *
gweather_location_format_two_serialize (GWeatherLocation *location)
{
- g_autoptr(GWeatherLocation) real_loc = NULL;
- g_autoptr(GWeatherLocation) parent = NULL;
+ g_autoptr (GWeatherLocation) real_loc = NULL;
+ g_autoptr (GWeatherLocation) parent = NULL;
const char *name;
const char *station_code;
gboolean is_city;
@@ -1371,74 +1377,75 @@ gweather_location_format_two_serialize (GWeatherLocation *location)
/* Normalize location to be a weather station or detached */
if (location->level == GWEATHER_LOCATION_CITY) {
- real_loc = gweather_location_next_child (location, NULL);
+ real_loc = gweather_location_next_child (location, NULL);
is_city = TRUE;
} else {
- is_city = FALSE;
+ is_city = FALSE;
}
if (!real_loc)
- real_loc = gweather_location_ref (location);
+ real_loc = gweather_location_ref (location);
parent = gweather_location_get_parent (real_loc);
g_variant_builder_init (&latlon_builder, G_VARIANT_TYPE ("a(dd)"));
if (real_loc->latlon_valid)
- g_variant_builder_add (&latlon_builder, "(dd)", real_loc->latitude, real_loc->longitude);
+ g_variant_builder_add (&latlon_builder, "(dd)", real_loc->latitude, real_loc->longitude);
g_variant_builder_init (&parent_latlon_builder, G_VARIANT_TYPE ("a(dd)"));
if (parent && parent->latlon_valid)
- g_variant_builder_add (&parent_latlon_builder, "(dd)", parent->latitude, parent->longitude);
+ g_variant_builder_add (&parent_latlon_builder, "(dd)", parent->latitude, parent->longitude);
station_code = gweather_location_get_code (real_loc);
return g_variant_new ("(ssba(dd)a(dd))",
- name,
- station_code ? station_code : "",
- is_city,
- &latlon_builder, &parent_latlon_builder);
+ name,
+ station_code ? station_code : "",
+ is_city,
+ &latlon_builder,
+ &parent_latlon_builder);
}
GWeatherLocation *
_gweather_location_new_detached (GWeatherLocation *nearest_station,
- const char *name,
- gboolean latlon_valid,
- gdouble latitude,
- gdouble longitude)
+ const char *name,
+ gboolean latlon_valid,
+ gdouble latitude,
+ gdouble longitude)
{
GWeatherLocation *self;
char *normalized;
self = location_new (GWEATHER_LOCATION_DETACHED);
if (name != NULL) {
- self->_english_name = g_strdup (name);
- self->_local_name = g_strdup (name);
+ self->_english_name = g_strdup (name);
+ self->_local_name = g_strdup (name);
- normalized = g_utf8_normalize (name, -1, G_NORMALIZE_ALL);
- self->_english_sort_name = g_utf8_casefold (normalized, -1);
- self->_local_sort_name = g_strdup (self->_english_sort_name);
- g_free (normalized);
+ normalized = g_utf8_normalize (name, -1, G_NORMALIZE_ALL);
+ self->_english_sort_name = g_utf8_casefold (normalized, -1);
+ self->_local_sort_name = g_strdup (self->_english_sort_name);
+ g_free (normalized);
} else if (nearest_station) {
- self->_english_name = g_strdup (gweather_location_get_english_name (nearest_station));
- self->_local_name = g_strdup (gweather_location_get_name (nearest_station));
- self->_english_sort_name = g_strdup (gweather_location_get_english_sort_name (nearest_station));
- self->_local_sort_name = g_strdup (gweather_location_get_sort_name (nearest_station));
+ self->_english_name = g_strdup (gweather_location_get_english_name (nearest_station));
+ self->_local_name = g_strdup (gweather_location_get_name (nearest_station));
+ self->_english_sort_name = g_strdup (gweather_location_get_english_sort_name (nearest_station));
+ self->_local_sort_name = g_strdup (gweather_location_get_sort_name (nearest_station));
}
self->_parent = nearest_station; /* a reference is passed */
self->_children = NULL;
if (nearest_station)
- self->_station_code = g_strdup (gweather_location_get_code (nearest_station));
+ self->_station_code = g_strdup (gweather_location_get_code (nearest_station));
g_assert (nearest_station || latlon_valid);
if (latlon_valid) {
- self->latlon_valid = TRUE;
- self->latitude = latitude;
- self->longitude = longitude;
+ self->latlon_valid = TRUE;
+ self->latitude = latitude;
+ self->longitude = longitude;
} else {
- self->latlon_valid = nearest_station->latlon_valid;
- self->latitude = nearest_station->latitude;
- self->longitude = nearest_station->longitude;
+ self->latlon_valid = nearest_station->latlon_valid;
+ self->latitude = nearest_station->latitude;
+ self->longitude = nearest_station->longitude;
}
return self;
@@ -1446,17 +1453,17 @@ _gweather_location_new_detached (GWeatherLocation *nearest_station,
static GWeatherLocation *
gweather_location_common_deserialize (GWeatherLocation *world,
- const char *name,
- const char *station_code,
- gboolean is_city,
- gboolean latlon_valid,
- gdouble latitude,
- gdouble longitude,
- gboolean parent_latlon_valid,
- gdouble parent_latitude,
- gdouble parent_longitude)
+ const char *name,
+ const char *station_code,
+ gboolean is_city,
+ gboolean latlon_valid,
+ gdouble latitude,
+ gdouble longitude,
+ gboolean parent_latlon_valid,
+ gdouble parent_latitude,
+ gdouble parent_longitude)
{
- g_autoptr(GWeatherLocation) by_station_code = NULL;
+ g_autoptr (GWeatherLocation) by_station_code = NULL;
DbWorldLocByMetarRef loc_by_metar;
GWeatherLocation *found;
gsize i;
@@ -1470,8 +1477,8 @@ gweather_location_common_deserialize (GWeatherLocation *world,
if (found && (g_strcmp0 (name, gweather_location_get_english_name (found)) == 0 ||
g_strcmp0 (name, gweather_location_get_name (found)) == 0))
- return g_steal_pointer (&found);
- g_clear_pointer (&found, gweather_location_unref);
+ return g_steal_pointer (&found);
+ g_clear_pointer (&found, gweather_location_unref);
}
if (station_code[0] == '\0')
@@ -1484,78 +1491,84 @@ gweather_location_common_deserialize (GWeatherLocation *world,
* return it directly
*/
if (station_code[0] == '@')
- return g_steal_pointer (&by_station_code);
+ return g_steal_pointer (&by_station_code);
/* If we don't have coordinates, fallback immediately to making up
* a location
*/
if (!latlon_valid)
- return by_station_code
- ? _gweather_location_new_detached (g_steal_pointer (&by_station_code),
- name, FALSE, 0, 0)
- : NULL;
+ return by_station_code
+ ? _gweather_location_new_detached (g_steal_pointer (&by_station_code),
+ name,
+ FALSE,
+ 0,
+ 0)
+ : NULL;
found = NULL;
loc_by_metar = db_world_get_loc_by_metar (world->db->world);
for (i = 0; i < db_world_loc_by_metar_get_length (loc_by_metar); i++) {
- g_autoptr(GWeatherLocation) ws = NULL, city = NULL;
- /* Skip if the metar code does not match */
- if (!g_str_equal (station_code, db_world_loc_by_metar_entry_get_key (db_world_loc_by_metar_get_at
(loc_by_metar, i))))
- continue;
+ g_autoptr (GWeatherLocation) ws = NULL, city = NULL;
+ /* Skip if the metar code does not match */
+ if (!g_str_equal (station_code, db_world_loc_by_metar_entry_get_key (db_world_loc_by_metar_get_at
(loc_by_metar, i))))
+ continue;
- /* Be lazy and allocate the location */
- ws = location_ref_for_idx (world->db, db_world_loc_by_metar_entry_get_value
(db_world_loc_by_metar_get_at (loc_by_metar, i)), NULL);
+ /* Be lazy and allocate the location */
+ ws = location_ref_for_idx (world->db, db_world_loc_by_metar_entry_get_value
(db_world_loc_by_metar_get_at (loc_by_metar, i)), NULL);
- if (!ws->latlon_valid ||
- ABS(ws->latitude - latitude) >= EPSILON ||
- ABS(ws->longitude - longitude) >= EPSILON)
- /* Not what we're looking for... */
- continue;
+ if (!ws->latlon_valid ||
+ ABS (ws->latitude - latitude) >= EPSILON ||
+ ABS (ws->longitude - longitude) >= EPSILON)
+ /* Not what we're looking for... */
+ continue;
- city = gweather_location_get_parent (ws);
+ city = gweather_location_get_parent (ws);
- /* If we can't check for the latitude and longitude
+ /* If we can't check for the latitude and longitude
of the parent, we just assume we found what we needed
*/
- if ((!parent_latlon_valid || !city || !city->latlon_valid) ||
- (ABS(parent_latitude - city->latitude) < EPSILON &&
- ABS(parent_longitude - city->longitude) < EPSILON)) {
-
- /* Found! Now check which one we want (ws or city) and the name... */
- if (is_city)
- found = city;
- else
- found = ws;
-
- if (found == NULL) {
- /* Oops! There is no city for this weather station! */
- continue;
- }
-
- if (name == NULL ||
- g_str_equal (name, gweather_location_get_english_name (found)) ||
- g_str_equal (name, gweather_location_get_name (found)))
- found = gweather_location_ref (found);
- else
- found = _gweather_location_new_detached (gweather_location_ref (ws), name, TRUE, latitude,
longitude);
-
- return found;
- }
+ if ((!parent_latlon_valid || !city || !city->latlon_valid) ||
+ (ABS (parent_latitude - city->latitude) < EPSILON &&
+ ABS (parent_longitude - city->longitude) < EPSILON)) {
+
+ /* Found! Now check which one we want (ws or city) and the name... */
+ if (is_city)
+ found = city;
+ else
+ found = ws;
+
+ if (found == NULL) {
+ /* Oops! There is no city for this weather station! */
+ continue;
+ }
+
+ if (name == NULL ||
+ g_str_equal (name, gweather_location_get_english_name (found)) ||
+ g_str_equal (name, gweather_location_get_name (found)))
+ found = gweather_location_ref (found);
+ else
+ found = _gweather_location_new_detached (gweather_location_ref (ws), name, TRUE, latitude,
longitude);
+
+ return found;
+ }
}
/* No weather station matches the serialized data, let's pick
one at random from the station code list */
if (by_station_code)
- return _gweather_location_new_detached (g_steal_pointer (&by_station_code),
- name, TRUE, latitude, longitude);
+ return _gweather_location_new_detached (g_steal_pointer (&by_station_code),
+ name,
+ TRUE,
+ latitude,
+ longitude);
else
- return NULL;
+ return NULL;
}
static GWeatherLocation *
gweather_location_format_one_deserialize (GWeatherLocation *world,
- GVariant *variant)
+ GVariant *variant)
{
const char *name;
const char *station_code;
@@ -1565,20 +1578,17 @@ gweather_location_format_one_deserialize (GWeatherLocation *world,
/* This one instead is a critical, because format is specified in
the containing variant */
g_return_val_if_fail (g_variant_is_of_type (variant,
- G_VARIANT_TYPE ("(ssbm(dd)m(dd))")), NULL);
+ G_VARIANT_TYPE ("(ssbm(dd)m(dd))")),
+ NULL);
- g_variant_get (variant, "(&s&sbm(dd)m(dd))", &name, &station_code, &is_city,
- &latlon_valid, &latitude, &longitude,
- &parent_latlon_valid, &parent_latitude, &parent_longitude);
+ g_variant_get (variant, "(&s&sbm(dd)m(dd))", &name, &station_code, &is_city, &latlon_valid, &latitude,
&longitude, &parent_latlon_valid, &parent_latitude, &parent_longitude);
- return gweather_location_common_deserialize(world, name, station_code, is_city,
- latlon_valid, latitude, longitude,
- parent_latlon_valid, parent_latitude, parent_longitude);
+ return gweather_location_common_deserialize (world, name, station_code, is_city, latlon_valid, latitude,
longitude, parent_latlon_valid, parent_latitude, parent_longitude);
}
static GWeatherLocation *
gweather_location_format_two_deserialize (GWeatherLocation *world,
- GVariant *variant)
+ GVariant *variant)
{
const char *name;
const char *station_code;
@@ -1590,35 +1600,33 @@ gweather_location_format_two_deserialize (GWeatherLocation *world,
/* This one instead is a critical, because format is specified in
the containing variant */
g_return_val_if_fail (g_variant_is_of_type (variant,
- G_VARIANT_TYPE ("(ssba(dd)a(dd))")), NULL);
+ G_VARIANT_TYPE ("(ssba(dd)a(dd))")),
+ NULL);
- g_variant_get (variant, "(&s&sb@a(dd)@a(dd))", &name, &station_code, &is_city,
- &latlon_variant, &parent_latlon_variant);
+ g_variant_get (variant, "(&s&sb@a(dd)@a(dd))", &name, &station_code, &is_city, &latlon_variant,
&parent_latlon_variant);
if (g_variant_n_children (latlon_variant) > 0) {
- latlon_valid = TRUE;
- g_variant_get_child (latlon_variant, 0, "(dd)", &latitude, &longitude);
+ latlon_valid = TRUE;
+ g_variant_get_child (latlon_variant, 0, "(dd)", &latitude, &longitude);
} else {
- latlon_valid = FALSE;
- latitude = 0;
- longitude = 0;
+ latlon_valid = FALSE;
+ latitude = 0;
+ longitude = 0;
}
if (g_variant_n_children (parent_latlon_variant) > 0) {
- parent_latlon_valid = TRUE;
- g_variant_get_child (parent_latlon_variant, 0, "(dd)", &parent_latitude, &parent_longitude);
+ parent_latlon_valid = TRUE;
+ g_variant_get_child (parent_latlon_variant, 0, "(dd)", &parent_latitude, &parent_longitude);
} else {
- parent_latlon_valid = FALSE;
- parent_latitude = 0;
- parent_longitude = 0;
+ parent_latlon_valid = FALSE;
+ parent_latitude = 0;
+ parent_longitude = 0;
}
g_variant_unref (latlon_variant);
g_variant_unref (parent_latlon_variant);
- return gweather_location_common_deserialize(world, name, station_code, is_city,
- latlon_valid, latitude, longitude,
- parent_latlon_valid, parent_latitude, parent_longitude);
+ return gweather_location_common_deserialize (world, name, station_code, is_city, latlon_valid, latitude,
longitude, parent_latlon_valid, parent_latitude, parent_longitude);
}
/**
@@ -1643,8 +1651,7 @@ gweather_location_serialize (GWeatherLocation *loc)
g_return_val_if_fail (loc != NULL, NULL);
g_return_val_if_fail (loc->level >= GWEATHER_LOCATION_CITY, NULL);
- return g_variant_new ("(uv)", FORMAT,
- gweather_location_format_two_serialize (loc));
+ return g_variant_new ("(uv)", FORMAT, gweather_location_format_two_serialize (loc));
}
/**
@@ -1662,7 +1669,7 @@ gweather_location_serialize (GWeatherLocation *loc)
*/
GWeatherLocation *
gweather_location_deserialize (GWeatherLocation *world,
- GVariant *serialized)
+ GVariant *serialized)
{
GVariant *v;
GWeatherLocation *loc;
@@ -1674,16 +1681,16 @@ gweather_location_deserialize (GWeatherLocation *world,
/* This is not a critical error, because the serialization format
is not public, so apps can't check this before calling */
if (!g_variant_is_of_type (serialized, G_VARIANT_TYPE ("(uv)")))
- return NULL;
+ return NULL;
g_variant_get (serialized, "(uv)", &format, &v);
if (format == 1)
- loc = gweather_location_format_one_deserialize (world, v);
+ loc = gweather_location_format_one_deserialize (world, v);
else if (format == 2)
- loc = gweather_location_format_two_deserialize (world, v);
+ loc = gweather_location_format_two_deserialize (world, v);
else
- loc = NULL;
+ loc = NULL;
g_variant_unref (v);
return loc;
@@ -1701,31 +1708,27 @@ gweather_location_deserialize (GWeatherLocation *world,
*/
GWeatherLocation *
gweather_location_new_detached (const char *name,
- const char *icao,
- gdouble latitude,
- gdouble longitude)
+ const char *icao,
+ gdouble latitude,
+ gdouble longitude)
{
- g_autoptr(GWeatherLocation) world = NULL;
- g_autoptr(GWeatherLocation) city = NULL;
+ g_autoptr (GWeatherLocation) world = NULL;
+ g_autoptr (GWeatherLocation) city = NULL;
g_return_val_if_fail (name != NULL, NULL);
if (*name == 0)
- name = NULL;
+ name = NULL;
world = gweather_location_get_world ();
if (icao != NULL) {
- return gweather_location_common_deserialize (world, name,
- icao, FALSE,
- TRUE, latitude, longitude,
- FALSE, 0, 0);
+ return gweather_location_common_deserialize (world, name, icao, FALSE, TRUE, latitude, longitude,
FALSE, 0, 0);
} else {
- city = gweather_location_find_nearest_city (world, latitude, longitude);
+ city = gweather_location_find_nearest_city (world, latitude, longitude);
- latitude = DEGREES_TO_RADIANS (latitude);
- longitude = DEGREES_TO_RADIANS (longitude);
- return _gweather_location_new_detached (g_steal_pointer (&city), name,
- TRUE, latitude, longitude);
+ latitude = DEGREES_TO_RADIANS (latitude);
+ longitude = DEGREES_TO_RADIANS (longitude);
+ return _gweather_location_new_detached (g_steal_pointer (&city), name, TRUE, latitude, longitude);
}
}
diff --git a/libgweather/gweather-private.c b/libgweather/gweather-private.c
index 8b394011..16bc49e0 100644
--- a/libgweather/gweather-private.c
+++ b/libgweather/gweather-private.c
@@ -14,13 +14,13 @@
char *
_radians_to_degrees_str (gdouble radians)
{
- char *str;
- double degrees;
+ char *str;
+ double degrees;
- str = g_malloc0 (DEGREES_STR_SIZE);
- /* Max 4 decimals */
- degrees = (double) ((int) (RADIANS_TO_DEGREES (radians) * 10000)) / 10000;
- /* Too many digits */
- g_return_val_if_fail (degrees <= 1000 || degrees >= -1000, NULL);
- return g_ascii_formatd (str, G_ASCII_DTOSTR_BUF_SIZE, "%g", degrees);
+ str = g_malloc0 (DEGREES_STR_SIZE);
+ /* Max 4 decimals */
+ degrees = (double) ((int) (RADIANS_TO_DEGREES (radians) * 10000)) / 10000;
+ /* Too many digits */
+ g_return_val_if_fail (degrees <= 1000 || degrees >= -1000, NULL);
+ return g_ascii_formatd (str, G_ASCII_DTOSTR_BUF_SIZE, "%g", degrees);
}
diff --git a/libgweather/gweather-timezone.c b/libgweather/gweather-timezone.c
index 2925f97b..a75b82e8 100644
--- a/libgweather/gweather-timezone.c
+++ b/libgweather/gweather-timezone.c
@@ -23,7 +23,8 @@
* or "Europe/London".
*/
-struct _GWeatherTimezone {
+struct _GWeatherTimezone
+{
GWeatherDb *db;
guint db_idx;
@@ -35,18 +36,17 @@ struct _GWeatherTimezone {
int ref_count;
};
-#define TZ_MAGIC "TZif"
-#define TZ_HEADER_SIZE 44
-#define TZ_TIMECNT_OFFSET 32
+#define TZ_MAGIC "TZif"
+#define TZ_HEADER_SIZE 44
+#define TZ_TIMECNT_OFFSET 32
#define TZ_TRANSITIONS_OFFSET 44
-#define TZ_TTINFO_SIZE 6
+#define TZ_TTINFO_SIZE 6
#define TZ_TTINFO_GMTOFF_OFFSET 0
-#define TZ_TTINFO_ISDST_OFFSET 4
+#define TZ_TTINFO_ISDST_OFFSET 4
static gboolean
-parse_tzdata (const char *tz_name, time_t start, time_t end,
- int *offset, gboolean *has_dst, int *dst_offset)
+parse_tzdata (const char *tz_name, time_t start, time_t end, int *offset, gboolean *has_dst, int *dst_offset)
{
char *filename, *contents;
gsize length;
@@ -60,23 +60,23 @@ parse_tzdata (const char *tz_name, time_t start, time_t end,
filename = g_build_filename (ZONEINFO_DIR, tz_name, NULL);
if (!g_file_get_contents (filename, &contents, &length, NULL)) {
- g_free (filename);
- return FALSE;
+ g_free (filename);
+ return FALSE;
}
g_free (filename);
if (length < TZ_HEADER_SIZE ||
- strncmp (contents, TZ_MAGIC, strlen (TZ_MAGIC)) != 0) {
- g_free (contents);
- return FALSE;
+ strncmp (contents, TZ_MAGIC, strlen (TZ_MAGIC)) != 0) {
+ g_free (contents);
+ return FALSE;
}
- timecnt = GUINT32_FROM_BE (*(guint32 *)(void *)(contents + TZ_TIMECNT_OFFSET));
- transitions = (void *)(contents + TZ_TRANSITIONS_OFFSET);
+ timecnt = GUINT32_FROM_BE (*(guint32 *) (void *) (contents + TZ_TIMECNT_OFFSET));
+ transitions = (void *) (contents + TZ_TRANSITIONS_OFFSET);
transitions_size = timecnt * sizeof (*transitions);
- ttinfo_map = (void *)(contents + TZ_TRANSITIONS_OFFSET + transitions_size);
+ ttinfo_map = (void *) (contents + TZ_TRANSITIONS_OFFSET + transitions_size);
ttinfo_map_size = timecnt;
- ttinfos = (void *)(ttinfo_map + ttinfo_map_size);
+ ttinfos = (void *) (ttinfo_map + ttinfo_map_size);
/* @transitions is an array of @timecnt time_t values. We need to
* find the transition into the current offset, which is the last
@@ -85,51 +85,51 @@ parse_tzdata (const char *tz_name, time_t start, time_t end,
* doing DST.
*/
for (i = 1; i < timecnt && initial_transition == -1; i++) {
- if (GINT32_FROM_BE (transitions[i]) > start) {
- initial_transition = ttinfo_map[i - 1];
- if (GINT32_FROM_BE (transitions[i]) < end)
- second_transition = ttinfo_map[i];
- }
+ if (GINT32_FROM_BE (transitions[i]) > start) {
+ initial_transition = ttinfo_map[i - 1];
+ if (GINT32_FROM_BE (transitions[i]) < end)
+ second_transition = ttinfo_map[i];
+ }
}
if (initial_transition == -1) {
- if (timecnt)
- initial_transition = ttinfo_map[timecnt - 1];
- else
- initial_transition = 0;
+ if (timecnt)
+ initial_transition = ttinfo_map[timecnt - 1];
+ else
+ initial_transition = 0;
}
/* Copy the data out of the corresponding ttinfo structs */
- initial_offset = *(gint32 *)(void *)(ttinfos +
- initial_transition * TZ_TTINFO_SIZE +
- TZ_TTINFO_GMTOFF_OFFSET);
+ initial_offset = *(gint32 *) (void *) (ttinfos +
+ initial_transition * TZ_TTINFO_SIZE +
+ TZ_TTINFO_GMTOFF_OFFSET);
initial_offset = GINT32_FROM_BE (initial_offset);
initial_isdst = *(ttinfos +
- initial_transition * TZ_TTINFO_SIZE +
- TZ_TTINFO_ISDST_OFFSET);
+ initial_transition * TZ_TTINFO_SIZE +
+ TZ_TTINFO_ISDST_OFFSET);
if (second_transition != -1) {
- second_offset = *(gint32 *)(void *)(ttinfos +
- second_transition * TZ_TTINFO_SIZE +
- TZ_TTINFO_GMTOFF_OFFSET);
- second_offset = GINT32_FROM_BE (second_offset);
- second_isdst = *(ttinfos +
- second_transition * TZ_TTINFO_SIZE +
- TZ_TTINFO_ISDST_OFFSET);
-
- *has_dst = (initial_isdst != second_isdst);
+ second_offset = *(gint32 *) (void *) (ttinfos +
+ second_transition * TZ_TTINFO_SIZE +
+ TZ_TTINFO_GMTOFF_OFFSET);
+ second_offset = GINT32_FROM_BE (second_offset);
+ second_isdst = *(ttinfos +
+ second_transition * TZ_TTINFO_SIZE +
+ TZ_TTINFO_ISDST_OFFSET);
+
+ *has_dst = (initial_isdst != second_isdst);
} else
- *has_dst = FALSE;
+ *has_dst = FALSE;
if (!*has_dst)
- *offset = initial_offset / 60;
+ *offset = initial_offset / 60;
else {
- if (initial_isdst) {
- *offset = second_offset / 60;
- *dst_offset = initial_offset / 60;
- } else {
- *offset = initial_offset / 60;
- *dst_offset = second_offset / 60;
- }
+ if (initial_isdst) {
+ *offset = second_offset / 60;
+ *dst_offset = initial_offset / 60;
+ } else {
+ *offset = initial_offset / 60;
+ *dst_offset = second_offset / 60;
+ }
}
g_free (contents);
@@ -137,8 +137,8 @@ parse_tzdata (const char *tz_name, time_t start, time_t end,
}
GWeatherTimezone *
-_gweather_timezone_ref_for_idx (GWeatherDb *db,
- guint idx)
+_gweather_timezone_ref_for_idx (GWeatherDb *db,
+ guint idx)
{
GWeatherTimezone *zone;
DbWorldTimezonesEntryRef ref;
@@ -155,19 +155,18 @@ _gweather_timezone_ref_for_idx (GWeatherDb *db,
ref = db_world_timezones_get_at (db->timezones_ref, idx);
id = db_world_timezones_entry_get_key (ref);
- if (parse_tzdata (id, db->year_start, db->year_end,
- &offset, &has_dst, &dst_offset)) {
- zone = g_slice_new0 (GWeatherTimezone);
- zone->ref_count = 1;
- zone->db = db;
- zone->db_idx = idx;
+ if (parse_tzdata (id, db->year_start, db->year_end, &offset, &has_dst, &dst_offset)) {
+ zone = g_slice_new0 (GWeatherTimezone);
+ zone->ref_count = 1;
+ zone->db = db;
+ zone->db_idx = idx;
- zone->offset = offset;
- zone->has_dst = has_dst;
- zone->dst_offset = dst_offset;
+ zone->offset = offset;
+ zone->has_dst = has_dst;
+ zone->dst_offset = dst_offset;
- /* Insert weak reference */
- g_ptr_array_index (db->timezones, idx) = zone;
+ /* Insert weak reference */
+ g_ptr_array_index (db->timezones, idx) = zone;
}
return zone;
@@ -198,7 +197,7 @@ gweather_timezone_get_by_tzid (const char *tzid)
gweather_location_unref (world);
if (!db_world_timezones_lookup (db->timezones_ref, tzid, &idx, NULL))
- return NULL;
+ return NULL;
return _gweather_timezone_ref_for_idx (db, idx);
}
@@ -232,12 +231,12 @@ gweather_timezone_unref (GWeatherTimezone *zone)
g_return_if_fail (zone != NULL);
if (!--zone->ref_count) {
- if (zone->db)
- g_ptr_array_index (zone->db->timezones, zone->db_idx) = 0;
+ if (zone->db)
+ g_ptr_array_index (zone->db->timezones, zone->db_idx) = 0;
- g_free (zone->_id);
- g_free (zone->_name);
- g_slice_free (GWeatherTimezone, zone);
+ g_free (zone->_id);
+ g_free (zone->_name);
+ g_slice_free (GWeatherTimezone, zone);
}
}
@@ -259,7 +258,7 @@ gweather_timezone_get_utc (void)
zone->ref_count = 1;
zone->db_idx = INVALID_IDX;
zone->_id = g_strdup ("GMT");
- zone->_name = g_strdup (_("Greenwich Mean Time"));
+ zone->_name = g_strdup (_ ("Greenwich Mean Time"));
zone->offset = 0;
zone->has_dst = FALSE;
zone->dst_offset = 0;
@@ -292,14 +291,14 @@ gweather_timezone_get_name (GWeatherTimezone *zone)
return zone->_name;
if (!zone->db || !IDX_VALID (zone->db_idx))
- return NULL;
+ return NULL;
ref = db_world_timezones_entry_get_value (db_world_timezones_get_at (zone->db->timezones_ref,
zone->db_idx));
name = EMPTY_TO_NULL (db_i18n_get_str (db_timezone_get_name (ref)));
msgctxt = EMPTY_TO_NULL (db_i18n_get_msgctxt (db_timezone_get_name (ref)));
if (!name)
- return NULL;
+ return NULL;
if (msgctxt)
zone->_name = g_strdup (g_dpgettext2 (LOCATIONS_GETTEXT_PACKAGE, msgctxt, name));
@@ -324,7 +323,7 @@ gweather_timezone_get_tzid (GWeatherTimezone *zone)
return zone->_id;
if (!zone->db || !IDX_VALID (zone->db_idx))
- return NULL;
+ return NULL;
return db_world_timezones_entry_get_key (db_world_timezones_get_at (zone->db->timezones_ref,
zone->db_idx));
}
@@ -377,4 +376,3 @@ gweather_timezone_get_dst_offset (GWeatherTimezone *zone)
g_return_val_if_fail (zone->has_dst, 0);
return zone->dst_offset;
}
-
diff --git a/libgweather/gweather-weather.c b/libgweather/gweather-weather.c
index 624bf1ad..ea7b317c 100644
--- a/libgweather/gweather-weather.c
+++ b/libgweather/gweather-weather.c
@@ -8,25 +8,24 @@
#include "gweather-weather.h"
-#include "gweather-private.h"
#include "gweather-enum-types.h"
+#include "gweather-private.h"
-#include <stdio.h>
-#include <stdlib.h>
#include <assert.h>
-#include <string.h>
#include <ctype.h>
+#include <errno.h>
+#include <langinfo.h>
#include <math.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
#include <time.h>
#include <unistd.h>
-#include <langinfo.h>
-#include <errno.h>
#include <gio/gio.h>
#define MOON_PHASES 36
-
/**
* GWeatherInfo:
*
@@ -38,14 +37,14 @@
* moon phases.
*/
-
#define TEMPERATURE_UNIT "temperature-unit"
#define DISTANCE_UNIT "distance-unit"
#define SPEED_UNIT "speed-unit"
#define PRESSURE_UNIT "pressure-unit"
#define DEFAULT_LOCATION "default-location"
-enum {
+enum
+{
PROP_0,
PROP_LOCATION,
PROP_ENABLED_PROVIDERS,
@@ -54,7 +53,8 @@ enum {
PROP_LAST
};
-enum {
+enum
+{
SIGNAL_UPDATED,
SIGNAL_LAST
};
@@ -95,11 +95,13 @@ _weather_location_free (WeatherLocation *location)
}
static gboolean
-should_use_caps (GWeatherFormatOptions options) {
+should_use_caps (GWeatherFormatOptions options)
+{
return options == GWEATHER_FORMAT_OPTION_DEFAULT ||
(options & GWEATHER_FORMAT_OPTION_SENTENCE_CAPITALIZATION);
}
+/* clang-format off */
static const gchar *wind_direction_str[] = {
N_("variable"),
N_("north"), N_("north — northeast"), N_("northeast"), N_("east — northeast"),
@@ -115,6 +117,7 @@ static const gchar *wind_direction_caps_str[] = {
N_("South"), N_("South — Southwest"), N_("Southwest"), N_("West — Southwest"),
N_("West"), N_("West — Northwest"), N_("Northwest"), N_("North — Northwest")
};
+/* clang-format on */
const gchar *
gweather_wind_direction_to_string_full (GWeatherWindDirection wind,
@@ -123,11 +126,11 @@ gweather_wind_direction_to_string_full (GWeatherWindDirection wind,
gboolean use_caps = should_use_caps (options);
if (wind <= GWEATHER_WIND_INVALID || wind >= GWEATHER_WIND_LAST)
- return use_caps ? C_("wind direction", "Invalid")
- : C_("wind direction", "invalid");
+ return use_caps ? C_ ("wind direction", "Invalid")
+ : C_ ("wind direction", "invalid");
- return use_caps ? _(wind_direction_caps_str[(int)wind])
- : _(wind_direction_str[(int)wind]);
+ return use_caps ? _ (wind_direction_caps_str[(int) wind])
+ : _ (wind_direction_str[(int) wind]);
}
const gchar *
@@ -137,19 +140,19 @@ gweather_wind_direction_to_string (GWeatherWindDirection wind)
}
static const gchar *sky_str[] = {
- N_("clear sky"),
- N_("broken clouds"),
- N_("scattered clouds"),
- N_("few clouds"),
- N_("overcast")
+ N_ ("clear sky"),
+ N_ ("broken clouds"),
+ N_ ("scattered clouds"),
+ N_ ("few clouds"),
+ N_ ("overcast")
};
static const gchar *sky_caps_str[] = {
- N_("Clear sky"),
- N_("Broken clouds"),
- N_("Scattered clouds"),
- N_("Few clouds"),
- N_("Overcast")
+ N_ ("Clear sky"),
+ N_ ("Broken clouds"),
+ N_ ("Scattered clouds"),
+ N_ ("Few clouds"),
+ N_ ("Overcast")
};
const char *
@@ -159,20 +162,19 @@ gweather_sky_to_string (GWeatherSky sky)
}
const gchar *
-gweather_sky_to_string_full (GWeatherSky sky,
+gweather_sky_to_string_full (GWeatherSky sky,
GWeatherFormatOptions options)
{
gboolean use_caps = should_use_caps (options);
if (sky <= GWEATHER_SKY_INVALID || sky >= GWEATHER_SKY_LAST)
- return use_caps ? C_("sky conditions", "Invalid")
- : C_("sky conditions", "invalid");
+ return use_caps ? C_ ("sky conditions", "Invalid")
+ : C_ ("sky conditions", "invalid");
- return use_caps ? _(sky_caps_str[(int)sky])
- : _(sky_str[(int)sky]);
+ return use_caps ? _ (sky_caps_str[(int) sky])
+ : _ (sky_str[(int) sky]);
}
-
/*
* Even though tedious, I switched to a 2D array for weather condition
* strings, in order to facilitate internationalization, esp. for languages
@@ -189,6 +191,8 @@ gweather_sky_to_string_full (GWeatherSky sky,
* special meaning.
*/
+/* clang-format off */
+
/*
* Note, magic numbers, when you change the size here, make sure to change
* the below function so that new values are recognized
@@ -261,27 +265,29 @@ static const gchar *conditions_caps_str[24][13] = {
/* DUST_WHIRLS */ {N_("Dust whirls"), N_("Dust whirls in the vicinity") , "??",
N_("Dust whirls"), "??", "??", "??",
"??", "??", "??",
"??", "??", "??" }
};
+/* clang-format on */
+
const gchar *
-gweather_conditions_to_string_full (GWeatherConditions *cond,
- GWeatherFormatOptions options)
+gweather_conditions_to_string_full (GWeatherConditions *cond,
+ GWeatherFormatOptions options)
{
gboolean use_caps = should_use_caps (options);
const gchar *str;
if (!cond->significant) {
- return "-";
+ return "-";
} else {
- if (cond->phenomenon > GWEATHER_PHENOMENON_INVALID &&
- cond->phenomenon < GWEATHER_PHENOMENON_LAST &&
- cond->qualifier > GWEATHER_QUALIFIER_INVALID &&
- cond->qualifier < GWEATHER_QUALIFIER_LAST)
- str = use_caps ? _(conditions_caps_str[(int)cond->phenomenon][(int)cond->qualifier])
- : _(conditions_str[(int)cond->phenomenon][(int)cond->qualifier]);
- else
- str = use_caps ? C_("sky conditions", "Invalid")
- : C_("sky conditions", "invalid");
- return (strlen (str) > 0) ? str : "-";
+ if (cond->phenomenon > GWEATHER_PHENOMENON_INVALID &&
+ cond->phenomenon < GWEATHER_PHENOMENON_LAST &&
+ cond->qualifier > GWEATHER_QUALIFIER_INVALID &&
+ cond->qualifier < GWEATHER_QUALIFIER_LAST)
+ str = use_caps ? _ (conditions_caps_str[(int) cond->phenomenon][(int) cond->qualifier])
+ : _ (conditions_str[(int) cond->phenomenon][(int) cond->qualifier]);
+ else
+ str = use_caps ? C_ ("sky conditions", "Invalid")
+ : C_ ("sky conditions", "invalid");
+ return (strlen (str) > 0) ? str : "-";
}
}
@@ -302,7 +308,7 @@ requests_init (GWeatherInfo *info)
void
_gweather_info_begin_request (GWeatherInfo *info,
- SoupMessage *message)
+ SoupMessage *message)
{
info->requests_pending = g_slist_prepend (info->requests_pending, message);
g_object_ref (message);
@@ -310,53 +316,53 @@ _gweather_info_begin_request (GWeatherInfo *info,
static void
copy_weather_data (GWeatherInfo *src,
- GWeatherInfo *dest)
-{
- 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;
+ GWeatherInfo *dest)
+{
+ 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
fixup_current_conditions (GWeatherInfo *info)
{
- GWeatherInfo *first_forecast;
+ GWeatherInfo *first_forecast;
- /* Current conditions already available */
- if (info->update != 0) {
- g_debug ("Not fixing up current conditions, already valid");
- return;
- } else if (!info->forecast_list ||
- !info->forecast_list->data) {
- g_debug ("No forecast list available, not fixing up");
- return;
- }
+ /* Current conditions already available */
+ if (info->update != 0) {
+ g_debug ("Not fixing up current conditions, already valid");
+ return;
+ } else if (!info->forecast_list ||
+ !info->forecast_list->data) {
+ g_debug ("No forecast list available, not fixing up");
+ return;
+ }
- first_forecast = info->forecast_list->data;
- /* Add current conditions from forecast if close enough */
- if (first_forecast->update - time(NULL) > 60 * 60) {
- g_debug ("Forecast is too far in the future, ignoring");
- return;
- }
+ first_forecast = info->forecast_list->data;
+ /* Add current conditions from forecast if close enough */
+ if (first_forecast->update - time (NULL) > 60 * 60) {
+ g_debug ("Forecast is too far in the future, ignoring");
+ return;
+ }
- copy_weather_data (first_forecast, info);
- g_debug ("Fixed up missing current weather with first forecast data");
+ copy_weather_data (first_forecast, info);
+ g_debug ("Fixed up missing current weather with first forecast data");
}
void
_gweather_info_request_done (GWeatherInfo *info,
- SoupMessage *message)
+ SoupMessage *message)
{
info->requests_pending = g_slist_remove (info->requests_pending, message);
g_object_ref (message);
@@ -375,7 +381,7 @@ void
free_forecast_list (GWeatherInfo *info)
{
if (!info)
- return;
+ return;
g_slist_free_full (info->forecast_list, g_object_unref);
info->forecast_list = NULL;
@@ -390,13 +396,13 @@ calc_dew (gdouble temp, gdouble humidity)
gdouble esat, esurf, tmp;
if (temp > -500.0 && humidity > -1.0) {
- temp = TEMP_F_TO_C (temp);
+ temp = TEMP_F_TO_C (temp);
- esat = 6.11 * pow (10.0, (7.5 * temp) / (237.7 + temp));
- esurf = (humidity / 100) * esat;
+ esat = 6.11 * pow (10.0, (7.5 * temp) / (237.7 + temp));
+ esurf = (humidity / 100) * esat;
} else {
- esurf = -1.0;
- esat = 1.0;
+ esurf = -1.0;
+ esat = 1.0;
}
tmp = log10 (esurf / 6.11);
@@ -409,16 +415,16 @@ calc_humidity (gdouble temp, gdouble dewp)
gdouble esat, esurf;
if (temp > -500.0 && dewp > -500.0) {
- temp = TEMP_F_TO_C (temp);
- dewp = TEMP_F_TO_C (dewp);
+ temp = TEMP_F_TO_C (temp);
+ dewp = TEMP_F_TO_C (dewp);
- esat = 6.11 * pow (10.0, (7.5 * temp) / (237.7 + temp));
- esurf = 6.11 * pow (10.0, (7.5 * dewp) / (237.7 + dewp));
+ esat = 6.11 * pow (10.0, (7.5 * temp) / (237.7 + temp));
+ esurf = 6.11 * pow (10.0, (7.5 * dewp) / (237.7 + dewp));
} else {
- esurf = -1.0;
- esat = 1.0;
+ esurf = -1.0;
+ esat = 1.0;
}
- return ((esurf/esat) * 100.0);
+ return ((esurf / esat) * 100.0);
}
static inline gdouble
@@ -431,9 +437,9 @@ calc_apparent (GWeatherInfo *info)
gdouble humidity;
if (info->hasHumidity)
- humidity = info->humidity;
+ humidity = info->humidity;
else
- humidity = calc_humidity (temp, dew);
+ humidity = calc_humidity (temp, dew);
/*
* Wind chill calculations as of 01-Nov-2001
@@ -443,11 +449,11 @@ calc_apparent (GWeatherInfo *info)
*/
if (temp <= 50.0) {
if (wind > 3.0) {
- gdouble v = pow (wind, 0.16);
- apparent = 35.74 + 0.6215 * temp - 35.75 * v + 0.4275 * temp * v;
- } else if (wind >= 0.) {
- apparent = temp;
- }
+ gdouble v = pow (wind, 0.16);
+ apparent = 35.74 + 0.6215 * temp - 35.75 * v + 0.4275 * temp * v;
+ } else if (wind >= 0.) {
+ apparent = temp;
+ }
}
/*
* Heat index calculations:
@@ -455,54 +461,31 @@ calc_apparent (GWeatherInfo *info)
*/
else if (temp >= 80.0) {
if (temp >= -500. && humidity >= 0) {
- gdouble t2, h2;
- gdouble t3, h3;
+ gdouble t2, h2;
+ gdouble t3, h3;
- t2 = temp * temp;
- h2 = humidity * humidity;
+ t2 = temp * temp;
+ h2 = humidity * humidity;
#if 1
- /*
+ /*
* A really precise formula. Note that overall precision is
* constrained by the accuracy of the instruments and that the
* we receive the temperature and dewpoints as integers.
*/
- t3 = t2 * temp;
- h3 = h2 * temp;
-
- apparent = 16.923
- + 0.185212 * temp
- + 5.37941 * humidity
- - 0.100254 * temp * humidity
- + 9.41695e-3 * t2
- + 7.28898e-3 * h2
- + 3.45372e-4 * t2 * humidity
- - 8.14971e-4 * temp * h2
- + 1.02102e-5 * t2 * h2
- - 3.8646e-5 * t3
- + 2.91583e-5 * h3
- + 1.42721e-6 * t3 * humidity
- + 1.97483e-7 * temp * h3
- - 2.18429e-8 * t3 * h2
- + 8.43296e-10 * t2 * h3
- - 4.81975e-11 * t3 * h3;
+ t3 = t2 * temp;
+ h3 = h2 * temp;
+
+ apparent = 16.923 + 0.185212 * temp + 5.37941 * humidity - 0.100254 * temp * humidity +
9.41695e-3 * t2 + 7.28898e-3 * h2 + 3.45372e-4 * t2 * humidity - 8.14971e-4 * temp * h2 + 1.02102e-5 * t2 *
h2 - 3.8646e-5 * t3 + 2.91583e-5 * h3 + 1.42721e-6 * t3 * humidity + 1.97483e-7 * temp * h3 - 2.18429e-8 * t3
* h2 + 8.43296e-10 * t2 * h3 - 4.81975e-11 * t3 * h3;
#else
- /*
+ /*
* An often cited alternative: values are within 5 degrees for
* most ranges between 10% and 70% humidity and to 110 degrees.
*/
- apparent = - 42.379
- + 2.04901523 * temp
- + 10.14333127 * humidity
- - 0.22475541 * temp * humidity
- - 6.83783e-3 * t2
- - 5.481717e-2 * h2
- + 1.22874e-3 * t2 * humidity
- + 8.5282e-4 * temp * h2
- - 1.99e-6 * t2 * h2;
+ apparent = -42.379 + 2.04901523 * temp + 10.14333127 * humidity - 0.22475541 * temp * humidity -
6.83783e-3 * t2 - 5.481717e-2 * h2 + 1.22874e-3 * t2 * humidity + 8.5282e-4 * temp * h2 - 1.99e-6 * t2 * h2;
#endif
- }
+ }
} else {
apparent = temp;
}
@@ -518,7 +501,7 @@ gweather_info_reset (GWeatherInfo *info)
free_forecast_list (info);
info->update = 0;
- info->current_time = time(NULL);
+ info->current_time = time (NULL);
info->sky = -1;
info->cond.significant = FALSE;
info->cond.phenomenon = GWEATHER_PHENOMENON_NONE;
@@ -544,9 +527,9 @@ gweather_info_reset (GWeatherInfo *info)
}
static void
-settings_changed_cb (GSettings *settings,
- const char *key,
- GWeatherInfo *info)
+settings_changed_cb (GSettings *settings,
+ const char *key,
+ GWeatherInfo *info)
{
/* Only emit the signal if no network requests are pending.
Otherwise just wait for the update that will happen at
@@ -562,8 +545,7 @@ gweather_info_init (GWeatherInfo *info)
info->providers = GWEATHER_PROVIDER_METAR | GWEATHER_PROVIDER_IWIN;
info->settings = g_settings_new ("org.gnome.GWeather4");
- g_signal_connect_object (info->settings, "changed",
- G_CALLBACK (settings_changed_cb), info, 0);
+ g_signal_connect_object (info->settings, "changed", G_CALLBACK (settings_changed_cb), info, 0);
gweather_info_reset (info);
}
@@ -575,12 +557,13 @@ get_cache (void)
char *filename;
filename = g_build_filename (g_get_user_cache_dir (),
- "libgweather", NULL);
+ "libgweather",
+ NULL);
if (g_mkdir_with_parents (filename, 0700) < 0) {
- g_warning ("Failed to create libgweather cache directory: %s. Check your XDG_CACHE_HOME setting!",
strerror (errno));
- g_free (filename);
- return NULL;
+ g_warning ("Failed to create libgweather cache directory: %s. Check your XDG_CACHE_HOME setting!",
strerror (errno));
+ g_free (filename);
+ return NULL;
}
cache = soup_cache_new (filename, SOUP_CACHE_SINGLE_USER);
@@ -608,7 +591,7 @@ ref_session (GWeatherInfo *info)
session = static_session;
if (session != NULL)
- return g_object_ref (session);
+ return g_object_ref (session);
session = soup_session_new ();
user_agent = g_strdup_printf ("libgweather/%s %s (%s)",
@@ -619,16 +602,15 @@ ref_session (GWeatherInfo *info)
cache = get_cache ();
if (cache != NULL) {
- soup_session_add_feature (session, SOUP_SESSION_FEATURE (cache));
- g_object_set_data_full (G_OBJECT (session), "libgweather-cache", g_object_ref (cache),
- (GDestroyNotify) dump_and_unref_cache);
+ soup_session_add_feature (session, SOUP_SESSION_FEATURE (cache));
+ g_object_set_data_full (G_OBJECT (session), "libgweather-cache", g_object_ref (cache),
(GDestroyNotify) dump_and_unref_cache);
- soup_cache_load (cache);
- g_object_unref (cache);
+ soup_cache_load (cache);
+ g_object_unref (cache);
}
static_session = session;
- g_object_add_weak_pointer (G_OBJECT (session), (void**) &static_session);
+ g_object_add_weak_pointer (G_OBJECT (session), (void **) &static_session);
return session;
}
@@ -649,7 +631,7 @@ gweather_info_store_cache (void)
SoupCache *cache;
if (static_session == NULL)
- return;
+ return;
cache = g_object_get_data (G_OBJECT (static_session), "libgweather-cache");
soup_cache_dump (cache);
@@ -680,32 +662,32 @@ gweather_info_update (GWeatherInfo *info)
/* Update in progress */
if (!requests_init (info))
- return ;
+ return;
gweather_info_reset (info);
if (!info->session)
- info->session = ref_session (info);
+ info->session = ref_session (info);
if (info->providers & GWEATHER_PROVIDER_METAR)
- metar_start_open (info);
+ metar_start_open (info);
ok = FALSE;
/* Try national forecast services first */
if (info->providers & GWEATHER_PROVIDER_IWIN)
- ok = iwin_start_open (info);
+ ok = iwin_start_open (info);
if (ok)
- return;
+ return;
/* Try met.no next */
if (info->providers & GWEATHER_PROVIDER_MET_NO)
- ok = metno_start_open (info);
+ ok = metno_start_open (info);
if (ok)
- return;
+ return;
/* Try OpenWeatherMap next */
if (info->providers & GWEATHER_PROVIDER_OWM)
- owm_start_open (info);
+ owm_start_open (info);
}
void
@@ -717,8 +699,8 @@ gweather_info_abort (GWeatherInfo *info)
g_return_if_fail (GWEATHER_IS_INFO (info));
if (info->session == NULL) {
- g_assert (info->requests_pending == NULL);
- return;
+ g_assert (info->requests_pending == NULL);
+ return;
}
list = info->requests_pending;
@@ -726,7 +708,7 @@ gweather_info_abort (GWeatherInfo *info)
info->requests_pending = &dummy;
for (iter = list; iter; iter = iter->next)
- soup_session_cancel_message (info->session, iter->data, SOUP_STATUS_CANCELLED);
+ soup_session_cancel_message (info->session, iter->data, SOUP_STATUS_CANCELLED);
g_slist_free (list);
info->requests_pending = NULL;
@@ -757,7 +739,7 @@ gweather_info_finalize (GObject *object)
g_clear_object (&info->settings);
if (info->glocation)
- gweather_location_unref (info->glocation);
+ gweather_location_unref (info->glocation);
g_clear_pointer (&info->application_id, g_free);
g_clear_pointer (&info->contact_info, g_free);
@@ -793,7 +775,7 @@ gweather_info_get_location_name (GWeatherInfo *info)
{
g_return_val_if_fail (GWEATHER_IS_INFO (info), NULL);
- return g_strdup(info->location.name);
+ return g_strdup (info->location.name);
}
gchar *
@@ -807,15 +789,15 @@ gweather_info_get_update (GWeatherInfo *info)
return g_strdup ("-");
if (info->update != 0) {
- GDateTime *now = g_date_time_new_from_unix_local (info->update);
+ GDateTime *now = g_date_time_new_from_unix_local (info->update);
- out = g_date_time_format (now, _("%a, %b %d / %H∶%M"));
- if (!out)
- out = g_strdup ("???");
+ out = g_date_time_format (now, _ ("%a, %b %d / %H∶%M"));
+ if (!out)
+ out = g_strdup ("???");
- g_date_time_unref (now);
+ g_date_time_unref (now);
} else
- out = g_strdup (_("Unknown observation time"));
+ out = g_strdup (_ ("Unknown observation time"));
return out;
}
@@ -825,10 +807,10 @@ gweather_info_get_sky (GWeatherInfo *info)
{
g_return_val_if_fail (GWEATHER_IS_INFO (info), NULL);
if (!info->valid)
- return g_strdup("-");
+ return g_strdup ("-");
if (info->sky < 0)
- return g_strdup(C_("sky conditions", "Unknown"));
- return g_strdup(gweather_sky_to_string (info->sky));
+ return g_strdup (C_ ("sky conditions", "Unknown"));
+ return g_strdup (gweather_sky_to_string (info->sky));
}
gchar *
@@ -836,8 +818,8 @@ gweather_info_get_conditions (GWeatherInfo *info)
{
g_return_val_if_fail (GWEATHER_IS_INFO (info), NULL);
if (!info->valid)
- return g_strdup("-");
- return g_strdup(gweather_conditions_to_string (&info->cond));
+ return g_strdup ("-");
+ return g_strdup (gweather_conditions_to_string (&info->cond));
}
static gboolean
@@ -849,19 +831,19 @@ is_locale_metric (void)
* Do *not* translate it to "predefinito:mm", if it
* it isn't default:mm or default:inch it will not work
*/
- gchar *e = _("default:mm");
+ gchar *e = _ ("default:mm");
#ifdef HAVE__NL_MEASUREMENT_MEASUREMENT
const char *fmt;
fmt = nl_langinfo (_NL_MEASUREMENT_MEASUREMENT);
if (fmt && *fmt == 2)
- return FALSE;
+ return FALSE;
else
- return TRUE;
+ return TRUE;
#endif
- if (strcmp (e, "default:inch")==0)
+ if (strcmp (e, "default:inch") == 0)
return FALSE;
else if (strcmp (e, "default:mm"))
g_warning ("Whoever translated default:mm did so wrongly.\n");
@@ -880,14 +862,12 @@ GWeatherTemperatureUnit
gweather_temperature_unit_to_real (GWeatherTemperatureUnit unit)
{
if (G_UNLIKELY (unit == GWEATHER_TEMP_UNIT_INVALID)) {
- g_critical("Conversion to invalid temperature unit");
- unit = GWEATHER_TEMP_UNIT_DEFAULT;
+ g_critical ("Conversion to invalid temperature unit");
+ unit = GWEATHER_TEMP_UNIT_DEFAULT;
}
if (unit == GWEATHER_TEMP_UNIT_DEFAULT)
- return is_locale_metric() ?
- GWEATHER_TEMP_UNIT_CENTIGRADE :
- GWEATHER_TEMP_UNIT_FAHRENHEIT;
+ return is_locale_metric () ? GWEATHER_TEMP_UNIT_CENTIGRADE : GWEATHER_TEMP_UNIT_FAHRENHEIT;
return unit;
}
@@ -898,43 +878,43 @@ temperature_string (gfloat temp_f, GWeatherTemperatureUnit to_unit, gboolean wan
to_unit = gweather_temperature_unit_to_real (to_unit);
switch (to_unit) {
- case GWEATHER_TEMP_UNIT_FAHRENHEIT:
- if (!want_round) {
- /* TRANSLATOR: This is the temperature in degrees Fahrenheit (U+2109 DEGREE FAHRENHEIT)
+ case GWEATHER_TEMP_UNIT_FAHRENHEIT:
+ if (!want_round) {
+ /* TRANSLATOR: This is the temperature in degrees Fahrenheit (U+2109 DEGREE FAHRENHEIT)
* with a non-break space (U+00A0) between the digits and the degrees sign */
- return g_strdup_printf (_("%.1f\u00A0\u2109"), temp_f);
- } else {
- /* TRANSLATOR: This is the temperature in degrees Fahrenheit (U+2109 DEGREE FAHRENHEIT)i
+ return g_strdup_printf (_ ("%.1f\u00A0\u2109"), temp_f);
+ } else {
+ /* TRANSLATOR: This is the temperature in degrees Fahrenheit (U+2109 DEGREE FAHRENHEIT)i
* with a non-break space (U+00A0) between the digits and the degrees sign */
- return g_strdup_printf (_("%d\u00A0\u2109"), (int)floor (temp_f + 0.5));
- }
- break;
- case GWEATHER_TEMP_UNIT_CENTIGRADE:
- if (!want_round) {
- /* TRANSLATOR: This is the temperature in degrees Celsius (U+2103 DEGREE CELSIUS)
+ return g_strdup_printf (_ ("%d\u00A0\u2109"), (int) floor (temp_f + 0.5));
+ }
+ break;
+ case GWEATHER_TEMP_UNIT_CENTIGRADE:
+ if (!want_round) {
+ /* TRANSLATOR: This is the temperature in degrees Celsius (U+2103 DEGREE CELSIUS)
* with a non-break space (U+00A0) between the digits and the degrees sign */
- return g_strdup_printf (_("%.1f\u00A0\u2103"), TEMP_F_TO_C (temp_f));
- } else {
- /* TRANSLATOR: This is the temperature in degrees Celsius (U+2103 DEGREE CELSIUS)
+ return g_strdup_printf (_ ("%.1f\u00A0\u2103"), TEMP_F_TO_C (temp_f));
+ } else {
+ /* TRANSLATOR: This is the temperature in degrees Celsius (U+2103 DEGREE CELSIUS)
* with a non-break space (U+00A0) between the digits and the degrees sign */
- return g_strdup_printf (_("%d\u00A0\u2103"), (int)floor (TEMP_F_TO_C (temp_f) + 0.5));
- }
- break;
- case GWEATHER_TEMP_UNIT_KELVIN:
- if (!want_round) {
- /* TRANSLATOR: This is the temperature in kelvin (U+212A KELVIN SIGN)
+ return g_strdup_printf (_ ("%d\u00A0\u2103"), (int) floor (TEMP_F_TO_C (temp_f) + 0.5));
+ }
+ break;
+ case GWEATHER_TEMP_UNIT_KELVIN:
+ if (!want_round) {
+ /* TRANSLATOR: This is the temperature in kelvin (U+212A KELVIN SIGN)
* with a non-break space (U+00A0) between the digits and the degrees sign */
- return g_strdup_printf (_("%.1f\u00A0\u212A"), TEMP_F_TO_K (temp_f));
- } else {
- /* TRANSLATOR: This is the temperature in kelvin (U+212A KELVIN SIGN)
+ return g_strdup_printf (_ ("%.1f\u00A0\u212A"), TEMP_F_TO_K (temp_f));
+ } else {
+ /* TRANSLATOR: This is the temperature in kelvin (U+212A KELVIN SIGN)
* with a non-break space (U+00A0) between the digits and the degrees sign */
- return g_strdup_printf (_("%d\u00A0\u212A"), (int)floor (TEMP_F_TO_K (temp_f)));
- }
- break;
+ return g_strdup_printf (_ ("%d\u00A0\u212A"), (int) floor (TEMP_F_TO_K (temp_f)));
+ }
+ break;
- case GWEATHER_TEMP_UNIT_INVALID:
- case GWEATHER_TEMP_UNIT_DEFAULT:
- g_assert_not_reached ();
+ case GWEATHER_TEMP_UNIT_INVALID:
+ case GWEATHER_TEMP_UNIT_DEFAULT:
+ g_assert_not_reached ();
}
return NULL;
@@ -946,9 +926,9 @@ gweather_info_get_temp (GWeatherInfo *info)
g_return_val_if_fail (GWEATHER_IS_INFO (info), NULL);
if (!info->valid)
- return g_strdup("-");
+ return g_strdup ("-");
if (info->temp < -500.0)
- return g_strdup(C_("temperature", "Unknown"));
+ return g_strdup (C_ ("temperature", "Unknown"));
return temperature_string (info->temp, g_settings_get_enum (info->settings, TEMPERATURE_UNIT), FALSE);
}
@@ -959,9 +939,9 @@ gweather_info_get_temp_min (GWeatherInfo *info)
g_return_val_if_fail (GWEATHER_IS_INFO (info), NULL);
if (!info->valid || !info->tempMinMaxValid)
- return g_strdup("-");
+ return g_strdup ("-");
if (info->temp_min < -500.0)
- return g_strdup(C_("temperature", "Unknown"));
+ return g_strdup (C_ ("temperature", "Unknown"));
return temperature_string (info->temp_min, g_settings_get_enum (info->settings, TEMPERATURE_UNIT),
FALSE);
}
@@ -972,9 +952,9 @@ gweather_info_get_temp_max (GWeatherInfo *info)
g_return_val_if_fail (GWEATHER_IS_INFO (info), NULL);
if (!info->valid || !info->tempMinMaxValid)
- return g_strdup("-");
+ return g_strdup ("-");
if (info->temp_max < -500.0)
- return g_strdup(C_("temperature", "Unknown"));
+ return g_strdup (C_ ("temperature", "Unknown"));
return temperature_string (info->temp_max, g_settings_get_enum (info->settings, TEMPERATURE_UNIT),
FALSE);
}
@@ -987,14 +967,14 @@ gweather_info_get_dew (GWeatherInfo *info)
g_return_val_if_fail (GWEATHER_IS_INFO (info), NULL);
if (!info->valid)
- return g_strdup("-");
+ return g_strdup ("-");
if (info->hasHumidity)
- dew = calc_dew (info->temp, info->humidity);
+ dew = calc_dew (info->temp, info->humidity);
else
- dew = info->dew;
+ dew = info->dew;
if (dew < -500.0)
- return g_strdup(C_("dew", "Unknown"));
+ return g_strdup (C_ ("dew", "Unknown"));
return temperature_string (info->dew, g_settings_get_enum (info->settings, TEMPERATURE_UNIT), FALSE);
}
@@ -1007,17 +987,17 @@ gweather_info_get_humidity (GWeatherInfo *info)
g_return_val_if_fail (GWEATHER_IS_INFO (info), NULL);
if (!info->valid)
- return g_strdup("-");
+ return g_strdup ("-");
if (info->hasHumidity)
- humidity = info->humidity;
+ humidity = info->humidity;
else
- humidity = calc_humidity (info->temp, info->dew);
+ humidity = calc_humidity (info->temp, info->dew);
if (humidity < 0.0)
- return g_strdup(C_("humidity", "Unknown"));
+ return g_strdup (C_ ("humidity", "Unknown"));
/* TRANSLATOR: This is the humidity in percent */
- return g_strdup_printf(_("%.f%%"), humidity);
+ return g_strdup_printf (_ ("%.f%%"), humidity);
}
gchar *
@@ -1028,11 +1008,11 @@ gweather_info_get_apparent (GWeatherInfo *info)
g_return_val_if_fail (GWEATHER_IS_INFO (info), NULL);
if (!info->valid)
- return g_strdup("-");
+ return g_strdup ("-");
apparent = calc_apparent (info);
if (apparent < -500.0)
- return g_strdup(C_("temperature", "Unknown"));
+ return g_strdup (C_ ("temperature", "Unknown"));
return temperature_string (apparent, g_settings_get_enum (info->settings, TEMPERATURE_UNIT), FALSE);
}
@@ -1041,14 +1021,12 @@ static GWeatherSpeedUnit
speed_unit_to_real (GWeatherSpeedUnit unit)
{
if (G_UNLIKELY (unit == GWEATHER_SPEED_UNIT_INVALID)) {
- g_critical("Conversion to invalid speed unit");
- unit = GWEATHER_SPEED_UNIT_DEFAULT;
+ g_critical ("Conversion to invalid speed unit");
+ unit = GWEATHER_SPEED_UNIT_DEFAULT;
}
if (unit == GWEATHER_SPEED_UNIT_DEFAULT)
- return is_locale_metric() ?
- GWEATHER_SPEED_UNIT_KPH :
- GWEATHER_SPEED_UNIT_MPH;
+ return is_locale_metric () ? GWEATHER_SPEED_UNIT_KPH : GWEATHER_SPEED_UNIT_MPH;
return unit;
}
@@ -1059,26 +1037,26 @@ windspeed_string (gfloat knots, GWeatherSpeedUnit to_unit)
to_unit = speed_unit_to_real (to_unit);
switch (to_unit) {
- case GWEATHER_SPEED_UNIT_KNOTS:
- /* TRANSLATOR: This is the wind speed in knots */
- return g_strdup_printf(_("%0.1f knots"), knots);
- case GWEATHER_SPEED_UNIT_MPH:
- /* TRANSLATOR: This is the wind speed in miles per hour */
- return g_strdup_printf(_("%.1f mph"), WINDSPEED_KNOTS_TO_MPH (knots));
- case GWEATHER_SPEED_UNIT_KPH:
- /* TRANSLATOR: This is the wind speed in kilometers per hour */
- return g_strdup_printf(_("%.1f km/h"), WINDSPEED_KNOTS_TO_KPH (knots));
- case GWEATHER_SPEED_UNIT_MS:
- /* TRANSLATOR: This is the wind speed in meters per second */
- return g_strdup_printf(_("%.1f m/s"), WINDSPEED_KNOTS_TO_MS (knots));
- case GWEATHER_SPEED_UNIT_BFT:
- /* TRANSLATOR: This is the wind speed as a Beaufort force factor
+ case GWEATHER_SPEED_UNIT_KNOTS:
+ /* TRANSLATOR: This is the wind speed in knots */
+ return g_strdup_printf (_ ("%0.1f knots"), knots);
+ case GWEATHER_SPEED_UNIT_MPH:
+ /* TRANSLATOR: This is the wind speed in miles per hour */
+ return g_strdup_printf (_ ("%.1f mph"), WINDSPEED_KNOTS_TO_MPH (knots));
+ case GWEATHER_SPEED_UNIT_KPH:
+ /* TRANSLATOR: This is the wind speed in kilometers per hour */
+ return g_strdup_printf (_ ("%.1f km/h"), WINDSPEED_KNOTS_TO_KPH (knots));
+ case GWEATHER_SPEED_UNIT_MS:
+ /* TRANSLATOR: This is the wind speed in meters per second */
+ return g_strdup_printf (_ ("%.1f m/s"), WINDSPEED_KNOTS_TO_MS (knots));
+ case GWEATHER_SPEED_UNIT_BFT:
+ /* TRANSLATOR: This is the wind speed as a Beaufort force factor
* (commonly used in nautical wind estimation).
*/
- return g_strdup_printf(_("Beaufort force %.1f"), WINDSPEED_KNOTS_TO_BFT (knots));
- case GWEATHER_SPEED_UNIT_INVALID:
- case GWEATHER_SPEED_UNIT_DEFAULT:
- g_assert_not_reached ();
+ return g_strdup_printf (_ ("Beaufort force %.1f"), WINDSPEED_KNOTS_TO_BFT (knots));
+ case GWEATHER_SPEED_UNIT_INVALID:
+ case GWEATHER_SPEED_UNIT_DEFAULT:
+ g_assert_not_reached ();
}
return NULL;
@@ -1090,22 +1068,22 @@ gweather_info_get_wind (GWeatherInfo *info)
g_return_val_if_fail (GWEATHER_IS_INFO (info), NULL);
if (!info->valid)
- return g_strdup("-");
+ return g_strdup ("-");
if (info->windspeed < 0.0 || info->wind < 0)
- return g_strdup(C_("wind speed", "Unknown"));
+ return g_strdup (C_ ("wind speed", "Unknown"));
if (info->windspeed == 0.00) {
- return g_strdup(_("Calm"));
+ return g_strdup (_ ("Calm"));
} else {
- gchar *speed_string;
- gchar *wind_string;
+ gchar *speed_string;
+ gchar *wind_string;
- speed_string = windspeed_string (info->windspeed, g_settings_get_enum (info->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 (info->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;
+ g_free (speed_string);
+ return wind_string;
}
}
@@ -1121,26 +1099,26 @@ gweather_speed_unit_to_string (GWeatherSpeedUnit unit)
unit = speed_unit_to_real (unit);
switch (unit) {
- case GWEATHER_SPEED_UNIT_KNOTS:
- /* TRANSLATOR: This is the wind speed in knots */
- return _("knots");
- case GWEATHER_SPEED_UNIT_MPH:
- /* TRANSLATOR: This is the wind speed in miles per hour */
- return _("mph");
- case GWEATHER_SPEED_UNIT_KPH:
- /* TRANSLATOR: This is the wind speed in kilometers per hour */
- return _("km/h");
- case GWEATHER_SPEED_UNIT_MS:
- /* TRANSLATOR: This is the wind speed in meters per second */
- return _("m/s");
- case GWEATHER_SPEED_UNIT_BFT:
- /* TRANSLATOR: This is the wind speed as a Beaufort force factor
+ case GWEATHER_SPEED_UNIT_KNOTS:
+ /* TRANSLATOR: This is the wind speed in knots */
+ return _ ("knots");
+ case GWEATHER_SPEED_UNIT_MPH:
+ /* TRANSLATOR: This is the wind speed in miles per hour */
+ return _ ("mph");
+ case GWEATHER_SPEED_UNIT_KPH:
+ /* TRANSLATOR: This is the wind speed in kilometers per hour */
+ return _ ("km/h");
+ case GWEATHER_SPEED_UNIT_MS:
+ /* TRANSLATOR: This is the wind speed in meters per second */
+ return _ ("m/s");
+ case GWEATHER_SPEED_UNIT_BFT:
+ /* TRANSLATOR: This is the wind speed as a Beaufort force factor
* (commonly used in nautical wind estimation).
*/
- return _("Beaufort force");
- case GWEATHER_SPEED_UNIT_INVALID:
- case GWEATHER_SPEED_UNIT_DEFAULT:
- g_assert_not_reached ();
+ return _ ("Beaufort force");
+ case GWEATHER_SPEED_UNIT_INVALID:
+ case GWEATHER_SPEED_UNIT_DEFAULT:
+ g_assert_not_reached ();
}
return NULL;
@@ -1150,14 +1128,12 @@ static GWeatherPressureUnit
pressure_unit_to_real (GWeatherPressureUnit unit)
{
if (G_UNLIKELY (unit == GWEATHER_PRESSURE_UNIT_INVALID)) {
- g_critical("Conversion to invalid pressure unit");
- unit = GWEATHER_PRESSURE_UNIT_DEFAULT;
+ g_critical ("Conversion to invalid pressure unit");
+ unit = GWEATHER_PRESSURE_UNIT_DEFAULT;
}
if (unit == GWEATHER_PRESSURE_UNIT_DEFAULT)
- return is_locale_metric() ?
- GWEATHER_PRESSURE_UNIT_MM_HG :
- GWEATHER_PRESSURE_UNIT_INCH_HG;
+ return is_locale_metric () ? GWEATHER_PRESSURE_UNIT_MM_HG : GWEATHER_PRESSURE_UNIT_INCH_HG;
return unit;
}
@@ -1170,34 +1146,34 @@ gweather_info_get_pressure (GWeatherInfo *info)
g_return_val_if_fail (GWEATHER_IS_INFO (info), NULL);
if (!info->valid)
- return g_strdup("-");
+ return g_strdup ("-");
if (info->pressure < 0.0)
- return g_strdup(C_("pressure", "Unknown"));
+ return g_strdup (C_ ("pressure", "Unknown"));
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"), 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 (info->pressure));
- case GWEATHER_PRESSURE_UNIT_KPA:
- /* TRANSLATOR: This is pressure in kiloPascals */
- 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 (info->pressure));
- case GWEATHER_PRESSURE_UNIT_MB:
- /* TRANSLATOR: This is pressure in millibars */
- 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 (info->pressure));
-
- case GWEATHER_PRESSURE_UNIT_INVALID:
- case GWEATHER_PRESSURE_UNIT_DEFAULT:
- g_assert_not_reached ();
+ case GWEATHER_PRESSURE_UNIT_INCH_HG:
+ /* TRANSLATOR: This is pressure in inches of mercury */
+ 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 (info->pressure));
+ case GWEATHER_PRESSURE_UNIT_KPA:
+ /* TRANSLATOR: This is pressure in kiloPascals */
+ 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 (info->pressure));
+ case GWEATHER_PRESSURE_UNIT_MB:
+ /* TRANSLATOR: This is pressure in millibars */
+ 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 (info->pressure));
+
+ case GWEATHER_PRESSURE_UNIT_INVALID:
+ case GWEATHER_PRESSURE_UNIT_DEFAULT:
+ g_assert_not_reached ();
}
return NULL;
@@ -1207,14 +1183,12 @@ static GWeatherDistanceUnit
distance_unit_to_real (GWeatherDistanceUnit unit)
{
if (G_UNLIKELY (unit == GWEATHER_DISTANCE_UNIT_INVALID)) {
- g_critical("Conversion to invalid distance unit");
- unit = GWEATHER_DISTANCE_UNIT_DEFAULT;
+ g_critical ("Conversion to invalid distance unit");
+ unit = GWEATHER_DISTANCE_UNIT_DEFAULT;
}
if (unit == GWEATHER_DISTANCE_UNIT_DEFAULT)
- return is_locale_metric() ?
- GWEATHER_DISTANCE_UNIT_METERS :
- GWEATHER_DISTANCE_UNIT_MILES;
+ return is_locale_metric () ? GWEATHER_DISTANCE_UNIT_METERS : GWEATHER_DISTANCE_UNIT_MILES;
return unit;
}
@@ -1229,23 +1203,23 @@ gweather_info_get_visibility (GWeatherInfo *info)
if (!info->valid)
return g_strdup ("-");
if (info->visibility < 0.0)
- return g_strdup (C_("visibility", "Unknown"));
+ return g_strdup (C_ ("visibility", "Unknown"));
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"), info->visibility);
- case GWEATHER_DISTANCE_UNIT_KM:
- /* TRANSLATOR: This is the visibility in kilometers */
- 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 (info->visibility));
-
- case GWEATHER_DISTANCE_UNIT_INVALID:
- case GWEATHER_DISTANCE_UNIT_DEFAULT:
- g_assert_not_reached ();
+ case GWEATHER_DISTANCE_UNIT_MILES:
+ /* TRANSLATOR: This is the visibility in miles */
+ 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 (info->visibility));
+ case GWEATHER_DISTANCE_UNIT_METERS:
+ /* TRANSLATOR: This is the visibility in meters */
+ return g_strdup_printf (_ ("%.0fm"), VISIBILITY_SM_TO_M (info->visibility));
+
+ case GWEATHER_DISTANCE_UNIT_INVALID:
+ case GWEATHER_DISTANCE_UNIT_DEFAULT:
+ g_assert_not_reached ();
}
return NULL;
@@ -1266,7 +1240,7 @@ gweather_info_get_sunrise (GWeatherInfo *info)
sunrise = g_date_time_new_from_unix_local (info->sunrise);
- buf = g_date_time_format (sunrise, _("%H∶%M"));
+ buf = g_date_time_format (sunrise, _ ("%H∶%M"));
if (!buf)
buf = g_strdup ("-");
@@ -1288,7 +1262,7 @@ gweather_info_get_sunset (GWeatherInfo *info)
return g_strdup ("-");
sunset = g_date_time_new_from_unix_local (info->sunset);
- buf = g_date_time_format (sunset, _("%H∶%M"));
+ buf = g_date_time_format (sunset, _ ("%H∶%M"));
if (!buf)
buf = g_strdup ("-");
@@ -1312,7 +1286,7 @@ gweather_info_get_forecast_list (GWeatherInfo *info)
g_return_val_if_fail (GWEATHER_IS_INFO (info), NULL);
if (!info->valid)
- return NULL;
+ return NULL;
return info->forecast_list;
}
@@ -1363,10 +1337,10 @@ gweather_info_get_weather_summary (GWeatherInfo *info)
g_return_val_if_fail (GWEATHER_IS_INFO (info), NULL);
if (!info->valid)
- return g_strdup (_("Retrieval failed"));
+ return g_strdup (_ ("Retrieval failed"));
buf = gweather_info_get_conditions (info);
if (g_str_equal (buf, "-")) {
- g_free (buf);
+ g_free (buf);
buf = gweather_info_get_sky (info);
}
@@ -1398,21 +1372,21 @@ gweather_info_is_daytime (GWeatherInfo *info)
_gweather_info_ensure_sun (info);
if (info->polarNight)
- return FALSE;
+ return FALSE;
if (info->midnightSun)
- return TRUE;
+ return TRUE;
current_time = info->current_time;
- return ( !info->sunriseValid || (current_time >= info->sunrise) ) &&
- ( !info->sunsetValid || (current_time < info->sunset) );
+ return (!info->sunriseValid || (current_time >= info->sunrise)) &&
+ (!info->sunsetValid || (current_time < info->sunset));
}
const gchar *
gweather_info_get_icon_name (GWeatherInfo *info)
{
- GWeatherConditions cond;
- GWeatherSky sky;
- gboolean daytime;
+ GWeatherConditions cond;
+ GWeatherSky sky;
+ gboolean daytime;
g_return_val_if_fail (GWEATHER_IS_INFO (info), NULL);
@@ -1420,82 +1394,82 @@ gweather_info_get_icon_name (GWeatherInfo *info)
sky = info->sky;
if (cond.significant) {
- if (cond.phenomenon != GWEATHER_PHENOMENON_NONE &&
- cond.qualifier == GWEATHER_QUALIFIER_THUNDERSTORM)
+ if (cond.phenomenon != GWEATHER_PHENOMENON_NONE &&
+ cond.qualifier == GWEATHER_QUALIFIER_THUNDERSTORM)
return "weather-storm";
switch (cond.phenomenon) {
- case GWEATHER_PHENOMENON_INVALID:
- case GWEATHER_PHENOMENON_LAST:
- case GWEATHER_PHENOMENON_NONE:
- break;
-
- case GWEATHER_PHENOMENON_DRIZZLE:
- case GWEATHER_PHENOMENON_RAIN:
- case GWEATHER_PHENOMENON_UNKNOWN_PRECIPITATION:
- case GWEATHER_PHENOMENON_HAIL:
- case GWEATHER_PHENOMENON_SMALL_HAIL:
- return "weather-showers";
-
- case GWEATHER_PHENOMENON_SNOW:
- case GWEATHER_PHENOMENON_SNOW_GRAINS:
- case GWEATHER_PHENOMENON_ICE_PELLETS:
- case GWEATHER_PHENOMENON_ICE_CRYSTALS:
- return "weather-snow";
-
- case GWEATHER_PHENOMENON_TORNADO:
- case GWEATHER_PHENOMENON_SQUALL:
- return "weather-storm";
-
- case GWEATHER_PHENOMENON_MIST:
- case GWEATHER_PHENOMENON_FOG:
- case GWEATHER_PHENOMENON_SMOKE:
- case GWEATHER_PHENOMENON_VOLCANIC_ASH:
- case GWEATHER_PHENOMENON_SAND:
- case GWEATHER_PHENOMENON_HAZE:
- case GWEATHER_PHENOMENON_SPRAY:
- case GWEATHER_PHENOMENON_DUST:
- case GWEATHER_PHENOMENON_SANDSTORM:
- case GWEATHER_PHENOMENON_DUSTSTORM:
- case GWEATHER_PHENOMENON_FUNNEL_CLOUD:
- case GWEATHER_PHENOMENON_DUST_WHIRLS:
- return "weather-fog";
+ case GWEATHER_PHENOMENON_INVALID:
+ case GWEATHER_PHENOMENON_LAST:
+ case GWEATHER_PHENOMENON_NONE:
+ break;
+
+ case GWEATHER_PHENOMENON_DRIZZLE:
+ case GWEATHER_PHENOMENON_RAIN:
+ case GWEATHER_PHENOMENON_UNKNOWN_PRECIPITATION:
+ case GWEATHER_PHENOMENON_HAIL:
+ case GWEATHER_PHENOMENON_SMALL_HAIL:
+ return "weather-showers";
+
+ case GWEATHER_PHENOMENON_SNOW:
+ case GWEATHER_PHENOMENON_SNOW_GRAINS:
+ case GWEATHER_PHENOMENON_ICE_PELLETS:
+ case GWEATHER_PHENOMENON_ICE_CRYSTALS:
+ return "weather-snow";
+
+ case GWEATHER_PHENOMENON_TORNADO:
+ case GWEATHER_PHENOMENON_SQUALL:
+ return "weather-storm";
+
+ case GWEATHER_PHENOMENON_MIST:
+ case GWEATHER_PHENOMENON_FOG:
+ case GWEATHER_PHENOMENON_SMOKE:
+ case GWEATHER_PHENOMENON_VOLCANIC_ASH:
+ case GWEATHER_PHENOMENON_SAND:
+ case GWEATHER_PHENOMENON_HAZE:
+ case GWEATHER_PHENOMENON_SPRAY:
+ case GWEATHER_PHENOMENON_DUST:
+ case GWEATHER_PHENOMENON_SANDSTORM:
+ case GWEATHER_PHENOMENON_DUSTSTORM:
+ case GWEATHER_PHENOMENON_FUNNEL_CLOUD:
+ case GWEATHER_PHENOMENON_DUST_WHIRLS:
+ return "weather-fog";
}
}
daytime = gweather_info_is_daytime (info);
switch (sky) {
- case GWEATHER_SKY_INVALID:
- case GWEATHER_SKY_LAST:
- case GWEATHER_SKY_CLEAR:
- if (daytime)
- return "weather-clear";
- else
- return "weather-clear-night";
-
- case GWEATHER_SKY_BROKEN:
- case GWEATHER_SKY_SCATTERED:
- case GWEATHER_SKY_FEW:
- if (daytime)
- return "weather-few-clouds";
- else
- return "weather-few-clouds-night";
-
- case GWEATHER_SKY_OVERCAST:
- return "weather-overcast";
-
- default: /* unrecognized */
- return NULL;
+ case GWEATHER_SKY_INVALID:
+ case GWEATHER_SKY_LAST:
+ case GWEATHER_SKY_CLEAR:
+ if (daytime)
+ return "weather-clear";
+ else
+ return "weather-clear-night";
+
+ case GWEATHER_SKY_BROKEN:
+ case GWEATHER_SKY_SCATTERED:
+ case GWEATHER_SKY_FEW:
+ if (daytime)
+ return "weather-few-clouds";
+ else
+ return "weather-few-clouds-night";
+
+ case GWEATHER_SKY_OVERCAST:
+ return "weather-overcast";
+
+ default: /* unrecognized */
+ return NULL;
}
}
const gchar *
gweather_info_get_symbolic_icon_name (GWeatherInfo *info)
{
- GWeatherConditions cond;
- GWeatherSky sky;
- gboolean daytime;
+ GWeatherConditions cond;
+ GWeatherSky sky;
+ gboolean daytime;
g_return_val_if_fail (GWEATHER_IS_INFO (info), NULL);
@@ -1503,210 +1477,210 @@ gweather_info_get_symbolic_icon_name (GWeatherInfo *info)
sky = info->sky;
if (cond.significant) {
- if (cond.phenomenon != GWEATHER_PHENOMENON_NONE &&
- cond.qualifier == GWEATHER_QUALIFIER_THUNDERSTORM)
+ if (cond.phenomenon != GWEATHER_PHENOMENON_NONE &&
+ cond.qualifier == GWEATHER_QUALIFIER_THUNDERSTORM)
return "weather-storm-symbolic";
switch (cond.phenomenon) {
- case GWEATHER_PHENOMENON_INVALID:
- case GWEATHER_PHENOMENON_LAST:
- case GWEATHER_PHENOMENON_NONE:
- break;
-
- case GWEATHER_PHENOMENON_DRIZZLE:
- case GWEATHER_PHENOMENON_RAIN:
- case GWEATHER_PHENOMENON_UNKNOWN_PRECIPITATION:
- case GWEATHER_PHENOMENON_HAIL:
- case GWEATHER_PHENOMENON_SMALL_HAIL:
- return "weather-showers-symbolic";
-
- case GWEATHER_PHENOMENON_SNOW:
- case GWEATHER_PHENOMENON_SNOW_GRAINS:
- case GWEATHER_PHENOMENON_ICE_PELLETS:
- case GWEATHER_PHENOMENON_ICE_CRYSTALS:
- return "weather-snow-symbolic";
-
- case GWEATHER_PHENOMENON_TORNADO:
- case GWEATHER_PHENOMENON_SQUALL:
- return "weather-storm-symbolic";
-
- case GWEATHER_PHENOMENON_MIST:
- case GWEATHER_PHENOMENON_FOG:
- case GWEATHER_PHENOMENON_SMOKE:
- case GWEATHER_PHENOMENON_VOLCANIC_ASH:
- case GWEATHER_PHENOMENON_SAND:
- case GWEATHER_PHENOMENON_HAZE:
- case GWEATHER_PHENOMENON_SPRAY:
- case GWEATHER_PHENOMENON_DUST:
- case GWEATHER_PHENOMENON_SANDSTORM:
- case GWEATHER_PHENOMENON_DUSTSTORM:
- case GWEATHER_PHENOMENON_FUNNEL_CLOUD:
- case GWEATHER_PHENOMENON_DUST_WHIRLS:
- return "weather-fog-symbolic";
+ case GWEATHER_PHENOMENON_INVALID:
+ case GWEATHER_PHENOMENON_LAST:
+ case GWEATHER_PHENOMENON_NONE:
+ break;
+
+ case GWEATHER_PHENOMENON_DRIZZLE:
+ case GWEATHER_PHENOMENON_RAIN:
+ case GWEATHER_PHENOMENON_UNKNOWN_PRECIPITATION:
+ case GWEATHER_PHENOMENON_HAIL:
+ case GWEATHER_PHENOMENON_SMALL_HAIL:
+ return "weather-showers-symbolic";
+
+ case GWEATHER_PHENOMENON_SNOW:
+ case GWEATHER_PHENOMENON_SNOW_GRAINS:
+ case GWEATHER_PHENOMENON_ICE_PELLETS:
+ case GWEATHER_PHENOMENON_ICE_CRYSTALS:
+ return "weather-snow-symbolic";
+
+ case GWEATHER_PHENOMENON_TORNADO:
+ case GWEATHER_PHENOMENON_SQUALL:
+ return "weather-storm-symbolic";
+
+ case GWEATHER_PHENOMENON_MIST:
+ case GWEATHER_PHENOMENON_FOG:
+ case GWEATHER_PHENOMENON_SMOKE:
+ case GWEATHER_PHENOMENON_VOLCANIC_ASH:
+ case GWEATHER_PHENOMENON_SAND:
+ case GWEATHER_PHENOMENON_HAZE:
+ case GWEATHER_PHENOMENON_SPRAY:
+ case GWEATHER_PHENOMENON_DUST:
+ case GWEATHER_PHENOMENON_SANDSTORM:
+ case GWEATHER_PHENOMENON_DUSTSTORM:
+ case GWEATHER_PHENOMENON_FUNNEL_CLOUD:
+ case GWEATHER_PHENOMENON_DUST_WHIRLS:
+ return "weather-fog-symbolic";
}
}
daytime = gweather_info_is_daytime (info);
switch (sky) {
- case GWEATHER_SKY_INVALID:
- case GWEATHER_SKY_LAST:
- case GWEATHER_SKY_CLEAR:
- if (daytime)
- return "weather-clear-symbolic";
- else
- return "weather-clear-night-symbolic";
-
- case GWEATHER_SKY_BROKEN:
- case GWEATHER_SKY_SCATTERED:
- case GWEATHER_SKY_FEW:
- if (daytime)
- return "weather-few-clouds-symbolic";
- else
- return "weather-few-clouds-night-symbolic";
-
- case GWEATHER_SKY_OVERCAST:
- return "weather-overcast-symbolic";
-
- default: /* unrecognized */
- return NULL;
+ case GWEATHER_SKY_INVALID:
+ case GWEATHER_SKY_LAST:
+ case GWEATHER_SKY_CLEAR:
+ if (daytime)
+ return "weather-clear-symbolic";
+ else
+ return "weather-clear-night-symbolic";
+
+ case GWEATHER_SKY_BROKEN:
+ case GWEATHER_SKY_SCATTERED:
+ case GWEATHER_SKY_FEW:
+ if (daytime)
+ return "weather-few-clouds-symbolic";
+ else
+ return "weather-few-clouds-night-symbolic";
+
+ case GWEATHER_SKY_OVERCAST:
+ return "weather-overcast-symbolic";
+
+ default: /* unrecognized */
+ return NULL;
}
}
static gboolean
temperature_value (gdouble temp_f,
- GWeatherTemperatureUnit to_unit,
- gdouble *value,
- GSettings *settings)
+ GWeatherTemperatureUnit to_unit,
+ gdouble *value,
+ GSettings *settings)
{
gboolean ok = TRUE;
*value = 0.0;
if (temp_f < -500.0)
- return FALSE;
+ return FALSE;
if (to_unit == GWEATHER_TEMP_UNIT_DEFAULT)
- to_unit = g_settings_get_enum (settings, TEMPERATURE_UNIT);
+ to_unit = g_settings_get_enum (settings, TEMPERATURE_UNIT);
to_unit = gweather_temperature_unit_to_real (to_unit);
switch (to_unit) {
case GWEATHER_TEMP_UNIT_FAHRENHEIT:
- *value = temp_f;
- break;
+ *value = temp_f;
+ break;
case GWEATHER_TEMP_UNIT_CENTIGRADE:
- *value = TEMP_F_TO_C (temp_f);
- break;
+ *value = TEMP_F_TO_C (temp_f);
+ break;
case GWEATHER_TEMP_UNIT_KELVIN:
- *value = TEMP_F_TO_K (temp_f);
- break;
+ *value = TEMP_F_TO_K (temp_f);
+ break;
case GWEATHER_TEMP_UNIT_INVALID:
case GWEATHER_TEMP_UNIT_DEFAULT:
- g_assert_not_reached ();
+ g_assert_not_reached ();
}
return ok;
}
static gboolean
-speed_value (gdouble knots,
- GWeatherSpeedUnit to_unit,
- gdouble *value,
- GSettings *settings)
+speed_value (gdouble knots,
+ GWeatherSpeedUnit to_unit,
+ gdouble *value,
+ GSettings *settings)
{
gboolean ok = TRUE;
*value = -1.0;
if (knots < 0.0)
- return FALSE;
+ return FALSE;
if (to_unit == GWEATHER_SPEED_UNIT_DEFAULT)
- to_unit = g_settings_get_enum (settings, SPEED_UNIT);
+ to_unit = g_settings_get_enum (settings, SPEED_UNIT);
to_unit = speed_unit_to_real (to_unit);
switch (to_unit) {
case GWEATHER_SPEED_UNIT_KNOTS:
*value = knots;
- break;
+ break;
case GWEATHER_SPEED_UNIT_MPH:
*value = WINDSPEED_KNOTS_TO_MPH (knots);
- break;
+ break;
case GWEATHER_SPEED_UNIT_KPH:
*value = WINDSPEED_KNOTS_TO_KPH (knots);
- break;
+ break;
case GWEATHER_SPEED_UNIT_MS:
*value = WINDSPEED_KNOTS_TO_MS (knots);
- break;
- case GWEATHER_SPEED_UNIT_BFT:
- *value = WINDSPEED_KNOTS_TO_BFT (knots);
- break;
+ break;
+ case GWEATHER_SPEED_UNIT_BFT:
+ *value = WINDSPEED_KNOTS_TO_BFT (knots);
+ break;
case GWEATHER_SPEED_UNIT_INVALID:
case GWEATHER_SPEED_UNIT_DEFAULT:
- g_assert_not_reached ();
+ g_assert_not_reached ();
}
return ok;
}
static gboolean
-pressure_value (gdouble inHg,
- GWeatherPressureUnit to_unit,
- gdouble *value,
- GSettings *settings)
+pressure_value (gdouble inHg,
+ GWeatherPressureUnit to_unit,
+ gdouble *value,
+ GSettings *settings)
{
gboolean ok = TRUE;
*value = -1.0;
if (inHg < 0.0)
- return FALSE;
+ return FALSE;
if (to_unit == GWEATHER_PRESSURE_UNIT_DEFAULT)
- to_unit = g_settings_get_enum (settings, PRESSURE_UNIT);
+ to_unit = g_settings_get_enum (settings, PRESSURE_UNIT);
to_unit = pressure_unit_to_real (to_unit);
switch (to_unit) {
case GWEATHER_PRESSURE_UNIT_INCH_HG:
*value = inHg;
- break;
+ break;
case GWEATHER_PRESSURE_UNIT_MM_HG:
*value = PRESSURE_INCH_TO_MM (inHg);
- break;
+ break;
case GWEATHER_PRESSURE_UNIT_KPA:
*value = PRESSURE_INCH_TO_KPA (inHg);
- break;
+ break;
case GWEATHER_PRESSURE_UNIT_HPA:
*value = PRESSURE_INCH_TO_HPA (inHg);
- break;
+ break;
case GWEATHER_PRESSURE_UNIT_MB:
*value = PRESSURE_INCH_TO_MB (inHg);
- break;
+ break;
case GWEATHER_PRESSURE_UNIT_ATM:
*value = PRESSURE_INCH_TO_ATM (inHg);
- break;
+ break;
case GWEATHER_PRESSURE_UNIT_INVALID:
case GWEATHER_PRESSURE_UNIT_DEFAULT:
- g_assert_not_reached ();
+ g_assert_not_reached ();
}
return ok;
}
static gboolean
-distance_value (gdouble miles,
- GWeatherDistanceUnit to_unit,
- gdouble *value,
- GSettings *settings)
+distance_value (gdouble miles,
+ GWeatherDistanceUnit to_unit,
+ gdouble *value,
+ GSettings *settings)
{
gboolean ok = TRUE;
*value = -1.0;
if (miles < 0.0)
- return FALSE;
+ return FALSE;
if (to_unit == GWEATHER_DISTANCE_UNIT_DEFAULT)
- to_unit = g_settings_get_enum (settings, DISTANCE_UNIT);
+ to_unit = g_settings_get_enum (settings, DISTANCE_UNIT);
to_unit = distance_unit_to_real (to_unit);
switch (to_unit) {
@@ -1721,7 +1695,7 @@ distance_value (gdouble miles,
break;
case GWEATHER_DISTANCE_UNIT_INVALID:
case GWEATHER_DISTANCE_UNIT_DEFAULT:
- g_assert_not_reached ();
+ g_assert_not_reached ();
}
return ok;
@@ -1742,10 +1716,10 @@ gweather_info_get_value_sky (GWeatherInfo *info, GWeatherSky *sky)
g_return_val_if_fail (sky != NULL, FALSE);
if (!info->valid)
- return FALSE;
+ return FALSE;
if (info->sky <= GWEATHER_SKY_INVALID || info->sky >= GWEATHER_SKY_LAST)
- return FALSE;
+ return FALSE;
*sky = info->sky;
@@ -1769,15 +1743,15 @@ gweather_info_get_value_conditions (GWeatherInfo *info, GWeatherConditionPhenome
g_return_val_if_fail (qualifier != NULL, FALSE);
if (!info->valid)
- return FALSE;
+ return FALSE;
if (!info->cond.significant)
- return FALSE;
+ return FALSE;
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))
+ info->cond.phenomenon < GWEATHER_PHENOMENON_LAST &&
+ info->cond.qualifier > GWEATHER_QUALIFIER_INVALID &&
+ info->cond.qualifier < GWEATHER_QUALIFIER_LAST))
return FALSE;
*phenomenon = info->cond.phenomenon;
@@ -1801,7 +1775,7 @@ gweather_info_get_value_temp (GWeatherInfo *info, GWeatherTemperatureUnit unit,
g_return_val_if_fail (value != NULL, FALSE);
if (!info->valid)
- return FALSE;
+ return FALSE;
return temperature_value (info->temp, unit, value, info->settings);
}
@@ -1821,7 +1795,7 @@ gweather_info_get_value_temp_min (GWeatherInfo *info, GWeatherTemperatureUnit un
g_return_val_if_fail (value != NULL, FALSE);
if (!info->valid || !info->tempMinMaxValid)
- return FALSE;
+ return FALSE;
return temperature_value (info->temp_min, unit, value, info->settings);
}
@@ -1841,7 +1815,7 @@ gweather_info_get_value_temp_max (GWeatherInfo *info, GWeatherTemperatureUnit un
g_return_val_if_fail (value != NULL, FALSE);
if (!info->valid || !info->tempMinMaxValid)
- return FALSE;
+ return FALSE;
return temperature_value (info->temp_max, unit, value, info->settings);
}
@@ -1863,12 +1837,12 @@ gweather_info_get_value_dew (GWeatherInfo *info, GWeatherTemperatureUnit unit, g
g_return_val_if_fail (value != NULL, FALSE);
if (!info->valid)
- return FALSE;
+ return FALSE;
if (info->hasHumidity)
- dew = calc_dew (info->temp, info->humidity);
+ dew = calc_dew (info->temp, info->humidity);
else
- dew = info->dew;
+ dew = info->dew;
return temperature_value (dew, unit, value, info->settings);
}
@@ -1888,7 +1862,7 @@ gweather_info_get_value_apparent (GWeatherInfo *info, GWeatherTemperatureUnit un
g_return_val_if_fail (value != NULL, FALSE);
if (!info->valid)
- return FALSE;
+ return FALSE;
return temperature_value (calc_apparent (info), unit, value, info->settings);
}
@@ -1909,7 +1883,7 @@ gweather_info_get_value_update (GWeatherInfo *info, time_t *value)
g_return_val_if_fail (value != NULL, FALSE);
if (!info->valid)
- return FALSE;
+ return FALSE;
*value = info->update;
@@ -1932,7 +1906,7 @@ gweather_info_get_value_sunrise (GWeatherInfo *info, time_t *value)
_gweather_info_ensure_sun (info);
if (!info->sunriseValid)
- return FALSE;
+ return FALSE;
*value = info->sunrise;
@@ -1955,7 +1929,7 @@ gweather_info_get_value_sunset (GWeatherInfo *info, time_t *value)
_gweather_info_ensure_sun (info);
if (!info->sunsetValid)
- return FALSE;
+ return FALSE;
*value = info->sunset;
@@ -1971,9 +1945,9 @@ gweather_info_get_value_sunset (GWeatherInfo *info, time_t *value)
* Returns: TRUE is @value is valid, FALSE otherwise.
*/
gboolean
-gweather_info_get_value_moonphase (GWeatherInfo *info,
- GWeatherMoonPhase *value,
- GWeatherMoonLatitude *lat)
+gweather_info_get_value_moonphase (GWeatherInfo *info,
+ GWeatherMoonPhase *value,
+ GWeatherMoonLatitude *lat)
{
g_return_val_if_fail (GWEATHER_IS_INFO (info), FALSE);
g_return_val_if_fail (value != NULL, FALSE);
@@ -1982,10 +1956,10 @@ gweather_info_get_value_moonphase (GWeatherInfo *info,
_gweather_info_ensure_moon (info);
if (!info->moonValid)
- return FALSE;
+ return FALSE;
*value = info->moonphase;
- *lat = info->moonlatitude;
+ *lat = info->moonlatitude;
return TRUE;
}
@@ -2001,9 +1975,9 @@ gweather_info_get_value_moonphase (GWeatherInfo *info,
*/
gboolean
gweather_info_get_value_wind (GWeatherInfo *info,
- GWeatherSpeedUnit unit,
- gdouble *speed,
- GWeatherWindDirection *direction)
+ GWeatherSpeedUnit unit,
+ gdouble *speed,
+ GWeatherWindDirection *direction)
{
gboolean res = FALSE;
@@ -2012,7 +1986,7 @@ gweather_info_get_value_wind (GWeatherInfo *info,
g_return_val_if_fail (direction != NULL, FALSE);
if (!info->valid)
- return FALSE;
+ return FALSE;
if (info->windspeed < 0.0 || info->wind <= GWEATHER_WIND_INVALID || info->wind >= GWEATHER_WIND_LAST)
return FALSE;
@@ -2033,14 +2007,14 @@ gweather_info_get_value_wind (GWeatherInfo *info,
*/
gboolean
gweather_info_get_value_pressure (GWeatherInfo *info,
- GWeatherPressureUnit unit,
- gdouble *value)
+ GWeatherPressureUnit unit,
+ gdouble *value)
{
g_return_val_if_fail (GWEATHER_IS_INFO (info), FALSE);
g_return_val_if_fail (value != NULL, FALSE);
if (!info->valid)
- return FALSE;
+ return FALSE;
return pressure_value (info->pressure, unit, value, info->settings);
}
@@ -2055,20 +2029,20 @@ gweather_info_get_value_pressure (GWeatherInfo *info,
*/
gboolean
gweather_info_get_value_visibility (GWeatherInfo *info,
- GWeatherDistanceUnit unit,
- gdouble *value)
+ GWeatherDistanceUnit unit,
+ gdouble *value)
{
g_return_val_if_fail (GWEATHER_IS_INFO (info), FALSE);
g_return_val_if_fail (value != NULL, FALSE);
if (!info->valid)
- return FALSE;
+ return FALSE;
return distance_value (info->visibility, unit, value, info->settings);
}
static void
-gweather_info_set_location_internal (GWeatherInfo *info,
+gweather_info_set_location_internal (GWeatherInfo *info,
GWeatherLocation *location)
{
GVariant *default_loc = NULL;
@@ -2080,46 +2054,46 @@ gweather_info_set_location_internal (GWeatherInfo *info,
return;
if (info->glocation)
- gweather_location_unref (info->glocation);
+ gweather_location_unref (info->glocation);
info->glocation = location;
if (info->glocation) {
gweather_location_ref (location);
} else {
- g_autoptr(GWeatherLocation) world = NULL;
+ g_autoptr (GWeatherLocation) world = NULL;
const gchar *station_code;
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);
- if (strcmp(name, "") == 0)
- name = NULL;
+ if (strcmp (name, "") == 0)
+ name = NULL;
- world = gweather_location_get_world ();
- info->glocation = gweather_location_find_by_station_code (world, station_code);
+ world = gweather_location_get_world ();
+ info->glocation = gweather_location_find_by_station_code (world, station_code);
}
if (info->glocation) {
_weather_location_free (&info->location);
_gweather_location_update_weather_location (info->glocation,
- &info->location);
+ &info->location);
}
if (name) {
- g_free (info->location.name);
- info->location.name = g_strdup (name);
+ g_free (info->location.name);
+ info->location.name = g_strdup (name);
}
if (latlon_override) {
- info->location.latlon_valid = TRUE;
- info->location.latitude = DEGREES_TO_RADIANS (lat);
- info->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)
- g_variant_unref (default_loc);
+ g_variant_unref (default_loc);
}
/**
@@ -2132,8 +2106,8 @@ gweather_info_set_location_internal (GWeatherInfo *info,
* @info, you must call gweather_info_update() to obtain the new data.
*/
void
-gweather_info_set_location (GWeatherInfo *info,
- GWeatherLocation *location)
+gweather_info_set_location (GWeatherInfo *info,
+ GWeatherLocation *location)
{
g_return_if_fail (GWEATHER_IS_INFO (info));
@@ -2152,7 +2126,7 @@ GWeatherProvider
gweather_info_get_enabled_providers (GWeatherInfo *info)
{
g_return_val_if_fail (GWEATHER_IS_INFO (info),
- GWEATHER_PROVIDER_NONE);
+ GWEATHER_PROVIDER_NONE);
return info->providers;
}
@@ -2170,8 +2144,8 @@ gweather_info_get_enabled_providers (GWeatherInfo *info)
* not set to a valid value.
*/
void
-gweather_info_set_enabled_providers (GWeatherInfo *info,
- GWeatherProvider providers)
+gweather_info_set_enabled_providers (GWeatherInfo *info,
+ GWeatherProvider providers)
{
g_return_if_fail (GWEATHER_IS_INFO (info));
@@ -2181,7 +2155,7 @@ gweather_info_set_enabled_providers (GWeatherInfo *info,
}
if (info->providers == providers)
- return;
+ return;
info->providers = providers;
@@ -2220,7 +2194,7 @@ gweather_info_get_application_id (GWeatherInfo *info)
*/
void
gweather_info_set_application_id (GWeatherInfo *info,
- const char *application_id)
+ const char *application_id)
{
g_return_if_fail (GWEATHER_IS_INFO (info));
g_return_if_fail (g_application_id_is_valid (application_id));
@@ -2229,8 +2203,8 @@ gweather_info_set_application_id (GWeatherInfo *info,
info->application_id = g_strdup (application_id);
if (info->session) {
- g_clear_object (&info->session);
- info->session = ref_session (info);
+ g_clear_object (&info->session);
+ info->session = ref_session (info);
}
}
@@ -2267,7 +2241,7 @@ gweather_info_get_contact_info (GWeatherInfo *info)
*/
void
gweather_info_set_contact_info (GWeatherInfo *info,
- const char *contact_info)
+ const char *contact_info)
{
g_return_if_fail (GWEATHER_IS_INFO (info));
g_return_if_fail (contact_info != NULL);
@@ -2276,60 +2250,60 @@ gweather_info_set_contact_info (GWeatherInfo *info,
info->contact_info = g_strdup (contact_info);
if (info->session) {
- g_clear_object (&info->session);
- info->session = ref_session (info);
+ g_clear_object (&info->session);
+ info->session = ref_session (info);
}
}
static void
gweather_info_set_property (GObject *object,
- guint property_id,
- const GValue *value,
- GParamSpec *pspec)
+ guint property_id,
+ const GValue *value,
+ GParamSpec *pspec)
{
GWeatherInfo *self = GWEATHER_INFO (object);
switch (property_id) {
- case PROP_LOCATION:
- gweather_info_set_location_internal (self, (GWeatherLocation*) g_value_get_boxed (value));
- break;
- case PROP_ENABLED_PROVIDERS:
- gweather_info_set_enabled_providers (self, g_value_get_flags (value));
- break;
- case PROP_APPLICATION_ID:
- gweather_info_set_application_id (self, g_value_get_string (value));
- break;
- case PROP_CONTACT_INFO:
- gweather_info_set_contact_info (self, g_value_get_string (value));
- break;
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+ case PROP_LOCATION:
+ gweather_info_set_location_internal (self, (GWeatherLocation *) g_value_get_boxed (value));
+ break;
+ case PROP_ENABLED_PROVIDERS:
+ gweather_info_set_enabled_providers (self, g_value_get_flags (value));
+ break;
+ case PROP_APPLICATION_ID:
+ gweather_info_set_application_id (self, g_value_get_string (value));
+ break;
+ case PROP_CONTACT_INFO:
+ gweather_info_set_contact_info (self, g_value_get_string (value));
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
}
}
static void
-gweather_info_get_property (GObject *object,
- guint property_id,
- GValue *value,
- GParamSpec *pspec)
+gweather_info_get_property (GObject *object,
+ guint property_id,
+ GValue *value,
+ GParamSpec *pspec)
{
GWeatherInfo *self = GWEATHER_INFO (object);
switch (property_id) {
- case PROP_LOCATION:
- g_value_set_boxed (value, self->glocation);
- break;
- case PROP_ENABLED_PROVIDERS:
- g_value_set_flags (value, self->providers);
- break;
- case PROP_APPLICATION_ID:
- g_value_set_string (value, self->application_id);
- break;
- case PROP_CONTACT_INFO:
- g_value_set_string (value, self->contact_info);
- break;
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+ case PROP_LOCATION:
+ g_value_set_boxed (value, self->glocation);
+ break;
+ case PROP_ENABLED_PROVIDERS:
+ g_value_set_flags (value, self->providers);
+ break;
+ case PROP_APPLICATION_ID:
+ g_value_set_string (value, self->application_id);
+ break;
+ case PROP_CONTACT_INFO:
+ g_value_set_string (value, self->contact_info);
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
}
}
@@ -2362,32 +2336,32 @@ gweather_info_class_init (GWeatherInfoClass *klass)
gobject_class->constructed = gweather_info_constructed;
pspec = g_param_spec_boxed ("location",
- "Location",
- "The location this info represents",
- GWEATHER_TYPE_LOCATION,
- G_PARAM_STATIC_STRINGS | G_PARAM_READWRITE | G_PARAM_CONSTRUCT);
+ "Location",
+ "The location this info represents",
+ GWEATHER_TYPE_LOCATION,
+ G_PARAM_STATIC_STRINGS | G_PARAM_READWRITE | G_PARAM_CONSTRUCT);
g_object_class_install_property (gobject_class, PROP_LOCATION, pspec);
pspec = g_param_spec_flags ("enabled-providers",
- "Enabled providers",
- "A bitmask of enabled weather service providers",
- GWEATHER_TYPE_PROVIDER,
- GWEATHER_PROVIDER_NONE,
- G_PARAM_STATIC_STRINGS | G_PARAM_READWRITE);
+ "Enabled providers",
+ "A bitmask of enabled weather service providers",
+ GWEATHER_TYPE_PROVIDER,
+ GWEATHER_PROVIDER_NONE,
+ G_PARAM_STATIC_STRINGS | G_PARAM_READWRITE);
g_object_class_install_property (gobject_class, PROP_ENABLED_PROVIDERS, pspec);
pspec = g_param_spec_string ("application-id",
- "Application ID",
- "An unique reverse-DNS application ID",
- NULL,
- G_PARAM_STATIC_STRINGS | G_PARAM_READWRITE);
+ "Application ID",
+ "An unique reverse-DNS application ID",
+ NULL,
+ G_PARAM_STATIC_STRINGS | G_PARAM_READWRITE);
g_object_class_install_property (gobject_class, PROP_APPLICATION_ID, pspec);
pspec = g_param_spec_string ("contact-info",
- "Contact information",
- "An email address or contact form URL",
- NULL,
- G_PARAM_STATIC_STRINGS | G_PARAM_READWRITE);
+ "Contact information",
+ "An email address or contact form URL",
+ NULL,
+ G_PARAM_STATIC_STRINGS | G_PARAM_READWRITE);
g_object_class_install_property (gobject_class, PROP_CONTACT_INFO, pspec);
/**
@@ -2399,13 +2373,14 @@ gweather_info_class_init (GWeatherInfoClass *klass)
* to @gweather_info_update().
*/
gweather_info_signals[SIGNAL_UPDATED] = g_signal_new ("updated",
- GWEATHER_TYPE_INFO,
- G_SIGNAL_RUN_FIRST,
- 0,
- NULL, /* accumulator */
- NULL, /* accu_data */
- g_cclosure_marshal_VOID__VOID,
- G_TYPE_NONE, 0);
+ GWEATHER_TYPE_INFO,
+ G_SIGNAL_RUN_FIRST,
+ 0,
+ NULL, /* accumulator */
+ NULL, /* accu_data */
+ g_cclosure_marshal_VOID__VOID,
+ G_TYPE_NONE,
+ 0);
_gweather_gettext_init ();
}
@@ -2427,7 +2402,7 @@ GWeatherInfo *
gweather_info_new (GWeatherLocation *location)
{
if (location != NULL)
- return g_object_new (GWEATHER_TYPE_INFO, "location", location, NULL);
+ return g_object_new (GWEATHER_TYPE_INFO, "location", location, NULL);
return g_object_new (GWEATHER_TYPE_INFO, NULL);
}
@@ -2435,10 +2410,13 @@ GWeatherInfo *
_gweather_info_new_clone (GWeatherInfo *original)
{
return g_object_new (GWEATHER_TYPE_INFO,
- "application-id", original->application_id,
- "contact-info", original->contact_info,
- "enabled-providers", original->providers,
- "location", original->glocation,
+ "application-id",
+ original->application_id,
+ "contact-info",
+ original->contact_info,
+ "enabled-providers",
+ original->providers,
+ "location",
+ original->glocation,
NULL);
}
-
diff --git a/libgweather/tests/test_libgweather.c b/libgweather/tests/test_libgweather.c
index 9adb0e36..fb6bd5c2 100644
--- a/libgweather/tests/test_libgweather.c
+++ b/libgweather/tests/test_libgweather.c
@@ -6,16 +6,17 @@
#include "config.h"
+#include <libsoup/soup.h>
#include <locale.h>
#include <string.h>
-#include <libsoup/soup.h>
#include <libgweather/gweather-version.h>
/* We use internal API */
#include "gweather-private.h"
-extern void _gweather_location_reset_world (void);
+extern void
+_gweather_location_reset_world (void);
/* For test_metar_weather_stations */
#define METAR_SOURCES "https://www.aviationweather.gov/docs/metar/stations.txt"
@@ -27,12 +28,12 @@ static double max_distance = 0.0;
static void
test_named_timezones (void)
{
- g_autoptr(GWeatherLocation) world = NULL;
+ g_autoptr (GWeatherLocation) world = NULL;
world = gweather_location_get_world ();
g_assert_nonnull (world);
- g_autoptr(GWeatherLocation) child = NULL;
+ g_autoptr (GWeatherLocation) child = NULL;
while ((child = gweather_location_next_child (world, child)) != NULL) {
GWeatherLocationLevel level;
const char *code;
@@ -95,7 +96,7 @@ get_list_from_configuration (GWeatherLocation *world,
g_free (key);
}
- g_variant_unref (child);
+ g_variant_unref (child);
}
g_variant_unref (v);
@@ -111,12 +112,13 @@ get_list_from_configuration (GWeatherLocation *world,
{'location': <(uint32 2, <('Perm', 'USPP', true, [(1.0122909661567112,
0.98174770424681035)], [(1.0122909661567112, 0.98174770424681035)])>)>} \
]"
-static void test_timezones (void);
+static void
+test_timezones (void);
static void
test_named_timezones_deserialized (void)
{
- g_autoptr(GWeatherLocation) world = NULL;
+ g_autoptr (GWeatherLocation) world = NULL;
GList *list, *l;
world = gweather_location_get_world ();
@@ -152,9 +154,9 @@ static void
test_no_code_serialize (void)
{
GVariant *variant;
- g_autoptr(GWeatherLocation) world = NULL;
- g_autoptr(GWeatherLocation) loc = NULL;
- g_autoptr(GWeatherLocation) new_loc = NULL;
+ g_autoptr (GWeatherLocation) world = NULL;
+ g_autoptr (GWeatherLocation) loc = NULL;
+ g_autoptr (GWeatherLocation) new_loc = NULL;
GString *str;
world = gweather_location_get_world ();
@@ -186,7 +188,7 @@ test_no_code_serialize (void)
static void
test_timezone (GWeatherLocation *location)
{
- g_autoptr(GWeatherTimezone) gtz = NULL;
+ g_autoptr (GWeatherTimezone) gtz = NULL;
const char *tz;
tz = gweather_location_get_timezone_str (location);
@@ -219,7 +221,7 @@ test_timezone (GWeatherLocation *location)
static void
test_timezones_children (GWeatherLocation *location)
{
- g_autoptr(GWeatherLocation) child = NULL;
+ g_autoptr (GWeatherLocation) child = NULL;
while ((child = gweather_location_next_child (location, child)) != NULL) {
if (gweather_location_get_level (child) >= GWEATHER_LOCATION_COUNTRY)
test_timezone (child);
@@ -231,7 +233,7 @@ test_timezones_children (GWeatherLocation *location)
static void
test_timezones (void)
{
- g_autoptr(GWeatherLocation) world = NULL;
+ g_autoptr (GWeatherLocation) world = NULL;
world = gweather_location_get_world ();
g_assert_nonnull (world);
@@ -245,12 +247,12 @@ test_timezones (void)
static void
test_distance (GWeatherLocation *location)
{
- g_autoptr(GWeatherLocation) parent = NULL;
+ g_autoptr (GWeatherLocation) parent = NULL;
double distance;
parent = gweather_location_get_parent (location);
if (gweather_location_get_level (parent) < GWEATHER_LOCATION_CITY)
- return;
+ return;
distance = gweather_location_get_distance (location, parent);
if (distance > TOO_FAR) {
@@ -258,7 +260,7 @@ test_distance (GWeatherLocation *location)
gweather_location_get_name (location),
gweather_location_get_name (parent),
distance);
- max_distance = MAX(max_distance, distance);
+ max_distance = MAX (max_distance, distance);
g_test_fail ();
}
}
@@ -266,7 +268,7 @@ test_distance (GWeatherLocation *location)
static void
test_airport_distance_children (GWeatherLocation *location)
{
- g_autoptr(GWeatherLocation) child = NULL;
+ g_autoptr (GWeatherLocation) child = NULL;
while ((child = gweather_location_next_child (location, child)) != NULL) {
if (gweather_location_get_level (child) == GWEATHER_LOCATION_WEATHER_STATION)
@@ -279,7 +281,7 @@ test_airport_distance_children (GWeatherLocation *location)
static void
test_airport_distance_sanity (void)
{
- g_autoptr(GWeatherLocation) world = NULL;
+ g_autoptr (GWeatherLocation) world = NULL;
world = gweather_location_get_world ();
g_assert_nonnull (world);
@@ -353,7 +355,7 @@ parse_metar_stations (const char *contents)
static void
test_metar_weather_station (GWeatherLocation *location,
- GHashTable *stations_ht)
+ GHashTable *stations_ht)
{
const char *code, *line;
@@ -381,9 +383,9 @@ test_metar_weather_station (GWeatherLocation *location,
static void
test_metar_weather_stations_children (GWeatherLocation *location,
- GHashTable *stations_ht)
+ GHashTable *stations_ht)
{
- g_autoptr(GWeatherLocation) child = NULL;
+ g_autoptr (GWeatherLocation) child = NULL;
while ((child = gweather_location_next_child (location, child)) != NULL) {
if (gweather_location_get_level (child) == GWEATHER_LOCATION_WEATHER_STATION)
@@ -396,7 +398,7 @@ test_metar_weather_stations_children (GWeatherLocation *location,
static void
test_metar_weather_stations (void)
{
- g_autoptr(GWeatherLocation) world = NULL;
+ g_autoptr (GWeatherLocation) world = NULL;
SoupMessage *msg;
SoupSession *session;
GHashTable *stations_ht;
@@ -436,74 +438,76 @@ test_metar_weather_stations (void)
static void
set_gsettings (void)
{
- char *tmpdir, *schema_text, *dest, *cmdline;
- int result;
-
- /* Create the installed schemas directory */
- tmpdir = g_dir_make_tmp ("libgweather-test-XXXXXX", NULL);
- g_assert_nonnull (tmpdir);
-
- /* Copy the schemas files */
- g_assert_true (g_file_get_contents (SCHEMAS_BUILDDIR "/org.gnome.GWeather4.enums.xml", &schema_text,
NULL, NULL));
- dest = g_build_filename (tmpdir, "org.gnome.GWeather4.enums.xml", NULL);
- g_assert_true (g_file_set_contents (dest, schema_text, -1, NULL));
- g_free (dest);
- g_free (schema_text);
-
- g_assert_true (g_file_get_contents (SCHEMASDIR "/org.gnome.GWeather4.gschema.xml", &schema_text,
NULL, NULL));
- dest = g_build_filename (tmpdir, "org.gnome.GWeather4.gschema.xml", NULL);
- g_assert_true (g_file_set_contents (dest, schema_text, -1, NULL));
- g_free (dest);
- g_free (schema_text);
-
- /* Compile the schemas */
- cmdline = g_strdup_printf ("glib-compile-schemas --targetdir=%s "
- "--schema-file=%s/org.gnome.GWeather4.enums.xml "
- "--schema-file=%s/org.gnome.GWeather4.gschema.xml",
- tmpdir, SCHEMAS_BUILDDIR, SCHEMASDIR);
- g_assert_true (g_spawn_command_line_sync (cmdline, NULL, NULL, &result, NULL));
- g_assert_cmpint (result, ==, 0);
- g_free (cmdline);
-
- /* Set envvar */
- g_setenv ("GSETTINGS_SCHEMA_DIR", tmpdir, TRUE);
- g_setenv ("GSETTINGS_BACKEND", "memory", TRUE);
-
- g_free (tmpdir);
+ char *tmpdir, *schema_text, *dest, *cmdline;
+ int result;
+
+ /* Create the installed schemas directory */
+ tmpdir = g_dir_make_tmp ("libgweather-test-XXXXXX", NULL);
+ g_assert_nonnull (tmpdir);
+
+ /* Copy the schemas files */
+ g_assert_true (g_file_get_contents (SCHEMAS_BUILDDIR "/org.gnome.GWeather4.enums.xml", &schema_text,
NULL, NULL));
+ dest = g_build_filename (tmpdir, "org.gnome.GWeather4.enums.xml", NULL);
+ g_assert_true (g_file_set_contents (dest, schema_text, -1, NULL));
+ g_free (dest);
+ g_free (schema_text);
+
+ g_assert_true (g_file_get_contents (SCHEMASDIR "/org.gnome.GWeather4.gschema.xml", &schema_text, NULL,
NULL));
+ dest = g_build_filename (tmpdir, "org.gnome.GWeather4.gschema.xml", NULL);
+ g_assert_true (g_file_set_contents (dest, schema_text, -1, NULL));
+ g_free (dest);
+ g_free (schema_text);
+
+ /* Compile the schemas */
+ cmdline = g_strdup_printf ("glib-compile-schemas --targetdir=%s "
+ "--schema-file=%s/org.gnome.GWeather4.enums.xml "
+ "--schema-file=%s/org.gnome.GWeather4.gschema.xml",
+ tmpdir,
+ SCHEMAS_BUILDDIR,
+ SCHEMASDIR);
+ g_assert_true (g_spawn_command_line_sync (cmdline, NULL, NULL, &result, NULL));
+ g_assert_cmpint (result, ==, 0);
+ g_free (cmdline);
+
+ /* Set envvar */
+ g_setenv ("GSETTINGS_SCHEMA_DIR", tmpdir, TRUE);
+ g_setenv ("GSETTINGS_BACKEND", "memory", TRUE);
+
+ g_free (tmpdir);
}
static void
test_utc_sunset (void)
{
- g_autoptr(GWeatherLocation) world = NULL;
- g_autoptr(GWeatherLocation) utc = NULL;
- GWeatherInfo *info;
- char *sunset;
- GWeatherMoonPhase phase;
- GWeatherMoonLatitude lat;
- gboolean ret;
-
- world = gweather_location_get_world ();
- g_assert_nonnull (world);
- utc = gweather_location_find_by_station_code (world, "@UTC");
- g_assert_nonnull (utc);
-
- info = gweather_info_new (utc);
- gweather_info_set_enabled_providers (info, GWEATHER_PROVIDER_NONE);
- gweather_info_update (info);
-
- sunset = gweather_info_get_sunset (info);
- g_assert_nonnull (sunset);
- g_free (sunset);
-
- ret = gweather_info_get_value_moonphase (info, &phase, &lat);
- g_assert_false (ret);
-
- g_object_unref (info);
-
- g_clear_pointer (&world, gweather_location_unref);
- g_clear_pointer (&utc, gweather_location_unref);
- _gweather_location_reset_world ();
+ g_autoptr (GWeatherLocation) world = NULL;
+ g_autoptr (GWeatherLocation) utc = NULL;
+ GWeatherInfo *info;
+ char *sunset;
+ GWeatherMoonPhase phase;
+ GWeatherMoonLatitude lat;
+ gboolean ret;
+
+ world = gweather_location_get_world ();
+ g_assert_nonnull (world);
+ utc = gweather_location_find_by_station_code (world, "@UTC");
+ g_assert_nonnull (utc);
+
+ info = gweather_info_new (utc);
+ gweather_info_set_enabled_providers (info, GWEATHER_PROVIDER_NONE);
+ gweather_info_update (info);
+
+ sunset = gweather_info_get_sunset (info);
+ g_assert_nonnull (sunset);
+ g_free (sunset);
+
+ ret = gweather_info_get_value_moonphase (info, &phase, &lat);
+ g_assert_false (ret);
+
+ g_object_unref (info);
+
+ g_clear_pointer (&world, gweather_location_unref);
+ g_clear_pointer (&utc, gweather_location_unref);
+ _gweather_location_reset_world ();
}
static void
@@ -531,7 +535,8 @@ check_bad_duplicate_weather_stations (gpointer key,
if (g_hash_table_size (dedup) > 1) {
g_print ("Airport '%s' is defined %u times in different ways\n",
- (const char *) key, stations->len);
+ (const char *) key,
+ stations->len);
g_test_fail ();
}
@@ -543,9 +548,9 @@ out:
static void
test_bad_duplicate_weather_stations_children (GWeatherLocation *location,
- GHashTable *stations_ht)
+ GHashTable *stations_ht)
{
- g_autoptr(GWeatherLocation) child = NULL;
+ g_autoptr (GWeatherLocation) child = NULL;
while ((child = gweather_location_next_child (location, child)) != NULL) {
if (gweather_location_get_level (child) == GWEATHER_LOCATION_WEATHER_STATION) {
GPtrArray *stations;
@@ -568,15 +573,14 @@ test_bad_duplicate_weather_stations_children (GWeatherLocation *location,
static void
test_bad_duplicate_weather_stations (void)
{
- g_autoptr(GWeatherLocation) world = NULL;
+ g_autoptr (GWeatherLocation) world = NULL;
GHashTable *stations_ht;
g_setenv ("LIBGWEATHER_LOCATIONS_NO_NEAREST", "1", TRUE);
world = gweather_location_get_world ();
g_assert_nonnull (world);
- stations_ht = g_hash_table_new_full (g_str_hash, g_str_equal,
- g_free, (GDestroyNotify) NULL);
+ stations_ht = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, (GDestroyNotify) NULL);
test_bad_duplicate_weather_stations_children (world, stations_ht);
g_hash_table_foreach (stations_ht, check_bad_duplicate_weather_stations, NULL);
@@ -591,17 +595,16 @@ test_bad_duplicate_weather_stations (void)
static void
test_duplicate_weather_stations_children (GWeatherLocation *location)
{
- g_autoptr(GHashTable) stations_ht = NULL;
+ g_autoptr (GHashTable) stations_ht = NULL;
- g_autoptr(GWeatherLocation) child = NULL;
+ g_autoptr (GWeatherLocation) child = NULL;
while ((child = gweather_location_next_child (location, child)) != NULL) {
if (gweather_location_get_level (child) == GWEATHER_LOCATION_WEATHER_STATION) {
const char *code;
code = gweather_location_get_code (child);
if (stations_ht == NULL) {
- stations_ht = g_hash_table_new_full (g_str_hash, g_str_equal,
- g_free, (GDestroyNotify) NULL);
+ stations_ht = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, (GDestroyNotify) NULL);
} else {
gboolean exists;
@@ -611,7 +614,8 @@ test_duplicate_weather_stations_children (GWeatherLocation *location)
parent_level = gweather_location_get_level (location);
g_print ("Duplicate weather station '%s' in %s (level '%s')\n",
- code, gweather_location_get_name (location),
+ code,
+ gweather_location_get_name (location),
gweather_location_level_to_string (parent_level));
g_test_fail ();
}
@@ -627,7 +631,7 @@ test_duplicate_weather_stations_children (GWeatherLocation *location)
static void
test_duplicate_weather_stations (void)
{
- g_autoptr(GWeatherLocation) world = NULL;
+ g_autoptr (GWeatherLocation) world = NULL;
g_setenv ("LIBGWEATHER_LOCATIONS_NO_NEAREST", "1", TRUE);
world = gweather_location_get_world ();
@@ -643,8 +647,8 @@ test_duplicate_weather_stations (void)
static void
test_location_names (void)
{
- g_autoptr(GWeatherLocation) world = NULL;
- g_autoptr(GWeatherLocation) brussels = NULL;
+ g_autoptr (GWeatherLocation) world = NULL;
+ g_autoptr (GWeatherLocation) brussels = NULL;
char *old_locale;
world = gweather_location_get_world ();
@@ -683,11 +687,11 @@ test_location_names (void)
}
static gboolean
-find_loc_children (GWeatherLocation *location,
- const char *search_str,
- GWeatherLocation **ret)
+find_loc_children (GWeatherLocation *location,
+ const char *search_str,
+ GWeatherLocation **ret)
{
- g_autoptr(GWeatherLocation) child = NULL;
+ g_autoptr (GWeatherLocation) child = NULL;
while ((child = gweather_location_next_child (location, child)) != NULL) {
if (gweather_location_get_level (child) == GWEATHER_LOCATION_WEATHER_STATION) {
const char *code;
@@ -708,7 +712,7 @@ find_loc_children (GWeatherLocation *location,
static GWeatherLocation *
find_loc (GWeatherLocation *world,
- const char *search_str)
+ const char *search_str)
{
GWeatherLocation *loc = NULL;
@@ -718,7 +722,7 @@ find_loc (GWeatherLocation *world,
static void
weather_updated (GWeatherInfo *info,
- GMainLoop *loop)
+ GMainLoop *loop)
{
g_assert_not_reached ();
}
@@ -726,15 +730,15 @@ weather_updated (GWeatherInfo *info,
static gboolean
stop_loop_cb (gpointer user_data)
{
- g_main_loop_quit (user_data);
- return G_SOURCE_REMOVE;
+ g_main_loop_quit (user_data);
+ return G_SOURCE_REMOVE;
}
static void
test_weather_loop_use_after_free (void)
{
GMainLoop *loop;
- g_autoptr(GWeatherLocation) world = NULL;
+ g_autoptr (GWeatherLocation) world = NULL;
GWeatherLocation *loc;
GWeatherInfo *info;
const char *search_str = "LFLL";
@@ -755,13 +759,12 @@ test_weather_loop_use_after_free (void)
gweather_info_set_application_id (info, "org.gnome.LibGWeather");
gweather_info_set_contact_info (info, "https://gitlab.gnome.org/GNOME/libgweather/");
gweather_info_set_enabled_providers (info,
- GWEATHER_PROVIDER_METAR |
- GWEATHER_PROVIDER_IWIN |
- GWEATHER_PROVIDER_MET_NO |
- GWEATHER_PROVIDER_OWM);
+ GWEATHER_PROVIDER_METAR |
+ GWEATHER_PROVIDER_IWIN |
+ GWEATHER_PROVIDER_MET_NO |
+ GWEATHER_PROVIDER_OWM);
gweather_info_set_location (info, loc);
- g_signal_connect (G_OBJECT (info), "updated",
- G_CALLBACK (weather_updated), loop);
+ g_signal_connect (G_OBJECT (info), "updated", G_CALLBACK (weather_updated), loop);
gweather_info_update (info);
g_object_unref (info);
@@ -775,39 +778,39 @@ test_weather_loop_use_after_free (void)
static void
test_walk_world (void)
{
- g_autoptr(GWeatherLocation) cur = NULL, next = NULL;
+ g_autoptr (GWeatherLocation) cur = NULL, next = NULL;
gint visited = 0;
next = gweather_location_get_world ();
while (next) {
- /* Update cur pointer. */
- g_clear_pointer (&cur, gweather_location_unref);
- cur = g_steal_pointer (&next);
- visited += 1;
- g_assert_cmpint (cur->ref_count, ==, 1);
+ /* Update cur pointer. */
+ g_clear_pointer (&cur, gweather_location_unref);
+ cur = g_steal_pointer (&next);
+ visited += 1;
+ g_assert_cmpint (cur->ref_count, ==, 1);
- /* Select next item, which is in this order:
+ /* Select next item, which is in this order:
* 1. The first child
* 2. Walk up the parent tree and try to find a sibbling
* Note that cur remains valid after the loop and points to the world
* again.
*/
- if ((next = gweather_location_next_child (cur, NULL)))
- continue;
-
- while (TRUE) {
- g_autoptr(GWeatherLocation) child = NULL;
- /* Move cur to the parent, keeping the child as reference. */
- child = g_steal_pointer (&cur);
- cur = gweather_location_get_parent (child);
- if (!cur)
- break;
- g_assert_cmpint (cur->ref_count, ==, 1);
- g_assert_cmpint (child->ref_count, ==, 1);
-
- if ((next = gweather_location_next_child (cur, gweather_location_ref (child))))
- break;
- }
+ if ((next = gweather_location_next_child (cur, NULL)))
+ continue;
+
+ while (TRUE) {
+ g_autoptr (GWeatherLocation) child = NULL;
+ /* Move cur to the parent, keeping the child as reference. */
+ child = g_steal_pointer (&cur);
+ cur = gweather_location_get_parent (child);
+ if (!cur)
+ break;
+ g_assert_cmpint (cur->ref_count, ==, 1);
+ g_assert_cmpint (child->ref_count, ==, 1);
+
+ if ((next = gweather_location_next_child (cur, gweather_location_ref (child))))
+ break;
+ }
}
/* cur must be NULL at this point */
@@ -841,39 +844,39 @@ test_radians_to_degrees_str (void)
static void
log_handler (const char *log_domain, GLogLevelFlags log_level, const char *message, gpointer user_data)
{
- g_print ("%s\n", message);
+ g_print ("%s\n", message);
}
int
main (int argc, char *argv[])
{
- setlocale (LC_ALL, "");
-
- g_test_init (&argc, &argv, NULL);
- g_test_bug_base ("http://gitlab.gnome.org/GNOME/libgweather/issues/");
-
- /* We need to handle log messages produced by g_message so they're interpreted correctly by the
GTester framework */
- g_log_set_handler (NULL, G_LOG_LEVEL_MESSAGE | G_LOG_LEVEL_INFO | G_LOG_LEVEL_DEBUG, log_handler,
NULL);
-
- g_setenv ("LIBGWEATHER_LOCATIONS_PATH",
- TEST_LOCATIONS,
- FALSE);
- set_gsettings ();
-
- g_test_add_func ("/weather/radians-to-degrees_str", test_radians_to_degrees_str);
- g_test_add_func ("/weather/named-timezones", test_named_timezones);
- g_test_add_func ("/weather/named-timezones-deserialized", test_named_timezones_deserialized);
- g_test_add_func ("/weather/no-code-serialize", test_no_code_serialize);
- g_test_add_func ("/weather/timezones", test_timezones);
- g_test_add_func ("/weather/airport_distance_sanity", test_airport_distance_sanity);
- g_test_add_func ("/weather/metar_weather_stations", test_metar_weather_stations);
- g_test_add_func ("/weather/utc_sunset", test_utc_sunset);
- g_test_add_func ("/weather/weather-loop-use-after-free", test_weather_loop_use_after_free);
- /* Modifies environment, so needs to run last */
- g_test_add_func ("/weather/bad_duplicate_weather_stations", test_bad_duplicate_weather_stations);
- g_test_add_func ("/weather/duplicate_weather_stations", test_duplicate_weather_stations);
- g_test_add_func ("/weather/location-names", test_location_names);
- g_test_add_func ("/weather/walk_world", test_walk_world);
-
- return g_test_run ();
+ setlocale (LC_ALL, "");
+
+ g_test_init (&argc, &argv, NULL);
+ g_test_bug_base ("http://gitlab.gnome.org/GNOME/libgweather/issues/");
+
+ /* We need to handle log messages produced by g_message so they're interpreted correctly by the GTester
framework */
+ g_log_set_handler (NULL, G_LOG_LEVEL_MESSAGE | G_LOG_LEVEL_INFO | G_LOG_LEVEL_DEBUG, log_handler, NULL);
+
+ g_setenv ("LIBGWEATHER_LOCATIONS_PATH",
+ TEST_LOCATIONS,
+ FALSE);
+ set_gsettings ();
+
+ g_test_add_func ("/weather/radians-to-degrees_str", test_radians_to_degrees_str);
+ g_test_add_func ("/weather/named-timezones", test_named_timezones);
+ g_test_add_func ("/weather/named-timezones-deserialized", test_named_timezones_deserialized);
+ g_test_add_func ("/weather/no-code-serialize", test_no_code_serialize);
+ g_test_add_func ("/weather/timezones", test_timezones);
+ g_test_add_func ("/weather/airport_distance_sanity", test_airport_distance_sanity);
+ g_test_add_func ("/weather/metar_weather_stations", test_metar_weather_stations);
+ g_test_add_func ("/weather/utc_sunset", test_utc_sunset);
+ g_test_add_func ("/weather/weather-loop-use-after-free", test_weather_loop_use_after_free);
+ /* Modifies environment, so needs to run last */
+ g_test_add_func ("/weather/bad_duplicate_weather_stations", test_bad_duplicate_weather_stations);
+ g_test_add_func ("/weather/duplicate_weather_stations", test_duplicate_weather_stations);
+ g_test_add_func ("/weather/location-names", test_location_names);
+ g_test_add_func ("/weather/walk_world", test_walk_world);
+
+ return g_test_run ();
}
diff --git a/libgweather/tools/test_metar.c b/libgweather/tools/test_metar.c
index 72a3e13a..2405ae2c 100644
--- a/libgweather/tools/test_metar.c
+++ b/libgweather/tools/test_metar.c
@@ -8,9 +8,9 @@
#include "gweather-private.h"
-#include <string.h>
-#include <stdio.h>
#include <glib.h>
+#include <stdio.h>
+#include <string.h>
#ifndef BUFLEN
#define BUFLEN 4096
@@ -41,7 +41,7 @@ print_info (GWeatherInfo *info)
static void
weather_updated_cb (GWeatherInfo *info,
- gpointer user_data)
+ gpointer user_data)
{
print_info (info);
g_main_loop_quit (user_data);
@@ -51,15 +51,15 @@ int
main (int argc, char **argv)
{
FILE *stream = stdin;
- gchar* filename = NULL;
- gchar* code = NULL;
+ gchar *filename = NULL;
+ gchar *code = NULL;
GOptionEntry entries[] = {
- { "file", 'f', 0, G_OPTION_ARG_FILENAME, &filename, "file containing METAR observations", NULL },
- { "code", 'c', 0, G_OPTION_ARG_STRING, &code, "ICAO code to get METAR observations from", NULL },
+ { "file", 'f', 0, G_OPTION_ARG_FILENAME, &filename, "file containing METAR observations", NULL },
+ { "code", 'c', 0, G_OPTION_ARG_STRING, &code, "ICAO code to get METAR observations from", NULL },
{ NULL }
};
- GOptionContext* context;
- GError* error = NULL;
+ GOptionContext *context;
+ GError *error = NULL;
char buf[BUFLEN];
int len;
GWeatherInfo *info;
@@ -69,8 +69,8 @@ main (int argc, char **argv)
g_option_context_parse (context, &argc, &argv, &error);
if (error) {
- perror (error->message);
- return error->code;
+ perror (error->message);
+ return error->code;
}
if (code) {
@@ -82,8 +82,7 @@ main (int argc, char **argv)
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);
+ g_signal_connect (G_OBJECT (info), "updated", G_CALLBACK (weather_updated_cb), loop);
metar_start_open (info);
@@ -93,27 +92,27 @@ main (int argc, char **argv)
}
if (filename) {
- stream = fopen (filename, "r");
- if (!stream) {
- perror ("fopen");
- return -1;
- }
+ stream = fopen (filename, "r");
+ if (!stream) {
+ perror ("fopen");
+ return -1;
+ }
} else {
- fprintf (stderr, "Enter a METAR string...\n");
+ fprintf (stderr, "Enter a METAR string...\n");
}
while (fgets (buf, sizeof (buf), stream)) {
- len = strlen (buf);
- if (buf[len - 1] == '\n') {
- buf[--len] = '\0';
- }
- printf ("\n%s\n", buf);
-
- /* a bit hackish... */
- info = g_object_new (GWEATHER_TYPE_INFO, NULL);
- info->valid = 1;
- metar_parse (buf, info);
- print_info (info);
+ len = strlen (buf);
+ if (buf[len - 1] == '\n') {
+ buf[--len] = '\0';
+ }
+ printf ("\n%s\n", buf);
+
+ /* a bit hackish... */
+ info = g_object_new (GWEATHER_TYPE_INFO, NULL);
+ info->valid = 1;
+ metar_parse (buf, info);
+ print_info (info);
}
return 0;
}
diff --git a/libgweather/tools/test_sun_moon.c b/libgweather/tools/test_sun_moon.c
index 2cdc9ec3..d6808be6 100644
--- a/libgweather/tools/test_sun_moon.c
+++ b/libgweather/tools/test_sun_moon.c
@@ -12,28 +12,25 @@
#include <string.h>
#include <time.h>
-#include "gweather-weather.h"
#include "gweather-private.h"
+#include "gweather-weather.h"
int
main (int argc, char **argv)
{
- GWeatherInfo *info;
- GOptionContext* context;
- GError* error = NULL;
- gdouble latitude, longitude;
- gchar* gtime = NULL;
- GDate gdate;
- struct tm tm;
- time_t phases[4];
+ GWeatherInfo *info;
+ GOptionContext *context;
+ GError *error = NULL;
+ gdouble latitude, longitude;
+ gchar *gtime = NULL;
+ GDate gdate;
+ struct tm tm;
+ time_t phases[4];
const GOptionEntry entries[] = {
- { "latitude", 0, 0, G_OPTION_ARG_DOUBLE, &latitude,
- "observer's latitude in degrees north", NULL },
- { "longitude", 0, 0, G_OPTION_ARG_DOUBLE, &longitude,
- "observer's longitude in degrees east", NULL },
- { "time", 0, 0, G_OPTION_ARG_STRING, >ime,
- "time in seconds from Unix epoch", NULL },
- { NULL }
+ { "latitude", 0, 0, G_OPTION_ARG_DOUBLE, &latitude, "observer's latitude in degrees north", NULL },
+ { "longitude", 0, 0, G_OPTION_ARG_DOUBLE, &longitude, "observer's longitude in degrees east", NULL },
+ { "time", 0, 0, G_OPTION_ARG_STRING, >ime, "time in seconds from Unix epoch", NULL },
+ { NULL }
};
context = g_option_context_new ("- test libgweather sun/moon calculations");
@@ -41,54 +38,55 @@ main (int argc, char **argv)
g_option_context_parse (context, &argc, &argv, &error);
if (error) {
- perror (error->message);
- return error->code;
- }
- else if (latitude < -90. || latitude > 90.) {
- perror ("invalid latitude: should be [-90 .. 90]");
- return -1;
+ perror (error->message);
+ return error->code;
+ } else if (latitude < -90. || latitude > 90.) {
+ perror ("invalid latitude: should be [-90 .. 90]");
+ return -1;
} else if (longitude < -180. || longitude > 180.) {
- perror ("invalid longitude: should be [-180 .. 180]");
- return -1;
+ perror ("invalid longitude: should be [-180 .. 180]");
+ return -1;
}
info = g_object_new (GWEATHER_TYPE_INFO, NULL);
- info->location.latitude = DEGREES_TO_RADIANS(latitude);
- info->location.longitude = DEGREES_TO_RADIANS(longitude);
+ 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);
- info->current_time = mktime(&tm);
+ // printf(" gtime=%s\n", gtime);
+ g_date_set_parse (&gdate, gtime);
+ g_date_to_struct_tm (&gdate, &tm);
+ info->current_time = mktime (&tm);
} else {
- info->current_time = time(NULL);
+ info->current_time = time (NULL);
}
_gweather_info_ensure_sun (info);
_gweather_info_ensure_moon (info);
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(&info->current_time)));
- printf("daytime: %s\n", gweather_info_is_daytime(info) ? "yes" : "no");
- printf("sunrise: %s",
- (info->sunriseValid ? ctime(&info->sunrise) : "(invalid)\n"));
- printf("sunset: %s",
- (info->sunsetValid ? ctime(&info->sunset) : "(invalid)\n"));
+ fabs (latitude),
+ (latitude >= 0. ? 'N' : 'S'),
+ fabs (longitude),
+ (longitude >= 0. ? 'E' : 'W'),
+ asctime (gmtime (&info->current_time)));
+ printf ("daytime: %s\n", gweather_info_is_daytime (info) ? "yes" : "no");
+ printf ("sunrise: %s",
+ (info->sunriseValid ? ctime (&info->sunrise) : "(invalid)\n"));
+ printf ("sunset: %s",
+ (info->sunsetValid ? ctime (&info->sunset) : "(invalid)\n"));
if (info->moonValid) {
- printf("moonphase: %g\n", info->moonphase);
- printf("moonlat: %g\n", info->moonlatitude);
+ 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])));
- printf(" 1stQ: %s", asctime(gmtime(&phases[1])));
- printf(" Full: %s", asctime(gmtime(&phases[2])));
- printf(" 3rdQ: %s", asctime(gmtime(&phases[3])));
- }
+ if (gweather_info_get_upcoming_moonphases (info, phases)) {
+ printf (" New: %s", asctime (gmtime (&phases[0])));
+ printf (" 1stQ: %s", asctime (gmtime (&phases[1])));
+ printf (" Full: %s", asctime (gmtime (&phases[2])));
+ printf (" 3rdQ: %s", asctime (gmtime (&phases[3])));
+ }
}
return 0;
}
diff --git a/libgweather/tools/test_weather.c b/libgweather/tools/test_weather.c
index 55493a74..99dd1875 100644
--- a/libgweather/tools/test_weather.c
+++ b/libgweather/tools/test_weather.c
@@ -1,6 +1,6 @@
-#include <gweather-version.h>
#include "gweather-weather.h"
+#include <gweather-version.h>
#include <locale.h>
@@ -12,9 +12,9 @@ static GWeatherProvider providers = GWEATHER_PROVIDER_METAR | GWEATHER_PROVIDER_
//static GWeatherProvider providers = GWEATHER_PROVIDER_METAR | GWEATHER_PROVIDER_IWIN;
static gboolean
-find_loc_children (GWeatherLocation *location,
- const char *search_str,
- GWeatherLocation **ret)
+find_loc_children (GWeatherLocation *location,
+ const char *search_str,
+ GWeatherLocation **ret)
{
g_autoptr (GWeatherLocation) child = NULL;
@@ -38,7 +38,7 @@ find_loc_children (GWeatherLocation *location,
static GWeatherLocation *
find_loc (GWeatherLocation *world,
- const char *search_str)
+ const char *search_str)
{
GWeatherLocation *loc = NULL;
@@ -48,7 +48,7 @@ find_loc (GWeatherLocation *world,
static void
weather_updated (GWeatherInfo *info,
- GMainLoop *loop)
+ GMainLoop *loop)
{
GSList *forecasts, *l;
time_t val;
@@ -68,7 +68,7 @@ weather_updated (GWeatherInfo *info,
forecasts = gweather_info_get_forecast_list (info);
if (!forecasts) {
if (!weather_printed)
- g_warning ("No forecasts, but no weather either?!");
+ g_warning ("No forecasts, but no weather either?!");
return;
}
@@ -95,11 +95,12 @@ weather_updated (GWeatherInfo *info,
g_main_loop_quit (loop);
}
-#define ADD_PROVIDER_STR(x) { \
- if (s->len != 0) \
- g_string_append (s, ", "); \
- g_string_append(s, x); \
-}
+#define ADD_PROVIDER_STR(x) \
+ { \
+ if (s->len != 0) \
+ g_string_append (s, ", "); \
+ g_string_append (s, x); \
+ }
static gboolean
set_providers (GWeatherInfo *info)
@@ -108,13 +109,13 @@ set_providers (GWeatherInfo *info)
s = g_string_new (NULL);
if (providers & GWEATHER_PROVIDER_METAR)
- ADD_PROVIDER_STR("METAR");
+ ADD_PROVIDER_STR ("METAR");
if (providers & GWEATHER_PROVIDER_IWIN)
- ADD_PROVIDER_STR("IWIN");
+ ADD_PROVIDER_STR ("IWIN");
if (providers & GWEATHER_PROVIDER_MET_NO)
- ADD_PROVIDER_STR("MET_NO");
+ ADD_PROVIDER_STR ("MET_NO");
if (providers & GWEATHER_PROVIDER_OWM)
- ADD_PROVIDER_STR("OWM");
+ ADD_PROVIDER_STR ("OWM");
if (providers == GWEATHER_PROVIDER_NONE) {
g_string_free (s, TRUE);
g_warning ("No providers enabled, failing");
@@ -157,8 +158,7 @@ main (int argc, char **argv)
if (!set_providers (info))
return 1;
gweather_info_set_location (info, loc);
- g_signal_connect (G_OBJECT (info), "updated",
- G_CALLBACK (weather_updated), loop);
+ g_signal_connect (G_OBJECT (info), "updated", G_CALLBACK (weather_updated), loop);
gweather_info_update (info);
g_main_loop_run (loop);
diff --git a/libgweather/weather-iwin.c b/libgweather/weather-iwin.c
index d7de12c6..9b420e0b 100644
--- a/libgweather/weather-iwin.c
+++ b/libgweather/weather-iwin.c
@@ -28,7 +28,7 @@ hasAttr (xmlNode *node, const char *attr_name, const char *attr_value)
if (!attr)
return res;
- res = g_str_equal ((const char *)attr, attr_value);
+ res = g_str_equal ((const char *) attr, attr_value);
xmlFree (attr);
@@ -47,8 +47,8 @@ parseForecastXml (const char *buff, GWeatherInfo *original_info)
if (!buff || !*buff)
return NULL;
- #define XC (const xmlChar *)
- #define isElem(_node,_name) g_str_equal ((const char *)_node->name, _name)
+#define XC (const xmlChar *)
+#define isElem(_node, _name) g_str_equal ((const char *) _node->name, _name)
doc = xmlParseMemory (buff, strlen (buff));
if (!doc)
@@ -63,7 +63,7 @@ parseForecastXml (const char *buff, GWeatherInfo *original_info)
if (isElem (node, "data")) {
xmlNode *n;
char *time_layout = NULL;
- gint64 update_times[7] = {0};
+ gint64 update_times[7] = { 0 };
for (n = node->children; n; n = n->next) {
if (!n->name)
@@ -79,7 +79,7 @@ parseForecastXml (const char *buff, GWeatherInfo *original_info)
xmlChar *val = xmlNodeGetContent (c);
if (val) {
- time_layout = g_strdup ((const char *)val);
+ time_layout = g_strdup ((const char *) val);
xmlFree (val);
}
} else if (c->name && isElem (c, "start-valid-time")) {
@@ -88,7 +88,7 @@ parseForecastXml (const char *buff, GWeatherInfo *original_info)
if (val) {
GDateTime *dt;
- dt = g_date_time_new_from_iso8601 ((const char *)val, NULL);
+ dt = g_date_time_new_from_iso8601 ((const char *) val, NULL);
if (dt != NULL) {
update_times[count] = g_date_time_to_unix (dt);
g_date_time_unref (dt);
@@ -120,9 +120,9 @@ parseForecastXml (const char *buff, GWeatherInfo *original_info)
if (!res) {
int i;
- for (i = 0; i < 7; i++) {
+ for (i = 0; i < 7; i++) {
GWeatherInfo *nfo = _gweather_info_new_clone (original_info);
- nfo->current_time = nfo->update = update_times[i];
+ nfo->current_time = nfo->update = update_times[i];
if (nfo)
res = g_slist_append (res, nfo);
@@ -140,7 +140,7 @@ parseForecastXml (const char *buff, GWeatherInfo *original_info)
for (c = p->children; c && at; c = c->next) {
if (isElem (c, "value")) {
- GWeatherInfo *nfo = (GWeatherInfo *)at->data;
+ GWeatherInfo *nfo = (GWeatherInfo *) at->data;
xmlChar *val = xmlNodeGetContent (c);
/* can pass some values as <value xsi:nil="true"/> */
@@ -151,9 +151,9 @@ parseForecastXml (const char *buff, GWeatherInfo *original_info)
nfo->temp_min = nfo->temp_max;
} else {
if (is_max)
- nfo->temp_max = atof ((const char *)val);
+ nfo->temp_max = atof ((const char *) val);
else
- nfo->temp_min = atof ((const char *)val);
+ nfo->temp_min = atof ((const char *) val);
}
if (val)
@@ -178,22 +178,23 @@ parseForecastXml (const char *buff, GWeatherInfo *original_info)
/* Checking from top to bottom, if 'value' contains 'name', then
that win,
thus put longer (more precise) values to the top. */
unsigned int i;
- struct _ph_list {
+ struct _ph_list
+ {
const char *name;
GWeatherConditionPhenomenon ph;
} ph_list[] = {
- { "Ice Crystals", GWEATHER_PHENOMENON_ICE_CRYSTALS } ,
- { "Volcanic Ash", GWEATHER_PHENOMENON_VOLCANIC_ASH } ,
- { "Blowing Sand", GWEATHER_PHENOMENON_SANDSTORM } ,
- { "Blowing Dust", GWEATHER_PHENOMENON_DUSTSTORM } ,
- { "Blowing Snow", GWEATHER_PHENOMENON_FUNNEL_CLOUD } ,
- { "Drizzle", GWEATHER_PHENOMENON_DRIZZLE } ,
- { "Rain", GWEATHER_PHENOMENON_RAIN } ,
- { "Snow", GWEATHER_PHENOMENON_SNOW } ,
- { "Fog", GWEATHER_PHENOMENON_FOG } ,
- { "Smoke", GWEATHER_PHENOMENON_SMOKE } ,
- { "Sand", GWEATHER_PHENOMENON_SAND } ,
- { "Haze", GWEATHER_PHENOMENON_HAZE } ,
+ { "Ice Crystals", GWEATHER_PHENOMENON_ICE_CRYSTALS },
+ { "Volcanic Ash", GWEATHER_PHENOMENON_VOLCANIC_ASH },
+ { "Blowing Sand", GWEATHER_PHENOMENON_SANDSTORM },
+ { "Blowing Dust", GWEATHER_PHENOMENON_DUSTSTORM },
+ { "Blowing Snow", GWEATHER_PHENOMENON_FUNNEL_CLOUD },
+ { "Drizzle", GWEATHER_PHENOMENON_DRIZZLE },
+ { "Rain", GWEATHER_PHENOMENON_RAIN },
+ { "Snow", GWEATHER_PHENOMENON_SNOW },
+ { "Fog", GWEATHER_PHENOMENON_FOG },
+ { "Smoke", GWEATHER_PHENOMENON_SMOKE },
+ { "Sand", GWEATHER_PHENOMENON_SAND },
+ { "Haze", GWEATHER_PHENOMENON_HAZE },
{ "Dust", GWEATHER_PHENOMENON_DUST } /*,
{ "", GWEATHER_PHENOMENON_SNOW_GRAINS } ,
{ "", GWEATHER_PHENOMENON_ICE_PELLETS } ,
@@ -206,35 +207,36 @@ parseForecastXml (const char *buff, GWeatherInfo *original_info)
{ "", GWEATHER_PHENOMENON_TORNADO } ,
{ "", GWEATHER_PHENOMENON_DUST_WHIRLS } */
};
- struct _sky_list {
+ struct _sky_list
+ {
const char *name;
GWeatherSky sky;
} sky_list[] = {
- { "Mostly Sunny", GWEATHER_SKY_BROKEN } ,
- { "Mostly Clear", GWEATHER_SKY_BROKEN } ,
- { "Partly Cloudy", GWEATHER_SKY_SCATTERED } ,
- { "Mostly Cloudy", GWEATHER_SKY_FEW } ,
- { "Sunny", GWEATHER_SKY_CLEAR } ,
- { "Clear", GWEATHER_SKY_CLEAR } ,
- { "Cloudy", GWEATHER_SKY_OVERCAST } ,
- { "Clouds", GWEATHER_SKY_SCATTERED } ,
- { "Rain", GWEATHER_SKY_SCATTERED } ,
+ { "Mostly Sunny", GWEATHER_SKY_BROKEN },
+ { "Mostly Clear", GWEATHER_SKY_BROKEN },
+ { "Partly Cloudy", GWEATHER_SKY_SCATTERED },
+ { "Mostly Cloudy", GWEATHER_SKY_FEW },
+ { "Sunny", GWEATHER_SKY_CLEAR },
+ { "Clear", GWEATHER_SKY_CLEAR },
+ { "Cloudy", GWEATHER_SKY_OVERCAST },
+ { "Clouds", GWEATHER_SKY_SCATTERED },
+ { "Rain", GWEATHER_SKY_SCATTERED },
{ "Snow", GWEATHER_SKY_SCATTERED }
};
nfo->valid = TRUE;
for (i = 0; i < G_N_ELEMENTS (ph_list); i++) {
- if (strstr ((const char *)val, ph_list [i].name)) {
+ if (strstr ((const char *) val, ph_list[i].name)) {
nfo->cond.significant = TRUE;
- nfo->cond.phenomenon = ph_list [i].ph;
+ 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)) {
- nfo->sky = sky_list [i].sky;
+ if (strstr ((const char *) val, sky_list[i].name)) {
+ nfo->sky = sky_list[i].sky;
break;
}
}
@@ -290,8 +292,8 @@ parseForecastXml (const char *buff, GWeatherInfo *original_info)
}
xmlFreeDoc (doc);
- #undef XC
- #undef isElem
+#undef XC
+#undef isElem
return res;
}
@@ -304,13 +306,15 @@ iwin_finish (SoupSession *session, SoupMessage *msg, gpointer data)
if (!SOUP_STATUS_IS_SUCCESSFUL (msg->status_code)) {
/* forecast data is not really interesting anyway ;) */
- if (msg->status_code == SOUP_STATUS_CANCELLED) {
- g_debug ("Failed to get IWIN forecast data: %d %s\n",
- msg->status_code, msg->reason_phrase);
- return;
- }
- g_warning ("Failed to get IWIN forecast data: %d %s\n",
- msg->status_code, msg->reason_phrase);
+ if (msg->status_code == SOUP_STATUS_CANCELLED) {
+ g_debug ("Failed to get IWIN forecast data: %d %s\n",
+ msg->status_code,
+ msg->reason_phrase);
+ return;
+ }
+ g_warning ("Failed to get IWIN forecast data: %d %s\n",
+ msg->status_code,
+ msg->reason_phrase);
_gweather_info_request_done (data, msg);
return;
}
@@ -347,12 +351,13 @@ iwin_start_open (GWeatherInfo *info)
(@ and : prefixes were used in the past for Australia and UK) */
if (!loc->zone || loc->zone[0] == '-' || loc->zone[0] == '@' || loc->zone[0] == ':') {
g_debug ("iwin_start_open, ignoring location %s because zone '%s' has no weather info",
- loc->name, loc->zone ? loc->zone : "(empty)");
+ loc->name,
+ loc->zone ? loc->zone : "(empty)");
return FALSE;
}
if (!loc->latlon_valid)
- return FALSE;
+ return FALSE;
/* see the description here: http://www.weather.gov/forecasts/xml/ */
now = time (NULL);
@@ -361,7 +366,11 @@ iwin_start_open (GWeatherInfo *info)
latstr = _radians_to_degrees_str (loc->latitude);
lonstr = _radians_to_degrees_str (loc->longitude);
url = g_strdup_printf
("https://www.weather.gov/forecasts/xml/sample_products/browser_interface/ndfdBrowserClientByDay.php?&lat=%s&lon=%s&format=24+hourly&startDate=%04d-%02d-%02d&numDays=7",
- latstr, lonstr, 1900 + tm.tm_year, 1 + tm.tm_mon, tm.tm_mday);
+ latstr,
+ lonstr,
+ 1900 + tm.tm_year,
+ 1 + tm.tm_mon,
+ tm.tm_mday);
g_debug ("iwin_start_open, requesting: %s", url);
msg = soup_message_new ("GET", url);
_gweather_info_begin_request (info, msg);
diff --git a/libgweather/weather-metar.c b/libgweather/weather-metar.c
index 94a77ca2..88bd86c2 100644
--- a/libgweather/weather-metar.c
+++ b/libgweather/weather-metar.c
@@ -13,7 +13,8 @@
#include <string.h>
#include <sys/types.h>
-enum {
+enum
+{
TIME_RE,
WIND_RE,
VIS_RE,
@@ -45,8 +46,8 @@ make_time (gint utcDate, gint utcHour, gint utcMin)
tm.tm_mday = utcDate;
}
tm.tm_hour = utcHour;
- tm.tm_min = utcMin;
- tm.tm_sec = 0;
+ tm.tm_min = utcMin;
+ tm.tm_sec = 0;
/* mktime() assumes value is local, not UTC. Use tm_gmtoff to compensate */
#ifdef HAVE_TM_TM_GMOFF
@@ -90,15 +91,15 @@ metar_tok_wind (gchar *tokp, GWeatherInfo *info)
gustp = strchr (tokp, 'G');
if (gustp) {
memset (sgust, 0, sizeof (sgust));
- glen = strspn (gustp + 1, CONST_DIGITS);
+ glen = strspn (gustp + 1, CONST_DIGITS);
strncpy (sgust, gustp + 1, glen);
- tokp = gustp + 1 + glen;
+ tokp = gustp + 1 + glen;
}
if (!strcmp (tokp, "MPS"))
- info->windspeed = WINDSPEED_MS_TO_KNOTS ((GWeatherWindSpeed)spd);
+ info->windspeed = WINDSPEED_MS_TO_KNOTS ((GWeatherWindSpeed) spd);
else
- info->windspeed = (GWeatherWindSpeed)spd;
+ info->windspeed = (GWeatherWindSpeed) spd;
if ((349 <= dir) || (dir <= 11))
info->wind = GWEATHER_WIND_N;
@@ -145,41 +146,41 @@ metar_tok_vis (gchar *tokp, GWeatherInfo *info)
memset (sval, 0, sizeof (sval));
- if (!strcmp (tokp,"CAVOK")) {
+ if (!strcmp (tokp, "CAVOK")) {
// "Ceiling And Visibility OK": visibility >= 10 KM
- info->visibility=10000. / VISIBILITY_SM_TO_M (1.);
+ 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') {
- info->visibility = 0.001;
- } else {
- num = (*(pfrac - 1) - '0');
- strncpy (sval, pfrac + 1, pend - pfrac - 1);
- den = atoi (sval);
- info->visibility =
- ((GWeatherVisibility)num / ((GWeatherVisibility)den));
-
- psp = strchr (tokp, ' ');
- if (psp) {
- *psp = '\0';
- val = atoi (tokp);
- info->visibility += (GWeatherVisibility)val;
- }
- }
- } else {
- strncpy (sval, tokp, pend - tokp);
+ if (*tokp == 'M') {
+ info->visibility = 0.001;
+ } else {
+ num = (*(pfrac - 1) - '0');
+ strncpy (sval, pfrac + 1, pend - pfrac - 1);
+ den = atoi (sval);
+ info->visibility =
+ ((GWeatherVisibility) num / ((GWeatherVisibility) den));
+
+ psp = strchr (tokp, ' ');
+ if (psp) {
+ *psp = '\0';
+ val = atoi (tokp);
+ info->visibility += (GWeatherVisibility) val;
+ }
+ }
+ } else {
+ strncpy (sval, tokp, pend - tokp);
val = atoi (sval);
- info->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);
- info->visibility = (GWeatherVisibility)val / VISIBILITY_SM_TO_M (1.);
+ val = atoi (sval);
+ info->visibility = (GWeatherVisibility) val / VISIBILITY_SM_TO_M (1.);
}
}
@@ -231,8 +232,8 @@ metar_tok_pres (gchar *tokp, GWeatherInfo *info)
sfract[2] = 0;
fract = atoi (sfract);
- info->pressure = (GWeatherPressure)intg + (((GWeatherPressure)fract)/100.0);
- } else { /* *tokp == 'Q' */
+ info->pressure = (GWeatherPressure) intg + (((GWeatherPressure) fract) / 100.0);
+ } else { /* *tokp == 'Q' */
gchar spres[5];
gint pres;
@@ -240,7 +241,7 @@ metar_tok_pres (gchar *tokp, GWeatherInfo *info)
spres[4] = 0;
pres = atoi (spres);
- info->pressure = PRESSURE_MBAR_TO_INCH ((GWeatherPressure)pres);
+ info->pressure = PRESSURE_MBAR_TO_INCH ((GWeatherPressure) pres);
}
}
@@ -257,20 +258,20 @@ metar_tok_temp (gchar *tokp, GWeatherInfo *info)
pdew = psep + 1;
info->temp = (*ptemp == 'M') ? TEMP_C_TO_F (-atoi (ptemp + 1))
- : TEMP_C_TO_F (atoi (ptemp));
+ : TEMP_C_TO_F (atoi (ptemp));
if (*pdew) {
- info->dew = (*pdew == 'M') ? TEMP_C_TO_F (-atoi (pdew + 1))
- : TEMP_C_TO_F (atoi (pdew));
+ info->dew = (*pdew == 'M') ? TEMP_C_TO_F (-atoi (pdew + 1))
+ : TEMP_C_TO_F (atoi (pdew));
} else {
- info->dew = -1000.0;
+ info->dew = -1000.0;
}
}
/* How "important" are the conditions to be reported to the user.
Indexed by GWeatherConditionPhenomenon */
static const int importance_scale[] = {
- 0, /* invalid */
- 0, /* none */
+ 0, /* invalid */
+ 0, /* none */
20, /* drizzle */
30, /* rain */
35, /* snow */
@@ -298,16 +299,16 @@ static const int importance_scale[] = {
static gboolean
condition_more_important (GWeatherConditions *which,
- GWeatherConditions *than)
+ GWeatherConditions *than)
{
if (!than->significant)
- return TRUE;
+ return TRUE;
if (!which->significant)
- return FALSE;
+ return FALSE;
if (importance_scale[than->phenomenon] <
- importance_scale[which->phenomenon])
- return TRUE;
+ importance_scale[which->phenomenon])
+ return TRUE;
return FALSE;
}
@@ -322,7 +323,7 @@ metar_tok_cond (gchar *tokp, GWeatherInfo *info)
g_debug ("metar_tok_cond: %s", tokp);
if ((strlen (tokp) > 3) && ((*tokp == '+') || (*tokp == '-')))
- ++tokp; /* FIX */
+ ++tokp; /* FIX */
if ((*tokp == '+') || (*tokp == '-'))
pphen = tokp + 1;
@@ -337,7 +338,7 @@ metar_tok_cond (gchar *tokp, GWeatherInfo *info)
memset (sphen, 0, sizeof (sphen));
strncpy (sphen, pphen, sizeof (sphen));
- sphen[sizeof (sphen)-1] = '\0';
+ sphen[sizeof (sphen) - 1] = '\0';
/* Defaults */
new_cond.qualifier = GWEATHER_QUALIFIER_NONE;
@@ -426,14 +427,14 @@ metar_tok_cond (gchar *tokp, GWeatherInfo *info)
new_cond.significant = TRUE;
if (condition_more_important (&new_cond, &info->cond))
- info->cond = new_cond;
+ info->cond = new_cond;
}
-#define TIME_RE_STR "([0-9]{6})Z"
-#define WIND_RE_STR "(([0-9]{3})|VRB)([0-9]?[0-9]{2})(G[0-9]?[0-9]{2})?(KT|MPS)"
-#define VIS_RE_STR "((([0-9]?[0-9])|(M?([12] )?([1357]/1?[0-9])))SM)|" \
- "([0-9]{4}(N|NE|E|SE|S|SW|W|NW( [0-9]{4}(N|NE|E|SE|S|SW|W|NW))?)?)|" \
- "CAVOK"
+#define TIME_RE_STR "([0-9]{6})Z"
+#define WIND_RE_STR "(([0-9]{3})|VRB)([0-9]?[0-9]{2})(G[0-9]?[0-9]{2})?(KT|MPS)"
+#define VIS_RE_STR "((([0-9]?[0-9])|(M?([12] )?([1357]/1?[0-9])))SM)|" \
+ "([0-9]{4}(N|NE|E|SE|S|SW|W|NW( [0-9]{4}(N|NE|E|SE|S|SW|W|NW))?)?)|" \
+ "CAVOK"
#define COND_RE_STR
"(-|\\+)?(VC|MI|BC|PR|TS|BL|SH|DR|FZ)?(DZ|RA|SN|SG|IC|PE|GR|GS|UP|BR|FG|FU|VA|SA|HZ|PY|DU|SQ|SS|DS|PO|\\+?FC)"
#define CLOUD_RE_STR "((CLR|BKN|SCT|FEW|OVC|SKC|NSC)([0-9]{3}|///)?(CB|TCU|///)?)"
#define TEMP_RE_STR "(M?[0-9][0-9])/(M?(//|[0-9][0-9])?)"
@@ -505,21 +506,22 @@ metar_parse (gchar *metar, GWeatherInfo *info)
int token_start, token_end;
i2 = RE_NUM;
- token_start = strlen(p);
+ token_start = strlen (p);
token_end = token_start;
for (i = 0; i < RE_NUM; i++) {
GMatchInfo *match_info;
- if (g_regex_match_full (metar_re[i], p, -1, 0, 0, &match_info, NULL))
- {
+ if (g_regex_match_full (metar_re[i], p, -1, 0, 0, &match_info, NULL)) {
int tmp_token_start, tmp_token_end;
/* Skip leading and trailing space characters, if present.
(the regular expressions include those characters to
only get matches limited to whole words). */
g_match_info_fetch_pos (match_info, 0, &tmp_token_start, &tmp_token_end);
- if (p[tmp_token_start] == ' ') tmp_token_start++;
- if (p[tmp_token_end - 1] == ' ') tmp_token_end--;
+ if (p[tmp_token_start] == ' ')
+ tmp_token_start++;
+ if (p[tmp_token_end - 1] == ' ')
+ tmp_token_end--;
/* choose the regular expression with the earliest match */
if (tmp_token_start < token_start) {
@@ -534,7 +536,7 @@ metar_parse (gchar *metar, GWeatherInfo *info)
if (i2 != RE_NUM) {
tokp = g_strndup (p + token_start, token_end - token_start);
- metar_f[i2] (tokp, info);
+ metar_f[i2](tokp, info);
g_free (tokp);
}
@@ -555,22 +557,24 @@ metar_finish (SoupSession *session, SoupMessage *msg, gpointer data)
if (!SOUP_STATUS_IS_SUCCESSFUL (msg->status_code)) {
if (msg->status_code == SOUP_STATUS_CANCELLED) {
- g_debug ("Failed to get METAR data: %d %s.\n",
- msg->status_code, msg->reason_phrase);
- return;
- }
-
- info = data;
- if (SOUP_STATUS_IS_TRANSPORT_ERROR (msg->status_code)) {
- 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"),
- msg->status_code, msg->reason_phrase);
- }
-
- _gweather_info_request_done (info, msg);
- return;
+ g_debug ("Failed to get METAR data: %d %s.\n",
+ msg->status_code,
+ msg->reason_phrase);
+ return;
+ }
+
+ info = data;
+ if (SOUP_STATUS_IS_TRANSPORT_ERROR (msg->status_code)) {
+ 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"),
+ msg->status_code,
+ msg->reason_phrase);
+ }
+
+ _gweather_info_request_done (info, msg);
+ return;
}
info = data;
@@ -583,27 +587,27 @@ metar_finish (SoupSession *session, SoupMessage *msg, gpointer data)
p = strstr (msg->response_body->data, searchkey);
if (p) {
- p += strlen (searchkey);
- eoln = strstr (p, "</raw_text>");
- if (eoln)
- metar = g_strndup (p, eoln - p);
- else
- metar = g_strdup (p);
- success = metar_parse (metar, info);
- g_free (metar);
- if (success)
- g_debug ("Successfully parsed METAR for %s", loc->code);
- else
- g_debug ("Failed to parse raw_text METAR for %s", loc->code);
+ p += strlen (searchkey);
+ eoln = strstr (p, "</raw_text>");
+ if (eoln)
+ metar = g_strndup (p, eoln - p);
+ else
+ metar = g_strdup (p);
+ success = metar_parse (metar, info);
+ g_free (metar);
+ if (success)
+ g_debug ("Successfully parsed METAR for %s", loc->code);
+ else
+ g_debug ("Failed to parse raw_text METAR for %s", loc->code);
} else if (!strstr (msg->response_body->data, "aviationweather.gov")) {
- /* The response doesn't even seem to have come from NOAA...
+ /* The response doesn't even seem to have come from NOAA...
* most likely it is a wifi hotspot login page. Call that a
* network error.
*/
- info->network_error = TRUE;
- g_debug ("Response to query for %s did not come from correct server", loc->code);
+ 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);
+ g_debug ("Failed to parse METAR for %s", loc->code);
}
g_free (searchkey);
@@ -630,15 +634,23 @@ metar_start_open (GWeatherInfo *info)
g_debug ("metar_start_open, requesting:
https://www.aviationweather.gov/adds/dataserver_current/httpparam?dataSource=metars&requestType=retrieve&format=xml&hoursBeforeNow=3&mostRecent=true&fields=raw_text&stationString=%s",
loc->code);
msg = soup_form_request_new (
- "GET", "https://www.aviationweather.gov/adds/dataserver_current/httpparam",
- "dataSource", "metars",
- "requestType", "retrieve",
- "format", "xml",
- "hoursBeforeNow", "3",
- "mostRecent", "true",
- "fields", "raw_text",
- "stationString", loc->code,
- NULL);
+ "GET",
+ "https://www.aviationweather.gov/adds/dataserver_current/httpparam",
+ "dataSource",
+ "metars",
+ "requestType",
+ "retrieve",
+ "format",
+ "xml",
+ "hoursBeforeNow",
+ "3",
+ "mostRecent",
+ "true",
+ "fields",
+ "raw_text",
+ "stationString",
+ loc->code,
+ NULL);
_gweather_info_begin_request (info, msg);
soup_session_queue_message (info->session, msg, metar_finish, info);
}
diff --git a/libgweather/weather-metno.c b/libgweather/weather-metno.c
index d5b09bd6..8a044908 100644
--- a/libgweather/weather-metno.c
+++ b/libgweather/weather-metno.c
@@ -8,10 +8,10 @@
#include "gweather-private.h"
-#include <time.h>
+#include <stdio.h>
#include <stdlib.h>
#include <string.h>
-#include <stdio.h>
+#include <time.h>
#include <glib.h>
@@ -19,63 +19,65 @@
#include <libxml/xpath.h>
#include <libxml/xpathInternals.h>
-#define XC(t) ((const xmlChar *)(t))
+#define XC(t) ((const xmlChar *) (t))
/* As per https://gitlab.gnome.org/GNOME/libgweather/-/issues/59#note_1004747 */
#define API_ENDPOINT_DOMAIN "aa037rv1tsaszxi6o.api.met.no"
/* Reference for symbols at https://api.met.no/weatherapi/weathericon/2.0/ */
-typedef struct {
+typedef struct
+{
const char *code;
GWeatherSky sky;
GWeatherConditions condition;
} MetnoSymbol;
static MetnoSymbol symbols[] = {
- { "clearsky", GWEATHER_SKY_CLEAR, { FALSE, GWEATHER_PHENOMENON_NONE, GWEATHER_QUALIFIER_NONE } },
/* Sun */
- { "fair", GWEATHER_SKY_BROKEN, { FALSE, GWEATHER_PHENOMENON_NONE, GWEATHER_QUALIFIER_NONE } }, /*
LightCloud */
- { "partlycloudy", GWEATHER_SKY_SCATTERED, { FALSE, GWEATHER_PHENOMENON_NONE, GWEATHER_QUALIFIER_NONE }
}, /* PartlyCloudy */
- { "cloudy", GWEATHER_SKY_OVERCAST, { FALSE, GWEATHER_PHENOMENON_NONE, GWEATHER_QUALIFIER_NONE } }, /*
Cloudy */
- { "rainshowers", GWEATHER_SKY_BROKEN, { TRUE, GWEATHER_PHENOMENON_RAIN, GWEATHER_QUALIFIER_LIGHT }
}, /* LightRainSun */
- { "rainshowersandthunder", GWEATHER_SKY_BROKEN, { TRUE, GWEATHER_PHENOMENON_RAIN,
GWEATHER_QUALIFIER_THUNDERSTORM } }, /* LightRainThunderSun */
- { "sleetshowers", GWEATHER_SKY_BROKEN, { TRUE, GWEATHER_PHENOMENON_ICE_PELLETS,
GWEATHER_QUALIFIER_NONE } }, /* SleetSun */
- { "snowshowers", GWEATHER_SKY_BROKEN, { TRUE, GWEATHER_PHENOMENON_SNOW, GWEATHER_QUALIFIER_NONE } },
/* SnowSun */
- { "rain", GWEATHER_SKY_OVERCAST, { TRUE, GWEATHER_PHENOMENON_RAIN, GWEATHER_QUALIFIER_LIGHT } }, /*
SnowSun */
- { "heavyrain", GWEATHER_SKY_OVERCAST, { TRUE, GWEATHER_PHENOMENON_RAIN, GWEATHER_QUALIFIER_NONE } }, /*
Rain */
- { "heavyrainandthunder", GWEATHER_SKY_OVERCAST, { TRUE, GWEATHER_PHENOMENON_RAIN,
GWEATHER_QUALIFIER_THUNDERSTORM } }, /* RainThunder */
- { "sleet", GWEATHER_SKY_OVERCAST, { TRUE, GWEATHER_PHENOMENON_ICE_PELLETS, GWEATHER_QUALIFIER_NONE } },
/* Sleet */
- { "snow", GWEATHER_SKY_OVERCAST, { TRUE, GWEATHER_PHENOMENON_SNOW, GWEATHER_QUALIFIER_NONE } }, /* Snow
*/
- { "snowandthunder", GWEATHER_SKY_OVERCAST, { TRUE, GWEATHER_PHENOMENON_SNOW,
GWEATHER_QUALIFIER_THUNDERSTORM } }, /* SnowThunder */
- { "fog", GWEATHER_SKY_CLEAR, { TRUE, GWEATHER_PHENOMENON_FOG, GWEATHER_QUALIFIER_NONE } }, /* Fog */
- { "sleetshowersandthunder", GWEATHER_SKY_BROKEN, { TRUE, GWEATHER_PHENOMENON_ICE_PELLETS,
GWEATHER_QUALIFIER_THUNDERSTORM } }, /* SleetSunThunder */
- { "snowshowersandthunder", GWEATHER_SKY_BROKEN, { TRUE, GWEATHER_PHENOMENON_SNOW,
GWEATHER_QUALIFIER_THUNDERSTORM } }, /* SnowSunThunder */
- { "rainandthunder", GWEATHER_SKY_OVERCAST, { TRUE, GWEATHER_PHENOMENON_RAIN,
GWEATHER_QUALIFIER_THUNDERSTORM } }, /* LightRainThunder */
- { "sleetandthunder", GWEATHER_SKY_OVERCAST, { TRUE, GWEATHER_PHENOMENON_ICE_PELLETS,
GWEATHER_QUALIFIER_THUNDERSTORM } }, /* SleetThunder */
- { "lightrainshowersandthunder", GWEATHER_SKY_BROKEN, { TRUE, GWEATHER_PHENOMENON_DRIZZLE,
GWEATHER_QUALIFIER_THUNDERSTORM } }, /* DrizzleThunderSun */
- { "heavyrainshowersandthunder", GWEATHER_SKY_BROKEN, { TRUE, GWEATHER_PHENOMENON_RAIN,
GWEATHER_QUALIFIER_THUNDERSTORM } }, /* RainThunderSun */
- { "lightssleetshowersandthunder", GWEATHER_SKY_BROKEN, { TRUE, GWEATHER_PHENOMENON_ICE_PELLETS,
GWEATHER_QUALIFIER_LIGHT } }, /* LightSleetThunderSun */
- { "heavysleetshowersandthunder", GWEATHER_SKY_BROKEN, { TRUE, GWEATHER_PHENOMENON_ICE_PELLETS,
GWEATHER_QUALIFIER_HEAVY } }, /* HeavySleetThunderSun */
- { "lightssnowshowersandthunder", GWEATHER_SKY_BROKEN, { TRUE, GWEATHER_PHENOMENON_SNOW,
GWEATHER_QUALIFIER_LIGHT } }, /* LightSnowThunderSun */
- { "heavysnowshowersandthunder", GWEATHER_SKY_BROKEN, { TRUE, GWEATHER_PHENOMENON_SNOW,
GWEATHER_QUALIFIER_HEAVY } }, /* HeavySnowThunderSun */
- { "lightrainandthunder", GWEATHER_SKY_OVERCAST, { TRUE, GWEATHER_PHENOMENON_DRIZZLE,
GWEATHER_QUALIFIER_THUNDERSTORM } }, /* DrizzleThunder */
- { "lightsleetandthunder", GWEATHER_SKY_OVERCAST, { TRUE, GWEATHER_PHENOMENON_ICE_PELLETS,
GWEATHER_QUALIFIER_LIGHT } }, /* LightSleetThunder */
- { "heavysleetandthunder", GWEATHER_SKY_OVERCAST, { TRUE, GWEATHER_PHENOMENON_ICE_PELLETS,
GWEATHER_QUALIFIER_HEAVY } }, /* HeavySleetThunder */
- { "lightsnowandthunder", GWEATHER_SKY_OVERCAST, { TRUE, GWEATHER_PHENOMENON_SNOW,
GWEATHER_QUALIFIER_LIGHT } }, /* LightSnowThunder */
- { "heavysnowandthunder", GWEATHER_SKY_OVERCAST, { TRUE, GWEATHER_PHENOMENON_SNOW,
GWEATHER_QUALIFIER_HEAVY } }, /* HeavySnowThunder */
- { "lightrainshowers", GWEATHER_SKY_BROKEN, { TRUE, GWEATHER_PHENOMENON_DRIZZLE,
GWEATHER_QUALIFIER_NONE } }, /* DrizzleSun */
- { "heavyrainshowers", GWEATHER_SKY_BROKEN, { TRUE, GWEATHER_PHENOMENON_RAIN, GWEATHER_QUALIFIER_NONE
} }, /* RainSun */
- { "lightsleetshowers", GWEATHER_SKY_BROKEN, { TRUE, GWEATHER_PHENOMENON_ICE_PELLETS,
GWEATHER_QUALIFIER_LIGHT } }, /* LightSleetSun */
- { "heavysleetshowers", GWEATHER_SKY_BROKEN, { TRUE, GWEATHER_PHENOMENON_ICE_PELLETS,
GWEATHER_QUALIFIER_HEAVY } }, /* HeavySleetSun */
- { "lightsnowshowers", GWEATHER_SKY_BROKEN, { TRUE, GWEATHER_PHENOMENON_SNOW, GWEATHER_QUALIFIER_LIGHT
} }, /* LightSnowSun */
- { "heavysnowshowers", GWEATHER_SKY_BROKEN, { TRUE, GWEATHER_PHENOMENON_SNOW, GWEATHER_QUALIFIER_HEAVY
} }, /* HeavySnowSun */
- { "lightrain", GWEATHER_SKY_OVERCAST, { TRUE, GWEATHER_PHENOMENON_DRIZZLE, GWEATHER_QUALIFIER_NONE }
}, /* Drizzle */
- { "lightsleet", GWEATHER_SKY_OVERCAST, { TRUE, GWEATHER_PHENOMENON_ICE_PELLETS,
GWEATHER_QUALIFIER_LIGHT } }, /* LightSleet */
- { "heavysleet", GWEATHER_SKY_OVERCAST, { TRUE, GWEATHER_PHENOMENON_ICE_PELLETS,
GWEATHER_QUALIFIER_HEAVY } }, /* HeavySleet */
- { "lightsnow", GWEATHER_SKY_OVERCAST, { TRUE, GWEATHER_PHENOMENON_SNOW, GWEATHER_QUALIFIER_LIGHT } },
/* LightSnow */
- { "heavysnow", GWEATHER_SKY_OVERCAST, { TRUE, GWEATHER_PHENOMENON_SNOW, GWEATHER_QUALIFIER_HEAVY } }
/* HeavySnow */
+ { "clearsky", GWEATHER_SKY_CLEAR, { FALSE, GWEATHER_PHENOMENON_NONE, GWEATHER_QUALIFIER_NONE } },
/* Sun */
+ { "fair", GWEATHER_SKY_BROKEN, { FALSE, GWEATHER_PHENOMENON_NONE, GWEATHER_QUALIFIER_NONE } },
/* LightCloud */
+ { "partlycloudy", GWEATHER_SKY_SCATTERED, { FALSE, GWEATHER_PHENOMENON_NONE, GWEATHER_QUALIFIER_NONE }
}, /* PartlyCloudy */
+ { "cloudy", GWEATHER_SKY_OVERCAST, { FALSE, GWEATHER_PHENOMENON_NONE, GWEATHER_QUALIFIER_NONE } },
/* Cloudy */
+ { "rainshowers", GWEATHER_SKY_BROKEN, { TRUE, GWEATHER_PHENOMENON_RAIN, GWEATHER_QUALIFIER_LIGHT } },
/* LightRainSun */
+ { "rainshowersandthunder", GWEATHER_SKY_BROKEN, { TRUE, GWEATHER_PHENOMENON_RAIN,
GWEATHER_QUALIFIER_THUNDERSTORM } }, /* LightRainThunderSun */
+ { "sleetshowers", GWEATHER_SKY_BROKEN, { TRUE, GWEATHER_PHENOMENON_ICE_PELLETS, GWEATHER_QUALIFIER_NONE
} }, /* SleetSun */
+ { "snowshowers", GWEATHER_SKY_BROKEN, { TRUE, GWEATHER_PHENOMENON_SNOW, GWEATHER_QUALIFIER_NONE } },
/* SnowSun */
+ { "rain", GWEATHER_SKY_OVERCAST, { TRUE, GWEATHER_PHENOMENON_RAIN, GWEATHER_QUALIFIER_LIGHT } },
/* SnowSun */
+ { "heavyrain", GWEATHER_SKY_OVERCAST, { TRUE, GWEATHER_PHENOMENON_RAIN, GWEATHER_QUALIFIER_NONE } },
/* Rain */
+ { "heavyrainandthunder", GWEATHER_SKY_OVERCAST, { TRUE, GWEATHER_PHENOMENON_RAIN,
GWEATHER_QUALIFIER_THUNDERSTORM } }, /* RainThunder */
+ { "sleet", GWEATHER_SKY_OVERCAST, { TRUE, GWEATHER_PHENOMENON_ICE_PELLETS, GWEATHER_QUALIFIER_NONE } },
/* Sleet */
+ { "snow", GWEATHER_SKY_OVERCAST, { TRUE, GWEATHER_PHENOMENON_SNOW, GWEATHER_QUALIFIER_NONE } },
/* Snow */
+ { "snowandthunder", GWEATHER_SKY_OVERCAST, { TRUE, GWEATHER_PHENOMENON_SNOW,
GWEATHER_QUALIFIER_THUNDERSTORM } }, /* SnowThunder */
+ { "fog", GWEATHER_SKY_CLEAR, { TRUE, GWEATHER_PHENOMENON_FOG, GWEATHER_QUALIFIER_NONE } },
/* Fog */
+ { "sleetshowersandthunder", GWEATHER_SKY_BROKEN, { TRUE, GWEATHER_PHENOMENON_ICE_PELLETS,
GWEATHER_QUALIFIER_THUNDERSTORM } }, /* SleetSunThunder */
+ { "snowshowersandthunder", GWEATHER_SKY_BROKEN, { TRUE, GWEATHER_PHENOMENON_SNOW,
GWEATHER_QUALIFIER_THUNDERSTORM } }, /* SnowSunThunder */
+ { "rainandthunder", GWEATHER_SKY_OVERCAST, { TRUE, GWEATHER_PHENOMENON_RAIN,
GWEATHER_QUALIFIER_THUNDERSTORM } }, /* LightRainThunder */
+ { "sleetandthunder", GWEATHER_SKY_OVERCAST, { TRUE, GWEATHER_PHENOMENON_ICE_PELLETS,
GWEATHER_QUALIFIER_THUNDERSTORM } }, /* SleetThunder */
+ { "lightrainshowersandthunder", GWEATHER_SKY_BROKEN, { TRUE, GWEATHER_PHENOMENON_DRIZZLE,
GWEATHER_QUALIFIER_THUNDERSTORM } }, /* DrizzleThunderSun */
+ { "heavyrainshowersandthunder", GWEATHER_SKY_BROKEN, { TRUE, GWEATHER_PHENOMENON_RAIN,
GWEATHER_QUALIFIER_THUNDERSTORM } }, /* RainThunderSun */
+ { "lightssleetshowersandthunder", GWEATHER_SKY_BROKEN, { TRUE, GWEATHER_PHENOMENON_ICE_PELLETS,
GWEATHER_QUALIFIER_LIGHT } }, /* LightSleetThunderSun */
+ { "heavysleetshowersandthunder", GWEATHER_SKY_BROKEN, { TRUE, GWEATHER_PHENOMENON_ICE_PELLETS,
GWEATHER_QUALIFIER_HEAVY } }, /* HeavySleetThunderSun */
+ { "lightssnowshowersandthunder", GWEATHER_SKY_BROKEN, { TRUE, GWEATHER_PHENOMENON_SNOW,
GWEATHER_QUALIFIER_LIGHT } }, /* LightSnowThunderSun */
+ { "heavysnowshowersandthunder", GWEATHER_SKY_BROKEN, { TRUE, GWEATHER_PHENOMENON_SNOW,
GWEATHER_QUALIFIER_HEAVY } }, /* HeavySnowThunderSun */
+ { "lightrainandthunder", GWEATHER_SKY_OVERCAST, { TRUE, GWEATHER_PHENOMENON_DRIZZLE,
GWEATHER_QUALIFIER_THUNDERSTORM } }, /* DrizzleThunder */
+ { "lightsleetandthunder", GWEATHER_SKY_OVERCAST, { TRUE, GWEATHER_PHENOMENON_ICE_PELLETS,
GWEATHER_QUALIFIER_LIGHT } }, /* LightSleetThunder */
+ { "heavysleetandthunder", GWEATHER_SKY_OVERCAST, { TRUE, GWEATHER_PHENOMENON_ICE_PELLETS,
GWEATHER_QUALIFIER_HEAVY } }, /* HeavySleetThunder */
+ { "lightsnowandthunder", GWEATHER_SKY_OVERCAST, { TRUE, GWEATHER_PHENOMENON_SNOW,
GWEATHER_QUALIFIER_LIGHT } }, /* LightSnowThunder */
+ { "heavysnowandthunder", GWEATHER_SKY_OVERCAST, { TRUE, GWEATHER_PHENOMENON_SNOW,
GWEATHER_QUALIFIER_HEAVY } }, /* HeavySnowThunder */
+ { "lightrainshowers", GWEATHER_SKY_BROKEN, { TRUE, GWEATHER_PHENOMENON_DRIZZLE, GWEATHER_QUALIFIER_NONE
} }, /* DrizzleSun */
+ { "heavyrainshowers", GWEATHER_SKY_BROKEN, { TRUE, GWEATHER_PHENOMENON_RAIN, GWEATHER_QUALIFIER_NONE }
}, /* RainSun */
+ { "lightsleetshowers", GWEATHER_SKY_BROKEN, { TRUE, GWEATHER_PHENOMENON_ICE_PELLETS,
GWEATHER_QUALIFIER_LIGHT } }, /* LightSleetSun */
+ { "heavysleetshowers", GWEATHER_SKY_BROKEN, { TRUE, GWEATHER_PHENOMENON_ICE_PELLETS,
GWEATHER_QUALIFIER_HEAVY } }, /* HeavySleetSun */
+ { "lightsnowshowers", GWEATHER_SKY_BROKEN, { TRUE, GWEATHER_PHENOMENON_SNOW, GWEATHER_QUALIFIER_LIGHT }
}, /* LightSnowSun */
+ { "heavysnowshowers", GWEATHER_SKY_BROKEN, { TRUE, GWEATHER_PHENOMENON_SNOW, GWEATHER_QUALIFIER_HEAVY }
}, /* HeavySnowSun */
+ { "lightrain", GWEATHER_SKY_OVERCAST, { TRUE, GWEATHER_PHENOMENON_DRIZZLE, GWEATHER_QUALIFIER_NONE } },
/* Drizzle */
+ { "lightsleet", GWEATHER_SKY_OVERCAST, { TRUE, GWEATHER_PHENOMENON_ICE_PELLETS, GWEATHER_QUALIFIER_LIGHT
} }, /* LightSleet */
+ { "heavysleet", GWEATHER_SKY_OVERCAST, { TRUE, GWEATHER_PHENOMENON_ICE_PELLETS, GWEATHER_QUALIFIER_HEAVY
} }, /* HeavySleet */
+ { "lightsnow", GWEATHER_SKY_OVERCAST, { TRUE, GWEATHER_PHENOMENON_SNOW, GWEATHER_QUALIFIER_LIGHT } },
/* LightSnow */
+ { "heavysnow", GWEATHER_SKY_OVERCAST, { TRUE, GWEATHER_PHENOMENON_SNOW, GWEATHER_QUALIFIER_HEAVY } }
/* HeavySnow */
};
-static struct {
+static struct
+{
const char *name;
GWeatherWindDirection direction;
} wind_directions[] = {
@@ -98,7 +100,7 @@ static struct {
};
static time_t
-date_to_time_t (const xmlChar *str, const char * tzid)
+date_to_time_t (const xmlChar *str, const char *tzid)
{
struct tm time = { 0 };
GTimeZone *tz;
@@ -106,26 +108,26 @@ date_to_time_t (const xmlChar *str, const char * tzid)
time_t rval;
char *after;
- after = strptime ((const char*) str, "%Y-%m-%dT%T", &time);
+ after = strptime ((const char *) str, "%Y-%m-%dT%T", &time);
if (after == NULL) {
- g_warning ("Cannot parse date string \"%s\"", str);
- return 0;
+ g_warning ("Cannot parse date string \"%s\"", str);
+ return 0;
}
if (*after == 'Z')
- tzid = "UTC";
+ tzid = "UTC";
tz = g_time_zone_new_identifier (tzid);
if (tz == NULL)
tz = g_time_zone_new_utc ();
dt = g_date_time_new (tz,
- time.tm_year + 1900,
- time.tm_mon + 1,
- time.tm_mday,
- time.tm_hour,
- time.tm_min,
- time.tm_sec);
+ time.tm_year + 1900,
+ time.tm_mon + 1,
+ time.tm_mday,
+ time.tm_hour,
+ time.tm_min,
+ time.tm_sec);
rval = g_date_time_to_unix (dt);
@@ -155,105 +157,105 @@ symbol_search (const char *code)
static inline void
read_symbol (GWeatherInfo *info,
- xmlNodePtr node)
+ xmlNodePtr node)
{
xmlChar *val;
- MetnoSymbol* symbol;
+ MetnoSymbol *symbol;
- val = xmlGetProp (node, XC("code"));
+ val = xmlGetProp (node, XC ("code"));
- symbol = symbol_search ((char *)val);
+ symbol = symbol_search ((char *) val);
if (symbol != NULL) {
- info->valid = TRUE;
- info->sky = symbol->sky;
- info->cond = symbol->condition;
+ info->valid = TRUE;
+ info->sky = symbol->sky;
+ info->cond = symbol->condition;
}
xmlFree (val);
}
static inline void
read_wind_direction (GWeatherInfo *info,
- xmlNodePtr node)
+ xmlNodePtr node)
{
xmlChar *val;
unsigned int i;
- val = xmlGetProp (node, XC("code"));
+ val = xmlGetProp (node, XC ("code"));
if (val == NULL)
- val = xmlGetProp (node, XC("name"));
+ val = xmlGetProp (node, XC ("name"));
if (val == NULL)
- return;
+ return;
for (i = 0; i < G_N_ELEMENTS (wind_directions); i++) {
- if (strcmp ((char*) val, wind_directions[i].name) == 0) {
- info->wind = wind_directions[i].direction;
+ if (strcmp ((char *) val, wind_directions[i].name) == 0) {
+ info->wind = wind_directions[i].direction;
xmlFree (val);
- return;
- }
+ return;
+ }
}
xmlFree (val);
}
static inline void
read_wind_speed (GWeatherInfo *info,
- xmlNodePtr node)
+ xmlNodePtr node)
{
xmlChar *val;
double mps;
- val = xmlGetProp (node, XC("mps"));
+ val = xmlGetProp (node, XC ("mps"));
if (val == NULL)
- return;
+ return;
- mps = g_ascii_strtod ((char*) val, NULL);
+ mps = g_ascii_strtod ((char *) val, NULL);
info->windspeed = WINDSPEED_MS_TO_KNOTS (mps);
xmlFree (val);
}
static inline void
read_temperature (GWeatherInfo *info,
- xmlNodePtr node)
+ xmlNodePtr node)
{
xmlChar *val;
double celsius;
- val = xmlGetProp (node, XC("value"));
+ val = xmlGetProp (node, XC ("value"));
if (val == NULL)
- return;
+ return;
- celsius = g_ascii_strtod ((char*) val, NULL);
+ celsius = g_ascii_strtod ((char *) val, NULL);
info->temp = TEMP_C_TO_F (celsius);
xmlFree (val);
}
static inline void
read_pressure (GWeatherInfo *info,
- xmlNodePtr node)
+ xmlNodePtr node)
{
xmlChar *val;
double hpa;
- val = xmlGetProp (node, XC("value"));
+ val = xmlGetProp (node, XC ("value"));
if (val == NULL)
- return;
+ return;
- hpa = g_ascii_strtod ((char*) val, NULL);
+ hpa = g_ascii_strtod ((char *) val, NULL);
info->pressure = PRESSURE_MBAR_TO_INCH (hpa);
xmlFree (val);
}
static inline void
read_humidity (GWeatherInfo *info,
- xmlNodePtr node)
+ xmlNodePtr node)
{
xmlChar *val;
double percent;
- val = xmlGetProp (node, XC("value"));
+ val = xmlGetProp (node, XC ("value"));
if (val == NULL)
- return;
+ return;
- percent = g_ascii_strtod ((char*) val, NULL);
+ percent = g_ascii_strtod ((char *) val, NULL);
info->humidity = percent;
info->hasHumidity = TRUE;
xmlFree (val);
@@ -261,37 +263,37 @@ read_humidity (GWeatherInfo *info,
static inline void
read_child_node (GWeatherInfo *info,
- xmlNodePtr node)
+ xmlNodePtr node)
{
- if (strcmp ((char*) node->name, "symbol") == 0)
- read_symbol (info, node);
- else if (strcmp ((char*) node->name, "windDirection") == 0)
- read_wind_direction (info, node);
- else if (strcmp ((char*) node->name, "windSpeed") == 0)
- read_wind_speed (info, node);
- else if (strcmp ((char*) node->name, "temperature") == 0)
- read_temperature (info, node);
- else if (strcmp ((char*) node->name, "pressure") == 0)
- read_pressure (info, node);
- else if (strcmp ((char*) node->name, "humidity") == 0)
- read_humidity (info, node);
+ if (strcmp ((char *) node->name, "symbol") == 0)
+ read_symbol (info, node);
+ else if (strcmp ((char *) node->name, "windDirection") == 0)
+ read_wind_direction (info, node);
+ else if (strcmp ((char *) node->name, "windSpeed") == 0)
+ read_wind_speed (info, node);
+ else if (strcmp ((char *) node->name, "temperature") == 0)
+ read_temperature (info, node);
+ else if (strcmp ((char *) node->name, "pressure") == 0)
+ read_pressure (info, node);
+ else if (strcmp ((char *) node->name, "humidity") == 0)
+ read_humidity (info, node);
}
static inline void
fill_info_from_node (GWeatherInfo *info,
- xmlNodePtr node)
+ xmlNodePtr node)
{
xmlNodePtr child;
for (child = node->children; child != NULL; child = child->next) {
- if (child->type == XML_ELEMENT_NODE)
- read_child_node (info, child);
+ if (child->type == XML_ELEMENT_NODE)
+ read_child_node (info, child);
}
}
static void
-parse_forecast_xml_new (GWeatherInfo *original_info,
- SoupMessageBody *body)
+parse_forecast_xml_new (GWeatherInfo *original_info,
+ SoupMessageBody *body)
{
xmlDocPtr doc;
xmlXPathContextPtr xpath_ctx;
@@ -300,32 +302,32 @@ parse_forecast_xml_new (GWeatherInfo *original_info,
doc = xmlParseMemory (body->data, body->length);
if (!doc)
- return;
+ return;
xpath_ctx = xmlXPathNewContext (doc);
- xpath_result = xmlXPathEval (XC("/weatherdata/product/time"), xpath_ctx);
+ xpath_result = xmlXPathEval (XC ("/weatherdata/product/time"), xpath_ctx);
if (!xpath_result || xpath_result->type != XPATH_NODESET)
- goto out;
+ goto out;
for (i = 0; i < xpath_result->nodesetval->nodeNr; i++) {
- xmlNodePtr node;
- GWeatherInfo *info;
- xmlChar *val;
- time_t from_time, to_time;
- xmlNode *location;
+ xmlNodePtr node;
+ GWeatherInfo *info;
+ xmlChar *val;
+ time_t from_time, to_time;
+ xmlNode *location;
- node = xpath_result->nodesetval->nodeTab[i];
+ node = xpath_result->nodesetval->nodeTab[i];
- val = xmlGetProp (node, XC("from"));
- from_time = date_to_time_t (val, original_info->location.tz_hint);
- xmlFree (val);
+ val = xmlGetProp (node, XC ("from"));
+ from_time = date_to_time_t (val, original_info->location.tz_hint);
+ xmlFree (val);
- val = xmlGetProp (node, XC("to"));
- to_time = date_to_time_t (val, original_info->location.tz_hint);
- xmlFree (val);
+ val = xmlGetProp (node, XC ("to"));
+ to_time = date_to_time_t (val, original_info->location.tz_hint);
+ xmlFree (val);
- /* The legacy XML API has forecast in a list of "parent" elements
+ /* The legacy XML API has forecast in a list of "parent" elements
with details (indicated by from==to) and "children" elements
that hold only precipitation and symbol. For our purpose,
the parent element is enough, except that we actually
@@ -333,29 +335,31 @@ parse_forecast_xml_new (GWeatherInfo *original_info,
Additionally, compared to the old API the new API has one
<location> element inside each <time> element.
*/
- if (from_time == to_time) {
- info = _gweather_info_new_clone (original_info);
- info->current_time = info->update = from_time;
-
- for (location = node->children;
- location && location->type != XML_ELEMENT_NODE;
- location = location->next);
- if (location)
- fill_info_from_node (info, location);
-
- if (i < xpath_result->nodesetval->nodeNr - 1) {
- i++;
- node = xpath_result->nodesetval->nodeTab[i];
-
- for (location = node->children;
- location && location->type != XML_ELEMENT_NODE;
- location = location->next);
- if (location)
- fill_info_from_node (info, location);
- }
-
- original_info->forecast_list = g_slist_append (original_info->forecast_list, info);
- }
+ if (from_time == to_time) {
+ info = _gweather_info_new_clone (original_info);
+ info->current_time = info->update = from_time;
+
+ for (location = node->children;
+ location && location->type != XML_ELEMENT_NODE;
+ location = location->next)
+ ;
+ if (location)
+ fill_info_from_node (info, location);
+
+ if (i < xpath_result->nodesetval->nodeNr - 1) {
+ i++;
+ node = xpath_result->nodesetval->nodeTab[i];
+
+ for (location = node->children;
+ location && location->type != XML_ELEMENT_NODE;
+ location = location->next)
+ ;
+ if (location)
+ fill_info_from_node (info, location);
+ }
+
+ original_info->forecast_list = g_slist_append (original_info->forecast_list, info);
+ }
}
xmlXPathFreeObject (xpath_result);
@@ -366,33 +370,35 @@ parse_forecast_xml_new (GWeatherInfo *original_info,
That's very nice of them!
*/
- original_info->forecast_attribution = g_strdup(_("Weather data from the <a
href=\"https://www.met.no/\">Norwegian Meteorological Institute</a>."));
+ original_info->forecast_attribution = g_strdup (_ ("Weather data from the <a
href=\"https://www.met.no/\">Norwegian Meteorological Institute</a>."));
- out:
+out:
xmlXPathFreeContext (xpath_ctx);
xmlFreeDoc (doc);
}
static void
metno_finish_new (SoupSession *session,
- SoupMessage *msg,
- gpointer user_data)
+ SoupMessage *msg,
+ gpointer user_data)
{
GWeatherInfo *info;
WeatherLocation *loc;
guint num_forecasts;
if (!SOUP_STATUS_IS_SUCCESSFUL (msg->status_code)) {
- /* forecast data is not really interesting anyway ;) */
- if (msg->status_code == SOUP_STATUS_CANCELLED) {
- g_debug ("Failed to get met.no forecast data: %d %s\n",
- msg->status_code, msg->reason_phrase);
- return;
- }
- g_message ("Failed to get met.no forecast data: %d %s\n",
- msg->status_code, msg->reason_phrase);
- _gweather_info_request_done (user_data, msg);
- return;
+ /* forecast data is not really interesting anyway ;) */
+ if (msg->status_code == SOUP_STATUS_CANCELLED) {
+ g_debug ("Failed to get met.no forecast data: %d %s\n",
+ msg->status_code,
+ msg->reason_phrase);
+ return;
+ }
+ g_message ("Failed to get met.no forecast data: %d %s\n",
+ msg->status_code,
+ msg->reason_phrase);
+ _gweather_info_request_done (user_data, msg);
+ return;
}
info = user_data;
@@ -421,14 +427,14 @@ metno_start_open (GWeatherInfo *info)
loc = &info->location;
if (!loc->latlon_valid)
- return FALSE;
+ return FALSE;
/* see the description here: https://api.met.no/weatherapi/locationforecast/2.0/documentation */
latstr = _radians_to_degrees_str (loc->latitude);
lonstr = _radians_to_degrees_str (loc->longitude);
- url = g_strdup_printf("https://" API_ENDPOINT_DOMAIN
"/weatherapi/locationforecast/2.0/classic?lat=%s&lon=%s", latstr, lonstr);
+ url = g_strdup_printf ("https://" API_ENDPOINT_DOMAIN
"/weatherapi/locationforecast/2.0/classic?lat=%s&lon=%s", latstr, lonstr);
g_debug ("metno_start_open, requesting: %s", url);
message = soup_message_new ("GET", url);
diff --git a/libgweather/weather-moon.c b/libgweather/weather-moon.c
index 379b921f..4d0ab85d 100644
--- a/libgweather/weather-moon.c
+++ b/libgweather/weather-moon.c
@@ -18,10 +18,10 @@
#include <sys/types.h>
#endif
+#include <glib.h>
#include <math.h>
-#include <time.h>
#include <string.h>
-#include <glib.h>
+#include <time.h>
/*
* Elements of the Moon's orbit, epoch 2000 Jan 1.5
@@ -29,11 +29,11 @@
* The page only lists most values to 2 decimal places
*/
-#define LUNAR_MEAN_LONGITUDE 218.316
+#define LUNAR_MEAN_LONGITUDE 218.316
#define LUNAR_PERIGEE_MEAN_LONG 318.15
-#define LUNAR_NODE_MEAN_LONG 125.08
-#define LUNAR_PROGRESSION 13.176358
-#define LUNAR_INCLINATION DEGREES_TO_RADIANS(5.145396)
+#define LUNAR_NODE_MEAN_LONG 125.08
+#define LUNAR_PROGRESSION 13.176358
+#define LUNAR_INCLINATION DEGREES_TO_RADIANS (5.145396)
/*
* calc_moon_internal:
@@ -48,7 +48,7 @@
static gboolean
calc_moon_internal (time_t update, gdouble *moonphase, gdouble *moonlatitude)
{
- time_t t;
+ time_t t;
gdouble ra_h;
gdouble decl_r;
gdouble ndays, sunMeanAnom_d;
@@ -66,44 +66,40 @@ calc_moon_internal (time_t update, gdouble *moonphase, gdouble *moonlatitude)
* position of the moon (section 65 of above reference)
*/
t = update;
- ndays = EPOCH_TO_J2000(t) / 86400.;
+ ndays = EPOCH_TO_J2000 (t) / 86400.;
sunMeanAnom_d = fmod (MEAN_ECLIPTIC_LONGITUDE (ndays) - PERIGEE_LONGITUDE (ndays),
- 360.);
+ 360.);
sunEclipLong_r = sunEclipLongitude (t);
moonLong_d = fmod (LUNAR_MEAN_LONGITUDE + (ndays * LUNAR_PROGRESSION),
- 360.);
- /* 5: moon's mean anomaly */
- moonMeanAnom_d = fmod ((moonLong_d - (0.1114041 * ndays)
- - (LUNAR_PERIGEE_MEAN_LONG + LUNAR_NODE_MEAN_LONG)),
- 360.);
- /* 6: ascending node mean longitude */
+ 360.);
+ /* 5: moon's mean anomaly */
+ moonMeanAnom_d = fmod ((moonLong_d - (0.1114041 * ndays) - (LUNAR_PERIGEE_MEAN_LONG +
LUNAR_NODE_MEAN_LONG)),
+ 360.);
+ /* 6: ascending node mean longitude */
ascNodeMeanLong_d = fmod (LUNAR_NODE_MEAN_LONG - (0.0529539 * ndays),
- 360.);
- eviction_d = 1.2739 /* 7: eviction */
- * sin (DEGREES_TO_RADIANS (2.0 * (moonLong_d - RADIANS_TO_DEGREES (sunEclipLong_r))
- - moonMeanAnom_d));
+ 360.);
+ eviction_d = 1.2739 /* 7: eviction */
+ * sin (DEGREES_TO_RADIANS (2.0 * (moonLong_d - RADIANS_TO_DEGREES (sunEclipLong_r)) -
moonMeanAnom_d));
sinSunMeanAnom = sin (DEGREES_TO_RADIANS (sunMeanAnom_d));
Ae = 0.1858 * sinSunMeanAnom;
- A3 = 0.37 * sinSunMeanAnom; /* 8: annual equation */
- moonMeanAnom_d += eviction_d - Ae - A3; /* 9: "third correction" */
+ A3 = 0.37 * sinSunMeanAnom; /* 8: annual equation */
+ moonMeanAnom_d += eviction_d - Ae - A3; /* 9: "third correction" */
moonMeanAnom_r = DEGREES_TO_RADIANS (moonMeanAnom_d);
- Ec = 6.2886 * sin (moonMeanAnom_r); /* 10: equation of center */
- A4 = 0.214 * sin (2.0 * moonMeanAnom_r); /* 11: "yet another correction" */
+ Ec = 6.2886 * sin (moonMeanAnom_r); /* 10: equation of center */
+ A4 = 0.214 * sin (2.0 * moonMeanAnom_r); /* 11: "yet another correction" */
/* Steps 12-14 give the true longitude after correcting for variation */
- moonLong_d += eviction_d + Ec - Ae + A4
- + (0.6583 * sin (2.0 * (moonMeanAnom_r - sunEclipLong_r)));
+ moonLong_d += eviction_d + Ec - Ae + A4 + (0.6583 * sin (2.0 * (moonMeanAnom_r - sunEclipLong_r)));
- /* 15: corrected longitude of node */
+ /* 15: corrected longitude of node */
corrLong_d = ascNodeMeanLong_d - 0.16 * sinSunMeanAnom;
/*
* Calculate ecliptic latitude (16-19) and longitude (20) of the moon,
* then convert to right ascension and declination.
*/
- lN_r = DEGREES_TO_RADIANS (moonLong_d - corrLong_d); /* l''-N' */
- lambda_r = DEGREES_TO_RADIANS(corrLong_d)
- + atan2 (sin (lN_r) * cos (LUNAR_INCLINATION), cos (lN_r));
+ lN_r = DEGREES_TO_RADIANS (moonLong_d - corrLong_d); /* l''-N' */
+ lambda_r = DEGREES_TO_RADIANS (corrLong_d) + atan2 (sin (lN_r) * cos (LUNAR_INCLINATION), cos (lN_r));
beta_r = asin (sin (lN_r) * sin (LUNAR_INCLINATION));
ecl2equ (t, lambda_r, beta_r, &ra_h, &decl_r);
@@ -111,8 +107,8 @@ calc_moon_internal (time_t update, gdouble *moonphase, gdouble *moonlatitude)
* The phase is the angle from the sun's longitude to the moon's
*/
*moonphase =
- fmod (15.*ra_h - RADIANS_TO_DEGREES (sunEclipLongitude (update)),
- 360.);
+ fmod (15. * ra_h - RADIANS_TO_DEGREES (sunEclipLongitude (update)),
+ 360.);
if (*moonphase < 0)
*moonphase += 360;
*moonlatitude = RADIANS_TO_DEGREES (decl_r);
@@ -127,9 +123,9 @@ _gweather_info_ensure_moon (GWeatherInfo *info)
return;
if (!info->moonValid)
- info->moonValid = calc_moon_internal (info->current_time,
- &info->moonphase,
- &info->moonlatitude);
+ info->moonValid = calc_moon_internal (info->current_time,
+ &info->moonphase,
+ &info->moonlatitude);
}
/*
@@ -144,46 +140,46 @@ _gweather_info_ensure_moon (GWeatherInfo *info)
static gboolean
calc_moon_phases (GWeatherInfo *info, time_t *phases)
{
- time_t tmp_update;
- gdouble tmp_moonphase;
- gdouble tmp_moonlatitude;
- time_t *ptime;
- int idx;
- gdouble advance;
- int iter;
- time_t dtime;
+ time_t tmp_update;
+ gdouble tmp_moonphase;
+ gdouble tmp_moonlatitude;
+ time_t *ptime;
+ int idx;
+ gdouble advance;
+ int iter;
+ time_t dtime;
_gweather_info_ensure_moon (info);
ptime = phases;
for (idx = 0; idx < 4; idx++) {
- tmp_update = info->current_time;
- tmp_moonphase = info->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.) - info->moonphase;
- if (advance < 0.)
- advance += 360.;
-
- for (iter = 0; iter < 10; iter++) {
- /* Convert angle change (degrees) to dtime (seconds) */
- dtime = advance / LUNAR_PROGRESSION * 86400.;
- if ((dtime > -10) && (dtime < 10))
- break;
- tmp_update += dtime;
- (void)calc_moon_internal (tmp_update, &tmp_moonphase, &tmp_moonlatitude);
-
- if (idx == 0 && tmp_moonphase > 180.) {
- advance = 360. - tmp_moonphase;
- } else {
- advance = (idx * 90.) - tmp_moonphase;
- }
- }
- *ptime++ = tmp_update;
+ advance = (idx * 90.) - info->moonphase;
+ if (advance < 0.)
+ advance += 360.;
+
+ for (iter = 0; iter < 10; iter++) {
+ /* Convert angle change (degrees) to dtime (seconds) */
+ dtime = advance / LUNAR_PROGRESSION * 86400.;
+ if ((dtime > -10) && (dtime < 10))
+ break;
+ tmp_update += dtime;
+ (void) calc_moon_internal (tmp_update, &tmp_moonphase, &tmp_moonlatitude);
+
+ if (idx == 0 && tmp_moonphase > 180.) {
+ advance = 360. - tmp_moonphase;
+ } else {
+ advance = (idx * 90.) - tmp_moonphase;
+ }
+ }
+ *ptime++ = tmp_update;
}
return TRUE;
@@ -205,5 +201,5 @@ gweather_info_get_upcoming_moonphases (GWeatherInfo *info, time_t *phases)
g_return_val_if_fail (GWEATHER_IS_INFO (info), FALSE);
g_return_val_if_fail (phases != NULL, FALSE);
- return calc_moon_phases(info, phases);
+ return calc_moon_phases (info, phases);
}
diff --git a/libgweather/weather-owm.c b/libgweather/weather-owm.c
index 2976be12..8c81da43 100644
--- a/libgweather/weather-owm.c
+++ b/libgweather/weather-owm.c
@@ -8,87 +8,89 @@
#include "gweather-private.h"
-#include <stdio.h>
-#include <stdlib.h>
#include <assert.h>
-#include <string.h>
#include <ctype.h>
+#include <langinfo.h>
#include <math.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
#include <time.h>
#include <unistd.h>
-#include <langinfo.h>
#include <libxml/parser.h>
#include <libxml/xpath.h>
#include <libxml/xpathInternals.h>
-#define XC(t) ((const xmlChar *)(t))
+#define XC(t) ((const xmlChar *) (t))
/* Reference for symbols at http://bugs.openweathermap.org/projects/api/wiki/Weather_Condition_Codes */
/* FIXME: the libgweather API is not expressive enough */
-static struct owm_symbol {
+static struct owm_symbol
+{
int symbol;
GWeatherSky sky;
GWeatherConditions condition;
} symbols[] = {
- { 200, GWEATHER_SKY_OVERCAST, { TRUE, GWEATHER_PHENOMENON_RAIN, GWEATHER_QUALIFIER_THUNDERSTORM } }, /*
Thunderstorm with light rain */
- { 201, GWEATHER_SKY_OVERCAST, { TRUE, GWEATHER_PHENOMENON_RAIN, GWEATHER_QUALIFIER_THUNDERSTORM } }, /*
Thunderstorm with rain */
- { 202, GWEATHER_SKY_OVERCAST, { TRUE, GWEATHER_PHENOMENON_RAIN, GWEATHER_QUALIFIER_THUNDERSTORM } }, /*
Thunderstorm with heavy rain */
- { 210, GWEATHER_SKY_OVERCAST, { TRUE, GWEATHER_PHENOMENON_RAIN, GWEATHER_QUALIFIER_THUNDERSTORM } }, /*
Light thunderstorm */
- { 211, GWEATHER_SKY_OVERCAST, { TRUE, GWEATHER_PHENOMENON_RAIN, GWEATHER_QUALIFIER_THUNDERSTORM } }, /*
Thunderstorm */
- { 212, GWEATHER_SKY_OVERCAST, { TRUE, GWEATHER_PHENOMENON_RAIN, GWEATHER_QUALIFIER_THUNDERSTORM } }, /*
Heavy thunderstorm */
- { 221, GWEATHER_SKY_OVERCAST, { TRUE, GWEATHER_PHENOMENON_RAIN, GWEATHER_QUALIFIER_THUNDERSTORM } }, /*
Ragged thunderstorm */
+ { 200, GWEATHER_SKY_OVERCAST, { TRUE, GWEATHER_PHENOMENON_RAIN, GWEATHER_QUALIFIER_THUNDERSTORM } },
/* Thunderstorm with light rain */
+ { 201, GWEATHER_SKY_OVERCAST, { TRUE, GWEATHER_PHENOMENON_RAIN, GWEATHER_QUALIFIER_THUNDERSTORM } },
/* Thunderstorm with rain */
+ { 202, GWEATHER_SKY_OVERCAST, { TRUE, GWEATHER_PHENOMENON_RAIN, GWEATHER_QUALIFIER_THUNDERSTORM } },
/* Thunderstorm with heavy rain */
+ { 210, GWEATHER_SKY_OVERCAST, { TRUE, GWEATHER_PHENOMENON_RAIN, GWEATHER_QUALIFIER_THUNDERSTORM } },
/* Light thunderstorm */
+ { 211, GWEATHER_SKY_OVERCAST, { TRUE, GWEATHER_PHENOMENON_RAIN, GWEATHER_QUALIFIER_THUNDERSTORM } },
/* Thunderstorm */
+ { 212, GWEATHER_SKY_OVERCAST, { TRUE, GWEATHER_PHENOMENON_RAIN, GWEATHER_QUALIFIER_THUNDERSTORM } },
/* Heavy thunderstorm */
+ { 221, GWEATHER_SKY_OVERCAST, { TRUE, GWEATHER_PHENOMENON_RAIN, GWEATHER_QUALIFIER_THUNDERSTORM } },
/* Ragged thunderstorm */
{ 230, GWEATHER_SKY_OVERCAST, { TRUE, GWEATHER_PHENOMENON_DRIZZLE, GWEATHER_QUALIFIER_THUNDERSTORM } },
/* Thunderstorm with light drizzle */
{ 231, GWEATHER_SKY_OVERCAST, { TRUE, GWEATHER_PHENOMENON_DRIZZLE, GWEATHER_QUALIFIER_THUNDERSTORM } },
/* Thunderstorm with drizzle */
{ 232, GWEATHER_SKY_OVERCAST, { TRUE, GWEATHER_PHENOMENON_DRIZZLE, GWEATHER_QUALIFIER_THUNDERSTORM } },
/* Thunderstorm with heavy drizzle */
- { 300, GWEATHER_SKY_OVERCAST, { TRUE, GWEATHER_PHENOMENON_DRIZZLE, GWEATHER_QUALIFIER_LIGHT } }, /*
Light intensity drizzle */
- { 301, GWEATHER_SKY_OVERCAST, { TRUE, GWEATHER_PHENOMENON_DRIZZLE, GWEATHER_QUALIFIER_NONE } }, /*
Drizzle */
- { 302, GWEATHER_SKY_OVERCAST, { TRUE, GWEATHER_PHENOMENON_DRIZZLE, GWEATHER_QUALIFIER_HEAVY } }, /*
Heavy intensity drizzle */
- { 310, GWEATHER_SKY_OVERCAST, { TRUE, GWEATHER_PHENOMENON_DRIZZLE, GWEATHER_QUALIFIER_LIGHT } }, /*
Light intensity drizzle rain */
- { 311, GWEATHER_SKY_OVERCAST, { TRUE, GWEATHER_PHENOMENON_DRIZZLE, GWEATHER_QUALIFIER_NONE } }, /*
Drizzle rain */
- { 312, GWEATHER_SKY_OVERCAST, { TRUE, GWEATHER_PHENOMENON_DRIZZLE, GWEATHER_QUALIFIER_HEAVY } }, /*
Heavy intensity drizzle rain */
+ { 300, GWEATHER_SKY_OVERCAST, { TRUE, GWEATHER_PHENOMENON_DRIZZLE, GWEATHER_QUALIFIER_LIGHT } }, /*
Light intensity drizzle */
+ { 301, GWEATHER_SKY_OVERCAST, { TRUE, GWEATHER_PHENOMENON_DRIZZLE, GWEATHER_QUALIFIER_NONE } }, /*
Drizzle */
+ { 302, GWEATHER_SKY_OVERCAST, { TRUE, GWEATHER_PHENOMENON_DRIZZLE, GWEATHER_QUALIFIER_HEAVY } }, /*
Heavy intensity drizzle */
+ { 310, GWEATHER_SKY_OVERCAST, { TRUE, GWEATHER_PHENOMENON_DRIZZLE, GWEATHER_QUALIFIER_LIGHT } }, /*
Light intensity drizzle rain */
+ { 311, GWEATHER_SKY_OVERCAST, { TRUE, GWEATHER_PHENOMENON_DRIZZLE, GWEATHER_QUALIFIER_NONE } }, /*
Drizzle rain */
+ { 312, GWEATHER_SKY_OVERCAST, { TRUE, GWEATHER_PHENOMENON_DRIZZLE, GWEATHER_QUALIFIER_HEAVY } }, /*
Heavy intensity drizzle rain */
{ 321, GWEATHER_SKY_OVERCAST, { TRUE, GWEATHER_PHENOMENON_DRIZZLE, GWEATHER_QUALIFIER_SHOWERS } }, /*
Drizzle showers */
- { 500, GWEATHER_SKY_OVERCAST, { TRUE, GWEATHER_PHENOMENON_RAIN, GWEATHER_QUALIFIER_LIGHT } }, /* Light
rain */
+ { 500, GWEATHER_SKY_OVERCAST, { TRUE, GWEATHER_PHENOMENON_RAIN, GWEATHER_QUALIFIER_LIGHT } }, /*
Light rain */
{ 501, GWEATHER_SKY_OVERCAST, { TRUE, GWEATHER_PHENOMENON_RAIN, GWEATHER_QUALIFIER_MODERATE } }, /*
Moderate rain */
- { 502, GWEATHER_SKY_OVERCAST, { TRUE, GWEATHER_PHENOMENON_RAIN, GWEATHER_QUALIFIER_HEAVY } }, /* Heavy
intensity rain */
- { 503, GWEATHER_SKY_OVERCAST, { TRUE, GWEATHER_PHENOMENON_RAIN, GWEATHER_QUALIFIER_HEAVY } }, /* Very
heavy rain */
- { 504, GWEATHER_SKY_OVERCAST, { TRUE, GWEATHER_PHENOMENON_RAIN, GWEATHER_QUALIFIER_HEAVY } }, /* Extreme
rain */
+ { 502, GWEATHER_SKY_OVERCAST, { TRUE, GWEATHER_PHENOMENON_RAIN, GWEATHER_QUALIFIER_HEAVY } }, /*
Heavy intensity rain */
+ { 503, GWEATHER_SKY_OVERCAST, { TRUE, GWEATHER_PHENOMENON_RAIN, GWEATHER_QUALIFIER_HEAVY } }, /* Very
heavy rain */
+ { 504, GWEATHER_SKY_OVERCAST, { TRUE, GWEATHER_PHENOMENON_RAIN, GWEATHER_QUALIFIER_HEAVY } }, /*
Extreme rain */
{ 511, GWEATHER_SKY_OVERCAST, { TRUE, GWEATHER_PHENOMENON_RAIN, GWEATHER_QUALIFIER_FREEZING } }, /*
Freezing rain */
- { 520, GWEATHER_SKY_OVERCAST, { TRUE, GWEATHER_PHENOMENON_RAIN, GWEATHER_QUALIFIER_SHOWERS } }, /* Light
intensity shower rain */
- { 521, GWEATHER_SKY_OVERCAST, { TRUE, GWEATHER_PHENOMENON_RAIN, GWEATHER_QUALIFIER_SHOWERS } }, /*
Shower rain */
- { 522, GWEATHER_SKY_OVERCAST, { TRUE, GWEATHER_PHENOMENON_RAIN, GWEATHER_QUALIFIER_SHOWERS } }, /* Heavy
intensity shower rain */
+ { 520, GWEATHER_SKY_OVERCAST, { TRUE, GWEATHER_PHENOMENON_RAIN, GWEATHER_QUALIFIER_SHOWERS } }, /*
Light intensity shower rain */
+ { 521, GWEATHER_SKY_OVERCAST, { TRUE, GWEATHER_PHENOMENON_RAIN, GWEATHER_QUALIFIER_SHOWERS } }, /*
Shower rain */
+ { 522, GWEATHER_SKY_OVERCAST, { TRUE, GWEATHER_PHENOMENON_RAIN, GWEATHER_QUALIFIER_SHOWERS } }, /*
Heavy intensity shower rain */
- { 600, GWEATHER_SKY_OVERCAST, { TRUE, GWEATHER_PHENOMENON_SNOW, GWEATHER_QUALIFIER_LIGHT } }, /* Light
snow */
- { 601, GWEATHER_SKY_OVERCAST, { TRUE, GWEATHER_PHENOMENON_SNOW, GWEATHER_QUALIFIER_NONE } }, /* Snow */
- { 602, GWEATHER_SKY_OVERCAST, { TRUE, GWEATHER_PHENOMENON_SNOW, GWEATHER_QUALIFIER_HEAVY } }, /* Heavy
snow */
+ { 600, GWEATHER_SKY_OVERCAST, { TRUE, GWEATHER_PHENOMENON_SNOW, GWEATHER_QUALIFIER_LIGHT } }, /*
Light snow */
+ { 601, GWEATHER_SKY_OVERCAST, { TRUE, GWEATHER_PHENOMENON_SNOW, GWEATHER_QUALIFIER_NONE } }, /*
Snow */
+ { 602, GWEATHER_SKY_OVERCAST, { TRUE, GWEATHER_PHENOMENON_SNOW, GWEATHER_QUALIFIER_HEAVY } }, /*
Heavy snow */
{ 611, GWEATHER_SKY_OVERCAST, { TRUE, GWEATHER_PHENOMENON_ICE_PELLETS, GWEATHER_QUALIFIER_NONE } }, /*
Sleet */
- { 621, GWEATHER_SKY_OVERCAST, { TRUE, GWEATHER_PHENOMENON_SNOW, GWEATHER_QUALIFIER_SHOWERS } }, /*
Shower snow */
+ { 621, GWEATHER_SKY_OVERCAST, { TRUE, GWEATHER_PHENOMENON_SNOW, GWEATHER_QUALIFIER_SHOWERS } }, /*
Shower snow */
- { 701, GWEATHER_SKY_CLEAR, { TRUE, GWEATHER_PHENOMENON_MIST, GWEATHER_QUALIFIER_NONE } }, /* Mist */
- { 711, GWEATHER_SKY_CLEAR, { TRUE, GWEATHER_PHENOMENON_SMOKE, GWEATHER_QUALIFIER_NONE } }, /* Smoke */
- { 721, GWEATHER_SKY_CLEAR, { TRUE, GWEATHER_PHENOMENON_HAZE, GWEATHER_QUALIFIER_NONE } }, /* Haze */
+ { 701, GWEATHER_SKY_CLEAR, { TRUE, GWEATHER_PHENOMENON_MIST, GWEATHER_QUALIFIER_NONE } }, /* Mist
*/
+ { 711, GWEATHER_SKY_CLEAR, { TRUE, GWEATHER_PHENOMENON_SMOKE, GWEATHER_QUALIFIER_NONE } }, /*
Smoke */
+ { 721, GWEATHER_SKY_CLEAR, { TRUE, GWEATHER_PHENOMENON_HAZE, GWEATHER_QUALIFIER_NONE } }, /* Haze
*/
{ 731, GWEATHER_SKY_CLEAR, { TRUE, GWEATHER_PHENOMENON_DUST_WHIRLS, GWEATHER_QUALIFIER_NONE } }, /*
Dust/sand whirls */
- { 741, GWEATHER_SKY_CLEAR, { TRUE, GWEATHER_PHENOMENON_FOG, GWEATHER_QUALIFIER_NONE } }, /* Fog */
+ { 741, GWEATHER_SKY_CLEAR, { TRUE, GWEATHER_PHENOMENON_FOG, GWEATHER_QUALIFIER_NONE } }, /* Fog
*/
- { 800, GWEATHER_SKY_CLEAR, { FALSE, GWEATHER_PHENOMENON_NONE, GWEATHER_QUALIFIER_NONE } }, /* Clear sky
*/
- { 801, GWEATHER_SKY_FEW, { FALSE, GWEATHER_PHENOMENON_NONE, GWEATHER_QUALIFIER_NONE } }, /* Few clouds */
+ { 800, GWEATHER_SKY_CLEAR, { FALSE, GWEATHER_PHENOMENON_NONE, GWEATHER_QUALIFIER_NONE } }, /* Clear
sky */
+ { 801, GWEATHER_SKY_FEW, { FALSE, GWEATHER_PHENOMENON_NONE, GWEATHER_QUALIFIER_NONE } }, /* Few
clouds */
{ 802, GWEATHER_SKY_SCATTERED, { FALSE, GWEATHER_PHENOMENON_NONE, GWEATHER_QUALIFIER_NONE } }, /*
Scattered clouds */
- { 803, GWEATHER_SKY_BROKEN, { FALSE, GWEATHER_PHENOMENON_NONE, GWEATHER_QUALIFIER_NONE } }, /* Broken
clouds */
- { 804, GWEATHER_SKY_OVERCAST, { FALSE, GWEATHER_PHENOMENON_NONE, GWEATHER_QUALIFIER_NONE } }, /*
Overcast clouds */
+ { 803, GWEATHER_SKY_BROKEN, { FALSE, GWEATHER_PHENOMENON_NONE, GWEATHER_QUALIFIER_NONE } }, /* Broken
clouds */
+ { 804, GWEATHER_SKY_OVERCAST, { FALSE, GWEATHER_PHENOMENON_NONE, GWEATHER_QUALIFIER_NONE } }, /*
Overcast clouds */
/* XXX: all these are a bit iffy */
{ 900, GWEATHER_SKY_OVERCAST, { TRUE, GWEATHER_PHENOMENON_TORNADO, GWEATHER_QUALIFIER_NONE } }, /*
Tornado */
{ 901, GWEATHER_SKY_OVERCAST, { TRUE, GWEATHER_PHENOMENON_TORNADO, GWEATHER_QUALIFIER_NONE } }, /*
Tropical storm */
{ 902, GWEATHER_SKY_OVERCAST, { TRUE, GWEATHER_PHENOMENON_TORNADO, GWEATHER_QUALIFIER_NONE } }, /*
Hurricane */
- { 903, GWEATHER_SKY_CLEAR, { FALSE, GWEATHER_PHENOMENON_NONE, GWEATHER_QUALIFIER_NONE } }, /* Cold */
- { 904, GWEATHER_SKY_CLEAR, { FALSE, GWEATHER_PHENOMENON_NONE, GWEATHER_QUALIFIER_NONE } }, /* Hot */
- { 905, GWEATHER_SKY_CLEAR, { FALSE, GWEATHER_PHENOMENON_NONE, GWEATHER_QUALIFIER_NONE } }, /* Windy */
- { 906, GWEATHER_SKY_OVERCAST, { TRUE, GWEATHER_PHENOMENON_HAIL, GWEATHER_QUALIFIER_NONE } }, /* Hail */
+ { 903, GWEATHER_SKY_CLEAR, { FALSE, GWEATHER_PHENOMENON_NONE, GWEATHER_QUALIFIER_NONE } }, /* Cold
*/
+ { 904, GWEATHER_SKY_CLEAR, { FALSE, GWEATHER_PHENOMENON_NONE, GWEATHER_QUALIFIER_NONE } }, /* Hot */
+ { 905, GWEATHER_SKY_CLEAR, { FALSE, GWEATHER_PHENOMENON_NONE, GWEATHER_QUALIFIER_NONE } }, /* Windy
*/
+ { 906, GWEATHER_SKY_OVERCAST, { TRUE, GWEATHER_PHENOMENON_HAIL, GWEATHER_QUALIFIER_NONE } }, /* Hail
*/
};
-static struct {
+static struct
+{
const char *name;
GWeatherWindDirection direction;
} wind_directions[] = {
@@ -111,7 +113,7 @@ static struct {
};
static time_t
-date_to_time_t (const xmlChar *str, const char * tzid)
+date_to_time_t (const xmlChar *str, const char *tzid)
{
struct tm time = { 0 };
GTimeZone *tz;
@@ -119,26 +121,26 @@ date_to_time_t (const xmlChar *str, const char * tzid)
time_t rval;
char *after;
- after = strptime ((const char*) str, "%Y-%m-%dT%T", &time);
+ after = strptime ((const char *) str, "%Y-%m-%dT%T", &time);
if (after == NULL) {
- g_warning ("Cannot parse date string \"%s\"", str);
- return 0;
+ g_warning ("Cannot parse date string \"%s\"", str);
+ return 0;
}
if (*after == 'Z')
- tzid = "UTC";
+ tzid = "UTC";
tz = g_time_zone_new_identifier (tzid);
if (tz == NULL)
tz = g_time_zone_new_utc ();
dt = g_date_time_new (tz,
- time.tm_year + 1900,
- time.tm_mon + 1,
- time.tm_mday,
- time.tm_hour,
- time.tm_min,
- time.tm_sec);
+ time.tm_year + 1900,
+ time.tm_mon + 1,
+ time.tm_mday,
+ time.tm_hour,
+ time.tm_min,
+ time.tm_sec);
rval = g_date_time_to_unix (dt);
@@ -160,17 +162,16 @@ symbol_compare (const void *key,
static inline void
read_symbol (GWeatherInfo *info,
- xmlNodePtr node)
+ xmlNodePtr node)
{
xmlChar *val;
struct owm_symbol *obj, ref;
- val = xmlGetProp (node, XC("number"));
+ val = xmlGetProp (node, XC ("number"));
- ref.symbol = strtol ((char*) val, NULL, 0) - 1;
+ ref.symbol = strtol ((char *) val, NULL, 0) - 1;
xmlFree (val);
- obj = bsearch (&ref, symbols, G_N_ELEMENTS (symbols),
- sizeof (struct owm_symbol), symbol_compare);
+ obj = bsearch (&ref, symbols, G_N_ELEMENTS (symbols), sizeof (struct owm_symbol), symbol_compare);
if (obj == NULL) {
g_warning ("Unknown symbol %d returned from OpenWeatherMap",
@@ -185,110 +186,110 @@ read_symbol (GWeatherInfo *info,
static inline void
read_wind_direction (GWeatherInfo *info,
- xmlNodePtr node)
+ xmlNodePtr node)
{
xmlChar *val;
unsigned int i;
- val = xmlGetProp (node, XC("code"));
+ val = xmlGetProp (node, XC ("code"));
if (val == NULL)
- return;
+ return;
for (i = 0; i < G_N_ELEMENTS (wind_directions); i++) {
- if (strcmp ((char*) val, wind_directions[i].name) == 0) {
- info->wind = wind_directions[i].direction;
- xmlFree (val);
- return;
- }
+ if (strcmp ((char *) val, wind_directions[i].name) == 0) {
+ info->wind = wind_directions[i].direction;
+ xmlFree (val);
+ return;
+ }
}
xmlFree (val);
}
static inline void
read_wind_speed (GWeatherInfo *info,
- xmlNodePtr node)
+ xmlNodePtr node)
{
xmlChar *val;
double mps;
- val = xmlGetProp (node, XC("mps"));
+ val = xmlGetProp (node, XC ("mps"));
if (val == NULL)
- return;
+ return;
- mps = g_ascii_strtod ((char*) val, NULL);
+ mps = g_ascii_strtod ((char *) val, NULL);
info->windspeed = WINDSPEED_MS_TO_KNOTS (mps);
xmlFree (val);
}
static inline void
read_temperature (GWeatherInfo *info,
- xmlNodePtr node)
+ xmlNodePtr node)
{
xmlChar *unit;
xmlChar *val;
double celsius;
- unit = xmlGetProp (node, XC("unit"));
- if (unit == NULL || strcmp ((char*)unit, "celsius")) {
+ unit = xmlGetProp (node, XC ("unit"));
+ if (unit == NULL || strcmp ((char *) unit, "celsius")) {
xmlFree (unit);
return;
}
xmlFree (unit);
- val = xmlGetProp (node, XC("value"));
+ val = xmlGetProp (node, XC ("value"));
if (val == NULL)
- return;
+ return;
- celsius = g_ascii_strtod ((char*) val, NULL);
+ celsius = g_ascii_strtod ((char *) val, NULL);
info->temp = TEMP_C_TO_F (celsius);
xmlFree (val);
}
static inline void
read_pressure (GWeatherInfo *info,
- xmlNodePtr node)
+ xmlNodePtr node)
{
xmlChar *unit;
xmlChar *val;
double hpa;
/* hPa == mbar */
- unit = xmlGetProp (node, XC("unit"));
- if (unit == NULL || strcmp ((char*)unit, "hPa")) {
+ unit = xmlGetProp (node, XC ("unit"));
+ if (unit == NULL || strcmp ((char *) unit, "hPa")) {
xmlFree (unit);
return;
}
xmlFree (unit);
- val = xmlGetProp (node, XC("value"));
+ val = xmlGetProp (node, XC ("value"));
if (val == NULL)
- return;
+ return;
- hpa = g_ascii_strtod ((char*) val, NULL);
+ hpa = g_ascii_strtod ((char *) val, NULL);
info->pressure = PRESSURE_MBAR_TO_INCH (hpa);
xmlFree (val);
}
static inline void
read_humidity (GWeatherInfo *info,
- xmlNodePtr node)
+ xmlNodePtr node)
{
xmlChar *unit;
xmlChar *val;
double percent;
- unit = xmlGetProp (node, XC("unit"));
- if (unit == NULL || strcmp ((char*)unit, "%")) {
+ unit = xmlGetProp (node, XC ("unit"));
+ if (unit == NULL || strcmp ((char *) unit, "%")) {
xmlFree (unit);
return;
}
xmlFree (unit);
- val = xmlGetProp (node, XC("value"));
+ val = xmlGetProp (node, XC ("value"));
if (val == NULL)
- return;
+ return;
- percent = g_ascii_strtod ((char*) val, NULL);
+ percent = g_ascii_strtod ((char *) val, NULL);
info->humidity = percent;
info->hasHumidity = TRUE;
xmlFree (val);
@@ -296,37 +297,37 @@ read_humidity (GWeatherInfo *info,
static inline void
read_child_node (GWeatherInfo *info,
- xmlNodePtr node)
+ xmlNodePtr node)
{
- if (strcmp ((char*) node->name, "symbol") == 0)
- read_symbol (info, node);
- else if (strcmp ((char*) node->name, "windDirection") == 0)
- read_wind_direction (info, node);
- else if (strcmp ((char*) node->name, "windSpeed") == 0)
- read_wind_speed (info, node);
- else if (strcmp ((char*) node->name, "temperature") == 0)
- read_temperature (info, node);
- else if (strcmp ((char*) node->name, "pressure") == 0)
- read_pressure (info, node);
- else if (strcmp ((char*) node->name, "humidity") == 0)
+ if (strcmp ((char *) node->name, "symbol") == 0)
+ read_symbol (info, node);
+ else if (strcmp ((char *) node->name, "windDirection") == 0)
+ read_wind_direction (info, node);
+ else if (strcmp ((char *) node->name, "windSpeed") == 0)
+ read_wind_speed (info, node);
+ else if (strcmp ((char *) node->name, "temperature") == 0)
+ read_temperature (info, node);
+ else if (strcmp ((char *) node->name, "pressure") == 0)
+ read_pressure (info, node);
+ else if (strcmp ((char *) node->name, "humidity") == 0)
read_humidity (info, node);
}
static inline void
fill_info_from_node (GWeatherInfo *info,
- xmlNodePtr node)
+ xmlNodePtr node)
{
xmlNodePtr child;
for (child = node->children; child != NULL; child = child->next) {
- if (child->type == XML_ELEMENT_NODE)
- read_child_node (info, child);
+ if (child->type == XML_ELEMENT_NODE)
+ read_child_node (info, child);
}
}
static GWeatherInfo *
make_info_from_node (GWeatherInfo *original_info,
- xmlNodePtr node)
+ xmlNodePtr node)
{
GWeatherInfo *info;
xmlChar *val;
@@ -335,7 +336,7 @@ make_info_from_node (GWeatherInfo *original_info,
info = _gweather_info_new_clone (original_info);
- val = xmlGetProp (node, XC("from"));
+ val = xmlGetProp (node, XC ("from"));
info->current_time = info->update = date_to_time_t (val, info->location.tz_hint);
xmlFree (val);
@@ -345,7 +346,7 @@ make_info_from_node (GWeatherInfo *original_info,
}
static void
-parse_forecast_xml (GWeatherInfo *original_info,
+parse_forecast_xml (GWeatherInfo *original_info,
SoupMessageBody *body)
{
xmlDocPtr doc;
@@ -355,35 +356,35 @@ parse_forecast_xml (GWeatherInfo *original_info,
doc = xmlParseMemory (body->data, body->length);
if (!doc)
- return;
+ return;
xpath_ctx = xmlXPathNewContext (doc);
- xpath_result = xmlXPathEval (XC("/weatherdata/forecast/time"), xpath_ctx);
+ xpath_result = xmlXPathEval (XC ("/weatherdata/forecast/time"), xpath_ctx);
if (!xpath_result || xpath_result->type != XPATH_NODESET)
- goto out;
+ goto out;
for (i = 0; i < xpath_result->nodesetval->nodeNr; i++) {
- xmlNodePtr node;
- GWeatherInfo *info;
+ xmlNodePtr node;
+ GWeatherInfo *info;
- node = xpath_result->nodesetval->nodeTab[i];
- info = make_info_from_node (original_info, node);
+ node = xpath_result->nodesetval->nodeTab[i];
+ info = make_info_from_node (original_info, node);
- info->forecast_list = g_slist_append (info->forecast_list, info);
+ info->forecast_list = g_slist_append (info->forecast_list, info);
}
xmlXPathFreeObject (xpath_result);
- xpath_result = xmlXPathEval (XC("/weatherdata/credit/link"), xpath_ctx);
+ xpath_result = xmlXPathEval (XC ("/weatherdata/credit/link"), xpath_ctx);
if (!xpath_result || xpath_result->type != XPATH_NODESET)
- goto out;
+ goto out;
- original_info->forecast_attribution = g_strdup(_("Weather data from the <a
href=\"https://openweathermap.org\">Open Weather Map project</a>"));
+ original_info->forecast_attribution = g_strdup (_ ("Weather data from the <a
href=\"https://openweathermap.org\">Open Weather Map project</a>"));
- out:
+out:
if (xpath_result)
- xmlXPathFreeObject (xpath_result);
+ xmlXPathFreeObject (xpath_result);
xmlXPathFreeContext (xpath_ctx);
xmlFreeDoc (doc);
}
@@ -391,22 +392,24 @@ parse_forecast_xml (GWeatherInfo *original_info,
static void
owm_finish (SoupSession *session,
SoupMessage *msg,
- gpointer user_data)
+ gpointer user_data)
{
GWeatherInfo *info;
WeatherLocation *loc;
if (!SOUP_STATUS_IS_SUCCESSFUL (msg->status_code)) {
- /* forecast data is not really interesting anyway ;) */
- if (msg->status_code == SOUP_STATUS_CANCELLED) {
- g_debug ("Failed to get OpenWeatherMap forecast data: %d %s\n",
- msg->status_code, msg->reason_phrase);
- return;
- }
- g_warning ("Failed to get OpenWeatherMap forecast data: %d %s\n",
- msg->status_code, msg->reason_phrase);
- _gweather_info_request_done (user_data, msg);
- return;
+ /* forecast data is not really interesting anyway ;) */
+ if (msg->status_code == SOUP_STATUS_CANCELLED) {
+ g_debug ("Failed to get OpenWeatherMap forecast data: %d %s\n",
+ msg->status_code,
+ msg->reason_phrase);
+ return;
+ }
+ g_warning ("Failed to get OpenWeatherMap forecast data: %d %s\n",
+ msg->status_code,
+ msg->reason_phrase);
+ _gweather_info_request_done (user_data, msg);
+ return;
}
info = user_data;
@@ -430,7 +433,7 @@ owm_start_open (GWeatherInfo *info)
loc = &info->location;
if (!loc->latlon_valid)
- return FALSE;
+ return FALSE;
/* see the description here: http://bugs.openweathermap.org/projects/api/wiki/Api_2_5_forecast */
@@ -439,9 +442,9 @@ owm_start_open (GWeatherInfo *info)
#define TEMPLATE_START "https://api.openweathermap.org/data/2.5/forecast?lat=%s&lon=%s&mode=xml&units=metric"
#ifdef OWM_APIKEY
- #define TEMPLATE TEMPLATE_START "&APPID=" OWM_APIKEY
+#define TEMPLATE TEMPLATE_START "&APPID=" OWM_APIKEY
#else
- #define TEMPLATE TEMPLATE_START
+#define TEMPLATE TEMPLATE_START
#endif
url = g_strdup_printf (TEMPLATE, latstr, lonstr);
diff --git a/libgweather/weather-sun.c b/libgweather/weather-sun.c
index 7330ca47..f5635e54 100644
--- a/libgweather/weather-sun.c
+++ b/libgweather/weather-sun.c
@@ -16,11 +16,11 @@
#include "gweather-private.h"
+#include <glib.h>
#include <math.h>
#include <time.h>
-#include <glib.h>
-#define ECCENTRICITY(d) (0.01671123 - (d)/36525.*0.00004392)
+#define ECCENTRICITY(d) (0.01671123 - (d) / 36525. * 0.00004392)
/*
* Ecliptic longitude of the sun at specified time (UT)
@@ -28,38 +28,34 @@
* Return value is in radians
*/
gdouble
-sunEclipLongitude(time_t t)
+sunEclipLongitude (time_t t)
{
gdouble ndays, meanAnom, eccenAnom, delta, e, longitude;
/*
* Start with an estimate based on a fixed daily rate
*/
- ndays = EPOCH_TO_J2000(t) / 86400.;
- meanAnom = DEGREES_TO_RADIANS(MEAN_ECLIPTIC_LONGITUDE(ndays)
- - PERIGEE_LONGITUDE(ndays));
-
+ ndays = EPOCH_TO_J2000 (t) / 86400.;
+ meanAnom = DEGREES_TO_RADIANS (MEAN_ECLIPTIC_LONGITUDE (ndays) - PERIGEE_LONGITUDE (ndays));
+
/*
* Approximate solution of Kepler's equation:
* Find E which satisfies E - e sin(E) = M (mean anomaly)
- */
+ */
eccenAnom = meanAnom;
- e = ECCENTRICITY(ndays);
+ e = ECCENTRICITY (ndays);
- while (1e-12 < fabs( delta = eccenAnom - e * sin(eccenAnom) - meanAnom))
- {
- eccenAnom -= delta / (1.- e * cos(eccenAnom));
+ while (1e-12 < fabs (delta = eccenAnom - e * sin (eccenAnom) - meanAnom)) {
+ eccenAnom -= delta / (1. - e * cos (eccenAnom));
}
/*
* Earth's longitude on the ecliptic
*/
- longitude = fmod( DEGREES_TO_RADIANS (PERIGEE_LONGITUDE(ndays))
- + 2. * atan (sqrt ((1.+e)/(1.-e))
- * tan (eccenAnom / 2.)),
- 2. * M_PI);
+ longitude = fmod (DEGREES_TO_RADIANS (PERIGEE_LONGITUDE (ndays)) + 2. * atan (sqrt ((1. + e) / (1. - e))
* tan (eccenAnom / 2.)),
+ 2. * M_PI);
if (longitude < 0.) {
- longitude += 2 * M_PI;
+ longitude += 2 * M_PI;
}
return longitude;
}
@@ -68,11 +64,8 @@ static gdouble
ecliptic_obliquity (gdouble time)
{
gdouble jc = EPOCH_TO_J2000 (time) / (36525. * 86400.);
- gdouble eclip_secs = (84381.448
- - (46.84024 * jc)
- - (59.e-5 * jc * jc)
- + (1.813e-3 * jc * jc * jc));
- return DEGREES_TO_RADIANS(eclip_secs / 3600.);
+ gdouble eclip_secs = (84381.448 - (46.84024 * jc) - (59.e-5 * jc * jc) + (1.813e-3 * jc * jc * jc));
+ return DEGREES_TO_RADIANS (eclip_secs / 3600.);
}
/*
@@ -82,21 +75,21 @@ ecliptic_obliquity (gdouble time)
*/
void
ecl2equ (gdouble time,
- gdouble eclipLon, gdouble eclipLat,
- gdouble *ra, gdouble *decl)
+ gdouble eclipLon,
+ gdouble eclipLat,
+ gdouble *ra,
+ gdouble *decl)
{
- gdouble mEclipObliq = ecliptic_obliquity(time);
+ gdouble mEclipObliq = ecliptic_obliquity (time);
if (ra) {
- *ra = RADIANS_TO_HOURS (atan2 ((sin (eclipLon) * cos (mEclipObliq)
- - tan (eclipLat) * sin(mEclipObliq)),
- cos (eclipLon)));
- if (*ra < 0.)
- *ra += 24.;
+ *ra = RADIANS_TO_HOURS (atan2 ((sin (eclipLon) * cos (mEclipObliq) - tan (eclipLat) * sin
(mEclipObliq)),
+ cos (eclipLon)));
+ if (*ra < 0.)
+ *ra += 24.;
}
if (decl) {
- *decl = asin (( sin (eclipLat) * cos (mEclipObliq))
- + cos (eclipLat) * sin (mEclipObliq) * sin(eclipLon));
+ *decl = asin ((sin (eclipLat) * cos (mEclipObliq)) + cos (eclipLat) * sin (mEclipObliq) * sin
(eclipLon));
}
}
@@ -106,16 +99,14 @@ ecl2equ (gdouble time,
* Returned "rise" and "set" values are sideral times in hours
*/
static void
-gstObsv (gdouble ra, gdouble decl,
- gdouble obsLat, gdouble obsLon,
- gdouble *rise, gdouble *set)
+gstObsv (gdouble ra, gdouble decl, gdouble obsLat, gdouble obsLon, gdouble *rise, gdouble *set)
{
double a = acos (-tan (obsLat) * tan (decl));
double b;
if (isnan (a) != 0) {
- *set = *rise = a;
- return;
+ *set = *rise = a;
+ return;
}
a = RADIANS_TO_HOURS (a);
b = 24. - a + ra;
@@ -123,26 +114,24 @@ gstObsv (gdouble ra, gdouble decl,
a -= RADIANS_TO_HOURS (obsLon);
b -= RADIANS_TO_HOURS (obsLon);
if ((a = fmod (a, 24.)) < 0)
- a += 24.;
+ a += 24.;
if ((b = fmod (b, 24.)) < 0)
- b += 24.;
+ b += 24.;
*set = a;
*rise = b;
}
-
static gdouble
t0 (time_t date)
{
- gdouble t = ((gdouble)(EPOCH_TO_J2000 (date) / 86400)) / 36525.0;
+ gdouble t = ((gdouble) (EPOCH_TO_J2000 (date) / 86400)) / 36525.0;
gdouble t0 = fmod (6.697374558 + 2400.051366 * t + 2.5862e-5 * t * t, 24.);
if (t0 < 0.)
t0 += 24.;
return t0;
}
-
static gboolean
calc_sun (GWeatherInfo *info, time_t t)
{
@@ -178,22 +167,24 @@ calc_sun (GWeatherInfo *info, time_t t)
*/
ecl2equ (lcl_midn, lambda, 0., &ra1, &decl1);
ecl2equ (lcl_midn + 86400.,
- lambda + DEGREES_TO_RADIANS(SOL_PROGRESSION), 0.,
- &ra2, &decl2);
+ lambda + DEGREES_TO_RADIANS (SOL_PROGRESSION),
+ 0.,
+ &ra2,
+ &decl2);
/*
* If the observer is within the Arctic or Antarctic Circles then
* the sun may be above or below the horizon for the full day.
*/
- decl_midn = MIN(decl1,decl2);
- decl_noon = (decl1+decl2)/2.;
+ decl_midn = MIN (decl1, decl2);
+ decl_noon = (decl1 + decl2) / 2.;
info->midnightSun =
- (obsLat > (M_PI/2.-decl_midn)) || (obsLat < (-M_PI/2.-decl_midn));
+ (obsLat > (M_PI / 2. - decl_midn)) || (obsLat < (-M_PI / 2. - decl_midn));
info->polarNight =
- (obsLat > (M_PI/2.+decl_noon)) || (obsLat < (-M_PI/2.+decl_noon));
+ (obsLat > (M_PI / 2. + decl_noon)) || (obsLat < (-M_PI / 2. + decl_noon));
if (info->midnightSun || info->polarNight) {
- info->sunriseValid = info->sunsetValid = FALSE;
- return FALSE;
+ info->sunriseValid = info->sunsetValid = FALSE;
+ return FALSE;
}
/*
@@ -204,8 +195,8 @@ calc_sun (GWeatherInfo *info, time_t t)
gstObsv (ra2, decl2, obsLat, obsLon - (gm_hoff * M_PI / 12.), &rise2, &set2);
/* TODO: include calculations for regions near the poles. */
- if (isnan(rise1) || isnan(rise2)) {
- info->sunriseValid = info->sunsetValid = FALSE;
+ if (isnan (rise1) || isnan (rise2)) {
+ info->sunriseValid = info->sunsetValid = FALSE;
return FALSE;
}
@@ -216,8 +207,8 @@ calc_sun (GWeatherInfo *info, time_t t)
set2 += 24.;
}
- tt = t0(lcl_midn);
- t00 = tt - (gm_hoff + RADIANS_TO_HOURS(obsLon)) * 1.002737909;
+ tt = t0 (lcl_midn);
+ t00 = tt - (gm_hoff + RADIANS_TO_HOURS (obsLon)) * 1.002737909;
if (t00 < 0.)
t00 += 24.;
@@ -227,8 +218,8 @@ calc_sun (GWeatherInfo *info, time_t t)
rise2 += 24.;
}
if (set1 < t00) {
- set1 += 24.;
- set2 += 24.;
+ set1 += 24.;
+ set2 += 24.;
}
/*
@@ -243,9 +234,9 @@ calc_sun (GWeatherInfo *info, time_t t)
* refraction and the Sun's finite diameter (steps 9,10)
*/
decl2 = (decl1 + decl2) / 2.;
- x = DEGREES_TO_RADIANS(0.830725);
- u = acos ( sin(obsLat) / cos(decl2) );
- dt = RADIANS_TO_HOURS ( asin ( sin(x) / sin(u) ) / cos(decl2) );
+ x = DEGREES_TO_RADIANS (0.830725);
+ u = acos (sin (obsLat) / cos (decl2));
+ dt = RADIANS_TO_HOURS (asin (sin (x) / sin (u)) / cos (decl2));
/*
* Subtract the correction value from sunrise and add to sunset,
@@ -253,17 +244,17 @@ calc_sun (GWeatherInfo *info, time_t t)
*/
rise1 = (rise1 - dt - tt) * 0.9972695661;
if (rise1 < 0.)
- rise1 += 24;
+ rise1 += 24;
else if (rise1 >= 24.)
- rise1 -= 24.;
+ rise1 -= 24.;
info->sunriseValid = ((rise1 >= 0.) && (rise1 < 24.));
info->sunrise = (rise1 * 3600.) + lcl_midn;
- set1 = (set1 + dt - tt) * 0.9972695661;
+ set1 = (set1 + dt - tt) * 0.9972695661;
if (set1 < 0.)
- set1 += 24;
+ set1 += 24;
else if (set1 >= 24.)
- set1 -= 24.;
+ set1 -= 24.;
info->sunsetValid = ((set1 >= 0.) && (set1 < 24.));
info->sunset = (set1 * 3600.) + lcl_midn;
@@ -277,7 +268,7 @@ _gweather_info_ensure_sun (GWeatherInfo *info)
return;
if (!info->sunriseValid && !info->sunsetValid)
- calc_sun (info, info->current_time);
+ calc_sun (info, info->current_time);
}
/**
@@ -292,9 +283,9 @@ _gweather_info_ensure_sun (GWeatherInfo *info)
gint
gweather_info_next_sun_event (GWeatherInfo *info)
{
- time_t now = time (NULL);
+ time_t now = time (NULL);
struct tm ltm;
- time_t nxtEvent;
+ time_t nxtEvent;
g_return_val_if_fail (info != NULL, -1);
@@ -309,10 +300,10 @@ gweather_info_next_sun_event (GWeatherInfo *info)
nxtEvent = mktime (<m);
if (info->sunsetValid &&
- (info->sunset > now) && (info->sunset < nxtEvent))
- nxtEvent = info->sunset;
+ (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);
+ (info->sunrise > now) && (info->sunrise < nxtEvent))
+ nxtEvent = info->sunrise;
+ return (gint) (nxtEvent - now);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]