more additions for future file handling
Some checks failed
build_test / build (push) Failing after 3m32s

This commit is contained in:
PoliEcho 2025-05-28 17:58:42 +02:00
parent eaf6f44464
commit 7f427a47fc
5 changed files with 155 additions and 98 deletions

View File

@ -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

View File

@ -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,
@ -84,7 +84,7 @@ 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) {
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);
@ -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++;
}

View File

@ -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"
@ -39,14 +46,28 @@ void menu() {
{
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], '_');
}
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];
@ -115,20 +136,46 @@ void menu() {
break;
case "easy_edit"_sh:
case "ee"_sh: {
std::string name = spawncmd("Reference Name");
const std::string name = spawncmd(loc_strings->reference_name);
if (name == "") {
print_in_middle(main_menu.win, 10, 0, 40,
loc_strings->unknown_command, COLOR_PAIR(1));
loc_strings->invalid_input, COLOR_PAIR(1));
}
std::clog << vytvorTrestniOznameni();
const time_t current_time = time(nullptr);
const tm* local_time = localtime(&current_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));
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], ' ');
}
break;
}
redrawwin(main_menu.win);
wrefresh(main_menu.win);

View File

@ -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;

View File

@ -1,6 +1,7 @@
#ifndef PARADOCS_STRINGS_H_
#define PARADOCS_STRINGS_H_
#include "const.h"
typedef struct {
const char* invalid_option;
const char* try_str;
@ -36,6 +37,8 @@ typedef struct {
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;