-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathotp_add_entry.cpp
68 lines (61 loc) · 2.48 KB
/
otp_add_entry.cpp
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
#include <string>
#include <semaphore>
#include "otp_add_entry.hpp"
OTP_AddEntry::OTP_AddEntry(GApplication* application,
GtkContainer* cont,
std::shared_ptr<CommandReader> command_reader,
std::binary_semaphore* sem)
: app(application),
container(cont),
cmd_reader(command_reader),
add_window(),
notification_sem(sem) {
button = gtk_button_new_with_label("ADD NEW");
placeholder_label = gtk_label_new(nullptr);
layout = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 10);
gtk_container_add(GTK_CONTAINER(container), layout);
gtk_box_set_homogeneous(reinterpret_cast<GtkBox*>(layout), TRUE);
gtk_container_add(GTK_CONTAINER(layout), button);
gtk_container_add(GTK_CONTAINER(layout), placeholder_label);
g_signal_connect(button, "clicked", G_CALLBACK(on_button_clicked), this);
}
OTP_AddEntry::~OTP_AddEntry() {
gtk_container_remove(GTK_CONTAINER(layout), placeholder_label);
gtk_container_remove(GTK_CONTAINER(layout), button);
gtk_container_remove(GTK_CONTAINER(container), layout);
}
void OTP_AddEntry::on_button_clicked(GtkButton* button, gpointer data) {
OTP_AddEntry* instance = static_cast<OTP_AddEntry*>(data);
instance->on_button_clicked_member();
}
void OTP_AddEntry::on_button_clicked_member() {
std::string result;
try {
printf("Adding new entry...\n");
add_window = make_shared<OTP_EntryAddWindow>(app, cmd_reader, notification_sem);
} catch (std::invalid_argument e) {
result = e.what();
printf("%s\n", result.c_str());
// color_text(result, "yellow");
// gtk_label_set_markup(info_bar, result.c_str());
} catch (std::out_of_range e) {
result = e.what();
printf("%s\n", result.c_str());
// color_text(result, "yellow");
// gtk_label_set_markup(info_bar, result.c_str());
} catch (ReaderException e) {
result = std::string("ERROR: ").append(e.what());
result.append(".");
if (e.get_error_number() == EPERM) {
result.append(" No permission to open device.");
} else if (e.get_error_number() == ENOENT) {
result.append(" Device doesn't exist.");
} else {
result.append(" Unknown error: ");
result.append(std::to_string(e.get_error_number()));
}
printf("result: %s\n", result.c_str());
// color_text(result, "yellow");
// gtk_label_set_markup(info_bar, result.c_str());
}
}