[epiphany] EphyCookiesDialog: Make final class.



commit 87dea3e369e85e25c999771becd3f39a4ef77762
Author: Arnaud Bonatti <arnaud bonatti gmail com>
Date:   Wed Nov 4 11:25:58 2015 +0100

    EphyCookiesDialog: Make final class.

 src/cookies-dialog.c            |  161 +++++++++++++++++++--------------------
 src/cookies-dialog.h            |   32 +-------
 src/prefs-dialog.c              |    7 +-
 src/resources/cookies-dialog.ui |    2 +-
 4 files changed, 87 insertions(+), 115 deletions(-)
---
diff --git a/src/cookies-dialog.c b/src/cookies-dialog.c
index 049d8d4..7f17c25 100644
--- a/src/cookies-dialog.c
+++ b/src/cookies-dialog.c
@@ -39,8 +39,10 @@ enum
        COL_COOKIES_DATA,
 };
 
-struct CookiesDialogPrivate
+struct _EphyCookiesDialog
 {
+       GtkDialog parent_instance;
+
        GtkWidget *cookies_treeview;
        GtkTreeSelection *tree_selection;
        GtkWidget *liststore;
@@ -55,65 +57,55 @@ struct CookiesDialogPrivate
        char *search_text;
 };
 
-G_DEFINE_TYPE_WITH_PRIVATE (CookiesDialog, cookies_dialog, GTK_TYPE_DIALOG)
+G_DEFINE_TYPE (EphyCookiesDialog, ephy_cookies_dialog, GTK_TYPE_DIALOG)
 
-static void populate_model    (CookiesDialog       *dialog);
+static void populate_model    (EphyCookiesDialog   *dialog);
 static void cookie_changed_cb (WebKitCookieManager *cookie_manager,
-                              CookiesDialog       *dialog);
+                               EphyCookiesDialog   *dialog);
 
 static void
-reload_model (CookiesDialog *dialog)
+reload_model (EphyCookiesDialog *dialog)
 {
-       g_signal_handlers_disconnect_by_func (dialog->priv->cookie_manager, cookie_changed_cb, dialog);
-       gtk_list_store_clear (GTK_LIST_STORE (dialog->priv->liststore));
-       dialog->priv->filled = FALSE;
+       g_signal_handlers_disconnect_by_func (dialog->cookie_manager, cookie_changed_cb, dialog);
+       gtk_list_store_clear (GTK_LIST_STORE (dialog->liststore));
+       dialog->filled = FALSE;
        populate_model (dialog);
 }
 
 static void
 cookie_changed_cb (WebKitCookieManager *cookie_manager,
-                  CookiesDialog       *dialog)
+                   EphyCookiesDialog   *dialog)
 {
        reload_model (dialog);
 }
 
 static void
-cookies_dialog_dispose (GObject *object)
+ephy_cookies_dialog_dispose (GObject *object)
 {
-       CookiesDialogPrivate *priv;
-
-       priv = EPHY_COOKIES_DIALOG (object)->priv;
-
-       g_signal_handlers_disconnect_by_func (priv->cookie_manager, cookie_changed_cb, object);
-
-       G_OBJECT_CLASS (cookies_dialog_parent_class)->dispose (object);
+       g_signal_handlers_disconnect_by_func (EPHY_COOKIES_DIALOG (object)->cookie_manager, 
cookie_changed_cb, object);
+       G_OBJECT_CLASS (ephy_cookies_dialog_parent_class)->dispose (object);
 }
 
 static void
-cookies_dialog_finalize (GObject *object)
+ephy_cookies_dialog_finalize (GObject *object)
 {
-       CookiesDialogPrivate *priv;
-
-       priv = EPHY_COOKIES_DIALOG (object)->priv;
-
-       g_free (priv->search_text);
-       G_OBJECT_CLASS (cookies_dialog_parent_class)->finalize (object);
+       g_free (EPHY_COOKIES_DIALOG (object)->search_text);
+       G_OBJECT_CLASS (ephy_cookies_dialog_parent_class)->finalize (object);
 }
 
 static void
-cookie_remove (CookiesDialog *dialog,
+cookie_remove (EphyCookiesDialog *dialog,
               gpointer data)
 {
        const char *domain = (const char *) data;
 
-       webkit_cookie_manager_delete_cookies_for_domain (dialog->priv->cookie_manager,
-                                                        domain);
+       webkit_cookie_manager_delete_cookies_for_domain (dialog->cookie_manager, domain);
 }
 
 static void
-forget (GSimpleAction *action,
-        GVariant      *parameter,
-        CookiesDialog *dialog)
+forget (GSimpleAction     *action,
+        GVariant          *parameter,
+        EphyCookiesDialog *dialog)
 {
        GList *llist, *rlist = NULL, *l, *r;
        GtkTreeModel *model;
@@ -121,7 +113,7 @@ forget (GSimpleAction *action,
        GtkTreeIter iter, iter2;
        GtkTreeRowReference *row_ref = NULL;
 
-       llist = gtk_tree_selection_get_selected_rows (dialog->priv->tree_selection, &model);
+       llist = gtk_tree_selection_get_selected_rows (dialog->tree_selection, &model);
 
        if (llist == NULL)
        {
@@ -171,15 +163,15 @@ forget (GSimpleAction *action,
                cookie_remove (dialog, (gpointer)g_value_get_string (&val));
                g_value_unset (&val);
 
-               gtk_tree_model_sort_convert_iter_to_child_iter (GTK_TREE_MODEL_SORT 
(dialog->priv->treemodelsort),
+               gtk_tree_model_sort_convert_iter_to_child_iter (GTK_TREE_MODEL_SORT (dialog->treemodelsort),
                                                                &filter_iter,
                                                                &iter);
 
-               gtk_tree_model_filter_convert_iter_to_child_iter (GTK_TREE_MODEL_FILTER 
(dialog->priv->treemodelfilter),
+               gtk_tree_model_filter_convert_iter_to_child_iter (GTK_TREE_MODEL_FILTER 
(dialog->treemodelfilter),
                                                                  &child_iter,
                                                                  &filter_iter);
 
-               gtk_list_store_remove (GTK_LIST_STORE (dialog->priv->liststore), &child_iter);
+               gtk_list_store_remove (GTK_LIST_STORE (dialog->liststore), &child_iter);
 
                gtk_tree_row_reference_free ((GtkTreeRowReference *)r->data);
                gtk_tree_path_free (path);
@@ -196,7 +188,7 @@ forget (GSimpleAction *action,
 
                if (path != NULL)
                {
-                       gtk_tree_view_set_cursor (GTK_TREE_VIEW (dialog->priv->cookies_treeview), path, NULL, 
FALSE);
+                       gtk_tree_view_set_cursor (GTK_TREE_VIEW (dialog->cookies_treeview), path, NULL, 
FALSE);
                        gtk_tree_path_free (path);
                }
 
@@ -215,51 +207,51 @@ update_selection_actions (GActionMap *action_map,
 }
 
 static void
-on_treeview_selection_changed (GtkTreeSelection *selection,
-                              CookiesDialog    *dialog)
+on_treeview_selection_changed (GtkTreeSelection  *selection,
+                               EphyCookiesDialog *dialog)
 {
-       update_selection_actions (G_ACTION_MAP (dialog->priv->action_group),
+       update_selection_actions (G_ACTION_MAP (dialog->action_group),
                                  gtk_tree_selection_count_selected_rows (selection) > 0);
 }
 
 static void
-on_search_entry_changed (GtkSearchEntry *entry,
-                        CookiesDialog *dialog)
+on_search_entry_changed (GtkSearchEntry    *entry,
+                         EphyCookiesDialog *dialog)
 {
        const char *text;
 
        text = gtk_entry_get_text (GTK_ENTRY (entry));
-       g_free (dialog->priv->search_text);
-       dialog->priv->search_text = g_strdup (text);
-       gtk_tree_model_filter_refilter (GTK_TREE_MODEL_FILTER (dialog->priv->treemodelfilter));
+       g_free (dialog->search_text);
+       dialog->search_text = g_strdup (text);
+       gtk_tree_model_filter_refilter (GTK_TREE_MODEL_FILTER (dialog->treemodelfilter));
 }
 
 static void
-forget_all (GSimpleAction *action,
-            GVariant      *parameter,
-            CookiesDialog *dialog)
+forget_all (GSimpleAction     *action,
+            GVariant          *parameter,
+            EphyCookiesDialog *dialog)
 {
-       webkit_cookie_manager_delete_all_cookies (dialog->priv->cookie_manager);
+       webkit_cookie_manager_delete_all_cookies (dialog->cookie_manager);
        reload_model (dialog);
 }
 
 static void
-cookies_dialog_class_init (CookiesDialogClass *klass)
+ephy_cookies_dialog_class_init (EphyCookiesDialogClass *klass)
 {
        GObjectClass *object_class = G_OBJECT_CLASS (klass);
        GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
 
-       object_class->dispose = cookies_dialog_dispose;
-       object_class->finalize = cookies_dialog_finalize;
+       object_class->dispose = ephy_cookies_dialog_dispose;
+       object_class->finalize = ephy_cookies_dialog_finalize;
 
        gtk_widget_class_set_template_from_resource (widget_class,
                                                     "/org/gnome/epiphany/cookies-dialog.ui");
 
-       gtk_widget_class_bind_template_child_private (widget_class, CookiesDialog, liststore);
-       gtk_widget_class_bind_template_child_private (widget_class, CookiesDialog, treemodelfilter);
-       gtk_widget_class_bind_template_child_private (widget_class, CookiesDialog, treemodelsort);
-       gtk_widget_class_bind_template_child_private (widget_class, CookiesDialog, cookies_treeview);
-       gtk_widget_class_bind_template_child_private (widget_class, CookiesDialog, tree_selection);
+       gtk_widget_class_bind_template_child (widget_class, EphyCookiesDialog, liststore);
+       gtk_widget_class_bind_template_child (widget_class, EphyCookiesDialog, treemodelfilter);
+       gtk_widget_class_bind_template_child (widget_class, EphyCookiesDialog, treemodelsort);
+       gtk_widget_class_bind_template_child (widget_class, EphyCookiesDialog, cookies_treeview);
+       gtk_widget_class_bind_template_child (widget_class, EphyCookiesDialog, tree_selection);
 
        gtk_widget_class_bind_template_callback (widget_class, on_treeview_selection_changed);
        gtk_widget_class_bind_template_callback (widget_class, on_search_entry_changed);
@@ -285,7 +277,7 @@ cookie_search_equal (GtkTreeModel *model,
 }
 
 static void
-cookie_add (CookiesDialog *dialog,
+cookie_add (EphyCookiesDialog *dialog,
            gpointer data)
 {
        char *domain = (char *) data;
@@ -294,7 +286,7 @@ cookie_add (CookiesDialog *dialog,
        int column[3] = { COL_COOKIES_HOST, COL_COOKIES_HOST_KEY, COL_COOKIES_DATA };
        GValue value[3] = { { 0, }, { 0, }, { 0, } };
 
-       store = GTK_LIST_STORE (dialog->priv->liststore);
+       store = GTK_LIST_STORE (dialog->liststore);
 
        /* NOTE: We use this strange method to insert the row, because
         * we want to use g_value_take_string but all the row data needs to
@@ -342,8 +334,8 @@ compare_cookie_host_keys (GtkTreeModel *model,
 
 static void
 get_domains_with_cookies_cb (WebKitCookieManager *cookie_manager,
-                            GAsyncResult *result,
-                            CookiesDialog *dialog)
+                             GAsyncResult        *result,
+                             EphyCookiesDialog   *dialog)
 {
        gchar **domains;
        guint i;
@@ -359,11 +351,11 @@ get_domains_with_cookies_cb (WebKitCookieManager *cookie_manager,
        g_free (domains);
 
        /* Now turn on sorting */
-       gtk_tree_sortable_set_sort_func (GTK_TREE_SORTABLE (dialog->priv->liststore),
+       gtk_tree_sortable_set_sort_func (GTK_TREE_SORTABLE (dialog->liststore),
                                         COL_COOKIES_HOST_KEY,
                                         (GtkTreeIterCompareFunc) compare_cookie_host_keys,
                                         NULL, NULL);
-       gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (dialog->priv->liststore),
+       gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (dialog->liststore),
                                              COL_COOKIES_HOST_KEY,
                                              GTK_SORT_ASCENDING);
 
@@ -372,25 +364,25 @@ get_domains_with_cookies_cb (WebKitCookieManager *cookie_manager,
                          G_CALLBACK (cookie_changed_cb),
                          dialog);
 
-       dialog->priv->filled = TRUE;
+       dialog->filled = TRUE;
 }
 
 static gboolean
-row_visible_func (GtkTreeModel *model,
-                 GtkTreeIter  *iter,
-                 CookiesDialog *dialog)
+row_visible_func (GtkTreeModel      *model,
+                  GtkTreeIter       *iter,
+                  EphyCookiesDialog *dialog)
 {
        gboolean visible = FALSE;
        gchar *host;
 
-       if (dialog->priv->search_text == NULL)
+       if (dialog->search_text == NULL)
                return TRUE;
 
        gtk_tree_model_get (model, iter,
                            COL_COOKIES_HOST, &host,
                            -1);
 
-       if (host != NULL && strstr (host, dialog->priv->search_text) != NULL)
+       if (host != NULL && strstr (host, dialog->search_text) != NULL)
                visible = TRUE;
 
        g_free (host);
@@ -399,29 +391,27 @@ row_visible_func (GtkTreeModel *model,
 }
 
 static void
-populate_model (CookiesDialog *dialog)
+populate_model (EphyCookiesDialog *dialog)
 {
-       g_assert (dialog->priv->filled == FALSE);
+       g_assert (dialog->filled == FALSE);
 
-       webkit_cookie_manager_get_domains_with_cookies (dialog->priv->cookie_manager,
+       webkit_cookie_manager_get_domains_with_cookies (dialog->cookie_manager,
                                                        NULL,
                                                        (GAsyncReadyCallback) get_domains_with_cookies_cb,
                                                        dialog);
 }
 
 static void
-setup_page (CookiesDialog *dialog)
+setup_page (EphyCookiesDialog *dialog)
 {
-       CookiesDialogPrivate *priv = dialog->priv;
-
-       gtk_tree_view_set_search_equal_func (GTK_TREE_VIEW (priv->cookies_treeview),
+       gtk_tree_view_set_search_equal_func (GTK_TREE_VIEW (dialog->cookies_treeview),
                                             (GtkTreeViewSearchEqualFunc) cookie_search_equal,
                                             dialog, NULL);
        populate_model (dialog);
 }
 
 static GActionGroup *
-create_action_group (CookiesDialog *dialog)
+create_action_group (EphyCookiesDialog *dialog)
 {
        const GActionEntry entries[] = {
                { "forget", forget },
@@ -437,26 +427,33 @@ create_action_group (CookiesDialog *dialog)
 }
 
 static void
-cookies_dialog_init (CookiesDialog *dialog)
+ephy_cookies_dialog_init (EphyCookiesDialog *dialog)
 {
        WebKitWebContext *web_context;
        EphyEmbedShell *shell = ephy_embed_shell_get_default ();
 
-       dialog->priv = cookies_dialog_get_instance_private (dialog);
        gtk_widget_init_template (GTK_WIDGET (dialog));
 
-       gtk_tree_model_filter_set_visible_func (GTK_TREE_MODEL_FILTER (dialog->priv->treemodelfilter),
+       gtk_tree_model_filter_set_visible_func (GTK_TREE_MODEL_FILTER (dialog->treemodelfilter),
                                                (GtkTreeModelFilterVisibleFunc)row_visible_func,
                                                dialog,
                                                NULL);
 
        web_context = ephy_embed_shell_get_web_context (shell);
-       dialog->priv->cookie_manager = webkit_web_context_get_cookie_manager (web_context);
+       dialog->cookie_manager = webkit_web_context_get_cookie_manager (web_context);
 
        setup_page (dialog);
 
-       dialog->priv->action_group = create_action_group (dialog);
-       gtk_widget_insert_action_group (dialog, "cookies", dialog->priv->action_group);
+       dialog->action_group = create_action_group (dialog);
+       gtk_widget_insert_action_group (dialog, "cookies", dialog->action_group);
 
-       update_selection_actions (G_ACTION_MAP (dialog->priv->action_group), FALSE);
+       update_selection_actions (G_ACTION_MAP (dialog->action_group), FALSE);
+}
+
+EphyCookiesDialog *
+ephy_cookies_dialog_new (void)
+{
+       return g_object_new (EPHY_TYPE_COOKIES_DIALOG,
+                            "use-header-bar", TRUE,
+                            NULL);
 }
diff --git a/src/cookies-dialog.h b/src/cookies-dialog.h
index 33efc69..39c3561 100644
--- a/src/cookies-dialog.h
+++ b/src/cookies-dialog.h
@@ -20,37 +20,13 @@
 #ifndef COOKIES_DIALOG_H
 #define COOKIES_DIALOG_H
 
-#include <glib-object.h>
-#include <gtk/gtk.h>
-
 G_BEGIN_DECLS
 
-#define EPHY_TYPE_COOKIES_DIALOG               (cookies_dialog_get_type ())
-#define EPHY_COOKIES_DIALOG(o)         (G_TYPE_CHECK_INSTANCE_CAST ((o), EPHY_TYPE_COOKIES_DIALOG, 
CookiesDialog))
-#define EPHY_COOKIES_DIALOG_CLASS(k)   (G_TYPE_CHECK_CLASS_CAST((k), EPHY_TYPE_COOKIES_DIALOG, 
CookiesDialogClass))
-#define EPHY_IS_COOKIES_DIALOG(o)              (G_TYPE_CHECK_INSTANCE_TYPE ((o), EPHY_TYPE_COOKIES_DIALOG))
-#define EPHY_IS_COOKIES_DIALOG_CLASS(k)        (G_TYPE_CHECK_CLASS_TYPE ((k), EPHY_TYPE_COOKIES_DIALOG))
-#define EPHY_COOKIES_DIALOG_GET_CLASS(o)       (G_TYPE_INSTANCE_GET_CLASS ((o), EPHY_TYPE_COOKIES_DIALOG, 
CookiesDialogClass))
-
-typedef struct CookiesDialog           CookiesDialog;
-typedef struct CookiesDialogClass              CookiesDialogClass;
-typedef struct CookiesDialogPrivate    CookiesDialogPrivate;
-
-struct CookiesDialog
-{
-        GtkDialog parent;
-
-       /*< private >*/
-        CookiesDialogPrivate *priv;
-};
-
-struct CookiesDialogClass
-{
-        GtkDialogClass parent_class;
-};
+#define EPHY_TYPE_COOKIES_DIALOG (ephy_cookies_dialog_get_type ())
+G_DECLARE_FINAL_TYPE (EphyCookiesDialog, ephy_cookies_dialog, EPHY, COOKIES_DIALOG, GtkDialog);
 
-GType         cookies_dialog_get_type  (void);
+EphyCookiesDialog *ephy_cookies_dialog_new (void);
 
 G_END_DECLS
 
-#endif
+#endif /* COOKIES_DIALOG_H */
diff --git a/src/prefs-dialog.c b/src/prefs-dialog.c
index 136936c..8b2db0e 100644
--- a/src/prefs-dialog.c
+++ b/src/prefs-dialog.c
@@ -145,11 +145,10 @@ static void
 on_manage_cookies_button_clicked (GtkWidget *button,
                                  PrefsDialog *dialog)
 {
-       CookiesDialog *cookies_dialog;
+       EphyCookiesDialog *cookies_dialog;
+
+       cookies_dialog = ephy_cookies_dialog_new ();
 
-       cookies_dialog = g_object_new (EPHY_TYPE_COOKIES_DIALOG,
-                                      "use-header-bar", TRUE,
-                                      NULL);
        gtk_window_set_transient_for (GTK_WINDOW (cookies_dialog), GTK_WINDOW (dialog));
        gtk_window_set_modal (GTK_WINDOW (cookies_dialog), TRUE);
        gtk_window_present (GTK_WINDOW (cookies_dialog));
diff --git a/src/resources/cookies-dialog.ui b/src/resources/cookies-dialog.ui
index 464cfc7..331e089 100644
--- a/src/resources/cookies-dialog.ui
+++ b/src/resources/cookies-dialog.ui
@@ -17,7 +17,7 @@
   <object class="GtkTreeModelSort" id="treemodelsort">
     <property name="model">treemodelfilter</property>
   </object>
-  <template class="CookiesDialog" parent="GtkDialog">
+  <template class="EphyCookiesDialog" parent="GtkDialog">
     <property name="height_request">500</property>
     <property name="modal">True</property>
     <property name="window_position">center</property>


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