aboutsummaryrefslogtreecommitdiff
path: root/src/ui/lobby_enter_dialog.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/ui/lobby_enter_dialog.c')
-rw-r--r--src/ui/lobby_enter_dialog.c104
1 files changed, 104 insertions, 0 deletions
diff --git a/src/ui/lobby_enter_dialog.c b/src/ui/lobby_enter_dialog.c
new file mode 100644
index 0000000..6de4d1c
--- /dev/null
+++ b/src/ui/lobby_enter_dialog.c
@@ -0,0 +1,104 @@
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/lobby_enter_dialog.c
23 */
24
25#include "lobby_enter_dialog.h"
26
27#include <gnunet/platform.h>
28#include <gnunet/gnunet_chat_lib.h>
29#include <gnunet/gnunet_util_lib.h>
30
31#include "text_input.h"
32#include "../application.h"
33#include "../util.h"
34
35void
36lobby_enter_dialog_event(UI_LOBBY_ENTER_DIALOG_Handle *enter_dialog,
37 struct MESSENGER_Application *app,
38 int key)
39{
40 struct GNUNET_CHAT_Uri *uri;
41
42 switch (key)
43 {
44 case 27:
45 case KEY_EXIT:
46 if (enter_dialog->error)
47 GNUNET_free(enter_dialog->error);
48
49 enter_dialog->error = NULL;
50 enter_dialog->window = NULL;
51 break;
52 case '\n':
53 case KEY_ENTER:
54 if (enter_dialog->uri_len > 0)
55 {
56 if (enter_dialog->error)
57 GNUNET_free(enter_dialog->error);
58
59 enter_dialog->error = NULL;
60 uri = GNUNET_CHAT_uri_parse(enter_dialog->uri, &(enter_dialog->error));
61
62 if (uri)
63 {
64 GNUNET_CHAT_lobby_join(app->chat.handle, uri);
65 GNUNET_CHAT_uri_destroy(uri);
66
67 enter_dialog->uri_len = 0;
68 enter_dialog->window = NULL;
69 }
70 }
71
72 break;
73 default:
74 break;
75 }
76
77 text_input_event(enter_dialog->uri, key);
78}
79
80void
81lobby_enter_dialog_print(UI_LOBBY_ENTER_DIALOG_Handle *enter_dialog,
82 UNUSED struct MESSENGER_Application *app)
83{
84 if (!(enter_dialog->window))
85 return;
86
87 WINDOW *window = *(enter_dialog->window);
88
89 werase(window);
90 wmove(window, 0, 0);
91
92 wprintw(window, "%s", enter_dialog->uri);
93
94 if (enter_dialog->error)
95 {
96 wmove(window, 1, 0);
97 wprintw(window, "ERROR: %s", enter_dialog->error);
98 }
99
100 wmove(window, 0, enter_dialog->uri_pos);
101
102 wcursyncup(window);
103 curs_set(1);
104}