CMake integration
This commit is contained in:
@@ -0,0 +1,18 @@
|
||||
add_library(modals STATIC)
|
||||
|
||||
file(GLOB M_HEADERS "*.h")
|
||||
file(GLOB M_SOURCES "*.c")
|
||||
|
||||
target_link_libraries(modals PRIVATE widget ui-widget-core)
|
||||
|
||||
target_sources(modals
|
||||
PRIVATE
|
||||
${M_SOURCES}
|
||||
PUBLIC
|
||||
FILE_SET HEADERS
|
||||
FILES
|
||||
${M_HEADERS}
|
||||
)
|
||||
|
||||
target_include_directories(modals PRIVATE "../widget")
|
||||
target_include_directories(modals PRIVATE "../ui-widget-core")
|
||||
@@ -0,0 +1,69 @@
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
#include <ncurses.h>
|
||||
|
||||
// #include "../app.h"
|
||||
// #include "../widget/dialogue.h"
|
||||
// #include "../widget/group.h"
|
||||
// #include "../widget/input.h"
|
||||
// #include "../widget/button.h"
|
||||
|
||||
#include <widget.h>
|
||||
#include "../connection.h"
|
||||
|
||||
typedef struct {
|
||||
button_t *element;
|
||||
enum w_type type;
|
||||
} group_bt_t;
|
||||
|
||||
void asa_modal_dialogue_callback(callback_args_t *args) {
|
||||
int32_t response;
|
||||
callback_args_t d_args;
|
||||
app_t *app = args->app;
|
||||
dialogue_t *d = (dialogue_t *)app->active_widget;
|
||||
memcpy(&d_args, args, sizeof(callback_args_t));
|
||||
d_args.app = NULL;
|
||||
d_args.resp_data = &response;
|
||||
d_args.element = app->active_widget;
|
||||
input_t *in_ip = d->g_content->elements[0].element;
|
||||
input_t *in_port = d->g_content->elements[1].element;
|
||||
dialogue_default_callback(&d_args);
|
||||
if (response > -1) {
|
||||
switch (response) {
|
||||
case 0:
|
||||
get_ip_port(app->params, in_ip->value, in_port->value);
|
||||
connect_to_server(app);
|
||||
d->needs_destroy = true;
|
||||
app->query_args->state = S_WAIT_SERVER;
|
||||
break;
|
||||
case 1:
|
||||
destroy_app(app, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
dialogue_t *init_asa_modal(app_t *app) {
|
||||
if (app == NULL)
|
||||
return NULL;
|
||||
group_el_init_t content[] = {
|
||||
{.type = w_input, .label = "Address", .length = 15},
|
||||
{.type = w_input, .label = "Port", .length = 5},
|
||||
{.type = w_end}};
|
||||
|
||||
group_el_init_t actions[] = {
|
||||
{.type = w_button, .label = "Connect", .is_default = 1},
|
||||
{.type = w_button, .label = "Cancel", .is_default = 0},
|
||||
{.type = w_end}};
|
||||
|
||||
init_dialogue(&(app->modal), "Connect to server",
|
||||
"There is information needed", &(app->coordinates));
|
||||
dialogue_t *d = &(app->modal);
|
||||
|
||||
d->w.callback = asa_modal_dialogue_callback;
|
||||
d->g_content = init_group(&(d->win), &(d->w), content, horizontal);
|
||||
d->g_action = init_group(&(d->win), &(d->w), actions, horizontal);
|
||||
|
||||
dialogue_init_active_id(d);
|
||||
|
||||
return NULL;
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
#ifndef ASK_SERVER_ADDR_H
|
||||
#define ASK_SERVER_ADDR_H
|
||||
|
||||
#include <widget.h>
|
||||
#include "../widget/dialogue.h"
|
||||
|
||||
dialogue_t *init_asa_modal(app_t *app);
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,36 @@
|
||||
#include <widget.h>
|
||||
#include <ncurses.h>
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
|
||||
void dwn_pr_modal_cb(callback_args_t *args) {}
|
||||
|
||||
dialogue_t *init_dwn_pr_modal(app_t *app, bool is_upload) {
|
||||
if (app == NULL)
|
||||
return NULL;
|
||||
group_el_init_t content[] = {
|
||||
{.type = w_progress, .label = "", .length = 30}, /* length is ignored */
|
||||
{.type = w_end}};
|
||||
|
||||
char text[256];
|
||||
sprintf(text, "%s file: %s", is_upload ? "Uploading" : "Downloading",
|
||||
is_upload ? app->query_args->file->name : app->file_args->f_selected.name);
|
||||
group_el_init_t actions[] = {
|
||||
{.type = w_button, .label = "Cancel", .is_default = 1}, {.type = w_end}};
|
||||
|
||||
app->modal.w.parent_win = &app->win;
|
||||
init_dialogue(&(app->modal), is_upload ? "Upload" : "Download", text,
|
||||
&(app->coordinates));
|
||||
dialogue_t *d = &(app->modal);
|
||||
|
||||
d->w.callback = dwn_pr_modal_cb;
|
||||
d->g_content = init_group(&(d->win), &(d->w), content, horizontal);
|
||||
d->g_action = init_group(&(d->win), &(d->w), actions, horizontal);
|
||||
|
||||
app->query_args->progress_bar = d->g_content->elements[0].element;
|
||||
app->query_args->active_dialogue = d;
|
||||
|
||||
dialogue_init_active_id(d);
|
||||
|
||||
return NULL;
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
#ifndef DOWNLOAD_PR_H
|
||||
#define DOWNLOAD_PR_H
|
||||
|
||||
#include <widget.h>
|
||||
|
||||
dialogue_t *init_dwn_pr_modal(app_t *app, bool is_upload);
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,73 @@
|
||||
#include <ncurses.h>
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <widget.h>
|
||||
|
||||
typedef struct {
|
||||
button_t *element;
|
||||
enum w_type type;
|
||||
} group_bt_t;
|
||||
|
||||
void init_login_credentials_modal_cb(callback_args_t *args) {
|
||||
int32_t response;
|
||||
callback_args_t d_args;
|
||||
app_t *app = args->app;
|
||||
dialogue_t *d = (dialogue_t *)app->active_widget;
|
||||
memcpy(&d_args, args, sizeof(callback_args_t));
|
||||
d_args.app = NULL;
|
||||
d_args.resp_data = &response;
|
||||
d_args.element = app->active_widget;
|
||||
input_t *in_name = d->g_content->elements[0].element;
|
||||
input_t *in_pass = d->g_content->elements[1].element;
|
||||
dialogue_default_callback(&d_args);
|
||||
if (response > -1) {
|
||||
switch (response) {
|
||||
case 0:
|
||||
app->params->uname = malloc(in_name->value_len + 1);
|
||||
app->params->pass = malloc(in_pass->value_len + 1);
|
||||
strncpy(app->params->uname, in_name->value, in_name->value_len);
|
||||
app->params->uname[in_name->value_len] = 0;
|
||||
strncpy(app->params->pass, in_pass->value, in_pass->value_len);
|
||||
app->params->pass[in_pass->value_len] = 0;
|
||||
write(app->params->sd, app->params->uname, in_name->value_len);
|
||||
app->query_args->state = S_WAIT_SERVER;
|
||||
d->needs_destroy = true;
|
||||
print_bars(app);
|
||||
break;
|
||||
case 1:
|
||||
destroy_app(app, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
dialogue_t *init_login_credentials_modal(app_t *app) {
|
||||
if (app == NULL)
|
||||
return NULL;
|
||||
group_el_init_t content[] = {
|
||||
{.type = w_input, .label = "Username", .length = 15},
|
||||
{.type = w_input,
|
||||
.label = "Password",
|
||||
.length = 15,
|
||||
.is_hidden_value = true},
|
||||
{.type = w_end}};
|
||||
|
||||
group_el_init_t actions[] = {
|
||||
{.type = w_button, .label = "Login", .is_default = true},
|
||||
{.type = w_button, .label = "Cancel", .is_default = false},
|
||||
{.type = w_end}};
|
||||
|
||||
init_dialogue(&(app->modal), "Credentials", "There is information needed",
|
||||
&(app->coordinates));
|
||||
dialogue_t *d = &(app->modal);
|
||||
|
||||
d->w.callback = init_login_credentials_modal_cb;
|
||||
d->g_content = init_group(&(d->win), &(d->w), content, horizontal);
|
||||
d->g_action = init_group(&(d->win), &(d->w), actions, horizontal);
|
||||
|
||||
dialogue_init_active_id(d);
|
||||
|
||||
return NULL;
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
#ifndef LOGIN_CREDENTIALS_MODAL_H
|
||||
#define LOGIN_CREDENTIALS_MODAL_H
|
||||
|
||||
#include <widget.h>
|
||||
|
||||
dialogue_t *init_login_credentials_modal(app_t *app);
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,53 @@
|
||||
#include <ncurses.h>
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <widget.h>
|
||||
|
||||
typedef struct {
|
||||
button_t *element;
|
||||
enum w_type type;
|
||||
} group_bt_t;
|
||||
|
||||
void login_modal_option_cb(callback_args_t *args) {
|
||||
int32_t response;
|
||||
callback_args_t d_args;
|
||||
app_t *app = args->app;
|
||||
dialogue_t *d = (dialogue_t *)app->active_widget;
|
||||
memcpy(&d_args, args, sizeof(callback_args_t));
|
||||
d_args.app = NULL;
|
||||
d_args.resp_data = &response;
|
||||
d_args.element = app->active_widget;
|
||||
dialogue_default_callback(&d_args);
|
||||
if (response > -1) {
|
||||
switch (response) {
|
||||
case 0:
|
||||
break;
|
||||
case 1:
|
||||
d->needs_destroy = true;
|
||||
app->query_args->state = S_ASK_LOGIN_USER;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
dialogue_t *init_login_option_modal(app_t *app) {
|
||||
if (app == NULL)
|
||||
return NULL;
|
||||
group_el_init_t children[] = {{.type = w_button, .label = "Anonymous"},
|
||||
{.type = w_button, .label = "User"},
|
||||
{.type = w_button, .label = "Register"},
|
||||
{.type = w_end}};
|
||||
|
||||
init_dialogue(&(app->modal), "Login",
|
||||
"Select your login "
|
||||
"option",
|
||||
&(app->coordinates));
|
||||
app->modal.g_action =
|
||||
init_group(&(app->modal.win), &(app->modal.w), children,
|
||||
horizontal);
|
||||
app->modal.w.callback = login_modal_option_cb;
|
||||
dialogue_init_active_id(&(app->modal));
|
||||
|
||||
return NULL;
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
#ifndef LOGIN_OPTION_MODAL_H
|
||||
#define LOGIN_OPTION_MODAL_H
|
||||
|
||||
#include <widget.h>
|
||||
|
||||
dialogue_t *init_login_option_modal(app_t *app);
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,49 @@
|
||||
#include <ncurses.h>
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <widget.h>
|
||||
|
||||
typedef struct {
|
||||
button_t *element;
|
||||
enum w_type type;
|
||||
} group_bt_t;
|
||||
|
||||
void init_notification_modal_cb(callback_args_t *args) {
|
||||
int32_t response;
|
||||
callback_args_t d_args;
|
||||
app_t *app = args->app;
|
||||
dialogue_t *d = (dialogue_t *)app->active_widget;
|
||||
memcpy(&d_args, args, sizeof(callback_args_t));
|
||||
d_args.app = NULL;
|
||||
d_args.resp_data = &response;
|
||||
d_args.element = app->active_widget;
|
||||
dialogue_default_callback(&d_args);
|
||||
|
||||
app->query_args->state = WAIT_CLIENT;
|
||||
d->needs_destroy = true;
|
||||
}
|
||||
|
||||
dialogue_t *init_notification_modal(app_t *app) {
|
||||
if (app == NULL)
|
||||
return NULL;
|
||||
|
||||
group_el_init_t actions[] = {
|
||||
{.type = w_button, .label = "OK", .is_default = 1}, {.type = w_end}};
|
||||
|
||||
init_dialogue(&(app->modal), "Notification", app->query_args->notification,
|
||||
&(app->coordinates));
|
||||
free(app->query_args->notification);
|
||||
app->query_args->notification = NULL;
|
||||
dialogue_t *d = &(app->modal);
|
||||
app->query_args->active_dialogue = d;
|
||||
|
||||
d->w.callback = init_notification_modal_cb;
|
||||
d->g_content = NULL;
|
||||
d->g_action = init_group(&(d->win), &(d->w), actions, horizontal);
|
||||
|
||||
dialogue_init_active_id(d);
|
||||
|
||||
return NULL;
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
#ifndef NOTIFICATION_H
|
||||
#define NOTIFICATION_H
|
||||
|
||||
#include <widget.h>
|
||||
|
||||
dialogue_t *init_notification_modal(app_t *app);
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,52 @@
|
||||
#include <ncurses.h>
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <widget.h>
|
||||
|
||||
typedef struct {
|
||||
button_t *element;
|
||||
enum w_type type;
|
||||
} group_bt_t;
|
||||
|
||||
void server_message_modal_cb(callback_args_t *args) {
|
||||
int32_t response;
|
||||
callback_args_t d_args;
|
||||
app_t *app = args->app;
|
||||
dialogue_t *d = (dialogue_t *)app->active_widget;
|
||||
memcpy(&d_args, args, sizeof(callback_args_t));
|
||||
d_args.app = NULL;
|
||||
d_args.resp_data = &response;
|
||||
d_args.element = app->active_widget;
|
||||
dialogue_default_callback(&d_args);
|
||||
if (response > -1) {
|
||||
switch (response) {
|
||||
case 0:
|
||||
d->needs_destroy = true;
|
||||
/* TODO: macros */
|
||||
free(app->query_args->server_message.text);
|
||||
app->query_args->server_message.text = NULL;
|
||||
app->query_args->server_message.capacity = 0;
|
||||
app->query_args->server_message.size = 0;
|
||||
app->query_args->state = S_NEXT_ACTION;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void *init_server_message_modal(app_t *app) {
|
||||
if (app == NULL)
|
||||
return NULL;
|
||||
group_el_init_t children[] = {
|
||||
{.type = w_button, .label = "OK", .is_default = 1}, {.type = w_end}};
|
||||
|
||||
init_dialogue(&(app->modal), "Server response",
|
||||
app->query_args->server_message.text, &(app->coordinates));
|
||||
app->modal.g_action =
|
||||
init_group(&(app->modal.win), &(app->modal.w), children, horizontal);
|
||||
app->modal.w.callback = server_message_modal_cb;
|
||||
dialogue_init_active_id(&(app->modal));
|
||||
|
||||
return NULL;
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
#ifndef SERVER_MESSAGE_H
|
||||
#define SERVER_MESSAGE_H
|
||||
|
||||
#include <widget.h>
|
||||
|
||||
void *init_server_message_modal(app_t *app);
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,60 @@
|
||||
#include "../file_processor.h"
|
||||
#include <widget.h>
|
||||
#include <ncurses.h>
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
|
||||
void upload_dialogue_modal_cb(callback_args_t *args) {
|
||||
int32_t response = -1;
|
||||
callback_args_t d_args;
|
||||
app_t *app = args->app;
|
||||
dialogue_t *d = (dialogue_t *)app->active_widget;
|
||||
memcpy(&d_args, args, sizeof(callback_args_t));
|
||||
d_args.app = NULL;
|
||||
d_args.resp_data = &response;
|
||||
d_args.element = app->active_widget;
|
||||
dialogue_default_callback(&d_args);
|
||||
ui_fs_file_list_t *fui =
|
||||
(ui_fs_file_list_t *)d->g_content->elements[0].element;
|
||||
switch (response) {
|
||||
case 0:
|
||||
app->query_args->state = S_WAIT_SERVER;
|
||||
d->needs_destroy = true;
|
||||
break;
|
||||
case 1:
|
||||
file_upload_open(fui->d_path, fui->current->name, app->query_args);
|
||||
d->needs_destroy = true;
|
||||
app->query_args->state = S_UPLOAD_PARAMS;
|
||||
break;
|
||||
case -2:
|
||||
d->needs_destroy = true;
|
||||
app->query_args->state = WAIT_CLIENT;
|
||||
}
|
||||
}
|
||||
|
||||
dialogue_t *init_upload_dialogue_modal(app_t *app) {
|
||||
if (app == NULL)
|
||||
return NULL;
|
||||
group_el_init_t content[] = {
|
||||
// {.type = w_input, .label = "File description", .length = 30},
|
||||
{.type = w_fs_file_list, .label = "File", .length = 30},
|
||||
{.type = w_end}};
|
||||
|
||||
group_el_init_t actions[] = {
|
||||
{.type = w_button, .label = "Cancel", .is_default = 0}, {.type = w_end}};
|
||||
|
||||
app->modal.w.parent_win = &app->win;
|
||||
init_dialogue(&(app->modal), "Upload new file", "Enter essential data",
|
||||
&(app->coordinates));
|
||||
dialogue_t *d = &(app->modal);
|
||||
|
||||
d->w.callback = upload_dialogue_modal_cb;
|
||||
d->g_content = init_group(&(d->win), &(d->w), content, horizontal);
|
||||
d->g_action = init_group(&(d->win), &(d->w), actions, horizontal);
|
||||
|
||||
app->query_args->active_dialogue = d;
|
||||
|
||||
dialogue_init_active_id(d);
|
||||
|
||||
return NULL;
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
#ifndef UPLOAD_DIALOGUE_H
|
||||
#define UPLOAD_DIALOGUE_H
|
||||
|
||||
#include <widget.h>
|
||||
|
||||
dialogue_t *init_upload_dialogue_modal(app_t *app);
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,75 @@
|
||||
#include <widget.h>
|
||||
#include <ncurses.h>
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
void upload_props_dialogue_modal_cb(callback_args_t *args) {
|
||||
int32_t response = -1;
|
||||
callback_args_t d_args;
|
||||
app_t *app = args->app;
|
||||
dialogue_t *d = (dialogue_t *)app->active_widget;
|
||||
memcpy(&d_args, args, sizeof(callback_args_t));
|
||||
d_args.app = NULL;
|
||||
d_args.resp_data = &response;
|
||||
d_args.element = app->active_widget;
|
||||
dialogue_default_callback(&d_args);
|
||||
char query[256];
|
||||
int32_t query_len = 0;
|
||||
input_t *desc_input = (input_t *)d->g_content->elements[0].element;
|
||||
if (response > -1) {
|
||||
switch (response) {
|
||||
case 0:
|
||||
query_len =
|
||||
sprintf(query, "file upload \"%s\" %zu 1\n",
|
||||
app->query_args->file->name, app->query_args->file->size);
|
||||
app->query_args->file->description =
|
||||
malloc(desc_input->value_len + 9); /* reserve space for \n:END:\n */
|
||||
strcpy(app->query_args->file->description, desc_input->value);
|
||||
d->needs_destroy = true;
|
||||
app->query_args->state = S_UPLOAD_REQUESTED;
|
||||
write(app->query_args->sd, query, query_len);
|
||||
break;
|
||||
case 1:
|
||||
if (app->query_args->file->name != NULL)
|
||||
free(app->query_args->file->name);
|
||||
if (app->query_args->file->path != NULL)
|
||||
free(app->query_args->file->path);
|
||||
free(app->query_args->file);
|
||||
app->query_args->file = NULL;
|
||||
app->query_args->state = S_WAIT_SERVER;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
dialogue_t *init_upload_props_dialogue_modal(app_t *app) {
|
||||
if (app == NULL)
|
||||
return NULL;
|
||||
group_el_init_t content[] = {
|
||||
{.type = w_input, .label = "File description", .length = 30},
|
||||
{.type = w_end}};
|
||||
|
||||
group_el_init_t actions[] = {
|
||||
{.type = w_button, .label = "Upload", .is_default = 1},
|
||||
{.type = w_button, .label = "Cancel", .is_default = 0},
|
||||
{.type = w_end},
|
||||
};
|
||||
|
||||
app->modal.w.parent_win = &app->win;
|
||||
init_dialogue(&(app->modal), "Description for the file",
|
||||
"Enter essential data", &(app->coordinates));
|
||||
dialogue_t *d = &(app->modal);
|
||||
|
||||
d->w.callback = upload_props_dialogue_modal_cb;
|
||||
d->g_content = init_group(&(d->win), &(d->w), content, horizontal);
|
||||
d->g_action = init_group(&(d->win), &(d->w), actions, horizontal);
|
||||
|
||||
app->query_args->active_dialogue = d;
|
||||
|
||||
dialogue_init_active_id(d);
|
||||
|
||||
return NULL;
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
#ifndef UPLOAD_PROPS_DIALOGUE_H
|
||||
#define UPLOAD_PROPS_DIALOGUE_H
|
||||
|
||||
#include <widget.h>
|
||||
|
||||
dialogue_t *init_upload_props_dialogue_modal(app_t *app);
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user