[epiphany] Create a new clear data dialog



commit 0a301e9086cc33364baa9165dfbf8c525fd9697e
Author: William Jon McCann <william jon mccann gmail com>
Date:   Mon Dec 9 15:25:37 2013 +0100

    Create a new clear data dialog
    
    https://bugzilla.gnome.org/show_bug.cgi?id=720113

 po/POTFILES.in                     |    1 +
 src/Makefile.am                    |    3 +
 src/clear-data-dialog.c            |  215 +++++++++++++++++++++++++++++++++++
 src/clear-data-dialog.h            |   68 +++++++++++
 src/epiphany.gresource.xml         |    1 +
 src/prefs-dialog.c                 |   11 ++-
 src/resources/clear-data-dialog.ui |  221 ++++++++++++++++++++++++++++++++++++
 7 files changed, 517 insertions(+), 3 deletions(-)
---
diff --git a/po/POTFILES.in b/po/POTFILES.in
index dc999b7..c22a101 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -59,4 +59,5 @@ src/ephy-window.c
 src/pdm-dialog.c
 src/popup-commands.c
 src/prefs-dialog.c
+src/clear-data-dialog.c
 src/window-commands.c
diff --git a/src/Makefile.am b/src/Makefile.am
index ce372c9..9888283 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -30,6 +30,7 @@ NOINST_H_FILES = \
        ephy-window-action.h                    \
        languages.h                             \
        pdm-dialog.h                            \
+       clear-data-dialog.h                     \
        popup-commands.h                        \
        prefs-dialog.h                          \
        window-commands.h
@@ -66,6 +67,7 @@ libephymain_la_SOURCES = \
        ephy-window.c                           \
        ephy-window-action.c                    \
        pdm-dialog.c                            \
+       clear-data-dialog.c                     \
        popup-commands.c                        \
        prefs-dialog.c                          \
        window-commands.c                       \
@@ -104,6 +106,7 @@ RESOURCE_FILES = \
        resources/epiphany-application-menu.ui    \
        resources/prefs-dialog.ui                 \
        resources/prefs-lang-dialog.ui            \
+       resources/clear-data-dialog.ui            \
        resources/epiphany.css                    \
        resources/error.html                      \
        resources/process-crash.html              \
diff --git a/src/clear-data-dialog.c b/src/clear-data-dialog.c
new file mode 100644
index 0000000..5436e45
--- /dev/null
+++ b/src/clear-data-dialog.c
@@ -0,0 +1,215 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+/*
+ *  Copyright © 2013 Red Hat, Inc.
+ *
+ *  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, write to the Free Software
+ *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ */
+
+#include "config.h"
+
+#include <glib/gi18n.h>
+#include <gtk/gtk.h>
+#include <string.h>
+
+#define SECRET_API_SUBJECT_TO_CHANGE
+#include <libsecret/secret.h>
+#include <webkit2/webkit2.h>
+
+#include "ephy-history-service.h"
+#include "ephy-embed-shell.h"
+
+#include "clear-data-dialog.h"
+
+struct ClearDataDialogPrivate
+{
+       GtkWidget *cache_checkbutton;
+       GtkWidget *history_checkbutton;
+       GtkWidget *passwords_checkbutton;
+       GtkWidget *cookies_checkbutton;
+       GtkWidget *clear_button;
+
+       ClearDataDialogFlags flags;
+       guint num_checked;
+};
+
+G_DEFINE_TYPE_WITH_PRIVATE (ClearDataDialog, clear_data_dialog, GTK_TYPE_DIALOG)
+
+static void
+clear_data_dialog_class_init (ClearDataDialogClass *klass)
+{
+       GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
+
+       gtk_widget_class_set_template_from_resource (widget_class,
+                                                    "/org/gnome/epiphany/clear-data-dialog.ui");
+
+       gtk_widget_class_bind_template_child_private (widget_class, ClearDataDialog, cookies_checkbutton);
+       gtk_widget_class_bind_template_child_private (widget_class, ClearDataDialog, cache_checkbutton);
+       gtk_widget_class_bind_template_child_private (widget_class, ClearDataDialog, passwords_checkbutton);
+       gtk_widget_class_bind_template_child_private (widget_class, ClearDataDialog, history_checkbutton);
+       gtk_widget_class_bind_template_child_private (widget_class, ClearDataDialog, clear_button);
+}
+
+static WebKitCookieManager *
+get_cookie_manager (void)
+{
+       WebKitWebContext *web_context;
+
+       web_context = webkit_web_context_get_default ();
+       return webkit_web_context_get_cookie_manager (web_context);
+}
+
+static void
+delete_all_passwords (ClearDataDialog *dialog)
+{
+       GHashTable *attributes;
+
+       attributes = secret_attributes_build (SECRET_SCHEMA_COMPAT_NETWORK, NULL);
+       secret_service_clear (NULL, SECRET_SCHEMA_COMPAT_NETWORK,
+                             attributes, NULL,
+                             (GAsyncReadyCallback)secret_service_clear_finish,
+                             NULL);
+       g_hash_table_unref (attributes);
+}
+
+static void
+clear_data_dialog_response_cb (GtkDialog *widget,
+                              int response,
+                              ClearDataDialog *dialog)
+{
+       ClearDataDialogPrivate *priv = dialog->priv;
+
+       if (response == GTK_RESPONSE_OK)
+       {
+               if (gtk_toggle_button_get_active
+                       (GTK_TOGGLE_BUTTON (priv->history_checkbutton)))
+               {
+                       EphyEmbedShell *shell;
+                       EphyHistoryService *history;
+
+                       shell = ephy_embed_shell_get_default ();
+                       history = EPHY_HISTORY_SERVICE (ephy_embed_shell_get_global_history_service (shell));
+                       ephy_history_service_clear (history, NULL, NULL, NULL);
+               }
+               if (gtk_toggle_button_get_active
+                       (GTK_TOGGLE_BUTTON (priv->cookies_checkbutton)))
+               {
+                       WebKitCookieManager *cookie_manager;
+
+                       cookie_manager = get_cookie_manager ();
+                       webkit_cookie_manager_delete_all_cookies (cookie_manager);
+               }
+               if (gtk_toggle_button_get_active
+                       (GTK_TOGGLE_BUTTON (priv->passwords_checkbutton)))
+               {
+                       delete_all_passwords (dialog);
+               }
+               if (gtk_toggle_button_get_active
+                       (GTK_TOGGLE_BUTTON (priv->cache_checkbutton)))
+               {
+                       EphyEmbedShell *shell;
+                       WebKitFaviconDatabase *database;
+
+                       shell = ephy_embed_shell_get_default ();
+
+                       ephy_embed_shell_clear_cache (shell);
+
+                       database = webkit_web_context_get_favicon_database (webkit_web_context_get_default 
());
+                       webkit_favicon_database_clear (database);
+               }
+       }
+
+       gtk_widget_destroy (GTK_WIDGET (dialog));
+}
+
+static void
+checkbutton_toggled_cb (GtkToggleButton *toggle,
+                       ClearDataDialog *dialog)
+{
+       if (gtk_toggle_button_get_active (toggle) == TRUE)
+       {
+               dialog->priv->num_checked++;
+       }
+       else
+       {
+               dialog->priv->num_checked--;
+       }
+
+       gtk_widget_set_sensitive (dialog->priv->clear_button,
+                                 dialog->priv->num_checked != 0);
+}
+
+static void
+update_flags (ClearDataDialog *dialog)
+{
+       ClearDataDialogPrivate *priv = dialog->priv;
+
+       gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (priv->cookies_checkbutton),
+                                     (priv->flags & CLEAR_DATA_COOKIES));
+       gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (priv->passwords_checkbutton),
+                                     (priv->flags & CLEAR_DATA_PASSWORDS));
+       gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (priv->history_checkbutton),
+                                     (priv->flags & CLEAR_DATA_HISTORY));
+       gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (priv->cache_checkbutton),
+                                     (priv->flags & CLEAR_DATA_CACHE));
+}
+
+static void
+setup_page (ClearDataDialog *dialog)
+{
+       ClearDataDialogPrivate *priv = dialog->priv;
+
+       g_signal_connect (priv->cookies_checkbutton,
+                         "toggled",
+                         G_CALLBACK (checkbutton_toggled_cb),
+                         dialog);
+       g_signal_connect (priv->history_checkbutton,
+                         "toggled",
+                         G_CALLBACK (checkbutton_toggled_cb),
+                         dialog);
+       g_signal_connect (priv->cache_checkbutton,
+                         "toggled",
+                         G_CALLBACK (checkbutton_toggled_cb),
+                         dialog);
+       g_signal_connect (priv->passwords_checkbutton,
+                         "toggled",
+                         G_CALLBACK (checkbutton_toggled_cb),
+                         dialog);
+
+       update_flags (dialog);
+}
+
+static void
+clear_data_dialog_init (ClearDataDialog *dialog)
+{
+       dialog->priv = clear_data_dialog_get_instance_private (dialog);
+       gtk_widget_init_template (GTK_WIDGET (dialog));
+
+       setup_page (dialog);
+
+       g_signal_connect (dialog, "response",
+                         G_CALLBACK (clear_data_dialog_response_cb), dialog);
+}
+
+void
+clear_data_dialog_set_flags (ClearDataDialog     *dialog,
+                            ClearDataDialogFlags flags)
+{
+       if (dialog->priv->flags != flags)
+       {
+               dialog->priv->flags = flags;
+               update_flags (dialog);
+       }
+}
diff --git a/src/clear-data-dialog.h b/src/clear-data-dialog.h
new file mode 100644
index 0000000..5106a61
--- /dev/null
+++ b/src/clear-data-dialog.h
@@ -0,0 +1,68 @@
+/*
+ *  Copyright © 2013 Red Hat, Inc.
+ *
+ *  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, write to the Free Software
+ *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ */
+
+#ifndef CLEAR_DATA_DIALOG_H
+#define CLEAR_DATA_DIALOG_H
+
+#include <glib-object.h>
+#include <gtk/gtk.h>
+
+G_BEGIN_DECLS
+
+#define EPHY_TYPE_CLEAR_DATA_DIALOG            (clear_data_dialog_get_type ())
+#define EPHY_CLEAR_DATA_DIALOG(o)              (G_TYPE_CHECK_INSTANCE_CAST ((o), 
EPHY_TYPE_CLEAR_DATA_DIALOG, ClearDataDialog))
+#define EPHY_CLEAR_DATA_DIALOG_CLASS(k)        (G_TYPE_CHECK_CLASS_CAST((k), EPHY_TYPE_CLEAR_DATA_DIALOG, 
ClearDataDialogClass))
+#define EPHY_IS_CLEAR_DATA_DIALOG(o)           (G_TYPE_CHECK_INSTANCE_TYPE ((o), 
EPHY_TYPE_CLEAR_DATA_DIALOG))
+#define EPHY_IS_CLEAR_DATA_DIALOG_CLASS(k)     (G_TYPE_CHECK_CLASS_TYPE ((k), EPHY_TYPE_CLEAR_DATA_DIALOG))
+#define EPHY_CLEAR_DATA_DIALOG_GET_CLASS(o)    (G_TYPE_INSTANCE_GET_CLASS ((o), EPHY_TYPE_CLEAR_DATA_DIALOG, 
ClearDataDialogClass))
+
+typedef struct ClearDataDialog         ClearDataDialog;
+typedef struct ClearDataDialogClass            ClearDataDialogClass;
+typedef struct ClearDataDialogPrivate  ClearDataDialogPrivate;
+
+typedef enum
+{
+       CLEAR_DATA_NONE = 0,
+       CLEAR_DATA_CACHE = 1 << 0,
+       CLEAR_DATA_PASSWORDS = 1 << 1,
+       CLEAR_DATA_HISTORY = 1 << 2,
+       CLEAR_DATA_COOKIES = 1 << 4
+} ClearDataDialogFlags;
+
+struct ClearDataDialog
+{
+        GtkDialog parent;
+
+       /*< private >*/
+        ClearDataDialogPrivate *priv;
+};
+
+struct ClearDataDialogClass
+{
+        GtkDialogClass parent_class;
+};
+
+GType         clear_data_dialog_get_type           (void);
+
+void          clear_data_dialog_set_flags (ClearDataDialog     *dialog,
+                                           ClearDataDialogFlags flags);
+
+G_END_DECLS
+
+#endif
diff --git a/src/epiphany.gresource.xml b/src/epiphany.gresource.xml
index 7b0874d..b08bccf 100644
--- a/src/epiphany.gresource.xml
+++ b/src/epiphany.gresource.xml
@@ -4,6 +4,7 @@
     <file preprocess="xml-stripblanks" compressed="true">epiphany.ui</file>
     <file preprocess="xml-stripblanks" compressed="true">prefs-dialog.ui</file>
     <file preprocess="xml-stripblanks" compressed="true">prefs-lang-dialog.ui</file>
+    <file preprocess="xml-stripblanks" compressed="true">clear-data-dialog.ui</file>
     <file preprocess="xml-stripblanks">epiphany-application-menu.ui</file>
     <file preprocess="xml-stripblanks">epiphany-ui.xml</file>
     <file preprocess="xml-stripblanks">epiphany-bookmark-editor-ui.xml</file>
diff --git a/src/prefs-dialog.c b/src/prefs-dialog.c
index ae4b29b..1d4336d 100644
--- a/src/prefs-dialog.c
+++ b/src/prefs-dialog.c
@@ -37,7 +37,7 @@
 #include "ephy-session.h"
 #include "ephy-settings.h"
 #include "ephy-shell.h"
-#include "pdm-dialog.h"
+#include "clear-data-dialog.h"
 
 #include <glib/gi18n.h>
 #include <gtk/gtk.h>
@@ -915,8 +915,13 @@ static void
 clear_cache_button_clicked_cb (GtkWidget *button,
                               PrefsDialog *dialog)
 {
-       pdm_dialog_show_clear_all_dialog (NULL, GTK_WIDGET (dialog),
-                                         CLEAR_ALL_CACHE);
+       ClearDataDialog *clear_dialog;
+
+       clear_dialog = g_object_new (EPHY_TYPE_CLEAR_DATA_DIALOG, NULL);
+       clear_data_dialog_set_flags (clear_dialog, CLEAR_DATA_CACHE);
+       gtk_window_set_transient_for (GTK_WINDOW (clear_dialog), GTK_WINDOW (dialog));
+       gtk_window_set_modal (GTK_WINDOW (clear_dialog), TRUE);
+       gtk_window_present (GTK_WINDOW (clear_dialog));
 }
 
 static gboolean
diff --git a/src/resources/clear-data-dialog.ui b/src/resources/clear-data-dialog.ui
new file mode 100644
index 0000000..18b5540
--- /dev/null
+++ b/src/resources/clear-data-dialog.ui
@@ -0,0 +1,221 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- Generated with glade 3.16.0 on Mon Dec  9 15:28:24 2013 -->
+<interface>
+  <!-- interface-requires gtk+ 3.10 -->
+  <template class="ClearDataDialog" parent="GtkDialog">
+    <property name="can_focus">False</property>
+    <property name="border_width">5</property>
+    <property name="title" translatable="yes">Clear Personal Data</property>
+    <property name="modal">True</property>
+    <property name="window_position">center</property>
+    <property name="destroy_with_parent">True</property>
+    <property name="type_hint">dialog</property>
+    <child internal-child="vbox">
+      <object class="GtkBox" id="dialog-vbox2">
+        <property name="visible">True</property>
+        <property name="can_focus">False</property>
+        <property name="orientation">vertical</property>
+        <property name="spacing">2</property>
+        <child internal-child="action_area">
+          <object class="GtkButtonBox" id="dialog-action_area2">
+            <property name="visible">True</property>
+            <property name="can_focus">False</property>
+            <property name="layout_style">end</property>
+            <child>
+              <object class="GtkButton" id="cancel_button">
+                <property name="label">_Cancel</property>
+                <property name="visible">True</property>
+                <property name="can_focus">True</property>
+                <property name="can_default">True</property>
+                <property name="receives_default">False</property>
+                <property name="use_underline">True</property>
+              </object>
+              <packing>
+                <property name="expand">False</property>
+                <property name="fill">False</property>
+                <property name="position">0</property>
+              </packing>
+            </child>
+            <child>
+              <object class="GtkButton" id="clear_button">
+                <property name="label">C_lear</property>
+                <property name="visible">True</property>
+                <property name="sensitive">False</property>
+                <property name="can_focus">True</property>
+                <property name="can_default">True</property>
+                <property name="receives_default">False</property>
+                <property name="use_underline">True</property>
+              </object>
+              <packing>
+                <property name="expand">False</property>
+                <property name="fill">False</property>
+                <property name="position">1</property>
+              </packing>
+            </child>
+          </object>
+          <packing>
+            <property name="expand">False</property>
+            <property name="fill">True</property>
+            <property name="pack_type">end</property>
+            <property name="position">0</property>
+          </packing>
+        </child>
+        <child>
+          <object class="GtkBox" id="box1">
+            <property name="visible">True</property>
+            <property name="can_focus">False</property>
+            <property name="border_width">5</property>
+            <property name="orientation">vertical</property>
+            <property name="spacing">12</property>
+            <child>
+              <object class="GtkLabel" id="label1">
+                <property name="visible">True</property>
+                <property name="can_focus">False</property>
+                <property name="xalign">0</property>
+                <property name="label" translatable="yes">Select the personal data you wish to 
clear</property>
+                <attributes>
+                  <attribute name="weight" value="bold"/>
+                </attributes>
+              </object>
+              <packing>
+                <property name="expand">False</property>
+                <property name="fill">True</property>
+                <property name="position">0</property>
+              </packing>
+            </child>
+            <child>
+              <object class="GtkBox" id="box2">
+                <property name="visible">True</property>
+                <property name="can_focus">False</property>
+                <property name="orientation">vertical</property>
+                <property name="spacing">6</property>
+                <child>
+                  <object class="GtkLabel" id="label2">
+                    <property name="visible">True</property>
+                    <property name="can_focus">False</property>
+                    <property name="xalign">0</property>
+                    <property name="label" translatable="yes">You are about to clear personal data that is 
stored about the web pages you have visited. Check the types of information that you want to 
remove:</property>
+                    <property name="wrap">True</property>
+                    <property name="max_width_chars">50</property>
+                  </object>
+                  <packing>
+                    <property name="expand">False</property>
+                    <property name="fill">True</property>
+                    <property name="position">0</property>
+                  </packing>
+                </child>
+                <child>
+                  <object class="GtkBox" id="box3">
+                    <property name="visible">True</property>
+                    <property name="can_focus">False</property>
+                    <property name="margin_left">10</property>
+                    <property name="margin_right">10</property>
+                    <property name="margin_top">10</property>
+                    <property name="margin_bottom">10</property>
+                    <property name="orientation">vertical</property>
+                    <property name="spacing">2</property>
+                    <child>
+                      <object class="GtkCheckButton" id="cookies_checkbutton">
+                        <property name="label" translatable="yes">Cookies</property>
+                        <property name="visible">True</property>
+                        <property name="can_focus">True</property>
+                        <property name="receives_default">False</property>
+                        <property name="xalign">0</property>
+                        <property name="draw_indicator">True</property>
+                      </object>
+                      <packing>
+                        <property name="expand">False</property>
+                        <property name="fill">True</property>
+                        <property name="position">0</property>
+                      </packing>
+                    </child>
+                    <child>
+                      <object class="GtkCheckButton" id="cache_checkbutton">
+                        <property name="label" translatable="yes">Cache and temporary files</property>
+                        <property name="visible">True</property>
+                        <property name="can_focus">True</property>
+                        <property name="receives_default">False</property>
+                        <property name="xalign">0</property>
+                        <property name="draw_indicator">True</property>
+                      </object>
+                      <packing>
+                        <property name="expand">False</property>
+                        <property name="fill">True</property>
+                        <property name="position">1</property>
+                      </packing>
+                    </child>
+                    <child>
+                      <object class="GtkCheckButton" id="history_checkbutton">
+                        <property name="label" translatable="yes">Browsing history</property>
+                        <property name="visible">True</property>
+                        <property name="can_focus">True</property>
+                        <property name="receives_default">False</property>
+                        <property name="xalign">0</property>
+                        <property name="draw_indicator">True</property>
+                      </object>
+                      <packing>
+                        <property name="expand">False</property>
+                        <property name="fill">True</property>
+                        <property name="position">2</property>
+                      </packing>
+                    </child>
+                    <child>
+                      <object class="GtkCheckButton" id="passwords_checkbutton">
+                        <property name="label" translatable="yes">Saved passwords</property>
+                        <property name="visible">True</property>
+                        <property name="can_focus">True</property>
+                        <property name="receives_default">False</property>
+                        <property name="xalign">0</property>
+                        <property name="draw_indicator">True</property>
+                      </object>
+                      <packing>
+                        <property name="expand">False</property>
+                        <property name="fill">True</property>
+                        <property name="position">3</property>
+                      </packing>
+                    </child>
+                  </object>
+                  <packing>
+                    <property name="expand">False</property>
+                    <property name="fill">True</property>
+                    <property name="position">1</property>
+                  </packing>
+                </child>
+              </object>
+              <packing>
+                <property name="expand">False</property>
+                <property name="fill">True</property>
+                <property name="position">1</property>
+              </packing>
+            </child>
+            <child>
+              <object class="GtkLabel" id="label3">
+                <property name="visible">True</property>
+                <property name="can_focus">False</property>
+                <property name="xalign">0</property>
+                <property name="label" translatable="yes">You cannot undo this action. The data you are 
choosing to clear will be removed forever.</property>
+                <property name="wrap">True</property>
+                <property name="max_width_chars">50</property>
+              </object>
+              <packing>
+                <property name="expand">False</property>
+                <property name="fill">True</property>
+                <property name="pack_type">end</property>
+                <property name="position">2</property>
+              </packing>
+            </child>
+          </object>
+          <packing>
+            <property name="expand">False</property>
+            <property name="fill">True</property>
+            <property name="position">1</property>
+          </packing>
+        </child>
+      </object>
+    </child>
+    <action-widgets>
+      <action-widget response="-6">cancel_button</action-widget>
+      <action-widget response="-5">clear_button</action-widget>
+    </action-widgets>
+  </template>
+</interface>


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