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(); 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) QUrl AppEnv::getPlayerFetchingUrl(QString crewID, QString pageNumber)
{ {
return QUrl(QString("https://socialclub.rockstargames.com/crewsapi/GetMembersList?crewId=%1&pageNumber=%2").arg(crewID, 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 // Web Stuff
static QByteArray getUserAgent(); static QByteArray getUserAgent();
static QUrl getCrewFetchingUrl(QString crewID);
static QUrl getPlayerFetchingUrl(QString crewID, QString pageNumber); static QUrl getPlayerFetchingUrl(QString crewID, QString pageNumber);
}; };

View file

@ -47,10 +47,35 @@ CrewDatabase::~CrewDatabase()
QStringList CrewDatabase::getCrews() 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) 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 Q_OBJECT
public: public:
explicit CrewDatabase(QObject *parent = 0); explicit CrewDatabase(QObject *parent = 0);
void setCrewName(int crewID, QString crewName);
QString getCrewName(int crewID);
QStringList getCrews(); QStringList getCrews();
~CrewDatabase(); ~CrewDatabase();

View file

@ -45,11 +45,13 @@ void DatabaseThread::run()
// Quick time scan // Quick time scan
if (crewList.length() <= 3) if (crewList.length() <= 3)
{ {
scanCrewReference(crewList, 2500);
scanCrewMembersList(crewList, 3, 2500); scanCrewMembersList(crewList, 3, 2500);
emit playerNameUpdated(); emit playerNameUpdated();
} }
else if (crewList.length() <= 5) else if (crewList.length() <= 5)
{ {
scanCrewReference(crewList, 2500);
scanCrewMembersList(crewList, 2, 2500); scanCrewMembersList(crewList, 2, 2500);
emit playerNameUpdated(); emit playerNameUpdated();
} }
@ -64,6 +66,7 @@ void DatabaseThread::run()
crewList = crewDB->getCrews(); crewList = crewDB->getCrews();
// Long time scan // Long time scan
scanCrewReference(crewList, 10000);
scanCrewMembersList(crewList, crewMaxPages, 10000); scanCrewMembersList(crewList, crewMaxPages, 10000);
emit playerNameUpdated(); 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) void DatabaseThread::scanCrewMembersList(QStringList crewList, int maxPages, int requestDelay)
{ {
foreach (const QString &crewID, crewList) foreach (const QString &crewID, crewList)

View file

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

View file

@ -44,8 +44,8 @@
#include <QUrl> #include <QUrl>
#include <QDir> #include <QDir>
PictureDialog::PictureDialog(ProfileDatabase *profileDB, QWidget *parent) : PictureDialog::PictureDialog(ProfileDatabase *profileDB, CrewDatabase *crewDB, QWidget *parent) :
QDialog(parent), profileDB(profileDB), QDialog(parent), profileDB(profileDB), crewDB(crewDB),
ui(new Ui::PictureDialog) ui(new Ui::PictureDialog)
{ {
ui->setupUi(this); ui->setupUi(this);
@ -59,6 +59,7 @@ PictureDialog::PictureDialog(ProfileDatabase *profileDB, QWidget *parent) :
picArea = ""; picArea = "";
picTitl = ""; picTitl = "";
picPath = ""; picPath = "";
created = "";
crewID = ""; crewID = "";
locX = ""; locX = "";
locY = ""; locY = "";
@ -178,7 +179,8 @@ void PictureDialog::setSnapmaticPicture(SnapmaticPicture *picture, QString pictu
locX = QString::number(picture->getLocationX()); locX = QString::number(picture->getLocationX());
locY = QString::number(picture->getLocationY()); locY = QString::number(picture->getLocationY());
locZ = QString::number(picture->getLocationZ()); locZ = QString::number(picture->getLocationZ());
crewID = QString::number(picture->getCrewNumber()); crewID = crewDB->getCrewName(picture->getCrewNumber());
created = picture->getCreatedDateTime().toString(Qt::DefaultLocaleShortDate);
plyrsList = picture->getPlayers(); plyrsList = picture->getPlayers();
picTitl = picture->getPictureTitl(); picTitl = picture->getPictureTitl();
picArea = picture->getArea(); picArea = picture->getArea();
@ -214,8 +216,8 @@ void PictureDialog::setSnapmaticPicture(SnapmaticPicture *picture, QString pictu
if (crewID == "") { crewID = tr("No crew"); } if (crewID == "") { crewID = tr("No crew"); }
this->setWindowTitle(windowTitleStr.arg(picture->getCreatedDateTime().toString(Qt::DefaultLocaleLongDate))); this->setWindowTitle(windowTitleStr.arg(picture->getPictureStr()));
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));
} }
else else
{ {
@ -279,7 +281,7 @@ void PictureDialog::playerNameUpdated()
plyrsStr.append("</a>"); plyrsStr.append("</a>");
} }
plyrsStr.remove(0,2); 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 "SnapmaticPicture.h"
#include "ProfileDatabase.h" #include "ProfileDatabase.h"
#include "CrewDatabase.h"
#include <QMouseEvent> #include <QMouseEvent>
#include <QDialog> #include <QDialog>
#include <QEvent> #include <QEvent>
@ -34,7 +35,7 @@ class PictureDialog : public QDialog
{ {
Q_OBJECT Q_OBJECT
public: 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, bool indexed, int index);
void setSnapmaticPicture(SnapmaticPicture *picture, QString picPath, bool readOk); void setSnapmaticPicture(SnapmaticPicture *picture, QString picPath, bool readOk);
void setSnapmaticPicture(SnapmaticPicture *picture, QString picPath); void setSnapmaticPicture(SnapmaticPicture *picture, QString picPath);
@ -71,6 +72,7 @@ protected:
private: private:
ProfileDatabase *profileDB; ProfileDatabase *profileDB;
CrewDatabase *crewDB;
Ui::PictureDialog *ui; Ui::PictureDialog *ui;
QMap<QString, QString> globalMap; QMap<QString, QString> globalMap;
SnapmaticPicture *smpic; SnapmaticPicture *smpic;
@ -85,6 +87,7 @@ private:
QString picArea; QString picArea;
QString picTitl; QString picTitl;
QString picPath; QString picPath;
QString created;
QString crewID; QString crewID;
QString locX; QString locX;
QString locY; QString locY;

View file

@ -80,8 +80,8 @@
<property name="text"> <property name="text">
<string>&lt;span style=&quot; font-weight:600;&quot;&gt;Title: &lt;/span&gt;%6&lt;br/&gt; <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;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;Players: &lt;/span&gt;%4 (Crew %5)&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;Created: &lt;/span&gt;%8&lt;br/&gt;</string>
</property> </property>
<property name="wordWrap"> <property name="wordWrap">
<bool>true</bool> <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) 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->setSnapmaticPicture(picture, picturePath);
picWidget->setContentMode(contentMode); picWidget->setContentMode(contentMode);
widgets[picWidget] = "PIC" + picture->getPictureSortStr(); widgets[picWidget] = "PIC" + picture->getPictureSortStr();

View file

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

View file

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

View file

@ -406,7 +406,7 @@ bool UserInterface::openFile(QString selectedFile, bool warn)
void UserInterface::openSnapmaticFile(SnapmaticPicture *picture) 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->setWindowFlags(picDialog->windowFlags()^Qt::WindowContextHelpButtonHint);
picDialog->setSnapmaticPicture(picture, true); picDialog->setSnapmaticPicture(picture, true);
picDialog->setModal(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 else
{ {
QString languageName = language; QString languageName = language;
@ -360,9 +364,6 @@ int main(int argc, char *argv[])
#endif #endif
// End internal translate loading // End internal translate loading
QLocale locale;
qDebug() << locale.nativeLanguageName();
QStringList applicationArgs = a.arguments(); QStringList applicationArgs = a.arguments();
QString selectedAction; QString selectedAction;
QString arg1; QString arg1;
@ -416,7 +417,7 @@ int main(int argc, char *argv[])
CrewDatabase *crewDB = new CrewDatabase(); CrewDatabase *crewDB = new CrewDatabase();
ProfileDatabase *profileDB = new ProfileDatabase(); ProfileDatabase *profileDB = new ProfileDatabase();
DatabaseThread *threadDB = new DatabaseThread(crewDB); DatabaseThread *threadDB = new DatabaseThread(crewDB);
PictureDialog *picDialog = new PictureDialog(profileDB); PictureDialog *picDialog = new PictureDialog(profileDB, crewDB);
SnapmaticPicture picture; SnapmaticPicture picture;
bool readOk = picture.readingPictureFromFile(arg1); bool readOk = picture.readingPictureFromFile(arg1);