Improve sets handling

Move the “check unknown sets” method inside the cards database, so that
it can be executed when the card database gets reloaded after a card
database update.
Additionally, show the user a welcome message the first time they run a
new cockatrice version, so that they know why they get shown the “edit
sets” window and how to hide/disable sets.
This commit is contained in:
Fabio Bas 2015-05-01 18:55:14 +02:00
parent c356a6fc48
commit 66adeb6d75
4 changed files with 59 additions and 35 deletions

View file

@ -14,6 +14,7 @@
#include <QNetworkRequest>
#include <QDebug>
#include <QImageReader>
#include <QMessageBox>
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;
}