1
0
Fork 0
mirror of https://gitlab.gnome.org/GNOME/calls.git synced 2024-11-15 12:55:36 +00:00

emergency-calls-manager: Query origins for numbers

When the origins change we notify that emergency numbers
might have changed.
This commit is contained in:
Guido Günther 2021-12-17 19:42:47 +01:00 committed by Evangelos Ribeiro Tzaras
parent 9af09a0db9
commit d5cba4db7f

View file

@ -9,6 +9,8 @@
#define G_LOG_DOMAIN "CallsEmergencyCallsManger" #define G_LOG_DOMAIN "CallsEmergencyCallsManger"
#include "calls-emergency-calls-manager.h" #include "calls-emergency-calls-manager.h"
#include "calls-origin.h"
#include "calls-manager.h"
/** /**
* SECTION:calls-emergency-calls-manager * SECTION:calls-emergency-calls-manager
@ -23,7 +25,7 @@ typedef struct _CallsEmergencyCallsManager
{ {
CallsDBusEmergencyCallsSkeleton parent; CallsDBusEmergencyCallsSkeleton parent;
int dbus_name_id; GListModel *origins;
} CallsEmergencyCallsManger; } CallsEmergencyCallsManger;
static void calls_emergency_calls_iface_init (CallsDBusEmergencyCallsIface *iface); static void calls_emergency_calls_iface_init (CallsDBusEmergencyCallsIface *iface);
@ -35,22 +37,66 @@ G_DEFINE_TYPE_WITH_CODE (CallsEmergencyCallsManager,
CALLS_DBUS_TYPE_EMERGENCY_CALLS, CALLS_DBUS_TYPE_EMERGENCY_CALLS,
calls_emergency_calls_iface_init)); calls_emergency_calls_iface_init));
static void
on_origins_changed (CallsEmergencyCallsManger *self)
{
g_assert (CALLS_IS_EMERGENCY_CALLS_MANAGER (self));
g_signal_emit_by_name (self, "emergency-numbers-changed", 0);
}
static gboolean static gboolean
handle_call_emergency_contact (CallsDBusEmergencyCalls *object, handle_call_emergency_contact (CallsDBusEmergencyCalls *object,
GDBusMethodInvocation *invocation, GDBusMethodInvocation *invocation,
const gchar *arg_id) const gchar *arg_id)
{ {
return FALSE; g_debug ("Calling %s", arg_id);
calls_dbus_emergency_calls_complete_call_emergency_contact (object, invocation);
return TRUE;
} }
#define CONTACT_FORMAT "(ssia{sv})"
#define CONTACTS_FORMAT "a" CONTACT_FORMAT
static gboolean static gboolean
handle_get_emergency_contacts (CallsDBusEmergencyCalls *object, handle_get_emergency_contacts (CallsDBusEmergencyCalls *object,
GDBusMethodInvocation *invocation) GDBusMethodInvocation *invocation)
{ {
return FALSE; GVariant *contacts;
} GVariantBuilder contacts_builder;
CallsEmergencyCallsManger *self = CALLS_EMERGENCY_CALLS_MANAGER (object);
g_variant_builder_init (&contacts_builder, G_VARIANT_TYPE (CONTACTS_FORMAT));
for (int i = 0; i < g_list_model_get_n_items (self->origins); i++) {
CallsOrigin *origin = g_list_model_get_item (self->origins, i);
g_auto (GStrv) emergency_numbers = NULL;
emergency_numbers = calls_origin_get_emergency_numbers (origin);
if (!emergency_numbers)
continue;
for (int j = 0; j < g_strv_length (emergency_numbers); j++) {
g_variant_builder_open (&contacts_builder, G_VARIANT_TYPE (CONTACT_FORMAT));
g_variant_builder_add (&contacts_builder, "s", emergency_numbers[j]);
/* For non-addressbook numbers we just use the number itself as contact */
g_variant_builder_add (&contacts_builder, "s", emergency_numbers[j]);
/* Currently unused */
g_variant_builder_add (&contacts_builder, "i", 0);
/* 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);
calls_dbus_emergency_calls_complete_get_emergency_contacts (object, invocation, contacts);
return TRUE;
}
static void static void
calls_emergency_calls_iface_init (CallsDBusEmergencyCallsIface *iface) calls_emergency_calls_iface_init (CallsDBusEmergencyCallsIface *iface)
@ -60,14 +106,33 @@ calls_emergency_calls_iface_init (CallsDBusEmergencyCallsIface *iface)
} }
static void static void
calls_emergency_calls_manager_class_init (CallsEmergencyCallsManagerClass *klass) calls_emergency_calls_manager_dispose (GObject *object)
{ {
CallsEmergencyCallsManager *self = CALLS_EMERGENCY_CALLS_MANAGER (object);
g_clear_object (&self->origins);
G_OBJECT_CLASS (calls_emergency_calls_manager_parent_class)->dispose (object);
} }
static void
calls_emergency_calls_manager_class_init (CallsEmergencyCallsManagerClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
object_class->dispose = calls_emergency_calls_manager_dispose;
}
static void static void
calls_emergency_calls_manager_init (CallsEmergencyCallsManager *self) calls_emergency_calls_manager_init (CallsEmergencyCallsManager *self)
{ {
CallsManager *manager = calls_manager_get_default ();
self->origins = g_object_ref (calls_manager_get_origins (manager));
g_signal_connect_object (self->origins,
"items-changed",
G_CALLBACK (on_origins_changed),
self, G_CONNECT_SWAPPED);
} }
CallsEmergencyCallsManager * CallsEmergencyCallsManager *