calendar-management/calendars: Switch to toasts
It's time to move on from the old in-app notification style. Switch to toasts.
This commit is contained in:
@@ -34,12 +34,10 @@ struct _GcalCalendarsPage
|
|||||||
|
|
||||||
GtkListBoxRow *add_calendar_row;
|
GtkListBoxRow *add_calendar_row;
|
||||||
GtkListBox *listbox;
|
GtkListBox *listbox;
|
||||||
GtkLabel *notification_label;
|
|
||||||
GtkRevealer *notification_revealer;
|
|
||||||
GtkSizeGroup *sizegroup;
|
GtkSizeGroup *sizegroup;
|
||||||
|
AdwToastOverlay *toast_overlay;
|
||||||
|
|
||||||
GcalCalendar *removed_calendar;
|
AdwToast *toast;
|
||||||
gint notification_timeout_id;
|
|
||||||
|
|
||||||
GcalContext *context;
|
GcalContext *context;
|
||||||
};
|
};
|
||||||
@@ -189,17 +187,14 @@ delete_calendar (GcalCalendarsPage *self,
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
/* Enable the source again to remove it's name from disabled list */
|
/* Enable the source again to remove it's name from disabled list */
|
||||||
gcal_calendar_set_visible (self->removed_calendar, TRUE);
|
gcal_calendar_set_visible (calendar, TRUE);
|
||||||
e_source_remove_sync (removed_source, NULL, &error);
|
e_source_remove_sync (removed_source, NULL, &error);
|
||||||
|
|
||||||
if (error != NULL)
|
if (error != NULL)
|
||||||
{
|
{
|
||||||
g_warning ("[source-dialog] Error removing source: %s", error->message);
|
g_warning ("[source-dialog] Error removing source: %s", error->message);
|
||||||
add_calendar (self, self->removed_calendar);
|
add_calendar (self, calendar);
|
||||||
}
|
}
|
||||||
|
|
||||||
gtk_revealer_set_reveal_child (self->notification_revealer, FALSE);
|
|
||||||
g_clear_handle_id (&self->notification_timeout_id, g_source_remove);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -244,22 +239,6 @@ listbox_sort_func (GtkListBoxRow *row1,
|
|||||||
return g_strcmp0 (parent_name1, parent_name2);
|
return g_strcmp0 (parent_name1, parent_name2);
|
||||||
}
|
}
|
||||||
|
|
||||||
static gboolean
|
|
||||||
remove_calendar_after_delay_cb (gpointer data)
|
|
||||||
{
|
|
||||||
GcalCalendarsPage *self = GCAL_CALENDARS_PAGE (data);
|
|
||||||
|
|
||||||
g_assert (self->removed_calendar != NULL);
|
|
||||||
|
|
||||||
delete_calendar (self, self->removed_calendar);
|
|
||||||
g_clear_object (&self->removed_calendar);
|
|
||||||
|
|
||||||
gtk_revealer_set_reveal_child (self->notification_revealer, FALSE);
|
|
||||||
self->notification_timeout_id = 0;
|
|
||||||
|
|
||||||
return G_SOURCE_REMOVE;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
on_calendar_color_changed_cb (GcalCalendar *calendar,
|
on_calendar_color_changed_cb (GcalCalendar *calendar,
|
||||||
GParamSpec *pspec,
|
GParamSpec *pspec,
|
||||||
@@ -273,19 +252,6 @@ on_calendar_color_changed_cb (GcalCalendar *calendar,
|
|||||||
gtk_image_set_from_paintable (GTK_IMAGE (icon), color_paintable);
|
gtk_image_set_from_paintable (GTK_IMAGE (icon), color_paintable);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
|
||||||
on_close_notification_button_clicked_cb (GtkWidget *button,
|
|
||||||
GcalCalendarsPage *self)
|
|
||||||
{
|
|
||||||
g_assert (self->removed_calendar != NULL);
|
|
||||||
|
|
||||||
delete_calendar (self, self->removed_calendar);
|
|
||||||
g_clear_object (&self->removed_calendar);
|
|
||||||
|
|
||||||
gtk_revealer_set_reveal_child (self->notification_revealer, FALSE);
|
|
||||||
g_clear_handle_id (&self->notification_timeout_id, g_source_remove);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
on_listbox_row_activated_cb (GtkListBox *listbox,
|
on_listbox_row_activated_cb (GtkListBox *listbox,
|
||||||
GtkListBoxRow *row,
|
GtkListBoxRow *row,
|
||||||
@@ -322,19 +288,47 @@ on_manager_calendar_removed_cb (GcalManager *manager,
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
on_undo_remove_button_clicked_cb (GtkButton *button,
|
on_toast_button_clicked_cb (AdwToast *toast,
|
||||||
GcalCalendarsPage *self)
|
GcalCalendarsPage *self)
|
||||||
{
|
{
|
||||||
if (!self->removed_calendar)
|
GcalCalendar *calendar;
|
||||||
return;
|
|
||||||
|
|
||||||
gcal_calendar_set_visible (self->removed_calendar, TRUE);
|
GCAL_ENTRY;
|
||||||
|
|
||||||
add_calendar (self, self->removed_calendar);
|
calendar = g_object_get_data (G_OBJECT (toast), "calendar");
|
||||||
g_clear_object (&self->removed_calendar);
|
g_assert (calendar != NULL);
|
||||||
|
|
||||||
gtk_revealer_set_reveal_child (self->notification_revealer, FALSE);
|
gcal_calendar_set_visible (calendar, TRUE);
|
||||||
g_clear_handle_id (&self->notification_timeout_id, g_source_remove);
|
add_calendar (self, calendar);
|
||||||
|
|
||||||
|
g_object_set_data (G_OBJECT (toast), "calendar", NULL);
|
||||||
|
|
||||||
|
g_clear_object (&self->toast);
|
||||||
|
|
||||||
|
GCAL_EXIT;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
on_toast_dismissed_cb (AdwToast *toast,
|
||||||
|
GcalCalendarsPage *self)
|
||||||
|
{
|
||||||
|
GcalCalendar *calendar;
|
||||||
|
|
||||||
|
GCAL_ENTRY;
|
||||||
|
|
||||||
|
calendar = g_object_get_data (G_OBJECT (toast), "calendar");
|
||||||
|
|
||||||
|
if (!calendar)
|
||||||
|
{
|
||||||
|
g_assert (self->toast == NULL);
|
||||||
|
GCAL_RETURN ();
|
||||||
|
}
|
||||||
|
|
||||||
|
delete_calendar (self, calendar);
|
||||||
|
|
||||||
|
g_clear_object (&self->toast);
|
||||||
|
|
||||||
|
GCAL_EXIT;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -359,6 +353,7 @@ gcal_calendars_page_activate (GcalCalendarManagementPage *page,
|
|||||||
GcalCalendar *calendar)
|
GcalCalendar *calendar)
|
||||||
{
|
{
|
||||||
g_autofree gchar *new_string = NULL;
|
g_autofree gchar *new_string = NULL;
|
||||||
|
g_autoptr (AdwToast) toast = NULL;
|
||||||
GcalCalendarsPage *self;
|
GcalCalendarsPage *self;
|
||||||
|
|
||||||
GCAL_ENTRY;
|
GCAL_ENTRY;
|
||||||
@@ -369,32 +364,26 @@ gcal_calendars_page_activate (GcalCalendarManagementPage *page,
|
|||||||
self = GCAL_CALENDARS_PAGE (page);
|
self = GCAL_CALENDARS_PAGE (page);
|
||||||
|
|
||||||
/* Remove the previously deleted calendar, if any */
|
/* Remove the previously deleted calendar, if any */
|
||||||
if (self->removed_calendar)
|
g_clear_pointer (&self->toast, adw_toast_dismiss);
|
||||||
{
|
|
||||||
delete_calendar (self, self->removed_calendar);
|
|
||||||
g_clear_object (&self->removed_calendar);
|
|
||||||
}
|
|
||||||
|
|
||||||
self->removed_calendar = g_object_ref (calendar);
|
|
||||||
|
|
||||||
/* Remove the listbox entry (if any) */
|
/* Remove the listbox entry (if any) */
|
||||||
remove_calendar (self, calendar);
|
remove_calendar (self, calendar);
|
||||||
|
|
||||||
/* Update notification label */
|
/* Create the new toast */
|
||||||
new_string = g_markup_printf_escaped (_("Calendar <b>%s</b> removed"),
|
new_string = g_markup_printf_escaped (_("Calendar <b>%s</b> removed"),
|
||||||
gcal_calendar_get_name (self->removed_calendar));
|
gcal_calendar_get_name (calendar));
|
||||||
gtk_label_set_markup (self->notification_label, new_string);
|
|
||||||
|
|
||||||
gtk_revealer_set_reveal_child (self->notification_revealer, TRUE);
|
toast = adw_toast_new (new_string);
|
||||||
|
adw_toast_set_timeout (toast, 7);
|
||||||
|
adw_toast_set_button_label (toast, _("Undo"));
|
||||||
|
g_object_set_data_full (G_OBJECT (toast), "calendar", g_object_ref (calendar), g_object_unref);
|
||||||
|
g_signal_connect (toast, "dismissed", G_CALLBACK (on_toast_dismissed_cb), self);
|
||||||
|
g_signal_connect (toast, "button-clicked", G_CALLBACK (on_toast_button_clicked_cb), self);
|
||||||
|
adw_toast_overlay_add_toast (self->toast_overlay, g_object_ref (toast));
|
||||||
|
|
||||||
/* Remove old notifications */
|
self->toast = g_steal_pointer (&toast);
|
||||||
if (self->notification_timeout_id != 0)
|
|
||||||
g_source_remove (self->notification_timeout_id);
|
|
||||||
|
|
||||||
self->notification_timeout_id = g_timeout_add_seconds (7, remove_calendar_after_delay_cb, self);
|
|
||||||
|
|
||||||
gcal_calendar_set_visible (self->removed_calendar, FALSE);
|
|
||||||
|
|
||||||
|
gcal_calendar_set_visible (calendar, FALSE);
|
||||||
|
|
||||||
GCAL_EXIT;
|
GCAL_EXIT;
|
||||||
}
|
}
|
||||||
@@ -416,7 +405,7 @@ gcal_calendars_page_finalize (GObject *object)
|
|||||||
{
|
{
|
||||||
GcalCalendarsPage *self = (GcalCalendarsPage *)object;
|
GcalCalendarsPage *self = (GcalCalendarsPage *)object;
|
||||||
|
|
||||||
g_clear_handle_id (&self->notification_timeout_id, g_source_remove);
|
g_clear_object (&self->toast);
|
||||||
g_clear_object (&self->context);
|
g_clear_object (&self->context);
|
||||||
|
|
||||||
G_OBJECT_CLASS (gcal_calendars_page_parent_class)->finalize (object);
|
G_OBJECT_CLASS (gcal_calendars_page_parent_class)->finalize (object);
|
||||||
@@ -491,13 +480,10 @@ gcal_calendars_page_class_init (GcalCalendarsPageClass *klass)
|
|||||||
|
|
||||||
gtk_widget_class_bind_template_child (widget_class, GcalCalendarsPage, add_calendar_row);
|
gtk_widget_class_bind_template_child (widget_class, GcalCalendarsPage, add_calendar_row);
|
||||||
gtk_widget_class_bind_template_child (widget_class, GcalCalendarsPage, listbox);
|
gtk_widget_class_bind_template_child (widget_class, GcalCalendarsPage, listbox);
|
||||||
gtk_widget_class_bind_template_child (widget_class, GcalCalendarsPage, notification_label);
|
|
||||||
gtk_widget_class_bind_template_child (widget_class, GcalCalendarsPage, notification_revealer);
|
|
||||||
gtk_widget_class_bind_template_child (widget_class, GcalCalendarsPage, sizegroup);
|
gtk_widget_class_bind_template_child (widget_class, GcalCalendarsPage, sizegroup);
|
||||||
|
gtk_widget_class_bind_template_child (widget_class, GcalCalendarsPage, toast_overlay);
|
||||||
|
|
||||||
gtk_widget_class_bind_template_callback (widget_class, on_close_notification_button_clicked_cb);
|
|
||||||
gtk_widget_class_bind_template_callback (widget_class, on_listbox_row_activated_cb);
|
gtk_widget_class_bind_template_callback (widget_class, on_listbox_row_activated_cb);
|
||||||
gtk_widget_class_bind_template_callback (widget_class, on_undo_remove_button_clicked_cb);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
|||||||
@@ -2,47 +2,7 @@
|
|||||||
<interface>
|
<interface>
|
||||||
<template class="GcalCalendarsPage" parent="AdwBin">
|
<template class="GcalCalendarsPage" parent="AdwBin">
|
||||||
<child>
|
<child>
|
||||||
<object class="GtkOverlay">
|
<object class="AdwToastOverlay" id="toast_overlay">
|
||||||
|
|
||||||
<child type="overlay">
|
|
||||||
<object class="GtkRevealer" id="notification_revealer">
|
|
||||||
<property name="halign">center</property>
|
|
||||||
<property name="valign">start</property>
|
|
||||||
<child>
|
|
||||||
<object class="GtkFrame">
|
|
||||||
<child>
|
|
||||||
<object class="GtkBox">
|
|
||||||
<property name="spacing">12</property>
|
|
||||||
<child>
|
|
||||||
<object class="GtkLabel" id="notification_label">
|
|
||||||
<property name="use_markup">True</property>
|
|
||||||
</object>
|
|
||||||
</child>
|
|
||||||
<child>
|
|
||||||
<object class="GtkButton" id="notification_action_button">
|
|
||||||
<property name="label" translatable="yes">Undo</property>
|
|
||||||
<signal name="clicked" handler="on_undo_remove_button_clicked_cb" object="GcalCalendarsPage" swapped="no"/>
|
|
||||||
</object>
|
|
||||||
</child>
|
|
||||||
<child>
|
|
||||||
<object class="GtkButton">
|
|
||||||
<property name="icon-name">window-close-symbolic</property>
|
|
||||||
<property name="focus_on_click">False</property>
|
|
||||||
<signal name="clicked" handler="on_close_notification_button_clicked_cb" object="GcalCalendarsPage" swapped="no"/>
|
|
||||||
<style>
|
|
||||||
<class name="flat" />
|
|
||||||
</style>
|
|
||||||
</object>
|
|
||||||
</child>
|
|
||||||
</object>
|
|
||||||
</child>
|
|
||||||
<style>
|
|
||||||
<class name="app-notification"/>
|
|
||||||
</style>
|
|
||||||
</object>
|
|
||||||
</child>
|
|
||||||
</object>
|
|
||||||
</child>
|
|
||||||
|
|
||||||
<child>
|
<child>
|
||||||
<object class="AdwToolbarView">
|
<object class="AdwToolbarView">
|
||||||
|
|||||||
Reference in New Issue
Block a user