Simplify country code handling
This commit is contained in:
@@ -48,16 +48,16 @@ struct _CallsContactsProvider
|
||||
GObject parent_instance;
|
||||
|
||||
FolksIndividualAggregator *folks_aggregator;
|
||||
CallsSettings *settings;
|
||||
|
||||
GHashTable *phone_number_best_matches;
|
||||
gchar *country_code;
|
||||
};
|
||||
|
||||
G_DEFINE_TYPE (CallsContactsProvider, calls_contacts_provider, G_TYPE_OBJECT)
|
||||
|
||||
enum {
|
||||
PROP_0,
|
||||
PROP_COUNTRY_CODE,
|
||||
PROP_SETTINGS,
|
||||
PROP_LAST_PROP
|
||||
};
|
||||
static GParamSpec *props[PROP_LAST_PROP];
|
||||
@@ -177,28 +177,8 @@ calls_contacts_provider_set_property (GObject *object,
|
||||
CallsContactsProvider *self = CALLS_CONTACTS_PROVIDER (object);
|
||||
|
||||
switch (property_id) {
|
||||
case PROP_COUNTRY_CODE:
|
||||
g_free (self->country_code);
|
||||
self->country_code = g_value_dup_string (value);
|
||||
break;
|
||||
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
calls_contacts_provider_get_property (GObject *object,
|
||||
guint property_id,
|
||||
GValue *value,
|
||||
GParamSpec *pspec)
|
||||
{
|
||||
CallsContactsProvider *self = CALLS_CONTACTS_PROVIDER (object);
|
||||
|
||||
switch (property_id) {
|
||||
case PROP_COUNTRY_CODE:
|
||||
g_value_set_string (value, self->country_code);
|
||||
case PROP_SETTINGS:
|
||||
self->settings = g_value_dup_object (value);
|
||||
break;
|
||||
|
||||
default:
|
||||
@@ -213,8 +193,8 @@ calls_contacts_provider_finalize (GObject *object)
|
||||
{
|
||||
CallsContactsProvider *self = CALLS_CONTACTS_PROVIDER (object);
|
||||
|
||||
g_clear_object (&self->country_code);
|
||||
g_clear_object (&self->folks_aggregator);
|
||||
g_clear_object (&self->settings);
|
||||
g_clear_pointer (&self->phone_number_best_matches, g_hash_table_unref);
|
||||
|
||||
G_OBJECT_CLASS (calls_contacts_provider_parent_class)->finalize (object);
|
||||
@@ -226,7 +206,6 @@ calls_contacts_provider_class_init (CallsContactsProviderClass *klass)
|
||||
{
|
||||
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
||||
|
||||
object_class->get_property = calls_contacts_provider_get_property;
|
||||
object_class->set_property = calls_contacts_provider_set_property;
|
||||
object_class->finalize = calls_contacts_provider_finalize;
|
||||
|
||||
@@ -250,11 +229,13 @@ calls_contacts_provider_class_init (CallsContactsProviderClass *klass)
|
||||
1,
|
||||
FOLKS_TYPE_INDIVIDUAL);
|
||||
|
||||
props[PROP_COUNTRY_CODE] = g_param_spec_string ("country-code",
|
||||
"country code",
|
||||
"The default country code to use",
|
||||
NULL,
|
||||
G_PARAM_READWRITE);
|
||||
props[PROP_SETTINGS] =
|
||||
g_param_spec_object ("settings",
|
||||
"settings",
|
||||
"The settings object to use",
|
||||
CALLS_TYPE_SETTINGS,
|
||||
G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY |
|
||||
G_PARAM_STATIC_STRINGS);
|
||||
|
||||
g_object_class_install_properties (object_class, PROP_LAST_PROP, props);
|
||||
}
|
||||
@@ -287,9 +268,9 @@ calls_contacts_provider_init (CallsContactsProvider *self)
|
||||
}
|
||||
|
||||
CallsContactsProvider *
|
||||
calls_contacts_provider_new (void)
|
||||
calls_contacts_provider_new (CallsSettings *settings)
|
||||
{
|
||||
return g_object_new (CALLS_TYPE_CONTACTS_PROVIDER, NULL);
|
||||
return g_object_new (CALLS_TYPE_CONTACTS_PROVIDER, "settings", settings, NULL);
|
||||
}
|
||||
|
||||
|
||||
@@ -321,7 +302,6 @@ calls_contacts_provider_lookup_phone_number (CallsContactsProvider *self,
|
||||
const gchar *number)
|
||||
{
|
||||
g_autoptr (CallsBestMatch) best_match = NULL;
|
||||
g_autofree gchar *country_code = NULL;
|
||||
|
||||
g_return_val_if_fail (CALLS_IS_CONTACTS_PROVIDER (self), NULL);
|
||||
|
||||
@@ -330,15 +310,15 @@ calls_contacts_provider_lookup_phone_number (CallsContactsProvider *self,
|
||||
if (best_match) {
|
||||
g_object_ref (best_match);
|
||||
|
||||
g_object_get (best_match, "country-code", &country_code, NULL);
|
||||
if (g_strcmp0 (country_code, self->country_code) != 0)
|
||||
calls_best_match_set_phone_number (best_match, number);
|
||||
|
||||
return g_steal_pointer (&best_match);
|
||||
}
|
||||
|
||||
best_match = calls_best_match_new (number);
|
||||
|
||||
g_object_bind_property (self->settings, "country-code",
|
||||
best_match, "country-code",
|
||||
G_BINDING_SYNC_CREATE);
|
||||
|
||||
g_hash_table_insert (self->phone_number_best_matches, g_strdup (number), g_object_ref (best_match));
|
||||
|
||||
return g_steal_pointer (&best_match);
|
||||
|
||||
Reference in New Issue
Block a user