region: Use GtkRevealer instead of GdNotification

GtkRevealer combined with the "app-notification" class is enough
to represent the notification concept nowadays.

https://bugzilla.gnome.org/show_bug.cgi?id=775183
This commit is contained in:
Felipe Borges 2016-11-27 17:22:40 +01:00
parent b995e16c98
commit 6f51428094
2 changed files with 66 additions and 32 deletions

View file

@ -47,8 +47,6 @@
#include <act/act.h> #include <act/act.h>
#include <libgd/gd-notification.h>
#define GNOME_DESKTOP_INPUT_SOURCES_DIR "org.gnome.desktop.input-sources" #define GNOME_DESKTOP_INPUT_SOURCES_DIR "org.gnome.desktop.input-sources"
#define KEY_INPUT_SOURCES "sources" #define KEY_INPUT_SOURCES "sources"
@ -209,7 +207,7 @@ restart_now (CcRegionPanel *self)
{ {
CcRegionPanelPrivate *priv = self->priv; CcRegionPanelPrivate *priv = self->priv;
gd_notification_dismiss (GD_NOTIFICATION (self->priv->notification)); gtk_revealer_set_reveal_child (GTK_REVEALER (self->priv->notification), FALSE);
g_dbus_proxy_call (priv->session, g_dbus_proxy_call (priv->session,
"Logout", "Logout",
@ -223,42 +221,14 @@ show_restart_notification (CcRegionPanel *self,
const gchar *locale) const gchar *locale)
{ {
CcRegionPanelPrivate *priv = self->priv; CcRegionPanelPrivate *priv = self->priv;
GtkWidget *box;
GtkWidget *label;
GtkWidget *button;
gchar *current_locale = NULL; gchar *current_locale = NULL;
if (priv->notification)
return;
if (locale) { if (locale) {
current_locale = g_strdup (setlocale (LC_MESSAGES, NULL)); current_locale = g_strdup (setlocale (LC_MESSAGES, NULL));
setlocale (LC_MESSAGES, locale); setlocale (LC_MESSAGES, locale);
} }
priv->notification = gd_notification_new (); gtk_revealer_set_reveal_child (GTK_REVEALER (priv->notification), TRUE);
g_object_add_weak_pointer (G_OBJECT (priv->notification),
(gpointer *)&priv->notification);
box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 6);
gtk_widget_set_margin_start (box, 6);
gtk_widget_set_margin_end (box, 6);
gtk_widget_set_margin_top (box, 6);
gtk_widget_set_margin_bottom (box, 6);
label = gtk_label_new (_("Your session needs to be restarted for changes to take effect"));
gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
gtk_label_set_max_width_chars (GTK_LABEL (label), 30);
g_object_set (G_OBJECT (label), "xalign", 0, NULL);
button = gtk_button_new_with_label (_("Restart Now"));
gtk_widget_set_valign (button, GTK_ALIGN_CENTER);
g_signal_connect_swapped (button, "clicked",
G_CALLBACK (restart_now), self);
gtk_box_pack_start (GTK_BOX (box), label, FALSE, FALSE, 0);
gtk_box_pack_start (GTK_BOX (box), button, FALSE, FALSE, 0);
gtk_widget_show_all (box);
gtk_container_add (GTK_CONTAINER (priv->notification), box);
gtk_overlay_add_overlay (GTK_OVERLAY (self->priv->overlay), priv->notification);
gtk_widget_show (priv->notification);
if (locale) { if (locale) {
setlocale (LC_MESSAGES, current_locale); setlocale (LC_MESSAGES, current_locale);
@ -266,6 +236,14 @@ show_restart_notification (CcRegionPanel *self,
} }
} }
static void
dismiss_notification (CcRegionPanel *self)
{
CcRegionPanelPrivate *priv = self->priv;
gtk_revealer_set_reveal_child (GTK_REVEALER (priv->notification), FALSE);
}
typedef struct { typedef struct {
CcRegionPanel *self; CcRegionPanel *self;
int category; int category;
@ -1818,6 +1796,7 @@ static void
cc_region_panel_init (CcRegionPanel *self) cc_region_panel_init (CcRegionPanel *self)
{ {
CcRegionPanelPrivate *priv; CcRegionPanelPrivate *priv;
GtkWidget *button;
GError *error = NULL; GError *error = NULL;
priv = self->priv = REGION_PANEL_PRIVATE (self); priv = self->priv = REGION_PANEL_PRIVATE (self);
@ -1848,6 +1827,14 @@ cc_region_panel_init (CcRegionPanel *self)
session_proxy_ready, session_proxy_ready,
self); self);
priv->notification = GTK_WIDGET (gtk_builder_get_object (priv->builder, "notification"));
button = GTK_WIDGET (gtk_builder_get_object (priv->builder, "restart-button"));
g_signal_connect_swapped (button, "clicked", G_CALLBACK (restart_now), self);
button = GTK_WIDGET (gtk_builder_get_object (priv->builder, "dismiss-button"));
g_signal_connect_swapped (button, "clicked", G_CALLBACK (dismiss_notification), self);
setup_login_button (self); setup_login_button (self);
setup_language_section (self); setup_language_section (self);
setup_input_section (self); setup_input_section (self);

View file

@ -3,6 +3,53 @@
<!-- interface-requires gtk+ 3.0 --> <!-- interface-requires gtk+ 3.0 -->
<object class="GtkOverlay" id="overlay"> <object class="GtkOverlay" id="overlay">
<property name="visible">True</property> <property name="visible">True</property>
<child type="overlay">
<object class="GtkRevealer" id="notification">
<property name="visible">True</property>
<property name="halign">GTK_ALIGN_CENTER</property>
<property name="valign">GTK_ALIGN_START</property>
<child>
<object class="GtkBox">
<property name="visible">True</property>
<property name="spacing">6</property>
<style>
<class name="app-notification"/>
</style>
<child>
<object class="GtkLabel">
<property name="visible">True</property>
<property name="wrap">True</property>
<property name="max_width_chars">30</property>
<property name="label" translatable="yes">Your session needs to be restarted for changes to take effect</property>
</object>
</child>
<child>
<object class="GtkButton" id="restart-button">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="valign">GTK_ALIGN_CENTER</property>
<property name="label" translatable="yes">Restart Now</property>
</object>
</child>
<child>
<object class="GtkButton" id="dismiss-button">
<property name="visible">True</property>
<property name="valign">GTK_ALIGN_CENTER</property>
<style>
<class name="flat"/>
</style>
<child>
<object class="GtkImage">
<property name="visible">True</property>
<property name="icon_name">window-close-symbolic</property>
</object>
</child>
</object>
</child>
</object>
</child>
</object>
</child>
<child> <child>
<object class="GtkBox" id="vbox_region"> <object class="GtkBox" id="vbox_region">
<property name="visible">True</property> <property name="visible">True</property>