From afc58c547f25affd9075ee5eef4444b7c0855e06 Mon Sep 17 00:00:00 2001 From: Aldrik Ramaekers Date: Mon, 12 Jan 2026 14:27:43 +0100 Subject: ui improvements --- TODO | 1 + include/config.hpp | 2 +- include/exporter.hpp | 5 ++++- include/ui.hpp | 1 + src/administration_reader.cpp | 3 +++ src/locales/en.cpp | 12 ++++++------ src/main_linux.cpp | 16 ++++++++++++++++ src/providers/MailerSend.cpp | 12 ++++++++++-- src/ui/ui_main.cpp | 23 +++++++---------------- 9 files changed, 49 insertions(+), 26 deletions(-) diff --git a/TODO b/TODO index 17dc4e4..ec54557 100644 --- a/TODO +++ b/TODO @@ -4,6 +4,7 @@ Fix: - When reloading view, lock main thread as the freeing might cause a crash - reload invoice when backing out of edit mode. Unsaved changed are not undone atm - Handle missing file loading crash +- handle invalid file format crash. check if xml object is found before using it. Refactor: - Refactor zip writing to be faster (Windows is slow) diff --git a/include/config.hpp b/include/config.hpp index ed1feed..1bc2b99 100644 --- a/include/config.hpp +++ b/include/config.hpp @@ -30,7 +30,7 @@ #define u32 uint32_t #define u64 uint64_t -#define SIMULATE_AI_IMPORT 1 +#define SIMULATE_AI_IMPORT 0 #define SIMULATE_EMAIL_FAILURE 0 #define SIMULATE_EMAIL 0 #define SIMULATE_SLOW_DISK 0 diff --git a/include/exporter.hpp b/include/exporter.hpp index 649c8c2..cde937c 100644 --- a/include/exporter.hpp +++ b/include/exporter.hpp @@ -20,7 +20,10 @@ #define E_ERR_SUCCESS 0 #define E_ERR_FAILED_REQUEST 1 -#define E_ERR_UNIMPLEMENTED 2 +#define E_ERR_TIMEOUT 2 +#define E_ERR_UNAUTHORIZED 3 +#define E_ERR_SERVER_ERROR 4 +#define E_ERR_LIMITS_REACHED 5 typedef uint32_t e_err; diff --git a/include/ui.hpp b/include/ui.hpp index ad8a202..6ed2acb 100644 --- a/include/ui.hpp +++ b/include/ui.hpp @@ -52,6 +52,7 @@ namespace ui { extern ImFont* fontSmall; void set_state(main_state state); + void set_window_title(const char* title); void recreate_window_for_main_views(); diff --git a/src/administration_reader.cpp b/src/administration_reader.cpp index aadc853..268e984 100644 --- a/src/administration_reader.cpp +++ b/src/administration_reader.cpp @@ -19,6 +19,7 @@ #include #include +#include "ui.hpp" #include "logger.hpp" #include "strops.hpp" #include "memops.hpp" @@ -49,6 +50,8 @@ bool administration_reader::open_existing(char* file_path) if (!tinyfd_fileExists(file_path)) return false; + ui::set_window_title(file_path); + STOPWATCH_START; administration::create_from_file(file_path); diff --git a/src/locales/en.cpp b/src/locales/en.cpp index 673c3b7..2725df0 100644 --- a/src/locales/en.cpp +++ b/src/locales/en.cpp @@ -286,14 +286,14 @@ locale_entry en_locales[] = { { "country.ZW", "Zimbabwe" }, // Navigation. - {"nav.invoices", "Invoices"}, - {"nav.expenses", "Expenses"}, - {"nav.contacts", "Contacts"}, - {"nav.reports", "Reports"}, + {"nav.invoices", ICON_FA_FILE_ALT" Invoices"}, + {"nav.expenses", ICON_FA_INBOX " Expenses"}, + {"nav.contacts", ICON_FA_ADDRESS_BOOK" Contacts"}, + {"nav.reports", ICON_FA_CHART_BAR" Reports"}, {"nav.reports.results", "Earnings"}, {"nav.reports.tax", "Tax return"}, - {"nav.projects", "Projects"}, - {"nav.settings", "Settings"}, + {"nav.projects", ICON_FA_BRIEFCASE" Projects"}, + {"nav.settings", ICON_FA_COG" Settings"}, // Contact strings. {"contact.form.identifier", "Identifier"}, diff --git a/src/main_linux.cpp b/src/main_linux.cpp index 092fd80..2455c06 100644 --- a/src/main_linux.cpp +++ b/src/main_linux.cpp @@ -23,6 +23,7 @@ #include #include "ui.hpp" +#include "strops.hpp" #include "administration.hpp" #include "administration_writer.hpp" #include "administration_reader.hpp" @@ -48,6 +49,15 @@ static void glfw_error_callback(int error, const char* description) fprintf(stderr, "GLFW Error %d: %s\n", error, description); } +void ui::set_window_title(const char* filename) +{ + char final_title[256]; + if (filename) strops::format(final_title, 256, "OpenBooks (%s)", filename); + else strops::copy(final_title, "OpenBooks", 256); + + if (window) glfwSetWindowTitle(window, final_title); +} + static void _create_window(bool is_setup_window) { if (window) { @@ -71,12 +81,18 @@ static void _create_window(bool is_setup_window) } glfwWindowHint(GLFW_SAMPLES, 4); + + window = glfwCreateWindow(windowWidth, windowHeight, "OpenBooks", nullptr, nullptr); if (window == nullptr) return; glfwMakeContextCurrent(window); glfwSwapInterval(1); + if (!is_setup_window) { + ui::set_window_title(administration::get_file_path()); + } + IMGUI_CHECKVERSION(); ImGui::CreateContext(); ImGuiIO& io = ImGui::GetIO(); (void)io; diff --git a/src/providers/MailerSend.cpp b/src/providers/MailerSend.cpp index fe83aea..e219165 100644 --- a/src/providers/MailerSend.cpp +++ b/src/providers/MailerSend.cpp @@ -62,13 +62,21 @@ bool _MailerSend_send_email(const char* sender, const char* recipient, const cha if (!res) { logger::error("Failed to send email. Reason: Timeout"); - return E_ERR_FAILED_REQUEST; + return E_ERR_TIMEOUT; } if (res->status != 200 && res->status != 202) { int status = res->status; logger::error("Failed to send email. Status code: '%d'", status); - return E_ERR_FAILED_REQUEST; + logger::error(res->body.c_str()); + + switch(status) { + case 403: + case 401: return E_ERR_UNAUTHORIZED; + case 429: return E_ERR_LIMITS_REACHED; + case 500: return E_ERR_SERVER_ERROR; + default: return E_ERR_FAILED_REQUEST; + } } logger::info("Email sent."); diff --git a/src/ui/ui_main.cpp b/src/ui/ui_main.cpp index f20b9a8..e95b753 100644 --- a/src/ui/ui_main.cpp +++ b/src/ui/ui_main.cpp @@ -16,6 +16,7 @@ #include #include +#include #include "ui.hpp" #include "administration.hpp" @@ -110,7 +111,7 @@ void ui::draw_main() ImGuiIO& io = ImGui::GetIO(); float menuBarHeight = ImGui::GetFrameHeight(); - float statusBarHeight = 26.0f; + float statusBarHeight = 32.0f; float sidePanelWidth = 120.0f; ImGui::SetNextWindowPos(ImVec2(0, menuBarHeight)); ImGui::SetNextWindowSize(ImVec2(sidePanelWidth, io.DisplaySize.y - menuBarHeight - statusBarHeight)); @@ -125,7 +126,7 @@ void ui::draw_main() ImGui::PushStyleColor(ImGuiCol_Button, ImVec4(0.0f, 0.0f, 0.0f, 0.0f)); // Transparent background ImGui::PushStyleVar(ImGuiStyleVar_ButtonTextAlign, ImVec2(0.0f, 0.5f)); ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, ImVec2(0, 0)); // Reduce spacing between buttons - ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, ImVec2(10.0f, 0.0f)); + ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, ImVec2(10.0f, 4.0f)); float buttonWidth = sidePanelWidth; @@ -155,12 +156,10 @@ void ui::draw_main() ImGui::PopStyleVar(3); } ImGui::End(); - ImGui::PopStyleVar(); - ImGui::PopStyleVar(); - ImGui::PopStyleVar(); + ImGui::PopStyleVar(3); ImGui::SetNextWindowPos(ImVec2(sidePanelWidth, menuBarHeight)); - ImGui::SetNextWindowSize(ImVec2(io.DisplaySize.x - sidePanelWidth, io.DisplaySize.y - menuBarHeight - statusBarHeight)); + ImGui::SetNextWindowSize(ImVec2(io.DisplaySize.x - sidePanelWidth, io.DisplaySize.y - menuBarHeight)); // Main content ImGui::PushStyleColor(ImGuiCol_WindowBg, IM_COL32(255, 255, 255, 255)); @@ -171,7 +170,7 @@ void ui::draw_main() // Status bar. ImGui::SetNextWindowPos(ImVec2(0, io.DisplaySize.y - statusBarHeight)); - ImGui::SetNextWindowSize(ImVec2(io.DisplaySize.x, statusBarHeight)); + ImGui::SetNextWindowSize(ImVec2(sidePanelWidth, statusBarHeight)); ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(10, 3)); ImGui::Begin("StatusBar", nullptr, @@ -182,16 +181,8 @@ void ui::draw_main() ImGuiWindowFlags_NoSavedSettings | ImGuiWindowFlags_NoBringToFrontOnFocus | ImGuiWindowFlags_NoCollapse); - - const char* path = administration::get_file_path(); - if (path == NULL) { - ImGui::Text("%s: %s", locale::get("ui.workingOn"), locale::get("ui.unsavedProject")); - } - else { - ImGui::Text("%s: %s", locale::get("ui.workingOn"), path); - } - ImGui::SameLine(); + ImGui::Button(ICON_FA_BELL"##notifications"); ImGui::End(); ImGui::PopStyleVar(); -- cgit v1.2.3-70-g09d2