-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathuiComponent.cpp
More file actions
209 lines (185 loc) · 5.68 KB
/
uiComponent.cpp
File metadata and controls
209 lines (185 loc) · 5.68 KB
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
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
/*
(c) Matthew Slocum 2015
uiComponent.cpp
uiComponent is responsible for drawing the menus and interprating user input
the menu can:
change the destination
update destination list
change crypto key
start the messenger
*/
#include <iostream>
#include <string>
#include <stdlib.h>
#include "uiComponent.h"
#include "regComponent.h"
#include "msgComponent.h"
using namespace std;
uiComponent::uiComponent() {
cur_menu = MAIN;
select = "0";
}
void uiComponent::bind_regComponent(regComponent * in) {
reg = in;
}
void uiComponent::run() {
while(select!="q") {
//draw menu
switch(cur_menu) {
case(MAIN):
draw_main();
break;
case(SET_DEST):
draw_set_dest();
break;
case(SETTINGS):
draw_settings();
break;
case(SETTINGS_VIEW_KEY):
draw_view_key();
break;
case(SETTINGS_SET_KEY):
draw_set_key();
break;
case(SETTINGS_ADD_IP):
draw_add_ip();
break;
}
//get input
getInput();
//use input
switch(cur_menu) { //which menu are we refering to?
case(MAIN):
if(select=="1") {
cur_menu = SET_DEST;
} else if (select == "2") {
cin.ignore();
reg->msg->run();
} else if (select == "s") {
cur_menu = SETTINGS;
}
break;
case(SET_DEST):
if (select == "s") {
cur_menu = SETTINGS;
} else if (select == "m") {
cur_menu = MAIN;
} else {
int i;
i = atoi(select.c_str());
if(i<=reg->dest_count && i>=1) {
reg->setDest(i-1);
cur_menu = MAIN;
}
}
break;
case(SETTINGS_VIEW_KEY):
if (select == "s") {
cur_menu = SETTINGS;
} else if (select == "m") {
cur_menu = MAIN;
}
break;
case(SETTINGS_SET_KEY):
reg->setKey(select);
cur_menu = SETTINGS_VIEW_KEY;
break;
case(SETTINGS_ADD_IP):
reg->addIPToTable(select);
cur_menu = MAIN;
break;
case(SETTINGS):
if (select == "1") {
cur_menu = SETTINGS_VIEW_KEY;
} else if (select == "2") {
cur_menu = SETTINGS_SET_KEY;
prompt_helper = "Enter New Crypto Key";
} else if (select == "3") {
cur_menu = SETTINGS_ADD_IP;
prompt_helper = "Add Destination {name,IP}";
} else if (select == "m") {
cur_menu = MAIN;
}
break;
}
}
}
void uiComponent::draw_menu_header(string menu_name) {
string destination;
if(reg->dest==-1) {
destination = "Unset";
} else {
destination = "[" + reg->name_list[reg->dest] + "] " + reg->dest_list[reg->dest];
}
system("clear");
cout << "|------------TauNet v0.01------------|" << endl;
cout << "| Destination: " << destination << endl;
cout << "| Menu: " << menu_name << endl;
cout << "|------------------------------------|" << endl;
}
void uiComponent:: draw_menu_footer() {
cout << "|" << endl;
cout << "| q. Quit" << endl;
cout << "|------------------------------------|" << endl << endl;
}
void uiComponent::draw_main() {
draw_menu_header("Main");
cout << "| 1. Set Destination" << endl;
cout << "| 2. Start Messenger" << endl;
cout << "|" << endl;
cout << "| s. Settings Menu" << endl;
cout << "| d. Debug Menu" << endl;
draw_menu_footer();
}
void uiComponent::draw_settings() {
draw_menu_header("Settings");
cout << "| 1. View crypto key" << endl;
cout << "| 2. Change crypto key" << endl;
cout << "|" << endl;
cout << "| 3. Add IP" << endl;
cout << "|" << endl;
cout << "| m. Main Menu" << endl;
draw_menu_footer();
}
void uiComponent::draw_debug() {
draw_menu_header("Debug");
cout << "| 1. View IP list" << endl;
cout << "| 2. View Crypto Key" << endl;
cout << "|" << endl;
cout << "| m. Main Menu" << endl;
draw_menu_footer();
}
void uiComponent::draw_set_dest() {
draw_menu_header("Set Destination");
reg->printDest();
cout << "|" << endl;
cout << "| s. Settings Menu" << endl;
cout << "| m. Main Menu" << endl;
draw_menu_footer();
}
void uiComponent::draw_view_key() {
draw_menu_header("View Crypto Key");
cout << "| Key: " << reg->key << endl;
cout << "|" << endl;
cout << "| s. Settings Menu" << endl;
cout << "| m. Main Menu" << endl;
draw_menu_footer();
}
void uiComponent::draw_set_key() {
draw_menu_header("View Crypto Key");
cout << "| Current Key: " << reg->key << endl;
cout << "|------------------------------------|" << endl << endl;
}
void uiComponent::draw_add_ip() {
draw_menu_header("Add User,IP");
}
void uiComponent::getInput() {
cin.clear();
if(prompt_helper!="") {
cout << "TauNet [" << prompt_helper << "]> ";
prompt_helper="";
} else {
cout << "TauNet> ";
}
cin >> select;
}