file.h (3984B)
1 /* 2 This file is part of GNUnet. 3 Copyright (C) 2022--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 file.h 23 */ 24 25 #ifndef FILE_H_ 26 #define FILE_H_ 27 28 #include "application.h" 29 #include "ui/message.h" 30 31 typedef struct MESSENGER_FileInfo 32 { 33 MESSENGER_Application *app; 34 35 guint update_task; 36 GList *file_messages; 37 38 GdkPixbuf *preview_image; 39 GdkPixbufAnimation *preview_animation; 40 GdkPixbufAnimationIter *preview_animation_iter; 41 42 guint redraw_animation_task; 43 GList *preview_widgets; 44 } MESSENGER_FileInfo; 45 46 /** 47 * Creates a file information struct to potentially update 48 * all GUI appearances of a specific file at once. 49 * 50 * @param file Chat file 51 */ 52 void 53 file_create_info(struct GNUNET_CHAT_File *file); 54 55 /** 56 * Destroys and frees resources allocated for a given 57 * file information struct. 58 * 59 * @param file Chat file 60 */ 61 void 62 file_destroy_info(struct GNUNET_CHAT_File *file); 63 64 /** 65 * Adds a UI message handle to the list of handles 66 * which get updated by state changes. 67 * 68 * @param file Chat file 69 * @param message UI message handle 70 */ 71 void 72 file_add_ui_message_to_info(const struct GNUNET_CHAT_File *file, 73 UI_MESSAGE_Handle *message); 74 75 /** 76 * Adds a widget to the list of widgets which get 77 * redrawn automatically when displaying an animation. 78 * 79 * @param file Chat file 80 * @param widget Preview widget 81 */ 82 void 83 file_add_widget_to_preview(const struct GNUNET_CHAT_File *file, 84 GtkWidget *widget); 85 86 /** 87 * Removes a widgets from the list of widgets which 88 * get redrawn automatically when displaying an 89 * animation. 90 * 91 * @param file Chat file 92 * @param widget Preview widget 93 */ 94 void 95 file_remove_widget_from_preview(const struct GNUNET_CHAT_File *file, 96 GtkWidget *widget); 97 98 /** 99 * Updates the connected UI elements for a given 100 * file depending on the current state of its upload 101 * process. 102 * 103 * @param file Chat file 104 * @param completed Amount of uploaded bytes 105 * @param size Size of the file in bytes 106 */ 107 void 108 file_update_upload_info(const struct GNUNET_CHAT_File *file, 109 uint64_t completed, 110 uint64_t size); 111 112 /** 113 * Updates the connected UI elements for a given 114 * file depending on the current state of its download 115 * process. 116 * 117 * @param file Chat file 118 * @param app Messenger application 119 * @param completed Amount of downloaded bytes 120 * @param size Size of the file in bytes 121 */ 122 void 123 file_update_download_info(const struct GNUNET_CHAT_File *file, 124 MESSENGER_Application *app, 125 uint64_t completed, 126 uint64_t size); 127 128 /** 129 * Loads required image data for a given file into memory 130 * to display a preview image. 131 * 132 * @param file Chat file 133 */ 134 void 135 file_load_preview_image(struct GNUNET_CHAT_File *file); 136 137 /** 138 * Unloads/Frees required image data of a given file from 139 * memory to displaying a preview image. 140 * 141 * @param file Chat file 142 */ 143 void 144 file_unload_preview_image(const struct GNUNET_CHAT_File *file); 145 146 /** 147 * Returns the current image data to preview a given file 148 * as animated or static image. 149 * 150 * @param file Chat file 151 */ 152 GdkPixbuf* 153 file_get_current_preview_image(const struct GNUNET_CHAT_File *file); 154 155 #endif /* FILE_H_ */