From ba5c40b15dc4c5aa1df95c720188b2f2924d5d02 Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Tue, 20 Feb 2024 11:00:24 +0200 Subject: [PATCH] Refactoring. Code duplication. --- src/app/puzzle/vpapplication.cpp | 14 +----------- src/app/tape/mapplication.cpp | 14 +----------- src/app/valentina/core/vapplication.cpp | 15 +------------ src/libs/vganalytics/vganalytics.cpp | 29 ++++++++++++++++++++++++- src/libs/vganalytics/vganalytics.h | 3 +++ src/libs/vmisc/vabstractapplication.cpp | 3 ++- 6 files changed, 36 insertions(+), 42 deletions(-) diff --git a/src/app/puzzle/vpapplication.cpp b/src/app/puzzle/vpapplication.cpp index fc0638ba1..24e7af8fa 100644 --- a/src/app/puzzle/vpapplication.cpp +++ b/src/app/puzzle/vpapplication.cpp @@ -433,19 +433,7 @@ void VPApplication::InitOptions() VTheme::SetIconTheme(); VTheme::InitThemeMode(); - auto *statistic = VGAnalytics::Instance(); - QString clientID = settings->GetClientID(); - if (clientID.isEmpty()) - { - clientID = QUuid::createUuid().toString(); - settings->SetClientID(clientID); - } - statistic->SetClientID(clientID); - statistic->SetGUILanguage(settings->GetLocale()); - statistic->SetMeasurementId(GA_MEASUREMENT_ID); - statistic->SetApiSecret(GA_API_SECRET); - statistic->SetRepoRevision(QLatin1String(BUILD_REVISION)); - statistic->Enable(settings->IsCollectStatistic()); + VGAnalytics::Init(settings); m_shortcutManager = new VPuzzleShortcutManager(this); } diff --git a/src/app/tape/mapplication.cpp b/src/app/tape/mapplication.cpp index 2c2787b11..16f7e2890 100644 --- a/src/app/tape/mapplication.cpp +++ b/src/app/tape/mapplication.cpp @@ -479,19 +479,7 @@ void MApplication::InitOptions() VTheme::SetIconTheme(); VTheme::InitThemeMode(); - auto *statistic = VGAnalytics::Instance(); - QString clientID = settings->GetClientID(); - if (clientID.isEmpty()) - { - clientID = QUuid::createUuid().toString(); - settings->SetClientID(clientID); - } - statistic->SetClientID(clientID); - statistic->SetGUILanguage(settings->GetLocale()); - statistic->SetMeasurementId(GA_MEASUREMENT_ID); - statistic->SetApiSecret(GA_API_SECRET); - statistic->SetRepoRevision(QLatin1String(BUILD_REVISION)); - statistic->Enable(settings->IsCollectStatistic()); + VGAnalytics::Init(settings); m_shortcutManager = new VTapeShortcutManager(this); } diff --git a/src/app/valentina/core/vapplication.cpp b/src/app/valentina/core/vapplication.cpp index a7e4261c7..b50ce4de8 100644 --- a/src/app/valentina/core/vapplication.cpp +++ b/src/app/valentina/core/vapplication.cpp @@ -37,7 +37,6 @@ #include "../qmuparser/qmuparsererror.h" #include "../version.h" #include "../vformat/knownmeasurements/vknownmeasurementsdatabase.h" -#include "../vganalytics/def.h" #include "../vganalytics/vganalytics.h" #include "../vmisc/qt_dispatch/qt_dispatch.h" #include "../vmisc/theme/vtheme.h" @@ -690,19 +689,7 @@ void VApplication::InitOptions() m_shortcutManager = new VValentinaShortcutManager(this); } - auto *statistic = VGAnalytics::Instance(); - QString clientID = settings->GetClientID(); - if (clientID.isEmpty()) - { - clientID = QUuid::createUuid().toString(); - settings->SetClientID(clientID); - } - statistic->SetClientID(clientID); - statistic->SetGUILanguage(settings->GetLocale()); - statistic->SetMeasurementId(GA_MEASUREMENT_ID); - statistic->SetApiSecret(GA_API_SECRET); - statistic->SetRepoRevision(QLatin1String(BUILD_REVISION)); - statistic->Enable(settings->IsCollectStatistic()); + VGAnalytics::Init(settings); } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/libs/vganalytics/vganalytics.cpp b/src/libs/vganalytics/vganalytics.cpp index ce6da9a2d..23417fe4f 100644 --- a/src/libs/vganalytics/vganalytics.cpp +++ b/src/libs/vganalytics/vganalytics.cpp @@ -26,7 +26,6 @@ ** *************************************************************************/ #include "vganalytics.h" -#include "../vmisc/defglobal.h" #include "vganalyticsworker.h" #include @@ -61,6 +60,14 @@ #include "../vmisc/compatibility.h" #endif +#if !defined(BUILD_REVISION) && defined(QBS_BUILD) +#include +#define BUILD_REVISION VCS_REPO_STATE_REVISION +#endif + +#include "../vmisc/vcommonsettings.h" +#include "def.h" + using namespace std::chrono_literals; using namespace Qt::Literals::StringLiterals; @@ -151,6 +158,26 @@ auto VGAnalytics::Instance() -> VGAnalytics * return instance; } +//--------------------------------------------------------------------------------------------------------------------- +void VGAnalytics::Init(VCommonSettings *settings) +{ + SCASSERT(settings != nullptr) + + auto *statistic = VGAnalytics::Instance(); + QString clientID = settings->GetClientID(); + if (clientID.isEmpty()) + { + clientID = QUuid::createUuid().toString(); + settings->SetClientID(clientID); + } + statistic->SetClientID(clientID); + statistic->SetGUILanguage(settings->GetLocale()); + statistic->SetMeasurementId(GA_MEASUREMENT_ID); + statistic->SetApiSecret(GA_API_SECRET); + statistic->SetRepoRevision(QLatin1String(BUILD_REVISION)); + statistic->Enable(settings->IsCollectStatistic()); +} + //--------------------------------------------------------------------------------------------------------------------- void VGAnalytics::SetLogLevel(enum VGAnalytics::LogLevel logLevel) { diff --git a/src/libs/vganalytics/vganalytics.h b/src/libs/vganalytics/vganalytics.h index ecd888c7b..d83990ac6 100644 --- a/src/libs/vganalytics/vganalytics.h +++ b/src/libs/vganalytics/vganalytics.h @@ -36,6 +36,7 @@ class QNetworkAccessManager; class VGAnalyticsWorker; +class VCommonSettings; // https://developers.google.com/analytics/devguides/collection/protocol/ga4/verify-implementation?client_type=gtag class VGAnalytics : public QObject @@ -47,6 +48,8 @@ public: static auto Instance() -> VGAnalytics *; + static void Init(VCommonSettings *settings); + enum LogLevel { Debug, diff --git a/src/libs/vmisc/vabstractapplication.cpp b/src/libs/vmisc/vabstractapplication.cpp index 4f7041269..723488605 100644 --- a/src/libs/vmisc/vabstractapplication.cpp +++ b/src/libs/vmisc/vabstractapplication.cpp @@ -28,10 +28,11 @@ #include "vabstractapplication.h" -#include "QtConcurrent/qtconcurrentrun.h" #include "compatibility.h" #include "svgfont/vsvgfontdatabase.h" #include "vtranslator.h" + +#include "QtConcurrent/qtconcurrentrun.h" #include #include #include