aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTheJackiMonster <thejackimonster@gmail.com>2022-08-19 00:26:21 +0200
committerTheJackiMonster <thejackimonster@gmail.com>2022-08-19 00:26:21 +0200
commit4db85b1a2178004a5f54ae798b6776a723145974 (patch)
treebf2aaf6a94ec4fcde1c524d2aa64b3fb37f8c277
parent3e527b0e1eeb1ce61cda8251494a35b2a3ce872e (diff)
downloadmessenger-cli-4db85b1a2178004a5f54ae798b6776a723145974.tar.gz
messenger-cli-4db85b1a2178004a5f54ae798b6776a723145974.zip
Added lobby opening with custom delay
Signed-off-by: TheJackiMonster <thejackimonster@gmail.com>
-rw-r--r--src/ui/chats.c12
-rw-r--r--src/ui/chats.h4
-rw-r--r--src/ui/list_input.h2
-rw-r--r--src/ui/lobby_create_dialog.c129
-rw-r--r--src/ui/lobby_create_dialog.h16
-rw-r--r--src/ui/members.h1
6 files changed, 142 insertions, 22 deletions
diff --git a/src/ui/chats.c b/src/ui/chats.c
index 5517541..c2cc2ae 100644
--- a/src/ui/chats.c
+++ b/src/ui/chats.c
@@ -68,6 +68,11 @@ chats_event(UI_CHATS_Handle *chats,
68 chat_open_dialog_event(&(chats->open_dialog), app, key); 68 chat_open_dialog_event(&(chats->open_dialog), app, key);
69 return; 69 return;
70 } 70 }
71 else if (chats->create_dialog.win)
72 {
73 lobby_create_dialog_event(&(chats->create_dialog), app, key);
74 return;
75 }
71 else if (chats->enter_dialog.window) 76 else if (chats->enter_dialog.window)
72 { 77 {
73 lobby_enter_dialog_event(&(chats->enter_dialog), app, key); 78 lobby_enter_dialog_event(&(chats->enter_dialog), app, key);
@@ -124,6 +129,8 @@ chats_event(UI_CHATS_Handle *chats,
124 } 129 }
125 else if (chats->line_selected == count - 3) 130 else if (chats->line_selected == count - 3)
126 chats->open_dialog.window = &(chats->window); 131 chats->open_dialog.window = &(chats->window);
132 else if (chats->line_selected == count - 2)
133 chats->create_dialog.win = &(chats->window);
127 else if (chats->line_selected == count - 1) 134 else if (chats->line_selected == count - 1)
128 chats->enter_dialog.window = &(chats->window); 135 chats->enter_dialog.window = &(chats->window);
129 break; 136 break;
@@ -187,6 +194,11 @@ chats_print(UI_CHATS_Handle *chats,
187 chat_open_dialog_print(&(chats->open_dialog), app); 194 chat_open_dialog_print(&(chats->open_dialog), app);
188 return; 195 return;
189 } 196 }
197 else if (chats->create_dialog.win)
198 {
199 lobby_create_dialog_print(&(chats->create_dialog), app);
200 return;
201 }
190 else if (chats->enter_dialog.window) 202 else if (chats->enter_dialog.window)
191 { 203 {
192 lobby_enter_dialog_print(&(chats->enter_dialog), app); 204 lobby_enter_dialog_print(&(chats->enter_dialog), app);
diff --git a/src/ui/chats.h b/src/ui/chats.h
index b355dc7..db4e987 100644
--- a/src/ui/chats.h
+++ b/src/ui/chats.h
@@ -33,7 +33,7 @@
33#include <gnunet/gnunet_util_lib.h> 33#include <gnunet/gnunet_util_lib.h>
34 34
35#include "chat_open_dialog.h" 35#include "chat_open_dialog.h"
36 36#include "lobby_create_dialog.h"
37#include "lobby_enter_dialog.h" 37#include "lobby_enter_dialog.h"
38 38
39struct MESSENGER_Application; 39struct MESSENGER_Application;
@@ -49,7 +49,7 @@ typedef struct UI_CHATS_Handle
49 struct GNUNET_CHAT_Context *selected; 49 struct GNUNET_CHAT_Context *selected;
50 50
51 UI_CHAT_OPEN_DIALOG_Handle open_dialog; 51 UI_CHAT_OPEN_DIALOG_Handle open_dialog;
52 52 UI_LOBBY_CREATE_DIALOG_Handle create_dialog;
53 UI_LOBBY_ENTER_DIALOG_Handle enter_dialog; 53 UI_LOBBY_ENTER_DIALOG_Handle enter_dialog;
54} UI_CHATS_Handle; 54} UI_CHATS_Handle;
55 55
diff --git a/src/ui/list_input.h b/src/ui/list_input.h
index aad3ae4..932d0fd 100644
--- a/src/ui/list_input.h
+++ b/src/ui/list_input.h
@@ -30,7 +30,7 @@
30 30
31#define list_input_reset(list) { \ 31#define list_input_reset(list) { \
32 (list)->line_index = 0; \ 32 (list)->line_index = 0; \
33 (list)->selected = NULL; \ 33 (list)->selected = 0; \
34} 34}
35 35
36#define list_input_select(list, line_width, item) { \ 36#define list_input_select(list, line_width, item) { \
diff --git a/src/ui/lobby_create_dialog.c b/src/ui/lobby_create_dialog.c
index 9c80929..f294391 100644
--- a/src/ui/lobby_create_dialog.c
+++ b/src/ui/lobby_create_dialog.c
@@ -24,30 +24,125 @@
24 24
25#include "lobby_create_dialog.h" 25#include "lobby_create_dialog.h"
26 26
27#include "list_input.h"
28#include "../application.h"
29#include "../util.h"
30
31void
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
27void 43void
28lobby_create_dialog_event(UI_LOBBY_CREATE_DIALOG_Handle *create_dialog, 44lobby_create_dialog_event(UI_LOBBY_CREATE_DIALOG_Handle *create_dialog,
29 struct MESSENGER_Application *app, 45 UNUSED struct MESSENGER_Application *app,
30 int key) 46 int key)
31{ 47{
32 // TODO 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 GNUNET_TIME_relative_multiply(
89 GNUNET_TIME_relative_get_second_(),
90 create_dialog->selected
91 ),
92 _lobby_open_with_uri,
93 create_dialog
94 );
95
96 break;
97 default:
98 break;
99 }
100
101 if (!(create_dialog->lobby))
102 list_input_event(create_dialog, key)
103 else
104 list_input_event(create_dialog, KEY_RESIZE);
105}
106
107static void
108_lobby_iterate_print(UI_LOBBY_CREATE_DIALOG_Handle *create_dialog,
109 const char *label)
110{
111 list_input_print(create_dialog, 1);
112
113 const int attrs_select = A_BOLD;
114
115 if (selected) wattron(create_dialog->window, attrs_select);
116
117 wmove(create_dialog->window, y, 0);
118 wprintw(create_dialog->window, "%s", label);
119
120 if (selected) wattroff(create_dialog->window, attrs_select);
33} 121}
34 122
35void 123void
36lobby_create_dialog_print(UI_LOBBY_CREATE_DIALOG_Handle *create_dialog, 124lobby_create_dialog_print(UI_LOBBY_CREATE_DIALOG_Handle *create_dialog,
37 struct MESSENGER_Application *app) 125 UNUSED struct MESSENGER_Application *app)
38{ 126{
39 /* 127 if (!(create_dialog->win))
40 Delay until it expires: 128 return;
41 129
42 30 seconds 130 create_dialog->window = *(create_dialog->win);
43 5 minutes 131
44 1 hour 132 list_input_reset(create_dialog);
45 8 hours 133 werase(create_dialog->window);
46 1 day 134
47 1 week 135 if (create_dialog->uri)
48 4 weeks 136 _lobby_iterate_print(create_dialog, create_dialog->uri);
49 Off 137 else
50 */ 138 {
51 139 _lobby_iterate_print(create_dialog, "30 seconds");
52 // TODO 140 _lobby_iterate_print(create_dialog, "5 minutes");
141 _lobby_iterate_print(create_dialog, "1 hour");
142 _lobby_iterate_print(create_dialog, "8 hours");
143 _lobby_iterate_print(create_dialog, "1 day");
144 _lobby_iterate_print(create_dialog, "1 week");
145 _lobby_iterate_print(create_dialog, "4 weeks");
146 _lobby_iterate_print(create_dialog, "Off");
147 }
53} 148}
diff --git a/src/ui/lobby_create_dialog.h b/src/ui/lobby_create_dialog.h
index f780522..bdc34da 100644
--- a/src/ui/lobby_create_dialog.h
+++ b/src/ui/lobby_create_dialog.h
@@ -28,13 +28,25 @@
28#include <stdlib.h> 28#include <stdlib.h>
29#include <curses.h> 29#include <curses.h>
30 30
31#include <gnunet/platform.h>
32#include <gnunet/gnunet_chat_lib.h>
33#include <gnunet/gnunet_util_lib.h>
34
31struct MESSENGER_Application; 35struct MESSENGER_Application;
32 36
33typedef struct UI_LOBBY_CREATE_DIALOG_Handle 37typedef struct UI_LOBBY_CREATE_DIALOG_Handle
34{ 38{
35 WINDOW **window; 39 WINDOW *window;
40 WINDOW **win;
41
42 int line_index;
43 int line_offset;
44 int line_selected;
45
46 uint64_t selected;
36 47
37 // TODO 48 struct GNUNET_CHAT_Lobby *lobby;
49 char *uri;
38} UI_LOBBY_CREATE_DIALOG_Handle; 50} UI_LOBBY_CREATE_DIALOG_Handle;
39 51
40void 52void
diff --git a/src/ui/members.h b/src/ui/members.h
index 8e70ca4..fc924a2 100644
--- a/src/ui/members.h
+++ b/src/ui/members.h
@@ -25,6 +25,7 @@
25#ifndef UI_MEMBERS_H_ 25#ifndef UI_MEMBERS_H_
26#define UI_MEMBERS_H_ 26#define UI_MEMBERS_H_
27 27
28#include <stdbool.h>
28#include <stdlib.h> 29#include <stdlib.h>
29#include <curses.h> 30#include <curses.h>
30 31