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>
|
2012-04-05 14:16:22 +00:00
|
|
|
#include <QObject>
|
2011-12-09 19:47:11 +00:00
|
|
|
#include <QPointer>
|
|
|
|
#include <QSettings>
|
2012-08-06 20:30:58 +00:00
|
|
|
#include <QVector>
|
2011-10-27 16:15:46 +00:00
|
|
|
|
2013-01-23 09:29:07 +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 {
|
2012-04-05 14:16:22 +00:00
|
|
|
|
2012-07-27 21:10:47 +00:00
|
|
|
class JobExecutor;
|
|
|
|
|
|
|
|
class JobPrivate : public QObject {
|
2012-04-05 14:16:22 +00:00
|
|
|
Q_OBJECT
|
|
|
|
public:
|
2012-07-27 21:10:47 +00:00
|
|
|
JobPrivate( const QString& service_ )
|
2012-04-05 14:16:22 +00:00
|
|
|
: error( NoError )
|
|
|
|
, service( service_ )
|
2012-06-09 20:11:16 +00:00
|
|
|
, autoDelete( true )
|
|
|
|
, insecureFallback( false ) {}
|
2012-04-05 14:16:22 +00:00
|
|
|
|
|
|
|
QKeychain::Error error;
|
|
|
|
QString errorString;
|
|
|
|
QString service;
|
|
|
|
bool autoDelete;
|
2012-06-09 20:11:16 +00:00
|
|
|
bool insecureFallback;
|
2012-04-05 14:16:22 +00:00
|
|
|
QPointer<QSettings> settings;
|
|
|
|
};
|
|
|
|
|
2012-07-27 21:10:47 +00:00
|
|
|
class ReadPasswordJobPrivate : public QObject {
|
2012-04-05 14:16:22 +00:00
|
|
|
Q_OBJECT
|
|
|
|
public:
|
2012-07-27 21:10:47 +00:00
|
|
|
explicit ReadPasswordJobPrivate( ReadPasswordJob* qq ) : q( qq ), walletHandle( 0 ), dataType( Text ) {}
|
2012-08-06 20:30:58 +00:00
|
|
|
void scheduledStart();
|
|
|
|
|
2012-04-05 14:16:22 +00:00
|
|
|
ReadPasswordJob* const q;
|
|
|
|
QByteArray data;
|
|
|
|
QString key;
|
2012-05-08 08:47:38 +00:00
|
|
|
int walletHandle;
|
|
|
|
enum DataType {
|
|
|
|
Binary,
|
|
|
|
Text
|
|
|
|
};
|
|
|
|
DataType dataType;
|
|
|
|
|
2013-01-23 09:29:07 +00:00
|
|
|
#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 );
|
2012-07-27 21:10:47 +00:00
|
|
|
friend class QKeychain::JobExecutor;
|
2013-06-06 12:25:07 +00:00
|
|
|
void fallbackOnError(const QDBusError& err);
|
2012-05-08 08:47:38 +00:00
|
|
|
|
|
|
|
private Q_SLOTS:
|
2013-08-22 08:58:46 +00:00
|
|
|
void kwalletWalletFound( QDBusPendingCallWatcher* watcher );
|
2012-05-08 08:47:38 +00:00
|
|
|
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:
|
2013-09-25 10:35:16 +00:00
|
|
|
void kwalletWalletFound( QDBusPendingCallWatcher* ) {}
|
2012-05-09 17:18:10 +00:00
|
|
|
void kwalletOpenFinished( QDBusPendingCallWatcher* ) {}
|
|
|
|
void kwalletEntryTypeFinished( QDBusPendingCallWatcher* ) {}
|
|
|
|
void kwalletReadFinished( QDBusPendingCallWatcher* ) {}
|
2012-05-08 08:47:38 +00:00
|
|
|
#endif
|
|
|
|
|
2012-04-05 14:16:22 +00:00
|
|
|
};
|
|
|
|
|
2012-07-27 21:10:47 +00:00
|
|
|
class WritePasswordJobPrivate : public QObject {
|
2012-04-05 14:16:22 +00:00
|
|
|
Q_OBJECT
|
|
|
|
public:
|
2012-07-27 21:10:47 +00:00
|
|
|
explicit WritePasswordJobPrivate( WritePasswordJob* qq ) : q( qq ), mode( Delete ) {}
|
2012-08-06 20:30:58 +00:00
|
|
|
void scheduledStart();
|
|
|
|
|
2012-04-05 14:16:22 +00:00
|
|
|
enum Mode {
|
|
|
|
Delete,
|
|
|
|
Text,
|
|
|
|
Binary
|
|
|
|
};
|
2013-11-11 19:01:22 +00:00
|
|
|
|
|
|
|
static QString modeToString(Mode m);
|
|
|
|
static Mode stringToMode(const QString& s);
|
|
|
|
|
2012-04-05 14:16:22 +00:00
|
|
|
WritePasswordJob* const q;
|
|
|
|
Mode mode;
|
|
|
|
QString key;
|
|
|
|
QByteArray binaryData;
|
|
|
|
QString textData;
|
2012-05-07 16:21:22 +00:00
|
|
|
|
2013-01-23 09:29:07 +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 );
|
2012-07-27 21:10:47 +00:00
|
|
|
friend class QKeychain::JobExecutor;
|
2013-06-06 12:25:07 +00:00
|
|
|
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
|
2012-04-05 14:16:22 +00:00
|
|
|
};
|
|
|
|
|
2012-07-27 21:10:47 +00:00
|
|
|
class DeletePasswordJobPrivate : public QObject {
|
2012-05-07 14:56:52 +00:00
|
|
|
Q_OBJECT
|
|
|
|
public:
|
2012-07-27 21:10:47 +00:00
|
|
|
explicit DeletePasswordJobPrivate( DeletePasswordJob* qq ) : q( qq ) {}
|
2012-05-07 14:56:52 +00:00
|
|
|
void doStart();
|
|
|
|
DeletePasswordJob* const q;
|
|
|
|
QString key;
|
|
|
|
private Q_SLOTS:
|
|
|
|
void jobFinished( QKeychain::Job* );
|
|
|
|
};
|
|
|
|
|
2012-08-06 20:30:58 +00:00
|
|
|
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
|