2018-09-15 10:33:36 +00:00
|
|
|
/* calls-application.c
|
|
|
|
*
|
2019-08-01 13:25:53 +00:00
|
|
|
* Copyright (C) 2018, 2019 Purism SPC
|
2018-09-15 10:33:36 +00:00
|
|
|
* Copyright (C) 2018 Mohammed Sadiq <sadiq@sadiqpk.org>
|
|
|
|
*
|
|
|
|
* 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/>.
|
|
|
|
*
|
|
|
|
* Authors:
|
|
|
|
* Bob Ham <bob.ham@puri.sm>
|
|
|
|
* Mohammed Sadiq <sadiq@sadiqpk.org>
|
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: GPL-3.0-or-later
|
|
|
|
*/
|
|
|
|
|
2021-06-18 09:10:36 +00:00
|
|
|
#define G_LOG_DOMAIN "CallsApplication"
|
|
|
|
|
2018-09-15 10:33:36 +00:00
|
|
|
#include "config.h"
|
2021-04-02 07:52:14 +00:00
|
|
|
#include "calls-dbus-manager.h"
|
2018-09-15 10:33:36 +00:00
|
|
|
#include "calls-history-box.h"
|
|
|
|
#include "calls-new-call-box.h"
|
|
|
|
#include "calls-encryption-indicator.h"
|
2018-11-09 16:30:40 +00:00
|
|
|
#include "calls-ringer.h"
|
2020-05-19 10:36:29 +00:00
|
|
|
#include "calls-notifier.h"
|
2019-07-22 10:52:46 +00:00
|
|
|
#include "calls-record-store.h"
|
2018-09-15 10:33:36 +00:00
|
|
|
#include "calls-call-window.h"
|
|
|
|
#include "calls-main-window.h"
|
2020-03-17 15:29:43 +00:00
|
|
|
#include "calls-manager.h"
|
2018-09-15 10:33:36 +00:00
|
|
|
#include "calls-application.h"
|
2021-07-30 10:43:30 +00:00
|
|
|
#include "calls-log.h"
|
2021-04-16 16:15:59 +00:00
|
|
|
#include "version.h"
|
2018-09-15 10:33:36 +00:00
|
|
|
|
2021-10-01 16:34:57 +00:00
|
|
|
#include <call-ui.h>
|
2018-11-23 14:34:41 +00:00
|
|
|
#include <glib/gi18n.h>
|
2020-09-29 10:22:47 +00:00
|
|
|
#include <handy.h>
|
2020-10-28 17:17:44 +00:00
|
|
|
#include <libcallaudio.h>
|
2018-11-23 14:34:41 +00:00
|
|
|
|
2018-09-15 10:33:36 +00:00
|
|
|
/**
|
|
|
|
* SECTION: calls-application
|
|
|
|
* @title: CallsApplication
|
|
|
|
* @short_description: Base Application class
|
|
|
|
* @include: "calls-application.h"
|
|
|
|
*/
|
|
|
|
|
2018-11-23 14:34:41 +00:00
|
|
|
#define DEFAULT_PROVIDER_PLUGIN "mm"
|
|
|
|
|
2018-09-15 10:33:36 +00:00
|
|
|
struct _CallsApplication
|
|
|
|
{
|
|
|
|
GtkApplication parent_instance;
|
|
|
|
|
2019-08-08 12:51:17 +00:00
|
|
|
gboolean daemon;
|
2019-07-22 10:52:46 +00:00
|
|
|
CallsRinger *ringer;
|
2020-05-19 10:36:29 +00:00
|
|
|
CallsNotifier *notifier;
|
2019-07-22 10:52:46 +00:00
|
|
|
CallsRecordStore *record_store;
|
2019-08-05 10:25:45 +00:00
|
|
|
CallsMainWindow *main_window;
|
|
|
|
CallsCallWindow *call_window;
|
2021-04-02 07:52:14 +00:00
|
|
|
CallsDBusManager *dbus_manager;
|
2021-02-24 07:23:52 +00:00
|
|
|
|
|
|
|
char *uri;
|
2018-09-15 10:33:36 +00:00
|
|
|
};
|
|
|
|
|
2020-02-17 16:01:43 +00:00
|
|
|
G_DEFINE_TYPE (CallsApplication, calls_application, GTK_TYPE_APPLICATION);
|
|
|
|
|
|
|
|
|
|
|
|
static gboolean start_proper (CallsApplication *self);
|
2018-09-15 10:33:36 +00:00
|
|
|
|
|
|
|
|
2021-07-30 10:43:30 +00:00
|
|
|
static gboolean
|
|
|
|
cmd_verbose_cb (const char *option_name,
|
|
|
|
const char *value,
|
|
|
|
gpointer data,
|
|
|
|
GError **error)
|
|
|
|
{
|
|
|
|
calls_log_increase_verbosity ();
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2021-04-02 07:52:14 +00:00
|
|
|
static gboolean
|
|
|
|
calls_application_dbus_register (GApplication *application,
|
|
|
|
GDBusConnection *connection,
|
|
|
|
const gchar *object_path,
|
|
|
|
GError **error)
|
|
|
|
{
|
|
|
|
CallsApplication *self = CALLS_APPLICATION (application);
|
|
|
|
|
|
|
|
G_APPLICATION_CLASS (calls_application_parent_class)->dbus_register (application,
|
|
|
|
connection,
|
|
|
|
object_path,
|
|
|
|
error);
|
|
|
|
|
|
|
|
self->dbus_manager = calls_dbus_manager_new ();
|
|
|
|
return calls_dbus_manager_register (self->dbus_manager, connection, object_path, error);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
calls_application_dbus_unregister (GApplication *application,
|
|
|
|
GDBusConnection *connection,
|
|
|
|
const gchar *object_path)
|
|
|
|
{
|
|
|
|
CallsApplication *self = CALLS_APPLICATION (application);
|
|
|
|
|
|
|
|
g_clear_object (&self->dbus_manager);
|
|
|
|
|
|
|
|
G_APPLICATION_CLASS (calls_application_parent_class)->dbus_unregister (application,
|
|
|
|
connection,
|
|
|
|
object_path);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-09-15 10:33:36 +00:00
|
|
|
static void
|
2021-06-09 12:19:27 +00:00
|
|
|
set_provider_names_action (GSimpleAction *action,
|
|
|
|
GVariant *parameter,
|
|
|
|
gpointer user_data)
|
2018-09-15 10:33:36 +00:00
|
|
|
{
|
2021-06-09 12:19:27 +00:00
|
|
|
CallsManager *manager;
|
|
|
|
g_autofree const char **names = NULL;
|
|
|
|
g_autofree const char **loaded = NULL;
|
|
|
|
gsize length;
|
|
|
|
guint length_loaded;
|
2018-09-15 10:33:36 +00:00
|
|
|
|
2021-06-09 12:19:27 +00:00
|
|
|
names = g_variant_get_strv (parameter, &length);
|
|
|
|
g_return_if_fail (names && *names);
|
2018-09-15 10:33:36 +00:00
|
|
|
|
2021-06-09 12:19:27 +00:00
|
|
|
manager = calls_manager_get_default ();
|
|
|
|
loaded = calls_manager_get_provider_names (manager, &length_loaded);
|
|
|
|
|
|
|
|
/* 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);
|
2021-04-16 17:47:01 +00:00
|
|
|
}
|
2018-11-23 14:34:41 +00:00
|
|
|
|
2021-06-09 12:19:27 +00:00
|
|
|
for (guint i = 0; i < length; i++) {
|
|
|
|
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)
|
|
|
|
{
|
2021-09-23 07:32:37 +00:00
|
|
|
CallsManager *manager = calls_manager_get_default ();
|
|
|
|
CallsSettings *settings = calls_manager_get_settings (manager);
|
2021-06-10 02:25:50 +00:00
|
|
|
g_auto (GStrv) plugins = NULL;
|
2021-06-09 12:19:27 +00:00
|
|
|
/**
|
|
|
|
* Only add default providers when there are none added yet,
|
|
|
|
* This makes sure we're not resetting explicitly set providers
|
|
|
|
*/
|
2021-09-23 07:32:37 +00:00
|
|
|
if (calls_manager_has_any_provider (manager))
|
2021-06-09 12:19:27 +00:00
|
|
|
return;
|
|
|
|
|
2021-09-23 07:32:37 +00:00
|
|
|
plugins = calls_settings_get_autoload_plugins (settings);
|
2021-06-10 02:25:50 +00:00
|
|
|
for (guint i = 0; plugins[i] != NULL; i++) {
|
2021-09-23 07:32:37 +00:00
|
|
|
calls_manager_add_provider (manager, plugins[i]);
|
2021-06-10 02:25:50 +00:00
|
|
|
}
|
2018-09-15 10:33:36 +00:00
|
|
|
}
|
|
|
|
|
2018-11-23 14:34:41 +00:00
|
|
|
|
2019-08-08 12:51:17 +00:00
|
|
|
static void
|
|
|
|
set_daemon_action (GSimpleAction *action,
|
|
|
|
GVariant *parameter,
|
|
|
|
gpointer user_data)
|
|
|
|
{
|
|
|
|
CallsApplication *self = CALLS_APPLICATION (user_data);
|
|
|
|
|
2021-04-16 17:47:01 +00:00
|
|
|
if (self->main_window) {
|
|
|
|
g_warning ("Cannot set application as a daemon"
|
|
|
|
" because application is already started");
|
|
|
|
return;
|
|
|
|
}
|
2019-08-08 12:51:17 +00:00
|
|
|
|
|
|
|
self->daemon = TRUE;
|
|
|
|
|
|
|
|
g_debug ("Application marked as daemon");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-02-17 16:01:43 +00:00
|
|
|
#define DIALLING "0-9*#+ABCD"
|
|
|
|
#define SIGNALLING ",TP!W@X"
|
|
|
|
#define VISUAL "[:space:]\\-.()t/"
|
|
|
|
#define REJECT_RE "[^" DIALLING SIGNALLING VISUAL "]"
|
|
|
|
#define VISUAL_RE "[" VISUAL "]"
|
|
|
|
|
|
|
|
static gboolean
|
2021-04-16 17:47:01 +00:00
|
|
|
check_dial_number (const char *number)
|
2020-02-17 16:01:43 +00:00
|
|
|
{
|
2021-01-12 16:49:24 +00:00
|
|
|
g_autoptr (GError) error = NULL;
|
2021-02-10 23:32:25 +00:00
|
|
|
g_autoptr (GRegex) reject = g_regex_new (REJECT_RE, 0, 0, &error);
|
2020-02-17 16:01:43 +00:00
|
|
|
gboolean matches;
|
|
|
|
|
2021-04-16 17:47:01 +00:00
|
|
|
if (!reject) {
|
|
|
|
g_warning ("Could not compile regex for"
|
|
|
|
" dial number checking: %s",
|
|
|
|
error->message);
|
|
|
|
return FALSE;
|
|
|
|
}
|
2020-02-17 16:01:43 +00:00
|
|
|
|
|
|
|
matches = g_regex_match (reject, number, 0, NULL);
|
|
|
|
|
|
|
|
return !matches;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-04-16 17:47:01 +00:00
|
|
|
static char *
|
|
|
|
extract_dial_string (const char *number)
|
2020-02-17 16:01:43 +00:00
|
|
|
{
|
2021-02-10 23:38:10 +00:00
|
|
|
g_autoptr (GError) error = NULL;
|
2021-02-10 23:32:25 +00:00
|
|
|
g_autoptr (GRegex) replace_visual = g_regex_new (VISUAL_RE, 0, 0, &error);
|
2021-04-16 17:47:01 +00:00
|
|
|
char *dial_string;
|
2020-02-17 16:01:43 +00:00
|
|
|
|
2021-04-16 17:47:01 +00:00
|
|
|
if (!replace_visual) {
|
|
|
|
g_warning ("Could not compile regex for"
|
|
|
|
" dial number extracting: %s",
|
|
|
|
error->message);
|
|
|
|
return NULL;
|
|
|
|
}
|
2020-02-17 16:01:43 +00:00
|
|
|
|
|
|
|
dial_string = g_regex_replace_literal
|
|
|
|
(replace_visual, number, -1, 0, "", 0, &error);
|
|
|
|
|
2021-04-16 17:47:01 +00:00
|
|
|
if (!dial_string) {
|
|
|
|
g_warning ("Error replacing visual separators"
|
|
|
|
" in dial number: %s",
|
|
|
|
error->message);
|
|
|
|
return NULL;
|
|
|
|
}
|
2020-02-17 16:01:43 +00:00
|
|
|
|
|
|
|
return dial_string;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-09-07 12:03:27 +00:00
|
|
|
static void
|
|
|
|
call_number (CallsApplication *self,
|
|
|
|
const char *number)
|
|
|
|
{
|
|
|
|
g_autofree char *dial_string = NULL;
|
|
|
|
gboolean number_ok;
|
|
|
|
|
|
|
|
number_ok = check_dial_number (number);
|
|
|
|
if (!number_ok) {
|
|
|
|
g_warning ("Dial number `%s' is not a valid dial string",
|
|
|
|
number);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
dial_string = extract_dial_string (number);
|
|
|
|
if (!dial_string) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
g_debug ("Dialing dial string `%s' extracted from number `%s'",
|
|
|
|
dial_string, number);
|
|
|
|
|
|
|
|
start_proper (self);
|
|
|
|
|
|
|
|
calls_main_window_dial (self->main_window,
|
|
|
|
dial_string);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-02-17 16:01:43 +00:00
|
|
|
static void
|
|
|
|
dial_action (GSimpleAction *action,
|
|
|
|
GVariant *parameter,
|
|
|
|
gpointer user_data)
|
|
|
|
{
|
|
|
|
CallsApplication *self = CALLS_APPLICATION (user_data);
|
2021-04-16 17:47:01 +00:00
|
|
|
const char *number;
|
2020-02-17 16:01:43 +00:00
|
|
|
|
|
|
|
number = g_variant_get_string (parameter, NULL);
|
|
|
|
g_return_if_fail (number != NULL);
|
|
|
|
|
2021-09-07 12:03:27 +00:00
|
|
|
call_number (self, number);
|
2020-02-17 16:01:43 +00:00
|
|
|
}
|
|
|
|
|
2021-01-19 15:03:28 +00:00
|
|
|
static void
|
|
|
|
copy_number (GSimpleAction *action,
|
|
|
|
GVariant *parameter,
|
|
|
|
gpointer user_data)
|
|
|
|
{
|
2021-04-16 17:47:01 +00:00
|
|
|
const char *number = g_variant_get_string (parameter, NULL);
|
2021-01-19 15:03:28 +00:00
|
|
|
GtkClipboard *clipboard =
|
|
|
|
gtk_clipboard_get_default (gdk_display_get_default ());
|
|
|
|
|
|
|
|
gtk_clipboard_set_text (clipboard, number, -1);
|
|
|
|
|
|
|
|
g_debug ("Copied `%s' to clipboard", number);
|
|
|
|
}
|
2020-02-17 16:01:43 +00:00
|
|
|
|
2021-05-11 16:18:35 +00:00
|
|
|
static void
|
|
|
|
show_accounts (GSimpleAction *action,
|
|
|
|
GVariant *parameter,
|
|
|
|
gpointer user_data)
|
|
|
|
{
|
|
|
|
CallsApplication *app = CALLS_APPLICATION (g_application_get_default ());
|
|
|
|
calls_main_window_show_accounts_overview (app->main_window);
|
|
|
|
}
|
|
|
|
|
2021-01-20 15:58:42 +00:00
|
|
|
static void
|
|
|
|
manager_state_changed_cb (GApplication *application)
|
|
|
|
{
|
|
|
|
GAction* dial_action = g_action_map_lookup_action (G_ACTION_MAP (application), "dial");
|
|
|
|
CallsManagerState state = calls_manager_get_state (calls_manager_get_default ());
|
|
|
|
|
|
|
|
g_simple_action_set_enabled (G_SIMPLE_ACTION (dial_action), state == CALLS_MANAGER_STATE_READY);
|
|
|
|
}
|
|
|
|
|
2018-11-23 14:34:41 +00:00
|
|
|
static const GActionEntry actions[] =
|
|
|
|
{
|
2021-06-09 12:19:27 +00:00
|
|
|
{ "set-provider-names", set_provider_names_action, "as" },
|
|
|
|
{ "set-default-providers", set_default_providers_action, NULL },
|
2019-08-08 12:51:17 +00:00
|
|
|
{ "set-daemon", set_daemon_action, NULL },
|
2020-02-17 16:01:43 +00:00
|
|
|
{ "dial", dial_action, "s" },
|
2021-01-19 15:03:28 +00:00
|
|
|
{ "copy-number", copy_number, "s"},
|
2021-05-11 16:18:35 +00:00
|
|
|
/* TODO About dialog { "about", show_about, NULL}, */
|
|
|
|
{ "accounts", show_accounts, NULL},
|
2018-11-23 14:34:41 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2021-02-25 09:06:27 +00:00
|
|
|
static int
|
|
|
|
calls_application_handle_local_options (GApplication *application,
|
|
|
|
GVariantDict *options)
|
|
|
|
{
|
|
|
|
if (g_variant_dict_contains (options, "version")) {
|
|
|
|
g_print ("%s %s\n", APP_DATA_NAME, *VCS_TAG ? VCS_TAG : PACKAGE_VERSION);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-09-15 10:33:36 +00:00
|
|
|
static void
|
|
|
|
startup (GApplication *application)
|
|
|
|
{
|
2021-02-10 23:38:10 +00:00
|
|
|
g_autoptr (GtkCssProvider) provider = NULL;
|
|
|
|
g_autoptr (GError) error = NULL;
|
2019-08-01 13:25:53 +00:00
|
|
|
|
2018-09-15 10:33:36 +00:00
|
|
|
G_APPLICATION_CLASS (calls_application_parent_class)->startup (application);
|
|
|
|
|
2020-09-29 10:22:47 +00:00
|
|
|
hdy_init ();
|
|
|
|
|
2020-10-28 17:17:44 +00:00
|
|
|
if (!call_audio_init (&error))
|
|
|
|
{
|
|
|
|
g_warning ("Failed to init libcallaudio: %s", error->message);
|
|
|
|
}
|
2021-10-01 16:34:57 +00:00
|
|
|
cui_init (TRUE);
|
2020-10-28 17:17:44 +00:00
|
|
|
|
2018-11-09 16:30:40 +00:00
|
|
|
g_set_prgname (APP_ID);
|
|
|
|
g_set_application_name (_("Calls"));
|
|
|
|
|
2018-11-23 14:34:41 +00:00
|
|
|
g_action_map_add_action_entries (G_ACTION_MAP (application),
|
|
|
|
actions,
|
|
|
|
G_N_ELEMENTS (actions),
|
|
|
|
application);
|
2020-01-28 15:35:02 +00:00
|
|
|
|
2021-09-23 07:32:37 +00:00
|
|
|
g_signal_connect_swapped (calls_manager_get_default (),
|
2021-01-20 15:58:42 +00:00
|
|
|
"notify::state",
|
|
|
|
G_CALLBACK (manager_state_changed_cb),
|
|
|
|
application);
|
|
|
|
|
|
|
|
manager_state_changed_cb (application);
|
|
|
|
|
2021-01-19 15:49:08 +00:00
|
|
|
provider = gtk_css_provider_new ();
|
2021-07-10 02:15:22 +00:00
|
|
|
gtk_css_provider_load_from_resource (provider, "/org/gnome/Calls/style.css");
|
2021-01-19 15:49:08 +00:00
|
|
|
gtk_style_context_add_provider_for_screen (gdk_screen_get_default (),
|
|
|
|
GTK_STYLE_PROVIDER (provider),
|
|
|
|
GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
|
2018-11-23 14:34:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-02-25 09:06:27 +00:00
|
|
|
static int
|
|
|
|
calls_application_command_line (GApplication *application,
|
|
|
|
GApplicationCommandLine *command_line)
|
|
|
|
{
|
|
|
|
CallsApplication *self = CALLS_APPLICATION (application);
|
|
|
|
GVariantDict *options;
|
|
|
|
const char *arg;
|
|
|
|
g_autoptr (GVariant) providers = NULL;
|
|
|
|
g_auto(GStrv) arguments = NULL;
|
|
|
|
gint argc;
|
|
|
|
|
|
|
|
options = g_application_command_line_get_options_dict (command_line);
|
|
|
|
|
|
|
|
providers = g_variant_dict_lookup_value (options, "provider", G_VARIANT_TYPE_STRING_ARRAY);
|
|
|
|
if (providers) {
|
|
|
|
g_action_group_activate_action (G_ACTION_GROUP (application),
|
|
|
|
"set-provider-names",
|
|
|
|
providers);
|
|
|
|
} else {
|
|
|
|
g_action_group_activate_action (G_ACTION_GROUP (application),
|
|
|
|
"set-default-providers",
|
|
|
|
NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (g_variant_dict_contains (options, "daemon"))
|
|
|
|
g_action_group_activate_action (G_ACTION_GROUP (application),
|
|
|
|
"set-daemon", NULL);
|
|
|
|
|
|
|
|
if (g_variant_dict_lookup (options, "dial", "&s", &arg))
|
|
|
|
g_action_group_activate_action (G_ACTION_GROUP (application),
|
|
|
|
"dial", g_variant_new_string (arg));
|
|
|
|
|
|
|
|
arguments = g_application_command_line_get_arguments (command_line, &argc);
|
|
|
|
|
|
|
|
/* Keep only the first URI, if there are many */
|
|
|
|
for (guint i = 0; i < argc; i++)
|
|
|
|
if (g_str_has_prefix (arguments[i], "tel:") ||
|
|
|
|
g_str_has_prefix (arguments[i], "sip:") ||
|
|
|
|
g_str_has_prefix (arguments[i], "sips:")) {
|
|
|
|
g_free (self->uri);
|
|
|
|
self->uri = g_strdup (arguments[i]);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
g_application_activate (application);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2021-10-01 16:34:57 +00:00
|
|
|
static void
|
|
|
|
app_shutdown (GApplication *application)
|
|
|
|
{
|
|
|
|
cui_uninit ();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-01-12 00:27:45 +00:00
|
|
|
static void
|
|
|
|
notify_window_visible_cb (GtkWidget *window,
|
|
|
|
GParamSpec *pspec,
|
|
|
|
CallsApplication *application)
|
|
|
|
{
|
|
|
|
CallsManager *manager = calls_manager_get_default ();
|
|
|
|
|
|
|
|
g_return_if_fail (CALLS_IS_APPLICATION (application));
|
|
|
|
g_return_if_fail (CALLS_IS_CALL_WINDOW (window));
|
|
|
|
|
|
|
|
/* The UI is being closed, hang up active calls */
|
|
|
|
if (!gtk_widget_is_visible (window))
|
|
|
|
calls_manager_hang_up_all_calls (manager);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-08-05 10:25:45 +00:00
|
|
|
static gboolean
|
|
|
|
start_proper (CallsApplication *self)
|
|
|
|
{
|
|
|
|
GtkApplication *gtk_app;
|
|
|
|
|
2021-04-16 17:47:01 +00:00
|
|
|
if (self->main_window) {
|
|
|
|
return TRUE;
|
|
|
|
}
|
2019-08-05 10:25:45 +00:00
|
|
|
|
|
|
|
gtk_app = GTK_APPLICATION (self);
|
|
|
|
|
2020-03-18 11:53:13 +00:00
|
|
|
self->ringer = calls_ringer_new ();
|
2019-08-05 10:25:45 +00:00
|
|
|
g_assert (self->ringer != NULL);
|
|
|
|
|
2020-03-18 12:58:13 +00:00
|
|
|
self->record_store = calls_record_store_new ();
|
2019-08-05 10:25:45 +00:00
|
|
|
g_assert (self->record_store != NULL);
|
|
|
|
|
2020-06-17 11:44:11 +00:00
|
|
|
self->notifier = calls_notifier_new ();
|
2020-05-19 10:36:29 +00:00
|
|
|
g_assert (CALLS_IS_NOTIFIER (self->notifier));
|
|
|
|
|
2019-08-05 10:25:45 +00:00
|
|
|
self->main_window = calls_main_window_new
|
|
|
|
(gtk_app,
|
2020-06-17 11:44:11 +00:00
|
|
|
G_LIST_MODEL (self->record_store));
|
2019-08-05 10:25:45 +00:00
|
|
|
g_assert (self->main_window != NULL);
|
|
|
|
|
2020-03-17 20:50:39 +00:00
|
|
|
self->call_window = calls_call_window_new (gtk_app);
|
2019-08-05 10:25:45 +00:00
|
|
|
g_assert (self->call_window != NULL);
|
|
|
|
|
2021-01-12 00:27:45 +00:00
|
|
|
g_signal_connect (self->call_window,
|
|
|
|
"notify::visible",
|
|
|
|
G_CALLBACK (notify_window_visible_cb),
|
|
|
|
self);
|
|
|
|
|
2019-08-05 10:25:45 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2021-03-09 16:22:12 +00:00
|
|
|
static void
|
|
|
|
open_sip_uri (CallsApplication *self,
|
2021-04-16 17:47:01 +00:00
|
|
|
const char *uri)
|
2021-03-09 16:22:12 +00:00
|
|
|
{
|
2021-04-16 17:47:01 +00:00
|
|
|
char **tokens = NULL;
|
2021-03-09 16:22:12 +00:00
|
|
|
g_assert (uri);
|
|
|
|
|
|
|
|
tokens = g_strsplit (uri, "///", 2);
|
|
|
|
|
|
|
|
if (tokens) {
|
|
|
|
/* Remove "///" from "sip:///user@host" */
|
2021-04-16 17:47:01 +00:00
|
|
|
g_autofree char *dial_string = g_strconcat (tokens[0], tokens[1], NULL);
|
2021-03-09 16:22:12 +00:00
|
|
|
|
|
|
|
calls_main_window_dial (self->main_window, dial_string);
|
|
|
|
|
|
|
|
g_strfreev (tokens);
|
2021-04-16 17:47:01 +00:00
|
|
|
} else {
|
2021-03-09 16:22:12 +00:00
|
|
|
/* Dial the uri as it is */
|
|
|
|
calls_main_window_dial (self->main_window, uri);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-08-05 10:25:45 +00:00
|
|
|
static void
|
|
|
|
open_tel_uri (CallsApplication *self,
|
2021-04-16 17:47:01 +00:00
|
|
|
const char *uri)
|
2019-08-05 10:25:45 +00:00
|
|
|
{
|
2021-09-07 12:03:27 +00:00
|
|
|
const char *number = NULL;
|
2019-08-05 10:25:45 +00:00
|
|
|
|
|
|
|
g_debug ("Opening tel URI `%s'", uri);
|
|
|
|
|
2021-09-07 12:03:27 +00:00
|
|
|
number = &uri[4]; // tel:NUMBER
|
|
|
|
if (!number || number[0] == '\0') {
|
2021-04-16 17:47:01 +00:00
|
|
|
g_autofree char *msg =
|
2021-09-07 12:03:27 +00:00
|
|
|
g_strdup_printf (_("Tried invalid tel URI `%s'"), uri);
|
2021-04-16 17:47:01 +00:00
|
|
|
|
|
|
|
g_signal_emit_by_name (calls_manager_get_default (),
|
|
|
|
"error",
|
|
|
|
msg);
|
2021-09-07 12:03:27 +00:00
|
|
|
g_warning ("Ignoring invalid tel URI `%s'", uri);
|
2021-04-16 17:47:01 +00:00
|
|
|
return;
|
|
|
|
}
|
2019-08-05 10:25:45 +00:00
|
|
|
|
2021-09-07 12:03:27 +00:00
|
|
|
call_number (self, number);
|
2019-08-05 10:25:45 +00:00
|
|
|
}
|
2018-11-23 14:34:41 +00:00
|
|
|
|
2021-02-24 07:23:52 +00:00
|
|
|
static void
|
|
|
|
activate (GApplication *application)
|
|
|
|
{
|
|
|
|
CallsApplication *self = CALLS_APPLICATION (application);
|
|
|
|
gboolean present;
|
|
|
|
|
|
|
|
g_debug ("Activated");
|
|
|
|
|
2021-04-16 17:47:01 +00:00
|
|
|
if (self->main_window) {
|
|
|
|
present = TRUE;
|
|
|
|
} else {
|
|
|
|
gboolean ok = start_proper (self);
|
|
|
|
if (!ok)
|
|
|
|
return;
|
2021-02-24 07:23:52 +00:00
|
|
|
|
2021-04-16 17:47:01 +00:00
|
|
|
present = !self->daemon;
|
|
|
|
}
|
2021-02-24 07:23:52 +00:00
|
|
|
|
2021-04-16 17:47:01 +00:00
|
|
|
if (present || self->uri) {
|
|
|
|
gtk_window_present (GTK_WINDOW (self->main_window));
|
|
|
|
}
|
2021-02-24 07:23:52 +00:00
|
|
|
|
2021-04-16 17:47:01 +00:00
|
|
|
if (self->uri) {
|
2021-03-09 16:22:12 +00:00
|
|
|
if (g_str_has_prefix (self->uri, "tel:"))
|
|
|
|
open_tel_uri (self, self->uri);
|
|
|
|
|
|
|
|
else if (g_str_has_prefix (self->uri, "sip:") ||
|
|
|
|
g_str_has_prefix (self->uri, "sips:"))
|
|
|
|
open_sip_uri (self, self->uri);
|
|
|
|
}
|
2021-02-24 07:23:52 +00:00
|
|
|
|
|
|
|
g_clear_pointer (&self->uri, g_free);
|
|
|
|
}
|
2019-07-22 10:52:46 +00:00
|
|
|
|
2019-08-05 10:25:45 +00:00
|
|
|
static void
|
|
|
|
app_open (GApplication *application,
|
|
|
|
GFile **files,
|
|
|
|
gint n_files,
|
2021-04-16 17:47:01 +00:00
|
|
|
const char *hint)
|
2019-08-05 10:25:45 +00:00
|
|
|
{
|
|
|
|
CallsApplication *self = CALLS_APPLICATION (application);
|
|
|
|
|
|
|
|
g_assert (n_files > 0);
|
|
|
|
|
2021-02-24 07:23:52 +00:00
|
|
|
if (n_files > 1)
|
|
|
|
g_warning ("Calls can handle only one call a time. %u items provided", n_files);
|
2019-08-05 10:25:45 +00:00
|
|
|
|
2021-03-09 16:22:12 +00:00
|
|
|
if (g_file_has_uri_scheme (files[0], "tel") ||
|
|
|
|
g_file_has_uri_scheme (files[0], "sip") ||
|
2021-04-16 17:47:01 +00:00
|
|
|
g_file_has_uri_scheme (files[0], "sips")) {
|
2019-08-05 10:25:45 +00:00
|
|
|
|
2021-04-16 17:47:01 +00:00
|
|
|
g_free (self->uri);
|
|
|
|
self->uri = g_file_get_uri (files[0]);
|
|
|
|
g_debug ("Opening %s", self->uri);
|
2021-01-12 17:24:12 +00:00
|
|
|
|
2021-04-16 17:47:01 +00:00
|
|
|
g_application_activate (application);
|
|
|
|
} else {
|
|
|
|
g_autofree char *msg = NULL;
|
|
|
|
g_autofree char *uri = NULL;
|
2021-01-12 17:24:12 +00:00
|
|
|
|
2021-04-16 17:47:01 +00:00
|
|
|
uri = g_file_get_parse_name (files[0]);
|
|
|
|
g_warning ("Don't know how to"
|
|
|
|
" open file `%s', ignoring",
|
|
|
|
uri);
|
2021-01-12 17:24:12 +00:00
|
|
|
|
2021-04-16 17:47:01 +00:00
|
|
|
msg = g_strdup_printf (_("Don't know how to open `%s'"), uri);
|
|
|
|
|
|
|
|
g_signal_emit_by_name (calls_manager_get_default (),
|
|
|
|
"error", msg);
|
|
|
|
}
|
2018-09-15 10:33:36 +00:00
|
|
|
}
|
|
|
|
|
2018-11-23 14:34:41 +00:00
|
|
|
|
|
|
|
static void
|
2020-03-17 15:29:43 +00:00
|
|
|
finalize (GObject *object)
|
2018-11-23 14:34:41 +00:00
|
|
|
{
|
|
|
|
CallsApplication *self = (CallsApplication *)object;
|
|
|
|
|
2019-08-05 10:25:45 +00:00
|
|
|
g_clear_object (&self->call_window);
|
|
|
|
g_clear_object (&self->main_window);
|
2019-08-01 13:25:53 +00:00
|
|
|
g_clear_object (&self->record_store);
|
2018-11-23 14:34:41 +00:00
|
|
|
g_clear_object (&self->ringer);
|
2020-05-19 10:36:29 +00:00
|
|
|
g_clear_object (&self->notifier);
|
2021-02-24 07:23:52 +00:00
|
|
|
g_free (self->uri);
|
2018-11-23 14:34:41 +00:00
|
|
|
|
2021-01-22 14:02:22 +00:00
|
|
|
G_OBJECT_CLASS (calls_application_parent_class)->finalize (object);
|
2018-11-23 14:34:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-09-15 10:33:36 +00:00
|
|
|
static void
|
|
|
|
calls_application_class_init (CallsApplicationClass *klass)
|
|
|
|
{
|
|
|
|
GApplicationClass *application_class = G_APPLICATION_CLASS (klass);
|
|
|
|
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
|
|
|
|
2018-11-23 14:34:41 +00:00
|
|
|
object_class->finalize = finalize;
|
2018-09-15 10:33:36 +00:00
|
|
|
|
2021-02-25 09:06:27 +00:00
|
|
|
application_class->handle_local_options = calls_application_handle_local_options;
|
2018-09-15 10:33:36 +00:00
|
|
|
application_class->startup = startup;
|
2021-02-25 09:06:27 +00:00
|
|
|
application_class->command_line = calls_application_command_line;
|
2021-10-01 16:34:57 +00:00
|
|
|
application_class->shutdown = app_shutdown;
|
2018-09-15 10:33:36 +00:00
|
|
|
application_class->activate = activate;
|
2019-08-05 10:25:45 +00:00
|
|
|
application_class->open = app_open;
|
2021-04-02 07:52:14 +00:00
|
|
|
application_class->dbus_register = calls_application_dbus_register;
|
|
|
|
application_class->dbus_unregister = calls_application_dbus_unregister;
|
2018-09-15 10:33:36 +00:00
|
|
|
|
|
|
|
g_type_ensure (CALLS_TYPE_ENCRYPTION_INDICATOR);
|
|
|
|
g_type_ensure (CALLS_TYPE_HISTORY_BOX);
|
|
|
|
g_type_ensure (CALLS_TYPE_NEW_CALL_BOX);
|
|
|
|
}
|
|
|
|
|
2018-11-23 14:34:41 +00:00
|
|
|
|
2018-09-15 10:33:36 +00:00
|
|
|
static void
|
|
|
|
calls_application_init (CallsApplication *self)
|
|
|
|
{
|
2018-11-23 14:34:41 +00:00
|
|
|
const GOptionEntry options[] = {
|
|
|
|
{
|
|
|
|
"provider", 'p', G_OPTION_FLAG_NONE,
|
2021-06-09 12:19:27 +00:00
|
|
|
G_OPTION_ARG_STRING_ARRAY, NULL,
|
2021-10-18 15:05:48 +00:00
|
|
|
_("The name of the plugin to use as a call provider"),
|
2018-11-23 14:34:41 +00:00
|
|
|
_("PLUGIN")
|
|
|
|
},
|
2019-08-08 12:51:17 +00:00
|
|
|
{
|
|
|
|
"daemon", 'd', G_OPTION_FLAG_NONE,
|
|
|
|
G_OPTION_ARG_NONE, NULL,
|
|
|
|
_("Whether to present the main window on startup"),
|
|
|
|
NULL
|
|
|
|
},
|
2020-02-17 16:01:43 +00:00
|
|
|
{
|
|
|
|
"dial", 'l', G_OPTION_FLAG_NONE,
|
|
|
|
G_OPTION_ARG_STRING, NULL,
|
2021-09-07 11:49:05 +00:00
|
|
|
_("Dial a telephone number"),
|
2020-02-17 16:01:43 +00:00
|
|
|
_("NUMBER")
|
|
|
|
},
|
2021-04-16 17:57:03 +00:00
|
|
|
{
|
2021-07-30 10:43:30 +00:00
|
|
|
"verbose", 'v', G_OPTION_FLAG_NO_ARG,
|
|
|
|
G_OPTION_ARG_CALLBACK, cmd_verbose_cb,
|
|
|
|
_("Enable verbose debug messages"),
|
|
|
|
NULL
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"version", 0, G_OPTION_FLAG_NONE,
|
2021-04-16 17:57:03 +00:00
|
|
|
G_OPTION_ARG_NONE, NULL,
|
|
|
|
_("Print current version"),
|
|
|
|
NULL
|
|
|
|
},
|
2018-11-23 14:34:41 +00:00
|
|
|
{
|
|
|
|
NULL
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
g_application_add_main_option_entries (G_APPLICATION (self), options);
|
2018-09-15 10:33:36 +00:00
|
|
|
}
|
|
|
|
|
2018-11-23 14:34:41 +00:00
|
|
|
|
2018-09-15 10:33:36 +00:00
|
|
|
CallsApplication *
|
|
|
|
calls_application_new (void)
|
|
|
|
{
|
|
|
|
return g_object_new (CALLS_TYPE_APPLICATION,
|
|
|
|
"application-id", APP_ID,
|
2021-02-25 09:06:27 +00:00
|
|
|
"flags", G_APPLICATION_HANDLES_OPEN | G_APPLICATION_HANDLES_COMMAND_LINE,
|
2019-08-26 12:03:20 +00:00
|
|
|
"register-session", TRUE,
|
2018-09-15 10:33:36 +00:00
|
|
|
NULL);
|
|
|
|
}
|