QString PictureLoader::getPicUrl()
{
    if (!picDownload) return QString("");

    CardInfo *card = cardBeingDownloaded.getCard();
    CardSet *set=cardBeingDownloaded.getCurrentSet();
    QString picUrl = QString("");

    // if sets have been defined for the card, they can contain custom picUrls
    if(set)
    {
        // first check if Hq is enabled and a custom Hq card url exists in cards.xml
        if(picDownloadHq)
        {
            picUrl = card->getCustomPicURLHq(set->getShortName());
            if (!picUrl.isEmpty())
                return picUrl;
        }

        // then, test for a custom, non-Hq card url in cards.xml
        picUrl = card->getCustomPicURL(set->getShortName());
        if (!picUrl.isEmpty())
            return picUrl;
    }

    // if a card has a muid, use the default url; if not, use the fallback
    int muid = set ? 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()));
    }

    if (picUrl.contains("!name!") ||
            picUrl.contains("!setcode!") ||
            picUrl.contains("!setname!") ||
            picUrl.contains("!cardid!")) {
        qDebug() << "Insufficient card data to download" << card->getName() << "Url:" << picUrl;
        return QString("");
    }

    return picUrl;
}
Esempio n. 2
0
QString PictureLoader::getPicUrl()
{
    if (!picDownload) return QString("");

    CardInfo *card = cardBeingDownloaded.getCard();
    CardSet *set=cardBeingDownloaded.getCurrentSet();
    QString picUrl = QString("");

    // if sets have been defined for the card, they can contain custom picUrls
    if(set)
    {
        picUrl = card->getCustomPicURL(set->getShortName());
        if (!picUrl.isEmpty())
            return picUrl;
    }

    // if a card has a muid, use the default url; if not, use the fallback
    int muid = set ? card->getMuId(set->getShortName()) : 0;
    picUrl = muid ? settingsCache->getPicUrl() : settingsCache->getPicUrlFallback();

    picUrl.replace("!name!", QUrl::toPercentEncoding(card->getCorrectedName()));
    picUrl.replace("!name_lower!", QUrl::toPercentEncoding(card->getCorrectedName().toLower()));
    picUrl.replace("!cardid!", QUrl::toPercentEncoding(QString::number(muid)));
    if (set)
    {
        picUrl.replace("!setcode!", QUrl::toPercentEncoding(set->getShortName()));
        picUrl.replace("!setcode_lower!", QUrl::toPercentEncoding(set->getShortName().toLower()));
        picUrl.replace("!setname!", QUrl::toPercentEncoding(set->getLongName()));
        picUrl.replace("!setname_lower!", QUrl::toPercentEncoding(set->getLongName().toLower()));
    }

    if (
        picUrl.contains("!name!") ||
        picUrl.contains("!name_lower!") ||
        picUrl.contains("!setcode!") ||
        picUrl.contains("!setcode_lower!") ||
        picUrl.contains("!setname!") ||
        picUrl.contains("!setname_lower!") ||
        picUrl.contains("!cardid!")
        )
    {
        qDebug() << "Insufficient card data to download" << card->getName() << "Url:" << picUrl;
        return QString("");
    }

    return picUrl;
}
/**
 * Update the prices of the cards in deckList.
 */
void DBPriceUpdater::updatePrices()
{
    QString base = "https://api.deckbrew.com/mtg/cards", q = "";
    QStringList cards = deck->getCardList();
    muidMap.clear();
    urls.clear();
    CardInfo * card;
    int muid;
    SetList sets;
    bool bNotFirst=false;

    for (int i = 0; i < cards.size(); ++i) {
        card = db->getCard(cards[i], false);
        sets = card->getSets();
        for(int j = 0; j < sets.size(); ++j)
        {
            muid=card->getMuId(sets[j]->getShortName());

            if (!muid) {
                continue;
            }

            //qDebug() << "muid " << muid << " card: " << cards[i] << endl;
            if(bNotFirst)
            {
                q += QString("&m=%1").arg(muid);
            } else {
                q += QString("?m=%1").arg(muid);
                bNotFirst = true;
            }
            muidMap.insert(muid, cards[i]);

            if(q.length() > 240)
            {
                urls.append(base + q);
                bNotFirst=false;
                q = "";
            }
        }
    }
    if(q.length() > 0)
        urls.append(base + q);

    requestNext();
}