diff --git a/plugins/mm/calls-mm-origin.c b/plugins/mm/calls-mm-origin.c index 2413320..8ac3491 100644 --- a/plugins/mm/calls-mm-origin.c +++ b/plugins/mm/calls-mm-origin.c @@ -27,6 +27,7 @@ #include "calls-ussd.h" #include "calls-mm-call.h" #include "calls-message-source.h" +#include "itu-e212-iso.h" #include @@ -37,6 +38,7 @@ struct _CallsMMOrigin MMObject *mm_obj; MMModemVoice *voice; MMModem3gppUssd *ussd; + MMSim *sim; /* XXX: These should be used only for pointer comparison, * The content should never be used as it might be @@ -47,6 +49,7 @@ struct _CallsMMOrigin gulong ussd_handle_id; gchar *name; GHashTable *calls; + char *country_code; }; static void calls_mm_origin_message_source_interface_init (CallsOriginInterface *iface); @@ -647,7 +650,7 @@ get_property (GObject *object, break; case PROP_COUNTRY_CODE: - g_value_set_string (value, NULL); + g_value_set_string (value, self->country_code); break; default: @@ -747,6 +750,28 @@ call_mm_ussd_changed_cb (CallsMMOrigin *self) G_CONNECT_SWAPPED); } +static void +cb_get_sim_ready (MMModem *modem, + GAsyncResult *res, + gpointer user_data) +{ + const char *code; + CallsMMOrigin *self = CALLS_MM_ORIGIN (user_data); + + self->sim = mm_modem_get_sim_finish (modem, res, NULL); + + code = get_country_iso_for_mcc (mm_sim_get_imsi (self->sim)); + if (code) { + if (g_strcmp0 (self->country_code, code) == 0) + return; + + g_debug ("Setting the country code to `%s'", code); + + self->country_code = g_strdup (code); + g_object_notify_by_pspec (G_OBJECT (self), props[PROP_COUNTRY_CODE]); + } +} + static void constructed (GObject *object) { @@ -755,6 +780,11 @@ constructed (GObject *object) self->name = modem_get_name (mm_object_get_modem (self->mm_obj)); + mm_modem_get_sim (mm_object_get_modem (self->mm_obj), + NULL, + (GAsyncReadyCallback) cb_get_sim_ready, + self); + g_signal_connect_object (self->mm_obj, "notify::modem3gpp-ussd", G_CALLBACK (call_mm_ussd_changed_cb), self, G_CONNECT_SWAPPED); @@ -786,6 +816,7 @@ dispose (GObject *object) remove_calls (self, NULL); g_clear_object (&self->mm_obj); g_clear_object (&self->ussd); + g_clear_pointer (&self->country_code, g_free); G_OBJECT_CLASS (calls_mm_origin_parent_class)->dispose (object); }