Use SettingsStorage instead.

This commit is contained in:
sledgehammer999
2016-03-14 14:39:13 +02:00
parent 663791fac2
commit d721939d5f
12 changed files with 262 additions and 228 deletions

View File

@@ -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"));

View File

@@ -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();

View File

@@ -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)

View File

@@ -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;

View File

@@ -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();