diff --git a/data/meson.build b/data/meson.build index 026941389f47876c26c7982b105f4749a79c3acf..88e3d2f640a59e65d56d6b38c7e96b4f57615f19 100644 --- a/data/meson.build +++ b/data/meson.build @@ -1,21 +1,3 @@ -pkgconfig.generate( - filebase: 'gweather-3.0', - name: 'GWeather', - description: 'GWeather shared library', - version: meson.project_version(), - libraries: lib_libgweather, - subdirs: 'libgweather-3.0', - requires: [ - 'gtk+-3.0', - ], - requires_private: [ - 'gio-2.0', - 'libsoup-2.4', - 'libxml-2.0', - 'geocode-glib-1.0', - ], -) - if enable_glade_catalog install_data('glade/libgweather.xml', install_dir: glade_catalogdir, diff --git a/libgweather/gweather-location-entry.c b/libgweather/gweather-location-entry.c index b6c7e236fcad2d551ea6b98946b7ab6e245d0ad0..92c3ce634e80b9f218023d590357bda25a23e7c0 100644 --- a/libgweather/gweather-location-entry.c +++ b/libgweather/gweather-location-entry.c @@ -67,12 +67,6 @@ static void set_location_internal (GWeatherLocationEntry *entry, GtkTreeModel *model, GtkTreeIter *iter, GWeatherLocation *loc); -static GWeatherLocation * -create_new_detached_location (GWeatherLocation *nearest_station, - const char *name, - gboolean latlon_valid, - gdouble latitude, - gdouble longitude); static void fill_location_entry_model (GtkTreeStore *store, GWeatherLocation *loc, const char *parent_display_name, @@ -325,7 +319,7 @@ set_location_internal (GWeatherLocationEntry *entry, g_free (name); } else if (loc) { priv->location = gweather_location_ref (loc); - gtk_entry_set_text (GTK_ENTRY (entry), loc->local_name); + gtk_entry_set_text (GTK_ENTRY (entry), gweather_location_get_name (loc)); priv->custom_text = FALSE; } else { priv->location = NULL; @@ -520,9 +514,9 @@ fill_location_entry_model (GtkTreeStore *store, GWeatherLocation *loc, /* Recurse, initializing the names to the country name */ for (i = 0; children[i]; i++) { fill_location_entry_model (store, children[i], - loc->local_name, - loc->local_sort_name, - loc->english_sort_name, + gweather_location_get_name (loc), + gweather_location_get_sort_name (loc), + gweather_location_get_english_sort_name (loc), show_named_timezones); } break; @@ -533,9 +527,9 @@ fill_location_entry_model (GtkTreeStore *store, GWeatherLocation *loc, * 'London, United Kingdom' * You shouldn't need to translate this string unless the language has a different comma. */ - display_name = g_strdup_printf (_("%s, %s"), loc->local_name, parent_display_name); - local_compare_name = g_strdup_printf ("%s, %s", loc->local_sort_name, parent_compare_local_name); - english_compare_name = g_strdup_printf ("%s, %s", loc->english_sort_name, parent_compare_english_name); + display_name = g_strdup_printf (_("%s, %s"), gweather_location_get_name (loc), parent_display_name); + local_compare_name = g_strdup_printf ("%s, %s", gweather_location_get_sort_name (loc), parent_compare_local_name); + english_compare_name = g_strdup_printf ("%s, %s", gweather_location_get_english_sort_name (loc), parent_compare_english_name); for (i = 0; children[i]; i++) { fill_location_entry_model (store, children[i], @@ -562,11 +556,11 @@ fill_location_entry_model (GtkTreeStore *store, GWeatherLocation *loc, * You shouldn't need to translate this string unless the language has a different comma. */ display_name = g_strdup_printf (_("%s, %s"), - loc->local_name, parent_display_name); + gweather_location_get_name (loc), parent_display_name); local_compare_name = g_strdup_printf ("%s, %s", - loc->local_sort_name, parent_compare_local_name); + gweather_location_get_sort_name (loc), parent_compare_local_name); english_compare_name = g_strdup_printf ("%s, %s", - loc->english_sort_name, parent_compare_english_name); + gweather_location_get_english_sort_name (loc), parent_compare_english_name); gtk_tree_store_insert_with_values (store, NULL, NULL, -1, LOC_GWEATHER_LOCATION_ENTRY_COL_LOCATION, loc, @@ -584,9 +578,9 @@ fill_location_entry_model (GtkTreeStore *store, GWeatherLocation *loc, if (show_named_timezones) { gtk_tree_store_insert_with_values (store, NULL, NULL, -1, LOC_GWEATHER_LOCATION_ENTRY_COL_LOCATION, loc, - LOC_GWEATHER_LOCATION_ENTRY_COL_DISPLAY_NAME, loc->local_name, - LOC_GWEATHER_LOCATION_ENTRY_COL_LOCAL_COMPARE_NAME, loc->local_sort_name, - LOC_GWEATHER_LOCATION_ENTRY_COL_ENGLISH_COMPARE_NAME, loc->english_sort_name, + LOC_GWEATHER_LOCATION_ENTRY_COL_DISPLAY_NAME, gweather_location_get_name (loc), + LOC_GWEATHER_LOCATION_ENTRY_COL_LOCAL_COMPARE_NAME, gweather_location_get_sort_name (loc), + LOC_GWEATHER_LOCATION_ENTRY_COL_ENGLISH_COMPARE_NAME, gweather_location_get_english_sort_name (loc), -1); } break; @@ -706,7 +700,11 @@ match_selected (GtkEntryCompletion *completion, GtkTreeIter *iter, gpointer entry) { - if (model != ((GWeatherLocationEntry *)entry)->priv->model) { + GWeatherLocationEntryPrivate *priv; + + priv = ((GWeatherLocationEntry *)entry)->priv; + + if (model != priv->model) { GeocodePlace *place; char *display_name; GeocodeLocation *loc; @@ -720,17 +718,17 @@ match_selected (GtkEntryCompletion *completion, -1); country_code = geocode_place_get_country_code (place); - if (country_code != NULL) - scope = gweather_location_find_by_country_code (gweather_location_get_world (), country_code); - else - scope = gweather_location_get_world (); + if (country_code != NULL && gweather_location_get_level (priv->top) == GWEATHER_LOCATION_WORLD) + scope = gweather_location_find_by_country_code (priv->top, country_code); + if (!scope) + scope = priv->top; loc = geocode_place_get_location (place); location = gweather_location_find_nearest_city (scope, geocode_location_get_latitude (loc), geocode_location_get_longitude (loc)); - location = create_new_detached_location(location, display_name, TRUE, - geocode_location_get_latitude (loc) * M_PI / 180.0, - geocode_location_get_longitude (loc) * M_PI / 180.0); + location = _gweather_location_new_detached (location, display_name, TRUE, + geocode_location_get_latitude (loc) * M_PI / 180.0, + geocode_location_get_longitude (loc) * M_PI / 180.0); set_location_internal (entry, model, NULL, location); @@ -849,45 +847,3 @@ gweather_location_entry_new (GWeatherLocation *top) "top", top, NULL); } - -static GWeatherLocation * -create_new_detached_location (GWeatherLocation *nearest_station, - const char *name, - gboolean latlon_valid, - gdouble latitude, - gdouble longitude) -{ - GWeatherLocation *self; - char *normalized; - - self = g_slice_new0 (GWeatherLocation); - self->ref_count = 1; - self->level = GWEATHER_LOCATION_DETACHED; - 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); - - self->parent = nearest_station; - self->children = NULL; - - if (nearest_station) - self->station_code = g_strdup (nearest_station->station_code); - - g_assert (nearest_station || latlon_valid); - - if (latlon_valid) { - 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; - } - - return self; -} diff --git a/libgweather/gweather-location.c b/libgweather/gweather-location.c index 1477e51a247798df29c17cff867c200cbc051bf5..c472f27447f0eee6473487e6c97bbc2b0f892517 100644 --- a/libgweather/gweather-location.c +++ b/libgweather/gweather-location.c @@ -616,6 +616,26 @@ gweather_location_get_english_name (GWeatherLocation *loc) return loc->english_name; } +/** + * gweather_location_get_english_sort_name: + * @loc: a #GWeatherLocation + * + * Gets @loc's english "sort name", which is the english name after having + * g_utf8_normalize() (with %G_NORMALIZE_ALL) and g_utf8_casefold() + * called on it. You can use this to sort locations, or to comparing + * user input against a location name. + * + * Return value: @loc's English name for sorting + * Since: 3.38 + **/ +const char * +gweather_location_get_english_sort_name (GWeatherLocation *loc) +{ + g_return_val_if_fail (loc != NULL, NULL); + + return loc->english_sort_name; +} + /** * gweather_location_get_level: * @loc: a #GWeatherLocation diff --git a/libgweather/gweather-location.h b/libgweather/gweather-location.h index b33afb559f4470a9c97b7ea3ee4aa969d7601e6e..701862d83dca809fd1a402b943da89c3f81fe926 100644 --- a/libgweather/gweather-location.h +++ b/libgweather/gweather-location.h @@ -65,6 +65,8 @@ const char *gweather_location_get_sort_name (GWeatherLocation *loc) GWEATHER_EXTERN const char *gweather_location_get_english_name (GWeatherLocation *loc); GWEATHER_EXTERN +const char *gweather_location_get_english_sort_name (GWeatherLocation *loc); +GWEATHER_EXTERN GWeatherLocationLevel gweather_location_get_level (GWeatherLocation *loc); GWEATHER_EXTERN GWeatherLocation *gweather_location_get_parent (GWeatherLocation *loc); diff --git a/libgweather/test_libgweather.c b/libgweather/test_libgweather.c index f152a4fe91c0ebd9de66d3e91be33625a14636b8..f482fcbca69a1d23bf830903e0d0552eaf293669 100644 --- a/libgweather/test_libgweather.c +++ b/libgweather/test_libgweather.c @@ -43,7 +43,7 @@ test_named_timezones (void) guint i; world = gweather_location_get_world (); - g_assert (world); + g_assert_nonnull (world); children = gweather_location_get_children (world); for (i = 0; children[i] != NULL; i++) { @@ -132,7 +132,7 @@ test_named_timezones_deserialized (void) GList *list, *l; world = gweather_location_get_world (); - g_assert (world); + g_assert_nonnull (world); list = get_list_from_configuration (world, CONFIGURATION, 3); for (l = list; l != NULL; l = l->next) @@ -171,7 +171,7 @@ test_no_code_serialize (void) g_assert_nonnull (world); loc = gweather_location_find_nearest_city (world, 56.833333, 53.183333); - g_assert (loc); + g_assert_nonnull (loc); g_assert_cmpstr (gweather_location_get_name (loc), ==, "Izhevsk"); g_assert_null (gweather_location_get_code (loc)); @@ -204,11 +204,11 @@ test_timezone (GWeatherLocation *location) GWeatherTimezone **tzs; tzs = gweather_location_get_timezones (location); - g_assert (tzs); + g_assert_nonnull (tzs); /* Only countries should have multiple timezones associated */ if ((tzs[0] == NULL && gweather_location_get_level (location) < GWEATHER_LOCATION_WEATHER_STATION) && - gweather_location_get_level (location) > GWEATHER_LOCATION_COUNTRY) { + gweather_location_get_level (location) >= GWEATHER_LOCATION_COUNTRY) { g_print ("Location '%s' does not have an associated timezone\n", gweather_location_get_name (location)); g_test_fail (); @@ -247,7 +247,7 @@ test_timezones (void) GWeatherLocation *world; world = gweather_location_get_world (); - g_assert (world); + g_assert_nonnull (world); test_timezones_children (world); @@ -296,7 +296,7 @@ test_airport_distance_sanity (void) GWeatherLocation *world; world = gweather_location_get_world (); - g_assert (world); + g_assert_nonnull (world); test_airport_distance_children (world); @@ -418,12 +418,12 @@ test_metar_weather_stations (void) char *contents; world = gweather_location_get_world (); - g_assert (world); + g_assert_nonnull (world); msg = soup_message_new ("GET", METAR_SOURCES); session = soup_session_new (); soup_session_send_message (session, msg); - g_assert (SOUP_STATUS_IS_SUCCESSFUL (msg->status_code)); + g_assert_true (SOUP_STATUS_IS_SUCCESSFUL (msg->status_code)); g_object_unref (session); g_assert_nonnull (msg->response_body); @@ -448,20 +448,19 @@ set_gsettings (void) int result; /* Create the installed schemas directory */ - tmpdir = g_strdup_printf ("libgweather-test-XXXXXX"); - tmpdir = g_dir_make_tmp (tmpdir, NULL); + tmpdir = g_dir_make_tmp ("libgweather-test-XXXXXX", NULL); g_assert_nonnull (tmpdir); /* Copy the schemas files */ - g_assert (g_file_get_contents (SCHEMAS_BUILDDIR "/org.gnome.GWeather.enums.xml", &schema_text, NULL, NULL)); + g_assert_true (g_file_get_contents (SCHEMAS_BUILDDIR "/org.gnome.GWeather.enums.xml", &schema_text, NULL, NULL)); dest = g_strdup_printf ("%s/org.gnome.GWeather.enums.xml", tmpdir); - g_assert (g_file_set_contents (dest, schema_text, -1, NULL)); + g_assert_true (g_file_set_contents (dest, schema_text, -1, NULL)); g_free (dest); g_free (schema_text); - g_assert (g_file_get_contents (SCHEMASDIR "/org.gnome.GWeather.gschema.xml", &schema_text, NULL, NULL)); + g_assert_true (g_file_get_contents (SCHEMASDIR "/org.gnome.GWeather.gschema.xml", &schema_text, NULL, NULL)); dest = g_strdup_printf ("%s/org.gnome.GWeather.gschema.xml", tmpdir); - g_assert (g_file_set_contents (dest, schema_text, -1, NULL)); + g_assert_true (g_file_set_contents (dest, schema_text, -1, NULL)); g_free (dest); g_free (schema_text); @@ -470,8 +469,8 @@ set_gsettings (void) "--schema-file=%s/org.gnome.GWeather.enums.xml " "--schema-file=%s/org.gnome.GWeather.gschema.xml", tmpdir, SCHEMAS_BUILDDIR, SCHEMASDIR); - g_assert (g_spawn_command_line_sync (cmdline, NULL, NULL, &result, NULL)); - g_assert (result == 0); + g_assert_true (g_spawn_command_line_sync (cmdline, NULL, NULL, &result, NULL)); + g_assert_cmpint (result, ==, 0); g_free (cmdline); /* Set envvar */ @@ -581,7 +580,7 @@ test_bad_duplicate_weather_stations (void) g_setenv ("LIBGWEATHER_LOCATIONS_NO_NEAREST", "1", TRUE); world = gweather_location_get_world (); - g_assert (world); + g_assert_nonnull (world); stations_ht = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, (GDestroyNotify) NULL); @@ -643,7 +642,7 @@ test_duplicate_weather_stations (void) g_setenv ("LIBGWEATHER_LOCATIONS_NO_NEAREST", "1", TRUE); world = gweather_location_get_world (); - g_assert (world); + g_assert_nonnull (world); test_duplicate_weather_stations_children (world); @@ -657,10 +656,10 @@ test_location_names (void) GWeatherLocation *world, *brussels; world = gweather_location_get_world (); - g_assert (world); + g_assert_nonnull (world); brussels = gweather_location_find_nearest_city (world, 50.833333, 4.333333); - g_assert (brussels); + g_assert_nonnull (brussels); g_assert_cmpstr (gweather_location_get_name (brussels), ==, "Brussels"); g_assert_cmpstr (gweather_location_get_sort_name (brussels), ==, "brussels"); g_assert_cmpstr (gweather_location_get_english_name (brussels), ==, "Brussels"); @@ -670,10 +669,10 @@ test_location_names (void) _gweather_location_reset_world (); world = gweather_location_get_world (); - g_assert (world); + g_assert_nonnull (world); brussels = gweather_location_find_nearest_city (world, 50.833333, 4.333333); - g_assert (brussels); + g_assert_nonnull (brussels); g_assert_cmpstr (gweather_location_get_name (brussels), ==, "Bruxelles"); g_assert_cmpstr (gweather_location_get_sort_name (brussels), ==, "bruxelles"); g_assert_cmpstr (gweather_location_get_english_name (brussels), ==, "Brussels"); diff --git a/meson.build b/meson.build index 98724ea1a3ac1de4cd172a385cc3f939613e103e..9bf8e753dbb9aa6d2f993fc4f7c1271afae61fe4 100644 --- a/meson.build +++ b/meson.build @@ -124,3 +124,21 @@ endif subdir('po') subdir('po-locations') meson.add_install_script('meson/meson_post_install.py') + +pkgconfig.generate( + filebase: 'gweather-3.0', + name: 'GWeather', + description: 'GWeather shared library', + version: meson.project_version(), + libraries: lib_libgweather, + subdirs: 'libgweather-3.0', + requires: [ + 'gtk+-3.0', + ], + requires_private: [ + 'gio-2.0', + 'libsoup-2.4', + 'libxml-2.0', + 'geocode-glib-1.0', + ], +)