Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Introduce DeletePasswordJob to delete passwords.

Creating a WritePasswordJob with no password data does the same, but that makes rather cryptic API.
  • Loading branch information...
commit 7465902216242489bc8c7f7d811fddc65bb1126b 1 parent 8b1a574
Frank Osterfeld authored
32 keychain.cpp
@@ -131,3 +131,35 @@ void WritePasswordJob::setTextData( const QString& data ) {
131 131 void WritePasswordJob::doStart() {
132 132 d->doStart();
133 133 }
  134 +
  135 +DeletePasswordJob::DeletePasswordJob( const QString& service, QObject* parent )
  136 + : Job( service, parent )
  137 + , d( new Private( this ) ) {
  138 +}
  139 +
  140 +DeletePasswordJob::~DeletePasswordJob() {
  141 + delete d;
  142 +}
  143 +
  144 +void DeletePasswordJob::doStart() {
  145 + //Internally, to delete a password we just execute a write job with no data set (null byte array).
  146 + //In all current implementations, this deletes the entry so this is sufficient
  147 + WritePasswordJob* job = new WritePasswordJob( service(), this );
  148 + connect( job, SIGNAL(finished(QKeychain::Job*)), d, SLOT(jobFinished(QKeychain::Job*)) );
  149 + job->setKey( d->key );
  150 + job->start();
  151 +}
  152 +
  153 +QString DeletePasswordJob::key() const {
  154 + return d->key;
  155 +}
  156 +
  157 +void DeletePasswordJob::setKey( const QString& key ) {
  158 + d->key = key;
  159 +}
  160 +
  161 +void DeletePasswordJob::Private::jobFinished( Job* job ) {
  162 + q->setError( job->error() );
  163 + q->setErrorString( job->errorString() );
  164 + q->emitFinished();
  165 +}
19 keychain.h
@@ -107,6 +107,23 @@ class QKEYCHAIN_EXPORT WritePasswordJob : public Job {
107 107 Private* const d;
108 108 };
109 109
110   -}
  110 +class QKEYCHAIN_EXPORT DeletePasswordJob : public Job {
  111 + Q_OBJECT
  112 +public:
  113 + explicit DeletePasswordJob( const QString& service, QObject* parent=0 );
  114 + ~DeletePasswordJob();
  115 +
  116 + QString key() const;
  117 + void setKey( const QString& key );
  118 +
  119 +protected:
  120 + void doStart();
  121 +
  122 +private:
  123 + class Private;
  124 + Private* const d;
  125 +};
  126 +
  127 +} // namespace QtKeychain
111 128
112 129 #endif
11 keychain_p.h
@@ -60,6 +60,17 @@ class WritePasswordJob::Private : public QObject {
60 60 QString textData;
61 61 };
62 62
  63 +class DeletePasswordJob::Private : public QObject {
  64 + Q_OBJECT
  65 +public:
  66 + explicit Private( DeletePasswordJob* qq ) : q( qq ) {}
  67 + void doStart();
  68 + DeletePasswordJob* const q;
  69 + QString key;
  70 +private Q_SLOTS:
  71 + void jobFinished( QKeychain::Job* );
  72 +};
  73 +
63 74 }
64 75
65 76 #endif // KEYCHAIN_P_H
2  testclient.cpp
@@ -78,7 +78,7 @@ int main( int argc, char** argv ) {
78 78 const QString acc = *it;
79 79 if ( ++it != args.constEnd() )
80 80 return printUsage();
81   - WritePasswordJob job( QLatin1String("qtkeychain-testclient") );
  81 + DeletePasswordJob job( QLatin1String("qtkeychain-testclient") );
82 82 job.setAutoDelete( false );
83 83 job.setKey( acc );
84 84 QEventLoop loop;

0 comments on commit 7465902

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