From 3c8f2b878ba4c307506178dfa6db7d8f7b22b6b6 Mon Sep 17 00:00:00 2001 From: Max-Wilhelm Bruker Date: Sat, 17 Oct 2009 17:13:55 +0200 Subject: [PATCH] improved importer --- cockatrice/src/carddatabase.cpp | 7 +- cockatrice/src/carddatabase.h | 16 +-- cockatrice/src/carddatabasemodel.cpp | 2 +- cockatrice/src/window_deckeditor.cpp | 3 +- oracle/sets.xml | 146 +++++++++++++-------------- oracle/src/oracleimporter.cpp | 10 +- oracle/src/oracleimporter.h | 8 +- oracle/src/window_main.cpp | 54 +++++++++- oracle/src/window_main.h | 7 ++ 9 files changed, 160 insertions(+), 93 deletions(-) diff --git a/cockatrice/src/carddatabase.cpp b/cockatrice/src/carddatabase.cpp index 8a25b85d..f83550a0 100644 --- a/cockatrice/src/carddatabase.cpp +++ b/cockatrice/src/carddatabase.cpp @@ -98,8 +98,9 @@ QString CardInfo::getMainCardType() const QString CardInfo::getCorrectedName() const { + QString result = name; // Fire // Ice, Circle of Protection: Red - return getName().remove(" // ").remove(":"); + return result.remove(" // ").remove(":"); } void CardInfo::addToSet(CardSet *set) @@ -204,10 +205,10 @@ QXmlStreamWriter &operator<<(QXmlStreamWriter &xml, const CardInfo *info) xml.writeStartElement("card"); xml.writeTextElement("name", info->getName()); - SetList sets = info->getSets(); + const SetList &sets = info->getSets(); for (int i = 0; i < sets.size(); i++) xml.writeTextElement("set", sets[i]->getShortName()); - QStringList colors = info->getColors(); + const QStringList &colors = info->getColors(); for (int i = 0; i < colors.size(); i++) xml.writeTextElement("color", colors[i]); diff --git a/cockatrice/src/carddatabase.h b/cockatrice/src/carddatabase.h index 528fcf7a..225773e5 100644 --- a/cockatrice/src/carddatabase.h +++ b/cockatrice/src/carddatabase.h @@ -61,15 +61,15 @@ public: const SetList &_sets = SetList(), const QString &_picURL = QString()); ~CardInfo(); - QString getName() const { return name; } - SetList getSets() const { return sets; } - QString getManaCost() const { return manacost; } - QString getCardType() const { return cardtype; } - QString getPowTough() const { return powtough; } - QString getText() const { return text; } + const QString &getName() const { return name; } + const SetList &getSets() const { return sets; } + const QString &getManaCost() const { return manacost; } + const QString &getCardType() const { return cardtype; } + const QString &getPowTough() const { return powtough; } + const QString &getText() const { return text; } void setText(const QString &_text) { text = _text; } - QStringList getColors() const { return colors; } - QString getPicURL() const { return picURL; } + const QStringList &getColors() const { return colors; } + const QString &getPicURL() const { return picURL; } QString getMainCardType() const; QString getCorrectedName() const; int getTableRow() const { return tableRow; } diff --git a/cockatrice/src/carddatabasemodel.cpp b/cockatrice/src/carddatabasemodel.cpp index 958da904..146aadc2 100644 --- a/cockatrice/src/carddatabasemodel.cpp +++ b/cockatrice/src/carddatabasemodel.cpp @@ -35,7 +35,7 @@ QVariant CardDatabaseModel::data(const QModelIndex &index, int role) const case 0: return card->getName(); case 1: { QStringList setList; - QList sets = card->getSets(); + const QList &sets = card->getSets(); for (int i = 0; i < sets.size(); i++) setList << sets[i]->getShortName(); return setList.join(", "); diff --git a/cockatrice/src/window_deckeditor.cpp b/cockatrice/src/window_deckeditor.cpp index da594a6f..d98e550f 100644 --- a/cockatrice/src/window_deckeditor.cpp +++ b/cockatrice/src/window_deckeditor.cpp @@ -33,6 +33,7 @@ WndDeckEditor::WndDeckEditor(CardDatabase *_db, QWidget *parent) databaseView = new QTreeView(); databaseView->setModel(databaseDisplayModel); databaseView->setUniformRowHeights(true); + databaseView->setAlternatingRowColors(true); databaseView->setSortingEnabled(true); databaseView->sortByColumn(0, Qt::AscendingOrder); databaseView->resizeColumnToContents(0); @@ -194,7 +195,7 @@ void WndDeckEditor::updateCardInfoRight(const QModelIndex ¤t, const QModel void WndDeckEditor::updateSearch(const QString &search) { - databaseDisplayModel->setFilterRegExp(search); + databaseDisplayModel->setFilterFixedString(search); } bool WndDeckEditor::confirmClose() diff --git a/oracle/sets.xml b/oracle/sets.xml index e83a0065..cf646a6d 100644 --- a/oracle/sets.xml +++ b/oracle/sets.xml @@ -1,292 +1,292 @@ - + http://www.wizards.com/global/images/magic/general/%1.jpg http://gatherer.wizards.com/Pages/Search/Default.aspx?output=spoiler&method=text&set=["!longname!"] - + ARB Alara Reborn - + AL Alliances - + AQ Antiquities - + AP Apocalypse - + AN Arabian Nights - + BOK Betrayers of Kamigawa - + CHK Champions of Kamigawa - + CH Chronicles - + 6E Classic Sixth Edition - + CS Coldsnap - + CFX Conflux - + DS Darksteel - + DIS Dissension - + 8E Eighth Edition - + EVE Eventide - + EX Exodus - + FE Fallen Empires - + FD Fifth Dawn - + 5E Fifth Edition - + 4E Fourth Edition - + FUT Future Sight - + GP Guildpact - + HL Homelands - + IA Ice Age - + IN Invasion - + JU Judgment - + LG Legends - + LE Legions - + A Limited Edition Alpha - + B Limited Edition Beta - + LRW Lorwyn - + M10 Magic 2010 - + MM Mercadian Masques - + MI Mirage - + MR Mirrodin - + MOR Morningtide - + NE Nemesis - + 9E Ninth Edition - + OD Odyssey - + ON Onslaught - + PLC Planar Chaos - + PS Planeshift - + PT Portal - + P2 Portal Second Age - + P3 Portal Three Kingdoms - + PR Promo set for Gatherer - + PY Prophecy - + RAV Ravnica: City of Guilds - + R Revised Edition - + SOK Saviors of Kamigawa - + SC Scourge - + 7E Seventh Edition - + SHM Shadowmoor - + ALA Shards of Alara - + ST Starter 1999 - + ST2K Starter 2000 - + SH Stronghold - + TE Tempest - + 10E Tenth Edition - + DK The Dark - + TSP Time Spiral - + TSB Time Spiral "Timeshifted" - + TO Torment - + UG Unglued - + UNH Unhinged - + U Unlimited Edition - + UD Urza's Destiny - + UL Urza's Legacy - + US Urza's Saga - + VI Visions - + WL Weatherlight - + ZEN Zendikar diff --git a/oracle/src/oracleimporter.cpp b/oracle/src/oracleimporter.cpp index a61e5207..913fbc4f 100644 --- a/oracle/src/oracleimporter.cpp +++ b/oracle/src/oracleimporter.cpp @@ -18,6 +18,7 @@ OracleImporter::OracleImporter(const QString &_dataDir, QObject *parent) break; if (xml.name() == "set") { QString shortName, longName; + bool import = xml.attributes().value("import").toString().toInt(); while (!xml.atEnd()) { if (xml.readNext() == QXmlStreamReader::EndElement) break; @@ -28,7 +29,7 @@ OracleImporter::OracleImporter(const QString &_dataDir, QObject *parent) else if (xml.name() == "url") editionURL = xml.readElementText(); } - setsToDownload << SetToDownload(edition, editionLong, editionURL); + setsToDownload << SetToDownload(edition, editionLong, editionURL, import); edition = editionLong = editionURL = QString(); } else if (xml.name() == "picture_url") pictureUrl = xml.readElementText(); @@ -182,6 +183,13 @@ QString OracleImporter::getURLFromName(QString name) const void OracleImporter::downloadNextFile() { if (setIndex == -1) { + for (int i = 0; i < setsToDownload.size(); ++i) + if (!setsToDownload[i].getImport()) { + setsToDownload.removeAt(i); + --i; + } + if (setsToDownload.isEmpty()) + return; setIndex = 0; emit setIndexChanged(0, 0, setsToDownload[0].getLongName()); } diff --git a/oracle/src/oracleimporter.h b/oracle/src/oracleimporter.h index a95db244..897cfcef 100644 --- a/oracle/src/oracleimporter.h +++ b/oracle/src/oracleimporter.h @@ -9,12 +9,15 @@ class QBuffer; class SetToDownload { private: QString shortName, longName, url; + bool import; public: const QString &getShortName() const { return shortName; } const QString &getLongName() const { return longName; } const QString &getUrl() const { return url; } - SetToDownload(const QString &_shortName, const QString &_longName, const QString &_url) - : shortName(_shortName), longName(_longName), url(_url) { } + bool getImport() const { return import; } + void setImport(bool _import) { qDebug(QString("%1: setting import to %2").arg(getShortName()).arg(_import).toUtf8()); import = _import; } + SetToDownload(const QString &_shortName, const QString &_longName, const QString &_url, bool _import) + : shortName(_shortName), longName(_longName), url(_url), import(_import) { } }; class OracleImporter : public CardDatabase { @@ -41,6 +44,7 @@ public: int importTextSpoiler(CardSet *set, const QByteArray &data); void downloadNextFile(); int getSetsCount() const { return setsToDownload.size(); } + QList &getSets() { return setsToDownload; } }; #endif diff --git a/oracle/src/window_main.cpp b/oracle/src/window_main.cpp index ddd0ac4a..6f0fef5d 100644 --- a/oracle/src/window_main.cpp +++ b/oracle/src/window_main.cpp @@ -7,6 +7,30 @@ WindowMain::WindowMain(QWidget *parent) { importer = new OracleImporter("../oracle", this); + QVBoxLayout *checkboxLayout = new QVBoxLayout; + QList &sets = importer->getSets(); + for (int i = 0; i < sets.size(); ++i) { + QCheckBox *checkBox = new QCheckBox(sets[i].getLongName()); + checkBox->setChecked(sets[i].getImport()); + connect(checkBox, SIGNAL(stateChanged(int)), this, SLOT(checkBoxChanged(int))); + checkboxLayout->addWidget(checkBox); + checkBoxList << checkBox; + } + + QWidget *checkboxFrame = new QWidget; + checkboxFrame->setLayout(checkboxLayout); + + QScrollArea *checkboxArea = new QScrollArea; + checkboxArea->setWidget(checkboxFrame); + checkboxArea->setWidgetResizable(true); + + startButton = new QPushButton(tr("&Start download")); + connect(startButton, SIGNAL(clicked()), this, SLOT(actStart())); + + QVBoxLayout *settingsLayout = new QVBoxLayout; + settingsLayout->addWidget(checkboxArea); + settingsLayout->addWidget(startButton); + totalLabel = new QLabel(tr("Total progress:")); totalProgressBar = new QProgressBar; nextSetLabel1 = new QLabel(tr("Current file:")); @@ -26,8 +50,13 @@ WindowMain::WindowMain(QWidget *parent) grid->addWidget(fileProgressBar, 2, 1); grid->addWidget(messageLog, 3, 0, 1, 2); + QHBoxLayout *mainLayout = new QHBoxLayout; + mainLayout->addLayout(settingsLayout); + mainLayout->addSpacing(10); + mainLayout->addLayout(grid); + QWidget *centralWidget = new QWidget; - centralWidget->setLayout(grid); + centralWidget->setLayout(mainLayout); setCentralWidget(centralWidget); connect(importer, SIGNAL(setIndexChanged(int, int, const QString &)), this, SLOT(updateTotalProgress(int, int, const QString &))); @@ -35,9 +64,7 @@ WindowMain::WindowMain(QWidget *parent) totalProgressBar->setMaximum(importer->getSetsCount()); setWindowTitle(tr("Oracle importer")); - setFixedSize(300, 300); - - importer->downloadNextFile(); + setFixedSize(500, 300); } void WindowMain::updateTotalProgress(int cardsImported, int setIndex, const QString &nextSetName) @@ -58,3 +85,22 @@ void WindowMain::updateFileProgress(int bytesRead, int totalBytes) fileProgressBar->setMaximum(totalBytes); fileProgressBar->setValue(bytesRead); } + +void WindowMain::actStart() +{ + startButton->setEnabled(false); + for (int i = 0; i < checkBoxList.size(); ++i) + checkBoxList[i]->setEnabled(false); + importer->downloadNextFile(); +} + +void WindowMain::checkBoxChanged(int state) +{ + QCheckBox *checkBox = qobject_cast(sender()); + QList &sets = importer->getSets(); + for (int i = 0; i < sets.size(); ++i) + if (sets[i].getLongName() == checkBox->text()) { + sets[i].setImport(state); + break; + } +} \ No newline at end of file diff --git a/oracle/src/window_main.h b/oracle/src/window_main.h index 19c83a7a..3c1391eb 100644 --- a/oracle/src/window_main.h +++ b/oracle/src/window_main.h @@ -2,23 +2,30 @@ #define WINDOW_MAIN_H #include +#include class OracleImporter; class QLabel; class QProgressBar; class QTextEdit; +class QPushButton; +class QCheckBox; class WindowMain : public QMainWindow { Q_OBJECT private: OracleImporter *importer; + QPushButton *startButton; QLabel *totalLabel, *fileLabel, *nextSetLabel1, *nextSetLabel2; QProgressBar *totalProgressBar, *fileProgressBar; QTextEdit *messageLog; + QList checkBoxList; private slots: void updateTotalProgress(int cardsImported, int setIndex, const QString &nextSetName); void updateFileProgress(int bytesRead, int totalBytes); + void actStart(); + void checkBoxChanged(int state); public: WindowMain(QWidget *parent = 0); };