added ability to change Snapmatic Location

This commit is contained in:
Syping 2017-11-12 15:58:59 +01:00
parent f62b1b08c0
commit a591adf6ea
33 changed files with 1586 additions and 730 deletions

View file

@ -32,9 +32,11 @@
#include <QUrl>
#define crewMaxPages 83
#define maxLoadFails 3
DatabaseThread::DatabaseThread(CrewDatabase *crewDB, QObject *parent) : QThread(parent), crewDB(crewDB)
{
continueLastCrew = true;
threadRunning = true;
}
@ -46,7 +48,7 @@ void DatabaseThread::run()
QStringList crewListR;
// Register thread loop end signal
QObject::connect(this, SIGNAL(threadEndCommited()), &threadLoop, SLOT(quit()));
QObject::connect(this, SIGNAL(threadTerminated()), &threadLoop, SLOT(quit()));
// Setup crewList for Quick time scan
crewList = crewDB->getCrews();
@ -130,7 +132,6 @@ void DatabaseThread::scanCrewReference(const QStringList &crewList, const int &r
if (threadRunning && crewID != QLatin1String("0"))
{
QNetworkAccessManager *netManager = new QNetworkAccessManager();
QNetworkRequest netRequest(AppEnv::getCrewFetchingUrl(crewID));
#if QT_VERSION >= 0x050600
netRequest.setAttribute(QNetworkRequest::FollowRedirectsAttribute, true);
@ -144,9 +145,10 @@ void DatabaseThread::scanCrewReference(const QStringList &crewList, const int &r
QEventLoop *downloadLoop = new QEventLoop();
QObject::connect(netReply, SIGNAL(finished()), downloadLoop, SLOT(quit()));
QObject::connect(this, SIGNAL(threadEndCommited()), downloadLoop, SLOT(quit()));
if (!continueLastCrew) { QObject::connect(this, SIGNAL(threadTerminated()), downloadLoop, SLOT(quit())); }
QTimer::singleShot(30000, downloadLoop, SLOT(quit()));
downloadLoop->exec();
downloadLoop->disconnect();
delete downloadLoop;
if (netReply->isFinished())
@ -168,11 +170,15 @@ void DatabaseThread::scanCrewReference(const QStringList &crewList, const int &r
}
}
QEventLoop *waitingLoop = new QEventLoop();
QTimer::singleShot(requestDelay, waitingLoop, SLOT(quit()));
QObject::connect(this, SIGNAL(threadEndCommited()), waitingLoop, SLOT(quit()));
waitingLoop->exec();
delete waitingLoop;
if (threadRunning)
{
QEventLoop *waitingLoop = new QEventLoop();
QTimer::singleShot(requestDelay, waitingLoop, SLOT(quit()));
if (!continueLastCrew) { QObject::connect(this, SIGNAL(threadTerminated()), waitingLoop, SLOT(quit())); }
waitingLoop->exec();
waitingLoop->disconnect();
delete waitingLoop;
}
delete netReply;
delete netManager;
@ -186,14 +192,14 @@ void DatabaseThread::scanCrewMembersList(const QStringList &crewList, const int
{
if (threadRunning && crewID != QLatin1String("0"))
{
int currentFail = 0;
int currentPage = 0;
int foundPlayers = 0;
int totalPlayers = 1000;
while(foundPlayers < totalPlayers && currentPage < maxPages)
while(foundPlayers < totalPlayers && currentPage < maxPages && (continueLastCrew ? true : threadRunning))
{
QNetworkAccessManager *netManager = new QNetworkAccessManager();
QNetworkRequest netRequest(AppEnv::getPlayerFetchingUrl(crewID, currentPage));
#if QT_VERSION >= 0x050600
netRequest.setAttribute(QNetworkRequest::FollowRedirectsAttribute, true);
@ -207,9 +213,10 @@ void DatabaseThread::scanCrewMembersList(const QStringList &crewList, const int
QEventLoop *downloadLoop = new QEventLoop();
QObject::connect(netReply, SIGNAL(finished()), downloadLoop, SLOT(quit()));
QObject::connect(this, SIGNAL(threadEndCommited()), downloadLoop, SLOT(quit()));
if (!continueLastCrew) { QObject::connect(this, SIGNAL(threadTerminated()), downloadLoop, SLOT(quit())); }
QTimer::singleShot(30000, downloadLoop, SLOT(quit()));
downloadLoop->exec();
downloadLoop->disconnect();
delete downloadLoop;
if (netReply->isFinished())
@ -227,30 +234,43 @@ void DatabaseThread::scanCrewMembersList(const QStringList &crewList, const int
for (QVariant memberVariant : memberList)
{
QMap<QString, QVariant> memberMap = memberVariant.toMap();
foundPlayers++;
if (memberMap.contains("RockstarId") && memberMap.contains("Name"))
{
int RockstarId = memberMap["RockstarId"].toInt();
QString memberName = memberMap["Name"].toString();
if (!memberName.isEmpty() && RockstarId != 0)
{
foundPlayers++;
emit playerNameFound(RockstarId, memberName);
}
}
}
}
QEventLoop *waitingLoop = new QEventLoop();
QTimer::singleShot(requestDelay, waitingLoop, SLOT(quit()));
QObject::connect(this, SIGNAL(threadEndCommited()), waitingLoop, SLOT(quit()));
waitingLoop->exec();
delete waitingLoop;
currentPage++;
}
else
{
currentFail++;
if (currentFail == maxLoadFails)
{
currentFail = 0;
currentPage++;
}
}
delete netReply;
delete netManager;
if (foundPlayers < totalPlayers && currentPage < maxPages && (continueLastCrew ? true : threadRunning))
{
QEventLoop *waitingLoop = new QEventLoop();
QTimer::singleShot(requestDelay, waitingLoop, SLOT(quit()));
if (!continueLastCrew) { QObject::connect(this, SIGNAL(threadTerminated()), waitingLoop, SLOT(quit())); }
waitingLoop->exec();
waitingLoop->disconnect();
delete waitingLoop;
}
}
}
}
@ -258,7 +278,7 @@ void DatabaseThread::scanCrewMembersList(const QStringList &crewList, const int
void DatabaseThread::deleteCompatibleCrews(QStringList *crewList)
{
for (QString& crewNID : *crewList)
for (QString crewNID : *crewList)
{
if (crewDB->isCompatibleCrew(crewNID))
{
@ -270,7 +290,7 @@ void DatabaseThread::deleteCompatibleCrews(QStringList *crewList)
QStringList DatabaseThread::deleteCompatibleCrews(const QStringList &crewList)
{
QStringList crewListR = crewList;
for (QString& crewNID : crewListR)
for (QString crewNID : crewListR)
{
if (crewDB->isCompatibleCrew(crewNID))
{
@ -280,8 +300,8 @@ QStringList DatabaseThread::deleteCompatibleCrews(const QStringList &crewList)
return crewListR;
}
void DatabaseThread::doEndThread()
void DatabaseThread::terminateThread()
{
threadRunning = false;
emit threadEndCommited();
emit threadTerminated();
}