[gnome-control-center] wwan: Use AdwToasts for notifications
- From: Robert Ancell <rancell src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-control-center] wwan: Use AdwToasts for notifications
- Date: Tue, 10 May 2022 04:31:35 +0000 (UTC)
commit 1204b91f525e352ad1001ac3aec9948f2e676d0b
Author: Mohammed Sadiq <sadiq sadiqpk org>
Date: Wed Jan 12 19:17:48 2022 +0530
wwan: Use AdwToasts for notifications
AdwToasts replaces the GtkLabel inside revealer for notifications
and this simplifies handling the notifications and the toast-overlay
handles the complexities of when to show/withdraw them, the order
they are displayed, etc.
panels/wwan/cc-wwan-device-page.c | 17 +++------
panels/wwan/cc-wwan-device-page.h | 2 +-
panels/wwan/cc-wwan-network-dialog.c | 43 +++------------------
panels/wwan/cc-wwan-network-dialog.ui | 33 +---------------
panels/wwan/cc-wwan-panel.c | 69 ++--------------------------------
panels/wwan/cc-wwan-panel.ui | 36 +-----------------
panels/wwan/cc-wwan-sim-lock-dialog.ui | 33 +---------------
7 files changed, 19 insertions(+), 214 deletions(-)
---
diff --git a/panels/wwan/cc-wwan-device-page.c b/panels/wwan/cc-wwan-device-page.c
index b5dae5f9b..13aa87a1b 100644
--- a/panels/wwan/cc-wwan-device-page.c
+++ b/panels/wwan/cc-wwan-device-page.c
@@ -73,7 +73,7 @@ struct _CcWwanDevicePage
CcListRow *sim_lock_row;
GtkButton *unlock_button;
- GtkLabel *notification_label;
+ AdwToastOverlay *toast_overlay;
CcWwanDevice *device;
CcWwanData *wwan_data;
@@ -598,6 +598,7 @@ cc_wwan_device_page_init (CcWwanDevicePage *self)
static void
cc_wwan_error_changed_cb (CcWwanDevicePage *self)
{
+ AdwToast *toast;
const gchar *message;
message = cc_wwan_device_get_simple_error (self->device);
@@ -605,19 +606,13 @@ cc_wwan_error_changed_cb (CcWwanDevicePage *self)
if (!message)
return;
- /*
- * The label is first set to empty, which will result in
- * the revealer to be closed. Then the real label is
- * set. This will animate the revealer which can bring
- * the user's attention.
- */
- gtk_label_set_label (self->notification_label, "");
- gtk_label_set_label (self->notification_label, message);
+ toast = adw_toast_new (message);
+ adw_toast_overlay_add_toast (self->toast_overlay, toast);
}
CcWwanDevicePage *
cc_wwan_device_page_new (CcWwanDevice *device,
- GtkWidget *notification_label)
+ GtkWidget *toast_overlay)
{
CcWwanDevicePage *self;
@@ -627,7 +622,7 @@ cc_wwan_device_page_new (CcWwanDevice *device,
"device", device,
NULL);
- self->notification_label = GTK_LABEL (notification_label);
+ self->toast_overlay = ADW_TOAST_OVERLAY (toast_overlay);
g_signal_connect_object (self->device, "notify::error",
G_CALLBACK (cc_wwan_error_changed_cb),
diff --git a/panels/wwan/cc-wwan-device-page.h b/panels/wwan/cc-wwan-device-page.h
index 923346a89..0fd03c13e 100644
--- a/panels/wwan/cc-wwan-device-page.h
+++ b/panels/wwan/cc-wwan-device-page.h
@@ -34,7 +34,7 @@ G_BEGIN_DECLS
G_DECLARE_FINAL_TYPE (CcWwanDevicePage, cc_wwan_device_page, CC, WWAN_DEVICE_PAGE, GtkBox)
CcWwanDevicePage *cc_wwan_device_page_new (CcWwanDevice *device,
- GtkWidget *notification_label);
+ GtkWidget *toast_overlay);
CcWwanDevice *cc_wwan_device_page_get_device (CcWwanDevicePage *self);
void cc_wwan_device_page_set_sim_index (CcWwanDevicePage *self,
gint sim_index);
diff --git a/panels/wwan/cc-wwan-network-dialog.c b/panels/wwan/cc-wwan-network-dialog.c
index 4a16b49c3..ac0054747 100644
--- a/panels/wwan/cc-wwan-network-dialog.c
+++ b/panels/wwan/cc-wwan-network-dialog.c
@@ -45,12 +45,11 @@ struct _CcWwanNetworkDialog
{
GtkDialog parent_instance;
+ AdwToastOverlay *toast_overlay;
CcListRow *automatic_row;
GtkButton *button_apply;
GtkSpinner *loading_spinner;
GtkBox *network_search_title;
- GtkLabel *notification_label;
- GtkRevealer *notification_revealer;
GtkListBox *operator_list_box;
GtkButton *refresh_button;
@@ -61,7 +60,6 @@ struct _CcWwanNetworkDialog
GCancellable *search_cancellable;
- guint revealer_timeout_id;
gboolean no_update_network;
};
@@ -108,28 +106,6 @@ cc_wwan_network_row_init (CcWwanNetworkRow *row)
{
}
-static void
-cc_wwan_on_notification_closed (CcWwanNetworkDialog *self,
- GtkWidget *button)
-{
- g_assert (CC_IS_WWAN_NETWORK_DIALOG (self));
-
- gtk_revealer_set_reveal_child (GTK_REVEALER (self->notification_revealer), FALSE);
-
- if (self->revealer_timeout_id != 0)
- g_source_remove (self->revealer_timeout_id);
-
- self->revealer_timeout_id = 0;
-}
-
-static gboolean
-cc_wwan_on_notification_timeout (gpointer user_data)
-{
- cc_wwan_on_notification_closed (user_data, NULL);
-
- return G_SOURCE_REMOVE;
-}
-
static void
cc_wwan_network_changed_cb (CcWwanNetworkDialog *self,
CcWwanNetworkRow *row)
@@ -270,14 +246,14 @@ cc_wwan_network_scan_complete_cb (GObject *object,
}
else if (!g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED))
{
+ AdwToast *toast;
+
self->no_update_network = TRUE;
gtk_widget_activate (GTK_WIDGET (self->automatic_row));
gtk_widget_set_sensitive (GTK_WIDGET (self->operator_list_box), FALSE);
- gtk_label_set_label (self->notification_label,
- cc_wwan_error_get_message (error));
- gtk_revealer_set_reveal_child (self->notification_revealer, TRUE);
- self->revealer_timeout_id = g_timeout_add_seconds (5, cc_wwan_on_notification_timeout, self);
+ toast = adw_toast_new (cc_wwan_error_get_message (error));
+ adw_toast_overlay_add_toast (self->toast_overlay, toast);
gtk_widget_show (GTK_WIDGET (self->operator_list_box));
g_warning ("Error: scanning networks failed: %s", error->message);
@@ -388,11 +364,6 @@ cc_wwan_network_dialog_dispose (GObject *object)
{
CcWwanNetworkDialog *self = (CcWwanNetworkDialog *)object;
- if (self->revealer_timeout_id != 0)
- g_source_remove (self->revealer_timeout_id);
-
- self->revealer_timeout_id = 0;
-
g_cancellable_cancel (self->search_cancellable);
g_clear_object (&self->search_cancellable);
@@ -424,17 +395,15 @@ cc_wwan_network_dialog_class_init (CcWwanNetworkDialogClass *klass)
gtk_widget_class_set_template_from_resource (widget_class,
"/org/gnome/control-center/wwan/cc-wwan-network-dialog.ui");
+ gtk_widget_class_bind_template_child (widget_class, CcWwanNetworkDialog, toast_overlay);
gtk_widget_class_bind_template_child (widget_class, CcWwanNetworkDialog, automatic_row);
gtk_widget_class_bind_template_child (widget_class, CcWwanNetworkDialog, button_apply);
gtk_widget_class_bind_template_child (widget_class, CcWwanNetworkDialog, loading_spinner);
gtk_widget_class_bind_template_child (widget_class, CcWwanNetworkDialog, network_search_title);
- gtk_widget_class_bind_template_child (widget_class, CcWwanNetworkDialog, notification_label);
- gtk_widget_class_bind_template_child (widget_class, CcWwanNetworkDialog, notification_revealer);
gtk_widget_class_bind_template_child (widget_class, CcWwanNetworkDialog, operator_list_box);
gtk_widget_class_bind_template_child (widget_class, CcWwanNetworkDialog, refresh_button);
gtk_widget_class_bind_template_callback (widget_class, cc_wwan_network_changed_cb);
- gtk_widget_class_bind_template_callback (widget_class, cc_wwan_on_notification_closed);
gtk_widget_class_bind_template_callback (widget_class, cc_wwan_auto_network_changed_cb);
gtk_widget_class_bind_template_callback (widget_class, cc_wwan_network_dialog_refresh_networks);
gtk_widget_class_bind_template_callback (widget_class, cc_wwan_network_dialog_apply_clicked_cb);
diff --git a/panels/wwan/cc-wwan-network-dialog.ui b/panels/wwan/cc-wwan-network-dialog.ui
index b473f89ee..1ffc4e5ea 100644
--- a/panels/wwan/cc-wwan-network-dialog.ui
+++ b/panels/wwan/cc-wwan-network-dialog.ui
@@ -13,39 +13,8 @@
<property name="width-request">340</property>
<property name="height-request">360</property>
<child>
- <object class="GtkOverlay">
+ <object class="AdwToastOverlay" id="toast_overlay">
<property name="hexpand">True</property>
- <child type="overlay">
- <object class="GtkRevealer" id="notification_revealer">
- <property name="halign">center</property>
- <property name="valign">start</property>
- <property name="child">
- <object class="GtkBox">
- <property name="spacing">12</property>
- <style>
- <class name="frame"/>
- <class name="app-notification"/>
- </style>
- <child>
- <object class="GtkLabel" id="notification_label">
- <property name="wrap">True</property>
- <property name="wrap-mode">word-char</property>
- <property name="use-markup">True</property>
- </object>
- </child>
- <child>
- <object class="GtkButton">
- <property name="icon-name">window-close-symbolic</property>
- <signal name="clicked" handler="cc_wwan_on_notification_closed" swapped="yes"/>
- <accessibility>
- <property name="label" translatable="yes">Close</property>
- </accessibility>
- </object>
- </child>
- </object>
- </property>
- </object>
- </child>
<property name="child">
<object class="GtkBox">
<property name="margin-start">12</property>
diff --git a/panels/wwan/cc-wwan-panel.c b/panels/wwan/cc-wwan-panel.c
index 63f519d74..066a61598 100644
--- a/panels/wwan/cc-wwan-panel.c
+++ b/panels/wwan/cc-wwan-panel.c
@@ -48,6 +48,7 @@ struct _CcWwanPanel
{
CcPanel parent_instance;
+ AdwToastOverlay *toast_overlay;
AdwComboRow *data_list_row;
GtkListBox *data_sim_select_listbox;
GtkStack *devices_stack;
@@ -55,8 +56,6 @@ struct _CcWwanPanel
GtkSwitch *enable_switch;
GtkStack *main_stack;
GtkRevealer *multi_device_revealer;
- GtkLabel *notification_label;
- GtkRevealer *notification_revealer;
GDBusProxy *rfkill_proxy;
MMManager *mm_manager;
@@ -71,8 +70,6 @@ struct _CcWwanPanel
CmdlineOperation arg_operation;
char *arg_device;
-
- guint revealer_timeout_id;
};
enum {
@@ -235,17 +232,6 @@ wwan_model_get_item_from_mm_object (GListModel *model,
return NULL;
}
-static void
-wwan_notification_close_clicked_cb (CcWwanPanel *self)
-{
- gtk_revealer_set_reveal_child (self->notification_revealer, FALSE);
-
- if (self->revealer_timeout_id != 0)
- g_source_remove (self->revealer_timeout_id);
-
- self->revealer_timeout_id = 0;
-}
-
static void
cc_wwan_panel_update_data_selection (CcWwanPanel *self)
{
@@ -364,44 +350,6 @@ cc_wwan_panel_update_view (CcWwanPanel *self)
g_list_model_get_n_items (G_LIST_MODEL (self->devices)) > 1);
}
-static void
-cc_wwan_panel_on_notification_closed (CcWwanPanel *self,
- GtkWidget *button)
-{
- gtk_revealer_set_reveal_child (self->notification_revealer, FALSE);
-
- if (self->revealer_timeout_id != 0)
- g_source_remove (self->revealer_timeout_id);
-
- self->revealer_timeout_id = 0;
-}
-
-static gboolean
-cc_wwan_panel_on_notification_timeout (gpointer user_data)
-{
- cc_wwan_panel_on_notification_closed (user_data, NULL);
-
- return G_SOURCE_REMOVE;
-}
-
-static void
-cc_wwan_panel_notification_changed_cb (CcWwanPanel *self)
-{
- const gchar *label;
-
- label = gtk_label_get_label (self->notification_label);
-
- if (label && *label)
- {
- gtk_revealer_set_reveal_child (self->notification_revealer, TRUE);
- self->revealer_timeout_id = g_timeout_add_seconds (5, cc_wwan_panel_on_notification_timeout, self);
- }
- else
- {
- cc_wwan_panel_on_notification_closed (self, NULL);
- }
-}
-
static void
cc_wwan_panel_add_device (CcWwanPanel *self,
CcWwanDevice *device)
@@ -417,7 +365,7 @@ cc_wwan_panel_add_device (CcWwanPanel *self,
operator_name = g_strdup_printf (_("SIM %d"), n_items);
stack_name = g_strdup_printf ("sim-%d", n_items);
- device_page = cc_wwan_device_page_new (device, GTK_WIDGET (self->notification_label));
+ device_page = cc_wwan_device_page_new (device, GTK_WIDGET (self->toast_overlay));
cc_wwan_device_page_set_sim_index (device_page, n_items);
gtk_stack_add_titled (self->devices_stack,
GTK_WIDGET (device_page), stack_name, operator_name);
@@ -686,11 +634,6 @@ cc_wwan_panel_dispose (GObject *object)
{
CcWwanPanel *self = (CcWwanPanel *)object;
- if (self->revealer_timeout_id != 0)
- g_source_remove (self->revealer_timeout_id);
-
- self->revealer_timeout_id = 0;
-
g_cancellable_cancel (self->cancellable);
g_clear_object (&self->devices);
@@ -719,6 +662,7 @@ cc_wwan_panel_class_init (CcWwanPanelClass *klass)
gtk_widget_class_set_template_from_resource (widget_class,
"/org/gnome/control-center/wwan/cc-wwan-panel.ui");
+ gtk_widget_class_bind_template_child (widget_class, CcWwanPanel, toast_overlay);
gtk_widget_class_bind_template_child (widget_class, CcWwanPanel, data_list_row);
gtk_widget_class_bind_template_child (widget_class, CcWwanPanel, data_sim_select_listbox);
gtk_widget_class_bind_template_child (widget_class, CcWwanPanel, devices_stack);
@@ -726,12 +670,9 @@ cc_wwan_panel_class_init (CcWwanPanelClass *klass)
gtk_widget_class_bind_template_child (widget_class, CcWwanPanel, enable_switch);
gtk_widget_class_bind_template_child (widget_class, CcWwanPanel, main_stack);
gtk_widget_class_bind_template_child (widget_class, CcWwanPanel, multi_device_revealer);
- gtk_widget_class_bind_template_child (widget_class, CcWwanPanel, notification_label);
- gtk_widget_class_bind_template_child (widget_class, CcWwanPanel, notification_revealer);
gtk_widget_class_bind_template_callback (widget_class, wwan_data_list_selected_sim_changed_cb);
gtk_widget_class_bind_template_callback (widget_class, wwan_on_airplane_off_clicked_cb);
- gtk_widget_class_bind_template_callback (widget_class, wwan_notification_close_clicked_cb);
gtk_widget_class_bind_template_callback (widget_class, cc_wwan_data_item_activate_cb);
}
@@ -751,10 +692,6 @@ cc_wwan_panel_init (CcWwanPanel *self)
adw_combo_row_set_model (ADW_COMBO_ROW (self->data_list_row),
G_LIST_MODEL (self->data_devices_name_list));
- g_signal_connect_object (self->notification_label, "notify::label",
- G_CALLBACK (cc_wwan_panel_notification_changed_cb),
- self, G_CONNECT_SWAPPED);
-
if (cc_object_storage_has_object (CC_OBJECT_NMCLIENT))
{
self->nm_client = cc_object_storage_get_object (CC_OBJECT_NMCLIENT);
diff --git a/panels/wwan/cc-wwan-panel.ui b/panels/wwan/cc-wwan-panel.ui
index cfb5229bc..a984022af 100644
--- a/panels/wwan/cc-wwan-panel.ui
+++ b/panels/wwan/cc-wwan-panel.ui
@@ -13,40 +13,7 @@
</child>
<child type="content">
- <object class="GtkOverlay">
-
- <!-- Notification Revealer -->
- <child type="overlay">
- <object class="GtkRevealer" id="notification_revealer">
- <property name="halign">center</property>
- <property name="valign">start</property>
- <property name="child">
- <object class="GtkBox">
- <property name="spacing">12</property>
- <style>
- <class name="frame"/>
- <class name="app-notification"/>
- </style>
- <child>
- <object class="GtkLabel" id="notification_label">
- <property name="wrap">True</property>
- <property name="use-markup">True</property>
- </object>
- </child>
- <child>
- <object class="GtkButton">
- <signal name="clicked" handler="wwan_notification_close_clicked_cb" swapped="yes"/>
- <property name="icon-name">window-close-symbolic</property>
- <accessibility>
- <property name="label" translatable="yes">Close</property>
- </accessibility>
- </object>
- </child>
- </object>
- </property>
- </object>
- </child>
-
+ <object class="AdwToastOverlay" id="toast_overlay">
<property name="child">
<object class="GtkScrolledWindow">
<property name="hscrollbar-policy">never</property>
@@ -224,7 +191,6 @@
</child>
</object> <!-- ./GtkScrolledWindow -->
</property>
-
</object>
</child>
diff --git a/panels/wwan/cc-wwan-sim-lock-dialog.ui b/panels/wwan/cc-wwan-sim-lock-dialog.ui
index 4e28cf2c5..56f927bf2 100644
--- a/panels/wwan/cc-wwan-sim-lock-dialog.ui
+++ b/panels/wwan/cc-wwan-sim-lock-dialog.ui
@@ -64,38 +64,7 @@
<property name="margin-start">18</property>
<property name="margin-end">18</property>
<child>
- <object class="GtkOverlay">
- <child type="overlay">
- <object class="GtkRevealer" id="notification_revealer">
- <property name="halign">center</property>
- <property name="valign">start</property>
- <property name="child">
- <object class="GtkBox">
- <property name="spacing">12</property>
- <style>
- <class name="frame"/>
- <class name="app-notification"/>
- </style>
- <child>
- <object class="GtkLabel" id="notification_label">
- <property name="wrap">True</property>
- <property name="wrap-mode">word-char</property>
- <property name="use-markup">True</property>
- </object>
- </child>
- <child>
- <object class="GtkButton">
- <property name="icon-name">window-close-symbolic</property>
- <accessibility>
- <property name="label" translatable="yes">Close</property>
- </accessibility>
- </object>
- </child>
- </object>
- </property>
- </object>
- </child>
-
+ <object class="AdwToastOverlay" id="toast_overlay">
<property name="child">
<object class="GtkStack" id="pin_settings_stack">
<property name="transition-type">slide-left</property>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]