[MOD/WIP] Redesign the login UI

With delegation-checking!
This commit is contained in:
lda 2024-02-06 22:20:01 +01:00
parent fbffd544cf
commit c028d8ccca
2 changed files with 81 additions and 18 deletions

6
src/include/easters.h Normal file
View File

@ -0,0 +1,6 @@
#ifndef MATRIX_EASTERS_H
#define MATRIX_EASTERS_H
extern void easter_goda(void);
#endif

View File

@ -9,6 +9,7 @@
#include <string.h>
#include <unistd.h>
#include <easters.h>
#include <matrix.h>
#include <utils.h>
@ -24,9 +25,11 @@ void * ui_login_init(ui_screen_t *that)
jwidget *login_widget = jwidget_create(that->owner->stack);
jinput *server, *login, *password;
jwidget *login_content;
jwidget *login_box;
jlabel *login_to_mastrix = jlabel_create(
"Login to Matrix", login_widget
);
jlabel *error;
jpainted *logo;
login_content = jwidget_create(login_widget);
@ -49,23 +52,33 @@ void * ui_login_init(ui_screen_t *that)
mastrix.width, mastrix.height,
login_content
);
error = jlabel_create("Please enter your logins", login_content);
/* Add the actual elements */
server = jinput_create("Server name: ", 32, login_content);
login = jinput_create("Username: ", 32, login_content);
password = jinput_create("Password: ", 64, login_content);
login_box = jwidget_create(login_content);
jlayout_set_vbox(login_box)->spacing = 2;
jwidget_set_padding(login_box, 1, 100, 1, 1);
jwidget_set_border(login_box, J_BORDER_SOLID, 1, C_BLACK);
jwidget_set_stretch(server , 1, 0, false);
jwidget_set_padding(server, 0, 0, 0, 6);
jwidget_set_stretch(login , 1, 0, false);
jwidget_set_padding(login, 0, 0, 0, 6);
jwidget_set_stretch(password , 1, 0, false);
jwidget_set_padding(password, 0, 0, 0, 6);
server = jinput_create("Server name: ", 32, login_box );
jlabel_create("", login_box);
login = jinput_create("Username: ", 32, login_box );
password = jinput_create("Password: ", 64, login_box );
jwidget_set_padding(server, 0, 60, 0, 1);
jwidget_set_stretch(server, 1, 0, true);
jwidget_set_padding(login, 0, 60, 0, 1);
jwidget_set_stretch(login, 1, 0, true);
jwidget_set_padding(password, 0, 60, 0, 1);
jwidget_set_stretch(password, 1, 0, true);
/* Store those so that they can be referenced later */
utils_hashmap_add(that->data, "server", server);
utils_hashmap_add(that->data, "login", login);
utils_hashmap_add(that->data, "password", password);
utils_hashmap_add(that->data, "error", error);
utils_hashmap_add(that->data, "focusing", "server");
@ -100,16 +113,60 @@ void ui_login_event(ui_screen_t *that, jevent e)
{
if (!strcmp(focus_to, "server"))
{
utils_hashmap_add(that->data, "focusing", "login");
ui_login_focus(that);
jinput *server = utils_hashmap_get(that->data, "server");
char *delegated;
char *serv_name = (char *) jinput_value(server);
m_delegation_t status;
if (!strcmp(serv_name, "GODA"))
{
easter_goda();
}
status = matrix_delegate(serv_name, &delegated);
switch (status)
{
case DELEG_FAIL_ERROR:
jlabel_asprintf(
utils_hashmap_get(that->data, "error"),
"Couldn't find a correct servname for '%s'.",
serv_name
);
jlabel_set_text_color(
utils_hashmap_get(that->data, "error"),
C_RED
);
break;
case DELEG_IGNORE:
delegated = utils_strcpy(serv_name);
break;
case DELEG_SUCCESS:
jlabel_asprintf(
utils_hashmap_get(that->data, "error"),
"'%s' => '%s'",
serv_name, delegated
);
jlabel_set_text_color(
utils_hashmap_get(that->data, "error"),
C_GREEN
);
break;
case DELEG_FAIL_PROMPT:
jlabel_asprintf(
utils_hashmap_get(that->data, "error"),
"Please enter the delegation for '%s'.",
serv_name
);
jlabel_set_text_color(
utils_hashmap_get(that->data, "error"),
C_BLACK
);
break;
}
return;
}
if (!strcmp(focus_to, "login"))
{
utils_hashmap_add(that->data, "focusing", "password");
ui_login_focus(that);
return;
}
/* TODO */
}
}