[epiphany/wip/sync-rebase: 57/74] ephy-notification-manager: Rename to ephy-notification-container



commit 9918b4bfe9e3624a374f4e95095d59c8914de490
Author: Gabriel Ivascu <ivascu gabriel59 gmail com>
Date:   Tue Aug 30 15:39:29 2016 +0300

    ephy-notification-manager: Rename to ephy-notification-container

 embed/Makefile.am                        |    4 +-
 embed/ephy-embed.c                       |   25 ++++---
 embed/ephy-embed.h                       |   34 +++++-----
 embed/ephy-notification-container.c      |   81 +++++++++++++++++++++
 embed/ephy-notification-container.h      |   52 ++++++++++++++
 embed/ephy-notification-manager.c        |  112 ------------------------------
 embed/ephy-notification-manager.h        |   50 -------------
 lib/widgets/ephy-password-notification.c |    6 +-
 src/ephy-window.c                        |    4 +-
 9 files changed, 170 insertions(+), 198 deletions(-)
---
diff --git a/embed/Makefile.am b/embed/Makefile.am
index e2f4da4..bc6d4a8 100644
--- a/embed/Makefile.am
+++ b/embed/Makefile.am
@@ -42,8 +42,8 @@ libephyembed_la_SOURCES = \
        ephy-find-toolbar.h             \
        ephy-hosts-manager.c            \
        ephy-hosts-manager.h            \
-       ephy-notification-manager.c     \
-       ephy-notification-manager.h     \
+       ephy-notification-container.c   \
+       ephy-notification-container.h   \
        ephy-view-source-handler.c      \
        ephy-view-source-handler.h      \
        ephy-web-view.c                 \
diff --git a/embed/ephy-embed.c b/embed/ephy-embed.c
index 9faaa5d..88ad4db 100644
--- a/embed/ephy-embed.c
+++ b/embed/ephy-embed.c
@@ -28,7 +28,7 @@
 #include "ephy-embed-shell.h"
 #include "ephy-embed-utils.h"
 #include "ephy-find-toolbar.h"
-#include "ephy-notification-manager.h"
+#include "ephy-notification-container.h"
 #include "ephy-prefs.h"
 #include "ephy-settings.h"
 #include "ephy-string.h"
@@ -949,26 +949,27 @@ ephy_embed_inspector_is_loaded (EphyEmbed *embed)
 }
 
 void
-ephy_embed_attach_notification_manager (EphyEmbed *embed)
+ephy_embed_attach_notification_container (EphyEmbed *embed)
 {
-  EphyNotificationManager *manager;
+  EphyNotificationContainer *container;
 
   g_return_if_fail (EPHY_IS_EMBED (embed));
 
-  manager = ephy_notification_manager_dup_singleton ();
-  gtk_overlay_add_overlay (GTK_OVERLAY (embed->overlay), GTK_WIDGET (manager));
-
-  if (ephy_notification_manager_get_children_num (manager) == 0)
-    gtk_widget_hide (GTK_WIDGET (manager));
+  container = ephy_notification_container_get_default ();
+  gtk_overlay_add_overlay (GTK_OVERLAY (embed->overlay), GTK_WIDGET (container));
 }
 
 void
-ephy_embed_detach_notification_manager (EphyEmbed *embed)
+ephy_embed_detach_notification_container (EphyEmbed *embed)
 {
-  EphyNotificationManager *manager;
+  EphyNotificationContainer *container;
 
   g_return_if_fail (EPHY_IS_EMBED (embed));
 
-  manager = ephy_notification_manager_dup_singleton ();
-  gtk_container_remove (GTK_CONTAINER (embed->overlay), GTK_WIDGET (manager));
+  container = ephy_notification_container_get_default ();
+  /* Since the overlay container will own the one and only reference to the
+   * notification widget, removing it from the container will destroy the
+   * singleton. To prevent this, add a reference to it before removing it
+   * from the container. */
+  gtk_container_remove (GTK_CONTAINER (embed->overlay), g_object_ref (container));
 }
diff --git a/embed/ephy-embed.h b/embed/ephy-embed.h
index dd6c85d..45a1aa0 100644
--- a/embed/ephy-embed.h
+++ b/embed/ephy-embed.h
@@ -30,22 +30,22 @@ G_BEGIN_DECLS
 
 G_DECLARE_FINAL_TYPE (EphyEmbed, ephy_embed, EPHY, EMBED, GtkBox)
 
-EphyWebView*     ephy_embed_get_web_view                (EphyEmbed  *embed);
-EphyFindToolbar* ephy_embed_get_find_toolbar            (EphyEmbed  *embed);
-void             ephy_embed_add_top_widget              (EphyEmbed  *embed,
-                                                         GtkWidget  *widget,
-                                                         gboolean    destroy_on_transition);
-void             ephy_embed_remove_top_widget           (EphyEmbed  *embed,
-                                                         GtkWidget  *widget);
-void             ephy_embed_entering_fullscreen         (EphyEmbed *embed);
-void             ephy_embed_leaving_fullscreen          (EphyEmbed *embed);
-void             ephy_embed_set_delayed_load_request    (EphyEmbed *embed,
-                                                         WebKitURIRequest          *request,
-                                                         WebKitWebViewSessionState *state);
-gboolean         ephy_embed_has_load_pending            (EphyEmbed *embed);
-gboolean         ephy_embed_inspector_is_loaded         (EphyEmbed *embed);
-const char      *ephy_embed_get_title                   (EphyEmbed *embed);
-void             ephy_embed_attach_notification_manager (EphyEmbed *embed);
-void             ephy_embed_detach_notification_manager (EphyEmbed *embed);
+EphyWebView*     ephy_embed_get_web_view                  (EphyEmbed  *embed);
+EphyFindToolbar* ephy_embed_get_find_toolbar              (EphyEmbed  *embed);
+void             ephy_embed_add_top_widget                (EphyEmbed  *embed,
+                                                           GtkWidget  *widget,
+                                                           gboolean    destroy_on_transition);
+void             ephy_embed_remove_top_widget             (EphyEmbed  *embed,
+                                                           GtkWidget  *widget);
+void             ephy_embed_entering_fullscreen           (EphyEmbed *embed);
+void             ephy_embed_leaving_fullscreen            (EphyEmbed *embed);
+void             ephy_embed_set_delayed_load_request      (EphyEmbed *embed,
+                                                           WebKitURIRequest          *request,
+                                                           WebKitWebViewSessionState *state);
+gboolean         ephy_embed_has_load_pending              (EphyEmbed *embed);
+gboolean         ephy_embed_inspector_is_loaded           (EphyEmbed *embed);
+const char      *ephy_embed_get_title                     (EphyEmbed *embed);
+void             ephy_embed_attach_notification_container (EphyEmbed *embed);
+void             ephy_embed_detach_notification_container (EphyEmbed *embed);
 
 G_END_DECLS
diff --git a/embed/ephy-notification-container.c b/embed/ephy-notification-container.c
new file mode 100644
index 0000000..a683fec
--- /dev/null
+++ b/embed/ephy-notification-container.c
@@ -0,0 +1,81 @@
+/* -*- Mode: C; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/*
+ *  Copyright © 2016 Gabriel Ivascu <ivascu gabriel59 gmail com>
+ *
+ *  This program 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 2, or (at your option)
+ *  any later version.
+ *
+ *  This program 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 this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "config.h"
+#include "ephy-notification-container.h"
+
+struct _EphyNotificationContainer {
+  GdNotification  parent_instance;
+
+  GtkWidget      *grid;
+};
+
+struct _EphyNotificationContainerClass {
+  GdNotificationClass parent_class;
+};
+
+G_DEFINE_TYPE (EphyNotificationContainer, ephy_notification_container, GD_TYPE_NOTIFICATION);
+
+static EphyNotificationContainer *notification_container = NULL;
+
+static void
+ephy_notification_container_init (EphyNotificationContainer *self)
+{
+  /* Globally accessible singleton */
+  g_assert (notification_container == NULL);
+  notification_container = self;
+  g_object_add_weak_pointer (G_OBJECT (notification_container),
+                             (gpointer *)&notification_container);
+
+  gtk_widget_set_halign (GTK_WIDGET (self), GTK_ALIGN_CENTER);
+  gtk_widget_set_valign (GTK_WIDGET (self), GTK_ALIGN_START);
+  gtk_widget_set_visible (GTK_WIDGET (self), TRUE);
+
+  self->grid = gtk_grid_new ();
+  gtk_orientable_set_orientation (GTK_ORIENTABLE (self->grid), GTK_ORIENTATION_VERTICAL);
+  gtk_grid_set_row_spacing (GTK_GRID (self->grid), 6);
+  gtk_container_add (GTK_CONTAINER (self), self->grid);
+}
+
+static void
+ephy_notification_container_class_init (EphyNotificationContainerClass *klass)
+{
+}
+
+EphyNotificationContainer *
+ephy_notification_container_get_default (void)
+{
+  if (notification_container != NULL)
+    return notification_container;
+
+  return g_object_new (EPHY_TYPE_NOTIFICATION_CONTAINER,
+                       "show-close-button", TRUE,
+                       "timeout", -1,
+                       NULL);
+}
+
+void
+ephy_notification_container_add_notification (EphyNotificationContainer *self,
+                                              GtkWidget                 *notification)
+{
+  g_return_if_fail (EPHY_IS_NOTIFICATION_CONTAINER (self));
+  g_return_if_fail (GTK_IS_WIDGET (notification));
+
+  gtk_container_add (GTK_CONTAINER (self->grid), notification);
+  gtk_widget_show_all (GTK_WIDGET (self));
+}
diff --git a/embed/ephy-notification-container.h b/embed/ephy-notification-container.h
new file mode 100644
index 0000000..30628ed
--- /dev/null
+++ b/embed/ephy-notification-container.h
@@ -0,0 +1,52 @@
+/* -*- Mode: C; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/*
+ *  Copyright © 2016 Gabriel Ivascu <ivascu gabriel59 gmail com>
+ *
+ *  This program 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 2, or (at your option)
+ *  any later version.
+ *
+ *  This program 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 this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef EPHY_NOTIFICATION_CONTAINER_H
+#define EPHY_NOTIFICATION_CONTAINER_H
+
+#include <libgd/gd.h>
+
+G_BEGIN_DECLS
+
+#define EPHY_TYPE_NOTIFICATION_CONTAINER (ephy_notification_container_get_type ())
+
+/* FIXME: Replace this boilerplate with G_DECLARE_FINAL_TYPE. This won't prove
+ * trivial, since G_DECLARE_FINAL_TYPE requires that an autocleanup function
+ * has been declared for the parent type, and libgd doesn't have one yet.
+ */
+#define EPHY_NOTIFICATION_CONTAINER(obj) \
+  (G_TYPE_CHECK_INSTANCE_CAST ((obj), \
+   EPHY_TYPE_NOTIFICATION_CONTAINER, EphyNotificationContainer))
+
+#define EPHY_IS_NOTIFICATION_CONTAINER(obj) \
+  (G_TYPE_CHECK_INSTANCE_TYPE ((obj), \
+   EPHY_TYPE_NOTIFICATION_CONTAINER))
+
+typedef struct _EphyNotificationContainer      EphyNotificationContainer;
+typedef struct _EphyNotificationContainerClass EphyNotificationContainerClass;
+
+GType                      ephy_notification_container_get_type         (void) G_GNUC_CONST;
+
+EphyNotificationContainer *ephy_notification_container_get_default      (void);
+
+void                       ephy_notification_container_add_notification (EphyNotificationContainer *self,
+                                                                         GtkWidget                 
*notification);
+
+G_END_DECLS
+
+#endif
diff --git a/lib/widgets/ephy-password-notification.c b/lib/widgets/ephy-password-notification.c
index 091c94f..2b553b1 100644
--- a/lib/widgets/ephy-password-notification.c
+++ b/lib/widgets/ephy-password-notification.c
@@ -19,7 +19,7 @@
 #include "config.h"
 #include "ephy-password-notification.h"
 
-#include "ephy-notification-manager.h"
+#include "ephy-notification-container.h"
 
 #include <glib/gi18n.h>
 
@@ -160,6 +160,6 @@ ephy_password_notification_show (EphyPasswordNotification *self)
 {
   g_return_if_fail (EPHY_IS_PASSWORD_NOTIFICATION (self));
 
-  ephy_notification_manager_add_notification (ephy_notification_manager_dup_singleton (),
-                                              GTK_WIDGET (self));
+  ephy_notification_container_add_notification (ephy_notification_container_get_default (),
+                                                GTK_WIDGET (self));
 }
diff --git a/src/ephy-window.c b/src/ephy-window.c
index 1c60770..b363f0e 100644
--- a/src/ephy-window.c
+++ b/src/ephy-window.c
@@ -2078,7 +2078,7 @@ ephy_window_connect_active_embed (EphyWindow *window)
   view = ephy_embed_get_web_view (embed);
   web_view = EPHY_GET_WEBKIT_WEB_VIEW_FROM_EMBED (embed);
 
-  ephy_embed_attach_notification_manager (window->active_embed);
+  ephy_embed_attach_notification_container (window->active_embed);
 
   sync_tab_security (view, NULL, window);
   sync_tab_document_type (view, NULL, window);
@@ -2160,7 +2160,7 @@ ephy_window_disconnect_active_embed (EphyWindow *window)
   web_view = EPHY_GET_WEBKIT_WEB_VIEW_FROM_EMBED (embed);
   view = EPHY_WEB_VIEW (web_view);
 
-  ephy_embed_detach_notification_manager (window->active_embed);
+  ephy_embed_detach_notification_container (window->active_embed);
 
   g_signal_handlers_disconnect_by_func (web_view,
                                         G_CALLBACK (sync_tab_zoom),


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