From 1194c43e5577b5fe60ad91dd5906ea28b40bcd19 Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Wed, 4 Oct 2023 17:01:30 +0300 Subject: [PATCH] Fix collecting user statistic. Fix calculation of screen resolution for primary screen in case of HighDPI screen. Collect new metrics: screens number, screen pixel ratio, country code (based on IP), platform type, total memory. --- src/libs/vganalytics/vganalytics.cpp | 496 ++++++--------------- src/libs/vganalytics/vganalytics.h | 9 +- src/libs/vganalytics/vganalyticsworker.cpp | 13 +- src/libs/vganalytics/vganalyticsworker.h | 2 + 4 files changed, 151 insertions(+), 369 deletions(-) diff --git a/src/libs/vganalytics/vganalytics.cpp b/src/libs/vganalytics/vganalytics.cpp index dac63937a..3fb909941 100644 --- a/src/libs/vganalytics/vganalytics.cpp +++ b/src/libs/vganalytics/vganalytics.cpp @@ -26,6 +26,7 @@ ** *************************************************************************/ #include "vganalytics.h" +#include "../vmisc/defglobal.h" #include "vganalyticsworker.h" #include @@ -47,6 +48,88 @@ #include #include +#ifdef Q_OS_WIN +#include +#elif defined(Q_OS_MACOS) +#include +#include +#elif defined(Q_OS_LINUX) +#include +#endif + +#if (defined(Q_CC_GNU) && Q_CC_GNU < 409) && !defined(Q_CC_CLANG) +// DO NOT WORK WITH GCC 4.8 +#else +#if __cplusplus >= 201402L +using namespace std::chrono_literals; +#else +#include "../vmisc/bpstd/chrono.hpp" +using namespace bpstd::literals::chrono_literals; +#endif // __cplusplus >= 201402L +#endif //(defined(Q_CC_GNU) && Q_CC_GNU < 409) && !defined(Q_CC_CLANG) + +namespace +{ + +//--------------------------------------------------------------------------------------------------------------------- +auto GetSystemMemorySize() -> qint64 +{ +#ifdef Q_OS_WIN + MEMORYSTATUSEX memory_status; + ZeroMemory(&memory_status, sizeof(MEMORYSTATUSEX)); + memory_status.dwLength = sizeof(MEMORYSTATUSEX); + if (GlobalMemoryStatusEx(&memory_status)) + { + return static_cast(memory_status.ullTotalPhys); + } + + return -1; +#elif defined(Q_OS_MACOS) + vm_size_t pageSize; + vm_statistics64_data_t vmStats; + + mach_port_t machPort = mach_host_self(); + mach_msg_type_number_t count = sizeof(vmStats) / sizeof(natural_t); + host_page_size(machPort, &pageSize); + + host_statistics64(machPort, HOST_VM_INFO, reinterpret_cast(&vmStats), &count); + + qulonglong freeMemory = static_cast(vmStats.free_count) * static_cast(pageSize); + qulonglong totalMemoryUsed = + (static_cast(vmStats.active_count) + static_cast(vmStats.inactive_count) + + static_cast(vmStats.wire_count)) * + static_cast(pageSize); + return static_cast(freeMemory + totalMemoryUsed); +#elif defined(Q_OS_LINUX) + struct sysinfo info; // NOLINT(cppcoreguidelines-pro-type-member-init,hicpp-member-init) + sysinfo(&info); + return static_cast(info.totalram) * static_cast(info.mem_unit); +#else + // Unsupported platform + return -1; +#endif +} + +//--------------------------------------------------------------------------------------------------------------------- +auto GetSystemMemorySizeGB() -> double +{ + qint64 totalMemoryBytes = GetSystemMemorySize(); + if (totalMemoryBytes != -1) + { + return static_cast(totalMemoryBytes) / (1024 * 1024 * 1024); // Convert bytes to gigabytes + } + + return -1.0; // Unsupported platform or error +} + +//--------------------------------------------------------------------------------------------------------------------- +auto TotalMemory() -> QString +{ + double size = GetSystemMemorySizeGB(); + return !qFuzzyCompare(size, -1.0) ? QStringLiteral("%1 GB").arg(size) : QStringLiteral("Unknown RAM"); +} +} // namespace + //--------------------------------------------------------------------------------------------------------------------- VGAnalytics::VGAnalytics(QObject *parent) : QObject{parent}, @@ -82,9 +165,9 @@ void VGAnalytics::SetLogLevel(enum VGAnalytics::LogLevel logLevel) auto VGAnalytics::LogLevel() const -> enum VGAnalytics::LogLevel { return d->m_logLevel; } //--------------------------------------------------------------------------------------------------------------------- -void VGAnalytics::SetRepoRevision(const QString &rev) +void VGAnalytics::SetRepoRevision(QString rev) { - d->m_repoRevision = !rev.isEmpty() ? rev : QStringLiteral("Unknown"); + d->m_repoRevision = !rev.isEmpty() ? rev.remove(QStringLiteral("Git:")) : QStringLiteral("Unknown"); } //--------------------------------------------------------------------------------------------------------------------- @@ -269,6 +352,8 @@ auto VGAnalytics::InitAppStartEventParams(qint64 engagementTimeMsec) const -> QH {QStringLiteral("cpu_architecture"), QSysInfo::currentCpuArchitecture()}, {QStringLiteral("revision"), d->m_repoRevision}, {QStringLiteral("os_version"), QSysInfo::prettyProductName()}, + {QStringLiteral("screens_number"), d->m_screensNumber}, + {QStringLiteral("screen_pixel_ratio"), d->m_screenPixelRatio}, {QStringLiteral("screen_size"), d->m_screenResolution}, {QStringLiteral("screen_scale_factor"), d->m_screenScaleFactor}, // In order for user activity to display in standard reports like Realtime, engagement_time_msec and @@ -276,377 +361,68 @@ auto VGAnalytics::InitAppStartEventParams(qint64 engagementTimeMsec) const -> QH // https://developers.google.com/analytics/devguides/collection/protocol/ga4/sending-events?client_type=gtag#optional_parameters_for_reports {QStringLiteral("engagement_time_msec"), engagementTimeMsec}, {QStringLiteral("gui_language"), d->m_guiLanguage}, - {QStringLiteral("countryId"), TerritoryCode()}, + {QStringLiteral("country_code"), CountryCode()}, + {QStringLiteral("kernel_type"), QSysInfo::kernelType()}, + {QStringLiteral("total_memory"), TotalMemory()}, }; return params; } //--------------------------------------------------------------------------------------------------------------------- -auto VGAnalytics::TerritoryCode() -> QString +auto VGAnalytics::CountryCode() -> QString { - QLocale loc = QLocale::system(); + QNetworkAccessManager manager; + QNetworkRequest request(QUrl(QStringLiteral("https://api.country.is"))); + QNetworkReply *reply = manager.get(request); -#if QT_VERSION >= QT_VERSION_CHECK(6, 2, 0) - return QLocale::territoryToCode(loc.territory()); -#elif QT_VERSION >= QT_VERSION_CHECK(6, 1, 0) - return QLocale::countryToCode(loc.country()); -#else - return GetTerritoryCode(loc.country()); -#endif -} + QTimer timer; + timer.setSingleShot(true); + timer.start(V_SECONDS(5)); // Set the timeout to 5 seconds -//--------------------------------------------------------------------------------------------------------------------- -#if QT_VERSION < QT_VERSION_CHECK(6, 1, 0) -auto VGAnalytics::GetTerritoryCode(QLocale::Country territory) -> QString -{ - if (territory == QLocale::AnyCountry || territory > QLocale::LastCountry) + QEventLoop eventLoop; + + QObject::connect(&timer, &QTimer::timeout, &eventLoop, &QEventLoop::quit); + QObject::connect(reply, &QNetworkReply::finished, &eventLoop, &QEventLoop::quit); + + eventLoop.exec(); + + QString country = QStringLiteral("Unknown"); + + if (timer.isActive()) { - return {}; + // The API response was received before the timeout + if (reply->error() == QNetworkReply::NoError) + { + QByteArray responseData = reply->readAll(); + QJsonParseError error; + QJsonDocument jsonDoc = QJsonDocument::fromJson(responseData, &error); + + if (error.error == QJsonParseError::NoError && jsonDoc.isObject()) + { + QJsonObject jsonObj = jsonDoc.object(); + if (jsonObj.contains(QStringLiteral("country"))) + { + country = jsonObj[QStringLiteral("country")].toString().toLower(); + } + } + } + else + { + qDebug() << "Error:" << reply->errorString(); + } + } + else + { + // Timeout occurred + qDebug() << "Request timed out"; + reply->abort(); } - static const QHash territoryCodeList = { - {QLocale::Afghanistan, QLatin1String("AF")}, - {QLocale::AlandIslands, QLatin1String("AX")}, - {QLocale::Albania, QLatin1String("AL")}, - {QLocale::Algeria, QLatin1String("DZ")}, - {QLocale::AmericanSamoa, QLatin1String("AS")}, - {QLocale::Andorra, QLatin1String("AD")}, - {QLocale::Angola, QLatin1String("AO")}, - {QLocale::Anguilla, QLatin1String("AI")}, - {QLocale::Antarctica, QLatin1String("AQ")}, - {QLocale::AntiguaAndBarbuda, QLatin1String("AG")}, - {QLocale::Argentina, QLatin1String("AR")}, - {QLocale::Armenia, QLatin1String("AM")}, - {QLocale::Aruba, QLatin1String("AW")}, - {QLocale::AscensionIsland, QLatin1String("AC")}, - {QLocale::Australia, QLatin1String("AU")}, - {QLocale::Austria, QLatin1String("AT")}, - {QLocale::Azerbaijan, QLatin1String("AZ")}, - {QLocale::Bahamas, QLatin1String("BS")}, - {QLocale::Bahrain, QLatin1String("BH")}, - {QLocale::Bangladesh, QLatin1String("BD")}, - {QLocale::Barbados, QLatin1String("BB")}, - {QLocale::Belarus, QLatin1String("BY")}, - {QLocale::Belgium, QLatin1String("BE")}, - {QLocale::Belize, QLatin1String("BZ")}, - {QLocale::Benin, QLatin1String("BJ")}, - {QLocale::Bermuda, QLatin1String("BM")}, - {QLocale::Bhutan, QLatin1String("BT")}, - {QLocale::Bolivia, QLatin1String("BO")}, -#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) - {QLocale::BosniaAndHerzegovina, QLatin1String("BA")}, -#else - {QLocale::BosniaAndHerzegowina, QLatin1String("BA")}, -#endif - {QLocale::Botswana, QLatin1String("BW")}, - {QLocale::BouvetIsland, QLatin1String("BV")}, - {QLocale::Brazil, QLatin1String("BR")}, - {QLocale::BritishIndianOceanTerritory, QLatin1String("IO")}, - {QLocale::BritishVirginIslands, QLatin1String("VG")}, - {QLocale::Brunei, QLatin1String("BN")}, - {QLocale::Bulgaria, QLatin1String("BG")}, - {QLocale::BurkinaFaso, QLatin1String("BF")}, - {QLocale::Burundi, QLatin1String("BI")}, - {QLocale::Cambodia, QLatin1String("KH")}, - {QLocale::Cameroon, QLatin1String("CM")}, - {QLocale::Canada, QLatin1String("CA")}, - {QLocale::CanaryIslands, QLatin1String("IC")}, - {QLocale::CapeVerde, QLatin1String("CV")}, -#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) - {QLocale::CaribbeanNetherlands, QLatin1String("BQ")}, -#endif - {QLocale::CaymanIslands, QLatin1String("KY")}, - {QLocale::CentralAfricanRepublic, QLatin1String("CF")}, - {QLocale::CeutaAndMelilla, QLatin1String("EA")}, - {QLocale::Chad, QLatin1String("TD")}, - {QLocale::Chile, QLatin1String("CL")}, - {QLocale::China, QLatin1String("CN")}, - {QLocale::ChristmasIsland, QLatin1String("CX")}, - {QLocale::ClippertonIsland, QLatin1String("CP")}, - {QLocale::CocosIslands, QLatin1String("CC")}, - {QLocale::Colombia, QLatin1String("CO")}, - {QLocale::Comoros, QLatin1String("KM")}, - {QLocale::CongoBrazzaville, QLatin1String("CG")}, - {QLocale::CongoKinshasa, QLatin1String("CD")}, - {QLocale::CookIslands, QLatin1String("CK")}, - {QLocale::CostaRica, QLatin1String("CR")}, - {QLocale::Croatia, QLatin1String("HR")}, - {QLocale::Cuba, QLatin1String("CU")}, -#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) - {QLocale::Curacao, QLatin1String("CW")}, -#else - {QLocale::CuraSao, QLatin1String("CW")}, -#endif - {QLocale::Cyprus, QLatin1String("CY")}, -#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) - {QLocale::Czechia, QLatin1String("CZ")}, -#else - {QLocale::CzechRepublic, QLatin1String("CZ")}, -#endif - {QLocale::Denmark, QLatin1String("DK")}, - {QLocale::DiegoGarcia, QLatin1String("DG")}, - {QLocale::Djibouti, QLatin1String("DJ")}, - {QLocale::Dominica, QLatin1String("DM")}, - {QLocale::DominicanRepublic, QLatin1String("DO")}, - {QLocale::Ecuador, QLatin1String("EC")}, - {QLocale::Egypt, QLatin1String("EG")}, - {QLocale::ElSalvador, QLatin1String("SV")}, - {QLocale::EquatorialGuinea, QLatin1String("GQ")}, - {QLocale::Eritrea, QLatin1String("ER")}, - {QLocale::Estonia, QLatin1String("EE")}, -#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) - {QLocale::Eswatini, QLatin1String("SZ")}, -#else - {QLocale::Swaziland, QLatin1String("SZ")}, -#endif - {QLocale::Ethiopia, QLatin1String("ET")}, -#if QT_VERSION >= QT_VERSION_CHECK(5, 12, 0) - {QLocale::Europe, QLatin1String("150")}, -#endif -#if QT_VERSION >= QT_VERSION_CHECK(5, 7, 0) - {QLocale::EuropeanUnion, QLatin1String("EU")}, -#endif - {QLocale::FalklandIslands, QLatin1String("FK")}, - {QLocale::FaroeIslands, QLatin1String("FO")}, - {QLocale::Fiji, QLatin1String("FJ")}, - {QLocale::Finland, QLatin1String("FI")}, - {QLocale::France, QLatin1String("FR")}, - {QLocale::FrenchGuiana, QLatin1String("GF")}, - {QLocale::FrenchPolynesia, QLatin1String("PF")}, - {QLocale::FrenchSouthernTerritories, QLatin1String("TF")}, - {QLocale::Gabon, QLatin1String("GA")}, - {QLocale::Gambia, QLatin1String("GM")}, - {QLocale::Georgia, QLatin1String("GE")}, - {QLocale::Germany, QLatin1String("DE")}, - {QLocale::Ghana, QLatin1String("GH")}, - {QLocale::Gibraltar, QLatin1String("GI")}, - {QLocale::Greece, QLatin1String("GR")}, - {QLocale::Greenland, QLatin1String("GL")}, - {QLocale::Grenada, QLatin1String("GD")}, - {QLocale::Guadeloupe, QLatin1String("GP")}, - {QLocale::Guam, QLatin1String("GU")}, - {QLocale::Guatemala, QLatin1String("GT")}, - {QLocale::Guernsey, QLatin1String("GG")}, - {QLocale::GuineaBissau, QLatin1String("GW")}, - {QLocale::Guinea, QLatin1String("GN")}, - {QLocale::Guyana, QLatin1String("GY")}, - {QLocale::Haiti, QLatin1String("HT")}, - {QLocale::HeardAndMcDonaldIslands, QLatin1String("HM")}, - {QLocale::Honduras, QLatin1String("HN")}, - {QLocale::HongKong, QLatin1String("HK")}, - {QLocale::Hungary, QLatin1String("HU")}, - {QLocale::Iceland, QLatin1String("IS")}, - {QLocale::India, QLatin1String("IN")}, - {QLocale::Indonesia, QLatin1String("ID")}, - {QLocale::Iran, QLatin1String("IR")}, - {QLocale::Iraq, QLatin1String("IQ")}, - {QLocale::Ireland, QLatin1String("IE")}, - {QLocale::IsleOfMan, QLatin1String("IM")}, - {QLocale::Israel, QLatin1String("IL")}, - {QLocale::Italy, QLatin1String("IT")}, - {QLocale::IvoryCoast, QLatin1String("CI")}, - {QLocale::Jamaica, QLatin1String("JM")}, - {QLocale::Japan, QLatin1String("JP")}, - {QLocale::Jersey, QLatin1String("JE")}, - {QLocale::Jordan, QLatin1String("JO")}, - {QLocale::Kazakhstan, QLatin1String("KZ")}, - {QLocale::Kenya, QLatin1String("KE")}, - {QLocale::Kiribati, QLatin1String("KI")}, - {QLocale::Kosovo, QLatin1String("XK")}, - {QLocale::Kuwait, QLatin1String("KW")}, - {QLocale::Kyrgyzstan, QLatin1String("KG")}, - {QLocale::Laos, QLatin1String("LA")}, -#if QT_VERSION >= QT_VERSION_CHECK(5, 12, 0) - {QLocale::LatinAmerica, QLatin1String("419")}, -#else - {QLocale::LatinAmericaAndTheCaribbean, QLatin1String("419")}, -#endif - {QLocale::Latvia, QLatin1String("LV")}, - {QLocale::Lebanon, QLatin1String("LB")}, - {QLocale::Lesotho, QLatin1String("LS")}, - {QLocale::Liberia, QLatin1String("LR")}, - {QLocale::Libya, QLatin1String("LY")}, - {QLocale::Liechtenstein, QLatin1String("LI")}, - {QLocale::Lithuania, QLatin1String("LT")}, - {QLocale::Luxembourg, QLatin1String("LU")}, -#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) - {QLocale::Macao, QLatin1String("MO")}, -#else - {QLocale::Macau, QLatin1String("MO")}, -#endif - {QLocale::Macedonia, QLatin1String("MK")}, - {QLocale::Madagascar, QLatin1String("MG")}, - {QLocale::Malawi, QLatin1String("MW")}, - {QLocale::Malaysia, QLatin1String("MY")}, - {QLocale::Maldives, QLatin1String("MV")}, - {QLocale::Mali, QLatin1String("ML")}, - {QLocale::Malta, QLatin1String("MT")}, - {QLocale::MarshallIslands, QLatin1String("MH")}, - {QLocale::Martinique, QLatin1String("MQ")}, - {QLocale::Mauritania, QLatin1String("MR")}, - {QLocale::Mauritius, QLatin1String("MU")}, - {QLocale::Mayotte, QLatin1String("YT")}, - {QLocale::Mexico, QLatin1String("MX")}, - {QLocale::Micronesia, QLatin1String("FM")}, - {QLocale::Moldova, QLatin1String("MD")}, - {QLocale::Monaco, QLatin1String("MC")}, - {QLocale::Mongolia, QLatin1String("MN")}, - {QLocale::Montenegro, QLatin1String("ME")}, - {QLocale::Montserrat, QLatin1String("MS")}, - {QLocale::Morocco, QLatin1String("MA")}, - {QLocale::Mozambique, QLatin1String("MZ")}, - {QLocale::Myanmar, QLatin1String("MM")}, - {QLocale::Namibia, QLatin1String("NA")}, - {QLocale::NauruCountry, QLatin1String("NR")}, - {QLocale::Nepal, QLatin1String("NP")}, - {QLocale::Netherlands, QLatin1String("NL")}, - {QLocale::NewCaledonia, QLatin1String("NC")}, - {QLocale::NewZealand, QLatin1String("NZ")}, - {QLocale::Nicaragua, QLatin1String("NI")}, - {QLocale::Nigeria, QLatin1String("NG")}, - {QLocale::Niger, QLatin1String("NE")}, - {QLocale::Niue, QLatin1String("NU")}, - {QLocale::NorfolkIsland, QLatin1String("NF")}, - {QLocale::NorthernMarianaIslands, QLatin1String("MP")}, - {QLocale::NorthKorea, QLatin1String("KP")}, - {QLocale::Norway, QLatin1String("NO")}, - {QLocale::Oman, QLatin1String("OM")}, -#if QT_VERSION >= QT_VERSION_CHECK(5, 7, 0) - {QLocale::OutlyingOceania, QLatin1String("QO")}, -#endif - {QLocale::Pakistan, QLatin1String("PK")}, - {QLocale::Palau, QLatin1String("PW")}, - {QLocale::PalestinianTerritories, QLatin1String("PS")}, - {QLocale::Panama, QLatin1String("PA")}, - {QLocale::PapuaNewGuinea, QLatin1String("PG")}, - {QLocale::Paraguay, QLatin1String("PY")}, - {QLocale::Peru, QLatin1String("PE")}, - {QLocale::Philippines, QLatin1String("PH")}, - {QLocale::Pitcairn, QLatin1String("PN")}, - {QLocale::Poland, QLatin1String("PL")}, - {QLocale::Portugal, QLatin1String("PT")}, - {QLocale::PuertoRico, QLatin1String("PR")}, - {QLocale::Qatar, QLatin1String("QA")}, - {QLocale::Reunion, QLatin1String("RE")}, - {QLocale::Romania, QLatin1String("RO")}, - {QLocale::Russia, QLatin1String("RU")}, - {QLocale::Rwanda, QLatin1String("RW")}, - {QLocale::SaintBarthelemy, QLatin1String("BL")}, - {QLocale::SaintHelena, QLatin1String("SH")}, - {QLocale::SaintKittsAndNevis, QLatin1String("KN")}, - {QLocale::SaintLucia, QLatin1String("LC")}, - {QLocale::SaintMartin, QLatin1String("MF")}, - {QLocale::SaintPierreAndMiquelon, QLatin1String("PM")}, -#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) - {QLocale::SaintVincentAndGrenadines, QLatin1String("VC")}, -#else - {QLocale::SaintVincentAndTheGrenadines, QLatin1String("VC")}, -#endif - {QLocale::Samoa, QLatin1String("WS")}, - {QLocale::SanMarino, QLatin1String("SM")}, - {QLocale::SaoTomeAndPrincipe, QLatin1String("ST")}, - {QLocale::SaudiArabia, QLatin1String("SA")}, - {QLocale::Senegal, QLatin1String("SN")}, - {QLocale::Serbia, QLatin1String("RS")}, - {QLocale::Seychelles, QLatin1String("SC")}, - {QLocale::SierraLeone, QLatin1String("SL")}, - {QLocale::Singapore, QLatin1String("SG")}, - {QLocale::SintMaarten, QLatin1String("SX")}, - {QLocale::Slovakia, QLatin1String("SK")}, - {QLocale::Slovenia, QLatin1String("SI")}, - {QLocale::SolomonIslands, QLatin1String("SB")}, - {QLocale::Somalia, QLatin1String("SO")}, - {QLocale::SouthAfrica, QLatin1String("ZA")}, -#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) - {QLocale::SouthGeorgiaAndSouthSandwichIslands, QLatin1String("GS")}, -#else - {QLocale::SouthGeorgiaAndTheSouthSandwichIslands, QLatin1String("GS")}, -#endif - {QLocale::SouthKorea, QLatin1String("KR")}, - {QLocale::SouthSudan, QLatin1String("SS")}, - {QLocale::Spain, QLatin1String("ES")}, - {QLocale::SriLanka, QLatin1String("LK")}, - {QLocale::Sudan, QLatin1String("SD")}, - {QLocale::Suriname, QLatin1String("SR")}, -#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) - {QLocale::SvalbardAndJanMayen, QLatin1String("SJ")}, -#else - {QLocale::SvalbardAndJanMayenIslands, QLatin1String("SJ")}, -#endif + // Clean up the reply + reply->deleteLater(); - {QLocale::Sweden, QLatin1String("SE")}, - {QLocale::Switzerland, QLatin1String("CH")}, - {QLocale::Syria, QLatin1String("SY")}, - {QLocale::Taiwan, QLatin1String("TW")}, - {QLocale::Tajikistan, QLatin1String("TJ")}, - {QLocale::Tanzania, QLatin1String("TZ")}, - {QLocale::Thailand, QLatin1String("TH")}, -#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) - {QLocale::TimorLeste, QLatin1String("TL")}, -#else - {QLocale::EastTimor, QLatin1String("TL")}, -#endif - {QLocale::Togo, QLatin1String("TG")}, -#if QT_VERSION >= QT_VERSION_CHECK(5, 7, 0) - {QLocale::TokelauCountry, QLatin1String("TK")}, -#else - {QLocale::Tokelau, QLatin1String("TK")}, -#endif - {QLocale::Tonga, QLatin1String("TO")}, - {QLocale::TrinidadAndTobago, QLatin1String("TT")}, - {QLocale::TristanDaCunha, QLatin1String("TA")}, - {QLocale::Tunisia, QLatin1String("TN")}, - {QLocale::Turkey, QLatin1String("TR")}, - {QLocale::Turkmenistan, QLatin1String("TM")}, - {QLocale::TurksAndCaicosIslands, QLatin1String("TC")}, -#if QT_VERSION >= QT_VERSION_CHECK(5, 7, 0) - {QLocale::TuvaluCountry, QLatin1String("TV")}, -#else - {QLocale::Tuvalu, QLatin1String("TV")}, -#endif - {QLocale::Uganda, QLatin1String("UG")}, - {QLocale::Ukraine, QLatin1String("UA")}, - {QLocale::UnitedArabEmirates, QLatin1String("AE")}, - {QLocale::UnitedKingdom, QLatin1String("GB")}, -#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) - {QLocale::UnitedStatesOutlyingIslands, QLatin1String("UM")}, -#else - {QLocale::UnitedStatesMinorOutlyingIslands, QLatin1String("UM")}, -#endif - {QLocale::UnitedStates, QLatin1String("US")}, - {QLocale::UnitedStatesVirginIslands, QLatin1String("VI")}, - {QLocale::Uruguay, QLatin1String("UY")}, - {QLocale::Uzbekistan, QLatin1String("UZ")}, - {QLocale::Vanuatu, QLatin1String("VU")}, -#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) - {QLocale::VaticanCity, QLatin1String("VA")}, -#else - {QLocale::VaticanCityState, QLatin1String("VA")}, -#endif - {QLocale::Venezuela, QLatin1String("VE")}, - {QLocale::Vietnam, QLatin1String("VN")}, -#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) - {QLocale::WallisAndFutuna, QLatin1String("WF")}, -#else - {QLocale::WallisAndFutunaIslands, QLatin1String("WF")}, -#endif - {QLocale::WesternSahara, QLatin1String("EH")}, -#if QT_VERSION >= QT_VERSION_CHECK(5, 12, 0) - {QLocale::World, QLatin1String("001")}, -#endif - {QLocale::Yemen, QLatin1String("YE")}, - {QLocale::Zambia, QLatin1String("ZM")}, - {QLocale::Zimbabwe, QLatin1String("ZW")}, - }; - - if (territoryCodeList.contains(territory)) - { - return territoryCodeList.value(territory); - } - - return {}; + return country; } -#endif //--------------------------------------------------------------------------------------------------------------------- /** diff --git a/src/libs/vganalytics/vganalytics.h b/src/libs/vganalytics/vganalytics.h index 973fdbd63..68115244d 100644 --- a/src/libs/vganalytics/vganalytics.h +++ b/src/libs/vganalytics/vganalytics.h @@ -67,7 +67,7 @@ public: void SetLogLevel(LogLevel logLevel); auto LogLevel() const -> LogLevel; - void SetRepoRevision(const QString &rev); + void SetRepoRevision(QString rev); auto RepoRevision() const -> QString; void SetGUILanguage(const QString &language); @@ -83,6 +83,8 @@ public: void SetNetworkAccessManager(QNetworkAccessManager *networkAccessManager); auto NetworkAccessManager() const -> QNetworkAccessManager *; + static auto CountryCode() -> QString; + public slots: void SendAppFreshInstallEvent(qint64 engagementTimeMsec); void SendAppStartEvent(qint64 engagementTimeMsec); @@ -100,11 +102,6 @@ private: auto InitAppStartEventParams(qint64 engagementTimeMsec) const -> QHash; - static auto TerritoryCode() -> QString; -#if QT_VERSION < QT_VERSION_CHECK(6, 1, 0) - static auto GetTerritoryCode(QLocale::Country territory) -> QString; -#endif - friend auto operator<<(QDataStream &outStream, const VGAnalytics &analytics) -> QDataStream &; friend auto operator>>(QDataStream &inStream, VGAnalytics &analytics) -> QDataStream &; }; diff --git a/src/libs/vganalytics/vganalyticsworker.cpp b/src/libs/vganalytics/vganalyticsworker.cpp index 6e95c22a4..1d327212d 100644 --- a/src/libs/vganalytics/vganalyticsworker.cpp +++ b/src/libs/vganalytics/vganalyticsworker.cpp @@ -58,10 +58,17 @@ VGAnalyticsWorker::VGAnalyticsWorker(QObject *parent) m_guiLanguage = QLocale::system().name().toLower().replace(QChar('_'), QChar('-')); - QScreen *screen = QGuiApplication::primaryScreen(); - QSize size = screen->size(); + m_screensNumber = QString::number(QGuiApplication::screens().size()); - m_screenResolution = QStringLiteral("%1x%2").arg(size.width()).arg(size.height()); + QScreen *screen = QGuiApplication::primaryScreen(); + QSize logicalSize = screen->size(); + qreal devicePixelRatio = screen->devicePixelRatio(); + m_screenPixelRatio = QString::number(devicePixelRatio); + + int screenWidth = qRound(logicalSize.width() * devicePixelRatio); + int screenHeight = qRound(logicalSize.height() * devicePixelRatio); + + m_screenResolution = QStringLiteral("%1x%2").arg(screenWidth).arg(screenHeight); m_screenScaleFactor = screen->logicalDotsPerInchX() / 96.0; m_timer.setInterval(m_timerInterval); diff --git a/src/libs/vganalytics/vganalyticsworker.h b/src/libs/vganalytics/vganalyticsworker.h index 08cb531f9..a6dbc205f 100644 --- a/src/libs/vganalytics/vganalyticsworker.h +++ b/src/libs/vganalytics/vganalyticsworker.h @@ -74,6 +74,8 @@ public: QString m_appName{}; // NOLINT(misc-non-private-member-variables-in-classes) QString m_appVersion{}; // NOLINT(misc-non-private-member-variables-in-classes) QString m_guiLanguage{}; // NOLINT(misc-non-private-member-variables-in-classes) + QString m_screensNumber{}; // NOLINT(misc-non-private-member-variables-in-classes) + QString m_screenPixelRatio{}; // NOLINT(misc-non-private-member-variables-in-classes) QString m_screenResolution{QStringLiteral("0x0")}; // NOLINT(misc-non-private-member-variables-in-classes) QString m_repoRevision{QStringLiteral("Unknown")}; // NOLINT(misc-non-private-member-variables-in-classes)