mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-09-24 02:13:02 -07:00
[PictureLoader] Store per-host limits readably and show them per URL
This commit is contained in:
parent
d0a5c5d1e0
commit
8a16b43a90
3 changed files with 137 additions and 22 deletions
|
|
@ -84,21 +84,46 @@ void DownloadSettings::setDownloadSpoilerStatus(bool _spoilerStatus)
|
|||
|
||||
QHash<QString, int> DownloadSettings::getHostRequestLimits() const
|
||||
{
|
||||
const QVariantMap stored = getValue("hostRequestLimits").toMap();
|
||||
auto settings = getSettings();
|
||||
if (!defaultGroup.isEmpty()) {
|
||||
settings.beginGroup(defaultGroup);
|
||||
}
|
||||
settings.beginGroup("hostRequestLimits");
|
||||
|
||||
QHash<QString, int> hostRequestLimits;
|
||||
for (auto it = stored.cbegin(); it != stored.cend(); ++it) {
|
||||
hostRequestLimits.insert(it.key(), it.value().toInt());
|
||||
const QStringList hosts = settings.childKeys();
|
||||
for (const QString &host : hosts) {
|
||||
hostRequestLimits.insert(host, settings.value(host).toInt());
|
||||
}
|
||||
|
||||
settings.endGroup();
|
||||
if (!defaultGroup.isEmpty()) {
|
||||
settings.endGroup();
|
||||
}
|
||||
return hostRequestLimits;
|
||||
}
|
||||
|
||||
void DownloadSettings::setHostRequestLimits(const QHash<QString, int> &hostRequestLimits)
|
||||
{
|
||||
QVariantMap stored;
|
||||
for (auto it = hostRequestLimits.cbegin(); it != hostRequestLimits.cend(); ++it) {
|
||||
stored.insert(it.key(), it.value());
|
||||
auto settings = getSettings();
|
||||
if (!defaultGroup.isEmpty()) {
|
||||
settings.beginGroup(defaultGroup);
|
||||
}
|
||||
setValue(stored, "hostRequestLimits");
|
||||
|
||||
// Drop the legacy single-key form (an opaque @Variant blob) written by earlier builds so each
|
||||
// host is stored as a plain, hand-editable key in its own subgroup.
|
||||
settings.remove("hostRequestLimits");
|
||||
settings.beginGroup("hostRequestLimits");
|
||||
settings.remove(QString());
|
||||
for (auto it = hostRequestLimits.cbegin(); it != hostRequestLimits.cend(); ++it) {
|
||||
settings.setValue(it.key(), it.value());
|
||||
}
|
||||
settings.endGroup();
|
||||
|
||||
if (!defaultGroup.isEmpty()) {
|
||||
settings.endGroup();
|
||||
}
|
||||
settings.sync();
|
||||
emit hostRequestLimitsChanged();
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue