Refactor personInfo function: update parameters to include person list, enhance memory handling, and improve user interaction in TUI.

This commit is contained in:
2025-05-17 21:44:45 +02:00
parent c311dce195
commit 3a0fd9fe65
4 changed files with 113 additions and 71 deletions
+32 -32
View File
@@ -1,32 +1,32 @@
17,Klara,Novotna,3010,1,0,1
18,Jan,Novak,3011,1,0,1
19,Petr,Horak,3012,1,0,1
20,Lucie,Kralova,3013,1,0,1
21,Martin,Prochazka,3014,1,0,1
22,Anna,Urbanova,3015,1,0,1
23,David,Svoboda,3016,1,0,1
24,Veronika,Kucerova,3017,1,0,1
25,Tomas,Blaha,3018,1,0,1
26,Barbora,Kratochvilova,3019,1,0,1
27,Jakub,Pospisil,3020,1,0,1
28,Eliska,Valkova,3021,1,0,1
29,Ondrej,Stepanek,3022,1,0,1
30,Simona,Holubova,3023,1,0,1
31,Filip,Navratil,3024,1,0,1
32,Adela,Slavikova,3025,1,0,1
33,Radek,Polak,3026,1,0,1
34,Monika,Adamcova,3027,1,0,1
35,Jaroslav,Kolar,3028,1,0,1
36,Petra,Malikova,3029,1,0,1
37,Daniel,Richter,3030,1,0,1
38,Kristyna,Stastna,3031,1,0,1
39,Stepan,Musil,3032,1,0,1
40,Lenka,Jurickova,3033,1,0,1
41,Patrik,Vanek,3034,1,0,1
42,Karolina,Vitkova,3035,1,0,1
43,Stanislav,Sevcik,3036,1,0,1
44,Alena,Matouskova,3037,1,0,1
45,Josef,Suchy,3038,1,0,1
46,Marketa,Rezacova,3039,1,0,1
47,Libor,Hanak,3040,1,0,1
48,Libor,Hanak,3040,1,0,1
1,Klara,Novotna,3010,1,0,0
2,Jan,Novak,3011,1,0,0
3,Petr,Horak,3012,1,0,0
4,Lucie,Kralova,3013,1,0,0
5,Martin,Prochazka,3014,1,0,0
6,Anna,Urbanova,3015,1,0,0
7,David,Svoboda,3016,1,0,0
8,Veronika,Kucerova,3017,1,0,0
9,Tomas,Blaha,3018,1,0,0
10,Barbora,Kratochvilova,3019,1,0,0
11,Jakub,Pospisil,3020,1,0,0
12,Eliska,Valkova,3021,1,0,0
13,Ondrej,Stepanek,3022,1,0,0
14,Simona,Holubova,3023,1,0,0
15,Filip,Navratil,3024,1,0,0
16,Adela,Slavikova,3025,1,0,0
17,Radek,Polak,3026,1,0,0
18,Monika,Adamcova,3027,1,0,0
19,Jaroslav,Kolar,3028,1,0,0
20,Petra,Malikova,3029,1,0,0
21,Daniel,Richter,3030,1,0,0
22,Kristyna,Stastna,3031,1,0,0
23,Stepan,Musil,3032,1,0,0
24,Lenka,Jurickova,3033,1,0,0
25,Patrik,Vanek,3034,1,0,0
26,Karolina,Vitkova,3035,1,0,0
27,Stanislav,Sevcik,3036,1,0,0
28,Alena,Matouskova,3037,1,0,0
29,Josef,Suchy,3038,1,0,0
30,Marketa,Rezacova,3039,1,0,0
31,Libor,Hanak,3040,1,0,0
32,Libor,Hanak,3040,1,0,0
1 17 1 Klara Novotna 3010 1 0 0
2 18 1 2 Jan Novak 3011 1 0 0
3 19 1 3 Petr Horak 3012 1 0 0
4 20 1 4 Lucie Kralova 3013 1 0 0
5 21 1 5 Martin Prochazka 3014 1 0 0
6 22 1 6 Anna Urbanova 3015 1 0 0
7 23 1 7 David Svoboda 3016 1 0 0
8 24 1 8 Veronika Kucerova 3017 1 0 0
9 25 1 9 Tomas Blaha 3018 1 0 0
10 26 1 10 Barbora Kratochvilova 3019 1 0 0
11 27 1 11 Jakub Pospisil 3020 1 0 0
12 28 1 12 Eliska Valkova 3021 1 0 0
13 29 1 13 Ondrej Stepanek 3022 1 0 0
14 30 1 14 Simona Holubova 3023 1 0 0
15 31 1 15 Filip Navratil 3024 1 0 0
16 32 1 16 Adela Slavikova 3025 1 0 0
17 33 1 17 Radek Polak 3026 1 0 0
18 34 1 18 Monika Adamcova 3027 1 0 0
19 35 1 19 Jaroslav Kolar 3028 1 0 0
20 36 1 20 Petra Malikova 3029 1 0 0
21 37 1 21 Daniel Richter 3030 1 0 0
22 38 1 22 Kristyna Stastna 3031 1 0 0
23 39 1 23 Stepan Musil 3032 1 0 0
24 40 1 24 Lenka Jurickova 3033 1 0 0
25 41 1 25 Patrik Vanek 3034 1 0 0
26 42 1 26 Karolina Vitkova 3035 1 0 0
27 43 1 27 Stanislav Sevcik 3036 1 0 0
28 44 1 28 Alena Matouskova 3037 1 0 0
29 45 1 29 Josef Suchy 3038 1 0 0
30 46 1 30 Marketa Rezacova 3039 1 0 0
31 47 1 31 Libor Hanak 3040 1 0 0
32 48 1 32 Libor Hanak 3040 1 0 0
+2 -1
View File
@@ -16,10 +16,11 @@ void personListing(list_t *person_list, int terminal_x, int terminal_y);
void personSearch(list_t *person_list, int terminal_x, int terminal_y);
void personInfo(node_t *_person, int terminal_x, int terminal_y);
void personInfo(list_t * _list ,node_t *_person, int terminal_x, int terminal_y);
void exportDialog(list_t *_list, int terminal_x, int terminal_y);
void editDatabaseMenu(list_t *_person_list, int terminal_x, int terminal_y);
#endif
+16 -8
View File
@@ -255,7 +255,7 @@ void personListing(list_t *person_list, int terminal_x, int terminal_y)
int idx = 0, row = 2;
while (current && row < win_height)
{
if (current->user.uuid)
if (idx >= offset && row < win_height - 1)
{
if (idx == highlight)
@@ -278,7 +278,7 @@ void personListing(list_t *person_list, int terminal_x, int terminal_y)
keyboard_input = wgetch(personlisting);
if (keyboard_input == KEY_UP)
{
if (highlight > 1)
if (highlight > 0)
{
highlight--;
if (highlight < offset)
@@ -303,7 +303,7 @@ void personListing(list_t *person_list, int terminal_x, int terminal_y)
selected = selected->next;
idx++;
}
personInfo(selected, terminal_x, terminal_y);
personInfo(person_list, selected, terminal_x, terminal_y);
}
else if (keyboard_input == 27 || keyboard_input == 'q')
{
@@ -460,10 +460,10 @@ void personSearch(list_t *person_list, int terminal_x, int terminal_y)
}
}
void personInfo(node_t *_person, int terminal_x, int terminal_y)
void personInfo(list_t *_list, node_t *_person, int terminal_x, int terminal_y)
{
int win_height = 14;
int win_width = 50;
int win_width = 60;
int start_y = (terminal_y - win_height) / 2;
int start_x = (terminal_x - win_width) / 2;
@@ -483,7 +483,7 @@ void personInfo(node_t *_person, int terminal_x, int terminal_y)
wattroff(personinfodialog, COLOR_PAIR(6));
keypad(personinfodialog, TRUE);
char buttons[2][20] = {"<Print to file...>", "<Back>"};
char buttons[3][20] = {"<Print to file...>", "<Add Time Event>", "<Back>"};
char prompts[6][32] = {"Name", "Surname", "Department", "Last time event", "Total time", "Available"};
char keyboard_input;
@@ -520,7 +520,7 @@ void personInfo(node_t *_person, int terminal_x, int terminal_y)
wrefresh(personinfodialog);
for (int i = 0; i < 2; i++)
for (int i = 0; i < 3; i++)
{
if (highlight == i)
wattron(personinfodialog, COLOR_PAIR(2));
@@ -541,8 +541,12 @@ void personInfo(node_t *_person, int terminal_x, int terminal_y)
if (keyboard_input == '\t')
{
highlight = !highlight;
if (highlight != 2)
highlight++;
else
highlight = 1;
}
else if (keyboard_input == '\n')
{
if (highlight == 0)
@@ -550,6 +554,10 @@ void personInfo(node_t *_person, int terminal_x, int terminal_y)
exportPersonInfo(_person);
}
else if (highlight == 1)
{
addTimeEvent(_person, _list);
}
else if (highlight == 2)
{
delwin(personinfodialog);
touchwin(stdscr);
+49 -16
View File
@@ -156,14 +156,54 @@ int addPersonToList(
int loadPersonToList(list_t *_list, uint16_t _uuid, char *_name, char *_surname, uint32_t _department, time_t _last_event, time_t _total, BYTE _available)
{
node_t *new_node = (node_t *)malloc(sizeof(node_t));
if (new_node == NULL)
return 0;
if (!strlen(_name) || !strlen(_surname))
{
free(new_node);
new_node = NULL;
return 0;
}
pthread_mutex_lock(&_list->lock);
if (_list->head == NULL)
{
_list->head = (node_t *)malloc(sizeof(node_t));
if (_list->head == NULL) {
pthread_mutex_unlock(&_list->lock);
return 0;
}
_list->head->next = NULL;
_list->head->user.name = NULL;
_list->head->user.surname = NULL;
}
if (_list->head->user.name == NULL && _list->head->user.surname == NULL)
{
node_t *target = _list->head;
target->user.uuid = _uuid;
target->user.name = (char *)malloc(strlen(_name) + 1);
target->user.surname = (char *)malloc(strlen(_surname) + 1);
if (target->user.name == NULL || target->user.surname == NULL)
{
free(target->user.name);
free(target->user.surname);
pthread_mutex_unlock(&_list->lock);
return 0;
}
strcpy(target->user.name, _name);
strcpy(target->user.surname, _surname);
target->user.department = _department;
target->user.last_time_event = _last_event;
target->user.total = _total;
target->user.available = _available;
pthread_mutex_unlock(&_list->lock);
return 1;
}
node_t *new_node = (node_t *)malloc(sizeof(node_t));
if (new_node == NULL)
{
pthread_mutex_unlock(&_list->lock);
return 0;
}
@@ -176,6 +216,7 @@ int loadPersonToList(list_t *_list, uint16_t _uuid, char *_name, char *_surname,
free(new_node->user.name);
free(new_node->user.surname);
free(new_node);
pthread_mutex_unlock(&_list->lock);
return 0;
}
@@ -188,16 +229,6 @@ int loadPersonToList(list_t *_list, uint16_t _uuid, char *_name, char *_surname,
new_node->next = NULL;
pthread_mutex_lock(&_list->lock);
if (_list->head == NULL)
{
_list->head = new_node;
pthread_mutex_unlock(&_list->lock);
return 0;
}
node_t *current = _list->head;
while (current->next != NULL)
{
@@ -223,8 +254,10 @@ int addTimeEvent(
pthread_mutex_lock(&_list->lock);
if (_person->user.available)
{
if (current_time > _person->user.last_time_event) {
_person->user.total += (current_time - _person->user.last_time_event);
}
}
_person->user.available = !_person->user.available;
_person->user.last_time_event = current_time;