summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorAldrik Ramaekers <aldrikboy@gmail.com>2025-10-04 18:36:31 +0200
committerAldrik Ramaekers <aldrikboy@gmail.com>2025-10-04 18:36:31 +0200
commitcd827834f9ee329c27b82d987f0d1d48a854a954 (patch)
tree3f2b63cc88f7d01ac6c55ff6c8cd5ff26dae55b5 /include
parent83cbf0e4a142ab2c57fd4fdfc056517b7149828b (diff)
namespace importer
Diffstat (limited to 'include')
-rw-r--r--include/config.hpp2
-rw-r--r--include/importer.hpp66
-rw-r--r--include/ui.hpp145
3 files changed, 109 insertions, 104 deletions
diff --git a/include/config.hpp b/include/config.hpp
index df99ab2..fc15e84 100644
--- a/include/config.hpp
+++ b/include/config.hpp
@@ -42,5 +42,7 @@ namespace config {
namespace colors {
static const ImU32 COLOR_ERROR_OUTLINE = IM_COL32(255, 0, 0, 80);
+ static const ImU32 COLOR_ERROR = IM_COL32(235, 64, 52, 255);
+ static const ImU32 COLOR_DEFAULT = IM_COL32(235, 255, 255, 255);
}
} \ No newline at end of file
diff --git a/include/importer.hpp b/include/importer.hpp
index 7e23e20..fde297a 100644
--- a/include/importer.hpp
+++ b/include/importer.hpp
@@ -18,40 +18,42 @@
#include "administration.hpp"
-typedef uint32_t i_err;
-
#define I_ERR_SUCCESS 0
#define I_ERR_FAILED_UPLOAD 1
#define I_ERR_FAILED_QUERY 2
#define I_ERR_FAILED_IMPORT 3
-typedef enum
-{
- IMPORT_STARTING,
- IMPORT_UPLOADING_FILE,
- IMPORT_QUERYING,
- IMPORT_WAITING_FOR_RESPONSE,
- IMPORT_DONE,
-} import_status;
-
-typedef struct
-{
- time_t started_at;
- invoice result;
- char file_path[MAX_LEN_PATH];
- i_err error;
- import_status status;
-} import_invoice_request;
-
-typedef struct
-{
- bool (*upload_file)(char* file_path, char* file_id, size_t file_id_len);
- bool (*query_with_file)(char* query, size_t query_length, char* file_id, char** response);
-} ai_provider_impl;
-
-extern ai_provider_impl _chatgpt_api_provider;
-extern ai_provider_impl _deepseek_api_provider;
-
-const char* import_error_to_str(i_err error);
-const char* import_status_to_str(import_status status);
-import_invoice_request* ai_document_to_invoice(char* file_path); \ No newline at end of file
+namespace importer {
+
+ typedef uint32_t i_err;
+
+ typedef enum
+ {
+ IMPORT_STARTING,
+ IMPORT_UPLOADING_FILE,
+ IMPORT_QUERYING,
+ IMPORT_WAITING_FOR_RESPONSE,
+ IMPORT_DONE,
+ } status;
+
+ typedef struct
+ {
+ time_t started_at;
+ invoice result;
+ char file_path[MAX_LEN_PATH];
+ i_err error;
+ status status;
+ } invoice_request;
+
+ typedef struct
+ {
+ bool (*upload_file)(char* file_path, char* file_id, size_t file_id_len);
+ bool (*query_with_file)(char* query, size_t query_length, char* file_id, char** response);
+ } ai_provider_impl;
+
+ const char* error_to_string(i_err error);
+ const char* status_to_string(status status);
+
+ invoice_request* ai_document_to_invoice(char* file_path);
+
+} \ No newline at end of file
diff --git a/include/ui.hpp b/include/ui.hpp
index 931f302..9304f78 100644
--- a/include/ui.hpp
+++ b/include/ui.hpp
@@ -20,84 +20,85 @@
#include "administration.hpp"
#define STATUS_TEXT_LEN 64
-#define STATUS_DURATION 4.0f
-#define STATUS_FLASH_INTERVAL 0.1f
-#define STATUS_MAX_FLASHES 2
-#define COLOR_ERROR IM_COL32(235, 64, 52, 255)
-#define COLOR_DEFAULT IM_COL32(235, 255, 255, 255)
-
-typedef enum
-{
- UI_INVOICES = 0,
- UI_EXPENSES = 1,
- UI_CONTACTS = 2,
- UI_REPORT_RESULTS = 3,
- UI_REPORT_TAX = 4,
- UI_PROJECTS = 5,
- UI_SETTINGS = 6,
- UI_LOG = 7,
-
- UI_END
-} main_state;
-
-typedef enum
-{
- LIST,
- EDIT,
- CREATE,
- VIEW,
- VIEW_IMPORT_REQUEST,
-} view_state;
-
-typedef struct
-{
- bool visible;
- int flash_count;
- int color;
- char text[STATUS_TEXT_LEN];
- float time;
- bool loading;
-} ui_status;
-
-extern ImFont* fontBold;
-extern ImFont* fontBig;
-
-ui_status ui_get_status();
-void ui_set_status_loading(bool loading);
-void ui_set_status_error(const char* txt);
-void ui_set_status_ex(const char* txt, int color);
-void ui_set_status(const char* txt);
-void ui_draw_status();
-
-void ui_set_state(main_state state);
-
-void ui_draw_main();
-void ui_draw_contacts();
-void ui_draw_projects();
-void ui_draw_invoices();
-void ui_draw_settings();
-void ui_draw_expenses();
-void ui_draw_earnings();
-void ui_draw_log();
-
-void ui_setup_invoices();
-void ui_setup_contacts();
-void ui_setup_projects();
-void ui_setup_settings();
-void ui_setup_expenses();
-void ui_setup_earnings();
-
-void ui_destroy_invoices();
-void ui_destroy_settings();
-void ui_destroy_expenses();
-void ui_destroy_earnings();
+namespace ui {
+
+ typedef enum
+ {
+ UI_INVOICES = 0,
+ UI_EXPENSES = 1,
+ UI_CONTACTS = 2,
+ UI_REPORT_RESULTS = 3,
+ UI_REPORT_TAX = 4,
+ UI_PROJECTS = 5,
+ UI_SETTINGS = 6,
+ UI_LOG = 7,
+
+ UI_END
+ } main_state;
+
+ typedef enum
+ {
+ LIST_ALL,
+ EDIT_EXISTING,
+ CREATE,
+ VIEW_EXISTING,
+ VIEW_IMPORT_REQUEST,
+ } view_state;
+
+ typedef struct
+ {
+ bool visible;
+ int flash_count;
+ int color;
+ char text[STATUS_TEXT_LEN];
+ float time;
+ bool loading;
+ } status;
+
+ extern ImFont* fontBold;
+ extern ImFont* fontBig;
+
+ void set_state(main_state state);
+
+ // Status functions.
+ status get_status();
+ void set_status_loading(bool loading);
+ void set_status_error(const char* txt);
+ void set_status(const char* txt);
+ void draw_status();
+
+ // Draw calls.
+ void draw_main();
+ void draw_contacts();
+ void draw_projects();
+ void draw_invoices();
+ void draw_settings();
+ void draw_expenses();
+ void draw_earnings();
+ void draw_log();
+
+ // Setup calls.
+ void setup_invoices();
+ void setup_contacts();
+ void setup_projects();
+ void setup_settings();
+ void setup_expenses();
+ void setup_earnings();
+
+ // Destroy calls.
+ void destroy_invoices();
+ void destroy_settings();
+ void destroy_expenses();
+ void destroy_earnings();
+
+}
// Custom imgui widgets.
namespace ImGui
{
void InputTextWithError(const char* text, char* buffer, size_t buf_size, bool has_error);
- int TextInputWithAutocomplete(const char* hint, char* buffer, size_t buf_size, char** suggestions, int suggestion_count, bool has_error);
+ int TextInputWithAutocomplete(const char* hint, char* buffer, size_t buf_size, char** suggestions, int suggestion_count, bool has_error);
bool FormInvoiceFileSelector(char* text, char* buffer);
void FormContactAutocomplete(contact* buffer, bool has_error);