[Pkg-owncloud-commits] [qtkeychain] 28/115: Refactor API to asynchronous job-based classes. As all Linux solutions will require async calls to DBus etc., they'd have to use local event loops otherwise.
Sandro Knauß
hefee-guest at moszumanska.debian.org
Sat Mar 15 19:25:43 UTC 2014
This is an automated email from the git hooks/post-receive script.
hefee-guest pushed a commit to branch master
in repository qtkeychain.
commit 2b6e40b992d80ba11fe277c735ced1cced8a6d0e
Author: Frank Osterfeld <frank.osterfeld at kdab.com>
Date: Thu Apr 5 16:16:22 2012 +0200
Refactor API to asynchronous job-based classes.
As all Linux solutions will require async calls to DBus etc., they'd have to use local event loops otherwise.
---
keychain.cpp | 129 +++++++++++++++++++++++++++++++++++++-
keychain.h | 181 +++++++++++++++++++++++-------------------------------
keychain_dbus.cpp | 8 +--
keychain_mac.cpp | 115 +++++++++++++++++-----------------
keychain_p.h | 162 ++++++++++++++++++++++++++++++++++++++++++++++--
keychain_win.cpp | 8 +--
testclient.cpp | 43 +++++++++----
7 files changed, 455 insertions(+), 191 deletions(-)
diff --git a/keychain.cpp b/keychain.cpp
index b4455b1..1c691e4 100644
--- a/keychain.cpp
+++ b/keychain.cpp
@@ -11,9 +11,130 @@
using namespace QKeychain;
+Job::Job( const QString& service, QObject *parent )
+ : QObject( parent )
+ , d ( new Private( service ) ) {
+}
+
+Job::~Job() {
+ delete d;
+}
+
+QString Job::service() const {
+ return d->service;
+}
+
+QSettings* Job::settings() const {
+ return d->settings;
+}
+
+void Job::setSettings( QSettings* settings ) {
+ d->settings = settings;
+}
+
+void Job::start() {
+ QMetaObject::invokeMethod( this, "doStart", Qt::QueuedConnection );
+}
+
+bool Job::autoDelete() const {
+ return d->autoDelete;
+}
+
+void Job::setAutoDelete( bool autoDelete ) {
+ d->autoDelete = autoDelete;
+}
+
+void Job::emitFinished() {
+ emit finished( this );
+ if ( d->autoDelete )
+ deleteLater();
+}
+
+void Job::emitFinishedWithError( Error error, const QString& errorString ) {
+ d->error = error;
+ d->errorString = errorString;
+ emitFinished();
+}
+
+Error Job::error() const {
+ return d->error;
+}
+
+QString Job::errorString() const {
+ return d->errorString;
+}
+
+void Job::setError( Error error ) {
+ d->error = error;
+}
+
+void Job::setErrorString( const QString& errorString ) {
+ d->errorString = errorString;
+}
+
+ReadPasswordJob::ReadPasswordJob( const QString& service, QObject* parent )
+ : Job( service, parent )
+ , d( new Private( this ) )
+{}
+
+ReadPasswordJob::~ReadPasswordJob() {
+ delete d;
+}
+
+QString ReadPasswordJob::textData() const {
+ return QString::fromUtf8( d->data );
+}
+
+QByteArray ReadPasswordJob::binaryData() const {
+ return d->data;
+}
+
+QString ReadPasswordJob::key() const {
+ return d->key;
+}
+
+void ReadPasswordJob::setKey( const QString& key ) {
+ d->key = key;
+}
+
+void ReadPasswordJob::doStart() {
+ d->doStart();
+}
+
+WritePasswordJob::WritePasswordJob( const QString& service, QObject* parent )
+ : Job( service, parent )
+ , d( new Private( this ) ) {
+}
+
+WritePasswordJob::~WritePasswordJob() {
+ delete d;
+}
+
+QString WritePasswordJob::key() const {
+ return d->key;
+}
+
+void WritePasswordJob::setKey( const QString& key ) {
+ d->key = key;
+}
+
+void WritePasswordJob::setBinaryData( const QByteArray& data ) {
+ d->binaryData = data;
+ d->mode = Private::Binary;
+}
+
+void WritePasswordJob::setTextData( const QString& data ) {
+ d->textData = data;
+ d->mode = Private::Text;
+}
+
+void WritePasswordJob::doStart() {
+ d->doStart();
+}
+
+#if 0
Keychain::Keychain( const QString& service, QSettings* settings )
- : d( new Private( service, settings ) )
-{
+ : d( new Private( service, settings ) ) {
Q_ASSERT( !service.isEmpty() );
}
@@ -25,7 +146,7 @@ QString Keychain::service() const {
return d->service;
}
-Keychain::Error Keychain::error() const {
+QKeychain::Error Keychain::error() const {
return d->error;
}
@@ -76,3 +197,5 @@ void Keychain::deleteEntry( const QString& key ) {
d->error = ret;
d->errorString = err;
}
+
+#endif
diff --git a/keychain.h b/keychain.h
index 13cc052..5ddb0bb 100644
--- a/keychain.h
+++ b/keychain.h
@@ -11,127 +11,100 @@
#include "qkeychain_export.h"
+#include <QtCore/QObject>
#include <QtCore/QString>
class QSettings;
namespace QKeychain {
+
/**
- * Provides access to platform-specific key stores for secure persistence of
- * passwords and other sensitive user data.
- *
- * On Windows, TODO
- * On Mac OS X, the OS X keychain is used.
- * On other Unixes, TODO
- *
- * TODO we don't guarantee anything
+ * Error codes
*/
-class QKEYCHAIN_EXPORT Keychain {
+enum Error {
+ NoError=0, /**< No error occurred, operation was successful */
+ EntryNotFound, /**< For the given key no data was found */
+ CouldNotDeleteEntry, /**< Could not delete existing secret data */
+ AccessDeniedByUser, /**< User denied access to keychain */
+ AccessDenied, /**< Access denied for other reasons */
+ EntryAlreadyExists, /**< There is already an entry for the given key and overwriting was not enforced */
+ NotImplemented, /**< Not implemented on platform */
+ OtherError /**< Something else went wrong (errorString() might provide details) */
+};
+
+class QKEYCHAIN_EXPORT Job : public QObject {
+ Q_OBJECT
public:
- /**
- * Creates a Keychain object.
- *
- * @param service The service name of your service/application. Used as identifier,
- * to disambiguate keys and avoid clashes with other applications.
- * Must not be empty.
- * @param settings An optional settings object that is used to store the encrypted data
- * if no keychain is available on the platform. Currently only used on Windows.
- * If 0, a default-constructed QSettings object will be used.
- */
- explicit Keychain( const QString& service, QSettings* settings=0 );
-
- /**
- * Destructor
- */
- ~Keychain();
-
- /**
- * Error codes
- */
- enum Error {
- NoError=0, /**< No error occurred, operation was successful */
- EntryNotFound, /**< For the given key no data was found */
- CouldNotDeleteEntry, /**< Could not delete existing secret data */
- AccessDeniedByUser, /**< User denied access to keychain */
- AccessDenied, /**< Access denied for other reasons */
- EntryAlreadyExists, /**< There is already an entry for the given key and overwriting was not enforced */
- NotImplemented, /**< Not implemented on platform */
- OtherError /**< Something else went wrong (errorString() might provide details) */
- };
-
- /**
- * The service name used as identifier.
- */
+ explicit Job( const QString& service, QObject* parent=0 );
+ ~Job();
+
+ QSettings* settings() const;
+ void setSettings( QSettings* settings );
+
+ void start();
+
QString service() const;
- /**
- * The error code of the last operation.
- */
Error error() const;
-
- /**
- * Human-readable error description of the last operation.
- */
QString errorString() const;
- /**
- * Stores a @p password in the keychain, for a given @p key.
- * error() and errorString() hold the result of the write operation.
- *
- * @param key the key to store a password for
- * @param password the password to store
- * @param om Whether to overwrite existing passwords
- */
- void writePassword( const QString& key,
- const QString& password );
-
- /**
- * Stores @p data in the keychain, for a given @p key.
- * error() and errorString() hold the result of the write operation.
- *
- * @param key the key to store a password for
- * @param data the data to store
- * @param om Whether to overwrite existing passwords
- */
- void writeEntry( const QString& key,
- const QByteArray& data );
-
- /**
- * Reads the password for a given @p key from the keychain.
- * error() and errorString() hold the result of the read operation.
- *
- * @param key the key to read the password for
- */
- QString readPassword( const QString& key );
-
- /**
- * Reads data for a given @p key from the keychain.
- * error() and errorString() hold the result of the read operation.
- *
- * @param key the key to read the password for
- */
- QByteArray readEntry( const QString& key );
-
- /**
- * Returns whether the keychain has an entry with key @p key
- * error() and errorString() hold the result of the read operation.
- *
- * @param key the key to check for
- */
- bool entryExists( const QString& key );
-
- /**
- * Deletes the data for a @p key from the keychain.
- * error() and errorString() hold the result of the delete operation.
- *
- * @param key The key to delete the data for
- */
- void deleteEntry( const QString& key );
+ bool autoDelete() const;
+ void setAutoDelete( bool autoDelete );
+
+Q_SIGNALS:
+ void finished( QKeychain::Job* );
+
+protected:
+ Q_INVOKABLE virtual void doStart() = 0;
+
+ void setError( Error error );
+ void setErrorString( const QString& errorString );
+ void emitFinished();
+ void emitFinishedWithError(Error, const QString& errorString);
+
+private:
+ class Private;
+ Private* const d;
+};
+
+class QKEYCHAIN_EXPORT ReadPasswordJob : public Job {
+ Q_OBJECT
+public:
+ explicit ReadPasswordJob( const QString& service, QObject* parent=0 );
+ ~ReadPasswordJob();
+
+ QString key() const;
+ void setKey( const QString& key );
+
+ QByteArray binaryData() const;
+ QString textData() const;
+
+protected:
+ void doStart();
+
+private:
+ class Private;
+ Private* const d;
+};
+
+class QKEYCHAIN_EXPORT WritePasswordJob : public Job {
+ Q_OBJECT
+public:
+ explicit WritePasswordJob( const QString& service, QObject* parent=0 );
+ ~WritePasswordJob();
+
+ QString key() const;
+ void setKey( const QString& key );
+
+ void setBinaryData( const QByteArray& data );
+ void setTextData( const QString& data );
+
+protected:
+ void doStart();
private:
class Private;
Private* const d;
- Q_DISABLE_COPY(Keychain)
};
}
diff --git a/keychain_dbus.cpp b/keychain_dbus.cpp
index 3c1fde7..6c67f7c 100644
--- a/keychain_dbus.cpp
+++ b/keychain_dbus.cpp
@@ -12,7 +12,7 @@
using namespace QKeychain;
-Keychain::Error Keychain::Private::readEntryImpl( QByteArray* pw,
+QKeychain::Error Keychain::Private::readEntryImpl( QByteArray* pw,
const QString& key,
QString* err ) {
Q_UNUSED( key )
@@ -21,14 +21,14 @@ Keychain::Error Keychain::Private::readEntryImpl( QByteArray* pw,
return NotImplemented;
}
-Keychain::Error Keychain::Private::writeEntryImpl( const QString& key,
+QKeychain::Error Keychain::Private::writeEntryImpl( const QString& key,
const QByteArray& data_,
QString* err ) {
Q_ASSERT( err );
return NotImplemented;
}
-Keychain::Error Keychain::Private::deleteEntryImpl( const QString& key,
+QKeychain::Error Keychain::Private::deleteEntryImpl( const QString& key,
QString* err ) {
Q_ASSERT( err );
err->clear();
@@ -36,7 +36,7 @@ Keychain::Error Keychain::Private::deleteEntryImpl( const QString& key,
}
-Keychain::Error Keychain::Private::entryExistsImpl( bool* exists,
+QKeychain::Error Keychain::Private::entryExistsImpl( bool* exists,
const QString& key,
QString* err ) {
Q_ASSERT( exists );
diff --git a/keychain_mac.cpp b/keychain_mac.cpp
index b835f13..d81ecf5 100644
--- a/keychain_mac.cpp
+++ b/keychain_mac.cpp
@@ -61,28 +61,54 @@ static OSStatus readPw( QByteArray* pw,
return ret;
}
-Keychain::Error Keychain::Private::readEntryImpl( QByteArray* pw,
- const QString& account,
- QString* err ) {
- Q_ASSERT( pw );
- Q_ASSERT( err );
- err->clear();
- const OSStatus ret = readPw( pw, service, account, 0 );
+void ReadPasswordJob::Private::doStart()
+{
+ QString errorString;
+ Error error = NoError;
+ const OSStatus ret = readPw( &data, q->service(), q->key(), 0 );
+
switch ( ret ) {
case noErr:
- return NoError;
+ break;
case errSecItemNotFound:
- *err = tr("Password not found");
- return EntryNotFound;
+ errorString = tr("Password not found");
+ error = EntryNotFound;
+ break;
default:
- *err = strForStatus( ret );
+ errorString = strForStatus( ret );
+ error = OtherError;
+ break;
+ }
+ q->emitFinishedWithError( error, errorString );
+}
+
+
+static QKeychain::Error deleteEntryImpl( const QString& service, const QString& account, QString* err ) {
+ SecKeychainItemRef ref;
+ QByteArray pw;
+ const OSStatus ret1 = readPw( &pw, service, account, &ref );
+ if ( ret1 == errSecItemNotFound )
+ return NoError; // No item stored, we're done
+ if ( ret1 != noErr ) {
+ *err = strForStatus( ret1 );
+ //TODO map error code, set errstr
return OtherError;
}
+ const Releaser<SecKeychainItemRef> releaser( ref );
+
+ const OSStatus ret2 = SecKeychainItemDelete( ref );
+
+ if ( ret2 == noErr )
+ return NoError;
+ //TODO map error code
+ *err = strForStatus( ret2 );
+ return CouldNotDeleteEntry;
}
-Keychain::Error Keychain::Private::writeEntryImpl( const QString& account,
- const QByteArray& data,
- QString* err ) {
+static QKeychain::Error writeEntryImpl( const QString& service,
+ const QString& account,
+ const QByteArray& data,
+ QString* err ) {
Q_ASSERT( err );
err->clear();
const QByteArray serviceData = service.toUtf8();
@@ -100,11 +126,11 @@ Keychain::Error Keychain::Private::writeEntryImpl( const QString& account,
switch ( ret ) {
case errSecDuplicateItem:
{
- Error derr = deleteEntryImpl( account, err );
+ Error derr = deleteEntryImpl( service, account, err );
if ( derr != NoError )
return CouldNotDeleteEntry;
else
- return writeEntryImpl( account, data, err );
+ return writeEntryImpl( service, account, data, err );
}
default:
*err = strForStatus( ret );
@@ -115,48 +141,19 @@ Keychain::Error Keychain::Private::writeEntryImpl( const QString& account,
return NoError;
}
-Keychain::Error Keychain::Private::deleteEntryImpl( const QString& account,
- QString* err ) {
- SecKeychainItemRef ref;
- QByteArray pw;
- const OSStatus ret1 = readPw( &pw, service, account, &ref );
- if ( ret1 == errSecItemNotFound )
- return NoError; // No item stored, we're done
- if ( ret1 != noErr ) {
- *err = strForStatus( ret1 );
- //TODO map error code, set errstr
- return OtherError;
+void WritePasswordJob::Private::doStart()
+{
+ QString errorString;
+ Error error = NoError;
+
+ if ( mode == Delete ) {
+ const Error derr = deleteEntryImpl( q->service(), key, &errorString );
+ if ( derr != NoError )
+ error = CouldNotDeleteEntry;
+ q->emitFinishedWithError( error, errorString );
+ return;
}
- const Releaser<SecKeychainItemRef> releaser( ref );
-
- const OSStatus ret2 = SecKeychainItemDelete( ref );
-
- if ( ret2 == noErr )
- return NoError;
- //TODO map error code
- *err = strForStatus( ret2 );
- return CouldNotDeleteEntry;
-}
-
-
-Keychain::Error Keychain::Private::entryExistsImpl( bool* exists,
- const QString& account,
- QString* err ) {
- Q_ASSERT( exists );
- *exists = false;
- SecKeychainItemRef ref;
- QByteArray pw;
- const OSStatus ret1 = readPw( &pw, service, account, &ref );
- if ( ret1 == errSecItemNotFound ) {
- return NoError;
- }
- if ( ret1 != noErr ) {
- *err = strForStatus( ret1 );
- //TODO map error code, set errstr
- return OtherError;
- }
-
- CFRelease( ref );
- *exists = true;
- return NoError;
+ const QByteArray data = mode == Text ? textData.toUtf8() : binaryData;
+ error = writeEntryImpl( q->service(), key, data, &errorString );
+ q->emitFinishedWithError( error, errorString );
}
diff --git a/keychain_p.h b/keychain_p.h
index 316388b..821287c 100644
--- a/keychain_p.h
+++ b/keychain_p.h
@@ -10,34 +10,186 @@
#define KEYCHAIN_P_H
#include <QCoreApplication>
+#include <QObject>
#include <QPointer>
#include <QSettings>
#include "keychain.h"
namespace QKeychain {
+
+class Job::Private : public QObject {
+ Q_OBJECT
+public:
+ Private( const QString& service_ )
+ : error( NoError )
+ , service( service_ )
+ , autoDelete( true ) {}
+
+ QKeychain::Error error;
+ QString errorString;
+ QString service;
+ bool autoDelete;
+ QPointer<QSettings> settings;
+};
+
+class ReadPasswordJob::Private : public QObject {
+ Q_OBJECT
+public:
+ explicit Private( ReadPasswordJob* qq ) : q( qq ) {}
+ void doStart();
+ ReadPasswordJob* const q;
+ QByteArray data;
+ QString key;
+};
+
+class WritePasswordJob::Private : public QObject {
+ Q_OBJECT
+public:
+ explicit Private( WritePasswordJob* qq ) : q( qq ), mode( Delete ) {}
+ void doStart();
+ enum Mode {
+ Delete,
+ Text,
+ Binary
+ };
+ WritePasswordJob* const q;
+ Mode mode;
+ QString key;
+ QByteArray binaryData;
+ QString textData;
+};
+
+#if 0
+/**
+ * Provides access to platform-specific key stores for secure persistence of
+ * passwords and other sensitive user data.
+ *
+ * On Windows, TODO
+ * On Mac OS X, the OS X keychain is used.
+ * On other Unixes, TODO
+ *
+ * TODO we don't guarantee anything
+ */
+class Keychain {
+public:
+ /**
+ * Creates a Keychain object.
+ *
+ * @param service The service name of your service/application. Used as identifier,
+ * to disambiguate keys and avoid clashes with other applications.
+ * Must not be empty.
+ * @param settings An optional settings object that is used to store the encrypted data
+ * if no keychain is available on the platform. Currently only used on Windows.
+ * If 0, a default-constructed QSettings object will be used.
+ */
+ explicit Keychain( const QString& service, QSettings* settings=0 );
+
+ /**
+ * Destructor
+ */
+ ~Keychain();
+
+ /**
+ * The service name used as identifier.
+ */
+ QString service() const;
+
+ /**
+ * The error code of the last operation.
+ */
+ Error error() const;
+
+ /**
+ * Human-readable error description of the last operation.
+ */
+ QString errorString() const;
+
+ /**
+ * Stores a @p password in the keychain, for a given @p key.
+ * error() and errorString() hold the result of the write operation.
+ *
+ * @param key the key to store a password for
+ * @param password the password to store
+ * @param om Whether to overwrite existing passwords
+ */
+ void writePassword( const QString& key,
+ const QString& password );
+
+ /**
+ * Stores @p data in the keychain, for a given @p key.
+ * error() and errorString() hold the result of the write operation.
+ *
+ * @param key the key to store a password for
+ * @param data the data to store
+ * @param om Whether to overwrite existing passwords
+ */
+ void writeEntry( const QString& key,
+ const QByteArray& data );
+
+ /**
+ * Reads the password for a given @p key from the keychain.
+ * error() and errorString() hold the result of the read operation.
+ *
+ * @param key the key to read the password for
+ */
+ QString readPassword( const QString& key );
+
+ /**
+ * Reads data for a given @p key from the keychain.
+ * error() and errorString() hold the result of the read operation.
+ *
+ * @param key the key to read the password for
+ */
+ QByteArray readEntry( const QString& key );
+
+ /**
+ * Returns whether the keychain has an entry with key @p key
+ * error() and errorString() hold the result of the read operation.
+ *
+ * @param key the key to check for
+ */
+ bool entryExists( const QString& key );
+
+ /**
+ * Deletes the data for a @p key from the keychain.
+ * error() and errorString() hold the result of the delete operation.
+ *
+ * @param key The key to delete the data for
+ */
+ void deleteEntry( const QString& key );
+
+private:
+ class Private;
+ Private* const d;
+ Q_DISABLE_COPY(Keychain)
+};
+
class Keychain::Private {
Q_DECLARE_TR_FUNCTIONS(Keychain::Private)
public:
explicit Private( const QString& service_, QSettings* settings_ ) : service( service_ ), settings( settings_ ), error( NoError ) {}
- Keychain::Error writeEntryImpl( const QString& account,
+ QKeychain::Error writeEntryImpl( const QString& account,
const QByteArray& data,
QString* errorString );
- Keychain::Error deleteEntryImpl( const QString& account,
+ QKeychain::Error deleteEntryImpl( const QString& account,
QString* errorString );
- Keychain::Error readEntryImpl( QByteArray* password,
+ QKeychain::Error readEntryImpl( QByteArray* password,
const QString& account,
QString* errorString );
- Keychain::Error entryExistsImpl( bool* exists,
+ QKeychain::Error entryExistsImpl( bool* exists,
const QString& key,
QString* errorString );
const QString service;
QPointer<QSettings> settings;
- Keychain::Error error;
+ QKeychain::Error error;
QString errorString;
};
+
+#endif
+
}
#endif // KEYCHAIN_P_H
diff --git a/keychain_win.cpp b/keychain_win.cpp
index 8ebc406..e118873 100644
--- a/keychain_win.cpp
+++ b/keychain_win.cpp
@@ -17,7 +17,7 @@
using namespace QKeychain;
-Keychain::Error Keychain::Private::readEntryImpl( QByteArray* pw,
+QtKeychain::Error Keychain::Private::readEntryImpl( QByteArray* pw,
const QString& key,
QString* err ) {
Q_ASSERT( pw );
@@ -56,7 +56,7 @@ Keychain::Error Keychain::Private::readEntryImpl( QByteArray* pw,
return NoError;
}
-Keychain::Error Keychain::Private::writeEntryImpl( const QString& key,
+QtKeychain::Error Keychain::Private::writeEntryImpl( const QString& key,
const QByteArray& data_,
QString* err ) {
Q_ASSERT( err );
@@ -95,7 +95,7 @@ Keychain::Error Keychain::Private::writeEntryImpl( const QString& key,
return NoError;
}
-Keychain::Error Keychain::Private::deleteEntryImpl( const QString& key,
+QtKeychain::Error Keychain::Private::deleteEntryImpl( const QString& key,
QString* err ) {
Q_ASSERT( err );
err->clear();
@@ -114,7 +114,7 @@ Keychain::Error Keychain::Private::deleteEntryImpl( const QString& key,
}
-Keychain::Error Keychain::Private::entryExistsImpl( bool* exists,
+QtKeychain::Error Keychain::Private::entryExistsImpl( bool* exists,
const QString& key,
QString* err ) {
Q_ASSERT( exists );
diff --git a/testclient.cpp b/testclient.cpp
index 0507a2d..70e923a 100644
--- a/testclient.cpp
+++ b/testclient.cpp
@@ -39,10 +39,16 @@ int main( int argc, char** argv ) {
const QString pass = *it;
if ( ++it != args.constEnd() )
return printUsage();
- Keychain k( QLatin1String("qtkeychain-testclient") );
- k.writePassword( acc, pass );
- if ( k.error() ) {
- std::cerr << "Storing password failed: " << qPrintable(k.errorString()) << std::endl;
+ WritePasswordJob job( QLatin1String("qtkeychain-testclient") );
+ job.setAutoDelete( false );
+ job.setKey( acc );
+ job.setTextData( pass );
+ QEventLoop loop;
+ job.connect( &job, SIGNAL(finished(QKeychain::Job*)), &loop, SLOT(quit()) );
+ job.start();
+ loop.exec();
+ if ( job.error() ) {
+ std::cerr << "Storing password failed: " << qPrintable(job.errorString()) << std::endl;
return 1;
}
std::cout << "Password stored successfully" << std::endl;
@@ -52,10 +58,17 @@ int main( int argc, char** argv ) {
const QString acc = *it;
if ( ++it != args.constEnd() )
return printUsage();
- Keychain k( QLatin1String("qtkeychain-testclient") );
- const QString pw = k.readPassword( acc );
- if ( k.error() ) {
- std::cerr << "Restoring password failed: " << qPrintable(k.errorString()) << std::endl;
+ ReadPasswordJob job( QLatin1String("qtkeychain-testclient") );
+ job.setAutoDelete( false );
+ job.setKey( acc );
+ QEventLoop loop;
+ job.connect( &job, SIGNAL(finished(QKeychain::Job*)), &loop, SLOT(quit()) );
+ job.start();
+ loop.exec();
+
+ const QString pw = job.textData();
+ if ( job.error() ) {
+ std::cerr << "Restoring password failed: " << qPrintable(job.errorString()) << std::endl;
return 1;
}
std::cout << qPrintable(pw) << std::endl;
@@ -65,10 +78,16 @@ int main( int argc, char** argv ) {
const QString acc = *it;
if ( ++it != args.constEnd() )
return printUsage();
- Keychain k( QLatin1String("qtkeychain-testclient") );
- k.deleteEntry( acc );
- if ( k.error() ) {
- std::cerr << "Deleting password failed: " << qPrintable(k.errorString()) << std::endl;
+ WritePasswordJob job( QLatin1String("qtkeychain-testclient") );
+ job.setAutoDelete( false );
+ job.setKey( acc );
+ QEventLoop loop;
+ job.connect( &job, SIGNAL(finished(QKeychain::Job*)), &loop, SLOT(quit()) );
+ job.start();
+ loop.exec();
+
+ if ( job.error() ) {
+ std::cerr << "Deleting password failed: " << qPrintable(job.errorString()) << std::endl;
return 1;
}
std::cout << "Password deleted successfully" << std::endl;
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-owncloud/qtkeychain.git
More information about the Pkg-owncloud-commits
mailing list