/**************************************************************************** ** ** 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 "usagestatisticplugin.h" #include "usagestatisticconstants.h" #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include "datasources/qtclicensesource.h" #include "datasources/buildcountsource.h" #include "datasources/buildsystemsource.h" #include "datasources/modeusagetimesource.h" #include "datasources/examplesdatasource.h" #include "datasources/kitsource.h" #include "datasources/qmldesignerusagetimesource.h" #include "services/datasubmitter.h" #include "ui/usagestatisticpage.h" #include "ui/outputpane.h" #include "common/utils.h" namespace UsageStatistic { namespace Internal { UsageStatisticPlugin::UsageStatisticPlugin() = default; UsageStatisticPlugin::~UsageStatisticPlugin() = default; bool UsageStatisticPlugin::initialize(const QStringList &arguments, QString *errorString) { Q_UNUSED(arguments) Q_UNUSED(errorString) // We have to create a pane here because of OutputPaneManager internal initialization order createOutputPane(); return true; } void UsageStatisticPlugin::extensionsInitialized() { } static void addDefaultDataSources(KUserFeedback::Provider &provider) { provider.addDataSource(new KUserFeedback::ApplicationVersionSource); provider.addDataSource(new KUserFeedback::CompilerInfoSource); provider.addDataSource(new KUserFeedback::CpuInfoSource); provider.addDataSource(new KUserFeedback::LocaleInfoSource); provider.addDataSource(new KUserFeedback::OpenGLInfoSource); provider.addDataSource(new KUserFeedback::PlatformInfoSource); provider.addDataSource(new KUserFeedback::QPAInfoSource); provider.addDataSource(new KUserFeedback::QtVersionSource); provider.addDataSource(new KUserFeedback::ScreenInfoSource); provider.addDataSource(new KUserFeedback::StartCountSource); provider.addDataSource(new KUserFeedback::UsageTimeSource); provider.addDataSource(new KUserFeedback::StyleInfoSource); } static void addQtCreatorDataSources(KUserFeedback::Provider &provider) { provider.addDataSource(new QtcLicenseSource); provider.addDataSource(new BuildCountSource); provider.addDataSource(new BuildSystemSource); provider.addDataSource(new ModeUsageTimeSource); provider.addDataSource(new ExamplesDataSource); provider.addDataSource(new KitSource); provider.addDataSource(new QmlDesignerUsageTimeSource); } bool UsageStatisticPlugin::delayedInitialize() { // We should create the provider only after everything else // is initialised (e.g., setting organization name) createProvider(); addDefaultDataSources(*m_provider); addQtCreatorDataSources(*m_provider); createUsageStatisticPage(); restoreSettings(); configureOutputPane(); return true; } ExtensionSystem::IPlugin::ShutdownFlag UsageStatisticPlugin::aboutToShutdown() { storeSettings(); return SynchronousShutdown; } void UsageStatisticPlugin::createUsageStatisticPage() { m_usageStatisticPage = std::make_unique(m_provider); connect(m_usageStatisticPage.get(), &UsageStatisticPage::settingsChanged, this, &UsageStatisticPlugin::storeSettings); } void UsageStatisticPlugin::createOutputPane() { m_outputPane = std::make_unique(); } void UsageStatisticPlugin::configureOutputPane() { Q_ASSERT(m_outputPane); m_outputPane->setProvider(m_provider); connect(m_provider.get(), &KUserFeedback::Provider::showEncouragementMessage, m_outputPane.get(), &OutputPane::flash); } void UsageStatisticPlugin::storeSettings() { if (m_provider) { m_provider->store(); } } void UsageStatisticPlugin::restoreSettings() { if (m_provider) { m_provider->load(); } } static constexpr int encouragementTimeSec() { return 1800; } static constexpr int encouragementIntervalDays() { return 1; } static constexpr int submissionIntervalDays() { return 10; } void UsageStatisticPlugin::createProvider() { Q_ASSERT(!m_provider); m_provider = std::make_shared(); m_provider->setFeedbackServer(QString::fromUtf8(Utils::serverUrl())); m_provider->setDataSubmitter(new DataSubmitter); m_provider->setApplicationUsageTimeUntilEncouragement(encouragementTimeSec()); m_provider->setEncouragementDelay(encouragementTimeSec()); m_provider->setEncouragementInterval(encouragementIntervalDays()); m_provider->setSubmissionInterval(submissionIntervalDays()); } } // namespace Internal } // namespace UsageStatistic