diff --git a/TestList.csv b/TestList.csv index d3cbcc7..884d7cd 100644 --- a/TestList.csv +++ b/TestList.csv @@ -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 \ No newline at end of file +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 diff --git a/include/tui.h b/include/tui.h index b9e6b5a..f04e866 100644 --- a/include/tui.h +++ b/include/tui.h @@ -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 \ No newline at end of file diff --git a/src/tui.c b/src/tui.c index dc94e25..23584d4 100644 --- a/src/tui.c +++ b/src/tui.c @@ -255,20 +255,20 @@ 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) - wattron(personlisting, COLOR_PAIR(2)); - mvwprintw(personlisting, row, 2, "%-10hu %-20s %-20s %s", - current->user.uuid, - current->user.surname, - current->user.name, - current->user.available ? "Yes " : "No "); - if (idx == highlight) - wattroff(personlisting, COLOR_PAIR(2)); - row++; - } + + if (idx >= offset && row < win_height - 1) + { + if (idx == highlight) + wattron(personlisting, COLOR_PAIR(2)); + mvwprintw(personlisting, row, 2, "%-10hu %-20s %-20s %s", + current->user.uuid, + current->user.surname, + current->user.name, + current->user.available ? "Yes " : "No "); + if (idx == highlight) + wattroff(personlisting, COLOR_PAIR(2)); + row++; + } idx++; current = current->next; } @@ -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] = {"", ""}; + char buttons[3][20] = {"", "", ""}; 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); diff --git a/src/users.c b/src/users.c index 1f40513..d374e3a 100644 --- a/src/users.c +++ b/src/users.c @@ -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,7 +254,9 @@ int addTimeEvent( pthread_mutex_lock(&_list->lock); if (_person->user.available) { - _person->user.total += (current_time - _person->user.last_time_event); + if (current_time > _person->user.last_time_event) { + _person->user.total += (current_time - _person->user.last_time_event); + } } _person->user.available = !_person->user.available;