From e00b90d64ec2dfec0c9bf6bb0e12cc90f1fb3c87 Mon Sep 17 00:00:00 2001 From: Evangelos Ribeiro Tzaras Date: Thu, 10 Jun 2021 04:25:50 +0200 Subject: [PATCH] application: settings: Add autoload-plugins setting This setting will be used to define the provider plugins to be loaded on application startup if calls has been invoked without `--provider` --- data/sm.puri.Calls.gschema.xml | 6 ++++++ src/calls-application.c | 7 ++++++- src/calls-settings.c | 35 ++++++++++++++++++++++++++++++++++ src/calls-settings.h | 15 +++++++++------ 4 files changed, 56 insertions(+), 7 deletions(-) diff --git a/data/sm.puri.Calls.gschema.xml b/data/sm.puri.Calls.gschema.xml index c957571..282e449 100644 --- a/data/sm.puri.Calls.gschema.xml +++ b/data/sm.puri.Calls.gschema.xml @@ -14,5 +14,11 @@ The country code is used for contact name lookup + + ["mm", "sip"] + The plugins to load automatically + These plugins will be automatically loaded on application startup. + + diff --git a/src/calls-application.c b/src/calls-application.c index efdfba1..7042f0c 100644 --- a/src/calls-application.c +++ b/src/calls-application.c @@ -206,6 +206,8 @@ set_default_providers_action (GSimpleAction *action, GVariant *parameter, gpointer user_data) { + CallsApplication *self = CALLS_APPLICATION (user_data); + g_auto (GStrv) plugins = NULL; /** * Only add default providers when there are none added yet, * This makes sure we're not resetting explicitly set providers @@ -213,7 +215,10 @@ set_default_providers_action (GSimpleAction *action, if (calls_manager_has_any_provider (calls_manager_get_default ())) return; - /* TODO get defaults from GSettings */ + plugins = calls_settings_get_autoload_plugins (self->settings); + for (guint i = 0; plugins[i] != NULL; i++) { + calls_manager_add_provider (calls_manager_get_default (), plugins[i]); + } } diff --git a/src/calls-settings.c b/src/calls-settings.c index 1506f96..c33d766 100644 --- a/src/calls-settings.c +++ b/src/calls-settings.c @@ -40,6 +40,7 @@ enum { PROP_0, PROP_AUTO_USE_DEFAULT_ORIGINS, PROP_COUNTRY_CODE, + PROP_AUTOLOAD_PLUGINS, PROP_LAST_PROP }; static GParamSpec *props[PROP_LAST_PROP]; @@ -70,6 +71,10 @@ calls_settings_set_property (GObject *object, calls_settings_set_country_code (self, g_value_get_string (value)); break; + case PROP_AUTOLOAD_PLUGINS: + calls_settings_set_autoload_plugins (self, g_value_get_boxed (value)); + break; + default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); break; @@ -94,6 +99,10 @@ calls_settings_get_property (GObject *object, g_value_set_string (value, calls_settings_get_country_code (self)); break; + case PROP_AUTOLOAD_PLUGINS: + g_value_set_boxed (value, calls_settings_get_autoload_plugins (self)); + break; + default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); break; @@ -147,6 +156,13 @@ calls_settings_class_init (CallsSettingsClass *klass) "", G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS); + props[PROP_AUTOLOAD_PLUGINS] = + g_param_spec_boxed ("autoload-plugins", + "autoload plugins", + "The plugins to automatically load on startup", + G_TYPE_STRV, + G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS); + g_object_class_install_properties (object_class, PROP_LAST_PROP, props); } @@ -232,3 +248,22 @@ calls_settings_set_country_code (CallsSettings *self, g_debug ("Setting country code to %s", country_code); g_settings_set_string (G_SETTINGS (self->settings), "country-code", country_code); } + + +char ** +calls_settings_get_autoload_plugins (CallsSettings *self) +{ + g_return_val_if_fail (CALLS_IS_SETTINGS (self), NULL); + + return g_settings_get_strv (G_SETTINGS (self->settings), "autoload-plugins"); +} + + +void +calls_settings_set_autoload_plugins (CallsSettings *self, + const char * const *plugins) +{ + g_return_if_fail (CALLS_IS_SETTINGS (self)); + + g_settings_set_strv (G_SETTINGS (self->settings), "autoload-plugins", plugins); +} diff --git a/src/calls-settings.h b/src/calls-settings.h index 57c9b7d..8c23b64 100644 --- a/src/calls-settings.h +++ b/src/calls-settings.h @@ -33,12 +33,15 @@ G_BEGIN_DECLS G_DECLARE_FINAL_TYPE (CallsSettings, calls_settings, CALLS, SETTINGS, GObject) 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); +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); +char **calls_settings_get_autoload_plugins (CallsSettings *self); +void calls_settings_set_autoload_plugins (CallsSettings *self, + const char * const *plugins); G_END_DECLS