messages.h (3121B)
1 /* 2 This file is part of GNUnet. 3 Copyright (C) 2022--2024, 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/messages.h 23 */ 24 25 #ifndef UI_MESSAGES_H_ 26 #define UI_MESSAGES_H_ 27 28 #include <time.h> 29 #include <unistd.h> 30 #include <curses.h> 31 32 #include <gnunet/gnunet_chat_lib.h> 33 #include <gnunet/gnunet_util_lib.h> 34 35 struct MESSENGER_Application; 36 37 /** 38 * @struct UI_MESSAGES_List 39 */ 40 typedef struct UI_MESSAGES_List 41 { 42 time_t timestamp; 43 44 struct GNUNET_CHAT_Message *message; 45 46 struct UI_MESSAGES_List *prev; 47 struct UI_MESSAGES_List *next; 48 } UI_MESSAGES_List; 49 50 #define TEXT_LEN_MAX 1024 51 52 /** 53 * @struct UI_MESSAGES_Handle 54 */ 55 typedef struct UI_MESSAGES_Handle 56 { 57 WINDOW *window; 58 59 UI_MESSAGES_List *head; 60 UI_MESSAGES_List *tail; 61 62 int line_prev; 63 int line_next; 64 65 int line_index; 66 int line_offset; 67 int line_selected; 68 time_t line_time; 69 70 struct GNUNET_CHAT_Message *selected; 71 72 char text [1024]; 73 int text_len; 74 int text_pos; 75 } UI_MESSAGES_Handle; 76 77 #define UI_MESSAGES_COLS_MIN 50 78 79 #define UI_MESSAGES_FILE_PREFIX "file:" 80 #define UI_MESSAGES_FILE_PREFIX_LEN 5 81 82 /** 83 * Processes the current key event by the view 84 * to show a chats list of messages. 85 * 86 * @param[in,out] messages Chat messages view 87 * @param[in,out] app Application handle 88 * @param[in] key Key 89 */ 90 void 91 messages_event(UI_MESSAGES_Handle *messages, 92 struct MESSENGER_Application *app, 93 int key); 94 95 /** 96 * Prints the content of the view to show 97 * a chats list of messages to its selected 98 * window view on screen. 99 * 100 * @param[in,out] messages Chat messages view 101 */ 102 void 103 messages_print(UI_MESSAGES_Handle *messages); 104 105 /** 106 * Clears the list of messages the view 107 * would print to the screen. 108 * 109 * @param[out] messages Chat messages view 110 */ 111 void 112 messages_clear(UI_MESSAGES_Handle *messages); 113 114 /** 115 * Adds a new chat message to the list of 116 * messages the view will print to the 117 * screen. 118 * 119 * @param[in,out] messages Chat messages view 120 * @param[in,out] message Chat message 121 */ 122 void 123 messages_add(UI_MESSAGES_Handle *messages, 124 struct GNUNET_CHAT_Message *message); 125 126 /** 127 * Removes a chat message from the list of 128 * messages the view would print to the 129 * screen. 130 * 131 * @param[in,out] messages Chat messages view 132 * @param[in,out] message Chat message 133 */ 134 void 135 messages_remove(UI_MESSAGES_Handle *messages, 136 struct GNUNET_CHAT_Message *message); 137 138 #endif /* UI_MESSAGES_H_ */