From 26a0d5bc263a7d4de4daae3de1da850505f0ef65 Mon Sep 17 00:00:00 2001 From: apa420 Date: Tue, 15 May 2018 19:44:58 +0200 Subject: [PATCH 1/3] Added the functionality of having logs in custom folders as well as resetting the custom path to default. --- src/singletons/loggingmanager.cpp | 22 +++++++++ src/singletons/loggingmanager.hpp | 3 +- src/singletons/settingsmanager.hpp | 4 ++ src/widgets/settingspages/moderationpage.cpp | 48 +++++++++++++++++++- 4 files changed, 74 insertions(+), 3 deletions(-) diff --git a/src/singletons/loggingmanager.cpp b/src/singletons/loggingmanager.cpp index c03009702..c921ddc66 100644 --- a/src/singletons/loggingmanager.cpp +++ b/src/singletons/loggingmanager.cpp @@ -39,11 +39,26 @@ void LoggingManager::addMessage(const QString &channelName, messages::MessagePtr QString LoggingManager::getDirectoryForChannel(const QString &channelName) { + auto customPath = getApp()->settings->logPath; + if (channelName.startsWith("/whispers")) { + if (customPath != "") + return customPath + "/Whispers"; return this->pathManager->whispersLogsFolderPath; } else if (channelName.startsWith("/mentions")) { + if (customPath != "") + return customPath + "/Mentions"; return this->pathManager->mentionsLogsFolderPath; } else { + if (customPath != "") { + QString logPath(customPath + QDir::separator() + channelName); + + if (!this->pathManager->createFolder(logPath)) { + debug::Log("Error creating channel logs folder for channel {}", channelName); + } + + return logPath; + } QString logPath(this->pathManager->channelsLogsFolderPath + QDir::separator() + channelName); @@ -55,5 +70,12 @@ QString LoggingManager::getDirectoryForChannel(const QString &channelName) } } +void LoggingManager::refreshLoggingPath() +{ + // if (app->settings->logPath == "") { + + //} +} + } // namespace singletons } // namespace chatterino diff --git a/src/singletons/loggingmanager.hpp b/src/singletons/loggingmanager.hpp index 30681ce62..b7e2d91c3 100644 --- a/src/singletons/loggingmanager.hpp +++ b/src/singletons/loggingmanager.hpp @@ -7,7 +7,6 @@ namespace chatterino { namespace singletons { - class PathManager; class LoggingManager @@ -23,6 +22,8 @@ public: void addMessage(const QString &channelName, messages::MessagePtr message); + void refreshLoggingPath(); + private: std::map> loggingChannels; QString getDirectoryForChannel(const QString &channelName); diff --git a/src/singletons/settingsmanager.hpp b/src/singletons/settingsmanager.hpp index f9b2fcbdd..e3eaf8523 100644 --- a/src/singletons/settingsmanager.hpp +++ b/src/singletons/settingsmanager.hpp @@ -101,6 +101,10 @@ public: /// Logging BoolSetting enableLogging = {"/logging/enabled", false}; + BoolSetting customLogPath = {"/logging/customPath", false}; + + QStringSetting logPath = {"/logging/path", ""}; + QStringSetting pathHighlightSound = {"/highlighting/highlightSoundPath", "qrc:/sounds/ping2.wav"}; QStringSetting highlightUserBlacklist = {"/highlighting/blacklistedUsers", ""}; diff --git a/src/widgets/settingspages/moderationpage.cpp b/src/widgets/settingspages/moderationpage.cpp index 81faa01bd..cad7a5c85 100644 --- a/src/widgets/settingspages/moderationpage.cpp +++ b/src/widgets/settingspages/moderationpage.cpp @@ -1,6 +1,7 @@ #include "moderationpage.hpp" #include "application.hpp" +#include "singletons/loggingmanager.hpp" #include "singletons/pathmanager.hpp" #include "util/layoutcreator.hpp" @@ -35,10 +36,14 @@ ModerationPage::ModerationPage() auto layout = layoutCreator.setLayoutType(); { // Logs (copied from LoggingMananger) - auto logPath = app->paths->logsFolderPath; auto created = layout.emplace(); - created->setText("Logs are saved to " + CreateLink(logPath, true)); + if (app->settings->logPath == "") { + created->setText("Logs are saved to " + + CreateLink(QCoreApplication::applicationDirPath(), true)); + } else { + created->setText("Logs are saved to " + CreateLink(app->settings->logPath, true)); + } created->setTextFormat(Qt::RichText); created->setTextInteractionFlags(Qt::TextBrowserInteraction | Qt::LinksAccessibleByKeyboard | @@ -47,6 +52,45 @@ ModerationPage::ModerationPage() layout.append(this->createCheckBox("Enable logging", app->settings->enableLogging)); layout->addStretch(1); + + auto selectDir = layout.emplace("Logs"); + + QObject::connect( + selectDir.getElement(), &QPushButton::clicked, this, + [ this, created, app, dirMemory = QString{app->settings->logPath} ]() mutable { + auto dirName = QFileDialog::getExistingDirectory(); + + created->setText("Logs are saved to " + CreateLink(dirName, true)); + app->settings->customLogPath = true; + if (dirName == "" && dirMemory == "") { + created->setText("Logs are saved to " + + CreateLink(QCoreApplication::applicationDirPath(), true)); + app->settings->customLogPath = false; + } else if (dirName == "") { + dirName = dirMemory; + created->setText("Logs are saved to " + CreateLink(dirName, true)); + } + app->settings->logPath = dirName; + + qDebug() << "dirMemory" << dirMemory; + qDebug() << "dirName" << dirName; + qDebug() << app->settings->logPath.getValue(); + qDebug() << app->settings->customLogPath.getValue(); + + dirMemory = dirName; + app->logging->refreshLoggingPath(); + + }); + auto resetDir = layout.emplace("Reset logpath"); + QObject::connect( + resetDir.getElement(), &QPushButton::clicked, this, [this, created, app]() mutable { + app->settings->logPath = ""; + created->setText("Logs are saved to " + + CreateLink(QCoreApplication::applicationDirPath(), true)); + app->settings->customLogPath = false; + app->logging->refreshLoggingPath(); + }); + // Logs end // clang-format off From 3157b10ef24aab5c3a4783b643e4c7472b59c7c1 Mon Sep 17 00:00:00 2001 From: apa420 Date: Wed, 16 May 2018 01:39:08 +0200 Subject: [PATCH 2/3] fixed some functionality, cleaned up and removed an unused QBoolSetting --- src/singletons/settingsmanager.hpp | 5 +- src/widgets/settingspages/moderationpage.cpp | 50 ++++++++++---------- 2 files changed, 26 insertions(+), 29 deletions(-) diff --git a/src/singletons/settingsmanager.hpp b/src/singletons/settingsmanager.hpp index e3eaf8523..acf65d742 100644 --- a/src/singletons/settingsmanager.hpp +++ b/src/singletons/settingsmanager.hpp @@ -101,9 +101,8 @@ public: /// Logging BoolSetting enableLogging = {"/logging/enabled", false}; - BoolSetting customLogPath = {"/logging/customPath", false}; - - QStringSetting logPath = {"/logging/path", ""}; + QStringSetting logPath = {"/logging/path", + QStandardPaths::writableLocation(QStandardPaths::AppDataLocation)}; QStringSetting pathHighlightSound = {"/highlighting/highlightSoundPath", "qrc:/sounds/ping2.wav"}; diff --git a/src/widgets/settingspages/moderationpage.cpp b/src/widgets/settingspages/moderationpage.cpp index cad7a5c85..65ccb3f94 100644 --- a/src/widgets/settingspages/moderationpage.cpp +++ b/src/widgets/settingspages/moderationpage.cpp @@ -53,41 +53,39 @@ ModerationPage::ModerationPage() layout->addStretch(1); - auto selectDir = layout.emplace("Logs"); + auto selectDir = layout.emplace("Set custom logpath"); - QObject::connect( - selectDir.getElement(), &QPushButton::clicked, this, - [ this, created, app, dirMemory = QString{app->settings->logPath} ]() mutable { - auto dirName = QFileDialog::getExistingDirectory(); + // Setting custom logpath + QObject::connect(selectDir.getElement(), &QPushButton::clicked, this, [ + this, created, app, dirMemory = QString{app->settings->logPath} + ]() mutable { + auto dirName = QFileDialog::getExistingDirectory(this); + created->setText("Logs are saved to " + CreateLink(dirName, true)); + if (dirName == "" && dirMemory == "") { + created->setText( + "Logs are saved to " + + CreateLink(QStandardPaths::writableLocation(QStandardPaths::AppDataLocation), + true)); + } else if (dirName == "") { + dirName = dirMemory; created->setText("Logs are saved to " + CreateLink(dirName, true)); - app->settings->customLogPath = true; - if (dirName == "" && dirMemory == "") { - created->setText("Logs are saved to " + - CreateLink(QCoreApplication::applicationDirPath(), true)); - app->settings->customLogPath = false; - } else if (dirName == "") { - dirName = dirMemory; - created->setText("Logs are saved to " + CreateLink(dirName, true)); - } - app->settings->logPath = dirName; + } - qDebug() << "dirMemory" << dirMemory; - qDebug() << "dirName" << dirName; - qDebug() << app->settings->logPath.getValue(); - qDebug() << app->settings->customLogPath.getValue(); + app->settings->logPath = dirName; + dirMemory = dirName; + app->logging->refreshLoggingPath(); - dirMemory = dirName; - app->logging->refreshLoggingPath(); - - }); + }); + // Reset custom logpath auto resetDir = layout.emplace("Reset logpath"); QObject::connect( resetDir.getElement(), &QPushButton::clicked, this, [this, created, app]() mutable { app->settings->logPath = ""; - created->setText("Logs are saved to " + - CreateLink(QCoreApplication::applicationDirPath(), true)); - app->settings->customLogPath = false; + created->setText( + "Logs are saved to " + + CreateLink(QStandardPaths::writableLocation(QStandardPaths::AppDataLocation), + true)); app->logging->refreshLoggingPath(); }); From 3c3abba20210ad41e5a9f5f83f4ec923434ec519 Mon Sep 17 00:00:00 2001 From: Rasmus Karlsson Date: Tue, 5 Jun 2018 15:19:39 +0200 Subject: [PATCH 3/3] Fix some compilation errors caused by an incorrect merge --- src/widgets/settingspages/moderationpage.cpp | 42 ++++++++++---------- 1 file changed, 20 insertions(+), 22 deletions(-) diff --git a/src/widgets/settingspages/moderationpage.cpp b/src/widgets/settingspages/moderationpage.cpp index 29a154b19..2c428ade7 100644 --- a/src/widgets/settingspages/moderationpage.cpp +++ b/src/widgets/settingspages/moderationpage.cpp @@ -1,9 +1,9 @@ #include "moderationpage.hpp" #include "application.hpp" -#include "singletons/loggingmanager.hpp" #include "controllers/taggedusers/taggeduserscontroller.hpp" #include "controllers/taggedusers/taggedusersmodel.hpp" +#include "singletons/loggingmanager.hpp" #include "singletons/pathmanager.hpp" #include "util/layoutcreator.hpp" #include "widgets/helper/editablemodelview.hpp" @@ -59,35 +59,33 @@ ModerationPage::ModerationPage() created->setOpenExternalLinks(true); logs.append(this->createCheckBox("Enable logging", app->settings->enableLogging)); -< logs->addStretch(1); - auto selectDir = layout.emplace("Set custom logpath"); + auto selectDir = logs.emplace("Set custom logpath"); // Setting custom logpath - QObject::connect(selectDir.getElement(), &QPushButton::clicked, this, [ - this, created, app, dirMemory = QString{app->settings->logPath} - ]() mutable { - auto dirName = QFileDialog::getExistingDirectory(this); - created->setText("Logs are saved to " + CreateLink(dirName, true)); - - if (dirName == "" && dirMemory == "") { - created->setText( - "Logs are saved to " + - CreateLink(QStandardPaths::writableLocation(QStandardPaths::AppDataLocation), - true)); - } else if (dirName == "") { - dirName = dirMemory; + QObject::connect( + selectDir.getElement(), &QPushButton::clicked, this, + [this, created, app, dirMemory = QString{app->settings->logPath}]() mutable { + auto dirName = QFileDialog::getExistingDirectory(this); created->setText("Logs are saved to " + CreateLink(dirName, true)); - } - app->settings->logPath = dirName; - dirMemory = dirName; - app->logging->refreshLoggingPath(); + if (dirName == "" && dirMemory == "") { + created->setText("Logs are saved to " + + CreateLink(QStandardPaths::writableLocation( + QStandardPaths::AppDataLocation), + true)); + } else if (dirName == "") { + dirName = dirMemory; + created->setText("Logs are saved to " + CreateLink(dirName, true)); + } - }); + app->settings->logPath = dirName; + dirMemory = dirName; + app->logging->refreshLoggingPath(); + }); // Reset custom logpath - auto resetDir = layout.emplace("Reset logpath"); + auto resetDir = logs.emplace("Reset logpath"); QObject::connect( resetDir.getElement(), &QPushButton::clicked, this, [this, created, app]() mutable { app->settings->logPath = "";