diff --git a/src/calls-account.c b/src/calls-account.c new file mode 100644 index 0000000..216413c --- /dev/null +++ b/src/calls-account.c @@ -0,0 +1,93 @@ +/* + * Copyright (C) 2021 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 . + * + * Author: Evangelos Ribeiro Tzaras + * + * SPDX-License-Identifier: GPL-3.0-or-later + * + */ + +#include "calls-credentials.h" +#include "calls-account.h" +#include "enum-types.h" + +/** + * SECTION:account + * @short_description: An interface for online accounts + * @Title: CallsAccount + * + * #CallsAccount is meant to be implemented by a #CallsOrigin when + * the #CallsOrigin uses #CallsCredentials to connect to the internet. + */ + +enum { + SIGNAL_ACCOUNT_STATE_CHANGED, + SIGNAL_LAST_SIGNAL +}; +static guint signals[SIGNAL_LAST_SIGNAL]; + +G_DEFINE_INTERFACE (CallsAccount, calls_account, CALLS_TYPE_ORIGIN) + + +static void +calls_account_default_init (CallsAccountInterface *iface) +{ + signals[SIGNAL_ACCOUNT_STATE_CHANGED] = + g_signal_new ("account-state-changed", + G_TYPE_FROM_INTERFACE (iface), + G_SIGNAL_RUN_LAST, + 0, NULL, NULL, NULL, + G_TYPE_NONE, + 2, CALLS_TYPE_ACCOUNT_STATE, CALLS_TYPE_ACCOUNT_STATE); + + g_object_interface_install_property (iface, + g_param_spec_object ("account-credentials", + "Account credentials", + "The credentials to be used for authentication", + CALLS_TYPE_CREDENTIALS, + G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY)); + + g_object_interface_install_property (iface, + g_param_spec_enum ("account-state", + "Account state", + "The state of the account", + CALLS_TYPE_ACCOUNT_STATE, + CALLS_ACCOUNT_NULL, + G_PARAM_READABLE)); +} + +/** + * calls_account_go_online: + * @self: a #CallsAccount + * @online: %TRUE to try to go online, %FALSE to go offline + * + * Connect or disconnect to a server. + */ +void +calls_account_go_online (CallsAccount *self, + gboolean online) +{ + CallsAccountInterface *iface; + + g_return_if_fail (CALLS_IS_ACCOUNT (self)); + + iface = CALLS_ACCOUNT_GET_IFACE (self); + g_return_if_fail (iface->go_online != NULL); + + return iface->go_online (self, online); +} diff --git a/src/calls-account.h b/src/calls-account.h new file mode 100644 index 0000000..ab33921 --- /dev/null +++ b/src/calls-account.h @@ -0,0 +1,70 @@ +/* + * Copyright (C) 2021 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 . + * + * Author: Evangelos Ribeiro Tzaras + * + * SPDX-License-Identifier: GPL-3.0-or-later + * + */ + +#pragma once + +#include "calls-origin.h" + +#include + +G_BEGIN_DECLS + + +#define CALLS_TYPE_ACCOUNT (calls_account_get_type ()) + +G_DECLARE_INTERFACE (CallsAccount, calls_account, CALLS, ACCOUNT, CallsOrigin); + + +struct _CallsAccountInterface +{ + GTypeInterface parent_iface; + + void (*go_online) (CallsAccount *self, + gboolean online); +}; +/** + * CallsAccountState: + * @CALLS_ACCOUNT_NULL: Not initialized + * @CALLS_ACCOUNT_OFFLINE: Account considered offline (not ready for placing or receiving calls) + * @CALLS_ACCOUNT_CONNECTING: Trying to connect to server + * @CALLS_ACCOUNT_CONNECTION_FAILURE: Could not connect to server (f.e. DNS error, unreachable) + * @CALLS_ACCOUNT_AUTHENTICATING: Authenticating using web-auth/proxy-auth + * @CALLS_ACCOUNT_AUTHENTICATION_FAILURE: Could not authenticate to server (f.e. wrong credentials) + * @CALLS_ACCOUNT_ONLINE: Account considered online (can place and receive calls) + */ +typedef enum { + CALLS_ACCOUNT_NULL = 0, + CALLS_ACCOUNT_OFFLINE, + CALLS_ACCOUNT_CONNECTING, + CALLS_ACCOUNT_CONNECTION_FAILURE, + CALLS_ACCOUNT_AUTHENTICATING, + CALLS_ACCOUNT_AUTHENTICATION_FAILURE, + CALLS_ACCOUNT_ONLINE +} CallsAccountState; + + +void calls_account_go_online (CallsAccount *self, + gboolean online); + +G_END_DECLS diff --git a/src/meson.build b/src/meson.build index 16120d8..eaadef9 100644 --- a/src/meson.build +++ b/src/meson.build @@ -64,7 +64,11 @@ calls_vala = static_library ( ) -calls_enum_headers = files(['calls-call.h', 'calls-ussd.h', 'calls-manager.h']) +calls_enum_headers = files(['calls-call.h', + 'calls-ussd.h', + 'calls-manager.h', + 'calls-account.h', + ]) calls_enum_sources = gnome.mkenums_simple('enum-types', sources : calls_enum_headers) @@ -107,6 +111,7 @@ calls_sources = files(['calls-message-source.c', 'calls-message-source.h', 'calls-contacts-box.c', 'calls-contacts-box.h', 'calls-contacts-row.c', 'calls-contacts-row.h', 'calls-credentials.c', 'calls-credentials.h', + 'calls-account.c', 'calls-account.h', ]) + wayland_sources + calls_generated_sources calls_config_data = config_data