-
Notifications
You must be signed in to change notification settings - Fork 0
/
keychain.h
45 lines (35 loc) · 1.06 KB
/
keychain.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
#ifndef KEYCHAIN_H
#define KEYCHAIN_H
#include <boost/utility.hpp>
#include <QString>
class Keychain : boost::noncopyable {
public:
virtual ~Keychain() {}
virtual bool isAvailable() = 0;
virtual const QString getPassword(const QString& account) = 0;
virtual bool setPassword(const QString& account, const QString& password) = 0;
virtual const QString& implementationName() const = 0;
static Keychain* getDefault();
static void init();
protected:
static const QString kServiceName;
private:
// Fun for all the family.
struct KeychainDefinition {
KeychainDefinition(const QString& name) : name_(name) {}
virtual ~KeychainDefinition() {}
const QString& getName() const { return name_; }
virtual Keychain* getInstance() const = 0;
protected:
const QString& name_;
};
template<typename T>
struct KeychainImpl : public KeychainDefinition {
KeychainImpl() : KeychainDefinition(T::kImplementationName) { T::init(); }
virtual Keychain* getInstance() const {
return new T();
}
};
static const KeychainDefinition* kCompiledImplementations[];
};
#endif