summaryrefslogtreecommitdiffstats
path: root/libraries/ganalytics
diff options
context:
space:
mode:
Diffstat (limited to 'libraries/ganalytics')
-rw-r--r--libraries/ganalytics/include/ganalytics.h72
-rw-r--r--libraries/ganalytics/src/ganalytics.cpp152
-rw-r--r--libraries/ganalytics/src/ganalytics_worker.cpp280
-rw-r--r--libraries/ganalytics/src/ganalytics_worker.h70
4 files changed, 287 insertions, 287 deletions
diff --git a/libraries/ganalytics/include/ganalytics.h b/libraries/ganalytics/include/ganalytics.h
index bfca6d37..ba422457 100644
--- a/libraries/ganalytics/include/ganalytics.h
+++ b/libraries/ganalytics/include/ganalytics.h
@@ -8,59 +8,59 @@ class GAnalyticsWorker;
class GAnalytics : public QObject
{
- Q_OBJECT
- Q_ENUMS(LogLevel)
+ Q_OBJECT
+ Q_ENUMS(LogLevel)
public:
- explicit GAnalytics(const QString &trackingID, const QString &clientID, const int version, QObject *parent = 0);
- ~GAnalytics();
+ explicit GAnalytics(const QString &trackingID, const QString &clientID, const int version, QObject *parent = 0);
+ ~GAnalytics();
public:
- enum LogLevel
- {
- Debug,
- Info,
- Error
- };
+ enum LogLevel
+ {
+ Debug,
+ Info,
+ Error
+ };
- int version();
+ int version();
- void setLogLevel(LogLevel logLevel);
- LogLevel logLevel() const;
+ void setLogLevel(LogLevel logLevel);
+ LogLevel logLevel() const;
- // Getter and Setters
- void setViewportSize(const QString &viewportSize);
- QString viewportSize() const;
+ // Getter and Setters
+ void setViewportSize(const QString &viewportSize);
+ QString viewportSize() const;
- void setLanguage(const QString &language);
- QString language() const;
+ void setLanguage(const QString &language);
+ QString language() const;
- void setAnonymizeIPs(bool anonymize);
- bool anonymizeIPs();
+ void setAnonymizeIPs(bool anonymize);
+ bool anonymizeIPs();
- void setSendInterval(int milliseconds);
- int sendInterval() const;
+ void setSendInterval(int milliseconds);
+ int sendInterval() const;
- void enable(bool state = true);
- bool isEnabled();
+ void enable(bool state = true);
+ bool isEnabled();
- /// Get or set the network access manager. If none is set, the class creates its own on the first request
- void setNetworkAccessManager(QNetworkAccessManager *networkAccessManager);
- QNetworkAccessManager *networkAccessManager() const;
+ /// Get or set the network access manager. If none is set, the class creates its own on the first request
+ void setNetworkAccessManager(QNetworkAccessManager *networkAccessManager);
+ QNetworkAccessManager *networkAccessManager() const;
public slots:
- void sendScreenView(const QString &screenName, const QVariantMap &customValues = QVariantMap());
- void sendEvent(const QString &category, const QString &action, const QString &label = QString(), const QVariant &value = QVariant(),
- const QVariantMap &customValues = QVariantMap());
- void sendException(const QString &exceptionDescription, bool exceptionFatal = true, const QVariantMap &customValues = QVariantMap());
- void startSession();
- void endSession();
+ void sendScreenView(const QString &screenName, const QVariantMap &customValues = QVariantMap());
+ void sendEvent(const QString &category, const QString &action, const QString &label = QString(), const QVariant &value = QVariant(),
+ const QVariantMap &customValues = QVariantMap());
+ void sendException(const QString &exceptionDescription, bool exceptionFatal = true, const QVariantMap &customValues = QVariantMap());
+ void startSession();
+ void endSession();
private:
- GAnalyticsWorker *d;
+ GAnalyticsWorker *d;
- friend QDataStream &operator<<(QDataStream &outStream, const GAnalytics &analytics);
- friend QDataStream &operator>>(QDataStream &inStream, GAnalytics &analytics);
+ friend QDataStream &operator<<(QDataStream &outStream, const GAnalytics &analytics);
+ friend QDataStream &operator>>(QDataStream &inStream, GAnalytics &analytics);
};
QDataStream &operator<<(QDataStream &outStream, const GAnalytics &analytics);
diff --git a/libraries/ganalytics/src/ganalytics.cpp b/libraries/ganalytics/src/ganalytics.cpp
index 5f2d1484..a4b7394f 100644
--- a/libraries/ganalytics/src/ganalytics.cpp
+++ b/libraries/ganalytics/src/ganalytics.cpp
@@ -16,10 +16,10 @@
GAnalytics::GAnalytics(const QString &trackingID, const QString &clientID, const int version, QObject *parent) : QObject(parent)
{
- d = new GAnalyticsWorker(this);
- d->m_trackingID = trackingID;
- d->m_clientID = clientID;
- d->m_version = version;
+ d = new GAnalyticsWorker(this);
+ d->m_trackingID = trackingID;
+ d->m_clientID = clientID;
+ d->m_version = version;
}
/**
@@ -27,100 +27,100 @@ GAnalytics::GAnalytics(const QString &trackingID, const QString &clientID, const
*/
GAnalytics::~GAnalytics()
{
- delete d;
+ delete d;
}
void GAnalytics::setLogLevel(GAnalytics::LogLevel logLevel)
{
- d->m_logLevel = logLevel;
+ d->m_logLevel = logLevel;
}
GAnalytics::LogLevel GAnalytics::logLevel() const
{
- return d->m_logLevel;
+ return d->m_logLevel;
}
// SETTER and GETTER
void GAnalytics::setViewportSize(const QString &viewportSize)
{
- d->m_viewportSize = viewportSize;
+ d->m_viewportSize = viewportSize;
}
QString GAnalytics::viewportSize() const
{
- return d->m_viewportSize;
+ return d->m_viewportSize;
}
void GAnalytics::setLanguage(const QString &language)
{
- d->m_language = language;
+ d->m_language = language;
}
QString GAnalytics::language() const
{
- return d->m_language;
+ return d->m_language;
}
void GAnalytics::setAnonymizeIPs(bool anonymize)
{
- d->m_anonymizeIPs = anonymize;
+ d->m_anonymizeIPs = anonymize;
}
bool GAnalytics::anonymizeIPs()
{
- return d->m_anonymizeIPs;
+ return d->m_anonymizeIPs;
}
void GAnalytics::setSendInterval(int milliseconds)
{
- d->m_timer.setInterval(milliseconds);
+ d->m_timer.setInterval(milliseconds);
}
int GAnalytics::sendInterval() const
{
- return (d->m_timer.interval());
+ return (d->m_timer.interval());
}
bool GAnalytics::isEnabled()
{
- return d->m_isEnabled;
+ return d->m_isEnabled;
}
void GAnalytics::enable(bool state)
{
- d->enable(state);
+ d->enable(state);
}
int GAnalytics::version()
{
- return d->m_version;
+ return d->m_version;
}
void GAnalytics::setNetworkAccessManager(QNetworkAccessManager *networkAccessManager)
{
- if (d->networkManager != networkAccessManager)
- {
- // Delete the old network manager if it was our child
- if (d->networkManager && d->networkManager->parent() == this)
- {
- d->networkManager->deleteLater();
- }
+ if (d->networkManager != networkAccessManager)
+ {
+ // Delete the old network manager if it was our child
+ if (d->networkManager && d->networkManager->parent() == this)
+ {
+ d->networkManager->deleteLater();
+ }
- d->networkManager = networkAccessManager;
- }
+ d->networkManager = networkAccessManager;
+ }
}
QNetworkAccessManager *GAnalytics::networkAccessManager() const
{
- return d->networkManager;
+ return d->networkManager;
}
static void appendCustomValues(QUrlQuery &query, const QVariantMap &customValues)
{
- for (QVariantMap::const_iterator iter = customValues.begin(); iter != customValues.end(); ++iter)
- {
- query.addQueryItem(iter.key(), iter.value().toString());
- }
+ for (QVariantMap::const_iterator iter = customValues.begin(); iter != customValues.end(); ++iter)
+ {
+ query.addQueryItem(iter.key(), iter.value().toString());
+ }
}
/**
@@ -131,15 +131,15 @@ static void appendCustomValues(QUrlQuery &query, const QVariantMap &customValues
*/
void GAnalytics::sendScreenView(const QString &screenName, const QVariantMap &customValues)
{
- d->logMessage(Info, QString("ScreenView: %1").arg(screenName));
+ d->logMessage(Info, QString("ScreenView: %1").arg(screenName));
- QUrlQuery query = d->buildStandardPostQuery("screenview");
- query.addQueryItem("cd", screenName);
- query.addQueryItem("an", d->m_appName);
- query.addQueryItem("av", d->m_appVersion);
- appendCustomValues(query, customValues);
+ QUrlQuery query = d->buildStandardPostQuery("screenview");
+ query.addQueryItem("cd", screenName);
+ query.addQueryItem("an", d->m_appName);
+ query.addQueryItem("av", d->m_appVersion);
+ appendCustomValues(query, customValues);
- d->enqueQueryWithCurrentTime(query);
+ d->enqueQueryWithCurrentTime(query);
}
/**
@@ -149,19 +149,19 @@ void GAnalytics::sendScreenView(const QString &screenName, const QVariantMap &cu
*/
void GAnalytics::sendEvent(const QString &category, const QString &action, const QString &label, const QVariant &value, const QVariantMap &customValues)
{
- QUrlQuery query = d->buildStandardPostQuery("event");
- query.addQueryItem("an", d->m_appName);
- query.addQueryItem("av", d->m_appVersion);
- query.addQueryItem("ec", category);
- query.addQueryItem("ea", action);
- if (!label.isEmpty())
- query.addQueryItem("el", label);
- if (value.isValid())
- query.addQueryItem("ev", value.toString());
+ QUrlQuery query = d->buildStandardPostQuery("event");
+ query.addQueryItem("an", d->m_appName);
+ query.addQueryItem("av", d->m_appVersion);
+ query.addQueryItem("ec", category);
+ query.addQueryItem("ea", action);
+ if (!label.isEmpty())
+ query.addQueryItem("el", label);
+ if (value.isValid())
+ query.addQueryItem("ev", value.toString());
- appendCustomValues(query, customValues);
+ appendCustomValues(query, customValues);
- d->enqueQueryWithCurrentTime(query);
+ d->enqueQueryWithCurrentTime(query);
}
/**
@@ -171,23 +171,23 @@ void GAnalytics::sendEvent(const QString &category, const QString &action, const
*/
void GAnalytics::sendException(const QString &exceptionDescription, bool exceptionFatal, const QVariantMap &customValues)
{
- QUrlQuery query = d->buildStandardPostQuery("exception");
- query.addQueryItem("an", d->m_appName);
- query.addQueryItem("av", d->m_appVersion);
+ QUrlQuery query = d->buildStandardPostQuery("exception");
+ query.addQueryItem("an", d->m_appName);
+ query.addQueryItem("av", d->m_appVersion);
- query.addQueryItem("exd", exceptionDescription);
+ query.addQueryItem("exd", exceptionDescription);
- if (exceptionFatal)
- {
- query.addQueryItem("exf", "1");
- }
- else
- {
- query.addQueryItem("exf", "0");
- }
- appendCustomValues(query, customValues);
+ if (exceptionFatal)
+ {
+ query.addQueryItem("exf", "1");
+ }
+ else
+ {
+ query.addQueryItem("exf", "0");
+ }
+ appendCustomValues(query, customValues);
- d->enqueQueryWithCurrentTime(query);
+ d->enqueQueryWithCurrentTime(query);
}
/**
@@ -197,9 +197,9 @@ void GAnalytics::sendException(const QString &exceptionDescription, bool excepti
*/
void GAnalytics::startSession()
{
- QVariantMap customValues;
- customValues.insert("sc", "start");
- sendEvent("Session", "Start", QString(), QVariant(), customValues);
+ QVariantMap customValues;
+ customValues.insert("sc", "start");
+ sendEvent("Session", "Start", QString(), QVariant(), customValues);
}
/**
@@ -209,9 +209,9 @@ void GAnalytics::startSession()
*/
void GAnalytics::endSession()
{
- QVariantMap customValues;
- customValues.insert("sc", "end");
- sendEvent("Session", "End", QString(), QVariant(), customValues);
+ QVariantMap customValues;
+ customValues.insert("sc", "end");
+ sendEvent("Session", "End", QString(), QVariant(), customValues);
}
/**
@@ -219,9 +219,9 @@ void GAnalytics::endSession()
*/
QDataStream &operator<<(QDataStream &outStream, const GAnalytics &analytics)
{
- outStream << analytics.d->persistMessageQueue();
+ outStream << analytics.d->persistMessageQueue();
- return outStream;
+ return outStream;
}
/**
@@ -229,9 +229,9 @@ QDataStream &operator<<(QDataStream &outStream, const GAnalytics &analytics)
*/
QDataStream &operator>>(QDataStream &inStream, GAnalytics &analytics)
{
- QList<QString> dataList;
- inStream >> dataList;
- analytics.d->readMessagesFromFile(dataList);
+ QList<QString> dataList;
+ inStream >> dataList;
+ analytics.d->readMessagesFromFile(dataList);
- return inStream;
+ return inStream;
}
diff --git a/libraries/ganalytics/src/ganalytics_worker.cpp b/libraries/ganalytics/src/ganalytics_worker.cpp
index f55a4d09..5980d3bd 100644
--- a/libraries/ganalytics/src/ganalytics_worker.cpp
+++ b/libraries/ganalytics/src/ganalytics_worker.cpp
@@ -12,50 +12,50 @@
const QLatin1String GAnalyticsWorker::dateTimeFormat("yyyy,MM,dd-hh:mm::ss:zzz");
GAnalyticsWorker::GAnalyticsWorker(GAnalytics *parent)
- : QObject(parent), q(parent), m_logLevel(GAnalytics::Error)
+ : QObject(parent), q(parent), m_logLevel(GAnalytics::Error)
{
- m_appName = QCoreApplication::instance()->applicationName();
- m_appVersion = QCoreApplication::instance()->applicationVersion();
- m_request.setUrl(QUrl("https://www.google-analytics.com/collect"));
- m_request.setHeader(QNetworkRequest::ContentTypeHeader, "application/x-www-form-urlencoded");
- m_request.setHeader(QNetworkRequest::UserAgentHeader, getUserAgent());
+ m_appName = QCoreApplication::instance()->applicationName();
+ m_appVersion = QCoreApplication::instance()->applicationVersion();
+ m_request.setUrl(QUrl("https://www.google-analytics.com/collect"));
+ m_request.setHeader(QNetworkRequest::ContentTypeHeader, "application/x-www-form-urlencoded");
+ m_request.setHeader(QNetworkRequest::UserAgentHeader, getUserAgent());
- m_language = QLocale::system().name().toLower().replace("_", "-");
- m_screenResolution = getScreenResolution();
+ m_language = QLocale::system().name().toLower().replace("_", "-");
+ m_screenResolution = getScreenResolution();
- m_timer.setInterval(m_timerInterval);
- connect(&m_timer, &QTimer::timeout, this, &GAnalyticsWorker::postMessage);
+ m_timer.setInterval(m_timerInterval);
+ connect(&m_timer, &QTimer::timeout, this, &GAnalyticsWorker::postMessage);
}
void GAnalyticsWorker::enable(bool state)
{
- // state change to the same is not valid.
- if(m_isEnabled == state)
- {
- return;
- }
-
- m_isEnabled = state;
- if(m_isEnabled)
- {
- // enable -> start doing things :)
- m_timer.start();
- }
- else
- {
- // disable -> stop the timer
- m_timer.stop();
- }
+ // state change to the same is not valid.
+ if(m_isEnabled == state)
+ {
+ return;
+ }
+
+ m_isEnabled = state;
+ if(m_isEnabled)
+ {
+ // enable -> start doing things :)
+ m_timer.start();
+ }
+ else
+ {
+ // disable -> stop the timer
+ m_timer.stop();
+ }
}
void GAnalyticsWorker::logMessage(GAnalytics::LogLevel level, const QString &message)
{
- if (m_logLevel > level)
- {
- return;
- }
+ if (m_logLevel > level)
+ {
+ return;
+ }
- qDebug() << "[Analytics]" << message;
+ qDebug() << "[Analytics]" << message;
}
/**
@@ -66,23 +66,23 @@ void GAnalyticsWorker::logMessage(GAnalytics::LogLevel level, const QString &mes
*/
QUrlQuery GAnalyticsWorker::buildStandardPostQuery(const QString &type)
{
- QUrlQuery query;
- query.addQueryItem("v", "1");
- query.addQueryItem("tid", m_trackingID);
- query.addQueryItem("cid", m_clientID);
- if (!m_userID.isEmpty())
- {
- query.addQueryItem("uid", m_userID);
- }
- query.addQueryItem("t", type);
- query.addQueryItem("ul", m_language);
- query.addQueryItem("vp", m_viewportSize);
- query.addQueryItem("sr", m_screenResolution);
- if(m_anonymizeIPs)
- {
- query.addQueryItem("aip", "1");
- }
- return query;
+ QUrlQuery query;
+ query.addQueryItem("v", "1");
+ query.addQueryItem("tid", m_trackingID);
+ query.addQueryItem("cid", m_clientID);
+ if (!m_userID.isEmpty())
+ {
+ query.addQueryItem("uid", m_userID);
+ }
+ query.addQueryItem("t", type);
+ query.addQueryItem("ul", m_language);
+ query.addQueryItem("vp", m_viewportSize);
+ query.addQueryItem("sr", m_screenResolution);
+ if(m_anonymizeIPs)
+ {
+ query.addQueryItem("aip", "1");
+ }
+ return query;
}
/**
@@ -91,10 +91,10 @@ QUrlQuery GAnalyticsWorker::buildStandardPostQuery(const QString &type)
*/
QString GAnalyticsWorker::getScreenResolution()
{
- QScreen *screen = QGuiApplication::primaryScreen();
- QSize size = screen->size();
+ QScreen *screen = QGuiApplication::primaryScreen();
+ QSize size = screen->size();
- return QString("%1x%2").arg(size.width()).arg(size.height());
+ return QString("%1x%2").arg(size.width()).arg(size.height());
}
/**
@@ -106,7 +106,7 @@ QString GAnalyticsWorker::getScreenResolution()
*/
QString GAnalyticsWorker::getUserAgent()
{
- return QString("%1/%2").arg(m_appName).arg(m_appVersion);
+ return QString("%1/%2").arg(m_appName).arg(m_appVersion);
}
/**
@@ -118,13 +118,13 @@ QString GAnalyticsWorker::getUserAgent()
*/
QList<QString> GAnalyticsWorker::persistMessageQueue()
{
- QList<QString> dataList;
- foreach (QueryBuffer buffer, m_messageQueue)
- {
- dataList << buffer.postQuery.toString();
- dataList << buffer.time.toString(dateTimeFormat);
- }
- return dataList;
+ QList<QString> dataList;
+ foreach (QueryBuffer buffer, m_messageQueue)
+ {
+ dataList << buffer.postQuery.toString();
+ dataList << buffer.time.toString(dateTimeFormat);
+ }
+ return dataList;
}
/**
@@ -134,19 +134,19 @@ QList<QString> GAnalyticsWorker::persistMessageQueue()
*/
void GAnalyticsWorker::readMessagesFromFile(const QList<QString> &dataList)
{
- QListIterator<QString> iter(dataList);
- while (iter.hasNext())
- {
- QString queryString = iter.next();
- QString dateString = iter.next();
- QUrlQuery query;
- query.setQuery(queryString);
- QDateTime dateTime = QDateTime::fromString(dateString, dateTimeFormat);
- QueryBuffer buffer;
- buffer.postQuery = query;
- buffer.time = dateTime;
- m_messageQueue.enqueue(buffer);
- }
+ QListIterator<QString> iter(dataList);
+ while (iter.hasNext())
+ {
+ QString queryString = iter.next();
+ QString dateString = iter.next();
+ QUrlQuery query;
+ query.setQuery(queryString);
+ QDateTime dateTime = QDateTime::fromString(dateString, dateTimeFormat);
+ QueryBuffer buffer;
+ buffer.postQuery = query;
+ buffer.time = dateTime;
+ m_messageQueue.enqueue(buffer);
+ }
}
/**
@@ -156,11 +156,11 @@ void GAnalyticsWorker::readMessagesFromFile(const QList<QString> &dataList)
*/
void GAnalyticsWorker::enqueQueryWithCurrentTime(const QUrlQuery &query)
{
- QueryBuffer buffer;
- buffer.postQuery = query;
- buffer.time = QDateTime::currentDateTime();
+ QueryBuffer buffer;
+ buffer.postQuery = query;
+ buffer.time = QDateTime::currentDateTime();
- m_messageQueue.enqueue(buffer);
+ m_messageQueue.enqueue(buffer);
}
/**
@@ -175,50 +175,50 @@ void GAnalyticsWorker::enqueQueryWithCurrentTime(const QUrlQuery &query)
*/
void GAnalyticsWorker::postMessage()
{
- if (m_messageQueue.isEmpty())
- {
- // queue empty -> try sending later
- m_timer.start();
- return;
- }
- else
- {
- // queue has messages -> stop timer and start sending
- m_timer.stop();
- }
-
- QString connection = "close";
- if (m_messageQueue.count() > 1)
- {
- connection = "keep-alive";
- }
-
- QueryBuffer buffer = m_messageQueue.head();
- QDateTime sendTime = QDateTime::currentDateTime();
- qint64 timeDiff = buffer.time.msecsTo(sendTime);
-
- if (timeDiff > fourHours)
- {
- // too old.
- m_messageQueue.dequeue();
- emit postMessage();
- return;
- }
-
- buffer.postQuery.addQueryItem("qt", QString::number(timeDiff));
- m_request.setRawHeader("Connection", connection.toUtf8());
- m_request.setHeader(QNetworkRequest::ContentLengthHeader, buffer.postQuery.toString().length());
-
- logMessage(GAnalytics::Debug, "Query string = " + buffer.postQuery.toString());
-
- // Create a new network access manager if we don't have one yet
- if (networkManager == NULL)
- {
- networkManager = new QNetworkAccessManager(this);
- }
-
- QNetworkReply *reply = networkManager->post(m_request, buffer.postQuery.query(QUrl::EncodeUnicode).toUtf8());
- connect(reply, SIGNAL(finished()), this, SLOT(postMessageFinished()));
+ if (m_messageQueue.isEmpty())
+ {
+ // queue empty -> try sending later
+ m_timer.start();
+ return;
+ }
+ else
+ {
+ // queue has messages -> stop timer and start sending
+ m_timer.stop();
+ }
+
+ QString connection = "close";
+ if (m_messageQueue.count() > 1)
+ {
+ connection = "keep-alive";
+ }
+
+ QueryBuffer buffer = m_messageQueue.head();
+ QDateTime sendTime = QDateTime::currentDateTime();
+ qint64 timeDiff = buffer.time.msecsTo(sendTime);
+
+ if (timeDiff > fourHours)
+ {
+ // too old.
+ m_messageQueue.dequeue();
+ emit postMessage();
+ return;
+ }
+
+ buffer.postQuery.addQueryItem("qt", QString::number(timeDiff));
+ m_request.setRawHeader("Connection", connection.toUtf8());
+ m_request.setHeader(QNetworkRequest::ContentLengthHeader, buffer.postQuery.toString().length());
+
+ logMessage(GAnalytics::Debug, "Query string = " + buffer.postQuery.toString());
+
+ // Create a new network access manager if we don't have one yet
+ if (networkManager == NULL)
+ {
+ networkManager = new QNetworkAccessManager(this);
+ }
+
+ QNetworkReply *reply = networkManager->post(m_request, buffer.postQuery.query(QUrl::EncodeUnicode).toUtf8());
+ connect(reply, SIGNAL(finished()), this, SLOT(postMessageFinished()));
}
/**
@@ -232,23 +232,23 @@ void GAnalyticsWorker::postMessage()
*/
void GAnalyticsWorker::postMessageFinished()
{
- QNetworkReply *reply = qobject_cast<QNetworkReply *>(sender());
-
- int httpStausCode = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt();
- if (httpStausCode < 200 || httpStausCode > 299)
- {
- logMessage(GAnalytics::Error, QString("Error posting message: %s").arg(reply->errorString()));
-
- // An error ocurred. Try sending later.
- m_timer.start();
- return;
- }
- else
- {
- logMessage(GAnalytics::Debug, "Message sent");
- }
-
- m_messageQueue.dequeue();
- postMessage();
- reply->deleteLater();
+ QNetworkReply *reply = qobject_cast<QNetworkReply *>(sender());
+
+ int httpStausCode = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt();
+ if (httpStausCode < 200 || httpStausCode > 299)
+ {
+ logMessage(GAnalytics::Error, QString("Error posting message: %s").arg(reply->errorString()));
+
+ // An error ocurred. Try sending later.
+ m_timer.start();
+ return;
+ }
+ else
+ {
+ logMessage(GAnalytics::Debug, "Message sent");
+ }
+
+ m_messageQueue.dequeue();
+ postMessage();
+ reply->deleteLater();
}
diff --git a/libraries/ganalytics/src/ganalytics_worker.h b/libraries/ganalytics/src/ganalytics_worker.h
index 559e0eb6..1962f799 100644
--- a/libraries/ganalytics/src/ganalytics_worker.h
+++ b/libraries/ganalytics/src/ganalytics_worker.h
@@ -8,58 +8,58 @@
struct QueryBuffer
{
- QUrlQuery postQuery;
- QDateTime time;
+ QUrlQuery postQuery;
+ QDateTime time;
};
class GAnalyticsWorker : public QObject
{
- Q_OBJECT
+ Q_OBJECT
public:
- explicit GAnalyticsWorker(GAnalytics *parent = 0);
+ explicit GAnalyticsWorker(GAnalytics *parent = 0);
- GAnalytics *q;
+ GAnalytics *q;
- QNetworkAccessManager *networkManager = nullptr;
+ QNetworkAccessManager *networkManager = nullptr;
- QQueue<QueryBuffer> m_messageQueue;
- QTimer m_timer;
- QNetworkRequest m_request;
- GAnalytics::LogLevel m_logLevel;
+ QQueue<QueryBuffer> m_messageQueue;
+ QTimer m_timer;
+ QNetworkRequest m_request;
+ GAnalytics::LogLevel m_logLevel;
- QString m_trackingID;
- QString m_clientID;
- QString m_userID;
- QString m_appName;
- QString m_appVersion;
- QString m_language;
- QString m_screenResolution;
- QString m_viewportSize;
+ QString m_trackingID;
+ QString m_clientID;
+ QString m_userID;
+ QString m_appName;
+ QString m_appVersion;
+ QString m_language;
+ QString m_screenResolution;
+ QString m_viewportSize;
- bool m_anonymizeIPs = false;
- bool m_isEnabled = false;
- int m_timerInterval = 30000;
- int m_version = 0;
+ bool m_anonymizeIPs = false;
+ bool m_isEnabled = false;
+ int m_timerInterval = 30000;
+ int m_version = 0;
- const static int fourHours = 4 * 60 * 60 * 1000;
- const static QLatin1String dateTimeFormat;
+ const static int fourHours = 4 * 60 * 60 * 1000;
+ const static QLatin1String dateTimeFormat;
public:
- void logMessage(GAnalytics::LogLevel level, const QString &message);
+ void logMessage(GAnalytics::LogLevel level, const QString &message);
- QUrlQuery buildStandardPostQuery(const QString &type);
- QString getScreenResolution();
- QString getUserAgent();
- QList<QString> persistMessageQueue();
- void readMessagesFromFile(const QList<QString> &dataList);
+ QUrlQuery buildStandardPostQuery(const QString &type);
+ QString getScreenResolution();
+ QString getUserAgent();
+ QList<QString> persistMessageQueue();
+ void readMessagesFromFile(const QList<QString> &dataList);
- void enqueQueryWithCurrentTime(const QUrlQuery &query);
- void setIsSending(bool doSend);
- void enable(bool state);
+ void enqueQueryWithCurrentTime(const QUrlQuery &query);
+ void setIsSending(bool doSend);
+ void enable(bool state);
public slots:
- void postMessage();
- void postMessageFinished();
+ void postMessage();
+ void postMessageFinished();
};