From fc116be6a5af212c3f5d6409ef685974e8936691 Mon Sep 17 00:00:00 2001 From: Eike Ziller Date: Thu, 15 May 2025 11:21:07 +0200 Subject: Add information about opened Qt examples MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Check if the project that was opened (parsed) is in a subdirectory of any Qt version's examples path. If so, assume that it is a Qt example. Log a hash of the relative path below the Qt example path, the full hash ID of the project path, and the Qt version number. Fixes: QTCREATORBUG-32879 Change-Id: I41560b23145f2b0a8b8e5905b907bd10df54a2ec Reviewed-by: Kai Köhne --- src/usagestatisticplugin.cpp | 59 +++++++++++++++++++++++++++++++++++++++----- 1 file changed, 53 insertions(+), 6 deletions(-) (limited to 'src') diff --git a/src/usagestatisticplugin.cpp b/src/usagestatisticplugin.cpp index b5fd66c..4d1d718 100644 --- a/src/usagestatisticplugin.cpp +++ b/src/usagestatisticplugin.cpp @@ -29,6 +29,7 @@ #include #include +#include #include #include @@ -44,6 +45,7 @@ using namespace QtSupport; using namespace Utils; Q_LOGGING_CATEGORY(statLog, "qtc.usagestatistic", QtWarningMsg); +Q_LOGGING_CATEGORY(qtexampleLog, "qtc.usagestatistic.qtexample", QtWarningMsg); const char kSettingsPageId[] = "UsageStatistic.PreferencesPage"; @@ -51,6 +53,17 @@ namespace UsageStatistic::Internal { static UsageStatisticPlugin *m_instance = nullptr; +static QString hashed(const QString &path) +{ + return QString::fromLatin1( + QCryptographicHash::hash(path.toUtf8(), QCryptographicHash::Sha1).toHex()); +} + +static QString projectId(Project *project) +{ + return hashed(project->projectFilePath().toFSPathString()); +} + class ModeChanges : public QObject { Q_OBJECT @@ -133,18 +146,51 @@ public: } if (qtPackages.isEmpty()) return; - const QString projectID = QString::fromLatin1( - QCryptographicHash::hash(project->projectFilePath().toFSPathString().toUtf8(), - QCryptographicHash::Sha1) - .toHex()); - const QString json = "{\"projectid\":\"" + projectID + "\",\"qtmodules\":[\"" - + qtPackages.join("\",\"") + "\"]}"; + const QString json = "{\"projectid\":\"" + projectId(project) + + "\",\"qtmodules\":[\"" + qtPackages.join("\",\"") + + "\"],\"qtversion\":\"" + + qtVersion->qtVersion().toString() + "\"}"; tracker->interaction("QtModules", json, 0); }); }); } }; +class QtExample : public QObject +{ + Q_OBJECT +public: + QtExample(QInsightTracker *tracker) + { + connect(ProjectManager::instance(), + &ProjectManager::projectAdded, + this, + [this, tracker](Project *project) { + connect(project, &Project::anyParsingFinished, this, [project, tracker] { + const QtVersions versions = QtVersionManager::versions(); + for (QtVersion *qtVersion : versions) { + const FilePath examplesPath = qtVersion->examplesPath(); + if (examplesPath.isEmpty()) + continue; + if (!project->projectFilePath().isChildOf(examplesPath)) + continue; + const FilePath examplePath = project->projectFilePath() + .relativeChildPath(examplesPath) + .parentDir(); + const QString exampleHash = hashed(examplePath.path()); + const QString json = "{\"projectid\":\"" + projectId(project) + + "\",\"qtexample\":\"" + exampleHash + + "\",\"qtversion\":\"" + + qtVersion->qtVersion().toString() + "\"}"; + qCDebug(qtexampleLog) << qPrintable(json); + tracker->interaction("QtExample", json, 0); + return; + } + }); + }); + } +}; + class Settings : public AspectContainer { public: @@ -361,6 +407,7 @@ void UsageStatisticPlugin::createProviders() // startup configs first, otherwise they will be attributed to the UI state m_providers.push_back(std::make_unique(m_tracker.get())); m_providers.push_back(std::make_unique(m_tracker.get())); + m_providers.push_back(std::make_unique(m_tracker.get())); // not needed for QDS if (!ICore::isQtDesignStudio()) { -- cgit v1.2.3 From 2bdbd4ca6091bcb23fa845e5a3d9b9086e3da5e1 Mon Sep 17 00:00:00 2001 From: Eike Ziller Date: Thu, 15 May 2025 11:47:31 +0200 Subject: Add logging for QtModules and add Qt version number for it MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change-Id: Iab678149461cbed768bb4a1fac3d03f6a79ab1cc Reviewed-by: Kai Köhne --- src/usagestatisticplugin.cpp | 2 ++ 1 file changed, 2 insertions(+) (limited to 'src') diff --git a/src/usagestatisticplugin.cpp b/src/usagestatisticplugin.cpp index 4d1d718..4e630e1 100644 --- a/src/usagestatisticplugin.cpp +++ b/src/usagestatisticplugin.cpp @@ -45,6 +45,7 @@ using namespace QtSupport; using namespace Utils; Q_LOGGING_CATEGORY(statLog, "qtc.usagestatistic", QtWarningMsg); +Q_LOGGING_CATEGORY(qtmodulesLog, "qtc.usagestatistic.qtmodules", QtWarningMsg); Q_LOGGING_CATEGORY(qtexampleLog, "qtc.usagestatistic.qtexample", QtWarningMsg); const char kSettingsPageId[] = "UsageStatistic.PreferencesPage"; @@ -150,6 +151,7 @@ public: + "\",\"qtmodules\":[\"" + qtPackages.join("\",\"") + "\"],\"qtversion\":\"" + qtVersion->qtVersion().toString() + "\"}"; + qCDebug(qtmodulesLog) << qPrintable(json); tracker->interaction("QtModules", json, 0); }); }); -- cgit v1.2.3