* PictureLoader: Replace downloadedPics cache with QNetworkCache Currently when the "Download card pictures on the fly" option is enabled, Cockatrice stores downloaded pictures into a downloadedPics sub-folder, keyed on set and card name. If a picture is found in that folder, we never try to download a picture for that card ever again (until it is reprinted in a more recent set, I guess). This has the unfortunate consequence that if you change the URLs for downloading card images, the changes are not applied to cards that already have their picture downloaded. In particular, if you use localized card pictures (through !sflang!), you get a mix of cards in different languages depending on the currently configured language at the time each card was downloaded. This patch removes that mechanism in favor of setting a QNetworkDiskCache on the QNetworkAccessManager used by the PictureLoader to download pictures. The QNetworkDiskCache caches the picture keyed on their URL: if the URL changes, a new request will be made. In particular, if you use picture URLs with !sflang! and change the language, pictures for the current language will be downloaded even for cards that already have a picture. The QNetworkDiskCache is configured with a maximum size of 4GB, which should be enough to hold one high-quality JPEG for each M:TG card in existence. Note that this does not affect the existing mechanism for defining custom card art, either through the CUSTOM directory or the set-based one. Cockatrice will still read existing cards in the downloadedPics directory as before, it will just no longer write into that directory (since pictures are cached by the QNetworkDiskCache instead). To fully switch to the new cache, users should use the "Delete Downloaded Images" button in the settings: it will clear the QNetworkDiskCache but also remove the downloadedPics directory. * Do not use system cache dir for portable installs * Add settings for network cache size * Delete corrupted cache entries * Use old-style connect() syntax (Qt5 build failure) * Add setNetworkCacheSizeInMB to test mocks * setTransferTimeout was added in Qt 5.15 * Improve logging messages We now have the following messages - "Trying to download picture from url: URL" before loading a picture when picture download is enabled - "Trying to load picture from cache: URL" before loading a picture when picture download is disabled (i.e. cache-only offline mode) - "Removing corrupted cache file for url URL and retrying (ERR)" when when we fail to load a picture from the cache. Usually, this should be due to the timeout, in which case ERR will be "Operation Canceled". - "Download failed for url URL (ERR)" when there was an error downloading a picture from the network (ERR is the error message) - "Following redirect to URL" and "Following cached redirect to URL" when following a redirect (from network/from cache) - "Image successfully downloaded from URL" and "Image successfully loaded from cached url at URL" on success - "Possible cached/downloaded picture at URL could not be loaded" on ImageReader error * Clarify that network cache is on disk Also migrate "Delete Downloaded Image" to a "Clear" button right next to the network cache size. * Remove qPrintable * Move pixmap cache settings to card sources * qDebug().nospace() * some formatting on debug messages * format * inverted condition --------- Co-authored-by: ebbit1q <ebbit1q@gmail.com>
281 lines
7.5 KiB
C++
281 lines
7.5 KiB
C++
|
|
#include "mocks.h"
|
|
|
|
CardDatabaseSettings::CardDatabaseSettings(QString settingPath, QObject *parent)
|
|
: SettingsManager(settingPath + "cardDatabase.ini", parent)
|
|
{
|
|
}
|
|
void CardDatabaseSettings::setSortKey(QString /* shortName */, unsigned int /* sortKey */){};
|
|
void CardDatabaseSettings::setEnabled(QString /* shortName */, bool /* enabled */){};
|
|
void CardDatabaseSettings::setIsKnown(QString /* shortName */, bool /* isknown */){};
|
|
unsigned int CardDatabaseSettings::getSortKey(QString /* shortName */)
|
|
{
|
|
return 0;
|
|
};
|
|
bool CardDatabaseSettings::isEnabled(QString /* shortName */)
|
|
{
|
|
return true;
|
|
};
|
|
bool CardDatabaseSettings::isKnown(QString /* shortName */)
|
|
{
|
|
return true;
|
|
};
|
|
|
|
QString SettingsCache::getDataPath()
|
|
{
|
|
return "";
|
|
}
|
|
QString SettingsCache::getSettingsPath()
|
|
{
|
|
return "";
|
|
}
|
|
void SettingsCache::translateLegacySettings()
|
|
{
|
|
}
|
|
QString SettingsCache::getSafeConfigPath(QString /* configEntry */, QString defaultPath) const
|
|
{
|
|
return defaultPath;
|
|
}
|
|
QString SettingsCache::getSafeConfigFilePath(QString /* configEntry */, QString defaultPath) const
|
|
{
|
|
return defaultPath;
|
|
}
|
|
SettingsCache::SettingsCache()
|
|
: settings{new QSettings("global.ini", QSettings::IniFormat, this)}, shortcutsSettings{nullptr},
|
|
cardDatabaseSettings{new CardDatabaseSettings("", this)}, serversSettings{nullptr}, messageSettings{nullptr},
|
|
gameFiltersSettings{nullptr}, layoutsSettings{nullptr}, downloadSettings{nullptr},
|
|
cardDatabasePath{QString("%1/cards.xml").arg(CARDDB_DATADIR)},
|
|
customCardDatabasePath{QString("%1/customsets/").arg(CARDDB_DATADIR)},
|
|
spoilerDatabasePath{QString("%1/spoiler.xml").arg(CARDDB_DATADIR)},
|
|
tokenDatabasePath{QString("%1/tokens.xml").arg(CARDDB_DATADIR)}
|
|
{
|
|
}
|
|
void SettingsCache::setUseTearOffMenus(bool /* _useTearOffMenus */)
|
|
{
|
|
}
|
|
void SettingsCache::setKnownMissingFeatures(const QString & /* _knownMissingFeatures */)
|
|
{
|
|
}
|
|
void SettingsCache::setCardInfoViewMode(const int /* _viewMode */)
|
|
{
|
|
}
|
|
void SettingsCache::setHighlightWords(const QString & /* _highlightWords */)
|
|
{
|
|
}
|
|
void SettingsCache::setMasterVolume(int /* _masterVolume */)
|
|
{
|
|
}
|
|
void SettingsCache::setLeftJustified(const int /* _leftJustified */)
|
|
{
|
|
}
|
|
void SettingsCache::setCardScaling(const int /* _scaleCards */)
|
|
{
|
|
}
|
|
void SettingsCache::setShowMessagePopups(const int /* _showMessagePopups */)
|
|
{
|
|
}
|
|
void SettingsCache::setShowMentionPopups(const int /* _showMentionPopus */)
|
|
{
|
|
}
|
|
void SettingsCache::setRoomHistory(const int /* _roomHistory */)
|
|
{
|
|
}
|
|
void SettingsCache::setLang(const QString & /* _lang */)
|
|
{
|
|
}
|
|
void SettingsCache::setShowTipsOnStartup(bool /* _showTipsOnStartup */)
|
|
{
|
|
}
|
|
void SettingsCache::setSeenTips(const QList<int> & /* _seenTips */)
|
|
{
|
|
}
|
|
void SettingsCache::setDeckPath(const QString & /* _deckPath */)
|
|
{
|
|
}
|
|
void SettingsCache::setReplaysPath(const QString & /* _replaysPath */)
|
|
{
|
|
}
|
|
void SettingsCache::setThemesPath(const QString & /* _themesPath */)
|
|
{
|
|
}
|
|
void SettingsCache::setPicsPath(const QString & /* _picsPath */)
|
|
{
|
|
}
|
|
void SettingsCache::setCardDatabasePath(const QString & /* _cardDatabasePath */)
|
|
{
|
|
}
|
|
void SettingsCache::setCustomCardDatabasePath(const QString & /* _customCardDatabasePath */)
|
|
{
|
|
}
|
|
void SettingsCache::setSpoilerDatabasePath(const QString & /* _spoilerDatabasePath */)
|
|
{
|
|
}
|
|
void SettingsCache::setTokenDatabasePath(const QString & /* _tokenDatabasePath */)
|
|
{
|
|
}
|
|
void SettingsCache::setThemeName(const QString & /* _themeName */)
|
|
{
|
|
}
|
|
void SettingsCache::setPicDownload(int /* _picDownload */)
|
|
{
|
|
}
|
|
void SettingsCache::setNotificationsEnabled(int /* _notificationsEnabled */)
|
|
{
|
|
}
|
|
void SettingsCache::setSpectatorNotificationsEnabled(int /* _spectatorNotificationsEnabled */)
|
|
{
|
|
}
|
|
void SettingsCache::setBuddyConnectNotificationsEnabled(int /* _buddyConnectNotificationsEnabled */)
|
|
{
|
|
}
|
|
void SettingsCache::setDoubleClickToPlay(int /* _doubleClickToPlay */)
|
|
{
|
|
}
|
|
void SettingsCache::setPlayToStack(int /* _playToStack */)
|
|
{
|
|
}
|
|
void SettingsCache::setStartingHandSize(int /* _startingHandSize */)
|
|
{
|
|
}
|
|
void SettingsCache::setAnnotateTokens(int /* _annotateTokens */)
|
|
{
|
|
}
|
|
void SettingsCache::setTabGameSplitterSizes(const QByteArray & /* _tabGameSplitterSizes */)
|
|
{
|
|
}
|
|
void SettingsCache::setDisplayCardNames(int /* _displayCardNames */)
|
|
{
|
|
}
|
|
void SettingsCache::setHorizontalHand(int /* _horizontalHand */)
|
|
{
|
|
}
|
|
void SettingsCache::setInvertVerticalCoordinate(int /* _invertVerticalCoordinate */)
|
|
{
|
|
}
|
|
void SettingsCache::setMinPlayersForMultiColumnLayout(int /* _minPlayersForMultiColumnLayout */)
|
|
{
|
|
}
|
|
void SettingsCache::setTapAnimation(int /* _tapAnimation */)
|
|
{
|
|
}
|
|
void SettingsCache::setChatMention(int /* _chatMention */)
|
|
{
|
|
}
|
|
void SettingsCache::setChatMentionCompleter(const int /* _enableMentionCompleter */)
|
|
{
|
|
}
|
|
void SettingsCache::setChatMentionForeground(int /* _chatMentionForeground */)
|
|
{
|
|
}
|
|
void SettingsCache::setChatHighlightForeground(int /* _chatHighlightForeground */)
|
|
{
|
|
}
|
|
void SettingsCache::setChatMentionColor(const QString & /* _chatMentionColor */)
|
|
{
|
|
}
|
|
void SettingsCache::setChatHighlightColor(const QString & /* _chatHighlightColor */)
|
|
{
|
|
}
|
|
void SettingsCache::setZoneViewSortByName(int /* _zoneViewSortByName */)
|
|
{
|
|
}
|
|
void SettingsCache::setZoneViewSortByType(int /* _zoneViewSortByType */)
|
|
{
|
|
}
|
|
void SettingsCache::setZoneViewPileView(int /* _zoneViewPileView */)
|
|
{
|
|
}
|
|
void SettingsCache::setSoundEnabled(int /* _soundEnabled */)
|
|
{
|
|
}
|
|
void SettingsCache::setSoundThemeName(const QString & /* _soundThemeName */)
|
|
{
|
|
}
|
|
void SettingsCache::setIgnoreUnregisteredUsers(int /* _ignoreUnregisteredUsers */)
|
|
{
|
|
}
|
|
void SettingsCache::setIgnoreUnregisteredUserMessages(int /* _ignoreUnregisteredUserMessages */)
|
|
{
|
|
}
|
|
void SettingsCache::setMainWindowGeometry(const QByteArray & /* _mainWindowGeometry */)
|
|
{
|
|
}
|
|
void SettingsCache::setTokenDialogGeometry(const QByteArray & /* _tokenDialogGeometry */)
|
|
{
|
|
}
|
|
void SettingsCache::setPixmapCacheSize(const int /* _pixmapCacheSize */)
|
|
{
|
|
}
|
|
void SettingsCache::setNetworkCacheSizeInMB(const int /* _networkCacheSize */)
|
|
{
|
|
}
|
|
void SettingsCache::setClientID(const QString & /* _clientID */)
|
|
{
|
|
}
|
|
void SettingsCache::setClientVersion(const QString & /* _clientVersion */)
|
|
{
|
|
}
|
|
QStringList SettingsCache::getCountries() const
|
|
{
|
|
static QStringList countries = QStringList() << "us";
|
|
return countries;
|
|
}
|
|
void SettingsCache::setGameDescription(const QString /* _gameDescription */)
|
|
{
|
|
}
|
|
void SettingsCache::setMaxPlayers(const int /* _maxPlayers */)
|
|
{
|
|
}
|
|
void SettingsCache::setGameTypes(const QString /* _gameTypes */)
|
|
{
|
|
}
|
|
void SettingsCache::setOnlyBuddies(const bool /* _onlyBuddies */)
|
|
{
|
|
}
|
|
void SettingsCache::setOnlyRegistered(const bool /* _onlyRegistered */)
|
|
{
|
|
}
|
|
void SettingsCache::setSpectatorsAllowed(const bool /* _spectatorsAllowed */)
|
|
{
|
|
}
|
|
void SettingsCache::setSpectatorsNeedPassword(const bool /* _spectatorsNeedPassword */)
|
|
{
|
|
}
|
|
void SettingsCache::setSpectatorsCanTalk(const bool /* _spectatorsCanTalk */)
|
|
{
|
|
}
|
|
void SettingsCache::setSpectatorsCanSeeEverything(const bool /* _spectatorsCanSeeEverything */)
|
|
{
|
|
}
|
|
void SettingsCache::setCreateGameAsSpectator(const bool /* _createGameAsSpectator */)
|
|
{
|
|
}
|
|
void SettingsCache::setRememberGameSettings(const bool /* _rememberGameSettings */)
|
|
{
|
|
}
|
|
void SettingsCache::setNotifyAboutUpdate(int /* _notifyaboutupdate */)
|
|
{
|
|
}
|
|
void SettingsCache::setNotifyAboutNewVersion(int /* _notifyaboutnewversion */)
|
|
{
|
|
}
|
|
void SettingsCache::setDownloadSpoilerStatus(bool /* _spoilerStatus */)
|
|
{
|
|
}
|
|
void SettingsCache::setUpdateReleaseChannel(int /* _updateReleaseChannel */)
|
|
{
|
|
}
|
|
void SettingsCache::setMaxFontSize(int /* _max */)
|
|
{
|
|
}
|
|
|
|
void PictureLoader::clearPixmapCache(CardInfoPtr /* card */)
|
|
{
|
|
}
|
|
|
|
SettingsCache *settingsCache;
|
|
|
|
SettingsCache &SettingsCache::instance()
|
|
{
|
|
return *settingsCache;
|
|
}
|