mirror of
https://github.com/Chatterino/chatterino2.git
synced 2024-11-21 22:24:07 +01:00
Add ability to customize cache folder
Add an advanced settings page, currently only housing the "Cache" category Fix #541
This commit is contained in:
parent
3fc91bded5
commit
a07255be2d
9 changed files with 133 additions and 14 deletions
|
@ -253,7 +253,8 @@ SOURCES += \
|
|||
src/widgets/helper/Button.cpp \
|
||||
src/messages/MessageContainer.cpp \
|
||||
src/debug/Benchmark.cpp \
|
||||
src/common/UsernameSet.cpp
|
||||
src/common/UsernameSet.cpp \
|
||||
src/widgets/settingspages/AdvancedPage.cpp
|
||||
|
||||
HEADERS += \
|
||||
src/Application.hpp \
|
||||
|
@ -449,7 +450,8 @@ HEADERS += \
|
|||
src/util/LayoutHelper.hpp \
|
||||
src/widgets/helper/Button.hpp \
|
||||
src/messages/MessageContainer.hpp \
|
||||
src/common/UsernameSet.hpp
|
||||
src/common/UsernameSet.hpp \
|
||||
src/widgets/settingspages/AdvancedPage.hpp
|
||||
|
||||
RESOURCES += \
|
||||
resources/resources.qrc \
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
#include "common/NetworkData.hpp"
|
||||
|
||||
#include "Application.hpp"
|
||||
#include "singletons/Paths.hpp"
|
||||
#include "util/DebugCount.hpp"
|
||||
|
||||
|
@ -42,9 +41,7 @@ QString NetworkData::getHash()
|
|||
void NetworkData::writeToCache(const QByteArray &bytes)
|
||||
{
|
||||
if (this->useQuickLoadCache_) {
|
||||
auto app = getApp();
|
||||
|
||||
QFile cachedFile(getPaths()->cacheDirectory + "/" + this->getHash());
|
||||
QFile cachedFile(getPaths()->cacheDirectory() + "/" + this->getHash());
|
||||
|
||||
if (cachedFile.open(QIODevice::WriteOnly)) {
|
||||
cachedFile.write(bytes);
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
#include "common/NetworkRequest.hpp"
|
||||
|
||||
#include "Application.hpp"
|
||||
#include "common/NetworkData.hpp"
|
||||
#include "common/NetworkManager.hpp"
|
||||
#include "common/Outcome.hpp"
|
||||
|
@ -11,6 +10,7 @@
|
|||
|
||||
#include <QFile>
|
||||
#include <QtConcurrent>
|
||||
|
||||
#include <cassert>
|
||||
|
||||
namespace chatterino {
|
||||
|
@ -145,9 +145,8 @@ void NetworkRequest::execute()
|
|||
|
||||
Outcome NetworkRequest::tryLoadCachedFile()
|
||||
{
|
||||
auto app = getApp();
|
||||
|
||||
QFile cachedFile(getPaths()->cacheDirectory + "/" + this->data->getHash());
|
||||
QFile cachedFile(getPaths()->cacheDirectory() + "/" +
|
||||
this->data->getHash());
|
||||
|
||||
if (!cachedFile.exists()) {
|
||||
// File didn't exist
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
#include "singletons/Paths.hpp"
|
||||
|
||||
#include "singletons/Settings.hpp"
|
||||
|
||||
#include <QCoreApplication>
|
||||
#include <QCryptographicHash>
|
||||
#include <QDir>
|
||||
|
@ -33,6 +35,27 @@ bool Paths::isPortable()
|
|||
return this->portable_.get();
|
||||
}
|
||||
|
||||
QString Paths::cacheDirectory()
|
||||
{
|
||||
static QStringSetting cachePathSetting = [] {
|
||||
QStringSetting cachePathSetting("/cache/path");
|
||||
|
||||
cachePathSetting.connect([](const auto &newPath, auto) {
|
||||
QDir().mkpath(newPath); //
|
||||
});
|
||||
|
||||
return cachePathSetting;
|
||||
}();
|
||||
|
||||
auto path = cachePathSetting.getValue();
|
||||
|
||||
if (path == "") {
|
||||
return this->cacheDirectory_;
|
||||
}
|
||||
|
||||
return path;
|
||||
}
|
||||
|
||||
void Paths::initAppFilePathHash()
|
||||
{
|
||||
this->applicationFilePathHash =
|
||||
|
@ -104,7 +127,7 @@ void Paths::initSubDirectories()
|
|||
|
||||
makePath("");
|
||||
this->settingsDirectory = makePath("Settings");
|
||||
this->cacheDirectory = makePath("Cache");
|
||||
this->cacheDirectory_ = makePath("Cache");
|
||||
this->messageLogDirectory = makePath("Logs");
|
||||
this->miscDirectory = makePath("Misc");
|
||||
}
|
||||
|
|
|
@ -19,9 +19,6 @@ public:
|
|||
// Directory for settings files. Same as <appDataDirectory>/Settings
|
||||
QString settingsDirectory;
|
||||
|
||||
// Directory for cache files. Same as <appDataDirectory>/Misc
|
||||
QString cacheDirectory;
|
||||
|
||||
// Directory for message log files. Same as <appDataDirectory>/Misc
|
||||
QString messageLogDirectory;
|
||||
|
||||
|
@ -34,6 +31,8 @@ public:
|
|||
bool createFolder(const QString &folderPath);
|
||||
bool isPortable();
|
||||
|
||||
QString cacheDirectory();
|
||||
|
||||
private:
|
||||
void initAppFilePathHash();
|
||||
void initCheckPortable();
|
||||
|
@ -41,6 +40,9 @@ private:
|
|||
void initSubDirectories();
|
||||
|
||||
boost::optional<bool> portable_;
|
||||
|
||||
// Directory for cache files. Same as <appDataDirectory>/Misc
|
||||
QString cacheDirectory_;
|
||||
};
|
||||
|
||||
Paths *getPaths();
|
||||
|
|
|
@ -153,6 +153,8 @@ public:
|
|||
IntSetting startUpNotification = {"/misc/startUpNotification", 0};
|
||||
QStringSetting currentVersion = {"/misc/currentVersion", ""};
|
||||
|
||||
QStringSetting cachePath = {"/cache/path", ""};
|
||||
|
||||
void saveSnapshot();
|
||||
void restoreSnapshot();
|
||||
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
#include "widgets/helper/SettingsDialogTab.hpp"
|
||||
#include "widgets/settingspages/AboutPage.hpp"
|
||||
#include "widgets/settingspages/AccountsPage.hpp"
|
||||
#include "widgets/settingspages/AdvancedPage.hpp"
|
||||
#include "widgets/settingspages/BrowserExtensionPage.hpp"
|
||||
#include "widgets/settingspages/CommandPage.hpp"
|
||||
#include "widgets/settingspages/EmotesPage.hpp"
|
||||
|
@ -103,6 +104,7 @@ void SettingsDialog::addTabs()
|
|||
// this->addTab(new SpecialChannelsPage);
|
||||
this->addTab(new BrowserExtensionPage);
|
||||
this->addTab(new ExternalToolsPage);
|
||||
this->addTab(new AdvancedPage);
|
||||
|
||||
this->ui_.tabContainer->addStretch(1);
|
||||
this->addTab(new AboutPage, Qt::AlignBottom);
|
||||
|
|
79
src/widgets/settingspages/AdvancedPage.cpp
Normal file
79
src/widgets/settingspages/AdvancedPage.cpp
Normal file
|
@ -0,0 +1,79 @@
|
|||
#include "AdvancedPage.hpp"
|
||||
|
||||
#include "Application.hpp"
|
||||
#include "controllers/taggedusers/TaggedUsersController.hpp"
|
||||
#include "controllers/taggedusers/TaggedUsersModel.hpp"
|
||||
#include "singletons/Logging.hpp"
|
||||
#include "singletons/Paths.hpp"
|
||||
#include "util/Helpers.hpp"
|
||||
#include "util/LayoutCreator.hpp"
|
||||
|
||||
#include <QFileDialog>
|
||||
#include <QFormLayout>
|
||||
#include <QGroupBox>
|
||||
#include <QHBoxLayout>
|
||||
#include <QHeaderView>
|
||||
#include <QLabel>
|
||||
#include <QListView>
|
||||
#include <QPushButton>
|
||||
#include <QTableView>
|
||||
#include <QTextEdit>
|
||||
#include <QVBoxLayout>
|
||||
#include <QtConcurrent/QtConcurrent>
|
||||
|
||||
namespace chatterino {
|
||||
|
||||
AdvancedPage::AdvancedPage()
|
||||
: SettingsPage("Advanced", "")
|
||||
{
|
||||
auto app = getApp();
|
||||
LayoutCreator<AdvancedPage> layoutCreator(this);
|
||||
|
||||
auto tabs = layoutCreator.emplace<QTabWidget>();
|
||||
|
||||
{
|
||||
auto layout = tabs.appendTab(new QVBoxLayout, "Cache");
|
||||
auto folderLabel = layout.emplace<QLabel>();
|
||||
|
||||
folderLabel->setTextFormat(Qt::RichText);
|
||||
folderLabel->setTextInteractionFlags(Qt::TextBrowserInteraction |
|
||||
Qt::LinksAccessibleByKeyboard |
|
||||
Qt::LinksAccessibleByKeyboard);
|
||||
folderLabel->setOpenExternalLinks(true);
|
||||
|
||||
getSettings()->cachePath.connect([folderLabel](const auto &,
|
||||
auto) mutable {
|
||||
QString newPath = getPaths()->cacheDirectory();
|
||||
|
||||
QString pathShortened = "Cache saved at <a href=\"file:///" +
|
||||
newPath +
|
||||
"\"><span style=\"color: white;\">" +
|
||||
shortenString(newPath, 50) + "</span></a>";
|
||||
|
||||
folderLabel->setText(pathShortened);
|
||||
folderLabel->setToolTip(newPath);
|
||||
});
|
||||
|
||||
layout->addStretch(1);
|
||||
|
||||
auto selectDir = layout.emplace<QPushButton>("Set custom cache folder");
|
||||
|
||||
QObject::connect(
|
||||
selectDir.getElement(), &QPushButton::clicked, this, [this] {
|
||||
auto dirName = QFileDialog::getExistingDirectory(this);
|
||||
|
||||
getSettings()->cachePath = dirName;
|
||||
});
|
||||
|
||||
auto resetDir =
|
||||
layout.emplace<QPushButton>("Reset custom cache folder");
|
||||
QObject::connect(resetDir.getElement(), &QPushButton::clicked, this,
|
||||
[]() mutable {
|
||||
getSettings()->cachePath = ""; //
|
||||
});
|
||||
|
||||
// Logs end
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace chatterino
|
13
src/widgets/settingspages/AdvancedPage.hpp
Normal file
13
src/widgets/settingspages/AdvancedPage.hpp
Normal file
|
@ -0,0 +1,13 @@
|
|||
#pragma once
|
||||
|
||||
#include "widgets/settingspages/SettingsPage.hpp"
|
||||
|
||||
namespace chatterino {
|
||||
|
||||
class AdvancedPage : public SettingsPage
|
||||
{
|
||||
public:
|
||||
AdvancedPage();
|
||||
};
|
||||
|
||||
} // namespace chatterino
|
Loading…
Reference in a new issue