mirror of
https://github.com/qbittorrent/qBittorrent.git
synced 2024-11-29 05:48:47 +03:00
Use SettingsStorage instead.
This commit is contained in:
parent
663791fac2
commit
d721939d5f
12 changed files with 262 additions and 228 deletions
|
@ -60,8 +60,8 @@
|
|||
#include "application.h"
|
||||
#include "filelogger.h"
|
||||
#include "base/logger.h"
|
||||
#include "base/settingsstorage.h"
|
||||
#include "base/preferences.h"
|
||||
#include "base/settingsstorage.h"
|
||||
#include "base/utils/fs.h"
|
||||
#include "base/utils/misc.h"
|
||||
#include "base/iconprovider.h"
|
||||
|
@ -72,7 +72,26 @@
|
|||
#include "base/bittorrent/session.h"
|
||||
#include "base/bittorrent/torrenthandle.h"
|
||||
|
||||
static const char PARAMS_SEPARATOR[] = "|";
|
||||
namespace
|
||||
{
|
||||
#define SETTINGS_KEY(name) "Application/" name
|
||||
|
||||
// FileLogger properties keys
|
||||
#define FILELOGGER_SETTINGS_KEY(name) SETTINGS_KEY("FileLogger/") name
|
||||
const QString KEY_FILELOGGER_ENABLED = FILELOGGER_SETTINGS_KEY("Enabled");
|
||||
const QString KEY_FILELOGGER_PATH = FILELOGGER_SETTINGS_KEY("Path");
|
||||
const QString KEY_FILELOGGER_BACKUP = FILELOGGER_SETTINGS_KEY("Backup");
|
||||
const QString KEY_FILELOGGER_DELETEOLD = FILELOGGER_SETTINGS_KEY("DeleteOld");
|
||||
const QString KEY_FILELOGGER_MAXSIZE = FILELOGGER_SETTINGS_KEY("MaxSize");
|
||||
const QString KEY_FILELOGGER_AGE = FILELOGGER_SETTINGS_KEY("Age");
|
||||
const QString KEY_FILELOGGER_AGETYPE = FILELOGGER_SETTINGS_KEY("AgeType");
|
||||
|
||||
//just a shortcut
|
||||
inline SettingsStorage *settings() { return SettingsStorage::instance(); }
|
||||
|
||||
const QString LOG_FOLDER("logs");
|
||||
const char PARAMS_SEPARATOR[] = "|";
|
||||
}
|
||||
|
||||
Application::Application(const QString &id, int &argc, char **argv)
|
||||
: BaseApplication(id, argc, argv)
|
||||
|
@ -106,20 +125,104 @@ Application::Application(const QString &id, int &argc, char **argv)
|
|||
|
||||
connect(this, SIGNAL(messageReceived(const QString &)), SLOT(processMessage(const QString &)));
|
||||
connect(this, SIGNAL(aboutToQuit()), SLOT(cleanup()));
|
||||
connect(Preferences::instance(), SIGNAL(changed()), SLOT(configure()));
|
||||
|
||||
configure();
|
||||
if (isFileLoggerEnabled())
|
||||
m_fileLogger = new FileLogger(fileLoggerPath(), isFileLoggerBackup(), fileLoggerMaxSize(), isFileLoggerDeleteOld(), fileLoggerAge(), static_cast<FileLogger::FileLogAgeType>(fileLoggerAgeType()));
|
||||
|
||||
Logger::instance()->addMessage(tr("qBittorrent %1 started", "qBittorrent v3.2.0alpha started").arg(VERSION));
|
||||
}
|
||||
|
||||
void Application::configure()
|
||||
bool Application::isFileLoggerEnabled() const
|
||||
{
|
||||
bool fileLogEnabled = Preferences::instance()->fileLogEnabled();
|
||||
return settings()->loadValue(KEY_FILELOGGER_ENABLED, true).toBool();
|
||||
}
|
||||
|
||||
if (fileLogEnabled && !m_fileLogger)
|
||||
m_fileLogger = new FileLogger;
|
||||
else if (!fileLogEnabled)
|
||||
void Application::setFileLoggerEnabled(bool value)
|
||||
{
|
||||
if (value && !m_fileLogger)
|
||||
m_fileLogger = new FileLogger(fileLoggerPath(), isFileLoggerBackup(), fileLoggerMaxSize(), isFileLoggerDeleteOld(), fileLoggerAge(), static_cast<FileLogger::FileLogAgeType>(fileLoggerAgeType()));
|
||||
else if (!value)
|
||||
delete m_fileLogger;
|
||||
settings()->storeValue(KEY_FILELOGGER_ENABLED, value);
|
||||
}
|
||||
|
||||
QString Application::fileLoggerPath() const
|
||||
{
|
||||
return settings()->loadValue(KEY_FILELOGGER_PATH, QVariant(Utils::Fs::QDesktopServicesDataLocation() + LOG_FOLDER)).toString();
|
||||
}
|
||||
|
||||
void Application::setFileLoggerPath(const QString &value)
|
||||
{
|
||||
if (m_fileLogger)
|
||||
m_fileLogger->changePath(value);
|
||||
settings()->storeValue(KEY_FILELOGGER_PATH, value);
|
||||
}
|
||||
|
||||
bool Application::isFileLoggerBackup() const
|
||||
{
|
||||
return settings()->loadValue(KEY_FILELOGGER_BACKUP, true).toBool();
|
||||
}
|
||||
|
||||
void Application::setFileLoggerBackup(bool value)
|
||||
{
|
||||
if (m_fileLogger)
|
||||
m_fileLogger->setBackup(value);
|
||||
settings()->storeValue(KEY_FILELOGGER_BACKUP, value);
|
||||
}
|
||||
|
||||
bool Application::isFileLoggerDeleteOld() const
|
||||
{
|
||||
return settings()->loadValue(KEY_FILELOGGER_DELETEOLD, true).toBool();
|
||||
}
|
||||
|
||||
void Application::setFileLoggerDeleteOld(bool value)
|
||||
{
|
||||
if (value && m_fileLogger)
|
||||
m_fileLogger->deleteOld(fileLoggerAge(), static_cast<FileLogger::FileLogAgeType>(fileLoggerAgeType()));
|
||||
settings()->storeValue(KEY_FILELOGGER_DELETEOLD, value);
|
||||
}
|
||||
|
||||
int Application::fileLoggerMaxSize() const
|
||||
{
|
||||
int val = settings()->loadValue(KEY_FILELOGGER_MAXSIZE, 10).toInt();
|
||||
if (val < 1)
|
||||
return 1;
|
||||
if (val > 1000)
|
||||
return 1000;
|
||||
return val;
|
||||
}
|
||||
|
||||
void Application::setFileLoggerMaxSize(const int value)
|
||||
{
|
||||
if (m_fileLogger)
|
||||
m_fileLogger->setMaxSize(value);
|
||||
settings()->storeValue(KEY_FILELOGGER_MAXSIZE, std::min(std::max(value, 1), 1000));
|
||||
}
|
||||
|
||||
int Application::fileLoggerAge() const
|
||||
{
|
||||
int val = settings()->loadValue(KEY_FILELOGGER_AGE, 6).toInt();
|
||||
if (val < 1)
|
||||
return 1;
|
||||
if (val > 365)
|
||||
return 365;
|
||||
return val;
|
||||
}
|
||||
|
||||
void Application::setFileLoggerAge(const int value)
|
||||
{
|
||||
settings()->storeValue(KEY_FILELOGGER_AGE, std::min(std::max(value, 1), 365));
|
||||
}
|
||||
|
||||
int Application::fileLoggerAgeType() const
|
||||
{
|
||||
int val = settings()->loadValue(KEY_FILELOGGER_AGETYPE, 1).toInt();
|
||||
return (val < 0 || val > 2) ? 1 : val;
|
||||
}
|
||||
|
||||
void Application::setFileLoggerAgeType(const int value)
|
||||
{
|
||||
settings()->storeValue(KEY_FILELOGGER_AGETYPE, (value < 0 || value > 2) ? 1 : value);
|
||||
}
|
||||
|
||||
void Application::processMessage(const QString &message)
|
||||
|
|
|
@ -76,6 +76,22 @@ public:
|
|||
int exec(const QStringList ¶ms);
|
||||
bool sendParams(const QStringList ¶ms);
|
||||
|
||||
// FileLogger properties
|
||||
bool isFileLoggerEnabled() const;
|
||||
void setFileLoggerEnabled(bool value);
|
||||
QString fileLoggerPath() const;
|
||||
void setFileLoggerPath(const QString &path);
|
||||
bool isFileLoggerBackup() const;
|
||||
void setFileLoggerBackup(bool value);
|
||||
bool isFileLoggerDeleteOld() const;
|
||||
void setFileLoggerDeleteOld(bool value);
|
||||
int fileLoggerMaxSize() const;
|
||||
void setFileLoggerMaxSize(const int value);
|
||||
int fileLoggerAge() const;
|
||||
void setFileLoggerAge(const int value);
|
||||
int fileLoggerAgeType() const;
|
||||
void setFileLoggerAgeType(const int value);
|
||||
|
||||
protected:
|
||||
#ifndef DISABLE_GUI
|
||||
#ifdef Q_OS_MAC
|
||||
|
@ -85,7 +101,6 @@ protected:
|
|||
#endif
|
||||
|
||||
private slots:
|
||||
void configure();
|
||||
void processMessage(const QString &message);
|
||||
void torrentFinished(BitTorrent::TorrentHandle *const torrent);
|
||||
void allTorrentsFinished();
|
||||
|
|
|
@ -26,37 +26,31 @@
|
|||
* exception statement from your version.
|
||||
*/
|
||||
|
||||
#include <QDateTime>
|
||||
#include <QDir>
|
||||
#include <QFile>
|
||||
#include <QTextStream>
|
||||
#include "filelogger.h"
|
||||
#include "base/preferences.h"
|
||||
#include "base/logger.h"
|
||||
#include "base/utils/fs.h"
|
||||
|
||||
namespace
|
||||
{
|
||||
enum FileLogAgeType
|
||||
{
|
||||
DAYS,
|
||||
MONTHS,
|
||||
YEARS
|
||||
};
|
||||
}
|
||||
|
||||
FileLogger::FileLogger()
|
||||
: m_logFile(nullptr)
|
||||
FileLogger::FileLogger(const QString &path, const bool backup, const int maxSize, const bool deleteOld, const int age, const FileLogAgeType ageType)
|
||||
: m_backup(backup)
|
||||
, m_maxSize(maxSize)
|
||||
, m_logFile(nullptr)
|
||||
{
|
||||
m_flusher.setInterval(0);
|
||||
m_flusher.setSingleShot(true);
|
||||
connect(&m_flusher, SIGNAL(timeout()), SLOT(flushLog()));
|
||||
|
||||
configure();
|
||||
changePath(path);
|
||||
if (deleteOld)
|
||||
this->deleteOld(age, ageType);
|
||||
|
||||
const Logger* const logger = Logger::instance();
|
||||
foreach (const Log::Msg& msg, logger->getMessages())
|
||||
addLogMessage(msg);
|
||||
|
||||
connect(Preferences::instance(), SIGNAL(changed()), SLOT(configure()));
|
||||
connect(logger, SIGNAL(newLogMessage(const Log::Msg &)), SLOT(addLogMessage(const Log::Msg &)));
|
||||
}
|
||||
|
||||
|
@ -67,10 +61,9 @@ FileLogger::~FileLogger()
|
|||
delete m_logFile;
|
||||
}
|
||||
|
||||
void FileLogger::configure()
|
||||
void FileLogger::changePath(const QString& newPath)
|
||||
{
|
||||
const Preferences* const pref = Preferences::instance();
|
||||
QString tmpPath = Utils::Fs::fromNativePath(pref->fileLogPath());
|
||||
QString tmpPath = Utils::Fs::fromNativePath(newPath);
|
||||
QDir dir(tmpPath);
|
||||
dir.mkpath(tmpPath);
|
||||
tmpPath = dir.absoluteFilePath("qbittorrent.log");
|
||||
|
@ -85,22 +78,22 @@ void FileLogger::configure()
|
|||
m_logFile = new QFile(m_path);
|
||||
openLogFile();
|
||||
}
|
||||
}
|
||||
|
||||
m_backup = pref->fileLogBackup();
|
||||
m_size = pref->fileLogMaxSize();
|
||||
|
||||
if (pref->fileLogDeleteOld()) {
|
||||
void FileLogger::deleteOld(const int age, const FileLogAgeType ageType)
|
||||
{
|
||||
QDateTime date = QDateTime::currentDateTime();
|
||||
QDir dir(m_path);
|
||||
|
||||
switch (static_cast<FileLogAgeType>(pref->fileLogAgeType())) {
|
||||
switch (ageType) {
|
||||
case DAYS:
|
||||
date = date.addDays(pref->fileLogAge());
|
||||
date = date.addDays(age);
|
||||
break;
|
||||
case MONTHS:
|
||||
date = date.addMonths(pref->fileLogAge());
|
||||
date = date.addMonths(age);
|
||||
break;
|
||||
default:
|
||||
date = date.addYears(pref->fileLogAge());
|
||||
date = date.addYears(age);
|
||||
}
|
||||
|
||||
foreach (const QFileInfo file, dir.entryInfoList(QStringList("qbittorrent.log.bak*"), QDir::Files | QDir::Writable, QDir::Time | QDir::Reversed)) {
|
||||
|
@ -109,6 +102,15 @@ void FileLogger::configure()
|
|||
Utils::Fs::forceRemove(file.absoluteFilePath());
|
||||
}
|
||||
}
|
||||
|
||||
void FileLogger::setBackup(bool value)
|
||||
{
|
||||
m_backup = value;
|
||||
}
|
||||
|
||||
void FileLogger::setMaxSize(int value)
|
||||
{
|
||||
m_maxSize = value;
|
||||
}
|
||||
|
||||
void FileLogger::addLogMessage(const Log::Msg &msg)
|
||||
|
@ -133,7 +135,7 @@ void FileLogger::addLogMessage(const Log::Msg &msg)
|
|||
|
||||
str << QDateTime::fromMSecsSinceEpoch(msg.timestamp).toString(Qt::ISODate) << " - " << msg.message << endl;
|
||||
|
||||
if (m_backup && (m_logFile->size() >= (m_size * 1024 * 1024))) {
|
||||
if (m_backup && (m_logFile->size() >= (m_maxSize * 1024 * 1024))) {
|
||||
closeLogFile();
|
||||
int counter = 0;
|
||||
QString backupLogFilename = m_path + ".bak";
|
||||
|
|
|
@ -45,11 +45,22 @@ class FileLogger : public QObject
|
|||
Q_DISABLE_COPY(FileLogger)
|
||||
|
||||
public:
|
||||
FileLogger();
|
||||
enum FileLogAgeType
|
||||
{
|
||||
DAYS,
|
||||
MONTHS,
|
||||
YEARS
|
||||
};
|
||||
|
||||
FileLogger(const QString &path, const bool backup, const int maxSize, const bool deleteOld, const int age, const FileLogAgeType ageType);
|
||||
~FileLogger();
|
||||
|
||||
void changePath(const QString &newPath);
|
||||
void deleteOld(const int age, const FileLogAgeType ageType);
|
||||
void setBackup(bool value);
|
||||
void setMaxSize(int value);
|
||||
|
||||
private slots:
|
||||
void configure();
|
||||
void addLogMessage(const Log::Msg &msg);
|
||||
void flushLog();
|
||||
|
||||
|
@ -57,9 +68,9 @@ private:
|
|||
void openLogFile();
|
||||
void closeLogFile();
|
||||
|
||||
bool m_backup;
|
||||
int m_size;
|
||||
QString m_path;
|
||||
bool m_backup;
|
||||
int m_maxSize;
|
||||
QFile *m_logFile;
|
||||
QTimer m_flusher;
|
||||
};
|
||||
|
|
|
@ -60,8 +60,6 @@
|
|||
|
||||
Preferences* Preferences::m_instance = 0;
|
||||
|
||||
static const QString LOG_FOLDER("logs");
|
||||
|
||||
Preferences::Preferences()
|
||||
: m_randomPort(rand() % 64512 + 1024)
|
||||
{
|
||||
|
@ -862,111 +860,6 @@ void Preferences::setSearchEnabled(bool enabled)
|
|||
setValue("Preferences/Search/SearchEnabled", enabled);
|
||||
}
|
||||
|
||||
// Execution Log
|
||||
bool Preferences::isExecutionLogEnabled() const
|
||||
{
|
||||
return value("Preferences/ExecutionLog/enabled", false).toBool();
|
||||
}
|
||||
|
||||
void Preferences::setExecutionLogEnabled(bool b)
|
||||
{
|
||||
setValue("Preferences/ExecutionLog/enabled", b);
|
||||
}
|
||||
|
||||
int Preferences::executionLogMessageTypes() const
|
||||
{
|
||||
// as default value we need all the bits set
|
||||
// -1 is considered the portable way to achieve that
|
||||
return value("MainWindow/ExecutionLog/Types", -1).toInt();
|
||||
}
|
||||
|
||||
void Preferences::setExecutionLogMessageTypes(const int &value)
|
||||
{
|
||||
setValue("MainWindow/ExecutionLog/Types", value);
|
||||
}
|
||||
|
||||
// File log
|
||||
bool Preferences::fileLogEnabled() const
|
||||
{
|
||||
return value("Application/FileLogger/Enabled", true).toBool();
|
||||
}
|
||||
|
||||
void Preferences::setFileLogEnabled(bool enabled)
|
||||
{
|
||||
setValue("Application/FileLogger/Enabled", enabled);
|
||||
}
|
||||
|
||||
QString Preferences::fileLogPath() const
|
||||
{
|
||||
return value("Application/FileLogger/Path", QVariant(Utils::Fs::QDesktopServicesDataLocation() + LOG_FOLDER)).toString();
|
||||
}
|
||||
|
||||
void Preferences::setFileLogPath(const QString &path)
|
||||
{
|
||||
setValue("Application/FileLogger/Path", path);
|
||||
}
|
||||
|
||||
bool Preferences::fileLogBackup() const
|
||||
{
|
||||
return value("Application/FileLogger/Backup", true).toBool();
|
||||
}
|
||||
|
||||
void Preferences::setFileLogBackup(bool backup)
|
||||
{
|
||||
setValue("Application/FileLogger/Backup", backup);
|
||||
}
|
||||
|
||||
bool Preferences::fileLogDeleteOld() const
|
||||
{
|
||||
return value("Application/FileLogger/DeleteOld", true).toBool();
|
||||
}
|
||||
|
||||
void Preferences::setFileLogDeleteOld(bool deleteOld)
|
||||
{
|
||||
setValue("Application/FileLogger/DeleteOld", deleteOld);
|
||||
}
|
||||
|
||||
int Preferences::fileLogMaxSize() const
|
||||
{
|
||||
int val = value("Application/FileLogger/MaxSize", 10).toInt();
|
||||
if (val < 1)
|
||||
return 1;
|
||||
if (val > 1000)
|
||||
return 1000;
|
||||
return val;
|
||||
}
|
||||
|
||||
void Preferences::setFileLogMaxSize(const int &size)
|
||||
{
|
||||
setValue("Application/FileLogger/MaxSize", std::min(std::max(size, 1), 1000));
|
||||
}
|
||||
|
||||
int Preferences::fileLogAge() const
|
||||
{
|
||||
int val = value("Application/FileLogger/Age", 6).toInt();
|
||||
if (val < 1)
|
||||
return 1;
|
||||
if (val > 365)
|
||||
return 365;
|
||||
return val;
|
||||
}
|
||||
|
||||
void Preferences::setFileLogAge(const int &age)
|
||||
{
|
||||
setValue("Application/FileLogger/Age", std::min(std::max(age, 1), 365));
|
||||
}
|
||||
|
||||
int Preferences::fileLogAgeType() const
|
||||
{
|
||||
int val = value("Application/FileLogger/AgeType", 1).toInt();
|
||||
return (val < 0 || val > 2) ? 1 : val;
|
||||
}
|
||||
|
||||
void Preferences::setFileLogAgeType(const int &ageType)
|
||||
{
|
||||
setValue("Application/FileLogger/AgeType", (ageType < 0 || ageType > 2) ? 1 : ageType);
|
||||
}
|
||||
|
||||
// Queueing system
|
||||
bool Preferences::isQueueingSystemEnabled() const
|
||||
{
|
||||
|
|
|
@ -273,29 +273,6 @@ public:
|
|||
bool isSearchEnabled() const;
|
||||
void setSearchEnabled(bool enabled);
|
||||
|
||||
// Execution Log
|
||||
bool isExecutionLogEnabled() const;
|
||||
void setExecutionLogEnabled(bool b);
|
||||
int executionLogMessageTypes() const;
|
||||
void setExecutionLogMessageTypes(const int &value);
|
||||
|
||||
// File log
|
||||
bool fileLogEnabled() const;
|
||||
void setFileLogEnabled(bool enabled);
|
||||
QString fileLogPath() const;
|
||||
void setFileLogPath(const QString &path);
|
||||
bool fileLogBackup() const;
|
||||
void setFileLogBackup(bool backup);
|
||||
bool fileLogDeleteOld() const;
|
||||
void setFileLogDeleteOld(bool deleteOld);
|
||||
int fileLogMaxSize() const;
|
||||
void setFileLogMaxSize(const int &size);
|
||||
int fileLogAge() const;
|
||||
void setFileLogAge(const int &age);
|
||||
int fileLogAgeType() const;
|
||||
void setFileLogAgeType(const int &ageType);
|
||||
|
||||
|
||||
// Queueing system
|
||||
bool isQueueingSystemEnabled() const;
|
||||
void setQueueingSystemEnabled(bool enabled);
|
||||
|
|
|
@ -81,7 +81,8 @@ namespace
|
|||
{ "AddNewTorrentDialog/Expanded", "AddNewTorrentDialog/expanded" },
|
||||
{ "AddNewTorrentDialog/SavePathHistory", "TorrentAdditionDlg/save_path_history" },
|
||||
{ "AddNewTorrentDialog/Enabled", "Preferences/Downloads/NewAdditionDialog" },
|
||||
{ "AddNewTorrentDialog/TopLevel", "Preferences/Downloads/NewAdditionDialogFront" }
|
||||
{ "AddNewTorrentDialog/TopLevel", "Preferences/Downloads/NewAdditionDialogFront" },
|
||||
{ "ExecutionLog/Enabled", "Preferences/ExecutionLog/enabled" }
|
||||
|
||||
};
|
||||
|
||||
|
|
|
@ -35,19 +35,17 @@
|
|||
#include <QPalette>
|
||||
#include "executionlog.h"
|
||||
#include "ui_executionlog.h"
|
||||
#include "base/preferences.h"
|
||||
#include "guiiconprovider.h"
|
||||
#include "loglistwidget.h"
|
||||
|
||||
ExecutionLog::ExecutionLog(QWidget *parent)
|
||||
ExecutionLog::ExecutionLog(QWidget *parent, const Log::MsgTypes &types)
|
||||
: QWidget(parent)
|
||||
, ui(new Ui::ExecutionLog)
|
||||
, m_peerList(new LogListWidget(MAX_LOG_MESSAGES))
|
||||
{
|
||||
ui->setupUi(this);
|
||||
|
||||
m_msgList = new LogListWidget(MAX_LOG_MESSAGES,
|
||||
Log::MsgTypes(Preferences::instance()->executionLogMessageTypes()));
|
||||
m_msgList = new LogListWidget(MAX_LOG_MESSAGES, Log::MsgTypes(types));
|
||||
|
||||
ui->tabConsole->setTabIcon(0, GuiIconProvider::instance()->getIcon("view-calendar-journal"));
|
||||
ui->tabConsole->setTabIcon(1, GuiIconProvider::instance()->getIcon("view-filter"));
|
||||
|
|
|
@ -46,7 +46,7 @@ class ExecutionLog: public QWidget
|
|||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit ExecutionLog(QWidget *parent = 0);
|
||||
ExecutionLog(QWidget *parent, const Log::MsgTypes &types);
|
||||
void showMsgTypes(const Log::MsgTypes &types);
|
||||
~ExecutionLog();
|
||||
|
||||
|
|
|
@ -65,6 +65,7 @@
|
|||
#include "options_imp.h"
|
||||
#include "speedlimitdlg.h"
|
||||
#include "base/preferences.h"
|
||||
#include "base/settingsstorage.h"
|
||||
#include "trackerlist.h"
|
||||
#include "peerlistwidget.h"
|
||||
#include "transferlistfilterswidget.h"
|
||||
|
@ -94,6 +95,19 @@ void qt_mac_set_dock_menu(QMenu *menu);
|
|||
#define TIME_TRAY_BALLOON 5000
|
||||
#define PREVENT_SUSPEND_INTERVAL 60000
|
||||
|
||||
namespace
|
||||
{
|
||||
#define SETTINGS_KEY(name) "MainWindow/" name
|
||||
|
||||
// ExecutionLog properties keys
|
||||
#define EXECUTIONLOG_SETTINGS_KEY(name) SETTINGS_KEY("ExecutionLog/") name
|
||||
const QString KEY_EXECUTIONLOG_ENABLED = EXECUTIONLOG_SETTINGS_KEY("Enabled");
|
||||
const QString KEY_EXECUTIONLOG_TYPES = EXECUTIONLOG_SETTINGS_KEY("Types");
|
||||
|
||||
//just a shortcut
|
||||
inline SettingsStorage *settings() { return SettingsStorage::instance(); }
|
||||
}
|
||||
|
||||
/*****************************************************
|
||||
* *
|
||||
* GUI *
|
||||
|
@ -273,9 +287,9 @@ MainWindow::MainWindow(QWidget *parent)
|
|||
actionSpeed_in_title_bar->setChecked(pref->speedInTitleBar());
|
||||
actionRSS_Reader->setChecked(pref->isRSSEnabled());
|
||||
actionSearch_engine->setChecked(pref->isSearchEnabled());
|
||||
actionExecutionLogs->setChecked(pref->isExecutionLogEnabled());
|
||||
actionExecutionLogs->setChecked(isExecutionLogEnabled());
|
||||
|
||||
Log::MsgTypes flags(pref->executionLogMessageTypes());
|
||||
Log::MsgTypes flags(executionLogMsgTypes());
|
||||
actionNormalMessages->setChecked(flags & Log::NORMAL);
|
||||
actionInformationMessages->setChecked(flags & Log::INFO);
|
||||
actionWarningMessages->setChecked(flags & Log::WARNING);
|
||||
|
@ -382,6 +396,29 @@ MainWindow::~MainWindow()
|
|||
#endif
|
||||
}
|
||||
|
||||
bool MainWindow::isExecutionLogEnabled() const
|
||||
{
|
||||
return settings()->loadValue(KEY_EXECUTIONLOG_ENABLED, false).toBool();
|
||||
}
|
||||
|
||||
void MainWindow::setExecutionLogEnabled(bool value)
|
||||
{
|
||||
settings()->storeValue(KEY_EXECUTIONLOG_ENABLED, value);
|
||||
}
|
||||
|
||||
int MainWindow::executionLogMsgTypes() const
|
||||
{
|
||||
// as default value we need all the bits set
|
||||
// -1 is considered the portable way to achieve that
|
||||
return settings()->loadValue(KEY_EXECUTIONLOG_TYPES, -1).toInt();
|
||||
}
|
||||
|
||||
void MainWindow::setExecutionLogMsgTypes(const int value)
|
||||
{
|
||||
m_executionLog->showMsgTypes(static_cast<Log::MsgTypes>(value));
|
||||
settings()->storeValue(KEY_EXECUTIONLOG_TYPES, value);
|
||||
}
|
||||
|
||||
void MainWindow::addToolbarContextMenu()
|
||||
{
|
||||
const Preferences* const pref = Preferences::instance();
|
||||
|
@ -1522,7 +1559,7 @@ void MainWindow::on_actionExecutionLogs_triggered(bool checked)
|
|||
{
|
||||
if (checked) {
|
||||
Q_ASSERT(!m_executionLog);
|
||||
m_executionLog = new ExecutionLog(tabs);
|
||||
m_executionLog = new ExecutionLog(tabs, static_cast<Log::MsgType>(executionLogMsgTypes()));
|
||||
int index_tab = tabs->addTab(m_executionLog, tr("Execution Log"));
|
||||
tabs->setTabIcon(index_tab, GuiIconProvider::instance()->getIcon("view-calendar-journal"));
|
||||
}
|
||||
|
@ -1534,7 +1571,7 @@ void MainWindow::on_actionExecutionLogs_triggered(bool checked)
|
|||
actionInformationMessages->setEnabled(checked);
|
||||
actionWarningMessages->setEnabled(checked);
|
||||
actionCriticalMessages->setEnabled(checked);
|
||||
Preferences::instance()->setExecutionLogEnabled(checked);
|
||||
setExecutionLogEnabled(checked);
|
||||
}
|
||||
|
||||
void MainWindow::on_actionNormalMessages_triggered(bool checked)
|
||||
|
@ -1542,12 +1579,9 @@ void MainWindow::on_actionNormalMessages_triggered(bool checked)
|
|||
if (!m_executionLog)
|
||||
return;
|
||||
|
||||
Preferences* const pref = Preferences::instance();
|
||||
|
||||
Log::MsgTypes flags(pref->executionLogMessageTypes());
|
||||
Log::MsgTypes flags(executionLogMsgTypes());
|
||||
checked ? (flags |= Log::NORMAL) : (flags &= ~Log::NORMAL);
|
||||
m_executionLog->showMsgTypes(flags);
|
||||
pref->setExecutionLogMessageTypes(flags);
|
||||
setExecutionLogMsgTypes(flags);
|
||||
}
|
||||
|
||||
void MainWindow::on_actionInformationMessages_triggered(bool checked)
|
||||
|
@ -1555,12 +1589,9 @@ void MainWindow::on_actionInformationMessages_triggered(bool checked)
|
|||
if (!m_executionLog)
|
||||
return;
|
||||
|
||||
Preferences* const pref = Preferences::instance();
|
||||
|
||||
Log::MsgTypes flags(pref->executionLogMessageTypes());
|
||||
Log::MsgTypes flags(executionLogMsgTypes());
|
||||
checked ? (flags |= Log::INFO) : (flags &= ~Log::INFO);
|
||||
m_executionLog->showMsgTypes(flags);
|
||||
pref->setExecutionLogMessageTypes(flags);
|
||||
setExecutionLogMsgTypes(flags);
|
||||
}
|
||||
|
||||
void MainWindow::on_actionWarningMessages_triggered(bool checked)
|
||||
|
@ -1568,12 +1599,9 @@ void MainWindow::on_actionWarningMessages_triggered(bool checked)
|
|||
if (!m_executionLog)
|
||||
return;
|
||||
|
||||
Preferences* const pref = Preferences::instance();
|
||||
|
||||
Log::MsgTypes flags(pref->executionLogMessageTypes());
|
||||
Log::MsgTypes flags(executionLogMsgTypes());
|
||||
checked ? (flags |= Log::WARNING) : (flags &= ~Log::WARNING);
|
||||
m_executionLog->showMsgTypes(flags);
|
||||
pref->setExecutionLogMessageTypes(flags);
|
||||
setExecutionLogMsgTypes(flags);
|
||||
}
|
||||
|
||||
void MainWindow::on_actionCriticalMessages_triggered(bool checked)
|
||||
|
@ -1581,12 +1609,9 @@ void MainWindow::on_actionCriticalMessages_triggered(bool checked)
|
|||
if (!m_executionLog)
|
||||
return;
|
||||
|
||||
Preferences* const pref = Preferences::instance();
|
||||
|
||||
Log::MsgTypes flags(pref->executionLogMessageTypes());
|
||||
Log::MsgTypes flags(executionLogMsgTypes());
|
||||
checked ? (flags |= Log::CRITICAL) : (flags &= ~Log::CRITICAL);
|
||||
m_executionLog->showMsgTypes(flags);
|
||||
pref->setExecutionLogMessageTypes(flags);
|
||||
setExecutionLogMsgTypes(flags);
|
||||
}
|
||||
|
||||
void MainWindow::on_actionAutoExit_qBittorrent_toggled(bool enabled)
|
||||
|
|
|
@ -81,6 +81,12 @@ public:
|
|||
QMenu* getTrayIconMenu();
|
||||
PropertiesWidget *getProperties() const { return properties; }
|
||||
|
||||
// ExecutionLog properties
|
||||
bool isExecutionLogEnabled() const;
|
||||
void setExecutionLogEnabled(bool value);
|
||||
int executionLogMsgTypes() const;
|
||||
void setExecutionLogMsgTypes(const int value);
|
||||
|
||||
public slots:
|
||||
void trackerAuthenticationRequired(BitTorrent::TorrentHandle *const torrent);
|
||||
void setTabText(int index, QString text) const;
|
||||
|
|
|
@ -42,6 +42,7 @@
|
|||
|
||||
#include <cstdlib>
|
||||
|
||||
#include "app/application.h"
|
||||
#include "base/preferences.h"
|
||||
#include "base/utils/fs.h"
|
||||
#include "base/scanfoldersmodel.h"
|
||||
|
@ -444,13 +445,14 @@ void options_imp::saveOptions()
|
|||
checkAssociateMagnetLinks->setEnabled(!checkAssociateMagnetLinks->isChecked());
|
||||
}
|
||||
#endif
|
||||
pref->setFileLogEnabled(checkFileLog->isChecked());
|
||||
pref->setFileLogPath(Utils::Fs::fromNativePath(textFileLogPath->text()));
|
||||
pref->setFileLogBackup(checkFileLogBackup->isChecked());
|
||||
pref->setFileLogMaxSize(spinFileLogSize->value());
|
||||
pref->setFileLogDeleteOld(checkFileLogDelete->isChecked());
|
||||
pref->setFileLogAge(spinFileLogAge->value());
|
||||
pref->setFileLogAgeType(comboFileLogAgeType->currentIndex());
|
||||
Application * const app = static_cast<Application*>(QCoreApplication::instance());
|
||||
app->setFileLoggerPath(Utils::Fs::fromNativePath(textFileLogPath->text()));
|
||||
app->setFileLoggerBackup(checkFileLogBackup->isChecked());
|
||||
app->setFileLoggerMaxSize(spinFileLogSize->value());
|
||||
app->setFileLoggerAge(spinFileLogAge->value());
|
||||
app->setFileLoggerAgeType(comboFileLogAgeType->currentIndex());
|
||||
app->setFileLoggerDeleteOld(checkFileLogDelete->isChecked());
|
||||
app->setFileLoggerEnabled(checkFileLog->isChecked());
|
||||
// End General preferences
|
||||
|
||||
auto session = BitTorrent::Session::instance();
|
||||
|
@ -641,18 +643,19 @@ void options_imp::loadOptions()
|
|||
checkAssociateMagnetLinks->setEnabled(!checkAssociateMagnetLinks->isChecked());
|
||||
#endif
|
||||
|
||||
checkFileLog->setChecked(pref->fileLogEnabled());
|
||||
textFileLogPath->setText(Utils::Fs::toNativePath(pref->fileLogPath()));
|
||||
fileLogBackup = pref->fileLogBackup();
|
||||
const Application * const app = static_cast<Application*>(QCoreApplication::instance());
|
||||
checkFileLog->setChecked(app->isFileLoggerEnabled());
|
||||
textFileLogPath->setText(Utils::Fs::toNativePath(app->fileLoggerPath()));
|
||||
fileLogBackup = app->isFileLoggerBackup();
|
||||
checkFileLogBackup->setChecked(fileLogBackup);
|
||||
spinFileLogSize->setEnabled(fileLogBackup);
|
||||
fileLogDelete = pref->fileLogDeleteOld();
|
||||
fileLogDelete = app->isFileLoggerDeleteOld();
|
||||
checkFileLogDelete->setChecked(fileLogDelete);
|
||||
spinFileLogAge->setEnabled(fileLogDelete);
|
||||
comboFileLogAgeType->setEnabled(fileLogDelete);
|
||||
spinFileLogSize->setValue(pref->fileLogMaxSize());
|
||||
spinFileLogAge->setValue(pref->fileLogAge());
|
||||
comboFileLogAgeType->setCurrentIndex(pref->fileLogAgeType());
|
||||
spinFileLogSize->setValue(app->fileLoggerMaxSize());
|
||||
spinFileLogAge->setValue(app->fileLoggerAge());
|
||||
comboFileLogAgeType->setCurrentIndex(app->fileLoggerAgeType());
|
||||
// End General preferences
|
||||
|
||||
auto session = BitTorrent::Session::instance();
|
||||
|
|
Loading…
Reference in a new issue