messenger-gtk

Gtk+3 graphical user interfaces for GNUnet Messenger
Log | Files | Refs | Submodules | README | LICENSE

application.h (8484B)


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