mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-06-27 17:13:54 -07:00
Allow toggling between caching methods.
Took 1 hour 30 minutes Took 9 seconds
This commit is contained in:
parent
b1286866dd
commit
c8c7dcba5f
7 changed files with 138 additions and 35 deletions
|
|
@ -1,5 +1,6 @@
|
||||||
#include "cache_settings.h"
|
#include "cache_settings.h"
|
||||||
|
|
||||||
|
#include "../../interface/card_picture_loader/card_picture_loader_cache_method.h"
|
||||||
#include "../../interface/card_picture_loader/card_picture_loader_local_schemes.h"
|
#include "../../interface/card_picture_loader/card_picture_loader_local_schemes.h"
|
||||||
#include "../network/update/client/release_channel.h"
|
#include "../network/update/client/release_channel.h"
|
||||||
#include "card_counter_settings.h"
|
#include "card_counter_settings.h"
|
||||||
|
|
@ -265,7 +266,11 @@ SettingsCache::SettingsCache()
|
||||||
|
|
||||||
networkCacheSize = settings->value("personal/networkCacheSize", NETWORK_CACHE_SIZE_DEFAULT).toInt();
|
networkCacheSize = settings->value("personal/networkCacheSize", NETWORK_CACHE_SIZE_DEFAULT).toInt();
|
||||||
redirectCacheTtl = settings->value("personal/redirectCacheTtl", NETWORK_REDIRECT_CACHE_TTL_DEFAULT).toInt();
|
redirectCacheTtl = settings->value("personal/redirectCacheTtl", NETWORK_REDIRECT_CACHE_TTL_DEFAULT).toInt();
|
||||||
saveCardImagesToLocalStorage = settings->value("personal/saveCardImagesToLocalStorage", true).toBool();
|
cardPictureLoaderCacheMethod =
|
||||||
|
settings
|
||||||
|
->value("personal/cardPictureLoaderCacheMethod",
|
||||||
|
static_cast<int>(CardPictureLoaderCacheMethod::CacheMethod::NETWORK_CACHE))
|
||||||
|
.toInt();
|
||||||
localCardImageStorageNamingScheme =
|
localCardImageStorageNamingScheme =
|
||||||
settings
|
settings
|
||||||
->value("personal/localCardImageStorageNamingScheme",
|
->value("personal/localCardImageStorageNamingScheme",
|
||||||
|
|
@ -1104,6 +1109,13 @@ void SettingsCache::setPixmapCacheSize(const int _pixmapCacheSize)
|
||||||
emit pixmapCacheSizeChanged(pixmapCacheSize);
|
emit pixmapCacheSizeChanged(pixmapCacheSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void SettingsCache::setCardImageCacheMethod(const CardPictureLoaderCacheMethod::CacheMethod _cardImageCachingMethod)
|
||||||
|
{
|
||||||
|
cardPictureLoaderCacheMethod = static_cast<int>(_cardImageCachingMethod);
|
||||||
|
settings->setValue("personal/cardPictureLoaderCacheMethod", cardPictureLoaderCacheMethod);
|
||||||
|
emit cardPictureLoaderCacheMethodChanged(cardPictureLoaderCacheMethod);
|
||||||
|
}
|
||||||
|
|
||||||
void SettingsCache::setNetworkCacheSizeInMB(const int _networkCacheSize)
|
void SettingsCache::setNetworkCacheSizeInMB(const int _networkCacheSize)
|
||||||
{
|
{
|
||||||
networkCacheSize = _networkCacheSize;
|
networkCacheSize = _networkCacheSize;
|
||||||
|
|
@ -1118,13 +1130,6 @@ void SettingsCache::setNetworkRedirectCacheTtl(const int _redirectCacheTtl)
|
||||||
emit redirectCacheTtlChanged(redirectCacheTtl);
|
emit redirectCacheTtlChanged(redirectCacheTtl);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SettingsCache::setSaveCardImagesToLocalStorage(QT_STATE_CHANGED_T _saveCardImagesToLocalStorage)
|
|
||||||
{
|
|
||||||
saveCardImagesToLocalStorage = _saveCardImagesToLocalStorage;
|
|
||||||
settings->setValue("personal/saveCardImagesToLocalStorage", saveCardImagesToLocalStorage);
|
|
||||||
emit saveCardImagesToLocalStorageChanged(saveCardImagesToLocalStorage);
|
|
||||||
}
|
|
||||||
|
|
||||||
void SettingsCache::setLocalCardImageStorageNamingScheme(
|
void SettingsCache::setLocalCardImageStorageNamingScheme(
|
||||||
const CardPictureLoaderLocalSchemes::NamingScheme _localCardImageStorageNamingScheme)
|
const CardPictureLoaderLocalSchemes::NamingScheme _localCardImageStorageNamingScheme)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,7 @@
|
||||||
#ifndef SETTINGSCACHE_H
|
#ifndef SETTINGSCACHE_H
|
||||||
#define SETTINGSCACHE_H
|
#define SETTINGSCACHE_H
|
||||||
|
|
||||||
|
#include "../../interface/card_picture_loader/card_picture_loader_cache_method.h"
|
||||||
#include "../../interface/card_picture_loader/card_picture_loader_local_schemes.h"
|
#include "../../interface/card_picture_loader/card_picture_loader_local_schemes.h"
|
||||||
#include "shortcuts_settings.h"
|
#include "shortcuts_settings.h"
|
||||||
|
|
||||||
|
|
@ -185,7 +186,7 @@ signals:
|
||||||
void pixmapCacheSizeChanged(int newSizeInMBs);
|
void pixmapCacheSizeChanged(int newSizeInMBs);
|
||||||
void networkCacheSizeChanged(int newSizeInMBs);
|
void networkCacheSizeChanged(int newSizeInMBs);
|
||||||
void redirectCacheTtlChanged(int newTtl);
|
void redirectCacheTtlChanged(int newTtl);
|
||||||
void saveCardImagesToLocalStorageChanged(bool saveCardImagesToLocalStorage);
|
void cardPictureLoaderCacheMethodChanged(int cardPictureLoaderCacheMethod);
|
||||||
void localCardImageStorageNamingSchemeChanged(int localCardImageStorageNamingScheme);
|
void localCardImageStorageNamingSchemeChanged(int localCardImageStorageNamingScheme);
|
||||||
void masterVolumeChanged(int value);
|
void masterVolumeChanged(int value);
|
||||||
void chatMentionCompleterChanged();
|
void chatMentionCompleterChanged();
|
||||||
|
|
@ -305,7 +306,7 @@ private:
|
||||||
int pixmapCacheSize;
|
int pixmapCacheSize;
|
||||||
int networkCacheSize;
|
int networkCacheSize;
|
||||||
int redirectCacheTtl;
|
int redirectCacheTtl;
|
||||||
bool saveCardImagesToLocalStorage;
|
int cardPictureLoaderCacheMethod;
|
||||||
int localCardImageStorageNamingScheme;
|
int localCardImageStorageNamingScheme;
|
||||||
bool scaleCards;
|
bool scaleCards;
|
||||||
int verticalCardOverlapPercent;
|
int verticalCardOverlapPercent;
|
||||||
|
|
@ -786,6 +787,10 @@ public:
|
||||||
{
|
{
|
||||||
return pixmapCacheSize;
|
return pixmapCacheSize;
|
||||||
}
|
}
|
||||||
|
[[nodiscard]] CardPictureLoaderCacheMethod::CacheMethod getCardPictureLoaderCacheMethod() const
|
||||||
|
{
|
||||||
|
return static_cast<CardPictureLoaderCacheMethod::CacheMethod>(cardPictureLoaderCacheMethod);
|
||||||
|
}
|
||||||
[[nodiscard]] int getNetworkCacheSizeInMB() const
|
[[nodiscard]] int getNetworkCacheSizeInMB() const
|
||||||
{
|
{
|
||||||
return networkCacheSize;
|
return networkCacheSize;
|
||||||
|
|
@ -794,10 +799,6 @@ public:
|
||||||
{
|
{
|
||||||
return redirectCacheTtl;
|
return redirectCacheTtl;
|
||||||
}
|
}
|
||||||
[[nodiscard]] bool getSaveCardImagesToLocalStorage() const
|
|
||||||
{
|
|
||||||
return saveCardImagesToLocalStorage;
|
|
||||||
}
|
|
||||||
[[nodiscard]] CardPictureLoaderLocalSchemes::NamingScheme getLocalCardImageStorageNamingScheme() const
|
[[nodiscard]] CardPictureLoaderLocalSchemes::NamingScheme getLocalCardImageStorageNamingScheme() const
|
||||||
{
|
{
|
||||||
return static_cast<CardPictureLoaderLocalSchemes::NamingScheme>(localCardImageStorageNamingScheme);
|
return static_cast<CardPictureLoaderLocalSchemes::NamingScheme>(localCardImageStorageNamingScheme);
|
||||||
|
|
@ -1106,9 +1107,9 @@ public slots:
|
||||||
void setIgnoreUnregisteredUsers(QT_STATE_CHANGED_T _ignoreUnregisteredUsers);
|
void setIgnoreUnregisteredUsers(QT_STATE_CHANGED_T _ignoreUnregisteredUsers);
|
||||||
void setIgnoreUnregisteredUserMessages(QT_STATE_CHANGED_T _ignoreUnregisteredUserMessages);
|
void setIgnoreUnregisteredUserMessages(QT_STATE_CHANGED_T _ignoreUnregisteredUserMessages);
|
||||||
void setPixmapCacheSize(const int _pixmapCacheSize);
|
void setPixmapCacheSize(const int _pixmapCacheSize);
|
||||||
|
void setCardImageCacheMethod(CardPictureLoaderCacheMethod::CacheMethod _cardImageCachingMethod);
|
||||||
void setNetworkCacheSizeInMB(const int _networkCacheSize);
|
void setNetworkCacheSizeInMB(const int _networkCacheSize);
|
||||||
void setNetworkRedirectCacheTtl(const int _redirectCacheTtl);
|
void setNetworkRedirectCacheTtl(const int _redirectCacheTtl);
|
||||||
void setSaveCardImagesToLocalStorage(QT_STATE_CHANGED_T _saveCardImagesToLocalStorage);
|
|
||||||
void setLocalCardImageStorageNamingScheme(
|
void setLocalCardImageStorageNamingScheme(
|
||||||
const CardPictureLoaderLocalSchemes::NamingScheme _localCardImageStorageNamingScheme);
|
const CardPictureLoaderLocalSchemes::NamingScheme _localCardImageStorageNamingScheme);
|
||||||
void setCardScaling(const QT_STATE_CHANGED_T _scaleCards);
|
void setCardScaling(const QT_STATE_CHANGED_T _scaleCards);
|
||||||
|
|
|
||||||
|
|
@ -169,7 +169,8 @@ void CardPictureLoader::imageLoaded(const ExactCard &card, const QImage &image)
|
||||||
|
|
||||||
QPixmapCache::insert(card.getPixmapCacheKey(), finalPixmap);
|
QPixmapCache::insert(card.getPixmapCacheKey(), finalPixmap);
|
||||||
|
|
||||||
if (SettingsCache::instance().getSaveCardImagesToLocalStorage()) {
|
if (SettingsCache::instance().getCardPictureLoaderCacheMethod() ==
|
||||||
|
CardPictureLoaderCacheMethod::CacheMethod::FILESYSTEM_CACHE) {
|
||||||
saveCardImageToLocalStorage(card, finalPixmap);
|
saveCardImageToLocalStorage(card, finalPixmap);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,30 @@
|
||||||
|
#ifndef COCKATRICE_CARD_PICTURE_LOADER_CACHE_METHOD_H
|
||||||
|
#define COCKATRICE_CARD_PICTURE_LOADER_CACHE_METHOD_H
|
||||||
|
#include <QList>
|
||||||
|
#include <QString>
|
||||||
|
|
||||||
|
namespace CardPictureLoaderCacheMethod
|
||||||
|
{
|
||||||
|
enum class CacheMethod
|
||||||
|
{
|
||||||
|
NETWORK_CACHE,
|
||||||
|
FILESYSTEM_CACHE
|
||||||
|
};
|
||||||
|
|
||||||
|
struct CacheMethodInfo
|
||||||
|
{
|
||||||
|
CacheMethod id;
|
||||||
|
QString displayName;
|
||||||
|
};
|
||||||
|
|
||||||
|
static inline const QList<CacheMethodInfo> methods()
|
||||||
|
{
|
||||||
|
static QList<CacheMethodInfo> all = {
|
||||||
|
{CacheMethod::NETWORK_CACHE, "Network Cache"},
|
||||||
|
{CacheMethod::FILESYSTEM_CACHE, "Filesystem Cache"},
|
||||||
|
};
|
||||||
|
return all;
|
||||||
|
}
|
||||||
|
} // namespace CardPictureLoaderCacheMethod
|
||||||
|
|
||||||
|
#endif // COCKATRICE_CARD_PICTURE_LOADER_CACHE_METHOD_H
|
||||||
|
|
@ -26,10 +26,14 @@ CardPictureLoaderWorker::CardPictureLoaderWorker()
|
||||||
cache->setCacheDirectory(SettingsCache::instance().getNetworkCachePath());
|
cache->setCacheDirectory(SettingsCache::instance().getNetworkCachePath());
|
||||||
cache->setMaximumCacheSize(1024L * 1024L *
|
cache->setMaximumCacheSize(1024L * 1024L *
|
||||||
static_cast<qint64>(SettingsCache::instance().getNetworkCacheSizeInMB()));
|
static_cast<qint64>(SettingsCache::instance().getNetworkCacheSizeInMB()));
|
||||||
// Note: the settings is in MB, but QNetworkDiskCache uses bytes
|
|
||||||
connect(&SettingsCache::instance(), &SettingsCache::networkCacheSizeChanged, this,
|
connect(&SettingsCache::instance(), &SettingsCache::networkCacheSizeChanged, cache, [this](int newSizeInMB) {
|
||||||
[this](int newSizeInMB) { cache->setMaximumCacheSize(1024L * 1024L * static_cast<qint64>(newSizeInMB)); });
|
if (cache)
|
||||||
|
cache->setMaximumCacheSize(1024L * 1024L * static_cast<qint64>(newSizeInMB));
|
||||||
|
});
|
||||||
|
|
||||||
networkManager->setCache(cache);
|
networkManager->setCache(cache);
|
||||||
|
|
||||||
// Use a ManualRedirectPolicy since we keep track of redirects in picDownloadFinished
|
// Use a ManualRedirectPolicy since we keep track of redirects in picDownloadFinished
|
||||||
// We can't use NoLessSafeRedirectPolicy because it is not applied with AlwaysCache
|
// We can't use NoLessSafeRedirectPolicy because it is not applied with AlwaysCache
|
||||||
networkManager->setRedirectPolicy(QNetworkRequest::ManualRedirectPolicy);
|
networkManager->setRedirectPolicy(QNetworkRequest::ManualRedirectPolicy);
|
||||||
|
|
@ -65,14 +69,19 @@ void CardPictureLoaderWorker::queueRequest(const QUrl &url, CardPictureLoaderWor
|
||||||
QUrl cachedRedirect = getCachedRedirect(url);
|
QUrl cachedRedirect = getCachedRedirect(url);
|
||||||
if (!cachedRedirect.isEmpty()) {
|
if (!cachedRedirect.isEmpty()) {
|
||||||
queueRequest(cachedRedirect, worker);
|
queueRequest(cachedRedirect, worker);
|
||||||
} else if (cache->metaData(url).isValid()) {
|
return;
|
||||||
// If we hit a cached url, we get to make the request for free, since it won't contribute towards the rate-limit
|
|
||||||
makeRequest(url, worker);
|
|
||||||
} else {
|
|
||||||
requestLoadQueue.append(qMakePair(url, worker));
|
|
||||||
emit imageRequestQueued(url, worker->cardToDownload.getCard(), worker->cardToDownload.getSetName());
|
|
||||||
processQueuedRequests();
|
|
||||||
}
|
}
|
||||||
|
if (SettingsCache::instance().getCardPictureLoaderCacheMethod() ==
|
||||||
|
CardPictureLoaderCacheMethod::CacheMethod::NETWORK_CACHE &&
|
||||||
|
cache->metaData(url).isValid()) {
|
||||||
|
// If we hit a cached url, we get to make the request for free, since it won't contribute towards the
|
||||||
|
// rate-limit
|
||||||
|
makeRequest(url, worker);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
requestLoadQueue.append(qMakePair(url, worker));
|
||||||
|
emit imageRequestQueued(url, worker->cardToDownload.getCard(), worker->cardToDownload.getSetName());
|
||||||
|
processQueuedRequests();
|
||||||
}
|
}
|
||||||
|
|
||||||
QNetworkReply *CardPictureLoaderWorker::makeRequest(const QUrl &url, CardPictureLoaderWorkerWork *worker)
|
QNetworkReply *CardPictureLoaderWorker::makeRequest(const QUrl &url, CardPictureLoaderWorkerWork *worker)
|
||||||
|
|
@ -87,9 +96,12 @@ QNetworkReply *CardPictureLoaderWorker::makeRequest(const QUrl &url, CardPicture
|
||||||
QNetworkRequest req(url);
|
QNetworkRequest req(url);
|
||||||
req.setHeader(QNetworkRequest::UserAgentHeader, QString("Cockatrice %1").arg(VERSION_STRING));
|
req.setHeader(QNetworkRequest::UserAgentHeader, QString("Cockatrice %1").arg(VERSION_STRING));
|
||||||
req.setRawHeader("Accept", "image/avif,image/webp,image/apng,image/,/*;q=0.8");
|
req.setRawHeader("Accept", "image/avif,image/webp,image/apng,image/,/*;q=0.8");
|
||||||
if (!picDownload) {
|
|
||||||
req.setAttribute(QNetworkRequest::CacheLoadControlAttribute, QNetworkRequest::AlwaysCache);
|
bool useNetworkCache = !picDownload && SettingsCache::instance().getCardPictureLoaderCacheMethod() ==
|
||||||
}
|
CardPictureLoaderCacheMethod::CacheMethod::NETWORK_CACHE;
|
||||||
|
|
||||||
|
req.setAttribute(QNetworkRequest::CacheLoadControlAttribute,
|
||||||
|
useNetworkCache ? QNetworkRequest::AlwaysCache : QNetworkRequest::AlwaysNetwork);
|
||||||
|
|
||||||
QNetworkReply *reply = networkManager->get(req);
|
QNetworkReply *reply = networkManager->get(req);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1244,6 +1244,41 @@ StorageSettingsPage::StorageSettingsPage()
|
||||||
pixmapCacheEdit.setValue(SettingsCache::instance().getPixmapCacheSize());
|
pixmapCacheEdit.setValue(SettingsCache::instance().getPixmapCacheSize());
|
||||||
pixmapCacheEdit.setSuffix(" MB");
|
pixmapCacheEdit.setSuffix(" MB");
|
||||||
|
|
||||||
|
// Caching method
|
||||||
|
|
||||||
|
cardPictureLoaderCacheMethodComboBox = new QComboBox;
|
||||||
|
for (auto method : CardPictureLoaderCacheMethod::methods()) {
|
||||||
|
cardPictureLoaderCacheMethodComboBox->addItem(method.displayName, static_cast<int>(method.id));
|
||||||
|
}
|
||||||
|
|
||||||
|
int currentCacheMethod = static_cast<int>(SettingsCache::instance().getCardPictureLoaderCacheMethod());
|
||||||
|
|
||||||
|
int currentIndex = cardPictureLoaderCacheMethodComboBox->findData(currentCacheMethod);
|
||||||
|
if (currentIndex >= 0) {
|
||||||
|
cardPictureLoaderCacheMethodComboBox->setCurrentIndex(currentIndex);
|
||||||
|
}
|
||||||
|
|
||||||
|
connect(cardPictureLoaderCacheMethodComboBox, qOverload<int>(&QComboBox::currentIndexChanged), this,
|
||||||
|
[this](int index) {
|
||||||
|
auto cacheMethod = static_cast<CardPictureLoaderCacheMethod::CacheMethod>(
|
||||||
|
cardPictureLoaderCacheMethodComboBox->itemData(index).toInt());
|
||||||
|
|
||||||
|
bool useNetworkCache = (cacheMethod == CardPictureLoaderCacheMethod::CacheMethod::NETWORK_CACHE);
|
||||||
|
|
||||||
|
if (useNetworkCache) {
|
||||||
|
clearImageBackupsButtonClicked();
|
||||||
|
} else {
|
||||||
|
clearDownloadedPicsButtonClicked();
|
||||||
|
}
|
||||||
|
|
||||||
|
mpNetworkCacheGroupBox->setEnabled(useNetworkCache);
|
||||||
|
mpImageBackupGroupBox->setEnabled(!useNetworkCache);
|
||||||
|
|
||||||
|
SettingsCache::instance().setCardImageCacheMethod(cacheMethod);
|
||||||
|
});
|
||||||
|
|
||||||
|
// Network Cache
|
||||||
|
|
||||||
networkCacheEdit.setMinimum(NETWORK_CACHE_SIZE_MIN);
|
networkCacheEdit.setMinimum(NETWORK_CACHE_SIZE_MIN);
|
||||||
networkCacheEdit.setMaximum(NETWORK_CACHE_SIZE_MAX);
|
networkCacheEdit.setMaximum(NETWORK_CACHE_SIZE_MAX);
|
||||||
networkCacheEdit.setSingleStep(1);
|
networkCacheEdit.setSingleStep(1);
|
||||||
|
|
@ -1256,10 +1291,6 @@ StorageSettingsPage::StorageSettingsPage()
|
||||||
networkRedirectCacheTtlEdit.setValue(SettingsCache::instance().getRedirectCacheTtl());
|
networkRedirectCacheTtlEdit.setValue(SettingsCache::instance().getRedirectCacheTtl());
|
||||||
|
|
||||||
// Image Backup
|
// Image Backup
|
||||||
saveCardImagesToLocalStorageCheckBox.setChecked(SettingsCache::instance().getSaveCardImagesToLocalStorage());
|
|
||||||
connect(&saveCardImagesToLocalStorageCheckBox, &QCheckBox::QT_STATE_CHANGED, &SettingsCache::instance(),
|
|
||||||
&SettingsCache::setSaveCardImagesToLocalStorage);
|
|
||||||
|
|
||||||
localCardImageStorageNamingSchemeComboBox = new QComboBox;
|
localCardImageStorageNamingSchemeComboBox = new QComboBox;
|
||||||
for (const auto &scheme : CardPictureLoaderLocalSchemes::exportSchemes()) {
|
for (const auto &scheme : CardPictureLoaderLocalSchemes::exportSchemes()) {
|
||||||
localCardImageStorageNamingSchemeComboBox->addItem(scheme.displayName, static_cast<int>(scheme.id));
|
localCardImageStorageNamingSchemeComboBox->addItem(scheme.displayName, static_cast<int>(scheme.id));
|
||||||
|
|
@ -1281,7 +1312,12 @@ StorageSettingsPage::StorageSettingsPage()
|
||||||
|
|
||||||
connect(&clearBackupsButton, &QPushButton::clicked, this, &StorageSettingsPage::clearImageBackupsButtonClicked);
|
connect(&clearBackupsButton, &QPushButton::clicked, this, &StorageSettingsPage::clearImageBackupsButtonClicked);
|
||||||
|
|
||||||
|
auto cacheMethodLayout = new QHBoxLayout;
|
||||||
|
cacheMethodLayout->addWidget(&cardPictureLoaderCacheMethodLabel);
|
||||||
|
cacheMethodLayout->addWidget(cardPictureLoaderCacheMethodComboBox);
|
||||||
|
|
||||||
auto networkCacheLayout = new QHBoxLayout;
|
auto networkCacheLayout = new QHBoxLayout;
|
||||||
|
networkCacheLayout->addWidget(&clearDownloadedPicsButton);
|
||||||
networkCacheLayout->addStretch();
|
networkCacheLayout->addStretch();
|
||||||
networkCacheLayout->addWidget(&networkCacheLabel);
|
networkCacheLayout->addWidget(&networkCacheLabel);
|
||||||
networkCacheLayout->addWidget(&networkCacheEdit);
|
networkCacheLayout->addWidget(&networkCacheEdit);
|
||||||
|
|
@ -1299,7 +1335,6 @@ StorageSettingsPage::StorageSettingsPage()
|
||||||
lpNetworkCacheGrid->addWidget(&networkCacheExplainerLabel, 0, 0);
|
lpNetworkCacheGrid->addWidget(&networkCacheExplainerLabel, 0, 0);
|
||||||
lpNetworkCacheGrid->addLayout(networkCacheLayout, 1, 0);
|
lpNetworkCacheGrid->addLayout(networkCacheLayout, 1, 0);
|
||||||
lpNetworkCacheGrid->addLayout(networkRedirectCacheLayout, 2, 0);
|
lpNetworkCacheGrid->addLayout(networkRedirectCacheLayout, 2, 0);
|
||||||
lpNetworkCacheGrid->addWidget(&clearDownloadedPicsButton, 3, 0);
|
|
||||||
|
|
||||||
// Image Backup Layout
|
// Image Backup Layout
|
||||||
lpImageBackupGrid->addWidget(&imageBackupExplainerLabel, 0, 0, 1, 2);
|
lpImageBackupGrid->addWidget(&imageBackupExplainerLabel, 0, 0, 1, 2);
|
||||||
|
|
@ -1309,7 +1344,7 @@ StorageSettingsPage::StorageSettingsPage()
|
||||||
lpImageBackupGrid->addWidget(&clearBackupsButton, 3, 1);
|
lpImageBackupGrid->addWidget(&clearBackupsButton, 3, 1);
|
||||||
|
|
||||||
lpPixmapCacheGrid->addWidget(&pixmapCacheExplainerLabel, 0, 0);
|
lpPixmapCacheGrid->addWidget(&pixmapCacheExplainerLabel, 0, 0);
|
||||||
lpPixmapCacheGrid->addLayout(pixmapCacheLayout, 1, 0);
|
lpPixmapCacheGrid->addLayout(pixmapCacheLayout, 1, 1);
|
||||||
|
|
||||||
connect(&pixmapCacheEdit, qOverload<int>(&QSpinBox::valueChanged), &SettingsCache::instance(),
|
connect(&pixmapCacheEdit, qOverload<int>(&QSpinBox::valueChanged), &SettingsCache::instance(),
|
||||||
&SettingsCache::setPixmapCacheSize);
|
&SettingsCache::setPixmapCacheSize);
|
||||||
|
|
@ -1318,6 +1353,9 @@ StorageSettingsPage::StorageSettingsPage()
|
||||||
connect(&networkRedirectCacheTtlEdit, qOverload<int>(&QSpinBox::valueChanged), &SettingsCache::instance(),
|
connect(&networkRedirectCacheTtlEdit, qOverload<int>(&QSpinBox::valueChanged), &SettingsCache::instance(),
|
||||||
&SettingsCache::setNetworkRedirectCacheTtl);
|
&SettingsCache::setNetworkRedirectCacheTtl);
|
||||||
|
|
||||||
|
mpCacheMethodGroupBox = new QGroupBox;
|
||||||
|
mpCacheMethodGroupBox->setLayout(cacheMethodLayout);
|
||||||
|
|
||||||
mpNetworkCacheGroupBox = new QGroupBox;
|
mpNetworkCacheGroupBox = new QGroupBox;
|
||||||
mpNetworkCacheGroupBox->setLayout(lpNetworkCacheGrid);
|
mpNetworkCacheGroupBox->setLayout(lpNetworkCacheGrid);
|
||||||
|
|
||||||
|
|
@ -1329,12 +1367,19 @@ StorageSettingsPage::StorageSettingsPage()
|
||||||
|
|
||||||
auto *lpMainLayout = new QVBoxLayout;
|
auto *lpMainLayout = new QVBoxLayout;
|
||||||
|
|
||||||
|
lpMainLayout->addWidget(mpCacheMethodGroupBox);
|
||||||
lpMainLayout->addWidget(mpNetworkCacheGroupBox);
|
lpMainLayout->addWidget(mpNetworkCacheGroupBox);
|
||||||
lpMainLayout->addWidget(mpImageBackupGroupBox);
|
lpMainLayout->addWidget(mpImageBackupGroupBox);
|
||||||
lpMainLayout->addWidget(mpPixmapCacheGroupBox);
|
lpMainLayout->addWidget(mpPixmapCacheGroupBox);
|
||||||
|
|
||||||
setLayout(lpMainLayout);
|
setLayout(lpMainLayout);
|
||||||
|
|
||||||
|
bool useNetworkCache = SettingsCache::instance().getCardPictureLoaderCacheMethod() ==
|
||||||
|
CardPictureLoaderCacheMethod::CacheMethod::NETWORK_CACHE;
|
||||||
|
|
||||||
|
mpNetworkCacheGroupBox->setEnabled(useNetworkCache);
|
||||||
|
mpImageBackupGroupBox->setEnabled(!useNetworkCache);
|
||||||
|
|
||||||
connect(&SettingsCache::instance(), &SettingsCache::langChanged, this, &StorageSettingsPage::retranslateUi);
|
connect(&SettingsCache::instance(), &SettingsCache::langChanged, this, &StorageSettingsPage::retranslateUi);
|
||||||
retranslateUi();
|
retranslateUi();
|
||||||
}
|
}
|
||||||
|
|
@ -1342,6 +1387,7 @@ StorageSettingsPage::StorageSettingsPage()
|
||||||
void StorageSettingsPage::clearDownloadedPicsButtonClicked()
|
void StorageSettingsPage::clearDownloadedPicsButtonClicked()
|
||||||
{
|
{
|
||||||
CardPictureLoader::clearNetworkCache();
|
CardPictureLoader::clearNetworkCache();
|
||||||
|
CardPictureLoader::clearPixmapCache();
|
||||||
QMessageBox::information(this, tr("Success"), tr("Cached card pictures have been reset."));
|
QMessageBox::information(this, tr("Success"), tr("Cached card pictures have been reset."));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1352,6 +1398,8 @@ void StorageSettingsPage::clearImageBackupsButtonClicked()
|
||||||
QDir dir(picsPath);
|
QDir dir(picsPath);
|
||||||
bool success = dir.removeRecursively();
|
bool success = dir.removeRecursively();
|
||||||
|
|
||||||
|
CardPictureLoader::clearPixmapCache();
|
||||||
|
|
||||||
if (success) {
|
if (success) {
|
||||||
QMessageBox::information(this, tr("Success"), tr("Downloaded card pictures have been reset."));
|
QMessageBox::information(this, tr("Success"), tr("Downloaded card pictures have been reset."));
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -1361,6 +1409,8 @@ void StorageSettingsPage::clearImageBackupsButtonClicked()
|
||||||
|
|
||||||
void StorageSettingsPage::retranslateUi()
|
void StorageSettingsPage::retranslateUi()
|
||||||
{
|
{
|
||||||
|
cardPictureLoaderCacheMethodLabel.setText(tr("Card Picture Loader Caching Method:"));
|
||||||
|
|
||||||
networkCacheExplainerLabel.setText(
|
networkCacheExplainerLabel.setText(
|
||||||
tr("The network cache is the preferred way of storing images. Downloaded images "
|
tr("The network cache is the preferred way of storing images. Downloaded images "
|
||||||
"are stored here until the size of the cache exceeds the configured size. Cockatrice automatically monitors "
|
"are stored here until the size of the cache exceeds the configured size. Cockatrice automatically monitors "
|
||||||
|
|
@ -1383,6 +1433,7 @@ void StorageSettingsPage::retranslateUi()
|
||||||
clearDownloadedPicsButton.setText(tr("Delete Cached Images"));
|
clearDownloadedPicsButton.setText(tr("Delete Cached Images"));
|
||||||
clearBackupsButton.setText(tr("Delete Saved Images"));
|
clearBackupsButton.setText(tr("Delete Saved Images"));
|
||||||
|
|
||||||
|
mpCacheMethodGroupBox->setTitle(tr("Card Picture Loader Cache Method"));
|
||||||
mpNetworkCacheGroupBox->setTitle(tr("Network Cache"));
|
mpNetworkCacheGroupBox->setTitle(tr("Network Cache"));
|
||||||
mpImageBackupGroupBox->setTitle(tr("Image Backup"));
|
mpImageBackupGroupBox->setTitle(tr("Image Backup"));
|
||||||
mpPixmapCacheGroupBox->setTitle(tr("In-Memory Picture Cache"));
|
mpPixmapCacheGroupBox->setTitle(tr("In-Memory Picture Cache"));
|
||||||
|
|
|
||||||
|
|
@ -249,6 +249,7 @@ private:
|
||||||
QPushButton clearDownloadedPicsButton;
|
QPushButton clearDownloadedPicsButton;
|
||||||
QPushButton clearBackupsButton;
|
QPushButton clearBackupsButton;
|
||||||
|
|
||||||
|
QGroupBox *mpCacheMethodGroupBox;
|
||||||
QGroupBox *mpNetworkCacheGroupBox;
|
QGroupBox *mpNetworkCacheGroupBox;
|
||||||
QGroupBox *mpImageBackupGroupBox;
|
QGroupBox *mpImageBackupGroupBox;
|
||||||
QGroupBox *mpPixmapCacheGroupBox;
|
QGroupBox *mpPixmapCacheGroupBox;
|
||||||
|
|
@ -257,6 +258,8 @@ private:
|
||||||
QLabel imageBackupExplainerLabel;
|
QLabel imageBackupExplainerLabel;
|
||||||
QLabel pixmapCacheExplainerLabel;
|
QLabel pixmapCacheExplainerLabel;
|
||||||
|
|
||||||
|
QLabel cardPictureLoaderCacheMethodLabel;
|
||||||
|
QComboBox *cardPictureLoaderCacheMethodComboBox;
|
||||||
QLabel networkCacheLabel;
|
QLabel networkCacheLabel;
|
||||||
QSpinBox networkCacheEdit;
|
QSpinBox networkCacheEdit;
|
||||||
QLabel networkRedirectCacheTtlLabel;
|
QLabel networkRedirectCacheTtlLabel;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue