diff --git a/plugins/telemetry/CMakeLists.txt b/plugins/telemetry/CMakeLists.txt index 972691cd02..c745b7c59f 100644 --- a/plugins/telemetry/CMakeLists.txt +++ b/plugins/telemetry/CMakeLists.txt @@ -1,19 +1,20 @@ set(kritaplugintelemetry_SOURCES telemetry_provider.cpp telemetry.cpp cpu_info_source.cpp tools_info_source.cpp assert_info_source.cpp image_properties_source.cpp actions_info_source.cpp + general_info_source.cpp ) add_subdirectory( tests ) add_library(kritaplugintelemetry MODULE ${kritaplugintelemetry_SOURCES}) generate_export_header(kritaplugintelemetry EXPORT_MACRO_NAME TELEMETRY_PLUGIN_EXPORT) target_link_libraries(kritaplugintelemetry kritalibtelemetry KUserFeedbackCore kritaui) install(TARGETS kritaplugintelemetry DESTINATION ${KRITA_PLUGIN_INSTALL_DIR}) diff --git a/plugins/telemetry/general_info_source.cpp b/plugins/telemetry/general_info_source.cpp new file mode 100644 index 0000000000..34e0a4c7bf --- /dev/null +++ b/plugins/telemetry/general_info_source.cpp @@ -0,0 +1,45 @@ +/* This file is part of the KDE project + Copyright (C) 2017 Alexey Kapustin + + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. +*/ +#include "general_info_source.h" + +#include +#include +#include +#include + +using namespace UserFeedback; +using namespace KUserFeedback; + +TelemetryGeneralInfoSource::TelemetryGeneralInfoSource() + : AbstractDataSource(QStringLiteral("general"), Provider::DetailedSystemInformation) +{ +} + +QString TelemetryGeneralInfoSource::description() const +{ + return QObject::tr("The general info about Krita."); +} + +QVariant TelemetryGeneralInfoSource::data() +{ + QVariantMap m; + m.insert(QStringLiteral("appVersion"), qApp->applicationVersion()); + return m; +} diff --git a/plugins/telemetry/general_info_source.h b/plugins/telemetry/general_info_source.h new file mode 100644 index 0000000000..65b78fcdf6 --- /dev/null +++ b/plugins/telemetry/general_info_source.h @@ -0,0 +1,40 @@ +/* This file is part of the KDE project + Copyright (C) 2017 Alexey Kapustin + + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. +*/ +#ifndef KISUSERFEEDBACK_GENERALINFOSOURCE_H +#define KISUSERFEEDBACK_GENERALINFOSOURCE_H + +#include "abstractdatasource.h" +#include "kuserfeedbackcore_export.h" + +namespace UserFeedback { + +/*! Data source reporting the general information about Krita. + * + * The default telemetry mode for this source is Provider::DetailedSystemInformation. + */ +class TelemetryGeneralInfoSource : public KUserFeedback::AbstractDataSource { +public: + TelemetryGeneralInfoSource(); + QString description() const override; + QVariant data() override; +}; +} + +#endif // KISUSERFEEDBACK_GENERALINFOSOURCE_H diff --git a/plugins/telemetry/telemetry_provider.cpp b/plugins/telemetry/telemetry_provider.cpp index 8c3f1697f7..a18e414206 100644 --- a/plugins/telemetry/telemetry_provider.cpp +++ b/plugins/telemetry/telemetry_provider.cpp @@ -1,264 +1,268 @@ /* This file is part of the KDE project Copyright (C) 2017 Alexey Kapustin This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #include "telemetry_provider.h" #include "KPluginFactory" #include "KisPart.h" #include #include #include #include #include "Vc/cpuid.h" #include "actions_info_source.h" +#include "general_info_source.h" #include "tools_info_source.h" #include #include #include #include #include #include #include #include #include #include + TelemetryProvider::TelemetryProvider() { m_installProvider.reset(new KUserFeedback::Provider); m_installProvider->setTelemetryMode(KUserFeedback::Provider::DetailedUsageStatistics); KConfigGroup configGroup = KSharedConfig::openConfig()->group("KisTelemetryInstall"); QString isFirstStart = configGroup.readEntry("FirstStart"); if (isFirstStart.isEmpty()) { //don't append install source + std::unique_ptr cpu(new UserFeedback::TelemetryCpuInfoSource()); + m_installSources.push_back(std::move(cpu)); + std::unique_ptr qt(new KUserFeedback::QtVersionSource()); + m_installSources.push_back(std::move(qt)); + std::unique_ptr compiler(new KUserFeedback::CompilerInfoSource()); + m_installSources.push_back(std::move(compiler)); + std::unique_ptr locale(new KUserFeedback::LocaleInfoSource()); + m_installSources.push_back(std::move(locale)); + std::unique_ptr opengl(new KUserFeedback::OpenGLInfoSource()); + m_installSources.push_back(std::move(opengl)); + std::unique_ptr platform(new KUserFeedback::PlatformInfoSource()); + m_installSources.push_back(std::move(platform)); + std::unique_ptr screen(new KUserFeedback::ScreenInfoSource()); + m_installSources.push_back(std::move(screen)); + std::unique_ptr general(new UserFeedback::TelemetryGeneralInfoSource); + m_installSources.push_back(std::move(general)); } - std::unique_ptr cpu(new UserFeedback::TelemetryCpuInfoSource()); - m_installSources.push_back(std::move(cpu)); - std::unique_ptr qt(new KUserFeedback::QtVersionSource()); - m_installSources.push_back(std::move(qt)); - std::unique_ptr compiler(new KUserFeedback::CompilerInfoSource()); - m_installSources.push_back(std::move(compiler)); - std::unique_ptr locale(new KUserFeedback::LocaleInfoSource()); - m_installSources.push_back(std::move(locale)); - std::unique_ptr opengl(new KUserFeedback::OpenGLInfoSource()); - m_installSources.push_back(std::move(opengl)); - std::unique_ptr platform(new KUserFeedback::PlatformInfoSource()); - m_installSources.push_back(std::move(platform)); - std::unique_ptr screen(new KUserFeedback::ScreenInfoSource()); - m_installSources.push_back(std::move(screen)); - for (auto& source : m_installSources) { m_installProvider->addDataSource(source.get()); } m_toolsProvider.reset(new KUserFeedback::Provider); m_toolsProvider.data()->setTelemetryMode(KUserFeedback::Provider::DetailedUsageStatistics); std::unique_ptr tools(new UserFeedback::TelemetryToolsInfoSource); m_toolSources.push_back(std::move(tools)); for (auto& source : m_toolSources) { m_toolsProvider->addDataSource(source.get()); } m_assertsProvider.reset(new KUserFeedback::Provider); m_toolsProvider->setTelemetryMode(KUserFeedback::Provider::DetailedUsageStatistics); std::unique_ptr asserts(new UserFeedback::TelemetryAssertInfoSource); m_assertsSources.push_back(std::move(asserts)); for (auto& source : m_assertsSources) { m_assertsProvider->addDataSource(source.get()); } m_imagePropertiesProvider.reset(new KUserFeedback::Provider); m_imagePropertiesProvider->setTelemetryMode(KUserFeedback::Provider::DetailedUsageStatistics); std::unique_ptr imageProperties(new UserFeedback::TelemetryImagePropertiesSource); m_imagePropertiesSources.push_back(std::move(imageProperties)); for (auto& source : m_imagePropertiesSources) { m_imagePropertiesProvider.data()->addDataSource(source.get()); } m_actionsInfoProvider.reset(new KUserFeedback::Provider); m_actionsInfoProvider->setTelemetryMode(KUserFeedback::Provider::DetailedUsageStatistics); std::unique_ptr actionsInfo(new UserFeedback::TelemetryActionsInfoSource); m_actionsSources.push_back(std::move(actionsInfo)); for (auto& source : m_actionsSources) { m_actionsInfoProvider->addDataSource(source.get()); } } void TelemetryProvider::sendData(QString path, QString adress) { if (!path.endsWith(QLatin1Char('/'))) path += QLatin1Char('/'); TelemetryCategory enumPath = pathToKind(path); QString finalAdress = adress.isNull() ? m_adress : adress; switch (enumPath) { case tools: { m_toolsProvider->setFeedbackServer(QUrl(finalAdress + path)); m_toolsProvider->submit(); break; } case install: { KConfigGroup configGroup = KSharedConfig::openConfig()->group("KisTelemetryInstall"); QString isFirstStart = configGroup.readEntry("FirstStart"); -// if (isFirstStart.isEmpty()) { -// //don't append install source -// configGroup.writeEntry("FirstStart", true); -// } else { -// break; -// } + + if (isFirstStart.isEmpty()) { + //don't append install source + configGroup.writeEntry("FirstStart", true); + } else { + break; + } m_installProvider->setFeedbackServer(QUrl(finalAdress + path)); m_installProvider->submit(); break; } case asserts: { m_assertsProvider->setFeedbackServer(QUrl(finalAdress + path)); m_assertsProvider->submit(); break; } case imageProperties: { m_imagePropertiesProvider->setFeedbackServer(QUrl(finalAdress + path)); m_imagePropertiesProvider->submit(); break; } case actions: { qDebug() << "Send actions!"; m_actionsInfoProvider->setFeedbackServer(QUrl(finalAdress + path)); m_actionsInfoProvider->submit(); break; } default: break; } } void TelemetryProvider::getTimeTicket(QString id) { KisTelemetryTicket* ticket = m_tickets.value(id).lock().data(); if (!ticket) { return; } KisTimeTicket* timeTicket = nullptr; KUserFeedback::AbstractDataSource* m_tools = m_toolSources[0].get(); UserFeedback::TelemetryToolsInfoSource* tools = nullptr; timeTicket = dynamic_cast(ticket); tools = dynamic_cast(m_tools); KIS_SAFE_ASSERT_RECOVER_RETURN(timeTicket); KIS_SAFE_ASSERT_RECOVER_RETURN(tools); KIS_SAFE_ASSERT_RECOVER_RETURN(ticket); tools->deactivateTool(id); m_tickets.remove(id); } void TelemetryProvider::putTimeTicket(QString id) { if (m_tickets.count(id)) { return; } KUserFeedback::AbstractDataSource* m_tools = m_toolSources[0].get(); UserFeedback::TelemetryToolsInfoSource* tools = nullptr; QSharedPointer timeTicket = QSharedPointer::create(id); tools = dynamic_cast(m_tools); KIS_SAFE_ASSERT_RECOVER_RETURN(tools); QWeakPointer weakTimeTicket(timeTicket); m_tickets.insert(id, weakTimeTicket); tools->activateTool(timeTicket); } void TelemetryProvider::saveImageProperites(QString fileName, KisImagePropertiesTicket::ImageInfo imageInfo) { KUserFeedback::AbstractDataSource* m_imageProperties = m_imagePropertiesSources[0].get(); UserFeedback::TelemetryImagePropertiesSource* imageProperties = nullptr; QSharedPointer imagePropertiesTicket = QSharedPointer::create(imageInfo, fileName); imageProperties = dynamic_cast(m_imageProperties); KIS_SAFE_ASSERT_RECOVER_RETURN(imageProperties); if (m_tickets.count(fileName)) { imageProperties->removeDumpProperties(fileName); return; } QWeakPointer weakimagePropertiesTicket(imagePropertiesTicket); m_tickets.insert(fileName, weakimagePropertiesTicket); imageProperties->createNewImageProperties(imagePropertiesTicket); } void TelemetryProvider::saveActionInfo(QString id, KisActionInfoTicket::ActionInfo actionInfo) { static QString lastAction = "start name"; static QTime lastTime = QTime(0, 0, 0, 0); bool isSameAction = false; if (lastAction != actionInfo.name || QTime::currentTime().secsTo(lastTime)) { isSameAction = false; } else { isSameAction = true; } if (!isSameAction) { KUserFeedback::AbstractDataSource* m_actionsInfo = m_actionsSources[0].get(); UserFeedback::TelemetryActionsInfoSource* actionsInfoSource = nullptr; QSharedPointer actionsInfoTicket = QSharedPointer::create(actionInfo, id); actionsInfoSource = dynamic_cast(m_actionsInfo); KIS_SAFE_ASSERT_RECOVER_RETURN(actionsInfoSource); QWeakPointer weakactionsInfoTicket(actionsInfoTicket); m_tickets.insert(id, weakactionsInfoTicket); actionsInfoSource->insert(actionsInfoTicket); qDebug() << "ACTION STORED"; } lastTime = QTime::currentTime(); lastAction = actionInfo.name; } TelemetryProvider::~TelemetryProvider() { } TelemetryProvider::TelemetryCategory TelemetryProvider::pathToKind(QString path) { if (path == "tools/") return tools; else if (path == "install/") return install; else if (path == "asserts/") return asserts; else if (path == "imageProperties/") return imageProperties; else if (path == "actions/") return actions; return tools; }