Merge branch 'apa420-logging'

This commit is contained in:
Rasmus Karlsson 2018-06-05 15:19:54 +02:00
commit 147e55e5a7
4 changed files with 72 additions and 3 deletions

View file

@ -39,11 +39,26 @@ void LoggingManager::addMessage(const QString &channelName, messages::MessagePtr
QString LoggingManager::getDirectoryForChannel(const QString &channelName) QString LoggingManager::getDirectoryForChannel(const QString &channelName)
{ {
auto customPath = getApp()->settings->logPath;
if (channelName.startsWith("/whispers")) { if (channelName.startsWith("/whispers")) {
if (customPath != "")
return customPath + "/Whispers";
return this->pathManager->whispersLogsFolderPath; return this->pathManager->whispersLogsFolderPath;
} else if (channelName.startsWith("/mentions")) { } else if (channelName.startsWith("/mentions")) {
if (customPath != "")
return customPath + "/Mentions";
return this->pathManager->mentionsLogsFolderPath; return this->pathManager->mentionsLogsFolderPath;
} else { } 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() + QString logPath(this->pathManager->channelsLogsFolderPath + QDir::separator() +
channelName); channelName);
@ -55,5 +70,12 @@ QString LoggingManager::getDirectoryForChannel(const QString &channelName)
} }
} }
void LoggingManager::refreshLoggingPath()
{
// if (app->settings->logPath == "") {
//}
}
} // namespace singletons } // namespace singletons
} // namespace chatterino } // namespace chatterino

View file

@ -7,7 +7,6 @@
namespace chatterino { namespace chatterino {
namespace singletons { namespace singletons {
class PathManager; class PathManager;
class LoggingManager class LoggingManager
@ -23,6 +22,8 @@ public:
void addMessage(const QString &channelName, messages::MessagePtr message); void addMessage(const QString &channelName, messages::MessagePtr message);
void refreshLoggingPath();
private: private:
std::map<QString, std::unique_ptr<LoggingChannel>> loggingChannels; std::map<QString, std::unique_ptr<LoggingChannel>> loggingChannels;
QString getDirectoryForChannel(const QString &channelName); QString getDirectoryForChannel(const QString &channelName);

View file

@ -105,6 +105,9 @@ public:
/// Logging /// Logging
BoolSetting enableLogging = {"/logging/enabled", false}; BoolSetting enableLogging = {"/logging/enabled", false};
QStringSetting logPath = {"/logging/path",
QStandardPaths::writableLocation(QStandardPaths::AppDataLocation)};
QStringSetting pathHighlightSound = {"/highlighting/highlightSoundPath", QStringSetting pathHighlightSound = {"/highlighting/highlightSoundPath",
"qrc:/sounds/ping2.wav"}; "qrc:/sounds/ping2.wav"};
QStringSetting highlightUserBlacklist = {"/highlighting/blacklistedUsers", ""}; QStringSetting highlightUserBlacklist = {"/highlighting/blacklistedUsers", ""};

View file

@ -3,6 +3,7 @@
#include "application.hpp" #include "application.hpp"
#include "controllers/taggedusers/taggeduserscontroller.hpp" #include "controllers/taggedusers/taggeduserscontroller.hpp"
#include "controllers/taggedusers/taggedusersmodel.hpp" #include "controllers/taggedusers/taggedusersmodel.hpp"
#include "singletons/loggingmanager.hpp"
#include "singletons/pathmanager.hpp" #include "singletons/pathmanager.hpp"
#include "util/layoutcreator.hpp" #include "util/layoutcreator.hpp"
#include "widgets/helper/editablemodelview.hpp" #include "widgets/helper/editablemodelview.hpp"
@ -42,10 +43,15 @@ ModerationPage::ModerationPage()
auto logs = tabs.appendTab(new QVBoxLayout, "Logs"); auto logs = tabs.appendTab(new QVBoxLayout, "Logs");
{ {
auto logPath = app->paths->logsFolderPath; // Logs (copied from LoggingMananger)
auto created = logs.emplace<QLabel>(); auto created = logs.emplace<QLabel>();
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->setTextFormat(Qt::RichText);
created->setTextInteractionFlags(Qt::TextBrowserInteraction | created->setTextInteractionFlags(Qt::TextBrowserInteraction |
Qt::LinksAccessibleByKeyboard | Qt::LinksAccessibleByKeyboard |
@ -54,6 +60,43 @@ ModerationPage::ModerationPage()
logs.append(this->createCheckBox("Enable logging", app->settings->enableLogging)); logs.append(this->createCheckBox("Enable logging", app->settings->enableLogging));
logs->addStretch(1); logs->addStretch(1);
auto selectDir = logs.emplace<QPushButton>("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;
created->setText("Logs are saved to " + CreateLink(dirName, true));
}
app->settings->logPath = dirName;
dirMemory = dirName;
app->logging->refreshLoggingPath();
});
// Reset custom logpath
auto resetDir = logs.emplace<QPushButton>("Reset logpath");
QObject::connect(
resetDir.getElement(), &QPushButton::clicked, this, [this, created, app]() mutable {
app->settings->logPath = "";
created->setText(
"Logs are saved to " +
CreateLink(QStandardPaths::writableLocation(QStandardPaths::AppDataLocation),
true));
app->logging->refreshLoggingPath();
});
// Logs end
} }
auto modMode = tabs.appendTab(new QVBoxLayout, "Moderation mode"); auto modMode = tabs.appendTab(new QVBoxLayout, "Moderation mode");