messenger-cli

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

lobby_create_dialog.c (4198B)


      1 /*
      2    This file is part of GNUnet.
      3    Copyright (C) 2022--2025 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/lobby_create_dialog.c
     23  */
     24 
     25 #include "lobby_create_dialog.h"
     26 
     27 #include "list_input.h"
     28 #include "../application.h"
     29 #include "../util.h"
     30 
     31 void
     32 _lobby_open_with_uri(void *cls,
     33                      const struct GNUNET_CHAT_Uri *uri)
     34 {
     35   UI_LOBBY_CREATE_DIALOG_Handle *create_dialog = cls;
     36 
     37   if (create_dialog->uri)
     38     GNUNET_free(create_dialog->uri);
     39 
     40   create_dialog->uri = GNUNET_CHAT_uri_to_string(uri);
     41 }
     42 
     43 void
     44 lobby_create_dialog_event(UI_LOBBY_CREATE_DIALOG_Handle *create_dialog,
     45                           UNUSED struct MESSENGER_Application *app,
     46                           int key)
     47 {
     48   create_dialog->window = *(create_dialog->win);
     49 
     50   list_input_reset(create_dialog);
     51 
     52   if (create_dialog->uri)
     53     list_input_select(create_dialog, 1, 0)
     54   else
     55   {
     56     list_input_select(create_dialog, 1, 30);
     57     list_input_select(create_dialog, 1, 5 * 60);
     58     list_input_select(create_dialog, 1, 60 * 60);
     59     list_input_select(create_dialog, 1, 8 * 60 * 60);
     60     list_input_select(create_dialog, 1, 24 * 60 * 60);
     61     list_input_select(create_dialog, 1, 7 * 24 * 60 * 60);
     62     list_input_select(create_dialog, 1, 4 * 7 * 60 * 60);
     63     list_input_select(create_dialog, 1, 0);
     64   }
     65 
     66   switch (key)
     67   {
     68     case 27:
     69     case KEY_EXIT:
     70       if (create_dialog->lobby)
     71         GNUNET_CHAT_lobby_close(create_dialog->lobby);
     72 
     73       create_dialog->lobby = NULL;
     74       create_dialog->win = NULL;
     75       break;
     76     case '\n':
     77     case KEY_ENTER:
     78       if (create_dialog->uri)
     79       {
     80         GNUNET_free(create_dialog->uri);
     81 
     82         create_dialog->lobby = NULL;
     83         create_dialog->win = NULL;
     84       }
     85       else if (!(create_dialog->lobby))
     86         create_dialog->lobby = GNUNET_CHAT_lobby_open(
     87           app->chat.handle,
     88           create_dialog->selected,
     89           _lobby_open_with_uri,
     90           create_dialog
     91         );
     92 
     93       break;
     94     default:
     95       break;
     96   }
     97 
     98   if (!(create_dialog->lobby))
     99     list_input_event(create_dialog, key)
    100   else
    101     list_input_event(create_dialog, KEY_RESIZE);
    102 }
    103 
    104 static void
    105 _lobby_iterate_print(UI_LOBBY_CREATE_DIALOG_Handle *create_dialog,
    106                      const char *label)
    107 {
    108   list_input_print(create_dialog, 1);
    109 
    110   const int attrs_select = A_BOLD;
    111 
    112   if (selected) wattron(create_dialog->window, attrs_select);
    113 
    114   wmove(create_dialog->window, 1 + y, 0);
    115   wprintw(create_dialog->window, "> %s", label);
    116 
    117   if (selected) wattroff(create_dialog->window, attrs_select);
    118 }
    119 
    120 void
    121 lobby_create_dialog_print(UI_LOBBY_CREATE_DIALOG_Handle *create_dialog)
    122 {
    123   if (!(create_dialog->win))
    124     return;
    125 
    126   create_dialog->window = *(create_dialog->win);
    127 
    128   list_input_reset(create_dialog);
    129   werase(create_dialog->window);
    130 
    131   wmove(create_dialog->window, 0, 0);
    132 
    133   if (create_dialog->uri)
    134   {
    135     util_print_prompt(create_dialog->window, "This is the URI of the new lobby:");
    136 
    137 	_lobby_iterate_print(create_dialog, create_dialog->uri);
    138   }
    139   else
    140   {
    141     util_print_prompt(create_dialog->window, "Select the duration for the new lobby:");
    142 
    143     _lobby_iterate_print(create_dialog, "30 seconds");
    144     _lobby_iterate_print(create_dialog, "5 minutes");
    145     _lobby_iterate_print(create_dialog, "1 hour");
    146     _lobby_iterate_print(create_dialog, "8 hours");
    147     _lobby_iterate_print(create_dialog, "1 day");
    148     _lobby_iterate_print(create_dialog, "1 week");
    149     _lobby_iterate_print(create_dialog, "4 weeks");
    150     _lobby_iterate_print(create_dialog, "Off");
    151   }
    152 }