summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--application/MultiMC.cpp44
-rw-r--r--application/MultiMC.h1
-rw-r--r--application/pages/global/MultiMCPage.cpp17
-rw-r--r--application/pages/global/MultiMCPage.ui70
-rw-r--r--libraries/ganalytics/include/ganalytics.h7
-rw-r--r--libraries/ganalytics/src/ganalytics.cpp9
-rw-r--r--libraries/ganalytics/src/ganalytics_worker.cpp57
-rw-r--r--libraries/ganalytics/src/ganalytics_worker.h4
8 files changed, 156 insertions, 53 deletions
diff --git a/application/MultiMC.cpp b/application/MultiMC.cpp
index 2a903437..83bb731d 100644
--- a/application/MultiMC.cpp
+++ b/application/MultiMC.cpp
@@ -513,14 +513,11 @@ void MultiMC::initAnalytics()
{
if(BuildConfig.ANALYTICS_ID.isEmpty())
{
- qDebug() << "Analytics disabled by build.";
- return;
- }
- if(!m_settings->get("Analytics").toBool())
- {
- qDebug() << "Analytics disabled by user.";
return;
}
+
+ auto analyticsSetting = m_settings->getSetting("Analytics");
+ connect(analyticsSetting.get(), &Setting::SettingChanged, this, &MultiMC::analyticsSettingChanged);
QString clientID = m_settings->get("AnalyticsClientID").toString();
if(clientID.isEmpty())
{
@@ -533,9 +530,15 @@ void MultiMC::initAnalytics()
m_analytics->setLogLevel(GAnalytics::Debug);
m_analytics->setAnonymizeIPs(true);
m_analytics->setNetworkAccessManager(&ENV.qnam());
- m_analytics->startSending();
+
+ if(!m_settings->get("Analytics").toBool())
+ {
+ qDebug() << "Analytics disabled by user.";
+ return;
+ }
+
+ m_analytics->enable();
qDebug() << "Initialized analytics with tid" << BuildConfig.ANALYTICS_ID << "and cid" << clientID;
- // TODO: load unsent messages?
}
void MultiMC::shutdownAnalytics()
@@ -546,6 +549,22 @@ void MultiMC::shutdownAnalytics()
}
}
+void MultiMC::analyticsSettingChanged(const Setting&, QVariant value)
+{
+ if(!m_analytics)
+ return;
+ bool enabled = value.toBool();
+ if(enabled)
+ {
+ qDebug() << "Analytics enabled by user.";
+ }
+ else
+ {
+ qDebug() << "Analytics disabled by user.";
+ }
+ m_analytics->enable(enabled);
+}
+
void MultiMC::initInstances()
{
auto InstDirSetting = m_settings->getSetting("InstanceDir");
@@ -703,9 +722,12 @@ void MultiMC::initGlobalSettings()
// paste.ee API key
m_settings->registerSetting("PasteEEAPIKey", "multimc");
- // Analytics
- m_settings->registerSetting("Analytics", true);
- m_settings->registerSetting("AnalyticsClientID", QString());
+ if(!BuildConfig.ANALYTICS_ID.isEmpty())
+ {
+ // Analytics
+ m_settings->registerSetting("Analytics", true);
+ m_settings->registerSetting("AnalyticsClientID", QString());
+ }
// Init page provider
{
diff --git a/application/MultiMC.h b/application/MultiMC.h
index 55f63ac4..ae0ed531 100644
--- a/application/MultiMC.h
+++ b/application/MultiMC.h
@@ -162,6 +162,7 @@ private slots:
void controllerSucceeded();
void controllerFailed(const QString & error);
+ void analyticsSettingChanged(const Setting &setting, QVariant value);
private:
void initLogger();
diff --git a/application/pages/global/MultiMCPage.cpp b/application/pages/global/MultiMCPage.cpp
index 03b0c1be..11129d86 100644
--- a/application/pages/global/MultiMCPage.cpp
+++ b/application/pages/global/MultiMCPage.cpp
@@ -75,6 +75,11 @@ MultiMCPage::MultiMCPage(QWidget *parent) : QWidget(parent), ui(new Ui::MultiMCP
{
ui->updateSettingsBox->setHidden(true);
}
+ // Analytics
+ if(BuildConfig.ANALYTICS_ID.isEmpty())
+ {
+ ui->tabWidget->removeTab(ui->tabWidget->indexOf(ui->analyticsTab));
+ }
connect(ui->fontSizeBox, SIGNAL(valueChanged(int)), SLOT(refreshFontPreview()));
connect(ui->consoleFont, SIGNAL(currentFontChanged(QFont)), SLOT(refreshFontPreview()));
}
@@ -346,6 +351,12 @@ void MultiMCPage::applySettings()
s->set("InstSortMode", "Name");
break;
}
+
+ // Analytics
+ if(!BuildConfig.ANALYTICS_ID.isEmpty())
+ {
+ s->set("Analytics", ui->analyticsCheck->isChecked());
+ }
}
void MultiMCPage::loadSettings()
{
@@ -467,6 +478,12 @@ void MultiMCPage::loadSettings()
{
ui->sortByNameBtn->setChecked(true);
}
+
+ // Analytics
+ if(!BuildConfig.ANALYTICS_ID.isEmpty())
+ {
+ ui->analyticsCheck->setChecked(s->get("Analytics").toBool());
+ }
}
void MultiMCPage::refreshFontPreview()
diff --git a/application/pages/global/MultiMCPage.ui b/application/pages/global/MultiMCPage.ui
index 5336afdb..f9d74a38 100644
--- a/application/pages/global/MultiMCPage.ui
+++ b/application/pages/global/MultiMCPage.ui
@@ -6,7 +6,7 @@
<rect>
<x>0</x>
<y>0</y>
- <width>487</width>
+ <width>458</width>
<height>614</height>
</rect>
</property>
@@ -31,6 +31,9 @@
</property>
<item>
<widget class="QTabWidget" name="tabWidget">
+ <property name="toolTip">
+ <string notr="true"/>
+ </property>
<property name="tabShape">
<enum>QTabWidget::Rounded</enum>
</property>
@@ -431,7 +434,7 @@
</item>
</layout>
</widget>
- <widget class="QWidget" name="tab">
+ <widget class="QWidget" name="consoleTab">
<attribute name="title">
<string>Console</string>
</attribute>
@@ -566,6 +569,69 @@
</item>
</layout>
</widget>
+ <widget class="QWidget" name="analyticsTab">
+ <attribute name="title">
+ <string>Analytics</string>
+ </attribute>
+ <layout class="QVBoxLayout" name="verticalLayout_8">
+ <item>
+ <widget class="QGroupBox" name="consoleSettingsBox_2">
+ <property name="title">
+ <string>Analytics Settings</string>
+ </property>
+ <layout class="QVBoxLayout" name="verticalLayout_4">
+ <item>
+ <widget class="QCheckBox" name="analyticsCheck">
+ <property name="text">
+ <string>Send anonymous usage statistics?</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="Line" name="line">
+ <property name="orientation">
+ <enum>Qt::Horizontal</enum>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QLabel" name="label_5">
+ <property name="text">
+ <string>&lt;html&gt;&lt;head/&gt;
+&lt;body&gt;
+&lt;p&gt;MultiMC sends anonymous usage statistics on every start of the application.&lt;/p&gt;&lt;p&gt;The following data is collected:&lt;/p&gt;
+&lt;ul&gt;
+&lt;li&gt;MultiMC version.&lt;/li&gt;
+&lt;li&gt;Operating system name, version and architecture.&lt;/li&gt;
+&lt;li&gt;CPU architecture (kernel architecture on linux).&lt;/li&gt;
+&lt;li&gt;Size of system memory.&lt;/li&gt;
+&lt;li&gt;Java version, architecture and memory settings.&lt;/li&gt;
+&lt;/ul&gt;
+&lt;/body&gt;&lt;/html&gt;</string>
+ </property>
+ <property name="wordWrap">
+ <bool>true</bool>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </widget>
+ </item>
+ <item>
+ <spacer name="verticalSpacer">
+ <property name="orientation">
+ <enum>Qt::Vertical</enum>
+ </property>
+ <property name="sizeHint" stdset="0">
+ <size>
+ <width>20</width>
+ <height>40</height>
+ </size>
+ </property>
+ </spacer>
+ </item>
+ </layout>
+ </widget>
</widget>
</item>
</layout>
diff --git a/libraries/ganalytics/include/ganalytics.h b/libraries/ganalytics/include/ganalytics.h
index 48025dc1..1776c71e 100644
--- a/libraries/ganalytics/include/ganalytics.h
+++ b/libraries/ganalytics/include/ganalytics.h
@@ -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;
diff --git a/libraries/ganalytics/src/ganalytics.cpp b/libraries/ganalytics/src/ganalytics.cpp
index a03dfcad..bc3fe21e 100644
--- a/libraries/ganalytics/src/ganalytics.cpp
+++ b/libraries/ganalytics/src/ganalytics.cpp
@@ -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)
diff --git a/libraries/ganalytics/src/ganalytics_worker.cpp b/libraries/ganalytics/src/ganalytics_worker.cpp
index 2b03e14c..d002924f 100644
--- a/libraries/ganalytics/src/ganalytics_worker.cpp
+++ b/libraries/ganalytics/src/ganalytics_worker.cpp
@@ -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)
@@ -146,30 +167,6 @@ void GAnalyticsWorker::enqueQueryWithCurrentTime(const QUrlQuery &query)
}
/**
- * 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.
* If message was successfully send then this function
@@ -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
diff --git a/libraries/ganalytics/src/ganalytics_worker.h b/libraries/ganalytics/src/ganalytics_worker.h
index 88fa223a..3504a032 100644
--- a/libraries/ganalytics/src/ganalytics_worker.h
+++ b/libraries/ganalytics/src/ganalytics_worker.h
@@ -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();