[calls] ringer: Use CallsUiCallData instead of CallsCall
- From: Evangelos Ribeiro Tzaras <devrtz src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [calls] ringer: Use CallsUiCallData instead of CallsCall
- Date: Tue, 1 Feb 2022 05:50:58 +0000 (UTC)
commit 5b9609c4f7b972c3ee6f5294169e83b0994f4f57
Author: Evangelos Ribeiro Tzaras <devrtz fortysixandtwo eu>
Date: Mon Jan 31 17:18:35 2022 +0100
ringer: Use CallsUiCallData instead of CallsCall
This will allow us to handle pre-ringing better.
src/calls-ringer.c | 44 +++++++++++++++++---------------
src/calls-ui-call-data.c | 48 ++++++++++++++++++++++++++++++++++-
src/calls-ui-call-data.h | 2 ++
tests/test-ringer.c | 65 +++++++++++++++++++++++++++---------------------
4 files changed, 109 insertions(+), 50 deletions(-)
---
diff --git a/src/calls-ringer.c b/src/calls-ringer.c
index cdc65a74..a6255e9b 100644
--- a/src/calls-ringer.c
+++ b/src/calls-ringer.c
@@ -27,6 +27,7 @@
#include "calls-manager.h"
#include "calls-ringer.h"
+#include "calls-ui-call-data.h"
#include <glib/gi18n.h>
#include <glib-object.h>
@@ -285,11 +286,13 @@ restart (CallsRinger *self,
static inline gboolean
-is_ring_state (CallsCallState state)
+is_ring_state (CuiCallState state)
{
+#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
+
switch (state) {
- case CALLS_CALL_STATE_INCOMING:
- case CALLS_CALL_STATE_WAITING:
+ case CUI_CALL_STATE_INCOMING:
+ case CUI_CALL_STATE_WAITING:
return TRUE;
default:
return FALSE;
@@ -298,18 +301,19 @@ is_ring_state (CallsCallState state)
static inline gboolean
-is_active_state (CallsCallState state)
+is_active_state (CuiCallState state)
{
switch (state) {
- case CALLS_CALL_STATE_ACTIVE:
- case CALLS_CALL_STATE_DIALING:
- case CALLS_CALL_STATE_ALERTING:
- case CALLS_CALL_STATE_HELD:
+ case CUI_CALL_STATE_ACTIVE:
+ case CUI_CALL_STATE_CALLING:
+ case CUI_CALL_STATE_ALERTING:
+ case CUI_CALL_STATE_HELD:
return TRUE;
default:
return FALSE;
}
}
+#pragma GCC diagnostic warning "-Wdeprecated-declarations"
static gboolean
@@ -318,9 +322,9 @@ has_active_call (CallsRinger *self)
g_assert (CALLS_IS_RINGER (self));
for (GList *node = self->calls; node != NULL; node = node->next) {
- CallsCall *call = node->data;
+ CallsUiCallData *call = node->data;
- if (is_active_state (calls_call_get_state (call)))
+ if (is_active_state (cui_call_get_state (CUI_CALL (call))))
return TRUE;
}
return FALSE;
@@ -333,10 +337,10 @@ has_incoming_call (CallsRinger *self)
g_assert (CALLS_IS_RINGER (self));
for (GList *node = self->calls; node != NULL; node = node->next) {
- CallsCall *call = node->data;
+ CallsUiCallData *call = node->data;
- if (is_ring_state (calls_call_get_state (call)) &&
- !calls_call_get_silenced (call))
+ if (is_ring_state (cui_call_get_state (CUI_CALL (call))) &&
+ !calls_ui_call_data_get_silenced (call))
return TRUE;
}
return FALSE;
@@ -361,11 +365,11 @@ update_ring (CallsRinger *self)
static void
-call_added_cb (CallsRinger *self,
- CallsCall *call)
+call_added_cb (CallsRinger *self,
+ CallsUiCallData *call)
{
g_assert (CALLS_IS_RINGER (self));
- g_assert (CALLS_IS_CALL (call));
+ g_assert (CALLS_IS_UI_CALL_DATA (call));
self->calls = g_list_append (self->calls, call);
@@ -382,8 +386,8 @@ call_added_cb (CallsRinger *self,
static void
-call_removed_cb (CallsRinger *self,
- CallsCall *call)
+call_removed_cb (CallsRinger *self,
+ CallsUiCallData *call)
{
self->calls = g_list_remove (self->calls, call);
@@ -442,12 +446,12 @@ constructed (GObject *object)
CallsRinger *self = CALLS_RINGER (object);
g_signal_connect_swapped (calls_manager_get_default (),
- "call-add",
+ "ui-call-added",
G_CALLBACK (call_added_cb),
self);
g_signal_connect_swapped (calls_manager_get_default (),
- "call-remove",
+ "ui-call-removed",
G_CALLBACK (call_removed_cb),
self);
diff --git a/src/calls-ui-call-data.c b/src/calls-ui-call-data.c
index 7893b82f..647d0e7f 100644
--- a/src/calls-ui-call-data.c
+++ b/src/calls-ui-call-data.c
@@ -41,6 +41,7 @@ enum {
PROP_CAN_DTMF,
PROP_AVATAR_ICON,
PROP_ACTIVE_TIME,
+ PROP_SILENCED,
PROP_LAST_PROP
};
@@ -64,6 +65,7 @@ struct _CallsUiCallData
guint timer_id;
CuiCallState state;
+ gboolean silenced;
};
static void calls_ui_call_data_cui_call_interface_init (CuiCallInterface *iface);
@@ -412,6 +414,9 @@ calls_ui_call_data_get_property (GObject *object,
case PROP_ACTIVE_TIME:
g_value_set_double (value, self->active_time);
+
+ case PROP_SILENCED:
+ g_value_set_boolean (value, calls_ui_call_data_get_silenced (self));
break;
default:
@@ -476,6 +481,15 @@ calls_ui_call_data_class_init (CallsUiCallDataClass *klass)
g_object_class_install_property (object_class, PROP_PROTOCOL, props[PROP_PROTOCOL]);
+ props[PROP_SILENCED] =
+ g_param_spec_boolean ("silenced",
+ "Silenced",
+ "Whether the call ringing should be silenced",
+ FALSE,
+ G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
+
+ g_object_class_install_property (object_class, PROP_SILENCED, props[PROP_SILENCED]);
+
g_object_class_override_property (object_class, PROP_ID, "id");
props[PROP_ID] = g_object_class_find_property (object_class, "id");
@@ -531,6 +545,39 @@ calls_ui_call_data_get_call (CallsUiCallData *self)
return self->call;
}
+/**
+ * calls_ui_call_data_silence_ring:
+ * @self: a #CallsUiCallData
+ *
+ * Inhibit ringing
+ */
+void
+calls_ui_call_data_silence_ring (CallsUiCallData *self)
+{
+ g_return_if_fail (CALLS_IS_UI_CALL_DATA (self));
+ g_return_if_fail (self->state == CUI_CALL_STATE_INCOMING);
+
+ if (self->silenced)
+ return;
+
+ self->silenced = TRUE;
+ g_object_notify_by_pspec (G_OBJECT (self), props[PROP_SILENCED]);
+}
+
+/**
+ * calls_ui_call_data_get_silenced:
+ * @self: a #CallsUiCallData
+ *
+ * Returns: %TRUE if call has been silenced to not ring, %FALSE otherwise
+ */
+gboolean
+calls_ui_call_data_get_silenced (CallsUiCallData *self)
+{
+ g_return_val_if_fail (CALLS_IS_UI_CALL_DATA (self), FALSE);
+
+ return self->silenced;
+}
+
CuiCallState
calls_call_state_to_cui_call_state (CallsCallState state)
@@ -552,4 +599,3 @@ calls_call_state_to_cui_call_state (CallsCallState state)
return CUI_CALL_STATE_UNKNOWN;
}
}
-
diff --git a/src/calls-ui-call-data.h b/src/calls-ui-call-data.h
index 66499ae0..bf73a4b7 100644
--- a/src/calls-ui-call-data.h
+++ b/src/calls-ui-call-data.h
@@ -37,6 +37,8 @@ G_DECLARE_FINAL_TYPE (CallsUiCallData, calls_ui_call_data, CALLS, UI_CALL_DATA,
CallsUiCallData *calls_ui_call_data_new (CallsCall *call);
CallsCall *calls_ui_call_data_get_call (CallsUiCallData *self);
+void calls_ui_call_data_silence_ring (CallsUiCallData *self);
+gboolean calls_ui_call_data_get_silenced (CallsUiCallData *self);
CuiCallState calls_call_state_to_cui_call_state (CallsCallState state);
G_END_DECLS
diff --git a/tests/test-ringer.c b/tests/test-ringer.c
index 4edc5a3f..6f89eef6 100644
--- a/tests/test-ringer.c
+++ b/tests/test-ringer.c
@@ -9,6 +9,7 @@
#include "calls-manager.h"
#include "calls-ringer.h"
+#include "calls-ui-call-data.h"
#include "mock-call.h"
#include "mock-libfeedback.h"
#include "mock-contacts-provider.h"
@@ -146,33 +147,35 @@ __wrap_calls_contacts_provider_new (CallsSettings *settings)
/* add or remove calls */
static void
-add_call (CallsManager *manager,
- CallsMockCall *call)
+add_call (CallsManager *manager,
+ CallsUiCallData *call)
{
g_assert (CALLS_IS_MANAGER (manager));
- g_assert (CALLS_IS_MOCK_CALL (call));
+ g_assert (CALLS_IS_UI_CALL_DATA (call));
- g_signal_emit_by_name (manager, "call-add", CALLS_CALL (call), NULL);
+ g_signal_emit_by_name (manager, "ui-call-added", call, NULL);
}
static void
-remove_call (CallsManager *manager,
- CallsMockCall *call)
+remove_call (CallsManager *manager,
+ CallsUiCallData *call)
{
g_assert (CALLS_IS_MANAGER (manager));
- g_assert (CALLS_IS_MOCK_CALL (call));
+ g_assert (CALLS_IS_UI_CALL_DATA (call));
- g_signal_emit_by_name (manager, "call-remove", CALLS_CALL (call), NULL);
+ g_signal_emit_by_name (manager, "ui-call-removed", call, NULL);
}
/* TestData setup and tear down */
typedef struct {
- CallsManager *manager;
- CallsRinger *ringer;
- CallsMockCall *call_one;
- CallsMockCall *call_two;
- GMainLoop *loop;
+ CallsManager *manager;
+ CallsRinger *ringer;
+ CallsMockCall *call_one;
+ CallsUiCallData *ui_call_one;
+ CallsMockCall *call_two;
+ CallsUiCallData *ui_call_two;
+ GMainLoop *loop;
} TestData;
@@ -187,7 +190,9 @@ setup_test_data (void **state)
data->manager = calls_manager_get_default ();
data->ringer = calls_ringer_new ();
data->call_one = calls_mock_call_new ();
+ data->ui_call_one = calls_ui_call_data_new (CALLS_CALL (data->call_one));
data->call_two = calls_mock_call_new ();
+ data->ui_call_two = calls_ui_call_data_new (CALLS_CALL (data->call_two));
data->loop = g_main_loop_new (NULL, FALSE);
*state = data;
@@ -202,7 +207,9 @@ tear_down_test_data (void **state)
TestData *data = *state;
g_object_unref (data->call_one);
+ g_object_unref (data->ui_call_one);
g_object_unref (data->call_two);
+ g_object_unref (data->ui_call_two);
g_object_unref (data->ringer);
g_main_loop_unref (data->loop);
@@ -252,12 +259,12 @@ test_ringing_accept_call (void **state)
will_return (__wrap_lfb_event_end_feedback_async, 10);
calls_call_set_state (CALLS_CALL (data->call_one), CALLS_CALL_STATE_INCOMING);
- add_call (data->manager, data->call_one);
+ add_call (data->manager, data->ui_call_one);
/* main loop will quit in callback of notify::ring */
g_main_loop_run (data->loop);
- remove_call (data->manager, data->call_one);
+ remove_call (data->manager, data->ui_call_one);
assert_false (calls_ringer_get_is_ringing (data->ringer));
}
@@ -303,12 +310,12 @@ test_ringing_hang_up_call (void **state)
will_return (__wrap_lfb_event_end_feedback_async, 10);
calls_call_set_state (CALLS_CALL (data->call_one), CALLS_CALL_STATE_INCOMING);
- add_call (data->manager, data->call_one);
+ add_call (data->manager, data->ui_call_one);
/* main loop will quit in callback of notify::ring */
g_main_loop_run (data->loop);
- remove_call (data->manager, data->call_one);
+ remove_call (data->manager, data->ui_call_one);
assert_false (calls_ringer_get_is_ringing (data->ringer));
}
@@ -347,14 +354,14 @@ test_ringing_hang_up_call_ringer_cancelled (void **state)
will_return (__wrap_lfb_event_trigger_feedback_async, 50);
calls_call_set_state (CALLS_CALL (data->call_one), CALLS_CALL_STATE_INCOMING);
- add_call (data->manager, data->call_one);
+ add_call (data->manager, data->ui_call_one);
g_timeout_add (10, G_SOURCE_FUNC (t3_on_ringer_timeout), data);
/* main loop will quit in t3_on_ringer_timeout() */
g_main_loop_run (data->loop);
- remove_call (data->manager, data->call_one);
+ remove_call (data->manager, data->ui_call_one);
assert_false (calls_ringer_get_is_ringing (data->ringer));
}
@@ -370,8 +377,8 @@ t4_on_ringer_call_silence (CallsRinger *ringer,
switch (test_phase++) {
case 0: /* incoming call */
assert_true (calls_ringer_get_is_ringing (ringer));
- calls_call_silence_ring (CALLS_CALL (data->call_one));
- assert_true (calls_call_get_silenced (CALLS_CALL (data->call_one)));
+ calls_ui_call_data_silence_ring (data->ui_call_one);
+ assert_true (calls_ui_call_data_get_silenced (data->ui_call_one));
break;
case 1: /* incoming call hung up */
assert_false (calls_ringer_get_is_ringing (ringer));
@@ -401,12 +408,12 @@ test_ringing_silence_call (void **state)
will_return (__wrap_lfb_event_end_feedback_async, 10);
calls_call_set_state (CALLS_CALL (data->call_one), CALLS_CALL_STATE_INCOMING);
- add_call (data->manager, data->call_one);
+ add_call (data->manager, data->ui_call_one);
/* main loop will quit in callback of notify::ring */
g_main_loop_run (data->loop);
- remove_call (data->manager, data->call_one);
+ remove_call (data->manager, data->ui_call_one);
assert_false (calls_ringer_get_is_ringing (data->ringer));
}
@@ -419,13 +426,13 @@ t5_remove_calls (gpointer user_data)
TestData *data = user_data;
if (test_phase == 0) {
- remove_call (data->manager, data->call_one);
+ remove_call (data->manager, data->ui_call_one);
test_phase++;
return G_SOURCE_CONTINUE;
}
assert_true (calls_ringer_get_is_ringing (data->ringer));
- remove_call (data->manager, data->call_two);
+ remove_call (data->manager, data->ui_call_two);
return G_SOURCE_REMOVE;
}
@@ -442,7 +449,7 @@ t5_on_ringer_multiple_calls (CallsRinger *ringer,
switch (test_phase++) {
case 0: /* add second call, and schedule call removal */
assert_true (calls_ringer_get_is_ringing (ringer));
- add_call (data->manager, data->call_two);
+ add_call (data->manager, data->ui_call_two);
g_timeout_add (25, t5_remove_calls, data);
break;
case 1: /* both calls should be removed now */
@@ -473,7 +480,7 @@ test_ringing_multiple_calls (void **state)
will_return (__wrap_lfb_event_end_feedback_async, 10);
calls_call_set_state (CALLS_CALL (data->call_one), CALLS_CALL_STATE_INCOMING);
- add_call (data->manager, data->call_one);
+ add_call (data->manager, data->ui_call_one);
/* main loop will quit in callback of notify::ring */
g_main_loop_run (data->loop);
@@ -538,9 +545,9 @@ test_ringing_multiple_calls_with_restart (void **state)
will_return_always (__wrap_lfb_event_end_feedback_async, 10);
calls_call_set_state (CALLS_CALL (data->call_one), CALLS_CALL_STATE_INCOMING);
- add_call (data->manager, data->call_one);
+ add_call (data->manager, data->ui_call_one);
calls_call_set_state (CALLS_CALL (data->call_two), CALLS_CALL_STATE_INCOMING);
- add_call (data->manager, data->call_two);
+ add_call (data->manager, data->ui_call_two);
/* main loop will quit in callback of notify::ring */
g_main_loop_run (data->loop);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]