2011-10-27 16:15:46 +00:00
|
|
|
/******************************************************************************
|
2014-03-12 14:02:07 +00:00
|
|
|
* Copyright (C) 2011-2014 Frank Osterfeld <frank.osterfeld@gmail.com> *
|
2011-10-27 16:15:46 +00:00
|
|
|
* *
|
|
|
|
* This program is distributed in the hope that it will be useful, but *
|
|
|
|
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY *
|
|
|
|
* or FITNESS FOR A PARTICULAR PURPOSE. For licensing and distribution *
|
|
|
|
* details, check the accompanying file 'COPYING'. *
|
|
|
|
*****************************************************************************/
|
2011-10-27 16:14:37 +00:00
|
|
|
#ifndef KEYCHAIN_H
|
|
|
|
#define KEYCHAIN_H
|
|
|
|
|
2011-10-28 19:27:03 +00:00
|
|
|
#include "qkeychain_export.h"
|
|
|
|
|
2012-04-05 14:16:22 +00:00
|
|
|
#include <QtCore/QObject>
|
2011-10-27 16:15:46 +00:00
|
|
|
#include <QtCore/QString>
|
2011-10-27 16:14:37 +00:00
|
|
|
|
2011-12-09 19:47:11 +00:00
|
|
|
class QSettings;
|
|
|
|
|
2013-01-16 17:53:49 +00:00
|
|
|
#define QTKEYCHAIN_VERSION 0x000100
|
|
|
|
|
2011-10-27 19:17:54 +00:00
|
|
|
namespace QKeychain {
|
2012-04-05 14:16:22 +00:00
|
|
|
|
2011-10-27 18:46:23 +00:00
|
|
|
/**
|
2012-04-05 14:16:22 +00:00
|
|
|
* Error codes
|
2011-10-27 18:46:23 +00:00
|
|
|
*/
|
2012-04-05 14:16:22 +00:00
|
|
|
enum Error {
|
|
|
|
NoError=0, /**< No error occurred, operation was successful */
|
|
|
|
EntryNotFound, /**< For the given key no data was found */
|
|
|
|
CouldNotDeleteEntry, /**< Could not delete existing secret data */
|
|
|
|
AccessDeniedByUser, /**< User denied access to keychain */
|
|
|
|
AccessDenied, /**< Access denied for other reasons */
|
2012-05-08 15:23:26 +00:00
|
|
|
NoBackendAvailable, /**< No platform-specific keychain service available */
|
2012-04-05 14:16:22 +00:00
|
|
|
NotImplemented, /**< Not implemented on platform */
|
|
|
|
OtherError /**< Something else went wrong (errorString() might provide details) */
|
|
|
|
};
|
|
|
|
|
2012-07-27 21:10:47 +00:00
|
|
|
class JobExecutor;
|
|
|
|
class JobPrivate;
|
|
|
|
|
2012-04-05 14:16:22 +00:00
|
|
|
class QKEYCHAIN_EXPORT Job : public QObject {
|
|
|
|
Q_OBJECT
|
2011-10-27 16:14:37 +00:00
|
|
|
public:
|
2012-04-05 14:16:22 +00:00
|
|
|
explicit Job( const QString& service, QObject* parent=0 );
|
|
|
|
~Job();
|
|
|
|
|
|
|
|
QSettings* settings() const;
|
|
|
|
void setSettings( QSettings* settings );
|
|
|
|
|
|
|
|
void start();
|
|
|
|
|
2011-10-27 16:14:37 +00:00
|
|
|
QString service() const;
|
2011-10-27 18:46:23 +00:00
|
|
|
|
2011-10-27 16:15:46 +00:00
|
|
|
Error error() const;
|
|
|
|
QString errorString() const;
|
2011-10-27 16:14:37 +00:00
|
|
|
|
2012-04-05 14:16:22 +00:00
|
|
|
bool autoDelete() const;
|
|
|
|
void setAutoDelete( bool autoDelete );
|
|
|
|
|
2012-06-09 20:11:16 +00:00
|
|
|
bool insecureFallback() const;
|
|
|
|
void setInsecureFallback( bool insecureFallback );
|
|
|
|
|
2012-04-05 14:16:22 +00:00
|
|
|
Q_SIGNALS:
|
|
|
|
void finished( QKeychain::Job* );
|
|
|
|
|
|
|
|
protected:
|
|
|
|
Q_INVOKABLE virtual void doStart() = 0;
|
|
|
|
|
|
|
|
void setError( Error error );
|
|
|
|
void setErrorString( const QString& errorString );
|
|
|
|
void emitFinished();
|
|
|
|
void emitFinishedWithError(Error, const QString& errorString);
|
|
|
|
|
|
|
|
private:
|
2012-07-27 21:10:47 +00:00
|
|
|
JobPrivate* const d;
|
2012-04-05 14:16:22 +00:00
|
|
|
};
|
|
|
|
|
2012-07-27 21:10:47 +00:00
|
|
|
class ReadPasswordJobPrivate;
|
|
|
|
|
2012-04-05 14:16:22 +00:00
|
|
|
class QKEYCHAIN_EXPORT ReadPasswordJob : public Job {
|
|
|
|
Q_OBJECT
|
|
|
|
public:
|
|
|
|
explicit ReadPasswordJob( const QString& service, QObject* parent=0 );
|
|
|
|
~ReadPasswordJob();
|
|
|
|
|
|
|
|
QString key() const;
|
|
|
|
void setKey( const QString& key );
|
|
|
|
|
|
|
|
QByteArray binaryData() const;
|
|
|
|
QString textData() const;
|
|
|
|
|
|
|
|
protected:
|
|
|
|
void doStart();
|
|
|
|
|
|
|
|
private:
|
2012-07-27 21:10:47 +00:00
|
|
|
friend class QKeychain::ReadPasswordJobPrivate;
|
|
|
|
friend class QKeychain::JobExecutor;
|
|
|
|
ReadPasswordJobPrivate* const d;
|
2012-04-05 14:16:22 +00:00
|
|
|
};
|
|
|
|
|
2012-07-27 21:10:47 +00:00
|
|
|
class WritePasswordJobPrivate;
|
|
|
|
|
2012-04-05 14:16:22 +00:00
|
|
|
class QKEYCHAIN_EXPORT WritePasswordJob : public Job {
|
|
|
|
Q_OBJECT
|
|
|
|
public:
|
|
|
|
explicit WritePasswordJob( const QString& service, QObject* parent=0 );
|
|
|
|
~WritePasswordJob();
|
|
|
|
|
|
|
|
QString key() const;
|
|
|
|
void setKey( const QString& key );
|
|
|
|
|
|
|
|
void setBinaryData( const QByteArray& data );
|
|
|
|
void setTextData( const QString& data );
|
|
|
|
|
|
|
|
protected:
|
|
|
|
void doStart();
|
2011-10-27 16:14:37 +00:00
|
|
|
|
|
|
|
private:
|
2012-07-27 21:10:47 +00:00
|
|
|
friend class QKeychain::JobExecutor;
|
|
|
|
friend class QKeychain::WritePasswordJobPrivate;
|
2014-01-27 15:27:42 +00:00
|
|
|
friend class DeletePasswordJob;
|
2012-07-27 21:10:47 +00:00
|
|
|
WritePasswordJobPrivate* const d;
|
2011-10-27 16:14:37 +00:00
|
|
|
};
|
|
|
|
|
2012-07-27 21:10:47 +00:00
|
|
|
class DeletePasswordJobPrivate;
|
|
|
|
|
2012-05-07 14:56:52 +00:00
|
|
|
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:
|
2012-07-27 21:10:47 +00:00
|
|
|
friend class QKeychain::DeletePasswordJobPrivate;
|
|
|
|
DeletePasswordJobPrivate* const d;
|
2012-05-07 14:56:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace QtKeychain
|
2011-10-27 19:17:54 +00:00
|
|
|
|
2011-10-27 16:14:37 +00:00
|
|
|
#endif
|