From e37661d53a0249548238a89d41736260998348f6 Mon Sep 17 00:00:00 2001 From: brvphoenix <30111323+brvphoenix@users.noreply.github.com> Date: Sat, 11 Feb 2023 01:12:22 +0800 Subject: [PATCH] WebUI: Add filelog settings PR #18506. Closes #17421. --- src/webui/api/appcontroller.cpp | 77 ++++++++---- src/webui/webapplication.h | 2 +- src/webui/www/private/views/preferences.html | 117 +++++++++++++++--- .../www/private/views/preferencesToolbar.html | 7 +- 4 files changed, 162 insertions(+), 41 deletions(-) diff --git a/src/webui/api/appcontroller.cpp b/src/webui/api/appcontroller.cpp index d0097dd61..99533388b 100644 --- a/src/webui/api/appcontroller.cpp +++ b/src/webui/api/appcontroller.cpp @@ -107,6 +107,19 @@ void AppController::preferencesAction() QJsonObject data; + // Behavior + // Language + data[u"locale"_qs] = pref->getLocale(); + data[u"performance_warning"_qs] = session->isPerformanceWarningEnabled(); + // Log file + data[u"file_log_enabled"_qs] = app()->isFileLoggerEnabled(); + data[u"file_log_path"_qs] = app()->fileLoggerPath().toString(); + data[u"file_log_backup_enabled"_qs] = app()->isFileLoggerBackup(); + data[u"file_log_max_size"_qs] = app()->fileLoggerMaxSize() / 1024; + data[u"file_log_delete_old"_qs] = app()->isFileLoggerDeleteOld(); + data[u"file_log_age"_qs] = app()->fileLoggerAge(); + data[u"file_log_age_type"_qs] = app()->fileLoggerAgeType(); + // Downloads // When adding a torrent data[u"torrent_content_layout"_qs] = Utils::String::fromEnum(session->torrentContentLayout()); @@ -247,9 +260,6 @@ void AppController::preferencesAction() data[u"add_trackers"_qs] = session->additionalTrackers(); // Web UI - // Language - data[u"locale"_qs] = pref->getLocale(); - data[u"performance_warning"_qs] = session->isPerformanceWarningEnabled(); // HTTP Server data[u"web_ui_domain_list"_qs] = pref->getServerDomains(); data[u"web_ui_address"_qs] = pref->getWebUiAddress(); @@ -411,6 +421,45 @@ void AppController::setPreferencesAction() return (it != m.constEnd()); }; + // Behavior + // Language + if (hasKey(u"locale"_qs)) + { + QString locale = it.value().toString(); + if (pref->getLocale() != locale) + { + auto *translator = new QTranslator; + if (translator->load(u":/lang/qbittorrent_"_qs + locale)) + { + qDebug("%s locale recognized, using translation.", qUtf8Printable(locale)); + } + else + { + qDebug("%s locale unrecognized, using default (en).", qUtf8Printable(locale)); + } + qApp->installTranslator(translator); + + pref->setLocale(locale); + } + } + if (hasKey(u"performance_warning"_qs)) + session->setPerformanceWarningEnabled(it.value().toBool()); + // Log file + if (hasKey(u"file_log_enabled"_qs)) + app()->setFileLoggerEnabled(it.value().toBool()); + if (hasKey(u"file_log_path"_qs)) + app()->setFileLoggerPath(Path(it.value().toString())); + if (hasKey(u"file_log_backup_enabled"_qs)) + app()->setFileLoggerBackup(it.value().toBool()); + if (hasKey(u"file_log_max_size"_qs)) + app()->setFileLoggerMaxSize(it.value().toInt() * 1024); + if (hasKey(u"file_log_delete_old"_qs)) + app()->setFileLoggerDeleteOld(it.value().toBool()); + if (hasKey(u"file_log_age"_qs)) + app()->setFileLoggerAge(it.value().toInt()); + if (hasKey(u"file_log_age_type"_qs)) + app()->setFileLoggerAgeType(it.value().toInt()); + // Downloads // When adding a torrent if (hasKey(u"torrent_content_layout"_qs)) @@ -673,28 +722,6 @@ void AppController::setPreferencesAction() session->setAdditionalTrackers(it.value().toString()); // Web UI - // Language - if (hasKey(u"locale"_qs)) - { - QString locale = it.value().toString(); - if (pref->getLocale() != locale) - { - auto *translator = new QTranslator; - if (translator->load(u":/lang/qbittorrent_"_qs + locale)) - { - qDebug("%s locale recognized, using translation.", qUtf8Printable(locale)); - } - else - { - qDebug("%s locale unrecognized, using default (en).", qUtf8Printable(locale)); - } - qApp->installTranslator(translator); - - pref->setLocale(locale); - } - } - if (hasKey(u"performance_warning"_qs)) - session->setPerformanceWarningEnabled(it.value().toBool()); // HTTP Server if (hasKey(u"web_ui_domain_list"_qs)) pref->setServerDomains(it.value().toString()); diff --git a/src/webui/webapplication.h b/src/webui/webapplication.h index bba270496..b4351002e 100644 --- a/src/webui/webapplication.h +++ b/src/webui/webapplication.h @@ -52,7 +52,7 @@ #include "base/utils/version.h" #include "api/isessionmanager.h" -inline const Utils::Version<3, 2> API_VERSION {2, 8, 19}; +inline const Utils::Version<3, 2> API_VERSION {2, 8, 20}; class APIController; class AuthController; diff --git a/src/webui/www/private/views/preferences.html b/src/webui/www/private/views/preferences.html index 3c3634431..fca47c2b9 100644 --- a/src/webui/www/private/views/preferences.html +++ b/src/webui/www/private/views/preferences.html @@ -1,4 +1,49 @@ -