Eliminate borrowed save commands from the desktop settings dialog
This commit is contained in:
1 parent
4d3b294ee9
commit
e3b0eebc2b
2 files changed
+23
-99
No files matched your search
@@ -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 <QVBoxLayout>
|
||||
@@ -355,13 +353,7 @@ void SettingsDialog::onSave() {
|
||||
return;
|
||||
}
|
||||
if (gui_bridge_is_uasync_ready() && gui_bridge_get_inst()) {
|
||||
auto* arg = static_cast<chat_setting_arg*>(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<chat_setting_arg*>(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<const char*, bool>{"local_invites_enabled", m_networkPage->localInvitesEnabled()},
|
||||
QPair<const char*, bool>{"local_broadcasts_enabled", m_networkPage->localBroadcastsEnabled()}}) {
|
||||
if (!gui_bridge_is_uasync_ready() || !gui_bridge_get_inst()) continue;
|
||||
auto* arg = static_cast<chat_setting_arg*>(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<const char*, int> 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)) {
|
||||
|
||||
Reference in new issue
Block a user