This commit is contained in:
parent
6c8840b3e5
commit
4b7644bd4f
1
.gitignore
vendored
1
.gitignore
vendored
@ -4,3 +4,4 @@ compile_commands.json
|
|||||||
core*
|
core*
|
||||||
build
|
build
|
||||||
log
|
log
|
||||||
|
complaints
|
110
src/menu.cpp
110
src/menu.cpp
@ -1,3 +1,15 @@
|
|||||||
|
#include <curses.h>
|
||||||
|
#include <menu.h>
|
||||||
|
#include <ncurses.h>
|
||||||
|
#include <cstddef>
|
||||||
|
#include <cstdint>
|
||||||
|
#include <cstdio>
|
||||||
|
#include <cstdlib>
|
||||||
|
#include <cstring>
|
||||||
|
#include <filesystem>
|
||||||
|
#include <fstream>
|
||||||
|
#include <iostream>
|
||||||
|
#include <vector>
|
||||||
#include "const.h"
|
#include "const.h"
|
||||||
#include "cups.h"
|
#include "cups.h"
|
||||||
#include "editor_easy.h"
|
#include "editor_easy.h"
|
||||||
@ -5,21 +17,9 @@
|
|||||||
#include "memory.h"
|
#include "memory.h"
|
||||||
#include "strings.h"
|
#include "strings.h"
|
||||||
#include "types.h"
|
#include "types.h"
|
||||||
#include <cstddef>
|
|
||||||
#include <cstdlib>
|
|
||||||
#include <cstring>
|
|
||||||
#include <curses.h>
|
|
||||||
#include <iostream>
|
|
||||||
#include <locale>
|
|
||||||
#include <menu.h>
|
|
||||||
#include <ncurses.h>
|
|
||||||
|
|
||||||
std::vector<allocation> main_menu_allocated;
|
std::vector<allocation> main_menu_allocated;
|
||||||
|
#define COMPLAINTS_DIR "complaints"
|
||||||
const char *choices[] = {"paradox", "kompromis", "Stereotyp", "Žena"};
|
|
||||||
const char *date[] = {"2023-10-01", "2023-10-02", "2023-10-03", "2023-10-04"};
|
|
||||||
const char *choices2[] = {"PRINT", "EDIT", "DELETE", "Žena"};
|
|
||||||
|
|
||||||
void menu() {
|
void menu() {
|
||||||
current_allocated = &main_menu_allocated;
|
current_allocated = &main_menu_allocated;
|
||||||
/* Initialize curses */
|
/* Initialize curses */
|
||||||
@ -29,24 +29,40 @@ void menu() {
|
|||||||
start_color();
|
start_color();
|
||||||
cbreak();
|
cbreak();
|
||||||
noecho();
|
noecho();
|
||||||
curs_set(0); // Makes cursor invisible
|
curs_set(0); // Makes cursor invisible
|
||||||
keypad(stdscr, TRUE);
|
keypad(stdscr, TRUE);
|
||||||
for (uint8_t i = 0; i < 8; i++) {
|
for (uint8_t i = 0; i < 8; i++) {
|
||||||
init_pair(i, i, COLOR_BLACK);
|
init_pair(i, i, COLOR_BLACK);
|
||||||
}
|
}
|
||||||
async_clock_init();
|
async_clock_init();
|
||||||
|
|
||||||
/* Create items */
|
// Create items
|
||||||
size_t n_choices = ARRAY_SIZE(choices);
|
|
||||||
complete_menu main_menu = {nullptr, nullptr, 0, nullptr};
|
complete_menu main_menu = {nullptr, nullptr, 0, nullptr};
|
||||||
main_menu_allocated.push_back({COMPLETE_MENU_TYPE, &main_menu, 1});
|
main_menu_allocated.push_back({COMPLETE_MENU_TYPE, &main_menu, 1});
|
||||||
|
std::vector<ITEM*> items;
|
||||||
main_menu.items = new ITEM *[ARRAY_SIZE(choices) + 1];
|
if (std::filesystem::exists(COMPLAINTS_DIR)) {
|
||||||
main_menu.items_size = ARRAY_SIZE(choices) + 1;
|
for (const auto& directroy_entry :
|
||||||
for (size_t i = 0; i < n_choices; ++i) {
|
std::filesystem::directory_iterator(COMPLAINTS_DIR)) {
|
||||||
main_menu.items[i] = new_item(choices[i], date[i]);
|
if (directroy_entry.is_regular_file()) {
|
||||||
|
std::string name_date[2];
|
||||||
|
std::stringstream ssfn(directroy_entry.path().filename().string());
|
||||||
|
for (uint8_t i = 0; i < 2; i++) {
|
||||||
|
std::getline(ssfn, name_date[i], '_');
|
||||||
|
}
|
||||||
|
char* name = new char[name_date[0].length() + 1];
|
||||||
|
main_menu_allocated.push_back({GENERIC_TYPE, name, 1});
|
||||||
|
char* date = new char[name_date[1].length() + 1];
|
||||||
|
main_menu_allocated.push_back({GENERIC_TYPE, date, 1});
|
||||||
|
strcpy(name, name_date[0].c_str());
|
||||||
|
strcpy(date, name_date[1].c_str());
|
||||||
|
items.push_back(new_item(name, date));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
std::filesystem::create_directory(COMPLAINTS_DIR);
|
||||||
}
|
}
|
||||||
main_menu.items[n_choices] = nullptr;
|
items.push_back(nullptr);
|
||||||
|
main_menu.items = items.data();
|
||||||
|
|
||||||
/* Crate menu */
|
/* Crate menu */
|
||||||
main_menu.menu = new_menu(main_menu.items);
|
main_menu.menu = new_menu(main_menu.items);
|
||||||
@ -79,33 +95,33 @@ void menu() {
|
|||||||
int c;
|
int c;
|
||||||
while ((c = wgetch(main_menu.win)) != KEY_F(1)) {
|
while ((c = wgetch(main_menu.win)) != KEY_F(1)) {
|
||||||
switch (c) {
|
switch (c) {
|
||||||
case KEY_DOWN:
|
case KEY_DOWN:
|
||||||
menu_driver(main_menu.menu, REQ_DOWN_ITEM);
|
menu_driver(main_menu.menu, REQ_DOWN_ITEM);
|
||||||
break;
|
break;
|
||||||
case KEY_UP:
|
case KEY_UP:
|
||||||
menu_driver(main_menu.menu, REQ_UP_ITEM);
|
menu_driver(main_menu.menu, REQ_UP_ITEM);
|
||||||
break;
|
break;
|
||||||
case 10:
|
case 10:
|
||||||
|
|
||||||
refresh();
|
refresh();
|
||||||
break;
|
|
||||||
case ':':
|
|
||||||
switch (hash_djb2a(spawncmd())) {
|
|
||||||
case "print"_sh:
|
|
||||||
case "p"_sh:
|
|
||||||
// DONT FORGET TO PRINT ACTUAL DOCUMENT
|
|
||||||
printDocument("test");
|
|
||||||
current_allocated = &main_menu_allocated;
|
|
||||||
break;
|
break;
|
||||||
case "easy_edit"_sh:
|
case ':':
|
||||||
case "ee"_sh:
|
switch (hash_djb2a(spawncmd())) {
|
||||||
std::clog << vytvorTrestniOznameni();
|
case "print"_sh:
|
||||||
break;
|
case "p"_sh:
|
||||||
default:
|
// DONT FORGET TO PRINT ACTUAL DOCUMENT
|
||||||
print_in_middle(main_menu.win, 10, 0, 40, loc_strings->unknown_command,
|
printDocument("test");
|
||||||
COLOR_PAIR(1));
|
current_allocated = &main_menu_allocated;
|
||||||
break;
|
break;
|
||||||
}
|
case "easy_edit"_sh:
|
||||||
|
case "ee"_sh:
|
||||||
|
std::clog << vytvorTrestniOznameni();
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
print_in_middle(main_menu.win, 10, 0, 40,
|
||||||
|
loc_strings->unknown_command, COLOR_PAIR(1));
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
redrawwin(main_menu.win);
|
redrawwin(main_menu.win);
|
||||||
wrefresh(main_menu.win);
|
wrefresh(main_menu.win);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user