mirror of
https://github.com/qbittorrent/qBittorrent.git
synced 2025-01-06 15:04:34 +08:00
Use SettingsStorage instead.
This commit is contained in:
parent
663791fac2
commit
d721939d5f
@ -60,8 +60,8 @@
|
|||||||
#include "application.h"
|
#include "application.h"
|
||||||
#include "filelogger.h"
|
#include "filelogger.h"
|
||||||
#include "base/logger.h"
|
#include "base/logger.h"
|
||||||
#include "base/settingsstorage.h"
|
|
||||||
#include "base/preferences.h"
|
#include "base/preferences.h"
|
||||||
|
#include "base/settingsstorage.h"
|
||||||
#include "base/utils/fs.h"
|
#include "base/utils/fs.h"
|
||||||
#include "base/utils/misc.h"
|
#include "base/utils/misc.h"
|
||||||
#include "base/iconprovider.h"
|
#include "base/iconprovider.h"
|
||||||
@ -72,7 +72,26 @@
|
|||||||
#include "base/bittorrent/session.h"
|
#include "base/bittorrent/session.h"
|
||||||
#include "base/bittorrent/torrenthandle.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)
|
Application::Application(const QString &id, int &argc, char **argv)
|
||||||
: BaseApplication(id, argc, 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(messageReceived(const QString &)), SLOT(processMessage(const QString &)));
|
||||||
connect(this, SIGNAL(aboutToQuit()), SLOT(cleanup()));
|
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));
|
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)
|
void Application::setFileLoggerEnabled(bool value)
|
||||||
m_fileLogger = new FileLogger;
|
{
|
||||||
else if (!fileLogEnabled)
|
if (value && !m_fileLogger)
|
||||||
|
m_fileLogger = new FileLogger(fileLoggerPath(), isFileLoggerBackup(), fileLoggerMaxSize(), isFileLoggerDeleteOld(), fileLoggerAge(), static_cast<FileLogger::FileLogAgeType>(fileLoggerAgeType()));
|
||||||
|
else if (!value)
|
||||||
delete m_fileLogger;
|
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)
|
void Application::processMessage(const QString &message)
|
||||||
|
@ -76,6 +76,22 @@ public:
|
|||||||
int exec(const QStringList ¶ms);
|
int exec(const QStringList ¶ms);
|
||||||
bool sendParams(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:
|
protected:
|
||||||
#ifndef DISABLE_GUI
|
#ifndef DISABLE_GUI
|
||||||
#ifdef Q_OS_MAC
|
#ifdef Q_OS_MAC
|
||||||
@ -85,7 +101,6 @@ protected:
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void configure();
|
|
||||||
void processMessage(const QString &message);
|
void processMessage(const QString &message);
|
||||||
void torrentFinished(BitTorrent::TorrentHandle *const torrent);
|
void torrentFinished(BitTorrent::TorrentHandle *const torrent);
|
||||||
void allTorrentsFinished();
|
void allTorrentsFinished();
|
||||||
|
@ -26,37 +26,31 @@
|
|||||||
* exception statement from your version.
|
* exception statement from your version.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <QDateTime>
|
||||||
#include <QDir>
|
#include <QDir>
|
||||||
#include <QFile>
|
#include <QFile>
|
||||||
#include <QTextStream>
|
#include <QTextStream>
|
||||||
#include "filelogger.h"
|
#include "filelogger.h"
|
||||||
#include "base/preferences.h"
|
|
||||||
#include "base/logger.h"
|
#include "base/logger.h"
|
||||||
#include "base/utils/fs.h"
|
#include "base/utils/fs.h"
|
||||||
|
|
||||||
namespace
|
FileLogger::FileLogger(const QString &path, const bool backup, const int maxSize, const bool deleteOld, const int age, const FileLogAgeType ageType)
|
||||||
{
|
: m_backup(backup)
|
||||||
enum FileLogAgeType
|
, m_maxSize(maxSize)
|
||||||
{
|
, m_logFile(nullptr)
|
||||||
DAYS,
|
|
||||||
MONTHS,
|
|
||||||
YEARS
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
FileLogger::FileLogger()
|
|
||||||
: m_logFile(nullptr)
|
|
||||||
{
|
{
|
||||||
m_flusher.setInterval(0);
|
m_flusher.setInterval(0);
|
||||||
m_flusher.setSingleShot(true);
|
m_flusher.setSingleShot(true);
|
||||||
connect(&m_flusher, SIGNAL(timeout()), SLOT(flushLog()));
|
connect(&m_flusher, SIGNAL(timeout()), SLOT(flushLog()));
|
||||||
|
|
||||||
configure();
|
changePath(path);
|
||||||
|
if (deleteOld)
|
||||||
|
this->deleteOld(age, ageType);
|
||||||
|
|
||||||
const Logger* const logger = Logger::instance();
|
const Logger* const logger = Logger::instance();
|
||||||
foreach (const Log::Msg& msg, logger->getMessages())
|
foreach (const Log::Msg& msg, logger->getMessages())
|
||||||
addLogMessage(msg);
|
addLogMessage(msg);
|
||||||
|
|
||||||
connect(Preferences::instance(), SIGNAL(changed()), SLOT(configure()));
|
|
||||||
connect(logger, SIGNAL(newLogMessage(const Log::Msg &)), SLOT(addLogMessage(const Log::Msg &)));
|
connect(logger, SIGNAL(newLogMessage(const Log::Msg &)), SLOT(addLogMessage(const Log::Msg &)));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -67,10 +61,9 @@ FileLogger::~FileLogger()
|
|||||||
delete m_logFile;
|
delete m_logFile;
|
||||||
}
|
}
|
||||||
|
|
||||||
void FileLogger::configure()
|
void FileLogger::changePath(const QString& newPath)
|
||||||
{
|
{
|
||||||
const Preferences* const pref = Preferences::instance();
|
QString tmpPath = Utils::Fs::fromNativePath(newPath);
|
||||||
QString tmpPath = Utils::Fs::fromNativePath(pref->fileLogPath());
|
|
||||||
QDir dir(tmpPath);
|
QDir dir(tmpPath);
|
||||||
dir.mkpath(tmpPath);
|
dir.mkpath(tmpPath);
|
||||||
tmpPath = dir.absoluteFilePath("qbittorrent.log");
|
tmpPath = dir.absoluteFilePath("qbittorrent.log");
|
||||||
@ -85,30 +78,39 @@ void FileLogger::configure()
|
|||||||
m_logFile = new QFile(m_path);
|
m_logFile = new QFile(m_path);
|
||||||
openLogFile();
|
openLogFile();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
m_backup = pref->fileLogBackup();
|
void FileLogger::deleteOld(const int age, const FileLogAgeType ageType)
|
||||||
m_size = pref->fileLogMaxSize();
|
{
|
||||||
|
QDateTime date = QDateTime::currentDateTime();
|
||||||
|
QDir dir(m_path);
|
||||||
|
|
||||||
if (pref->fileLogDeleteOld()) {
|
switch (ageType) {
|
||||||
QDateTime date = QDateTime::currentDateTime();
|
case DAYS:
|
||||||
|
date = date.addDays(age);
|
||||||
switch (static_cast<FileLogAgeType>(pref->fileLogAgeType())) {
|
break;
|
||||||
case DAYS:
|
case MONTHS:
|
||||||
date = date.addDays(pref->fileLogAge());
|
date = date.addMonths(age);
|
||||||
break;
|
break;
|
||||||
case MONTHS:
|
default:
|
||||||
date = date.addMonths(pref->fileLogAge());
|
date = date.addYears(age);
|
||||||
break;
|
|
||||||
default:
|
|
||||||
date = date.addYears(pref->fileLogAge());
|
|
||||||
}
|
|
||||||
|
|
||||||
foreach (const QFileInfo file, dir.entryInfoList(QStringList("qbittorrent.log.bak*"), QDir::Files | QDir::Writable, QDir::Time | QDir::Reversed)) {
|
|
||||||
if (file.lastModified() < date)
|
|
||||||
break;
|
|
||||||
Utils::Fs::forceRemove(file.absoluteFilePath());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
foreach (const QFileInfo file, dir.entryInfoList(QStringList("qbittorrent.log.bak*"), QDir::Files | QDir::Writable, QDir::Time | QDir::Reversed)) {
|
||||||
|
if (file.lastModified() < date)
|
||||||
|
break;
|
||||||
|
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)
|
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;
|
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();
|
closeLogFile();
|
||||||
int counter = 0;
|
int counter = 0;
|
||||||
QString backupLogFilename = m_path + ".bak";
|
QString backupLogFilename = m_path + ".bak";
|
||||||
|
@ -45,11 +45,22 @@ class FileLogger : public QObject
|
|||||||
Q_DISABLE_COPY(FileLogger)
|
Q_DISABLE_COPY(FileLogger)
|
||||||
|
|
||||||
public:
|
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();
|
~FileLogger();
|
||||||
|
|
||||||
|
void changePath(const QString &newPath);
|
||||||
|
void deleteOld(const int age, const FileLogAgeType ageType);
|
||||||
|
void setBackup(bool value);
|
||||||
|
void setMaxSize(int value);
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void configure();
|
|
||||||
void addLogMessage(const Log::Msg &msg);
|
void addLogMessage(const Log::Msg &msg);
|
||||||
void flushLog();
|
void flushLog();
|
||||||
|
|
||||||
@ -57,9 +68,9 @@ private:
|
|||||||
void openLogFile();
|
void openLogFile();
|
||||||
void closeLogFile();
|
void closeLogFile();
|
||||||
|
|
||||||
bool m_backup;
|
|
||||||
int m_size;
|
|
||||||
QString m_path;
|
QString m_path;
|
||||||
|
bool m_backup;
|
||||||
|
int m_maxSize;
|
||||||
QFile *m_logFile;
|
QFile *m_logFile;
|
||||||
QTimer m_flusher;
|
QTimer m_flusher;
|
||||||
};
|
};
|
||||||
|
@ -60,8 +60,6 @@
|
|||||||
|
|
||||||
Preferences* Preferences::m_instance = 0;
|
Preferences* Preferences::m_instance = 0;
|
||||||
|
|
||||||
static const QString LOG_FOLDER("logs");
|
|
||||||
|
|
||||||
Preferences::Preferences()
|
Preferences::Preferences()
|
||||||
: m_randomPort(rand() % 64512 + 1024)
|
: m_randomPort(rand() % 64512 + 1024)
|
||||||
{
|
{
|
||||||
@ -862,111 +860,6 @@ void Preferences::setSearchEnabled(bool enabled)
|
|||||||
setValue("Preferences/Search/SearchEnabled", 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
|
// Queueing system
|
||||||
bool Preferences::isQueueingSystemEnabled() const
|
bool Preferences::isQueueingSystemEnabled() const
|
||||||
{
|
{
|
||||||
|
@ -273,29 +273,6 @@ public:
|
|||||||
bool isSearchEnabled() const;
|
bool isSearchEnabled() const;
|
||||||
void setSearchEnabled(bool enabled);
|
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
|
// Queueing system
|
||||||
bool isQueueingSystemEnabled() const;
|
bool isQueueingSystemEnabled() const;
|
||||||
void setQueueingSystemEnabled(bool enabled);
|
void setQueueingSystemEnabled(bool enabled);
|
||||||
|
@ -81,7 +81,8 @@ namespace
|
|||||||
{ "AddNewTorrentDialog/Expanded", "AddNewTorrentDialog/expanded" },
|
{ "AddNewTorrentDialog/Expanded", "AddNewTorrentDialog/expanded" },
|
||||||
{ "AddNewTorrentDialog/SavePathHistory", "TorrentAdditionDlg/save_path_history" },
|
{ "AddNewTorrentDialog/SavePathHistory", "TorrentAdditionDlg/save_path_history" },
|
||||||
{ "AddNewTorrentDialog/Enabled", "Preferences/Downloads/NewAdditionDialog" },
|
{ "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 <QPalette>
|
||||||
#include "executionlog.h"
|
#include "executionlog.h"
|
||||||
#include "ui_executionlog.h"
|
#include "ui_executionlog.h"
|
||||||
#include "base/preferences.h"
|
|
||||||
#include "guiiconprovider.h"
|
#include "guiiconprovider.h"
|
||||||
#include "loglistwidget.h"
|
#include "loglistwidget.h"
|
||||||
|
|
||||||
ExecutionLog::ExecutionLog(QWidget *parent)
|
ExecutionLog::ExecutionLog(QWidget *parent, const Log::MsgTypes &types)
|
||||||
: QWidget(parent)
|
: QWidget(parent)
|
||||||
, ui(new Ui::ExecutionLog)
|
, ui(new Ui::ExecutionLog)
|
||||||
, m_peerList(new LogListWidget(MAX_LOG_MESSAGES))
|
, m_peerList(new LogListWidget(MAX_LOG_MESSAGES))
|
||||||
{
|
{
|
||||||
ui->setupUi(this);
|
ui->setupUi(this);
|
||||||
|
|
||||||
m_msgList = new LogListWidget(MAX_LOG_MESSAGES,
|
m_msgList = new LogListWidget(MAX_LOG_MESSAGES, Log::MsgTypes(types));
|
||||||
Log::MsgTypes(Preferences::instance()->executionLogMessageTypes()));
|
|
||||||
|
|
||||||
ui->tabConsole->setTabIcon(0, GuiIconProvider::instance()->getIcon("view-calendar-journal"));
|
ui->tabConsole->setTabIcon(0, GuiIconProvider::instance()->getIcon("view-calendar-journal"));
|
||||||
ui->tabConsole->setTabIcon(1, GuiIconProvider::instance()->getIcon("view-filter"));
|
ui->tabConsole->setTabIcon(1, GuiIconProvider::instance()->getIcon("view-filter"));
|
||||||
|
@ -46,7 +46,7 @@ class ExecutionLog: public QWidget
|
|||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit ExecutionLog(QWidget *parent = 0);
|
ExecutionLog(QWidget *parent, const Log::MsgTypes &types);
|
||||||
void showMsgTypes(const Log::MsgTypes &types);
|
void showMsgTypes(const Log::MsgTypes &types);
|
||||||
~ExecutionLog();
|
~ExecutionLog();
|
||||||
|
|
||||||
|
@ -65,6 +65,7 @@
|
|||||||
#include "options_imp.h"
|
#include "options_imp.h"
|
||||||
#include "speedlimitdlg.h"
|
#include "speedlimitdlg.h"
|
||||||
#include "base/preferences.h"
|
#include "base/preferences.h"
|
||||||
|
#include "base/settingsstorage.h"
|
||||||
#include "trackerlist.h"
|
#include "trackerlist.h"
|
||||||
#include "peerlistwidget.h"
|
#include "peerlistwidget.h"
|
||||||
#include "transferlistfilterswidget.h"
|
#include "transferlistfilterswidget.h"
|
||||||
@ -94,6 +95,19 @@ void qt_mac_set_dock_menu(QMenu *menu);
|
|||||||
#define TIME_TRAY_BALLOON 5000
|
#define TIME_TRAY_BALLOON 5000
|
||||||
#define PREVENT_SUSPEND_INTERVAL 60000
|
#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 *
|
* GUI *
|
||||||
@ -273,9 +287,9 @@ MainWindow::MainWindow(QWidget *parent)
|
|||||||
actionSpeed_in_title_bar->setChecked(pref->speedInTitleBar());
|
actionSpeed_in_title_bar->setChecked(pref->speedInTitleBar());
|
||||||
actionRSS_Reader->setChecked(pref->isRSSEnabled());
|
actionRSS_Reader->setChecked(pref->isRSSEnabled());
|
||||||
actionSearch_engine->setChecked(pref->isSearchEnabled());
|
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);
|
actionNormalMessages->setChecked(flags & Log::NORMAL);
|
||||||
actionInformationMessages->setChecked(flags & Log::INFO);
|
actionInformationMessages->setChecked(flags & Log::INFO);
|
||||||
actionWarningMessages->setChecked(flags & Log::WARNING);
|
actionWarningMessages->setChecked(flags & Log::WARNING);
|
||||||
@ -382,6 +396,29 @@ MainWindow::~MainWindow()
|
|||||||
#endif
|
#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()
|
void MainWindow::addToolbarContextMenu()
|
||||||
{
|
{
|
||||||
const Preferences* const pref = Preferences::instance();
|
const Preferences* const pref = Preferences::instance();
|
||||||
@ -1522,7 +1559,7 @@ void MainWindow::on_actionExecutionLogs_triggered(bool checked)
|
|||||||
{
|
{
|
||||||
if (checked) {
|
if (checked) {
|
||||||
Q_ASSERT(!m_executionLog);
|
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"));
|
int index_tab = tabs->addTab(m_executionLog, tr("Execution Log"));
|
||||||
tabs->setTabIcon(index_tab, GuiIconProvider::instance()->getIcon("view-calendar-journal"));
|
tabs->setTabIcon(index_tab, GuiIconProvider::instance()->getIcon("view-calendar-journal"));
|
||||||
}
|
}
|
||||||
@ -1534,7 +1571,7 @@ void MainWindow::on_actionExecutionLogs_triggered(bool checked)
|
|||||||
actionInformationMessages->setEnabled(checked);
|
actionInformationMessages->setEnabled(checked);
|
||||||
actionWarningMessages->setEnabled(checked);
|
actionWarningMessages->setEnabled(checked);
|
||||||
actionCriticalMessages->setEnabled(checked);
|
actionCriticalMessages->setEnabled(checked);
|
||||||
Preferences::instance()->setExecutionLogEnabled(checked);
|
setExecutionLogEnabled(checked);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::on_actionNormalMessages_triggered(bool checked)
|
void MainWindow::on_actionNormalMessages_triggered(bool checked)
|
||||||
@ -1542,12 +1579,9 @@ void MainWindow::on_actionNormalMessages_triggered(bool checked)
|
|||||||
if (!m_executionLog)
|
if (!m_executionLog)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
Preferences* const pref = Preferences::instance();
|
Log::MsgTypes flags(executionLogMsgTypes());
|
||||||
|
|
||||||
Log::MsgTypes flags(pref->executionLogMessageTypes());
|
|
||||||
checked ? (flags |= Log::NORMAL) : (flags &= ~Log::NORMAL);
|
checked ? (flags |= Log::NORMAL) : (flags &= ~Log::NORMAL);
|
||||||
m_executionLog->showMsgTypes(flags);
|
setExecutionLogMsgTypes(flags);
|
||||||
pref->setExecutionLogMessageTypes(flags);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::on_actionInformationMessages_triggered(bool checked)
|
void MainWindow::on_actionInformationMessages_triggered(bool checked)
|
||||||
@ -1555,12 +1589,9 @@ void MainWindow::on_actionInformationMessages_triggered(bool checked)
|
|||||||
if (!m_executionLog)
|
if (!m_executionLog)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
Preferences* const pref = Preferences::instance();
|
Log::MsgTypes flags(executionLogMsgTypes());
|
||||||
|
|
||||||
Log::MsgTypes flags(pref->executionLogMessageTypes());
|
|
||||||
checked ? (flags |= Log::INFO) : (flags &= ~Log::INFO);
|
checked ? (flags |= Log::INFO) : (flags &= ~Log::INFO);
|
||||||
m_executionLog->showMsgTypes(flags);
|
setExecutionLogMsgTypes(flags);
|
||||||
pref->setExecutionLogMessageTypes(flags);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::on_actionWarningMessages_triggered(bool checked)
|
void MainWindow::on_actionWarningMessages_triggered(bool checked)
|
||||||
@ -1568,12 +1599,9 @@ void MainWindow::on_actionWarningMessages_triggered(bool checked)
|
|||||||
if (!m_executionLog)
|
if (!m_executionLog)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
Preferences* const pref = Preferences::instance();
|
Log::MsgTypes flags(executionLogMsgTypes());
|
||||||
|
|
||||||
Log::MsgTypes flags(pref->executionLogMessageTypes());
|
|
||||||
checked ? (flags |= Log::WARNING) : (flags &= ~Log::WARNING);
|
checked ? (flags |= Log::WARNING) : (flags &= ~Log::WARNING);
|
||||||
m_executionLog->showMsgTypes(flags);
|
setExecutionLogMsgTypes(flags);
|
||||||
pref->setExecutionLogMessageTypes(flags);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::on_actionCriticalMessages_triggered(bool checked)
|
void MainWindow::on_actionCriticalMessages_triggered(bool checked)
|
||||||
@ -1581,12 +1609,9 @@ void MainWindow::on_actionCriticalMessages_triggered(bool checked)
|
|||||||
if (!m_executionLog)
|
if (!m_executionLog)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
Preferences* const pref = Preferences::instance();
|
Log::MsgTypes flags(executionLogMsgTypes());
|
||||||
|
|
||||||
Log::MsgTypes flags(pref->executionLogMessageTypes());
|
|
||||||
checked ? (flags |= Log::CRITICAL) : (flags &= ~Log::CRITICAL);
|
checked ? (flags |= Log::CRITICAL) : (flags &= ~Log::CRITICAL);
|
||||||
m_executionLog->showMsgTypes(flags);
|
setExecutionLogMsgTypes(flags);
|
||||||
pref->setExecutionLogMessageTypes(flags);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::on_actionAutoExit_qBittorrent_toggled(bool enabled)
|
void MainWindow::on_actionAutoExit_qBittorrent_toggled(bool enabled)
|
||||||
|
@ -81,6 +81,12 @@ public:
|
|||||||
QMenu* getTrayIconMenu();
|
QMenu* getTrayIconMenu();
|
||||||
PropertiesWidget *getProperties() const { return properties; }
|
PropertiesWidget *getProperties() const { return properties; }
|
||||||
|
|
||||||
|
// ExecutionLog properties
|
||||||
|
bool isExecutionLogEnabled() const;
|
||||||
|
void setExecutionLogEnabled(bool value);
|
||||||
|
int executionLogMsgTypes() const;
|
||||||
|
void setExecutionLogMsgTypes(const int value);
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void trackerAuthenticationRequired(BitTorrent::TorrentHandle *const torrent);
|
void trackerAuthenticationRequired(BitTorrent::TorrentHandle *const torrent);
|
||||||
void setTabText(int index, QString text) const;
|
void setTabText(int index, QString text) const;
|
||||||
|
@ -42,6 +42,7 @@
|
|||||||
|
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
|
|
||||||
|
#include "app/application.h"
|
||||||
#include "base/preferences.h"
|
#include "base/preferences.h"
|
||||||
#include "base/utils/fs.h"
|
#include "base/utils/fs.h"
|
||||||
#include "base/scanfoldersmodel.h"
|
#include "base/scanfoldersmodel.h"
|
||||||
@ -444,13 +445,14 @@ void options_imp::saveOptions()
|
|||||||
checkAssociateMagnetLinks->setEnabled(!checkAssociateMagnetLinks->isChecked());
|
checkAssociateMagnetLinks->setEnabled(!checkAssociateMagnetLinks->isChecked());
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
pref->setFileLogEnabled(checkFileLog->isChecked());
|
Application * const app = static_cast<Application*>(QCoreApplication::instance());
|
||||||
pref->setFileLogPath(Utils::Fs::fromNativePath(textFileLogPath->text()));
|
app->setFileLoggerPath(Utils::Fs::fromNativePath(textFileLogPath->text()));
|
||||||
pref->setFileLogBackup(checkFileLogBackup->isChecked());
|
app->setFileLoggerBackup(checkFileLogBackup->isChecked());
|
||||||
pref->setFileLogMaxSize(spinFileLogSize->value());
|
app->setFileLoggerMaxSize(spinFileLogSize->value());
|
||||||
pref->setFileLogDeleteOld(checkFileLogDelete->isChecked());
|
app->setFileLoggerAge(spinFileLogAge->value());
|
||||||
pref->setFileLogAge(spinFileLogAge->value());
|
app->setFileLoggerAgeType(comboFileLogAgeType->currentIndex());
|
||||||
pref->setFileLogAgeType(comboFileLogAgeType->currentIndex());
|
app->setFileLoggerDeleteOld(checkFileLogDelete->isChecked());
|
||||||
|
app->setFileLoggerEnabled(checkFileLog->isChecked());
|
||||||
// End General preferences
|
// End General preferences
|
||||||
|
|
||||||
auto session = BitTorrent::Session::instance();
|
auto session = BitTorrent::Session::instance();
|
||||||
@ -641,18 +643,19 @@ void options_imp::loadOptions()
|
|||||||
checkAssociateMagnetLinks->setEnabled(!checkAssociateMagnetLinks->isChecked());
|
checkAssociateMagnetLinks->setEnabled(!checkAssociateMagnetLinks->isChecked());
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
checkFileLog->setChecked(pref->fileLogEnabled());
|
const Application * const app = static_cast<Application*>(QCoreApplication::instance());
|
||||||
textFileLogPath->setText(Utils::Fs::toNativePath(pref->fileLogPath()));
|
checkFileLog->setChecked(app->isFileLoggerEnabled());
|
||||||
fileLogBackup = pref->fileLogBackup();
|
textFileLogPath->setText(Utils::Fs::toNativePath(app->fileLoggerPath()));
|
||||||
|
fileLogBackup = app->isFileLoggerBackup();
|
||||||
checkFileLogBackup->setChecked(fileLogBackup);
|
checkFileLogBackup->setChecked(fileLogBackup);
|
||||||
spinFileLogSize->setEnabled(fileLogBackup);
|
spinFileLogSize->setEnabled(fileLogBackup);
|
||||||
fileLogDelete = pref->fileLogDeleteOld();
|
fileLogDelete = app->isFileLoggerDeleteOld();
|
||||||
checkFileLogDelete->setChecked(fileLogDelete);
|
checkFileLogDelete->setChecked(fileLogDelete);
|
||||||
spinFileLogAge->setEnabled(fileLogDelete);
|
spinFileLogAge->setEnabled(fileLogDelete);
|
||||||
comboFileLogAgeType->setEnabled(fileLogDelete);
|
comboFileLogAgeType->setEnabled(fileLogDelete);
|
||||||
spinFileLogSize->setValue(pref->fileLogMaxSize());
|
spinFileLogSize->setValue(app->fileLoggerMaxSize());
|
||||||
spinFileLogAge->setValue(pref->fileLogAge());
|
spinFileLogAge->setValue(app->fileLoggerAge());
|
||||||
comboFileLogAgeType->setCurrentIndex(pref->fileLogAgeType());
|
comboFileLogAgeType->setCurrentIndex(app->fileLoggerAgeType());
|
||||||
// End General preferences
|
// End General preferences
|
||||||
|
|
||||||
auto session = BitTorrent::Session::instance();
|
auto session = BitTorrent::Session::instance();
|
||||||
|
Loading…
Reference in New Issue
Block a user