2018-11-09 16:30:40 +00:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2018 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: Bob Ham <bob.ham@puri.sm>
|
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: GPL-3.0-or-later
|
|
|
|
*
|
|
|
|
*/
|
2021-06-18 08:55:47 +00:00
|
|
|
#define G_LOG_DOMAIN "CallsRinger"
|
2018-11-09 16:30:40 +00:00
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
2022-01-31 16:01:50 +00:00
|
|
|
#include "calls-manager.h"
|
|
|
|
#include "calls-ringer.h"
|
2022-01-31 16:18:35 +00:00
|
|
|
#include "calls-ui-call-data.h"
|
2022-01-31 16:01:50 +00:00
|
|
|
|
2022-09-13 10:25:15 +00:00
|
|
|
#include "enum-types.h"
|
|
|
|
|
2018-11-09 16:30:40 +00:00
|
|
|
#include <glib/gi18n.h>
|
|
|
|
#include <glib-object.h>
|
|
|
|
|
2020-05-20 14:14:23 +00:00
|
|
|
#define LIBFEEDBACK_USE_UNSTABLE_API
|
|
|
|
#include <libfeedback.h>
|
|
|
|
|
2022-04-24 10:24:55 +00:00
|
|
|
|
2022-11-02 17:41:21 +00:00
|
|
|
/* cancel lfb operations after reaching the timeout */
|
|
|
|
#define LFB_TIMEOUT_MS 1000
|
|
|
|
|
|
|
|
|
2021-10-25 14:58:40 +00:00
|
|
|
enum {
|
|
|
|
PROP_0,
|
2022-09-13 10:25:15 +00:00
|
|
|
PROP_RING_STATE,
|
2021-10-25 14:58:40 +00:00
|
|
|
PROP_LAST_PROP
|
|
|
|
};
|
|
|
|
static GParamSpec *props[PROP_LAST_PROP];
|
|
|
|
|
|
|
|
|
2021-10-14 08:38:30 +00:00
|
|
|
struct _CallsRinger {
|
2022-04-24 10:24:55 +00:00
|
|
|
GObject parent_instance;
|
2018-11-09 16:30:40 +00:00
|
|
|
|
2022-04-24 10:24:55 +00:00
|
|
|
GList *calls;
|
2022-09-13 10:25:15 +00:00
|
|
|
LfbEvent *ringing_event;
|
|
|
|
LfbEvent *ringing_soft_event;
|
|
|
|
|
|
|
|
GCancellable *cancel;
|
|
|
|
|
2021-10-25 14:58:40 +00:00
|
|
|
CallsRingState state;
|
2022-09-13 10:25:15 +00:00
|
|
|
CallsRingState target_state;
|
2021-11-26 07:40:11 +00:00
|
|
|
|
2022-09-13 10:25:15 +00:00
|
|
|
gboolean freeze_state_notify;
|
2022-11-02 17:41:21 +00:00
|
|
|
guint request_timeout_id;
|
2018-11-09 16:30:40 +00:00
|
|
|
};
|
|
|
|
|
2022-04-24 10:24:55 +00:00
|
|
|
|
|
|
|
G_DEFINE_TYPE (CallsRinger, calls_ringer, G_TYPE_OBJECT)
|
|
|
|
|
2018-11-09 16:30:40 +00:00
|
|
|
|
2022-09-13 10:25:15 +00:00
|
|
|
static void target_state_step (CallsRinger *self);
|
|
|
|
|
|
|
|
|
2021-10-26 22:14:10 +00:00
|
|
|
static const char *
|
|
|
|
ring_state_to_string (CallsRingState state)
|
|
|
|
{
|
2022-09-13 10:25:15 +00:00
|
|
|
g_autoptr (GEnumClass) enum_class = NULL;
|
|
|
|
GEnumValue *enum_val;
|
|
|
|
|
|
|
|
enum_class = g_type_class_ref (CALLS_TYPE_RING_STATE);
|
|
|
|
enum_val = g_enum_get_value (enum_class, state);
|
|
|
|
|
|
|
|
return enum_val ? enum_val->value_nick : "invalid-state";
|
2021-10-26 22:14:10 +00:00
|
|
|
}
|
2021-10-25 14:58:40 +00:00
|
|
|
|
2022-04-24 10:24:55 +00:00
|
|
|
|
2021-10-25 14:58:40 +00:00
|
|
|
static void
|
2022-09-13 10:25:15 +00:00
|
|
|
set_ring_state (CallsRinger *self,
|
|
|
|
CallsRingState state)
|
2021-10-25 14:58:40 +00:00
|
|
|
{
|
2022-09-13 10:25:15 +00:00
|
|
|
g_assert (CALLS_IS_RINGER (self));
|
|
|
|
g_assert (state >= CALLS_RING_STATE_INACTIVE && state <= CALLS_RING_STATE_ERROR);
|
|
|
|
|
2022-11-02 17:41:21 +00:00
|
|
|
g_clear_handle_id (&self->request_timeout_id, g_source_remove);
|
|
|
|
|
2021-10-25 14:58:40 +00:00
|
|
|
if (self->state == state)
|
|
|
|
return;
|
|
|
|
|
2022-09-13 10:25:15 +00:00
|
|
|
g_debug ("Setting ring state to '%s'", ring_state_to_string (state));
|
2021-10-25 14:58:40 +00:00
|
|
|
self->state = state;
|
|
|
|
|
2022-09-13 10:25:15 +00:00
|
|
|
if (state == self->target_state)
|
|
|
|
self->freeze_state_notify = FALSE;
|
|
|
|
else
|
|
|
|
target_state_step (self);
|
2021-10-26 22:14:10 +00:00
|
|
|
|
2022-09-13 10:25:15 +00:00
|
|
|
if (!self->freeze_state_notify)
|
|
|
|
g_object_notify_by_pspec (G_OBJECT (self), props[PROP_RING_STATE]);
|
2021-10-25 14:58:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-11-09 16:30:40 +00:00
|
|
|
static void
|
2020-05-20 14:14:23 +00:00
|
|
|
on_event_triggered (LfbEvent *event,
|
|
|
|
GAsyncResult *res,
|
|
|
|
CallsRinger *self)
|
2018-11-09 16:30:40 +00:00
|
|
|
{
|
2022-04-24 10:24:55 +00:00
|
|
|
g_autoptr (GError) err = NULL;
|
2022-09-13 10:25:15 +00:00
|
|
|
CallsRingState state;
|
|
|
|
gboolean ok;
|
2022-04-24 10:24:55 +00:00
|
|
|
|
|
|
|
g_return_if_fail (LFB_IS_EVENT (event));
|
2018-11-09 16:30:40 +00:00
|
|
|
|
2022-09-13 10:25:15 +00:00
|
|
|
ok = lfb_event_trigger_feedback_finish (event, res, &err);
|
|
|
|
g_debug ("Feedback '%s' triggered %ssuccessfully",
|
|
|
|
lfb_event_get_event (event),
|
|
|
|
ok ? "" : "un");
|
2021-11-26 06:42:40 +00:00
|
|
|
|
2022-09-13 10:25:15 +00:00
|
|
|
if (!CALLS_IS_RINGER (self)) {
|
|
|
|
g_warning ("Event feedback triggered, but ringer is gone");
|
|
|
|
return;
|
|
|
|
}
|
2021-10-28 14:43:42 +00:00
|
|
|
|
2022-09-13 10:25:15 +00:00
|
|
|
if (!ok) {
|
|
|
|
if (g_error_matches (err, G_IO_ERROR, G_IO_ERROR_CANCELLED))
|
|
|
|
g_debug ("Feedback has been cancelled");
|
|
|
|
else
|
|
|
|
g_warning ("Failed to trigger feedback for '%s': %s",
|
|
|
|
lfb_event_get_event (event), err->message);
|
2021-11-26 06:42:40 +00:00
|
|
|
|
2022-09-13 10:25:15 +00:00
|
|
|
set_ring_state (self, CALLS_RING_STATE_ERROR);
|
2021-10-25 14:58:40 +00:00
|
|
|
return;
|
2021-11-26 06:42:40 +00:00
|
|
|
}
|
2018-11-09 16:30:40 +00:00
|
|
|
|
2021-10-25 14:58:40 +00:00
|
|
|
|
2022-09-13 10:25:15 +00:00
|
|
|
if (event == self->ringing_event)
|
|
|
|
state = CALLS_RING_STATE_RINGING;
|
|
|
|
else
|
|
|
|
state = CALLS_RING_STATE_RINGING_SOFT;
|
|
|
|
|
|
|
|
set_ring_state (self, state);
|
2018-11-09 16:30:40 +00:00
|
|
|
}
|
|
|
|
|
2021-10-14 09:41:18 +00:00
|
|
|
|
2018-11-09 16:30:40 +00:00
|
|
|
static void
|
2020-05-20 14:14:23 +00:00
|
|
|
on_event_feedback_ended (LfbEvent *event,
|
|
|
|
GAsyncResult *res,
|
|
|
|
CallsRinger *self)
|
2018-11-09 16:30:40 +00:00
|
|
|
{
|
2022-04-24 10:24:55 +00:00
|
|
|
g_autoptr (GError) err = NULL;
|
2022-09-13 10:25:15 +00:00
|
|
|
gboolean ok;
|
2021-10-14 08:38:30 +00:00
|
|
|
|
2022-09-13 10:25:15 +00:00
|
|
|
g_assert (LFB_IS_EVENT (event));
|
2020-05-20 14:14:23 +00:00
|
|
|
|
2022-09-13 10:25:15 +00:00
|
|
|
ok = lfb_event_end_feedback_finish (event, res, &err);
|
|
|
|
g_debug ("Ended feedback '%s' %ssucessfully",
|
|
|
|
lfb_event_get_event (event),
|
|
|
|
ok ? "" : "un");
|
2021-10-26 22:14:10 +00:00
|
|
|
|
2022-09-13 10:25:15 +00:00
|
|
|
if (!CALLS_IS_RINGER (self)) {
|
|
|
|
g_warning ("Event feedback ended, but ringer is gone");
|
|
|
|
return;
|
|
|
|
}
|
2021-10-25 14:58:40 +00:00
|
|
|
|
2022-09-13 10:25:15 +00:00
|
|
|
if (!ok) {
|
|
|
|
if (g_error_matches (err, G_IO_ERROR, G_IO_ERROR_CANCELLED))
|
|
|
|
g_debug ("Ending feedback has been cancelled");
|
|
|
|
else
|
|
|
|
g_warning ("Failed to end feedback for '%s': %s",
|
|
|
|
lfb_event_get_event (event), err->message);
|
2021-10-25 14:58:40 +00:00
|
|
|
|
2022-09-13 10:25:15 +00:00
|
|
|
set_ring_state (self, CALLS_RING_STATE_ERROR);
|
|
|
|
}
|
2018-11-09 16:30:40 +00:00
|
|
|
}
|
|
|
|
|
2021-10-14 09:41:18 +00:00
|
|
|
|
2018-11-09 16:30:40 +00:00
|
|
|
static void
|
2021-10-14 08:38:30 +00:00
|
|
|
on_feedback_ended (LfbEvent *event,
|
2020-05-20 14:14:23 +00:00
|
|
|
CallsRinger *self)
|
2018-11-09 16:30:40 +00:00
|
|
|
{
|
2022-09-13 10:25:15 +00:00
|
|
|
g_assert (LFB_IS_EVENT (event));
|
2018-11-09 16:30:40 +00:00
|
|
|
|
2022-09-13 10:25:15 +00:00
|
|
|
g_debug ("Feedback ended");
|
2021-10-14 09:41:18 +00:00
|
|
|
|
2022-09-13 10:25:15 +00:00
|
|
|
if (!CALLS_IS_RINGER (self)) {
|
|
|
|
g_warning ("Feedback stopped, but ringer is gone");
|
2021-10-25 14:58:40 +00:00
|
|
|
return;
|
|
|
|
}
|
2018-11-09 16:30:40 +00:00
|
|
|
|
2022-09-13 10:25:15 +00:00
|
|
|
set_ring_state (self, CALLS_RING_STATE_INACTIVE);
|
|
|
|
}
|
2021-11-26 06:42:40 +00:00
|
|
|
|
|
|
|
|
2022-11-02 17:41:21 +00:00
|
|
|
static gboolean
|
|
|
|
request_timed_out (CallsRinger *self)
|
|
|
|
{
|
|
|
|
if (!CALLS_IS_RINGER (self))
|
|
|
|
return G_SOURCE_REMOVE;
|
|
|
|
|
|
|
|
g_debug ("Request '%s' timed out, cancelling..",
|
|
|
|
ring_state_to_string (self->target_state));
|
|
|
|
|
|
|
|
g_cancellable_cancel (self->cancel);
|
|
|
|
|
|
|
|
set_ring_state (self, CALLS_RING_STATE_ERROR);
|
|
|
|
|
|
|
|
return G_SOURCE_REMOVE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-09-13 10:25:15 +00:00
|
|
|
static LfbEvent *
|
|
|
|
get_event_for_state (CallsRinger *self,
|
|
|
|
CallsRingState state)
|
2021-11-26 06:42:40 +00:00
|
|
|
{
|
2022-09-13 10:25:15 +00:00
|
|
|
switch (state) {
|
|
|
|
case CALLS_RING_STATE_RINGING:
|
|
|
|
return self->ringing_event;
|
|
|
|
case CALLS_RING_STATE_RINGING_SOFT:
|
|
|
|
return self->ringing_soft_event;
|
|
|
|
default:
|
|
|
|
g_assert_not_reached ();
|
|
|
|
}
|
|
|
|
}
|
2021-11-26 06:42:40 +00:00
|
|
|
|
|
|
|
|
2022-09-13 10:25:15 +00:00
|
|
|
static void
|
|
|
|
target_state_step (CallsRinger *self)
|
|
|
|
{
|
|
|
|
LfbEvent *event;
|
2021-11-26 06:42:40 +00:00
|
|
|
|
2022-09-13 10:25:15 +00:00
|
|
|
g_assert (CALLS_IS_RINGER (self));
|
2021-11-26 06:42:40 +00:00
|
|
|
|
2022-09-13 10:25:15 +00:00
|
|
|
if (self->state == self->target_state ||
|
|
|
|
self->state == CALLS_RING_STATE_ERROR)
|
|
|
|
return;
|
2021-11-26 06:42:40 +00:00
|
|
|
|
2022-09-13 10:25:15 +00:00
|
|
|
g_clear_object (&self->cancel);
|
|
|
|
self->cancel = g_cancellable_new ();
|
2021-11-26 06:42:40 +00:00
|
|
|
|
2022-09-13 10:25:15 +00:00
|
|
|
if (self->state == CALLS_RING_STATE_INACTIVE) {
|
|
|
|
event = get_event_for_state (self, self->target_state);
|
2021-11-26 06:42:40 +00:00
|
|
|
|
2022-09-13 10:25:15 +00:00
|
|
|
lfb_event_trigger_feedback_async (event,
|
|
|
|
self->cancel,
|
|
|
|
(GAsyncReadyCallback) on_event_triggered,
|
|
|
|
self);
|
|
|
|
} else {
|
|
|
|
gboolean needs_restart =
|
|
|
|
self->target_state == CALLS_RING_STATE_RINGING ||
|
|
|
|
self->target_state == CALLS_RING_STATE_RINGING_SOFT;
|
2021-11-26 06:42:40 +00:00
|
|
|
|
2022-09-13 10:25:15 +00:00
|
|
|
if (needs_restart)
|
|
|
|
self->freeze_state_notify = TRUE;
|
2021-11-26 06:42:40 +00:00
|
|
|
|
2022-09-13 10:25:15 +00:00
|
|
|
event = get_event_for_state (self, self->state);
|
2021-11-26 06:42:40 +00:00
|
|
|
|
2022-09-13 10:25:15 +00:00
|
|
|
lfb_event_end_feedback_async (event,
|
|
|
|
self->cancel,
|
|
|
|
(GAsyncReadyCallback) on_event_feedback_ended,
|
|
|
|
self);
|
|
|
|
}
|
2022-11-02 17:41:21 +00:00
|
|
|
|
|
|
|
self->request_timeout_id =
|
|
|
|
g_timeout_add (LFB_TIMEOUT_MS, G_SOURCE_FUNC (request_timed_out), self);
|
2021-11-26 06:42:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
2022-09-13 10:25:15 +00:00
|
|
|
set_target_state (CallsRinger *self,
|
|
|
|
CallsRingState state)
|
2021-11-26 06:42:40 +00:00
|
|
|
{
|
2022-09-13 10:25:15 +00:00
|
|
|
g_assert (CALLS_IS_RINGER (self));
|
|
|
|
g_assert (state >= CALLS_RING_STATE_INACTIVE &&
|
|
|
|
state <= CALLS_RING_STATE_RINGING_SOFT);
|
2021-11-26 06:42:40 +00:00
|
|
|
|
2022-09-13 10:25:15 +00:00
|
|
|
if (self->target_state == state)
|
|
|
|
return;
|
2021-11-26 06:42:40 +00:00
|
|
|
|
2022-09-13 10:25:15 +00:00
|
|
|
self->target_state = state;
|
2021-11-26 06:42:40 +00:00
|
|
|
|
2022-09-13 10:25:15 +00:00
|
|
|
target_state_step (self);
|
2021-11-26 06:42:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-10-14 09:41:18 +00:00
|
|
|
static inline gboolean
|
2022-01-31 16:18:35 +00:00
|
|
|
is_ring_state (CuiCallState state)
|
2018-11-09 16:30:40 +00:00
|
|
|
{
|
2022-09-12 17:47:25 +00:00
|
|
|
return state == CUI_CALL_STATE_INCOMING;
|
2018-11-09 16:30:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static inline gboolean
|
2022-01-31 16:18:35 +00:00
|
|
|
is_active_state (CuiCallState state)
|
2018-11-09 16:30:40 +00:00
|
|
|
{
|
2021-10-14 08:38:30 +00:00
|
|
|
switch (state) {
|
2022-01-31 16:18:35 +00:00
|
|
|
case CUI_CALL_STATE_ACTIVE:
|
|
|
|
case CUI_CALL_STATE_CALLING:
|
|
|
|
case CUI_CALL_STATE_HELD:
|
2021-10-14 08:38:30 +00:00
|
|
|
return TRUE;
|
|
|
|
default:
|
|
|
|
return FALSE;
|
|
|
|
}
|
2018-11-09 16:30:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-10-14 09:41:18 +00:00
|
|
|
static gboolean
|
2022-09-13 10:25:15 +00:00
|
|
|
have_active_call (CallsRinger *self)
|
2018-11-09 16:30:40 +00:00
|
|
|
{
|
2021-10-14 09:41:18 +00:00
|
|
|
g_assert (CALLS_IS_RINGER (self));
|
2018-11-09 16:30:40 +00:00
|
|
|
|
2021-10-14 09:41:18 +00:00
|
|
|
for (GList *node = self->calls; node != NULL; node = node->next) {
|
2022-01-31 16:18:35 +00:00
|
|
|
CallsUiCallData *call = node->data;
|
2018-11-09 16:30:40 +00:00
|
|
|
|
2022-01-31 16:18:35 +00:00
|
|
|
if (is_active_state (cui_call_get_state (CUI_CALL (call))))
|
2021-10-14 09:41:18 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
return FALSE;
|
|
|
|
}
|
2018-11-09 16:30:40 +00:00
|
|
|
|
|
|
|
|
2021-10-14 09:41:18 +00:00
|
|
|
static gboolean
|
2022-09-13 10:25:15 +00:00
|
|
|
have_incoming_call (CallsRinger *self)
|
2021-10-14 09:41:18 +00:00
|
|
|
{
|
|
|
|
g_assert (CALLS_IS_RINGER (self));
|
|
|
|
|
|
|
|
for (GList *node = self->calls; node != NULL; node = node->next) {
|
2022-01-31 16:18:35 +00:00
|
|
|
CallsUiCallData *call = node->data;
|
2021-10-14 09:41:18 +00:00
|
|
|
|
2022-01-31 16:18:35 +00:00
|
|
|
if (is_ring_state (cui_call_get_state (CUI_CALL (call))) &&
|
2022-02-01 07:25:14 +00:00
|
|
|
!calls_ui_call_data_get_silenced (call) &&
|
|
|
|
calls_ui_call_data_get_ui_active (call))
|
2021-10-14 09:41:18 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
return FALSE;
|
2018-11-09 16:30:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
2021-10-14 09:41:18 +00:00
|
|
|
update_ring (CallsRinger *self)
|
2018-11-09 16:30:40 +00:00
|
|
|
{
|
2022-09-13 10:25:15 +00:00
|
|
|
CallsRingState target_state;
|
|
|
|
|
2021-10-14 09:41:18 +00:00
|
|
|
g_assert (CALLS_IS_RINGER (self));
|
2021-03-12 17:21:41 +00:00
|
|
|
|
2022-09-13 10:25:15 +00:00
|
|
|
if (self->state == CALLS_RING_STATE_ERROR) {
|
|
|
|
g_debug ("Can't ring because we're in an error state");
|
2021-10-14 09:41:18 +00:00
|
|
|
return;
|
|
|
|
}
|
2018-11-09 16:30:40 +00:00
|
|
|
|
2022-09-13 10:25:15 +00:00
|
|
|
if (have_incoming_call (self))
|
|
|
|
target_state = !have_active_call (self) ? CALLS_RING_STATE_RINGING : CALLS_RING_STATE_RINGING_SOFT;
|
2021-10-14 09:41:18 +00:00
|
|
|
else
|
2022-09-13 10:25:15 +00:00
|
|
|
target_state = CALLS_RING_STATE_INACTIVE;
|
|
|
|
|
|
|
|
set_target_state (self, target_state);
|
2018-11-09 16:30:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
2022-01-31 16:18:35 +00:00
|
|
|
call_added_cb (CallsRinger *self,
|
|
|
|
CallsUiCallData *call)
|
2018-11-09 16:30:40 +00:00
|
|
|
{
|
2021-10-14 09:41:18 +00:00
|
|
|
g_assert (CALLS_IS_RINGER (self));
|
2022-01-31 16:18:35 +00:00
|
|
|
g_assert (CALLS_IS_UI_CALL_DATA (call));
|
2021-10-14 09:41:18 +00:00
|
|
|
|
|
|
|
self->calls = g_list_append (self->calls, call);
|
2020-03-18 11:53:13 +00:00
|
|
|
|
2022-02-01 07:25:14 +00:00
|
|
|
g_object_connect (call,
|
|
|
|
"swapped-signal::notify::state", G_CALLBACK (update_ring), self,
|
|
|
|
"swapped-signal::notify::silenced", G_CALLBACK (update_ring), self,
|
|
|
|
"swapped-signal::notify::ui-active", G_CALLBACK (update_ring), self,
|
|
|
|
NULL);
|
|
|
|
|
2021-10-14 09:41:18 +00:00
|
|
|
update_ring (self);
|
2018-11-09 16:30:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
2022-01-31 16:18:35 +00:00
|
|
|
call_removed_cb (CallsRinger *self,
|
|
|
|
CallsUiCallData *call)
|
2018-11-09 16:30:40 +00:00
|
|
|
{
|
2021-10-14 09:41:18 +00:00
|
|
|
self->calls = g_list_remove (self->calls, call);
|
2018-11-09 16:30:40 +00:00
|
|
|
|
2020-03-18 11:53:13 +00:00
|
|
|
g_signal_handlers_disconnect_by_data (call, self);
|
2021-10-14 09:41:18 +00:00
|
|
|
|
|
|
|
update_ring (self);
|
2018-11-09 16:30:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
2020-03-18 11:53:13 +00:00
|
|
|
calls_ringer_init (CallsRinger *self)
|
2018-11-09 16:30:40 +00:00
|
|
|
{
|
2021-02-10 23:38:10 +00:00
|
|
|
g_autoptr (GError) err = NULL;
|
2020-05-20 14:14:23 +00:00
|
|
|
|
2021-10-14 08:38:30 +00:00
|
|
|
if (lfb_init (APP_ID, &err)) {
|
2022-09-13 10:25:15 +00:00
|
|
|
self->ringing_event = lfb_event_new ("phone-incoming-call");
|
2021-10-14 08:38:30 +00:00
|
|
|
/* Let feedbackd do the loop */
|
2022-09-13 10:25:15 +00:00
|
|
|
lfb_event_set_timeout (self->ringing_event, 0);
|
|
|
|
g_signal_connect (self->ringing_event,
|
|
|
|
"feedback-ended",
|
|
|
|
G_CALLBACK (on_feedback_ended),
|
|
|
|
self);
|
|
|
|
|
|
|
|
/* FIXME change event once it's available in feedbackd,
|
|
|
|
* see https://source.puri.sm/Librem5/feedbackd/-/issues/37
|
|
|
|
*/
|
|
|
|
self->ringing_soft_event = lfb_event_new ("phone-incoming-call");
|
|
|
|
lfb_event_set_timeout (self->ringing_soft_event, 15);
|
|
|
|
lfb_event_set_feedback_profile (self->ringing_soft_event, "quiet");
|
|
|
|
g_signal_connect (self->ringing_soft_event,
|
2021-10-14 08:38:30 +00:00
|
|
|
"feedback-ended",
|
|
|
|
G_CALLBACK (on_feedback_ended),
|
|
|
|
self);
|
|
|
|
} else {
|
|
|
|
g_warning ("Failed to init libfeedback: %s", err->message);
|
2022-09-13 10:25:15 +00:00
|
|
|
set_ring_state (self, CALLS_RING_STATE_ERROR);
|
2021-10-14 08:38:30 +00:00
|
|
|
}
|
2018-11-09 16:30:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-10-25 14:58:40 +00:00
|
|
|
static void
|
|
|
|
get_property (GObject *object,
|
|
|
|
guint property_id,
|
|
|
|
GValue *value,
|
|
|
|
GParamSpec *pspec)
|
|
|
|
{
|
|
|
|
switch (property_id) {
|
2022-09-13 10:25:15 +00:00
|
|
|
case PROP_RING_STATE:
|
|
|
|
g_value_set_enum (value, calls_ringer_get_state (CALLS_RINGER (object)));
|
2021-11-26 07:40:11 +00:00
|
|
|
break;
|
|
|
|
|
2021-10-25 14:58:40 +00:00
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-11-09 16:30:40 +00:00
|
|
|
static void
|
|
|
|
constructed (GObject *object)
|
|
|
|
{
|
2020-03-18 11:53:13 +00:00
|
|
|
g_autoptr (GList) calls = NULL;
|
|
|
|
GList *c;
|
2018-11-09 16:30:40 +00:00
|
|
|
CallsRinger *self = CALLS_RINGER (object);
|
|
|
|
|
2020-03-18 11:53:13 +00:00
|
|
|
g_signal_connect_swapped (calls_manager_get_default (),
|
2022-01-31 16:18:35 +00:00
|
|
|
"ui-call-added",
|
2020-03-18 11:53:13 +00:00
|
|
|
G_CALLBACK (call_added_cb),
|
|
|
|
self);
|
2018-11-09 16:30:40 +00:00
|
|
|
|
2020-03-18 11:53:13 +00:00
|
|
|
g_signal_connect_swapped (calls_manager_get_default (),
|
2022-01-31 16:18:35 +00:00
|
|
|
"ui-call-removed",
|
2020-03-18 11:53:13 +00:00
|
|
|
G_CALLBACK (call_removed_cb),
|
|
|
|
self);
|
2018-11-09 16:30:40 +00:00
|
|
|
|
2020-03-18 11:53:13 +00:00
|
|
|
calls = calls_manager_get_calls (calls_manager_get_default ());
|
|
|
|
for (c = calls; c != NULL; c = c->next) {
|
|
|
|
call_added_cb (self, c->data);
|
|
|
|
}
|
2018-11-09 16:30:40 +00:00
|
|
|
|
2020-03-18 11:53:13 +00:00
|
|
|
G_OBJECT_CLASS (calls_ringer_parent_class)->constructed (object);
|
2018-11-09 16:30:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-09-23 14:22:31 +00:00
|
|
|
static void
|
2020-05-20 14:14:23 +00:00
|
|
|
dispose (GObject *object)
|
2019-09-23 14:22:31 +00:00
|
|
|
{
|
|
|
|
CallsRinger *self = CALLS_RINGER (object);
|
|
|
|
|
2021-10-26 12:43:59 +00:00
|
|
|
g_signal_handlers_disconnect_by_data (calls_manager_get_default (), self);
|
2019-09-23 14:22:31 +00:00
|
|
|
|
2022-11-02 17:41:21 +00:00
|
|
|
g_clear_handle_id (&self->request_timeout_id, g_source_remove);
|
|
|
|
|
2022-09-13 10:25:15 +00:00
|
|
|
g_cancellable_cancel (self->cancel);
|
|
|
|
g_clear_object (&self->cancel);
|
2022-08-18 19:12:11 +00:00
|
|
|
|
2020-05-20 14:14:23 +00:00
|
|
|
G_OBJECT_CLASS (calls_ringer_parent_class)->dispose (object);
|
2019-09-23 14:22:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-08-18 18:57:46 +00:00
|
|
|
static void
|
|
|
|
finalize (GObject *object)
|
|
|
|
{
|
|
|
|
CallsRinger *self = CALLS_RINGER (object);
|
|
|
|
|
2022-09-13 10:25:15 +00:00
|
|
|
if (lfb_is_initted ())
|
2022-08-18 18:57:46 +00:00
|
|
|
lfb_uninit ();
|
|
|
|
|
2022-09-13 10:25:15 +00:00
|
|
|
g_clear_object (&self->ringing_event);
|
|
|
|
g_clear_object (&self->ringing_soft_event);
|
2022-08-18 18:57:46 +00:00
|
|
|
|
|
|
|
G_OBJECT_CLASS (calls_ringer_parent_class)->finalize (object);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-11-09 16:30:40 +00:00
|
|
|
static void
|
|
|
|
calls_ringer_class_init (CallsRingerClass *klass)
|
|
|
|
{
|
|
|
|
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
|
|
|
|
|
|
|
object_class->constructed = constructed;
|
2020-05-20 14:14:23 +00:00
|
|
|
object_class->dispose = dispose;
|
2022-08-18 18:57:46 +00:00
|
|
|
object_class->finalize = finalize;
|
2021-10-25 14:58:40 +00:00
|
|
|
object_class->get_property = get_property;
|
|
|
|
|
2022-09-13 10:25:15 +00:00
|
|
|
props[PROP_RING_STATE] =
|
|
|
|
g_param_spec_enum ("state",
|
|
|
|
"",
|
|
|
|
"",
|
|
|
|
CALLS_TYPE_RING_STATE,
|
|
|
|
CALLS_RING_STATE_INACTIVE,
|
|
|
|
G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
|
2021-11-26 07:40:11 +00:00
|
|
|
|
2021-10-25 14:58:40 +00:00
|
|
|
g_object_class_install_properties (object_class,
|
|
|
|
PROP_LAST_PROP,
|
|
|
|
props);
|
2018-11-09 16:30:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
CallsRinger *
|
2020-03-18 11:53:13 +00:00
|
|
|
calls_ringer_new (void)
|
2018-11-09 16:30:40 +00:00
|
|
|
{
|
2020-03-18 11:53:13 +00:00
|
|
|
return g_object_new (CALLS_TYPE_RINGER, NULL);
|
2018-11-09 16:30:40 +00:00
|
|
|
}
|
2021-10-25 14:58:40 +00:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
2022-09-13 10:25:15 +00:00
|
|
|
* calls_ringer_get_state
|
2021-11-26 07:40:11 +00:00
|
|
|
* @self: A #CallsRinger
|
|
|
|
*
|
2022-09-13 10:25:15 +00:00
|
|
|
* Returns: The #CallsRingerState
|
2021-11-26 07:40:11 +00:00
|
|
|
*/
|
2022-09-13 10:25:15 +00:00
|
|
|
CallsRingState
|
|
|
|
calls_ringer_get_state (CallsRinger *self)
|
2021-11-26 07:40:11 +00:00
|
|
|
{
|
2022-09-13 10:25:15 +00:00
|
|
|
g_return_val_if_fail (CALLS_IS_RINGER (self), CALLS_RING_STATE_INACTIVE);
|
2021-11-26 07:40:11 +00:00
|
|
|
|
2022-09-13 10:25:15 +00:00
|
|
|
return self->state;
|
2021-11-26 07:40:11 +00:00
|
|
|
}
|