[epiphany] password-dialog: Make it a EphyDataDialog
- From: Michael Catanzaro <mcatanzaro src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [epiphany] password-dialog: Make it a EphyDataDialog
- Date: Fri, 17 Jan 2020 16:52:26 +0000 (UTC)
commit af2648f7359925d4e92840c03827f2603d5bdcad
Author: Adrien Plazas <kekun plazas laposte net>
Date: Tue Jul 9 17:24:13 2019 +0200
password-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/passwords-dialog.c | 36 ++++++---------
src/passwords-dialog.h | 3 +-
src/resources/gtk/passwords-dialog.ui | 86 ++++++-----------------------------
3 files changed, 28 insertions(+), 97 deletions(-)
---
diff --git a/src/passwords-dialog.c b/src/passwords-dialog.c
index 1d12df527..8152a8f4a 100644
--- a/src/passwords-dialog.c
+++ b/src/passwords-dialog.c
@@ -39,7 +39,7 @@ typedef enum {
} PasswordsDialogColumn;
struct _EphyPasswordsDialog {
- GtkDialog parent_instance;
+ EphyDataDialog parent_instance;
EphyPasswordManager *manager;
GList *records;
@@ -54,13 +54,9 @@ struct _EphyPasswordsDialog {
GMenuModel *treeview_popup_menu_model;
GActionGroup *action_group;
-
- gboolean filled;
-
- char *search_text;
};
-G_DEFINE_TYPE (EphyPasswordsDialog, ephy_passwords_dialog, GTK_TYPE_DIALOG)
+G_DEFINE_TYPE (EphyPasswordsDialog, ephy_passwords_dialog, EPHY_TYPE_DATA_DIALOG)
enum {
PROP_0,
@@ -114,9 +110,6 @@ ephy_passwords_dialog_dispose (GObject *object)
g_clear_object (&dialog->manager);
- g_free (dialog->search_text);
- dialog->search_text = NULL;
-
g_list_free_full (dialog->records, g_object_unref);
dialog->records = NULL;
@@ -248,14 +241,8 @@ on_treeview_selection_changed (GtkTreeSelection *selection,
}
static void
-on_search_entry_changed (GtkSearchEntry *entry,
- EphyPasswordsDialog *dialog)
+on_search_text_changed (EphyPasswordsDialog *dialog)
{
- const char *text;
-
- text = gtk_entry_get_text (GTK_ENTRY (entry));
- g_free (dialog->search_text);
- dialog->search_text = g_strdup (text);
gtk_tree_model_filter_refilter (GTK_TREE_MODEL_FILTER (dialog->treemodelfilter));
}
@@ -384,7 +371,7 @@ ephy_passwords_dialog_class_init (EphyPasswordsDialogClass *klass)
gtk_widget_class_bind_template_callback (widget_class, on_passwords_treeview_button_press_event);
gtk_widget_class_bind_template_callback (widget_class, on_treeview_selection_changed);
- 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
@@ -397,7 +384,7 @@ forget_all (GSimpleAction *action,
ephy_password_manager_forget_all (dialog->manager);
gtk_list_store_clear (GTK_LIST_STORE (dialog->liststore));
- dialog->filled = FALSE;
+ ephy_data_dialog_set_has_data (EPHY_DATA_DIALOG (dialog), FALSE);
g_list_free_full (dialog->records, g_object_unref);
dialog->records = NULL;
@@ -409,6 +396,7 @@ populate_model_cb (GList *records,
{
EphyPasswordsDialog *dialog = EPHY_PASSWORDS_DIALOG (user_data);
+ ephy_data_dialog_set_is_loading (EPHY_DATA_DIALOG (dialog), FALSE);
for (GList *l = records; l && l->data; l = l->next) {
EphyPasswordRecord *record = EPHY_PASSWORD_RECORD (l->data);
GtkTreeIter iter;
@@ -422,6 +410,7 @@ populate_model_cb (GList *records,
COL_PASSWORDS_INVISIBLE, "●●●●●●●●",
COL_PASSWORDS_DATA, record,
-1);
+ ephy_data_dialog_set_has_data (EPHY_DATA_DIALOG (dialog), TRUE);
}
dialog->records = records;
@@ -431,8 +420,9 @@ static void
populate_model (EphyPasswordsDialog *dialog)
{
g_assert (EPHY_IS_PASSWORDS_DIALOG (dialog));
- g_assert (dialog->filled == FALSE);
+ g_assert (!ephy_data_dialog_get_has_data (EPHY_DATA_DIALOG (dialog)));
+ ephy_data_dialog_set_is_loading (EPHY_DATA_DIALOG (dialog), TRUE);
/* Ask for all password records. */
ephy_password_manager_query (dialog->manager,
NULL, NULL, NULL, NULL, NULL, NULL,
@@ -447,8 +437,9 @@ row_visible_func (GtkTreeModel *model,
char *username;
char *origin;
gboolean visible = FALSE;
+ const char *search_text = ephy_data_dialog_get_search_text (EPHY_DATA_DIALOG (dialog));
- if (dialog->search_text == NULL)
+ if (search_text == NULL)
return TRUE;
gtk_tree_model_get (model, iter,
@@ -456,9 +447,9 @@ row_visible_func (GtkTreeModel *model,
COL_PASSWORDS_USER, &username,
-1);
- if (origin != NULL && g_strrstr (origin, dialog->search_text) != NULL)
+ if (origin != NULL && g_strrstr (origin, search_text) != NULL)
visible = TRUE;
- else if (username != NULL && g_strrstr (username, dialog->search_text) != NULL)
+ else if (username != NULL && g_strrstr (username, search_text) != NULL)
visible = TRUE;
g_free (origin);
@@ -518,6 +509,5 @@ ephy_passwords_dialog_new (EphyPasswordManager *manager)
{
return EPHY_PASSWORDS_DIALOG (g_object_new (EPHY_TYPE_PASSWORDS_DIALOG,
"password-manager", manager,
- "use-header-bar", TRUE,
NULL));
}
diff --git a/src/passwords-dialog.h b/src/passwords-dialog.h
index eafbf2a84..b31ccde87 100644
--- a/src/passwords-dialog.h
+++ b/src/passwords-dialog.h
@@ -20,12 +20,13 @@
#pragma once
+#include "ephy-data-dialog.h"
#include "ephy-password-manager.h"
G_BEGIN_DECLS
#define EPHY_TYPE_PASSWORDS_DIALOG (ephy_passwords_dialog_get_type ())
-G_DECLARE_FINAL_TYPE (EphyPasswordsDialog, ephy_passwords_dialog, EPHY, PASSWORDS_DIALOG, GtkDialog);
+G_DECLARE_FINAL_TYPE (EphyPasswordsDialog, ephy_passwords_dialog, EPHY, PASSWORDS_DIALOG, EphyDataDialog);
EphyPasswordsDialog *ephy_passwords_dialog_new (EphyPasswordManager *manager);
diff --git a/src/resources/gtk/passwords-dialog.ui b/src/resources/gtk/passwords-dialog.ui
index ced62a748..e25ee5f72 100644
--- a/src/resources/gtk/passwords-dialog.ui
+++ b/src/resources/gtk/passwords-dialog.ui
@@ -21,82 +21,22 @@
<object class="GtkTreeModelSort" id="treemodelsort">
<property name="model">treemodelfilter</property>
</object>
- <template class="EphyPasswordsDialog" parent="GtkDialog">
- <property name="modal">True</property>
- <property name="window_position">center</property>
- <property name="default_width">600</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="gtk_search_bar_handle_event" object="search_bar" swapped="true"/>
- <child internal-child="headerbar">
- <object class="GtkHeaderBar">
- <property name="title" translatable="yes">Passwords</property>
- <property name="show-close-button">True</property>
- <child>
- <object class="GtkButton">
- <property name="label" translatable="yes">C_lear All</property>
- <property name="visible">True</property>
- <property name="use_underline">True</property>
- <property name="valign">center</property>
- <property name="action-name">passwords.forget-all</property>
- <accelerator key="Delete" modifiers="GDK_SHIFT_MASK" signal="clicked"/>
- <style>
- <class name="destructive-action"/>
- <class name="text-button"/>
- </style>
- </object>
- </child>
- <child>
- <object class="GtkToggleButton" id="search_button">
- <property name="visible">True</property>
- <property name="valign">center</property>
- <accelerator key="F" modifiers="GDK_CONTROL_MASK" signal="clicked"/>
- <style>
- <class name="image-button"/>
- </style>
- <child internal-child="accessible">
- <object class="AtkObject">
- <property name="AtkObject::accessible-name" translatable="yes">Search</property>
- <property name="AtkObject::accessible-description" translatable="yes">Filter
passwords</property>
- </object>
- </child>
- <child>
- <object class="GtkImage">
- <property name="visible">True</property>
- <property name="icon-name">edit-find-symbolic</property>
- <property name="icon-size">1</property>
- </object>
- </child>
- </object>
- <packing>
- <property name="pack-type">end</property>
- </packing>
- </child>
- </object>
- </child>
- <child internal-child="vbox">
+ <template class="EphyPasswordsDialog" parent="EphyDataDialog">
+ <property name="title" translatable="yes">Passwords</property>
+ <property name="clear_all_action_name">passwords.forget-all</property>
+ <property name="clear_all_description" translatable="yes">Remove all passwords</property>
+ <property name="search_description" translatable="yes">Search passwords</property>
+ <property name="empty_title" translatable="yes">There are no Passwords</property>
+ <property name="empty_description" translatable="yes">Saved passwords 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="GtkBox">
- <property name="border_width">0</property>
- <child>
- <object class="GtkSearchBar" id="search_bar">
- <property name="visible">True</property>
- <property name="search-mode-enabled" bind-source="search_button" bind-property="active"
bind-flags="bidirectional|sync-create"/>
- <child>
- <object class="GtkSearchEntry">
- <property name="visible">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 passwords</property>
- <signal name="search-changed" handler="on_search_entry_changed"/>
- </object>
- </child>
- </object>
- </child>
+ <property name="visible">True</property>
+ <property name="orientation">vertical</property>
<child>
<object class="GtkScrolledWindow">
- <property name="width_request">400</property>
+ <property name="width_request">300</property>
<property name="height_request">300</property>
<property name="visible">True</property>
<property name="expand">True</property>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]