forked from frankosterfeld/qtkeychain
-
Notifications
You must be signed in to change notification settings - Fork 0
/
keychain_p.h
167 lines (127 loc) · 4.23 KB
/
keychain_p.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
/******************************************************************************
* Copyright (C) 2011-2015 Frank Osterfeld <[email protected]> *
* *
* 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'. *
*****************************************************************************/
#ifndef KEYCHAIN_P_H
#define KEYCHAIN_P_H
#include <QCoreApplication>
#include <QObject>
#include <QPointer>
#include <QSettings>
#include <QQueue>
#if defined(KEYCHAIN_DBUS)
#include <QDBusPendingCallWatcher>
#include "kwallet_interface.h"
#else
class QDBusPendingCallWatcher;
#endif
#include "keychain.h"
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);
Job* const q;
Mode mode;
QByteArray data;
#if defined(KEYCHAIN_DBUS)
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* ) {}
virtual void kwalletFinished( QDBusPendingCallWatcher* ) {}
virtual void kwalletOpenFinished( QDBusPendingCallWatcher* ) {}
#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;
friend class Job;
friend class JobExecutor;
friend class ReadPasswordJob;
friend class WritePasswordJob;
friend class PlainTextStore;
};
class ReadPasswordJobPrivate : public JobPrivate {
Q_OBJECT
public:
explicit ReadPasswordJobPrivate( const QString &service_, ReadPasswordJob* qq );
void scheduledStart() override;
#if defined(KEYCHAIN_DBUS)
void fallbackOnError(const QDBusError& err);
private Q_SLOTS:
void kwalletOpenFinished( QDBusPendingCallWatcher* watcher );
void kwalletEntryTypeFinished( QDBusPendingCallWatcher* watcher );
void kwalletFinished( QDBusPendingCallWatcher* watcher );
#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* ) {}
#endif
friend class ReadPasswordJob;
};
class WritePasswordJobPrivate : public JobPrivate {
Q_OBJECT
public:
explicit WritePasswordJobPrivate( const QString &service_, WritePasswordJob* qq );
void scheduledStart() override;
#if defined(KEYCHAIN_DBUS)
void fallbackOnError(const QDBusError& err);
#endif
friend class WritePasswordJob;
};
class DeletePasswordJobPrivate : public JobPrivate {
Q_OBJECT
public:
explicit DeletePasswordJobPrivate( const QString &service_, DeletePasswordJob* qq );
void scheduledStart() override;
#if defined(KEYCHAIN_DBUS)
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;
};
}
#endif // KEYCHAIN_P_H