diff options
author | Eike Ziller <eike.ziller@qt.io> | 2019-11-11 12:02:22 +0100 |
---|---|---|
committer | Eike Ziller <eike.ziller@qt.io> | 2019-11-11 12:02:22 +0100 |
commit | 03f2d7ae72b71f7320eedcdf3c2611de82be4f83 (patch) | |
tree | a13a5f608cd410a1ff9444342e3977af36e4361a | |
parent | 706220849be60399d4c79ff0fb463ab6072464fa (diff) | |
parent | b11e36cf9d55db45c28d0141a4bb72da04b7f6ce (diff) |
Merge remote-tracking branch 'origin/4.10' into 4.11
Conflicts:
src/datasources/servicesource.cpp
src/datasources/servicesource.h
Change-Id: I4c2b815f3a4963d32d9ee4f053b727ce6df710c6
-rw-r--r-- | src/common/utils.h | 12 | ||||
-rw-r--r-- | src/datasources/buildsystemsource.cpp | 37 | ||||
-rw-r--r-- | src/datasources/buildsystemsource.h | 2 | ||||
-rw-r--r-- | src/datasources/servicesource.cpp | 114 | ||||
-rw-r--r-- | src/datasources/servicesource.h | 70 | ||||
-rw-r--r-- | src/src.pro | 2 | ||||
-rw-r--r-- | src/usagestatisticplugin.cpp | 9 |
7 files changed, 240 insertions, 6 deletions
diff --git a/src/common/utils.h b/src/common/utils.h index 6bf5fd4..592728a 100644 --- a/src/common/utils.h +++ b/src/common/utils.h @@ -36,6 +36,18 @@ constexpr auto secret() { return USP_AUTH_KEY; } //! Base server URL defined during building constexpr auto serverUrl() { return USP_SERVER_URL; } +/*! Data scheme version for the JSON document + * + * Should be changed if you change the output data format, + * for example, change a key or add a new data source. + */ +struct DocumentVersion +{ + int major = 1; + int minor = 0; + int patch = 0; +}; + } // namespace Utils } // namespace Internal } // namespace UsageStatistic diff --git a/src/datasources/buildsystemsource.cpp b/src/datasources/buildsystemsource.cpp index 4286821..5b9e4bf 100644 --- a/src/datasources/buildsystemsource.cpp +++ b/src/datasources/buildsystemsource.cpp @@ -25,6 +25,7 @@ #include "buildsystemsource.h" #include <QtCore/QSettings> +#include <QtCore/QCryptographicHash> #include <projectexplorer/project.h> #include <projectexplorer/session.h> @@ -96,21 +97,42 @@ QVariant BuildSystemSource::data() return result; } +static QSet<QByteArray> fromVariantList(const QVariantList &vl) +{ + QSet<QByteArray> result; + for (auto &&v : vl) { + result << v.toByteArray(); + } + + return result; +} + void BuildSystemSource::loadImpl(QSettings *settings) { auto setter = ScopedSettingsGroupSetter::forDataSource(*this, *settings); for (int i = QMake; i < Count; ++i) { m_projectsByBuildSystem[size_t(i)] = - settings->value(buildSystemKeys()[i]).toStringList().toSet(); + fromVariantList(settings->value(buildSystemKeys()[i]).toList()); } } +static QVariantList toVariantList(const QSet<QByteArray> &set) +{ + QVariantList result; + result.reserve(set.size()); + + std::transform(set.begin(), set.end(), std::back_inserter(result), + [](const QByteArray &ba) { return QVariant::fromValue(ba); }); + + return result; +} + void BuildSystemSource::storeImpl(QSettings *settings) { auto setter = ScopedSettingsGroupSetter::forDataSource(*this, *settings); for (int i = QMake; i < Count; ++i) { settings->setValue( - buildSystemKeys()[i], QStringList(m_projectsByBuildSystem[size_t(i)].toList())); + buildSystemKeys()[i], toVariantList(m_projectsByBuildSystem[size_t(i)])); } } @@ -120,13 +142,18 @@ void BuildSystemSource::resetImpl(QSettings *settings) storeImpl(settings); } +static QByteArray hashPath(const Utils::FilePath& name) +{ + return QCryptographicHash::hash(name.toString().toUtf8(), QCryptographicHash::Md5); +} + void BuildSystemSource::updateProjects() { for (auto project : ProjectExplorer::SessionManager::projects()) { if (project) { - auto projectName = QString::fromUtf8(project->id().name()).toLower(); - auto projectPath = project->projectFilePath().toString(); - m_projectsByBuildSystem[extractBuildSystemType(projectName)] << projectPath; + const auto projectName = QString::fromUtf8(project->id().name()).toLower(); + const auto projectPath = project->projectFilePath(); + m_projectsByBuildSystem[extractBuildSystemType(projectName)] << hashPath(projectPath); } } } diff --git a/src/datasources/buildsystemsource.h b/src/datasources/buildsystemsource.h index d390c37..a6ab03c 100644 --- a/src/datasources/buildsystemsource.h +++ b/src/datasources/buildsystemsource.h @@ -73,7 +73,7 @@ private: // Element is a set of full project paths. Full project path is used // as a permanent unique identifier. This identifier is only for // storing locally on user machine and should never be sent! - using ProjectsByBuildSystem = std::array<QSet<QString>, Count>; + using ProjectsByBuildSystem = std::array<QSet<QByteArray>, Count>; ProjectsByBuildSystem m_projectsByBuildSystem; }; diff --git a/src/datasources/servicesource.cpp b/src/datasources/servicesource.cpp new file mode 100644 index 0000000..8bb71eb --- /dev/null +++ b/src/datasources/servicesource.cpp @@ -0,0 +1,114 @@ +/**************************************************************************** +** +** Copyright (C) 2019 The Qt Company +** Contact: https://www.qt.io/licensing/ +** +** This file is part of UsageStatistic plugin for Qt Creator. +** +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3 as published by the Free Software +** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-3.0.html. +** +****************************************************************************/ +#include "servicesource.h" + +#include <QtCore/QDateTime> +#include <QtCore/QSettings> + +#include "common/utils.h" +#include "common/scopedsettingsgroupsetter.h" + +namespace UsageStatistic { +namespace Internal { + +using namespace KUserFeedback; + +ServiceSource::ServiceSource(std::shared_ptr<KUserFeedback::Provider> provider) + : AbstractDataSource(QStringLiteral("serviceData"), Provider::BasicSystemInformation) + , m_provider(std::move(provider)) +{ +} + +QString ServiceSource::name() const +{ + return tr("Service data"); +} + +QString ServiceSource::description() const +{ + return tr("Additional technical things to make data processing more reliable and useful"); +} + +static QString documentVersionKey() { return QStringLiteral("documentVersion"); } +static QString telemetryLevelKey() { return QStringLiteral("telemetryLevel"); } +static QString createdAtKey() { return QStringLiteral("createdAt"); } +static QString uuidKey() { return QStringLiteral("uuid"); } + +static QString documentVersionString() +{ + static const auto versionString = [](){ + const Utils::DocumentVersion v; + return QStringLiteral("%1.%2.%3").arg(v.major).arg(v.minor).arg(v.patch); + }(); + return versionString; +} + +static int telemetryLevel(const std::shared_ptr<KUserFeedback::Provider> &provider) +{ + if (!provider) { + return -1; + } + + switch (provider->telemetryMode()) { + case Provider::BasicSystemInformation: + return 1; + case Provider::BasicUsageStatistics: + return 2; + case Provider::DetailedSystemInformation: + return 3; + case Provider::DetailedUsageStatistics: + return 4; + default: + return -1; + } +} + +static QString createdAtString() +{ + return QDateTime::currentDateTime().toString(Qt::ISODate); +} + +QVariant ServiceSource::data() +{ + return QVariantMap{{documentVersionKey(), documentVersionString()}, + {telemetryLevelKey(), telemetryLevel(m_provider)}, + {createdAtKey(), createdAtString()}, + {uuidKey(), m_uuid.toString(QUuid::WithoutBraces)}}; +} + +void ServiceSource::loadImpl(QSettings *settings) +{ + auto setter = ScopedSettingsGroupSetter::forDataSource(*this, *settings); + m_uuid = qvariant_cast<QUuid>(settings->value(uuidKey(), m_uuid)); +} + +void ServiceSource::storeImpl(QSettings *settings) +{ + auto setter = ScopedSettingsGroupSetter::forDataSource(*this, *settings); + settings->setValue(uuidKey(), m_uuid); +} + +} // Internal +} // UsageStatistic diff --git a/src/datasources/servicesource.h b/src/datasources/servicesource.h new file mode 100644 index 0000000..707c407 --- /dev/null +++ b/src/datasources/servicesource.h @@ -0,0 +1,70 @@ +/**************************************************************************** +** +** Copyright (C) 2019 The Qt Company +** Contact: https://www.qt.io/licensing/ +** +** This file is part of UsageStatistic plugin for Qt Creator. +** +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3 as published by the Free Software +** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-3.0.html. +** +****************************************************************************/ +#pragma once + +#include <memory> + +#include <QtCore/QVariantMap> +#include <QtCore/QUuid> + +#include <KUserFeedback/AbstractDataSource> +#include <KUserFeedback/Provider> + +namespace UsageStatistic { +namespace Internal { + +//! Additional technical data +class ServiceSource : public KUserFeedback::AbstractDataSource +{ + Q_DECLARE_TR_FUNCTIONS(ServiceSource) + +public: + ServiceSource(std::shared_ptr<KUserFeedback::Provider> provider); + +public: // AbstractDataSource interface + QString name() const override; + + QString description() const override; + + /*! The output data format is: + * { + * "createdAt": "2019-10-14T10:22:38", + * "documentVersion": "1.0.0", + * "telemetryLevel": 4, + * "uuid": "049e5987-32de-487c-9e35-39b1a1380329" + * } + */ + QVariant data() override; + + void loadImpl(QSettings *settings) override; + void storeImpl(QSettings *settings) override; + +private: + std::shared_ptr<KUserFeedback::Provider> m_provider; + QUuid m_uuid = QUuid::createUuid(); +}; + +} // Internal +} // UsageStatistic diff --git a/src/src.pro b/src/src.pro index 40a368e..897f53c 100644 --- a/src/src.pro +++ b/src/src.pro @@ -11,6 +11,7 @@ DEFINES += $$shell_quote(USP_SERVER_URL=\"$$(USP_SERVER_URL)\") # UsageStatistic files SOURCES += \ + datasources/servicesource.cpp \ usagestatisticplugin.cpp \ datasources/qtclicensesource.cpp \ datasources/buildcountsource.cpp \ @@ -28,6 +29,7 @@ SOURCES += \ services/datasubmitter.cpp HEADERS += \ + datasources/servicesource.h \ usagestatisticplugin.h \ usagestatistic_global.h \ usagestatisticconstants.h \ diff --git a/src/usagestatisticplugin.cpp b/src/usagestatisticplugin.cpp index df09d74..5f04486 100644 --- a/src/usagestatisticplugin.cpp +++ b/src/usagestatisticplugin.cpp @@ -53,6 +53,7 @@ #include "datasources/examplesdatasource.h" #include "datasources/kitsource.h" #include "datasources/qmldesignerusagetimesource.h" +#include "datasources/servicesource.h" #include "services/datasubmitter.h" @@ -110,6 +111,13 @@ static void addQtCreatorDataSources(KUserFeedback::Provider &provider) provider.addDataSource(new QmlDesignerUsageTimeSource); } +static void addServiceDataSource(const std::shared_ptr<KUserFeedback::Provider> &provider) +{ + if (provider) { + provider->addDataSource(new ServiceSource(provider)); + } +} + bool UsageStatisticPlugin::delayedInitialize() { // We should create the provider only after everything else @@ -118,6 +126,7 @@ bool UsageStatisticPlugin::delayedInitialize() addDefaultDataSources(*m_provider); addQtCreatorDataSources(*m_provider); + addServiceDataSource(m_provider); createUsageStatisticPage(); |