aboutsummaryrefslogtreecommitdiff
path: root/src/ui
diff options
context:
space:
mode:
Diffstat (limited to 'src/ui')
-rw-r--r--src/ui/account_create.c122
-rw-r--r--src/ui/account_create_dialog.c122
-rw-r--r--src/ui/account_create_dialog.h (renamed from src/ui/account_create.h)22
-rw-r--r--src/ui/accounts.c10
-rw-r--r--src/ui/accounts.h4
-rw-r--r--src/ui/chat_open_dialog.c122
-rw-r--r--src/ui/chat_open_dialog.h51
-rw-r--r--src/ui/chats.c50
-rw-r--r--src/ui/chats.h4
9 files changed, 356 insertions, 151 deletions
diff --git a/src/ui/account_create.c b/src/ui/account_create.c
deleted file mode 100644
index 947317d..0000000
--- a/src/ui/account_create.c
+++ /dev/null
@@ -1,122 +0,0 @@
1/*
2 This file is part of GNUnet.
3 Copyright (C) 2022 GNUnet e.V.
4
5 GNUnet is free software: you can redistribute it and/or modify it
6 under the terms of the GNU Affero General Public License as published
7 by the Free Software Foundation, either version 3 of the License,
8 or (at your option) any later version.
9
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details.
14
15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17
18 SPDX-License-Identifier: AGPL3.0-or-later
19 */
20/*
21 * @author Tobias Frisch
22 * @file ui/account_create.c
23 */
24
25#include "account_create.h"
26
27#include <ctype.h>
28
29#include <gnunet/platform.h>
30#include <gnunet/gnunet_chat_lib.h>
31#include <gnunet/gnunet_util_lib.h>
32
33#include "../application.h"
34#include "../util.h"
35
36void
37account_create_event(UI_ACCOUNT_CREATE_Handle *create,
38 struct MESSENGER_Application *app,
39 int key)
40{
41 switch (key)
42 {
43 case 27:
44 case KEY_EXIT:
45 {
46 create->window = NULL;
47 break;
48 }
49 case KEY_LEFT:
50 {
51 create->name_pos--;
52 break;
53 }
54 case KEY_RIGHT:
55 {
56 create->name_pos++;
57 break;
58 }
59 case '\n':
60 case KEY_ENTER:
61 {
62 if (create->name_len > 0)
63 GNUNET_CHAT_account_create(app->chat.handle, create->name);
64
65 create->name_len = 0;
66 create->window = NULL;
67 break;
68 }
69 case KEY_BACKSPACE:
70 {
71 if ((create->name_pos < create->name_len) &&
72 (create->name_pos > 0))
73 for (int i = create->name_pos; i < create->name_len; i++)
74 create->name[i - 1] = create->name[i];
75
76 if ((create->name_pos > 0) && (create->name_len > 0))
77 {
78 create->name_pos--;
79 create->name_len--;
80 }
81
82 break;
83 }
84 default:
85 {
86 if (!isalnum(key))
87 break;
88
89 for (int i = create->name_len - 1; i >= create->name_pos; i--)
90 create->name[i + 1] = create->name[i];
91
92 create->name[create->name_pos++] = (char) key;
93 create->name_len++;
94 break;
95 }
96 }
97
98 if (create->name_len > 255)
99 create->name_len = 255;
100
101 create->name[create->name_len] = '\0';
102
103 if (create->name_pos < 0)
104 create->name_pos = 0;
105
106 if (create->name_pos > create->name_len)
107 create->name_pos = create->name_len;
108}
109
110void
111account_create_print(UI_ACCOUNT_CREATE_Handle *create,
112 UNUSED struct MESSENGER_Application *app)
113{
114 if (!(create->window))
115 return;
116
117 werase(create->window);
118 wmove(create->window, 0, 0);
119
120 wprintw(create->window, "%s", create->name);
121 wmove(create->window, 0, create->name_pos);
122}
diff --git a/src/ui/account_create_dialog.c b/src/ui/account_create_dialog.c
new file mode 100644
index 0000000..70e3fe3
--- /dev/null
+++ b/src/ui/account_create_dialog.c
@@ -0,0 +1,122 @@
1/*
2 This file is part of GNUnet.
3 Copyright (C) 2022 GNUnet e.V.
4
5 GNUnet is free software: you can redistribute it and/or modify it
6 under the terms of the GNU Affero General Public License as published
7 by the Free Software Foundation, either version 3 of the License,
8 or (at your option) any later version.
9
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details.
14
15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17
18 SPDX-License-Identifier: AGPL3.0-or-later
19 */
20/*
21 * @author Tobias Frisch
22 * @file ui/account_create_dialog.c
23 */
24
25#include "account_create_dialog.h"
26
27#include <ctype.h>
28
29#include <gnunet/platform.h>
30#include <gnunet/gnunet_chat_lib.h>
31#include <gnunet/gnunet_util_lib.h>
32
33#include "../application.h"
34#include "../util.h"
35
36void
37account_create_dialog_event(UI_ACCOUNT_CREATE_DIALOG_Handle *create_dialog,
38 struct MESSENGER_Application *app,
39 int key)
40{
41 switch (key)
42 {
43 case 27:
44 case KEY_EXIT:
45 {
46 create_dialog->window = NULL;
47 break;
48 }
49 case KEY_LEFT:
50 {
51 create_dialog->name_pos--;
52 break;
53 }
54 case KEY_RIGHT:
55 {
56 create_dialog->name_pos++;
57 break;
58 }
59 case '\n':
60 case KEY_ENTER:
61 {
62 if (create_dialog->name_len > 0)
63 GNUNET_CHAT_account_create(app->chat.handle, create_dialog->name);
64
65 create_dialog->name_len = 0;
66 create_dialog->window = NULL;
67 break;
68 }
69 case KEY_BACKSPACE:
70 {
71 if ((create_dialog->name_pos < create_dialog->name_len) &&
72 (create_dialog->name_pos > 0))
73 for (int i = create_dialog->name_pos; i < create_dialog->name_len; i++)
74 create_dialog->name[i - 1] = create_dialog->name[i];
75
76 if ((create_dialog->name_pos > 0) && (create_dialog->name_len > 0))
77 {
78 create_dialog->name_pos--;
79 create_dialog->name_len--;
80 }
81
82 break;
83 }
84 default:
85 {
86 if (!isalnum(key))
87 break;
88
89 for (int i = create_dialog->name_len - 1; i >= create_dialog->name_pos; i--)
90 create_dialog->name[i + 1] = create_dialog->name[i];
91
92 create_dialog->name[create_dialog->name_pos++] = (char) key;
93 create_dialog->name_len++;
94 break;
95 }
96 }
97
98 if (create_dialog->name_len > 255)
99 create_dialog->name_len = 255;
100
101 create_dialog->name[create_dialog->name_len] = '\0';
102
103 if (create_dialog->name_pos < 0)
104 create_dialog->name_pos = 0;
105
106 if (create_dialog->name_pos > create_dialog->name_len)
107 create_dialog->name_pos = create_dialog->name_len;
108}
109
110void
111account_create_dialog_print(UI_ACCOUNT_CREATE_DIALOG_Handle *create_dialog,
112 UNUSED struct MESSENGER_Application *app)
113{
114 if (!(create_dialog->window))
115 return;
116
117 werase(create_dialog->window);
118 wmove(create_dialog->window, 0, 0);
119
120 wprintw(create_dialog->window, "%s", create_dialog->name);
121 wmove(create_dialog->window, 0, create_dialog->name_pos);
122}
diff --git a/src/ui/account_create.h b/src/ui/account_create_dialog.h
index 3c06901..69dbb1c 100644
--- a/src/ui/account_create.h
+++ b/src/ui/account_create_dialog.h
@@ -19,33 +19,33 @@
19 */ 19 */
20/* 20/*
21 * @author Tobias Frisch 21 * @author Tobias Frisch
22 * @file ui/account_create.h 22 * @file ui/account_create_dialog.h
23 */ 23 */
24 24
25#ifndef UI_ACCOUNT_CREATE_H_ 25#ifndef UI_ACCOUNT_CREATE_DIALOG_H_
26#define UI_ACCOUNT_CREATE_H_ 26#define UI_ACCOUNT_CREATE_DIALOG_H_
27 27
28#include <stdlib.h> 28#include <stdlib.h>
29#include <curses.h> 29#include <curses.h>
30 30
31struct MESSENGER_Application; 31struct MESSENGER_Application;
32 32
33typedef struct UI_ACCOUNT_CREATE_Handle 33typedef struct UI_ACCOUNT_CREATE_DIALOG_Handle
34{ 34{
35 WINDOW *window; 35 WINDOW *window;
36 36
37 char name [256]; 37 char name [256];
38 int name_len; 38 int name_len;
39 int name_pos; 39 int name_pos;
40} UI_ACCOUNT_CREATE_Handle; 40} UI_ACCOUNT_CREATE_DIALOG_Handle;
41 41
42void 42void
43account_create_event(UI_ACCOUNT_CREATE_Handle *create, 43account_create_dialog_event(UI_ACCOUNT_CREATE_DIALOG_Handle *create_dialog,
44 struct MESSENGER_Application *app, 44 struct MESSENGER_Application *app,
45 int key); 45 int key);
46 46
47void 47void
48account_create_print(UI_ACCOUNT_CREATE_Handle *create, 48account_create_dialog_print(UI_ACCOUNT_CREATE_DIALOG_Handle *create_dialog,
49 struct MESSENGER_Application *app); 49 struct MESSENGER_Application *app);
50 50
51#endif /* UI_ACCOUNT_CREATE_H_ */ 51#endif /* UI_ACCOUNT_CREATE_DIALOG_H_ */
diff --git a/src/ui/accounts.c b/src/ui/accounts.c
index c3cdb85..377bdc9 100644
--- a/src/ui/accounts.c
+++ b/src/ui/accounts.c
@@ -49,9 +49,9 @@ accounts_event(UI_ACCOUNTS_Handle *accounts,
49 MESSENGER_Application *app, 49 MESSENGER_Application *app,
50 int key) 50 int key)
51{ 51{
52 if (accounts->create.window) 52 if (accounts->create_dialog.window)
53 { 53 {
54 account_create_event(&(accounts->create), app, key); 54 account_create_dialog_event(&(accounts->create_dialog), app, key);
55 return; 55 return;
56 } 56 }
57 57
@@ -88,7 +88,7 @@ accounts_event(UI_ACCOUNTS_Handle *accounts,
88 if (accounts->selected) 88 if (accounts->selected)
89 GNUNET_CHAT_connect(app->chat.handle, accounts->selected); 89 GNUNET_CHAT_connect(app->chat.handle, accounts->selected);
90 else 90 else
91 accounts->create.window = accounts->window; 91 accounts->create_dialog.window = accounts->window;
92 break; 92 break;
93 } 93 }
94 default: 94 default:
@@ -163,9 +163,9 @@ void
163accounts_print(UI_ACCOUNTS_Handle *accounts, 163accounts_print(UI_ACCOUNTS_Handle *accounts,
164 MESSENGER_Application *app) 164 MESSENGER_Application *app)
165{ 165{
166 if (accounts->create.window) 166 if (accounts->create_dialog.window)
167 { 167 {
168 account_create_print(&(accounts->create), app); 168 account_create_dialog_print(&(accounts->create_dialog), app);
169 return; 169 return;
170 } 170 }
171 171
diff --git a/src/ui/accounts.h b/src/ui/accounts.h
index a48411d..2ca55b5 100644
--- a/src/ui/accounts.h
+++ b/src/ui/accounts.h
@@ -32,7 +32,7 @@
32#include <gnunet/gnunet_chat_lib.h> 32#include <gnunet/gnunet_chat_lib.h>
33#include <gnunet/gnunet_util_lib.h> 33#include <gnunet/gnunet_util_lib.h>
34 34
35#include "account_create.h" 35#include "account_create_dialog.h"
36 36
37struct MESSENGER_Application; 37struct MESSENGER_Application;
38 38
@@ -46,7 +46,7 @@ typedef struct UI_ACCOUNTS_Handle
46 46
47 struct GNUNET_CHAT_Account *selected; 47 struct GNUNET_CHAT_Account *selected;
48 48
49 UI_ACCOUNT_CREATE_Handle create; 49 UI_ACCOUNT_CREATE_DIALOG_Handle create_dialog;
50} UI_ACCOUNTS_Handle; 50} UI_ACCOUNTS_Handle;
51 51
52void 52void
diff --git a/src/ui/chat_open_dialog.c b/src/ui/chat_open_dialog.c
new file mode 100644
index 0000000..4ebe8be
--- /dev/null
+++ b/src/ui/chat_open_dialog.c
@@ -0,0 +1,122 @@
1/*
2 This file is part of GNUnet.
3 Copyright (C) 2022 GNUnet e.V.
4
5 GNUnet is free software: you can redistribute it and/or modify it
6 under the terms of the GNU Affero General Public License as published
7 by the Free Software Foundation, either version 3 of the License,
8 or (at your option) any later version.
9
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details.
14
15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17
18 SPDX-License-Identifier: AGPL3.0-or-later
19 */
20/*
21 * @author Tobias Frisch
22 * @file ui/chat_open_dialog.c
23 */
24
25#include "chat_open_dialog.h"
26
27#include <ctype.h>
28
29#include <gnunet/platform.h>
30#include <gnunet/gnunet_chat_lib.h>
31#include <gnunet/gnunet_util_lib.h>
32
33#include "../application.h"
34#include "../util.h"
35
36void
37chat_open_dialog_event(UI_CHAT_OPEN_DIALOG_Handle *open_dialog,
38 struct MESSENGER_Application *app,
39 int key)
40{
41 switch (key)
42 {
43 case 27:
44 case KEY_EXIT:
45 {
46 open_dialog->window = NULL;
47 break;
48 }
49 case KEY_LEFT:
50 {
51 open_dialog->topic_pos--;
52 break;
53 }
54 case KEY_RIGHT:
55 {
56 open_dialog->topic_pos++;
57 break;
58 }
59 case '\n':
60 case KEY_ENTER:
61 {
62 if (open_dialog->topic_len > 0)
63 GNUNET_CHAT_group_create(app->chat.handle, open_dialog->topic);
64
65 open_dialog->topic_len = 0;
66 open_dialog->window = NULL;
67 break;
68 }
69 case KEY_BACKSPACE:
70 {
71 if ((open_dialog->topic_pos < open_dialog->topic_len) &&
72 (open_dialog->topic_pos > 0))
73 for (int i = open_dialog->topic_pos; i < open_dialog->topic_len; i++)
74 open_dialog->topic[i - 1] = open_dialog->topic[i];
75
76 if ((open_dialog->topic_pos > 0) && (open_dialog->topic_len > 0))
77 {
78 open_dialog->topic_pos--;
79 open_dialog->topic_len--;
80 }
81
82 break;
83 }
84 default:
85 {
86 if (!isalnum(key))
87 break;
88
89 for (int i = open_dialog->topic_len - 1; i >= open_dialog->topic_pos; i--)
90 open_dialog->topic[i + 1] = open_dialog->topic[i];
91
92 open_dialog->topic[open_dialog->topic_pos++] = (char) key;
93 open_dialog->topic_len++;
94 break;
95 }
96 }
97
98 if (open_dialog->topic_len > 255)
99 open_dialog->topic_len = 255;
100
101 open_dialog->topic[open_dialog->topic_len] = '\0';
102
103 if (open_dialog->topic_pos < 0)
104 open_dialog->topic_pos = 0;
105
106 if (open_dialog->topic_pos > open_dialog->topic_len)
107 open_dialog->topic_pos = open_dialog->topic_len;
108}
109
110void
111chat_open_dialog_print(UI_CHAT_OPEN_DIALOG_Handle *open_dialog,
112 UNUSED struct MESSENGER_Application *app)
113{
114 if (!(open_dialog->window))
115 return;
116
117 werase(open_dialog->window);
118 wmove(open_dialog->window, 0, 0);
119
120 wprintw(open_dialog->window, "%s", open_dialog->topic);
121 wmove(open_dialog->window, 0, open_dialog->topic_pos);
122}
diff --git a/src/ui/chat_open_dialog.h b/src/ui/chat_open_dialog.h
new file mode 100644
index 0000000..2adf465
--- /dev/null
+++ b/src/ui/chat_open_dialog.h
@@ -0,0 +1,51 @@
1/*
2 This file is part of GNUnet.
3 Copyright (C) 2022 GNUnet e.V.
4
5 GNUnet is free software: you can redistribute it and/or modify it
6 under the terms of the GNU Affero General Public License as published
7 by the Free Software Foundation, either version 3 of the License,
8 or (at your option) any later version.
9
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details.
14
15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17
18 SPDX-License-Identifier: AGPL3.0-or-later
19 */
20/*
21 * @author Tobias Frisch
22 * @file ui/chat_open_dialog.h
23 */
24
25#ifndef UI_CHAT_OPEN_DIALOG_H_
26#define UI_CHAT_OPEN_DIALOG_H_
27
28#include <stdlib.h>
29#include <curses.h>
30
31struct MESSENGER_Application;
32
33typedef struct UI_CHAT_OPEN_DIALOG_Handle
34{
35 WINDOW *window;
36
37 char topic [256];
38 int topic_len;
39 int topic_pos;
40} UI_CHAT_OPEN_DIALOG_Handle;
41
42void
43chat_open_dialog_event(UI_CHAT_OPEN_DIALOG_Handle *open_dialog,
44 struct MESSENGER_Application *app,
45 int key);
46
47void
48chat_open_dialog_print(UI_CHAT_OPEN_DIALOG_Handle *open_dialog,
49 struct MESSENGER_Application *app);
50
51#endif /* UI_CHAT_OPEN_DIALOG_H_ */
diff --git a/src/ui/chats.c b/src/ui/chats.c
index 991e43b..5d991a7 100644
--- a/src/ui/chats.c
+++ b/src/ui/chats.c
@@ -61,6 +61,12 @@ chats_event(UI_CHATS_Handle *chats,
61 MESSENGER_Application *app, 61 MESSENGER_Application *app,
62 int key) 62 int key)
63{ 63{
64 if (chats->open_dialog.window)
65 {
66 chat_open_dialog_event(&(chats->open_dialog), app, key);
67 return;
68 }
69
64 chats->line_index = 0; 70 chats->line_index = 0;
65 chats->selected = NULL; 71 chats->selected = NULL;
66 72
@@ -68,7 +74,7 @@ chats_event(UI_CHATS_Handle *chats,
68 app->chat.handle, 74 app->chat.handle,
69 &_chats_iterate, 75 &_chats_iterate,
70 chats 76 chats
71 ); 77 ) + 1;
72 78
73 switch (key) 79 switch (key)
74 { 80 {
@@ -108,7 +114,8 @@ chats_event(UI_CHATS_Handle *chats,
108 114
109 app->chat.context = chats->selected; 115 app->chat.context = chats->selected;
110 } 116 }
111 117 else
118 chats->open_dialog.window = chats->window;
112 break; 119 break;
113 } 120 }
114 default: 121 default:
@@ -137,13 +144,12 @@ chats_event(UI_CHATS_Handle *chats,
137 chats->line_offset = count - 1; 144 chats->line_offset = count - 1;
138} 145}
139 146
140int 147static int
141_chats_iterate_print(void *cls, 148_chats_print_entry(UI_CHATS_Handle *chats,
142 UNUSED struct GNUNET_CHAT_Handle *handle, 149 char type,
143 struct GNUNET_CHAT_Group *group) 150 char chat_type,
151 const char *text)
144{ 152{
145 UI_CHATS_Handle *chats = cls;
146
147 const bool selected = (chats->line_selected == chats->line_index); 153 const bool selected = (chats->line_selected == chats->line_index);
148 const int y = chats->line_index - chats->line_offset; 154 const int y = chats->line_index - chats->line_offset;
149 155
@@ -157,24 +163,44 @@ _chats_iterate_print(void *cls,
157 if (y >= height) 163 if (y >= height)
158 return GNUNET_NO; 164 return GNUNET_NO;
159 165
160 const char *name = GNUNET_CHAT_group_get_name(group);
161
162 const int attrs_select = A_BOLD; 166 const int attrs_select = A_BOLD;
163 167
164 if (selected) wattron(chats->window, attrs_select); 168 if (selected) wattron(chats->window, attrs_select);
165 169
166 wmove(chats->window, y, 0); 170 wmove(chats->window, y, 0);
167 wprintw(chats->window, "%s", name); 171
172 if (chat_type)
173 wprintw(chats->window, "[%c][%c] %s", type, chat_type, text);
174 else
175 wprintw(chats->window, "[%c] %s", type, text);
168 176
169 if (selected) wattroff(chats->window, attrs_select); 177 if (selected) wattroff(chats->window, attrs_select);
170 178
171 return GNUNET_YES; 179 return GNUNET_YES;
172} 180}
173 181
182int
183_chats_iterate_print(void *cls,
184 UNUSED struct GNUNET_CHAT_Handle *handle,
185 struct GNUNET_CHAT_Group *group)
186{
187 UI_CHATS_Handle *chats = cls;
188
189 const char *name = GNUNET_CHAT_group_get_name(group);
190
191 return _chats_print_entry(chats, 'x', 'G', name);
192}
193
174void 194void
175chats_print(UI_CHATS_Handle *chats, 195chats_print(UI_CHATS_Handle *chats,
176 MESSENGER_Application *app) 196 MESSENGER_Application *app)
177{ 197{
198 if (chats->open_dialog.window)
199 {
200 chat_open_dialog_print(&(chats->open_dialog), app);
201 return;
202 }
203
178 if (!(chats->window)) 204 if (!(chats->window))
179 return; 205 return;
180 206
@@ -186,4 +212,6 @@ chats_print(UI_CHATS_Handle *chats,
186 &_chats_iterate_print, 212 &_chats_iterate_print,
187 chats 213 chats
188 ); 214 );
215
216 _chats_print_entry(chats, '+', '\0', "Add chat");
189} 217}
diff --git a/src/ui/chats.h b/src/ui/chats.h
index 9ffee88..85a84eb 100644
--- a/src/ui/chats.h
+++ b/src/ui/chats.h
@@ -32,6 +32,8 @@
32#include <gnunet/gnunet_chat_lib.h> 32#include <gnunet/gnunet_chat_lib.h>
33#include <gnunet/gnunet_util_lib.h> 33#include <gnunet/gnunet_util_lib.h>
34 34
35#include "chat_open_dialog.h"
36
35struct MESSENGER_Application; 37struct MESSENGER_Application;
36 38
37typedef struct UI_CHATS_Handle 39typedef struct UI_CHATS_Handle
@@ -43,6 +45,8 @@ typedef struct UI_CHATS_Handle
43 int line_selected; 45 int line_selected;
44 46
45 struct GNUNET_CHAT_Context *selected; 47 struct GNUNET_CHAT_Context *selected;
48
49 UI_CHAT_OPEN_DIALOG_Handle open_dialog;
46} UI_CHATS_Handle; 50} UI_CHATS_Handle;
47 51
48void 52void