NOISSUE add analytics settings (enable/disable)
This commit is contained in:
@ -39,8 +39,8 @@ public:
|
||||
void setSendInterval(int milliseconds);
|
||||
int sendInterval() const;
|
||||
|
||||
void startSending();
|
||||
bool isSending() const;
|
||||
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);
|
||||
@ -54,9 +54,6 @@ public slots:
|
||||
void startSession();
|
||||
void endSession();
|
||||
|
||||
signals:
|
||||
void isSendingChanged(bool isSending);
|
||||
|
||||
private:
|
||||
GAnalyticsWorker *d;
|
||||
|
||||
|
@ -80,15 +80,14 @@ int GAnalytics::sendInterval() const
|
||||
return (d->m_timer.interval());
|
||||
}
|
||||
|
||||
void GAnalytics::startSending()
|
||||
bool GAnalytics::isEnabled()
|
||||
{
|
||||
if (!isSending())
|
||||
d->postMessage();
|
||||
return d->m_isEnabled;
|
||||
}
|
||||
|
||||
bool GAnalytics::isSending() const
|
||||
void GAnalytics::enable(bool state)
|
||||
{
|
||||
return d->m_isSending;
|
||||
d->enable(state);
|
||||
}
|
||||
|
||||
void GAnalytics::setNetworkAccessManager(QNetworkAccessManager *networkAccessManager)
|
||||
|
@ -23,10 +23,31 @@ GAnalyticsWorker::GAnalyticsWorker(GAnalytics *parent)
|
||||
m_language = QLocale::system().name().toLower().replace("_", "-");
|
||||
m_screenResolution = getScreenResolution();
|
||||
|
||||
m_timer.start(30000);
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
||||
void GAnalyticsWorker::logMessage(GAnalytics::LogLevel level, const QString &message)
|
||||
{
|
||||
if (m_logLevel > level)
|
||||
@ -145,30 +166,6 @@ void GAnalyticsWorker::enqueQueryWithCurrentTime(const QUrlQuery &query)
|
||||
m_messageQueue.enqueue(buffer);
|
||||
}
|
||||
|
||||
/**
|
||||
* Change status of class. Emit signal that status was changed.
|
||||
*/
|
||||
void GAnalyticsWorker::setIsSending(bool doSend)
|
||||
{
|
||||
if (doSend)
|
||||
{
|
||||
m_timer.stop();
|
||||
}
|
||||
else
|
||||
{
|
||||
m_timer.start();
|
||||
}
|
||||
|
||||
bool changed = (m_isSending != doSend);
|
||||
|
||||
m_isSending = doSend;
|
||||
|
||||
if (changed)
|
||||
{
|
||||
emit q->isSendingChanged(m_isSending);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This function is called by a timer interval.
|
||||
* The function tries to send a messages from the queue.
|
||||
@ -183,12 +180,14 @@ void GAnalyticsWorker::postMessage()
|
||||
{
|
||||
if (m_messageQueue.isEmpty())
|
||||
{
|
||||
setIsSending(false);
|
||||
// queue empty -> try sending later
|
||||
m_timer.start();
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
setIsSending(true);
|
||||
// queue has messages -> stop timer and start sending
|
||||
m_timer.stop();
|
||||
}
|
||||
|
||||
QString connection = "close";
|
||||
@ -243,8 +242,8 @@ void GAnalyticsWorker::postMessageFinished()
|
||||
{
|
||||
logMessage(GAnalytics::Error, QString("Error posting message: %s").arg(reply->errorString()));
|
||||
|
||||
// An error ocurred.
|
||||
setIsSending(false);
|
||||
// An error ocurred. Try sending later.
|
||||
m_timer.start();
|
||||
return;
|
||||
}
|
||||
else
|
||||
|
@ -38,7 +38,8 @@ public:
|
||||
QString m_viewportSize;
|
||||
|
||||
bool m_anonymizeIPs = false;
|
||||
bool m_isSending = false;
|
||||
bool m_isEnabled = false;
|
||||
int m_timerInterval = 30000;
|
||||
|
||||
const static int fourHours = 4 * 60 * 60 * 1000;
|
||||
const static QLatin1String dateTimeFormat;
|
||||
@ -54,6 +55,7 @@ public:
|
||||
|
||||
void enqueQueryWithCurrentTime(const QUrlQuery &query);
|
||||
void setIsSending(bool doSend);
|
||||
void enable(bool state);
|
||||
|
||||
public slots:
|
||||
void postMessage();
|
||||
|
Reference in New Issue
Block a user