diff options
author | Kai Koehne <kai.koehne@qt.io> | 2019-10-29 10:21:57 +0100 |
---|---|---|
committer | Kai Koehne <kai.koehne@qt.io> | 2019-11-01 14:52:49 +0000 |
commit | 93872ad36604e02a93ce310a7c34cfe32d7c76aa (patch) | |
tree | b90c261961a96edaf87cced6422730656e34e350 /datasources | |
parent | ed70a31ccc2467e66b3db99af6cbc52fd515a8be (diff) |
Move sources into src subdir
This makes it easier to add a CMakeLists.txt for the super-build.
Change-Id: I53566819281245c0d79d6527222d6f3a824e73dc
Reviewed-by: Eike Ziller <eike.ziller@qt.io>
Reviewed-by: Vitaly Fanaskov <vitaly.fanaskov@qt.io>
Diffstat (limited to 'datasources')
-rw-r--r-- | datasources/buildcountsource.cpp | 92 | ||||
-rw-r--r-- | datasources/buildcountsource.h | 69 | ||||
-rw-r--r-- | datasources/buildsystemsource.cpp | 135 | ||||
-rw-r--r-- | datasources/buildsystemsource.h | 81 | ||||
-rw-r--r-- | datasources/examplesdatasource.cpp | 119 | ||||
-rw-r--r-- | datasources/examplesdatasource.h | 69 | ||||
-rw-r--r-- | datasources/kitsource.cpp | 192 | ||||
-rw-r--r-- | datasources/kitsource.h | 84 | ||||
-rw-r--r-- | datasources/modeusagetimesource.cpp | 153 | ||||
-rw-r--r-- | datasources/modeusagetimesource.h | 90 | ||||
-rw-r--r-- | datasources/qmldesignerusagetimesource.cpp | 102 | ||||
-rw-r--r-- | datasources/qmldesignerusagetimesource.h | 49 | ||||
-rw-r--r-- | datasources/qtclicensesource.cpp | 98 | ||||
-rw-r--r-- | datasources/qtclicensesource.h | 55 | ||||
-rw-r--r-- | datasources/timeusagesourcebase.cpp | 103 | ||||
-rw-r--r-- | datasources/timeusagesourcebase.h | 79 |
16 files changed, 0 insertions, 1570 deletions
diff --git a/datasources/buildcountsource.cpp b/datasources/buildcountsource.cpp deleted file mode 100644 index 1a42305..0000000 --- a/datasources/buildcountsource.cpp +++ /dev/null @@ -1,92 +0,0 @@ -/**************************************************************************** -** -** 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 "buildcountsource.h" - -#include <QtCore/QSettings> - -#include "common/scopedsettingsgroupsetter.h" - -#include <projectexplorer/buildmanager.h> - -#include <KUserFeedback/Provider> - -namespace UsageStatistic { -namespace Internal { - -using namespace KUserFeedback; - -BuildCountSource::BuildCountSource() - : AbstractDataSource(QStringLiteral("buildsCount"), Provider::DetailedUsageStatistics) -{ - QObject::connect(ProjectExplorer::BuildManager::instance(), - &ProjectExplorer::BuildManager::buildQueueFinished, - [&](bool success){ ++(success ? m_succeededBuildsCount : m_failedBuildsCount); }); -} - -QString BuildCountSource::name() const -{ - return tr("Builds count"); -} - -QString BuildCountSource::description() const -{ - return tr("Count of succeeded and failed builds."); -} - -static QString succeededKey() { return QStringLiteral("succeeded"); } -static QString failedKey() { return QStringLiteral("failed"); } -static QString totalKey() { return QStringLiteral("total"); } - -QVariant BuildCountSource::data() -{ - return QVariantMap{{succeededKey(), m_succeededBuildsCount}, - {failedKey(), m_failedBuildsCount}, - {totalKey(), m_succeededBuildsCount + m_failedBuildsCount}}; -} - -void BuildCountSource::loadImpl(QSettings *settings) -{ - auto setter = ScopedSettingsGroupSetter::forDataSource(*this, *settings); - m_succeededBuildsCount = qvariant_cast<quint64>(settings->value(succeededKey(), succeededCountDflt())); - m_failedBuildsCount = qvariant_cast<quint64>(settings->value(failedKey(), failedCountDflt())); -} - -void BuildCountSource::storeImpl(QSettings *settings) -{ - auto setter = ScopedSettingsGroupSetter::forDataSource(*this, *settings); - settings->setValue(succeededKey(), m_succeededBuildsCount); - settings->setValue(failedKey(), m_failedBuildsCount); -} - -void BuildCountSource::resetImpl(QSettings *settings) -{ - m_succeededBuildsCount = succeededCountDflt(); - m_failedBuildsCount = failedCountDflt(); - - storeImpl(settings); -} - -} // namespace Internal -} // namespace UsageStatistic diff --git a/datasources/buildcountsource.h b/datasources/buildcountsource.h deleted file mode 100644 index 0cee9c4..0000000 --- a/datasources/buildcountsource.h +++ /dev/null @@ -1,69 +0,0 @@ -/**************************************************************************** -** -** 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 <QCoreApplication> - -#include <KUserFeedback/AbstractDataSource> - -namespace UsageStatistic { -namespace Internal { - -//! Tracks succeeded, failed, and total builds count -class BuildCountSource : public KUserFeedback::AbstractDataSource -{ - Q_DECLARE_TR_FUNCTIONS(BuildCountDataSource) - -public: - BuildCountSource(); - -public: // AbstractDataSource interface - QString name() const override; - QString description() const override; - - /*! The output data format is: - * { - * "succeeded": int, - * "failed" : int, - * "total" : int - * } - */ - QVariant data() override; - - void loadImpl(QSettings *settings) override; - void storeImpl(QSettings *settings) override; - void resetImpl(QSettings *settings) override; - -private: - static constexpr quint64 succeededCountDflt() { return 0; } - static constexpr quint64 failedCountDflt() { return 0; } - -private: - quint64 m_succeededBuildsCount = succeededCountDflt(); - quint64 m_failedBuildsCount = failedCountDflt(); -}; - -} // namespace Internal -} // namespace UsageStatistic diff --git a/datasources/buildsystemsource.cpp b/datasources/buildsystemsource.cpp deleted file mode 100644 index 26433c0..0000000 --- a/datasources/buildsystemsource.cpp +++ /dev/null @@ -1,135 +0,0 @@ -/**************************************************************************** -** -** 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 "buildsystemsource.h" - -#include <QtCore/QSettings> - -#include <projectexplorer/project.h> -#include <projectexplorer/session.h> - -#include <KUserFeedback/Provider> - -#include "common/scopedsettingsgroupsetter.h" - -namespace UsageStatistic { -namespace Internal { - -using namespace KUserFeedback; - -// Keep synchronized with BuildSystemSource::BuildSystem { -static const auto &buildSystemMarks() -{ - static const QString marks[] = {".qt4", ".cmake", ".qbs", ".autotools"}; - return marks; -} - -static const auto &buildSystemKeys() -{ - static const QString keys[] = {"qmake", "cmake", "qbs", "autotools", "other"}; - return keys; -} -// } - -static BuildSystemSource::BuildSystem extractBuildSystemType(const QString &name) -{ - auto begin = std::begin(buildSystemMarks()); - auto end = std::end(buildSystemMarks()); - - auto it = std::find_if(begin, end, [&](const QString &m){ return name.contains(m); }); - return it != end ? BuildSystemSource::BuildSystem(std::distance(begin, it)) - : BuildSystemSource::Other; -} - -BuildSystemSource::BuildSystemSource() - : AbstractDataSource(QStringLiteral("buildSystem"), Provider::DetailedUsageStatistics) -{ - connect(ProjectExplorer::SessionManager::instance(), - &ProjectExplorer::SessionManager::projectAdded, - this, &BuildSystemSource::updateProjects); - - connect(ProjectExplorer::SessionManager::instance(), - &ProjectExplorer::SessionManager::sessionLoaded, - this, &BuildSystemSource::updateProjects); -} - -BuildSystemSource::~BuildSystemSource() = default; - -QString BuildSystemSource::name() const -{ - return tr("Build system type"); -} - -QString BuildSystemSource::description() const -{ - return tr("Count of each used build systems"); -} - -QVariant BuildSystemSource::data() -{ - QVariantMap result; - for (int i = QMake; i < Count; ++i) { - result[buildSystemKeys()[i]] = m_projectsByBuildSystem[size_t(i)].count(); - } - - 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(); - } -} - -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())); - } -} - -void BuildSystemSource::resetImpl(QSettings *settings) -{ - ProjectsByBuildSystem().swap(m_projectsByBuildSystem); - storeImpl(settings); -} - -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; - } - } -} - -} // namespace Internal -} // namespace UsageStatistic diff --git a/datasources/buildsystemsource.h b/datasources/buildsystemsource.h deleted file mode 100644 index d390c37..0000000 --- a/datasources/buildsystemsource.h +++ /dev/null @@ -1,81 +0,0 @@ -/**************************************************************************** -** -** 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 <array> - -#include <QCoreApplication> -#include <QSet> - -#include <KUserFeedback/AbstractDataSource> - -namespace UsageStatistic { -namespace Internal { - -//! Tracks which build system is used for projects -class BuildSystemSource : public QObject, public KUserFeedback::AbstractDataSource -{ - Q_OBJECT - -public: // Types - enum BuildSystem { QMake, CMake, Qbs, Autotools, Other, Count }; - -public: - BuildSystemSource(); - ~BuildSystemSource() override; - -public: // AbstractDataSource interface - QString name() const override; - QString description() const override; - - /*! The output data format is (the value is projects count): - * { - * "autotools": int, - * "cmake" : int, - * "other" : int, - * "qbs" : int, - * "qmake" : int - * } - */ - QVariant data() override; - - void loadImpl(QSettings *settings) override; - void storeImpl(QSettings *settings) override; - void resetImpl(QSettings *settings) override; - -private: - void updateProjects(); - -private: - // Index is build system type - // 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>; - ProjectsByBuildSystem m_projectsByBuildSystem; -}; - -} // namespace Internal -} // namespace UsageStatistic diff --git a/datasources/examplesdatasource.cpp b/datasources/examplesdatasource.cpp deleted file mode 100644 index 8dc9b2d..0000000 --- a/datasources/examplesdatasource.cpp +++ /dev/null @@ -1,119 +0,0 @@ -/**************************************************************************** -** -** 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 "examplesdatasource.h" - -#include <QtCore/QSettings> -#include <QtCore/QRegularExpression> - -#include <projectexplorer/project.h> -#include <projectexplorer/session.h> - -#include <common/scopedsettingsgroupsetter.h> - -namespace UsageStatistic { -namespace Internal { - -using namespace KUserFeedback; - -ExamplesDataSource::ExamplesDataSource() - : AbstractDataSource(QStringLiteral("examplesData"), Provider::DetailedUsageStatistics) -{ - connect(ProjectExplorer::SessionManager::instance(), - &ProjectExplorer::SessionManager::startupProjectChanged, - this, &ExamplesDataSource::updateOpenedExamples); - - connect(ProjectExplorer::SessionManager::instance(), - &ProjectExplorer::SessionManager::projectAdded, - this, &ExamplesDataSource::updateOpenedExamples); - - connect(ProjectExplorer::SessionManager::instance(), - &ProjectExplorer::SessionManager::sessionLoaded, - this, &ExamplesDataSource::updateOpenedExamples); -} - -ExamplesDataSource::~ExamplesDataSource() = default; - -QString ExamplesDataSource::name() const -{ - return tr("Examples"); -} - -QString ExamplesDataSource::description() const -{ - return tr("The list of examples openned by the user. " - "Only example paths are collected and sent, for example: " - "widgets/mainwindows/application/application.pro"); -} - -static QString examplesKey() { return QStringLiteral("examples"); } - -QVariant ExamplesDataSource::data() -{ - return QVariantMap{{examplesKey(), QVariant(m_examplePaths.toList())}}; -} - -void ExamplesDataSource::loadImpl(QSettings *settings) -{ - auto setter = ScopedSettingsGroupSetter::forDataSource(*this, *settings); - m_examplePaths = settings->value(examplesKey()).toStringList().toSet(); -} - -void ExamplesDataSource::storeImpl(QSettings *settings) -{ - auto setter = ScopedSettingsGroupSetter::forDataSource(*this, *settings); - settings->setValue(examplesKey(), QStringList(m_examplePaths.toList())); -} - -void ExamplesDataSource::resetImpl(QSettings *settings) -{ - m_examplePaths.clear(); - storeImpl(settings); -} - -static QString examplePathGroupName() { return QStringLiteral("examplePathGroup"); } - -static QString examplePattern() -{ - return QStringLiteral("/Examples/Qt-(\\d+\\.*){1,3}/(?<%1>.*)$"); -} - -void ExamplesDataSource::updateOpenedExamples() -{ - QRegularExpression re(examplePattern().arg(examplePathGroupName())); - for (auto project : ProjectExplorer::SessionManager::projects()) { - if (project) { - auto projectPath = QDir::fromNativeSeparators(project->projectFilePath().toString()); - const auto match = re.match(projectPath); - if (match.hasMatch()) { - m_examplePaths << match.captured(examplePathGroupName()); - } - } - } -} - -} // namespace Internal -} // namespace UsageStatistic - - diff --git a/datasources/examplesdatasource.h b/datasources/examplesdatasource.h deleted file mode 100644 index 19b5779..0000000 --- a/datasources/examplesdatasource.h +++ /dev/null @@ -1,69 +0,0 @@ -/**************************************************************************** -** -** 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 <QtCore/QSet> - -#include <KUserFeedback/AbstractDataSource> - -namespace UsageStatistic { -namespace Internal { - -//! Tracks which examples were opened by the user -class ExamplesDataSource : public QObject, public KUserFeedback::AbstractDataSource -{ - Q_OBJECT - -public: - ExamplesDataSource(); - ~ExamplesDataSource() override; - -public: // AbstractDataSource interface - QString name() const override; - QString description() const override; - - /*! The output data format is: - * { - * "examples": [] - * } - * - * The array contains paths like "widgets/mainwindows/application/application.pro". - * Full paths aren't collected. - */ - QVariant data() override; - - void loadImpl(QSettings *settings) override; - void storeImpl(QSettings *settings) override; - void resetImpl(QSettings *settings) override; - -private: // Methods - void updateOpenedExamples(); - -private: // Data - QSet<QString> m_examplePaths; -}; - -} // namespace Internal -} // namespace UsageStatistic diff --git a/datasources/kitsource.cpp b/datasources/kitsource.cpp deleted file mode 100644 index 38d0ccc..0000000 --- a/datasources/kitsource.cpp +++ /dev/null @@ -1,192 +0,0 @@ -/**************************************************************************** -** -** 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 "kitsource.h" - -#include <QtCore/QSettings> - -#include <projectexplorer/kitinformation.h> -#include <projectexplorer/kitmanager.h> -#include <projectexplorer/projectexplorerconstants.h> -#include <projectexplorer/gcctoolchain.h> -#include <qtsupport/qtkitinformation.h> -#include <debugger/debuggerkitinformation.h> -#include <debugger/debuggeritem.h> - -#include "common/scopedsettingsgroupsetter.h" - -namespace UsageStatistic { -namespace Internal { - -using namespace KUserFeedback; -using namespace ProjectExplorer; - -KitSource::KitSource() - : AbstractDataSource(QStringLiteral("kits"), Provider::DetailedUsageStatistics) -{ -} - -KitSource::~KitSource() = default; - -QString KitSource::name() const -{ - return tr("Kits"); -} - -QString KitSource::description() const -{ - return tr("Kits usage statistic: compilers, debuggers, target architecture etc."); -} - -static QString kitsInfoKey() { return QStringLiteral("kitsInfo"); } - -static QString extractToolChainVersion(const ToolChain &toolChain) -{ - try { - return dynamic_cast<const GccToolChain &>(toolChain).version(); - } catch (...) { - return {}; - } -} - -class KitInfo -{ -public: - KitInfo &withQtVersionInfo() - { - static const QString qtKey = QStringLiteral("qt"); - static const QString qtQmlDebuggingSupportKey = QStringLiteral("qmlDebugging"); - static const QString qtQmlCompilerSupportKey = QStringLiteral("qmlCompiler"); - static const QString qtAbisKey = QStringLiteral("abis"); - - if (auto qtVersion = QtSupport::QtKitAspect::qtVersion(&m_kit)) { - QVariantMap qtData; - qtData.insert(versionKey(), qtVersion->qtVersionString()); - qtData.insert(qtQmlDebuggingSupportKey, qtVersion->isQmlDebuggingSupported()); - qtData.insert(qtQmlCompilerSupportKey, qtVersion->isQtQuickCompilerSupported()); - qtData.insert(qtAbisKey, abisToVarinatList(qtVersion->qtAbis())); - - m_map.insert(qtKey, qtData); - } - - return *this; - } - - KitInfo &withCompilerInfo() - { - static const QString compilerKey = QStringLiteral("compiler"); - - if (auto toolChain = ToolChainKitAspect::toolChain(&m_kit, Constants::CXX_LANGUAGE_ID)) { - m_map.insert(compilerKey, - QVariantMap{{nameKey(), toolChain->typeDisplayName()}, - {versionKey(), extractToolChainVersion(*toolChain)}}); - } - - return *this; - } - - KitInfo &withDebuggerInfo() - { - static const QString debuggerKey = QStringLiteral("debugger"); - - if (auto debuggerInfo = Debugger::DebuggerKitAspect::debugger(&m_kit)) { - m_map.insert(debuggerKey, - QVariantMap{{nameKey(), debuggerInfo->engineTypeName()}, - {versionKey(), debuggerInfo->version()}}); - } - - return *this; - } - - QVariantMap extract() const { return m_map; } - - static KitInfo forKit(Kit &kit) { return KitInfo(kit); } - -private: // Methods - KitInfo(Kit &kit) : m_kit(kit) { addKitInfo(); } - - void addKitInfo() - { - static QString defaultKitKey = QStringLiteral("default"); - - m_map.insert(defaultKitKey, &m_kit == KitManager::defaultKit()); - } - - static QVariantMap abiToVariantMap(const Abi &abi) - { - static const QString archKey = QStringLiteral("arch"); - static const QString osKey = QStringLiteral("os"); - static const QString osFlavorKey = QStringLiteral("osFlavor"); - static const QString binaryFormatKey = QStringLiteral("binaryFormat"); - static const QString wordWidthKey = QStringLiteral("wordWidth"); - - return QVariantMap{{archKey , Abi::toString(abi.architecture())}, - {osKey , Abi::toString(abi.os()) }, - {osFlavorKey , Abi::toString(abi.osFlavor()) }, - {binaryFormatKey, Abi::toString(abi.binaryFormat())}, - {wordWidthKey , Abi::toString(abi.wordWidth()) }}; - } - - template <class Container> - QVariantList abisToVarinatList(const Container &abis) - { - QVariantList result; - for (auto &&abi : abis) { - result << abiToVariantMap(abi); - } - - return result; - } - - static QString versionKey() { return QStringLiteral("version"); } - static QString nameKey() { return QStringLiteral("name"); } - -private: // Data - Kit &m_kit; - QVariantMap m_map; -}; - -static QVariantList kitsInfo() -{ - QVariantList kitsInfoList; - for (auto &&kit : KitManager::instance()->kits()) { - if (kit && kit->isValid()) { - kitsInfoList << KitInfo::forKit(*kit) - .withCompilerInfo() - .withDebuggerInfo() - .withQtVersionInfo() - .extract(); - } - } - - return kitsInfoList; -} - -QVariant KitSource::data() -{ - return QVariantMap{{kitsInfoKey(), kitsInfo()}}; -} - -} // namespace Internal -} // namespace UsageStatistic diff --git a/datasources/kitsource.h b/datasources/kitsource.h deleted file mode 100644 index 4256c01..0000000 --- a/datasources/kitsource.h +++ /dev/null @@ -1,84 +0,0 @@ -/**************************************************************************** -** -** 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 <QVariantMap> - -#include <KUserFeedback/AbstractDataSource> - -namespace UsageStatistic { -namespace Internal { - -//! Tracks which toolkits are used -class KitSource : public QObject, public KUserFeedback::AbstractDataSource -{ - Q_OBJECT - -public: - KitSource(); - ~KitSource() override; - -public: // AbstractDataSource interface - QString name() const override; - QString description() const override; - - /*! The output data format is: - * { - * "kitsInfo": [ - * { - * "compiler": { - * "name" : string, - * "version": int - * }, - * "debugger": { - * "name" : string, - * "version": string, - * }, - * "default": bool, - * "qt": { - * "abis": [ - * { - * "arch" : string, - * "binaryFormat": string, - * "os" : string, - * "osFlavor" : string, - * "wordWidth" : string - * } - * ], - * "qmlCompiler" : bool, - * "qmlDebugging": bool, - * "version" : string - * } - * }, - * ] - * } - * - * The version format if "\d+.\d+.\d+". - */ - QVariant data() override; -}; - -} // namespace Internal -} // namespace UsageStatistic diff --git a/datasources/modeusagetimesource.cpp b/datasources/modeusagetimesource.cpp deleted file mode 100644 index 445e419..0000000 --- a/datasources/modeusagetimesource.cpp +++ /dev/null @@ -1,153 +0,0 @@ -/**************************************************************************** -** -** 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 "modeusagetimesource.h" - -#include <QtCore/QSettings> - -#include <coreplugin/editormanager/editormanager.h> -#include <coreplugin/modemanager.h> - -#include <KUserFeedback/Provider> - -#include "common/scopedsettingsgroupsetter.h" - -namespace UsageStatistic { -namespace Internal { - -using namespace KUserFeedback; - -ModeUsageTimeSource::ModeUsageTimeSource() - : AbstractDataSource(QStringLiteral("modeUsageTime"), Provider::DetailedUsageStatistics) -{ - connect(Core::ModeManager::instance(), &Core::ModeManager::currentModeChanged, - this, &ModeUsageTimeSource::onCurrentModeIdChanged); - onCurrentModeIdChanged(Core::ModeManager::currentModeId()); -} - -ModeUsageTimeSource::~ModeUsageTimeSource() = default; - -QString ModeUsageTimeSource::name() const -{ - return tr("Modes usage time"); -} - -QString ModeUsageTimeSource::description() const -{ - return tr("How much time a user spent working in each mode (edit, debug, design, etc.)"); -} - -// Keep synced with ModeUsageTimeSource::Mode { -static const auto &modeMarks() -{ - static const QString marks[] = {"welcome", "edit", "design", "debug", "project", "help", "other"}; - return marks; -} -// } - -static ModeUsageTimeSource::Mode modeFromString(const QString &modeString) -{ - auto begin = std::begin(modeMarks()); - auto end = std::end(modeMarks()); - - auto it = std::find_if(begin, end, [&](const QString &mark) { return modeString.contains(mark); }); - - return it != end ? ModeUsageTimeSource::Mode(std::distance(begin, it)) - : ModeUsageTimeSource::Other; -} - -QVariant ModeUsageTimeSource::data() -{ - QVariantMap result; - - for (std::size_t i = Welcome; i < ModesCount; ++i) { - result[modeMarks()[i]] = m_timeByModes[i]; - } - - return result; -} - -void ModeUsageTimeSource::loadImpl(QSettings *settings) -{ - auto setter = ScopedSettingsGroupSetter::forDataSource(*this, *settings); - for (std::size_t i = Welcome; i < ModesCount; ++i) { - m_timeByModes[i] = qvariant_cast<qint64>(settings->value(modeMarks()[i], timeDflt())); - } -} - -void ModeUsageTimeSource::storeImpl(QSettings *settings) -{ - storeCurrentTimerValue(); - - auto setter = ScopedSettingsGroupSetter::forDataSource(*this, *settings); - for (std::size_t i = Welcome; i < ModesCount; ++i) { - settings->setValue(modeMarks()[i], m_timeByModes[i]); - } -} - -void ModeUsageTimeSource::resetImpl(QSettings *settings) -{ - std::fill(std::begin(m_timeByModes), std::end(m_timeByModes), timeDflt()); - storeImpl(settings); -} - -void ModeUsageTimeSource::setCurrentMode(ModeUsageTimeSource::Mode mode) -{ - m_currentMode = mode; -} - -ModeUsageTimeSource::Mode ModeUsageTimeSource::currentMode() const -{ - return m_currentMode; -} - -void ModeUsageTimeSource::onCurrentModeIdChanged(const Core::Id &modeId) -{ - auto mode = modeFromString(QString::fromUtf8(modeId.name().toLower().simplified())); - - if (m_currentMode == mode) { - return; - } - - if (m_currentTimer.isValid() && m_currentMode < ModesCount) { - m_timeByModes[m_currentMode] += m_currentTimer.elapsed(); - m_currentTimer.invalidate(); - } - - m_currentMode = mode; - - if (m_currentMode != ModesCount) { - m_currentTimer.start(); - } -} - -void ModeUsageTimeSource::storeCurrentTimerValue() -{ - if (m_currentTimer.isValid() && m_currentMode < ModesCount) { - m_timeByModes[m_currentMode] += m_currentTimer.restart(); - } -} - -} // namespace Internal -} // namespace UsageStatistic diff --git a/datasources/modeusagetimesource.h b/datasources/modeusagetimesource.h deleted file mode 100644 index f1fbde1..0000000 --- a/datasources/modeusagetimesource.h +++ /dev/null @@ -1,90 +0,0 @@ -/**************************************************************************** -** -** 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 <array> - -#include <QtCore/QElapsedTimer> - -#include <coreplugin/id.h> - -#include <KUserFeedback/AbstractDataSource> - -namespace UsageStatistic { -namespace Internal { - -//! Tracks which modes were used and for how long -class ModeUsageTimeSource : public QObject, public KUserFeedback::AbstractDataSource -{ - Q_OBJECT - -public: // Types - enum Mode {Welcome, Edit, Design, Debug, Projects, Help, Other, ModesCount}; - -public: - ModeUsageTimeSource(); - ~ModeUsageTimeSource() override; - -public: // AbstractDataSource interface - QString name() const override; - QString description() const override; - - /*! The output data format is: - * { - * "debug" : int, - * "design" : int, - * "edit" : int, - * "help" : int, - * "other" : int, - * "project": int, - * "welcome": int - * } - * - * The value is duration in milliseconds. - */ - QVariant data() override; - - void loadImpl(QSettings *settings) override; - void storeImpl(QSettings *settings) override; - void resetImpl(QSettings *settings) override; - -private: // Data - Mode m_currentMode = ModesCount; - QElapsedTimer m_currentTimer; - std::array<qint64, ModesCount> m_timeByModes{}; - -private: // Methods - void setCurrentMode(Mode mode); - Mode currentMode() const; - - void onCurrentModeIdChanged(const Core::Id &modeId); - - void storeCurrentTimerValue(); - - static constexpr qint64 timeDflt() { return 0; } -}; - -} // namespace Internal -} // namespace UsageStatistic diff --git a/datasources/qmldesignerusagetimesource.cpp b/datasources/qmldesignerusagetimesource.cpp deleted file mode 100644 index 6bb4a32..0000000 --- a/datasources/qmldesignerusagetimesource.cpp +++ /dev/null @@ -1,102 +0,0 @@ -/**************************************************************************** -** -** 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 "qmldesignerusagetimesource.h" - -#include <QtCore/QFileInfo> - -#include <coreplugin/editormanager/editormanager.h> -#include <coreplugin/editormanager/ieditor.h> -#include <coreplugin/modemanager.h> -#include <coreplugin/imode.h> - -namespace UsageStatistic { -namespace Internal { - -static QString currentModeName() -{ - if (auto modeManager = Core::ModeManager::instance()) { - if (auto mode = modeManager->currentMode()) { - return mode->displayName().toLower(); - } - } - - return {}; -} - -QmlDesignerUsageTimeSource::QmlDesignerUsageTimeSource() - : TimeUsageSourceBase(QStringLiteral("qmlDesignerUsageTime")) -{ - connect(Core::ModeManager::instance(), &Core::ModeManager::currentModeChanged, - this, [this](Core::Id modeId){ - updateTrackingState(QString::fromUtf8(modeId.name().toLower())); }); - - connect(Core::EditorManager::instance(), &Core::EditorManager::currentEditorChanged, - this, [this](){ updateTrackingState(currentModeName()); }); -} - -QmlDesignerUsageTimeSource::~QmlDesignerUsageTimeSource() = default; - -QString QmlDesignerUsageTimeSource::name() const -{ - return tr("QmlDesigner usage time"); -} - -QString QmlDesignerUsageTimeSource::description() const -{ - return tr("How long a user spent editing QML files in designer mode"); -} - -static bool isDesignMode(const QString &modeName) -{ - static const QString designModeName = QStringLiteral("design"); - return modeName == designModeName; -} - -static bool editingQmlFile() -{ - static const QSet<QString> validExtentions = {"qml", "qml.ui"}; - static const QString validMimeType = "qml"; - - if (auto document = Core::EditorManager::currentDocument()) { - QString mimeType = document->mimeType().toLower(); - QString extension = document->filePath().toFileInfo().completeSuffix().toLower(); - - return validExtentions.contains(extension) || mimeType.contains(validMimeType); - } - - return false; -} - -void QmlDesignerUsageTimeSource::updateTrackingState(const QString &modeName) -{ - if (isDesignMode(modeName) && editingQmlFile() && !isTimeTrackingActive()) { - Q_EMIT start(); - } else { - Q_EMIT stop(); - } -} - -} // namespace Internal -} // namespace UsageStatistic diff --git a/datasources/qmldesignerusagetimesource.h b/datasources/qmldesignerusagetimesource.h deleted file mode 100644 index 3cadf57..0000000 --- a/datasources/qmldesignerusagetimesource.h +++ /dev/null @@ -1,49 +0,0 @@ -/**************************************************************************** -** -** 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 "timeusagesourcebase.h" - -namespace UsageStatistic { -namespace Internal { - -//! Tracks time spent using QML Designer -class QmlDesignerUsageTimeSource : public TimeUsageSourceBase -{ -public: - QmlDesignerUsageTimeSource(); - ~QmlDesignerUsageTimeSource() override; - -public: // AbstractDataSource interface - QString name() const override; - QString description() const override; - -private: // Methods - void updateTrackingState(const QString &modeName); -}; - -} // namespace Internal -} // namespace UsageStatistic - diff --git a/datasources/qtclicensesource.cpp b/datasources/qtclicensesource.cpp deleted file mode 100644 index bee2c8c..0000000 --- a/datasources/qtclicensesource.cpp +++ /dev/null @@ -1,98 +0,0 @@ -/**************************************************************************** -** -** 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 "qtclicensesource.h" - -#include <coreplugin/icore.h> -#include <extensionsystem/iplugin.h> -#include <extensionsystem/pluginmanager.h> -#include <extensionsystem/pluginspec.h> - -#include <KUserFeedback/Provider> - -namespace UsageStatistic { -namespace Internal { - -using namespace KUserFeedback; - -QtcLicenseSource::QtcLicenseSource() - : AbstractDataSource(QStringLiteral("qtcLicense"), Provider::DetailedUsageStatistics) -{} - -QString QtcLicenseSource::description() const -{ - return tr("Qt Creator license type string: opensource, evaluation, commercial"); -} - -QString QtcLicenseSource::name() const -{ - return tr("Qt Creator license"); -} - -static const auto evaluationStr = QStringLiteral("evaluation"); -static const auto opensourceStr = QStringLiteral("opensource"); -static const auto commercialStr = QStringLiteral("commercial"); - -static bool isLicenseChecker(const ExtensionSystem::PluginSpec *spec) -{ - if (!spec) { - return false; - } - - static const auto pluginName = QStringLiteral("LicenseChecker"); - return spec->name().contains(pluginName); -} - -static bool hasEvaluationLicense(ExtensionSystem::IPlugin *plugin) -{ - if (!plugin) { - return false; - } - - bool isEvaluation = false; - - static const auto checkMethodName = "evaluationLicense"; - QMetaObject::invokeMethod(plugin, checkMethodName, Q_RETURN_ARG(bool, isEvaluation)); - - return isEvaluation; -} - -static QString licenseString() -{ - const auto plugins = ExtensionSystem::PluginManager::plugins(); - const auto it = std::find_if(plugins.begin(), plugins.end(), &isLicenseChecker); - if (it != plugins.end()) { - return hasEvaluationLicense((*it)->plugin()) ? evaluationStr: commercialStr; - } - - return opensourceStr; -} - -QVariant QtcLicenseSource::data() -{ - return QVariantMap{{"value", licenseString()}}; -} - -} // namespace Internal -} // namespace UsageStatistic diff --git a/datasources/qtclicensesource.h b/datasources/qtclicensesource.h deleted file mode 100644 index 80630d2..0000000 --- a/datasources/qtclicensesource.h +++ /dev/null @@ -1,55 +0,0 @@ -/**************************************************************************** -** -** 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 <QCoreApplication> - -#include <KUserFeedback/AbstractDataSource> - -namespace UsageStatistic { -namespace Internal { - -//! Tracks whether commercial or open source version is used -class QtcLicenseSource : public KUserFeedback::AbstractDataSource -{ - Q_DECLARE_TR_FUNCTIONS(QtcLicenseSource) - -public: - QtcLicenseSource(); - -public: // AbstractDataSource interface - QString description() const override; - QString name() const override; - - /*! The output data format is: - * { - * "value": string - * } - */ - QVariant data() override; -}; - -} // namespace Internal -} // namespace UsageStatistic diff --git a/datasources/timeusagesourcebase.cpp b/datasources/timeusagesourcebase.cpp deleted file mode 100644 index ab4c1e1..0000000 --- a/datasources/timeusagesourcebase.cpp +++ /dev/null @@ -1,103 +0,0 @@ -/**************************************************************************** -** -** 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 "timeusagesourcebase.h" - -#include <QtCore/QVariant> -#include <QtCore/QSettings> - -#include <KUserFeedback/Provider> - -#include <common/scopedsettingsgroupsetter.h> - -namespace UsageStatistic { -namespace Internal { - -using namespace KUserFeedback; - -TimeUsageSourceBase::TimeUsageSourceBase(const QString &id) - : AbstractDataSource(id, Provider::DetailedUsageStatistics) -{ - connect(this, &TimeUsageSourceBase::start, this, &TimeUsageSourceBase::onStarted); - connect(this, &TimeUsageSourceBase::stop, this, &TimeUsageSourceBase::onStopped); -} - -void TimeUsageSourceBase::onStarted() -{ - // Restart if required - if (m_timer.isValid()) { - onStopped(); - } - - ++m_startCount; - m_timer.start(); -} - -void TimeUsageSourceBase::onStopped() -{ - if (m_timer.isValid()) { - m_usageTime += m_timer.elapsed(); - } - - m_timer.invalidate(); -} - -bool TimeUsageSourceBase::isTimeTrackingActive() const -{ - return m_timer.isValid(); -} - -static QString usageTimeKey() { return QStringLiteral("usageTime"); } -static QString startCountKey() { return QStringLiteral("startCount"); } - -QVariant TimeUsageSourceBase::data() -{ - return QVariantMap{{usageTimeKey(), m_usageTime}, {startCountKey(), m_startCount}}; -} - -void TimeUsageSourceBase::loadImpl(QSettings *settings) -{ - auto setter = ScopedSettingsGroupSetter::forDataSource(*this, *settings); - m_usageTime = settings->value(usageTimeKey(), usageTimeDflt()).toLongLong(); - m_startCount = settings->value(startCountKey(), startCountDflt()).toLongLong(); -} - -void TimeUsageSourceBase::storeImpl(QSettings *settings) -{ - auto setter = ScopedSettingsGroupSetter::forDataSource(*this, *settings); - settings->setValue(usageTimeKey(), m_usageTime); - settings->setValue(startCountKey(), m_startCount); -} - -void TimeUsageSourceBase::resetImpl(QSettings *settings) -{ - m_usageTime = usageTimeDflt(); - m_startCount = startCountDflt(); - storeImpl(settings); -} - -TimeUsageSourceBase::~TimeUsageSourceBase() = default; - -} // namespace Internal -} // namespace UsageStatistic diff --git a/datasources/timeusagesourcebase.h b/datasources/timeusagesourcebase.h deleted file mode 100644 index e3d3730..0000000 --- a/datasources/timeusagesourcebase.h +++ /dev/null @@ -1,79 +0,0 @@ -/**************************************************************************** -** -** 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 <QtCore/QObject> -#include <QtCore/QElapsedTimer> - -#include <KUserFeedback/AbstractDataSource> - -namespace UsageStatistic { -namespace Internal { - -//! Base class for all time trackers -class TimeUsageSourceBase : public QObject, public KUserFeedback::AbstractDataSource -{ - Q_OBJECT - -public: - ~TimeUsageSourceBase() override; - -public: // AbstractDataSource interface - /*! The output data format is: - * { - * "startCount": int, - * "usageTime" : int - * } - */ - QVariant data() override; - - void loadImpl(QSettings *settings) override; - void storeImpl(QSettings *settings) override; - void resetImpl(QSettings *settings) override; - -protected: - TimeUsageSourceBase(const QString &id); - - void onStarted(); - void onStopped(); - - bool isTimeTrackingActive() const; - -Q_SIGNALS: - void start(); - void stop(); - -private: - static constexpr qint64 usageTimeDflt() { return 0; } - static constexpr qint64 startCountDflt() { return 0; } - -private: - QElapsedTimer m_timer; - qint64 m_usageTime = usageTimeDflt(); - qint64 m_startCount = startCountDflt(); -}; - -} // namespace Internal -} // namespace UsageStatistic |