changed picture download to multiverse id
This commit is contained in:
parent
25de242180
commit
b3f96f9490
5 changed files with 57 additions and 33 deletions
|
@ -12,6 +12,7 @@
|
||||||
#include <QNetworkAccessManager>
|
#include <QNetworkAccessManager>
|
||||||
#include <QNetworkReply>
|
#include <QNetworkReply>
|
||||||
#include <QNetworkRequest>
|
#include <QNetworkRequest>
|
||||||
|
#include <QDebug>
|
||||||
|
|
||||||
CardSet::CardSet(const QString &_shortName, const QString &_longName)
|
CardSet::CardSet(const QString &_shortName, const QString &_longName)
|
||||||
: shortName(_shortName), longName(_longName)
|
: shortName(_shortName), longName(_longName)
|
||||||
|
@ -116,8 +117,8 @@ void PictureLoadingThread::setPicsPath(const QString &path)
|
||||||
_picsPath = path;
|
_picsPath = path;
|
||||||
}
|
}
|
||||||
|
|
||||||
CardInfo::CardInfo(CardDatabase *_db, const QString &_name, const QString &_manacost, const QString &_cardtype, const QString &_powtough, const QString &_text, const QStringList &_colors, bool _cipt, int _tableRow, const SetList &_sets, const QString &_picURL)
|
CardInfo::CardInfo(CardDatabase *_db, const QString &_name, const QString &_manacost, const QString &_cardtype, const QString &_powtough, const QString &_text, const QStringList &_colors, bool _cipt, int _tableRow, const SetList &_sets, const QMap<QString, QString> &_picURLs)
|
||||||
: db(_db), name(_name), sets(_sets), manacost(_manacost), cardtype(_cardtype), powtough(_powtough), text(_text), colors(_colors), picURL(_picURL), cipt(_cipt), tableRow(_tableRow), pixmap(NULL)
|
: db(_db), name(_name), sets(_sets), manacost(_manacost), cardtype(_cardtype), powtough(_powtough), text(_text), colors(_colors), picURLs(_picURLs), cipt(_cipt), tableRow(_tableRow), pixmap(NULL)
|
||||||
{
|
{
|
||||||
for (int i = 0; i < sets.size(); i++)
|
for (int i = 0; i < sets.size(); i++)
|
||||||
sets[i]->append(this);
|
sets[i]->append(this);
|
||||||
|
@ -170,6 +171,13 @@ void CardInfo::addToSet(CardSet *set)
|
||||||
sets << set;
|
sets << set;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QString CardInfo::getPicURL() const
|
||||||
|
{
|
||||||
|
SetList sortedSets = sets;
|
||||||
|
sortedSets.sortByKey();
|
||||||
|
return picURLs.value(sortedSets.first()->getShortName());
|
||||||
|
}
|
||||||
|
|
||||||
QPixmap *CardInfo::loadPixmap()
|
QPixmap *CardInfo::loadPixmap()
|
||||||
{
|
{
|
||||||
if (pixmap)
|
if (pixmap)
|
||||||
|
@ -195,7 +203,7 @@ void CardInfo::imageLoaded(const QImage &image)
|
||||||
|
|
||||||
QPixmap *CardInfo::getPixmap(QSize size)
|
QPixmap *CardInfo::getPixmap(QSize size)
|
||||||
{
|
{
|
||||||
qDebug(QString("CardInfo::getPixmap(%1, %2) for %3").arg(size.width()).arg(size.height()).arg(getName()).toLatin1());
|
qDebug() << "CardInfo::getPixmap(" << size.width() << size.height() << ") for" << getName();
|
||||||
QPixmap *cachedPixmap = scaledPixmapCache.value(size.width());
|
QPixmap *cachedPixmap = scaledPixmapCache.value(size.width());
|
||||||
if (cachedPixmap)
|
if (cachedPixmap)
|
||||||
return cachedPixmap;
|
return cachedPixmap;
|
||||||
|
@ -220,13 +228,13 @@ QPixmap *CardInfo::getPixmap(QSize size)
|
||||||
void CardInfo::clearPixmapCache()
|
void CardInfo::clearPixmapCache()
|
||||||
{
|
{
|
||||||
if (pixmap) {
|
if (pixmap) {
|
||||||
qDebug(QString("Deleting pixmap for %1").arg(name).toLatin1());
|
qDebug() << "Deleting pixmap for" << name;
|
||||||
delete pixmap;
|
delete pixmap;
|
||||||
pixmap = 0;
|
pixmap = 0;
|
||||||
QMapIterator<int, QPixmap *> i(scaledPixmapCache);
|
QMapIterator<int, QPixmap *> i(scaledPixmapCache);
|
||||||
while (i.hasNext()) {
|
while (i.hasNext()) {
|
||||||
i.next();
|
i.next();
|
||||||
qDebug(QString(" Deleting cached pixmap for width %1").arg(i.key()).toLatin1());
|
qDebug() << " Deleting cached pixmap for width" << i.key();
|
||||||
delete i.value();
|
delete i.value();
|
||||||
}
|
}
|
||||||
scaledPixmapCache.clear();
|
scaledPixmapCache.clear();
|
||||||
|
@ -243,7 +251,7 @@ void CardInfo::clearPixmapCacheMiss()
|
||||||
|
|
||||||
void CardInfo::updatePixmapCache()
|
void CardInfo::updatePixmapCache()
|
||||||
{
|
{
|
||||||
qDebug(QString("Updating pixmap cache for %1").arg(name).toLatin1());
|
qDebug() << "Updating pixmap cache for" << name;
|
||||||
clearPixmapCache();
|
clearPixmapCache();
|
||||||
loadPixmap();
|
loadPixmap();
|
||||||
|
|
||||||
|
@ -256,8 +264,12 @@ QXmlStreamWriter &operator<<(QXmlStreamWriter &xml, const CardInfo *info)
|
||||||
xml.writeTextElement("name", info->getName());
|
xml.writeTextElement("name", info->getName());
|
||||||
|
|
||||||
const SetList &sets = info->getSets();
|
const SetList &sets = info->getSets();
|
||||||
for (int i = 0; i < sets.size(); i++)
|
for (int i = 0; i < sets.size(); i++) {
|
||||||
xml.writeTextElement("set", sets[i]->getShortName());
|
xml.writeStartElement("set");
|
||||||
|
xml.writeAttribute("picURL", info->getPicURL(sets[i]->getShortName()));
|
||||||
|
xml.writeCharacters(sets[i]->getShortName());
|
||||||
|
xml.writeEndElement();
|
||||||
|
}
|
||||||
const QStringList &colors = info->getColors();
|
const QStringList &colors = info->getColors();
|
||||||
for (int i = 0; i < colors.size(); i++)
|
for (int i = 0; i < colors.size(); i++)
|
||||||
xml.writeTextElement("color", colors[i]);
|
xml.writeTextElement("color", colors[i]);
|
||||||
|
@ -268,7 +280,6 @@ QXmlStreamWriter &operator<<(QXmlStreamWriter &xml, const CardInfo *info)
|
||||||
xml.writeTextElement("pt", info->getPowTough());
|
xml.writeTextElement("pt", info->getPowTough());
|
||||||
xml.writeTextElement("tablerow", QString::number(info->getTableRow()));
|
xml.writeTextElement("tablerow", QString::number(info->getTableRow()));
|
||||||
xml.writeTextElement("text", info->getText());
|
xml.writeTextElement("text", info->getText());
|
||||||
xml.writeTextElement("picURL", info->getPicURL());
|
|
||||||
if (info->getCipt())
|
if (info->getCipt())
|
||||||
xml.writeTextElement("cipt", "1");
|
xml.writeTextElement("cipt", "1");
|
||||||
xml.writeEndElement(); // card
|
xml.writeEndElement(); // card
|
||||||
|
@ -279,7 +290,7 @@ QXmlStreamWriter &operator<<(QXmlStreamWriter &xml, const CardInfo *info)
|
||||||
CardDatabase::CardDatabase(QObject *parent)
|
CardDatabase::CardDatabase(QObject *parent)
|
||||||
: QObject(parent), downloadRunning(false), loadSuccess(false), noCard(0)
|
: QObject(parent), downloadRunning(false), loadSuccess(false), noCard(0)
|
||||||
{
|
{
|
||||||
connect(settingsCache, SIGNAL(picsPathChanged()), this, SLOT(clearPixmapCache()));
|
connect(settingsCache, SIGNAL(picsPathChanged()), this, SLOT(picsPathChanged()));
|
||||||
connect(settingsCache, SIGNAL(cardDatabasePathChanged()), this, SLOT(loadCardDatabase()));
|
connect(settingsCache, SIGNAL(cardDatabasePathChanged()), this, SLOT(loadCardDatabase()));
|
||||||
connect(settingsCache, SIGNAL(picDownloadChanged()), this, SLOT(picDownloadChanged()));
|
connect(settingsCache, SIGNAL(picDownloadChanged()), this, SLOT(picDownloadChanged()));
|
||||||
|
|
||||||
|
@ -328,7 +339,6 @@ CardInfo *CardDatabase::getCard(const QString &cardName)
|
||||||
else if (cardHash.contains(cardName))
|
else if (cardHash.contains(cardName))
|
||||||
return cardHash.value(cardName);
|
return cardHash.value(cardName);
|
||||||
else {
|
else {
|
||||||
qDebug(QString("CardDatabase: card not found: %1").arg(cardName).toLatin1());
|
|
||||||
CardInfo *newCard = new CardInfo(this, cardName);
|
CardInfo *newCard = new CardInfo(this, cardName);
|
||||||
newCard->addToSet(getSet("TK"));
|
newCard->addToSet(getSet("TK"));
|
||||||
cardHash.insert(cardName, newCard);
|
cardHash.insert(cardName, newCard);
|
||||||
|
@ -341,7 +351,6 @@ CardSet *CardDatabase::getSet(const QString &setName)
|
||||||
if (setHash.contains(setName))
|
if (setHash.contains(setName))
|
||||||
return setHash.value(setName);
|
return setHash.value(setName);
|
||||||
else {
|
else {
|
||||||
qDebug(QString("CardDatabase: set not found: %1").arg(setName).toLatin1());
|
|
||||||
CardSet *newSet = new CardSet(setName);
|
CardSet *newSet = new CardSet(setName);
|
||||||
setHash.insert(setName, newSet);
|
setHash.insert(setName, newSet);
|
||||||
return newSet;
|
return newSet;
|
||||||
|
@ -372,7 +381,7 @@ void CardDatabase::clearPixmapCache()
|
||||||
|
|
||||||
void CardDatabase::startPicDownload(CardInfo *card)
|
void CardDatabase::startPicDownload(CardInfo *card)
|
||||||
{
|
{
|
||||||
if (card->getPicURL().isEmpty())
|
if (card->getPicURLs().isEmpty())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
cardsToDownload.append(card);
|
cardsToDownload.append(card);
|
||||||
|
@ -446,8 +455,9 @@ void CardDatabase::loadCardsFromXml(QXmlStreamReader &xml)
|
||||||
if (xml.readNext() == QXmlStreamReader::EndElement)
|
if (xml.readNext() == QXmlStreamReader::EndElement)
|
||||||
break;
|
break;
|
||||||
if (xml.name() == "card") {
|
if (xml.name() == "card") {
|
||||||
QString name, manacost, type, pt, text, picURL;
|
QString name, manacost, type, pt, text;
|
||||||
QStringList colors;
|
QStringList colors;
|
||||||
|
QMap<QString, QString> picURLs;
|
||||||
SetList sets;
|
SetList sets;
|
||||||
int tableRow = 0;
|
int tableRow = 0;
|
||||||
bool cipt = false;
|
bool cipt = false;
|
||||||
|
@ -464,18 +474,19 @@ void CardDatabase::loadCardsFromXml(QXmlStreamReader &xml)
|
||||||
pt = xml.readElementText();
|
pt = xml.readElementText();
|
||||||
else if (xml.name() == "text")
|
else if (xml.name() == "text")
|
||||||
text = xml.readElementText();
|
text = xml.readElementText();
|
||||||
else if (xml.name() == "set")
|
else if (xml.name() == "set") {
|
||||||
sets << getSet(xml.readElementText());
|
QString url = xml.attributes().value("picURL").toString();
|
||||||
else if (xml.name() == "color")
|
QString setName = xml.readElementText();
|
||||||
|
sets.append(getSet(setName));
|
||||||
|
picURLs.insert(setName, url);
|
||||||
|
} else if (xml.name() == "color")
|
||||||
colors << xml.readElementText();
|
colors << xml.readElementText();
|
||||||
else if (xml.name() == "tablerow")
|
else if (xml.name() == "tablerow")
|
||||||
tableRow = xml.readElementText().toInt();
|
tableRow = xml.readElementText().toInt();
|
||||||
else if (xml.name() == "picURL")
|
|
||||||
picURL = xml.readElementText();
|
|
||||||
else if (xml.name() == "cipt")
|
else if (xml.name() == "cipt")
|
||||||
cipt = (xml.readElementText() == "1");
|
cipt = (xml.readElementText() == "1");
|
||||||
}
|
}
|
||||||
cardHash.insert(name, new CardInfo(this, name, manacost, type, pt, text, colors, cipt, tableRow, sets, picURL));
|
cardHash.insert(name, new CardInfo(this, name, manacost, type, pt, text, colors, cipt, tableRow, sets, picURLs));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -502,7 +513,7 @@ bool CardDatabase::loadFromFile(const QString &fileName)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
qDebug(QString("%1 cards in %2 sets loaded").arg(cardHash.size()).arg(setHash.size()).toLatin1());
|
qDebug() << cardHash.size() << "cards in" << setHash.size() << "sets loaded";
|
||||||
return !cardHash.isEmpty();
|
return !cardHash.isEmpty();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -597,3 +608,9 @@ void CardDatabase::imageLoaded(CardInfo *card, QImage image)
|
||||||
{
|
{
|
||||||
card->imageLoaded(image);
|
card->imageLoaded(image);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CardDatabase::picsPathChanged()
|
||||||
|
{
|
||||||
|
loadingThread->setPicsPath(settingsCache->getPicsPath());
|
||||||
|
clearPixmapCache();
|
||||||
|
}
|
|
@ -66,7 +66,7 @@ private:
|
||||||
QString powtough;
|
QString powtough;
|
||||||
QString text;
|
QString text;
|
||||||
QStringList colors;
|
QStringList colors;
|
||||||
QString picURL;
|
QMap<QString, QString> picURLs;
|
||||||
bool cipt;
|
bool cipt;
|
||||||
int tableRow;
|
int tableRow;
|
||||||
QPixmap *pixmap;
|
QPixmap *pixmap;
|
||||||
|
@ -82,7 +82,7 @@ public:
|
||||||
bool cipt = false,
|
bool cipt = false,
|
||||||
int _tableRow = 0,
|
int _tableRow = 0,
|
||||||
const SetList &_sets = SetList(),
|
const SetList &_sets = SetList(),
|
||||||
const QString &_picURL = QString());
|
const QMap<QString, QString> &_picURLs = QMap<QString, QString>());
|
||||||
~CardInfo();
|
~CardInfo();
|
||||||
const QString &getName() const { return name; }
|
const QString &getName() const { return name; }
|
||||||
const SetList &getSets() const { return sets; }
|
const SetList &getSets() const { return sets; }
|
||||||
|
@ -93,12 +93,14 @@ public:
|
||||||
bool getCipt() const { return cipt; }
|
bool getCipt() const { return cipt; }
|
||||||
void setText(const QString &_text) { text = _text; }
|
void setText(const QString &_text) { text = _text; }
|
||||||
const QStringList &getColors() const { return colors; }
|
const QStringList &getColors() const { return colors; }
|
||||||
const QString &getPicURL() const { return picURL; }
|
QString getPicURL(const QString &set) const { return picURLs.value(set); }
|
||||||
|
QString getPicURL() const;
|
||||||
|
const QMap<QString, QString> &getPicURLs() const { return picURLs; }
|
||||||
QString getMainCardType() const;
|
QString getMainCardType() const;
|
||||||
QString getCorrectedName() const;
|
QString getCorrectedName() const;
|
||||||
int getTableRow() const { return tableRow; }
|
int getTableRow() const { return tableRow; }
|
||||||
void setTableRow(int _tableRow) { tableRow = _tableRow; }
|
void setTableRow(int _tableRow) { tableRow = _tableRow; }
|
||||||
void setPicURL(const QString &_picURL) { picURL = _picURL; }
|
void setPicURL(const QString &_set, const QString &_picURL) { picURLs.insert(_set, _picURL); }
|
||||||
void addToSet(CardSet *set);
|
void addToSet(CardSet *set);
|
||||||
QPixmap *loadPixmap();
|
QPixmap *loadPixmap();
|
||||||
QPixmap *getPixmap(QSize size);
|
QPixmap *getPixmap(QSize size);
|
||||||
|
@ -151,6 +153,7 @@ private slots:
|
||||||
void picDownloadFinished(QNetworkReply *reply);
|
void picDownloadFinished(QNetworkReply *reply);
|
||||||
void picDownloadChanged();
|
void picDownloadChanged();
|
||||||
void imageLoaded(CardInfo *card, QImage image);
|
void imageLoaded(CardInfo *card, QImage image);
|
||||||
|
void picsPathChanged();
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<cockatrice_setdatabase version="20100416">
|
<cockatrice_setdatabase version="20110126">
|
||||||
<picture_url>http://www.wizards.com/global/images/magic/general/%1.jpg</picture_url>
|
<picture_url>http://gatherer.wizards.com/Handlers/Image.ashx?multiverseid=%1&type=card</picture_url>
|
||||||
<set_url>http://gatherer.wizards.com/Pages/Search/Default.aspx?output=spoiler&method=text&set=["!longname!"]</set_url>
|
<set_url>http://gatherer.wizards.com/Pages/Search/Default.aspx?output=spoiler&method=text&set=["!longname!"]</set_url>
|
||||||
<set import="1">
|
<set import="1">
|
||||||
<name>ARB</name>
|
<name>ARB</name>
|
||||||
|
|
|
@ -64,7 +64,7 @@ void OracleImporter::readSetsFromXml(QXmlStreamReader &xml)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
CardInfo *OracleImporter::addCard(QString cardName, const QString &cardCost, const QString &cardType, const QString &cardPT, const QStringList &cardText)
|
CardInfo *OracleImporter::addCard(const QString &setName, QString cardName, int cardId, const QString &cardCost, const QString &cardType, const QString &cardPT, const QStringList &cardText)
|
||||||
{
|
{
|
||||||
QString fullCardText = cardText.join("\n");
|
QString fullCardText = cardText.join("\n");
|
||||||
bool splitCard = false;
|
bool splitCard = false;
|
||||||
|
@ -110,7 +110,6 @@ CardInfo *OracleImporter::addCard(QString cardName, const QString &cardCost, con
|
||||||
bool cipt = (cardText.contains(cardName + " enters the battlefield tapped."));
|
bool cipt = (cardText.contains(cardName + " enters the battlefield tapped."));
|
||||||
|
|
||||||
card = new CardInfo(this, cardName, cardCost, cardType, cardPT, fullCardText, colors, cipt);
|
card = new CardInfo(this, cardName, cardCost, cardType, cardPT, fullCardText, colors, cipt);
|
||||||
card->setPicURL(getURLFromName(cardName));
|
|
||||||
int tableRow = 1;
|
int tableRow = 1;
|
||||||
QString mainCardType = card->getMainCardType();
|
QString mainCardType = card->getMainCardType();
|
||||||
if ((mainCardType == "Land") || mArtifact)
|
if ((mainCardType == "Land") || mArtifact)
|
||||||
|
@ -123,6 +122,7 @@ CardInfo *OracleImporter::addCard(QString cardName, const QString &cardCost, con
|
||||||
|
|
||||||
cardHash.insert(cardName, card);
|
cardHash.insert(cardName, card);
|
||||||
}
|
}
|
||||||
|
card->setPicURL(setName, pictureUrl.arg(cardId));
|
||||||
return card;
|
return card;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -153,6 +153,7 @@ int OracleImporter::importTextSpoiler(CardSet *set, const QByteArray &data)
|
||||||
QDomNode divClass = div.attributes().namedItem("class");
|
QDomNode divClass = div.attributes().namedItem("class");
|
||||||
if (divClass.nodeValue() == "textspoiler") {
|
if (divClass.nodeValue() == "textspoiler") {
|
||||||
QString cardName, cardCost, cardType, cardPT, cardText;
|
QString cardName, cardCost, cardType, cardPT, cardText;
|
||||||
|
int cardId = 0;
|
||||||
|
|
||||||
QDomNodeList trs = div.elementsByTagName("tr");
|
QDomNodeList trs = div.elementsByTagName("tr");
|
||||||
for (int j = 0; j < trs.size(); ++j) {
|
for (int j = 0; j < trs.size(); ++j) {
|
||||||
|
@ -163,7 +164,7 @@ int OracleImporter::importTextSpoiler(CardSet *set, const QByteArray &data)
|
||||||
for (int i = 0; i < cardTextSplit.size(); ++i)
|
for (int i = 0; i < cardTextSplit.size(); ++i)
|
||||||
cardTextSplit[i] = cardTextSplit[i].trimmed();
|
cardTextSplit[i] = cardTextSplit[i].trimmed();
|
||||||
|
|
||||||
CardInfo *card = addCard(cardName, cardCost, cardType, cardPT, cardTextSplit);
|
CardInfo *card = addCard(set->getShortName(), cardName, cardId, cardCost, cardType, cardPT, cardTextSplit);
|
||||||
if (!set->contains(card)) {
|
if (!set->contains(card)) {
|
||||||
card->addToSet(set);
|
card->addToSet(set);
|
||||||
cards++;
|
cards++;
|
||||||
|
@ -173,9 +174,12 @@ int OracleImporter::importTextSpoiler(CardSet *set, const QByteArray &data)
|
||||||
QString v1 = tds.at(0).toElement().text().simplified();
|
QString v1 = tds.at(0).toElement().text().simplified();
|
||||||
QString v2 = tds.at(1).toElement().text().replace(trUtf8("—"), "-");
|
QString v2 = tds.at(1).toElement().text().replace(trUtf8("—"), "-");
|
||||||
|
|
||||||
if (v1 == "Name:")
|
if (v1 == "Name:") {
|
||||||
|
QDomElement a = tds.at(1).toElement().elementsByTagName("a").at(0).toElement();
|
||||||
|
QString href = a.attributes().namedItem("href").nodeValue();
|
||||||
|
cardId = href.mid(href.indexOf("multiverseid=") + 13).toInt();
|
||||||
cardName = v2.simplified();
|
cardName = v2.simplified();
|
||||||
else if (v1 == "Cost:")
|
} else if (v1 == "Cost:")
|
||||||
cardCost = v2.simplified();
|
cardCost = v2.simplified();
|
||||||
else if (v1 == "Type:")
|
else if (v1 == "Type:")
|
||||||
cardType = v2.simplified();
|
cardType = v2.simplified();
|
||||||
|
|
|
@ -35,7 +35,7 @@ private:
|
||||||
|
|
||||||
void downloadNextFile();
|
void downloadNextFile();
|
||||||
void readSetsFromXml(QXmlStreamReader &xml);
|
void readSetsFromXml(QXmlStreamReader &xml);
|
||||||
CardInfo *addCard(QString cardName, const QString &cardCost, const QString &cardType, const QString &cardPT, const QStringList &cardText);
|
CardInfo *addCard(const QString &setName, QString cardName, int cardId, const QString &cardCost, const QString &cardType, const QString &cardPT, const QStringList &cardText);
|
||||||
private slots:
|
private slots:
|
||||||
void httpRequestFinished(int requestId, bool error);
|
void httpRequestFinished(int requestId, bool error);
|
||||||
void readResponseHeader(const QHttpResponseHeader &responseHeader);
|
void readResponseHeader(const QHttpResponseHeader &responseHeader);
|
||||||
|
|
Loading…
Reference in a new issue