[epiphany] history-dialog: Make it a EphyDataDialog



commit 2fee764d3c8860c6170d80a1ab4a52d201a647ab
Author: Adrien Plazas <kekun plazas laposte net>
Date:   Mon Jul 8 22:57:30 2019 +0200

    history-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.
    Fixes https://gitlab.gnome.org/GNOME/epiphany/issues/992.

 src/ephy-history-dialog.c           |  82 ++++------
 src/ephy-history-dialog.h           |   3 +-
 src/resources/gtk/history-dialog.ui | 292 ++++--------------------------------
 3 files changed, 59 insertions(+), 318 deletions(-)
---
diff --git a/src/ephy-history-dialog.c b/src/ephy-history-dialog.c
index 66e7ac5f3..486d6393a 100644
--- a/src/ephy-history-dialog.c
+++ b/src/ephy-history-dialog.c
@@ -4,6 +4,7 @@
  *  Copyright © 2003, 2004 Christian Persch
  *  Copyright © 2012 Igalia S.L
  *  Copyright © 2018 Jan-Michael Brummer
+ *  Copyright © 2019 Purism SPC
  *
  *  This file is part of Epiphany.
  *
@@ -45,7 +46,7 @@
 #define NUM_FETCH_LIMIT 15
 
 struct _EphyHistoryDialog {
-  GtkWindow parent_instance;
+  EphyDataDialog parent_instance;
 
   EphySnapshotService *snapshot_service;
   EphyHistoryService *history_service;
@@ -54,23 +55,18 @@ struct _EphyHistoryDialog {
   GtkWidget *listbox;
   GtkWidget *forget_all_button;
   GtkWidget *popup_menu;
-  GtkWidget *search_bar;
-  GtkWidget *search_button;
-  GtkWidget *stack;
 
   GActionGroup *action_group;
 
   GList *urls;
   guint sorter_source;
 
-  char *search_text;
-
   gint num_fetch;
 
   GtkWidget *confirmation_dialog;
 };
 
-G_DEFINE_TYPE (EphyHistoryDialog, ephy_history_dialog, GTK_TYPE_WINDOW)
+G_DEFINE_TYPE (EphyHistoryDialog, ephy_history_dialog, EPHY_TYPE_DATA_DIALOG)
 
 enum {
   PROP_0,
@@ -128,13 +124,14 @@ on_find_urls_cb (gpointer service,
 static GList *
 substrings_filter (EphyHistoryDialog *self)
 {
+  const gchar *search_text = ephy_data_dialog_get_search_text (EPHY_DATA_DIALOG (self));
   char **tokens, **p;
   GList *substrings = NULL;
 
-  if (!self->search_text)
+  if (!search_text)
     return NULL;
 
-  tokens = p = g_strsplit (self->search_text, " ", -1);
+  tokens = p = g_strsplit (search_text, " ", -1);
 
   while (*p) {
     substrings = g_list_prepend (substrings, *p++);
@@ -293,13 +290,12 @@ add_urls_source (EphyHistoryDialog *self)
   GtkWidget *row;
   GList *children;
 
+  ephy_data_dialog_set_is_loading (EPHY_DATA_DIALOG (self), FALSE);
+
   children = gtk_container_get_children (GTK_CONTAINER (self->listbox));
-  if (!children) {
-    if (!self->search_text || g_strcmp0 (self->search_text, "") == 0)
-      gtk_stack_set_visible_child_name (GTK_STACK (self->stack), "empty");
-    else
-      gtk_stack_set_visible_child_name (GTK_STACK (self->stack), "no-results");
-  }
+  ephy_data_dialog_set_has_search_results (EPHY_DATA_DIALOG (self), !!children);
+  if (!children)
+    ephy_data_dialog_set_has_data (EPHY_DATA_DIALOG (self), FALSE);
   g_list_free (children);
 
   if (!self->urls || !self->num_fetch) {
@@ -313,7 +309,7 @@ add_urls_source (EphyHistoryDialog *self)
 
   row = create_row (self, url);
   gtk_list_box_insert (GTK_LIST_BOX (self->listbox), row, -1);
-  gtk_stack_set_visible_child_name (GTK_STACK (self->stack), "results");
+  ephy_data_dialog_set_has_data (EPHY_DATA_DIALOG (self), TRUE);
 
   self->urls = g_list_remove_link (self->urls, element);
   ephy_history_url_free (url);
@@ -483,15 +479,8 @@ update_popup_menu_actions (GActionGroup *action_group,
 }
 
 static void
-on_search_entry_changed (GtkSearchEntry    *entry,
-                         EphyHistoryDialog *self)
+on_search_text_changed (EphyHistoryDialog *self)
 {
-  const char *text;
-
-  text = gtk_entry_get_text (GTK_ENTRY (entry));
-  g_free (self->search_text);
-  self->search_text = g_strdup (text);
-
   filter_now (self);
 }
 
@@ -510,29 +499,20 @@ on_key_press_event (EphyHistoryDialog *self,
                     gpointer           user_data)
 {
   GdkEventKey *key = (GdkEventKey *)event;
-  gint ret;
-
-  ret = gtk_search_bar_handle_event (GTK_SEARCH_BAR (self->search_bar), event);
-
-  if (ret != GDK_EVENT_STOP) {
-    if (key->keyval == GDK_KEY_Escape) {
-      if (!gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (self->search_button)))
-        gtk_widget_destroy (GTK_WIDGET (self));
-      else
-        gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (self->search_button), FALSE);
-    } else if (isprint (key->keyval)) {
-      gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (self->search_button), TRUE);
-    } else if (key->keyval == GDK_KEY_Down || key->keyval == GDK_KEY_Page_Down) {
-      GList *childrens = gtk_container_get_children (GTK_CONTAINER (self->listbox));
-      GtkWidget *last = g_list_last (childrens)->data;
-      GtkWidget *focus = gtk_container_get_focus_child (GTK_CONTAINER (self->listbox));
-
-      if (focus == last)
-        load_further_data (self);
+
+  if (key->keyval == GDK_KEY_Down || key->keyval == GDK_KEY_Page_Down) {
+    GList *childrens = gtk_container_get_children (GTK_CONTAINER (self->listbox));
+    GtkWidget *last = g_list_last (childrens)->data;
+    GtkWidget *focus = gtk_container_get_focus_child (GTK_CONTAINER (self->listbox));
+
+    if (focus == last) {
+      load_further_data (self);
+
+      return GDK_EVENT_STOP;
     }
   }
 
-  return ret;
+  return GDK_EVENT_PROPAGATE;
 }
 
 static void
@@ -667,9 +647,6 @@ ephy_history_dialog_dispose (GObject *object)
 {
   EphyHistoryDialog *self = EPHY_HISTORY_DIALOG (object);
 
-  g_free (self->search_text);
-  self->search_text = NULL;
-
   if (self->cancellable) {
     g_cancellable_cancel (self->cancellable);
     g_clear_object (&self->cancellable);
@@ -736,18 +713,14 @@ ephy_history_dialog_class_init (EphyHistoryDialogClass *klass)
   gtk_widget_class_set_template_from_resource (widget_class,
                                                "/org/gnome/epiphany/gtk/history-dialog.ui");
   gtk_widget_class_bind_template_child (widget_class, EphyHistoryDialog, listbox);
-  gtk_widget_class_bind_template_child (widget_class, EphyHistoryDialog, forget_all_button);
   gtk_widget_class_bind_template_child (widget_class, EphyHistoryDialog, popup_menu);
-  gtk_widget_class_bind_template_child (widget_class, EphyHistoryDialog, search_bar);
-  gtk_widget_class_bind_template_child (widget_class, EphyHistoryDialog, search_button);
-  gtk_widget_class_bind_template_child (widget_class, EphyHistoryDialog, stack);
 
   gtk_widget_class_bind_template_callback (widget_class, on_listbox_row_activated);
   gtk_widget_class_bind_template_callback (widget_class, on_listbox_row_selected);
   gtk_widget_class_bind_template_callback (widget_class, on_listbox_button_press_event);
   gtk_widget_class_bind_template_callback (widget_class, on_listbox_key_press_event);
   gtk_widget_class_bind_template_callback (widget_class, on_key_press_event);
-  gtk_widget_class_bind_template_callback (widget_class, on_search_entry_changed);
+  gtk_widget_class_bind_template_callback (widget_class, on_search_text_changed);
   gtk_widget_class_bind_template_callback (widget_class, on_edge_reached);
 }
 
@@ -807,11 +780,14 @@ ephy_history_dialog_init (EphyHistoryDialog *self)
 
   if (ephy_embed_shell_get_mode (shell) == EPHY_EMBED_SHELL_MODE_INCOGNITO) {
     tooltip = _("It is not possible to modify history when in incognito mode.");
-    gtk_widget_set_tooltip_text (self->forget_all_button, tooltip);
+    ephy_data_dialog_set_clear_all_description (EPHY_DATA_DIALOG (self), tooltip);
 
     action = g_action_map_lookup_action (G_ACTION_MAP (self->action_group), "forget-all");
     g_simple_action_set_enabled (G_SIMPLE_ACTION (action), FALSE);
 
     update_selection_actions (self->action_group, FALSE);
+  } else {
+    ephy_data_dialog_set_can_clear (EPHY_DATA_DIALOG (self), TRUE);
   }
+  ephy_data_dialog_set_is_loading (EPHY_DATA_DIALOG (self), TRUE);
 }
diff --git a/src/ephy-history-dialog.h b/src/ephy-history-dialog.h
index a32e57a9d..5fea49394 100644
--- a/src/ephy-history-dialog.h
+++ b/src/ephy-history-dialog.h
@@ -22,13 +22,14 @@
 
 #include <gtk/gtk.h>
 
+#include "ephy-data-dialog.h"
 #include "ephy-history-service.h"
 
 G_BEGIN_DECLS
 
 #define EPHY_TYPE_HISTORY_DIALOG (ephy_history_dialog_get_type ())
 
-G_DECLARE_FINAL_TYPE (EphyHistoryDialog, ephy_history_dialog, EPHY, HISTORY_DIALOG, GtkWindow)
+G_DECLARE_FINAL_TYPE (EphyHistoryDialog, ephy_history_dialog, EPHY, HISTORY_DIALOG, EphyDataDialog)
 
 GtkWidget      *ephy_history_dialog_new        (EphyHistoryService *history_service);
 
diff --git a/src/resources/gtk/history-dialog.ui b/src/resources/gtk/history-dialog.ui
index 3449a2ce6..0fcb9553b 100644
--- a/src/resources/gtk/history-dialog.ui
+++ b/src/resources/gtk/history-dialog.ui
@@ -3,282 +3,46 @@
 <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="EphyHistoryDialog" parent="GtkWindow">
-    <property name="can_focus">False</property>
-    <property name="modal">True</property>
-    <property name="window_position">center-on-parent</property>
-    <property name="default_width">1000</property>
-    <property name="default_height">600</property>
-    <property name="destroy_with_parent">True</property>
-    <property name="type_hint">dialog</property>
+  <template class="EphyHistoryDialog" parent="EphyDataDialog">
+    <property name="title" translatable="yes">History</property>
+    <property name="clear_all_action_name">history.forget-all</property>
+    <property name="clear_all_description" translatable="yes">Remove all history</property>
+    <property name="search_description" translatable="yes">Search history</property>
+    <property name="empty_title" translatable="yes">The History is Empty</property>
+    <property name="empty_description" translatable="yes">Visited pages will be listed here</property>
     <signal name="key-press-event" handler="on_key_press_event" swapped="no"/>
-    <child type="titlebar">
-      <object class="GtkHeaderBar">
-        <property name="visible">True</property>
-        <property name="can_focus">False</property>
-        <property name="title" translatable="yes">History</property>
-        <property name="show_close_button">True</property>
-        <child>
-          <object class="GtkButton" id="forget_all_button">
-            <property name="visible">True</property>
-            <property name="can_focus">True</property>
-            <property name="receives_default">True</property>
-            <property name="action_name">history.forget-all</property>
-            <property name="image">image2</property>
-            <property name="always_show_image">True</property>
-            <property name="tooltip_text" translatable="yes">Remove all history</property>
-            <accelerator key="Delete" signal="clicked" modifiers="GDK_SHIFT_MASK"/>
-            <style>
-              <class name="destructive-action"/>
-            </style>
-          </object>
-        </child>
-        <child>
-          <object class="GtkToggleButton" id="search_button">
-            <property name="visible">True</property>
-            <property name="can_focus">True</property>
-            <property name="receives_default">True</property>
-            <property name="image">image1</property>
-            <property name="active" bind-source="search_bar" bind-property="search-mode-enabled" 
bind-flags="sync-create|bidirectional"/>
-          </object>
-          <packing>
-            <property name="pack_type">end</property>
-            <property name="position">1</property>
-          </packing>
-        </child>
-      </object>
-    </child>
+    <signal name="notify::search-text" handler="on_search_text_changed" swapped="yes"/>
     <child>
-      <object class="GtkBox">
+      <object class="GtkScrolledWindow" id="scrolled_window">
         <property name="visible">True</property>
-        <property name="can_focus">False</property>
-        <property name="orientation">vertical</property>
+        <property name="can_focus">True</property>
+        <signal name="edge-reached" handler="on_edge_reached" object="EphyHistoryDialog" swapped="no"/>
         <child>
-          <object class="GtkSearchBar" id="search_bar">
+          <object class="HdyColumn">
             <property name="visible">True</property>
             <property name="can_focus">False</property>
-            <property name="search_mode_enabled">False</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="GtkSearchEntry">
-                <property name="width_request">280</property>
+              <object class="GtkListBox" id="listbox">
                 <property name="visible">True</property>
-                <property name="can_focus">True</property>
-                <property name="primary_icon_name">edit-find-symbolic</property>
-                <property name="primary_icon_activatable">False</property>
-                <property name="primary_icon_sensitive">False</property>
-                <property name="placeholder_text" translatable="yes">Search history</property>
-                <signal name="search-changed" handler="on_search_entry_changed" swapped="no"/>
-              </object>
-            </child>
-          </object>
-          <packing>
-            <property name="expand">False</property>
-            <property name="fill">True</property>
-            <property name="position">0</property>
-          </packing>
-        </child>
-        <child>
-          <object class="GtkStack" id="stack">
-            <property name="can_focus">False</property>
-            <property name="expand">True</property>
-            <property name="visible">True</property>
-            <child>
-              <object class="GtkScrolledWindow">
-                <property name="can_focus">False</property>
-                <property name="expand">True</property>
-                <property name="hscrollbar_policy">never</property>
-                <property name="visible">True</property>
-                <child>
-                  <object class="GtkBox">
-                    <property name="can_focus">False</property>
-                    <property name="halign">center</property>
-                    <property name="orientation">vertical</property>
-                    <property name="valign">center</property>
-                    <property name="vexpand">True</property>
-                    <property name="visible">True</property>
-                    <child>
-                      <object class="GtkImage">
-                        <property name="can_focus">False</property>
-                        <property name="icon_name">web-browser-symbolic</property>
-                        <property name="icon_size">0</property>
-                        <property name="margin_bottom">18</property>
-                        <property name="pixel_size">128</property>
-                        <property name="valign">center</property>
-                        <property name="visible">True</property>
-                        <style>
-                          <class name="dim-label"/>
-                        </style>
-                      </object>
-                    </child>
-                    <child>
-                      <object class="GtkBox">
-                        <property name="can_focus">False</property>
-                        <property name="margin_end">12</property>
-                        <property name="margin_start">12</property>
-                        <property name="orientation">vertical</property>
-                        <property name="visible">True</property>
-                        <child>
-                          <object class="GtkLabel">
-                            <property name="can_focus">False</property>
-                            <property name="halign">center</property>
-                            <property name="justify">center</property>
-                            <property name="label" translatable="yes">The History is Empty</property>
-                            <property name="margin_bottom">12</property>
-                            <property name="opacity">0.5</property>
-                            <property name="visible">True</property>
-                            <property name="wrap">True</property>
-                            <attributes>
-                              <attribute name="scale" value="2"/>
-                              <attribute name="weight" value="bold"/>
-                            </attributes>
-                          </object>
-                        </child>
-                        <child>
-                          <object class="GtkLabel">
-                            <property name="can_focus">False</property>
-                            <property name="justify">center</property>
-                            <property name="label" translatable="yes">Visited pages will be listed 
here</property>
-                            <property name="margin_bottom">6</property>
-                            <property name="opacity">0.5</property>
-                            <property name="use_markup">True</property>
-                            <property name="visible">True</property>
-                            <property name="wrap">True</property>
-                          </object>
-                        </child>
-                      </object>
-                    </child>
-                  </object>
-                </child>
-              </object>
-              <packing>
-                <property name="name">empty</property>
-              </packing>
-            </child>
-            <child>
-              <object class="GtkScrolledWindow" id="scrolled_window">
-                <property name="visible">True</property>
-                <property name="can_focus">True</property>
-                <signal name="edge-reached" handler="on_edge_reached" object="EphyHistoryDialog" 
swapped="no"/>
-                <child>
-                  <object class="HdyColumn">
-                    <property name="visible">True</property>
-                    <property name="can_focus">False</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="GtkListBox" id="listbox">
-                        <property name="visible">True</property>
-                        <property name="can_focus">False</property>
-                        <property name="margin_top">6</property>
-                        <property name="margin_bottom">6</property>
-                        <property name="valign">start</property>
-                        <property name="selection_mode">multiple</property>
-                        <property name="activate_on_single_click">False</property>
-                        <signal name="button-press-event" handler="on_listbox_button_press_event" 
swapped="no"/>
-                        <signal name="key-press-event" handler="on_listbox_key_press_event" swapped="no"/>
-                        <signal name="row-activated" handler="on_listbox_row_activated" swapped="no"/>
-                        <style>
-                          <class name="frame"/>
-                        </style>
-                      </object>
-                    </child>
-                  </object>
-                </child>
-              </object>
-              <packing>
-                <property name="name">results</property>
-              </packing>
-            </child>
-            <child>
-              <object class="GtkScrolledWindow">
                 <property name="can_focus">False</property>
-                <property name="expand">True</property>
-                <property name="hscrollbar_policy">never</property>
-                <property name="visible">True</property>
-                <child>
-                  <object class="GtkBox">
-                    <property name="can_focus">False</property>
-                    <property name="halign">center</property>
-                    <property name="orientation">vertical</property>
-                    <property name="valign">center</property>
-                    <property name="vexpand">True</property>
-                    <property name="visible">True</property>
-                    <child>
-                      <object class="GtkImage">
-                        <property name="can_focus">False</property>
-                        <property name="icon_name">edit-find-symbolic</property>
-                        <property name="icon_size">0</property>
-                        <property name="margin_bottom">18</property>
-                        <property name="pixel_size">128</property>
-                        <property name="valign">center</property>
-                        <property name="visible">True</property>
-                        <style>
-                          <class name="dim-label"/>
-                        </style>
-                      </object>
-                    </child>
-                    <child>
-                      <object class="GtkBox">
-                        <property name="can_focus">False</property>
-                        <property name="margin_end">12</property>
-                        <property name="margin_start">12</property>
-                        <property name="orientation">vertical</property>
-                        <property name="visible">True</property>
-                        <child>
-                          <object class="GtkLabel">
-                            <property name="can_focus">False</property>
-                            <property name="halign">center</property>
-                            <property name="justify">center</property>
-                            <property name="label" translatable="yes">No Results Found</property>
-                            <property name="margin_bottom">12</property>
-                            <property name="opacity">0.5</property>
-                            <property name="visible">True</property>
-                            <property name="wrap">True</property>
-                            <attributes>
-                              <attribute name="scale" value="2"/>
-                              <attribute name="weight" value="bold"/>
-                            </attributes>
-                          </object>
-                        </child>
-                        <child>
-                          <object class="GtkLabel">
-                            <property name="can_focus">False</property>
-                            <property name="justify">center</property>
-                            <property name="label" translatable="yes">Try a different search</property>
-                            <property name="margin_bottom">6</property>
-                            <property name="opacity">0.5</property>
-                            <property name="use_markup">True</property>
-                            <property name="visible">True</property>
-                            <property name="wrap">True</property>
-                          </object>
-                        </child>
-                      </object>
-                    </child>
-                  </object>
-                </child>
+                <property name="margin_top">6</property>
+                <property name="margin_bottom">6</property>
+                <property name="valign">start</property>
+                <property name="selection_mode">multiple</property>
+                <property name="activate_on_single_click">False</property>
+                <signal name="button-press-event" handler="on_listbox_button_press_event" swapped="no"/>
+                <signal name="key-press-event" handler="on_listbox_key_press_event" swapped="no"/>
+                <signal name="row-activated" handler="on_listbox_row_activated" swapped="no"/>
+                <style>
+                  <class name="frame"/>
+                </style>
               </object>
-              <packing>
-                <property name="name">no-results</property>
-              </packing>
             </child>
           </object>
-          <packing>
-            <property name="expand">True</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]