diff --git a/cockatrice/src/carddatabase.cpp b/cockatrice/src/carddatabase.cpp index 5fbf81c5..4a3705b9 100644 --- a/cockatrice/src/carddatabase.cpp +++ b/cockatrice/src/carddatabase.cpp @@ -14,6 +14,7 @@ #include #include #include +#include const int CardDatabase::versionNeeded = 3; const char* CardDatabase::TOKENS_SETNAME = "TK"; @@ -1028,6 +1029,8 @@ LoadStatus CardDatabase::loadCardDatabase(const QString &path, bool tokens) allSets.append(setsIterator.next().value()); allSets.sortByKey(); + if(!tokens) + checkUnknownSets(); emit cardListChanged(); } @@ -1098,3 +1101,51 @@ void CardDatabase::picsPathChanged() pictureLoader->setPicsPath(settingsCache->getPicsPath()); clearPixmapCache(); } + +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; +} + +bool CardDatabase::hasDetectedFirstRun() +{ + if(detectedFirstRun) + { + detectedFirstRun=false; + return true; + } + + return false; +} \ No newline at end of file diff --git a/cockatrice/src/carddatabase.h b/cockatrice/src/carddatabase.h index 080a136e..24deb947 100644 --- a/cockatrice/src/carddatabase.h +++ b/cockatrice/src/carddatabase.h @@ -232,12 +232,14 @@ protected: QThread *pictureLoaderThread; PictureLoader *pictureLoader; LoadStatus loadStatus; + bool detectedFirstRun; private: static const int versionNeeded; void loadCardsFromXml(QXmlStreamReader &xml, bool tokens); void loadSetsFromXml(QXmlStreamReader &xml); CardInfo *getCardFromMap(CardNameMap &cardMap, const QString &cardName, bool createIfNotFound); + void checkUnknownSets(); public: static const char* TOKENS_SETNAME; @@ -265,6 +267,7 @@ public: bool getLoadSuccess() const { return loadStatus == Ok; } void cacheCardPixmaps(const QStringList &cardNames); void loadImage(CardInfo *card); + bool hasDetectedFirstRun(); public slots: void clearPixmapCache(); LoadStatus loadCardDatabase(const QString &path, bool tokens = false); diff --git a/cockatrice/src/tab_deck_editor.cpp b/cockatrice/src/tab_deck_editor.cpp index bb3d9e27..74052449 100644 --- a/cockatrice/src/tab_deck_editor.cpp +++ b/cockatrice/src/tab_deck_editor.cpp @@ -293,8 +293,7 @@ TabDeckEditor::TabDeckEditor(TabSupervisor *_tabSupervisor, QWidget *parent) resize(950, 700); - connect(this, SIGNAL(setListChanged()), db, SIGNAL(cardListChanged())); - QTimer::singleShot(0, this, SLOT(checkUnknownSets())); + QTimer::singleShot(0, this, SLOT(checkFirstRunDetected())); } TabDeckEditor::~TabDeckEditor() @@ -786,39 +785,11 @@ void TabDeckEditor::filterRemove(QAction *action) { filterModel->removeRow(idx.row(), idx.parent()); } -void TabDeckEditor::checkUnknownSets() +void TabDeckEditor::checkFirstRunDetected() { - SetList sets = db->getSetList(); - - // no set is enabled. Probably this is the first time running trice - if(!sets.getEnabledSetsNum()) + if(db->hasDetectedFirstRun()) { - sets.guessSortKeys(); - sets.sortByKey(); - sets.enableAll(); - db->emitCardListChanged(); - + QMessageBox::information(this, tr("Welcome"), tr("Hi! Its seems like it's the first time you run this version of Cockatrice.
All the sets in the card database have been enabled; if you want to hide a set from the deck editor, disable it in the \"Edit Sets\" window.")); actEditSets(); - return; - } - - int numUnknownSets = sets.getUnknownSetsNum(); - // no unkown sets. - if(!numUnknownSets) - return; - - int ret = QMessageBox::question(this, 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, QMessageBox::Yes); - - switch(ret) - { - case QMessageBox::No: - sets.markAllAsKnown(); - break; - case QMessageBox::Yes: - sets.enableAllUnknown(); - db->emitCardListChanged(); - break; - default: - break; } } \ No newline at end of file diff --git a/cockatrice/src/tab_deck_editor.h b/cockatrice/src/tab_deck_editor.h index af83703d..f482aaad 100644 --- a/cockatrice/src/tab_deck_editor.h +++ b/cockatrice/src/tab_deck_editor.h @@ -113,10 +113,9 @@ public: bool confirmClose(); public slots: void closeRequest(); - void checkUnknownSets(); + void checkFirstRunDetected(); signals: void deckEditorClosing(TabDeckEditor *tab); - void setListChanged(); }; #endif