mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-07-01 11:03:54 -07:00
Merge branch 'master' into newsearchbar
This commit is contained in:
commit
916735d613
14 changed files with 180 additions and 100 deletions
|
|
@ -101,6 +101,14 @@ QString PictureToLoad::getSetName() const
|
|||
return QString("");
|
||||
}
|
||||
|
||||
CardSet *PictureToLoad::getCurrentSet() const
|
||||
{
|
||||
if (setIndex < sortedSets.size())
|
||||
return sortedSets[setIndex];
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
|
||||
PictureLoader::PictureLoader(const QString &__picsPath, bool _picDownload, bool _picDownloadHq, QObject *parent)
|
||||
: QObject(parent),
|
||||
_picsPath(__picsPath), picDownload(_picDownload), picDownloadHq(_picDownloadHq),
|
||||
|
|
@ -134,15 +142,17 @@ void PictureLoader::processLoadQueue()
|
|||
PictureToLoad ptl = loadQueue.takeFirst();
|
||||
mutex.unlock();
|
||||
|
||||
QString setName = ptl.getSetName();
|
||||
QString correctedCardname = ptl.getCard()->getCorrectedName();
|
||||
qDebug() << "Trying to load picture (set: " << setName << " card: " << correctedCardname << ")";
|
||||
|
||||
//The list of paths to the folders in which to search for images
|
||||
QList<QString> picsPaths = QList<QString>() << _picsPath + "/CUSTOM/" + ptl.getCard()->getCorrectedName();
|
||||
QList<QString> picsPaths = QList<QString>() << _picsPath + "/CUSTOM/" + correctedCardname;
|
||||
|
||||
|
||||
QString setName=ptl.getSetName();
|
||||
if(!setName.isEmpty())
|
||||
{
|
||||
picsPaths << _picsPath + "/" + setName + "/" + ptl.getCard()->getCorrectedName()
|
||||
<< _picsPath + "/downloadedPics/" + setName + "/" + ptl.getCard()->getCorrectedName();
|
||||
picsPaths << _picsPath + "/" + setName + "/" + correctedCardname
|
||||
<< _picsPath + "/downloadedPics/" + setName + "/" + correctedCardname;
|
||||
}
|
||||
|
||||
QImage image;
|
||||
|
|
@ -154,12 +164,14 @@ void PictureLoader::processLoadQueue()
|
|||
for (int i = 0; i < picsPaths.length() && !found; i ++) {
|
||||
imgReader.setFileName(picsPaths.at(i));
|
||||
if (imgReader.read(&image)) {
|
||||
qDebug() << "Picture found on disk (set: " << setName << " card: " << correctedCardname << ")";
|
||||
emit imageLoaded(ptl.getCard(), image);
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
imgReader.setFileName(picsPaths.at(i) + ".full");
|
||||
if (imgReader.read(&image)) {
|
||||
qDebug() << "Picture.full found on disk (set: " << setName << " card: " << correctedCardname << ")";
|
||||
emit imageLoaded(ptl.getCard(), image);
|
||||
found = true;
|
||||
}
|
||||
|
|
@ -167,24 +179,32 @@ void PictureLoader::processLoadQueue()
|
|||
|
||||
if (!found) {
|
||||
if (picDownload) {
|
||||
qDebug() << "Picture NOT found, trying to download (set: " << setName << " card: " << correctedCardname << ")";
|
||||
cardsToDownload.append(ptl);
|
||||
if (!downloadRunning)
|
||||
startNextPicDownload();
|
||||
} else {
|
||||
if (ptl.nextSet())
|
||||
{
|
||||
qDebug() << "Picture NOT found and download disabled, moving to next set (newset: " << setName << " card: " << correctedCardname << ")";
|
||||
mutex.lock();
|
||||
loadQueue.prepend(ptl);
|
||||
else
|
||||
mutex.unlock();
|
||||
} else {
|
||||
qDebug() << "Picture NOT found, download disabled, no more sets to try: BAILING OUT (oldset: " << setName << " card: " << correctedCardname << ")";
|
||||
emit imageLoaded(ptl.getCard(), QImage());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
QString PictureLoader::getPicUrl(CardInfo *card)
|
||||
QString PictureLoader::getPicUrl()
|
||||
{
|
||||
if (!picDownload) return QString("");
|
||||
|
||||
CardSet *set = card->getPreferredSet();
|
||||
CardInfo *card = cardBeingDownloaded.getCard();
|
||||
CardSet *set=cardBeingDownloaded.getCurrentSet();
|
||||
QString picUrl = QString("");
|
||||
|
||||
// if sets have been defined for the card, they can contain custom picUrls
|
||||
|
|
@ -204,17 +224,19 @@ QString PictureLoader::getPicUrl(CardInfo *card)
|
|||
return picUrl;
|
||||
}
|
||||
|
||||
// otherwise, fallback to the default url
|
||||
picUrl = picDownloadHq ? settingsCache->getPicUrlHq() : settingsCache->getPicUrl();
|
||||
picUrl.replace("!name!", QUrl::toPercentEncoding(card->getCorrectedName()));
|
||||
// if a card has a muid, use the default url; if not, use the fallback
|
||||
int muid = set ? muid = card->getMuId(set->getShortName()) : 0;
|
||||
if(muid)
|
||||
picUrl = picDownloadHq ? settingsCache->getPicUrlHq() : settingsCache->getPicUrl();
|
||||
else
|
||||
picUrl = picDownloadHq ? settingsCache->getPicUrlHqFallback() : settingsCache->getPicUrlFallback();
|
||||
|
||||
picUrl.replace("!name!", QUrl::toPercentEncoding(card->getCorrectedName()));
|
||||
picUrl.replace("!cardid!", QUrl::toPercentEncoding(QString::number(muid)));
|
||||
if (set) {
|
||||
picUrl.replace("!setcode!", QUrl::toPercentEncoding(set->getShortName()));
|
||||
picUrl.replace("!setname!", QUrl::toPercentEncoding(set->getLongName()));
|
||||
}
|
||||
int muid = card->getPreferredMuId();
|
||||
if (muid)
|
||||
picUrl.replace("!cardid!", QUrl::toPercentEncoding(QString::number(muid)));
|
||||
|
||||
if (picUrl.contains("!name!") ||
|
||||
picUrl.contains("!setcode!") ||
|
||||
|
|
@ -239,19 +261,33 @@ void PictureLoader::startNextPicDownload()
|
|||
|
||||
cardBeingDownloaded = cardsToDownload.takeFirst();
|
||||
|
||||
QString picUrl = getPicUrl(cardBeingDownloaded.getCard());
|
||||
QString picUrl = getPicUrl();
|
||||
if (picUrl.isEmpty()) {
|
||||
qDebug() << "No url for" << cardBeingDownloaded.getCard()->getName();
|
||||
cardBeingDownloaded = 0;
|
||||
downloadRunning = false;
|
||||
return;
|
||||
picDownloadFailed();
|
||||
} else {
|
||||
QUrl url(picUrl);
|
||||
|
||||
QNetworkRequest req(url);
|
||||
qDebug() << "starting picture download:" << cardBeingDownloaded.getCard()->getName() << "Url:" << req.url();
|
||||
networkManager->get(req);
|
||||
}
|
||||
}
|
||||
|
||||
QUrl url(picUrl);
|
||||
|
||||
QNetworkRequest req(url);
|
||||
qDebug() << "starting picture download:" << cardBeingDownloaded.getCard()->getName() << "Url:" << req.url();
|
||||
networkManager->get(req);
|
||||
void PictureLoader::picDownloadFailed()
|
||||
{
|
||||
if (cardBeingDownloaded.nextSet())
|
||||
{
|
||||
qDebug() << "Picture NOT found, download failed, moving to next set (newset: " << cardBeingDownloaded.getSetName() << " card: " << cardBeingDownloaded.getCard()->getCorrectedName() << ")";
|
||||
mutex.lock();
|
||||
loadQueue.prepend(cardBeingDownloaded);
|
||||
mutex.unlock();
|
||||
emit startLoadQueue();
|
||||
} else {
|
||||
qDebug() << "Picture NOT found, download failed, no more sets to try: BAILING OUT (oldset: " << cardBeingDownloaded.getSetName() << " card: " << cardBeingDownloaded.getCard()->getCorrectedName() << ")";
|
||||
cardBeingDownloaded = 0;
|
||||
emit imageLoaded(cardBeingDownloaded.getCard(), QImage());
|
||||
}
|
||||
}
|
||||
|
||||
void PictureLoader::picDownloadFinished(QNetworkReply *reply)
|
||||
|
|
@ -288,21 +324,9 @@ void PictureLoader::picDownloadFinished(QNetworkReply *reply)
|
|||
}
|
||||
|
||||
emit imageLoaded(cardBeingDownloaded.getCard(), testImage);
|
||||
} else if (cardBeingDownloaded.getHq()) {
|
||||
qDebug() << "HQ: received invalid picture. URL:" << reply->request().url();
|
||||
cardBeingDownloaded.setHq(false);
|
||||
cardsToDownload.prepend(cardBeingDownloaded);
|
||||
} else {
|
||||
qDebug() << "LQ: received invalid picture. URL:" << reply->request().url();
|
||||
if (cardBeingDownloaded.nextSet()) {
|
||||
cardBeingDownloaded.setHq(true);
|
||||
mutex.lock();
|
||||
loadQueue.prepend(cardBeingDownloaded);
|
||||
mutex.unlock();
|
||||
emit startLoadQueue();
|
||||
} else
|
||||
emit imageLoaded(cardBeingDownloaded.getCard(), QImage());
|
||||
}
|
||||
picDownloadFailed();
|
||||
}
|
||||
|
||||
reply->deleteLater();
|
||||
startNextPicDownload();
|
||||
|
|
@ -497,21 +521,6 @@ void CardInfo::updatePixmapCache()
|
|||
emit pixmapUpdated();
|
||||
}
|
||||
|
||||
CardSet* CardInfo::getPreferredSet()
|
||||
{
|
||||
if(sets.isEmpty())
|
||||
return 0;
|
||||
SetList sortedSets = sets;
|
||||
sortedSets.sortByKey();
|
||||
return sortedSets.first();
|
||||
}
|
||||
|
||||
int CardInfo::getPreferredMuId()
|
||||
{
|
||||
CardSet *set = getPreferredSet();
|
||||
return set ? muIds[set->getShortName()] : 0;
|
||||
}
|
||||
|
||||
QString CardInfo::simplifyName(const QString &name) {
|
||||
QString simpleName(name);
|
||||
|
||||
|
|
|
|||
|
|
@ -53,6 +53,7 @@ private:
|
|||
public:
|
||||
PictureToLoad(CardInfo *_card = 0, bool _hq = true);
|
||||
CardInfo *getCard() const { return card; }
|
||||
CardSet *getCurrentSet() const;
|
||||
QString getSetName() const;
|
||||
bool nextSet();
|
||||
bool getHq() const { return hq; }
|
||||
|
|
@ -70,7 +71,7 @@ private:
|
|||
PictureToLoad cardBeingDownloaded;
|
||||
bool picDownload, picDownloadHq, downloadRunning, loadQueueRunning;
|
||||
void startNextPicDownload();
|
||||
QString getPicUrl(CardInfo* card);
|
||||
QString getPicUrl();
|
||||
public:
|
||||
PictureLoader(const QString &__picsPath, bool _picDownload, bool _picDownloadHq, QObject *parent = 0);
|
||||
~PictureLoader();
|
||||
|
|
@ -80,6 +81,7 @@ public:
|
|||
void loadImage(CardInfo *card);
|
||||
private slots:
|
||||
void picDownloadFinished(QNetworkReply *reply);
|
||||
void picDownloadFailed();
|
||||
public slots:
|
||||
void processLoadQueue();
|
||||
signals:
|
||||
|
|
@ -163,8 +165,6 @@ public:
|
|||
void clearPixmapCache();
|
||||
void clearPixmapCacheMiss();
|
||||
void imageLoaded(const QImage &image);
|
||||
CardSet *getPreferredSet();
|
||||
int getPreferredMuId();
|
||||
|
||||
/**
|
||||
* Simplify a name to have no punctuation and lowercase all letters, for
|
||||
|
|
|
|||
|
|
@ -56,7 +56,12 @@ void DlgCreateGame::sharedCtor()
|
|||
onlyBuddiesCheckBox = new QCheckBox(tr("Only &buddies can join"));
|
||||
onlyRegisteredCheckBox = new QCheckBox(tr("Only ®istered users can join"));
|
||||
if (room && room->getUserInfo()->user_level() & ServerInfo_User::IsRegistered)
|
||||
{
|
||||
onlyRegisteredCheckBox->setChecked(true);
|
||||
} else {
|
||||
onlyBuddiesCheckBox->setEnabled(false);
|
||||
onlyRegisteredCheckBox->setEnabled(false);
|
||||
}
|
||||
|
||||
QGridLayout *joinRestrictionsLayout = new QGridLayout;
|
||||
joinRestrictionsLayout->addWidget(passwordLabel, 0, 0);
|
||||
|
|
|
|||
|
|
@ -25,6 +25,8 @@ SettingsCache::SettingsCache()
|
|||
picDownloadHq = settings->value("personal/picturedownloadhq", false).toBool();
|
||||
picUrl = settings->value("personal/picUrl", PIC_URL_DEFAULT).toString();
|
||||
picUrlHq = settings->value("personal/picUrlHq", PIC_URL_HQ_DEFAULT).toString();
|
||||
picUrlFallback = settings->value("personal/picUrlFallback", PIC_URL_FALLBACK).toString();
|
||||
picUrlHqFallback = settings->value("personal/picUrlHqFallback", PIC_URL_HQ_FALLBACK).toString();
|
||||
|
||||
mainWindowGeometry = settings->value("interface/main_window_geometry").toByteArray();
|
||||
notificationsEnabled = settings->value("interface/notificationsenabled", true).toBool();
|
||||
|
|
@ -153,6 +155,18 @@ void SettingsCache::setPicUrlHq(const QString &_picUrlHq)
|
|||
settings->setValue("personal/picUrlHq", picUrlHq);
|
||||
}
|
||||
|
||||
void SettingsCache::setPicUrlFallback(const QString &_picUrlFallback)
|
||||
{
|
||||
picUrlFallback = _picUrlFallback;
|
||||
settings->setValue("personal/picUrlFallback", picUrlFallback);
|
||||
}
|
||||
|
||||
void SettingsCache::setPicUrlHqFallback(const QString &_picUrlHqFallback)
|
||||
{
|
||||
picUrlHqFallback = _picUrlHqFallback;
|
||||
settings->setValue("personal/picUrlHqFallback", picUrlHqFallback);
|
||||
}
|
||||
|
||||
void SettingsCache::setNotificationsEnabled(int _notificationsEnabled)
|
||||
{
|
||||
notificationsEnabled = _notificationsEnabled;
|
||||
|
|
|
|||
|
|
@ -4,7 +4,9 @@
|
|||
#include <QObject>
|
||||
|
||||
#define PIC_URL_DEFAULT "http://gatherer.wizards.com/Handlers/Image.ashx?multiverseid=!cardid!&type=card"
|
||||
#define PIC_URL_FALLBACK "http://mtgimage.com/set/!setcode!/!name!.jpg"
|
||||
#define PIC_URL_HQ_DEFAULT "http://mtgimage.com/multiverseid/!cardid!.jpg"
|
||||
#define PIC_URL_HQ_FALLBACK "http://mtgimage.com/set/!setcode!/!name!.jpg"
|
||||
|
||||
class QSettings;
|
||||
|
||||
|
|
@ -57,6 +59,8 @@ private:
|
|||
bool ignoreUnregisteredUsers;
|
||||
QString picUrl;
|
||||
QString picUrlHq;
|
||||
QString picUrlFallback;
|
||||
QString picUrlHqFallback;
|
||||
bool attemptAutoConnect;
|
||||
public:
|
||||
SettingsCache();
|
||||
|
|
@ -93,6 +97,8 @@ public:
|
|||
bool getIgnoreUnregisteredUsers() const { return ignoreUnregisteredUsers; }
|
||||
QString getPicUrl() const { return picUrl; }
|
||||
QString getPicUrlHq() const { return picUrlHq; }
|
||||
QString getPicUrlFallback() const { return picUrlFallback; }
|
||||
QString getPicUrlHqFallback() const { return picUrlHqFallback; }
|
||||
void copyPath(const QString &src, const QString &dst);
|
||||
bool getAutoConnect() const { return attemptAutoConnect; }
|
||||
public slots:
|
||||
|
|
@ -129,6 +135,8 @@ public slots:
|
|||
void setIgnoreUnregisteredUsers(bool _ignoreUnregisteredUsers);
|
||||
void setPicUrl(const QString &_picUrl);
|
||||
void setPicUrlHq(const QString &_picUrlHq);
|
||||
void setPicUrlFallback(const QString &_picUrlFallback);
|
||||
void setPicUrlHqFallback(const QString &_picUrlHqFallback);
|
||||
void setAutoConnect(const bool &_autoConnect);
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -365,7 +365,7 @@ void TabDeckEditor::updateCardInfoRight(const QModelIndex ¤t, const QModel
|
|||
|
||||
void TabDeckEditor::updateSearch(const QString &search)
|
||||
{
|
||||
databaseDisplayModel->setCardNameBeginning(search);
|
||||
databaseDisplayModel->setCardName(search);
|
||||
QModelIndexList sel = databaseView->selectionModel()->selectedRows();
|
||||
if (sel.isEmpty() && databaseDisplayModel->rowCount())
|
||||
databaseView->selectionModel()->setCurrentIndex(databaseDisplayModel->index(0, 0), QItemSelectionModel::SelectCurrent | QItemSelectionModel::Rows);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue