account_create_dialog.c (2122B)
1 /* 2 This file is part of GNUnet. 3 Copyright (C) 2022--2026 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 <gnunet/gnunet_chat_lib.h> 28 #include <gnunet/gnunet_util_lib.h> 29 30 #include "text_input.h" 31 32 #include "../application.h" 33 #include "../util.h" 34 35 void 36 account_create_dialog_event(UI_ACCOUNT_CREATE_DIALOG_Handle *create_dialog, 37 struct MESSENGER_Application *app, 38 int key) 39 { 40 switch (key) 41 { 42 case 27: 43 case KEY_EXIT: 44 create_dialog->window = NULL; 45 break; 46 case '\n': 47 case KEY_ENTER: 48 if (create_dialog->name_len > 0) 49 GNUNET_CHAT_account_create(app->chat.handle, create_dialog->name); 50 51 create_dialog->name_len = 0; 52 create_dialog->window = NULL; 53 break; 54 default: 55 break; 56 } 57 58 text_input_event(create_dialog->name, key); 59 } 60 61 void 62 account_create_dialog_print(UI_ACCOUNT_CREATE_DIALOG_Handle *create_dialog) 63 { 64 if (!(create_dialog->window)) 65 return; 66 67 WINDOW *window = *(create_dialog->window); 68 69 werase(window); 70 wmove(window, 0, 0); 71 72 util_print_prompt(window, "Enter name of the new account:"); 73 wmove(window, 1, 0); 74 75 wprintw(window, "> "); 76 wmove(window, 1, 2); 77 78 wattron(window, A_BOLD); 79 80 wprintw(window, "%s", create_dialog->name); 81 wmove(window, 1, 2 + create_dialog->name_pos); 82 83 wattroff(window, A_BOLD); 84 85 wcursyncup(window); 86 curs_set(1); 87 }