mirror of
https://gitlab.gnome.org/GNOME/calls.git
synced 2024-11-16 19:57:22 +00:00
application: Allow invoking with multiple -p
arguments
When calls is invoked with one or more `--provider` arguments, the application will only load the providers specified by the command line. If no `--provider` argument is given, the application will instead fall back to loading providers defined in the settings (see next commit).
This commit is contained in:
parent
f930874d00
commit
4f6fb722b1
3 changed files with 78 additions and 23 deletions
|
@ -119,6 +119,7 @@ handle_local_options (GApplication *application,
|
||||||
gboolean ok;
|
gboolean ok;
|
||||||
g_autoptr (GError) error = NULL;
|
g_autoptr (GError) error = NULL;
|
||||||
const char *arg;
|
const char *arg;
|
||||||
|
g_autoptr (GVariant) providers = NULL;
|
||||||
|
|
||||||
g_debug ("Registering application");
|
g_debug ("Registering application");
|
||||||
ok = g_application_register (application, NULL, &error);
|
ok = g_application_register (application, NULL, &error);
|
||||||
|
@ -135,16 +136,15 @@ handle_local_options (GApplication *application,
|
||||||
exit (0);
|
exit (0);
|
||||||
}
|
}
|
||||||
|
|
||||||
ok = g_variant_dict_lookup (options, "provider", "&s", &arg);
|
providers = g_variant_dict_lookup_value (options, "provider", G_VARIANT_TYPE_STRING_ARRAY);
|
||||||
if (ok) {
|
if (providers) {
|
||||||
g_action_group_activate_action (G_ACTION_GROUP (application),
|
g_action_group_activate_action (G_ACTION_GROUP (application),
|
||||||
"set-provider-name",
|
"set-provider-names",
|
||||||
g_variant_new_string (arg));
|
providers);
|
||||||
} else {
|
} else {
|
||||||
if (!calls_manager_has_any_provider (calls_manager_get_default ()))
|
g_action_group_activate_action (G_ACTION_GROUP (application),
|
||||||
g_action_group_activate_action (G_ACTION_GROUP (application),
|
"set-default-providers",
|
||||||
"set-provider-name",
|
NULL);
|
||||||
g_variant_new_string (DEFAULT_PROVIDER_PLUGIN));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ok = g_variant_dict_contains (options, "daemon");
|
ok = g_variant_dict_contains (options, "daemon");
|
||||||
|
@ -166,23 +166,54 @@ handle_local_options (GApplication *application,
|
||||||
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
set_provider_name_action (GSimpleAction *action,
|
set_provider_names_action (GSimpleAction *action,
|
||||||
GVariant *parameter,
|
GVariant *parameter,
|
||||||
gpointer user_data)
|
gpointer user_data)
|
||||||
{
|
{
|
||||||
const char *name;
|
CallsManager *manager;
|
||||||
|
g_autofree const char **names = NULL;
|
||||||
|
g_autofree const char **loaded = NULL;
|
||||||
|
gsize length;
|
||||||
|
guint length_loaded;
|
||||||
|
|
||||||
name = g_variant_get_string (parameter, NULL);
|
names = g_variant_get_strv (parameter, &length);
|
||||||
g_return_if_fail (name != NULL);
|
g_return_if_fail (names && *names);
|
||||||
|
|
||||||
if (calls_manager_has_provider (calls_manager_get_default (), name)) {
|
manager = calls_manager_get_default ();
|
||||||
g_warning ("Cannot add provider `%s' because it is already loaded",
|
loaded = calls_manager_get_provider_names (manager, &length_loaded);
|
||||||
name);
|
|
||||||
return;
|
/* remove unwanted providers */
|
||||||
|
for (guint i = 0; i < length_loaded; i++) {
|
||||||
|
g_autofree char *provider = g_strdup (loaded[i]);
|
||||||
|
if (!g_strv_contains (names, provider))
|
||||||
|
calls_manager_remove_provider (manager, provider);
|
||||||
}
|
}
|
||||||
|
|
||||||
g_debug ("Start loading provider `%s'", name);
|
for (guint i = 0; i < length; i++) {
|
||||||
calls_manager_add_provider (calls_manager_get_default (), name);
|
const char *name = names[i];
|
||||||
|
|
||||||
|
if (calls_manager_has_provider (manager, name))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
g_debug ("Loading provider `%s'", name);
|
||||||
|
calls_manager_add_provider (manager, name);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static void
|
||||||
|
set_default_providers_action (GSimpleAction *action,
|
||||||
|
GVariant *parameter,
|
||||||
|
gpointer user_data)
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Only add default providers when there are none added yet,
|
||||||
|
* This makes sure we're not resetting explicitly set providers
|
||||||
|
*/
|
||||||
|
if (calls_manager_has_any_provider (calls_manager_get_default ()))
|
||||||
|
return;
|
||||||
|
|
||||||
|
/* TODO get defaults from GSettings */
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -325,7 +356,8 @@ manager_state_changed_cb (GApplication *application)
|
||||||
|
|
||||||
static const GActionEntry actions[] =
|
static const GActionEntry actions[] =
|
||||||
{
|
{
|
||||||
{ "set-provider-name", set_provider_name_action, "s" },
|
{ "set-provider-names", set_provider_names_action, "as" },
|
||||||
|
{ "set-default-providers", set_default_providers_action, NULL },
|
||||||
{ "set-daemon", set_daemon_action, NULL },
|
{ "set-daemon", set_daemon_action, NULL },
|
||||||
{ "dial", dial_action, "s" },
|
{ "dial", dial_action, "s" },
|
||||||
{ "copy-number", copy_number, "s"},
|
{ "copy-number", copy_number, "s"},
|
||||||
|
@ -605,7 +637,7 @@ calls_application_init (CallsApplication *self)
|
||||||
const GOptionEntry options[] = {
|
const GOptionEntry options[] = {
|
||||||
{
|
{
|
||||||
"provider", 'p', G_OPTION_FLAG_NONE,
|
"provider", 'p', G_OPTION_FLAG_NONE,
|
||||||
G_OPTION_ARG_STRING, NULL,
|
G_OPTION_ARG_STRING_ARRAY, NULL,
|
||||||
_("The name of the plugin to use for the call Provider"),
|
_("The name of the plugin to use for the call Provider"),
|
||||||
_("PLUGIN")
|
_("PLUGIN")
|
||||||
},
|
},
|
||||||
|
|
|
@ -977,3 +977,24 @@ calls_manager_has_any_provider (CallsManager *self)
|
||||||
|
|
||||||
return !!g_hash_table_size (self->providers);
|
return !!g_hash_table_size (self->providers);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* calls_manager_get_provider_names:
|
||||||
|
* @self: The #CallsManager
|
||||||
|
* @length: (optional) (out): the length of the returned array
|
||||||
|
*
|
||||||
|
* Retrieves the names of all providers loaded by @self, as an array.
|
||||||
|
*
|
||||||
|
* You should free the return value with g_free().
|
||||||
|
*
|
||||||
|
* Returns: (array length=length) (transfer container): a
|
||||||
|
* %NULL-terminated array containing the names of providers.
|
||||||
|
*/
|
||||||
|
const char **
|
||||||
|
calls_manager_get_provider_names (CallsManager *self,
|
||||||
|
guint *length)
|
||||||
|
{
|
||||||
|
g_return_val_if_fail (CALLS_IS_MANAGER (self), NULL);
|
||||||
|
|
||||||
|
return (const char **) g_hash_table_get_keys_as_array (self->providers, length);
|
||||||
|
}
|
||||||
|
|
|
@ -75,6 +75,8 @@ GListModel *calls_manager_get_suitable_origins (CallsManager
|
||||||
const gchar *calls_manager_get_contact_name (CallsCall *call);
|
const gchar *calls_manager_get_contact_name (CallsCall *call);
|
||||||
gboolean calls_manager_has_active_call (CallsManager *self);
|
gboolean calls_manager_has_active_call (CallsManager *self);
|
||||||
void calls_manager_hang_up_all_calls (CallsManager *self);
|
void calls_manager_hang_up_all_calls (CallsManager *self);
|
||||||
gboolean calls_manager_has_any_provider (CallsManager *self);
|
gboolean calls_manager_has_any_provider (CallsManager *self);
|
||||||
|
const char **calls_manager_get_provider_names (CallsManager *self,
|
||||||
|
guint *length);
|
||||||
|
|
||||||
G_END_DECLS
|
G_END_DECLS
|
||||||
|
|
Loading…
Reference in a new issue