1
0
Fork 0
mirror of https://gitlab.gnome.org/GNOME/calls.git synced 2024-12-04 20:07:36 +00:00

emergency-calls-manager: Use network code to get emergency numbers

By far not all sims have emergency numbers and we want to respect the
users current location anyway.

We use a hash to avoid duplicates.
This commit is contained in:
Guido Günther 2023-07-19 12:41:54 +02:00
parent 678a41bade
commit e49cd86035

View file

@ -129,6 +129,10 @@ handle_get_emergency_contacts (CallsDBusEmergencyCalls *object,
GVariant *contacts;
GVariantBuilder contacts_builder;
CallsEmergencyCallsManager *self = CALLS_EMERGENCY_CALLS_MANAGER (object);
g_autoptr (GHashTable) numbers = g_hash_table_new_full (g_str_hash,
g_str_equal,
g_free,
NULL);
g_variant_builder_init (&contacts_builder, G_VARIANT_TYPE (CONTACTS_FORMAT));
@ -137,14 +141,36 @@ handle_get_emergency_contacts (CallsDBusEmergencyCalls *object,
g_auto (GStrv) emergency_numbers = NULL;
const char *country_code;
emergency_numbers = calls_origin_get_emergency_numbers (origin);
if (!emergency_numbers)
continue;
country_code = calls_origin_get_country_code (origin);
for (int j = 0; j < g_strv_length (emergency_numbers); j++) {
/* Emergency numbers by location */
country_code = calls_origin_get_network_country_code (origin);
emergency_numbers = calls_emergency_call_types_get_numbers_by_country_code (country_code);
for (int j = 0; emergency_numbers && j < g_strv_length (emergency_numbers); j++) {
g_autofree char *contact = NULL;
if (g_hash_table_contains (numbers, emergency_numbers[j]))
continue;
contact = calls_emergency_call_type_get_name (emergency_numbers[j], country_code);
if (contact == NULL)
contact = g_strdup (emergency_numbers[j]);
add_emergency_contact (&contacts_builder,
emergency_numbers[j],
contact,
CALLS_EMERGENCY_CONTACT_SOURCE_LOCATION);
g_hash_table_insert (numbers, g_strdup (emergency_numbers[j]), NULL);
}
g_clear_pointer (&emergency_numbers, g_strfreev);
/* Emergency numbers by origin */
country_code = calls_origin_get_country_code (origin);
emergency_numbers = calls_origin_get_emergency_numbers (origin);
for (int j = 0; emergency_numbers && j < g_strv_length (emergency_numbers); j++) {
g_autofree char *contact = NULL;
if (g_hash_table_contains (numbers, emergency_numbers[j]))
continue;
contact = calls_emergency_call_type_get_name (emergency_numbers[j], country_code);
if (contact == NULL)
contact = g_strdup (emergency_numbers[j]);
@ -154,6 +180,7 @@ handle_get_emergency_contacts (CallsDBusEmergencyCalls *object,
contact,
/* TODO: allow to query type */
CALLS_EMERGENCY_CONTACT_SOURCE_UNKNOWN);
g_hash_table_insert (numbers, g_strdup (emergency_numbers[j]), NULL);
}
}
contacts = g_variant_builder_end (&contacts_builder);