mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-07-22 18:32:17 -07:00
refactor DownloadSettings
This commit is contained in:
parent
27055944df
commit
63de07a515
3 changed files with 15 additions and 40 deletions
|
|
@ -588,8 +588,8 @@ DeckEditorSettingsPage::DeckEditorSettingsPage()
|
||||||
connect(urlList->model(), SIGNAL(rowsMoved(const QModelIndex, int, int, const QModelIndex, int)), this,
|
connect(urlList->model(), SIGNAL(rowsMoved(const QModelIndex, int, int, const QModelIndex, int)), this,
|
||||||
SLOT(urlListChanged(const QModelIndex, int, int, const QModelIndex, int)));
|
SLOT(urlListChanged(const QModelIndex, int, int, const QModelIndex, int)));
|
||||||
|
|
||||||
for (int i = 0; i < SettingsCache::instance().downloads().getCount(); i++)
|
foreach (QString url, SettingsCache::instance().downloads().getAllURLs())
|
||||||
urlList->addItem(SettingsCache::instance().downloads().getDownloadUrlAt(i));
|
urlList->addItem(url);
|
||||||
|
|
||||||
auto aAdd = new QAction(this);
|
auto aAdd = new QAction(this);
|
||||||
aAdd->setIcon(QPixmap("theme:icons/increment"));
|
aAdd->setIcon(QPixmap("theme:icons/increment"));
|
||||||
|
|
@ -694,7 +694,7 @@ DeckEditorSettingsPage::DeckEditorSettingsPage()
|
||||||
|
|
||||||
void DeckEditorSettingsPage::resetDownloadedURLsButtonClicked()
|
void DeckEditorSettingsPage::resetDownloadedURLsButtonClicked()
|
||||||
{
|
{
|
||||||
SettingsCache::instance().downloads().clear();
|
SettingsCache::instance().downloads().resetToDefaultURLs();
|
||||||
urlList->clear();
|
urlList->clear();
|
||||||
urlList->addItems(SettingsCache::instance().downloads().getAllURLs());
|
urlList->addItems(SettingsCache::instance().downloads().getAllURLs());
|
||||||
QMessageBox::information(this, tr("Success"), tr("Download URLs have been reset."));
|
QMessageBox::information(this, tr("Success"), tr("Download URLs have been reset."));
|
||||||
|
|
@ -774,11 +774,13 @@ void DeckEditorSettingsPage::actEditURL()
|
||||||
void DeckEditorSettingsPage::storeSettings()
|
void DeckEditorSettingsPage::storeSettings()
|
||||||
{
|
{
|
||||||
qInfo() << "URL Priority Reset";
|
qInfo() << "URL Priority Reset";
|
||||||
SettingsCache::instance().downloads().clear();
|
|
||||||
|
QStringList downloadUrls;
|
||||||
for (int i = 0; i < urlList->count(); i++) {
|
for (int i = 0; i < urlList->count(); i++) {
|
||||||
qInfo() << "Priority" << i << ":" << urlList->item(i)->text();
|
qInfo() << "Priority" << i << ":" << urlList->item(i)->text();
|
||||||
SettingsCache::instance().downloads().setDownloadUrlAt(i, urlList->item(i)->text());
|
downloadUrls << urlList->item(i)->text();
|
||||||
}
|
}
|
||||||
|
SettingsCache::instance().downloads().setDownloadUrls(downloadUrls);
|
||||||
}
|
}
|
||||||
|
|
||||||
void DeckEditorSettingsPage::urlListChanged(const QModelIndex &, int, int, const QModelIndex &, int)
|
void DeckEditorSettingsPage::urlListChanged(const QModelIndex &, int, int, const QModelIndex &, int)
|
||||||
|
|
|
||||||
|
|
@ -5,12 +5,10 @@
|
||||||
DownloadSettings::DownloadSettings(const QString &settingPath, QObject *parent = nullptr)
|
DownloadSettings::DownloadSettings(const QString &settingPath, QObject *parent = nullptr)
|
||||||
: SettingsManager(settingPath + "downloads.ini", parent)
|
: SettingsManager(settingPath + "downloads.ini", parent)
|
||||||
{
|
{
|
||||||
downloadURLs = getValue("urls", "downloads").value<QStringList>();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void DownloadSettings::setDownloadUrlAt(int index, const QString &url)
|
void DownloadSettings::setDownloadUrls(const QStringList &downloadURLs)
|
||||||
{
|
{
|
||||||
downloadURLs.insert(index, url);
|
|
||||||
setValue(QVariant::fromValue(downloadURLs), "urls", "downloads");
|
setValue(QVariant::fromValue(downloadURLs), "urls", "downloads");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -19,39 +17,22 @@ void DownloadSettings::setDownloadUrlAt(int index, const QString &url)
|
||||||
*/
|
*/
|
||||||
QStringList DownloadSettings::getAllURLs()
|
QStringList DownloadSettings::getAllURLs()
|
||||||
{
|
{
|
||||||
|
auto downloadURLs = getValue("urls", "downloads").toStringList();
|
||||||
|
|
||||||
// First run, these will be empty
|
// First run, these will be empty
|
||||||
if (downloadURLs.count() == 0) {
|
if (downloadURLs.count() == 0) {
|
||||||
populateDefaultURLs();
|
resetToDefaultURLs();
|
||||||
}
|
}
|
||||||
|
|
||||||
return downloadURLs;
|
return downloadURLs;
|
||||||
}
|
}
|
||||||
|
|
||||||
void DownloadSettings::populateDefaultURLs()
|
void DownloadSettings::resetToDefaultURLs()
|
||||||
{
|
{
|
||||||
downloadURLs.clear();
|
auto downloadURLs = QStringList();
|
||||||
downloadURLs.append("https://api.scryfall.com/cards/!set:uuid!?format=image&face=!prop:side!");
|
downloadURLs.append("https://api.scryfall.com/cards/!set:uuid!?format=image&face=!prop:side!");
|
||||||
downloadURLs.append("https://api.scryfall.com/cards/multiverse/!set:muid!?format=image");
|
downloadURLs.append("https://api.scryfall.com/cards/multiverse/!set:muid!?format=image");
|
||||||
downloadURLs.append("https://gatherer.wizards.com/Handlers/Image.ashx?multiverseid=!set:muid!&type=card");
|
downloadURLs.append("https://gatherer.wizards.com/Handlers/Image.ashx?multiverseid=!set:muid!&type=card");
|
||||||
downloadURLs.append("https://gatherer.wizards.com/Handlers/Image.ashx?name=!name!&type=card");
|
downloadURLs.append("https://gatherer.wizards.com/Handlers/Image.ashx?name=!name!&type=card");
|
||||||
setValue(QVariant::fromValue(downloadURLs), "urls", "downloads");
|
setValue(QVariant::fromValue(downloadURLs), "urls", "downloads");
|
||||||
}
|
}
|
||||||
|
|
||||||
QString DownloadSettings::getDownloadUrlAt(int index)
|
|
||||||
{
|
|
||||||
if (0 <= index && index < downloadURLs.size()) {
|
|
||||||
return downloadURLs[index];
|
|
||||||
}
|
|
||||||
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
|
|
||||||
int DownloadSettings::getCount()
|
|
||||||
{
|
|
||||||
return downloadURLs.size();
|
|
||||||
}
|
|
||||||
|
|
||||||
void DownloadSettings::clear()
|
|
||||||
{
|
|
||||||
downloadURLs.clear();
|
|
||||||
}
|
|
||||||
|
|
@ -14,16 +14,8 @@ public:
|
||||||
explicit DownloadSettings(const QString &, QObject *);
|
explicit DownloadSettings(const QString &, QObject *);
|
||||||
|
|
||||||
QStringList getAllURLs();
|
QStringList getAllURLs();
|
||||||
QString getDownloadUrlAt(int);
|
void setDownloadUrls(const QStringList &downloadURLs);
|
||||||
void setDownloadUrlAt(int, const QString &);
|
void resetToDefaultURLs();
|
||||||
int getCount();
|
|
||||||
void clear();
|
|
||||||
|
|
||||||
private:
|
|
||||||
QStringList downloadURLs;
|
|
||||||
|
|
||||||
private:
|
|
||||||
void populateDefaultURLs();
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // COCKATRICE_DOWNLOADSETTINGS_H
|
#endif // COCKATRICE_DOWNLOADSETTINGS_H
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue