diff --git a/src/calls-account-overview.c b/src/calls-account-overview.c index be8df08..d894ff7 100644 --- a/src/calls-account-overview.c +++ b/src/calls-account-overview.c @@ -78,7 +78,7 @@ struct _CallsAccountOverview { GtkEventController *key_controller; GtkEventController *key_controller_account; CallsAccountOverviewState state; - CallsInAppNotification *in_app_notification; + AdwToastOverlay *toast_overlay; }; G_DEFINE_TYPE (CallsAccountOverview, calls_account_overview, ADW_TYPE_WINDOW) @@ -228,7 +228,7 @@ on_account_message (CallsAccount *account, notification = g_strdup_printf ("%s: %s", calls_account_get_address (account), message); - calls_in_app_notification_show (self->in_app_notification, notification); + calls_in_app_notification_show (self->toast_overlay, notification); } @@ -363,7 +363,7 @@ 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_child (widget_class, CallsAccountOverview, toast_overlay); gtk_widget_class_bind_template_callback (widget_class, on_add_account_clicked); gtk_widget_class_bind_template_callback (widget_class, on_account_row_activated); diff --git a/src/calls-call-window.c b/src/calls-call-window.c index c33c51f..6509445 100644 --- a/src/calls-call-window.c +++ b/src/calls-call-window.c @@ -45,7 +45,7 @@ struct _CallsCallWindow { GListStore *calls; - CallsInAppNotification *in_app_notification; + AdwToastOverlay *toast_overlay; GtkStack *main_stack; GtkStack *header_bar_stack; @@ -272,7 +272,7 @@ calls_call_window_init (CallsCallWindow *self) g_signal_connect_object (calls_manager_get_default (), "message", G_CALLBACK (calls_in_app_notification_show), - self->in_app_notification, + self->toast_overlay, G_CONNECT_SWAPPED); g_signal_connect_object (calls_manager_get_default (), @@ -318,7 +318,7 @@ calls_call_window_class_init (CallsCallWindowClass *klass) object_class->dispose = dispose; gtk_widget_class_set_template_from_resource (widget_class, "/org/gnome/Calls/ui/call-window.ui"); - gtk_widget_class_bind_template_child (widget_class, CallsCallWindow, in_app_notification); + gtk_widget_class_bind_template_child (widget_class, CallsCallWindow, toast_overlay); gtk_widget_class_bind_template_child (widget_class, CallsCallWindow, main_stack); gtk_widget_class_bind_template_child (widget_class, CallsCallWindow, header_bar_stack); gtk_widget_class_bind_template_child (widget_class, CallsCallWindow, show_calls); diff --git a/src/calls-in-app-notification.c b/src/calls-in-app-notification.c index efb45e3..2e8e92d 100644 --- a/src/calls-in-app-notification.c +++ b/src/calls-in-app-notification.c @@ -26,166 +26,14 @@ #define DEFAULT_TIMEOUT_SECONDS 3 -struct _CallsInAppNotification { - GtkWidget parent_instance; - - GtkRevealer *revealer; - GtkLabel *label; - - guint timeout; - guint timeout_id; -}; - -G_DEFINE_TYPE (CallsInAppNotification, calls_in_app_notification, GTK_TYPE_WIDGET) - - -enum { - PROP_0, - PROP_TIMEOUT, - PROP_LAST_PROP, -}; -static GParamSpec *props[PROP_LAST_PROP]; - - -static gboolean -timeout_cb (CallsInAppNotification *self) -{ - calls_in_app_notification_hide (self); - return G_SOURCE_REMOVE; -} - - -static void -calls_in_app_notification_get_property (GObject *object, - guint property_id, - GValue *value, - GParamSpec *pspec) -{ - CallsInAppNotification *self = CALLS_IN_APP_NOTIFICATION (object); - - switch (property_id) { - case PROP_TIMEOUT: - g_value_set_uint (value, self->timeout); - break; - - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); - break; - } -} - - -static void -calls_in_app_notification_set_property (GObject *object, - guint property_id, - const GValue *value, - GParamSpec *pspec) -{ - CallsInAppNotification *self = CALLS_IN_APP_NOTIFICATION (object); - - switch (property_id) { - case PROP_TIMEOUT: - self->timeout = g_value_get_uint (value); - break; - - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); - break; - } -} - - -static void -calls_in_app_notification_dispose (GObject *object) -{ - CallsInAppNotification *self = CALLS_IN_APP_NOTIFICATION (object); - - GtkWidget *revealer = GTK_WIDGET (self->revealer); - - g_clear_pointer (&revealer, gtk_widget_unparent); - - G_OBJECT_CLASS (calls_in_app_notification_parent_class)->dispose (object); -} - - -static void -calls_in_app_notification_finalize (GObject *object) -{ - CallsInAppNotification *self = CALLS_IN_APP_NOTIFICATION (object); - - g_clear_handle_id (&self->timeout_id, g_source_remove); - - G_OBJECT_CLASS (calls_in_app_notification_parent_class)->finalize (object); -} - - -static void -calls_in_app_notification_class_init (CallsInAppNotificationClass *klass) -{ - GObjectClass *object_class = G_OBJECT_CLASS (klass); - GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass); - - object_class->get_property = calls_in_app_notification_get_property; - object_class->set_property = calls_in_app_notification_set_property; - object_class->dispose = calls_in_app_notification_dispose; - object_class->finalize = calls_in_app_notification_finalize; - - props[PROP_TIMEOUT] = g_param_spec_uint ("timeout", - "Timeout", - "The time the in-app notifaction should be shown", - 1, - G_MAXUINT, - DEFAULT_TIMEOUT_SECONDS, - G_PARAM_READWRITE | - G_PARAM_CONSTRUCT | - G_PARAM_STATIC_STRINGS); - - g_object_class_install_properties (object_class, PROP_LAST_PROP, props); - - gtk_widget_class_set_template_from_resource (widget_class, "/org/gnome/Calls/ui/in-app-notification.ui"); - gtk_widget_class_bind_template_child (widget_class, CallsInAppNotification, revealer); - gtk_widget_class_bind_template_child (widget_class, CallsInAppNotification, label); - gtk_widget_class_bind_template_callback (widget_class, calls_in_app_notification_hide); - - gtk_widget_class_set_layout_manager_type(widget_class, GTK_TYPE_BOX_LAYOUT); -} - - -static void -calls_in_app_notification_init (CallsInAppNotification *self) -{ - gtk_widget_init_template (GTK_WIDGET (self)); -} - - -CallsInAppNotification * -calls_in_app_notification_new (void) -{ - return g_object_new (CALLS_TYPE_IN_APP_NOTIFICATION, NULL); -} - - void -calls_in_app_notification_show (CallsInAppNotification *self, const gchar *message) +calls_in_app_notification_show (AdwToastOverlay *overlay, const gchar *message) { - g_return_if_fail (CALLS_IS_IN_APP_NOTIFICATION (self)); + AdwToast* toast; - gtk_label_set_text (self->label, message); + g_return_if_fail (ADW_IS_TOAST_OVERLAY (overlay)); - if (self->timeout_id) - g_source_remove (self->timeout_id); - - gtk_revealer_set_reveal_child (self->revealer, TRUE); - self->timeout_id = g_timeout_add_seconds (self->timeout, (GSourceFunc) timeout_cb, self); -} - - -void -calls_in_app_notification_hide (CallsInAppNotification *self) -{ - g_return_if_fail (CALLS_IS_IN_APP_NOTIFICATION (self)); - - g_clear_handle_id (&self->timeout_id, g_source_remove); - - gtk_revealer_set_reveal_child (self->revealer, FALSE); + toast = adw_toast_new (message); + adw_toast_set_timeout (toast, DEFAULT_TIMEOUT_SECONDS); + adw_toast_overlay_add_toast (overlay, toast); } diff --git a/src/calls-in-app-notification.h b/src/calls-in-app-notification.h index b113bfd..a7b5d8d 100644 --- a/src/calls-in-app-notification.h +++ b/src/calls-in-app-notification.h @@ -25,17 +25,11 @@ #ifndef CALLS_IN_APP_NOTIFICATION_H__ #define CALLS_IN_APP_NOTIFICATION_H__ +#include #include G_BEGIN_DECLS - -#define CALLS_TYPE_IN_APP_NOTIFICATION (calls_in_app_notification_get_type ()) - -G_DECLARE_FINAL_TYPE (CallsInAppNotification, calls_in_app_notification, CALLS, IN_APP_NOTIFICATION, GtkWidget) - -CallsInAppNotification * calls_in_app_notification_new (void); -void calls_in_app_notification_show (CallsInAppNotification *self, const gchar *message); -void calls_in_app_notification_hide (CallsInAppNotification *self); +void calls_in_app_notification_show (AdwToastOverlay *overlay, const gchar *message); G_END_DECLS diff --git a/src/calls-main-window.c b/src/calls-main-window.c index 2e8cc63..1d6899b 100644 --- a/src/calls-main-window.c +++ b/src/calls-main-window.c @@ -46,7 +46,7 @@ struct _CallsMainWindow { GListModel *record_store; - CallsInAppNotification *in_app_notification; + AdwToastOverlay *toast_overlay; AdwViewSwitcherTitle *title_switcher; AdwViewStack *main_stack; @@ -337,7 +337,7 @@ constructed (GObject *object) g_signal_connect_object (calls_manager_get_default (), "message", G_CALLBACK (calls_in_app_notification_show), - self->in_app_notification, + self->toast_overlay, G_CONNECT_SWAPPED); g_signal_connect_object (calls_manager_get_default (), @@ -457,7 +457,7 @@ calls_main_window_class_init (CallsMainWindowClass *klass) widget_class->size_allocate = size_allocate; gtk_widget_class_set_template_from_resource (widget_class, "/org/gnome/Calls/ui/main-window.ui"); - gtk_widget_class_bind_template_child (widget_class, CallsMainWindow, in_app_notification); + gtk_widget_class_bind_template_child (widget_class, CallsMainWindow, toast_overlay); gtk_widget_class_bind_template_child (widget_class, CallsMainWindow, title_switcher); gtk_widget_class_bind_template_child (widget_class, CallsMainWindow, main_stack); gtk_widget_class_bind_template_child (widget_class, CallsMainWindow, permanent_error_revealer); diff --git a/src/calls.gresources.xml b/src/calls.gresources.xml index 827bd2c..a94ae2d 100644 --- a/src/calls.gresources.xml +++ b/src/calls.gresources.xml @@ -9,7 +9,6 @@ contacts-box.ui contacts-row.ui history-box.ui - in-app-notification.ui main-window.ui new-call-box.ui new-call-header-bar.ui diff --git a/src/ui/account-overview.ui b/src/ui/account-overview.ui index e4d8369..f18b2ff 100644 --- a/src/ui/account-overview.ui +++ b/src/ui/account-overview.ui @@ -19,13 +19,7 @@ - - - - False - True - - + True diff --git a/src/ui/call-window.ui b/src/ui/call-window.ui index 321710b..6652e70 100644 --- a/src/ui/call-window.ui +++ b/src/ui/call-window.ui @@ -5,13 +5,7 @@ Calls True - - - - False - True - - + diff --git a/src/ui/in-app-notification.ui b/src/ui/in-app-notification.ui deleted file mode 100644 index 33e86a0..0000000 --- a/src/ui/in-app-notification.ui +++ /dev/null @@ -1,41 +0,0 @@ - - - - - diff --git a/src/ui/main-window.ui b/src/ui/main-window.ui index fdfa51b..6c9616d 100644 --- a/src/ui/main-window.ui +++ b/src/ui/main-window.ui @@ -33,13 +33,7 @@ - - - - False - True - - + vertical