Skip to content
Browse files

Introduce DeletePasswordJob to delete passwords.

Creating a WritePasswordJob with no password data does the same, but that makes rather cryptic API.
  • Loading branch information...
1 parent 8b1a574 commit 7465902216242489bc8c7f7d811fddc65bb1126b @frankosterfeld committed May 7, 2012
Showing with 62 additions and 2 deletions.
  1. +32 −0 keychain.cpp
  2. +18 −1 keychain.h
  3. +11 −0 keychain_p.h
  4. +1 −1 testclient.cpp
View
32 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();
+}
View
19 keychain.h
@@ -107,6 +107,23 @@ class QKEYCHAIN_EXPORT WritePasswordJob : public Job {
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
View
11 keychain_p.h
@@ -60,6 +60,17 @@ class WritePasswordJob::Private : public QObject {
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
View
2 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;

0 comments on commit 7465902

Please sign in to comment.
Something went wrong with that request. Please try again.