From cb533aabb7eebbfc6bab5d7b1892dbfca3dae589 Mon Sep 17 00:00:00 2001 From: Evangelos Ribeiro Tzaras Date: Tue, 18 May 2021 18:31:05 +0200 Subject: [PATCH] manager: Update country code By connecting to the "notify::country-code" signal of our origins. --- src/calls-manager.c | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/src/calls-manager.c b/src/calls-manager.c index 2b185ac..14be3c3 100644 --- a/src/calls-manager.c +++ b/src/calls-manager.c @@ -24,6 +24,7 @@ #include "config.h" +#include "calls-application.h" #include "calls-account-provider.h" #include "calls-contacts-provider.h" #include "calls-manager.h" @@ -248,6 +249,27 @@ ussd_state_changed_cb (CallsManager *self, g_signal_emit (self, signals[USSD_STATE_CHANGED], 0, ussd); } +static void +update_country_code_cb (CallsOrigin *origin, + GParamSpec *pspec, + CallsManager *self) +{ + CallsApplication *app; + g_autofree char *country_code = NULL; + + g_assert (CALLS_IS_MANAGER (self)); + app = CALLS_APPLICATION (g_application_get_default ()); + + g_object_get (G_OBJECT (origin), "country-code", &country_code, NULL); + + if (country_code && g_strcmp0 (country_code, self->country_code) == 0) + return; + + g_free (self->country_code); + self->country_code = country_code; + calls_application_set_country_code_setting (app, country_code); +} + static void add_origin (CallsManager *self, CallsOrigin *origin) { @@ -260,6 +282,11 @@ add_origin (CallsManager *self, CallsOrigin *origin) g_list_store_append (self->origins, origin); + g_signal_connect_object (origin, + "notify::country-code", + G_CALLBACK (update_country_code_cb), + self, + G_CONNECT_AFTER); g_signal_connect_swapped (origin, "call-added", G_CALLBACK (add_call), self); g_signal_connect_swapped (origin, "call-removed", G_CALLBACK (remove_call), self);