LoadStatus CardDatabase::loadCardDatabase(const QString &path, bool tokens) { LoadStatus tempLoadStatus = NotLoaded; if (!path.isEmpty()) tempLoadStatus = loadFromFile(path, tokens); if (tempLoadStatus == Ok) { SetList allSets; QHashIterator<QString, CardSet *> setsIterator(sets); while (setsIterator.hasNext()) allSets.append(setsIterator.next().value()); allSets.sortByKey(); for (int i = 0; i < allSets.size(); ++i) allSets[i]->setSortKey(i); emit cardListChanged(); } if (!tokens) { loadStatus = tempLoadStatus; qDebug() << "loadCardDatabase(): Path = " << path << " Status = " << loadStatus; } return tempLoadStatus; }
void CardDatabase::loadCardsFromXml(QXmlStreamReader &xml, bool tokens) { while (!xml.atEnd()) { if (xml.readNext() == QXmlStreamReader::EndElement) break; if (xml.name() == "card") { QString name, manacost, type, pt, text; QStringList colors; QStringMap customPicURLs, customPicURLsHq; MuidMap muids; SetList sets; int tableRow = 0; int loyalty = 0; bool cipt = false; bool isToken = false; while (!xml.atEnd()) { if (xml.readNext() == QXmlStreamReader::EndElement) break; if (xml.name() == "name") name = xml.readElementText(); else if (xml.name() == "manacost") manacost = xml.readElementText(); else if (xml.name() == "type") type = xml.readElementText(); else if (xml.name() == "pt") pt = xml.readElementText(); else if (xml.name() == "text") text = xml.readElementText(); else if (xml.name() == "set") { QXmlStreamAttributes attrs = xml.attributes(); QString setName = xml.readElementText(); sets.append(getSet(setName)); if (attrs.hasAttribute("muId")) { muids[setName] = attrs.value("muId").toString().toInt(); } if (attrs.hasAttribute("picURL")) { customPicURLs[setName] = attrs.value("picURL").toString(); } if (attrs.hasAttribute("picURLHq")) { customPicURLsHq[setName] = attrs.value("picURLHq").toString(); } } else if (xml.name() == "color") colors << xml.readElementText(); else if (xml.name() == "tablerow") tableRow = xml.readElementText().toInt(); else if (xml.name() == "cipt") cipt = (xml.readElementText() == "1"); else if (xml.name() == "loyalty") loyalty = xml.readElementText().toInt(); else if (xml.name() == "token") isToken = xml.readElementText().toInt(); } if (isToken == tokens) { addCard(new CardInfo(this, name, isToken, manacost, type, pt, text, colors, loyalty, cipt, tableRow, sets, customPicURLs, customPicURLsHq, muids)); } } } }
CardSet* CardInfo::getPreferredSet() { if(sets.isEmpty()) return 0; SetList sortedSets = sets; sortedSets.sortByKey(); return sortedSets.first(); }
/** * 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(); }
bool SetShowQuery::doQuery() { int setlistId = 0; // Insert a new entry in SetList if( d->type == DataQueryInsert ) { Log::self()->message("Creating a new setlist"); dataManager()->executeQuery( "INSERT INTO SetList(dummy) VALUES('dummy')" ); // Get new setlist id QSqlQuery setlistIdQuery = dataManager()->executeQuery("SELECT MAX(id) FROM SetList"); if( setlistIdQuery.next() ) { int setlistId = setlistIdQuery.value(0).toInt(); SetList *tempSetList = new SetList; tempSetList->setId( setlistId ); d->show->setSetList( tempSetList ); } } QSqlQuery setShowQuery; if( d->type == DataQueryInsert ) { Log::self()->message( QString("Insert new Show %1").arg( d->show->venue() ) ); setShowQuery.prepare("INSERT INTO Show(date, venue, city_id, setlist_id) VALUES(:date, :venue, :city_id, :setlist_id)"); } else if( d->type == DataQueryUpdate ) { Log::self()->message( QString("Updating Show %1").arg( d->show->venue() ) ); setShowQuery.prepare("UPDATE Show SET date = :date, venue = :venue, city_id = :city_id WHERE id = :id"); } else { return false; } RelationalDatabaseDataSerializer::serializeShow( setShowQuery, d->show ); dataManager()->executeQuery( setShowQuery ); return true; }
void CardDatabase::checkUnknownSets() { SetList sets = getSetList(); // no set is enabled. Probably this is the first time running trice if(!sets.getEnabledSetsNum()) { sets.guessSortKeys(); sets.sortByKey(); sets.enableAll(); detectedFirstRun = true; return; } int numUnknownSets = sets.getUnknownSetsNum(); // no unkown sets. if(!numUnknownSets) return; QMessageBox msgbox(QMessageBox::Question, tr("New sets found"), tr("%1 new set(s) have been found in the card database. Do you want to enable them?").arg(numUnknownSets), QMessageBox::Yes | QMessageBox::No | QMessageBox::Cancel); switch(msgbox.exec()) { case QMessageBox::No: sets.markAllAsKnown(); break; case QMessageBox::Yes: sets.enableAllUnknown(); break; default: break; } return; }