mirror of
https://gitlab.gnome.org/GNOME/calls.git
synced 2024-12-04 20:07:36 +00:00
calls-in-app-notification: migrate to AdwToastOverlay
Part-of: <https://gitlab.gnome.org/GNOME/calls/-/merge_requests/714>
This commit is contained in:
parent
915b855ec8
commit
76697050e8
10 changed files with 20 additions and 238 deletions
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -25,17 +25,11 @@
|
|||
#ifndef CALLS_IN_APP_NOTIFICATION_H__
|
||||
#define CALLS_IN_APP_NOTIFICATION_H__
|
||||
|
||||
#include <adwaita.h>
|
||||
#include <gtk/gtk.h>
|
||||
|
||||
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
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -9,7 +9,6 @@
|
|||
<file preprocess="xml-stripblanks">contacts-box.ui</file>
|
||||
<file preprocess="xml-stripblanks">contacts-row.ui</file>
|
||||
<file preprocess="xml-stripblanks">history-box.ui</file>
|
||||
<file preprocess="xml-stripblanks">in-app-notification.ui</file>
|
||||
<file preprocess="xml-stripblanks">main-window.ui</file>
|
||||
<file preprocess="xml-stripblanks">new-call-box.ui</file>
|
||||
<file preprocess="xml-stripblanks">new-call-header-bar.ui</file>
|
||||
|
|
|
@ -19,13 +19,7 @@
|
|||
</object>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkOverlay">
|
||||
<child type="overlay">
|
||||
<object class="CallsInAppNotification" id="in_app_notification">
|
||||
<property name="can-target">False</property>
|
||||
<property name="visible">True</property>
|
||||
</object>
|
||||
</child>
|
||||
<object class="AdwToastOverlay" id="toast_overlay">
|
||||
<property name="child">
|
||||
<object class="GtkStack" id="stack">
|
||||
<property name="vexpand">True</property>
|
||||
|
|
|
@ -5,13 +5,7 @@
|
|||
<property name="title" translatable="yes">Calls</property>
|
||||
<property name="hide-on-close">True</property>
|
||||
<child>
|
||||
<object class="GtkOverlay">
|
||||
<child type="overlay">
|
||||
<object class="CallsInAppNotification" id="in_app_notification">
|
||||
<property name="can-target">False</property>
|
||||
<property name="visible">True</property>
|
||||
</object>
|
||||
</child>
|
||||
<object class="AdwToastOverlay" id="toast_overlay">
|
||||
<property name="child">
|
||||
<object class="GtkStack" id="main_stack">
|
||||
<child>
|
||||
|
|
|
@ -1,41 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<interface>
|
||||
<requires lib="gtk" version="4.0"/>
|
||||
<template class="CallsInAppNotification" parent="GtkWidget">
|
||||
<property name="visible">False</property>
|
||||
<child>
|
||||
<object class="GtkRevealer" id="revealer">
|
||||
<property name="valign">start</property>
|
||||
<property name="halign">center</property>
|
||||
<property name="child">
|
||||
<object class="GtkBox">
|
||||
<child>
|
||||
<object class="GtkButton">
|
||||
<property name="receives_default">True</property>
|
||||
<signal name="clicked" handler="calls_in_app_notification_hide" swapped="yes"/>
|
||||
<child>
|
||||
<object class="GtkImage">
|
||||
<property name="icon_name">window-close-symbolic</property>
|
||||
</object>
|
||||
</child>
|
||||
<style>
|
||||
<class name="flat"/>
|
||||
</style>
|
||||
</object>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkLabel" id="label">
|
||||
<property name="wrap">True</property>
|
||||
<property name="margin-start">24</property>
|
||||
<property name="margin-end">24</property>
|
||||
</object>
|
||||
</child>
|
||||
<style>
|
||||
<class name="app-notification"/>
|
||||
</style>
|
||||
</object>
|
||||
</property>
|
||||
</object>
|
||||
</child>
|
||||
</template>
|
||||
</interface>
|
|
@ -33,13 +33,7 @@
|
|||
</object>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkOverlay">
|
||||
<child type="overlay">
|
||||
<object class="CallsInAppNotification" id="in_app_notification">
|
||||
<property name="can-target">False</property>
|
||||
<property name="visible">True</property>
|
||||
</object>
|
||||
</child>
|
||||
<object class="AdwToastOverlay" id="toast_overlay">
|
||||
<property name="child">
|
||||
<object class="GtkBox">
|
||||
<property name="orientation">vertical</property>
|
||||
|
|
Loading…
Reference in a new issue