diff --git a/tools/chatgui/src/settingsdialog.cpp b/tools/chatgui/src/settingsdialog.cpp index 8a2c9873..f2d966dc 100644 --- a/tools/chatgui/src/settingsdialog.cpp +++ b/tools/chatgui/src/settingsdialog.cpp @@ -14,14 +14,12 @@ #include "ptt_hotkey_manager.h" #include "connmonitorwindow.h" #include "../transport/gui_bridge.h" -#include "../../lib/mem.h" #include "../db/db_manager.h" #include "../transport/utun_node.h" #include "../transport/node_config.h" #include "../transport/config_updater.h" #include "../../lib/debug_config.h" extern "C" { -#include "chat/chat_core.h" #include "call/call.h" } #include @@ -355,13 +353,7 @@ void SettingsDialog::onSave() { return; } if (gui_bridge_is_uasync_ready() && gui_bridge_get_inst()) { - auto* arg = static_cast(u_calloc(1, sizeof(chat_setting_arg))); - if (!arg) { DEBUG_ERROR(DEBUG_CATEGORY_CALL, "Call status: request allocation failed"); return; } - arg->inst = gui_bridge_get_inst(); - const char* key = "incoming_call_policy"; - memcpy(arg->data, key, strlen(key) + 1); - snprintf(arg->data + strlen(key) + 1, sizeof(arg->data) - strlen(key) - 1, "%d", callPolicy); - gui_bridge_post_uasync_fn(chat_core_set_setting_trampoline, arg); + gui_bridge_post_setting(GUI_SETTING_CHAT, "incoming_call_policy", QByteArray::number(callPolicy).constData()); } else DEBUG_WARN(DEBUG_CATEGORY_CALL, "Call status: core unavailable; saved policy=%d applies at startup", callPolicy); DEBUG_INFO(DEBUG_CATEGORY_CALL, "Call status: sharing=%d policy=%d saved", m_publishCallStatus->isChecked(), callPolicy); @@ -370,12 +362,7 @@ void SettingsDialog::onSave() { /* update name in uTun if changed */ if (nameChanged) { - struct update_my_name_arg* arg = (struct update_my_name_arg*)u_calloc(1, sizeof(*arg)); - if (arg) { - arg->inst = gui_bridge_get_inst(); - snprintf(arg->name, sizeof(arg->name), "%s", newName.toUtf8().constData()); - gui_bridge_post_uasync_fn(chat_core_update_my_name_trampoline, arg); - } + gui_bridge_update_name(newName.toUtf8().constData()); m_oldNickname = newName; } @@ -423,16 +410,7 @@ void SettingsDialog::onSave() { QCoreApplication::translate("ChatGui", "Failed to save broadcast settings. Check the configuration file.")); return; } - auto* arg = static_cast(u_calloc(1, sizeof(chat_setting_arg))); - if (!arg) { - DEBUG_ERROR(DEBUG_CATEGORY_CONFIG, "Broadcast settings: request allocation failed"); - return; - } - arg->inst = gui_bridge_get_inst(); - const size_t keyLength = strlen(setting.first) + 1; - memcpy(arg->data, setting.first, keyLength); - snprintf(arg->data + keyLength, sizeof(arg->data) - keyLength, "%d", setting.second); - gui_bridge_post_uasync_fn(chat_core_set_setting_trampoline, arg); + gui_bridge_post_setting(GUI_SETTING_CHAT, setting.first, QByteArray::number(setting.second).constData()); } DEBUG_INFO(DEBUG_CATEGORY_CONFIG, "Broadcast settings saved n=%d r=%d; apply on next start", m_streamSubblocks->value(), m_streamRedundant->value()); @@ -443,30 +421,11 @@ void SettingsDialog::onSave() { for (const auto& setting : {QPair{"local_invites_enabled", m_networkPage->localInvitesEnabled()}, QPair{"local_broadcasts_enabled", m_networkPage->localBroadcastsEnabled()}}) { if (!gui_bridge_is_uasync_ready() || !gui_bridge_get_inst()) continue; - auto* arg = static_cast(u_calloc(1, sizeof(chat_setting_arg))); - if (!arg) { DEBUG_ERROR(DEBUG_CATEGORY_DISCOVERY, "LAN settings: request allocation failed"); return; } - arg->inst = gui_bridge_get_inst(); - size_t length = strlen(setting.first) + 1; - memcpy(arg->data, setting.first, length); - snprintf(arg->data + length, sizeof(arg->data) - length, "%d", setting.second ? 1 : 0); - gui_bridge_post_uasync_fn(chat_core_set_setting_trampoline, arg); + gui_bridge_post_setting(GUI_SETTING_CHAT, setting.first, setting.second ? "1" : "0"); } /* save channel sort preference to ui_state */ - { - const char* key = "channel_sort"; - QByteArray val = QByteArray::number(m_sortCombo->currentIndex()); - size_t klen = strlen(key), vlen = (size_t)val.size(); - size_t total = klen + 1 + vlen + 1; - if (total <= 256) { - struct save_ui_state_arg* arg = (struct save_ui_state_arg*)u_malloc(sizeof(struct save_ui_state_arg)); - if (!arg) return; - arg->inst = gui_bridge_get_inst(); - memcpy(arg->data, key, klen + 1); - memcpy(arg->data + klen + 1, val.constData(), vlen + 1); - gui_bridge_post_uasync_fn(chat_core_save_ui_state_trampoline, arg); - } - } + gui_bridge_post_setting(GUI_SETTING_UI_STATE, "channel_sort", QByteArray::number(m_sortCombo->currentIndex()).constData()); m_soundPage->applyAndSave(); m_audioDevicePage->applyAndSave(); @@ -481,56 +440,19 @@ void SettingsDialog::onSave() { /* Физические сочетания сохраняем в БД; Wayland-хоткеями владеет системный портал. */ if (!PttHotkeyManager::usesPortal()) { - const char* key = "radio_ptt_hotkeys"; - QByteArray val = m_radioPage->hotkeys().join('|').toUtf8(); - size_t klen = strlen(key), vlen = (size_t)val.size(); - size_t total = klen + 1 + vlen + 1; - if (total <= 256) { - struct save_ui_state_arg* arg = (struct save_ui_state_arg*)u_malloc(sizeof(struct save_ui_state_arg)); - if (!arg) return; - arg->inst = gui_bridge_get_inst(); - memcpy(arg->data, key, klen + 1); - memcpy(arg->data + klen + 1, val.constData(), vlen + 1); - gui_bridge_post_uasync_fn(chat_core_save_ui_state_trampoline, arg); - } + gui_bridge_post_setting(GUI_SETTING_UI_STATE, "radio_ptt_hotkeys", m_radioPage->hotkeys().join('|').toUtf8().constData()); } - /* save join_policy */ - { - const char* key = "join_policy"; - int v = m_joinPolicyCombo->currentIndex(); - QByteArray val = QByteArray::number(v); - size_t klen = strlen(key), vl = (size_t)val.size(), total = klen + 1 + vl + 1; - if (total <= 256) { - struct save_ui_state_arg* arg = (struct save_ui_state_arg*)u_malloc(sizeof(struct save_ui_state_arg)); - if (!arg) return; - arg->inst = gui_bridge_get_inst(); - memcpy(arg->data, key, klen + 1); - memcpy(arg->data + klen + 1, val.constData(), vl + 1); - gui_bridge_post_uasync_fn(chat_core_save_ui_state_trampoline, arg); - } - if (!m_configPath.isEmpty()) { - postChatSetting(m_configPath, "join_policy", v); - } - } - - /* save group_autoconnect */ - { - const char* key = "group_autoconnect"; - int v = m_autoConnectCheck->isChecked() ? 1 : 0; - QByteArray val = QByteArray::number(v); - size_t klen = strlen(key), vl = (size_t)val.size(), total = klen + 1 + vl + 1; - if (total <= 256) { - struct save_ui_state_arg* arg = (struct save_ui_state_arg*)u_malloc(sizeof(struct save_ui_state_arg)); - if (!arg) return; - arg->inst = gui_bridge_get_inst(); - memcpy(arg->data, key, klen + 1); - memcpy(arg->data + klen + 1, val.constData(), vl + 1); - gui_bridge_post_uasync_fn(chat_core_save_ui_state_trampoline, arg); - } - if (!m_configPath.isEmpty()) { - postChatSetting(m_configPath, "group_autoconnect", v); + const QPair policies[] = {{"join_policy", m_joinPolicyCombo->currentIndex()}, + {"group_autoconnect", m_autoConnectCheck->isChecked() ? 1 : 0}}; + for (const auto& setting : policies) { + const QByteArray value = QByteArray::number(setting.second); + gui_bridge_post_setting(GUI_SETTING_UI_STATE, setting.first, value.constData()); + if (m_configPath.isEmpty()) continue; + if (!config_update_option(m_configPath, "chatserver", setting.first, QString::fromLatin1(value))) { + DEBUG_ERROR(DEBUG_CATEGORY_CONFIG, "Settings: config save failed key=%s", setting.first); continue; } + gui_bridge_post_setting(GUI_SETTING_CHAT, setting.first, value.constData()); } const QString language = m_languageCombo->currentData().toString(); if (!config_update_option(m_configPath, "gui", "language", language)) { diff --git a/tools/chatgui/src/storagesettingspage.cpp b/tools/chatgui/src/storagesettingspage.cpp index ec1f9f2a..3bfe335b 100644 --- a/tools/chatgui/src/storagesettingspage.cpp +++ b/tools/chatgui/src/storagesettingspage.cpp @@ -10,6 +10,7 @@ #include #include #include +#include StorageSettingsPage::StorageSettingsPage(DbManager* db, QWidget* parent) : QWidget(parent) @@ -77,18 +78,19 @@ void StorageSettingsPage::applyAndSave() { int autoloadMaxSize = m_autoloadMaxSize->value(); int maxGb = m_maxStorageSize->value(); - for (const auto& setting : {QPair{"storage_autoload", autoload}, - {"storage_autoload_maxsize_mb", autoloadMaxSize}, {"storage_maxsize_gb", maxGb}}) + const QPair uiSettings[] = {{"storage_autoload", autoload}, + {"storage_autoload_maxsize_mb", autoloadMaxSize}, {"storage_maxsize_gb", maxGb}}; + for (const auto& setting : uiSettings) gui_bridge_post_setting(GUI_SETTING_UI_STATE, setting.first, QByteArray::number(setting.second).constData()); if (!m_configPath.isEmpty()) { - for (const auto& setting : {QPair{"storage_autoload", QString::number(autoload)}, - {"storage_unit_size", QString::number(autoloadMaxSize) + "M"}, - {"storage_total_size", QString::number(maxGb) + "G"}}) { + const QPair configSettings[] = {{"storage_autoload", QString::number(autoload)}, + {"storage_unit_size", QString::number(autoloadMaxSize) + "M"}, {"storage_total_size", QString::number(maxGb) + "G"}}; + for (const auto& setting : configSettings) { if (!config_update_option(m_configPath, "chatserver", setting.first, setting.second)) { DEBUG_ERROR(DEBUG_CATEGORY_CONFIG, "Storage settings: config save failed key=%s", setting.first); continue; } - if (!strcmp(setting.first, "storage_autoload")) + if (!std::strcmp(setting.first, "storage_autoload")) gui_bridge_post_setting(GUI_SETTING_CHAT, setting.first, setting.second.toUtf8().constData()); } }