showing name of crew and created date of picture

This commit is contained in:
Rafael 2016-05-09 10:24:34 +02:00
parent 5fcc69f5d6
commit 50866075b5
14 changed files with 140 additions and 21 deletions

View file

@ -110,6 +110,11 @@ QByteArray AppEnv::getUserAgent()
return QString("Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Firefox/45.0 gta5sync/1.0").toUtf8();
}
QUrl AppEnv::getCrewFetchingUrl(QString crewID)
{
return QUrl(QString("https://socialclub.rockstargames.com/reference/crewfeed/%1").arg(crewID));
}
QUrl AppEnv::getPlayerFetchingUrl(QString crewID, QString pageNumber)
{
return QUrl(QString("https://socialclub.rockstargames.com/crewsapi/GetMembersList?crewId=%1&pageNumber=%2").arg(crewID, pageNumber));

View file

@ -35,6 +35,7 @@ public:
// Web Stuff
static QByteArray getUserAgent();
static QUrl getCrewFetchingUrl(QString crewID);
static QUrl getPlayerFetchingUrl(QString crewID, QString pageNumber);
};

View file

@ -47,10 +47,35 @@ CrewDatabase::~CrewDatabase()
QStringList CrewDatabase::getCrews()
{
return crewDB->childKeys();
QStringList compatibleCrewList = crewDB->childKeys();
crewDB->endGroup();
crewDB->beginGroup("CrewList");
QStringList crewIDs = crewDB->value("IDs", QStringList()).toStringList();
crewIDs.append(compatibleCrewList);
crewIDs.removeDuplicates();
crewDB->endGroup();
crewDB->beginGroup("Crews");
return crewIDs;
}
QString CrewDatabase::getCrewName(int crewID)
{
return crewDB->value(QString::number(crewID), crewID).toString();
}
void CrewDatabase::setCrewName(int crewID, QString crewName)
{
crewDB->setValue(QString::number(crewID), crewName);
}
void CrewDatabase::addCrew(int crewID)
{
crewDB->setValue(QString::number(crewID), crewID);
QStringList crews = getCrews();
crews.append(QString::number(crewID));
crews.removeDuplicates();
crewDB->endGroup();
crewDB->beginGroup("CrewList");
crewDB->setValue("IDs", crews);
crewDB->endGroup();
crewDB->beginGroup("Crews");
}

View file

@ -28,6 +28,8 @@ class CrewDatabase : public QObject
Q_OBJECT
public:
explicit CrewDatabase(QObject *parent = 0);
void setCrewName(int crewID, QString crewName);
QString getCrewName(int crewID);
QStringList getCrews();
~CrewDatabase();

View file

@ -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)

View file

@ -32,6 +32,7 @@ public:
private:
CrewDatabase *crewDB;
void scanCrewMembersList(QStringList crewList, int maxPages, int requestDelay);
void scanCrewReference(QStringList crewList, int requestDelay);
bool threadRunning;
int crewMaxPages;
int plyrPerReq;

View file

@ -44,8 +44,8 @@
#include <QUrl>
#include <QDir>
PictureDialog::PictureDialog(ProfileDatabase *profileDB, QWidget *parent) :
QDialog(parent), profileDB(profileDB),
PictureDialog::PictureDialog(ProfileDatabase *profileDB, CrewDatabase *crewDB, QWidget *parent) :
QDialog(parent), profileDB(profileDB), crewDB(crewDB),
ui(new Ui::PictureDialog)
{
ui->setupUi(this);
@ -59,6 +59,7 @@ PictureDialog::PictureDialog(ProfileDatabase *profileDB, QWidget *parent) :
picArea = "";
picTitl = "";
picPath = "";
created = "";
crewID = "";
locX = "";
locY = "";
@ -178,7 +179,8 @@ void PictureDialog::setSnapmaticPicture(SnapmaticPicture *picture, QString pictu
locX = QString::number(picture->getLocationX());
locY = QString::number(picture->getLocationY());
locZ = QString::number(picture->getLocationZ());
crewID = QString::number(picture->getCrewNumber());
crewID = crewDB->getCrewName(picture->getCrewNumber());
created = picture->getCreatedDateTime().toString(Qt::DefaultLocaleShortDate);
plyrsList = picture->getPlayers();
picTitl = picture->getPictureTitl();
picArea = picture->getArea();
@ -214,8 +216,8 @@ void PictureDialog::setSnapmaticPicture(SnapmaticPicture *picture, QString pictu
if (crewID == "") { crewID = tr("No crew"); }
this->setWindowTitle(windowTitleStr.arg(picture->getCreatedDateTime().toString(Qt::DefaultLocaleLongDate)));
ui->labJSON->setText(jsonDrawString.arg(locX, locY, locZ, plyrsStr, crewID, picTitl, picAreaStr));
this->setWindowTitle(windowTitleStr.arg(picture->getPictureStr()));
ui->labJSON->setText(jsonDrawString.arg(locX, locY, locZ, plyrsStr, crewID, picTitl, picAreaStr, created));
}
else
{
@ -279,7 +281,7 @@ void PictureDialog::playerNameUpdated()
plyrsStr.append("</a>");
}
plyrsStr.remove(0,2);
ui->labJSON->setText(jsonDrawString.arg(locX, locY, locZ, plyrsStr, crewID, picTitl, picAreaStr));
ui->labJSON->setText(jsonDrawString.arg(locX, locY, locZ, plyrsStr, crewID, picTitl, picAreaStr, created));
}
}

View file

@ -21,6 +21,7 @@
#include "SnapmaticPicture.h"
#include "ProfileDatabase.h"
#include "CrewDatabase.h"
#include <QMouseEvent>
#include <QDialog>
#include <QEvent>
@ -34,7 +35,7 @@ class PictureDialog : public QDialog
{
Q_OBJECT
public:
explicit PictureDialog(ProfileDatabase *profileDB, QWidget *parent = 0);
explicit PictureDialog(ProfileDatabase *profileDB, CrewDatabase *crewDB, QWidget *parent = 0);
void setSnapmaticPicture(SnapmaticPicture *picture, QString picPath, bool readOk, bool indexed, int index);
void setSnapmaticPicture(SnapmaticPicture *picture, QString picPath, bool readOk);
void setSnapmaticPicture(SnapmaticPicture *picture, QString picPath);
@ -71,6 +72,7 @@ protected:
private:
ProfileDatabase *profileDB;
CrewDatabase *crewDB;
Ui::PictureDialog *ui;
QMap<QString, QString> globalMap;
SnapmaticPicture *smpic;
@ -85,6 +87,7 @@ private:
QString picArea;
QString picTitl;
QString picPath;
QString created;
QString crewID;
QString locX;
QString locY;

View file

@ -80,8 +80,8 @@
<property name="text">
<string>&lt;span style=&quot; font-weight:600;&quot;&gt;Title: &lt;/span&gt;%6&lt;br/&gt;
&lt;span style=&quot; font-weight:600;&quot;&gt;Location: &lt;/span&gt;%7 (%1, %2, %3)&lt;br/&gt;
&lt;span style=&quot; font-weight:600;&quot;&gt;Players: &lt;/span&gt;%4&lt;br/&gt;
&lt;span style=&quot; font-weight:600;&quot;&gt;Crew ID: &lt;/span&gt;%5</string>
&lt;span style=&quot; font-weight:600;&quot;&gt;Players: &lt;/span&gt;%4 (Crew %5)&lt;br/&gt;
&lt;span style=&quot; font-weight:600;&quot;&gt;Created: &lt;/span&gt;%8&lt;br/&gt;</string>
</property>
<property name="wordWrap">
<bool>true</bool>

View file

@ -136,7 +136,7 @@ void ProfileInterface::pictureLoaded(SnapmaticPicture *picture, QString pictureP
void ProfileInterface::pictureLoaded_f(SnapmaticPicture *picture, QString picturePath, bool inserted)
{
SnapmaticWidget *picWidget = new SnapmaticWidget(profileDB, threadDB);
SnapmaticWidget *picWidget = new SnapmaticWidget(profileDB, crewDB, threadDB);
picWidget->setSnapmaticPicture(picture, picturePath);
picWidget->setContentMode(contentMode);
widgets[picWidget] = "PIC" + picture->getPictureSortStr();

View file

@ -30,8 +30,8 @@
#include <QMenu>
#include <QFile>
SnapmaticWidget::SnapmaticWidget(ProfileDatabase *profileDB, DatabaseThread *threadDB, QWidget *parent) :
ProfileWidget(parent), profileDB(profileDB), threadDB(threadDB),
SnapmaticWidget::SnapmaticWidget(ProfileDatabase *profileDB, CrewDatabase *crewDB, DatabaseThread *threadDB, QWidget *parent) :
ProfileWidget(parent), profileDB(profileDB), crewDB(crewDB), threadDB(threadDB),
ui(new Ui::SnapmaticWidget)
{
ui->setupUi(this);
@ -95,7 +95,7 @@ void SnapmaticWidget::setSnapmaticPicture(SnapmaticPicture *picture)
void SnapmaticWidget::on_cmdView_clicked()
{
PictureDialog *picDialog = new PictureDialog(profileDB, this);
PictureDialog *picDialog = new PictureDialog(profileDB, crewDB, this);
picDialog->setWindowFlags(picDialog->windowFlags()^Qt::WindowContextHelpButtonHint);
picDialog->setSnapmaticPicture(smpic, picPath, true);
picDialog->setModal(true);

View file

@ -24,6 +24,7 @@
#include "ProfileDatabase.h"
#include "DatabaseThread.h"
#include "ProfileWidget.h"
#include "CrewDatabase.h"
#include <QContextMenuEvent>
#include <QMouseEvent>
#include <QWidget>
@ -38,7 +39,7 @@ class SnapmaticWidget : public ProfileWidget
Q_OBJECT
public:
SnapmaticWidget(ProfileDatabase *profileDB, DatabaseThread *threadDB, QWidget *parent = 0);
SnapmaticWidget(ProfileDatabase *profileDB, CrewDatabase *crewDB, DatabaseThread *threadDB, QWidget *parent = 0);
void setSnapmaticPicture(SnapmaticPicture *picture, QString picturePath);
void setSnapmaticPicture(SnapmaticPicture *picture);
void setSelectionMode(bool selectionMode);
@ -69,6 +70,7 @@ protected:
private:
ProfileDatabase *profileDB;
CrewDatabase *crewDB;
DatabaseThread *threadDB;
Ui::SnapmaticWidget *ui;
SnapmaticPicture *smpic;

View file

@ -406,7 +406,7 @@ bool UserInterface::openFile(QString selectedFile, bool warn)
void UserInterface::openSnapmaticFile(SnapmaticPicture *picture)
{
PictureDialog *picDialog = new PictureDialog(profileDB, this);
PictureDialog *picDialog = new PictureDialog(profileDB, crewDB, this);
picDialog->setWindowFlags(picDialog->windowFlags()^Qt::WindowContextHelpButtonHint);
picDialog->setSnapmaticPicture(picture, true);
picDialog->setModal(true);

View file

@ -252,6 +252,10 @@ int main(int argc, char *argv[])
}
}
}
else if (language == "en" || language == "English")
{
QLocale::setDefault(QLocale(QLocale::English, QLocale::AnyCountry));
}
else
{
QString languageName = language;
@ -360,9 +364,6 @@ int main(int argc, char *argv[])
#endif
// End internal translate loading
QLocale locale;
qDebug() << locale.nativeLanguageName();
QStringList applicationArgs = a.arguments();
QString selectedAction;
QString arg1;
@ -416,7 +417,7 @@ int main(int argc, char *argv[])
CrewDatabase *crewDB = new CrewDatabase();
ProfileDatabase *profileDB = new ProfileDatabase();
DatabaseThread *threadDB = new DatabaseThread(crewDB);
PictureDialog *picDialog = new PictureDialog(profileDB);
PictureDialog *picDialog = new PictureDialog(profileDB, crewDB);
SnapmaticPicture picture;
bool readOk = picture.readingPictureFromFile(arg1);