-
Notifications
You must be signed in to change notification settings - Fork 12
/
lock_screen.h
72 lines (53 loc) · 1.97 KB
/
lock_screen.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
#pragma once
#include <functional>
#include <gtkmm.h>
using UnlockCallback = std::function<void(std::string path, std::string masterPassword)>;
class LockScreen : public Gtk::Box {
public:
LockScreen(UnlockCallback _unlock_callback)
: Gtk::Box(Gtk::ORIENTATION_VERTICAL),
file_chooser(Gtk::FILE_CHOOSER_ACTION_SELECT_FOLDER),
password_field(),
unlock_button("Unlock"),
unlock_callback(_unlock_callback) {
set_halign(Gtk::ALIGN_CENTER);
set_valign(Gtk::ALIGN_CENTER);
set_spacing(5);
set_can_focus(false);
auto welcome_label = Gtk::manage(new Gtk::Label("Unlock your vault"));
pack_start(*welcome_label, false, true, 0);
pack_start(file_chooser, false, true, 0);
password_field.set_placeholder_text("Master Password");
password_field.set_visibility(false);
pack_start(password_field, false, true, 0);
unlock_button.set_image_from_icon_name("dialog-password");
unlock_button.set_always_show_image(true);
pack_start(unlock_button, false, true, 0);
unlock_button.signal_clicked().connect([this]() {
auto password_text = password_field.get_text();
auto vault_path = file_chooser.get_filename();
unlock_callback(vault_path, password_text);
});
password_field.signal_activate().connect([this]() { unlock_button.clicked(); });
show_all_children();
password_field.grab_focus();
};
std::string getPassword() {
return password_field.get_text();
}
void clearPassword() {
password_field.set_text("");
}
std::string getPath() {
return file_chooser.get_filename();
}
void setPath(std::string path) {
file_chooser.set_filename(path);
}
virtual ~LockScreen(){};
protected:
Gtk::FileChooserButton file_chooser;
Gtk::Entry password_field;
Gtk::Button unlock_button;
UnlockCallback unlock_callback;
};