qtkeychain/keychain_p.h

167 lines
4.3 KiB
C
Raw Normal View History

2011-10-27 16:15:46 +00:00
/******************************************************************************
2015-03-17 13:31:48 +00:00
* Copyright (C) 2011-2015 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 <QQueue>
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:
enum Mode {
Text,
Binary
};
virtual void scheduledStart() = 0;
static QString modeToString(Mode m);
static Mode stringToMode(const QString& s);
Mode mode;
#if defined(Q_OS_UNIX) && !defined(Q_OS_DARWIN)
org::kde::KWallet* iface;
int walletHandle;
static void gnomeKeyring_readCb( int result, const char* string, JobPrivate* data );
static void gnomeKeyring_writeCb( int result, JobPrivate* self );
virtual void fallbackOnError(const QDBusError& err) = 0;
protected Q_SLOTS:
void kwalletWalletFound( QDBusPendingCallWatcher* watcher );
virtual void kwalletFinished( QDBusPendingCallWatcher* watcher );
virtual void kwalletOpenFinished( QDBusPendingCallWatcher* watcher );
#else
void kwalletWalletFound(QDBusPendingCallWatcher *watcher) {}
virtual void kwalletFinished( QDBusPendingCallWatcher* watcher ) {}
virtual void kwalletOpenFinished( QDBusPendingCallWatcher* watcher ) {}
#endif
protected:
JobPrivate( const QString& service_, Job *q );
protected:
QKeychain::Error error;
QString errorString;
QString service;
bool autoDelete;
bool insecureFallback;
QPointer<QSettings> settings;
QString key;
Job* const q;
QByteArray data;
friend class Job;
friend class JobExecutor;
friend class ReadPasswordJob;
friend class WritePasswordJob;
};
class ReadPasswordJobPrivate : public JobPrivate {
Q_OBJECT
public:
explicit ReadPasswordJobPrivate( const QString &service_, ReadPasswordJob* qq );
void scheduledStart();
#if defined(Q_OS_UNIX) && !defined(Q_OS_DARWIN)
void fallbackOnError(const QDBusError& err);
2012-05-08 08:47:38 +00:00
private Q_SLOTS:
void kwalletOpenFinished( QDBusPendingCallWatcher* watcher );
void kwalletEntryTypeFinished( QDBusPendingCallWatcher* watcher );
void kwalletFinished( 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 kwalletFinished( QDBusPendingCallWatcher* ) {}
2012-05-08 08:47:38 +00:00
#endif
friend class ReadPasswordJob;
};
class WritePasswordJobPrivate : public JobPrivate {
Q_OBJECT
public:
explicit WritePasswordJobPrivate( const QString &service_, WritePasswordJob* qq );
void scheduledStart();
#if defined(Q_OS_UNIX) && !defined(Q_OS_DARWIN)
void fallbackOnError(const QDBusError& err);
2012-05-07 16:21:22 +00:00
#endif
friend class WritePasswordJob;
};
class DeletePasswordJobPrivate : public JobPrivate {
Q_OBJECT
public:
explicit DeletePasswordJobPrivate( const QString &service_, DeletePasswordJob* qq );
void scheduledStart();
#if defined(Q_OS_UNIX) && !defined(Q_OS_DARWIN)
void fallbackOnError(const QDBusError& err);
#endif
protected:
void doStart();
friend class DeletePasswordJob;
};
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;
QQueue<QPointer<Job> > m_queue;
bool m_jobRunning;
};
2011-10-27 19:17:54 +00:00
}
2011-10-27 16:14:37 +00:00
#endif // KEYCHAIN_P_H