1
0
Fork 0
mirror of https://gitlab.gnome.org/GNOME/calls.git synced 2025-01-05 19:15:32 +00:00

mm: Implement country-code property

Closes #167
This commit is contained in:
Evangelos Ribeiro Tzaras 2021-03-26 11:27:25 +01:00
parent 463344c52b
commit a559587a19

View file

@ -27,6 +27,7 @@
#include "calls-ussd.h"
#include "calls-mm-call.h"
#include "calls-message-source.h"
#include "itu-e212-iso.h"
#include <glib/gi18n.h>
@ -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);
}