mirror of
https://gitlab.gnome.org/GNOME/calls.git
synced 2024-12-04 20:07:36 +00:00
emergency-calls-manager: Move contact adding to separate function
Improves readability and will be get another call site soon.
This commit is contained in:
parent
9c0acdd560
commit
678a41bade
1 changed files with 23 additions and 9 deletions
|
@ -104,6 +104,24 @@ handle_call_emergency_contact (CallsDBusEmergencyCalls *object,
|
|||
#define CONTACT_FORMAT "(ssia{sv})"
|
||||
#define CONTACTS_FORMAT "a" CONTACT_FORMAT
|
||||
|
||||
|
||||
static void
|
||||
add_emergency_contact (GVariantBuilder *contacts_builder,
|
||||
const char *number,
|
||||
const char *contact,
|
||||
CallsEmergencyContactSource type)
|
||||
|
||||
{
|
||||
g_variant_builder_open (contacts_builder, G_VARIANT_TYPE (CONTACT_FORMAT));
|
||||
g_variant_builder_add (contacts_builder, "s", number);
|
||||
g_variant_builder_add (contacts_builder, "s", contact);
|
||||
g_variant_builder_add (contacts_builder, "i", type);
|
||||
/* Currently no hints */
|
||||
g_variant_builder_add (contacts_builder, "a{sv}", NULL);
|
||||
g_variant_builder_close (contacts_builder);
|
||||
}
|
||||
|
||||
|
||||
static gboolean
|
||||
handle_get_emergency_contacts (CallsDBusEmergencyCalls *object,
|
||||
GDBusMethodInvocation *invocation)
|
||||
|
@ -127,19 +145,15 @@ handle_get_emergency_contacts (CallsDBusEmergencyCalls *object,
|
|||
for (int j = 0; j < g_strv_length (emergency_numbers); j++) {
|
||||
g_autofree char *contact = NULL;
|
||||
|
||||
g_variant_builder_open (&contacts_builder, G_VARIANT_TYPE (CONTACT_FORMAT));
|
||||
g_variant_builder_add (&contacts_builder, "s", emergency_numbers[j]);
|
||||
|
||||
contact = calls_emergency_call_type_get_name (emergency_numbers[j], country_code);
|
||||
if (contact == NULL)
|
||||
contact = g_strdup (emergency_numbers[j]);
|
||||
g_variant_builder_add (&contacts_builder, "s", contact);
|
||||
/* Currently unused */
|
||||
g_variant_builder_add (&contacts_builder, "i",
|
||||
|
||||
add_emergency_contact (&contacts_builder,
|
||||
emergency_numbers[j],
|
||||
contact,
|
||||
/* TODO: allow to query type */
|
||||
CALLS_EMERGENCY_CONTACT_SOURCE_UNKNOWN);
|
||||
/* Currently no hints */
|
||||
g_variant_builder_add (&contacts_builder, "a{sv}", NULL);
|
||||
g_variant_builder_close (&contacts_builder);
|
||||
}
|
||||
}
|
||||
contacts = g_variant_builder_end (&contacts_builder);
|
||||
|
|
Loading…
Reference in a new issue