Refactoring. Code duplication.

This commit is contained in:
Roman Telezhynskyi 2024-02-20 11:00:24 +02:00
parent 01462c3d20
commit ba5c40b15d
6 changed files with 36 additions and 42 deletions

View File

@ -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);
}

View File

@ -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);
}

View File

@ -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);
}
//---------------------------------------------------------------------------------------------------------------------

View File

@ -26,7 +26,6 @@
**
*************************************************************************/
#include "vganalytics.h"
#include "../vmisc/defglobal.h"
#include "vganalyticsworker.h"
#include <QDataStream>
@ -61,6 +60,14 @@
#include "../vmisc/compatibility.h"
#endif
#if !defined(BUILD_REVISION) && defined(QBS_BUILD)
#include <vcsRepoState.h>
#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)
{

View File

@ -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,

View File

@ -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 <QDir>
#include <QFileSystemWatcher>
#include <QFuture>