1 #pragma once
2 
3 #include <QUrlQuery>
4 #include <QDateTime>
5 #include <QTimer>
6 #include <QNetworkRequest>
7 #include <QQueue>
8 
9 struct QueryBuffer
10 {
11     QUrlQuery postQuery;
12     QDateTime time;
13 };
14 
15 class GAnalyticsWorker : public QObject
16 {
17     Q_OBJECT
18 
19 public:
20     explicit GAnalyticsWorker(GAnalytics *parent = 0);
21 
22     GAnalytics *q;
23 
24     QNetworkAccessManager *networkManager = nullptr;
25 
26     QQueue<QueryBuffer> m_messageQueue;
27     QTimer m_timer;
28     QNetworkRequest m_request;
29     GAnalytics::LogLevel m_logLevel;
30 
31     QString m_trackingID;
32     QString m_clientID;
33     QString m_userID;
34     QString m_appName;
35     QString m_appVersion;
36     QString m_language;
37     QString m_screenResolution;
38     QString m_viewportSize;
39 
40     bool m_anonymizeIPs = false;
41     bool m_isEnabled = false;
42     int m_timerInterval = 30000;
43     int m_version = 0;
44 
45     const static int fourHours = 4 * 60 * 60 * 1000;
46     const static QLatin1String dateTimeFormat;
47 
48 public:
49     void logMessage(GAnalytics::LogLevel level, const QString &message);
50 
51     QUrlQuery buildStandardPostQuery(const QString &type);
52     QString getScreenResolution();
53     QString getUserAgent();
54     QList<QString> persistMessageQueue();
55     void readMessagesFromFile(const QList<QString> &dataList);
56 
57     void enqueQueryWithCurrentTime(const QUrlQuery &query);
58     void setIsSending(bool doSend);
59     void enable(bool state);
60 
61 public slots:
62     void postMessage();
63     void postMessageFinished();
64 };
65 
66