1
0
Fork 0
mirror of https://gitlab.gnome.org/GNOME/calls.git synced 2025-01-06 11:35:32 +00:00

application: settings: Add country code setting

This helps to unbreak country code lookup (see 5fd39121).
This commit is contained in:
Evangelos Ribeiro Tzaras 2021-05-18 16:05:46 +02:00
parent 4990529c6c
commit 7d3426598d
5 changed files with 87 additions and 4 deletions

View file

@ -8,5 +8,11 @@
<description>Whether calls should automatically use the default origin</description>
</key>
<key name="country-code" type="s">
<default>''</default>
<summary>The country code as reported by the modem</summary>
<description>The country code is used for contact name lookup</description>
</key>
</schema>
</schemalist>

View file

@ -300,6 +300,8 @@ startup (GApplication *application)
{
g_autoptr (GtkCssProvider) provider = NULL;
g_autoptr (GError) error = NULL;
CallsApplication *self = CALLS_APPLICATION (application);
CallsManager *manager;
G_APPLICATION_CLASS (calls_application_parent_class)->startup (application);
@ -318,7 +320,14 @@ startup (GApplication *application)
G_N_ELEMENTS (actions),
application);
g_signal_connect_swapped (calls_manager_get_default (),
self->settings = calls_settings_new ();
g_assert (self->settings != NULL);
manager = calls_manager_get_default ();
g_object_bind_property (self->settings, "country-code",
manager, "country-code",
G_BINDING_SYNC_CREATE);
g_signal_connect_swapped (manager,
"notify::state",
G_CALLBACK (manager_state_changed_cb),
application);
@ -377,9 +386,6 @@ start_proper (CallsApplication *self)
self->call_window = calls_call_window_new (gtk_app);
g_assert (self->call_window != NULL);
self->settings = calls_settings_new ();
g_assert (self->settings != NULL);
g_signal_connect (self->call_window,
"notify::visible",
G_CALLBACK (notify_window_visible_cb),
@ -617,3 +623,20 @@ calls_application_set_use_default_origins_setting (CallsApplication *self,
calls_settings_set_use_default_origins (self->settings, enabled);
}
char *
calls_application_get_country_code_setting (CallsApplication *self)
{
g_return_val_if_fail (CALLS_IS_APPLICATION (self), FALSE);
return calls_settings_get_country_code (self->settings);
}
void
calls_application_set_country_code_setting (CallsApplication *self,
const char *country_code)
{
g_return_if_fail (CALLS_IS_APPLICATION (self));
calls_settings_set_country_code (self->settings, country_code);
}

View file

@ -37,5 +37,8 @@ CallsApplication *calls_application_new (void);
gboolean calls_application_get_use_default_origins_setting (CallsApplication *self);
void calls_application_set_use_default_origins_setting (CallsApplication *self,
gboolean enabled);
char *calls_application_get_country_code_setting (CallsApplication *self);
void calls_application_set_country_code_setting (CallsApplication *self,
const char *country_code);
G_END_DECLS

View file

@ -39,6 +39,7 @@
enum {
PROP_0,
PROP_AUTO_USE_DEFAULT_ORIGINS,
PROP_COUNTRY_CODE,
PROP_LAST_PROP
};
static GParamSpec *props[PROP_LAST_PROP];
@ -65,6 +66,10 @@ calls_settings_set_property (GObject *object,
calls_settings_set_use_default_origins (self, g_value_get_boolean (value));
break;
case PROP_COUNTRY_CODE:
calls_settings_set_country_code (self, g_value_get_string (value));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
@ -85,6 +90,10 @@ calls_settings_get_property (GObject *object,
g_value_set_boolean (value, calls_settings_get_use_default_origins (self));
break;
case PROP_COUNTRY_CODE:
g_value_set_string (value, calls_settings_get_country_code (self));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
@ -131,6 +140,12 @@ calls_settings_class_init (CallsSettingsClass *klass)
"Automatically use default origins",
TRUE,
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
props[PROP_COUNTRY_CODE] =
g_param_spec_string ("country-code",
"country code",
"The country code (usually from the modem)",
"",
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
g_object_class_install_properties (object_class, PROP_LAST_PROP, props);
}
@ -184,3 +199,36 @@ calls_settings_set_use_default_origins (CallsSettings *self,
g_debug ("%sabling the use of default origins", enable ? "En" : "Dis");
g_settings_set_boolean (G_SETTINGS (self->settings), "auto-use-default-origins", enable);
}
/**
* calls_settings_get_country_code:
* @self: A #CallsSettings
*
* Whether to prompt the user when there multiple origigins or fall back to defaults
*
* Returns: (transfer full): The used country code
*/
char *
calls_settings_get_country_code (CallsSettings *self)
{
g_return_val_if_fail (CALLS_IS_SETTINGS (self), NULL);
return g_settings_get_string (G_SETTINGS (self->settings), "country-code");
}
/**
* calls_settings_set_country_code:
* @self: A #CallsSettings
* @country_code: The country code to set
*
* Sets the country code
*/
void
calls_settings_set_country_code (CallsSettings *self,
const char *country_code)
{
g_return_if_fail (CALLS_IS_SETTINGS (self));
g_debug ("Setting country code to %s", country_code);
g_settings_set_string (G_SETTINGS (self->settings), "country-code", country_code);
}

View file

@ -36,6 +36,9 @@ CallsSettings *calls_settings_new (void);
gboolean calls_settings_get_use_default_origins (CallsSettings *self);
void calls_settings_set_use_default_origins (CallsSettings *self,
gboolean enable);
char *calls_settings_get_country_code (CallsSettings *self);
void calls_settings_set_country_code (CallsSettings *self,
const char *country_code);
G_END_DECLS