application.h (8466B)
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 application.h 23 */ 24 25 #ifndef APPLICATION_H_ 26 #define APPLICATION_H_ 27 28 #ifndef MESSENGER_APPLICATION_NO_PORTAL 29 #include <libportal/portal.h> 30 #endif 31 32 #include <pipewire/pipewire.h> 33 #include <pthread.h> 34 35 #include <gnunet/gnunet_chat_lib.h> 36 37 #include "chat/messenger.h" 38 39 #include "ui/about.h" 40 #include "ui/accounts.h" 41 #include "ui/contact_info.h" 42 #include "ui/contacts.h" 43 #include "ui/delete_messages.h" 44 #include "ui/discourse.h" 45 #include "ui/files.h" 46 #include "ui/invite_contact.h" 47 #include "ui/messenger.h" 48 #include "ui/new_account.h" 49 #include "ui/new_contact.h" 50 #include "ui/new_group.h" 51 #include "ui/new_lobby.h" 52 #include "ui/new_platform.h" 53 #include "ui/new_tag.h" 54 #include "ui/play_media.h" 55 #include "ui/send_file.h" 56 #include "ui/settings.h" 57 58 #include "media.h" 59 #include "schedule.h" 60 #include "util.h" 61 62 #define MESSENGER_APPLICATION_APPNAME "GNUnet Messenger" 63 #define MESSENGER_APPLICATION_NAME "Messenger-GTK" 64 #define MESSENGER_APPLICATION_DESCRIPTION \ 65 "A GTK based GUI for the Messenger service of GNUnet." 66 #define MESSENGER_APPLICATION_TITLE "Messenger" 67 #define MESSENGER_APPLICATION_SUBTITLE "GNUnet" 68 69 typedef enum MESSENGER_ApplicationSignal 70 { 71 MESSENGER_NONE = 0, 72 MESSENGER_QUIT = 1, 73 MESSENGER_FAIL = 2 74 } MESSENGER_ApplicationSignal; 75 76 typedef enum MESSENGER_ApplicationState 77 { 78 MESSENGER_STATE_UNKNOWN = 0, 79 MESSENGER_STATE_ACCOUNTS = 1, 80 MESSENGER_STATE_NEW_ACCOUNT = 2, 81 MESSENGER_STATE_MAIN_WINDOW = 3 82 } MESSENGER_ApplicationState; 83 84 typedef struct MESSENGER_Application 85 { 86 char **argv; 87 int argc; 88 89 GtkApplication *application; 90 GList *notifications; 91 GList *requests; 92 guint init; 93 94 #ifndef MESSENGER_APPLICATION_NO_PORTAL 95 XdpPortal *portal; 96 XdpParent *parent; 97 XdpSession *session; 98 #endif 99 100 struct { 101 GQuark widget; 102 GQuark data; 103 GQuark ui; 104 } quarks; 105 106 struct { 107 struct pw_main_loop *main_loop; 108 struct pw_loop *loop; 109 struct pw_context *context; 110 } pw; 111 112 struct { 113 MESSENGER_MediaInfo camera; 114 MESSENGER_MediaInfo screen; 115 } media; 116 117 struct { 118 int status; 119 pthread_t tid; 120 char *identity; 121 122 CHAT_MESSENGER_Handle messenger; 123 124 MESSENGER_Schedule schedule; 125 } chat; 126 127 struct { 128 MESSENGER_ApplicationState state; 129 int status; 130 131 UI_MESSENGER_Handle messenger; 132 UI_ABOUT_Handle about; 133 134 UI_CONTACT_INFO_Handle contact_info; 135 UI_DELETE_MESSAGES_Handle delete_messages; 136 UI_DISCOURSE_Handle discourse; 137 UI_INVITE_CONTACT_Handle invite_contact; 138 UI_SEND_FILE_Handle send_file; 139 UI_PLAY_MEDIA_Handle play_media; 140 141 UI_NEW_ACCOUNT_Handle new_account; 142 UI_NEW_CONTACT_Handle new_contact; 143 UI_NEW_GROUP_Handle new_group; 144 UI_NEW_LOBBY_Handle new_lobby; 145 UI_NEW_PLATFORM_Handle new_platform; 146 UI_NEW_TAG_Handle new_tag; 147 148 UI_ACCOUNTS_Handle accounts; 149 UI_FILES_Handle files; 150 UI_CONTACTS_Handle contacts; 151 UI_SETTINGS_Handle settings; 152 153 MESSENGER_Schedule schedule; 154 } ui; 155 156 struct { 157 gboolean hide_delete_dialog; 158 159 gboolean autostart; 160 gboolean background_task; 161 162 gboolean disable_notifications; 163 gboolean play_notification_sounds; 164 165 gboolean send_read_receipts; 166 167 gulong auto_delete_delay; 168 169 gboolean accept_all_invitations; 170 gulong delete_invitations_delay; 171 172 gboolean accept_all_files; 173 gchar *download_folder_path; 174 gulong delete_files_delay; 175 176 gulong leave_chats_delay; 177 } settings; 178 } MESSENGER_Application; 179 180 /** 181 * Initializes the messenger application with 182 * startup arguments. 183 * 184 * @param app Messenger application 185 * @param argc Amount of arguments 186 * @param argv Arguments 187 */ 188 void 189 application_init(MESSENGER_Application *app, 190 int argc, 191 char **argv); 192 193 /** 194 * Returns the path from resources of the 195 * messenger application relative to its storage. 196 * 197 * @param app Messenger application 198 * @param path Path 199 * @return Resource path 200 */ 201 const gchar* 202 application_get_resource_path(MESSENGER_Application *app, 203 const char *path); 204 205 /** 206 * Runs the messenger application starting the 207 * second thread and waiting for the application 208 * to finish. 209 * 210 * @param app Messenger application 211 */ 212 void 213 application_run(MESSENGER_Application *app); 214 215 /** 216 * Initialize the pipewire core of the messenger 217 * application if possible. 218 * 219 * @param app Messenger application 220 */ 221 void 222 application_pw_core_init(MESSENGER_Application *app); 223 224 /** 225 * Cleanups the pipewire core of the messenger 226 * application if available. 227 */ 228 void 229 application_pw_core_cleanup(MESSENGER_Application *app); 230 231 /** 232 * Run the pipewire main loop of the messenger 233 * application if available. 234 * 235 * @param app Messenger application 236 */ 237 void 238 application_pw_main_loop_run(MESSENGER_Application *app); 239 240 #ifndef MESSENGER_APPLICATION_NO_PORTAL 241 /** 242 * Sets the active session for the messenger 243 * application and frees the previous one 244 * if any is still active. 245 * 246 * @param app Messenger application 247 * @param session Screencast session 248 */ 249 void 250 application_set_active_session(MESSENGER_Application *app, 251 XdpSession *session); 252 253 /** 254 * Returns the file descriptor to the pipewire 255 * remote where the screencast streams of the 256 * active session from the messenger application 257 * are available. 258 * 259 * @param app Messenger application 260 * @return File descriptor 261 */ 262 int 263 application_get_active_session_remote(MESSENGER_Application *app); 264 #endif 265 266 /** 267 * Shows the messenger application main window. 268 * 269 * @param app Messenger application 270 */ 271 void 272 application_show_window(MESSENGER_Application *app); 273 274 typedef void (*MESSENGER_ApplicationEvent) ( 275 MESSENGER_Application *app 276 ); 277 278 typedef void (*MESSENGER_ApplicationMessageEvent) ( 279 MESSENGER_Application *app, 280 struct GNUNET_CHAT_Context *context, 281 struct GNUNET_CHAT_Message *msg 282 ); 283 284 /** 285 * Calls a given event with the messenger application 286 * asyncronously but explicitly synchronized via mutex. 287 * 288 * @param app Messenger application 289 * @param event Event 290 */ 291 void 292 application_call_event(MESSENGER_Application *app, 293 MESSENGER_ApplicationEvent event); 294 295 /** 296 * Calls a given event with the messenger application 297 * syncronously. 298 * 299 * @param app Messenger application 300 * @param event Event 301 */ 302 void 303 application_call_sync_event(MESSENGER_Application *app, 304 MESSENGER_ApplicationEvent event); 305 306 /** 307 * Calls a given message event with the messenger 308 * application asyncronously but explicitly synchronized 309 * via mutex. 310 * 311 * @param app Messenger application 312 * @param event Message event 313 * @param context Chat context 314 * @param message Message 315 */ 316 void 317 application_call_message_event(MESSENGER_Application *app, 318 MESSENGER_ApplicationMessageEvent event, 319 struct GNUNET_CHAT_Context *context, 320 struct GNUNET_CHAT_Message *message); 321 322 /** 323 * Lock the thread of the GNUnet scheduler 324 * until it gets unlocked again. 325 * 326 * @param app Messenger application 327 */ 328 void 329 application_chat_lock(MESSENGER_Application *app); 330 331 /** 332 * Unlock the thread of the GNUnet scheduler 333 * after being locked. 334 * 335 * @param app Messenger application 336 */ 337 void 338 application_chat_unlock(MESSENGER_Application *app); 339 340 /** 341 * Signals the second thread to exit the application. 342 * 343 * @param app Messenger application 344 * @param signal Exit signal 345 */ 346 void 347 application_exit(MESSENGER_Application *app, 348 MESSENGER_ApplicationSignal signal); 349 350 /** 351 * Returns the exit status of the messenger application. 352 * 353 * @param app Messenger application 354 * @return Exit status 355 */ 356 int 357 application_status(MESSENGER_Application *app); 358 359 #endif /* APPLICATION_H_ */