2020-03-17 15:29:43 +00:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2020 Purism SPC
|
|
|
|
*
|
|
|
|
* This file is part of Calls.
|
|
|
|
*
|
|
|
|
* Calls is free software: you can redistribute it and/or modify it
|
|
|
|
* under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* Calls is distributed in the hope that it will be useful, but
|
|
|
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with Calls. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*
|
|
|
|
* Author: Julian Sparber <julian.sparber@puri.sm>
|
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: GPL-3.0-or-later
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2021-06-18 09:10:36 +00:00
|
|
|
#define G_LOG_DOMAIN "CallsManager"
|
|
|
|
|
2020-03-17 15:29:43 +00:00
|
|
|
#include "config.h"
|
2021-05-05 18:53:37 +00:00
|
|
|
|
2021-05-18 16:31:05 +00:00
|
|
|
#include "calls-application.h"
|
2021-05-05 18:53:37 +00:00
|
|
|
#include "calls-account-provider.h"
|
2021-01-20 14:20:09 +00:00
|
|
|
#include "calls-contacts-provider.h"
|
2021-05-05 18:53:37 +00:00
|
|
|
#include "calls-manager.h"
|
|
|
|
#include "calls-provider.h"
|
|
|
|
#include "calls-ussd.h"
|
|
|
|
|
2020-03-17 15:29:43 +00:00
|
|
|
#include "enum-types.h"
|
|
|
|
|
|
|
|
#include <glib/gi18n.h>
|
|
|
|
#include <libpeas/peas.h>
|
|
|
|
|
|
|
|
struct _CallsManager
|
|
|
|
{
|
|
|
|
GObject parent_instance;
|
|
|
|
|
2021-04-13 09:36:58 +00:00
|
|
|
GHashTable *providers;
|
|
|
|
/* This is the protocols supported in principle. This is collected from the loaded
|
|
|
|
providers and does not imply that there are any origins able to handle a given protocol.
|
|
|
|
See origins_by_protocol for a GListStore of suitable origins per protocol.
|
|
|
|
*/
|
|
|
|
GPtrArray *supported_protocols;
|
|
|
|
|
|
|
|
GListStore *origins;
|
|
|
|
/* origins_by_protocol maps protocol names to GListStore's of suitable origins */
|
|
|
|
GHashTable *origins_by_protocol;
|
|
|
|
|
2021-01-20 14:20:09 +00:00
|
|
|
CallsContactsProvider *contacts_provider;
|
2021-04-13 09:36:58 +00:00
|
|
|
|
2020-03-17 15:29:43 +00:00
|
|
|
CallsManagerState state;
|
2021-02-24 08:27:59 +00:00
|
|
|
CallsCall *primary_call;
|
2021-03-25 19:25:09 +00:00
|
|
|
char *country_code;
|
2020-03-17 15:29:43 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
G_DEFINE_TYPE (CallsManager, calls_manager, G_TYPE_OBJECT);
|
|
|
|
|
|
|
|
enum {
|
|
|
|
PROP_0,
|
|
|
|
PROP_STATE,
|
2021-03-25 19:25:09 +00:00
|
|
|
PROP_COUNTRY_CODE,
|
2020-03-17 15:29:43 +00:00
|
|
|
PROP_LAST_PROP,
|
|
|
|
};
|
|
|
|
static GParamSpec *props[PROP_LAST_PROP];
|
|
|
|
|
|
|
|
|
|
|
|
enum {
|
|
|
|
SIGNAL_CALL_ADD,
|
|
|
|
SIGNAL_CALL_REMOVE,
|
|
|
|
/* TODO: currently this event isn't emitted since the plugins don't give use
|
|
|
|
* a usable error or error message. */
|
|
|
|
SIGNAL_ERROR,
|
2020-07-07 12:40:31 +00:00
|
|
|
USSD_ADDED,
|
|
|
|
USSD_CANCELLED,
|
|
|
|
USSD_STATE_CHANGED,
|
2020-03-17 15:29:43 +00:00
|
|
|
SIGNAL_LAST_SIGNAL,
|
|
|
|
};
|
|
|
|
static guint signals [SIGNAL_LAST_SIGNAL];
|
|
|
|
|
|
|
|
static void
|
|
|
|
set_state (CallsManager *self, CallsManagerState state)
|
|
|
|
{
|
|
|
|
if (self->state == state)
|
|
|
|
return;
|
|
|
|
|
|
|
|
self->state = state;
|
|
|
|
|
|
|
|
g_object_notify_by_pspec (G_OBJECT (self), props[PROP_STATE]);
|
|
|
|
}
|
|
|
|
|
2021-04-13 09:36:58 +00:00
|
|
|
static void
|
|
|
|
update_state (CallsManager *self)
|
|
|
|
{
|
|
|
|
guint n_items;
|
2021-05-04 19:49:07 +00:00
|
|
|
GHashTableIter iter;
|
|
|
|
gpointer key;
|
|
|
|
gpointer value;
|
|
|
|
|
2021-04-13 09:36:58 +00:00
|
|
|
g_assert (CALLS_IS_MANAGER (self));
|
|
|
|
|
|
|
|
if (g_hash_table_size (self->providers) == 0) {
|
|
|
|
set_state (self, CALLS_MANAGER_STATE_NO_PROVIDER);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-05-04 19:49:07 +00:00
|
|
|
g_hash_table_iter_init (&iter, self->providers);
|
|
|
|
|
|
|
|
while (g_hash_table_iter_next (&iter, &key, &value)) {
|
|
|
|
CallsProvider *provider = CALLS_PROVIDER (value);
|
|
|
|
|
|
|
|
if (calls_provider_is_modem (provider) && !calls_provider_is_operational (provider)) {
|
|
|
|
set_state (self, CALLS_MANAGER_STATE_NO_VOICE_MODEM);
|
|
|
|
return;
|
|
|
|
}
|
2021-04-13 09:36:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
n_items = g_list_model_get_n_items (G_LIST_MODEL (self->origins));
|
|
|
|
|
|
|
|
if (n_items)
|
|
|
|
set_state (self, CALLS_MANAGER_STATE_READY);
|
|
|
|
else
|
|
|
|
set_state (self, CALLS_MANAGER_STATE_NO_ORIGIN);
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
check_supported_protocol (CallsManager *self,
|
|
|
|
const char *protocol)
|
|
|
|
{
|
|
|
|
guint index;
|
|
|
|
g_assert (CALLS_IS_MANAGER (self));
|
|
|
|
g_assert (protocol);
|
|
|
|
|
|
|
|
if (self->supported_protocols->len > 0)
|
|
|
|
return g_ptr_array_find_with_equal_func (self->supported_protocols,
|
|
|
|
protocol,
|
|
|
|
g_str_equal,
|
|
|
|
&index);
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* This function will update self->supported_protocols from available provider plugins */
|
|
|
|
static void
|
|
|
|
update_protocols (CallsManager *self)
|
|
|
|
{
|
|
|
|
GHashTableIter iter;
|
|
|
|
gpointer key, value;
|
|
|
|
const char * const *protocols;
|
|
|
|
|
|
|
|
g_assert (CALLS_IS_MANAGER (self));
|
|
|
|
|
|
|
|
g_ptr_array_remove_range (self->supported_protocols,
|
|
|
|
0, self->supported_protocols->len);
|
|
|
|
|
|
|
|
g_hash_table_iter_init (&iter, self->providers);
|
|
|
|
while (g_hash_table_iter_next (&iter, &key, &value)) {
|
|
|
|
const char *name = key;
|
|
|
|
CallsProvider *provider = CALLS_PROVIDER (value);
|
|
|
|
|
|
|
|
protocols = calls_provider_get_protocols (provider);
|
|
|
|
|
|
|
|
if (protocols == NULL) {
|
|
|
|
g_debug ("Plugin %s does not provide any protocols", name);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
for (guint i = 0; protocols[i] != NULL; i++) {
|
|
|
|
if (!check_supported_protocol (self, protocols[i]))
|
|
|
|
g_ptr_array_add (self->supported_protocols, g_strdup (protocols[i]));
|
|
|
|
|
|
|
|
if (!g_hash_table_contains (self->origins_by_protocol, protocols[i])) {
|
|
|
|
/* Add a new GListStore if there's none already.
|
|
|
|
* Actually adding origins to self->origins_by_protocol is done
|
|
|
|
* in rebuild_origins_by_protocol()
|
|
|
|
*/
|
|
|
|
GListStore *store = g_list_store_new (CALLS_TYPE_ORIGIN);
|
|
|
|
g_hash_table_insert (self->origins_by_protocol,
|
|
|
|
g_strdup (protocols[i]),
|
|
|
|
store);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
update_state (self);
|
|
|
|
}
|
|
|
|
|
2020-03-17 15:29:43 +00:00
|
|
|
static void
|
|
|
|
add_call (CallsManager *self, CallsCall *call, CallsOrigin *origin)
|
|
|
|
{
|
|
|
|
g_return_if_fail (CALLS_IS_MANAGER (self));
|
|
|
|
g_return_if_fail (CALLS_IS_ORIGIN (origin));
|
|
|
|
g_return_if_fail (CALLS_IS_CALL (call));
|
|
|
|
|
|
|
|
g_signal_emit (self, signals[SIGNAL_CALL_ADD], 0, call, origin);
|
2021-02-24 08:27:59 +00:00
|
|
|
|
|
|
|
if (self->primary_call == NULL)
|
|
|
|
self->primary_call = call;
|
|
|
|
else
|
|
|
|
calls_call_hang_up (call);
|
2020-03-17 15:29:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
remove_call (CallsManager *self, CallsCall *call, gchar *reason, CallsOrigin *origin)
|
|
|
|
{
|
|
|
|
g_return_if_fail (CALLS_IS_MANAGER (self));
|
|
|
|
g_return_if_fail (CALLS_IS_ORIGIN (origin));
|
|
|
|
g_return_if_fail (CALLS_IS_CALL (call));
|
|
|
|
|
|
|
|
/* We ignore the reason for now, because it doesn't give any usefull information */
|
|
|
|
g_signal_emit (self, signals[SIGNAL_CALL_REMOVE], 0, call, origin);
|
2021-02-24 08:27:59 +00:00
|
|
|
|
|
|
|
if (self->primary_call == call)
|
|
|
|
self->primary_call = NULL;
|
2020-03-17 15:29:43 +00:00
|
|
|
}
|
|
|
|
|
2020-07-07 12:40:31 +00:00
|
|
|
static void
|
|
|
|
ussd_added_cb (CallsManager *self,
|
|
|
|
char *response,
|
|
|
|
CallsUssd *ussd)
|
|
|
|
{
|
|
|
|
g_assert (CALLS_IS_MANAGER (self));
|
|
|
|
g_assert (CALLS_IS_USSD (ussd));
|
|
|
|
|
|
|
|
g_signal_emit (self, signals[USSD_ADDED], 0, ussd, response);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
ussd_cancelled_cb (CallsManager *self,
|
|
|
|
CallsUssd *ussd,
|
|
|
|
char *response)
|
|
|
|
{
|
|
|
|
g_assert (CALLS_IS_MANAGER (self));
|
|
|
|
g_assert (CALLS_IS_USSD (ussd));
|
|
|
|
|
|
|
|
g_signal_emit (self, signals[USSD_CANCELLED], 0, ussd);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
ussd_state_changed_cb (CallsManager *self,
|
|
|
|
CallsUssd *ussd)
|
|
|
|
{
|
|
|
|
g_assert (CALLS_IS_MANAGER (self));
|
|
|
|
g_assert (CALLS_IS_USSD (ussd));
|
|
|
|
|
|
|
|
g_signal_emit (self, signals[USSD_STATE_CHANGED], 0, ussd);
|
|
|
|
}
|
|
|
|
|
2021-05-18 16:31:05 +00:00
|
|
|
static void
|
|
|
|
update_country_code_cb (CallsOrigin *origin,
|
|
|
|
GParamSpec *pspec,
|
|
|
|
CallsManager *self)
|
|
|
|
{
|
|
|
|
CallsApplication *app;
|
|
|
|
g_autofree char *country_code = NULL;
|
|
|
|
|
|
|
|
g_assert (CALLS_IS_MANAGER (self));
|
|
|
|
app = CALLS_APPLICATION (g_application_get_default ());
|
|
|
|
|
|
|
|
g_object_get (G_OBJECT (origin), "country-code", &country_code, NULL);
|
|
|
|
|
|
|
|
if (country_code && g_strcmp0 (country_code, self->country_code) == 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
g_free (self->country_code);
|
|
|
|
self->country_code = country_code;
|
|
|
|
calls_application_set_country_code_setting (app, country_code);
|
|
|
|
}
|
|
|
|
|
2020-03-17 15:29:43 +00:00
|
|
|
static void
|
2021-04-18 00:33:13 +00:00
|
|
|
add_origin (CallsManager *self, CallsOrigin *origin)
|
2020-03-17 15:29:43 +00:00
|
|
|
{
|
2021-05-13 15:35:10 +00:00
|
|
|
g_autofree const char *name = NULL;
|
2021-04-14 14:05:40 +00:00
|
|
|
g_assert (CALLS_IS_MANAGER (self));
|
|
|
|
g_assert (CALLS_IS_ORIGIN (origin));
|
2020-03-17 15:29:43 +00:00
|
|
|
|
2021-05-13 15:35:10 +00:00
|
|
|
name = calls_origin_get_name (origin);
|
|
|
|
g_debug ("Adding origin %s (%p)", name, origin);
|
2021-04-17 14:43:21 +00:00
|
|
|
|
2021-04-13 09:36:58 +00:00
|
|
|
g_list_store_append (self->origins, origin);
|
|
|
|
|
2021-05-18 16:31:05 +00:00
|
|
|
g_signal_connect_object (origin,
|
|
|
|
"notify::country-code",
|
|
|
|
G_CALLBACK (update_country_code_cb),
|
|
|
|
self,
|
|
|
|
G_CONNECT_AFTER);
|
2020-03-17 15:29:43 +00:00
|
|
|
g_signal_connect_swapped (origin, "call-added", G_CALLBACK (add_call), self);
|
|
|
|
g_signal_connect_swapped (origin, "call-removed", G_CALLBACK (remove_call), self);
|
|
|
|
|
2020-07-07 12:40:31 +00:00
|
|
|
if (CALLS_IS_USSD (origin))
|
|
|
|
{
|
|
|
|
g_signal_connect_swapped (origin, "ussd-added", G_CALLBACK (ussd_added_cb), self);
|
|
|
|
g_signal_connect_swapped (origin, "ussd-cancelled", G_CALLBACK (ussd_cancelled_cb), self);
|
|
|
|
g_signal_connect_swapped (origin, "ussd-state-changed", G_CALLBACK (ussd_state_changed_cb), self);
|
|
|
|
}
|
|
|
|
|
2021-04-13 09:36:58 +00:00
|
|
|
calls_origin_foreach_call (origin, (CallsOriginForeachCallFunc) add_call, self);
|
2020-03-17 15:29:43 +00:00
|
|
|
}
|
|
|
|
|
2020-03-23 22:10:05 +00:00
|
|
|
static void
|
|
|
|
remove_call_cb (gpointer self, CallsCall *call, CallsOrigin *origin)
|
|
|
|
{
|
2021-04-13 09:36:58 +00:00
|
|
|
remove_call (self, call, NULL, origin);
|
2020-03-23 22:10:05 +00:00
|
|
|
}
|
|
|
|
|
2020-03-17 15:29:43 +00:00
|
|
|
static void
|
2021-04-18 00:33:13 +00:00
|
|
|
remove_origin (CallsManager *self, CallsOrigin *origin)
|
2020-03-17 15:29:43 +00:00
|
|
|
{
|
2021-05-13 15:35:10 +00:00
|
|
|
g_autofree const char *name = NULL;
|
2021-04-13 09:36:58 +00:00
|
|
|
guint position;
|
2020-03-23 22:10:05 +00:00
|
|
|
|
2021-04-13 09:36:58 +00:00
|
|
|
g_assert (CALLS_IS_MANAGER (self));
|
|
|
|
g_assert (CALLS_IS_ORIGIN (origin));
|
2020-03-17 15:29:43 +00:00
|
|
|
|
2021-05-13 15:35:10 +00:00
|
|
|
name = calls_origin_get_name (origin);
|
|
|
|
g_debug ("Removing origin %s (%p)", name, origin);
|
2021-04-17 14:43:21 +00:00
|
|
|
|
2020-03-17 15:29:43 +00:00
|
|
|
g_signal_handlers_disconnect_by_data (origin, self);
|
|
|
|
|
2021-04-13 09:36:58 +00:00
|
|
|
calls_origin_foreach_call (origin, remove_call_cb, self);
|
2020-03-17 15:29:43 +00:00
|
|
|
|
2021-04-13 09:36:58 +00:00
|
|
|
if (!g_list_store_find (self->origins, origin, &position))
|
|
|
|
g_warning ("Origin %p not found in list store while trying to remove it",
|
|
|
|
origin);
|
|
|
|
else
|
|
|
|
g_list_store_remove (self->origins, position);
|
2020-03-17 15:29:43 +00:00
|
|
|
|
2021-04-13 09:36:58 +00:00
|
|
|
update_state (self);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* rebuild_origins_by_protocols() when any origins were added or removed */
|
|
|
|
static void
|
|
|
|
rebuild_origins_by_protocols (CallsManager *self)
|
|
|
|
{
|
|
|
|
GHashTableIter iter;
|
|
|
|
gpointer key, value;
|
|
|
|
guint n_origins;
|
|
|
|
|
|
|
|
g_assert (CALLS_IS_MANAGER (self));
|
|
|
|
|
|
|
|
/* Remove everything */
|
|
|
|
g_hash_table_iter_init (&iter, self->origins_by_protocol);
|
|
|
|
|
|
|
|
while (g_hash_table_iter_next (&iter, &key, &value)) {
|
|
|
|
GListStore *store = G_LIST_STORE (value);
|
|
|
|
g_list_store_remove_all (store);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Iterate over all origins and check which protocols they support */
|
|
|
|
n_origins = g_list_model_get_n_items (G_LIST_MODEL (self->origins));
|
|
|
|
|
|
|
|
for (guint i = 0; i < n_origins; i++) {
|
|
|
|
g_autoptr (CallsOrigin) origin =
|
|
|
|
g_list_model_get_item (G_LIST_MODEL (self->origins), i);
|
|
|
|
|
|
|
|
for (guint j = 0; j < self->supported_protocols->len; j++) {
|
|
|
|
char *protocol = g_ptr_array_index (self->supported_protocols, j);
|
|
|
|
GListStore *store =
|
|
|
|
G_LIST_STORE (g_hash_table_lookup (self->origins_by_protocol, protocol));
|
|
|
|
|
|
|
|
g_assert (store);
|
|
|
|
|
|
|
|
if (calls_origin_supports_protocol (origin, protocol))
|
|
|
|
g_list_store_append (store, origin);
|
|
|
|
}
|
|
|
|
}
|
2020-03-17 15:29:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2021-04-13 09:36:58 +00:00
|
|
|
remove_provider (CallsManager *self,
|
|
|
|
const char *name)
|
2020-03-17 15:29:43 +00:00
|
|
|
{
|
2021-02-15 05:34:34 +00:00
|
|
|
GListModel *origins;
|
|
|
|
guint n_items;
|
2021-04-13 09:36:58 +00:00
|
|
|
CallsProvider *provider;
|
2020-03-17 15:29:43 +00:00
|
|
|
|
2021-04-13 09:36:58 +00:00
|
|
|
g_assert (CALLS_IS_MANAGER (self));
|
|
|
|
g_assert (name);
|
2020-03-17 15:29:43 +00:00
|
|
|
|
2021-04-13 09:36:58 +00:00
|
|
|
provider = g_hash_table_lookup (self->providers, name);
|
|
|
|
if (provider == NULL) {
|
|
|
|
g_warning ("Trying to remove provider %s which has not been found", name);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
g_debug ("Remove provider: %s", name);
|
|
|
|
g_signal_handlers_disconnect_by_data (provider, self);
|
|
|
|
|
|
|
|
origins = calls_provider_get_origins (provider);
|
2021-02-15 05:34:34 +00:00
|
|
|
g_signal_handlers_disconnect_by_data (origins, self);
|
|
|
|
n_items = g_list_model_get_n_items (origins);
|
2020-03-17 15:29:43 +00:00
|
|
|
|
2021-06-09 02:03:31 +00:00
|
|
|
for (guint i = 0; i < n_items; i++) {
|
|
|
|
g_autoptr(CallsOrigin) origin = NULL;
|
2021-02-15 05:34:34 +00:00
|
|
|
|
2021-06-09 02:03:31 +00:00
|
|
|
origin = g_list_model_get_item (origins, i);
|
|
|
|
remove_origin (self, origin);
|
|
|
|
}
|
2020-03-17 15:29:43 +00:00
|
|
|
|
2021-04-13 09:36:58 +00:00
|
|
|
g_hash_table_remove (self->providers, name);
|
|
|
|
calls_provider_unload_plugin (name);
|
|
|
|
|
|
|
|
update_protocols (self);
|
|
|
|
update_state (self);
|
|
|
|
rebuild_origins_by_protocols (self);
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
origin_found_in_any_provider (CallsManager *self,
|
|
|
|
CallsOrigin *origin)
|
|
|
|
{
|
|
|
|
GHashTableIter iter;
|
|
|
|
gpointer key, value;
|
|
|
|
|
|
|
|
g_return_val_if_fail (CALLS_IS_MANAGER (self), FALSE);
|
|
|
|
g_return_val_if_fail (CALLS_IS_ORIGIN (origin), FALSE);
|
|
|
|
|
|
|
|
g_hash_table_iter_init (&iter, self->providers);
|
|
|
|
while (g_hash_table_iter_next (&iter, &key, &value)) {
|
|
|
|
guint position;
|
|
|
|
CallsProvider *provider = CALLS_PROVIDER (value);
|
|
|
|
GListModel *origins = calls_provider_get_origins (provider);
|
|
|
|
|
|
|
|
if (origins && calls_find_in_store (origins,
|
|
|
|
origin,
|
|
|
|
&position))
|
|
|
|
return TRUE;
|
|
|
|
}
|
2021-04-02 14:04:07 +00:00
|
|
|
|
2021-04-13 09:36:58 +00:00
|
|
|
return FALSE;
|
2020-03-17 15:29:43 +00:00
|
|
|
}
|
|
|
|
|
2021-04-13 09:36:58 +00:00
|
|
|
|
|
|
|
|
2021-02-15 05:34:34 +00:00
|
|
|
static void
|
2021-04-13 09:36:58 +00:00
|
|
|
origin_items_changed_cb (GListModel *model,
|
|
|
|
guint position,
|
|
|
|
guint removed,
|
|
|
|
guint added,
|
|
|
|
CallsManager *self)
|
2021-02-15 05:34:34 +00:00
|
|
|
{
|
2021-04-13 09:36:58 +00:00
|
|
|
guint i;
|
|
|
|
CallsOrigin *origin;
|
|
|
|
guint purged = 0;
|
|
|
|
guint total_origins;
|
2021-02-15 05:34:34 +00:00
|
|
|
|
|
|
|
g_assert (CALLS_IS_MANAGER (self));
|
|
|
|
|
2021-04-13 09:36:58 +00:00
|
|
|
total_origins = g_list_model_get_n_items (G_LIST_MODEL (self->origins));
|
|
|
|
g_debug ("origins changed: pos=%d rem=%d added=%d total=%d",
|
|
|
|
position, removed, added, g_list_model_get_n_items (model));
|
2021-02-15 05:34:34 +00:00
|
|
|
|
2021-04-13 09:36:58 +00:00
|
|
|
/* Check stale/removed origins: We need to look up */
|
|
|
|
if (removed == 0)
|
|
|
|
goto skip_remove;
|
2021-02-15 05:34:34 +00:00
|
|
|
|
2021-04-13 09:36:58 +00:00
|
|
|
for (i = 0; i < total_origins - purged; i++) {
|
|
|
|
origin = g_list_model_get_item (G_LIST_MODEL (self->origins), i - purged);
|
2021-02-15 05:34:34 +00:00
|
|
|
|
2021-04-13 09:36:58 +00:00
|
|
|
if (!origin_found_in_any_provider (self, origin)) {
|
|
|
|
remove_origin (self, origin);
|
|
|
|
purged++;
|
2021-02-15 05:34:34 +00:00
|
|
|
}
|
2021-04-13 09:36:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/** The number of purged entries from self->origins must be equal to removed
|
|
|
|
* origins from the providers list
|
|
|
|
*/
|
|
|
|
if (purged != removed) {
|
|
|
|
g_warning ("Managed origins are not in sync anymore!");
|
|
|
|
}
|
|
|
|
|
|
|
|
skip_remove:
|
|
|
|
for (i = 0; i < added; i++) {
|
|
|
|
g_debug ("before adding: %d",
|
|
|
|
g_list_model_get_n_items (G_LIST_MODEL (self->origins)));
|
|
|
|
|
|
|
|
origin = g_list_model_get_item (model, position + i);
|
|
|
|
add_origin (self, origin); // add to list store
|
|
|
|
g_object_unref (origin);
|
|
|
|
|
|
|
|
g_debug ("after adding: %d",
|
|
|
|
g_list_model_get_n_items (G_LIST_MODEL (self->origins)));
|
|
|
|
}
|
|
|
|
|
|
|
|
rebuild_origins_by_protocols (self);
|
|
|
|
update_state (self);
|
2021-02-15 05:34:34 +00:00
|
|
|
}
|
|
|
|
|
2020-03-17 15:29:43 +00:00
|
|
|
static void
|
|
|
|
add_provider (CallsManager *self, const gchar *name)
|
|
|
|
{
|
2021-02-15 05:34:34 +00:00
|
|
|
GListModel *origins;
|
2021-04-13 09:36:58 +00:00
|
|
|
CallsProvider *provider;
|
|
|
|
guint n_items;
|
2020-03-17 15:29:43 +00:00
|
|
|
|
2021-04-13 09:36:58 +00:00
|
|
|
g_assert (CALLS_IS_MANAGER (self));
|
|
|
|
g_assert (name);
|
2020-03-17 15:29:43 +00:00
|
|
|
|
2021-04-13 09:36:58 +00:00
|
|
|
if (g_hash_table_lookup (self->providers, name))
|
2020-03-17 15:29:43 +00:00
|
|
|
return;
|
|
|
|
|
2021-04-13 09:36:58 +00:00
|
|
|
provider = calls_provider_load_plugin (name);
|
|
|
|
if (provider == NULL) {
|
|
|
|
g_warning ("Could not load a plugin with name `%s'", name);
|
2020-03-17 15:29:43 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-04-13 09:36:58 +00:00
|
|
|
g_hash_table_insert (self->providers, g_strdup (name), provider);
|
2020-03-17 15:29:43 +00:00
|
|
|
|
2021-04-13 09:36:58 +00:00
|
|
|
update_protocols (self);
|
|
|
|
|
|
|
|
origins = calls_provider_get_origins (provider);
|
2020-03-17 15:29:43 +00:00
|
|
|
|
2021-02-15 05:34:34 +00:00
|
|
|
g_signal_connect_object (origins, "items-changed",
|
|
|
|
G_CALLBACK (origin_items_changed_cb), self,
|
2021-04-13 09:36:58 +00:00
|
|
|
G_CONNECT_AFTER);
|
|
|
|
|
|
|
|
n_items = g_list_model_get_n_items (origins);
|
|
|
|
origin_items_changed_cb (origins, 0, 0, n_items, self);
|
2020-03-17 15:29:43 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
calls_manager_get_property (GObject *object,
|
|
|
|
guint property_id,
|
|
|
|
GValue *value,
|
|
|
|
GParamSpec *pspec)
|
|
|
|
{
|
|
|
|
CallsManager *self = CALLS_MANAGER (object);
|
|
|
|
|
|
|
|
switch (property_id) {
|
|
|
|
case PROP_STATE:
|
|
|
|
g_value_set_enum (value, calls_manager_get_state (self));
|
|
|
|
break;
|
2021-01-11 23:00:20 +00:00
|
|
|
|
2021-03-25 19:25:09 +00:00
|
|
|
case PROP_COUNTRY_CODE:
|
|
|
|
g_value_set_string (value, self->country_code);
|
|
|
|
break;
|
|
|
|
|
2020-03-17 15:29:43 +00:00
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
2021-01-11 23:00:20 +00:00
|
|
|
}
|
2020-03-17 15:29:43 +00:00
|
|
|
|
|
|
|
static void
|
|
|
|
calls_manager_set_property (GObject *object,
|
|
|
|
guint property_id,
|
|
|
|
const GValue *value,
|
|
|
|
GParamSpec *pspec)
|
|
|
|
{
|
|
|
|
CallsManager *self = CALLS_MANAGER (object);
|
|
|
|
|
|
|
|
switch (property_id) {
|
2021-03-25 19:25:09 +00:00
|
|
|
case PROP_COUNTRY_CODE:
|
|
|
|
g_free (self->country_code);
|
|
|
|
self->country_code = g_value_dup_string (value);
|
|
|
|
break;
|
|
|
|
|
2020-03-17 15:29:43 +00:00
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
calls_manager_finalize (GObject *object)
|
|
|
|
{
|
|
|
|
CallsManager *self = CALLS_MANAGER (object);
|
|
|
|
|
2021-04-13 09:36:58 +00:00
|
|
|
g_clear_object (&self->origins);
|
2021-01-20 14:20:09 +00:00
|
|
|
g_clear_object (&self->contacts_provider);
|
2021-03-25 19:25:09 +00:00
|
|
|
g_clear_pointer (&self->country_code, g_free);
|
2020-03-17 15:29:43 +00:00
|
|
|
|
2021-04-13 09:36:58 +00:00
|
|
|
g_clear_pointer (&self->providers, g_hash_table_unref);
|
|
|
|
g_clear_pointer (&self->origins_by_protocol, g_hash_table_unref);
|
|
|
|
g_clear_pointer (&self->supported_protocols, g_ptr_array_unref);
|
|
|
|
|
2020-03-17 15:29:43 +00:00
|
|
|
G_OBJECT_CLASS (calls_manager_parent_class)->finalize (object);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
calls_manager_class_init (CallsManagerClass *klass)
|
|
|
|
{
|
|
|
|
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
|
|
|
|
|
|
|
object_class->get_property = calls_manager_get_property;
|
|
|
|
object_class->set_property = calls_manager_set_property;
|
|
|
|
object_class->finalize = calls_manager_finalize;
|
|
|
|
|
|
|
|
signals[SIGNAL_CALL_ADD] =
|
|
|
|
g_signal_new ("call-add",
|
|
|
|
G_TYPE_FROM_CLASS (klass),
|
|
|
|
G_SIGNAL_RUN_FIRST,
|
|
|
|
0,
|
|
|
|
NULL, NULL, NULL,
|
|
|
|
G_TYPE_NONE,
|
|
|
|
2,
|
|
|
|
CALLS_TYPE_CALL,
|
|
|
|
CALLS_TYPE_ORIGIN);
|
|
|
|
|
|
|
|
signals[SIGNAL_CALL_REMOVE] =
|
|
|
|
g_signal_new ("call-remove",
|
|
|
|
G_TYPE_FROM_CLASS (klass),
|
|
|
|
G_SIGNAL_RUN_FIRST,
|
|
|
|
0,
|
|
|
|
NULL, NULL, NULL,
|
|
|
|
G_TYPE_NONE,
|
|
|
|
2,
|
|
|
|
CALLS_TYPE_CALL,
|
|
|
|
CALLS_TYPE_ORIGIN);
|
|
|
|
|
|
|
|
signals[SIGNAL_ERROR] =
|
|
|
|
g_signal_new ("error",
|
|
|
|
G_TYPE_FROM_CLASS (klass),
|
|
|
|
G_SIGNAL_RUN_FIRST,
|
|
|
|
0,
|
|
|
|
NULL, NULL, NULL,
|
|
|
|
G_TYPE_NONE,
|
|
|
|
1,
|
|
|
|
G_TYPE_STRING);
|
|
|
|
|
2020-07-07 12:40:31 +00:00
|
|
|
signals[USSD_ADDED] =
|
|
|
|
g_signal_new ("ussd-added",
|
|
|
|
G_TYPE_FROM_CLASS (klass),
|
|
|
|
G_SIGNAL_RUN_FIRST,
|
|
|
|
0,
|
|
|
|
NULL, NULL, NULL,
|
|
|
|
G_TYPE_NONE,
|
|
|
|
2,
|
|
|
|
CALLS_TYPE_USSD,
|
|
|
|
G_TYPE_STRING);
|
|
|
|
|
|
|
|
signals[USSD_CANCELLED] =
|
|
|
|
g_signal_new ("ussd-cancelled",
|
|
|
|
G_TYPE_FROM_CLASS (klass),
|
|
|
|
G_SIGNAL_RUN_FIRST,
|
|
|
|
0,
|
|
|
|
NULL, NULL, NULL,
|
|
|
|
G_TYPE_NONE,
|
|
|
|
1,
|
|
|
|
CALLS_TYPE_USSD);
|
|
|
|
|
|
|
|
signals[USSD_STATE_CHANGED] =
|
|
|
|
g_signal_new ("ussd-state-changed",
|
|
|
|
G_TYPE_FROM_CLASS (klass),
|
|
|
|
G_SIGNAL_RUN_FIRST,
|
|
|
|
0,
|
|
|
|
NULL, NULL, NULL,
|
|
|
|
G_TYPE_NONE,
|
|
|
|
1,
|
|
|
|
CALLS_TYPE_USSD);
|
|
|
|
|
2021-04-13 09:36:58 +00:00
|
|
|
props[PROP_STATE] =
|
|
|
|
g_param_spec_enum ("state",
|
|
|
|
"state",
|
|
|
|
"The state of the Manager",
|
|
|
|
CALLS_TYPE_MANAGER_STATE,
|
|
|
|
CALLS_MANAGER_STATE_NO_PROVIDER,
|
|
|
|
G_PARAM_READABLE | G_PARAM_EXPLICIT_NOTIFY);
|
2020-03-17 15:29:43 +00:00
|
|
|
|
2021-03-25 19:25:09 +00:00
|
|
|
props[PROP_COUNTRY_CODE] = g_param_spec_string ("country-code",
|
|
|
|
"country code",
|
|
|
|
"The default country code to use",
|
|
|
|
NULL,
|
|
|
|
G_PARAM_READWRITE);
|
|
|
|
|
2020-03-17 15:29:43 +00:00
|
|
|
g_object_class_install_properties (object_class, PROP_LAST_PROP, props);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
calls_manager_init (CallsManager *self)
|
|
|
|
{
|
2021-04-21 09:31:29 +00:00
|
|
|
PeasEngine *peas;
|
|
|
|
const gchar *dir;
|
|
|
|
|
2020-03-17 15:29:43 +00:00
|
|
|
self->state = CALLS_MANAGER_STATE_NO_PROVIDER;
|
2021-02-24 08:27:59 +00:00
|
|
|
self->primary_call = NULL;
|
2021-04-13 09:36:58 +00:00
|
|
|
self->providers = g_hash_table_new_full (g_str_hash,
|
|
|
|
g_str_equal,
|
|
|
|
g_free,
|
|
|
|
g_object_unref);
|
|
|
|
|
|
|
|
self->origins_by_protocol = g_hash_table_new_full (g_str_hash,
|
|
|
|
g_str_equal,
|
|
|
|
g_free,
|
|
|
|
g_object_unref);
|
|
|
|
|
|
|
|
self->origins = g_list_store_new (calls_origin_get_type ());
|
|
|
|
self->supported_protocols = g_ptr_array_new_full (5, g_free);
|
2021-01-20 14:20:09 +00:00
|
|
|
|
|
|
|
// Load the contacts provider
|
|
|
|
self->contacts_provider = calls_contacts_provider_new ();
|
2021-04-05 02:55:55 +00:00
|
|
|
g_object_bind_property (self, "country-code",
|
|
|
|
self->contacts_provider, "country-code",
|
|
|
|
G_BINDING_DEFAULT);
|
2021-04-21 09:31:29 +00:00
|
|
|
|
|
|
|
peas = peas_engine_get_default ();
|
|
|
|
|
|
|
|
dir = g_getenv ("CALLS_PLUGIN_DIR");
|
|
|
|
if (dir && dir[0] != '\0') {
|
2021-06-29 12:43:16 +00:00
|
|
|
/** Add the directory to the search path. prepend_search_path() does not work
|
|
|
|
* as expected. see https://gitlab.gnome.org/GNOME/libpeas/-/issues/19
|
|
|
|
*/
|
2021-04-21 09:31:29 +00:00
|
|
|
g_debug ("Adding %s to plugin search path", dir);
|
2021-06-29 12:43:16 +00:00
|
|
|
peas_engine_add_search_path (peas, dir, NULL);
|
2021-04-21 09:31:29 +00:00
|
|
|
}
|
|
|
|
|
2021-06-29 12:43:16 +00:00
|
|
|
peas_engine_add_search_path (peas, PLUGIN_LIBDIR, NULL);
|
|
|
|
g_debug ("Scanning for plugins in `%s'", PLUGIN_LIBDIR);
|
2020-03-17 15:29:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
CallsManager *
|
|
|
|
calls_manager_new (void)
|
|
|
|
{
|
|
|
|
return g_object_new (CALLS_TYPE_MANAGER, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
CallsManager *
|
|
|
|
calls_manager_get_default (void)
|
|
|
|
{
|
|
|
|
static CallsManager *instance;
|
|
|
|
|
|
|
|
if (instance == NULL) {
|
|
|
|
instance = calls_manager_new ();
|
|
|
|
g_object_add_weak_pointer (G_OBJECT (instance), (gpointer *)&instance);
|
|
|
|
}
|
|
|
|
return instance;
|
|
|
|
}
|
|
|
|
|
2021-01-20 14:20:09 +00:00
|
|
|
CallsContactsProvider *
|
|
|
|
calls_manager_get_contacts_provider (CallsManager *self)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (CALLS_IS_MANAGER (self), NULL);
|
|
|
|
|
|
|
|
return self->contacts_provider;
|
|
|
|
}
|
|
|
|
|
2021-04-13 09:36:58 +00:00
|
|
|
void
|
|
|
|
calls_manager_add_provider (CallsManager *self,
|
|
|
|
const char *name)
|
2020-03-17 15:29:43 +00:00
|
|
|
{
|
2021-04-13 09:36:58 +00:00
|
|
|
g_return_if_fail (CALLS_IS_MANAGER (self));
|
|
|
|
g_return_if_fail (name);
|
2020-03-17 15:29:43 +00:00
|
|
|
|
2021-04-13 09:36:58 +00:00
|
|
|
add_provider (self, name);
|
2020-03-17 15:29:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2021-04-13 09:36:58 +00:00
|
|
|
calls_manager_remove_provider (CallsManager *self,
|
|
|
|
const char *name)
|
2020-03-17 15:29:43 +00:00
|
|
|
{
|
|
|
|
g_return_if_fail (CALLS_IS_MANAGER (self));
|
2021-04-13 09:36:58 +00:00
|
|
|
g_return_if_fail (name);
|
2020-03-17 15:29:43 +00:00
|
|
|
|
2021-04-13 09:36:58 +00:00
|
|
|
remove_provider (self, name);
|
|
|
|
update_protocols (self);
|
|
|
|
}
|
2020-03-17 15:29:43 +00:00
|
|
|
|
2021-04-13 09:36:58 +00:00
|
|
|
gboolean
|
|
|
|
calls_manager_has_provider (CallsManager *self,
|
|
|
|
const char *name)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (CALLS_IS_MANAGER (self), FALSE);
|
|
|
|
g_return_val_if_fail (name, FALSE);
|
2020-03-17 15:29:43 +00:00
|
|
|
|
2021-04-13 09:36:58 +00:00
|
|
|
return !!g_hash_table_lookup (self->providers, name);
|
2020-03-17 15:29:43 +00:00
|
|
|
}
|
|
|
|
|
2021-05-05 18:53:37 +00:00
|
|
|
gboolean
|
|
|
|
calls_manager_is_modem_provider (CallsManager *self,
|
|
|
|
const char *name)
|
|
|
|
{
|
|
|
|
CallsProvider *provider;
|
|
|
|
|
|
|
|
g_return_val_if_fail (CALLS_IS_MANAGER (self), FALSE);
|
|
|
|
g_return_val_if_fail (name, FALSE);
|
|
|
|
|
|
|
|
provider = g_hash_table_lookup (self->providers, name);
|
|
|
|
g_return_val_if_fail (provider, FALSE);
|
|
|
|
|
|
|
|
return calls_provider_is_modem (provider);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* calls_manager_provder_add_accounts:
|
|
|
|
* @self: A #CallsManager
|
|
|
|
* @name: The name of the provider to add the account to
|
|
|
|
* @credentials: A #CallsCredentials storing the credentials of the account
|
|
|
|
*
|
|
|
|
* Returns: %TRUE if account successfully added, %FALSE otherwise
|
|
|
|
*/
|
|
|
|
gboolean
|
|
|
|
calls_manager_provider_add_account (CallsManager *self,
|
|
|
|
const char *name,
|
|
|
|
CallsCredentials *credentials)
|
|
|
|
{
|
|
|
|
CallsProvider *provider = NULL;
|
|
|
|
|
|
|
|
g_return_val_if_fail (CALLS_IS_MANAGER (self), FALSE);
|
|
|
|
g_return_val_if_fail (name, FALSE);
|
|
|
|
g_return_val_if_fail (CALLS_IS_CREDENTIALS (credentials), FALSE);
|
|
|
|
|
|
|
|
provider = g_hash_table_lookup (self->providers, name);
|
|
|
|
g_return_val_if_fail (CALLS_IS_PROVIDER (provider), FALSE);
|
|
|
|
g_return_val_if_fail (CALLS_IS_ACCOUNT_PROVIDER (provider), FALSE);
|
|
|
|
|
|
|
|
return calls_account_provider_add_account (CALLS_ACCOUNT_PROVIDER (provider),
|
|
|
|
credentials);
|
|
|
|
}
|
|
|
|
/**
|
|
|
|
* calls_manager_provder_remove_accounts:
|
|
|
|
* @self: A #CallsManager
|
|
|
|
* @name: The name of the provider to add the account to
|
|
|
|
* @credentials: A #CallsCredentials storing the credentials of the account
|
|
|
|
*
|
|
|
|
* Returns: %TRUE if account successfully removed, %FALSE otherwise
|
|
|
|
*/
|
|
|
|
gboolean
|
|
|
|
calls_manager_provider_remove_account (CallsManager *self,
|
|
|
|
const char *name,
|
|
|
|
CallsCredentials *credentials)
|
|
|
|
{
|
|
|
|
CallsProvider *provider = NULL;
|
|
|
|
|
|
|
|
g_return_val_if_fail (CALLS_IS_MANAGER (self), FALSE);
|
|
|
|
g_return_val_if_fail (name, FALSE);
|
|
|
|
g_return_val_if_fail (CALLS_IS_CREDENTIALS (credentials), FALSE);
|
|
|
|
|
|
|
|
provider = g_hash_table_lookup (self->providers, name);
|
|
|
|
g_return_val_if_fail (CALLS_IS_PROVIDER (provider), FALSE);
|
|
|
|
g_return_val_if_fail (CALLS_IS_ACCOUNT_PROVIDER (provider), FALSE);
|
|
|
|
|
|
|
|
return calls_account_provider_remove_account (CALLS_ACCOUNT_PROVIDER (provider),
|
|
|
|
credentials);
|
|
|
|
}
|
|
|
|
|
2020-03-17 15:29:43 +00:00
|
|
|
CallsManagerState
|
|
|
|
calls_manager_get_state (CallsManager *self)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (CALLS_IS_MANAGER (self), CALLS_MANAGER_STATE_UNKNOWN);
|
|
|
|
|
|
|
|
return self->state;
|
|
|
|
}
|
|
|
|
|
2021-02-15 05:34:34 +00:00
|
|
|
GListModel *
|
2020-03-17 15:29:43 +00:00
|
|
|
calls_manager_get_origins (CallsManager *self)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (CALLS_IS_MANAGER (self), NULL);
|
|
|
|
|
2021-04-13 09:36:58 +00:00
|
|
|
return G_LIST_MODEL (self->origins);
|
2020-03-17 15:29:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
GList *
|
|
|
|
calls_manager_get_calls (CallsManager *self)
|
|
|
|
{
|
2021-02-15 05:34:34 +00:00
|
|
|
GListModel *origins = NULL;
|
2020-03-17 15:29:43 +00:00
|
|
|
g_autoptr (GList) calls = NULL;
|
2021-02-15 05:34:34 +00:00
|
|
|
guint n_items = 0;
|
2020-03-17 15:29:43 +00:00
|
|
|
|
|
|
|
g_return_val_if_fail (CALLS_IS_MANAGER (self), NULL);
|
|
|
|
|
|
|
|
origins = calls_manager_get_origins (self);
|
2021-02-15 05:34:34 +00:00
|
|
|
if (origins)
|
|
|
|
n_items = g_list_model_get_n_items (origins);
|
|
|
|
|
|
|
|
for (guint i = 0; i < n_items; i++)
|
|
|
|
{
|
2021-04-21 09:28:03 +00:00
|
|
|
g_autoptr (CallsOrigin) origin = NULL;
|
2020-03-17 15:29:43 +00:00
|
|
|
|
2021-02-15 05:34:34 +00:00
|
|
|
origin = g_list_model_get_item (origins, i);
|
|
|
|
calls = g_list_concat (calls, calls_origin_get_calls (origin));
|
|
|
|
}
|
2020-03-17 15:29:43 +00:00
|
|
|
|
|
|
|
return g_steal_pointer (&calls);
|
|
|
|
}
|
|
|
|
|
2021-01-11 23:50:28 +00:00
|
|
|
/**
|
|
|
|
* calls_manager_hang_up_all_calls:
|
|
|
|
* @self: a #CallsManager
|
|
|
|
*
|
|
|
|
* Hangs up on every call known to @self.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
calls_manager_hang_up_all_calls (CallsManager *self)
|
|
|
|
{
|
|
|
|
g_autoptr (GList) calls = NULL;
|
|
|
|
GList *node;
|
|
|
|
CallsCall *call;
|
|
|
|
|
|
|
|
g_return_if_fail (CALLS_IS_MANAGER (self));
|
|
|
|
|
|
|
|
calls = calls_manager_get_calls (self);
|
|
|
|
|
|
|
|
for (node = calls; node; node = node->next)
|
|
|
|
{
|
|
|
|
call = node->data;
|
|
|
|
g_debug ("Hanging up on call %s", calls_call_get_name (call));
|
|
|
|
calls_call_hang_up (call);
|
|
|
|
}
|
|
|
|
|
|
|
|
g_debug ("Hanged up on all calls");
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* calls_manager_has_active_call
|
|
|
|
* @self: a #CallsManager
|
|
|
|
*
|
|
|
|
* Checks if @self has any active call
|
|
|
|
*
|
|
|
|
* Returns: %TRUE if there are active calls, %FALSE otherwise
|
|
|
|
*/
|
|
|
|
gboolean
|
|
|
|
calls_manager_has_active_call (CallsManager *self)
|
|
|
|
{
|
|
|
|
g_autoptr (GList) calls = NULL;
|
|
|
|
GList *node;
|
|
|
|
CallsCall *call;
|
|
|
|
|
|
|
|
g_return_val_if_fail (CALLS_IS_MANAGER (self), FALSE);
|
|
|
|
|
|
|
|
calls = calls_manager_get_calls (self);
|
|
|
|
|
|
|
|
for (node = calls; node; node = node->next)
|
|
|
|
{
|
|
|
|
call = node->data;
|
|
|
|
if (calls_call_get_state (call) != CALLS_CALL_STATE_DISCONNECTED)
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2021-04-13 09:36:58 +00:00
|
|
|
/**
|
|
|
|
* calls_manager_get_suitable_origins:
|
|
|
|
* @self: The #CallsManager
|
|
|
|
* @target: The target number/address
|
|
|
|
*
|
|
|
|
* Returns (transfer none): A #GListModel of suitable origins
|
|
|
|
*/
|
|
|
|
GListModel *
|
|
|
|
calls_manager_get_suitable_origins (CallsManager *self,
|
|
|
|
const char *target)
|
2020-03-17 15:29:43 +00:00
|
|
|
{
|
2021-04-13 09:36:58 +00:00
|
|
|
const char *protocol;
|
|
|
|
GListModel *model;
|
2020-03-17 15:29:43 +00:00
|
|
|
|
2021-04-13 09:36:58 +00:00
|
|
|
g_return_val_if_fail (CALLS_IS_MANAGER (self), NULL);
|
|
|
|
g_return_val_if_fail (target, NULL);
|
2021-03-25 19:25:09 +00:00
|
|
|
|
2021-04-13 09:36:58 +00:00
|
|
|
protocol = get_protocol_from_address_with_fallback (target);
|
2020-03-17 15:29:43 +00:00
|
|
|
|
2021-04-13 09:36:58 +00:00
|
|
|
model = g_hash_table_lookup (self->origins_by_protocol, protocol);
|
|
|
|
if (model && G_IS_LIST_MODEL (model))
|
|
|
|
return model;
|
2020-03-17 15:29:43 +00:00
|
|
|
|
2021-04-13 09:36:58 +00:00
|
|
|
return NULL;
|
2020-03-17 15:29:43 +00:00
|
|
|
}
|
2021-04-16 17:12:27 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* calls_manager_has_any_provider:
|
|
|
|
* @self: The #CallsManager
|
|
|
|
*
|
|
|
|
* Returns: %TRUE if any provider is loaded, %FALSE otherwise
|
|
|
|
*/
|
|
|
|
gboolean
|
|
|
|
calls_manager_has_any_provider (CallsManager *self)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (CALLS_IS_MANAGER (self), FALSE);
|
|
|
|
|
|
|
|
return !!g_hash_table_size (self->providers);
|
|
|
|
}
|
2021-06-09 12:19:27 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 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);
|
|
|
|
}
|