[epiphany] cookies-dialog: Make it a EphyDataDialog
- From: Michael Catanzaro <mcatanzaro src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [epiphany] cookies-dialog: Make it a EphyDataDialog
- Date: Fri, 17 Jan 2020 16:52:21 +0000 (UTC)
commit f4a27d09ff1ccfdef12cff999867a2fa5063a009
Author: Adrien Plazas <kekun plazas laposte net>
Date: Tue Jul 9 17:05:56 2019 +0200
cookies-dialog: Make it a EphyDataDialog
This will help factoring its code with other data management dialogs.
Fixes https://gitlab.gnome.org/GNOME/epiphany/issues/832.
src/cookies-dialog.c | 69 +++++-----------
src/cookies-dialog.h | 4 +-
src/resources/gtk/cookies-dialog.ui | 152 ++++++------------------------------
3 files changed, 48 insertions(+), 177 deletions(-)
---
diff --git a/src/cookies-dialog.c b/src/cookies-dialog.c
index 09157080f..b8bb9a57d 100644
--- a/src/cookies-dialog.c
+++ b/src/cookies-dialog.c
@@ -2,6 +2,7 @@
/*
* Copyright © 2013 Red Hat, Inc.
* Copyright © 2019 Jan-Michael Brummer
+ * Copyright © 2019 Purism SPC
*
* This file is part of Epiphany.
*
@@ -34,21 +35,16 @@
#include "cookies-dialog.h"
struct _EphyCookiesDialog {
- GtkDialog parent_instance;
+ EphyDataDialog parent_instance;
GtkWidget *cookies_listbox;
- GtkWidget *search_bar;
- GtkWidget *search_entry;
GActionGroup *action_group;
WebKitWebsiteDataManager *data_manager;
- gboolean filled;
-
- char *search_text;
};
-G_DEFINE_TYPE (EphyCookiesDialog, ephy_cookies_dialog, GTK_TYPE_DIALOG)
+G_DEFINE_TYPE (EphyCookiesDialog, ephy_cookies_dialog, EPHY_TYPE_DATA_DIALOG)
static void populate_model (EphyCookiesDialog *self);
@@ -69,26 +65,10 @@ static void
reload_model (EphyCookiesDialog *self)
{
clear_listbox (self->cookies_listbox);
- self->filled = FALSE;
+ ephy_data_dialog_set_has_data (EPHY_DATA_DIALOG (self), FALSE);
populate_model (self);
}
-static void
-ephy_cookies_dialog_dispose (GObject *object)
-{
- EphyCookiesDialog *self = EPHY_COOKIES_DIALOG (object);
-
- g_clear_pointer (&self->search_text, g_free);
- G_OBJECT_CLASS (ephy_cookies_dialog_parent_class)->dispose (object);
-}
-
-static void
-ephy_cookies_dialog_finalize (GObject *object)
-{
- g_free (EPHY_COOKIES_DIALOG (object)->search_text);
- G_OBJECT_CLASS (ephy_cookies_dialog_parent_class)->finalize (object);
-}
-
static void
forget_clicked (GtkButton *button,
gpointer user_data)
@@ -111,15 +91,9 @@ forget_clicked (GtkButton *button,
}
static void
-on_search_entry_changed (GtkSearchEntry *entry,
- EphyCookiesDialog *self)
+on_search_text_changed (EphyCookiesDialog *self)
{
- const char *text;
-
- text = gtk_entry_get_text (GTK_ENTRY (entry));
- g_free (self->search_text);
- self->search_text = g_strdup (text);
-
+ ephy_data_dialog_set_has_search_results (EPHY_DATA_DIALOG (self), FALSE);
gtk_list_box_invalidate_filter (GTK_LIST_BOX (self->cookies_listbox));
}
@@ -137,22 +111,16 @@ forget_all (GSimpleAction *action,
static void
ephy_cookies_dialog_class_init (EphyCookiesDialogClass *klass)
{
- GObjectClass *object_class = G_OBJECT_CLASS (klass);
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
- object_class->dispose = ephy_cookies_dialog_dispose;
- object_class->finalize = ephy_cookies_dialog_finalize;
-
g_type_ensure (WEBKIT_TYPE_WEBSITE_DATA);
gtk_widget_class_set_template_from_resource (widget_class,
"/org/gnome/epiphany/gtk/cookies-dialog.ui");
gtk_widget_class_bind_template_child (widget_class, EphyCookiesDialog, cookies_listbox);
- gtk_widget_class_bind_template_child (widget_class, EphyCookiesDialog, search_bar);
- gtk_widget_class_bind_template_child (widget_class, EphyCookiesDialog, search_entry);
- gtk_widget_class_bind_template_callback (widget_class, on_search_entry_changed);
+ gtk_widget_class_bind_template_callback (widget_class, on_search_text_changed);
}
static void
@@ -188,6 +156,7 @@ get_domains_with_cookies_cb (WebKitWebsiteDataManager *data_manager,
{
GList *data_list;
+ ephy_data_dialog_set_is_loading (EPHY_DATA_DIALOG (self), FALSE);
data_list = webkit_website_data_manager_fetch_finish (data_manager, result, NULL);
if (!data_list)
return;
@@ -198,14 +167,15 @@ get_domains_with_cookies_cb (WebKitWebsiteDataManager *data_manager,
/* The list items have been consumed, so we need only to free the list. */
g_list_free (data_list);
- self->filled = TRUE;
+ ephy_data_dialog_set_has_data (EPHY_DATA_DIALOG (self), TRUE);
}
static void
populate_model (EphyCookiesDialog *self)
{
- g_assert (self->filled == FALSE);
+ g_assert (!ephy_data_dialog_get_has_data (EPHY_DATA_DIALOG (self)));
+ ephy_data_dialog_set_is_loading (EPHY_DATA_DIALOG (self), TRUE);
webkit_website_data_manager_fetch (self->data_manager,
WEBKIT_WEBSITE_DATA_COOKIES,
NULL,
@@ -233,11 +203,16 @@ filter_func (GtkListBoxRow *row,
gpointer user_data)
{
EphyCookiesDialog *self = EPHY_COOKIES_DIALOG (user_data);
+ const gchar *search_text = ephy_data_dialog_get_search_text (EPHY_DATA_DIALOG (self));
+ gboolean result = TRUE;
+
+ if (search_text)
+ result = !!strstr (hdy_action_row_get_title (HDY_ACTION_ROW (row)), search_text);
- if (self->search_text)
- return !!strstr (hdy_action_row_get_title (HDY_ACTION_ROW (row)), self->search_text);
+ if (result)
+ ephy_data_dialog_set_has_search_results (EPHY_DATA_DIALOG (self), TRUE);
- return TRUE;
+ return result;
}
static void
@@ -258,14 +233,10 @@ ephy_cookies_dialog_init (EphyCookiesDialog *self)
gtk_list_box_set_header_func (GTK_LIST_BOX (self->cookies_listbox), hdy_list_box_separator_header, NULL,
NULL);
gtk_list_box_set_filter_func (GTK_LIST_BOX (self->cookies_listbox), filter_func, self, NULL);
-
- hdy_search_bar_connect_entry (HDY_SEARCH_BAR (self->search_bar), GTK_ENTRY (self->search_entry));
}
EphyCookiesDialog *
ephy_cookies_dialog_new (void)
{
- return g_object_new (EPHY_TYPE_COOKIES_DIALOG,
- "use-header-bar", TRUE,
- NULL);
+ return g_object_new (EPHY_TYPE_COOKIES_DIALOG, NULL);
}
diff --git a/src/cookies-dialog.h b/src/cookies-dialog.h
index 9724430b0..12194ef5d 100644
--- a/src/cookies-dialog.h
+++ b/src/cookies-dialog.h
@@ -20,10 +20,12 @@
#pragma once
+#include "ephy-data-dialog.h"
+
G_BEGIN_DECLS
#define EPHY_TYPE_COOKIES_DIALOG (ephy_cookies_dialog_get_type ())
-G_DECLARE_FINAL_TYPE (EphyCookiesDialog, ephy_cookies_dialog, EPHY, COOKIES_DIALOG, GtkDialog);
+G_DECLARE_FINAL_TYPE (EphyCookiesDialog, ephy_cookies_dialog, EPHY, COOKIES_DIALOG, EphyDataDialog);
EphyCookiesDialog *ephy_cookies_dialog_new (void);
diff --git a/src/resources/gtk/cookies-dialog.ui b/src/resources/gtk/cookies-dialog.ui
index b9931f7b7..c3ac22192 100644
--- a/src/resources/gtk/cookies-dialog.ui
+++ b/src/resources/gtk/cookies-dialog.ui
@@ -3,143 +3,41 @@
<interface>
<requires lib="gtk+" version="3.20"/>
<requires lib="libhandy" version="0.0"/>
- <object class="GtkImage" id="image1">
- <property name="visible">True</property>
- <property name="can_focus">False</property>
- <property name="icon_name">edit-find-symbolic</property>
- </object>
- <object class="GtkImage" id="image2">
- <property name="visible">True</property>
- <property name="can_focus">False</property>
- <property name="icon_name">user-trash-symbolic</property>
- </object>
- <template class="EphyCookiesDialog" parent="GtkDialog">
- <property name="can_focus">False</property>
- <property name="modal">True</property>
- <property name="window_position">center</property>
- <property name="default_width">300</property>
- <property name="default_height">600</property>
- <property name="destroy_with_parent">True</property>
- <property name="type_hint">dialog</property>
- <signal name="key-press-event" handler="hdy_search_bar_handle_event" object="search_bar" swapped="yes"/>
- <child type="titlebar">
- <object class="GtkHeaderBar">
+ <template class="EphyCookiesDialog" parent="EphyDataDialog">
+ <property name="title" translatable="yes">Cookies</property>
+ <property name="clear_all_action_name">cookies.forget-all</property>
+ <property name="clear_all_description" translatable="yes">Remove all cookies</property>
+ <property name="search_description" translatable="yes">Search cookies</property>
+ <property name="empty_title" translatable="yes">There are no Cookies</property>
+ <property name="empty_description" translatable="yes">Cookies left by visited pages will be listed
here</property>
+ <property name="can_clear">True</property>
+ <signal name="notify::search-text" handler="on_search_text_changed" swapped="yes"/>
+ <child>
+ <object class="GtkScrolledWindow">
<property name="visible">True</property>
- <property name="can_focus">False</property>
- <property name="title" translatable="yes">Cookies</property>
- <property name="show_close_button">True</property>
+ <property name="can_focus">True</property>
<child>
- <object class="GtkButton">
+ <object class="HdyColumn">
<property name="visible">True</property>
- <property name="can_focus">True</property>
- <property name="receives_default">True</property>
- <property name="action_name">cookies.forget-all</property>
- <property name="image">image2</property>
- <property name="always_show_image">True</property>
- <property name="tooltip_text" translatable="yes">Remove all cookies</property>
- <accelerator key="Delete" signal="clicked" modifiers="GDK_SHIFT_MASK"/>
- <style>
- <class name="destructive-action"/>
- </style>
- </object>
- </child>
- <child>
- <object class="GtkToggleButton">
- <property name="name">search_button</property>
- <property name="visible">True</property>
- <property name="can_focus">True</property>
- <property name="receives_default">True</property>
- <property name="image">image1</property>
- <property name="always_show_image">True</property>
- <property name="active" bind-source="search_bar" bind-property="search-mode-enabled"
bind-flags="sync-create|bidirectional"/>
- <child internal-child="accessible">
- <object class="AtkObject">
- <property name="AtkObject::accessible-name" translatable="yes">Search</property>
- <property name="AtkObject::accessible-description" translatable="yes">Filter
cookies</property>
- </object>
- </child>
- <accelerator key="f" signal="clicked" modifiers="GDK_SHIFT_MASK"/>
- </object>
- <packing>
- <property name="pack_type">end</property>
- <property name="position">1</property>
- </packing>
- </child>
- </object>
- </child>
- <child internal-child="vbox">
- <object class="GtkBox">
- <property name="can_focus">False</property>
- <property name="orientation">vertical</property>
- <child internal-child="action_area">
- <object class="GtkButtonBox">
<property name="can_focus">False</property>
- <property name="layout_style">end</property>
- <child>
- <placeholder/>
- </child>
- <child>
- <placeholder/>
- </child>
- </object>
- <packing>
- <property name="expand">False</property>
- <property name="fill">False</property>
- <property name="position">2</property>
- </packing>
- </child>
- <child>
- <object class="HdySearchBar" id="search_bar">
- <property name="visible">True</property>
- <property name="can_focus">False</property>
- <property name="valign">start</property>
- <property name="hexpand">True</property>
- <property name="show_close_button">False</property>
- <child>
- <object class="HdyColumn">
- <property name="visible">True</property>
- <property name="hexpand">True</property>
- <property name="maximum-width">600</property>
- <child>
- <object class="GtkSearchEntry" id="search_entry">
- <property name="visible">True</property>
- <property name="hexpand">True</property>
- <signal name="changed" handler="on_search_entry_changed"/>
- </object>
- </child>
- </object>
- </child>
- </object>
- <packing>
- <property name="expand">False</property>
- <property name="fill">True</property>
- <property name="position">0</property>
- </packing>
- </child>
- <child>
- <object class="GtkScrolledWindow">
- <property name="visible">True</property>
- <property name="can_focus">True</property>
- <property name="vexpand">True</property>
- <property name="shadow_type">in</property>
+ <property name="margin_start">6</property>
+ <property name="margin_end">6</property>
+ <property name="maximum_width">600</property>
+ <property name="linear_growth_width">400</property>
<child>
- <object class="GtkViewport">
+ <object class="GtkListBox" id="cookies_listbox">
<property name="visible">True</property>
<property name="can_focus">False</property>
- <child>
- <object class="GtkListBox" id="cookies_listbox">
- <property name="visible">True</property>
- <property name="can_focus">False</property>
- </object>
- </child>
+ <property name="margin_top">6</property>
+ <property name="margin_bottom">6</property>
+ <property name="valign">start</property>
+ <property name="selection_mode">none</property>
+ <style>
+ <class name="frame"/>
+ </style>
</object>
</child>
</object>
- <packing>
- <property name="expand">False</property>
- <property name="fill">True</property>
- <property name="position">1</property>
- </packing>
</child>
</object>
</child>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]