account-overview: Show notification on account message
Accounts implement the CallsMessageSource interface and emit messages when there are state changes of which the user should be informed. Closes #340
This commit is contained in:
@@ -29,6 +29,7 @@
|
||||
#include "calls-account-row.h"
|
||||
#include "calls-account-provider.h"
|
||||
#include "calls-manager.h"
|
||||
#include "calls-in-app-notification.h"
|
||||
|
||||
|
||||
/**
|
||||
@@ -64,6 +65,7 @@ struct _CallsAccountOverview {
|
||||
/* misc */
|
||||
CallsAccountOverviewState state;
|
||||
GList *providers;
|
||||
CallsInAppNotification *in_app_notification;
|
||||
};
|
||||
|
||||
G_DEFINE_TYPE (CallsAccountOverview, calls_account_overview, HDY_TYPE_WINDOW)
|
||||
@@ -167,6 +169,24 @@ on_edit_account_clicked (CallsAccountRow *row,
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
on_account_message (CallsAccount *account,
|
||||
const char *message,
|
||||
GtkMessageType message_type,
|
||||
CallsAccountOverview *self)
|
||||
{
|
||||
g_autofree char* notification = NULL;
|
||||
|
||||
g_assert (CALLS_IS_ACCOUNT (account));
|
||||
g_assert (CALLS_IS_ACCOUNT_OVERVIEW (self));
|
||||
|
||||
notification = g_strdup_printf ("%s: %s",
|
||||
calls_account_get_address (account),
|
||||
message);
|
||||
calls_in_app_notification_show (self->in_app_notification, notification);
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
update_account_list (CallsAccountOverview *self)
|
||||
{
|
||||
@@ -197,6 +217,11 @@ update_account_list (CallsAccountOverview *self)
|
||||
g_autoptr (CallsAccount) account = CALLS_ACCOUNT (g_list_model_get_item (model, i));
|
||||
CallsAccountRow *account_row = calls_account_row_new (provider, account);
|
||||
|
||||
g_signal_handlers_disconnect_by_data (account, self);
|
||||
g_signal_connect (account, "message",
|
||||
G_CALLBACK (on_account_message),
|
||||
self);
|
||||
|
||||
g_signal_connect (account_row, "edit-clicked",
|
||||
G_CALLBACK (on_edit_account_clicked),
|
||||
self);
|
||||
@@ -258,6 +283,8 @@ calls_account_overview_class_init (CallsAccountOverviewClass *klass)
|
||||
|
||||
gtk_widget_class_bind_template_child (widget_class, CallsAccountOverview, account_window);
|
||||
|
||||
gtk_widget_class_bind_template_child (widget_class, CallsAccountOverview, in_app_notification);
|
||||
|
||||
gtk_widget_class_bind_template_callback (widget_class, on_add_account_clicked);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user