Transfer storage settings snapshots through the owned bridge API

This commit is contained in:
evgeny committed 2026-10-27 17:27:04 +01:00
1 parent aec4d5a6d6
commit 69efa5f11f
2 files changed
+18 -39

No files matched your search

+15 -35
View File
@@ -3,10 +3,7 @@
#include "../db/db_manager.h"
#include "../transport/gui_bridge.h"
#include "../transport/config_updater.h"
#include "../../lib/mem.h"
extern "C" {
#include "chat/chat_core.h"
}
#include "debug_config.h"
#include <QVBoxLayout>
#include <QFormLayout>
#include <QCheckBox>
@@ -14,31 +11,6 @@ extern "C" {
#include <QLabel>
#include <QFrame>
static void saveUiStateInt(const char* key, int val) {
QByteArray v = QByteArray::number(val);
size_t klen = strlen(key), vlen = (size_t)v.size(), total = klen + 1 + vlen + 1;
if (total > 256) return;
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, v.constData(), vlen + 1);
gui_bridge_post_uasync_fn(chat_core_save_ui_state_trampoline, arg);
}
void postChatSetting(const QString& configPath, const char* name, int val) {
config_update_option(configPath, "chatserver", name, QString::number(val), CONFIG_UPDATE_REPLACE);
QByteArray v = QByteArray::number(val);
size_t nlen = strlen(name), vlen = (size_t)v.size(), total = nlen + 1 + vlen + 1;
if (total > 256) return;
struct chat_setting_arg* arg = (struct chat_setting_arg*)u_malloc(sizeof(struct chat_setting_arg));
if (!arg) return;
arg->inst = gui_bridge_get_inst();
memcpy(arg->data, name, nlen + 1);
memcpy(arg->data + nlen + 1, v.constData(), vlen + 1);
gui_bridge_post_uasync_fn(chat_core_set_setting_trampoline, arg);
}
StorageSettingsPage::StorageSettingsPage(DbManager* db, QWidget* parent)
: QWidget(parent)
, m_db(db)
@@ -105,13 +77,21 @@ void StorageSettingsPage::applyAndSave() {
int autoloadMaxSize = m_autoloadMaxSize->value();
int maxGb = m_maxStorageSize->value();
saveUiStateInt("storage_autoload", autoload);
saveUiStateInt("storage_autoload_maxsize_mb", autoloadMaxSize);
saveUiStateInt("storage_maxsize_gb", maxGb);
for (const auto& setting : {QPair<const char*, int>{"storage_autoload", autoload},
{"storage_autoload_maxsize_mb", autoloadMaxSize}, {"storage_maxsize_gb", maxGb}})
gui_bridge_post_setting(GUI_SETTING_UI_STATE, setting.first, QByteArray::number(setting.second).constData());
if (!m_configPath.isEmpty()) {
postChatSetting(m_configPath, "storage_autoload", autoload);
config_update_option(m_configPath, "chatserver", "storage_unit_size", QString::number(autoloadMaxSize) + "M", CONFIG_UPDATE_REPLACE);
config_update_option(m_configPath, "chatserver", "storage_total_size", QString::number(maxGb) + "G", CONFIG_UPDATE_REPLACE);
for (const auto& setting : {QPair<const char*, QString>{"storage_autoload", QString::number(autoload)},
{"storage_unit_size", QString::number(autoloadMaxSize) + "M"},
{"storage_total_size", QString::number(maxGb) + "G"}}) {
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"))
gui_bridge_post_setting(GUI_SETTING_CHAT, setting.first, setting.second.toUtf8().constData());
}
}
DEBUG_DEBUG(DEBUG_CATEGORY_CONFIG, "Storage settings requested: autoload=%d file_limit=%dMB total_limit=%dGB",
autoload, autoloadMaxSize, maxGb);
}
+3 -4
View File
@@ -1,5 +1,6 @@
/* Настройки media-хранилища: автозагрузка, лимит файла и общий размер.
* applyAndSave сохраняет значения и передаёт их chat_setting через uasync. */
* GUI: loadFromDb читает черновик, applyAndSave передаёт снимки ui_state мосту и сохраняет INI.
* В ядре сразу применяется только autoload; лимиты размера в INI используются после перезапуска. */
#pragma once
#include <QWidget>
@@ -8,8 +9,6 @@ class DbManager;
class QCheckBox;
class QSpinBox;
void postChatSetting(const QString& configPath, const char* name, int val);
class StorageSettingsPage : public QWidget {
Q_OBJECT
public:
@@ -17,7 +16,7 @@ public:
void setConfigPath(const QString& path) { m_configPath = path; }
void loadFromDb();
void applyAndSave();
void applyAndSave(); // Асинхронные запросы принадлежат мосту, включая отмену; ошибки логируются, возврат не подтверждает запись.
private:
DbManager* m_db = nullptr;