Commit 8e7bc4f1 authored by Gabriel Ivașcu's avatar Gabriel Ivașcu
Browse files

lib/widgets: Have a more generic notification

parent da9b7a70
......@@ -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 \
......
......@@ -19,76 +19,68 @@
*/
#include "config.h"
#include "ephy-password-notification.h"
#include "ephy-notification.h"
#include "ephy-notification-container.h"
#include <glib/gi18n.h>
struct _EphyPasswordNotification {
struct _EphyNotification {
GtkGrid parent_instance;
GtkWidget *note;
GtkWidget *suggestion;
GtkWidget *head;
GtkWidget *body;
char *user;
char *head_msg;
char *body_msg;
};
struct _EphyPasswordNotificationClass {
struct _EphyNotificationClass {
GtkGridClass parent_class;
};
enum {
PROP_0,
PROP_USER
PROP_HEAD,
PROP_BODY
};
G_DEFINE_TYPE (EphyPasswordNotification, ephy_password_notification, GTK_TYPE_GRID);
G_DEFINE_TYPE (EphyNotification, ephy_notification, GTK_TYPE_GRID);
static void
ephy_password_notification_constructed (GObject *object)
ephy_notification_constructed (GObject *object)
{
EphyPasswordNotification *self = EPHY_PASSWORD_NOTIFICATION (object);
char *account;
char *text;
account = g_strdup_printf ("<b>%s</b>", self->user);
text = g_strdup_printf (_("The password of your Firefox account %s "
"seems to have been changed."),
account);
EphyNotification *self = EPHY_NOTIFICATION (object);
gtk_label_set_markup (GTK_LABEL (self->note), text);
gtk_label_set_text (GTK_LABEL (self->suggestion),
_("Please visit Preferences and sign in with the new "
"password to continue the sync process."));
G_OBJECT_CLASS (ephy_notification_parent_class)->constructed (object);
g_free (account);
g_free (text);
G_OBJECT_CLASS (ephy_password_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_password_notification_finalize (GObject *object)
ephy_notification_finalize (GObject *object)
{
EphyPasswordNotification *self = EPHY_PASSWORD_NOTIFICATION (object);
EphyNotification *self = EPHY_NOTIFICATION (object);
g_free (self->user);
g_free (self->head_msg);
g_free (self->body_msg);
G_OBJECT_CLASS (ephy_password_notification_parent_class)->finalize (object);
G_OBJECT_CLASS (ephy_notification_parent_class)->finalize (object);
}
static void
ephy_password_notification_set_property (GObject *object,
guint prop_id,
const GValue *value,
GParamSpec *pspec)
ephy_notification_set_property (GObject *object,
guint prop_id,
const GValue *value,
GParamSpec *pspec)
{
EphyPasswordNotification *self = EPHY_PASSWORD_NOTIFICATION (object);
EphyNotification *self = EPHY_NOTIFICATION (object);
switch (prop_id) {
case PROP_USER:
self->user = g_value_dup_string (value);
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);
......@@ -97,16 +89,19 @@ ephy_password_notification_set_property (GObject *object,
}
static void
ephy_password_notification_get_property (GObject *object,
guint prop_id,
GValue *value,
GParamSpec *pspec)
ephy_notification_get_property (GObject *object,
guint prop_id,
GValue *value,
GParamSpec *pspec)
{
EphyPasswordNotification *self = EPHY_PASSWORD_NOTIFICATION (object);
EphyNotification *self = EPHY_NOTIFICATION (object);
switch (prop_id) {
case PROP_USER:
g_value_set_string (value, self->user);
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);
......@@ -115,52 +110,61 @@ ephy_password_notification_get_property (GObject *object,
}
static void
ephy_password_notification_init (EphyPasswordNotification *self)
ephy_notification_init (EphyNotification *self)
{
self->note = gtk_label_new (NULL);
gtk_widget_set_halign (self->note, GTK_ALIGN_CENTER);
gtk_widget_set_hexpand (self->note, TRUE);
gtk_grid_attach (GTK_GRID (self), self->note, 0, 0, 1, 1);
self->suggestion = gtk_label_new (NULL);
gtk_widget_set_halign (self->suggestion, GTK_ALIGN_CENTER);
gtk_widget_set_hexpand (self->suggestion, TRUE);
gtk_grid_attach (GTK_GRID (self), self->suggestion, 0, 1, 1, 1);
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_password_notification_class_init (EphyPasswordNotificationClass *klass)
ephy_notification_class_init (EphyNotificationClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
object_class->constructed = ephy_password_notification_constructed;
object_class->finalize = ephy_password_notification_finalize;
object_class->set_property = ephy_password_notification_set_property;
object_class->get_property = ephy_password_notification_get_property;
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_USER,
g_param_spec_string ("user",
"User",
"The email of the signed in user",
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));
}
EphyPasswordNotification *
ephy_password_notification_new (const char *user)
EphyNotification *
ephy_notification_new (const char *head,
const char *body)
{
return g_object_new (EPHY_TYPE_PASSWORD_NOTIFICATION,
return g_object_new (EPHY_TYPE_NOTIFICATION,
"column-spacing", 12,
"orientation", GTK_ORIENTATION_HORIZONTAL,
"user", user,
"head", head,
"body", body,
NULL);
}
void
ephy_password_notification_show (EphyPasswordNotification *self)
ephy_notification_show (EphyNotification *self)
{
g_return_if_fail (EPHY_IS_PASSWORD_NOTIFICATION (self));
g_return_if_fail (EPHY_IS_NOTIFICATION (self));
ephy_notification_container_add_notification (ephy_notification_container_get_default (),
GTK_WIDGET (self));
......
......@@ -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
......@@ -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
......@@ -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;
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment