diff options
author | Vitaly Fanaskov <vitaly.fanaskov@qt.io> | 2019-10-14 11:06:53 +0200 |
---|---|---|
committer | Vitaly Fanaskov <vitaly.fanaskov@qt.io> | 2019-10-14 11:21:38 +0000 |
commit | a883a60069fedb05413e92a13b98aa24489a8c83 (patch) | |
tree | 50dcf7b9f32539ee5419e8ef3cb72b77d9bb7617 | |
parent | 8aad17e3e47a63a4a33839fdcb71180d0215da27 (diff) |
Implement separate data source for collecting additional technical data
Fixes: QTCREATORBUG-22901
Change-Id: Ibd27d7241073675e79307d70e6b6ff44bb0ec069
Reviewed-by: Alessandro Portale <alessandro.portale@qt.io>
Reviewed-by: Janne Anttila <janne.anttila@qt.io>
-rw-r--r-- | common/utils.h | 12 | ||||
-rw-r--r-- | datasources/servicesource.cpp | 114 | ||||
-rw-r--r-- | datasources/servicesource.h | 70 | ||||
-rw-r--r-- | usagestatistic.pro | 2 | ||||
-rw-r--r-- | usagestatisticplugin.cpp | 9 |
5 files changed, 207 insertions, 0 deletions
diff --git a/common/utils.h b/common/utils.h index 6bf5fd4..592728a 100644 --- a/common/utils.h +++ b/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/datasources/servicesource.cpp b/datasources/servicesource.cpp new file mode 100644 index 0000000..8bb71eb --- /dev/null +++ b/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/datasources/servicesource.h b/datasources/servicesource.h new file mode 100644 index 0000000..707c407 --- /dev/null +++ b/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/usagestatistic.pro b/usagestatistic.pro index f9fd69d..94bb72d 100644 --- a/usagestatistic.pro +++ b/usagestatistic.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/usagestatisticplugin.cpp b/usagestatisticplugin.cpp index df09d74..5f04486 100644 --- a/usagestatisticplugin.cpp +++ b/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(); |