1
0
Fork 0
mirror of https://gitlab.gnome.org/GNOME/calls.git synced 2024-12-14 00:17:35 +00:00

ringer: codestyle

This commit is contained in:
Evangelos Ribeiro Tzaras 2021-10-14 10:38:30 +02:00
parent f206b7d257
commit 17a2c94387

View file

@ -34,8 +34,7 @@
#include <libfeedback.h> #include <libfeedback.h>
struct _CallsRinger struct _CallsRinger {
{
GObject parent_instance; GObject parent_instance;
/* call_count keeps track of total ongoing calls. /* call_count keeps track of total ongoing calls.
@ -59,14 +58,11 @@ on_event_triggered (LfbEvent *event,
g_return_if_fail (CALLS_IS_RINGER (self)); g_return_if_fail (CALLS_IS_RINGER (self));
if (lfb_event_trigger_feedback_finish (event, res, &err)) if (lfb_event_trigger_feedback_finish (event, res, &err))
{
self->playing = TRUE; self->playing = TRUE;
}
else else
{
g_warning ("Failed to trigger feedback for '%s': %s", g_warning ("Failed to trigger feedback for '%s': %s",
lfb_event_get_event (event), err->message); lfb_event_get_event (event), err->message);
}
g_object_unref (self); g_object_unref (self);
} }
@ -75,12 +71,10 @@ start (CallsRinger *self)
{ {
g_return_if_fail (self->playing == FALSE); g_return_if_fail (self->playing == FALSE);
if (self->event) if (self->event) {
{
if (self->call_count > self->ring_count) if (self->call_count > self->ring_count)
{
lfb_event_set_feedback_profile (self->event, "quiet"); lfb_event_set_feedback_profile (self->event, "quiet");
}
g_object_ref (self); g_object_ref (self);
lfb_event_trigger_feedback_async (self->event, lfb_event_trigger_feedback_async (self->event,
NULL, NULL,
@ -95,19 +89,16 @@ on_event_feedback_ended (LfbEvent *event,
CallsRinger *self) CallsRinger *self)
{ {
g_autoptr (GError) err = NULL; g_autoptr (GError) err = NULL;
g_return_if_fail (LFB_IS_EVENT (event)); g_return_if_fail (LFB_IS_EVENT (event));
g_return_if_fail (CALLS_IS_RINGER (self)); g_return_if_fail (CALLS_IS_RINGER (self));
if (lfb_event_end_feedback_finish (event, res, &err)) if (lfb_event_end_feedback_finish (event, res, &err))
{
self->playing = FALSE; self->playing = FALSE;
}
else else
{
g_warning ("Failed to end feedback for '%s': %s", g_warning ("Failed to end feedback for '%s': %s",
lfb_event_get_event (event), err->message); lfb_event_get_event (event), err->message);
} }
}
static void static void
on_feedback_ended (LfbEvent *event, on_feedback_ended (LfbEvent *event,
@ -131,18 +122,13 @@ stop (CallsRinger *self)
static void static void
update_ring (CallsRinger *self) update_ring (CallsRinger *self)
{ {
if (!self->playing) if (!self->playing) {
{ if (self->ring_count > 0) {
if (self->ring_count > 0)
{
g_debug ("Starting ringer"); g_debug ("Starting ringer");
start (self); start (self);
} }
} } else {
else if (self->ring_count == 0) {
{
if (self->ring_count == 0)
{
g_debug ("Stopping ringer"); g_debug ("Stopping ringer");
stop (self); stop (self);
} }
@ -153,8 +139,7 @@ update_ring (CallsRinger *self)
static inline gboolean static inline gboolean
is_ring_state (CallsCallState state) is_ring_state (CallsCallState state)
{ {
switch (state) switch (state) {
{
case CALLS_CALL_STATE_INCOMING: case CALLS_CALL_STATE_INCOMING:
case CALLS_CALL_STATE_WAITING: case CALLS_CALL_STATE_WAITING:
return TRUE; return TRUE;
@ -175,19 +160,13 @@ state_changed_cb (CallsRinger *self,
old_is_ring = is_ring_state (old_state); old_is_ring = is_ring_state (old_state);
if (old_is_ring == is_ring_state (new_state)) if (old_is_ring == is_ring_state (new_state))
{
// No change in ring state // No change in ring state
return; return;
}
if (old_is_ring) if (old_is_ring)
{
--self->ring_count; --self->ring_count;
}
else else
{
++self->ring_count; ++self->ring_count;
}
update_ring (self); update_ring (self);
} }
@ -201,16 +180,15 @@ update_count (CallsRinger *self,
self->call_count += delta; self->call_count += delta;
if (is_ring_state (calls_call_get_state (call))) if (is_ring_state (calls_call_get_state (call)))
{
self->ring_count += delta; self->ring_count += delta;
}
update_ring (self); update_ring (self);
} }
static void static void
call_added_cb (CallsRinger *self, CallsCall *call) call_added_cb (CallsRinger *self,
CallsCall *call)
{ {
update_count (self, call, +1); update_count (self, call, +1);
@ -222,7 +200,8 @@ call_added_cb (CallsRinger *self, CallsCall *call)
static void static void
call_removed_cb (CallsRinger *self, CallsCall *call) call_removed_cb (CallsRinger *self,
CallsCall *call)
{ {
update_count (self, call, -1); update_count (self, call, -1);
@ -235,18 +214,15 @@ calls_ringer_init (CallsRinger *self)
{ {
g_autoptr (GError) err = NULL; g_autoptr (GError) err = NULL;
if (lfb_init (APP_ID, &err)) if (lfb_init (APP_ID, &err)) {
{
self->event = lfb_event_new ("phone-incoming-call"); self->event = lfb_event_new ("phone-incoming-call");
/* Let feedbackd do the loop */ /* Let feedbackd do the loop */
lfb_event_set_timeout (self->event, 0); lfb_event_set_timeout (self->event, 0);
g_signal_connect (self->event, g_signal_connect (self->event,
"feedback-ended", "feedback-ended",
(GCallback)on_feedback_ended, G_CALLBACK (on_feedback_ended),
self); self);
} } else {
else
{
g_warning ("Failed to init libfeedback: %s", err->message); g_warning ("Failed to init libfeedback: %s", err->message);
} }
} }
@ -283,8 +259,7 @@ dispose (GObject *object)
{ {
CallsRinger *self = CALLS_RINGER (object); CallsRinger *self = CALLS_RINGER (object);
if (self->event) if (self->event) {
{
g_clear_object (&self->event); g_clear_object (&self->event);
lfb_uninit (); lfb_uninit ();
} }