message.h (4955B)
1 /* 2 This file is part of GNUnet. 3 Copyright (C) 2021--2024 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/message.h 23 */ 24 25 #ifndef UI_MESSAGE_H_ 26 #define UI_MESSAGE_H_ 27 28 #include <stdbool.h> 29 30 #include <glib-2.0/glib.h> 31 #include <gtk-3.0/gtk/gtk.h> 32 #include <libhandy-1/handy.h> 33 34 #include <gnunet/gnunet_chat_lib.h> 35 36 typedef struct MESSENGER_Application MESSENGER_Application; 37 38 typedef enum UI_MESSAGE_Type 39 { 40 UI_MESSAGE_DEFAULT = 0, 41 UI_MESSAGE_SENT = 1, 42 UI_MESSAGE_STATUS = 2 43 } UI_MESSAGE_Type; 44 45 typedef void (*UI_MESSAGE_StatusCallback)(MESSENGER_Application *app, 46 gboolean status, 47 gpointer user_data); 48 49 typedef struct UI_MESSAGE_Handle 50 { 51 UI_MESSAGE_Type type; 52 53 time_t timestamp; 54 struct GNUNET_CHAT_Message *msg; 55 struct GNUNET_CHAT_Contact *contact; 56 57 UI_MESSAGE_StatusCallback status_cb; 58 gpointer status_cls; 59 60 GtkBuilder *builder [2]; 61 GtkWidget *message_box; 62 GtkFlowBox *tag_flow_box; 63 64 HdyAvatar *sender_avatar; 65 GtkLabel *sender_label; 66 GtkImage *private_image; 67 68 GtkRevealer *deny_revealer; 69 GtkRevealer *accept_revealer; 70 71 GtkButton *deny_button; 72 GtkButton *accept_button; 73 74 GtkLabel *timestamp_label; 75 GtkImage *read_receipt_image; 76 77 GtkStack *content_stack; 78 79 GtkLabel *text_label; 80 81 GtkRevealer *file_revealer; 82 GtkLabel *filename_label; 83 GtkProgressBar *file_progress_bar; 84 GtkButton *file_button; 85 GtkImage *file_status_image; 86 87 GtkDrawingArea *preview_drawing_area; 88 89 GtkRevealer *media_revealer; 90 GtkImage *media_type_image; 91 GtkLabel *media_label; 92 GtkProgressBar *media_progress_bar; 93 GtkButton *media_button; 94 95 MESSENGER_Application *app; 96 } UI_MESSAGE_Handle; 97 98 /** 99 * Allocates and creates a new message handle 100 * to represent a message for a given messenger 101 * application by selected message type. 102 * 103 * @param app Messenger application 104 * @param type Message type 105 * @return New message handle 106 */ 107 UI_MESSAGE_Handle* 108 ui_message_new(MESSENGER_Application *app, 109 UI_MESSAGE_Type type); 110 111 /** 112 * Refreshes the visual state of the read receipt 113 * from a given message handle. 114 * 115 * @param handle Message handle 116 */ 117 void 118 ui_message_refresh(UI_MESSAGE_Handle *handle); 119 120 /** 121 * Updates a given message handle with the 122 * current data from a messenger application 123 * and a selected chat message. 124 * 125 * @param handle Message handle 126 * @param app Messenger application 127 * @param message Chat message 128 */ 129 void 130 ui_message_update(UI_MESSAGE_Handle *handle, 131 MESSENGER_Application *app, 132 struct GNUNET_CHAT_Message *message); 133 134 /** 135 * Sets the contact of a given message handle 136 * to track contact information widgets. 137 * 138 * @param handle Message handle 139 * @param contact Contact 140 */ 141 void 142 ui_message_set_contact(UI_MESSAGE_Handle *handle, 143 struct GNUNET_CHAT_Contact *contact); 144 145 /** 146 * Sets the callback and closure of a given message 147 * handle for actions of a status message. 148 * 149 * @param handle Message handle 150 * @param cb Status callback 151 * @param cls Status closure 152 */ 153 void 154 ui_message_set_status_callback(UI_MESSAGE_Handle *handle, 155 UI_MESSAGE_StatusCallback cb, 156 gpointer cls); 157 158 /** 159 * Adds a widget to represent a given tag message 160 * to another message handle. 161 * 162 * @param handle Message handle 163 * @param app Messenger application 164 * @param tag_message Chat tag message 165 */ 166 void 167 ui_message_add_tag(UI_MESSAGE_Handle *handle, 168 MESSENGER_Application *app, 169 struct GNUNET_CHAT_Message *tag_message); 170 171 /** 172 * Remove a widget representing a given tag message 173 * from another message handle. 174 * 175 * @param handle Message handle 176 * @param app Messenger application 177 * @param tag_message Chat tag message 178 */ 179 void 180 ui_message_remove_tag(UI_MESSAGE_Handle *handle, 181 MESSENGER_Application *app, 182 struct GNUNET_CHAT_Message *tag_message); 183 184 /** 185 * Frees its resources and destroys a given 186 * message handle. 187 * 188 * @param handle Message handle 189 * @param app Messenger application 190 */ 191 void 192 ui_message_delete(UI_MESSAGE_Handle *handle, 193 MESSENGER_Application *app); 194 195 #endif /* UI_MESSAGE_H_ */