diff options
| author | Aldrik Ramaekers <aldrikboy@gmail.com> | 2025-10-05 15:15:55 +0200 |
|---|---|---|
| committer | Aldrik Ramaekers <aldrikboy@gmail.com> | 2025-10-05 15:15:55 +0200 |
| commit | b278d242d03ba614779243ec9e9495fc95abea3d (patch) | |
| tree | 0d3cd94a3a059b0754c61da075c7dcecc081f358 /src/ui | |
| parent | 0a2b0e347d926ac0f29c9dd0f49e00634e822d0e (diff) | |
strops format
Diffstat (limited to 'src/ui')
| -rw-r--r-- | src/ui/imgui_extensions.cpp | 19 | ||||
| -rw-r--r-- | src/ui/ui_contacts.cpp | 9 | ||||
| -rw-r--r-- | src/ui/ui_earnings.cpp | 1 | ||||
| -rw-r--r-- | src/ui/ui_expenses.cpp | 6 | ||||
| -rw-r--r-- | src/ui/ui_invoices.cpp | 6 | ||||
| -rw-r--r-- | src/ui/ui_projects.cpp | 7 | ||||
| -rw-r--r-- | src/ui/ui_settings.cpp | 21 |
7 files changed, 32 insertions, 37 deletions
diff --git a/src/ui/imgui_extensions.cpp b/src/ui/imgui_extensions.cpp index 5a00648..4e8270a 100644 --- a/src/ui/imgui_extensions.cpp +++ b/src/ui/imgui_extensions.cpp @@ -1,4 +1,3 @@ -#include <stdio.h> #include <stdlib.h> #include "ui.hpp" @@ -93,7 +92,7 @@ namespace ImGui for (int x = 0; x < config::country_count; x++) { char locale_str[20]; - snprintf(locale_str, 20, "country.%s", config::country_codes[x]); + strops::format(locale_str, 20, "country.%s", config::country_codes[x]); countries[x] = locale::get(locale_str); } @@ -227,7 +226,7 @@ namespace ImGui for (int i = 0; i < autocomplete_count; i++) { autocomplete_strings[i] = (char*)malloc(200); - snprintf(autocomplete_strings[i], 200, "%s (%s %s)", autocomplete_list[i].name, autocomplete_list[i].address.address1, autocomplete_list[i].address.address2); + strops::format(autocomplete_strings[i], 200, "%s (%s %s)", autocomplete_list[i].name, autocomplete_list[i].address.address1, autocomplete_list[i].address.address2); } int autocomplete_index = ImGui::TextInputWithAutocomplete(locale::get("contact.form.fullname"), @@ -355,10 +354,10 @@ namespace ImGui { if (strcmp(selected_tax_rate->country_code, "00") == 0) { char category_code_desc[MAX_LEN_LONG_DESC]; - snprintf(category_code_desc, MAX_LEN_LONG_DESC, "taxcategory.%s", selected_tax_rate->category_code); - snprintf(rate_str_buf, 40, "%s", locale::get(category_code_desc)); + strops::format(category_code_desc, MAX_LEN_LONG_DESC, "taxcategory.%s", selected_tax_rate->category_code); + strops::format(rate_str_buf, 40, "%s", locale::get(category_code_desc)); } - else snprintf(rate_str_buf, 40, "%s/%.1f%%", selected_tax_rate->country_code, selected_tax_rate->rate); + else strops::format(rate_str_buf, 40, "%s/%.1f%%", selected_tax_rate->country_code, selected_tax_rate->rate); } if (has_error) { @@ -374,10 +373,10 @@ namespace ImGui if (strcmp(buffer[n].country_code, "00") == 0) { char category_code_desc[MAX_LEN_LONG_DESC]; - snprintf(category_code_desc, MAX_LEN_LONG_DESC, "taxcategory.%s", buffer[n].category_code); - snprintf(rate_str_buf, 40, "%s", locale::get(category_code_desc)); + strops::format(category_code_desc, MAX_LEN_LONG_DESC, "taxcategory.%s", buffer[n].category_code); + strops::format(rate_str_buf, 40, "%s", locale::get(category_code_desc)); } - else snprintf(rate_str_buf, 40, "%s/%.1f%%", buffer[n].country_code, buffer[n].rate); + else strops::format(rate_str_buf, 40, "%s/%.1f%%", buffer[n].country_code, buffer[n].rate); if (ImGui::Selectable(rate_str_buf, is_selected)) { selected_tax_rate_index = n; @@ -458,7 +457,7 @@ namespace ImGui const char* items[] = { option1, option2 }; char ID[MAX_LEN_LONG_DESC]; - snprintf(ID, MAX_LEN_LONG_DESC, "Mode##%p", buffer); + strops::format(ID, MAX_LEN_LONG_DESC, "Mode##%p", buffer); if (ImGui::BeginCombo(ID, items[*buffer])) { for (int n = 0; n < 2; n++) { bool is_selected = (n == (int)*buffer); diff --git a/src/ui/ui_contacts.cpp b/src/ui/ui_contacts.cpp index 03fcee0..7d585c9 100644 --- a/src/ui/ui_contacts.cpp +++ b/src/ui/ui_contacts.cpp @@ -14,9 +14,6 @@ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -#include <stdio.h> -#include <stdlib.h> - #include "strops.hpp" #include "config.hpp" #include "ui.hpp" @@ -163,7 +160,7 @@ static void draw_contact_list() ImGui::TableSetColumnIndex(3); char btn_name[20]; - snprintf(btn_name, sizeof(btn_name), "%s##%d", locale::get("form.view"), i); + strops::format(btn_name, sizeof(btn_name), "%s##%d", locale::get("form.view"), i); if (ImGui::Button(btn_name)) { active_contact = c; current_view_state = ui::view_state::VIEW_EXISTING; @@ -171,14 +168,14 @@ static void draw_contact_list() ImGui::SameLine(); - snprintf(btn_name, sizeof(btn_name), "%s##%d", locale::get("form.change"), i); + strops::format(btn_name, sizeof(btn_name), "%s##%d", locale::get("form.change"), i); if (ImGui::Button(btn_name)) { active_contact = c; current_view_state = ui::view_state::EDIT_EXISTING; } ImGui::SameLine(); - snprintf(btn_name, sizeof(btn_name), "%s##%d", locale::get("form.delete"), i); + strops::format(btn_name, sizeof(btn_name), "%s##%d", locale::get("form.delete"), i); if (ImGui::Button(btn_name)) { selected_for_removal = c; ImGui::OpenPopup("ConfirmDeletePopup"); diff --git a/src/ui/ui_earnings.cpp b/src/ui/ui_earnings.cpp index 5e04a61..1ceabbe 100644 --- a/src/ui/ui_earnings.cpp +++ b/src/ui/ui_earnings.cpp @@ -14,7 +14,6 @@ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -#include <stdio.h> #include <stdlib.h> #include "ui.hpp" diff --git a/src/ui/ui_expenses.cpp b/src/ui/ui_expenses.cpp index e4441ef..8812273 100644 --- a/src/ui/ui_expenses.cpp +++ b/src/ui/ui_expenses.cpp @@ -244,7 +244,7 @@ static void draw_expenses_list() ImGui::TableSetColumnIndex(6); char btn_name[20]; - snprintf(btn_name, sizeof(btn_name), "%s##%d", locale::get("form.view"), i); + strops::format(btn_name, sizeof(btn_name), "%s##%d", locale::get("form.view"), i); if (ImGui::Button(btn_name)) { active_invoice = c; current_view_state = ui::view_state::VIEW_EXISTING; @@ -252,14 +252,14 @@ static void draw_expenses_list() ImGui::SameLine(); - snprintf(btn_name, sizeof(btn_name), "%s##%d", locale::get("form.change"), i); + strops::format(btn_name, sizeof(btn_name), "%s##%d", locale::get("form.change"), i); if (ImGui::Button(btn_name)) { active_invoice = administration::invoice_create_copy(&c); // We create a copy because of billing item list pointers. current_view_state = ui::view_state::EDIT_EXISTING; } ImGui::SameLine(); - snprintf(btn_name, sizeof(btn_name), "%s##%d", locale::get("form.delete"), i); + strops::format(btn_name, sizeof(btn_name), "%s##%d", locale::get("form.delete"), i); if (ImGui::Button(btn_name)) { selected_for_removal = c; ImGui::OpenPopup("ConfirmDeletePopup"); diff --git a/src/ui/ui_invoices.cpp b/src/ui/ui_invoices.cpp index 191cd7d..4dd44e8 100644 --- a/src/ui/ui_invoices.cpp +++ b/src/ui/ui_invoices.cpp @@ -341,7 +341,7 @@ static void draw_invoices_list() ImGui::TableSetColumnIndex(6); char btn_name[20]; - snprintf(btn_name, sizeof(btn_name), "%s##%d", locale::get("form.view"), i); + strops::format(btn_name, sizeof(btn_name), "%s##%d", locale::get("form.view"), i); if (ImGui::Button(btn_name)) { active_invoice = c; current_view_state = ui::view_state::VIEW_EXISTING; @@ -351,14 +351,14 @@ static void draw_invoices_list() if (c.status == invoice_status::INVOICE_CONCEPT) { - snprintf(btn_name, sizeof(btn_name), "%s##%d", locale::get("form.change"), i); + strops::format(btn_name, sizeof(btn_name), "%s##%d", locale::get("form.change"), i); if (ImGui::Button(btn_name)) { active_invoice = administration::invoice_create_copy(&c); // We create a copy because of billing item list pointers. current_view_state = ui::view_state::EDIT_EXISTING; } ImGui::SameLine(); - snprintf(btn_name, sizeof(btn_name), "%s##%d", locale::get("form.delete"), i); + strops::format(btn_name, sizeof(btn_name), "%s##%d", locale::get("form.delete"), i); if (ImGui::Button(btn_name)) { selected_for_removal = c; ImGui::OpenPopup("ConfirmDeletePopup"); diff --git a/src/ui/ui_projects.cpp b/src/ui/ui_projects.cpp index f9f494d..66cc336 100644 --- a/src/ui/ui_projects.cpp +++ b/src/ui/ui_projects.cpp @@ -21,6 +21,7 @@ #include "administration.hpp" #include "administration_writer.hpp" #include "locales.hpp" +#include "strops.hpp" static ui::view_state current_view_state = ui::view_state::LIST_ALL; static project selected_for_cancellation; @@ -139,7 +140,7 @@ static void draw_project_list() ImGui::TableSetColumnIndex(3); char btn_name[20]; - snprintf(btn_name, sizeof(btn_name), "%s##%d", locale::get("form.view"), i); + strops::format(btn_name, sizeof(btn_name), "%s##%d", locale::get("form.view"), i); if (ImGui::Button(btn_name)) { active_project = c; current_view_state = ui::view_state::VIEW_EXISTING; @@ -148,14 +149,14 @@ static void draw_project_list() if (c.state == project_state::PROJECT_RUNNING) { ImGui::SameLine(); - snprintf(btn_name, sizeof(btn_name), "%s##%d", locale::get("form.change"), i); + strops::format(btn_name, sizeof(btn_name), "%s##%d", locale::get("form.change"), i); if (ImGui::Button(btn_name)) { active_project = c; current_view_state = ui::view_state::EDIT_EXISTING; } ImGui::SameLine(); - snprintf(btn_name, sizeof(btn_name), "%s##%d", locale::get("form.cancel"), i); + strops::format(btn_name, sizeof(btn_name), "%s##%d", locale::get("form.cancel"), i); if (ImGui::Button(btn_name)) { selected_for_cancellation = c; ImGui::OpenPopup("ConfirmCancelProject"); diff --git a/src/ui/ui_settings.cpp b/src/ui/ui_settings.cpp index cb6cdf5..8177f07 100644 --- a/src/ui/ui_settings.cpp +++ b/src/ui/ui_settings.cpp @@ -15,13 +15,13 @@ */ #include <stdlib.h> -#include <stdio.h> #include "strops.hpp" #include "ui.hpp" #include "imgui.h" #include "administration.hpp" #include "locales.hpp" +#include "importer.hpp" #include "administration_writer.hpp" extern void draw_contact_form(contact* buffer, bool viewing_only = false); @@ -103,7 +103,7 @@ static void draw_vat_rates() ImGui::TableNextRow(); char locale_buf[20]; - snprintf(locale_buf, sizeof(locale_buf), "country.%s", c.country_code); + strops::format(locale_buf, sizeof(locale_buf), "country.%s", c.country_code); ImGui::TableSetColumnIndex(0); ImGui::Text(locale::get(locale_buf)); @@ -112,7 +112,7 @@ static void draw_vat_rates() { ImGui::SameLine(); char btn_name[20]; - snprintf(btn_name, sizeof(btn_name), "+##%d",i); + strops::format(btn_name, sizeof(btn_name), "+##%d",i); ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, ImVec2(0,0)); if (ImGui::Button(btn_name, ImVec2(20,20))) { is_adding_item = true; @@ -131,7 +131,7 @@ static void draw_vat_rates() ImGui::TableSetColumnIndex(0); char category_code_desc[MAX_LEN_LONG_DESC]; - snprintf(category_code_desc, MAX_LEN_LONG_DESC, "taxcategory.%s", c.category_code); + strops::format(category_code_desc, MAX_LEN_LONG_DESC, "taxcategory.%s", c.category_code); ImGui::Text(can_be_modified ? "" : locale::get(category_code_desc)); @@ -338,18 +338,17 @@ static void draw_services() // AI service if (ImGui::CollapsingHeader(locale::get("settings.services.ai_service"))) { - // TODO: get this from iterator over ai_get_impl - char* services[2] = { - "OpenAI", - "DeepSeek", - }; + char* ai_service_names[AI_PROVIDER_END]; + for (u32 i = 0; i < AI_PROVIDER_END; i++) { + ai_service_names[i] = importer::get_ai_provider_implementation((ai_provider)i).provider_name; + } - if (ImGui::BeginCombo(locale::get("settings.services.ai_service.provider"), services[new_service.provider])) + if (ImGui::BeginCombo(locale::get("settings.services.ai_service.provider"), ai_service_names[new_service.provider])) { for (u32 n = 0; n < 2; n++) { bool is_selected = n == (uint32_t)new_service.provider; - if (ImGui::Selectable(services[n], is_selected)) { + if (ImGui::Selectable(ai_service_names[n], is_selected)) { new_service.provider = (ai_provider)n; } } |
