mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-06-10 16:24:45 -07:00
improved importer
This commit is contained in:
parent
aae2c437d6
commit
3c8f2b878b
9 changed files with 160 additions and 93 deletions
|
|
@ -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());
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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<SetToDownload> &getSets() { return setsToDownload; }
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -7,6 +7,30 @@ WindowMain::WindowMain(QWidget *parent)
|
|||
{
|
||||
importer = new OracleImporter("../oracle", this);
|
||||
|
||||
QVBoxLayout *checkboxLayout = new QVBoxLayout;
|
||||
QList<SetToDownload> &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<QCheckBox *>(sender());
|
||||
QList<SetToDownload> &sets = importer->getSets();
|
||||
for (int i = 0; i < sets.size(); ++i)
|
||||
if (sets[i].getLongName() == checkBox->text()) {
|
||||
sets[i].setImport(state);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
@ -2,23 +2,30 @@
|
|||
#define WINDOW_MAIN_H
|
||||
|
||||
#include <QMainWindow>
|
||||
#include <QList>
|
||||
|
||||
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<QCheckBox *> 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);
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue