messenger-cli

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

chat_open_dialog.c (2420B)


      1 /*
      2    This file is part of GNUnet.
      3    Copyright (C) 2022--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 ui/chat_open_dialog.c
     23  */
     24 
     25 #include "chat_open_dialog.h"
     26 
     27 #include <gnunet/gnunet_chat_lib.h>
     28 #include <gnunet/gnunet_util_lib.h>
     29 
     30 #include "text_input.h"
     31 
     32 #include "../application.h"
     33 #include "../util.h"
     34 
     35 void
     36 chat_open_dialog_event(UI_CHAT_OPEN_DIALOG_Handle *open_dialog,
     37 		       struct MESSENGER_Application *app,
     38 		       int key)
     39 {
     40   switch (key)
     41   {
     42     case 27:
     43     case KEY_EXIT:
     44       open_dialog->window = NULL;
     45       break;
     46     case '\n':
     47     case KEY_ENTER:
     48     {
     49       if (open_dialog->topic_len > 0)
     50       {
     51         struct GNUNET_CHAT_Group *group;
     52         char *group_name = malloc(open_dialog->topic_len + 2);
     53 
     54         group = GNUNET_CHAT_group_create(app->chat.handle, open_dialog->topic);
     55         group_name[0] = '#';
     56         memcpy(group_name + 1, open_dialog->topic, open_dialog->topic_len + 1);
     57 
     58         GNUNET_CHAT_group_set_name(group, group_name);
     59         free(group_name);
     60       }
     61 
     62       open_dialog->topic_len = 0;
     63       open_dialog->window = NULL;
     64       break;
     65     }
     66     default:
     67       break;
     68   }
     69 
     70   text_input_event(open_dialog->topic, key);
     71 }
     72 
     73 void
     74 chat_open_dialog_print(UI_CHAT_OPEN_DIALOG_Handle *open_dialog)
     75 {
     76   if (!(open_dialog->window))
     77     return;
     78 
     79   WINDOW *window = *(open_dialog->window);
     80 
     81   werase(window);
     82   wmove(window, 0, 0);
     83 
     84   util_print_prompt(window, "Enter the topic of the public chat:");
     85   wmove(window, 1, 0);
     86 
     87   wprintw(window, "> ");
     88   wmove(window, 1, 2);
     89 
     90   wattron(window, A_BOLD);
     91 
     92   wprintw(window, "%s", open_dialog->topic);
     93   wmove(window, 1, 2 + open_dialog->topic_pos);
     94 
     95   wattroff(window, A_BOLD);
     96 
     97   wcursyncup(window);
     98   curs_set(1);
     99 }