[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    [ksecrets] /: Adding unit tests
From:       Valentin Rusu <kde () rusu ! info>
Date:       2015-08-02 15:12:38
Message-ID: E1ZLuwI-0005ye-S2 () scm ! kde ! org
[Download RAW message or body]

Git commit bb68aa17e285584e497423b2d82d2b72937dd36b by Valentin Rusu.
Committed on 02/08/2015 at 15:11.
Pushed by vrusu into branch 'master'.

Adding unit tests

All these tests actually fail. Implementations will follow shortly :-)

M  +1    -1    CMakeLists.txt
M  +62   -13   autotests/api/ksecretsservice-test.cpp
M  +0    -1    autotests/api/ksecretsservice-test.h
M  +75   -60   src/api/ksecrets/ksecretscollection.cpp
M  +216  -198  src/api/ksecrets/ksecretscollection.h
M  +3    -5    src/api/ksecrets/ksecretscollection_p.h
M  +18   -29   src/api/ksecrets/ksecretsservice.h

http://commits.kde.org/ksecrets/bb68aa17e285584e497423b2d82d2b72937dd36b

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 253e0d1..e417f1e 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -1,7 +1,7 @@
 cmake_minimum_required(VERSION 2.8.12)
 
 project(KSecrets)
-set(CMAKE_EXPORT_COMPILE_COMMANDS)
+set(CMAKE_EXPORT_COMPILE_COMMANDS 1)
 
 include(FeatureSummary)
 find_package(ECM 5.11.0 NO_MODULE)
diff --git a/autotests/api/ksecretsservice-test.cpp b/autotests/api/ksecretsservice-test.cpp
index 53ebb33..00c1616 100644
--- a/autotests/api/ksecretsservice-test.cpp
+++ b/autotests/api/ksecretsservice-test.cpp
@@ -20,6 +20,7 @@
  */
 
 #include "ksecretsservice-test.h"
+#include <ksecretsservice.h>
 #include <ksecretscollection.h>
 #include <ksecretsvalue.h>
 #include <ksecretsitem.h>
@@ -29,41 +30,89 @@
 
 QTEST_MAIN(KSecretServiceTest)
 
-using namespace KSecrets;
+#define TEST_CREATE_COLLECTION_NAME "kf5-create-collection"
+#define TEST_COLLECTION_NAME "kf5-test-collection"
 
-KSecretServiceTest::KSecretServiceTest(QObject* parent): QObject(parent)
+KSecretServiceTest::KSecretServiceTest(QObject* parent)
+    : QObject(parent)
 {
-
 }
 
+KSecrets::CollectionPtr collection;
+
 void KSecretServiceTest::initTestCase()
 {
-    // TODO
+    collection = KSecrets::Service::findCollection(
+                     QLatin1String(TEST_CREATE_COLLECTION_NAME),
+                     KSecrets::Service::CreateCollection).result();
+    QVERIFY(collection->isValid().result());
 }
 
 void KSecretServiceTest::testCreateAndDelete()
 {
-    // TODO
-}
+    auto collection = KSecrets::Service::findCollection(
+                          QLatin1String(TEST_CREATE_COLLECTION_NAME),
+                          KSecrets::Service::OpenOnly).result();
+    QCOMPARE(collection->status(), KSecrets::Collection::NotFound);
 
-void KSecretServiceTest::testRenameCollection()
-{
-    // TODO
+    collection = KSecrets::Service::findCollection(
+                     QLatin1String(TEST_CREATE_COLLECTION_NAME),
+                     KSecrets::Service::CreateCollection).result();
+    QCOMPARE(collection->status(), KSecrets::Collection::NewlyCreated);
+
+    auto removeResult = collection->deleteCollection().result();
+    QVERIFY(removeResult);
 }
 
-void KSecretServiceTest::testCreateItem()
+void KSecretServiceTest::testRenameCollection()
 {
-    // TODO
+    auto NEW_COLLECTION_LABEL = QLatin1Literal("New collection name");
+    auto oldLabel = collection->label().result();
+    auto renameRes = collection->setLabel(NEW_COLLECTION_LABEL);
+    QVERIFY(renameRes);
+    auto newName = collection->label().result();
+    QCOMPARE(newName, NEW_COLLECTION_LABEL);
 }
 
 void KSecretServiceTest::testItems()
 {
-    // TODO
+    auto NEW_ITEM_NAME = QLatin1Literal("Test Item1");
+    auto NEW_ITEM_VALUE = QLatin1Literal("highly secret value");
+    QDateTime testTime = QDateTime::currentDateTime();
+
+    KSecrets::Secret secret;
+    secret.setValue(NEW_ITEM_VALUE);
+    auto createRes = collection->createItem(NEW_ITEM_NAME, secret).result();
+    QVERIFY(createRes);
+
+    auto foundItems = collection->searchItems(NEW_ITEM_NAME).result();
+    QVERIFY(foundItems.length() == 1);
+
+    auto theItem = foundItems.first();
+    QCOMPARE(theItem->label().result(), NEW_ITEM_NAME);
+    QVERIFY(theItem->createdTime().result() > testTime);
+    QVERIFY(theItem->modifiedTime().result() > testTime);
+
+    QDateTime oldModifiedTime = theItem->modifiedTime().result();
+    QVERIFY(theItem->setLabel(NEW_ITEM_NAME).result());
+    QVERIFY(theItem->modifiedTime().result()
+        == oldModifiedTime); // name was the same so item should have stayed
+                             // the same
+
+    auto NEW_ITEM_SECOND_NAME = QLatin1Literal("Test Item2");
+    QVERIFY(theItem->setLabel(NEW_ITEM_SECOND_NAME).result());
+    QCOMPARE(theItem->label().result(), NEW_ITEM_SECOND_NAME);
+    QVERIFY(theItem->modifiedTime().result() > oldModifiedTime);
+
+    auto theSecret = theItem->getSecret().result();
+    QCOMPARE(theSecret->value().toString(), NEW_ITEM_VALUE);
 }
 
 void KSecretServiceTest::cleanupTestCase()
 {
-    // TODO (if needed)
+    if (collection->isValid().result()) {
+        collection->deleteCollection();
+    }
 }
 
 #include "ksecretsservice-test.moc"
diff --git a/autotests/api/ksecretsservice-test.h b/autotests/api/ksecretsservice-test.h
index eee13f2..40222ea 100644
--- a/autotests/api/ksecretsservice-test.h
+++ b/autotests/api/ksecretsservice-test.h
@@ -33,7 +33,6 @@ private Q_SLOTS:
     void initTestCase();
     void testCreateAndDelete();
     void testRenameCollection();
-    void testCreateItem();
     void testItems();
     void cleanupTestCase();
 
diff --git a/src/api/ksecrets/ksecretscollection.cpp b/src/api/ksecrets/ksecretscollection.cpp
index 603686b..8954312 100644
--- a/src/api/ksecrets/ksecretscollection.cpp
+++ b/src/api/ksecrets/ksecretscollection.cpp
@@ -35,90 +35,105 @@ Collection::Collection()
     : QObject()
     , d(new CollectionPrivate(this))
 {
-  // nothing to do
+    // nothing to do
 }
 
 Collection::~Collection() {}
 
 QFuture<QList<CollectionPtr> > Collection::listCollections()
 {
-  return QtConcurrent::run(&CollectionPrivate::listCollections);
+    return QtConcurrent::run(&CollectionPrivate::listCollections);
 }
 
 Collection::Status Collection::status() const { return d->collectionStatus; }
 
 QFuture<bool> Collection::deleteCollection()
 {
-  return QtConcurrent::run(d.data(), &CollectionPrivate::deleteCollection);
+    return QtConcurrent::run(d.data(), &CollectionPrivate::deleteCollection);
 }
 
 QFuture<bool> Collection::renameCollection(const QString& newName)
 {
-  return QtConcurrent::run(
-      d.data(), &CollectionPrivate::renameCollection, newName);
+    return QtConcurrent::run(
+        d.data(), &CollectionPrivate::renameCollection, newName);
 }
 
 QFuture<QList<SecretItemPtr> > Collection::searchItems(
     const AttributesMap& attributes)
 {
-  return QtConcurrent::run(
-      d.data(), &CollectionPrivate::searchItems, attributes);
+    return QtConcurrent::run(
+        d.data(), &CollectionPrivate::searchItems, attributes);
+}
+
+QFuture<QList<SecretItemPtr> > Collection::searchItems(const QString&)
+{
+    AttributesMap attrs;
+    // TODO add here the label property
+    return searchItems(attrs);
+}
+
+QFuture<QList<SecretItemPtr> > Collection::searchItems(
+    const QString&, const AttributesMap& initialAttrs)
+{
+    AttributesMap attrs(initialAttrs);
+    // TODO add here the label property
+    return searchItems(attrs);
 }
 
 QFuture<QList<SecretPtr> > Collection::searchSecrets(
     const AttributesMap& attributes)
 {
-  return QtConcurrent::run(
-      d.data(), &CollectionPrivate::searchSecrets, attributes);
+    return QtConcurrent::run(
+        d.data(), &CollectionPrivate::searchSecrets, attributes);
 }
 
 QFuture<bool> Collection::createItem(const QString& label,
-    const QMap<QString, QString>& attributes, const Secret& secret,
+    const Secret& secret, const QMap<QString, QString>& attributes,
     CreateItemOptions options /* = DoNotReplaceExistingItem */)
 {
-  return QtConcurrent::run(d.data(), &CollectionPrivate::createItem, label,
-      attributes, secret, options);
+    return QtConcurrent::run(d.data(), &CollectionPrivate::createItem, label,
+        attributes, secret, options);
 }
 
 QFuture<QList<SecretItemPtr> > Collection::items() const
 {
-  return QtConcurrent::run(d.data(), &CollectionPrivate::items);
+    return QtConcurrent::run(d.data(), &CollectionPrivate::items);
 }
 
 QFuture<bool> Collection::isLocked() const
 {
-  return QtConcurrent::run(d.data(), &CollectionPrivate::isLocked);
+    return QtConcurrent::run(d.data(), &CollectionPrivate::isLocked);
 }
 
 QFuture<QString> Collection::label() const
 {
-  return QtConcurrent::run(d.data(), &CollectionPrivate::label);
+    return QtConcurrent::run(d.data(), &CollectionPrivate::label);
 }
 
 QFuture<QDateTime> Collection::createdTime() const
 {
-  return QtConcurrent::run(d.data(), &CollectionPrivate::createdTime);
+    return QtConcurrent::run(d.data(), &CollectionPrivate::createdTime);
 }
 
 QFuture<QDateTime> Collection::modifiedTime() const
 {
-  return QtConcurrent::run(d.data(), &CollectionPrivate::modifiedTime);
+    return QtConcurrent::run(d.data(), &CollectionPrivate::modifiedTime);
 }
 
 QFuture<bool> Collection::setLabel(const QString& label)
 {
-  return QtConcurrent::run(d.data(), &CollectionPrivate::writeProperty,
-      QLatin1Literal("Label"), QVariant(label));
+    return QtConcurrent::run(d.data(), &CollectionPrivate::writeProperty,
+        QLatin1Literal("Label"), QVariant(label));
 }
 
 QFuture<bool> Collection::lock()
 {
-  return QtConcurrent::run(d.data(), &CollectionPrivate::lock);
+    return QtConcurrent::run(d.data(), &CollectionPrivate::lock);
 }
 
 void Collection::emitStatusChanged()
 {
-  emit statusChanged(d->collectionStatus);
+    emit statusChanged(d->collectionStatus);
 }
 
 void Collection::emitContentsChanged() { emit contentsChanged(); }
@@ -135,114 +150,114 @@ CollectionPrivate::~CollectionPrivate() {}
 
 void CollectionPrivate::setStatus(Collection::Status newStatus)
 {
-  collectionStatus = newStatus;
-  collection->emitStatusChanged();
+    collectionStatus = newStatus;
+    collection->emitStatusChanged();
 }
 
 bool CollectionPrivate::isValid()
 {
-  // TODO figure out if something should be checked here
-  // otherways, let this like this as it'll be overriden in the dbus related
-  // class
-  return true;
+    // TODO figure out if something should be checked here
+    // otherways, let this like this as it'll be overriden in the dbus related
+    // class
+    return false;
 }
 
 QFuture<bool> Collection::isValid()
 {
-  return QtConcurrent::run(d.data(), &CollectionPrivate::isValid);
+    return QtConcurrent::run(d.data(), &CollectionPrivate::isValid);
 }
 
 bool CollectionPrivate::writeProperty(
     const QString& propName, const QVariant& propVal)
 {
-  // TODO
-  return false;
+    // TODO
+    return false;
 }
 
 bool CollectionPrivate::isNewlyCreated() const
 {
-  // TODO
-  return false;
+    // TODO
+    return false;
 }
 
 bool CollectionPrivate::lock()
 {
-  // TODO
-  return true;
+    // TODO
+    return true;
 }
 
 QList<CollectionPtr> CollectionPrivate::listCollections()
 {
-  // TODO
-  return QList<CollectionPtr>();
+    // TODO
+    return QList<CollectionPtr>();
 }
 
 bool CollectionPrivate::deleteCollection()
 {
-  // TODO
-  return true;
+    // TODO
+    return true;
 }
 
 bool CollectionPrivate::renameCollection(const QString&)
 {
-  // TODO
-  return true;
+    // TODO
+    return true;
 }
 
-QList<SecretItemPtr> CollectionPrivate::searchItems(const QStringMap&)
+QList<SecretItemPtr> CollectionPrivate::searchItems(const AttributesMap&)
 {
-  // TODO
-  return QList<SecretItemPtr>();
+    // TODO
+    return QList<SecretItemPtr>();
 }
 
-QList<SecretPtr> CollectionPrivate::searchSecrets(const QStringMap&)
+QList<SecretPtr> CollectionPrivate::searchSecrets(const AttributesMap&)
 {
-  // TODO
-  return QList<SecretPtr>();
+    // TODO
+    return QList<SecretPtr>();
 }
 
 bool CollectionPrivate::createItem(const QString& label,
     const AttributesMap& attributes, const Secret& secret,
     CreateItemOptions options)
 {
-  // TODO
-  return true;
+    // TODO
+    return true;
 }
 
 bool CollectionPrivate::isLocked()
 {
-  // TODO
-  return false;
+    // TODO
+    return false;
 }
 
 QString CollectionPrivate::label()
 {
-  // TODO
-  return QLatin1Literal("");
+    // TODO
+    return QLatin1Literal("");
 }
 
 bool CollectionPrivate::setLabel(const QString&)
 {
-  // TODO
-  return true;
+    // TODO
+    return true;
 }
 
 QDateTime CollectionPrivate::createdTime()
 {
-  // TODO
-  return QDateTime();
+    // TODO
+    return QDateTime();
 }
 
 QDateTime CollectionPrivate::modifiedTime()
 {
-  // TODO
-  return QDateTime();
+    // TODO
+    return QDateTime();
 }
 
 QList<SecretItemPtr> CollectionPrivate::items() const
 {
-  // TODO
-  return QList<SecretItemPtr>();
+    // TODO
+    return QList<SecretItemPtr>();
 }
 
 #include "ksecretscollection.moc"
diff --git a/src/api/ksecrets/ksecretscollection.h b/src/api/ksecrets/ksecretscollection.h
index cb1daf6..769ba02 100644
--- a/src/api/ksecrets/ksecretscollection.h
+++ b/src/api/ksecrets/ksecretscollection.h
@@ -49,206 +49,224 @@ typedef QSharedPointer<Collection> CollectionPtr;
  * and encrypted storage.
  */
 class KSECRETS_EXPORT Collection : public QObject {
-  Q_OBJECT
-  Q_DISABLE_COPY(Collection)
-  public:
-  virtual ~Collection();
-
-  /**
-   * @see status()
-   * @see statusChanged()
-   */
-  enum Status {
-    Invalid = 0, /// the collection objet is freshly initialized and none of
-                 /// it's methods have been called
-    Pending = 1, /// one of the collection methods was called but this object
-                 /// is yet to be connected to the backed
-    FoundExisting
-    = 2, /// this object is connected to an existing backend connection
-    NewlyCreated
-    = 3,          /// this object is connected to a newly created connection
-    NotFound = 4, /// the collection was not found
-    Deleted = 5   /// the collection was deleted. Calling methods in such a
-                  /// collection would lead to unpredictable results
-  };
-
-  /**
-   * Use this method to find out the names of all known secret service
-   * collections on the running system
-   */
-  static QFuture< QList<CollectionPtr> > listCollections();
-
-  /**
-   * This will get the actual findStatus of this collection
-   * @return Status
-   */
-  Status status() const;
-
-  /**
-   * Try to delete this collection. The user might be prompted to confirm that
-   * and as such he/she may choose not to confirm that operation.
-   *
-   * Please note that after successufully calling this method, this object
-   * is no longer valid and calling other methods on it would lead to
-   *undefined
-   * behaviour
-   */
-  QFuture<bool> deleteCollection();
-
-  /**
-   * Change the name of this collection
-   * @param newName is the new collection's name
-   */
-  QFuture<bool> renameCollection(const QString& newName);
-
-  /**
-   * Search for the items matching the specified attributes
-   * KSecrets uses overall the following standard attributes:
-   * "Label" : item's or collection's label
-   *
-   * @param attributes hold the searched items attributes
-   * You may want to initialize the map followin one of the followin cases:
-   * @li put in empty strings such as
-   * @code
-   * StrinStringMap attrs;
-   * attrs["Key"] = "";
-   * @endcode
-   * This will match all attributes having the key "Key"
-   * @li use search string as values,
-   * @code
-   * StrinStringMap attrs;
-   * attrs["Key"] = "string";
-   * @endcode
-   * This will try to exactly match "string" when finding items having "key"
-   *attributes
-   * @li use regular expressions
-   * @code
-   * StrinStringMap attrs;
-   * attrs["Key"] = "regexp:expr";
-   * @endcode
-   * This will find items having "Key" attribute, then will use the expr to do
-   *a QRegExp match
-   * against attribute values
-   *
-   * @return QFuture whose method results() will bring all the items found
-   *
-   */
-  QFuture<QList<SecretItemPtr> > searchItems(const StringStringMap &attributes);
-
-  /**
-   * Use this method to get several secrets without getting through getting
-   * items
-   */
-  QFuture<QList<SecretPtr> > searchSecrets(
-      const StringStringMap& attributes);
-
-  /**
-   * Create a new item inside the current collection
-   * @param label holds the item's label; this label will be automatically
-   *added to the attributes map under the index "Label" and it'll eventually
-   *replace an existing item on that slot
-   * @param attributes holds an map of property names / property values
-   * @param secret the secret the newly created item should hold
-   * @param replace true if the and eventually existing secret is to be
-   *replaced by the on specified here
-   *
-   * @see SecretItem
-   */
-  QFuture<bool> createItem(const QString& label,
-      const StringStringMap& attributes, const Secret& secret,
-      CreateItemOptions options = DoNotReplaceExistingItem);
-
-  /**
-   * Retrieve items stored inside this collection
-   */
-  QFuture<QList<SecretItemPtr> > items() const;
-
-  /**
-   * Retrieve the lock status of this collection
-   */
-  QFuture<bool> isLocked() const;
-
-  /**
-   * Retrieve this collection's label
-   */
-  QFuture<QString> label() const;
-
-  /**
-   * Get the creation timestamps of this collection
-   */
-  QFuture<QDateTime> createdTime() const;
-
-  /**
-   * Get the last modified timestamp of this collection
-   */
-  QFuture<QDateTime> modifiedTime() const;
-
-  /**
-   * Change this collection's label
-   */
-  QFuture<bool> setLabel(const QString& label);
-
-  /**
-   */
-  QFuture<bool> isValid();
-
-  /**
-   * Request collection lock. Locked collection's contents cannot be changed.
-   */
-  QFuture<bool> lock();
+    Q_OBJECT
+    Q_DISABLE_COPY(Collection)
+public:
+    virtual ~Collection();
+
+    /**
+     * @see status()
+     * @see statusChanged()
+     */
+    enum Status {
+        Invalid
+        = 0, /// the collection objet is freshly initialized and none of
+             /// it's methods have been called
+        Pending
+        = 1, /// one of the collection methods was called but this object
+             /// is yet to be connected to the backed
+        FoundExisting
+        = 2, /// this object is connected to an existing backend connection
+        NewlyCreated
+        = 3, /// this object is connected to a newly created connection
+        NotFound = 4, /// the collection was not found
+        Deleted = 5 /// the collection was deleted. Calling methods in such a
+                    /// collection would lead to unpredictable results
+    };
+
+    /**
+     * Use this method to find out the names of all known secret service
+     * collections on the running system
+     */
+    static QFuture<QList<CollectionPtr> > listCollections();
+
+    /**
+     * This will get the actual findStatus of this collection
+     * @return Status
+     */
+    Status status() const;
+
+    /**
+     * Try to delete this collection. The user might be prompted to confirm
+     *that
+     * and as such he/she may choose not to confirm that operation.
+     *
+     * Please note that after successufully calling this method, this object
+     * is no longer valid and calling other methods on it would lead to
+     *undefined
+     * behaviour
+     */
+    QFuture<bool> deleteCollection();
+
+    /**
+     * Change the name of this collection
+     * @param newName is the new collection's name
+     */
+    QFuture<bool> renameCollection(const QString& newName);
+
+    /**
+     * Search for the items matching the specified attributes
+     * KSecrets uses overall the following standard attributes:
+     * "Label" : item's or collection's label
+     *
+     * @param attributes hold the searched items attributes
+     * You may want to initialize the map followin one of the followin cases:
+     * @li put in empty strings such as
+     * @code
+     * StrinStringMap attrs;
+     * attrs["Key"] = "";
+     * @endcode
+     * This will match all attributes having the key "Key"
+     * @li use search string as values,
+     * @code
+     * StrinStringMap attrs;
+     * attrs["Key"] = "string";
+     * @endcode
+     * This will try to exactly match "string" when finding items having "key"
+     *attributes
+     * @li use regular expressions
+     * @code
+     * StrinStringMap attrs;
+     * attrs["Key"] = "regexp:expr";
+     * @endcode
+     * This will find items having "Key" attribute, then will use the expr to
+     *do
+     *a QRegExp match
+     * against attribute values
+     *
+     * @return QFuture whose method results() will bring all the items found
+     *
+     */
+    QFuture<QList<SecretItemPtr> > searchItems(
+        const AttributesMap& attributes);
+
+    QFuture<QList<SecretItemPtr> > searchItems(const QString& label);
+
+    QFuture<QList<SecretItemPtr> > searchItems(
+        const QString& label, const AttributesMap& attributes);
+
+    /**
+     * Use this method to get several secrets without getting through getting
+     * items
+     */
+    QFuture<QList<SecretPtr> > searchSecrets(
+        const StringStringMap& attributes);
+
+    /**
+     * Create a new item inside the current collection
+     * @param label holds the item's label
+     * this label will be automatically
+     * added to the attributes map under the index "Label" and it'll
+     *eventually
+     * replace an existing item on that slot
+     * @param attributes holds an map of property names / property values
+     * @param secret the secret the newly created item should hold
+     * @param replace true if the and eventually existing secret is to be
+     *replaced by the on specified here
+     *
+     * @see SecretItem
+     */
+    QFuture<bool> createItem(const QString& label, const Secret& secret,
+        const AttributesMap& attributes = AttributesMap(),
+        CreateItemOptions options = DoNotReplaceExistingItem);
+
+    /**
+     * Retrieve items stored inside this collection
+     */
+    QFuture<QList<SecretItemPtr> > items() const;
+
+    /**
+     * Retrieve the lock status of this collection
+     */
+    QFuture<bool> isLocked() const;
+
+    /**
+     * Retrieve this collection's label
+     */
+    QFuture<QString> label() const;
+
+    /**
+     * Get the creation timestamps of this collection
+     */
+    QFuture<QDateTime> createdTime() const;
+
+    /**
+     * Get the last modified timestamp of this collection
+     */
+    QFuture<QDateTime> modifiedTime() const;
+
+    /**
+     * Change this collection's label
+     */
+    QFuture<bool> setLabel(const QString& label);
+
+    /**
+     * Applications should check this before attempting other operations on
+     *this
+     * collection.
+     *
+     * @return true if the collection is actually connected to its backend
+     */
+    QFuture<bool> isValid();
+
+    /**
+     * Request collection lock. Locked collection's contents cannot be
+     * changed.
+     */
+    QFuture<bool> lock();
 
 Q_SIGNALS:
-  /**
-   * This signal is emmited with any collection status change.
-   * Please cast the given integer to the Status type
-   * @see Status
-   */
-  void statusChanged(int);
-  /**
-   * This signal is emmited when one of the collection's attributes changed or
-   * when one
-   * of the contained items changed
-   */
-  void contentsChanged();
-  /**
-   * This signal is emmited when the collection was effectively deleted by the
-   * delete job
-   * Calling other methods on this collection instance after this signal was
-   * emmited is undefined and
-   * may lead to unpredictable results.
-   */
-  void deleted();
-  /**
-   * TODO: not yet implemented
-   */
-  void itemCreated(const KSecrets::SecretItem&);
-  /**
-   * TODO: not yet implemented
-   */
-  void itemDeleted(const QString& itemLabel);
-  /**
-   * TODO: not yet implemented
-   */
-  void itemChanged(const KSecrets::SecretItem&);
-
-  protected:
-  friend class ServicePrivate; // collections are instantiated from the service only
-  explicit Collection();
-
-  private:
-  explicit Collection(CollectionPrivate*);
-
-  private:
-  friend class CollectionPrivate;
-
-  /** @internal */
-  void emitStatusChanged();
-  /** @internal */
-  void emitContentsChanged();
-  /** @internal */
-  void emitDeleted();
-
-  QSharedPointer<CollectionPrivate> d;
+    /**
+     * This signal is emmited with any collection status change.
+     * Please cast the given integer to the Status type
+     * @see Status
+     */
+    void statusChanged(int);
+    /**
+     * This signal is emmited when one of the collection's attributes changed
+     * or
+     * when one
+     * of the contained items changed
+     */
+    void contentsChanged();
+    /**
+     * This signal is emmited when the collection was effectively deleted by
+     * the
+     * delete job
+     * Calling other methods on this collection instance after this signal was
+     * emmited is undefined and
+     * may lead to unpredictable results.
+     */
+    void deleted();
+    /**
+     */
+    void itemCreated(const KSecrets::SecretItem&);
+    /**
+     */
+    void itemDeleted(const QString& itemLabel);
+    /**
+     */
+    void itemChanged(const KSecrets::SecretItem&);
+
+protected:
+    friend class ServicePrivate; // collections are instantiated from the
+                                 // service only
+    explicit Collection();
+
+private:
+    explicit Collection(CollectionPrivate*);
+
+private:
+    friend class CollectionPrivate;
+
+    /** @internal */
+    void emitStatusChanged();
+    /** @internal */
+    void emitContentsChanged();
+    /** @internal */
+    void emitDeleted();
+
+    QSharedPointer<CollectionPrivate> d;
 };
 
 }; // namespace
diff --git a/src/api/ksecrets/ksecretscollection_p.h b/src/api/ksecrets/ksecretscollection_p.h
index 8900502..dec4c99 100644
--- a/src/api/ksecrets/ksecretscollection_p.h
+++ b/src/api/ksecrets/ksecretscollection_p.h
@@ -32,8 +32,6 @@ class OrgFreedesktopSecretCollectionInterface;
 
 namespace KSecrets {
 
-typedef QMap<QString, QString> QStringMap;
-
 class CollectionPrivate {
   public:
   explicit CollectionPrivate(Collection*);
@@ -47,9 +45,9 @@ class CollectionPrivate {
   static QList<CollectionPtr> listCollections();
   bool deleteCollection();
   bool renameCollection(const QString&);
-  QList<SecretItemPtr> searchItems(const QStringMap&);
-  QList<SecretPtr> searchSecrets(const QStringMap&);
-  bool createItem(const QString& label, const QStringMap& attributes,
+  QList<SecretItemPtr> searchItems(const AttributesMap&);
+  QList<SecretPtr> searchSecrets(const AttributesMap&);
+  bool createItem(const QString& label, const AttributesMap& attributes,
       const Secret& secret, CreateItemOptions options);
   QList<SecretItemPtr> items() const;
   bool isLocked();
diff --git a/src/api/ksecrets/ksecretsservice.h b/src/api/ksecrets/ksecretsservice.h
index 702e60b..a1be890 100644
--- a/src/api/ksecrets/ksecretsservice.h
+++ b/src/api/ksecrets/ksecretsservice.h
@@ -31,6 +31,18 @@ namespace KSecrets {
 
 class ServicePrivate;
 
+/**
+ * KSecrets Service entry point.
+ *
+ * KDE applications use this class to actually handle their secrets.
+ * This class would do the magic of connecting to the right backend
+ * and store or retrieve the secrets.
+ *
+ * We encourage you to first read the Free Desktop draft about
+ * <a href="http://standards.freedesktop.org/secret-service/">Secret Service</a>
+ *
+ *
+ */
 class KSECRETS_EXPORT Service : public QObject {
   Q_OBJECT
   Q_DISABLE_COPY(Service)
@@ -39,39 +51,15 @@ class KSECRETS_EXPORT Service : public QObject {
 
   /**
    * Options used when findCollection method is called
-   * TODO add an option to allow searching into the KWallet
    */
   enum FindCollectionOptions {
-    OpenOnly = 0,        /// this will only try to open the collection without
-                         /// creating it if not found
-    CreateCollection = 1, /// the collection will be created if not found
+    OpenOnly = 0,           /// this will only try to open the collection without
+                            /// creating it if not found
+    CreateCollection = 1,   /// the collection will be created if not found
+    LookIntoKWallet = 2     /// Specify this if your application was ported from KWallet to KSecrets
   };
 
   /**
-   * This will try to find a collection given its name. If not found, it'll
-   * create it depending on the
-   * options given.
-   * @param collectionName collection name to be found
-   * @param options @see FindCollectionOptions
-   * @param collectionProperties specify collection properties and it's
-   * semantics depends on the options parameter
-   *      if options == CreateCollection, then the newly created collection
-   * will receive these properties
-   *      if options == OpenOnly, then the properties are used to match the
-   * existing collection so be careful
-   *                              not to specify a property not given when
-   * creation a collection or you'll not be
-   *                              able to find it with this method
-   * @param promptParentWindowId identifies the applications window to be used
-   * as a parent for prompt windows
-   * @return Collection instance to be used by the client application to
-   * further manipulated it's secrets
-   * @note Please note that the collection returned by this method is not yet
-   * connected to the secret storing
-   * infrastructure. As such, a NotFound status would not be immediatley
-   * known. Application should be prepared
-   * to get such an error upon the execution of the first KJob returned by one
-   * of the other methods of this class.
    */
   static QFuture<CollectionPtr> findCollection(const QString& collectionName,
       FindCollectionOptions options = CreateCollection,
@@ -81,6 +69,7 @@ class KSECRETS_EXPORT Service : public QObject {
   private:
   QSharedPointer<ServicePrivate> d;
 };
-}
+
+} // namespace
 
 #endif
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic