more additions for future file handling
Some checks failed
build_test / build (push) Failing after 3m32s
Some checks failed
build_test / build (push) Failing after 3m32s
This commit is contained in:
parent
eaf6f44464
commit
7f427a47fc
@ -17,4 +17,6 @@ inline constexpr auto operator""_sh(const char* str, size_t len) {
|
||||
return hash_djb2a(std::string_view{str, len});
|
||||
}
|
||||
|
||||
enum { NOT_SEND, SEND, REJECTED, ACCEPTED, STATUS_COUNT };
|
||||
|
||||
#endif
|
@ -1,19 +1,19 @@
|
||||
#include "gameske_funkce.h"
|
||||
#include "memory.h"
|
||||
#include "strings.h"
|
||||
#include <curses.h>
|
||||
#include <menu.h>
|
||||
#include <ncurses.h>
|
||||
#include <unistd.h>
|
||||
#include <chrono>
|
||||
#include <clocale>
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
#include <cstring>
|
||||
#include <curses.h>
|
||||
#include <format>
|
||||
#include <iostream>
|
||||
#include <menu.h>
|
||||
#include <ncurses.h>
|
||||
#include <string>
|
||||
#include <thread>
|
||||
#include <unistd.h>
|
||||
#include "memory.h"
|
||||
#include "strings.h"
|
||||
|
||||
/*
|
||||
size_t spawn_menu(uint16_t begin_y, uint16_t begin_x, const char** choices,
|
||||
@ -81,10 +81,10 @@ size_t spawn_menu(uint16_t begin_y, uint16_t begin_x, const char** choices,
|
||||
}
|
||||
*/
|
||||
|
||||
void print_in_middle(WINDOW *win, int starty, int startx, int width,
|
||||
const char *string, chtype color) {
|
||||
void print_in_middle(WINDOW* win, int starty, int startx, int width,
|
||||
const char* string, chtype color) {
|
||||
int length, x, y;
|
||||
float temp;
|
||||
uint8_t temp;
|
||||
|
||||
if (win == NULL)
|
||||
win = stdscr;
|
||||
@ -98,7 +98,7 @@ void print_in_middle(WINDOW *win, int starty, int startx, int width,
|
||||
|
||||
length = strlen(string);
|
||||
temp = (width - length) / 2;
|
||||
x = startx + (int)temp;
|
||||
x = startx + temp;
|
||||
wattron(win, color);
|
||||
mvwprintw(win, y, x, "%s", string);
|
||||
wattroff(win, color);
|
||||
@ -110,7 +110,7 @@ std::string spawncmd(const std::string prompt) {
|
||||
int pos = 0;
|
||||
int ch;
|
||||
|
||||
WINDOW *cmd_win = newwin(3, 40, LINES - 3, 0);
|
||||
WINDOW* cmd_win = newwin(3, 40, LINES - 3, 0);
|
||||
if (cmd_win == NULL)
|
||||
return "";
|
||||
|
||||
@ -134,7 +134,7 @@ std::string spawncmd(const std::string prompt) {
|
||||
if (pos > 0) {
|
||||
pos--;
|
||||
// Move cursor back and erase the character
|
||||
wmove(cmd_win, 1, 10 + pos);
|
||||
wmove(cmd_win, 1, prompt.length() + 3 + pos);
|
||||
waddch(cmd_win, ' ');
|
||||
wmove(cmd_win, 1, 10 + pos);
|
||||
}
|
||||
@ -143,7 +143,8 @@ std::string spawncmd(const std::string prompt) {
|
||||
} else if (isprint(ch)) {
|
||||
// Printable character
|
||||
cmd[pos] = ch;
|
||||
mvwaddch(cmd_win, 1, 10 + pos, ch); // Echo the character
|
||||
mvwaddch(cmd_win, 1, prompt.length() + 3 + pos,
|
||||
ch); // Echo the character
|
||||
pos++;
|
||||
}
|
||||
|
||||
@ -151,7 +152,7 @@ std::string spawncmd(const std::string prompt) {
|
||||
}
|
||||
wattroff(cmd_win, COLOR_PAIR(COLOR_CYAN));
|
||||
|
||||
cmd[pos] = '\0'; // Ensure null termination
|
||||
cmd[pos] = '\0'; // Ensure null termination
|
||||
// Restore echo state as needed
|
||||
curs_set(0);
|
||||
|
||||
@ -161,7 +162,7 @@ std::string spawncmd(const std::string prompt) {
|
||||
return std::string(cmd);
|
||||
}
|
||||
|
||||
void async_clock(WINDOW *win, WINDOW *text_win) {
|
||||
void async_clock(WINDOW* win, WINDOW* text_win) {
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(100));
|
||||
bool prev_echo_state;
|
||||
uint16_t prev_y, prev_x;
|
||||
@ -183,7 +184,7 @@ void async_clock(WINDOW *win, WINDOW *text_win) {
|
||||
if (dot_pos != std::string::npos) {
|
||||
time_str.erase(dot_pos);
|
||||
}
|
||||
} catch (const std::exception &e) {
|
||||
} catch (const std::exception& e) {
|
||||
std::clog << "Format error: " << e.what() << std::endl;
|
||||
time_str = "Error";
|
||||
}
|
||||
@ -205,11 +206,11 @@ void async_clock(WINDOW *win, WINDOW *text_win) {
|
||||
void async_clock_init() {
|
||||
|
||||
// memory leak
|
||||
WINDOW *win = newwin(3, 10, LINES - 3, COLS - 10);
|
||||
WINDOW* win = newwin(3, 10, LINES - 3, COLS - 10);
|
||||
current_allocated->push_back({WINDOW_TYPE, win, 1});
|
||||
|
||||
// memory leak
|
||||
WINDOW *text_win = newwin(3, 52, LINES - 3, COLS - 10 - 44);
|
||||
WINDOW* text_win = newwin(3, 52, LINES - 3, COLS - 10 - 44);
|
||||
current_allocated->push_back({WINDOW_TYPE, text_win, 1});
|
||||
|
||||
std::thread clock_thread(async_clock, win, text_win);
|
||||
|
141
src/menu.cpp
141
src/menu.cpp
@ -1,19 +1,26 @@
|
||||
#include <curses.h>
|
||||
#include <menu.h>
|
||||
#include <ncurses.h>
|
||||
#include <cerrno>
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
#include <cstring>
|
||||
#include <filesystem>
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
#include <nlohmann/json.hpp>
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include "const.h"
|
||||
#include "cups.h"
|
||||
#include "editor_easy.h"
|
||||
#include "gameske_funkce.h"
|
||||
#include "memory.h"
|
||||
#include "signal.h"
|
||||
#include "strings.h"
|
||||
#include "types.h"
|
||||
#include <cstdint>
|
||||
#include <cstring>
|
||||
#include <curses.h>
|
||||
#include <filesystem>
|
||||
#include <iostream>
|
||||
#include <menu.h>
|
||||
#include <ncurses.h>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
using nlohmann::json;
|
||||
|
||||
std::vector<allocation> main_menu_allocated;
|
||||
#define COMPLAINTS_DIR "complaints"
|
||||
@ -26,7 +33,7 @@ void menu() {
|
||||
start_color();
|
||||
cbreak();
|
||||
noecho();
|
||||
curs_set(0); // Makes cursor invisible
|
||||
curs_set(0); // Makes cursor invisible
|
||||
keypad(stdscr, TRUE);
|
||||
for (uint8_t i = 0; i < 8; i++) {
|
||||
init_pair(i, i, COLOR_BLACK);
|
||||
@ -37,19 +44,33 @@ void menu() {
|
||||
complete_menu main_menu = {nullptr, nullptr, 0, nullptr};
|
||||
main_menu_allocated.push_back({COMPLETE_MENU_TYPE, &main_menu, 1});
|
||||
{
|
||||
std::vector<ITEM *> items;
|
||||
std::vector<ITEM*> items;
|
||||
if (std::filesystem::exists(COMPLAINTS_DIR)) {
|
||||
for (const auto &directroy_entry :
|
||||
for (const std::filesystem::directory_entry& directroy_entry :
|
||||
std::filesystem::directory_iterator(COMPLAINTS_DIR)) {
|
||||
if (directroy_entry.is_regular_file()) {
|
||||
std::ifstream file(directroy_entry.path());
|
||||
std::string name_date[2];
|
||||
std::stringstream ssfn(directroy_entry.path().filename().string());
|
||||
for (uint8_t i = 0; i < 2; i++) {
|
||||
for (uint8_t i = 0; i < ARRAY_SIZE(name_date); i++) {
|
||||
std::getline(ssfn, name_date[i], '_');
|
||||
}
|
||||
char *name = new char[name_date[0].length() + 1];
|
||||
json complaint_json = json::parse(file);
|
||||
if (complaint_json["status"].is_null() ||
|
||||
complaint_json["status"].get<size_t>() >= STATUS_COUNT) {
|
||||
std::cerr << "Invalid status in file: "
|
||||
<< directroy_entry.path().filename().string()
|
||||
<< std::endl;
|
||||
safe_exit(EINVAL);
|
||||
}
|
||||
name_date[1].append(" ");
|
||||
name_date[1].append(
|
||||
loc_strings
|
||||
->status_strings[complaint_json["status"].get<uint8_t>()]);
|
||||
|
||||
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];
|
||||
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());
|
||||
@ -60,8 +81,8 @@ void menu() {
|
||||
std::filesystem::create_directory(COMPLAINTS_DIR);
|
||||
}
|
||||
items.push_back(nullptr);
|
||||
main_menu.items = new ITEM *[items.size()];
|
||||
memcpy(main_menu.items, items.data(), (items.size() * sizeof(ITEM *)));
|
||||
main_menu.items = new ITEM*[items.size()];
|
||||
memcpy(main_menu.items, items.data(), (items.size() * sizeof(ITEM*)));
|
||||
}
|
||||
|
||||
/* Crate menu */
|
||||
@ -95,40 +116,66 @@ void menu() {
|
||||
int c;
|
||||
while ((c = wgetch(main_menu.win)) != KEY_F(1)) {
|
||||
switch (c) {
|
||||
case KEY_DOWN:
|
||||
menu_driver(main_menu.menu, REQ_DOWN_ITEM);
|
||||
break;
|
||||
case KEY_UP:
|
||||
menu_driver(main_menu.menu, REQ_UP_ITEM);
|
||||
break;
|
||||
case 10:
|
||||
|
||||
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;
|
||||
case KEY_DOWN:
|
||||
menu_driver(main_menu.menu, REQ_DOWN_ITEM);
|
||||
break;
|
||||
case "easy_edit"_sh:
|
||||
case "ee"_sh: {
|
||||
std::string name = spawncmd("Reference Name");
|
||||
if (name == "") {
|
||||
print_in_middle(main_menu.win, 10, 0, 40,
|
||||
loc_strings->unknown_command, COLOR_PAIR(1));
|
||||
case KEY_UP:
|
||||
menu_driver(main_menu.menu, REQ_UP_ITEM);
|
||||
break;
|
||||
case 10:
|
||||
|
||||
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;
|
||||
case "easy_edit"_sh:
|
||||
case "ee"_sh: {
|
||||
const std::string name = spawncmd(loc_strings->reference_name);
|
||||
if (name == "") {
|
||||
print_in_middle(main_menu.win, 10, 0, 40,
|
||||
loc_strings->invalid_input, COLOR_PAIR(1));
|
||||
}
|
||||
|
||||
const time_t current_time = time(nullptr);
|
||||
const tm* local_time = localtime(¤t_time);
|
||||
|
||||
char formatted_date[11];
|
||||
strftime(formatted_date, sizeof(formatted_date), "%d-%m-%Y",
|
||||
local_time);
|
||||
|
||||
std::ofstream complaint_file(COMPLAINTS_DIR "/" + name + "_" +
|
||||
formatted_date);
|
||||
|
||||
const std::string complaint_text = vytvorTrestniOznameni();
|
||||
|
||||
json complaint_json = {{"date", formatted_date},
|
||||
{"status", NOT_SEND},
|
||||
{"complaint_text", complaint_text}};
|
||||
|
||||
complaint_file << complaint_json;
|
||||
|
||||
break;
|
||||
}
|
||||
default:
|
||||
print_in_middle(main_menu.win, 10, 0, 40,
|
||||
loc_strings->unknown_command, COLOR_PAIR(1));
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case 'm':
|
||||
std::stringstream item_name_ss(item_name(current_item(main_menu.menu)));
|
||||
std::string name_date[2];
|
||||
for (uint8_t i = 0; i < ARRAY_SIZE(name_date); i++) {
|
||||
std::getline(item_name_ss, name_date[i], ' ');
|
||||
}
|
||||
|
||||
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);
|
||||
wrefresh(main_menu.win);
|
||||
|
@ -76,7 +76,9 @@ Signature of the complainant: {0}
|
||||
*This is not a legal document, but only a template for informational purposes. For legal advice, please consult a qualified attorney.*
|
||||
)",
|
||||
.command = "Command",
|
||||
.invalid_input = "Invalid input"};
|
||||
.invalid_input = "Invalid input",
|
||||
.reference_name = "Reference Name",
|
||||
.status_strings = {"Not sent", "Sent", "Rejected", "Accepted"}};
|
||||
|
||||
constexpr strings czech_strings{
|
||||
.invalid_option = "Neplatná volba: ",
|
||||
@ -152,6 +154,8 @@ Podpis oznamovatele: {0}
|
||||
*Toto není právní dokument, ale pouze vzor pro informativní účely. Pro právní poradenství se obraťte na kvalifikovaného právníka.*
|
||||
)",
|
||||
.command = "Příkaz",
|
||||
.invalid_input = "Neplatný vstup"};
|
||||
.invalid_input = "Neplatný vstup",
|
||||
.reference_name = "Referenční Název",
|
||||
.status_strings = {"Nebylo odesláno", "Odesláno", "Zamítnuto", "Přijato"}};
|
||||
|
||||
const strings *loc_strings;
|
||||
const strings* loc_strings;
|
@ -1,44 +1,47 @@
|
||||
|
||||
#ifndef PARADOCS_STRINGS_H_
|
||||
#define PARADOCS_STRINGS_H_
|
||||
#include "const.h"
|
||||
typedef struct {
|
||||
const char *invalid_option;
|
||||
const char *try_str;
|
||||
const char *usage;
|
||||
const char *options;
|
||||
const char *print_this_help;
|
||||
const char *print_version;
|
||||
const char *version;
|
||||
const char *main_menu;
|
||||
const char *f1_to_exit;
|
||||
const char *unknown_command;
|
||||
const char* invalid_option;
|
||||
const char* try_str;
|
||||
const char* usage;
|
||||
const char* options;
|
||||
const char* print_this_help;
|
||||
const char* print_version;
|
||||
const char* version;
|
||||
const char* main_menu;
|
||||
const char* f1_to_exit;
|
||||
const char* unknown_command;
|
||||
|
||||
const char *min_terminal_size;
|
||||
const char *name_of_submiter;
|
||||
const char *address_of_submiter;
|
||||
const char *phone_of_submiter;
|
||||
const char *email_of_submiter;
|
||||
const char* min_terminal_size;
|
||||
const char* name_of_submiter;
|
||||
const char* address_of_submiter;
|
||||
const char* phone_of_submiter;
|
||||
const char* email_of_submiter;
|
||||
|
||||
const char *name_of_recipient;
|
||||
const char *address_of_recipient;
|
||||
const char *phone_of_recipient;
|
||||
const char *email_of_recipient;
|
||||
const char* name_of_recipient;
|
||||
const char* address_of_recipient;
|
||||
const char* phone_of_recipient;
|
||||
const char* email_of_recipient;
|
||||
|
||||
const char *place_of_incident;
|
||||
const char *date_of_incident;
|
||||
const char *description_of_incident;
|
||||
const char *evidence_of_incident;
|
||||
const char *additional_info;
|
||||
const char* place_of_incident;
|
||||
const char* date_of_incident;
|
||||
const char* description_of_incident;
|
||||
const char* evidence_of_incident;
|
||||
const char* additional_info;
|
||||
|
||||
const char *cease_and_desist_entry_of_information;
|
||||
const char *enter_all_information_and_press_f10;
|
||||
const char* cease_and_desist_entry_of_information;
|
||||
const char* enter_all_information_and_press_f10;
|
||||
|
||||
const char *criminal_complaint_template;
|
||||
const char *command;
|
||||
const char *invalid_input;
|
||||
const char* criminal_complaint_template;
|
||||
const char* command;
|
||||
const char* invalid_input;
|
||||
const char* reference_name;
|
||||
const char* status_strings[STATUS_COUNT];
|
||||
} strings;
|
||||
|
||||
extern const strings english_strings;
|
||||
extern const strings czech_strings;
|
||||
extern const strings *loc_strings;
|
||||
extern const strings* loc_strings;
|
||||
#endif
|
||||
|
Loading…
x
Reference in New Issue
Block a user