[Pkg-owncloud-commits] [qtkeychain] 31/115: Introduce DeletePasswordJob to delete passwords. Creating a WritePasswordJob with no password data does the same, but that makes rather cryptic API.

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 7465902216242489bc8c7f7d811fddc65bb1126b
Author: Frank Osterfeld <frank.osterfeld at kdab.com>
Date:   Mon May 7 16:56:52 2012 +0200

    Introduce DeletePasswordJob to delete passwords.
    Creating a WritePasswordJob with no password data does the same, but that makes rather cryptic API.
---
 keychain.cpp   | 32 ++++++++++++++++++++++++++++++++
 keychain.h     | 19 ++++++++++++++++++-
 keychain_p.h   | 11 +++++++++++
 testclient.cpp |  2 +-
 4 files changed, 62 insertions(+), 2 deletions(-)

diff --git a/keychain.cpp b/keychain.cpp
index 8ed4dab..3f275ee 100644
--- a/keychain.cpp
+++ b/keychain.cpp
@@ -131,3 +131,35 @@ void WritePasswordJob::setTextData( const QString& data ) {
 void WritePasswordJob::doStart() {
     d->doStart();
 }
+
+DeletePasswordJob::DeletePasswordJob( const QString& service, QObject* parent )
+    : Job( service, parent )
+    , d( new Private( this ) ) {
+}
+
+DeletePasswordJob::~DeletePasswordJob() {
+    delete d;
+}
+
+void DeletePasswordJob::doStart() {
+    //Internally, to delete a password we just execute a write job with no data set (null byte array).
+    //In all current implementations, this deletes the entry so this is sufficient
+    WritePasswordJob* job = new WritePasswordJob( service(), this );
+    connect( job, SIGNAL(finished(QKeychain::Job*)), d, SLOT(jobFinished(QKeychain::Job*)) );
+    job->setKey( d->key );
+    job->start();
+}
+
+QString DeletePasswordJob::key() const {
+    return d->key;
+}
+
+void DeletePasswordJob::setKey( const QString& key ) {
+    d->key = key;
+}
+
+void DeletePasswordJob::Private::jobFinished( Job* job ) {
+    q->setError( job->error() );
+    q->setErrorString( job->errorString() );
+    q->emitFinished();
+}
diff --git a/keychain.h b/keychain.h
index 5ddb0bb..82d0bd2 100644
--- a/keychain.h
+++ b/keychain.h
@@ -107,6 +107,23 @@ private:
     Private* const d;
 };
 
-}
+class QKEYCHAIN_EXPORT DeletePasswordJob : public Job {
+    Q_OBJECT
+public:
+    explicit DeletePasswordJob( const QString& service, QObject* parent=0 );
+    ~DeletePasswordJob();
+
+    QString key() const;
+    void setKey( const QString& key );
+
+protected:
+    void doStart();
+
+private:
+    class Private;
+    Private* const d;
+};
+
+} // namespace QtKeychain
 
 #endif
diff --git a/keychain_p.h b/keychain_p.h
index bac2b99..a7ae1cb 100644
--- a/keychain_p.h
+++ b/keychain_p.h
@@ -60,6 +60,17 @@ public:
     QString textData;
 };
 
+class DeletePasswordJob::Private : public QObject {
+    Q_OBJECT
+public:
+    explicit Private( DeletePasswordJob* qq ) : q( qq ) {}
+    void doStart();
+    DeletePasswordJob* const q;
+    QString key;
+private Q_SLOTS:
+    void jobFinished( QKeychain::Job* );
+};
+
 }
 
 #endif // KEYCHAIN_P_H
diff --git a/testclient.cpp b/testclient.cpp
index 70e923a..b381130 100644
--- a/testclient.cpp
+++ b/testclient.cpp
@@ -78,7 +78,7 @@ int main( int argc, char** argv ) {
         const QString acc = *it;
         if ( ++it != args.constEnd() )
             return printUsage();
-        WritePasswordJob job( QLatin1String("qtkeychain-testclient") );
+        DeletePasswordJob job( QLatin1String("qtkeychain-testclient") );
         job.setAutoDelete( false );
         job.setKey( acc );
         QEventLoop loop;

-- 
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