qtkeychain/keychain_p.h

158 lines
4.2 KiB
C
Raw Normal View History

2011-10-27 16:15:46 +00:00
/******************************************************************************
2013-07-22 18:22:39 +00:00
* Copyright (C) 2011-2013 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_P_H
#define KEYCHAIN_P_H
2011-10-27 16:15:46 +00:00
#include <QCoreApplication>
#include <QObject>
#include <QPointer>
#include <QSettings>
#include <QVector>
2011-10-27 16:15:46 +00:00
#if defined(Q_OS_UNIX) && !defined(Q_OS_DARWIN)
2012-05-07 16:21:22 +00:00
#include <QDBusPendingCallWatcher>
#include "kwallet_interface.h"
2012-05-09 17:18:10 +00:00
#else
class QDBusPendingCallWatcher;
2012-05-07 16:21:22 +00:00
#endif
2011-10-27 16:14:37 +00:00
#include "keychain.h"
2011-10-27 19:17:54 +00:00
namespace QKeychain {
class JobExecutor;
class JobPrivate : public QObject {
Q_OBJECT
public:
JobPrivate( const QString& service_ )
: error( NoError )
, service( service_ )
, autoDelete( true )
, insecureFallback( false ) {}
QKeychain::Error error;
QString errorString;
QString service;
bool autoDelete;
bool insecureFallback;
QPointer<QSettings> settings;
};
class ReadPasswordJobPrivate : public QObject {
Q_OBJECT
public:
explicit ReadPasswordJobPrivate( ReadPasswordJob* qq ) : q( qq ), walletHandle( 0 ), dataType( Text ) {}
void scheduledStart();
ReadPasswordJob* const q;
QByteArray data;
QString key;
2012-05-08 08:47:38 +00:00
int walletHandle;
enum DataType {
Binary,
Text
};
DataType dataType;
#if defined(Q_OS_UNIX) && !defined(Q_OS_DARWIN)
2012-05-08 08:47:38 +00:00
org::kde::KWallet* iface;
2013-03-19 11:24:15 +00:00
static void gnomeKeyring_cb( int result, const char* string, ReadPasswordJobPrivate* data );
friend class QKeychain::JobExecutor;
void fallbackOnError(const QDBusError& err);
2012-05-08 08:47:38 +00:00
const QString typeKey();
const QString dataKey();
2012-05-08 08:47:38 +00:00
private Q_SLOTS:
void kwalletOpenFinished( QDBusPendingCallWatcher* watcher );
void kwalletEntryTypeFinished( QDBusPendingCallWatcher* watcher );
void kwalletReadFinished( QDBusPendingCallWatcher* watcher );
2012-05-09 17:18:10 +00:00
#else //moc's too dumb to respect above macros, so just define empty slot implementations
private Q_SLOTS:
void kwalletOpenFinished( QDBusPendingCallWatcher* ) {}
void kwalletEntryTypeFinished( QDBusPendingCallWatcher* ) {}
void kwalletReadFinished( QDBusPendingCallWatcher* ) {}
2012-05-08 08:47:38 +00:00
#endif
};
class WritePasswordJobPrivate : public QObject {
Q_OBJECT
public:
explicit WritePasswordJobPrivate( WritePasswordJob* qq ) : q( qq ), mode( Delete ) {}
void scheduledStart();
enum Mode {
Delete,
Text,
Binary
};
WritePasswordJob* const q;
Mode mode;
QString key;
QByteArray binaryData;
QString textData;
2012-05-07 16:21:22 +00:00
#if defined(Q_OS_UNIX) && !defined(Q_OS_DARWIN)
2012-05-07 16:21:22 +00:00
org::kde::KWallet* iface;
2013-03-19 11:24:15 +00:00
static void gnomeKeyring_cb( int result, WritePasswordJobPrivate* self );
friend class QKeychain::JobExecutor;
void fallbackOnError(const QDBusError& err);
2012-05-07 16:21:22 +00:00
private Q_SLOTS:
void kwalletOpenFinished( QDBusPendingCallWatcher* watcher );
void kwalletWriteFinished( QDBusPendingCallWatcher* watcher );
2012-05-09 17:18:10 +00:00
#else
private Q_SLOTS:
void kwalletOpenFinished( QDBusPendingCallWatcher* ) {}
void kwalletWriteFinished( QDBusPendingCallWatcher* ) {}
2012-05-07 16:21:22 +00:00
#endif
};
class DeletePasswordJobPrivate : public QObject {
Q_OBJECT
public:
explicit DeletePasswordJobPrivate( DeletePasswordJob* qq ) : q( qq ) {}
void doStart();
DeletePasswordJob* const q;
QString key;
private Q_SLOTS:
void jobFinished( QKeychain::Job* );
};
class JobExecutor : public QObject {
Q_OBJECT
public:
static JobExecutor* instance();
void enqueue( Job* job );
private:
explicit JobExecutor();
void startNextIfNoneRunning();
private Q_SLOTS:
void jobFinished( QKeychain::Job* );
void jobDestroyed( QObject* object );
private:
static JobExecutor* s_instance;
Job* m_runningJob;
QVector<QPointer<Job> > m_queue;
};
2011-10-27 19:17:54 +00:00
}
2011-10-27 16:14:37 +00:00
#endif // KEYCHAIN_P_H