diff --git a/src/plugins/studiowelcome/qml/splashscreen/Welcome_splash.qml b/src/plugins/studiowelcome/qml/splashscreen/Welcome_splash.qml index 744fe6b2e21..a41f6003237 100644 --- a/src/plugins/studiowelcome/qml/splashscreen/Welcome_splash.qml +++ b/src/plugins/studiowelcome/qml/splashscreen/Welcome_splash.qml @@ -28,6 +28,7 @@ import QtQuick.Controls 2.3 import StudioFonts 1.0 import QtQuick.Layouts 1.0 import projectmodel 1.0 +import usagestatistics 1.0 Image { id: welcome_splash @@ -249,5 +250,21 @@ Image { ProjectModel { id: projectModel } + + UsageStatisticModel { + id: usageStatisticModel + } + } + + NoShowCheckbox { + id: usageStatisticCheckBox + x: -47 + y: 391 + text: "Enable Usage Statistics" + padding: 0 + scale: 0.5 + checked: usageStatisticModel.usageStatisticEnabled + + onCheckedChanged: usageStatisticModel.setPluginEnabled(usageStatisticCheckBox.checked) } } diff --git a/src/plugins/studiowelcome/qml/splashscreen/welcome_screens.qmlproject b/src/plugins/studiowelcome/qml/splashscreen/welcome_screens.qmlproject index de393d88b07..d43d2914ba2 100644 --- a/src/plugins/studiowelcome/qml/splashscreen/welcome_screens.qmlproject +++ b/src/plugins/studiowelcome/qml/splashscreen/welcome_screens.qmlproject @@ -39,7 +39,7 @@ Project { directory: "." } /* List of plugin directories passed to QML runtime */ - importPaths: [ "imports", "mockData", "../../../../share/3rdparty/studiofonts" ] + importPaths: [ "imports", "../welcomepage/mockData", "../../../../share/3rdparty/studiofonts" ] Environment { QT_AUTO_SCREEN_SCALE_FACTOR: "1" diff --git a/src/plugins/studiowelcome/qml/welcomepage/mockData/usagestatistics/UsageStatisticModel.qml b/src/plugins/studiowelcome/qml/welcomepage/mockData/usagestatistics/UsageStatisticModel.qml new file mode 100644 index 00000000000..c19250f2149 --- /dev/null +++ b/src/plugins/studiowelcome/qml/welcomepage/mockData/usagestatistics/UsageStatisticModel.qml @@ -0,0 +1,30 @@ +/**************************************************************************** +** +** Copyright (C) 2020 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of 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. +** +****************************************************************************/ + +import QtQuick 2.0 + +QtObject { + property bool usageStatisticEnabled: false +} diff --git a/src/plugins/studiowelcome/qml/welcomepage/mockData/usagestatistics/qmldir b/src/plugins/studiowelcome/qml/welcomepage/mockData/usagestatistics/qmldir new file mode 100644 index 00000000000..c83a43a8ae7 --- /dev/null +++ b/src/plugins/studiowelcome/qml/welcomepage/mockData/usagestatistics/qmldir @@ -0,0 +1 @@ +UsageStatisticModel 1.0 UsageStatisticModel.qml diff --git a/src/plugins/studiowelcome/studiowelcomeplugin.cpp b/src/plugins/studiowelcome/studiowelcomeplugin.cpp index b382bf1c760..c360c8c3924 100644 --- a/src/plugins/studiowelcome/studiowelcomeplugin.cpp +++ b/src/plugins/studiowelcome/studiowelcomeplugin.cpp @@ -26,6 +26,7 @@ #include "studiowelcomeplugin.h" #include +#include #include #include #include @@ -64,6 +65,70 @@ const char DO_NOT_SHOW_SPLASHSCREEN_AGAIN_KEY[] = "StudioSplashScreen"; QPointer s_view = nullptr; +static bool isUsageStatistic(const ExtensionSystem::PluginSpec *spec) +{ + if (!spec) + return false; + + return spec->name().contains("UsageStatistic"); +} + +ExtensionSystem::PluginSpec *getUsageStatisticPlugin() +{ + const auto plugins = ExtensionSystem::PluginManager::plugins(); + return Utils::findOrDefault(plugins, &isUsageStatistic); +} + +class UsageStatisticPluginModel : public QObject +{ + Q_OBJECT + + Q_PROPERTY(bool usageStatisticEnabled MEMBER m_usageStatisticEnabled NOTIFY usageStatisticChanged) +public: + explicit UsageStatisticPluginModel(QObject *parent = nullptr) + : QObject(parent) + { + setupModel(); + } + + void setupModel() + { + auto plugin = getUsageStatisticPlugin(); + if (plugin) + m_usageStatisticEnabled = plugin->isEnabledBySettings(); + else + m_usageStatisticEnabled = false; + + emit usageStatisticChanged(); + } + + Q_INVOKABLE void setPluginEnabled(bool b) + { + auto plugin = getUsageStatisticPlugin(); + + if (!plugin) + return; + + if (plugin->isEnabledBySettings() == b) + return; + + plugin->setEnabledBySettings(b); + ExtensionSystem::PluginManager::writeSettings(); + + const QString restartText = tr("The change will take effect after restart."); + Core::RestartDialog restartDialog(Core::ICore::dialogParent(), restartText); + restartDialog.exec(); + + setupModel(); + } + +signals: + void usageStatisticChanged(); + +private: + bool m_usageStatisticEnabled = false; +}; + class ProjectModel : public QAbstractListModel { Q_OBJECT @@ -210,6 +275,7 @@ bool StudioWelcomePlugin::initialize(const QStringList &arguments, QString *erro Q_UNUSED(errorString) qmlRegisterType("projectmodel", 1, 0, "ProjectModel"); + qmlRegisterType("usagestatistics", 1, 0, "UsageStatisticModel"); m_welcomeMode = new WelcomeMode;