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:
parent
8b1a574f35
commit
7465902216
32
keychain.cpp
32
keychain.cpp
|
@ -131,3 +131,35 @@ void WritePasswordJob::setTextData( const QString& data ) {
|
||||||
void WritePasswordJob::doStart() {
|
void WritePasswordJob::doStart() {
|
||||||
d->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();
|
||||||
|
}
|
||||||
|
|
19
keychain.h
19
keychain.h
|
@ -107,6 +107,23 @@ private:
|
||||||
Private* const d;
|
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
|
#endif
|
||||||
|
|
11
keychain_p.h
11
keychain_p.h
|
@ -60,6 +60,17 @@ public:
|
||||||
QString textData;
|
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
|
#endif // KEYCHAIN_P_H
|
||||||
|
|
|
@ -78,7 +78,7 @@ int main( int argc, char** argv ) {
|
||||||
const QString acc = *it;
|
const QString acc = *it;
|
||||||
if ( ++it != args.constEnd() )
|
if ( ++it != args.constEnd() )
|
||||||
return printUsage();
|
return printUsage();
|
||||||
WritePasswordJob job( QLatin1String("qtkeychain-testclient") );
|
DeletePasswordJob job( QLatin1String("qtkeychain-testclient") );
|
||||||
job.setAutoDelete( false );
|
job.setAutoDelete( false );
|
||||||
job.setKey( acc );
|
job.setKey( acc );
|
||||||
QEventLoop loop;
|
QEventLoop loop;
|
||||||
|
|
Loading…
Reference in New Issue