summaryrefslogtreecommitdiff
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)
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,
chat_open_dialog_event(&(chats->open_dialog), app, key);
return;
}
+ else if (chats->create_dialog.win)
+ {
+ lobby_create_dialog_event(&(chats->create_dialog), app, key);
+ return;
+ }
else if (chats->enter_dialog.window)
{
lobby_enter_dialog_event(&(chats->enter_dialog), app, key);
@@ -124,6 +129,8 @@ chats_event(UI_CHATS_Handle *chats,
}
else if (chats->line_selected == count - 3)
chats->open_dialog.window = &(chats->window);
+ else if (chats->line_selected == count - 2)
+ chats->create_dialog.win = &(chats->window);
else if (chats->line_selected == count - 1)
chats->enter_dialog.window = &(chats->window);
break;
@@ -187,6 +194,11 @@ chats_print(UI_CHATS_Handle *chats,
chat_open_dialog_print(&(chats->open_dialog), app);
return;
}
+ else if (chats->create_dialog.win)
+ {
+ lobby_create_dialog_print(&(chats->create_dialog), app);
+ return;
+ }
else if (chats->enter_dialog.window)
{
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 @@
#include <gnunet/gnunet_util_lib.h>
#include "chat_open_dialog.h"
-
+#include "lobby_create_dialog.h"
#include "lobby_enter_dialog.h"
struct MESSENGER_Application;
@@ -49,7 +49,7 @@ typedef struct UI_CHATS_Handle
struct GNUNET_CHAT_Context *selected;
UI_CHAT_OPEN_DIALOG_Handle open_dialog;
-
+ UI_LOBBY_CREATE_DIALOG_Handle create_dialog;
UI_LOBBY_ENTER_DIALOG_Handle enter_dialog;
} UI_CHATS_Handle;
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 @@
#define list_input_reset(list) { \
(list)->line_index = 0; \
- (list)->selected = NULL; \
+ (list)->selected = 0; \
}
#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 @@
#include "lobby_create_dialog.h"
+#include "list_input.h"
+#include "../application.h"
+#include "../util.h"
+
+void
+_lobby_open_with_uri(void *cls,
+ const struct GNUNET_CHAT_Uri *uri)
+{
+ UI_LOBBY_CREATE_DIALOG_Handle *create_dialog = cls;
+
+ if (create_dialog->uri)
+ GNUNET_free(create_dialog->uri);
+
+ create_dialog->uri = GNUNET_CHAT_uri_to_string(uri);
+}
+
void
lobby_create_dialog_event(UI_LOBBY_CREATE_DIALOG_Handle *create_dialog,
- struct MESSENGER_Application *app,
+ UNUSED struct MESSENGER_Application *app,
int key)
{
- // TODO
+ create_dialog->window = *(create_dialog->win);
+
+ list_input_reset(create_dialog);
+
+ if (create_dialog->uri)
+ list_input_select(create_dialog, 1, 0)
+ else
+ {
+ list_input_select(create_dialog, 1, 30);
+ list_input_select(create_dialog, 1, 5 * 60);
+ list_input_select(create_dialog, 1, 60 * 60);
+ list_input_select(create_dialog, 1, 8 * 60 * 60);
+ list_input_select(create_dialog, 1, 24 * 60 * 60);
+ list_input_select(create_dialog, 1, 7 * 24 * 60 * 60);
+ list_input_select(create_dialog, 1, 4 * 7 * 60 * 60);
+ list_input_select(create_dialog, 1, 0);
+ }
+
+ switch (key)
+ {
+ case 27:
+ case KEY_EXIT:
+ if (create_dialog->lobby)
+ GNUNET_CHAT_lobby_close(create_dialog->lobby);
+
+ create_dialog->lobby = NULL;
+ create_dialog->win = NULL;
+ break;
+ case '\n':
+ case KEY_ENTER:
+ if (create_dialog->uri)
+ {
+ GNUNET_free(create_dialog->uri);
+
+ create_dialog->lobby = NULL;
+ create_dialog->win = NULL;
+ }
+ else if (!(create_dialog->lobby))
+ create_dialog->lobby = GNUNET_CHAT_lobby_open(
+ app->chat.handle,
+ GNUNET_TIME_relative_multiply(
+ GNUNET_TIME_relative_get_second_(),
+ create_dialog->selected
+ ),
+ _lobby_open_with_uri,
+ create_dialog
+ );
+
+ break;
+ default:
+ break;
+ }
+
+ if (!(create_dialog->lobby))
+ list_input_event(create_dialog, key)
+ else
+ list_input_event(create_dialog, KEY_RESIZE);
+}
+
+static void
+_lobby_iterate_print(UI_LOBBY_CREATE_DIALOG_Handle *create_dialog,
+ const char *label)
+{
+ list_input_print(create_dialog, 1);
+
+ const int attrs_select = A_BOLD;
+
+ if (selected) wattron(create_dialog->window, attrs_select);
+
+ wmove(create_dialog->window, y, 0);
+ wprintw(create_dialog->window, "%s", label);
+
+ if (selected) wattroff(create_dialog->window, attrs_select);
}
void
lobby_create_dialog_print(UI_LOBBY_CREATE_DIALOG_Handle *create_dialog,
- struct MESSENGER_Application *app)
+ UNUSED struct MESSENGER_Application *app)
{
- /*
- Delay until it expires:
-
- 30 seconds
- 5 minutes
- 1 hour
- 8 hours
- 1 day
- 1 week
- 4 weeks
- Off
- */
-
- // TODO
+ if (!(create_dialog->win))
+ return;
+
+ create_dialog->window = *(create_dialog->win);
+
+ list_input_reset(create_dialog);
+ werase(create_dialog->window);
+
+ if (create_dialog->uri)
+ _lobby_iterate_print(create_dialog, create_dialog->uri);
+ else
+ {
+ _lobby_iterate_print(create_dialog, "30 seconds");
+ _lobby_iterate_print(create_dialog, "5 minutes");
+ _lobby_iterate_print(create_dialog, "1 hour");
+ _lobby_iterate_print(create_dialog, "8 hours");
+ _lobby_iterate_print(create_dialog, "1 day");
+ _lobby_iterate_print(create_dialog, "1 week");
+ _lobby_iterate_print(create_dialog, "4 weeks");
+ _lobby_iterate_print(create_dialog, "Off");
+ }
}
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 @@
#include <stdlib.h>
#include <curses.h>
+#include <gnunet/platform.h>
+#include <gnunet/gnunet_chat_lib.h>
+#include <gnunet/gnunet_util_lib.h>
+
struct MESSENGER_Application;
typedef struct UI_LOBBY_CREATE_DIALOG_Handle
{
- WINDOW **window;
+ WINDOW *window;
+ WINDOW **win;
+
+ int line_index;
+ int line_offset;
+ int line_selected;
+
+ uint64_t selected;
- // TODO
+ struct GNUNET_CHAT_Lobby *lobby;
+ char *uri;
} UI_LOBBY_CREATE_DIALOG_Handle;
void
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 @@
#ifndef UI_MEMBERS_H_
#define UI_MEMBERS_H_
+#include <stdbool.h>
#include <stdlib.h>
#include <curses.h>