This is an automated email from the git hooks/post-receive script.
git pushed a commit to branch main
in repository elements.
View the commit online.
commit dff4cecffba68906cc270e18a2f1ec699e72b485
Author: Alastair Poole <[email protected]>
AuthorDate: Thu Nov 26 12:28:36 2026 +0000
build: remove glib dependency.
---
NEWS | 6 ++
README.md | 2 +-
VERSION | 2 +-
po/meson.build | 8 ++-
src/lib/elements_effects.c | 4 +-
src/lib/elements_forecast.c | 153 +++++++++++++++++++++++++++++---------------
src/lib/elements_forecast.h | 7 +-
src/lib/elements_places.c | 137 ++++++++++++++++++++++++---------------
src/lib/elements_request.c | 7 +-
src/lib/elements_request.h | 2 +-
src/lib/elements_settings.c | 13 ++--
src/lib/elements_ui.c | 92 +++++++++++++++++---------
src/lib/meson.build | 6 +-
13 files changed, 288 insertions(+), 151 deletions(-)
diff --git a/NEWS b/NEWS
index e2841f5..7fe5280 100644
--- a/NEWS
+++ b/NEWS
@@ -1,3 +1,9 @@
+==============
+Elements 0.1.1
+==============
+
+ * Removed the direct GLib dependency.
+
==============
Elements 0.1.0
==============
diff --git a/README.md b/README.md
index a5d0902..052de78 100644
--- a/README.md
+++ b/README.md
@@ -22,7 +22,7 @@ Elements is an Elementary desktop weather app with offline place search and fore
## Build and install
-Requires Meson, Ninja, GNU gettext, EFL 1.26+ with `edje_cc`, json-c, and GLib 2.68+.
+Requires Meson, Ninja, GNU gettext, EFL 1.26+ with `edje_cc`, json-c, and ICU (icu-uc and icu-i18n).
```sh
meson setup build
diff --git a/VERSION b/VERSION
index 6e8bf73..17e51c3 100644
--- a/VERSION
+++ b/VERSION
@@ -1 +1 @@
-0.1.0
+0.1.1
diff --git a/po/meson.build b/po/meson.build
index d08be70..87b613e 100644
--- a/po/meson.build
+++ b/po/meson.build
@@ -1 +1,7 @@
-i18n.gettext('elements', preset : 'glib')
+i18n.gettext('elements', args : [
+ '--from-code=UTF-8',
+ '--add-comments',
+ '--keyword=_',
+ '--keyword=N_',
+ '--flag=N_:1:pass-c-format',
+])
diff --git a/src/lib/elements_effects.c b/src/lib/elements_effects.c
index 6802a56..4ee187c 100644
--- a/src/lib/elements_effects.c
+++ b/src/lib/elements_effects.c
@@ -91,9 +91,9 @@ _clouds_add(Elements_Effects *effects, bool fog)
{
double dx = x / (double) (ELEMENTS_CLOUD_WIDTH - 1);
double dy = y / (double) (ELEMENTS_CLOUD_HEIGHT - 1);
- double fade = sin(G_PI * dx) * sin(G_PI * dy);
+ double fade = sin(M_PI * dx) * sin(M_PI * dy);
double shape = fog ? fade * fade :
- fade * fade * (0.7 + 0.3 * cos(5 * G_PI * dx + 2 * dy));
+ fade * fade * (0.7 + 0.3 * cos(5 * M_PI * dx + 2 * dy));
pixels[y * ELEMENTS_CLOUD_WIDTH + x] = _pixel_get(166, 193, 213, (int) (shape * 255));
}
diff --git a/src/lib/elements_forecast.c b/src/lib/elements_forecast.c
index 325e7f3..b46b587 100644
--- a/src/lib/elements_forecast.c
+++ b/src/lib/elements_forecast.c
@@ -1,7 +1,10 @@
+#define _GNU_SOURCE
+
#include <json-c/json.h>
#include <math.h>
#include <stdlib.h>
#include <string.h>
+#include <unicode/ustring.h>
#include "elements_forecast.h"
@@ -17,38 +20,36 @@ _number_get(json_object *object, const char *key)
}
static bool
-_sun_below_horizon(GDateTime *timestamp, const Elements_Place *place)
+_sun_below_horizon(const struct tm *utc, const Elements_Place *place)
{
- GDateTime *utc = g_date_time_to_utc(timestamp);
- int year = g_date_time_get_year(utc);
- double minutes = g_date_time_get_hour(utc) * 60 + g_date_time_get_minute(utc);
- double year_length = g_date_is_leap_year(year) ? 366.0 : 365.0;
- double angle = 2 * G_PI / year_length *
- (g_date_time_get_day_of_year(utc) - 1 + (minutes / 60.0 - 12) / 24.0);
+ int year = utc->tm_year + 1900;
+ double minutes = utc->tm_hour * 60 + utc->tm_min;
+ double year_length = (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0)) ? 366.0 : 365.0;
+ double angle = 2 * M_PI / year_length *
+ (utc->tm_yday + (minutes / 60.0 - 12) / 24.0);
double equation = 229.18 * (0.000075 + 0.001868 * cos(angle) - 0.032077 * sin(angle) -
0.014615 * cos(2 * angle) - 0.040849 * sin(2 * angle));
double declination = 0.006918 - 0.399912 * cos(angle) + 0.070257 * sin(angle) -
0.006758 * cos(2 * angle) + 0.000907 * sin(2 * angle) -
0.002697 * cos(3 * angle) + 0.001480 * sin(3 * angle);
- double hour_angle = ((minutes + equation + 4 * place->longitude) / 4 - 180) * G_PI / 180;
- double latitude = place->latitude * G_PI / 180;
+ double hour_angle = ((minutes + equation + 4 * place->longitude) / 4 - 180) * M_PI / 180;
+ double latitude = place->latitude * M_PI / 180;
double elevation_sine = sin(latitude) * sin(declination) +
cos(latitude) * cos(declination) * cos(hour_angle);
- g_date_time_unref(utc);
/* The NOAA sunrise threshold accounts for refraction and the solar disc. */
- return elevation_sine < sin(-0.833 * G_PI / 180);
+ return elevation_sine < sin(-0.833 * M_PI / 180);
}
static Elements_Weather
-_weather_get(json_object *data, GDateTime *timestamp, const Elements_Place *place,
+_weather_get(json_object *data, const struct tm *utc, const Elements_Place *place,
bool *night)
{
static const char *periods[] = { "next_1_hours", "next_6_hours", "next_12_hours" };
const char *code = NULL;
size_t period_index = 0;
- for (; period_index < G_N_ELEMENTS(periods); period_index++)
+ for (; period_index < sizeof(periods) / sizeof(periods[0]); period_index++)
{
json_object *period = json_object_object_get(data, periods[period_index]);
json_object *summary = json_object_object_get(period, "summary");
@@ -65,7 +66,7 @@ _weather_get(json_object *data, GDateTime *timestamp, const Elements_Place *plac
(strstr(code, "_night") || strstr(code, "_polartwilight")))
*night = true;
else
- *night = _sun_below_horizon(timestamp, place);
+ *night = _sun_below_horizon(utc, place);
if (!code) return ELEMENTS_WEATHER_UNKNOWN;
if (strstr(code, "thunder")) return ELEMENTS_WEATHER_THUNDER;
if (strstr(code, "sleet")) return ELEMENTS_WEATHER_SLEET;
@@ -80,23 +81,86 @@ _weather_get(json_object *data, GDateTime *timestamp, const Elements_Place *plac
return ELEMENTS_WEATHER_UNKNOWN;
}
-GDateTime *
-elements_forecast_local_time(GTimeZone *zone, time_t timestamp)
+UCalendar *
+elements_forecast_zone_open(const char *name)
{
- GDateTime *utc = g_date_time_new_from_unix_utc(timestamp);
- GDateTime *local;
+ UChar identifier[128];
+ UErrorCode status = U_ZERO_ERROR;
+ UBool system_id = false;
- if (!utc) return NULL;
- local = g_date_time_to_timezone(utc, zone);
- g_date_time_unref(utc);
- return local;
+ u_strFromUTF8(identifier, 128, NULL, name, -1, &status);
+ if (U_SUCCESS(status))
+ {
+ UChar canonical[128];
+ ucal_getCanonicalTimeZoneID(identifier, -1, canonical, 128, &system_id, &status);
+ }
+ if (U_FAILURE(status) || !system_id)
+ u_uastrcpy(identifier, "UTC");
+
+ status = U_ZERO_ERROR;
+ return ucal_open(identifier, -1, "en_US", UCAL_GREGORIAN, &status);
+}
+
+bool
+elements_forecast_local_time(UCalendar *zone, time_t timestamp, struct tm *local)
+{
+ UErrorCode status = U_ZERO_ERROR;
+ int32_t offset;
+
+ if (!zone) return gmtime_r(×tamp, local) != NULL;
+ ucal_setMillis(zone, (UDate) timestamp * 1000, &status);
+ offset = ucal_get(zone, UCAL_ZONE_OFFSET, &status) +
+ ucal_get(zone, UCAL_DST_OFFSET, &status);
+ if (U_FAILURE(status)) return false;
+
+ time_t shifted;
+ if (__builtin_add_overflow(timestamp, offset / 1000, &shifted) ||
+ !gmtime_r(&shifted, local)) return false;
+ local->tm_isdst = ucal_inDaylightTime(zone, &status);
+ local->tm_gmtoff = offset / 1000;
+ return U_SUCCESS(status);
+}
+
+static bool
+_timestamp_parse(const char *stamp, time_t *timestamp, struct tm *utc)
+{
+ struct tm parsed = { 0 };
+ const char *end = strptime(stamp, "%Y-%m-%dT%H:%M:%S", &parsed);
+ int offset = 0;
+
+ if (!end) return false;
+ if (*end == '.' || *end == ',')
+ {
+ size_t digits = strspn(++end, "0123456789");
+ if (!digits) return false;
+ end += digits;
+ }
+ if (*end == 'Z')
+ end++;
+ else if (*end == '+' || *end == '-')
+ {
+ struct tm zone = { 0 };
+ end = strptime(end, "%z", &zone);
+ if (!end) return false;
+ offset = zone.tm_gmtoff;
+ }
+ else return false;
+ if (*end) return false;
+
+ struct tm original = parsed;
+ time_t wall = timegm(&parsed);
+ if (parsed.tm_year != original.tm_year || parsed.tm_mon != original.tm_mon ||
+ parsed.tm_mday != original.tm_mday || parsed.tm_hour != original.tm_hour ||
+ parsed.tm_min != original.tm_min || parsed.tm_sec != original.tm_sec)
+ return false;
+ return !__builtin_sub_overflow(wall, offset, timestamp) &&
+ gmtime_r(timestamp, utc) != NULL;
}
static int
-_day_key(GDateTime *local)
+_day_key(const struct tm *local)
{
- return g_date_time_get_year(local) * 10000 +
- g_date_time_get_month(local) * 100 + g_date_time_get_day_of_month(local);
+ return local->tm_year * 366 + local->tm_yday;
}
static void
@@ -116,20 +180,21 @@ _range_add(Elements_Forecast_Day *day, const Elements_Conditions *conditions, bo
bool
elements_forecast_parse(const char *json, const Elements_Place *place,
- GTimeZone *zone, time_t now,
+ time_t now,
Elements_Forecast *forecast)
{
json_object *root = json_tokener_parse(json);
json_object *properties = json_object_object_get(root, "properties");
json_object *series = json_object_object_get(properties, "timeseries");
Elements_Forecast parsed = { 0 };
- GDateTime *local_now = elements_forecast_local_time(zone, now);
+ UCalendar *zone = elements_forecast_zone_open(place->timezone);
+ struct tm local_now;
bool have_current = false, have_sample = false;
time_t last_sample = 0;
int today, last_day = 0, best_distance = 0;
- if (!local_now || !json_object_is_type(series, json_type_array)) goto done;
- today = _day_key(local_now);
+ if (!elements_forecast_local_time(zone, now, &local_now) || !json_object_is_type(series, json_type_array)) goto done;
+ today = _day_key(&local_now);
for (size_t i = 0; i < json_object_array_length(series); i++)
{
json_object *item = json_object_array_get_idx(series, i);
@@ -138,33 +203,19 @@ elements_forecast_parse(const char *json, const Elements_Place *place,
json_object *details = json_object_object_get(instant, "details");
const char *stamp = json_object_get_string(json_object_object_get(item, "time"));
Elements_Conditions conditions;
- GDateTime *utc, *local;
+ struct tm utc, local;
int day, distance;
conditions.temperature = _number_get(details, "air_temperature");
if (!stamp || !isfinite(conditions.temperature)) continue;
- utc = g_date_time_new_from_iso8601(stamp, NULL);
- if (!utc) continue;
- conditions.time = (time_t) g_date_time_to_unix(utc);
- local = g_date_time_to_timezone(utc, zone);
- if (!local)
- {
- g_date_time_unref(utc);
- continue;
- }
- day = _day_key(local);
- distance = abs(g_date_time_get_hour(local) * 60 + g_date_time_get_minute(local) -
- 12 * 60);
- g_date_time_unref(local);
- if (day < today || (have_sample && conditions.time <= last_sample))
- {
- g_date_time_unref(utc);
- continue;
- }
+ if (!_timestamp_parse(stamp, &conditions.time, &utc) ||
+ !elements_forecast_local_time(zone, conditions.time, &local)) continue;
+ day = _day_key(&local);
+ distance = abs(local.tm_hour * 60 + local.tm_min - 12 * 60);
+ if (day < today || (have_sample && conditions.time <= last_sample)) continue;
have_sample = true;
last_sample = conditions.time;
- conditions.weather = _weather_get(data, utc, place, &conditions.night);
- g_date_time_unref(utc);
+ conditions.weather = _weather_get(data, &utc, place, &conditions.night);
if ((!have_current && conditions.time >= now) ||
(conditions.time <= now && difftime(now, conditions.time) <= 90 * 60))
@@ -208,7 +259,7 @@ elements_forecast_parse(const char *json, const Elements_Place *place,
}
done:
- if (local_now) g_date_time_unref(local_now);
+ if (zone) ucal_close(zone);
json_object_put(root);
if (have_current) *forecast = parsed;
return have_current;
diff --git a/src/lib/elements_forecast.h b/src/lib/elements_forecast.h
index ca22141..83e5e1f 100644
--- a/src/lib/elements_forecast.h
+++ b/src/lib/elements_forecast.h
@@ -1,7 +1,7 @@
#ifndef ELEMENTS_FORECAST_H
#define ELEMENTS_FORECAST_H
-#include <glib.h>
+#include <unicode/ucal.h>
#include <stdbool.h>
#include <stddef.h>
#include <time.h>
@@ -53,9 +53,10 @@ typedef struct
double pressure;
} Elements_Forecast;
-GDateTime *elements_forecast_local_time(GTimeZone *zone, time_t timestamp);
+UCalendar *elements_forecast_zone_open(const char *name);
+bool elements_forecast_local_time(UCalendar *zone, time_t timestamp, struct tm *local);
bool elements_forecast_parse(const char *json, const Elements_Place *place,
- GTimeZone *zone, time_t now,
+ time_t now,
Elements_Forecast *forecast);
#endif
diff --git a/src/lib/elements_places.c b/src/lib/elements_places.c
index 92dba98..0c07ada 100644
--- a/src/lib/elements_places.c
+++ b/src/lib/elements_places.c
@@ -1,12 +1,16 @@
#define _GNU_SOURCE
#include <ctype.h>
-#include <glib.h>
+#include <Eina.h>
#include <locale.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
+#include <unicode/uchar.h>
+#include <unicode/unorm2.h>
+#include <unicode/ustring.h>
+#include <unicode/uscript.h>
#include "elements_build_config.h"
#include "elements_catalog.h"
@@ -61,34 +65,66 @@ done:
static char *
_search_text_get(const char *text)
{
- char *folded = g_utf8_casefold(text, -1);
- char *normalized = g_utf8_normalize(folded, -1, G_NORMALIZE_NFD);
- char *out = normalized;
+ UErrorCode status = U_ZERO_ERROR;
+ const UNormalizer2 *nfd = unorm2_getNFDInstance(&status);
+ int32_t length, folded_length, normalized_length, used = 0;
+ UChar *input = NULL, *folded = NULL, *normalized = NULL;
+ char *result = NULL;
bool latin = false;
- g_free(folded);
- if (!normalized) return NULL;
- for (const char *in = normalized, *next; *in; in = next)
+ if (U_FAILURE(status)) return NULL;
+ u_strFromUTF8(NULL, 0, &length, text, -1, &status);
+ if (U_FAILURE(status) && status != U_BUFFER_OVERFLOW_ERROR) return NULL;
+ status = U_ZERO_ERROR;
+ input = malloc(((size_t) length + 1) * sizeof(*input));
+ if (!input) goto done;
+ u_strFromUTF8(input, length + 1, NULL, text, -1, &status);
+ folded_length = u_strFoldCase(NULL, 0, input, length, U_FOLD_CASE_DEFAULT, &status);
+ if (U_FAILURE(status) && status != U_BUFFER_OVERFLOW_ERROR) goto done;
+ status = U_ZERO_ERROR;
+ folded = malloc(((size_t) folded_length + 1) * sizeof(*folded));
+ if (!folded) goto done;
+ u_strFoldCase(folded, folded_length + 1, input, length, U_FOLD_CASE_DEFAULT, &status);
+ normalized_length = unorm2_normalize(nfd, folded, folded_length, NULL, 0, &status);
+ if (U_FAILURE(status) && status != U_BUFFER_OVERFLOW_ERROR) goto done;
+ status = U_ZERO_ERROR;
+ normalized = malloc(((size_t) normalized_length + 1) * sizeof(*normalized));
+ if (!normalized) goto done;
+ unorm2_normalize(nfd, folded, folded_length, normalized, normalized_length + 1, &status);
+ if (U_FAILURE(status)) goto done;
+
+ for (int32_t i = 0; i < normalized_length;)
{
- gunichar character = g_utf8_get_char(in);
+ UChar32 character;
+ U16_NEXT(normalized, i, normalized_length, character);
+ int8_t type = u_charType(character);
- next = g_utf8_next_char(in);
-
- if (g_unichar_isalnum(character))
+ if ((U_GET_GC_MASK(character) & (U_GC_L_MASK | U_GC_N_MASK)) != 0)
{
- latin = g_unichar_get_script(character) == G_UNICODE_SCRIPT_LATIN;
- out += g_unichar_to_utf8(character, out);
+ latin = u_getIntPropertyValue(character, UCHAR_SCRIPT) == USCRIPT_LATIN;
+ U16_APPEND_UNSAFE(normalized, used, character);
}
- else if (g_unichar_ismark(character))
+ else if (type == U_NON_SPACING_MARK || type == U_COMBINING_SPACING_MARK ||
+ type == U_ENCLOSING_MARK)
{
- if (!latin) out += g_unichar_to_utf8(character, out);
+ if (!latin) U16_APPEND_UNSAFE(normalized, used, character);
}
- else if (out != normalized && out[-1] != ' ')
- *out++ = ' ';
+ else if (used && normalized[used - 1] != ' ')
+ normalized[used++] = ' ';
}
- if (out != normalized && out[-1] == ' ') out--;
- *out = '\0';
- return normalized;
+ if (used && normalized[used - 1] == ' ') used--;
+
+ u_strToUTF8(NULL, 0, &length, normalized, used, &status);
+ if (U_FAILURE(status) && status != U_BUFFER_OVERFLOW_ERROR) goto done;
+ status = U_ZERO_ERROR;
+ result = malloc((size_t) length + 1);
+ if (result) u_strToUTF8(result, length + 1, NULL, normalized, used, &status);
+
+done:
+ free(normalized);
+ free(folded);
+ free(input);
+ return result;
}
static bool
@@ -114,7 +150,7 @@ _place_score(const char *city, const char *region, const char *country,
size_t city_matches = 0;
if (!strcmp(city, query)) return 4;
- if (g_str_has_prefix(city, query)) return 3;
+ if (!strncmp(city, query, strlen(query))) return 3;
for (size_t i = 0; words[i]; i++)
{
if (_word_matches(city, words[i], false)) city_matches++;
@@ -157,7 +193,7 @@ typedef struct
{
const char *query;
char **words;
- GArray *matches;
+ Eina_Inarray *matches;
const char *country;
char *country_search;
} Elements_Place_Search;
@@ -171,7 +207,7 @@ _place_search_row(const Elements_Catalog_Place *place, const char *country, void
if (search->country != country)
{
- g_free(search->country_search);
+ free(search->country_search);
search->country = country;
search->country_search = _search_text_get(country);
}
@@ -181,8 +217,8 @@ _place_search_row(const Elements_Catalog_Place *place, const char *country, void
region = _search_text_get(place->region);
match.score = city && region ? _place_score(city, region, search->country_search,
search->query, search->words) : 0;
- g_free(city);
- g_free(region);
+ free(city);
+ free(region);
if (!match.score) return true;
snprintf(match.place.name, sizeof(match.place.name), "%s%s%s, %s",
@@ -192,8 +228,7 @@ _place_search_row(const Elements_Catalog_Place *place, const char *country, void
match.place.longitude = place->longitude;
match.population = place->population;
match.country = search->country;
- g_array_append_val(search->matches, match);
- return true;
+ return eina_inarray_push(search->matches, &match) >= 0;
}
static int
@@ -212,40 +247,42 @@ elements_places_search(const char *query, Elements_Place results[ELEMENTS_PLACES
Elements_Place_Search search = { 0 };
char *normalized = _search_text_get(query);
size_t count = 0;
- GHashTable *countries;
+ const char *countries[ELEMENTS_PLACES_LIMIT];
- if (!normalized || g_utf8_strlen(normalized, -1) < 2) goto done;
+ if (!normalized || eina_unicode_utf8_get_len(normalized) < 2) goto done;
search.query = normalized;
- search.words = g_strsplit(normalized, " ", -1);
- search.matches = g_array_new(FALSE, FALSE, sizeof(Elements_Place_Match));
+ search.words = eina_str_split(normalized, " ", 0);
+ search.matches = eina_inarray_new(sizeof(Elements_Place_Match), 0);
+ if (!search.words || !search.matches) goto done;
_catalog_each(_place_search_row, &search);
- g_array_sort(search.matches, _match_compare);
+ eina_inarray_sort(search.matches, _match_compare);
- countries = g_hash_table_new(g_direct_hash, g_direct_equal);
- for (guint i = 0; i < search.matches->len && count < ELEMENTS_PLACES_LIMIT; i++)
+ unsigned int match_count = eina_inarray_count(search.matches);
+ for (unsigned int i = 0; i < match_count && count < ELEMENTS_PLACES_LIMIT; i++)
{
- Elements_Place_Match *match = &g_array_index(search.matches, Elements_Place_Match, i);
- unsigned int occurrences = GPOINTER_TO_UINT(g_hash_table_lookup(countries, match->country));
+ Elements_Place_Match *match = eina_inarray_nth(search.matches, i);
+ unsigned int occurrences = 0;
+ for (size_t j = 0; j < count; j++)
+ if (countries[j] == match->country) occurrences++;
if (occurrences >= 3) continue;
+ countries[count] = match->country;
results[count++] = match->place;
- g_hash_table_insert(countries, (void *) match->country, GUINT_TO_POINTER(occurrences + 1));
match->score = 0;
}
- for (guint i = 0; i < search.matches->len && count < ELEMENTS_PLACES_LIMIT; i++)
+ for (unsigned int i = 0; i < match_count && count < ELEMENTS_PLACES_LIMIT; i++)
{
- Elements_Place_Match *match = &g_array_index(search.matches, Elements_Place_Match, i);
+ Elements_Place_Match *match = eina_inarray_nth(search.matches, i);
if (match->score) results[count++] = match->place;
}
- g_hash_table_unref(countries);
- g_array_unref(search.matches);
- g_strfreev(search.words);
- g_free(search.country_search);
-
done:
- g_free(normalized);
+ if (search.matches) eina_inarray_free(search.matches);
+ if (search.words) free(search.words[0]);
+ free(search.words);
+ free(search.country_search);
+ free(normalized);
return count;
}
@@ -259,12 +296,12 @@ typedef struct
} Elements_Timezone_Search;
static bool
-_timezone_search_row(const Elements_Catalog_Place *place, const char *country G_GNUC_UNUSED,
+_timezone_search_row(const Elements_Catalog_Place *place, const char *country EINA_UNUSED,
void *data)
{
Elements_Timezone_Search *search = data;
- double latitude = place->latitude * G_PI / 180.0;
- double longitude = place->longitude * G_PI / 180.0;
+ double latitude = place->latitude * M_PI / 180.0;
+ double longitude = place->longitude * M_PI / 180.0;
double latitude_sine = sin((latitude - search->latitude) / 2.0);
double longitude_sine = sin((longitude - search->longitude) / 2.0);
double distance = latitude_sine * latitude_sine +
@@ -284,8 +321,8 @@ elements_place_timezone_resolve(Elements_Place *place)
if (*place->timezone) return;
search.place = place;
- search.latitude = place->latitude * G_PI / 180.0;
- search.longitude = place->longitude * G_PI / 180.0;
+ search.latitude = place->latitude * M_PI / 180.0;
+ search.longitude = place->longitude * M_PI / 180.0;
search.latitude_cos = cos(search.latitude);
search.distance = INFINITY;
_catalog_each(_timezone_search_row, &search);
diff --git a/src/lib/elements_request.c b/src/lib/elements_request.c
index a4c03f8..5a0d83d 100644
--- a/src/lib/elements_request.c
+++ b/src/lib/elements_request.c
@@ -20,7 +20,6 @@ struct _Elements_Request
Ecore_Event_Handler *data_handler;
Ecore_Event_Handler *complete_handler;
Eina_Strbuf *body;
- GTimeZone *zone;
Elements_Place place;
Elements_Request_Cb done;
};
@@ -33,7 +32,6 @@ elements_request_free(Elements_Request *request)
if (request->complete_handler) ecore_event_handler_del(request->complete_handler);
if (request->url) ecore_con_url_free(request->url);
if (request->body) eina_strbuf_free(request->body);
- g_time_zone_unref(request->zone);
free(request);
}
@@ -72,7 +70,7 @@ _request_complete(void *data, int type EINA_UNUSED, void *event)
if (complete->status == 200)
{
if (elements_forecast_parse(eina_strbuf_string_get(request->body), &request->place,
- request->zone, time(NULL), &forecast))
+ time(NULL), &forecast))
_request_finish(request, &forecast, NULL);
else
_request_finish(request, NULL, _("The weather service returned no usable forecast."));
@@ -115,7 +113,7 @@ _ca_bundle_get(void)
}
Elements_Request *
-elements_request_start(const Elements_Place *place, GTimeZone *zone,
+elements_request_start(const Elements_Place *place,
Elements_Request_Cb done)
{
char url[256];
@@ -134,7 +132,6 @@ elements_request_start(const Elements_Place *place, GTimeZone *zone,
request = calloc(1, sizeof(*request));
if (!request) return NULL;
request->done = done;
- request->zone = g_time_zone_ref(zone);
request->place = *place;
request->url = ""
request->body = eina_strbuf_new();
diff --git a/src/lib/elements_request.h b/src/lib/elements_request.h
index a8466b0..952b543 100644
--- a/src/lib/elements_request.h
+++ b/src/lib/elements_request.h
@@ -7,7 +7,7 @@
typedef struct _Elements_Request Elements_Request;
typedef void (*Elements_Request_Cb)(const Elements_Forecast *forecast, const char *error);
-Elements_Request *elements_request_start(const Elements_Place *place, GTimeZone *zone,
+Elements_Request *elements_request_start(const Elements_Place *place,
Elements_Request_Cb done);
void elements_request_free(Elements_Request *request);
diff --git a/src/lib/elements_settings.c b/src/lib/elements_settings.c
index 846a151..51b1bac 100644
--- a/src/lib/elements_settings.c
+++ b/src/lib/elements_settings.c
@@ -1,4 +1,6 @@
-#include <glib.h>
+#define _GNU_SOURCE
+
+#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@@ -158,11 +160,14 @@ _heading_add(Evas_Object *box, const char *markup)
Evas_Object *label = elm_label_add(box);
char *escaped = elm_entry_utf8_to_markup(markup);
- char *heading = g_strdup_printf("<b>%s</b>", escaped ? escaped : "");
+ char *heading = NULL;
- elm_object_text_set(label, heading);
+ if (escaped && asprintf(&heading, "<b>%s</b>", escaped) < 0)
+ heading = NULL;
+
+ elm_object_text_set(label, heading ? heading : escaped ? escaped : "");
free(escaped);
- g_free(heading);
+ free(heading);
evas_object_size_hint_align_set(label, 0.0, 0.5);
_pack(box, label);
}
diff --git a/src/lib/elements_ui.c b/src/lib/elements_ui.c
index 69c5d16..67ca41b 100644
--- a/src/lib/elements_ui.c
+++ b/src/lib/elements_ui.c
@@ -1,9 +1,12 @@
+#define _GNU_SOURCE
+
#include <Elementary.h>
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
+#include <unicode/ustring.h>
#include "elements_intl.h"
#include "elements_about.h"
@@ -58,7 +61,7 @@ typedef struct
Elements_Current_View current;
Ecore_Timer *search_timer;
Ecore_Timer *clock_timer;
- GTimeZone *zone;
+ UCalendar *zone;
time_t clock_hour;
int clock_day;
Elements_Request *request;
@@ -97,10 +100,13 @@ static void
_label_set(Evas_Object *label, const char *value, bool bold)
{
char *escaped = elm_entry_utf8_to_markup(value);
- char *emphasis = bold && escaped ? g_strdup_printf("<b>%s</b>", escaped) : NULL;
+ char *emphasis = NULL;
+
+ if (bold && escaped && asprintf(&emphasis, "<b>%s</b>", escaped) < 0)
+ emphasis = NULL;
elm_object_text_set(label, emphasis ? emphasis : escaped ? escaped : "");
- g_free(emphasis);
+ free(emphasis);
free(escaped);
}
@@ -202,14 +208,35 @@ _weather_icon_add(Evas_Object *box, const char *name, int size)
return icon;
}
+static char *
+_local_time_format(struct tm local, const char *format)
+{
+ char text[128];
+ char abbreviation[32] = "UTC";
+
+ if (ui.zone && strstr(format, "%Z"))
+ {
+ UChar name[32];
+ UErrorCode status = U_ZERO_ERROR;
+ ucal_getTimeZoneDisplayName(ui.zone, local.tm_isdst ? UCAL_SHORT_DST : UCAL_SHORT_STANDARD,
+ "en_US", name, 32, &status);
+ u_strToUTF8(abbreviation, sizeof(abbreviation), NULL, name, -1, &status);
+ if (U_FAILURE(status) || status == U_STRING_NOT_TERMINATED_WARNING)
+ strftime(abbreviation, sizeof(abbreviation), "%z", &local);
+ }
+
+ local.tm_zone = abbreviation;
+ size_t length = strftime(text, sizeof(text), format, &local);
+ return length ? strdup(text) : NULL;
+}
+
static char *
_time_format(time_t timestamp, const char *format)
{
- GDateTime *local = elements_forecast_local_time(ui.zone, timestamp);
- char *text = local ? g_date_time_format(local, format) : NULL;
+ struct tm local;
- if (local) g_date_time_unref(local);
- return text;
+ return elements_forecast_local_time(ui.zone, timestamp, &local) ?
+ _local_time_format(local, format) : NULL;
}
static void
@@ -255,10 +282,11 @@ _hour_add(const Elements_Conditions *conditions, int *previous_day)
{
const Elements_Weather_Style *style = &styles[conditions->weather];
Evas_Object *card = _box_add(ui.hourly, EINA_FALSE, 4);
- GDateTime *local = elements_forecast_local_time(ui.zone, conditions->time);
- int day = g_date_time_get_day_of_year(local);
- char *hour = g_date_time_format(local, day == *previous_day ? "%H:%M" : "%a %H:%M");
- char *date = g_date_time_format(local, "%a %e %b · %H:%M %Z");
+ struct tm local;
+ bool have_local = elements_forecast_local_time(ui.zone, conditions->time, &local);
+ int day = have_local ? local.tm_yday + 1 : *previous_day;
+ char *hour = have_local ? _local_time_format(local, day == *previous_day ? "%H:%M" : "%a %H:%M") : NULL;
+ char *date = have_local ? _local_time_format(local, "%a %e %b · %H:%M %Z") : NULL;
char tooltip[128], temperature[32];
*previous_day = day;
@@ -269,9 +297,8 @@ _hour_add(const Elements_Conditions *conditions, int *previous_day)
snprintf(tooltip, sizeof(tooltip), "%s · %s", date ? date : "", _weather_label_get(conditions));
elm_object_tooltip_text_set(card, tooltip);
_pack(ui.hourly, card);
- g_free(hour);
- g_free(date);
- g_date_time_unref(local);
+ free(hour);
+ free(date);
}
static void
@@ -288,7 +315,7 @@ _day_add(const Elements_Forecast_Day *day)
_label_add(card, range, false);
_label_add(card, _weather_label_get(&day->representative), false);
_pack(ui.outlook, card);
- g_free(date);
+ free(date);
}
static void
@@ -311,7 +338,7 @@ _forecast_show(const Elements_Forecast *forecast)
_label_set(ui.current.temperature, temperature, true);
_label_set(ui.current.condition, _weather_label_get(&forecast->current), false);
_label_set(ui.current.date, sample ? sample : "", false);
- g_free(sample);
+ free(sample);
if (forecast->have_today) _range_text_get(range, sizeof(range), &forecast->today);
_label_set(ui.today_range, range, false);
@@ -422,7 +449,7 @@ _update(void *data EINA_UNUSED, Evas_Object *obj EINA_UNUSED,
void *event_info EINA_UNUSED)
{
elements_request_free(ui.request);
- ui.request = elements_request_start(&ui.place, ui.zone, _fetch_done);
+ ui.request = elements_request_start(&ui.place, _fetch_done);
if (ui.request)
{
_status_set("");
@@ -435,17 +462,16 @@ static Eina_Bool
_clock_tick(void *data EINA_UNUSED)
{
time_t now = time(NULL);
- GDateTime *local = elements_forecast_local_time(ui.zone, now);
+ struct tm local;
char *text;
int day;
bool day_changed, hour_changed;
- if (!local) return ECORE_CALLBACK_RENEW;
- text = g_date_time_format(local, "%a %e %b · %H:%M %Z");
+ if (!elements_forecast_local_time(ui.zone, now, &local)) return ECORE_CALLBACK_RENEW;
+ text = _local_time_format(local, "%a %e %b · %H:%M %Z");
_label_set(ui.clock, text ? text : "", false);
- g_free(text);
- day = g_date_time_get_day_of_year(local);
- g_date_time_unref(local);
+ free(text);
+ day = local.tm_yday + 1;
day_changed = ui.clock_day && ui.clock_day != day;
hour_changed = ui.clock_hour && ui.clock_hour != now / 3600;
@@ -459,10 +485,9 @@ _clock_tick(void *data EINA_UNUSED)
static void
_place_timezone_set(void)
{
- if (ui.zone) g_time_zone_unref(ui.zone);
+ if (ui.zone) ucal_close(ui.zone);
elements_place_timezone_resolve(&ui.place);
- ui.zone = g_time_zone_new_identifier(ui.place.timezone);
- if (!ui.zone) ui.zone = g_time_zone_new_utc();
+ ui.zone = elements_forecast_zone_open(ui.place.timezone);
ui.clock_hour = 0;
ui.clock_day = 0;
_clock_tick(NULL);
@@ -528,8 +553,17 @@ _results_show(bool show_current)
size_t count = 0;
elm_genlist_clear(ui.results_list);
- if (text) g_strstrip(text);
- if (!text || g_utf8_strlen(text, -1) < 2)
+ if (text)
+ {
+ const char *whitespace = " \t\r\n\v\f";
+ const char *start = text + strspn(text, whitespace);
+ size_t length = strlen(start);
+
+ while (length && strchr(whitespace, start[length - 1])) length--;
+ memmove(text, start, length);
+ text[length] = '\0';
+ }
+ if (!text || eina_unicode_utf8_get_len(text) < 2)
{
if (!show_current)
{
@@ -853,7 +887,7 @@ elements_ui_shutdown(void)
ui.request = NULL;
_search_cancel();
if (ui.clock_timer) ecore_timer_del(ui.clock_timer);
- g_time_zone_unref(ui.zone);
+ if (ui.zone) ucal_close(ui.zone);
elements_settings_free(ui.settings);
elements_effects_free(ui.effects);
elements_theme_view_free(ui.theme_view);
diff --git a/src/lib/meson.build b/src/lib/meson.build
index 3488131..3fc86f9 100644
--- a/src/lib/meson.build
+++ b/src/lib/meson.build
@@ -1,13 +1,13 @@
elements_json_dep = dependency('json-c')
elements_con_dep = dependency('ecore-con')
-elements_glib_dep = dependency('glib-2.0', version : '>=2.68')
+elements_icu_deps = [dependency('icu-i18n'), dependency('icu-uc')]
elements_math_dep = meson.get_compiler('c').find_library('m')
elements_elementary_dep = dependency('elementary', version : '>=1.26')
elements_forecast = static_library('elements_forecast',
['elements_forecast.c', 'elements_request.c'],
include_directories : include_directories('../..'),
- dependencies : [elements_json_dep, elements_con_dep, elements_glib_dep, elements_math_dep, elements_intl_dep, dependency('ecore')],
+ dependencies : [elements_json_dep, elements_con_dep, elements_math_dep, elements_intl_dep, dependency('ecore')] + elements_icu_deps,
)
elements_forecast_dep = declare_dependency(link_with : elements_forecast)
@@ -15,7 +15,7 @@ elements_ui = static_library('elements_ui',
['elements_ui.c', 'elements_intl.c', 'elements_about.c', 'elements_settings.c', 'elements_config.c', 'elements_effects.c', 'elements_places.c', 'elements_theme.c', 'elements_window.c'] + elements_catalog_source,
include_directories : include_directories('../..'),
dependencies : [elements_elementary_dep, elements_forecast_dep, dependency('eet'), dependency('edje'), dependency('ecore-evas'),
- dependency('efreet'), dependency('ecore-file'), elements_glib_dep, elements_math_dep, elements_intl_dep],
+ dependency('efreet'), dependency('ecore-file'), elements_math_dep, elements_intl_dep] + elements_icu_deps,
)
elements_ui_dep = declare_dependency(
link_with : elements_ui,
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.