summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAldrik Ramaekers <aldrik@mailbox.org>2026-01-08 17:40:15 +0100
committerAldrik Ramaekers <aldrik@mailbox.org>2026-01-08 17:40:15 +0100
commit0d70098dd5b704f2953c63f0c827b46b11935b81 (patch)
tree05efcc8cfac52672b147c2a32a66f87a05f881e7
parent9b87e0d3123bbc533c2e4d452b16fe82de0e5cd4 (diff)
setup window
-rw-r--r--TODO1
-rw-r--r--include/ui.hpp6
-rw-r--r--libs/tinyfiledialogs/tinyfiledialogs.c9
-rw-r--r--libs/tinyfiledialogs/tinyfiledialogs.h2
-rw-r--r--src/administration_reader.cpp2
-rw-r--r--src/main_linux.cpp69
-rw-r--r--src/ui/ui_main.cpp16
-rw-r--r--src/ui/ui_setup.cpp41
8 files changed, 130 insertions, 16 deletions
diff --git a/TODO b/TODO
index d2f301d..f24b3c8 100644
--- a/TODO
+++ b/TODO
@@ -3,6 +3,7 @@ TODO:
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
Refactor:
- Refactor zip writing to be faster (Windows is slow)
diff --git a/include/ui.hpp b/include/ui.hpp
index 9649eb8..8648518 100644
--- a/include/ui.hpp
+++ b/include/ui.hpp
@@ -34,6 +34,7 @@ namespace ui {
UI_PROJECTS = 5,
UI_SETTINGS = 6,
UI_LOG = 7,
+ UI_SETUP = 8,
UI_END
} main_state;
@@ -51,6 +52,8 @@ namespace ui {
extern ImFont* fontBig;
void set_state(main_state state);
+
+ void recreate_window_for_main_views();
// Draw calls.
void draw_main();
@@ -62,6 +65,7 @@ namespace ui {
void draw_earnings();
void draw_log();
void draw_tax_report();
+ void draw_setup();
// Setup calls.
void setup_invoices();
@@ -71,6 +75,7 @@ namespace ui {
void setup_expenses();
void setup_earnings();
void setup_tax_report();
+ void setup_setup();
// Destroy calls.
void destroy_invoices();
@@ -78,6 +83,7 @@ namespace ui {
void destroy_expenses();
void destroy_earnings();
void destroy_tax_report();
+ void destroy_setup();
}
diff --git a/libs/tinyfiledialogs/tinyfiledialogs.c b/libs/tinyfiledialogs/tinyfiledialogs.c
index 1b07cf7..b99080e 100644
--- a/libs/tinyfiledialogs/tinyfiledialogs.c
+++ b/libs/tinyfiledialogs/tinyfiledialogs.c
@@ -1740,7 +1740,6 @@ wchar_t * tinyfd_saveFileDialogW(
return lRetval;
}
-
wchar_t * tinyfd_openFileDialogW(
wchar_t const * aTitle, /* NULL or "" */
wchar_t const * aDefaultPathAndOrFile, /* NULL or "" */
@@ -3205,6 +3204,10 @@ char * tinyfd_saveFileDialog(
return p ;
}
+int tinyfd_fileExists(char const * aFilePathAndName)
+{
+ return fileExists(aFilePathAndName);
+}
/* in case of multiple files, the separator is | */
char * tinyfd_openFileDialog(
@@ -6718,6 +6721,10 @@ char * tinyfd_saveFileDialog(
return lBuff ;
}
+int tinyfd_fileExists(char const * aFilePathAndName)
+{
+ return fileExists(aFilePathAndName);
+}
/* in case of multiple files, the separator is | */
char * tinyfd_openFileDialog(
diff --git a/libs/tinyfiledialogs/tinyfiledialogs.h b/libs/tinyfiledialogs/tinyfiledialogs.h
index f9b19f6..da3ddf6 100644
--- a/libs/tinyfiledialogs/tinyfiledialogs.h
+++ b/libs/tinyfiledialogs/tinyfiledialogs.h
@@ -131,6 +131,8 @@ for console mode:
void tinyfd_beep(void);
+int tinyfd_fileExists(char const * aFilePathAndName);
+
int tinyfd_notifyPopup(
char const * aTitle, /* NULL or "" */
char const * aMessage, /* NULL or "" may contain \n \t */
diff --git a/src/administration_reader.cpp b/src/administration_reader.cpp
index 2c94028..a5f2449 100644
--- a/src/administration_reader.cpp
+++ b/src/administration_reader.cpp
@@ -47,6 +47,8 @@ bool administration_reader::open_existing(char* file_path)
if (!file_path) return false;
}
+ if (!tinyfd_fileExists(file_path)) return false;
+
STOPWATCH_START;
administration::create_from_file(file_path);
diff --git a/src/main_linux.cpp b/src/main_linux.cpp
index 1d05aff..e605659 100644
--- a/src/main_linux.cpp
+++ b/src/main_linux.cpp
@@ -33,27 +33,47 @@
#pragma comment(lib, "legacy_stdio_definitions")
#endif
+static GLFWwindow* window = 0;
+static bool redo_window = 0;
+
+void ui::recreate_window_for_main_views()
+{
+ redo_window = 1;
+}
+
static void glfw_error_callback(int error, const char* description)
{
fprintf(stderr, "GLFW Error %d: %s\n", error, description);
}
-// Main code
-int main(int argc, char** argv)
+static void _create_window(bool is_setup_window)
{
- glfwSetErrorCallback(glfw_error_callback);
- if (!glfwInit())
- return 1;
+ if (window) {
+ ImGui_ImplOpenGL2_Shutdown();
+ ImGui_ImplGlfw_Shutdown();
+ ImGui::DestroyContext();
+ glfwDestroyWindow(window);
+ }
- // Create window with graphics context
float main_scale = ImGui_ImplGlfw_GetContentScaleForMonitor(glfwGetPrimaryMonitor()); // Valid on GLFW 3.3+ only
- GLFWwindow* window = glfwCreateWindow((int)(1280 * main_scale), (int)(800 * main_scale), "OpenBooks", nullptr, nullptr);
+ int windowWidth = (int)(1280 * main_scale);
+ int windowHeight = (int)(800 * main_scale);
+
+ if (is_setup_window) {
+ glfwWindowHint(GLFW_RESIZABLE, false);
+ windowWidth = (int)(800 * main_scale);
+ windowHeight = (int)(500 * main_scale);
+ }
+ else {
+ glfwWindowHint(GLFW_RESIZABLE, true);
+ }
+
+ window = glfwCreateWindow(windowWidth, windowHeight, "OpenBooks", nullptr, nullptr);
if (window == nullptr)
- return 1;
+ return;
glfwMakeContextCurrent(window);
glfwSwapInterval(1); // Enable vsync
- // Setup Dear ImGui context
IMGUI_CHECKVERSION();
ImGui::CreateContext();
ImGuiIO& io = ImGui::GetIO(); (void)io;
@@ -77,19 +97,35 @@ int main(int argc, char** argv)
io.Fonts->AddFontFromFileTTF("/home/aldrik/Projects/open-books/build/Roboto-Regular.ttf");
ui::fontBold = io.Fonts->AddFontFromFileTTF("/home/aldrik/Projects/open-books/build/Roboto-Bold.ttf");
ui::fontBig = io.Fonts->AddFontFromFileTTF("/home/aldrik/Projects/open-books/build/Roboto-Bold.ttf", 30);
-
- ImVec4 clear_color = ImVec4(0.45f, 0.55f, 0.60f, 1.00f);
+}
- timer_lib_initialize();
- administration_writer::create();
+// Main code
+int main(int argc, char** argv)
+{
+ glfwSetErrorCallback(glfw_error_callback);
+ if (!glfwInit())
+ return 1;
if (argc < 2) {
administration::create_default("");
+ _create_window(true);
}
else {
- administration_reader::open_existing(argv[1]);
+ if (administration_reader::open_existing(argv[1])) {
+ _create_window(false);
+ ui::set_state(ui::main_state::UI_INVOICES);
+ }
+ else {
+ _create_window(true);
+ }
}
+
+ ImVec4 clear_color = ImVec4(0.45f, 0.55f, 0.60f, 1.00f);
+
+ timer_lib_initialize();
+ administration_writer::create();
+
while (!glfwWindowShouldClose(window))
{
glfwPollEvents();
@@ -118,6 +154,11 @@ int main(int argc, char** argv)
glfwMakeContextCurrent(window);
glfwSwapBuffers(window);
+
+ if (redo_window) {
+ _create_window(false);
+ redo_window = 0;
+ }
}
administration_writer::save_activities_blocking();
diff --git a/src/ui/ui_main.cpp b/src/ui/ui_main.cpp
index dde0882..0aad2ec 100644
--- a/src/ui/ui_main.cpp
+++ b/src/ui/ui_main.cpp
@@ -32,6 +32,7 @@ void (*drawcalls[ui::main_state::UI_END])(void) = {
ui::draw_projects,
ui::draw_settings,
ui::draw_log,
+ ui::draw_setup,
};
void (*setupcalls[ui::main_state::UI_END])(void) = {
@@ -43,6 +44,7 @@ void (*setupcalls[ui::main_state::UI_END])(void) = {
ui::setup_projects,
ui::setup_settings,
0,
+ ui::setup_setup,
};
void (*destroycalls[ui::main_state::UI_END])(void) = {
@@ -54,6 +56,7 @@ void (*destroycalls[ui::main_state::UI_END])(void) = {
0,
ui::destroy_settings,
0,
+ ui::destroy_setup,
};
void ui::set_state(ui::main_state state)
@@ -65,7 +68,18 @@ void ui::set_state(ui::main_state state)
void ui::draw_main()
{
- if (ui_state == ui::main_state::UI_END) ui::set_state(ui::main_state::UI_INVOICES);
+ if (ui_state == ui::main_state::UI_END) ui::set_state(ui::main_state::UI_SETUP);
+
+ if (ui_state == ui::main_state::UI_SETUP) {
+ ImGuiIO& io = ImGui::GetIO();
+ ImGui::SetNextWindowPos(ImVec2(0, 0));
+ ImGui::SetNextWindowSize(ImVec2(io.DisplaySize.x, io.DisplaySize.y));
+
+ ImGui::Begin("AccountingMainWindow", nullptr, ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoCollapse);
+ if (drawcalls[ui_state]) drawcalls[ui_state]();
+ ImGui::End();
+ return;
+ }
if (ImGui::BeginMainMenuBar())
{
diff --git a/src/ui/ui_setup.cpp b/src/ui/ui_setup.cpp
new file mode 100644
index 0000000..4f4a120
--- /dev/null
+++ b/src/ui/ui_setup.cpp
@@ -0,0 +1,41 @@
+/*
+* Copyright (c) 2025 Aldrik Ramaekers <aldrik.ramaekers@gmail.com>
+*
+* Permission to use, copy, modify, and/or distribute this software for any
+* purpose with or without fee is hereby granted, provided that the above
+* copyright notice and this permission notice appear in all copies.
+*
+* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+*/
+
+#include "ui.hpp"
+#include "imgui.h"
+#include "locales.hpp"
+#include "administration_writer.hpp"
+#include "administration_reader.hpp"
+
+void ui::draw_setup()
+{
+ if (ImGui::Button("Load administration")) {
+ if (administration_reader::open_existing(NULL)) {
+ ui::set_state(ui::main_state::UI_SETTINGS);
+ ui::recreate_window_for_main_views();
+ }
+ }
+}
+
+void ui::setup_setup()
+{
+
+}
+
+void ui::destroy_setup()
+{
+
+} \ No newline at end of file