ui: cancel option fo file upload
This commit is contained in:
@@ -5,6 +5,8 @@
|
|||||||
- [ ] Separate common structures in the common.h
|
- [ ] Separate common structures in the common.h
|
||||||
- [ ] Sorting in the file list
|
- [ ] Sorting in the file list
|
||||||
- [ ] Cancel upload/download
|
- [ ] Cancel upload/download
|
||||||
|
- [ ] Break line automatically in modal widgets
|
||||||
|
- [ ] Show download/upload progress in percentages
|
||||||
- [x] Input: fix non-Latin letters
|
- [x] Input: fix non-Latin letters
|
||||||
- [x] Get rid of unsigned integers
|
- [x] Get rid of unsigned integers
|
||||||
- [x] Check registration / enter server name again
|
- [x] Check registration / enter server name again
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
#include "alert.h"
|
||||||
|
#include "dialogue.h"
|
||||||
#include "group.h"
|
#include "group.h"
|
||||||
#include <ncursesw/ncurses.h>
|
#include <ncursesw/ncurses.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
@@ -11,7 +13,13 @@ void dwn_pr_modal_cb(w_cb_args_t *args) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
app_t *app = args->app;
|
app_t *app = args->app;
|
||||||
app->query_args->file->signal = sig_cancel;
|
/* TODO: forward actual file name */
|
||||||
|
bool response = w_bool_ask("Cancel file load", "Yes", "No", false,
|
||||||
|
"You're going to cancel download\n Are you sure?",
|
||||||
|
app->query_args->file->name);
|
||||||
|
if (response) {
|
||||||
|
app->query_args->file->signal = sig_cancel;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
w_dialogue_t *m_load_pr_init(app_t *app, bool is_upload) {
|
w_dialogue_t *m_load_pr_init(app_t *app, bool is_upload) {
|
||||||
|
|||||||
+95
-3
@@ -1,4 +1,6 @@
|
|||||||
#include "alert.h"
|
#include "alert.h"
|
||||||
|
#include "dialogue.h"
|
||||||
|
#include "widget_core.h"
|
||||||
#include <ncursesw/ncurses.h>
|
#include <ncursesw/ncurses.h>
|
||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
@@ -15,10 +17,12 @@ void alert_cb(w_cb_args_t *args) {
|
|||||||
|
|
||||||
void w_alert_init(app_t *_app) { app = _app; }
|
void w_alert_init(app_t *_app) { app = _app; }
|
||||||
|
|
||||||
void w_alert(const char *message) { w_notification("Alert", dc_alert, message); }
|
void w_alert(const char *message) {
|
||||||
|
w_notification("Alert", dc_alert, message);
|
||||||
|
}
|
||||||
|
|
||||||
void w_notification(const char *title, enum w_dialogue_color_scheme color,
|
void w_notification(const char *title, enum w_dialogue_color_scheme color,
|
||||||
const char *f_message, ...) {
|
const char *f_message, ...) {
|
||||||
if (app == NULL)
|
if (app == NULL)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@@ -36,7 +40,7 @@ void w_notification(const char *title, enum w_dialogue_color_scheme color,
|
|||||||
d->w.callback = alert_cb;
|
d->w.callback = alert_cb;
|
||||||
d->g_content = NULL;
|
d->g_content = NULL;
|
||||||
d->g_action = w_group_init(&(d->win), &(d->w), actions, &(d->id_map),
|
d->g_action = w_group_init(&(d->win), &(d->w), actions, &(d->id_map),
|
||||||
horizontal, g_action);
|
horizontal, g_action);
|
||||||
|
|
||||||
w_dialogue_init_active_id(d);
|
w_dialogue_init_active_id(d);
|
||||||
d->color_scheme = color;
|
d->color_scheme = color;
|
||||||
@@ -59,3 +63,91 @@ void w_notification(const char *title, enum w_dialogue_color_scheme color,
|
|||||||
app->modal.needs_update = true;
|
app->modal.needs_update = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int w_bool_callback(app_t *app, w_dialogue_t *dialogue, int32_t key) {
|
||||||
|
w_cb_args_t args;
|
||||||
|
args.app = app;
|
||||||
|
args.active_el = dialogue;
|
||||||
|
args.element = dialogue;
|
||||||
|
int _key = key;
|
||||||
|
args.data = (void *)&_key;
|
||||||
|
w_dialogue_callback_default(&args);
|
||||||
|
if (args.resp_data.code == cbrp_val) {
|
||||||
|
switch (args.resp_data.val.val.num) {
|
||||||
|
case 1:
|
||||||
|
return 1;
|
||||||
|
case 2:
|
||||||
|
return 2;
|
||||||
|
default:
|
||||||
|
return -2;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int w_bool_ask(const char *title, const char *text_y_btn,
|
||||||
|
const char *text_n_btn, bool yes_default, const char *f_message,
|
||||||
|
...) {
|
||||||
|
|
||||||
|
va_list args;
|
||||||
|
va_start(args, f_message);
|
||||||
|
|
||||||
|
if (app == NULL)
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
void *callback = app->active_callback;
|
||||||
|
|
||||||
|
w_group_el_init_t actions[] = {{.type = w_button, .val.num = 1}, /* YES */
|
||||||
|
{.type = w_button, .val.num = 2}, /* NO */
|
||||||
|
{.type = w_end}};
|
||||||
|
|
||||||
|
strcpy(actions[0].label, text_y_btn);
|
||||||
|
strcpy(actions[1].label, text_n_btn);
|
||||||
|
|
||||||
|
w_dialogue_t *d = malloc(sizeof(w_dialogue_t));
|
||||||
|
|
||||||
|
w_dialogue_vinit(d, title, &(app->coordinates), f_message, &args);
|
||||||
|
|
||||||
|
d->w.callback = alert_cb;
|
||||||
|
d->g_content = NULL;
|
||||||
|
d->g_action = w_group_init(&(d->win), &(d->w), actions, &(d->id_map),
|
||||||
|
horizontal, g_action);
|
||||||
|
|
||||||
|
if (yes_default) {
|
||||||
|
d->active_el = d->g_action->elements;
|
||||||
|
} else {
|
||||||
|
d->active_el = d->g_action->elements + 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
w_dialogue_draw(d);
|
||||||
|
wrefresh(d->win);
|
||||||
|
int c = 0;
|
||||||
|
|
||||||
|
bool response = false;
|
||||||
|
|
||||||
|
while ((c = wgetch(app->win))) {
|
||||||
|
int ret = w_bool_callback(app, d, c);
|
||||||
|
switch (ret) {
|
||||||
|
case 1:
|
||||||
|
response = true;
|
||||||
|
goto break_while;
|
||||||
|
case 2:
|
||||||
|
goto break_while;
|
||||||
|
}
|
||||||
|
w_dialogue_draw(d);
|
||||||
|
wrefresh(d->win);
|
||||||
|
}
|
||||||
|
|
||||||
|
break_while:
|
||||||
|
|
||||||
|
w_group_destroy(d->g_action);
|
||||||
|
delwin(d->win);
|
||||||
|
free(d);
|
||||||
|
app->active_callback = callback;
|
||||||
|
app_refresh(app);
|
||||||
|
if (app->modal.win != NULL) {
|
||||||
|
app->modal.needs_update = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return response;
|
||||||
|
}
|
||||||
+3
-1
@@ -7,6 +7,8 @@
|
|||||||
void w_alert_init(app_t *app);
|
void w_alert_init(app_t *app);
|
||||||
void w_alert(const char *message);
|
void w_alert(const char *message);
|
||||||
void w_notification(const char *title, enum w_dialogue_color_scheme color,
|
void w_notification(const char *title, enum w_dialogue_color_scheme color,
|
||||||
const char *f_message, ...);
|
const char *f_message, ...);
|
||||||
|
int w_bool_ask(const char *title, const char *yes_button,
|
||||||
|
const char *no_button, bool yes_default, const char *f_message, ...);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
Reference in New Issue
Block a user