Introduce DeletePasswordJob to delete passwords.

Creating a WritePasswordJob with no password data does the same, but that makes rather cryptic API.
This commit is contained in:
Frank Osterfeld 2012-05-07 16:56:52 +02:00
parent 8b1a574f35
commit 7465902216
4 changed files with 62 additions and 2 deletions

View File

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

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

View File

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

View File

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