aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEike Ziller <[email protected]>2025-08-12 14:50:49 +0200
committerEike Ziller <[email protected]>2025-08-12 14:50:49 +0200
commitaeb069da0b9e5d41c4f33d892591107dc8852e3f (patch)
tree9b4dae7b858474988f58db34a5d2401d980b34f7
parentd5875afb3b1c75bccfec01337e1cee4d9a5b6cd8 (diff)
parent80352e4d49092706fe87677369abe1cbe530a0f7 (diff)
Merge remote-tracking branch 'origin/17.0'HEADmaster
-rw-r--r--src/usagestatisticplugin.cpp54
1 files changed, 41 insertions, 13 deletions
diff --git a/src/usagestatisticplugin.cpp b/src/usagestatisticplugin.cpp
index 4e630e1..380083f 100644
--- a/src/usagestatisticplugin.cpp
+++ b/src/usagestatisticplugin.cpp
@@ -54,6 +54,17 @@ namespace UsageStatistic::Internal {
static UsageStatisticPlugin *m_instance = nullptr;
+#define QT_WITH_CONTEXTDATA QT_VERSION_CHECK(6, 9, 2)
+
+static void addEvent(QInsightTracker *tracker, const QString &key, const QString &data)
+{
+#if QT_VERSION >= QT_WITH_CONTEXTDATA
+ tracker->contextData(key, data);
+#else
+ tracker->interaction(key, data, 0);
+#endif
+}
+
static QString hashed(const QString &path)
{
return QString::fromLatin1(
@@ -88,11 +99,11 @@ class UILanguage : public QObject
public:
UILanguage(QInsightTracker *tracker)
{
- tracker->interaction(":CONFIG:UILanguage", ICore::userInterfaceLanguage(), 0);
+ addEvent(tracker, ":CONFIG:UILanguage", ICore::userInterfaceLanguage());
const QStringList languages = QLocale::system().uiLanguages();
- tracker->interaction(":CONFIG:SystemLanguage",
- languages.isEmpty() ? QString("Unknown") : languages.first(),
- 0);
+ addEvent(tracker,
+ ":CONFIG:SystemLanguage",
+ languages.isEmpty() ? QString("Unknown") : languages.first());
}
};
@@ -102,13 +113,11 @@ class Theme : public QObject
public:
Theme(QInsightTracker *tracker)
{
- tracker->interaction(":CONFIG:Theme",
- creatorTheme() ? creatorTheme()->id() : QString("Unknown"),
- 0);
+ addEvent(tracker, ":CONFIG:Theme", creatorTheme() ? creatorTheme()->id() : QString("Unknown"));
const QString systemTheme = QString::fromUtf8(QMetaEnum::fromType<Qt::ColorScheme>().valueToKey(
int(Utils::Theme::systemColorScheme())))
.toLower();
- tracker->interaction(":CONFIG:SystemTheme", systemTheme, 0);
+ addEvent(tracker, ":CONFIG:SystemTheme", systemTheme);
}
};
@@ -152,7 +161,7 @@ public:
+ "\"],\"qtversion\":\""
+ qtVersion->qtVersion().toString() + "\"}";
qCDebug(qtmodulesLog) << qPrintable(json);
- tracker->interaction("QtModules", json, 0);
+ addEvent(tracker, "QtModules", json);
});
});
}
@@ -185,7 +194,7 @@ public:
+ "\",\"qtversion\":\""
+ qtVersion->qtVersion().toString() + "\"}";
qCDebug(qtexampleLog) << qPrintable(json);
- tracker->interaction("QtExample", json, 0);
+ addEvent(tracker, "QtExample", json);
return;
}
});
@@ -322,12 +331,26 @@ ExtensionSystem::IPlugin::ShutdownFlag UsageStatisticPlugin::aboutToShutdown()
return SynchronousShutdown;
}
-static constexpr int submissionInterval()
+static constexpr int defaultSubmissionInterval()
{
using namespace std::literals;
return std::chrono::hours(1) / 1s;
}
+static constexpr int defaultBatchSize()
+{
+ return 100;
+}
+
+static int fromEnvironment(const QString &key, int defaultValue)
+{
+ bool ok = false;
+ const int env = qtcEnvironmentVariableIntValue(key, &ok);
+ if (ok)
+ return env;
+ return defaultValue;
+}
+
void UsageStatisticPlugin::configureInsight()
{
qCDebug(statLog) << "Configuring insight, enabled:" << theSettings().trackingEnabled.value();
@@ -353,8 +376,9 @@ void UsageStatisticPlugin::configureInsight()
qCDebug(statLog) << "Cache path:" << config->storagePath();
// TODO provide a button for removing the cache?
// TODO config->setStorageSize(???); // unlimited by default
- config->setSyncInterval(submissionInterval());
- config->setBatchSize(100);
+ config->setSyncInterval(
+ fromEnvironment("QTC_INSIGHT_SUBMISSIONINTERVAL", defaultSubmissionInterval()));
+ config->setBatchSize(fromEnvironment("QTC_INSIGHT_BATCHSIZE", defaultBatchSize()));
config->setDeviceModel(QString("%1 (%2)").arg(QSysInfo::productType(),
QSysInfo::currentCpuArchitecture()));
config->setDeviceVariant(QSysInfo::productVersion());
@@ -408,8 +432,12 @@ void UsageStatisticPlugin::createProviders()
{
// startup configs first, otherwise they will be attributed to the UI state
m_providers.push_back(std::make_unique<Theme>(m_tracker.get()));
+ // module and example telemetry require QInsightTracker::contextData to
+ // work reliably, because the key of QInsightTracker::interaction is limited to 255 characters.
+#if QT_VERSION >= QT_WITH_CONTEXTDATA
m_providers.push_back(std::make_unique<QtModules>(m_tracker.get()));
m_providers.push_back(std::make_unique<QtExample>(m_tracker.get()));
+#endif
// not needed for QDS
if (!ICore::isQtDesignStudio()) {