[epiphany] EphyPasswordsDialog: Make final class.
- From: Arnaud Bonatti <arnaudb src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [epiphany] EphyPasswordsDialog: Make final class.
- Date: Wed, 4 Nov 2015 15:42:06 +0000 (UTC)
commit ae3010bd2d0644a996592e577bf7c7467ec36d5c
Author: Arnaud Bonatti <arnaud bonatti gmail com>
Date: Wed Nov 4 12:01:06 2015 +0100
EphyPasswordsDialog: Make final class.
src/passwords-dialog.c | 221 +++++++++++++++++++------------------
src/passwords-dialog.h | 32 +-----
src/prefs-dialog.c | 7 +-
src/resources/passwords-dialog.ui | 2 +-
4 files changed, 122 insertions(+), 140 deletions(-)
---
diff --git a/src/passwords-dialog.c b/src/passwords-dialog.c
index ff6f02f..5a62e25 100644
--- a/src/passwords-dialog.c
+++ b/src/passwords-dialog.c
@@ -45,8 +45,10 @@ typedef enum
#define FORM_PASSWORD_KEY "form_password"
#define USERNAME_KEY "username"
-struct PasswordsDialogPrivate
+struct _EphyPasswordsDialog
{
+ GtkDialog parent_instance;
+
GtkWidget *passwords_treeview;
GtkTreeSelection *tree_selection;
GtkWidget *liststore;
@@ -66,56 +68,54 @@ struct PasswordsDialogPrivate
char *search_text;
};
-G_DEFINE_TYPE_WITH_PRIVATE (PasswordsDialog, passwords_dialog, GTK_TYPE_DIALOG)
+G_DEFINE_TYPE (EphyPasswordsDialog, ephy_passwords_dialog, GTK_TYPE_DIALOG)
-static void populate_model (PasswordsDialog *dialog);
+static void populate_model (EphyPasswordsDialog *dialog);
static void
-reload_model (PasswordsDialog *dialog)
+reload_model (EphyPasswordsDialog *dialog)
{
- gtk_list_store_clear (GTK_LIST_STORE (dialog->priv->liststore));
- dialog->priv->filled = FALSE;
+ gtk_list_store_clear (GTK_LIST_STORE (dialog->liststore));
+ dialog->filled = FALSE;
populate_model (dialog);
}
static void
-passwords_dialog_dispose (GObject *object)
+ephy_passwords_dialog_dispose (GObject *object)
{
- PasswordsDialogPrivate *priv;
-
- priv = EPHY_PASSWORDS_DIALOG (object)->priv;
+ EphyPasswordsDialog *dialog = EPHY_PASSWORDS_DIALOG (object);
- if (priv->ss_cancellable != NULL) {
- g_cancellable_cancel (priv->ss_cancellable);
- g_clear_object (&priv->ss_cancellable);
+ if (dialog->ss_cancellable != NULL) {
+ g_cancellable_cancel (dialog->ss_cancellable);
+ g_clear_object (&(dialog->ss_cancellable));
}
- g_clear_object (&priv->ss);
- g_free (priv->search_text);
- priv->search_text = NULL;
+ g_clear_object (&(dialog->ss));
+ g_free (dialog->search_text);
+ dialog->search_text = NULL;
- G_OBJECT_CLASS (passwords_dialog_parent_class)->dispose (object);
+ G_OBJECT_CLASS (ephy_passwords_dialog_parent_class)->dispose (object);
}
static void
-secret_remove_ready_cb (GObject *source,
- GAsyncResult *res,
- PasswordsDialog *dialog)
+secret_remove_ready_cb (GObject *source,
+ GAsyncResult *res,
+ EphyPasswordsDialog *dialog)
{
secret_item_delete_finish (SECRET_ITEM (source), res, NULL);
}
static void
-secret_remove (PasswordsDialog *dialog,
- SecretItem *item)
+secret_remove (EphyPasswordsDialog *dialog,
+ SecretItem *item)
{
secret_item_delete (item, NULL, (GAsyncReadyCallback)secret_remove_ready_cb, dialog);
}
static void
-forget (GSimpleAction *action,
- GVariant *parameter,
- PasswordsDialog *dialog)
+forget (GSimpleAction *action,
+ GVariant *parameter,
+ EphyPasswordsDialog *dialog)
{
GList *llist, *rlist = NULL, *l, *r;
GtkTreeModel *model;
@@ -123,7 +123,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)
{
@@ -174,15 +174,15 @@ forget (GSimpleAction *action,
secret_remove (dialog, item);
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);
@@ -199,7 +199,7 @@ forget (GSimpleAction *action,
if (path != NULL)
{
- gtk_tree_view_set_cursor (GTK_TREE_VIEW (dialog->priv->passwords_treeview), path,
NULL, FALSE);
+ gtk_tree_view_set_cursor (GTK_TREE_VIEW (dialog->passwords_treeview), path, NULL,
FALSE);
gtk_tree_path_free (path);
}
@@ -208,19 +208,19 @@ forget (GSimpleAction *action,
}
static void
-show_passwords (GSimpleAction *action,
- GVariant *parameter,
- PasswordsDialog *dialog)
+show_passwords (GSimpleAction *action,
+ GVariant *parameter,
+ EphyPasswordsDialog *dialog)
{
gboolean active;
- active = gtk_toggle_button_get_active (dialog->priv->show_passwords_button);
+ active = gtk_toggle_button_get_active (dialog->show_passwords_button);
- gtk_tree_view_column_set_attributes (GTK_TREE_VIEW_COLUMN (dialog->priv->password_column),
- GTK_CELL_RENDERER (dialog->priv->password_renderer),
+ gtk_tree_view_column_set_attributes (GTK_TREE_VIEW_COLUMN (dialog->password_column),
+ GTK_CELL_RENDERER (dialog->password_renderer),
"text", (active ? COL_PASSWORDS_PASSWORD :
COL_PASSWORDS_INVISIBLE),
NULL);
- gtk_widget_queue_draw (dialog->priv->passwords_treeview);
+ gtk_widget_queue_draw (dialog->passwords_treeview);
}
static void
@@ -234,27 +234,27 @@ update_selection_actions (GActionMap *action_map,
}
static void
-on_treeview_selection_changed (GtkTreeSelection *selection,
- PasswordsDialog *dialog)
+on_treeview_selection_changed (GtkTreeSelection *selection,
+ EphyPasswordsDialog *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,
- PasswordsDialog *dialog)
+on_search_entry_changed (GtkSearchEntry *entry,
+ EphyPasswordsDialog *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 char *
-get_selected_item (PasswordsDialog *dialog,
+get_selected_item (EphyPasswordsDialog *dialog,
PasswordsDialogColumn column)
{
GtkTreeModel *model;
@@ -262,7 +262,7 @@ get_selected_item (PasswordsDialog *dialog,
GtkTreeIter iter;
char *value;
- selected = gtk_tree_selection_get_selected_rows (dialog->priv->tree_selection, &model);
+ selected = gtk_tree_selection_get_selected_rows (dialog->tree_selection, &model);
gtk_tree_model_get_iter (model, &iter, selected->data);
gtk_tree_model_get (model, &iter,
column, &value,
@@ -273,9 +273,9 @@ get_selected_item (PasswordsDialog *dialog,
}
static void
-copy_password (GSimpleAction *action,
- GVariant *parameter,
- PasswordsDialog *dialog)
+copy_password (GSimpleAction *action,
+ GVariant *parameter,
+ EphyPasswordsDialog *dialog)
{
char *password;
@@ -289,9 +289,9 @@ copy_password (GSimpleAction *action,
}
static void
-copy_username (GSimpleAction *action,
- GVariant *parameter,
- PasswordsDialog *dialog)
+copy_username (GSimpleAction *action,
+ GVariant *parameter,
+ EphyPasswordsDialog *dialog)
{
char *username;
@@ -319,21 +319,21 @@ update_popup_menu_actions (GActionGroup *action_group,
}
static gboolean
-on_passwords_treeview_button_press_event (GtkWidget *widget,
- GdkEventButton *event,
- PasswordsDialog *dialog)
+on_passwords_treeview_button_press_event (GtkWidget *widget,
+ GdkEventButton *event,
+ EphyPasswordsDialog *dialog)
{
if (event->button == 3) {
int n;
GtkMenu *menu;
- n = gtk_tree_selection_count_selected_rows (dialog->priv->tree_selection);
+ n = gtk_tree_selection_count_selected_rows (dialog->tree_selection);
if (n == 0)
return FALSE;
- update_popup_menu_actions (G_ACTION_MAP (dialog->priv->action_group), (n == 1));
+ update_popup_menu_actions (G_ACTION_MAP (dialog->action_group), (n == 1));
- menu = gtk_menu_new_from_model (dialog->priv->treeview_popup_menu_model);
+ menu = gtk_menu_new_from_model (dialog->treeview_popup_menu_model);
gtk_menu_attach_to_widget (menu, dialog, NULL);
gtk_menu_popup (menu, NULL, NULL, NULL, NULL, event->button, event->time);
return TRUE;
@@ -343,25 +343,25 @@ on_passwords_treeview_button_press_event (GtkWidget *widget,
}
static void
-passwords_dialog_class_init (PasswordsDialogClass *klass)
+ephy_passwords_dialog_class_init (EphyPasswordsDialogClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
- object_class->dispose = passwords_dialog_dispose;
+ object_class->dispose = ephy_passwords_dialog_dispose;
gtk_widget_class_set_template_from_resource (widget_class,
"/org/gnome/epiphany/passwords-dialog.ui");
- gtk_widget_class_bind_template_child_private (widget_class, PasswordsDialog, liststore);
- gtk_widget_class_bind_template_child_private (widget_class, PasswordsDialog, treemodelfilter);
- gtk_widget_class_bind_template_child_private (widget_class, PasswordsDialog, treemodelsort);
- gtk_widget_class_bind_template_child_private (widget_class, PasswordsDialog, passwords_treeview);
- gtk_widget_class_bind_template_child_private (widget_class, PasswordsDialog, tree_selection);
- gtk_widget_class_bind_template_child_private (widget_class, PasswordsDialog, show_passwords_button);
- gtk_widget_class_bind_template_child_private (widget_class, PasswordsDialog, password_column);
- gtk_widget_class_bind_template_child_private (widget_class, PasswordsDialog, password_renderer);
- gtk_widget_class_bind_template_child_private (widget_class, PasswordsDialog,
treeview_popup_menu_model);
+ gtk_widget_class_bind_template_child (widget_class, EphyPasswordsDialog, liststore);
+ gtk_widget_class_bind_template_child (widget_class, EphyPasswordsDialog, treemodelfilter);
+ gtk_widget_class_bind_template_child (widget_class, EphyPasswordsDialog, treemodelsort);
+ gtk_widget_class_bind_template_child (widget_class, EphyPasswordsDialog, passwords_treeview);
+ gtk_widget_class_bind_template_child (widget_class, EphyPasswordsDialog, tree_selection);
+ gtk_widget_class_bind_template_child (widget_class, EphyPasswordsDialog, show_passwords_button);
+ gtk_widget_class_bind_template_child (widget_class, EphyPasswordsDialog, password_column);
+ gtk_widget_class_bind_template_child (widget_class, EphyPasswordsDialog, password_renderer);
+ gtk_widget_class_bind_template_child (widget_class, EphyPasswordsDialog, treeview_popup_menu_model);
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);
@@ -369,40 +369,40 @@ passwords_dialog_class_init (PasswordsDialogClass *klass)
}
static void
-delete_all_passwords_ready_cb (GObject *source_object,
- GAsyncResult *res,
- PasswordsDialog *dialog)
+delete_all_passwords_ready_cb (GObject *source_object,
+ GAsyncResult *res,
+ EphyPasswordsDialog *dialog)
{
- secret_service_clear_finish (dialog->priv->ss, res, NULL);
+ secret_service_clear_finish (dialog->ss, res, NULL);
reload_model (dialog);
}
static void
-forget_all (GSimpleAction *action,
- GVariant *parameter,
- PasswordsDialog *dialog)
+forget_all (GSimpleAction *action,
+ GVariant *parameter,
+ EphyPasswordsDialog *dialog)
{
GHashTable *attributes;
attributes = secret_attributes_build (EPHY_FORM_PASSWORD_SCHEMA, NULL);
- secret_service_clear (dialog->priv->ss,
+ secret_service_clear (dialog->ss,
EPHY_FORM_PASSWORD_SCHEMA,
attributes,
- dialog->priv->ss_cancellable,
+ dialog->ss_cancellable,
(GAsyncReadyCallback)delete_all_passwords_ready_cb,
dialog);
g_hash_table_unref (attributes);
}
static void
-secrets_search_ready_cb (GObject *source_object,
- GAsyncResult *res,
- PasswordsDialog *dialog)
+secrets_search_ready_cb (GObject *source_object,
+ GAsyncResult *res,
+ EphyPasswordsDialog *dialog)
{
GList *matches;
GList *l;
- matches = secret_service_search_finish (dialog->priv->ss, res, NULL);
+ matches = secret_service_search_finish (dialog->ss, res, NULL);
for (l = matches; l != NULL; l = l->next) {
SecretItem *item = l->data;
@@ -419,7 +419,7 @@ secrets_search_ready_cb (GObject *source_object,
value = secret_item_get_secret (item);
password = secret_value_get (value, NULL);
- gtk_list_store_insert_with_values (GTK_LIST_STORE (dialog->priv->liststore),
+ gtk_list_store_insert_with_values (GTK_LIST_STORE (dialog->liststore),
&iter,
-1,
COL_PASSWORDS_HOST, host,
@@ -437,19 +437,19 @@ secrets_search_ready_cb (GObject *source_object,
}
static void
-populate_model (PasswordsDialog *dialog)
+populate_model (EphyPasswordsDialog *dialog)
{
GHashTable *attributes;
- g_assert (dialog->priv->filled == FALSE);
+ g_assert (dialog->filled == FALSE);
attributes = secret_attributes_build (EPHY_FORM_PASSWORD_SCHEMA, NULL);
- secret_service_search (dialog->priv->ss,
+ secret_service_search (dialog->ss,
EPHY_FORM_PASSWORD_SCHEMA,
attributes,
SECRET_SEARCH_ALL | SECRET_SEARCH_UNLOCK | SECRET_SEARCH_LOAD_SECRETS,
- dialog->priv->ss_cancellable,
+ dialog->ss_cancellable,
(GAsyncReadyCallback)secrets_search_ready_cb,
dialog);
@@ -457,24 +457,24 @@ populate_model (PasswordsDialog *dialog)
}
static void
-secrets_ready_cb (GObject *source_object,
- GAsyncResult *res,
- PasswordsDialog *dialog)
+secrets_ready_cb (GObject *source_object,
+ GAsyncResult *res,
+ EphyPasswordsDialog *dialog)
{
- dialog->priv->ss = secret_service_get_finish (res, NULL);
+ dialog->ss = secret_service_get_finish (res, NULL);
populate_model (dialog);
}
static gboolean
-row_visible_func (GtkTreeModel *model,
- GtkTreeIter *iter,
- PasswordsDialog *dialog)
+row_visible_func (GtkTreeModel *model,
+ GtkTreeIter *iter,
+ EphyPasswordsDialog *dialog)
{
char *username;
char *host;
gboolean visible = FALSE;
- if (dialog->priv->search_text == NULL)
+ if (dialog->search_text == NULL)
return TRUE;
gtk_tree_model_get (model, iter,
@@ -482,9 +482,9 @@ row_visible_func (GtkTreeModel *model,
COL_PASSWORDS_USER, &username,
-1);
- if (host != NULL && g_strrstr (host, dialog->priv->search_text) != NULL)
+ if (host != NULL && g_strrstr (host, dialog->search_text) != NULL)
visible = TRUE;
- else if (username != NULL && g_strrstr (username, dialog->priv->search_text) != NULL)
+ else if (username != NULL && g_strrstr (username, dialog->search_text) != NULL)
visible = TRUE;
g_free (host);
@@ -494,7 +494,7 @@ row_visible_func (GtkTreeModel *model,
}
static GActionGroup *
-create_action_group (PasswordsDialog *dialog)
+create_action_group (EphyPasswordsDialog *dialog)
{
const GActionEntry entries[] = {
{ "copy-password", copy_password },
@@ -513,24 +513,31 @@ create_action_group (PasswordsDialog *dialog)
}
static void
-passwords_dialog_init (PasswordsDialog *dialog)
+ephy_passwords_dialog_init (EphyPasswordsDialog *dialog)
{
- dialog->priv = passwords_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);
- dialog->priv->ss_cancellable = g_cancellable_new ();
+ dialog->ss_cancellable = g_cancellable_new ();
secret_service_get (SECRET_SERVICE_OPEN_SESSION | SECRET_SERVICE_LOAD_COLLECTIONS,
- dialog->priv->ss_cancellable,
+ dialog->ss_cancellable,
(GAsyncReadyCallback)secrets_ready_cb,
dialog);
- dialog->priv->action_group = create_action_group (dialog);
- gtk_widget_insert_action_group (dialog, "passwords", dialog->priv->action_group);
+ dialog->action_group = create_action_group (dialog);
+ gtk_widget_insert_action_group (dialog, "passwords", dialog->action_group);
- update_selection_actions (G_ACTION_MAP (dialog->priv->action_group), FALSE);
+ update_selection_actions (G_ACTION_MAP (dialog->action_group), FALSE);
+}
+
+EphyPasswordsDialog *
+ephy_passwords_dialog_new (void)
+{
+ return g_object_new (EPHY_TYPE_PASSWORDS_DIALOG,
+ "use-header-bar", TRUE,
+ NULL);
}
diff --git a/src/passwords-dialog.h b/src/passwords-dialog.h
index c3880d4..c60c131 100644
--- a/src/passwords-dialog.h
+++ b/src/passwords-dialog.h
@@ -20,37 +20,13 @@
#ifndef PASSWORDS_DIALOG_H
#define PASSWORDS_DIALOG_H
-#include <glib-object.h>
-#include <gtk/gtk.h>
-
G_BEGIN_DECLS
-#define EPHY_TYPE_PASSWORDS_DIALOG (passwords_dialog_get_type ())
-#define EPHY_PASSWORDS_DIALOG(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), EPHY_TYPE_PASSWORDS_DIALOG,
PasswordsDialog))
-#define EPHY_PASSWORDS_DIALOG_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), EPHY_TYPE_PASSWORDS_DIALOG,
PasswordsDialogClass))
-#define EPHY_IS_PASSWORDS_DIALOG(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), EPHY_TYPE_PASSWORDS_DIALOG))
-#define EPHY_IS_PASSWORDS_DIALOG_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), EPHY_TYPE_PASSWORDS_DIALOG))
-#define EPHY_PASSWORDS_DIALOG_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), EPHY_TYPE_PASSWORDS_DIALOG,
PasswordsDialogClass))
-
-typedef struct PasswordsDialog PasswordsDialog;
-typedef struct PasswordsDialogClass PasswordsDialogClass;
-typedef struct PasswordsDialogPrivate PasswordsDialogPrivate;
-
-struct PasswordsDialog
-{
- GtkDialog parent;
-
- /*< private >*/
- PasswordsDialogPrivate *priv;
-};
-
-struct PasswordsDialogClass
-{
- GtkDialogClass parent_class;
-};
+#define EPHY_TYPE_PASSWORDS_DIALOG (ephy_passwords_dialog_get_type ())
+G_DECLARE_FINAL_TYPE (EphyPasswordsDialog, ephy_passwords_dialog, EPHY, PASSWORDS_DIALOG, GtkDialog);
-GType passwords_dialog_get_type (void);
+EphyPasswordsDialog *ephy_passwords_dialog_new (void);
G_END_DECLS
-#endif
+#endif /* PASSWORDS_DIALOG_H */
diff --git a/src/prefs-dialog.c b/src/prefs-dialog.c
index 8b2db0e..365e719 100644
--- a/src/prefs-dialog.c
+++ b/src/prefs-dialog.c
@@ -158,11 +158,10 @@ static void
on_manage_passwords_button_clicked (GtkWidget *button,
PrefsDialog *dialog)
{
- PasswordsDialog *passwords_dialog;
+ EphyPasswordsDialog *passwords_dialog;
+
+ passwords_dialog = ephy_passwords_dialog_new ();
- passwords_dialog = g_object_new (EPHY_TYPE_PASSWORDS_DIALOG,
- "use-header-bar", TRUE,
- NULL);
gtk_window_set_transient_for (GTK_WINDOW (passwords_dialog), GTK_WINDOW (dialog));
gtk_window_set_modal (GTK_WINDOW (passwords_dialog), TRUE);
gtk_window_present (GTK_WINDOW (passwords_dialog));
diff --git a/src/resources/passwords-dialog.ui b/src/resources/passwords-dialog.ui
index 63ed16e..cf69e1b 100644
--- a/src/resources/passwords-dialog.ui
+++ b/src/resources/passwords-dialog.ui
@@ -21,7 +21,7 @@
<object class="GtkTreeModelSort" id="treemodelsort">
<property name="model">treemodelfilter</property>
</object>
- <template class="PasswordsDialog" parent="GtkDialog">
+ <template class="EphyPasswordsDialog" 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]