2012-02-01 12:34:08 +00:00
|
|
|
/* libsecret - GLib wrapper for Secret Service
|
2012-01-20 14:10:35 +00:00
|
|
|
*
|
2012-01-23 16:20:18 +00:00
|
|
|
* Copyright 2012 Red Hat Inc.
|
2012-01-20 14:10:35 +00:00
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Lesser General Public License as published
|
2012-03-31 13:32:43 +00:00
|
|
|
* by the Free Software Foundation; either version 2.1 of the licence or (at
|
2012-01-20 14:10:35 +00:00
|
|
|
* your option) any later version.
|
|
|
|
*
|
|
|
|
* See the included COPYING file for more information.
|
2012-03-31 13:32:43 +00:00
|
|
|
*
|
|
|
|
* Author: Stef Walter <stefw@gnome.org>
|
2012-01-20 14:10:35 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
2012-02-01 12:34:08 +00:00
|
|
|
#include "secret-collection.h"
|
|
|
|
#include "secret-dbus-generated.h"
|
2012-07-05 19:26:20 +00:00
|
|
|
#include "secret-enum-types.h"
|
2012-02-01 12:34:08 +00:00
|
|
|
#include "secret-item.h"
|
2012-07-05 14:41:28 +00:00
|
|
|
#include "secret-paths.h"
|
2012-02-01 12:34:08 +00:00
|
|
|
#include "secret-private.h"
|
|
|
|
#include "secret-service.h"
|
|
|
|
#include "secret-types.h"
|
2012-01-20 14:10:35 +00:00
|
|
|
|
|
|
|
#include <glib/gi18n-lib.h>
|
|
|
|
|
2012-02-02 13:59:59 +00:00
|
|
|
/**
|
|
|
|
* SECTION:secret-collection
|
|
|
|
* @title: SecretCollection
|
|
|
|
* @short_description: A collection of secret items
|
|
|
|
*
|
|
|
|
* #SecretCollection represents a collection of secret items stored in the
|
|
|
|
* Secret Service.
|
|
|
|
*
|
|
|
|
* A collection can be in a locked or unlocked state. Use secret_service_lock()
|
|
|
|
* or secret_service_unlock() to lock or unlock the collection.
|
|
|
|
*
|
2012-03-17 13:25:50 +00:00
|
|
|
* Use the SecretCollection::items property or secret_collection_get_items() to
|
2012-02-02 13:59:59 +00:00
|
|
|
* lookup the items in the collection. There may not be any items exposed when
|
|
|
|
* the collection is locked.
|
2012-03-24 06:52:12 +00:00
|
|
|
*
|
2012-04-27 14:57:36 +00:00
|
|
|
* Stability: Unstable
|
2012-02-02 13:59:59 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* SecretCollection:
|
|
|
|
*
|
|
|
|
* A proxy object representing a collection of secrets in the Secret Service.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* SecretCollectionClass:
|
|
|
|
* @parent_class: the parent class
|
|
|
|
*
|
|
|
|
* The class for #SecretCollection.
|
|
|
|
*/
|
|
|
|
|
2012-07-05 19:26:20 +00:00
|
|
|
/**
|
|
|
|
* SecretCollectionFlags:
|
|
|
|
* @SECRET_COLLECTION_NONE: no flags for initializing the #SecretCollection
|
|
|
|
* @SECRET_COLLECTION_LOAD_ITEMS: load items while initializing the
|
|
|
|
* #SecretCollection
|
|
|
|
*
|
|
|
|
* Flags which determine which parts of the #SecretCollection proxy are initialized
|
|
|
|
* during a secret_collection_new() or secret_collection_new_sync() operation.
|
|
|
|
*/
|
|
|
|
|
2012-01-20 14:10:35 +00:00
|
|
|
enum {
|
|
|
|
PROP_0,
|
2012-01-23 16:20:18 +00:00
|
|
|
PROP_SERVICE,
|
2012-07-05 19:26:20 +00:00
|
|
|
PROP_FLAGS,
|
2012-01-20 14:10:35 +00:00
|
|
|
PROP_ITEMS,
|
|
|
|
PROP_LABEL,
|
|
|
|
PROP_LOCKED,
|
|
|
|
PROP_CREATED,
|
|
|
|
PROP_MODIFIED
|
|
|
|
};
|
|
|
|
|
2012-02-01 12:34:08 +00:00
|
|
|
struct _SecretCollectionPrivate {
|
2012-01-20 14:10:35 +00:00
|
|
|
/* Doesn't change between construct and finalize */
|
2012-02-01 12:34:08 +00:00
|
|
|
SecretService *service;
|
2012-01-20 14:10:35 +00:00
|
|
|
GCancellable *cancellable;
|
2012-01-23 16:20:18 +00:00
|
|
|
gboolean constructing;
|
2012-07-05 19:26:20 +00:00
|
|
|
SecretCollectionFlags init_flags;
|
2012-01-20 14:10:35 +00:00
|
|
|
|
|
|
|
/* Protected by mutex */
|
|
|
|
GMutex mutex;
|
|
|
|
GHashTable *items;
|
|
|
|
};
|
|
|
|
|
2012-02-01 12:34:08 +00:00
|
|
|
static GInitableIface *secret_collection_initable_parent_iface = NULL;
|
2012-01-25 13:26:52 +00:00
|
|
|
|
2012-02-01 12:34:08 +00:00
|
|
|
static GAsyncInitableIface *secret_collection_async_initable_parent_iface = NULL;
|
2012-01-25 13:26:52 +00:00
|
|
|
|
2012-02-01 12:34:08 +00:00
|
|
|
static void secret_collection_initable_iface (GInitableIface *iface);
|
2012-01-25 13:26:52 +00:00
|
|
|
|
2012-02-01 12:34:08 +00:00
|
|
|
static void secret_collection_async_initable_iface (GAsyncInitableIface *iface);
|
2012-01-25 13:26:52 +00:00
|
|
|
|
2012-02-01 12:34:08 +00:00
|
|
|
G_DEFINE_TYPE_WITH_CODE (SecretCollection, secret_collection, G_TYPE_DBUS_PROXY,
|
|
|
|
G_IMPLEMENT_INTERFACE (G_TYPE_INITABLE, secret_collection_initable_iface);
|
|
|
|
G_IMPLEMENT_INTERFACE (G_TYPE_ASYNC_INITABLE, secret_collection_async_initable_iface);
|
2012-01-25 13:26:52 +00:00
|
|
|
);
|
2012-01-20 14:10:35 +00:00
|
|
|
|
|
|
|
static GHashTable *
|
|
|
|
items_table_new (void)
|
|
|
|
{
|
|
|
|
return g_hash_table_new_full (g_str_hash, g_str_equal,
|
|
|
|
g_free, g_object_unref);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2012-02-01 12:34:08 +00:00
|
|
|
secret_collection_init (SecretCollection *self)
|
2012-01-20 14:10:35 +00:00
|
|
|
{
|
2012-02-01 12:34:08 +00:00
|
|
|
self->pv = G_TYPE_INSTANCE_GET_PRIVATE (self, SECRET_TYPE_COLLECTION,
|
|
|
|
SecretCollectionPrivate);
|
2012-01-20 14:10:35 +00:00
|
|
|
|
|
|
|
g_mutex_init (&self->pv->mutex);
|
|
|
|
self->pv->cancellable = g_cancellable_new ();
|
|
|
|
self->pv->items = items_table_new ();
|
2012-01-23 16:20:18 +00:00
|
|
|
self->pv->constructing = TRUE;
|
2012-01-20 14:10:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
on_set_label (GObject *source,
|
|
|
|
GAsyncResult *result,
|
|
|
|
gpointer user_data)
|
|
|
|
{
|
2012-02-01 12:34:08 +00:00
|
|
|
SecretCollection *self = SECRET_COLLECTION (user_data);
|
2012-01-20 14:10:35 +00:00
|
|
|
GError *error = NULL;
|
|
|
|
|
2012-02-01 12:34:08 +00:00
|
|
|
secret_collection_set_label_finish (self, result, &error);
|
2012-01-20 14:10:35 +00:00
|
|
|
if (error != NULL) {
|
2012-02-01 12:34:08 +00:00
|
|
|
g_warning ("couldn't set SecretCollection Label: %s", error->message);
|
2012-01-20 14:10:35 +00:00
|
|
|
g_error_free (error);
|
|
|
|
}
|
|
|
|
|
|
|
|
g_object_unref (self);
|
|
|
|
}
|
|
|
|
|
2012-07-05 21:14:50 +00:00
|
|
|
static void
|
|
|
|
collection_take_service (SecretCollection *self,
|
|
|
|
SecretService *service)
|
|
|
|
{
|
|
|
|
if (service == NULL)
|
|
|
|
return;
|
|
|
|
|
|
|
|
g_return_if_fail (self->pv->service == NULL);
|
|
|
|
|
|
|
|
self->pv->service = service;
|
|
|
|
g_object_add_weak_pointer (G_OBJECT (self->pv->service),
|
|
|
|
(gpointer *)&self->pv->service);
|
|
|
|
|
|
|
|
/* Yes, we expect that the service will stay around */
|
|
|
|
g_object_unref (service);
|
|
|
|
}
|
|
|
|
|
2012-01-20 14:10:35 +00:00
|
|
|
static void
|
2012-02-01 12:34:08 +00:00
|
|
|
secret_collection_set_property (GObject *obj,
|
2012-02-02 12:40:47 +00:00
|
|
|
guint prop_id,
|
|
|
|
const GValue *value,
|
|
|
|
GParamSpec *pspec)
|
2012-01-20 14:10:35 +00:00
|
|
|
{
|
2012-02-01 12:34:08 +00:00
|
|
|
SecretCollection *self = SECRET_COLLECTION (obj);
|
2012-01-20 14:10:35 +00:00
|
|
|
|
|
|
|
switch (prop_id) {
|
2012-01-23 16:20:18 +00:00
|
|
|
case PROP_SERVICE:
|
2012-07-05 21:14:50 +00:00
|
|
|
collection_take_service (self, g_value_dup_object (value));
|
2012-01-23 16:20:18 +00:00
|
|
|
break;
|
2012-07-05 19:26:20 +00:00
|
|
|
case PROP_FLAGS:
|
|
|
|
self->pv->init_flags = g_value_get_flags (value);
|
|
|
|
break;
|
2012-01-20 14:10:35 +00:00
|
|
|
case PROP_LABEL:
|
2012-02-01 12:34:08 +00:00
|
|
|
secret_collection_set_label (self, g_value_get_string (value),
|
2012-02-02 12:40:47 +00:00
|
|
|
self->pv->cancellable, on_set_label,
|
|
|
|
g_object_ref (self));
|
2012-01-20 14:10:35 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (obj, prop_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2012-02-01 12:34:08 +00:00
|
|
|
secret_collection_get_property (GObject *obj,
|
2012-02-02 12:40:47 +00:00
|
|
|
guint prop_id,
|
|
|
|
GValue *value,
|
|
|
|
GParamSpec *pspec)
|
2012-01-20 14:10:35 +00:00
|
|
|
{
|
2012-02-01 12:34:08 +00:00
|
|
|
SecretCollection *self = SECRET_COLLECTION (obj);
|
2012-01-20 14:10:35 +00:00
|
|
|
|
|
|
|
switch (prop_id) {
|
2012-01-23 16:20:18 +00:00
|
|
|
case PROP_SERVICE:
|
|
|
|
g_value_set_object (value, self->pv->service);
|
|
|
|
break;
|
2012-07-05 19:26:20 +00:00
|
|
|
case PROP_FLAGS:
|
|
|
|
g_value_set_flags (value, secret_collection_get_flags (self));
|
|
|
|
break;
|
2012-01-20 14:10:35 +00:00
|
|
|
case PROP_ITEMS:
|
2012-02-01 12:34:08 +00:00
|
|
|
g_value_take_boxed (value, secret_collection_get_items (self));
|
2012-01-20 14:10:35 +00:00
|
|
|
break;
|
|
|
|
case PROP_LABEL:
|
2012-02-01 12:34:08 +00:00
|
|
|
g_value_take_string (value, secret_collection_get_label (self));
|
2012-01-20 14:10:35 +00:00
|
|
|
break;
|
|
|
|
case PROP_LOCKED:
|
2012-02-01 12:34:08 +00:00
|
|
|
g_value_set_boolean (value, secret_collection_get_locked (self));
|
2012-01-20 14:10:35 +00:00
|
|
|
break;
|
|
|
|
case PROP_CREATED:
|
2012-02-01 12:34:08 +00:00
|
|
|
g_value_set_uint64 (value, secret_collection_get_created (self));
|
2012-01-20 14:10:35 +00:00
|
|
|
break;
|
|
|
|
case PROP_MODIFIED:
|
2012-02-01 12:34:08 +00:00
|
|
|
g_value_set_uint64 (value, secret_collection_get_modified (self));
|
2012-01-20 14:10:35 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (obj, prop_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2012-02-01 12:34:08 +00:00
|
|
|
secret_collection_dispose (GObject *obj)
|
2012-01-20 14:10:35 +00:00
|
|
|
{
|
2012-02-01 12:34:08 +00:00
|
|
|
SecretCollection *self = SECRET_COLLECTION (obj);
|
2012-01-20 14:10:35 +00:00
|
|
|
|
|
|
|
g_cancellable_cancel (self->pv->cancellable);
|
|
|
|
|
2012-02-01 12:34:08 +00:00
|
|
|
G_OBJECT_CLASS (secret_collection_parent_class)->dispose (obj);
|
2012-01-20 14:10:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2012-02-01 12:34:08 +00:00
|
|
|
secret_collection_finalize (GObject *obj)
|
2012-01-20 14:10:35 +00:00
|
|
|
{
|
2012-02-01 12:34:08 +00:00
|
|
|
SecretCollection *self = SECRET_COLLECTION (obj);
|
2012-01-20 14:10:35 +00:00
|
|
|
|
2012-01-23 16:20:18 +00:00
|
|
|
if (self->pv->service)
|
|
|
|
g_object_remove_weak_pointer (G_OBJECT (self->pv->service),
|
|
|
|
(gpointer *)&self->pv->service);
|
|
|
|
|
2012-01-20 14:10:35 +00:00
|
|
|
g_mutex_clear (&self->pv->mutex);
|
|
|
|
g_hash_table_destroy (self->pv->items);
|
|
|
|
g_object_unref (self->pv->cancellable);
|
|
|
|
|
2012-02-01 12:34:08 +00:00
|
|
|
G_OBJECT_CLASS (secret_collection_parent_class)->finalize (obj);
|
2012-01-20 14:10:35 +00:00
|
|
|
}
|
|
|
|
|
2012-02-01 12:34:08 +00:00
|
|
|
static SecretItem *
|
|
|
|
collection_lookup_item (SecretCollection *self,
|
2012-01-25 13:26:52 +00:00
|
|
|
const gchar *path)
|
2012-01-20 14:10:35 +00:00
|
|
|
{
|
2012-02-01 12:34:08 +00:00
|
|
|
SecretItem *item = NULL;
|
2012-01-20 14:10:35 +00:00
|
|
|
|
2012-01-25 13:26:52 +00:00
|
|
|
g_mutex_lock (&self->pv->mutex);
|
2012-01-20 14:10:35 +00:00
|
|
|
|
2012-01-25 13:26:52 +00:00
|
|
|
item = g_hash_table_lookup (self->pv->items, path);
|
|
|
|
if (item != NULL)
|
|
|
|
g_object_ref (item);
|
|
|
|
|
|
|
|
g_mutex_unlock (&self->pv->mutex);
|
2012-01-20 14:10:35 +00:00
|
|
|
|
2012-01-25 13:26:52 +00:00
|
|
|
return item;
|
2012-01-20 14:10:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2012-02-01 12:34:08 +00:00
|
|
|
collection_update_items (SecretCollection *self,
|
2012-01-25 13:26:52 +00:00
|
|
|
GHashTable *items)
|
2012-01-20 14:10:35 +00:00
|
|
|
{
|
2012-01-25 13:26:52 +00:00
|
|
|
GHashTable *previous;
|
2012-01-20 14:10:35 +00:00
|
|
|
|
2012-01-25 13:26:52 +00:00
|
|
|
g_hash_table_ref (items);
|
2012-01-20 14:10:35 +00:00
|
|
|
|
|
|
|
g_mutex_lock (&self->pv->mutex);
|
2012-01-25 13:26:52 +00:00
|
|
|
previous = self->pv->items;
|
|
|
|
self->pv->items = items;
|
2012-01-20 14:10:35 +00:00
|
|
|
g_mutex_unlock (&self->pv->mutex);
|
|
|
|
|
2012-01-25 13:26:52 +00:00
|
|
|
g_hash_table_unref (previous);
|
2012-06-27 14:33:22 +00:00
|
|
|
g_object_notify (G_OBJECT (self), "items");
|
2012-01-25 13:26:52 +00:00
|
|
|
}
|
2012-01-20 14:10:35 +00:00
|
|
|
|
|
|
|
static void
|
2012-02-01 12:34:08 +00:00
|
|
|
handle_property_changed (SecretCollection *self,
|
2012-01-20 14:10:35 +00:00
|
|
|
const gchar *property_name,
|
|
|
|
GVariant *value)
|
|
|
|
{
|
2012-07-05 19:26:20 +00:00
|
|
|
gboolean perform;
|
|
|
|
|
|
|
|
if (g_str_equal (property_name, "Label")) {
|
2012-01-20 14:10:35 +00:00
|
|
|
g_object_notify (G_OBJECT (self), "label");
|
|
|
|
|
2012-07-05 19:26:20 +00:00
|
|
|
} else if (g_str_equal (property_name, "Locked")) {
|
2012-01-20 14:10:35 +00:00
|
|
|
g_object_notify (G_OBJECT (self), "locked");
|
|
|
|
|
2012-07-05 19:26:20 +00:00
|
|
|
} else if (g_str_equal (property_name, "Created")) {
|
2012-01-20 14:10:35 +00:00
|
|
|
g_object_notify (G_OBJECT (self), "created");
|
|
|
|
|
2012-07-05 19:26:20 +00:00
|
|
|
} else if (g_str_equal (property_name, "Modified")) {
|
2012-01-20 14:10:35 +00:00
|
|
|
g_object_notify (G_OBJECT (self), "modified");
|
|
|
|
|
2012-07-05 19:26:20 +00:00
|
|
|
} else if (g_str_equal (property_name, "Items") && !self->pv->constructing) {
|
|
|
|
g_mutex_lock (&self->pv->mutex);
|
|
|
|
perform = self->pv->items != NULL;
|
|
|
|
g_mutex_unlock (&self->pv->mutex);
|
|
|
|
|
|
|
|
if (perform)
|
|
|
|
secret_collection_load_items (self, self->pv->cancellable, NULL, NULL);
|
|
|
|
}
|
2012-01-20 14:10:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2012-02-01 12:34:08 +00:00
|
|
|
secret_collection_properties_changed (GDBusProxy *proxy,
|
2012-02-02 12:40:47 +00:00
|
|
|
GVariant *changed_properties,
|
|
|
|
const gchar* const *invalidated_properties)
|
2012-01-20 14:10:35 +00:00
|
|
|
{
|
2012-02-01 12:34:08 +00:00
|
|
|
SecretCollection *self = SECRET_COLLECTION (proxy);
|
2012-01-20 14:10:35 +00:00
|
|
|
gchar *property_name;
|
|
|
|
GVariantIter iter;
|
|
|
|
GVariant *value;
|
|
|
|
|
|
|
|
g_object_freeze_notify (G_OBJECT (self));
|
|
|
|
|
|
|
|
g_variant_iter_init (&iter, changed_properties);
|
|
|
|
while (g_variant_iter_loop (&iter, "{sv}", &property_name, &value))
|
|
|
|
handle_property_changed (self, property_name, value);
|
|
|
|
|
|
|
|
g_object_thaw_notify (G_OBJECT (self));
|
|
|
|
}
|
|
|
|
|
2012-02-19 12:09:07 +00:00
|
|
|
static void
|
|
|
|
secret_collection_signal (GDBusProxy *proxy,
|
|
|
|
const gchar *sender_name,
|
|
|
|
const gchar *signal_name,
|
|
|
|
GVariant *parameters)
|
|
|
|
{
|
|
|
|
SecretCollection *self = SECRET_COLLECTION (proxy);
|
|
|
|
SecretItem *item;
|
|
|
|
const gchar *item_path;
|
|
|
|
GVariantBuilder builder;
|
|
|
|
gboolean found = FALSE;
|
|
|
|
GVariantIter iter;
|
|
|
|
GVariant *value;
|
|
|
|
GVariant *paths;
|
|
|
|
GVariant *path;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Remember that these signals come from a time before PropertiesChanged.
|
|
|
|
* We support them because they're in the spec, and ksecretservice uses them.
|
|
|
|
*/
|
|
|
|
|
|
|
|
paths = g_dbus_proxy_get_cached_property (G_DBUS_PROXY (self), "Items");
|
|
|
|
|
|
|
|
/* A new collection was added, add it to the Collections property */
|
|
|
|
if (g_str_equal (signal_name, SECRET_SIGNAL_ITEM_CREATED)) {
|
2012-06-27 14:36:45 +00:00
|
|
|
g_variant_get (parameters, "(@o)", &value);
|
2012-02-19 12:09:07 +00:00
|
|
|
g_variant_builder_init (&builder, G_VARIANT_TYPE ("ao"));
|
|
|
|
g_variant_iter_init (&iter, paths);
|
|
|
|
while ((path = g_variant_iter_next_value (&iter)) != NULL) {
|
|
|
|
if (g_variant_equal (path, value)) {
|
|
|
|
found = TRUE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
g_variant_builder_add_value (&builder, path);
|
|
|
|
g_variant_unref (path);
|
|
|
|
}
|
|
|
|
if (!found) {
|
|
|
|
g_variant_builder_add_value (&builder, value);
|
|
|
|
handle_property_changed (self, "Items", g_variant_builder_end (&builder));
|
|
|
|
}
|
|
|
|
g_variant_builder_clear (&builder);
|
|
|
|
g_variant_unref (value);
|
|
|
|
|
|
|
|
/* A collection was deleted, remove it from the Collections property */
|
|
|
|
} else if (g_str_equal (signal_name, SECRET_SIGNAL_ITEM_DELETED)) {
|
2012-06-27 14:36:45 +00:00
|
|
|
g_variant_get (parameters, "(@o)", &value);
|
2012-02-19 12:09:07 +00:00
|
|
|
g_variant_builder_init (&builder, G_VARIANT_TYPE ("ao"));
|
|
|
|
g_variant_iter_init (&iter, paths);
|
|
|
|
while ((path = g_variant_iter_next_value (&iter)) != NULL) {
|
|
|
|
if (g_variant_equal (path, value))
|
|
|
|
found = TRUE;
|
|
|
|
else
|
|
|
|
g_variant_builder_add_value (&builder, path);
|
|
|
|
g_variant_unref (path);
|
|
|
|
}
|
|
|
|
if (found)
|
|
|
|
handle_property_changed (self, "Items", g_variant_builder_end (&builder));
|
|
|
|
g_variant_unref (value);
|
|
|
|
|
|
|
|
/* The collection changed, update it */
|
|
|
|
} else if (g_str_equal (signal_name, SECRET_SIGNAL_ITEM_CHANGED)) {
|
2012-06-27 14:36:45 +00:00
|
|
|
g_variant_get (parameters, "(&o)", &item_path);
|
2012-02-19 12:09:07 +00:00
|
|
|
|
|
|
|
g_mutex_lock (&self->pv->mutex);
|
|
|
|
|
|
|
|
if (self->pv->items)
|
|
|
|
item = g_hash_table_lookup (self->pv->items, item_path);
|
|
|
|
else
|
|
|
|
item = NULL;
|
|
|
|
if (item)
|
|
|
|
g_object_ref (item);
|
|
|
|
|
|
|
|
g_mutex_unlock (&self->pv->mutex);
|
|
|
|
|
2012-06-27 14:38:35 +00:00
|
|
|
if (item) {
|
|
|
|
secret_item_refresh (item);
|
|
|
|
g_object_unref (item);
|
|
|
|
}
|
2012-02-19 12:09:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
g_variant_unref (paths);
|
|
|
|
}
|
|
|
|
|
2012-01-20 14:10:35 +00:00
|
|
|
static void
|
2012-02-01 12:34:08 +00:00
|
|
|
secret_collection_class_init (SecretCollectionClass *klass)
|
2012-01-20 14:10:35 +00:00
|
|
|
{
|
|
|
|
GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
|
|
|
|
GDBusProxyClass *proxy_class = G_DBUS_PROXY_CLASS (klass);
|
|
|
|
|
2012-02-01 12:34:08 +00:00
|
|
|
gobject_class->get_property = secret_collection_get_property;
|
|
|
|
gobject_class->set_property = secret_collection_set_property;
|
|
|
|
gobject_class->dispose = secret_collection_dispose;
|
|
|
|
gobject_class->finalize = secret_collection_finalize;
|
2012-01-20 14:10:35 +00:00
|
|
|
|
2012-02-01 12:34:08 +00:00
|
|
|
proxy_class->g_properties_changed = secret_collection_properties_changed;
|
2012-02-19 12:09:07 +00:00
|
|
|
proxy_class->g_signal = secret_collection_signal;
|
2012-01-20 14:10:35 +00:00
|
|
|
|
2012-02-02 13:59:59 +00:00
|
|
|
/**
|
|
|
|
* SecretCollection:service:
|
|
|
|
*
|
|
|
|
* The #SecretService object that this collection is associated with and
|
2012-03-24 12:31:14 +00:00
|
|
|
* uses to interact with the actual D-Bus Secret Service.
|
2012-02-02 13:59:59 +00:00
|
|
|
*/
|
2012-01-23 16:20:18 +00:00
|
|
|
g_object_class_install_property (gobject_class, PROP_SERVICE,
|
|
|
|
g_param_spec_object ("service", "Service", "Secret Service",
|
2012-02-01 12:34:08 +00:00
|
|
|
SECRET_TYPE_SERVICE, G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS));
|
2012-01-23 16:20:18 +00:00
|
|
|
|
2012-07-05 19:26:20 +00:00
|
|
|
/**
|
|
|
|
* SecretCollection:flags:
|
|
|
|
*
|
|
|
|
* A set of flags describing which parts of the secret collection have
|
|
|
|
* been initialized.
|
|
|
|
*/
|
|
|
|
g_object_class_install_property (gobject_class, PROP_FLAGS,
|
|
|
|
g_param_spec_flags ("flags", "Flags", "Collection flags",
|
|
|
|
secret_collection_flags_get_type (), SECRET_COLLECTION_NONE,
|
|
|
|
G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS));
|
|
|
|
|
2012-02-02 13:59:59 +00:00
|
|
|
/**
|
|
|
|
* SecretCollection:items:
|
|
|
|
*
|
|
|
|
* A list of #SecretItem objects representing the items that are in
|
|
|
|
* this collection. This list will be empty if the collection is locked.
|
|
|
|
*/
|
2012-01-20 14:10:35 +00:00
|
|
|
g_object_class_install_property (gobject_class, PROP_ITEMS,
|
|
|
|
g_param_spec_boxed ("items", "Items", "Items in collection",
|
2012-02-01 12:34:08 +00:00
|
|
|
_secret_list_get_type (), G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
|
2012-01-20 14:10:35 +00:00
|
|
|
|
2012-02-02 13:59:59 +00:00
|
|
|
/**
|
|
|
|
* SecretCollection:label:
|
|
|
|
*
|
|
|
|
* The human readable label for the collection.
|
|
|
|
*
|
|
|
|
* Setting this property will result in the label of the collection being
|
|
|
|
* set asynchronously. To properly track the changing of the label use the
|
|
|
|
* secret_collection_set_label() function.
|
|
|
|
*/
|
2012-01-20 14:10:35 +00:00
|
|
|
g_object_class_install_property (gobject_class, PROP_LABEL,
|
|
|
|
g_param_spec_string ("label", "Label", "Item label",
|
2012-01-23 16:20:18 +00:00
|
|
|
NULL, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
2012-01-20 14:10:35 +00:00
|
|
|
|
2012-02-02 13:59:59 +00:00
|
|
|
/**
|
|
|
|
* SecretCollection:locked:
|
|
|
|
*
|
|
|
|
* Whether the collection is locked or not.
|
|
|
|
*
|
|
|
|
* To lock or unlock a collection use the secret_service_lock() or
|
|
|
|
* secret_service_unlock() functions.
|
|
|
|
*/
|
2012-01-20 14:10:35 +00:00
|
|
|
g_object_class_install_property (gobject_class, PROP_LOCKED,
|
|
|
|
g_param_spec_boolean ("locked", "Locked", "Item locked",
|
2012-01-23 16:20:18 +00:00
|
|
|
TRUE, G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
|
2012-01-20 14:10:35 +00:00
|
|
|
|
2012-02-02 13:59:59 +00:00
|
|
|
/**
|
|
|
|
* SecretCollection:created:
|
|
|
|
*
|
|
|
|
* The date and time (in seconds since the UNIX epoch) that this
|
|
|
|
* collection was created.
|
|
|
|
*/
|
2012-01-20 14:10:35 +00:00
|
|
|
g_object_class_install_property (gobject_class, PROP_CREATED,
|
|
|
|
g_param_spec_uint64 ("created", "Created", "Item creation date",
|
2012-01-23 16:20:18 +00:00
|
|
|
0UL, G_MAXUINT64, 0UL, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
2012-01-20 14:10:35 +00:00
|
|
|
|
2012-02-02 13:59:59 +00:00
|
|
|
/**
|
|
|
|
* SecretCollection:modified:
|
|
|
|
*
|
|
|
|
* The date and time (in seconds since the UNIX epoch) that this
|
|
|
|
* collection was last modified.
|
|
|
|
*/
|
2012-01-20 14:10:35 +00:00
|
|
|
g_object_class_install_property (gobject_class, PROP_MODIFIED,
|
|
|
|
g_param_spec_uint64 ("modified", "Modified", "Item modified date",
|
2012-01-23 16:20:18 +00:00
|
|
|
0UL, G_MAXUINT64, 0UL, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
|
|
|
|
2012-02-01 12:34:08 +00:00
|
|
|
g_type_class_add_private (gobject_class, sizeof (SecretCollectionPrivate));
|
2012-01-20 14:10:35 +00:00
|
|
|
}
|
|
|
|
|
2012-01-25 13:26:52 +00:00
|
|
|
static gboolean
|
2012-02-01 12:34:08 +00:00
|
|
|
secret_collection_initable_init (GInitable *initable,
|
2012-02-02 12:40:47 +00:00
|
|
|
GCancellable *cancellable,
|
|
|
|
GError **error)
|
2012-01-20 14:10:35 +00:00
|
|
|
{
|
2012-02-01 12:34:08 +00:00
|
|
|
SecretCollection *self;
|
2012-07-05 21:14:50 +00:00
|
|
|
SecretService *service;
|
2012-01-23 16:20:18 +00:00
|
|
|
GDBusProxy *proxy;
|
2012-01-20 14:10:35 +00:00
|
|
|
|
2012-02-01 12:34:08 +00:00
|
|
|
if (!secret_collection_initable_parent_iface->init (initable, cancellable, error))
|
2012-01-25 13:26:52 +00:00
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
proxy = G_DBUS_PROXY (initable);
|
2012-01-20 14:10:35 +00:00
|
|
|
|
2012-02-01 12:34:08 +00:00
|
|
|
if (!_secret_util_have_cached_properties (proxy)) {
|
2012-01-25 13:26:52 +00:00
|
|
|
g_set_error (error, G_DBUS_ERROR, G_DBUS_ERROR_UNKNOWN_METHOD,
|
|
|
|
"No such secret collection at path: %s",
|
|
|
|
g_dbus_proxy_get_object_path (proxy));
|
|
|
|
return FALSE;
|
2012-01-23 16:20:18 +00:00
|
|
|
}
|
|
|
|
|
2012-02-01 12:34:08 +00:00
|
|
|
self = SECRET_COLLECTION (initable);
|
2012-01-23 16:20:18 +00:00
|
|
|
|
2012-07-05 21:14:50 +00:00
|
|
|
if (self->pv->service == NULL) {
|
|
|
|
service = secret_service_get_sync (SECRET_SERVICE_NONE, cancellable, error);
|
|
|
|
if (service == NULL)
|
|
|
|
return FALSE;
|
|
|
|
else
|
|
|
|
collection_take_service (self, service);
|
|
|
|
}
|
|
|
|
|
2012-07-05 19:26:20 +00:00
|
|
|
if (self->pv->init_flags & SECRET_COLLECTION_LOAD_ITEMS) {
|
|
|
|
if (!secret_collection_load_items_sync (self, cancellable, error))
|
|
|
|
return FALSE;
|
|
|
|
}
|
2012-01-20 14:10:35 +00:00
|
|
|
|
2012-06-27 14:39:37 +00:00
|
|
|
self->pv->constructing = FALSE;
|
2012-01-25 13:26:52 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2012-02-01 12:34:08 +00:00
|
|
|
secret_collection_initable_iface (GInitableIface *iface)
|
2012-01-25 13:26:52 +00:00
|
|
|
{
|
2012-02-01 12:34:08 +00:00
|
|
|
secret_collection_initable_parent_iface = g_type_interface_peek_parent (iface);
|
2012-01-25 13:26:52 +00:00
|
|
|
|
2012-02-01 12:34:08 +00:00
|
|
|
iface->init = secret_collection_initable_init;
|
2012-01-25 13:26:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
GCancellable *cancellable;
|
|
|
|
} InitClosure;
|
|
|
|
|
|
|
|
static void
|
|
|
|
init_closure_free (gpointer data)
|
|
|
|
{
|
|
|
|
InitClosure *closure = data;
|
|
|
|
g_clear_object (&closure->cancellable);
|
|
|
|
g_slice_free (InitClosure, closure);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
on_init_items (GObject *source,
|
|
|
|
GAsyncResult *result,
|
|
|
|
gpointer user_data)
|
|
|
|
{
|
|
|
|
GSimpleAsyncResult *res = G_SIMPLE_ASYNC_RESULT (user_data);
|
2012-02-01 12:34:08 +00:00
|
|
|
SecretCollection *self = SECRET_COLLECTION (source);
|
2012-01-25 13:26:52 +00:00
|
|
|
GError *error = NULL;
|
|
|
|
|
2012-07-05 19:26:20 +00:00
|
|
|
if (!secret_collection_load_items_finish (self, result, &error))
|
2012-01-25 13:26:52 +00:00
|
|
|
g_simple_async_result_take_error (res, error);
|
|
|
|
|
|
|
|
g_simple_async_result_complete (res);
|
|
|
|
g_object_unref (res);
|
|
|
|
}
|
|
|
|
|
2012-07-05 21:14:50 +00:00
|
|
|
static void
|
|
|
|
collection_ensure_for_flags_async (SecretCollection *self,
|
|
|
|
SecretCollectionFlags flags,
|
|
|
|
GSimpleAsyncResult *async)
|
|
|
|
{
|
|
|
|
InitClosure *init = g_simple_async_result_get_op_res_gpointer (async);
|
|
|
|
|
|
|
|
if (flags & SECRET_COLLECTION_LOAD_ITEMS)
|
|
|
|
secret_collection_load_items (self, init->cancellable,
|
|
|
|
on_init_items, g_object_ref (async));
|
|
|
|
|
|
|
|
else
|
|
|
|
g_simple_async_result_complete (async);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
on_init_service (GObject *source,
|
|
|
|
GAsyncResult *result,
|
|
|
|
gpointer user_data)
|
|
|
|
{
|
|
|
|
GSimpleAsyncResult *async = G_SIMPLE_ASYNC_RESULT (user_data);
|
|
|
|
SecretCollection *self = SECRET_COLLECTION (g_async_result_get_source_object (user_data));
|
|
|
|
SecretService *service;
|
|
|
|
GError *error = NULL;
|
|
|
|
|
|
|
|
service = secret_service_get_finish (result, &error);
|
|
|
|
if (error == NULL) {
|
|
|
|
collection_take_service (self, service);
|
|
|
|
collection_ensure_for_flags_async (self, self->pv->init_flags, async);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
g_simple_async_result_take_error (async, error);
|
|
|
|
g_simple_async_result_complete (async);
|
|
|
|
}
|
|
|
|
|
|
|
|
g_object_unref (self);
|
|
|
|
g_object_unref (async);
|
|
|
|
}
|
|
|
|
|
2012-01-25 13:26:52 +00:00
|
|
|
static void
|
|
|
|
on_init_base (GObject *source,
|
|
|
|
GAsyncResult *result,
|
|
|
|
gpointer user_data)
|
|
|
|
{
|
|
|
|
GSimpleAsyncResult *res = G_SIMPLE_ASYNC_RESULT (user_data);
|
2012-02-01 12:34:08 +00:00
|
|
|
SecretCollection *self = SECRET_COLLECTION (source);
|
2012-07-05 21:14:50 +00:00
|
|
|
InitClosure *init = g_simple_async_result_get_op_res_gpointer (res);
|
2012-01-25 13:26:52 +00:00
|
|
|
GDBusProxy *proxy = G_DBUS_PROXY (self);
|
|
|
|
GError *error = NULL;
|
|
|
|
|
2012-02-01 12:34:08 +00:00
|
|
|
if (!secret_collection_async_initable_parent_iface->init_finish (G_ASYNC_INITABLE (self),
|
2012-02-02 12:40:47 +00:00
|
|
|
result, &error)) {
|
2012-01-20 14:10:35 +00:00
|
|
|
g_simple_async_result_take_error (res, error);
|
|
|
|
g_simple_async_result_complete (res);
|
2012-01-25 13:26:52 +00:00
|
|
|
|
2012-02-01 12:34:08 +00:00
|
|
|
} else if (!_secret_util_have_cached_properties (proxy)) {
|
2012-01-25 13:26:52 +00:00
|
|
|
g_simple_async_result_set_error (res, G_DBUS_ERROR, G_DBUS_ERROR_UNKNOWN_METHOD,
|
|
|
|
"No such secret collection at path: %s",
|
|
|
|
g_dbus_proxy_get_object_path (proxy));
|
|
|
|
g_simple_async_result_complete (res);
|
|
|
|
|
2012-07-05 21:14:50 +00:00
|
|
|
} else if (self->pv->service == NULL) {
|
|
|
|
secret_service_get (SECRET_SERVICE_NONE, init->cancellable,
|
|
|
|
on_init_service, g_object_ref (res));
|
2012-07-05 19:26:20 +00:00
|
|
|
|
2012-01-25 13:26:52 +00:00
|
|
|
} else {
|
2012-07-05 21:14:50 +00:00
|
|
|
collection_ensure_for_flags_async (self, self->pv->init_flags, res);
|
2012-01-20 14:10:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
g_object_unref (res);
|
|
|
|
}
|
|
|
|
|
2012-01-25 13:26:52 +00:00
|
|
|
static void
|
2012-02-01 12:34:08 +00:00
|
|
|
secret_collection_async_initable_init_async (GAsyncInitable *initable,
|
2012-02-02 12:40:47 +00:00
|
|
|
int io_priority,
|
|
|
|
GCancellable *cancellable,
|
|
|
|
GAsyncReadyCallback callback,
|
|
|
|
gpointer user_data)
|
2012-01-25 13:26:52 +00:00
|
|
|
{
|
|
|
|
GSimpleAsyncResult *res;
|
|
|
|
InitClosure *closure;
|
|
|
|
|
|
|
|
res = g_simple_async_result_new (G_OBJECT (initable), callback, user_data,
|
2012-02-01 12:34:08 +00:00
|
|
|
secret_collection_async_initable_init_async);
|
2012-01-25 13:26:52 +00:00
|
|
|
closure = g_slice_new0 (InitClosure);
|
|
|
|
closure->cancellable = cancellable ? g_object_ref (cancellable) : NULL;
|
|
|
|
g_simple_async_result_set_op_res_gpointer (res, closure, init_closure_free);
|
|
|
|
|
2012-02-01 12:34:08 +00:00
|
|
|
secret_collection_async_initable_parent_iface->init_async (initable, io_priority,
|
2012-02-02 12:40:47 +00:00
|
|
|
cancellable,
|
|
|
|
on_init_base,
|
|
|
|
g_object_ref (res));
|
2012-01-25 13:26:52 +00:00
|
|
|
|
|
|
|
g_object_unref (res);
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2012-02-01 12:34:08 +00:00
|
|
|
secret_collection_async_initable_init_finish (GAsyncInitable *initable,
|
2012-02-02 12:40:47 +00:00
|
|
|
GAsyncResult *result,
|
|
|
|
GError **error)
|
2012-01-25 13:26:52 +00:00
|
|
|
{
|
2012-06-27 14:39:37 +00:00
|
|
|
SecretCollection *self = SECRET_COLLECTION (initable);
|
|
|
|
|
2012-01-25 13:26:52 +00:00
|
|
|
g_return_val_if_fail (g_simple_async_result_is_valid (result, G_OBJECT (initable),
|
2012-02-01 12:34:08 +00:00
|
|
|
secret_collection_async_initable_init_async), FALSE);
|
2012-01-25 13:26:52 +00:00
|
|
|
|
|
|
|
if (g_simple_async_result_propagate_error (G_SIMPLE_ASYNC_RESULT (result), error))
|
|
|
|
return FALSE;
|
|
|
|
|
2012-06-27 14:39:37 +00:00
|
|
|
self->pv->constructing = FALSE;
|
2012-01-25 13:26:52 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2012-02-01 12:34:08 +00:00
|
|
|
secret_collection_async_initable_iface (GAsyncInitableIface *iface)
|
2012-01-25 13:26:52 +00:00
|
|
|
{
|
2012-02-01 12:34:08 +00:00
|
|
|
secret_collection_async_initable_parent_iface = g_type_interface_peek_parent (iface);
|
2012-01-25 13:26:52 +00:00
|
|
|
|
2012-02-01 12:34:08 +00:00
|
|
|
iface->init_async = secret_collection_async_initable_init_async;
|
|
|
|
iface->init_finish = secret_collection_async_initable_init_finish;
|
2012-01-25 13:26:52 +00:00
|
|
|
}
|
|
|
|
|
2012-01-31 19:40:44 +00:00
|
|
|
/**
|
2012-02-01 12:34:08 +00:00
|
|
|
* secret_collection_new:
|
2012-07-05 21:14:50 +00:00
|
|
|
* @service: (allow-none): a secret service object
|
2012-03-24 12:31:14 +00:00
|
|
|
* @collection_path: the D-Bus path of the collection
|
2012-07-05 19:26:20 +00:00
|
|
|
* @flags: options for the collection initialization
|
2012-01-31 19:40:44 +00:00
|
|
|
* @cancellable: optional cancellation object
|
|
|
|
* @callback: called when the operation completes
|
|
|
|
* @user_data: data to be passed to the callback
|
|
|
|
*
|
|
|
|
* Get a new collection proxy for a collection in the secret service.
|
|
|
|
*
|
2012-07-05 21:14:50 +00:00
|
|
|
* If @service is NULL, then secret_service_get() will be called to get
|
|
|
|
* the default #SecretService proxy.
|
|
|
|
*
|
2012-01-31 19:40:44 +00:00
|
|
|
* This method will return immediately and complete asynchronously.
|
|
|
|
*/
|
2012-01-20 14:10:35 +00:00
|
|
|
void
|
2012-02-01 12:34:08 +00:00
|
|
|
secret_collection_new (SecretService *service,
|
2012-02-02 12:40:47 +00:00
|
|
|
const gchar *collection_path,
|
2012-07-05 19:26:20 +00:00
|
|
|
SecretCollectionFlags flags,
|
2012-02-02 12:40:47 +00:00
|
|
|
GCancellable *cancellable,
|
|
|
|
GAsyncReadyCallback callback,
|
|
|
|
gpointer user_data)
|
2012-01-20 14:10:35 +00:00
|
|
|
{
|
|
|
|
GDBusProxy *proxy;
|
|
|
|
|
2012-07-05 21:14:50 +00:00
|
|
|
g_return_if_fail (service == NULL || SECRET_IS_SERVICE (service));
|
2012-01-20 14:10:35 +00:00
|
|
|
g_return_if_fail (collection_path != NULL);
|
|
|
|
g_return_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable));
|
|
|
|
|
|
|
|
proxy = G_DBUS_PROXY (service);
|
|
|
|
|
2012-02-01 12:34:08 +00:00
|
|
|
g_async_initable_new_async (SECRET_SERVICE_GET_CLASS (service)->collection_gtype,
|
2012-01-25 13:26:52 +00:00
|
|
|
G_PRIORITY_DEFAULT, cancellable, callback, user_data,
|
2012-01-20 14:10:35 +00:00
|
|
|
"g-flags", G_DBUS_CALL_FLAGS_NONE,
|
2012-02-01 12:34:08 +00:00
|
|
|
"g-interface-info", _secret_gen_collection_interface_info (),
|
2012-01-20 14:10:35 +00:00
|
|
|
"g-name", g_dbus_proxy_get_name (proxy),
|
|
|
|
"g-connection", g_dbus_proxy_get_connection (proxy),
|
|
|
|
"g-object-path", collection_path,
|
2012-02-01 12:34:08 +00:00
|
|
|
"g-interface-name", SECRET_COLLECTION_INTERFACE,
|
2012-01-23 16:20:18 +00:00
|
|
|
"service", service,
|
2012-07-05 19:26:20 +00:00
|
|
|
"flags", flags,
|
2012-01-20 14:10:35 +00:00
|
|
|
NULL);
|
|
|
|
}
|
|
|
|
|
2012-01-31 19:40:44 +00:00
|
|
|
/**
|
2012-02-01 12:34:08 +00:00
|
|
|
* secret_collection_new_finish:
|
2012-01-31 19:40:44 +00:00
|
|
|
* @result: the asynchronous result passed to the callback
|
|
|
|
* @error: location to place an error on failure
|
|
|
|
*
|
|
|
|
* Finish asynchronous operation to get a new collection proxy for a
|
|
|
|
* collection in the secret service.
|
|
|
|
*
|
|
|
|
* Returns: (transfer full): the new collection, which should be unreferenced
|
|
|
|
* with g_object_unref()
|
|
|
|
*/
|
2012-02-01 12:34:08 +00:00
|
|
|
SecretCollection *
|
|
|
|
secret_collection_new_finish (GAsyncResult *result,
|
2012-02-02 12:40:47 +00:00
|
|
|
GError **error)
|
2012-01-20 14:10:35 +00:00
|
|
|
{
|
2012-01-25 13:26:52 +00:00
|
|
|
GObject *source_object;
|
|
|
|
GObject *object;
|
2012-01-20 14:10:35 +00:00
|
|
|
|
2012-01-25 13:26:52 +00:00
|
|
|
g_return_val_if_fail (G_IS_ASYNC_RESULT (result), NULL);
|
2012-01-23 16:20:18 +00:00
|
|
|
g_return_val_if_fail (error == NULL || *error == NULL, NULL);
|
2012-01-20 14:10:35 +00:00
|
|
|
|
2012-01-25 13:26:52 +00:00
|
|
|
source_object = g_async_result_get_source_object (result);
|
|
|
|
object = g_async_initable_new_finish (G_ASYNC_INITABLE (source_object),
|
|
|
|
result, error);
|
|
|
|
g_object_unref (source_object);
|
2012-01-23 16:20:18 +00:00
|
|
|
|
2012-01-25 13:26:52 +00:00
|
|
|
if (object == NULL)
|
2012-01-20 14:10:35 +00:00
|
|
|
return NULL;
|
2012-01-23 16:20:18 +00:00
|
|
|
|
2012-02-01 12:34:08 +00:00
|
|
|
return SECRET_COLLECTION (object);
|
2012-01-20 14:10:35 +00:00
|
|
|
}
|
|
|
|
|
2012-01-31 19:40:44 +00:00
|
|
|
/**
|
2012-02-01 12:34:08 +00:00
|
|
|
* secret_collection_new_sync:
|
2012-07-05 21:14:50 +00:00
|
|
|
* @service: (allow-none): a secret service object
|
2012-03-24 12:31:14 +00:00
|
|
|
* @collection_path: the D-Bus path of the collection
|
2012-07-05 19:26:20 +00:00
|
|
|
* @flags: options for the collection initialization
|
2012-01-31 19:40:44 +00:00
|
|
|
* @cancellable: optional cancellation object
|
|
|
|
* @error: location to place an error on failure
|
|
|
|
*
|
|
|
|
* Get a new collection proxy for a collection in the secret service.
|
|
|
|
*
|
2012-07-05 21:14:50 +00:00
|
|
|
* If @service is NULL, then secret_service_get_sync() will be called to get
|
|
|
|
* the default #SecretService proxy.
|
|
|
|
*
|
2012-02-02 12:40:47 +00:00
|
|
|
* This method may block indefinitely and should not be used in user interface
|
|
|
|
* threads.
|
2012-01-31 19:40:44 +00:00
|
|
|
*
|
|
|
|
* Returns: (transfer full): the new collection, which should be unreferenced
|
|
|
|
* with g_object_unref()
|
|
|
|
*/
|
2012-02-01 12:34:08 +00:00
|
|
|
SecretCollection *
|
|
|
|
secret_collection_new_sync (SecretService *service,
|
2012-02-02 12:40:47 +00:00
|
|
|
const gchar *collection_path,
|
2012-07-05 19:26:20 +00:00
|
|
|
SecretCollectionFlags flags,
|
2012-02-02 12:40:47 +00:00
|
|
|
GCancellable *cancellable,
|
|
|
|
GError **error)
|
2012-01-20 14:10:35 +00:00
|
|
|
{
|
2012-01-25 13:26:52 +00:00
|
|
|
GDBusProxy *proxy;
|
2012-01-20 14:10:35 +00:00
|
|
|
|
2012-07-05 21:14:50 +00:00
|
|
|
g_return_val_if_fail (service == NULL || SECRET_IS_SERVICE (service), NULL);
|
2012-01-20 14:10:35 +00:00
|
|
|
g_return_val_if_fail (collection_path != NULL, NULL);
|
|
|
|
g_return_val_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable), NULL);
|
|
|
|
g_return_val_if_fail (error == NULL || *error == NULL, NULL);
|
|
|
|
|
2012-01-25 13:26:52 +00:00
|
|
|
proxy = G_DBUS_PROXY (service);
|
2012-01-20 14:10:35 +00:00
|
|
|
|
2012-02-01 12:34:08 +00:00
|
|
|
return g_initable_new (SECRET_SERVICE_GET_CLASS (service)->collection_gtype,
|
2012-01-25 13:26:52 +00:00
|
|
|
cancellable, error,
|
|
|
|
"g-flags", G_DBUS_CALL_FLAGS_NONE,
|
2012-02-01 12:34:08 +00:00
|
|
|
"g-interface-info", _secret_gen_collection_interface_info (),
|
2012-01-25 13:26:52 +00:00
|
|
|
"g-name", g_dbus_proxy_get_name (proxy),
|
|
|
|
"g-connection", g_dbus_proxy_get_connection (proxy),
|
|
|
|
"g-object-path", collection_path,
|
2012-02-01 12:34:08 +00:00
|
|
|
"g-interface-name", SECRET_COLLECTION_INTERFACE,
|
2012-01-25 13:26:52 +00:00
|
|
|
"service", service,
|
2012-07-05 19:26:20 +00:00
|
|
|
"flags", flags,
|
2012-01-25 13:26:52 +00:00
|
|
|
NULL);
|
2012-01-20 14:10:35 +00:00
|
|
|
}
|
|
|
|
|
2012-07-05 19:26:20 +00:00
|
|
|
typedef struct {
|
|
|
|
GCancellable *cancellable;
|
|
|
|
GHashTable *items;
|
|
|
|
gint items_loading;
|
|
|
|
} ItemsClosure;
|
|
|
|
|
|
|
|
static void
|
|
|
|
items_closure_free (gpointer data)
|
|
|
|
{
|
|
|
|
ItemsClosure *closure = data;
|
|
|
|
g_clear_object (&closure->cancellable);
|
|
|
|
g_hash_table_unref (closure->items);
|
|
|
|
g_slice_free (ItemsClosure, closure);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
on_load_item (GObject *source,
|
|
|
|
GAsyncResult *result,
|
|
|
|
gpointer user_data)
|
|
|
|
{
|
|
|
|
GSimpleAsyncResult *res = G_SIMPLE_ASYNC_RESULT (user_data);
|
|
|
|
ItemsClosure *closure = g_simple_async_result_get_op_res_gpointer (res);
|
|
|
|
SecretCollection *self = SECRET_COLLECTION (g_async_result_get_source_object (user_data));
|
|
|
|
const gchar *path;
|
|
|
|
GError *error = NULL;
|
|
|
|
SecretItem *item;
|
|
|
|
|
|
|
|
closure->items_loading--;
|
|
|
|
|
|
|
|
item = secret_item_new_finish (result, &error);
|
|
|
|
|
|
|
|
if (error != NULL)
|
|
|
|
g_simple_async_result_take_error (res, error);
|
|
|
|
|
|
|
|
if (item != NULL) {
|
|
|
|
path = g_dbus_proxy_get_object_path (G_DBUS_PROXY (item));
|
|
|
|
g_hash_table_insert (closure->items, g_strdup (path), item);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (closure->items_loading == 0) {
|
|
|
|
collection_update_items (self, closure->items);
|
|
|
|
g_simple_async_result_complete_in_idle (res);
|
|
|
|
}
|
|
|
|
|
|
|
|
g_object_unref (self);
|
|
|
|
g_object_unref (res);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* secret_collection_load_items:
|
|
|
|
* @self: the secret collection
|
|
|
|
* @cancellable: optional cancellation object
|
|
|
|
* @callback: called when the operation completes
|
|
|
|
* @user_data: data to be passed to the callback
|
|
|
|
*
|
|
|
|
* Ensure that the #SecretCollection proxy has loaded all the items present
|
|
|
|
* in the Secret Service. This affects the result of
|
|
|
|
* secret_collection_get_items().
|
|
|
|
*
|
|
|
|
* You can also pass the %SECRET_COLLECTION_LOAD_ITEMS to
|
|
|
|
* secret_collection_new() in order to ensure that the collections have been
|
|
|
|
* loaded by the time you get the #SecretCollection proxy.
|
|
|
|
*
|
|
|
|
* This method will return immediately and complete asynchronously.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
secret_collection_load_items (SecretCollection *self,
|
|
|
|
GCancellable *cancellable,
|
|
|
|
GAsyncReadyCallback callback,
|
|
|
|
gpointer user_data)
|
|
|
|
{
|
|
|
|
ItemsClosure *closure;
|
|
|
|
SecretItem *item;
|
|
|
|
GSimpleAsyncResult *res;
|
|
|
|
const gchar *path;
|
|
|
|
GVariant *paths;
|
|
|
|
GVariantIter iter;
|
|
|
|
|
|
|
|
g_return_if_fail (SECRET_IS_COLLECTION (self));
|
|
|
|
g_return_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable));
|
|
|
|
|
|
|
|
paths = g_dbus_proxy_get_cached_property (G_DBUS_PROXY (self), "Items");
|
|
|
|
g_return_if_fail (paths != NULL);
|
|
|
|
|
|
|
|
res = g_simple_async_result_new (G_OBJECT (self), callback, user_data,
|
|
|
|
secret_collection_load_items);
|
|
|
|
closure = g_slice_new0 (ItemsClosure);
|
|
|
|
closure->cancellable = cancellable ? g_object_ref (cancellable) : NULL;
|
|
|
|
closure->items = items_table_new ();
|
|
|
|
g_simple_async_result_set_op_res_gpointer (res, closure, items_closure_free);
|
|
|
|
|
|
|
|
g_variant_iter_init (&iter, paths);
|
|
|
|
while (g_variant_iter_loop (&iter, "&o", &path)) {
|
|
|
|
item = collection_lookup_item (self, path);
|
|
|
|
|
|
|
|
/* No such collection yet create a new one */
|
|
|
|
if (item == NULL) {
|
|
|
|
secret_item_new (self->pv->service, path, SECRET_ITEM_NONE,
|
|
|
|
cancellable, on_load_item, g_object_ref (res));
|
|
|
|
closure->items_loading++;
|
|
|
|
|
|
|
|
} else {
|
|
|
|
g_hash_table_insert (closure->items, g_strdup (path), item);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (closure->items_loading == 0) {
|
|
|
|
collection_update_items (self, closure->items);
|
|
|
|
g_simple_async_result_complete_in_idle (res);
|
|
|
|
}
|
|
|
|
|
|
|
|
g_variant_unref (paths);
|
|
|
|
g_object_unref (res);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* secret_collection_load_items_finish:
|
|
|
|
* @self: the secret collection
|
|
|
|
* @result: the asynchronous result passed to the callback
|
|
|
|
* @error: location to place an error on failure
|
|
|
|
*
|
|
|
|
* Complete an asynchronous operation to ensure that the #SecretCollection proxy
|
|
|
|
* has loaded all the items present in the Secret Service.
|
|
|
|
*
|
|
|
|
* Returns: whether the load was successful or not
|
|
|
|
*/
|
|
|
|
gboolean
|
|
|
|
secret_collection_load_items_finish (SecretCollection *self,
|
|
|
|
GAsyncResult *result,
|
|
|
|
GError **error)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (SECRET_IS_COLLECTION (self), FALSE);
|
|
|
|
g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
|
|
|
|
g_return_val_if_fail (g_simple_async_result_is_valid (result, G_OBJECT (self),
|
|
|
|
secret_collection_load_items), FALSE);
|
|
|
|
|
|
|
|
if (g_simple_async_result_propagate_error (G_SIMPLE_ASYNC_RESULT (result), error))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* secret_collection_load_items_sync:
|
|
|
|
* @self: the secret collection
|
|
|
|
* @cancellable: optional cancellation object
|
|
|
|
* @error: location to place an error on failure
|
|
|
|
*
|
|
|
|
* Ensure that the #SecretCollection proxy has loaded all the items present
|
|
|
|
* in the Secret Service. This affects the result of
|
|
|
|
* secret_collection_get_items().
|
|
|
|
*
|
|
|
|
* You can also pass the %SECRET_COLLECTION_LOAD_ITEMS to
|
|
|
|
* secret_collection_new_sync() in order to ensure that the items have been
|
|
|
|
* loaded by the time you get the #SecretCollection proxy.
|
|
|
|
*
|
|
|
|
* This method may block indefinitely and should not be used in user interface
|
|
|
|
* threads.
|
|
|
|
*
|
|
|
|
* Returns: whether the load was successful or not
|
|
|
|
*/
|
|
|
|
gboolean
|
|
|
|
secret_collection_load_items_sync (SecretCollection *self,
|
|
|
|
GCancellable *cancellable,
|
|
|
|
GError **error)
|
|
|
|
{
|
|
|
|
SecretItem *item;
|
|
|
|
GHashTable *items;
|
|
|
|
GVariant *paths;
|
|
|
|
GVariantIter iter;
|
|
|
|
const gchar *path;
|
|
|
|
gboolean ret = TRUE;
|
|
|
|
|
|
|
|
g_return_val_if_fail (SECRET_IS_COLLECTION (self), FALSE);
|
|
|
|
g_return_val_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable), FALSE);
|
|
|
|
g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
|
|
|
|
|
|
|
|
paths = g_dbus_proxy_get_cached_property (G_DBUS_PROXY (self), "Items");
|
|
|
|
g_return_val_if_fail (paths != NULL, FALSE);
|
|
|
|
|
|
|
|
items = items_table_new ();
|
|
|
|
|
|
|
|
g_variant_iter_init (&iter, paths);
|
|
|
|
while (g_variant_iter_next (&iter, "&o", &path)) {
|
|
|
|
item = collection_lookup_item (self, path);
|
|
|
|
|
|
|
|
/* No such collection yet create a new one */
|
|
|
|
if (item == NULL) {
|
|
|
|
item = secret_item_new_sync (self->pv->service, path,
|
|
|
|
SECRET_ITEM_NONE,
|
|
|
|
cancellable, error);
|
|
|
|
if (item == NULL) {
|
|
|
|
ret = FALSE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
g_hash_table_insert (items, g_strdup (path), item);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ret)
|
|
|
|
collection_update_items (self, items);
|
|
|
|
|
|
|
|
g_hash_table_unref (items);
|
|
|
|
g_variant_unref (paths);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2012-02-02 12:40:47 +00:00
|
|
|
/**
|
|
|
|
* secret_collection_refresh:
|
|
|
|
* @self: the collection
|
|
|
|
*
|
|
|
|
* Refresh the properties on this collection. This fires off a request to
|
|
|
|
* refresh, and the properties will be updated later.
|
|
|
|
*
|
|
|
|
* Calling this method is not normally necessary, as the secret service
|
|
|
|
* will notify the client when properties change.
|
|
|
|
*/
|
2012-01-20 14:10:35 +00:00
|
|
|
void
|
2012-02-01 12:34:08 +00:00
|
|
|
secret_collection_refresh (SecretCollection *self)
|
2012-01-20 14:10:35 +00:00
|
|
|
{
|
2012-02-01 12:34:08 +00:00
|
|
|
g_return_if_fail (SECRET_IS_COLLECTION (self));
|
2012-01-20 14:10:35 +00:00
|
|
|
|
2012-02-01 12:34:08 +00:00
|
|
|
_secret_util_get_properties (G_DBUS_PROXY (self),
|
|
|
|
secret_collection_refresh,
|
2012-01-20 14:10:35 +00:00
|
|
|
self->pv->cancellable, NULL, NULL);
|
|
|
|
}
|
|
|
|
|
2012-01-26 17:23:12 +00:00
|
|
|
typedef struct {
|
|
|
|
GCancellable *cancellable;
|
2012-02-01 12:34:08 +00:00
|
|
|
SecretCollection *collection;
|
2012-07-05 21:14:50 +00:00
|
|
|
GHashTable *properties;
|
|
|
|
gchar *alias;
|
2012-01-26 17:23:12 +00:00
|
|
|
} CreateClosure;
|
|
|
|
|
|
|
|
static void
|
|
|
|
create_closure_free (gpointer data)
|
|
|
|
{
|
|
|
|
CreateClosure *closure = data;
|
|
|
|
g_clear_object (&closure->cancellable);
|
|
|
|
g_clear_object (&closure->collection);
|
2012-07-05 21:14:50 +00:00
|
|
|
g_hash_table_unref (closure->properties);
|
|
|
|
g_free (closure->alias);
|
2012-01-26 17:23:12 +00:00
|
|
|
g_slice_free (CreateClosure, closure);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
on_create_collection (GObject *source,
|
|
|
|
GAsyncResult *result,
|
|
|
|
gpointer user_data)
|
|
|
|
{
|
|
|
|
GSimpleAsyncResult *res = G_SIMPLE_ASYNC_RESULT (user_data);
|
|
|
|
CreateClosure *closure = g_simple_async_result_get_op_res_gpointer (res);
|
|
|
|
GError *error = NULL;
|
|
|
|
|
2012-02-01 12:34:08 +00:00
|
|
|
closure->collection = secret_collection_new_finish (result, &error);
|
2012-01-26 17:23:12 +00:00
|
|
|
if (error != NULL)
|
|
|
|
g_simple_async_result_take_error (res, error);
|
|
|
|
|
|
|
|
g_simple_async_result_complete (res);
|
|
|
|
g_object_unref (res);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
on_create_path (GObject *source,
|
|
|
|
GAsyncResult *result,
|
|
|
|
gpointer user_data)
|
|
|
|
{
|
|
|
|
GSimpleAsyncResult *res = G_SIMPLE_ASYNC_RESULT (user_data);
|
|
|
|
CreateClosure *closure = g_simple_async_result_get_op_res_gpointer (res);
|
2012-02-01 12:34:08 +00:00
|
|
|
SecretService *service = SECRET_SERVICE (source);
|
2012-01-26 17:23:12 +00:00
|
|
|
GError *error = NULL;
|
|
|
|
gchar *path;
|
|
|
|
|
2012-02-01 12:34:08 +00:00
|
|
|
path = secret_service_create_collection_path_finish (service, result, &error);
|
2012-01-26 17:23:12 +00:00
|
|
|
if (error == NULL) {
|
2012-07-05 19:26:20 +00:00
|
|
|
secret_collection_new (service, path, SECRET_COLLECTION_LOAD_ITEMS,
|
|
|
|
closure->cancellable,
|
2012-02-02 12:40:47 +00:00
|
|
|
on_create_collection, g_object_ref (res));
|
2012-01-26 17:23:12 +00:00
|
|
|
} else {
|
|
|
|
g_simple_async_result_take_error (res, error);
|
|
|
|
g_simple_async_result_complete (res);
|
|
|
|
}
|
|
|
|
|
|
|
|
g_object_unref (res);
|
|
|
|
}
|
|
|
|
|
2012-07-05 21:14:50 +00:00
|
|
|
static void
|
|
|
|
on_create_service (GObject *source,
|
|
|
|
GAsyncResult *result,
|
|
|
|
gpointer user_data)
|
|
|
|
{
|
|
|
|
GSimpleAsyncResult *async = G_SIMPLE_ASYNC_RESULT (user_data);
|
|
|
|
CreateClosure *create = g_simple_async_result_get_op_res_gpointer (async);
|
|
|
|
GError *error = NULL;
|
|
|
|
SecretService *service;
|
|
|
|
|
|
|
|
service = secret_service_get_finish (result, &error);
|
|
|
|
if (error == NULL) {
|
|
|
|
secret_service_create_collection_path (service, create->properties,
|
|
|
|
create->alias, create->cancellable,
|
|
|
|
on_create_path, g_object_ref (async));
|
|
|
|
g_object_unref (service);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
g_simple_async_result_take_error (async, error);
|
|
|
|
g_simple_async_result_complete (async);
|
|
|
|
}
|
|
|
|
|
|
|
|
g_object_unref (async);
|
|
|
|
}
|
|
|
|
|
2012-01-26 17:23:12 +00:00
|
|
|
static GHashTable *
|
|
|
|
collection_properties_new (const gchar *label)
|
|
|
|
{
|
|
|
|
GHashTable *properties;
|
|
|
|
GVariant *value;
|
|
|
|
|
|
|
|
properties = g_hash_table_new_full (g_str_hash, g_str_equal, NULL,
|
|
|
|
(GDestroyNotify)g_variant_unref);
|
|
|
|
value = g_variant_new_string (label);
|
|
|
|
g_hash_table_insert (properties,
|
2012-02-01 12:34:08 +00:00
|
|
|
SECRET_COLLECTION_INTERFACE ".Label",
|
2012-01-26 17:23:12 +00:00
|
|
|
g_variant_ref_sink (value));
|
|
|
|
|
|
|
|
return properties;
|
|
|
|
}
|
|
|
|
|
2012-01-31 19:40:44 +00:00
|
|
|
/**
|
2012-02-01 12:34:08 +00:00
|
|
|
* secret_collection_create:
|
2012-07-05 21:14:50 +00:00
|
|
|
* @service: (allow-none): a secret service object
|
2012-01-31 19:40:44 +00:00
|
|
|
* @label: label for the new collection
|
|
|
|
* @alias: (allow-none): alias to assign to the collection
|
|
|
|
* @cancellable: optional cancellation object
|
|
|
|
* @callback: called when the operation completes
|
|
|
|
* @user_data: data to pass to the callback
|
|
|
|
*
|
|
|
|
* Create a new collection in the secret service.
|
|
|
|
*
|
|
|
|
* This method returns immediately and completes asynchronously. The secret
|
2012-02-01 12:34:08 +00:00
|
|
|
* service may prompt the user. secret_service_prompt() will be used to handle
|
2012-01-31 19:40:44 +00:00
|
|
|
* any prompts that are required.
|
2012-03-24 12:31:14 +00:00
|
|
|
*
|
|
|
|
* An @alias is a well-known tag for a collection, such as 'default' (ie: the
|
|
|
|
* default collection to store items in). This allows other applications to
|
|
|
|
* easily identify and share a collection. If you specify an @alias, and a
|
|
|
|
* collection with that alias already exists, then a new collection will not
|
|
|
|
* be created. The previous one will be returned instead.
|
2012-07-05 21:14:50 +00:00
|
|
|
*
|
|
|
|
* If @service is NULL, then secret_service_get() will be called to get
|
|
|
|
* the default #SecretService proxy.
|
|
|
|
*
|
2012-01-31 19:40:44 +00:00
|
|
|
*/
|
2012-01-26 17:23:12 +00:00
|
|
|
void
|
2012-02-01 12:34:08 +00:00
|
|
|
secret_collection_create (SecretService *service,
|
2012-02-02 12:40:47 +00:00
|
|
|
const gchar *label,
|
|
|
|
const gchar *alias,
|
|
|
|
GCancellable *cancellable,
|
|
|
|
GAsyncReadyCallback callback,
|
|
|
|
gpointer user_data)
|
2012-01-26 17:23:12 +00:00
|
|
|
{
|
|
|
|
GSimpleAsyncResult *res;
|
|
|
|
CreateClosure *closure;
|
|
|
|
|
2012-07-05 21:14:50 +00:00
|
|
|
g_return_if_fail (service == NULL || SECRET_IS_SERVICE (service));
|
2012-01-26 17:23:12 +00:00
|
|
|
g_return_if_fail (label != NULL);
|
|
|
|
g_return_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable));
|
|
|
|
|
|
|
|
res = g_simple_async_result_new (NULL, callback, user_data,
|
2012-02-01 12:34:08 +00:00
|
|
|
secret_collection_create);
|
2012-01-26 17:23:12 +00:00
|
|
|
closure = g_slice_new0 (CreateClosure);
|
|
|
|
closure->cancellable = cancellable ? g_object_ref (cancellable) : NULL;
|
2012-07-05 21:14:50 +00:00
|
|
|
closure->properties = collection_properties_new (label);
|
|
|
|
closure->alias = g_strdup (alias);
|
2012-01-26 17:23:12 +00:00
|
|
|
g_simple_async_result_set_op_res_gpointer (res, closure, create_closure_free);
|
|
|
|
|
2012-07-05 21:14:50 +00:00
|
|
|
if (service == NULL) {
|
|
|
|
secret_service_get (SECRET_SERVICE_NONE, cancellable,
|
|
|
|
on_create_service, g_object_ref (res));
|
2012-01-26 17:23:12 +00:00
|
|
|
|
2012-07-05 21:14:50 +00:00
|
|
|
} else {
|
|
|
|
secret_service_create_collection_path (service, closure->properties,
|
|
|
|
closure->alias, closure->cancellable,
|
|
|
|
on_create_path, g_object_ref (res));
|
|
|
|
}
|
2012-01-26 17:23:12 +00:00
|
|
|
|
|
|
|
g_object_unref (res);
|
|
|
|
}
|
|
|
|
|
2012-01-31 19:40:44 +00:00
|
|
|
/**
|
2012-02-01 12:34:08 +00:00
|
|
|
* secret_collection_create_finish:
|
2012-01-31 19:40:44 +00:00
|
|
|
* @result: the asynchronous result passed to the callback
|
|
|
|
* @error: location to place an error on failure
|
|
|
|
*
|
|
|
|
* Finish operation to create a new collection in the secret service.
|
|
|
|
*
|
|
|
|
* Returns: (transfer full): the new collection, which should be unreferenced
|
|
|
|
* with g_object_unref()
|
|
|
|
*/
|
2012-02-01 12:34:08 +00:00
|
|
|
SecretCollection *
|
|
|
|
secret_collection_create_finish (GAsyncResult *result,
|
2012-02-02 12:40:47 +00:00
|
|
|
GError **error)
|
2012-01-26 17:23:12 +00:00
|
|
|
{
|
|
|
|
GSimpleAsyncResult *res;
|
|
|
|
CreateClosure *closure;
|
|
|
|
|
|
|
|
g_return_val_if_fail (g_simple_async_result_is_valid (result, NULL,
|
2012-02-01 12:34:08 +00:00
|
|
|
secret_collection_create), NULL);
|
2012-01-26 17:23:12 +00:00
|
|
|
g_return_val_if_fail (error == NULL || *error == NULL, NULL);
|
|
|
|
|
|
|
|
res = G_SIMPLE_ASYNC_RESULT (result);
|
|
|
|
|
|
|
|
if (g_simple_async_result_propagate_error (res, error))
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
closure = g_simple_async_result_get_op_res_gpointer (res);
|
|
|
|
if (closure->collection == NULL)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
return g_object_ref (closure->collection);
|
|
|
|
}
|
|
|
|
|
2012-01-31 19:20:31 +00:00
|
|
|
/**
|
2012-02-01 12:34:08 +00:00
|
|
|
* secret_collection_create_sync:
|
2012-07-05 21:14:50 +00:00
|
|
|
* @service: (allow-none): a secret service object
|
2012-01-31 19:20:31 +00:00
|
|
|
* @label: label for the new collection
|
|
|
|
* @alias: (allow-none): alias to assign to the collection
|
|
|
|
* @cancellable: optional cancellation object
|
|
|
|
* @error: location to place an error on failure
|
|
|
|
*
|
2012-01-31 19:40:44 +00:00
|
|
|
* Create a new collection in the secret service.
|
2012-01-31 19:20:31 +00:00
|
|
|
*
|
2012-02-02 12:40:47 +00:00
|
|
|
* This method may block indefinitely and should not be used in user interface
|
|
|
|
* threads. The secret service may prompt the user. secret_service_prompt()
|
|
|
|
* will be used to handle any prompts that are required.
|
2012-01-31 19:20:31 +00:00
|
|
|
*
|
2012-03-24 12:31:14 +00:00
|
|
|
* An @alias is a well-known tag for a collection, such as 'default' (ie: the
|
|
|
|
* default collection to store items in). This allows other applications to
|
|
|
|
* easily identify and share a collection. If you specify an @alias, and a
|
|
|
|
* collection with that alias already exists, then a new collection will not
|
|
|
|
* be created. The previous one will be returned instead.
|
|
|
|
*
|
2012-07-05 21:14:50 +00:00
|
|
|
* If @service is NULL, then secret_service_get_sync() will be called to get
|
|
|
|
* the default #SecretService proxy.
|
|
|
|
*
|
2012-01-31 19:40:44 +00:00
|
|
|
* Returns: (transfer full): the new collection, which should be unreferenced
|
|
|
|
* with g_object_unref()
|
2012-01-31 19:20:31 +00:00
|
|
|
*/
|
2012-02-01 12:34:08 +00:00
|
|
|
SecretCollection *
|
|
|
|
secret_collection_create_sync (SecretService *service,
|
2012-02-02 12:40:47 +00:00
|
|
|
const gchar *label,
|
|
|
|
const gchar *alias,
|
|
|
|
GCancellable *cancellable,
|
|
|
|
GError **error)
|
2012-01-26 17:23:12 +00:00
|
|
|
{
|
2012-02-01 12:34:08 +00:00
|
|
|
SecretCollection *collection;
|
2012-01-26 17:23:12 +00:00
|
|
|
GHashTable *properties;
|
|
|
|
gchar *path;
|
|
|
|
|
2012-07-05 21:14:50 +00:00
|
|
|
g_return_val_if_fail (service == NULL || SECRET_IS_SERVICE (service), NULL);
|
2012-01-26 17:23:12 +00:00
|
|
|
g_return_val_if_fail (label != NULL, NULL);
|
|
|
|
g_return_val_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable), NULL);
|
|
|
|
g_return_val_if_fail (error == NULL || *error == NULL, NULL);
|
|
|
|
|
2012-07-05 21:14:50 +00:00
|
|
|
if (service == NULL) {
|
|
|
|
service = secret_service_get_sync (SECRET_SERVICE_NONE, cancellable, error);
|
|
|
|
if (service == NULL)
|
|
|
|
return NULL;
|
|
|
|
} else {
|
|
|
|
g_object_ref (service);
|
|
|
|
}
|
|
|
|
|
2012-01-26 17:23:12 +00:00
|
|
|
properties = collection_properties_new (label);
|
|
|
|
|
2012-02-01 12:34:08 +00:00
|
|
|
path = secret_service_create_collection_path_sync (service, properties, alias,
|
2012-02-02 12:40:47 +00:00
|
|
|
cancellable, error);
|
2012-01-26 17:23:12 +00:00
|
|
|
|
|
|
|
g_hash_table_unref (properties);
|
|
|
|
|
2012-07-05 21:14:50 +00:00
|
|
|
if (path == NULL) {
|
|
|
|
g_object_unref (service);
|
2012-01-26 17:23:12 +00:00
|
|
|
return NULL;
|
2012-07-05 21:14:50 +00:00
|
|
|
}
|
2012-01-26 17:23:12 +00:00
|
|
|
|
2012-07-05 19:26:20 +00:00
|
|
|
collection = secret_collection_new_sync (service, path,
|
|
|
|
SECRET_COLLECTION_LOAD_ITEMS,
|
|
|
|
cancellable, error);
|
2012-07-05 21:14:50 +00:00
|
|
|
|
|
|
|
g_object_unref (service);
|
2012-01-26 17:23:12 +00:00
|
|
|
g_free (path);
|
|
|
|
|
|
|
|
return collection;
|
|
|
|
}
|
|
|
|
|
2012-06-27 14:41:13 +00:00
|
|
|
static void
|
|
|
|
on_service_delete_path (GObject *source,
|
|
|
|
GAsyncResult *result,
|
|
|
|
gpointer user_data)
|
|
|
|
{
|
|
|
|
GSimpleAsyncResult *async = G_SIMPLE_ASYNC_RESULT (user_data);
|
|
|
|
GError *error = NULL;
|
|
|
|
|
|
|
|
secret_service_delete_path_finish (SECRET_SERVICE (source), result, &error);
|
|
|
|
if (error != NULL)
|
|
|
|
g_simple_async_result_take_error (async, error);
|
|
|
|
g_simple_async_result_complete (async);
|
|
|
|
g_object_unref (async);
|
|
|
|
}
|
2012-01-31 19:20:31 +00:00
|
|
|
/**
|
2012-02-01 12:34:08 +00:00
|
|
|
* secret_collection_delete:
|
2012-01-31 19:20:31 +00:00
|
|
|
* @self: a collection
|
|
|
|
* @cancellable: optional cancellation object
|
|
|
|
* @callback: called when the operation completes
|
|
|
|
* @user_data: data to pass to the callback
|
|
|
|
*
|
|
|
|
* Delete this collection.
|
|
|
|
*
|
|
|
|
* This method returns immediately and completes asynchronously. The secret
|
2012-02-01 12:34:08 +00:00
|
|
|
* service may prompt the user. secret_service_prompt() will be used to handle
|
2012-01-31 19:20:31 +00:00
|
|
|
* any prompts that show up.
|
|
|
|
*/
|
2012-01-20 14:10:35 +00:00
|
|
|
void
|
2012-02-01 12:34:08 +00:00
|
|
|
secret_collection_delete (SecretCollection *self,
|
2012-02-02 12:40:47 +00:00
|
|
|
GCancellable *cancellable,
|
|
|
|
GAsyncReadyCallback callback,
|
|
|
|
gpointer user_data)
|
2012-01-20 14:10:35 +00:00
|
|
|
{
|
2012-06-27 14:41:13 +00:00
|
|
|
GSimpleAsyncResult *async;
|
2012-01-20 14:10:35 +00:00
|
|
|
const gchar *object_path;
|
|
|
|
|
2012-02-01 12:34:08 +00:00
|
|
|
g_return_if_fail (SECRET_IS_COLLECTION (self));
|
2012-01-20 14:10:35 +00:00
|
|
|
g_return_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable));
|
|
|
|
|
2012-06-27 14:41:13 +00:00
|
|
|
async = g_simple_async_result_new (G_OBJECT (self), callback, user_data,
|
|
|
|
secret_collection_delete);
|
|
|
|
|
2012-01-20 14:10:35 +00:00
|
|
|
object_path = g_dbus_proxy_get_object_path (G_DBUS_PROXY (self));
|
2012-02-01 12:34:08 +00:00
|
|
|
_secret_service_delete_path (self->pv->service, object_path, FALSE,
|
2012-06-27 14:41:13 +00:00
|
|
|
cancellable, on_service_delete_path,
|
|
|
|
g_object_ref (async));
|
|
|
|
|
|
|
|
g_object_unref (async);
|
2012-01-20 14:10:35 +00:00
|
|
|
}
|
|
|
|
|
2012-01-31 19:20:31 +00:00
|
|
|
/**
|
2012-02-01 12:34:08 +00:00
|
|
|
* secret_collection_delete_finish:
|
2012-01-31 19:20:31 +00:00
|
|
|
* @self: a collection
|
|
|
|
* @result: asynchronous result passed to the callback
|
|
|
|
* @error: location to place an error on failure
|
|
|
|
*
|
|
|
|
* Complete operation to delete this collection.
|
|
|
|
*
|
2012-02-02 12:40:47 +00:00
|
|
|
* Returns: whether the collection was successfully deleted or not
|
2012-01-31 19:20:31 +00:00
|
|
|
*/
|
2012-01-20 14:10:35 +00:00
|
|
|
gboolean
|
2012-02-01 12:34:08 +00:00
|
|
|
secret_collection_delete_finish (SecretCollection *self,
|
2012-02-02 12:40:47 +00:00
|
|
|
GAsyncResult *result,
|
|
|
|
GError **error)
|
2012-01-20 14:10:35 +00:00
|
|
|
{
|
2012-02-01 12:34:08 +00:00
|
|
|
g_return_val_if_fail (SECRET_IS_COLLECTION (self), FALSE);
|
2012-01-20 14:10:35 +00:00
|
|
|
g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
|
2012-06-27 14:41:13 +00:00
|
|
|
g_return_val_if_fail (g_simple_async_result_is_valid (result, G_OBJECT (self),
|
|
|
|
secret_collection_delete), FALSE);
|
|
|
|
|
|
|
|
if (g_simple_async_result_propagate_error (G_SIMPLE_ASYNC_RESULT (result), error))
|
|
|
|
return FALSE;
|
2012-01-20 14:10:35 +00:00
|
|
|
|
2012-06-27 14:41:13 +00:00
|
|
|
return TRUE;
|
2012-01-20 14:10:35 +00:00
|
|
|
}
|
|
|
|
|
2012-01-31 19:20:31 +00:00
|
|
|
/**
|
2012-02-01 12:34:08 +00:00
|
|
|
* secret_collection_delete_sync:
|
2012-01-31 19:20:31 +00:00
|
|
|
* @self: a collection
|
|
|
|
* @cancellable: optional cancellation object
|
|
|
|
* @error: location to place an error on failure
|
|
|
|
*
|
|
|
|
* Delete this collection.
|
|
|
|
*
|
2012-02-02 12:40:47 +00:00
|
|
|
* This method may block indefinitely and should not be used in user
|
|
|
|
* interface threads. The secret service may prompt the user.
|
|
|
|
* secret_service_prompt() will be used to handle any prompts that show up.
|
2012-01-31 19:20:31 +00:00
|
|
|
*
|
2012-02-02 12:40:47 +00:00
|
|
|
* Returns: whether the collection was successfully deleted or not
|
2012-01-31 19:20:31 +00:00
|
|
|
*/
|
2012-01-20 14:10:35 +00:00
|
|
|
gboolean
|
2012-02-01 12:34:08 +00:00
|
|
|
secret_collection_delete_sync (SecretCollection *self,
|
2012-02-02 12:40:47 +00:00
|
|
|
GCancellable *cancellable,
|
|
|
|
GError **error)
|
2012-01-20 14:10:35 +00:00
|
|
|
{
|
2012-02-01 12:34:08 +00:00
|
|
|
SecretSync *sync;
|
2012-01-20 14:10:35 +00:00
|
|
|
gboolean ret;
|
|
|
|
|
2012-02-01 12:34:08 +00:00
|
|
|
g_return_val_if_fail (SECRET_IS_COLLECTION (self), FALSE);
|
2012-01-20 14:10:35 +00:00
|
|
|
g_return_val_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable), FALSE);
|
|
|
|
g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
|
|
|
|
|
2012-02-01 12:34:08 +00:00
|
|
|
sync = _secret_sync_new ();
|
2012-01-20 14:10:35 +00:00
|
|
|
g_main_context_push_thread_default (sync->context);
|
|
|
|
|
2012-02-01 12:34:08 +00:00
|
|
|
secret_collection_delete (self, cancellable, _secret_sync_on_result, sync);
|
2012-01-20 14:10:35 +00:00
|
|
|
|
|
|
|
g_main_loop_run (sync->loop);
|
|
|
|
|
2012-02-01 12:34:08 +00:00
|
|
|
ret = secret_collection_delete_finish (self, sync->result, error);
|
2012-01-20 14:10:35 +00:00
|
|
|
|
|
|
|
g_main_context_pop_thread_default (sync->context);
|
2012-02-01 12:34:08 +00:00
|
|
|
_secret_sync_free (sync);
|
2012-01-20 14:10:35 +00:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2012-06-25 08:17:16 +00:00
|
|
|
/**
|
|
|
|
* secret_collection_get_service:
|
|
|
|
* @self: a collection
|
|
|
|
*
|
|
|
|
* Get the Secret Service object that this collection was created with.
|
|
|
|
*
|
|
|
|
* Returns: (transfer none): the Secret Service object
|
|
|
|
*/
|
|
|
|
SecretService *
|
|
|
|
secret_collection_get_service (SecretCollection *self)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (SECRET_IS_COLLECTION (self), NULL);
|
|
|
|
return self->pv->service;
|
|
|
|
}
|
|
|
|
|
2012-07-05 19:26:20 +00:00
|
|
|
/**
|
|
|
|
* secret_collection_get_flags:
|
|
|
|
* @self: the secret collection proxy
|
|
|
|
*
|
|
|
|
* Get the flags representing what features of the #SecretCollection proxy
|
|
|
|
* have been initialized.
|
|
|
|
*
|
|
|
|
* Use secret_collection_load_items() to initialize further features
|
|
|
|
* and change the flags.
|
|
|
|
*
|
|
|
|
* Returns: the flags for features initialized
|
|
|
|
*/
|
|
|
|
SecretCollectionFlags
|
|
|
|
secret_collection_get_flags (SecretCollection *self)
|
|
|
|
{
|
|
|
|
SecretCollectionFlags flags = 0;
|
|
|
|
|
|
|
|
g_return_val_if_fail (SECRET_IS_COLLECTION (self), SECRET_COLLECTION_NONE);
|
|
|
|
|
|
|
|
g_mutex_lock (&self->pv->mutex);
|
|
|
|
|
|
|
|
if (self->pv->items)
|
|
|
|
flags |= SECRET_COLLECTION_LOAD_ITEMS;
|
|
|
|
|
|
|
|
g_mutex_unlock (&self->pv->mutex);
|
|
|
|
|
|
|
|
return flags;
|
|
|
|
}
|
|
|
|
|
2012-01-31 19:20:31 +00:00
|
|
|
/**
|
2012-02-01 12:34:08 +00:00
|
|
|
* secret_collection_get_items:
|
2012-01-31 19:20:31 +00:00
|
|
|
* @self: a collection
|
|
|
|
*
|
|
|
|
* Get the list of items in this collection.
|
|
|
|
*
|
2012-02-01 12:34:08 +00:00
|
|
|
* Returns: (transfer full) (element-type Secret.Item): a list of items,
|
2012-01-31 19:20:31 +00:00
|
|
|
* when done, the list should be freed with g_list_free, and each item should
|
|
|
|
* be released with g_object_unref()
|
|
|
|
*/
|
2012-01-20 14:10:35 +00:00
|
|
|
GList *
|
2012-02-01 12:34:08 +00:00
|
|
|
secret_collection_get_items (SecretCollection *self)
|
2012-01-20 14:10:35 +00:00
|
|
|
{
|
|
|
|
GList *l, *items;
|
|
|
|
|
2012-02-01 12:34:08 +00:00
|
|
|
g_return_val_if_fail (SECRET_IS_COLLECTION (self), NULL);
|
2012-01-20 14:10:35 +00:00
|
|
|
|
|
|
|
g_mutex_lock (&self->pv->mutex);
|
|
|
|
items = g_hash_table_get_values (self->pv->items);
|
|
|
|
for (l = items; l != NULL; l = g_list_next (l))
|
|
|
|
g_object_ref (l->data);
|
|
|
|
g_mutex_unlock (&self->pv->mutex);
|
|
|
|
|
|
|
|
return items;
|
|
|
|
}
|
|
|
|
|
2012-02-01 12:34:08 +00:00
|
|
|
SecretItem *
|
|
|
|
_secret_collection_find_item_instance (SecretCollection *self,
|
2012-02-02 12:40:47 +00:00
|
|
|
const gchar *item_path)
|
2012-01-20 14:10:35 +00:00
|
|
|
{
|
2012-02-01 12:34:08 +00:00
|
|
|
SecretItem *item;
|
2012-01-20 14:10:35 +00:00
|
|
|
|
|
|
|
g_mutex_lock (&self->pv->mutex);
|
|
|
|
item = g_hash_table_lookup (self->pv->items, item_path);
|
|
|
|
if (item != NULL)
|
|
|
|
g_object_ref (item);
|
|
|
|
g_mutex_unlock (&self->pv->mutex);
|
|
|
|
|
|
|
|
return item;
|
|
|
|
}
|
|
|
|
|
2012-01-31 19:20:31 +00:00
|
|
|
/**
|
2012-02-01 12:34:08 +00:00
|
|
|
* secret_collection_get_label:
|
2012-01-31 19:20:31 +00:00
|
|
|
* @self: a collection
|
|
|
|
*
|
|
|
|
* Get the label of this collection.
|
|
|
|
*
|
|
|
|
* Returns: (transfer full): the label, which should be freed with g_free()
|
|
|
|
*/
|
2012-01-20 14:10:35 +00:00
|
|
|
gchar *
|
2012-02-01 12:34:08 +00:00
|
|
|
secret_collection_get_label (SecretCollection *self)
|
2012-01-20 14:10:35 +00:00
|
|
|
{
|
|
|
|
GVariant *variant;
|
|
|
|
gchar *label;
|
|
|
|
|
2012-02-01 12:34:08 +00:00
|
|
|
g_return_val_if_fail (SECRET_IS_COLLECTION (self), NULL);
|
2012-01-20 14:10:35 +00:00
|
|
|
|
|
|
|
variant = g_dbus_proxy_get_cached_property (G_DBUS_PROXY (self), "Label");
|
|
|
|
g_return_val_if_fail (variant != NULL, NULL);
|
|
|
|
|
|
|
|
label = g_variant_dup_string (variant, NULL);
|
|
|
|
g_variant_unref (variant);
|
|
|
|
|
|
|
|
return label;
|
|
|
|
}
|
|
|
|
|
2012-01-31 19:20:31 +00:00
|
|
|
/**
|
2012-02-01 12:34:08 +00:00
|
|
|
* secret_collection_set_label:
|
2012-01-31 19:20:31 +00:00
|
|
|
* @self: a collection
|
|
|
|
* @label: a new label
|
|
|
|
* @cancellable: optional cancellation object
|
|
|
|
* @callback: called when the operation completes
|
|
|
|
* @user_data: data to pass to the callback
|
|
|
|
*
|
|
|
|
* Set the label of this collection.
|
|
|
|
*
|
|
|
|
* This function returns immediately and completes asynchronously.
|
|
|
|
*/
|
2012-01-20 14:10:35 +00:00
|
|
|
void
|
2012-02-01 12:34:08 +00:00
|
|
|
secret_collection_set_label (SecretCollection *self,
|
2012-02-02 12:40:47 +00:00
|
|
|
const gchar *label,
|
|
|
|
GCancellable *cancellable,
|
|
|
|
GAsyncReadyCallback callback,
|
|
|
|
gpointer user_data)
|
2012-01-20 14:10:35 +00:00
|
|
|
{
|
2012-02-01 12:34:08 +00:00
|
|
|
g_return_if_fail (SECRET_IS_COLLECTION (self));
|
2012-01-20 14:10:35 +00:00
|
|
|
g_return_if_fail (label != NULL);
|
|
|
|
|
2012-02-01 12:34:08 +00:00
|
|
|
_secret_util_set_property (G_DBUS_PROXY (self), "Label",
|
2012-02-02 12:40:47 +00:00
|
|
|
g_variant_new_string (label),
|
|
|
|
secret_collection_set_label,
|
|
|
|
cancellable, callback, user_data);
|
2012-01-20 14:10:35 +00:00
|
|
|
}
|
|
|
|
|
2012-01-31 19:20:31 +00:00
|
|
|
/**
|
2012-02-01 12:34:08 +00:00
|
|
|
* secret_collection_set_label_finish:
|
2012-01-31 19:20:31 +00:00
|
|
|
* @self: a collection
|
|
|
|
* @result: asynchronous result passed to callback
|
|
|
|
* @error: location to place error on failure
|
|
|
|
*
|
|
|
|
* Complete asynchronous operation to set the label of this collection.
|
|
|
|
*
|
|
|
|
* Returns: whether the change was successful or not
|
|
|
|
*/
|
2012-01-20 14:10:35 +00:00
|
|
|
gboolean
|
2012-02-01 12:34:08 +00:00
|
|
|
secret_collection_set_label_finish (SecretCollection *self,
|
2012-02-02 12:40:47 +00:00
|
|
|
GAsyncResult *result,
|
|
|
|
GError **error)
|
2012-01-20 14:10:35 +00:00
|
|
|
{
|
2012-02-01 12:34:08 +00:00
|
|
|
g_return_val_if_fail (SECRET_IS_COLLECTION (self), FALSE);
|
2012-01-20 14:10:35 +00:00
|
|
|
|
2012-02-01 12:34:08 +00:00
|
|
|
return _secret_util_set_property_finish (G_DBUS_PROXY (self),
|
2012-02-02 12:40:47 +00:00
|
|
|
secret_collection_set_label,
|
|
|
|
result, error);
|
2012-01-20 14:10:35 +00:00
|
|
|
}
|
|
|
|
|
2012-01-31 19:20:31 +00:00
|
|
|
/**
|
2012-02-01 12:34:08 +00:00
|
|
|
* secret_collection_set_label_sync:
|
2012-01-31 19:20:31 +00:00
|
|
|
* @self: a collection
|
|
|
|
* @label: a new label
|
|
|
|
* @cancellable: optional cancellation object
|
|
|
|
* @error: location to place error on failure
|
|
|
|
*
|
|
|
|
* Set the label of this collection.
|
|
|
|
*
|
|
|
|
* This function may block indefinetely. Use the asynchronous version
|
|
|
|
* in user interface threads.
|
|
|
|
*
|
|
|
|
* Returns: whether the change was successful or not
|
|
|
|
*/
|
2012-01-20 14:10:35 +00:00
|
|
|
gboolean
|
2012-02-01 12:34:08 +00:00
|
|
|
secret_collection_set_label_sync (SecretCollection *self,
|
2012-02-02 12:40:47 +00:00
|
|
|
const gchar *label,
|
|
|
|
GCancellable *cancellable,
|
|
|
|
GError **error)
|
2012-01-20 14:10:35 +00:00
|
|
|
{
|
2012-02-01 12:34:08 +00:00
|
|
|
g_return_val_if_fail (SECRET_IS_COLLECTION (self), FALSE);
|
2012-01-20 14:10:35 +00:00
|
|
|
g_return_val_if_fail (label != NULL, FALSE);
|
|
|
|
|
2012-02-01 12:34:08 +00:00
|
|
|
return _secret_util_set_property_sync (G_DBUS_PROXY (self), "Label",
|
2012-02-02 12:40:47 +00:00
|
|
|
g_variant_new_string (label),
|
|
|
|
cancellable, error);
|
2012-01-20 14:10:35 +00:00
|
|
|
}
|
|
|
|
|
2012-01-31 19:20:31 +00:00
|
|
|
/**
|
2012-02-01 12:34:08 +00:00
|
|
|
* secret_collection_get_locked:
|
2012-01-31 19:20:31 +00:00
|
|
|
* @self: a collection
|
|
|
|
*
|
|
|
|
* Get whether the collection is locked or not.
|
|
|
|
*
|
2012-02-02 13:59:59 +00:00
|
|
|
* Use secret_service_lock() or secret_service_unlock() to lock or unlock the
|
|
|
|
* collection.
|
|
|
|
*
|
2012-01-31 19:20:31 +00:00
|
|
|
* Returns: whether the collection is locked or not
|
|
|
|
*/
|
2012-01-20 14:10:35 +00:00
|
|
|
gboolean
|
2012-02-01 12:34:08 +00:00
|
|
|
secret_collection_get_locked (SecretCollection *self)
|
2012-01-20 14:10:35 +00:00
|
|
|
{
|
|
|
|
GVariant *variant;
|
|
|
|
gboolean locked;
|
|
|
|
|
2012-02-01 12:34:08 +00:00
|
|
|
g_return_val_if_fail (SECRET_IS_COLLECTION (self), TRUE);
|
2012-01-20 14:10:35 +00:00
|
|
|
|
|
|
|
variant = g_dbus_proxy_get_cached_property (G_DBUS_PROXY (self), "Locked");
|
|
|
|
g_return_val_if_fail (variant != NULL, TRUE);
|
|
|
|
|
|
|
|
locked = g_variant_get_boolean (variant);
|
|
|
|
g_variant_unref (variant);
|
|
|
|
|
|
|
|
return locked;
|
|
|
|
}
|
|
|
|
|
2012-01-31 19:20:31 +00:00
|
|
|
/**
|
2012-02-01 12:34:08 +00:00
|
|
|
* secret_collection_get_created:
|
2012-01-31 19:20:31 +00:00
|
|
|
* @self: a collection
|
|
|
|
*
|
|
|
|
* Get the created date and time of the collection. The return value is
|
|
|
|
* the number of seconds since the unix epoch, January 1st 1970.
|
|
|
|
*
|
|
|
|
* Returns: the created date and time
|
|
|
|
*/
|
2012-01-20 14:10:35 +00:00
|
|
|
guint64
|
2012-02-01 12:34:08 +00:00
|
|
|
secret_collection_get_created (SecretCollection *self)
|
2012-01-20 14:10:35 +00:00
|
|
|
{
|
|
|
|
GVariant *variant;
|
|
|
|
guint64 created;
|
|
|
|
|
2012-02-01 12:34:08 +00:00
|
|
|
g_return_val_if_fail (SECRET_IS_COLLECTION (self), TRUE);
|
2012-01-20 14:10:35 +00:00
|
|
|
|
|
|
|
variant = g_dbus_proxy_get_cached_property (G_DBUS_PROXY (self), "Created");
|
|
|
|
g_return_val_if_fail (variant != NULL, 0);
|
|
|
|
|
|
|
|
created = g_variant_get_uint64 (variant);
|
|
|
|
g_variant_unref (variant);
|
|
|
|
|
|
|
|
return created;
|
|
|
|
}
|
|
|
|
|
2012-01-31 19:20:31 +00:00
|
|
|
/**
|
2012-02-01 12:34:08 +00:00
|
|
|
* secret_collection_get_modified:
|
2012-01-31 19:20:31 +00:00
|
|
|
* @self: a collection
|
|
|
|
*
|
|
|
|
* Get the modified date and time of the collection. The return value is
|
|
|
|
* the number of seconds since the unix epoch, January 1st 1970.
|
|
|
|
*
|
|
|
|
* Returns: the modified date and time
|
|
|
|
*/
|
2012-01-20 14:10:35 +00:00
|
|
|
guint64
|
2012-02-01 12:34:08 +00:00
|
|
|
secret_collection_get_modified (SecretCollection *self)
|
2012-01-20 14:10:35 +00:00
|
|
|
{
|
|
|
|
GVariant *variant;
|
|
|
|
guint64 modified;
|
|
|
|
|
2012-02-01 12:34:08 +00:00
|
|
|
g_return_val_if_fail (SECRET_IS_COLLECTION (self), TRUE);
|
2012-01-20 14:10:35 +00:00
|
|
|
|
|
|
|
variant = g_dbus_proxy_get_cached_property (G_DBUS_PROXY (self), "Modified");
|
|
|
|
g_return_val_if_fail (variant != NULL, 0);
|
|
|
|
|
|
|
|
modified = g_variant_get_uint64 (variant);
|
|
|
|
g_variant_unref (variant);
|
|
|
|
|
|
|
|
return modified;
|
|
|
|
}
|