[epiphany] lib/widgets: Have a more generic notification



commit 8e7bc4f1243aa8d36be128db951c3407b9dafebe
Author: Gabriel Ivascu <ivascu gabriel59 gmail com>
Date:   Mon Dec 5 15:38:47 2016 +0200

    lib/widgets: Have a more generic notification

 lib/widgets/Makefile.am                            |    4 +-
 lib/widgets/ephy-notification.c                    |  171 ++++++++++++++++++++
 ...password-notification.h => ephy-notification.h} |   10 +-
 lib/widgets/ephy-password-notification.c           |  167 -------------------
 po/POTFILES.in                                     |    1 +
 src/sync/ephy-sync-service.c                       |   15 ++-
 6 files changed, 190 insertions(+), 178 deletions(-)
---
diff --git a/lib/widgets/Makefile.am b/lib/widgets/Makefile.am
index 5f4aae1..869b1f3 100644
--- a/lib/widgets/Makefile.am
+++ b/lib/widgets/Makefile.am
@@ -72,8 +72,8 @@ libephywidgets_la_SOURCES = \
        ephy-location-entry.h                   \
        ephy-middle-clickable-button.c          \
        ephy-middle-clickable-button.h          \
-       ephy-password-notification.c            \
-       ephy-password-notification.h            \
+       ephy-notification.c                     \
+       ephy-notification.h                     \
        ephy-security-popover.c                 \
        ephy-security-popover.h                 \
        ephy-title-box.c                        \
diff --git a/lib/widgets/ephy-notification.c b/lib/widgets/ephy-notification.c
new file mode 100644
index 0000000..35740a6
--- /dev/null
+++ b/lib/widgets/ephy-notification.c
@@ -0,0 +1,171 @@
+/* -*- Mode: C; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/*
+ *  Copyright © 2016 Gabriel Ivascu <ivascu gabriel59 gmail com>
+ *
+ *  This file is part of Epiphany.
+ *
+ *  Epiphany is free software: you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation, either version 3 of the License, or
+ *  (at your option) any later version.
+ *
+ *  Epiphany is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with Epiphany.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "config.h"
+#include "ephy-notification.h"
+
+#include "ephy-notification-container.h"
+
+struct _EphyNotification {
+  GtkGrid    parent_instance;
+
+  GtkWidget *head;
+  GtkWidget *body;
+
+  char      *head_msg;
+  char      *body_msg;
+};
+
+struct _EphyNotificationClass {
+  GtkGridClass parent_class;
+};
+
+enum {
+  PROP_0,
+  PROP_HEAD,
+  PROP_BODY
+};
+
+G_DEFINE_TYPE (EphyNotification, ephy_notification, GTK_TYPE_GRID);
+
+static void
+ephy_notification_constructed (GObject *object)
+{
+  EphyNotification *self = EPHY_NOTIFICATION (object);
+
+  G_OBJECT_CLASS (ephy_notification_parent_class)->constructed (object);
+
+  gtk_label_set_text (GTK_LABEL (self->head), self->head_msg);
+  gtk_label_set_text (GTK_LABEL (self->body), self->body_msg);
+}
+
+static void
+ephy_notification_finalize (GObject *object)
+{
+  EphyNotification *self = EPHY_NOTIFICATION (object);
+
+  g_free (self->head_msg);
+  g_free (self->body_msg);
+
+  G_OBJECT_CLASS (ephy_notification_parent_class)->finalize (object);
+}
+
+static void
+ephy_notification_set_property (GObject      *object,
+                                guint         prop_id,
+                                const GValue *value,
+                                GParamSpec   *pspec)
+{
+  EphyNotification *self = EPHY_NOTIFICATION (object);
+
+  switch (prop_id) {
+    case PROP_HEAD:
+      self->head_msg = g_value_dup_string (value);
+      break;
+    case PROP_BODY:
+      self->body_msg = g_value_dup_string (value);
+      break;
+    default:
+      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+      break;
+  }
+}
+
+static void
+ephy_notification_get_property (GObject    *object,
+                                guint       prop_id,
+                                GValue     *value,
+                                GParamSpec *pspec)
+{
+  EphyNotification *self = EPHY_NOTIFICATION (object);
+
+  switch (prop_id) {
+    case PROP_HEAD:
+      g_value_set_string (value, self->head_msg);
+      break;
+    case PROP_BODY:
+      g_value_set_string (value, self->body_msg);
+      break;
+    default:
+      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+      break;
+  }
+}
+
+static void
+ephy_notification_init (EphyNotification *self)
+{
+  self->head = gtk_label_new (NULL);
+  gtk_widget_set_halign (self->head, GTK_ALIGN_CENTER);
+  gtk_widget_set_hexpand (self->head, TRUE);
+  gtk_grid_attach (GTK_GRID (self), self->head, 0, 0, 1, 1);
+
+  self->body = gtk_label_new (NULL);
+  gtk_widget_set_halign (self->body, GTK_ALIGN_CENTER);
+  gtk_widget_set_hexpand (self->body, TRUE);
+  gtk_grid_attach (GTK_GRID (self), self->body, 0, 1, 1, 1);
+}
+
+static void
+ephy_notification_class_init (EphyNotificationClass *klass)
+{
+  GObjectClass *object_class = G_OBJECT_CLASS (klass);
+
+  object_class->constructed = ephy_notification_constructed;
+  object_class->finalize = ephy_notification_finalize;
+  object_class->set_property = ephy_notification_set_property;
+  object_class->get_property = ephy_notification_get_property;
+
+  g_object_class_install_property (object_class,
+                                   PROP_HEAD,
+                                   g_param_spec_string ("head",
+                                                        "Head",
+                                                        "The notification head",
+                                                        "",
+                                                        G_PARAM_STATIC_STRINGS | G_PARAM_CONSTRUCT_ONLY | 
G_PARAM_WRITABLE));
+  g_object_class_install_property (object_class,
+                                   PROP_BODY,
+                                   g_param_spec_string ("body",
+                                                        "Body",
+                                                        "The notification body",
+                                                        "",
+                                                        G_PARAM_STATIC_STRINGS | G_PARAM_CONSTRUCT_ONLY | 
G_PARAM_WRITABLE));
+}
+
+EphyNotification *
+ephy_notification_new (const char *head,
+                       const char *body)
+{
+  return g_object_new (EPHY_TYPE_NOTIFICATION,
+                       "column-spacing", 12,
+                       "orientation", GTK_ORIENTATION_HORIZONTAL,
+                       "head", head,
+                       "body", body,
+                       NULL);
+}
+
+void
+ephy_notification_show (EphyNotification *self)
+{
+  g_return_if_fail (EPHY_IS_NOTIFICATION (self));
+
+  ephy_notification_container_add_notification (ephy_notification_container_get_default (),
+                                                GTK_WIDGET (self));
+}
diff --git a/lib/widgets/ephy-password-notification.h b/lib/widgets/ephy-notification.h
similarity index 71%
rename from lib/widgets/ephy-password-notification.h
rename to lib/widgets/ephy-notification.h
index bbb1026..0d7e492 100644
--- a/lib/widgets/ephy-password-notification.h
+++ b/lib/widgets/ephy-notification.h
@@ -25,12 +25,12 @@
 
 G_BEGIN_DECLS
 
-#define EPHY_TYPE_PASSWORD_NOTIFICATION (ephy_password_notification_get_type ())
+#define EPHY_TYPE_NOTIFICATION (ephy_notification_get_type ())
 
-G_DECLARE_FINAL_TYPE (EphyPasswordNotification, ephy_password_notification, EPHY, PASSWORD_NOTIFICATION, 
GtkGrid)
+G_DECLARE_FINAL_TYPE (EphyNotification, ephy_notification, EPHY, NOTIFICATION, GtkGrid)
 
-EphyPasswordNotification *ephy_password_notification_new  (const char *user);
-
-void                      ephy_password_notification_show (EphyPasswordNotification *self);
+EphyNotification *ephy_notification_new  (const char *head,
+                                          const char *body);
+void              ephy_notification_show (EphyNotification *self);
 
 G_END_DECLS
diff --git a/po/POTFILES.in b/po/POTFILES.in
index 11215b0..e3ecff0 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -57,4 +57,5 @@ src/resources/prefs-lang-dialog.ui
 src/resources/shortcuts-dialog.ui
 src/search-provider/ephy-search-provider.c
 src/sync/ephy-sync-secret.c
+src/sync/ephy-sync-service.c
 src/window-commands.c
diff --git a/src/sync/ephy-sync-service.c b/src/sync/ephy-sync-service.c
index b43cf3f..2e98b50 100644
--- a/src/sync/ephy-sync-service.c
+++ b/src/sync/ephy-sync-service.c
@@ -25,12 +25,13 @@
 #include "ephy-bookmarks-manager.h"
 #include "ephy-debug.h"
 #include "ephy-embed-prefs.h"
-#include "ephy-password-notification.h"
+#include "ephy-notification.h"
 #include "ephy-settings.h"
 #include "ephy-shell.h"
 #include "ephy-sync-crypto.h"
 #include "ephy-sync-secret.h"
 
+#include <glib/gi18n.h>
 #include <json-glib/json-glib.h>
 #include <string.h>
 
@@ -445,7 +446,6 @@ obtain_signed_certificate_response_cb (SoupSession *session,
 {
   StorageServerRequestAsyncData *data;
   EphySyncService *service;
-  EphyPasswordNotification *notification;
   JsonParser *parser;
   JsonObject *json;
   const char *certificate;
@@ -462,9 +462,16 @@ obtain_signed_certificate_response_cb (SoupSession *session,
    * if the user has changed his password since the last time he signed in.
    * When this happens, notify the user to sign in with the new password. */
   if (msg->status_code == 401 && json_object_get_int_member (json, "errno") == 110) {
-    notification = ephy_password_notification_new (ephy_sync_service_get_user_email (service));
-    ephy_password_notification_show (notification);
+    char *error = g_strdup_printf (_("The password of your Firefox account %s "
+                                     "seems to have been changed."),
+                                   ephy_sync_service_get_user_email (service));
+    const char *suggestion = _("Please visit Preferences and sign in with "
+                               "the new password to continue the sync process.");
+
+    ephy_notification_show (ephy_notification_new (error, suggestion));
+
     storage_server_request_async_data_free (data);
+    g_free (error);
     service->locked = FALSE;
     goto out;
   }


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]