mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-07-02 19:43:55 -07:00
added automatic download of card pictures
This commit is contained in:
parent
5bb08be2a4
commit
12a151a0c3
2 changed files with 48 additions and 3 deletions
|
|
@ -6,6 +6,7 @@
|
||||||
#include <QSettings>
|
#include <QSettings>
|
||||||
#include <QSvgRenderer>
|
#include <QSvgRenderer>
|
||||||
#include <QPainter>
|
#include <QPainter>
|
||||||
|
#include <QUrl>
|
||||||
|
|
||||||
CardSet::CardSet(const QString &_shortName, const QString &_longName)
|
CardSet::CardSet(const QString &_shortName, const QString &_longName)
|
||||||
: shortName(_shortName), longName(_longName)
|
: shortName(_shortName), longName(_longName)
|
||||||
|
|
@ -125,10 +126,42 @@ QPixmap *CardInfo::loadPixmap()
|
||||||
return pixmap;
|
return pixmap;
|
||||||
if (pixmap->load(QString("%1/%2/%3%4.full.jpg").arg(picsPath).arg(sets[i]->getShortName()).arg(correctedName).arg(1)))
|
if (pixmap->load(QString("%1/%2/%3%4.full.jpg").arg(picsPath).arg(sets[i]->getShortName()).arg(correctedName).arg(1)))
|
||||||
return pixmap;
|
return pixmap;
|
||||||
|
if(pixmap->load(QString("%1/%2/%3.full.jpg").arg(picsPath).arg("downloadedPics").arg(correctedName)))
|
||||||
|
return pixmap;
|
||||||
|
|
||||||
|
startDownload(picsPath, correctedName);
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
return pixmap;
|
return pixmap;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CardInfo::startDownload(QString picsPath, QString cardName)
|
||||||
|
{ if(!QDir(QString(picsPath+"/downloadedPics/")).exists())
|
||||||
|
{
|
||||||
|
QDir dir(picsPath);
|
||||||
|
dir.mkdir("downloadedPics");
|
||||||
|
}
|
||||||
|
newPic = new QFile(picsPath+"/downloadedPics/"+cardName+".full.jpg");
|
||||||
|
newPic->open(QIODevice::WriteOnly);
|
||||||
|
connect(&http, SIGNAL(requestFinished(int, bool)), this, SLOT(picDownloadFinished(int, bool)));
|
||||||
|
QUrl url(picURL);
|
||||||
|
http.setHost(url.host(), url.port(80));
|
||||||
|
dlID = http.get(url.path(), newPic);
|
||||||
|
}
|
||||||
|
|
||||||
|
void CardInfo::picDownloadFinished(int id, bool result)
|
||||||
|
{
|
||||||
|
if(id == dlID){
|
||||||
|
newPic->flush();
|
||||||
|
newPic->close();
|
||||||
|
http.close();
|
||||||
|
updatePixmapCache();
|
||||||
|
disconnect(&http, 0, this, 0);
|
||||||
|
delete newPic;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
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(QString("CardInfo::getPixmap(%1, %2) for %3").arg(size.width()).arg(size.height()).arg(getName()).toLatin1());
|
||||||
|
|
@ -307,7 +340,7 @@ 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;
|
QString name, manacost, type, pt, text, picURL;
|
||||||
QStringList colors;
|
QStringList colors;
|
||||||
SetList sets;
|
SetList sets;
|
||||||
int tableRow = 0;
|
int tableRow = 0;
|
||||||
|
|
@ -330,8 +363,10 @@ void CardDatabase::loadCardsFromXml(QXmlStreamReader &xml)
|
||||||
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();
|
||||||
}
|
}
|
||||||
cardHash.insert(name, new CardInfo(this, name, manacost, type, pt, text, colors, tableRow, sets));
|
cardHash.insert(name, new CardInfo(this, name, manacost, type, pt, text, colors, tableRow, sets, picURL));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,8 @@
|
||||||
#include <QDataStream>
|
#include <QDataStream>
|
||||||
#include <QList>
|
#include <QList>
|
||||||
#include <QXmlStreamReader>
|
#include <QXmlStreamReader>
|
||||||
|
#include <QHttp>
|
||||||
|
#include <QFile>
|
||||||
|
|
||||||
class CardDatabase;
|
class CardDatabase;
|
||||||
class CardInfo;
|
class CardInfo;
|
||||||
|
|
@ -31,7 +33,8 @@ public:
|
||||||
void sortByKey();
|
void sortByKey();
|
||||||
};
|
};
|
||||||
|
|
||||||
class CardInfo {
|
class CardInfo : QObject{
|
||||||
|
Q_OBJECT
|
||||||
private:
|
private:
|
||||||
CardDatabase *db;
|
CardDatabase *db;
|
||||||
|
|
||||||
|
|
@ -43,9 +46,14 @@ private:
|
||||||
QString text;
|
QString text;
|
||||||
QStringList colors;
|
QStringList colors;
|
||||||
QString picURL;
|
QString picURL;
|
||||||
|
QHttp http;
|
||||||
|
QFile *newPic;
|
||||||
|
int dlID;
|
||||||
int tableRow;
|
int tableRow;
|
||||||
QPixmap *pixmap;
|
QPixmap *pixmap;
|
||||||
QMap<int, QPixmap *> scaledPixmapCache;
|
QMap<int, QPixmap *> scaledPixmapCache;
|
||||||
|
|
||||||
|
void startDownload(QString, QString);
|
||||||
public:
|
public:
|
||||||
CardInfo(CardDatabase *_db,
|
CardInfo(CardDatabase *_db,
|
||||||
const QString &_name = QString(),
|
const QString &_name = QString(),
|
||||||
|
|
@ -75,6 +83,8 @@ public:
|
||||||
QPixmap *getPixmap(QSize size);
|
QPixmap *getPixmap(QSize size);
|
||||||
void clearPixmapCache();
|
void clearPixmapCache();
|
||||||
void updatePixmapCache();
|
void updatePixmapCache();
|
||||||
|
public slots:
|
||||||
|
void picDownloadFinished(int, bool);
|
||||||
};
|
};
|
||||||
|
|
||||||
class CardDatabase : public QObject {
|
class CardDatabase : public QObject {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue