-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathkeychain_container.h
78 lines (67 loc) · 2.22 KB
/
keychain_container.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
#pragma once
#include <gtkmm.h>
#include "helper.h"
#include "keychain_view.h"
#include "lock_screen.h"
class KeychainContainer : public Gtk::Bin {
public:
KeychainContainer(std::string path) : Gtk::Bin() {
lock_screen = std::unique_ptr<LockScreen>(
new LockScreen([this](std::string path, std::string master_password) {
unlock_callback(path, master_password);
}));
if (!path.empty()) {
lock_screen->setPath(path);
}
add(*lock_screen);
show_all_children();
}
void refresh() {
keychain_object->reloadItems();
keychain_view = std::unique_ptr<KeychainView>(new KeychainView(keychain_object));
remove();
add(*keychain_view);
show_all_children();
}
void lock() {
remove();
keychain_object.reset();
keychain_view.reset();
add(*lock_screen);
show_all_children();
}
void setUnlockCb(std::function<void(std::string title, std::string password)> fn) {
parent_unlock_cb = fn;
}
std::shared_ptr<Keychain> getKeychain() {
return std::shared_ptr<Keychain>(keychain_object);
}
void unlock(std::string master_password) {
unlock_impl(getPath(), master_password);
}
std::string getPath() {
return lock_screen->getPath();
}
protected:
void unlock_impl(std::string path, std::string master_password) {
try {
keychain_object = std::make_shared<Keychain>(path, master_password);
} catch (std::exception& e) {
errorDialog(e.what());
return;
}
remove();
keychain_view = std::unique_ptr<KeychainView>(new KeychainView(keychain_object));
add(*keychain_view);
show_all_children();
}
void unlock_callback(std::string path, std::string master_password) {
unlock_impl(path, master_password);
parent_unlock_cb(path, lock_screen->getPassword());
lock_screen->clearPassword();
}
std::unique_ptr<LockScreen> lock_screen;
std::shared_ptr<Keychain> keychain_object;
std::unique_ptr<KeychainView> keychain_view;
std::function<void(std::string title, std::string password)> parent_unlock_cb;
};