From 339093876c712cd6cf890fdab063943807b848c9 Mon Sep 17 00:00:00 2001 From: Evangelos Ribeiro Tzaras Date: Tue, 28 Dec 2021 15:32:22 +0100 Subject: [PATCH] manager: Propagate messages from account Not all portions from the user interface are listening directly to messages from accounts, so the manager should propagate them to allow the UI to pick them up. Closes #340 --- src/calls-manager.c | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/src/calls-manager.c b/src/calls-manager.c index 2a029da..7d5e4b3 100644 --- a/src/calls-manager.c +++ b/src/calls-manager.c @@ -27,6 +27,7 @@ #include "config.h" +#include "calls-account.h" #include "calls-application.h" #include "calls-contacts-provider.h" #include "calls-manager.h" @@ -199,6 +200,36 @@ update_protocols (CallsManager *self) update_state (self); } +/* propagate any message from origins, providers, calls, etc */ +static void +on_message (CallsMessageSource *source, + const char *message, + GtkMessageType message_type, + CallsManager *self) +{ + g_autofree char *notification = NULL; + + g_assert (CALLS_IS_MESSAGE_SOURCE (source)); + g_assert (CALLS_IS_MANAGER (self)); + + /* Prefix the message with the name of the source, if known */ + if (CALLS_IS_ACCOUNT (source)) { + notification = g_strdup_printf ("%s: %s", + calls_account_get_address (CALLS_ACCOUNT (source)), + message); + } + + if (notification) { + calls_message_source_emit_message (CALLS_MESSAGE_SOURCE (self), + notification, + message_type); + } else { + calls_message_source_emit_message (CALLS_MESSAGE_SOURCE (self), + message, + message_type); + } +} + static void add_call (CallsManager *self, CallsCall *call, CallsOrigin *origin) @@ -288,6 +319,11 @@ add_origin (CallsManager *self, CallsOrigin *origin) g_list_store_append (self->origins, origin); + g_signal_connect (origin, + "message", + G_CALLBACK (on_message), + self); + g_signal_connect_object (origin, "notify::country-code", G_CALLBACK (update_country_code_cb),