diff options
author | toni <matzeton@googlemail.com> | 2016-09-12 23:26:23 +0200 |
---|---|---|
committer | toni <matzeton@googlemail.com> | 2016-09-12 23:26:23 +0200 |
commit | e3d0c979b3ab8a6611b23941ce90f8f0f7c18149 (patch) | |
tree | ed314c3b6a5f5bb95919317bedf5137c186d0402 | |
parent | b8dbe6d96045bca500497dcd71a4db0e0b8a110e (diff) |
ui_ipc_msgclear + busy and error window
-rw-r--r-- | src/ui_ipc.c | 9 | ||||
-rw-r--r-- | src/ui_ipc.h | 3 | ||||
-rw-r--r-- | src/ui_nask.c | 27 |
3 files changed, 29 insertions, 10 deletions
diff --git a/src/ui_ipc.c b/src/ui_ipc.c index fa73f28..cce7825 100644 --- a/src/ui_ipc.c +++ b/src/ui_ipc.c @@ -138,3 +138,12 @@ ui_ipc_msgcount(enum UI_IPC_MSQ e_mq) if (mq_getattr(msqs[e_mq], &m_attr) != 0) return -1; return m_attr.mq_curmsgs; } + +void +ui_ipc_msgclear(enum UI_IPC_MSQ e_mq) +{ + char ipc_buf[IPC_MQSIZ+1]; + while (ui_ipc_msgcount(e_mq) > 0) { + ui_ipc_msgrecv(e_mq, ipc_buf, 0); + } +} diff --git a/src/ui_ipc.h b/src/ui_ipc.h index d366141..2e72276 100644 --- a/src/ui_ipc.h +++ b/src/ui_ipc.h @@ -50,4 +50,7 @@ ui_ipc_msgrecv(enum UI_IPC_MSQ e_mq, char *msg_ptr, time_t tmout); long ui_ipc_msgcount(enum UI_IPC_MSQ e_mq); +void +ui_ipc_msgclear(enum UI_IPC_MSQ e_mq); + #endif diff --git a/src/ui_nask.c b/src/ui_nask.c index 6e017c9..4857de6 100644 --- a/src/ui_nask.c +++ b/src/ui_nask.c @@ -31,7 +31,7 @@ static struct input *pw_input; static struct anic *heartbeat; static struct statusbar *higher, *lower; -static struct txtwindow *infownd; +static struct txtwindow *busywnd, *errwnd; static int atmout = APP_TIMEOUT; static char *title = NULL; static char busy_str[BSTR_LEN+1] = ".\0\0\0"; @@ -54,7 +54,7 @@ higher_statusbar_update(WINDOW *win, struct statusbar *bar, bool ui_timeout) } static int -infownd_update(WINDOW *win, struct txtwindow *tw, bool ui_timeout) +busywnd_update(WINDOW *win, struct txtwindow *tw, bool ui_timeout) { if (ui_timeout == TRUE && tw->active == TRUE) { size_t len = strlen(busy_str); @@ -91,24 +91,27 @@ passwd_input_cb(WINDOW *wnd, void *data, int key) switch (key) { case UIKEY_ENTER: ui_thrd_suspend(); + memset(busy_str, '\0', BSTR_LEN+1); ui_ipc_msgsend(MQ_PW, a->input); clear_input(wnd, a); deactivate_input(pw_input); ui_thrd_resume(); ui_ipc_msgrecv(MQ_IF, ipc_buf, 3); - show_info_wnd(infownd, "BUSY", ipc_buf, COLOR_PAIR(5), COLOR_PAIR(5), true, false); + show_info_wnd(busywnd, "BUSY", ipc_buf, COLOR_PAIR(5), COLOR_PAIR(5), true, false); sleep(2); if (ui_ipc_msgcount(MQ_IF) > 0) { ui_ipc_msgrecv(MQ_IF, ipc_buf, 3); - show_info_wnd(infownd, "ERROR", ipc_buf, COLOR_PAIR(4), COLOR_PAIR(4), true, true); + show_info_wnd(errwnd, "ERROR", ipc_buf, COLOR_PAIR(4), COLOR_PAIR(4), true, true); while (ui_wgetchtest(1500, '\n') != DOUI_KEY) { }; } ui_thrd_suspend(); - set_txtwindow_active(infownd, false); + set_txtwindow_active(busywnd, false); + set_txtwindow_active(errwnd, false); activate_input(pw_input); + ui_ipc_msgclear(MQ_IF); ui_thrd_resume(); break; case UIKEY_BACKSPACE: @@ -119,7 +122,7 @@ passwd_input_cb(WINDOW *wnd, void *data, int key) clear_input(wnd, a); deactivate_input(pw_input); ui_thrd_resume(); - show_info_wnd(infownd, "QUIT", "bye bye", COLOR_PAIR(5), COLOR_PAIR(5), true, true); + show_info_wnd(errwnd, "QUIT", "bye bye", COLOR_PAIR(5), COLOR_PAIR(5), true, true); sleep(2); return DOUI_ERR; case UIKEY_DOWN: @@ -150,14 +153,17 @@ init_ui_elements(unsigned int max_x, unsigned int max_y) higher_statusbar_update); lower = init_statusbar(max_y - 1, max_x, COLOR_PAIR(3), lower_statusbar_update); - infownd = init_txtwindow_centered(INFOWND_WIDTH, INFOWND_HEIGHT, - infownd_update); + busywnd = init_txtwindow_centered(INFOWND_WIDTH, INFOWND_HEIGHT, + busywnd_update); + errwnd = init_txtwindow_centered(INFOWND_WIDTH, INFOWND_HEIGHT, + NULL); register_input(NULL, pw_input, passwd_input_cb); register_statusbar(higher); register_statusbar(lower); register_anic_default(heartbeat); - register_txtwindow(infownd); + register_txtwindow(busywnd); + register_txtwindow(errwnd); activate_input(pw_input); set_statusbar_text(higher, title); } @@ -173,7 +179,8 @@ free_ui_elements(void) free_anic_default(heartbeat); free_statusbar(higher); free_statusbar(lower); - free_txtwindow(infownd); + free_txtwindow(busywnd); + free_txtwindow(errwnd); free_ui(); if (title) { free(title); |