messenger-cli

Command-line user interface for GNUnet Messenger
Log | Files | Refs | README | LICENSE

messages.h (3135B)


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