showing name of crew and created date of picture
This commit is contained in:
parent
5fcc69f5d6
commit
50866075b5
14 changed files with 140 additions and 21 deletions
|
@ -45,11 +45,13 @@ void DatabaseThread::run()
|
|||
// Quick time scan
|
||||
if (crewList.length() <= 3)
|
||||
{
|
||||
scanCrewReference(crewList, 2500);
|
||||
scanCrewMembersList(crewList, 3, 2500);
|
||||
emit playerNameUpdated();
|
||||
}
|
||||
else if (crewList.length() <= 5)
|
||||
{
|
||||
scanCrewReference(crewList, 2500);
|
||||
scanCrewMembersList(crewList, 2, 2500);
|
||||
emit playerNameUpdated();
|
||||
}
|
||||
|
@ -64,6 +66,7 @@ void DatabaseThread::run()
|
|||
crewList = crewDB->getCrews();
|
||||
|
||||
// Long time scan
|
||||
scanCrewReference(crewList, 10000);
|
||||
scanCrewMembersList(crewList, crewMaxPages, 10000);
|
||||
emit playerNameUpdated();
|
||||
|
||||
|
@ -72,6 +75,80 @@ void DatabaseThread::run()
|
|||
}
|
||||
}
|
||||
|
||||
void DatabaseThread::scanCrewReference(QStringList crewList, int requestDelay)
|
||||
{
|
||||
foreach (const QString &crewID, crewList)
|
||||
{
|
||||
if (crewID != "0")
|
||||
{
|
||||
QNetworkAccessManager *netManager = new QNetworkAccessManager();
|
||||
|
||||
QNetworkRequest netRequest(AppEnv::getCrewFetchingUrl(crewID));
|
||||
netRequest.setRawHeader("User-Agent", AppEnv::getUserAgent());
|
||||
netRequest.setRawHeader("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8");
|
||||
netRequest.setRawHeader("Accept-Language", "en-US;q=0.5,en;q=0.3");
|
||||
netRequest.setRawHeader("Connection", "keep-alive");
|
||||
|
||||
QNetworkReply *netReply = netManager->get(netRequest);
|
||||
|
||||
QEventLoop *downloadLoop = new QEventLoop();
|
||||
QObject::connect(netReply, SIGNAL(finished()), downloadLoop, SLOT(quit()));
|
||||
QTimer::singleShot(30000, downloadLoop, SLOT(quit()));
|
||||
downloadLoop->exec();
|
||||
delete downloadLoop;
|
||||
|
||||
if (netReply->isFinished())
|
||||
{
|
||||
QByteArray crewJson = netReply->readAll();
|
||||
QJsonDocument crewDocument = QJsonDocument::fromJson(crewJson);
|
||||
QJsonObject crewObject = crewDocument.object();
|
||||
QVariantMap crewMap = crewObject.toVariantMap();
|
||||
QString crewName;
|
||||
bool isFound = false;
|
||||
|
||||
if (crewMap.contains("activities"))
|
||||
{
|
||||
QList<QVariant> activitiesList = crewMap["activities"].toList();
|
||||
foreach (const QVariant &activitiesVariant, activitiesList)
|
||||
{
|
||||
QMap<QString, QVariant> activityRootMap = activitiesVariant.toMap();
|
||||
foreach(const QVariant &activityRootVariant, activityRootMap)
|
||||
{
|
||||
QMap<QString, QVariant> activityMap = activityRootVariant.toMap();
|
||||
foreach(const QVariant &activityVariant, activityMap)
|
||||
{
|
||||
QMap<QString, QVariant> activityFinalMap = activityVariant.toMap();
|
||||
if (activityFinalMap.contains("id") && activityFinalMap["id"] == crewID)
|
||||
{
|
||||
if (activityFinalMap.contains("name") && isFound == false)
|
||||
{
|
||||
isFound = true;
|
||||
crewName = activityFinalMap["name"].toString();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!crewName.isNull())
|
||||
{
|
||||
crewDB->setCrewName(crewID.toInt(), crewName);
|
||||
}
|
||||
}
|
||||
|
||||
QEventLoop *waitingLoop = new QEventLoop();
|
||||
QTimer::singleShot(requestDelay, waitingLoop, SLOT(quit()));
|
||||
waitingLoop->exec();
|
||||
delete waitingLoop;
|
||||
|
||||
netReply->deleteLater();
|
||||
delete netReply;
|
||||
netManager->deleteLater();
|
||||
delete netManager;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void DatabaseThread::scanCrewMembersList(QStringList crewList, int maxPages, int requestDelay)
|
||||
{
|
||||
foreach (const QString &crewID, crewList)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue