[seahorse] Use libsecret instead of libgnome-keyring
- From: Stefan Walter <stefw src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [seahorse] Use libsecret instead of libgnome-keyring
- Date: Wed, 27 Jun 2012 14:49:18 +0000 (UTC)
commit 9b12bfdd245867f928651bc5414cba67a3f84169
Author: Stef Walter <stefw gnome org>
Date: Mon Apr 30 20:19:46 2012 +0200
Use libsecret instead of libgnome-keyring
* Requires libsecret 0.4 or later
configure.ac | 12 +-
gkr/Makefile.am | 6 +-
gkr/seahorse-gkr-actions.c | 123 ++++--
gkr/seahorse-gkr-add-item.c | 79 ++--
gkr/seahorse-gkr-add-keyring.c | 38 +-
gkr/seahorse-gkr-backend.c | 405 ++++++++++---------
gkr/seahorse-gkr-backend.h | 6 +-
gkr/seahorse-gkr-dialogs.c | 42 ++-
gkr/seahorse-gkr-dialogs.h | 2 +-
gkr/seahorse-gkr-item-deleter.c | 52 +--
gkr/seahorse-gkr-item-properties.c | 80 ++--
gkr/seahorse-gkr-item.c | 700 ++++++++++++---------------------
gkr/seahorse-gkr-item.h | 38 +-
gkr/seahorse-gkr-keyring-deleter.c | 68 +---
gkr/seahorse-gkr-keyring-properties.c | 22 +-
gkr/seahorse-gkr-keyring.c | 528 +++++++------------------
gkr/seahorse-gkr-keyring.h | 25 +-
gkr/seahorse-gkr-operation.c | 362 -----------------
gkr/seahorse-gkr-operation.h | 52 ---
libseahorse/seahorse-interaction.c | 7 +-
libseahorse/seahorse-object-widget.c | 2 +-
libseahorse/seahorse-registry.c | 2 +
libseahorse/seahorse-secure-memory.c | 25 +-
pgp/seahorse-pgp-backend.c | 2 -
src/seahorse-key-manager.c | 2 -
25 files changed, 891 insertions(+), 1789 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index ce01ba3..0b45049 100644
--- a/configure.ac
+++ b/configure.ac
@@ -8,7 +8,7 @@ GCR_REQUIRED=3.3.4
GTK_REQUIRED=2.90.0
GNUPG_ACCEPTED="1.2 1.4 2.0"
GPGME_REQUIRED=1.0.0
-GNOME_KEYRING_REQUIRED=2.25.5
+LIBSECRET_REQUIRED=0.4
AVAHI_GLIB_REQUIRED=0.6
# -----------------------------------------------------------------------------
@@ -328,17 +328,17 @@ else
fi
# -----------------------------------------------------------------------------
-# GNOME-KEYRING
+# LIBSECRET
-PKG_CHECK_MODULES([GNOME_KEYRING], gnome-keyring-1 >= $GNOME_KEYRING_REQUIRED,
+PKG_CHECK_MODULES([LIBSECRET], libsecret-0 >= $LIBSECRET_REQUIRED,
[enable_gnome_keyring=yes],[enable_gnome_keyring=no])
if test "$enable_gnome_keyring" = "no"; then
- AC_MSG_ERROR([gnome-keyring library or headers not found.])
+ AC_MSG_ERROR([libsecret library or headers not found.])
fi
-SEAHORSE_CFLAGS="$SEAHORSE_CFLAGS $GNOME_KEYRING_CFLAGS"
-SEAHORSE_LIBS="$SEAHORSE_LIBS $GNOME_KEYRING_LIBS"
+SEAHORSE_CFLAGS="$SEAHORSE_CFLAGS $LIBSECRET_CFLAGS"
+SEAHORSE_LIBS="$SEAHORSE_LIBS $LIBSECRET_LIBS"
# -----------------------------------------------------------------------------
# KEY SHARING
diff --git a/gkr/Makefile.am b/gkr/Makefile.am
index 7fc401b..7c27549 100644
--- a/gkr/Makefile.am
+++ b/gkr/Makefile.am
@@ -11,7 +11,8 @@ INCLUDES = -I$(top_builddir) \
-DSEAHORSE_UIDIR=\""$(uidir)/"\" \
-DLOCALEDIR=\"$(localedir)\" \
-DEXECDIR=\""$(seahorselibexecbindir)"\" \
- -DGETTEXT_PACKAGE=\""seahorse\""
+ -DGETTEXT_PACKAGE=\""seahorse\"" \
+ -DSECRET_API_SUBJECT_TO_CHANGE
noinst_LTLIBRARIES = libseahorse-gkr.la
@@ -27,8 +28,7 @@ libseahorse_gkr_la_SOURCES = \
seahorse-gkr-item-properties.c \
seahorse-gkr-keyring.c seahorse-gkr-keyring.h \
seahorse-gkr-keyring-deleter.c seahorse-gkr-keyring-deleter.h \
- seahorse-gkr-keyring-properties.c \
- seahorse-gkr-operation.c seahorse-gkr-operation.h
+ seahorse-gkr-keyring-properties.c
libseahorse_gkr_la_LIBADD = \
$(top_builddir)/libseahorse/libseahorse.la
diff --git a/gkr/seahorse-gkr-actions.c b/gkr/seahorse-gkr-actions.c
index 8477415..fe55fe6 100644
--- a/gkr/seahorse-gkr-actions.c
+++ b/gkr/seahorse-gkr-actions.c
@@ -27,7 +27,6 @@
#include "seahorse-gkr-keyring.h"
#include "seahorse-gkr-keyring-deleter.h"
#include "seahorse-gkr-dialogs.h"
-#include "seahorse-gkr-operation.h"
#include "seahorse-action.h"
#include "seahorse-actions.h"
@@ -140,69 +139,119 @@ seahorse_gkr_backend_actions_instance (void)
}
static void
-on_set_default_keyring_done (GnomeKeyringResult result,
+on_set_default_keyring_done (GObject *source,
+ GAsyncResult *result,
gpointer user_data)
{
GtkWindow *parent = GTK_WINDOW (user_data);
+ GError *error = NULL;
- if (result != GNOME_KEYRING_RESULT_OK &&
- result != GNOME_KEYRING_RESULT_DENIED &&
- result != GNOME_KEYRING_RESULT_CANCELLED) {
- seahorse_util_show_error (parent, _("Couldn't set default keyring"),
- gnome_keyring_result_to_message (result));
- }
+ secret_service_set_alias_finish (SECRET_SERVICE (source), result, &error);
+ if (error != NULL)
+ seahorse_util_handle_error (&error, parent, _("Couldn't set default keyring"));
refresh_all_keyrings ();
+ if (parent)
+ g_object_unref (parent);
}
static void
on_keyring_default (GtkAction *action,
gpointer user_data)
{
- SeahorseGkrKeyring *keyring = SEAHORSE_GKR_KEYRING (user_data);
+ SecretCollection *keyring = SECRET_COLLECTION (user_data);
GtkWindow *parent = seahorse_action_get_window (action);
- if (parent == NULL)
- gnome_keyring_set_default_keyring (seahorse_gkr_keyring_get_name (keyring),
- on_set_default_keyring_done,
- NULL, NULL);
- else
- gnome_keyring_set_default_keyring (seahorse_gkr_keyring_get_name (keyring),
- on_set_default_keyring_done,
- g_object_ref (parent), g_object_unref);
+ if (parent != NULL)
+ g_object_ref (parent);
+
+ secret_service_set_alias_path (secret_collection_get_service (keyring), "default",
+ g_dbus_proxy_get_object_path (G_DBUS_PROXY (keyring)),
+ NULL, on_set_default_keyring_done, parent);
}
+typedef struct {
+ SecretService *service;
+ GtkWindow *parent;
+} ChangeClosure;
+
static void
-on_change_password_done (GnomeKeyringResult result, gpointer user_data)
+change_closure_free (gpointer data)
{
- GtkWindow *parent = GTK_WINDOW (user_data);
+ ChangeClosure *change = data;
+ g_object_unref (change->service);
+ if (change->parent)
+ g_object_unref (change->parent);
+ g_slice_free (ChangeClosure, change);
+}
- if (result != GNOME_KEYRING_RESULT_OK &&
- result != GNOME_KEYRING_RESULT_DENIED &&
- result != GNOME_KEYRING_RESULT_CANCELLED) {
- seahorse_util_show_error (parent, _("Couldn't change keyring password"),
- gnome_keyring_result_to_message (result));
- }
+static void
+on_change_password_done (GObject *source,
+ GAsyncResult *result,
+ gpointer user_data)
+{
+ ChangeClosure *change = user_data;
+ GError *error = NULL;
+ GVariant *retval;
+
+ retval = secret_service_prompt_path_finish (SECRET_SERVICE (source), result, NULL, &error);
+ if (retval != NULL)
+ g_variant_unref (retval);
+ if (error != NULL)
+ seahorse_util_handle_error (&error, change->parent,
+ _("Couldn't change keyring password"));
refresh_all_keyrings ();
+ change_closure_free (change);
+}
+
+static void
+on_change_password_prompt (GObject *source,
+ GAsyncResult *result,
+ gpointer user_data)
+{
+ ChangeClosure *change = user_data;
+ const gchar *prompt_path;
+ GError *error = NULL;
+ GVariant *retval;
+
+ retval = g_dbus_connection_call_finish (G_DBUS_CONNECTION (source), result, &error);
+ if (error == NULL) {
+ g_variant_get (retval, "@s", &prompt_path);
+ secret_service_prompt_path (change->service, prompt_path, NULL,
+ on_change_password_done, change);
+ g_variant_unref (retval);
+ } else {
+ seahorse_util_handle_error (&error, change->parent, _("Couldn't change keyring password"));
+ change_closure_free (change);
+ }
}
static void
on_keyring_password (GtkAction *action,
gpointer user_data)
{
- SeahorseGkrKeyring *keyring = SEAHORSE_GKR_KEYRING (user_data);
- GtkWindow *window = seahorse_action_get_window (action);
-
- if (window == NULL)
- gnome_keyring_change_password (seahorse_gkr_keyring_get_name (keyring),
- NULL, NULL, on_change_password_done,
- NULL, NULL);
- else
- gnome_keyring_change_password (seahorse_gkr_keyring_get_name (keyring),
- NULL, NULL, on_change_password_done,
- g_object_ref (window), g_object_unref);
-
+ SecretCollection *collection = SECRET_COLLECTION (user_data);
+ GDBusProxy *proxy;
+ ChangeClosure *change;
+
+ change = g_slice_new0 (ChangeClosure);
+ change->parent = seahorse_action_get_window (action);
+ if (change->parent)
+ g_object_ref (change->parent);
+ change->service = secret_collection_get_service (collection);
+ g_return_if_fail (change->service != NULL);
+ g_object_ref (change->service);
+
+ proxy = G_DBUS_PROXY (change->service);
+ g_dbus_connection_call (g_dbus_proxy_get_connection (proxy),
+ g_dbus_proxy_get_name (proxy),
+ g_dbus_proxy_get_object_path (proxy),
+ "org.gnome.keyring.InternalUnsupportedGuiltRiddenInterface",
+ "ChangeWithPrompt",
+ g_variant_new ("(o)", g_dbus_proxy_get_object_path (proxy)),
+ G_VARIANT_TYPE ("(o)"),
+ 0, -1, NULL, on_change_password_prompt, change);
}
static const GtkActionEntry KEYRING_ACTIONS[] = {
diff --git a/gkr/seahorse-gkr-add-item.c b/gkr/seahorse-gkr-add-item.c
index fc21cd6..9e7c6cd 100644
--- a/gkr/seahorse-gkr-add-item.c
+++ b/gkr/seahorse-gkr-add-item.c
@@ -40,26 +40,25 @@ void on_add_item_response (GtkDialog *dialog,
gpointer user_data);
static void
-item_add_done (GnomeKeyringResult result, guint32 item, gpointer data)
+on_item_stored (GObject *source,
+ GAsyncResult *result,
+ gpointer user_data)
{
- SeahorseWidget *swidget = SEAHORSE_WIDGET (data);
-
- g_return_if_fail (swidget);
+ SeahorseWidget *swidget = SEAHORSE_WIDGET (user_data);
+ GError *error = NULL;
/* Clear the operation without cancelling it since it is complete */
seahorse_gkr_dialog_complete_request (swidget, FALSE);
+ secret_service_store_finish (SECRET_SERVICE (source), result, &error);
+
/* Successful. Update the listings and stuff. */
- if (result == GNOME_KEYRING_RESULT_OK) {
- seahorse_gkr_backend_load_async (NULL, NULL, NULL, NULL);
-
- /* Setting the default keyring failed */
- } else if (result != GNOME_KEYRING_RESULT_CANCELLED) {
- seahorse_util_show_error (seahorse_widget_get_toplevel (swidget),
- _("Couldn't add keyring"),
- gnome_keyring_result_to_message (result));
+ if (error != NULL) {
+ seahorse_util_handle_error (&error, seahorse_widget_get_toplevel (swidget),
+ _("Couldn't add item"));
}
-
+
+ g_object_unref (swidget);
seahorse_widget_destroy (swidget);
}
@@ -87,45 +86,40 @@ on_add_item_response (GtkDialog *dialog,
gpointer user_data)
{
SeahorseWidget *swidget = SEAHORSE_WIDGET (user_data);
+ SecretCollection *collection;
+ GCancellable *cancellable;
GtkWidget *widget;
- gchar *keyring;
- const gchar *secret;
+ SecretValue *secret;
const gchar *label;
- gpointer request;
- GArray *attributes;
GtkTreeIter iter;
if (response == GTK_RESPONSE_HELP) {
seahorse_widget_show_help (swidget);
} else if (response == GTK_RESPONSE_ACCEPT) {
-
+ widget = seahorse_widget_get_widget (swidget, "item-keyring");
+ if (!gtk_combo_box_get_active_iter (GTK_COMBO_BOX (widget), &iter))
+ return;
+ gtk_tree_model_get (gtk_combo_box_get_model (GTK_COMBO_BOX (widget)),
+ &iter, 1, &collection, -1);
+
widget = seahorse_widget_get_widget (swidget, "item-label");
label = gtk_entry_get_text (GTK_ENTRY (widget));
g_return_if_fail (label && label[0]);
widget = g_object_get_data (G_OBJECT (swidget), "gkr-secure-entry");
- secret = gtk_entry_get_text (GTK_ENTRY (widget));
-
- widget = seahorse_widget_get_widget (swidget, "item-keyring");
- if (gtk_combo_box_get_active_iter (GTK_COMBO_BOX (widget), &iter)) {
- gtk_tree_model_get (gtk_combo_box_get_model (GTK_COMBO_BOX (widget)),
- &iter, 0, &keyring, -1);
- } else {
- keyring = NULL;
- }
-
- attributes = gnome_keyring_attribute_list_new ();
-
- request = gnome_keyring_item_create (keyring, GNOME_KEYRING_ITEM_NOTE, label,
- attributes, secret, FALSE, item_add_done,
- g_object_ref (swidget), g_object_unref);
- g_return_if_fail (request);
- seahorse_gkr_dialog_begin_request (swidget, request);
-
- g_free (keyring);
- gnome_keyring_attribute_list_free (attributes);
-
+ secret = secret_value_new (gtk_entry_get_text (GTK_ENTRY (widget)),
+ -1, "text/plain");
+
+ cancellable = seahorse_gkr_dialog_begin_request (swidget);
+ secret_service_store (secret_collection_get_service (collection),
+ SECRET_SCHEMA_NOTE,
+ g_dbus_proxy_get_object_path (G_DBUS_PROXY (collection)),
+ label, secret, cancellable, on_item_stored,
+ g_object_ref (swidget),
+ NULL);
+ g_object_unref (cancellable);
+
} else {
seahorse_widget_destroy (swidget);
}
@@ -147,7 +141,7 @@ seahorse_gkr_add_item_show (GtkWindow *parent)
/* Load up a list of all the keyrings, and select the default */
widget = seahorse_widget_get_widget (swidget, "item-keyring");
- store = gtk_list_store_new (1, G_TYPE_STRING);
+ store = gtk_list_store_new (2, G_TYPE_STRING, SECRET_TYPE_COLLECTION);
gtk_combo_box_set_model (GTK_COMBO_BOX (widget), GTK_TREE_MODEL (store));
cell = gtk_cell_renderer_text_new ();
gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (widget), cell, TRUE);
@@ -156,7 +150,10 @@ seahorse_gkr_add_item_show (GtkWindow *parent)
keyrings = seahorse_gkr_backend_get_keyrings (NULL);
for (l = keyrings; l; l = g_list_next (l)) {
gtk_list_store_append (store, &iter);
- gtk_list_store_set (store, &iter, 0, seahorse_gkr_keyring_get_name (l->data), -1);
+ gtk_list_store_set (store, &iter,
+ 0, secret_collection_get_label (l->data),
+ 1, l->data,
+ -1);
if (seahorse_gkr_keyring_get_is_default (l->data))
gtk_combo_box_set_active_iter (GTK_COMBO_BOX (widget), &iter);
}
diff --git a/gkr/seahorse-gkr-add-keyring.c b/gkr/seahorse-gkr-add-keyring.c
index fe76bb8..5c96a79 100644
--- a/gkr/seahorse-gkr-add-keyring.c
+++ b/gkr/seahorse-gkr-add-keyring.c
@@ -52,26 +52,27 @@ void on_add_keyring_properties_response (GtkDialog *dialog,
* internal seahorse list of keyrings
*/
static void
-keyring_add_done (GnomeKeyringResult result, gpointer data)
+on_keyring_create (GObject *source,
+ GAsyncResult *result,
+ gpointer data)
{
SeahorseWidget *swidget = SEAHORSE_WIDGET (data);
+ GError *error = NULL;
g_return_if_fail (swidget);
/* Clear the operation without cancelling it since it is complete */
seahorse_gkr_dialog_complete_request (swidget, FALSE);
+ secret_collection_create_finish (result, &error);
+
/* Successful. Update the listings and stuff. */
- if (result == GNOME_KEYRING_RESULT_OK) {
- seahorse_gkr_backend_load_async (NULL, NULL, NULL, NULL);
-
- /* Setting the default keyring failed */
- } else if (result != GNOME_KEYRING_RESULT_CANCELLED) {
- seahorse_util_show_error (seahorse_widget_get_toplevel (swidget),
- _("Couldn't add keyring"),
- gnome_keyring_result_to_message (result));
+ if (error != NULL) {
+ seahorse_util_handle_error (&error, seahorse_widget_get_toplevel (swidget),
+ _("Couldn't add keyring"));
}
-
+
+ g_object_unref (swidget);
seahorse_widget_destroy (swidget);
}
@@ -108,10 +109,10 @@ on_add_keyring_properties_response (GtkDialog *dialog,
gpointer user_data)
{
SeahorseWidget *swidget = SEAHORSE_WIDGET (user_data);
+ GCancellable *cancellable;
GtkEntry *entry;
const gchar *keyring;
- gpointer request;
-
+
if (response == GTK_RESPONSE_HELP) {
seahorse_widget_show_help (swidget);
@@ -122,11 +123,14 @@ on_add_keyring_properties_response (GtkDialog *dialog,
keyring = gtk_entry_get_text (entry);
g_return_if_fail (keyring && keyring[0]);
-
- request = gnome_keyring_create (keyring, NULL, keyring_add_done, g_object_ref (swidget), g_object_unref);
- g_return_if_fail (request);
- seahorse_gkr_dialog_begin_request (swidget, request);
-
+
+ cancellable = seahorse_gkr_dialog_begin_request (swidget);
+
+ secret_collection_create (seahorse_gkr_backend_get_service (NULL),
+ keyring, NULL, cancellable, on_keyring_create,
+ g_object_ref (swidget));
+ g_object_unref (cancellable);
+
} else {
seahorse_widget_destroy (swidget);
}
diff --git a/gkr/seahorse-gkr-backend.c b/gkr/seahorse-gkr-backend.c
index 4f009be..48dbf01 100644
--- a/gkr/seahorse-gkr-backend.c
+++ b/gkr/seahorse-gkr-backend.c
@@ -24,28 +24,49 @@
#include "seahorse-gkr-actions.h"
#include "seahorse-gkr-backend.h"
#include "seahorse-gkr-dialogs.h"
-#include "seahorse-gkr-operation.h"
#include "seahorse-backend.h"
#include "seahorse-progress.h"
-#include <gnome-keyring.h>
-
#include <glib/gi18n.h>
+
+typedef SecretService MySecretService;
+typedef SecretServiceClass MySecretServiceClass;
+
+GType my_secret_service_get_type (void);
+
+G_DEFINE_TYPE (MySecretService, my_secret_service, SECRET_TYPE_SERVICE);
+
+static void
+my_secret_service_init (MySecretService *self)
+{
+
+}
+
+static void
+my_secret_service_class_init (MySecretServiceClass *klass)
+{
+ klass->collection_gtype = SEAHORSE_TYPE_GKR_KEYRING;
+ klass->item_gtype = SEAHORSE_TYPE_GKR_ITEM;
+}
+
enum {
PROP_0,
PROP_NAME,
PROP_LABEL,
PROP_DESCRIPTION,
- PROP_ACTIONS
+ PROP_ACTIONS,
+ PROP_ALIASES
};
static SeahorseGkrBackend *gkr_backend = NULL;
struct _SeahorseGkrBackend {
GObject parent;
+ SecretService *service;
GHashTable *keyrings;
+ GHashTable *aliases;
GtkActionGroup *actions;
};
@@ -71,6 +92,89 @@ seahorse_gkr_backend_init (SeahorseGkrBackend *self)
self->actions = seahorse_gkr_backend_actions_instance ();
self->keyrings = g_hash_table_new_full (g_str_hash, g_str_equal,
g_free, g_object_unref);
+ self->aliases = g_hash_table_new_full (g_str_hash, g_str_equal,
+ g_free, g_free);
+}
+
+static void
+refresh_collection (SeahorseGkrBackend *self)
+{
+ GHashTable *seen = NULL;
+ GHashTableIter iter;
+ const gchar *object_path;
+ SeahorseGkrKeyring *keyring;
+ GList *keyrings;
+ GList *l;
+
+ seen = g_hash_table_new (g_str_hash, g_str_equal);
+
+ keyrings = secret_service_get_collections (self->service);
+
+ /* Add any keyrings we don't have */
+ for (l = keyrings; l != NULL; l = g_list_next (l)) {
+ object_path = g_dbus_proxy_get_object_path (l->data);
+
+ /* Don't list the session keyring */
+ if (g_strcmp0 (g_hash_table_lookup (self->aliases, "session"), object_path) == 0)
+ continue;
+
+ keyring = l->data;
+ g_hash_table_add (seen, (gpointer)object_path);
+
+ if (!g_hash_table_lookup (self->keyrings, object_path)) {
+ g_hash_table_insert (self->keyrings,
+ g_strdup (object_path),
+ g_object_ref (keyring));
+ gcr_collection_emit_added (GCR_COLLECTION (self), G_OBJECT (keyring));
+ }
+ }
+
+ /* Remove any that we didn't find */
+ g_hash_table_iter_init (&iter, self->keyrings);
+ while (g_hash_table_iter_next (&iter, (gpointer *)&object_path, NULL)) {
+ if (!g_hash_table_lookup (seen, object_path)) {
+ keyring = g_hash_table_lookup (self->keyrings, object_path);
+ g_object_ref (keyring);
+ g_hash_table_iter_remove (&iter);
+ gcr_collection_emit_removed (GCR_COLLECTION (self), G_OBJECT (keyring));
+ g_object_unref (keyring);
+ }
+ }
+
+ g_hash_table_destroy (seen);
+ g_list_free_full (keyrings, g_object_unref);
+}
+
+static void
+on_notify_collections (GObject *obj,
+ GParamSpec *pspec,
+ gpointer user_data)
+{
+ refresh_collection (SEAHORSE_GKR_BACKEND (user_data));
+}
+
+static void
+on_service_new (GObject *source,
+ GAsyncResult *result,
+ gpointer user_data)
+{
+ SeahorseGkrBackend *self = SEAHORSE_GKR_BACKEND (user_data);
+ GError *error = NULL;
+
+ self->service = secret_service_new_finish (result, &error);
+ if (error == NULL) {
+ g_signal_connect (self->service, "notify::collections", G_CALLBACK (on_notify_collections), self);
+ refresh_collection (self);
+
+ secret_service_ensure_collections (self->service, NULL, NULL, NULL);
+ secret_service_ensure_session (self->service, NULL, NULL, NULL);
+ seahorse_gkr_backend_load_async (self, NULL, NULL, NULL);
+ } else {
+ g_warning ("couldn't connect to secret service: %s", error->message);
+ g_error_free (error);
+ }
+
+ g_object_unref (self);
}
static void
@@ -80,7 +184,8 @@ seahorse_gkr_backend_constructed (GObject *obj)
G_OBJECT_CLASS (seahorse_gkr_backend_parent_class)->constructed (obj);
- seahorse_gkr_backend_load_async (self, NULL, NULL, NULL);
+ secret_service_new (my_secret_service_get_type (), NULL, SECRET_SERVICE_NONE,
+ NULL, on_service_new, g_object_ref (self));
}
static void
@@ -104,6 +209,9 @@ seahorse_gkr_backend_get_property (GObject *obj,
case PROP_ACTIONS:
g_value_set_object (value, self->actions);
break;
+ case PROP_ALIASES:
+ g_value_set_boxed (value, self->aliases);
+ break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (obj, prop_id, pspec);
break;
@@ -115,7 +223,14 @@ seahorse_gkr_backend_dispose (GObject *obj)
{
SeahorseGkrBackend *self = SEAHORSE_GKR_BACKEND (obj);
+ if (self->service) {
+ g_signal_handlers_disconnect_by_func (self->service, on_notify_collections, self);
+ g_object_unref (self->service);
+ self->service = NULL;
+ }
+
g_hash_table_remove_all (self->keyrings);
+ g_hash_table_remove_all (self->aliases);
gtk_action_group_set_sensitive (self->actions, FALSE);
G_OBJECT_CLASS (seahorse_gkr_backend_parent_class)->finalize (obj);
@@ -126,7 +241,10 @@ seahorse_gkr_backend_finalize (GObject *obj)
{
SeahorseGkrBackend *self = SEAHORSE_GKR_BACKEND (obj);
+ g_assert (self->service == NULL);
+
g_hash_table_destroy (self->keyrings);
+ g_hash_table_destroy (self->aliases);
g_clear_object (&self->actions);
g_return_if_fail (gkr_backend == self);
@@ -149,6 +267,10 @@ seahorse_gkr_backend_class_init (SeahorseGkrBackendClass *klass)
g_object_class_override_property (gobject_class, PROP_LABEL, "label");
g_object_class_override_property (gobject_class, PROP_DESCRIPTION, "description");
g_object_class_override_property (gobject_class, PROP_ACTIONS, "actions");
+
+ g_object_class_install_property (gobject_class, PROP_ALIASES,
+ g_param_spec_boxed ("aliases", "aliases", "Aliases",
+ G_TYPE_HASH_TABLE, G_PARAM_READABLE));
}
static guint
@@ -170,13 +292,17 @@ seahorse_gkr_backend_contains (GcrCollection *collection,
GObject *object)
{
SeahorseGkrBackend *self = SEAHORSE_GKR_BACKEND (collection);
- const gchar *keyring_name;
+ gboolean have;
+ gchar *uri;
if (!SEAHORSE_IS_GKR_KEYRING (object))
return FALSE;
- keyring_name = seahorse_gkr_keyring_get_name (SEAHORSE_GKR_KEYRING (object));
- return g_hash_table_lookup (self->keyrings, keyring_name) == object;
+ g_object_get (object, "uri", &uri, NULL);
+ have = (g_hash_table_lookup (self->keyrings, uri) == object);
+ g_free (uri);
+
+ return have;
}
static void
@@ -192,13 +318,7 @@ seahorse_gkr_backend_lookup_place (SeahorseBackend *backend,
const gchar *uri)
{
SeahorseGkrBackend *self = SEAHORSE_GKR_BACKEND (backend);
-
- if (g_str_has_prefix (uri, "secret-service://")) {
- uri += strlen ("secret-service://");
- return g_hash_table_lookup (self->keyrings, uri);
- }
-
- return NULL;
+ return g_hash_table_lookup (self->keyrings, uri);
}
static void
@@ -228,14 +348,12 @@ seahorse_gkr_backend_get (void)
return gkr_backend;
}
-SeahorseGkrKeyring *
-seahorse_gkr_backend_get_keyring (SeahorseGkrBackend *self,
- const gchar *keyring_name)
+SecretService *
+seahorse_gkr_backend_get_service (SeahorseGkrBackend *self)
{
self = self ? self : seahorse_gkr_backend_get ();
g_return_val_if_fail (SEAHORSE_IS_GKR_BACKEND (self), NULL);
- g_return_val_if_fail (keyring_name != NULL, NULL);
- return g_hash_table_lookup (self->keyrings, keyring_name);
+ return self->service;
}
GList *
@@ -246,212 +364,101 @@ seahorse_gkr_backend_get_keyrings (SeahorseGkrBackend *self)
return g_hash_table_get_values (self->keyrings);
}
-void
-seahorse_gkr_backend_remove_keyring (SeahorseGkrBackend *self,
- SeahorseGkrKeyring *keyring)
-{
- const gchar *keyring_name;
-
- self = self ? self : seahorse_gkr_backend_get ();
- g_return_if_fail (SEAHORSE_IS_GKR_BACKEND (self));
- g_return_if_fail (SEAHORSE_IS_GKR_KEYRING (keyring));
-
- keyring_name = seahorse_gkr_keyring_get_name (keyring);
- g_return_if_fail (g_hash_table_lookup (self->keyrings, keyring_name) == keyring);
-
- g_object_ref (keyring);
-
- g_hash_table_remove (self->keyrings, keyring_name);
- gcr_collection_emit_removed (GCR_COLLECTION (self), G_OBJECT (keyring));
-
- g_object_unref (keyring);
-}
-
-
typedef struct {
- SeahorseGkrBackend *backend;
- GCancellable *cancellable;
- gulong cancelled_sig;
- gpointer request;
- gint num_loads;
-} backend_load_closure;
+ gint outstanding;
+} LoadClosure;
static void
-backend_load_free (gpointer data)
+on_load_read_alias (GObject *source,
+ GAsyncResult *result,
+ const gchar *alias,
+ gpointer user_data)
{
- backend_load_closure *closure = data;
- g_assert (closure->request == NULL);
- g_assert (closure->num_loads == 0);
- if (closure->cancellable && closure->cancelled_sig)
- g_signal_handler_disconnect (closure->cancellable,
- closure->cancelled_sig);
- g_clear_object (&closure->cancellable);
- g_clear_object (&closure->backend);
- g_free (closure);
-}
-
-static void
-on_backend_load_default_keyring (GnomeKeyringResult result,
- const gchar *default_name,
- gpointer user_data)
-{
- SeahorseGkrBackend *self = SEAHORSE_GKR_BACKEND (user_data);
- const gchar *keyring_name;
- gboolean is_default;
- GList *keyrings, *l;
+ GSimpleAsyncResult *async = G_SIMPLE_ASYNC_RESULT (user_data);
+ LoadClosure *load = g_simple_async_result_get_op_res_gpointer (async);
+ SeahorseGkrBackend *self = SEAHORSE_GKR_BACKEND (g_async_result_get_source_object (user_data));
+ GError *error = NULL;
+ gchar *path;
- if (result != GNOME_KEYRING_RESULT_OK) {
- if (result != GNOME_KEYRING_RESULT_CANCELLED)
- g_warning ("couldn't get default keyring name: %s", gnome_keyring_result_to_message (result));
- return;
+ path = secret_service_read_alias_path_finish (SECRET_SERVICE (source), result, &error);
+ if (path != NULL) {
+ g_hash_table_replace (self->aliases, g_strdup (alias), path);
+ g_object_notify (G_OBJECT (self), "aliases");
}
- keyrings = seahorse_gkr_backend_get_keyrings (self);
- for (l = keyrings; l != NULL; l = g_list_next (l)) {
- keyring_name = seahorse_gkr_keyring_get_name (l->data);
- g_return_if_fail (keyring_name);
+ if (error != NULL)
+ g_simple_async_result_take_error (async, error);
- /* Remember default keyring could be null in strange circumstances */
- is_default = default_name && g_str_equal (keyring_name, default_name);
- g_object_set (l->data, "is-default", is_default, NULL);
+ load->outstanding--;
+ if (load->outstanding <= 0) {
+ refresh_collection (self);
+ g_simple_async_result_complete (async);
}
- g_list_free (keyrings);
-}
+ g_object_unref (self);
+ g_object_unref (async);
+
+}
static void
-on_backend_load_keyring_complete (GObject *object,
- GAsyncResult *result,
- gpointer user_data)
+on_load_read_default_alias (GObject *source,
+ GAsyncResult *result,
+ gpointer user_data)
{
- GSimpleAsyncResult *res = G_SIMPLE_ASYNC_RESULT (user_data);
- SeahorseGkrKeyring *keyring = SEAHORSE_GKR_KEYRING (object);
- backend_load_closure *closure = g_simple_async_result_get_op_res_gpointer (res);
- GError *error = NULL;
-
- g_assert (closure->num_loads > 0);
- closure->num_loads--;
- seahorse_progress_end (closure->cancellable, keyring);
-
- if (!seahorse_place_load_finish (SEAHORSE_PLACE (keyring), result, &error))
- g_simple_async_result_take_error (res, error);
-
- if (closure->num_loads == 0)
- g_simple_async_result_complete (res);
-
- g_object_unref (res);
+ on_load_read_alias (source, result, "default", user_data);
}
static void
-on_backend_load_list_keyring_names_complete (GnomeKeyringResult result,
- GList *list,
- gpointer user_data)
+on_load_read_session_alias (GObject *source,
+ GAsyncResult *result,
+ gpointer user_data)
{
- GSimpleAsyncResult *res = G_SIMPLE_ASYNC_RESULT (user_data);
- backend_load_closure *closure = g_simple_async_result_get_op_res_gpointer (res);
- SeahorseGkrKeyring *keyring;
- GError *error = NULL;
- gchar *keyring_name;
- GHashTableIter iter;
- GHashTable *checks;
- GList *l;
-
- closure->request = NULL;
-
- if (seahorse_gkr_propagate_error (result, &error)) {
- g_simple_async_result_take_error (res, error);
- g_simple_async_result_complete_in_idle (res);
- return;
- }
-
- /* Load up a list of all the current names */
- checks = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_object_unref);
- g_hash_table_iter_init (&iter, closure->backend->keyrings);
- while (g_hash_table_iter_next (&iter, (gpointer *)&keyring_name, (gpointer *)&keyring))
- g_hash_table_insert (checks, g_strdup (keyring_name), g_object_ref (keyring));
-
- for (l = list; l; l = g_list_next (l)) {
- keyring_name = l->data;
-
- /* Don't show the 'session' keyring */
- if (g_str_equal (keyring_name, "session"))
- continue;
-
- keyring = g_hash_table_lookup (checks, keyring_name);
-
- /* Already have a keyring */
- if (keyring != NULL) {
- g_object_ref (keyring);
- g_hash_table_remove (checks, keyring_name);
-
- /* Create a new keyring for this one */
- } else {
- keyring = seahorse_gkr_keyring_new (keyring_name);
- g_hash_table_insert (closure->backend->keyrings,
- g_strdup (keyring_name),
- g_object_ref (keyring));
- gcr_collection_emit_added (GCR_COLLECTION (closure->backend),
- G_OBJECT (keyring));
- }
-
- /* Refresh the keyring as well, and track the load */
- seahorse_place_load_async (SEAHORSE_PLACE (keyring), closure->cancellable,
- on_backend_load_keyring_complete,
- g_object_ref (res));
- seahorse_progress_prep_and_begin (closure->cancellable, keyring, NULL);
- closure->num_loads++;
- g_object_unref (keyring);
- }
-
- g_hash_table_iter_init (&iter, checks);
- while (g_hash_table_iter_next (&iter, (gpointer *)&keyring_name, (gpointer *)&keyring))
- seahorse_gkr_backend_remove_keyring (closure->backend, keyring);
- g_hash_table_destroy (checks);
-
- if (list == NULL)
- g_simple_async_result_complete_in_idle (res);
-
- /* Get the default keyring in the background */
- gnome_keyring_get_default_keyring (on_backend_load_default_keyring,
- g_object_ref (closure->backend),
- g_object_unref);
+ on_load_read_alias (source, result, "session", user_data);
}
static void
-on_backend_load_cancelled (GCancellable *cancellable,
- gpointer user_data)
+on_load_read_login_alias (GObject *source,
+ GAsyncResult *result,
+ gpointer user_data)
{
- backend_load_closure *closure = user_data;
-
- if (closure->request)
- gnome_keyring_cancel_request (closure->request);
+ on_load_read_alias (source, result, "login", user_data);
}
+
void
seahorse_gkr_backend_load_async (SeahorseGkrBackend *self,
GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer user_data)
{
- backend_load_closure *closure;
- GSimpleAsyncResult *res;
+ LoadClosure *load;
+ GSimpleAsyncResult *async;
self = self ? self : seahorse_gkr_backend_get ();
- res = g_simple_async_result_new (G_OBJECT (self), callback, user_data,
- seahorse_gkr_backend_load_async);
- closure = g_new0 (backend_load_closure, 1);
- closure->cancellable = cancellable ? g_object_ref (cancellable) : NULL;
- closure->backend = g_object_ref (self);
- g_simple_async_result_set_op_res_gpointer (res, closure, backend_load_free);
+ async = g_simple_async_result_new (G_OBJECT (self), callback, user_data,
+ seahorse_gkr_backend_load_async);
+ load = g_new0 (LoadClosure, 1);
+ load->outstanding = 0;
+ g_simple_async_result_set_op_res_gpointer (async, load, g_free);
+
+ if (!self->service) {
+ g_simple_async_result_complete_in_idle (async);
+ g_object_unref (async);
+ return;
+ }
- closure->request = gnome_keyring_list_keyring_names (on_backend_load_list_keyring_names_complete,
- g_object_ref (res), g_object_unref);
+ secret_service_read_alias_path (self->service, "default", cancellable,
+ on_load_read_default_alias, g_object_ref (async));
+ load->outstanding++;
- if (cancellable)
- closure->cancelled_sig = g_cancellable_connect (cancellable,
- G_CALLBACK (on_backend_load_cancelled),
- closure, NULL);
+ secret_service_read_alias_path (self->service, "session", cancellable,
+ on_load_read_session_alias, g_object_ref (async));
+ load->outstanding++;
- g_object_unref (res);
+ secret_service_read_alias_path (self->service, "login", cancellable,
+ on_load_read_login_alias, g_object_ref (async));
+ load->outstanding++;
+
+ g_object_unref (async);
}
gboolean
@@ -469,3 +476,15 @@ seahorse_gkr_backend_load_finish (SeahorseGkrBackend *self,
return TRUE;
}
+
+gboolean
+seahorse_gkr_backend_has_alias (SeahorseGkrBackend *self,
+ const gchar *alias,
+ SeahorseGkrKeyring *keyring)
+{
+ const gchar *object_path;
+
+ self = self ? self : seahorse_gkr_backend_get ();
+ object_path = g_dbus_proxy_get_object_path (G_DBUS_PROXY (keyring));
+ return g_strcmp0 (g_hash_table_lookup (self->aliases, alias), object_path) == 0;
+}
diff --git a/gkr/seahorse-gkr-backend.h b/gkr/seahorse-gkr-backend.h
index 6f34ba1..2d63250 100644
--- a/gkr/seahorse-gkr-backend.h
+++ b/gkr/seahorse-gkr-backend.h
@@ -47,12 +47,12 @@ GType seahorse_gkr_backend_get_type (void) G_GNUC_CONST;
SeahorseGkrBackend * seahorse_gkr_backend_get (void);
-SeahorseGkrKeyring * seahorse_gkr_backend_get_keyring (SeahorseGkrBackend *self,
- const gchar *keyring_name);
+SecretService * seahorse_gkr_backend_get_service (SeahorseGkrBackend *self);
GList * seahorse_gkr_backend_get_keyrings (SeahorseGkrBackend *self);
-void seahorse_gkr_backend_remove_keyring (SeahorseGkrBackend *self,
+gboolean seahorse_gkr_backend_has_alias (SeahorseGkrBackend *self,
+ const gchar *alias,
SeahorseGkrKeyring *keyring);
void seahorse_gkr_backend_load_async (SeahorseGkrBackend *self,
diff --git a/gkr/seahorse-gkr-dialogs.c b/gkr/seahorse-gkr-dialogs.c
index 5ab8528..93de223 100644
--- a/gkr/seahorse-gkr-dialogs.c
+++ b/gkr/seahorse-gkr-dialogs.c
@@ -51,16 +51,23 @@ update_wait_cursor (GtkWidget *dialog, gpointer unused)
gdk_window_set_cursor (gtk_widget_get_window (dialog), cursor);
}
-void
-seahorse_gkr_dialog_begin_request (SeahorseWidget *swidget, gpointer request)
+static void
+cancel_and_unref_cancellable (gpointer data)
+{
+ GCancellable *cancellable = data;
+ g_cancellable_cancel (cancellable);
+ g_object_unref (cancellable);
+}
+
+GCancellable *
+seahorse_gkr_dialog_begin_request (SeahorseWidget *swidget)
{
+ GCancellable *cancellable;
GtkWidget *dialog;
-
- g_return_if_fail (request);
-
+
dialog = seahorse_widget_get_toplevel (swidget);
- g_return_if_fail (GTK_IS_WIDGET (dialog));
-
+ g_return_val_if_fail (GTK_IS_WIDGET (dialog), NULL);
+
/* Cancel any old operation going on */
seahorse_gkr_dialog_complete_request (swidget, TRUE);
@@ -68,8 +75,10 @@ seahorse_gkr_dialog_begin_request (SeahorseWidget *swidget, gpointer request)
* Start the operation and tie it to the widget so that it will get
* cancelled if the widget is destroyed before the operation is complete
*/
- g_object_set_data_full (G_OBJECT (dialog), "gkr-request", request,
- gnome_keyring_cancel_request);
+ cancellable = g_cancellable_new ();
+ g_object_set_data_full (G_OBJECT (dialog), "gkr-request",
+ g_object_ref (cancellable),
+ cancel_and_unref_cancellable);
if (gtk_widget_get_realized (dialog))
update_wait_cursor (dialog, NULL);
@@ -77,20 +86,23 @@ seahorse_gkr_dialog_begin_request (SeahorseWidget *swidget, gpointer request)
g_signal_connect (dialog, "realize", G_CALLBACK (update_wait_cursor), dialog);
gtk_widget_set_sensitive (dialog, FALSE);
+ return cancellable;
}
void
seahorse_gkr_dialog_complete_request (SeahorseWidget *swidget, gboolean cancel)
{
GtkWidget *dialog;
- gpointer request;
-
+ GCancellable *cancellable;
+
dialog = seahorse_widget_get_toplevel (swidget);
g_return_if_fail (GTK_IS_WIDGET (dialog));
-
- request = g_object_steal_data (G_OBJECT (dialog), "gkr-request");
- if (request && cancel)
- gnome_keyring_cancel_request (request);
+
+ cancellable = g_object_steal_data (G_OBJECT (dialog), "gkr-request");
+ if (cancellable && cancel)
+ g_cancellable_cancel (cancellable);
+ if (cancellable)
+ g_object_unref (cancellable);
if (gtk_widget_get_realized (dialog))
update_wait_cursor (dialog, NULL);
diff --git a/gkr/seahorse-gkr-dialogs.h b/gkr/seahorse-gkr-dialogs.h
index 8b81b62..031f12b 100644
--- a/gkr/seahorse-gkr-dialogs.h
+++ b/gkr/seahorse-gkr-dialogs.h
@@ -38,7 +38,7 @@ void seahorse_gkr_item_properties_show (SeahorseGkrItem *git, Gtk
void seahorse_gkr_keyring_properties_show (SeahorseGkrKeyring *gkr, GtkWindow *parent);
-void seahorse_gkr_dialog_begin_request (SeahorseWidget *swidget, gpointer request);
+GCancellable * seahorse_gkr_dialog_begin_request (SeahorseWidget *swidget);
void seahorse_gkr_dialog_complete_request (SeahorseWidget *swidget, gboolean cancel);
diff --git a/gkr/seahorse-gkr-item-deleter.c b/gkr/seahorse-gkr-item-deleter.c
index 4bb9ed6..03da1be 100644
--- a/gkr/seahorse-gkr-item-deleter.c
+++ b/gkr/seahorse-gkr-item-deleter.c
@@ -25,13 +25,10 @@
#include "seahorse-gkr-backend.h"
#include "seahorse-gkr-item-deleter.h"
-#include "seahorse-gkr-operation.h"
#include "seahorse-delete-dialog.h"
#include "seahorse-object.h"
-#include <gnome-keyring.h>
-
#include <glib/gi18n.h>
#define SEAHORSE_GKR_ITEM_DELETER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), SEAHORSE_TYPE_GKR_ITEM_DELETER, SeahorseGkrItemDeleterClass))
@@ -81,7 +78,7 @@ seahorse_gkr_item_deleter_create_confirm (SeahorseDeleter *deleter,
num = g_list_length (self->items);
if (num == 1) {
prompt = g_strdup_printf (_ ("Are you sure you want to delete the password '%s'?"),
- seahorse_object_get_label (SEAHORSE_OBJECT (self->items->data)));
+ secret_item_get_label (SECRET_ITEM (self->items->data)));
} else {
prompt = g_strdup_printf (ngettext ("Are you sure you want to delete %d password?",
"Are you sure you want to delete %d passwords?",
@@ -141,39 +138,29 @@ delete_closure_free (gpointer data)
}
static void
-on_delete_gkr_complete (GnomeKeyringResult result,
+on_delete_gkr_complete (GObject *source,
+ GAsyncResult *result,
gpointer user_data)
{
GSimpleAsyncResult *res = G_SIMPLE_ASYNC_RESULT (user_data);
- DeleteClosure *closure = g_simple_async_result_get_op_res_gpointer (res);
- SeahorseGkrItemDeleter *self = SEAHORSE_GKR_ITEM_DELETER (g_async_result_get_source_object (user_data));
- SeahorseGkrKeyring *keyring;
GError *error = NULL;
- guint32 item_id;
- closure->request = NULL;
+ secret_item_delete_finish (SECRET_ITEM (source), result, &error);
+ if (error == NULL) {
+ delete_one_item (res);
- if (seahorse_gkr_propagate_error (result, &error)) {
+ } else {
g_simple_async_result_take_error (res, error);
g_simple_async_result_complete_in_idle (res);
-
- } else {
- g_object_get (closure->current, "place", &keyring, NULL);
- item_id = seahorse_gkr_item_get_item_id (closure->current);
- seahorse_gkr_keyring_remove_item (keyring, item_id);
- g_object_unref (keyring);
- delete_one_item (res);
}
- g_object_unref (self);
+ g_object_unref (res);
}
static void
delete_one_item (GSimpleAsyncResult *res)
{
DeleteClosure *closure = g_simple_async_result_get_op_res_gpointer (res);
- const gchar *name;
- guint32 item_id;
g_clear_object (&closure->current);
closure->current = g_queue_pop_head (&closure->queue);
@@ -181,24 +168,14 @@ delete_one_item (GSimpleAsyncResult *res)
g_simple_async_result_complete_in_idle (res);
} else {
- name = seahorse_gkr_item_get_keyring_name (closure->current);
- item_id = seahorse_gkr_item_get_item_id (closure->current);
- gnome_keyring_item_delete (name, item_id, on_delete_gkr_complete,
- g_object_ref (res), g_object_unref);
+ secret_item_delete (SECRET_ITEM (closure->current),
+ closure->cancellable,
+ on_delete_gkr_complete,
+ g_object_ref (res));
}
}
static void
-on_delete_gkr_cancelled (GCancellable *cancellable,
- gpointer user_data)
-{
- DeleteClosure *closure = user_data;
-
- if (closure->request)
- gnome_keyring_cancel_request (closure->request);
-}
-
-static void
seahorse_gkr_item_deleter_delete_async (SeahorseDeleter *deleter,
GCancellable *cancellable,
GAsyncReadyCallback callback,
@@ -218,11 +195,6 @@ seahorse_gkr_item_deleter_delete_async (SeahorseDeleter *deleter,
g_queue_push_tail (&closure->queue, g_object_ref (l->data));
g_simple_async_result_set_op_res_gpointer (res, closure, delete_closure_free);
- if (cancellable)
- closure->cancelled_sig = g_cancellable_connect (cancellable,
- G_CALLBACK (on_delete_gkr_cancelled),
- closure, NULL);
-
delete_one_item (res);
g_object_unref (res);
}
diff --git a/gkr/seahorse-gkr-item-properties.c b/gkr/seahorse-gkr-item-properties.c
index b4f1db2..f3aacb9 100644
--- a/gkr/seahorse-gkr-item-properties.c
+++ b/gkr/seahorse-gkr-item-properties.c
@@ -25,7 +25,6 @@
#include "seahorse-gkr-dialogs.h"
#include "seahorse-gkr-item.h"
-#include "seahorse-gkr-operation.h"
#include "seahorse-bind.h"
#include "seahorse-icons.h"
@@ -148,7 +147,7 @@ transform_network_visible (const GValue *from, GValue *to)
static gboolean
transform_attributes_server (const GValue *from, GValue *to)
{
- GnomeKeyringAttributeList *attrs;
+ GHashTable *attrs;
attrs = g_value_get_boxed (from);
if (attrs)
g_value_set_string (to, seahorse_gkr_find_string_attribute (attrs, "server"));
@@ -160,7 +159,7 @@ transform_attributes_server (const GValue *from, GValue *to)
static gboolean
transform_attributes_user (const GValue *from, GValue *to)
{
- GnomeKeyringAttributeList *attrs;
+ GHashTable *attrs;
attrs = g_value_get_boxed (from);
if (attrs)
g_value_set_string (to, seahorse_gkr_find_string_attribute (attrs, "user"));
@@ -174,7 +173,9 @@ transfer_password (SeahorseGkrItem *git, SeahorseWidget *swidget)
{
GtkWidget *expander;
GtkEntry *entry;
- const gchar *secret;
+ SecretValue *secret;
+ const gchar *password;
+ gsize length;
expander = seahorse_widget_get_widget (swidget, "password-expander");
g_return_if_fail (expander);
@@ -182,12 +183,18 @@ transfer_password (SeahorseGkrItem *git, SeahorseWidget *swidget)
entry = g_object_get_data (G_OBJECT (swidget), "secure-password-entry");
g_return_if_fail (entry);
+ password = "";
+ length = 0;
+
if (gtk_expander_get_expanded (GTK_EXPANDER (expander))) {
secret = seahorse_gkr_item_get_secret (git);
- gtk_entry_set_text (entry, secret ? secret : "");
- } else {
- gtk_entry_set_text (entry, "");
+ if (secret)
+ password = secret_value_get (secret, &length);
}
+
+ gtk_entry_buffer_set_text (gtk_entry_get_buffer (entry),
+ password, length);
+
g_object_set_data (G_OBJECT (entry), "changed", NULL);
}
@@ -201,7 +208,7 @@ on_update_password_ready (GObject *source,
GError *error = NULL;
GtkWidget *expander;
- if (seahorse_gkr_update_secret_finish (git, result, &error)) {
+ if (seahorse_gkr_item_set_secret_finish (git, result, &error)) {
transfer_password (git, swidget);
} else {
@@ -225,6 +232,7 @@ password_activate (GtkEntry *entry,
SeahorseGkrItem *git;
GtkWidget *expander;
GCancellable *cancellable;
+ SecretValue *value;
object = SEAHORSE_OBJECT_WIDGET (swidget)->object;
if (!object)
@@ -249,9 +257,11 @@ password_activate (GtkEntry *entry,
gtk_widget_set_sensitive (expander, FALSE);
cancellable = g_cancellable_new ();
- seahorse_gkr_update_secret_async (git, gtk_entry_get_text (entry), cancellable,
- on_update_password_ready, g_object_ref (swidget));
+ value = secret_value_new (gtk_entry_get_text (entry), -1, "text/plain");
+ seahorse_gkr_item_set_secret (git, value, cancellable,
+ on_update_password_ready, g_object_ref (swidget));
seahorse_progress_show (cancellable, _("Updating password"), TRUE);
+ secret_value_unref (value);
g_object_unref (cancellable);
}
@@ -325,11 +335,11 @@ on_item_description_complete (GObject *source,
SeahorseGkrItem *git = SEAHORSE_GKR_ITEM (source);
GError *error = NULL;
- if (!seahorse_gkr_update_description_finish (git, result, &error)) {
+ if (!secret_item_set_label_finish (SECRET_ITEM (git), result, &error)) {
/* Set back to original */
gtk_entry_set_text (closure->entry,
- seahorse_object_get_label (SEAHORSE_OBJECT (git)));
+ secret_item_get_label (SECRET_ITEM (git)));
seahorse_util_show_error (seahorse_widget_get_toplevel (closure->swidget),
_("Couldn't set description."), error->message);
@@ -369,9 +379,8 @@ on_item_description_activate (GtkWidget *entry,
closure->entry = GTK_ENTRY (entry);
cancellable = g_cancellable_new ();
- seahorse_gkr_update_description_async (git, gtk_entry_get_text (GTK_ENTRY (entry)),
- cancellable, on_item_description_complete,
- closure);
+ secret_item_set_label (SECRET_ITEM (git), gtk_entry_get_text (GTK_ENTRY (entry)),
+ cancellable, on_item_description_complete, closure);
seahorse_progress_show (cancellable, _("Updating password"), TRUE);
g_object_unref (cancellable);
}
@@ -425,11 +434,11 @@ setup_main (SeahorseWidget *swidget)
seahorse_widget_get_widget (swidget, "login-field"), NULL);
/* Server name */
- seahorse_bind_property_full ("item-attributes", object, transform_attributes_server, "label",
+ seahorse_bind_property_full ("attributes", object, transform_attributes_server, "label",
seahorse_widget_get_widget (swidget, "server-field"), NULL);
/* User name */
- seahorse_bind_property_full ("item-attributes", object, transform_attributes_user, "label",
+ seahorse_bind_property_full ("attributes", object, transform_attributes_user, "label",
seahorse_widget_get_widget (swidget, "login-field"), NULL);
/* Create the password entry */
@@ -465,36 +474,27 @@ setup_main (SeahorseWidget *swidget)
static gboolean
transform_item_details (const GValue *from, GValue *to)
{
- GnomeKeyringAttributeList *attrs;
- GnomeKeyringAttribute *attr;
+ GHashTableIter iter;
+ GHashTable *attrs;
GString *details;
+ gpointer key;
+ gpointer value;
gchar *text;
- guint i;
g_return_val_if_fail (G_VALUE_TYPE (to) == G_TYPE_STRING, FALSE);
attrs = g_value_get_boxed (from);
details = g_string_new (NULL);
if (attrs) {
- /* Build up the display string */
- for(i = 0; i < attrs->len; ++i) {
- attr = &(gnome_keyring_attribute_list_index (attrs, i));
- text = g_markup_escape_text (attr->name, -1);
- g_string_append_printf (details, "<b>%s</b>: ", text);
+ g_hash_table_iter_init (&iter, attrs);
+ while (g_hash_table_iter_next (&iter, &key, &value)) {
+ if (g_str_has_prefix (key, "gkr:") ||
+ g_str_has_prefix (key, "xdg:"))
+ continue;
+ text = g_markup_escape_text (key, -1);
+ g_string_append_printf (details, "<b>%s</b>: %s\n",
+ text, (gchar *)value);
g_free (text);
- switch (attr->type) {
- case GNOME_KEYRING_ATTRIBUTE_TYPE_STRING:
- text = g_markup_escape_text (attr->value.string, -1);
- g_string_append_printf (details, "%s\n", text);
- g_free (text);
- break;
- case GNOME_KEYRING_ATTRIBUTE_TYPE_UINT32:
- g_string_append_printf (details, "%u\n", attr->value.integer);
- break;
- default:
- g_string_append (details, "<i>[invalid]</i>\n");
- break;
- }
}
}
@@ -513,8 +513,8 @@ setup_details (SeahorseWidget *swidget)
widget = seahorse_widget_get_widget (swidget, "details-box");
g_return_if_fail (widget != NULL);
gtk_label_set_use_markup (GTK_LABEL (widget), TRUE);
-
- seahorse_bind_property_full ("item-attributes", object, transform_item_details,
+
+ seahorse_bind_property_full ("attributes", object, transform_item_details,
"label", widget, NULL);
}
diff --git a/gkr/seahorse-gkr-item.c b/gkr/seahorse-gkr-item.c
index 1b01cdf..c4ff513 100644
--- a/gkr/seahorse-gkr-item.c
+++ b/gkr/seahorse-gkr-item.c
@@ -22,6 +22,7 @@
#include "config.h"
+#include <stdlib.h>
#include <string.h>
#include <glib/gi18n.h>
@@ -32,7 +33,6 @@
#include "seahorse-gkr-item.h"
#include "seahorse-gkr-item-deleter.h"
#include "seahorse-gkr-keyring.h"
-#include "seahorse-gkr-operation.h"
#include "seahorse-deletable.h"
#include "seahorse-icons.h"
@@ -57,8 +57,8 @@ typedef struct _DisplayEntry DisplayEntry;
typedef struct _DisplayInfo DisplayInfo;
typedef void (*DisplayCustom) (const DisplayEntry *entry,
- GnomeKeyringItemInfo *item_info,
- GnomeKeyringAttributeList *item_attrs,
+ const gchar *label,
+ GHashTable *item_attrs,
DisplayInfo *info);
struct _DisplayEntry {
@@ -81,51 +81,39 @@ typedef struct {
const gchar *match_pattern;
} MappingEntry;
-typedef struct {
- GnomeKeyringItemType old;
- const gchar *item_type;
-} OldItemTypes;
-
static guint32
-get_attribute_int (GnomeKeyringAttributeList *attrs,
+get_attribute_int (GHashTable *attrs,
const gchar *name)
{
- guint i;
+ const gchar *value;
+ gchar *end;
+ guint32 num;
if (!attrs)
return 0;
- for (i = 0; i < attrs->len; i++) {
- GnomeKeyringAttribute *attr = &(gnome_keyring_attribute_list_index (attrs, i));
- if (g_ascii_strcasecmp (name, attr->name) == 0 &&
- attr->type == GNOME_KEYRING_ATTRIBUTE_TYPE_UINT32)
- return attr->value.integer;
+ value = g_hash_table_lookup (attrs, name);
+ if (value != NULL) {
+ num = strtoul (value, &end, 10);
+ if (end && *end == '\0')
+ return num;
}
return 0;
}
static const gchar *
-get_attribute_string (GnomeKeyringAttributeList *attrs,
+get_attribute_string (GHashTable *attrs,
const gchar *name)
{
- guint i;
-
if (!attrs)
return NULL;
- for (i = 0; i < attrs->len; i++) {
- GnomeKeyringAttribute *attr = &(gnome_keyring_attribute_list_index (attrs, i));
- if (g_ascii_strcasecmp (name, attr->name) == 0 &&
- attr->type == GNOME_KEYRING_ATTRIBUTE_TYPE_STRING)
- return attr->value.string;
- }
-
- return NULL;
+ return g_hash_table_lookup (attrs, name);
}
static gboolean
-is_network_item (GnomeKeyringAttributeList *attrs,
+is_network_item (GHashTable *attrs,
const gchar *match)
{
const gchar *protocol;
@@ -172,7 +160,7 @@ is_custom_network_label (const gchar *server,
}
static gchar *
-calc_network_label (GnomeKeyringAttributeList *attrs,
+calc_network_label (GHashTable *attrs,
gboolean always)
{
const gchar *val;
@@ -196,8 +184,8 @@ calc_network_label (GnomeKeyringAttributeList *attrs,
static void
network_custom (const DisplayEntry *entry,
- GnomeKeyringItemInfo *item,
- GnomeKeyringAttributeList *attrs,
+ const gchar *display,
+ GHashTable *attrs,
DisplayInfo *info)
{
const gchar *object;
@@ -205,7 +193,6 @@ network_custom (const DisplayEntry *entry,
const gchar *protocol;
const gchar *server;
guint32 port;
- gchar *display = NULL;
server = get_attribute_string (attrs, "server");
protocol = get_attribute_string (attrs, "protocol");
@@ -216,15 +203,11 @@ network_custom (const DisplayEntry *entry,
if (!protocol)
return;
- display = gnome_keyring_item_info_get_display_name (item);
-
/* If it's customized by the application or user then display that */
if (!is_custom_network_label (server, user, object, port, display))
info->label = calc_network_label (attrs, TRUE);
if (info->label == NULL)
- info->label = display;
- else
- g_free (display);
+ info->label = g_strdup (display);
if (server && protocol) {
info->details = g_markup_printf_escaped ("%s://%s%s%s/%s",
@@ -238,16 +221,14 @@ network_custom (const DisplayEntry *entry,
static void
chrome_custom (const DisplayEntry *entry,
- GnomeKeyringItemInfo *item,
- GnomeKeyringAttributeList *attrs,
+ const gchar *display,
+ GHashTable *attrs,
DisplayInfo *info)
{
- gchar *display;
const gchar *origin;
GRegex *regex;
GMatchInfo *match;
- display = gnome_keyring_item_info_get_display_name (item);
origin = get_attribute_string (attrs, "origin_url");
/* A brain dead url, parse */
@@ -262,9 +243,7 @@ chrome_custom (const DisplayEntry *entry,
}
if (info->label == NULL)
- info->label = (display);
- else
- g_free (display);
+ info->label = g_strdup (display);
info->details = g_markup_escape_text (origin ? origin : "", -1);
}
@@ -297,20 +276,18 @@ decode_telepathy_id (const gchar *account)
static void
empathy_custom (const DisplayEntry *entry,
- GnomeKeyringItemInfo *item,
- GnomeKeyringAttributeList *attrs,
+ const gchar *display,
+ GHashTable *attrs,
DisplayInfo *info)
{
const gchar *account;
GMatchInfo *match;
GRegex *regex;
- gchar *display;
gchar *identifier;
const gchar *prefix;
gchar *pos;
gsize len;
- display = gnome_keyring_item_info_get_display_name (item);
account = get_attribute_string (attrs, "account-id");
/* Translators: This should be the same as the string in empathy */
@@ -335,9 +312,7 @@ empathy_custom (const DisplayEntry *entry,
}
if (info->label == NULL)
- info->label = (display);
- else
- g_free (display);
+ info->label = g_strdup (display);
if (info->details == NULL)
info->details = g_markup_escape_text (account, -1);
@@ -345,17 +320,15 @@ empathy_custom (const DisplayEntry *entry,
static void
telepathy_custom (const DisplayEntry *entry,
- GnomeKeyringItemInfo *item,
- GnomeKeyringAttributeList *attrs,
+ const gchar *display,
+ GHashTable *attrs,
DisplayInfo *info)
{
const gchar *account;
GMatchInfo *match;
GRegex *regex;
- gchar *display;
gchar *identifier;
- display = gnome_keyring_item_info_get_display_name (item);
account = get_attribute_string (attrs, "account");
if (strstr (display, account)) {
@@ -372,9 +345,7 @@ telepathy_custom (const DisplayEntry *entry,
}
if (info->label == NULL)
- info->label = (display);
- else
- g_free (display);
+ info->label = g_strdup (display);
info->details = g_markup_escape_text (account, -1);
}
@@ -393,28 +364,6 @@ static const DisplayEntry DISPLAY_ENTRIES[] = {
{ NETWORK_MANAGER_SECRET, N_("Network Manager secret"), NULL },
};
-static const OldItemTypes OLD_ITEM_TYPES[] = {
- { GNOME_KEYRING_ITEM_GENERIC_SECRET, GENERIC_SECRET },
- { GNOME_KEYRING_ITEM_NETWORK_PASSWORD, NETWORK_PASSWORD },
- { GNOME_KEYRING_ITEM_NOTE, KEYRING_NOTE },
- { GNOME_KEYRING_ITEM_CHAINED_KEYRING_PASSWORD, CHAINED_KEYRING },
- { GNOME_KEYRING_ITEM_ENCRYPTION_KEY_PASSWORD, ENCRYPTION_KEY },
- { GNOME_KEYRING_ITEM_PK_STORAGE, PK_STORAGE },
-};
-
-static const gchar *
-map_item_type_to_string (GnomeKeyringItemType old)
-{
- guint i;
-
- for (i = 0; i < G_N_ELEMENTS (OLD_ITEM_TYPES); i++) {
- if (old == OLD_ITEM_TYPES[i].old)
- return OLD_ITEM_TYPES[i].item_type;
- }
-
- return GENERIC_SECRET;
-}
-
static const MappingEntry MAPPING_ENTRIES[] = {
{ GENERIC_SECRET, CHROME_PASSWORD, "application", "chrome*" },
{ GENERIC_SECRET, GOA_PASSWORD, "goa-identity", NULL },
@@ -426,11 +375,13 @@ static const MappingEntry MAPPING_ENTRIES[] = {
static const gchar *
map_item_type_to_specific (const gchar *item_type,
- GnomeKeyringAttributeList *attrs)
+ GHashTable *attrs)
{
const gchar *value;
guint i;
+ if (!item_type)
+ return GENERIC_SECRET;
if (!attrs)
return item_type;
@@ -451,38 +402,31 @@ map_item_type_to_specific (const gchar *item_type,
enum {
PROP_0,
- PROP_KEYRING_NAME,
- PROP_ITEM_ID,
- PROP_ITEM_INFO,
- PROP_ITEM_ATTRIBUTES,
PROP_HAS_SECRET,
PROP_DESCRIPTION,
- PROP_USE
+ PROP_USE,
+ PROP_PLACE,
+ PROP_FLAGS,
+ PROP_DELETABLE,
+ PROP_ICON,
+ PROP_LABEL,
+ PROP_MARKUP,
+ PROP_USAGE,
+ PROP_ACTIONS
};
struct _SeahorseGkrItemPrivate {
- gchar *keyring_name;
- guint32 item_id;
-
- gpointer req_info;
- GnomeKeyringItemInfo *item_info;
-
- gpointer req_attrs;
- GnomeKeyringAttributeList *item_attrs;
-
- gpointer req_secret;
- gchar *item_secret;
-
+ SecretValue *item_secret;
+ GCancellable *req_secret;
DisplayInfo *display_info;
+ GObject *place;
};
-static gboolean require_item_attrs (SeahorseGkrItem *self);
-
static void seahorse_gkr_item_deletable_iface (SeahorseDeletableIface *iface);
static void seahorse_gkr_item_viewable_iface (SeahorseViewableIface *iface);
-G_DEFINE_TYPE_WITH_CODE (SeahorseGkrItem, seahorse_gkr_item, SEAHORSE_TYPE_OBJECT,
+G_DEFINE_TYPE_WITH_CODE (SeahorseGkrItem, seahorse_gkr_item, SECRET_TYPE_ITEM,
G_IMPLEMENT_INTERFACE (SEAHORSE_TYPE_DELETABLE, seahorse_gkr_item_deletable_iface);
G_IMPLEMENT_INTERFACE (SEAHORSE_TYPE_VIEWABLE, seahorse_gkr_item_viewable_iface);
);
@@ -491,28 +435,6 @@ G_DEFINE_TYPE_WITH_CODE (SeahorseGkrItem, seahorse_gkr_item, SEAHORSE_TYPE_OBJEC
* INTERNAL HELPERS
*/
-static GType
-boxed_item_info_type (void)
-{
- static GType type = 0;
- if (!type)
- type = g_boxed_type_register_static ("GnomeKeyringItemInfo",
- (GBoxedCopyFunc)gnome_keyring_item_info_copy,
- (GBoxedFreeFunc)gnome_keyring_item_info_free);
- return type;
-}
-
-static GType
-boxed_attributes_type (void)
-{
- static GType type = 0;
- if (!type)
- type = g_boxed_type_register_static ("GnomeKeyringAttributeList",
- (GBoxedCopyFunc)gnome_keyring_attribute_list_copy,
- (GBoxedFreeFunc)gnome_keyring_attribute_list_free);
- return type;
-}
-
static void
free_display_info (DisplayInfo *info)
{
@@ -525,30 +447,33 @@ static DisplayInfo *
ensure_display_info (SeahorseGkrItem *self)
{
const gchar *item_type;
+ GHashTable *attrs;
DisplayInfo *info;
+ gchar *label;
guint i;
if (self->pv->display_info)
return self->pv->display_info;
- require_item_attrs (self);
-
info = g_new0 (DisplayInfo, 1);
- item_type = map_item_type_to_string (gnome_keyring_item_info_get_type (self->pv->item_info));
- item_type = map_item_type_to_specific (item_type, self->pv->item_attrs);
+ attrs = secret_item_get_attributes (SECRET_ITEM (self));
+ item_type = get_attribute_string (attrs, "xdg:schema");
+ item_type = map_item_type_to_specific (item_type, attrs);
g_assert (item_type != NULL);
info->item_type = item_type;
+ label = secret_item_get_label (SECRET_ITEM (self));
for (i = 0; i < G_N_ELEMENTS (DISPLAY_ENTRIES); i++) {
if (g_str_equal (DISPLAY_ENTRIES[i].item_type, item_type)) {
if (DISPLAY_ENTRIES[i].custom_func != NULL)
(DISPLAY_ENTRIES[i].custom_func) (&DISPLAY_ENTRIES[i],
- self->pv->item_info,
- self->pv->item_attrs,
+ label, attrs,
info);
- if (!info->label && self->pv->item_info)
- info->label = gnome_keyring_item_info_get_display_name (self->pv->item_info);
+ if (!info->label) {
+ info->label = label;
+ label = NULL;
+ }
if (!info->description)
info->description = DISPLAY_ENTRIES[i].description;
if (!info->details)
@@ -558,91 +483,69 @@ ensure_display_info (SeahorseGkrItem *self)
}
self->pv->display_info = info;
+ g_hash_table_unref (attrs);
+ g_free (label);
return info;
}
static void
-clear_display_info (SeahorseGkrItem *self)
+seahorse_gkr_item_g_properties_changed (GDBusProxy *proxy,
+ GVariant *changed_properties,
+ const gchar* const *invalidated_properties)
{
+ SeahorseGkrItem *self = SEAHORSE_GKR_ITEM (proxy);
+ GObject *obj = G_OBJECT (self);
+
if (self->pv->display_info) {
free_display_info (self->pv->display_info);
self->pv->display_info = NULL;
}
-}
-
-static gboolean
-received_result (SeahorseGkrItem *self, GnomeKeyringResult result)
-{
- if (result == GNOME_KEYRING_RESULT_CANCELLED)
- return FALSE;
-
- if (result == GNOME_KEYRING_RESULT_OK) {
- clear_display_info (self);
- return TRUE;
- }
- /* TODO: Implement so that we can display an error icon, along with some text */
- g_message ("failed to retrieve item %d from keyring %s: %s",
- self->pv->item_id, self->pv->keyring_name,
- gnome_keyring_result_to_message (result));
- return FALSE;
-}
-
-static void
-received_item_info (GnomeKeyringResult result, GnomeKeyringItemInfo *info, gpointer data)
-{
- SeahorseGkrItem *self = SEAHORSE_GKR_ITEM (data);
- self->pv->req_info = NULL;
- if (received_result (self, result))
- seahorse_gkr_item_set_info (self, info);
+ g_object_freeze_notify (obj);
+ g_object_notify (obj, "has-secret");
+ g_object_notify (obj, "use");
+ g_object_notify (obj, "label");
+ g_object_notify (obj, "icon");
+ g_object_notify (obj, "markup");
+ g_object_notify (obj, "description");
+ g_object_notify (obj, "flags");
+ g_object_thaw_notify (obj);
}
static void
-load_item_info (SeahorseGkrItem *self)
+received_item_secret (GObject *source,
+ GAsyncResult *result,
+ gpointer user_data)
{
- /* Already in progress */
- if (!self->pv->req_info) {
- g_object_ref (self);
- self->pv->req_info = gnome_keyring_item_get_info_full (self->pv->keyring_name,
- self->pv->item_id,
- GNOME_KEYRING_ITEM_INFO_BASICS,
- received_item_info,
- self, g_object_unref);
- }
-}
+ SeahorseGkrItem *self = SEAHORSE_GKR_ITEM (source);
+ SecretValue *value;
+ GError *error = NULL;
-static gboolean
-require_item_info (SeahorseGkrItem *self)
-{
- if (!self->pv->item_info)
- load_item_info (self);
- return self->pv->item_info != NULL;
-}
+ g_clear_object (&self->pv->req_secret);
-static void
-received_item_secret (GnomeKeyringResult result, GnomeKeyringItemInfo *info, gpointer data)
-{
- SeahorseGkrItem *self = SEAHORSE_GKR_ITEM (data);
- self->pv->req_secret = NULL;
- if (received_result (self, result)) {
- g_free (self->pv->item_secret);
- WITH_SECURE_MEM (self->pv->item_secret = gnome_keyring_item_info_get_secret (info));
+ value = secret_item_get_secret_finish (SECRET_ITEM (source), result, &error);
+ if (error == NULL) {
+ if (self->pv->item_secret)
+ secret_value_unref (self->pv->item_secret);
+ self->pv->item_secret = value;
g_object_notify (G_OBJECT (self), "has-secret");
+ } else {
+ g_message ("Couldn't retrieve secret: %s", error->message);
+ g_error_free (error);
}
+
+ g_object_unref (self);
}
static void
load_item_secret (SeahorseGkrItem *self)
{
- /* Already in progress */
- if (!self->pv->req_secret) {
- g_object_ref (self);
- self->pv->req_secret = gnome_keyring_item_get_info_full (self->pv->keyring_name,
- self->pv->item_id,
- GNOME_KEYRING_ITEM_INFO_SECRET,
- received_item_secret,
- self, g_object_unref);
- }
+ if (self->pv->req_secret)
+ return;
+
+ self->pv->req_secret = g_cancellable_new ();
+ secret_item_get_secret (SECRET_ITEM (self), self->pv->req_secret,
+ received_item_secret, g_object_ref (self));
}
static gboolean
@@ -653,36 +556,6 @@ require_item_secret (SeahorseGkrItem *self)
return self->pv->item_secret != NULL;
}
-static void
-received_item_attrs (GnomeKeyringResult result, GnomeKeyringAttributeList *attrs, gpointer data)
-{
- SeahorseGkrItem *self = SEAHORSE_GKR_ITEM (data);
- self->pv->req_attrs = NULL;
- if (received_result (self, result))
- seahorse_gkr_item_set_attributes (self, attrs);
-}
-
-static void
-load_item_attrs (SeahorseGkrItem *self)
-{
- /* Already in progress */
- if (!self->pv->req_attrs) {
- g_object_ref (self);
- self->pv->req_attrs = gnome_keyring_item_get_attributes (self->pv->keyring_name,
- self->pv->item_id,
- received_item_attrs,
- self, g_object_unref);
- }
-}
-
-static gboolean
-require_item_attrs (SeahorseGkrItem *self)
-{
- if (!self->pv->item_attrs)
- load_item_attrs (self);
- return self->pv->item_attrs != NULL;
-}
-
static gchar*
calc_name_markup (SeahorseGkrItem *self)
{
@@ -701,45 +574,9 @@ calc_name_markup (SeahorseGkrItem *self)
return g_string_free (result, FALSE);
}
-/* -----------------------------------------------------------------------------
- * OBJECT
- */
-
-void
-seahorse_gkr_item_realize (SeahorseGkrItem *self)
-{
- DisplayInfo *info;
- gchar *markup;
- GIcon *icon;
-
- if (!require_item_info (self))
- return;
-
- info = ensure_display_info (self);
- markup = calc_name_markup (self);
-
- icon = g_themed_icon_new (GCR_ICON_PASSWORD);
- g_object_set (self,
- "label", info->label,
- "icon", icon,
- "markup", markup,
- "flags", SEAHORSE_FLAG_DELETABLE | SEAHORSE_FLAG_PERSONAL,
- NULL);
- g_object_unref (icon);
- g_free (markup);
-
- g_object_notify (G_OBJECT (self), "has-secret");
- g_object_notify (G_OBJECT (self), "use");
- g_object_notify (G_OBJECT (self), "description");
-}
-
void
seahorse_gkr_item_refresh (SeahorseGkrItem *self)
{
- if (self->pv->item_info)
- load_item_info (self);
- if (self->pv->item_attrs)
- load_item_attrs (self);
if (self->pv->item_secret)
load_item_secret (self);
}
@@ -748,17 +585,6 @@ static void
seahorse_gkr_item_init (SeahorseGkrItem *self)
{
self->pv = G_TYPE_INSTANCE_GET_PRIVATE (self, SEAHORSE_TYPE_GKR_ITEM, SeahorseGkrItemPrivate);
- g_object_set (self, "usage", SEAHORSE_USAGE_CREDENTIALS, NULL);
-}
-
-static void
-seahorse_gkr_item_constructed (GObject *object)
-{
- SeahorseGkrItem *self = SEAHORSE_GKR_ITEM (object);
-
- G_OBJECT_CLASS (seahorse_gkr_item_parent_class)->constructed (object);
-
- seahorse_gkr_item_realize (self);
}
static void
@@ -769,18 +595,6 @@ seahorse_gkr_item_get_property (GObject *object, guint prop_id,
DisplayInfo *info;
switch (prop_id) {
- case PROP_KEYRING_NAME:
- g_value_set_string (value, seahorse_gkr_item_get_keyring_name (self));
- break;
- case PROP_ITEM_ID:
- g_value_set_uint (value, seahorse_gkr_item_get_item_id (self));
- break;
- case PROP_ITEM_INFO:
- g_value_set_boxed (value, seahorse_gkr_item_get_info (self));
- break;
- case PROP_ITEM_ATTRIBUTES:
- g_value_set_boxed (value, seahorse_gkr_item_get_attributes (self));
- break;
case PROP_HAS_SECRET:
g_value_set_boolean (value, self->pv->item_secret != NULL);
break;
@@ -788,11 +602,35 @@ seahorse_gkr_item_get_property (GObject *object, guint prop_id,
g_value_set_uint (value, seahorse_gkr_item_get_use (self));
break;
case PROP_DESCRIPTION:
- if (!require_item_info (self))
- break;
info = ensure_display_info (self);
g_value_set_string (value, info->description);
break;
+ case PROP_PLACE:
+ g_value_set_object (value, self->pv->place);
+ break;
+ case PROP_FLAGS:
+ g_value_set_flags (value, SEAHORSE_FLAG_DELETABLE | SEAHORSE_FLAG_PERSONAL);
+ break;
+ case PROP_LABEL:
+ info = ensure_display_info (self);
+ g_value_set_string (value, info->label);
+ break;
+ case PROP_MARKUP:
+ info = ensure_display_info (self);
+ g_value_take_string (value, calc_name_markup (self));
+ break;
+ case PROP_ICON:
+ g_value_take_object (value, g_themed_icon_new (GCR_ICON_PASSWORD));
+ break;
+ case PROP_DELETABLE:
+ g_value_set_boolean (value, TRUE);
+ break;
+ case PROP_USAGE:
+ g_value_set_enum (value, SEAHORSE_USAGE_CREDENTIALS);
+ break;
+ case PROP_ACTIONS:
+ g_value_set_object (value, NULL);
+ break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
@@ -800,25 +638,19 @@ seahorse_gkr_item_get_property (GObject *object, guint prop_id,
}
static void
-seahorse_gkr_item_set_property (GObject *object, guint prop_id, const GValue *value,
+seahorse_gkr_item_set_property (GObject *object,
+ guint prop_id,
+ const GValue *value,
GParamSpec *pspec)
{
SeahorseGkrItem *self = SEAHORSE_GKR_ITEM (object);
-
switch (prop_id) {
- case PROP_KEYRING_NAME:
- g_return_if_fail (self->pv->keyring_name == NULL);
- self->pv->keyring_name = g_value_dup_string (value);
- break;
- case PROP_ITEM_ID:
- g_return_if_fail (self->pv->item_id == 0);
- self->pv->item_id = g_value_get_uint (value);
- break;
- case PROP_ITEM_INFO:
- seahorse_gkr_item_set_info (self, g_value_get_boxed (value));
- break;
- case PROP_ITEM_ATTRIBUTES:
- seahorse_gkr_item_set_attributes (self, g_value_get_boxed (value));
+ case PROP_PLACE:
+ if (self->pv->place)
+ g_object_remove_weak_pointer (self->pv->place, (gpointer *)&self->pv->place);
+ self->pv->place = g_value_get_object (value);
+ if (self->pv->place)
+ g_object_add_weak_pointer (self->pv->place, (gpointer *)&self->pv->place);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
@@ -830,12 +662,17 @@ static void
seahorse_gkr_item_dispose (GObject *obj)
{
SeahorseGkrItem *self = SEAHORSE_GKR_ITEM (obj);
- SeahorsePlace *place;
- place = seahorse_object_get_place (SEAHORSE_OBJECT (self));
- if (place != NULL)
- seahorse_gkr_keyring_remove_item (SEAHORSE_GKR_KEYRING (place),
- self->pv->item_id);
+ if (self->pv->req_secret) {
+ g_cancellable_cancel (self->pv->req_secret);
+ g_object_unref (self->pv->req_secret);
+ self->pv->req_secret = NULL;
+ }
+
+ if (self->pv->place) {
+ g_object_remove_weak_pointer (self->pv->place, (gpointer *)&self->pv->place);
+ self->pv->place = NULL;
+ }
G_OBJECT_CLASS (seahorse_gkr_item_parent_class)->dispose (obj);
}
@@ -844,63 +681,34 @@ static void
seahorse_gkr_item_finalize (GObject *gobject)
{
SeahorseGkrItem *self = SEAHORSE_GKR_ITEM (gobject);
-
- g_free (self->pv->keyring_name);
- self->pv->keyring_name = NULL;
-
- if (self->pv->item_info)
- gnome_keyring_item_info_free (self->pv->item_info);
- self->pv->item_info = NULL;
- g_assert (self->pv->req_info == NULL);
-
- if (self->pv->item_attrs)
- gnome_keyring_attribute_list_free (self->pv->item_attrs);
- self->pv->item_attrs = NULL;
- g_assert (self->pv->req_attrs == NULL);
-
- g_free (self->pv->item_secret);
+
+ if (self->pv->item_secret)
+ secret_value_unref (self->pv->item_secret);
self->pv->item_secret = NULL;
g_assert (self->pv->req_secret == NULL);
-
+
G_OBJECT_CLASS (seahorse_gkr_item_parent_class)->finalize (gobject);
}
static void
seahorse_gkr_item_class_init (SeahorseGkrItemClass *klass)
{
- GObjectClass *gobject_class;
+ GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
+ GDBusProxyClass *proxy_class = G_DBUS_PROXY_CLASS (klass);
- seahorse_gkr_item_parent_class = g_type_class_peek_parent (klass);
- gobject_class = G_OBJECT_CLASS (klass);
-
- gobject_class->constructed = seahorse_gkr_item_constructed;
gobject_class->dispose = seahorse_gkr_item_dispose;
gobject_class->finalize = seahorse_gkr_item_finalize;
- gobject_class->set_property = seahorse_gkr_item_set_property;
gobject_class->get_property = seahorse_gkr_item_get_property;
+ gobject_class->set_property = seahorse_gkr_item_set_property;
+
+ proxy_class->g_properties_changed = seahorse_gkr_item_g_properties_changed;
g_type_class_add_private (klass, sizeof (SeahorseGkrItemPrivate));
-
- g_object_class_install_property (gobject_class, PROP_KEYRING_NAME,
- g_param_spec_string("keyring-name", "Keyring Name", "Keyring this item is in",
- "", G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
g_object_class_install_property (gobject_class, PROP_DESCRIPTION,
g_param_spec_string("description", "Description", "Item description",
"", G_PARAM_READABLE));
- g_object_class_install_property (gobject_class, PROP_ITEM_ID,
- g_param_spec_uint ("item-id", "Item ID", "GNOME Keyring Item ID",
- 0, G_MAXUINT, 0, G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
-
- g_object_class_install_property (gobject_class, PROP_ITEM_INFO,
- g_param_spec_boxed ("item-info", "Item Info", "GNOME Keyring Item Info",
- boxed_item_info_type (), G_PARAM_READWRITE));
-
- g_object_class_install_property (gobject_class, PROP_ITEM_ATTRIBUTES,
- g_param_spec_boxed ("item-attributes", "Item Attributes", "GNOME Keyring Item Attributes",
- boxed_attributes_type (), G_PARAM_READWRITE));
-
g_object_class_install_property (gobject_class, PROP_USE,
g_param_spec_uint ("use", "Use", "Item is used for",
0, G_MAXUINT, 0, G_PARAM_READABLE));
@@ -908,6 +716,36 @@ seahorse_gkr_item_class_init (SeahorseGkrItemClass *klass)
g_object_class_install_property (gobject_class, PROP_HAS_SECRET,
g_param_spec_boolean ("has-secret", "Has Secret", "Secret has been loaded",
FALSE, G_PARAM_READABLE));
+
+ g_object_class_install_property (gobject_class, PROP_PLACE,
+ g_param_spec_object ("place", "place", "place", SEAHORSE_TYPE_GKR_KEYRING,
+ G_PARAM_STATIC_STRINGS | G_PARAM_READWRITE));
+
+ g_object_class_install_property (gobject_class, PROP_FLAGS,
+ g_param_spec_flags ("flags", "flags", "flags", SEAHORSE_TYPE_FLAGS, SEAHORSE_FLAG_NONE,
+ G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB | G_PARAM_READABLE));
+
+ g_object_class_install_property (gobject_class, PROP_ICON,
+ g_param_spec_object ("icon", "Icon", "Icon", G_TYPE_ICON,
+ G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB | G_PARAM_READABLE));
+
+ g_object_class_install_property (gobject_class, PROP_LABEL,
+ g_param_spec_string ("label", "Label", "Label", "",
+ G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB | G_PARAM_READABLE));
+
+ g_object_class_install_property (gobject_class, PROP_MARKUP,
+ g_param_spec_string ("markup", "Markup", "Markup", "",
+ G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB | G_PARAM_READABLE));
+
+ g_object_class_install_property (gobject_class, PROP_USAGE,
+ g_param_spec_enum ("usage", "Object Usage", "How this object is used.",
+ SEAHORSE_TYPE_USAGE, SEAHORSE_USAGE_NONE, G_PARAM_READWRITE));
+
+ g_object_class_install_property (gobject_class, PROP_ACTIONS,
+ g_param_spec_object ("actions", "Actions", "Actions", GTK_TYPE_ACTION_GROUP,
+ G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB | G_PARAM_READABLE));
+
+ g_object_class_override_property (gobject_class, PROP_DELETABLE, "deletable");
}
static SeahorseDeleter *
@@ -949,63 +787,6 @@ seahorse_gkr_item_new (SeahorseGkrKeyring *keyring,
NULL);
}
-guint32
-seahorse_gkr_item_get_item_id (SeahorseGkrItem *self)
-{
- g_return_val_if_fail (SEAHORSE_IS_GKR_ITEM (self), 0);
- return self->pv->item_id;
-}
-
-const gchar*
-seahorse_gkr_item_get_keyring_name (SeahorseGkrItem *self)
-{
- g_return_val_if_fail (SEAHORSE_IS_GKR_ITEM (self), NULL);
- return self->pv->keyring_name;
-}
-
-GnomeKeyringItemInfo*
-seahorse_gkr_item_get_info (SeahorseGkrItem *self)
-{
- g_return_val_if_fail (SEAHORSE_IS_GKR_ITEM (self), NULL);
- require_item_info (self);
- return self->pv->item_info;
-}
-
-void
-seahorse_gkr_item_set_info (SeahorseGkrItem *self, GnomeKeyringItemInfo* info)
-{
- GObject *obj;
- gchar *secret;
-
- g_return_if_fail (SEAHORSE_IS_GKR_ITEM (self));
-
- clear_display_info (self);
-
- if (self->pv->item_info)
- gnome_keyring_item_info_free (self->pv->item_info);
- if (info)
- self->pv->item_info = gnome_keyring_item_info_copy (info);
- else
- self->pv->item_info = NULL;
-
- obj = G_OBJECT (self);
- g_object_freeze_notify (obj);
- seahorse_gkr_item_realize (self);
- g_object_notify (obj, "item-info");
- g_object_notify (obj, "use");
- g_object_notify (obj, "description");
-
- /* Get the secret out of the item info, if not already loaded */
- WITH_SECURE_MEM (secret = gnome_keyring_item_info_get_secret (self->pv->item_info));
- if (secret != NULL) {
- gnome_keyring_free_password (self->pv->item_secret);
- self->pv->item_secret = secret;
- g_object_notify (obj, "has-secret");
- }
-
- g_object_thaw_notify (obj);
-}
-
gboolean
seahorse_gkr_item_has_secret (SeahorseGkrItem *self)
{
@@ -1013,7 +794,7 @@ seahorse_gkr_item_has_secret (SeahorseGkrItem *self)
return self->pv->item_secret != NULL;
}
-const gchar*
+SecretValue *
seahorse_gkr_item_get_secret (SeahorseGkrItem *self)
{
g_return_val_if_fail (SEAHORSE_IS_GKR_ITEM (self), NULL);
@@ -1021,73 +802,94 @@ seahorse_gkr_item_get_secret (SeahorseGkrItem *self)
return self->pv->item_secret;
}
-GnomeKeyringAttributeList*
-seahorse_gkr_item_get_attributes (SeahorseGkrItem *self)
-{
- g_return_val_if_fail (SEAHORSE_IS_GKR_ITEM (self), NULL);
- require_item_attrs (self);
- return self->pv->item_attrs;
-}
-
-void
-seahorse_gkr_item_set_attributes (SeahorseGkrItem *self, GnomeKeyringAttributeList* attrs)
-{
- GObject *obj;
-
- g_return_if_fail (SEAHORSE_IS_GKR_ITEM (self));
-
- if (self->pv->item_attrs)
- gnome_keyring_attribute_list_free (self->pv->item_attrs);
- if (attrs)
- self->pv->item_attrs = gnome_keyring_attribute_list_copy (attrs);
- else
- self->pv->item_attrs = NULL;
-
- obj = G_OBJECT (self);
- g_object_freeze_notify (obj);
- seahorse_gkr_item_realize (self);
- g_object_notify (obj, "item-attributes");
- g_object_notify (obj, "use");
- g_object_notify (obj, "description");
- g_object_thaw_notify (obj);
-}
-
const gchar*
seahorse_gkr_item_get_attribute (SeahorseGkrItem *self, const gchar *name)
{
+ GHashTable *attributes;
+
g_return_val_if_fail (SEAHORSE_IS_GKR_ITEM (self), NULL);
- if (!require_item_attrs (self))
+
+ attributes = secret_item_get_attributes (SECRET_ITEM (self));
+ if (attributes == NULL)
return NULL;
- return seahorse_gkr_find_string_attribute (self->pv->item_attrs, name);
+ return g_hash_table_lookup (attributes, name);
}
+
const gchar*
-seahorse_gkr_find_string_attribute (GnomeKeyringAttributeList *attrs, const gchar *name)
+seahorse_gkr_find_string_attribute (GHashTable *attrs,
+ const gchar *name)
{
- guint i;
-
g_return_val_if_fail (attrs, NULL);
g_return_val_if_fail (name, NULL);
- for (i = 0; i < attrs->len; i++) {
- GnomeKeyringAttribute *attr = &(gnome_keyring_attribute_list_index (attrs, i));
- if (g_ascii_strcasecmp (name, attr->name) == 0 &&
- attr->type == GNOME_KEYRING_ATTRIBUTE_TYPE_STRING)
- return attr->value.string;
- }
-
- return NULL;
+ return g_hash_table_lookup (attrs, name);
}
SeahorseGkrUse
seahorse_gkr_item_get_use (SeahorseGkrItem *self)
{
- /* Network passwords */
- if (require_item_info (self)) {
- if (gnome_keyring_item_info_get_type (self->pv->item_info) == GNOME_KEYRING_ITEM_NETWORK_PASSWORD) {
- return SEAHORSE_GKR_USE_NETWORK;
- }
- }
+ const gchar *schema_name;
+
+ schema_name = seahorse_gkr_item_get_attribute (self, "xdg:schema");
+ if (schema_name && g_str_equal (schema_name, "org.gnome.keyring.NetworkPassword"))
+ return SEAHORSE_GKR_USE_NETWORK;
return SEAHORSE_GKR_USE_OTHER;
}
+
+static void
+on_set_secret (GObject *source,
+ GAsyncResult *result,
+ gpointer user_data)
+{
+ GSimpleAsyncResult *async = G_SIMPLE_ASYNC_RESULT (user_data);
+ SeahorseGkrItem *self = SEAHORSE_GKR_ITEM (source);
+ GError *error = NULL;
+
+ secret_item_set_secret_finish (SECRET_ITEM (source), result, &error);
+ if (error == NULL) {
+ if (self->pv->item_secret)
+ secret_value_unref (self->pv->item_secret);
+ self->pv->item_secret = g_simple_async_result_get_op_res_gpointer (async);
+ secret_value_ref (self->pv->item_secret);
+ g_object_notify (G_OBJECT (self), "has-secret");
+
+ } else {
+ g_simple_async_result_take_error (async, error);
+ }
+
+ g_simple_async_result_complete (async);
+ g_object_unref (async);
+}
+
+void
+seahorse_gkr_item_set_secret (SeahorseGkrItem *self,
+ SecretValue *value,
+ GCancellable *cancellable,
+ GAsyncReadyCallback callback,
+ gpointer user_data)
+{
+ GSimpleAsyncResult *async;
+
+ async = g_simple_async_result_new (G_OBJECT (self), callback, user_data,
+ seahorse_gkr_item_set_secret);
+ g_simple_async_result_set_op_res_gpointer (async, secret_value_ref (value),
+ secret_value_unref);
+
+ secret_item_set_secret (SECRET_ITEM (self), value, cancellable,
+ on_set_secret, g_object_ref (async));
+
+ g_object_unref (async);
+}
+
+gboolean
+seahorse_gkr_item_set_secret_finish (SeahorseGkrItem *self,
+ GAsyncResult *result,
+ GError **error)
+{
+ if (g_simple_async_result_propagate_error (G_SIMPLE_ASYNC_RESULT (result), error))
+ return FALSE;
+
+ return TRUE;
+}
diff --git a/gkr/seahorse-gkr-item.h b/gkr/seahorse-gkr-item.h
index 56d8adc..5844deb 100644
--- a/gkr/seahorse-gkr-item.h
+++ b/gkr/seahorse-gkr-item.h
@@ -24,7 +24,7 @@
#define __SEAHORSE_GKR_ITEM_H__
#include <gtk/gtk.h>
-#include <gnome-keyring.h>
+#include <secret/secret.h>
#include "seahorse-gkr.h"
#include "seahorse-gkr-keyring.h"
@@ -53,12 +53,12 @@ typedef struct _SeahorseGkrItemClass SeahorseGkrItemClass;
typedef struct _SeahorseGkrItemPrivate SeahorseGkrItemPrivate;
struct _SeahorseGkrItem {
- SeahorseObject parent;
+ SecretItem parent;
SeahorseGkrItemPrivate *pv;
};
struct _SeahorseGkrItemClass {
- SeahorseObjectClass parent_class;
+ SecretItemClass parent_class;
};
GType seahorse_gkr_item_get_type (void);
@@ -69,32 +69,26 @@ SeahorseGkrItem * seahorse_gkr_item_new (SeahorseGkrKe
void seahorse_gkr_item_refresh (SeahorseGkrItem *self);
-void seahorse_gkr_item_realize (SeahorseGkrItem *self);
-
-guint32 seahorse_gkr_item_get_item_id (SeahorseGkrItem *self);
-
-const gchar* seahorse_gkr_item_get_keyring_name (SeahorseGkrItem *self);
-
-GnomeKeyringItemInfo* seahorse_gkr_item_get_info (SeahorseGkrItem *self);
-
-void seahorse_gkr_item_set_info (SeahorseGkrItem *self,
- GnomeKeyringItemInfo* info);
-
gboolean seahorse_gkr_item_has_secret (SeahorseGkrItem *self);
-const gchar* seahorse_gkr_item_get_secret (SeahorseGkrItem *self);
-
-GnomeKeyringAttributeList* seahorse_gkr_item_get_attributes (SeahorseGkrItem *self);
-
-void seahorse_gkr_item_set_attributes (SeahorseGkrItem *self,
- GnomeKeyringAttributeList* attrs);
+SecretValue * seahorse_gkr_item_get_secret (SeahorseGkrItem *self);
const gchar* seahorse_gkr_item_get_attribute (SeahorseGkrItem *self,
const gchar *name);
-const gchar* seahorse_gkr_find_string_attribute (GnomeKeyringAttributeList *attrs,
- const gchar *name);
+const gchar* seahorse_gkr_find_string_attribute (GHashTable *attrs,
+ const gchar *name);
SeahorseGkrUse seahorse_gkr_item_get_use (SeahorseGkrItem *self);
+void seahorse_gkr_item_set_secret (SeahorseGkrItem *self,
+ SecretValue *value,
+ GCancellable *cancellable,
+ GAsyncReadyCallback callback,
+ gpointer user_data);
+
+gboolean seahorse_gkr_item_set_secret_finish (SeahorseGkrItem *self,
+ GAsyncResult *result,
+ GError **error);
+
#endif /* __SEAHORSE_GKR_ITEM_H__ */
diff --git a/gkr/seahorse-gkr-keyring-deleter.c b/gkr/seahorse-gkr-keyring-deleter.c
index a304225..a14678d 100644
--- a/gkr/seahorse-gkr-keyring-deleter.c
+++ b/gkr/seahorse-gkr-keyring-deleter.c
@@ -25,12 +25,8 @@
#include "seahorse-gkr-backend.h"
#include "seahorse-gkr-keyring-deleter.h"
-#include "seahorse-gkr-operation.h"
#include "seahorse-delete-dialog.h"
-#include "seahorse-object.h"
-
-#include <gnome-keyring.h>
#include <glib/gi18n.h>
@@ -78,7 +74,7 @@ seahorse_gkr_keyring_deleter_create_confirm (SeahorseDeleter *deleter,
dialog = seahorse_delete_dialog_new (parent,
_("Are you sure you want to delete the password keyring '%s'?"),
- seahorse_object_get_label (SEAHORSE_OBJECT (self->keyring)));
+ secret_collection_get_label (SECRET_COLLECTION (self->keyring)));
seahorse_delete_dialog_set_check_label (SEAHORSE_DELETE_DIALOG (dialog), _("I understand that all items will be permanently deleted."));
seahorse_delete_dialog_set_check_require (SEAHORSE_DELETE_DIALOG (dialog), TRUE);
@@ -107,52 +103,20 @@ seahorse_gkr_keyring_deleter_add_object (SeahorseDeleter *deleter,
return TRUE;
}
-typedef struct {
- GCancellable *cancellable;
- gpointer request;
- gulong cancelled_sig;
-} DeleteClosure;
-
static void
-delete_closure_free (gpointer data)
-{
- DeleteClosure *closure = data;
- if (closure->cancellable && closure->cancelled_sig)
- g_signal_handler_disconnect (closure->cancellable,
- closure->cancelled_sig);
- g_clear_object (&closure->cancellable);
- g_assert (!closure->request);
- g_free (closure);
-}
-
-static void
-on_delete_gkr_complete (GnomeKeyringResult result,
+on_delete_gkr_complete (GObject *source,
+ GAsyncResult *result,
gpointer user_data)
{
GSimpleAsyncResult *res = G_SIMPLE_ASYNC_RESULT (user_data);
- DeleteClosure *closure = g_simple_async_result_get_op_res_gpointer (res);
- SeahorseGkrKeyringDeleter *self = SEAHORSE_GKR_KEYRING_DELETER (g_async_result_get_source_object (user_data));
GError *error = NULL;
- closure->request = NULL;
-
- if (seahorse_gkr_propagate_error (result, &error))
+ secret_collection_delete_finish (SECRET_COLLECTION (source), result, &error);
+ if (error != NULL)
g_simple_async_result_take_error (res, error);
- else
- seahorse_gkr_backend_remove_keyring (NULL, self->keyring);
- g_simple_async_result_complete_in_idle (res);
- g_object_unref (self);
-}
-
-static void
-on_delete_gkr_cancelled (GCancellable *cancellable,
- gpointer user_data)
-{
- DeleteClosure *closure = user_data;
-
- if (closure->request)
- gnome_keyring_cancel_request (closure->request);
+ g_simple_async_result_complete (res);
+ g_object_unref (res);
}
static void
@@ -163,23 +127,13 @@ seahorse_gkr_keyring_deleter_delete_async (SeahorseDeleter *deleter,
{
SeahorseGkrKeyringDeleter *self = SEAHORSE_GKR_KEYRING_DELETER (deleter);
GSimpleAsyncResult *res;
- DeleteClosure *closure;
- const gchar *name;
res = g_simple_async_result_new (G_OBJECT (self), callback, user_data,
seahorse_gkr_keyring_deleter_delete_async);
- closure = g_new0 (DeleteClosure, 1);
- closure->cancellable = cancellable ? g_object_ref (cancellable) : NULL;
- g_simple_async_result_set_op_res_gpointer (res, closure, delete_closure_free);
-
- name = seahorse_gkr_keyring_get_name (self->keyring);
- closure->request = gnome_keyring_delete (name, on_delete_gkr_complete,
- g_object_ref (res), g_object_unref);
-
- if (cancellable)
- closure->cancelled_sig = g_cancellable_connect (cancellable,
- G_CALLBACK (on_delete_gkr_cancelled),
- closure, NULL);
+
+ secret_collection_delete (SECRET_COLLECTION (self->keyring),
+ cancellable, on_delete_gkr_complete,
+ g_object_ref (res));
g_object_unref (res);
}
diff --git a/gkr/seahorse-gkr-keyring-properties.c b/gkr/seahorse-gkr-keyring-properties.c
index 90a9167..1ff79dd 100644
--- a/gkr/seahorse-gkr-keyring-properties.c
+++ b/gkr/seahorse-gkr-keyring-properties.c
@@ -40,20 +40,14 @@ void on_keyring_properties_response (GtkDialog *dialog,
*/
static gboolean
-transform_keyring_created (const GValue *from, GValue *to)
+transform_keyring_created (const GValue *from,
+ GValue *to)
{
- GnomeKeyringInfo *info;
time_t time;
-
- info = g_value_get_boxed (from);
- if (info) {
- time = gnome_keyring_info_get_ctime (info);
- g_value_take_string (to, seahorse_util_get_display_date_string (time));
- }
-
- if (!g_value_get_string (to))
- g_value_set_string (to, "");
-
+
+ time = g_value_get_uint64 (from);
+ g_value_take_string (to, seahorse_util_get_display_date_string (time));
+
return TRUE;
}
@@ -73,11 +67,11 @@ setup_main (SeahorseWidget *swidget)
seahorse_widget_get_toplevel (swidget));
/* Setup the label properly */
- seahorse_bind_property ("keyring-name", object, "label",
+ seahorse_bind_property ("label", object, "label",
seahorse_widget_get_widget (swidget, "name-field"));
/* The date field */
- seahorse_bind_property_full ("keyring-info", object, transform_keyring_created, "label",
+ seahorse_bind_property_full ("created", object, transform_keyring_created, "label",
seahorse_widget_get_widget (swidget, "created-field"), NULL);
}
diff --git a/gkr/seahorse-gkr-keyring.c b/gkr/seahorse-gkr-keyring.c
index 529a29c..551a777 100644
--- a/gkr/seahorse-gkr-keyring.c
+++ b/gkr/seahorse-gkr-keyring.c
@@ -27,7 +27,6 @@
#include "seahorse-gkr-dialogs.h"
#include "seahorse-gkr-keyring-deleter.h"
#include "seahorse-gkr-keyring.h"
-#include "seahorse-gkr-operation.h"
#include "seahorse-gkr-actions.h"
#include "seahorse-action.h"
@@ -44,24 +43,19 @@
enum {
PROP_0,
PROP_DESCRIPTION,
- PROP_KEYRING_NAME,
PROP_KEYRING_INFO,
PROP_IS_DEFAULT,
PROP_URI,
PROP_ACTIONS,
- PROP_LOCKED,
PROP_LOCKABLE,
- PROP_UNLOCKABLE
+ PROP_UNLOCKABLE,
+
+ PROP_ICON,
+ PROP_DELETABLE
};
struct _SeahorseGkrKeyringPrivate {
GHashTable *items;
- gchar *keyring_name;
- gboolean is_default;
- gboolean locked;
-
- gpointer req_info;
- GnomeKeyringInfo *keyring_info;
};
static void seahorse_gkr_keyring_place_iface (SeahorsePlaceIface *iface);
@@ -74,7 +68,7 @@ static void seahorse_keyring_lockable_iface (SeahorseLockableIface *ifac
static void seahorse_keyring_viewable_iface (SeahorseViewableIface *iface);
-G_DEFINE_TYPE_WITH_CODE (SeahorseGkrKeyring, seahorse_gkr_keyring, SEAHORSE_TYPE_OBJECT,
+G_DEFINE_TYPE_WITH_CODE (SeahorseGkrKeyring, seahorse_gkr_keyring, SECRET_TYPE_COLLECTION,
G_IMPLEMENT_INTERFACE (GCR_TYPE_COLLECTION, seahorse_keyring_collection_iface);
G_IMPLEMENT_INTERFACE (SEAHORSE_TYPE_PLACE, seahorse_gkr_keyring_place_iface);
G_IMPLEMENT_INTERFACE (SEAHORSE_TYPE_DELETABLE, seahorse_keyring_deletable_iface);
@@ -82,267 +76,75 @@ G_DEFINE_TYPE_WITH_CODE (SeahorseGkrKeyring, seahorse_gkr_keyring, SEAHORSE_TYPE
G_IMPLEMENT_INTERFACE (SEAHORSE_TYPE_VIEWABLE, seahorse_keyring_viewable_iface);
);
-static GType
-boxed_type_keyring_info (void)
-{
- static GType type = 0;
- if (!type)
- type = g_boxed_type_register_static ("GnomeKeyringInfo",
- (GBoxedCopyFunc)gnome_keyring_info_copy,
- (GBoxedFreeFunc)gnome_keyring_info_free);
- return type;
-}
-
-static void
-received_keyring_info (GnomeKeyringResult result, GnomeKeyringInfo *info, gpointer data)
-{
- SeahorseGkrKeyring *self = SEAHORSE_GKR_KEYRING (data);
- self->pv->req_info = NULL;
-
- if (result == GNOME_KEYRING_RESULT_CANCELLED)
- return;
-
- if (result != GNOME_KEYRING_RESULT_OK) {
- /* TODO: Implement so that we can display an error icon, along with some text */
- g_message ("failed to retrieve info for keyring %s: %s",
- self->pv->keyring_name,
- gnome_keyring_result_to_message (result));
- return;
- }
-
- seahorse_gkr_keyring_set_info (self, info);
-}
-
-static void
-load_keyring_info (SeahorseGkrKeyring *self)
-{
- /* Already in progress */
- if (!self->pv->req_info) {
- g_object_ref (self);
- self->pv->req_info = gnome_keyring_get_info (self->pv->keyring_name,
- received_keyring_info,
- self, g_object_unref);
- }
-}
-
-static gboolean
-require_keyring_info (SeahorseGkrKeyring *self)
-{
- if (!self->pv->keyring_info)
- load_keyring_info (self);
- return self->pv->keyring_info != NULL;
-}
-
-/* -----------------------------------------------------------------------------
- * OBJECT
- */
-
-void
-seahorse_gkr_keyring_realize (SeahorseGkrKeyring *self)
-{
- const gchar *name;
- GIcon *icon;
-
- if (self->pv->keyring_name && g_str_equal (self->pv->keyring_name, "login"))
- name = _("Login keyring");
- else
- name = self->pv->keyring_name;
-
- icon = g_themed_icon_new ("folder");
-
- g_object_set (self,
- "label", name,
- "nickname", self->pv->keyring_name,
- "identifier", "",
- "flags", SEAHORSE_FLAG_DELETABLE | SEAHORSE_FLAG_PERSONAL,
- "icon", icon,
- "usage", SEAHORSE_USAGE_OTHER,
- NULL);
-
- g_object_unref (icon);
-}
-
-void
-seahorse_gkr_keyring_remove_item (SeahorseGkrKeyring *self,
- guint32 item_id)
-{
- SeahorseGkrItem *item;
-
- g_return_if_fail (SEAHORSE_IS_GKR_KEYRING (self));
-
- item = g_hash_table_lookup (self->pv->items, GUINT_TO_POINTER (item_id));
- if (item != NULL) {
- g_object_ref (item);
- g_object_set (item, "place", NULL, NULL);
- g_hash_table_remove (self->pv->items, GUINT_TO_POINTER (item_id));
- gcr_collection_emit_removed (GCR_COLLECTION (self), G_OBJECT (item));
- g_object_unref (item);
- }
-}
-
-typedef struct {
- SeahorseGkrKeyring *keyring;
- gpointer request;
- GCancellable *cancellable;
- gulong cancelled_sig;
-} keyring_load_closure;
-
-static void
-keyring_load_free (gpointer data)
-{
- keyring_load_closure *closure = data;
- if (closure->cancellable && closure->cancelled_sig)
- g_signal_handler_disconnect (closure->cancellable,
- closure->cancelled_sig);
- if (closure->cancellable)
- g_object_unref (closure->cancellable);
- g_clear_object (&closure->keyring);
- g_assert (!closure->request);
- g_free (closure);
-}
-
-/* Remove the given key from the context */
static void
-remove_key_from_context (gpointer kt,
- gpointer value,
- gpointer user_data)
+refresh_collection (SeahorseGkrKeyring *self)
{
- /* This function gets called as a GHFunc on the self->checks hashtable. */
- SeahorseGkrKeyring *self = SEAHORSE_GKR_KEYRING (user_data);
- seahorse_gkr_keyring_remove_item (self, GPOINTER_TO_UINT (kt));
-}
-
-static void
-on_keyring_load_list_item_ids (GnomeKeyringResult result,
- GList *list,
- gpointer user_data)
-{
- GSimpleAsyncResult *res = G_SIMPLE_ASYNC_RESULT (user_data);
- keyring_load_closure *closure = g_simple_async_result_get_op_res_gpointer (res);
+ SecretCollection *collection = SECRET_COLLECTION (self);
SeahorseGkrItem *item;
- const gchar *keyring_name;
- GError *error = NULL;
- GHashTable *checks;
+ const gchar *object_path;
GHashTableIter iter;
- gpointer key;
-
- closure->request = NULL;
-
- if (seahorse_gkr_propagate_error (result, &error)) {
- g_simple_async_result_take_error (res, error);
- g_simple_async_result_complete_in_idle (res);
- return;
- }
-
- keyring_name = seahorse_gkr_keyring_get_name (closure->keyring);
- g_return_if_fail (keyring_name);
-
- /* When loading new keys prepare a list of current */
- checks = g_hash_table_new (g_direct_hash, g_direct_equal);
- g_hash_table_iter_init (&iter, closure->keyring->pv->items);
- while (g_hash_table_iter_next (&iter, &key, NULL))
- g_hash_table_insert (checks, key, key);
-
- while (list) {
- item = g_hash_table_lookup (closure->keyring->pv->items, list->data);
-
- if (item == NULL) {
- item = seahorse_gkr_item_new (closure->keyring, keyring_name,
- GPOINTER_TO_UINT (list->data));
-
- /* Add to context */
- g_hash_table_insert (closure->keyring->pv->items, list->data, item);
- gcr_collection_emit_added (GCR_COLLECTION (closure->keyring), G_OBJECT (item));
+ GHashTable *seen;
+ GList *items = NULL;
+ GList *l;
+
+ seen = g_hash_table_new (g_str_hash, g_str_equal);
+
+ if (!secret_collection_get_locked (collection))
+ items = secret_collection_get_items (collection);
+
+ for (l = items; l != NULL; l = g_list_next (l)) {
+ object_path = g_dbus_proxy_get_object_path (l->data);
+ item = l->data;
+
+ g_hash_table_add (seen, (gpointer)object_path);
+ if (!g_hash_table_lookup (self->pv->items, object_path)) {
+ g_object_set (item, "place", self, NULL);
+ g_hash_table_insert (self->pv->items,
+ g_strdup (object_path),
+ g_object_ref (item));
+ gcr_collection_emit_added (GCR_COLLECTION (self), G_OBJECT (item));
}
-
- g_hash_table_remove (checks, list->data);
- list = g_list_next (list);
}
- g_hash_table_foreach (checks, (GHFunc)remove_key_from_context, closure->keyring);
- g_hash_table_destroy (checks);
-
- seahorse_progress_end (closure->cancellable, res);
- g_simple_async_result_complete_in_idle (res);
-}
-
-static void
-on_keyring_load_get_info (GnomeKeyringResult result,
- GnomeKeyringInfo *info,
- gpointer user_data)
-{
- GSimpleAsyncResult *res = G_SIMPLE_ASYNC_RESULT (user_data);
- keyring_load_closure *closure = g_simple_async_result_get_op_res_gpointer (res);
- GError *error = NULL;
- const gchar *name;
-
- closure->request = NULL;
-
- if (seahorse_gkr_propagate_error (result, &error)) {
- g_simple_async_result_take_error (res, error);
- g_simple_async_result_complete_in_idle (res);
-
- } else {
- seahorse_gkr_keyring_set_info (closure->keyring, info);
-
- /* Locked, no items... */
- if (gnome_keyring_info_get_is_locked (info)) {
- on_keyring_load_list_item_ids (GNOME_KEYRING_RESULT_OK, NULL, res);
-
- } else {
- name = seahorse_gkr_keyring_get_name (closure->keyring);
- closure->request = gnome_keyring_list_item_ids (name,
- on_keyring_load_list_item_ids,
- g_object_ref (res), g_object_unref);
+ /* Remove any that we didn't find */
+ g_hash_table_iter_init (&iter, self->pv->items);
+ while (g_hash_table_iter_next (&iter, (gpointer *)&object_path, NULL)) {
+ if (!g_hash_table_lookup (seen, object_path)) {
+ item = g_hash_table_lookup (self->pv->items, object_path);
+ g_object_ref (item);
+ g_object_set (item, "place", NULL, NULL);
+ g_hash_table_iter_remove (&iter);
+ gcr_collection_emit_removed (GCR_COLLECTION (self), G_OBJECT (item));
+ g_object_unref (item);
}
}
-}
-
-static void
-on_keyring_load_cancelled (GCancellable *cancellable,
- gpointer user_data)
-{
- keyring_load_closure *closure = user_data;
- if (closure->request)
- gnome_keyring_cancel_request (closure->request);
+ g_hash_table_destroy (seen);
+ g_list_free_full (items, g_object_unref);
}
static void
seahorse_gkr_keyring_load_async (SeahorsePlace *place,
- GCancellable *cancellable,
- GAsyncReadyCallback callback,
- gpointer user_data)
+ GCancellable *cancellable,
+ GAsyncReadyCallback callback,
+ gpointer user_data)
{
SeahorseGkrKeyring *self = SEAHORSE_GKR_KEYRING (place);
- keyring_load_closure *closure;
- GSimpleAsyncResult *res;
+ GSimpleAsyncResult *async;
- res = g_simple_async_result_new (G_OBJECT (self), callback, user_data,
- seahorse_gkr_keyring_load_async);
-
- closure = g_new0 (keyring_load_closure, 1);
- closure->keyring = g_object_ref (self);
- closure->cancellable = cancellable ? g_object_ref (cancellable) : NULL;
- g_simple_async_result_set_op_res_gpointer (res, closure, keyring_load_free);
-
- closure->request = gnome_keyring_get_info (seahorse_gkr_keyring_get_name (self),
- on_keyring_load_get_info,
- g_object_ref (res), g_object_unref);
+ async = g_simple_async_result_new (G_OBJECT (self), callback, user_data,
+ seahorse_gkr_keyring_load_async);
- if (cancellable)
- closure->cancelled_sig = g_cancellable_connect (cancellable,
- G_CALLBACK (on_keyring_load_cancelled),
- closure, NULL);
- seahorse_progress_prep_and_begin (cancellable, res, NULL);
+ refresh_collection (self);
- g_object_unref (res);
+ g_simple_async_result_complete_in_idle (async);
+ g_object_unref (async);
}
static gboolean
seahorse_gkr_keyring_load_finish (SeahorsePlace *place,
- GAsyncResult *result,
- GError **error)
+ GAsyncResult *result,
+ GError **error)
{
g_return_val_if_fail (g_simple_async_result_is_valid (result, G_OBJECT (place),
seahorse_gkr_keyring_load_async), FALSE);
@@ -354,20 +156,38 @@ seahorse_gkr_keyring_load_finish (SeahorsePlace *place,
}
static void
-seahorse_gkr_keyring_constructed (GObject *obj)
+on_aliases_changed (GObject *obj,
+ GParamSpec *pspec,
+ gpointer user_data)
{
- SeahorseGkrKeyring *self = SEAHORSE_GKR_KEYRING (obj);
+ g_object_notify (user_data, "is-default");
+ g_object_notify (user_data, "description");
+}
- G_OBJECT_CLASS (seahorse_gkr_keyring_parent_class)->constructed (obj);
+static void
+on_notify_items (GObject *obj,
+ GParamSpec *pspec,
+ gpointer user_data)
+{
+ refresh_collection (SEAHORSE_GKR_KEYRING (obj));
+}
- g_return_if_fail (self->pv->keyring_name);
+static void
+on_notify_locked (GObject *obj,
+ GParamSpec *pspec,
+ gpointer user_data)
+{
+ refresh_collection (SEAHORSE_GKR_KEYRING (obj));
}
static void
seahorse_gkr_keyring_init (SeahorseGkrKeyring *self)
{
self->pv = G_TYPE_INSTANCE_GET_PRIVATE (self, SEAHORSE_TYPE_GKR_KEYRING, SeahorseGkrKeyringPrivate);
- self->pv->items = g_hash_table_new_full (g_direct_hash, g_direct_equal, NULL, g_object_unref);
+ self->pv->items = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_object_unref);
+ g_signal_connect (self, "notify::items", G_CALLBACK (on_notify_items), NULL);
+ g_signal_connect (self, "notify::locked", G_CALLBACK (on_notify_locked), NULL);
+ g_signal_connect (seahorse_gkr_backend_get (), "notify::aliases", G_CALLBACK (on_aliases_changed), self);
}
static void
@@ -376,81 +196,47 @@ seahorse_gkr_keyring_finalize (GObject *obj)
SeahorseGkrKeyring *self = SEAHORSE_GKR_KEYRING (obj);
g_hash_table_destroy (self->pv->items);
-
- if (self->pv->keyring_info)
- gnome_keyring_info_free (self->pv->keyring_info);
- self->pv->keyring_info = NULL;
- g_assert (self->pv->req_info == NULL);
-
- g_free (self->pv->keyring_name);
- self->pv->keyring_name = NULL;
-
- if (self->pv->keyring_info)
- gnome_keyring_info_free (self->pv->keyring_info);
- self->pv->keyring_info = NULL;
+ g_signal_handlers_disconnect_by_func (self, on_notify_items, NULL);
+ g_signal_handlers_disconnect_by_func (self, on_notify_locked, NULL);
+ g_signal_handlers_disconnect_by_func (seahorse_gkr_backend_get (), on_aliases_changed, self);
G_OBJECT_CLASS (seahorse_gkr_keyring_parent_class)->finalize (obj);
}
static void
-seahorse_gkr_keyring_set_property (GObject *obj, guint prop_id, const GValue *value,
- GParamSpec *pspec)
-{
- SeahorseGkrKeyring *self = SEAHORSE_GKR_KEYRING (obj);
-
- switch (prop_id) {
- case PROP_KEYRING_NAME:
- g_return_if_fail (self->pv->keyring_name == NULL);
- self->pv->keyring_name = g_value_dup_string (value);
- g_object_notify (obj, "keyring-name");
- break;
- case PROP_KEYRING_INFO:
- seahorse_gkr_keyring_set_info (self, g_value_get_boxed (value));
- break;
- case PROP_IS_DEFAULT:
- seahorse_gkr_keyring_set_is_default (self, g_value_get_boolean (value));
- break;
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID (obj, prop_id, pspec);
- break;
- }
-}
-
-static void
seahorse_gkr_keyring_get_property (GObject *obj, guint prop_id, GValue *value,
GParamSpec *pspec)
{
SeahorseGkrKeyring *self = SEAHORSE_GKR_KEYRING (obj);
+ const gchar *object_path;
gchar *text;
switch (prop_id) {
case PROP_DESCRIPTION:
g_value_set_string (value, seahorse_gkr_keyring_get_description (self));
break;
- case PROP_KEYRING_NAME:
- g_value_set_string (value, seahorse_gkr_keyring_get_name (self));
- break;
- case PROP_KEYRING_INFO:
- g_value_set_boxed (value, seahorse_gkr_keyring_get_info (self));
- break;
case PROP_IS_DEFAULT:
g_value_set_boolean (value, seahorse_gkr_keyring_get_is_default (self));
break;
case PROP_URI:
- text = g_strdup_printf ("secret-service://%s", self->pv->keyring_name);
+ object_path = g_dbus_proxy_get_object_path (G_DBUS_PROXY (self));
+ text = g_strdup_printf ("secret-service://%s", object_path);
g_value_take_string (value, text);
break;
case PROP_ACTIONS:
g_value_take_object (value, seahorse_gkr_keyring_actions_new (self));
break;
- case PROP_LOCKED:
- g_value_set_boolean (value, seahorse_gkr_keyring_get_locked (self));
- break;
case PROP_LOCKABLE:
- g_value_set_boolean (value, !seahorse_gkr_keyring_get_locked (self));
+ g_value_set_boolean (value, !secret_collection_get_locked (SECRET_COLLECTION (self)));
break;
case PROP_UNLOCKABLE:
- g_value_set_boolean (value, seahorse_gkr_keyring_get_locked (self));
+ g_value_set_boolean (value, secret_collection_get_locked (SECRET_COLLECTION (self)));
+ break;
+ case PROP_DELETABLE:
+ g_value_set_boolean (value, TRUE);
+ break;
+ case PROP_ICON:
+ g_value_take_object (value, g_themed_icon_new ("folder"));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (obj, prop_id, pspec);
@@ -465,33 +251,21 @@ seahorse_gkr_keyring_class_init (SeahorseGkrKeyringClass *klass)
g_type_class_add_private (klass, sizeof (SeahorseGkrKeyringPrivate));
- gobject_class->constructed = seahorse_gkr_keyring_constructed;
gobject_class->finalize = seahorse_gkr_keyring_finalize;
- gobject_class->set_property = seahorse_gkr_keyring_set_property;
gobject_class->get_property = seahorse_gkr_keyring_get_property;
g_object_class_override_property (gobject_class, PROP_DESCRIPTION, "description");
g_object_class_override_property (gobject_class, PROP_URI, "uri");
g_object_class_override_property (gobject_class, PROP_ACTIONS, "actions");
-
- g_object_class_install_property (gobject_class, PROP_KEYRING_NAME,
- g_param_spec_string ("keyring-name", "Gnome Keyring Name", "Name of keyring.",
- "", G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
-
- g_object_class_install_property (gobject_class, PROP_KEYRING_INFO,
- g_param_spec_boxed ("keyring-info", "Gnome Keyring Info", "Info about keyring.",
- boxed_type_keyring_info (), G_PARAM_READWRITE));
+ g_object_class_override_property (gobject_class, PROP_ICON, "icon");
g_object_class_install_property (gobject_class, PROP_IS_DEFAULT,
g_param_spec_boolean ("is-default", "Is default", "Is the default keyring.",
- FALSE, G_PARAM_READWRITE));
-
- g_object_class_install_property (gobject_class, PROP_LOCKED,
- g_param_spec_boolean ("locked", "Locked", "Keyring is locked?",
FALSE, G_PARAM_READABLE));
g_object_class_override_property (gobject_class, PROP_LOCKABLE, "lockable");
g_object_class_override_property (gobject_class, PROP_UNLOCKABLE, "unlockable");
+ g_object_class_override_property (gobject_class, PROP_DELETABLE, "deletable");
}
static void
@@ -520,12 +294,10 @@ seahorse_gkr_keyring_contains (GcrCollection *collection,
GObject *object)
{
SeahorseGkrKeyring *self = SEAHORSE_GKR_KEYRING (collection);
- guint32 item_id;
if (!SEAHORSE_IS_GKR_ITEM (object))
return FALSE;
- item_id = seahorse_gkr_item_get_item_id (SEAHORSE_GKR_ITEM (object));
- return g_hash_table_lookup (self->pv->items, GUINT_TO_POINTER (item_id)) ? TRUE : FALSE;
+ return g_hash_table_lookup (self->pv->items, g_dbus_proxy_get_object_path (G_DBUS_PROXY (object))) != NULL;
}
static void
@@ -550,20 +322,23 @@ seahorse_keyring_deletable_iface (SeahorseDeletableIface *iface)
}
static void
-on_keyring_xlock_done (GnomeKeyringResult result,
- gpointer user_data)
+on_keyring_lock_done (GObject *source,
+ GAsyncResult *result,
+ gpointer user_data)
{
GSimpleAsyncResult *res = G_SIMPLE_ASYNC_RESULT (user_data);
SeahorseGkrKeyring *self = SEAHORSE_GKR_KEYRING (g_async_result_get_source_object (user_data));
GError *error = NULL;
- if (seahorse_gkr_propagate_error (result, &error))
+ secret_service_lock_finish (SECRET_SERVICE (source), result, NULL, &error);
+ if (error != NULL)
g_simple_async_result_take_error (res, error);
- seahorse_gkr_keyring_load_async (SEAHORSE_PLACE (self), NULL, NULL, NULL);
- g_simple_async_result_complete_in_idle (res);
+ refresh_collection (self);
+ g_simple_async_result_complete (res);
g_object_unref (self);
+ g_object_unref (res);
}
static void
@@ -573,14 +348,18 @@ seahorse_gkr_keyring_lock_async (SeahorseLockable *lockable,
GAsyncReadyCallback callback,
gpointer user_data)
{
- SeahorseGkrKeyring *self = SEAHORSE_GKR_KEYRING (lockable);
+ SecretCollection *self = SECRET_COLLECTION (lockable);
GSimpleAsyncResult *res;
+ GList *objects;
res = g_simple_async_result_new (G_OBJECT (self), callback, user_data,
seahorse_gkr_keyring_lock_async);
- gnome_keyring_lock (seahorse_gkr_keyring_get_name (self),
- on_keyring_xlock_done, g_object_ref (res), g_object_unref);
+ objects = g_list_prepend (NULL, self);
+ secret_service_lock (secret_collection_get_service (self),
+ objects, cancellable, on_keyring_lock_done,
+ g_object_ref (res));
+ g_list_free (objects);
g_object_unref (res);
}
@@ -600,20 +379,44 @@ seahorse_gkr_keyring_lock_finish (SeahorseLockable *lockable,
}
static void
+on_keyring_unlock_done (GObject *source,
+ GAsyncResult *result,
+ gpointer user_data)
+{
+ GSimpleAsyncResult *res = G_SIMPLE_ASYNC_RESULT (user_data);
+ SeahorseGkrKeyring *self = SEAHORSE_GKR_KEYRING (g_async_result_get_source_object (user_data));
+ GError *error = NULL;
+
+ secret_service_unlock_finish (SECRET_SERVICE (source), result, NULL, &error);
+ if (error != NULL)
+ g_simple_async_result_take_error (res, error);
+
+ refresh_collection (self);
+ g_simple_async_result_complete (res);
+
+ g_object_unref (self);
+ g_object_unref (res);
+}
+
+static void
seahorse_gkr_keyring_unlock_async (SeahorseLockable *lockable,
GTlsInteraction *interaction,
GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer user_data)
{
- SeahorseGkrKeyring *self = SEAHORSE_GKR_KEYRING (lockable);
+ SecretCollection *self = SECRET_COLLECTION (lockable);
GSimpleAsyncResult *res;
+ GList *objects;
res = g_simple_async_result_new (G_OBJECT (lockable), callback, user_data,
seahorse_gkr_keyring_unlock_async);
- gnome_keyring_unlock (seahorse_gkr_keyring_get_name (self), NULL,
- on_keyring_xlock_done, g_object_ref (res), g_object_unref);
+ objects = g_list_prepend (NULL, self);
+ secret_service_unlock (secret_collection_get_service (self),
+ objects, cancellable, on_keyring_unlock_done,
+ g_object_ref (res));
+ g_list_free (objects);
g_object_unref (res);
}
@@ -655,79 +458,18 @@ seahorse_keyring_viewable_iface (SeahorseViewableIface *iface)
iface->show_viewer = seahorse_gkr_keyring_show_viewer;
}
-SeahorseGkrKeyring*
-seahorse_gkr_keyring_new (const gchar *keyring_name)
-{
- return g_object_new (SEAHORSE_TYPE_GKR_KEYRING, "keyring-name", keyring_name, NULL);
-}
-
-const gchar*
-seahorse_gkr_keyring_get_name (SeahorseGkrKeyring *self)
-{
- g_return_val_if_fail (SEAHORSE_IS_GKR_KEYRING (self), NULL);
- return self->pv->keyring_name;
-}
-
const gchar *
seahorse_gkr_keyring_get_description (SeahorseGkrKeyring *self)
{
g_return_val_if_fail (SEAHORSE_IS_GKR_KEYRING (self), NULL);
- if (g_strcmp0 (self->pv->keyring_name, "login") == 0)
+ if (seahorse_gkr_backend_has_alias (NULL, "login", self))
return _("A keyring that is automatically unlocked on login");
return _("A keyring used to store passwords");
}
-GnomeKeyringInfo*
-seahorse_gkr_keyring_get_info (SeahorseGkrKeyring *self)
-{
- g_return_val_if_fail (SEAHORSE_IS_GKR_KEYRING (self), NULL);
- require_keyring_info (self);
- return self->pv->keyring_info;
-}
-
-void
-seahorse_gkr_keyring_set_info (SeahorseGkrKeyring *self, GnomeKeyringInfo *info)
-{
- GObject *obj;
-
- g_return_if_fail (SEAHORSE_IS_GKR_KEYRING (self));
-
- if (self->pv->keyring_info)
- gnome_keyring_info_free (self->pv->keyring_info);
- if (info)
- self->pv->keyring_info = gnome_keyring_info_copy (info);
- else
- self->pv->keyring_info = NULL;
-
- obj = G_OBJECT (self);
- g_object_freeze_notify (obj);
- seahorse_gkr_keyring_realize (self);
- g_object_notify (obj, "keyring-info");
- g_object_notify (obj, "locked");
- g_object_thaw_notify (obj);
-}
-
gboolean
seahorse_gkr_keyring_get_is_default (SeahorseGkrKeyring *self)
{
g_return_val_if_fail (SEAHORSE_IS_GKR_KEYRING (self), FALSE);
- return self->pv->is_default;
-}
-
-void
-seahorse_gkr_keyring_set_is_default (SeahorseGkrKeyring *self, gboolean is_default)
-{
- g_return_if_fail (SEAHORSE_IS_GKR_KEYRING (self));
- self->pv->is_default = is_default;
- g_object_notify (G_OBJECT (self), "is-default");
-}
-
-gboolean
-seahorse_gkr_keyring_get_locked (SeahorseGkrKeyring *self)
-{
- g_return_val_if_fail (SEAHORSE_IS_GKR_KEYRING (self), TRUE);
-
- if (!self->pv->keyring_info)
- return TRUE;
- return gnome_keyring_info_get_is_locked (self->pv->keyring_info);
+ return seahorse_gkr_backend_has_alias (NULL, "default", self);
}
diff --git a/gkr/seahorse-gkr-keyring.h b/gkr/seahorse-gkr-keyring.h
index 67e25eb..7992be7 100644
--- a/gkr/seahorse-gkr-keyring.h
+++ b/gkr/seahorse-gkr-keyring.h
@@ -27,7 +27,7 @@
#include <glib-object.h>
#include <gio/gio.h>
-#include <gnome-keyring.h>
+#include <secret/secret-unstable.h>
#define SEAHORSE_TYPE_GKR_KEYRING (seahorse_gkr_keyring_get_type ())
#define SEAHORSE_GKR_KEYRING(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), SEAHORSE_TYPE_GKR_KEYRING, SeahorseGkrKeyring))
@@ -41,37 +41,18 @@ typedef struct _SeahorseGkrKeyringClass SeahorseGkrKeyringClass;
typedef struct _SeahorseGkrKeyringPrivate SeahorseGkrKeyringPrivate;
struct _SeahorseGkrKeyring {
- SeahorseObject parent;
+ SecretCollection parent;
SeahorseGkrKeyringPrivate *pv;
};
struct _SeahorseGkrKeyringClass {
- SeahorseObjectClass parent_class;
+ SecretCollectionClass parent_class;
};
GType seahorse_gkr_keyring_get_type (void);
-SeahorseGkrKeyring* seahorse_gkr_keyring_new (const gchar *keyring_name);
-
-void seahorse_gkr_keyring_realize (SeahorseGkrKeyring *self);
-
-void seahorse_gkr_keyring_remove_item (SeahorseGkrKeyring *self,
- guint32 item_id);
-
-const gchar* seahorse_gkr_keyring_get_name (SeahorseGkrKeyring *self);
-
const gchar * seahorse_gkr_keyring_get_description (SeahorseGkrKeyring *self);
-GnomeKeyringInfo* seahorse_gkr_keyring_get_info (SeahorseGkrKeyring *self);
-
-void seahorse_gkr_keyring_set_info (SeahorseGkrKeyring *self,
- GnomeKeyringInfo *info);
-
gboolean seahorse_gkr_keyring_get_is_default (SeahorseGkrKeyring *self);
-void seahorse_gkr_keyring_set_is_default (SeahorseGkrKeyring *self,
- gboolean is_default);
-
-gboolean seahorse_gkr_keyring_get_locked (SeahorseGkrKeyring *self);
-
#endif /* __SEAHORSE_GKR_KEYRING_H__ */
diff --git a/libseahorse/seahorse-interaction.c b/libseahorse/seahorse-interaction.c
index be8cb58..834b845 100644
--- a/libseahorse/seahorse-interaction.c
+++ b/libseahorse/seahorse-interaction.c
@@ -25,9 +25,8 @@
#include "seahorse-interaction.h"
#include "seahorse-passphrase.h"
-#include <gnome-keyring-memory.h>
-
#include <glib/gi18n.h>
+#include <gcr/gcr.h>
enum {
PROP_0,
@@ -127,8 +126,8 @@ seahorse_interaction_ask_password (GTlsInteraction *interaction,
pass = seahorse_passphrase_prompt_get (dialog);
length = strlen (pass);
g_tls_password_set_value_full (password,
- (guchar *)gnome_keyring_memory_strdup (pass),
- length, gnome_keyring_memory_free);
+ (guchar *)gcr_secure_memory_strdup (pass),
+ length, gcr_secure_memory_free);
res = G_TLS_INTERACTION_HANDLED;
break;
default:
diff --git a/libseahorse/seahorse-object-widget.c b/libseahorse/seahorse-object-widget.c
index d15349d..45b9c01 100644
--- a/libseahorse/seahorse-object-widget.c
+++ b/libseahorse/seahorse-object-widget.c
@@ -88,7 +88,7 @@ seahorse_object_widget_class_init (SeahorseObjectWidgetClass *klass)
g_object_class_install_property (gobject_class, PROP_OBJECT,
g_param_spec_object ("object", "Seahorse Object",
"Seahorse Object of this widget",
- SEAHORSE_TYPE_OBJECT, G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
+ G_TYPE_OBJECT, G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
}
static void
diff --git a/libseahorse/seahorse-registry.c b/libseahorse/seahorse-registry.c
index 44fc13a..64245e5 100644
--- a/libseahorse/seahorse-registry.c
+++ b/libseahorse/seahorse-registry.c
@@ -165,6 +165,7 @@ seahorse_registry_dispose (GObject *obj)
{
SeahorseRegistryPrivate *pv = SEAHORSE_REGISTRY_GET_PRIVATE (obj);
g_hash_table_remove_all (pv->types);
+ g_hash_table_remove_all (pv->objects);
G_OBJECT_CLASS (seahorse_registry_parent_class)->dispose (obj);
}
@@ -173,6 +174,7 @@ seahorse_registry_finalize (GObject *obj)
{
SeahorseRegistryPrivate *pv = SEAHORSE_REGISTRY_GET_PRIVATE (obj);
g_hash_table_destroy (pv->types);
+ g_hash_table_destroy (pv->objects);
G_OBJECT_CLASS (seahorse_registry_parent_class)->finalize (obj);
}
diff --git a/libseahorse/seahorse-secure-memory.c b/libseahorse/seahorse-secure-memory.c
index 32a1f56..30cb185 100644
--- a/libseahorse/seahorse-secure-memory.c
+++ b/libseahorse/seahorse-secure-memory.c
@@ -25,9 +25,8 @@
#include <string.h>
#include <glib.h>
-
-#include <gnome-keyring-memory.h>
-
+#include <gcr/gcr.h>
+
#include "seahorse-secure-memory.h"
/* extern declared in seahorse-secure-memory.h */
@@ -50,7 +49,7 @@ switch_malloc (gsize size)
if (size == 0)
return NULL;
if (seahorse_use_secure_mem)
- p = gnome_keyring_memory_try_alloc (size);
+ p = gcr_secure_memory_try_alloc (size);
else
p = malloc (size);
return p;
@@ -74,7 +73,7 @@ switch_calloc (gsize num, gsize size)
if (size == 0 || num == 0)
return NULL;
if (seahorse_use_secure_mem)
- p = gnome_keyring_memory_try_alloc (size * num);
+ p = gcr_secure_memory_try_alloc (size * num);
else
p = calloc (num, size);
return p;
@@ -102,11 +101,11 @@ switch_realloc (gpointer mem, gsize size)
if (!mem) {
if (seahorse_use_secure_mem)
- p = gnome_keyring_memory_alloc (size);
+ p = gcr_secure_memory_alloc (size);
else
p = malloc (size);
- } else if (gnome_keyring_memory_is_secure (mem))
- p = gnome_keyring_memory_try_realloc (mem, size);
+ } else if (gcr_secure_memory_is_secure (mem))
+ p = gcr_secure_memory_try_realloc (mem, size);
else
p = realloc (mem, size);
return p;
@@ -123,8 +122,8 @@ static void
switch_free (gpointer mem)
{
if (mem) {
- if (gnome_keyring_memory_is_secure (mem))
- gnome_keyring_memory_free (mem);
+ if (gcr_secure_memory_is_secure (mem))
+ gcr_secure_memory_free (mem);
else
free (mem);
}
@@ -141,9 +140,9 @@ seahorse_try_gk_secure_memory ()
{
gpointer p;
- p = gnome_keyring_memory_try_alloc (10);
+ p = gcr_secure_memory_try_alloc (10);
if (p != NULL) {
- gnome_keyring_memory_free (p);
+ gcr_secure_memory_free (p);
return TRUE;
}
@@ -173,7 +172,7 @@ seahorse_secure_memory_init ()
vtable.calloc = switch_calloc;
g_mem_set_vtable (&vtable);
} else {
- g_warning ("Unable to allocate secure memory from gnome-keyring.\n");
+ g_warning ("Unable to allocate secure memory.\n");
g_warning ("Proceeding using insecure memory for password fields.\n");
}
}
diff --git a/pgp/seahorse-pgp-backend.c b/pgp/seahorse-pgp-backend.c
index 36df01f..2ea226b 100644
--- a/pgp/seahorse-pgp-backend.c
+++ b/pgp/seahorse-pgp-backend.c
@@ -34,8 +34,6 @@
#include "seahorse-servers.h"
#include "seahorse-util.h"
-#include <gnome-keyring.h>
-
#include <glib/gi18n.h>
#include <string.h>
diff --git a/src/seahorse-key-manager.c b/src/seahorse-key-manager.c
index e8f2fed..19defd8 100644
--- a/src/seahorse-key-manager.c
+++ b/src/seahorse-key-manager.c
@@ -34,8 +34,6 @@
#include "seahorse-progress.h"
#include "seahorse-util.h"
-#include "gkr/seahorse-gkr-item.h"
-
#include <glib/gi18n.h>
enum {
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]