From 9308711725629bb9255a209455a22d6e83f57623 Mon Sep 17 00:00:00 2001 From: Keshav Date: Mon, 14 Mar 2022 01:25:47 +0530 Subject: add more debug info in util class - pro: define new macros to get git info - main: -v print version info - util: - more info in debug; use QRandomGenerator --- src/WhatsApp.pro | 16 ++++++++++------ src/main.cpp | 12 +++++++++++- src/utils.cpp | 13 ++++++++++--- 3 files changed, 31 insertions(+), 10 deletions(-) (limited to 'src') diff --git a/src/WhatsApp.pro b/src/WhatsApp.pro index 103032b..083f339 100644 --- a/src/WhatsApp.pro +++ b/src/WhatsApp.pro @@ -35,17 +35,21 @@ DEFINES += QT_DEPRECATED_WARNINGS # No debug output in release mode CONFIG(release, debug|release):DEFINES += QT_NO_DEBUG_OUTPUT -# You can also make your code fail to compile if you use deprecated APIs. -# In order to do so, uncomment the following line. -# You can also select to disable deprecated APIs only up to a certain version of Qt. -#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 - - +# Define git info +GIT_HASH="\\\"$$system(git -C \""$$_PRO_FILE_PWD_"\" rev-parse --short HEAD)\\\"" +GIT_BRANCH="\\\"$$system(git -C \""$$_PRO_FILE_PWD_"\" rev-parse --abbrev-ref HEAD)\\\"" +BUILD_TIMESTAMP="\\\"$$system(date -u +\""%Y-%m-%dT%H:%M:%SUTC\"")\\\"" +DEFINES += GIT_HASH=$$GIT_HASH GIT_BRANCH=$$GIT_BRANCH BUILD_TIMESTAMP=$$BUILD_TIMESTAMP # Set program version VERSION = 3.0 DEFINES += VERSIONSTR=\\\"$${VERSION}\\\" +# You can also make your code fail to compile if you use deprecated APIs. +# In order to do so, uncomment the following line. +# You can also select to disable deprecated APIs only up to a certain version of Qt. +#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 + SOURCES += \ SunClock.cpp \ about.cpp \ diff --git a/src/main.cpp b/src/main.cpp index 0a069fc..6aaa42a 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -12,6 +12,17 @@ #include "rungaurd.h" int main(int argc, char *argv[]) { + + QStringList args; + for (int i = 0; i < argc; i++) + args << QString(argv[i]); + + if (args.contains("-v") || args.contains("--version")) { + qInfo() << QString("version: %1, branch: %2, commit: %3, built_at: %4") + .arg(VERSIONSTR, GIT_BRANCH, GIT_HASH, BUILD_TIMESTAMP); + return 0; + } + QApplication::setAttribute(Qt::AA_EnableHighDpiScaling); static const char ENV_VAR_QT_DEVICE_PIXEL_RATIO[] = "QT_DEVICE_PIXEL_RATIO"; if (!qEnvironmentVariableIsSet(ENV_VAR_QT_DEVICE_PIXEL_RATIO) && @@ -26,7 +37,6 @@ int main(int argc, char *argv[]) { #endif qputenv("QTWEBENGINE_CHROMIUM_FLAGS", "--disable-logging --single-process"); - QApplication app(argc, argv); app.setWindowIcon(QIcon(":/icons/app/icon-256.png")); diff --git a/src/utils.cpp b/src/utils.cpp index e248081..802c51d 100644 --- a/src/utils.cpp +++ b/src/utils.cpp @@ -3,6 +3,7 @@ #include #include #include +#include #include #include @@ -59,7 +60,7 @@ bool utils::delete_cache(const QString cache_dir) { // returns string with first letter capitalized QString utils::toCamelCase(const QString &s) { - QStringList parts = s.split(' ', QString::SkipEmptyParts); + QStringList parts = s.split(' ', Qt::SkipEmptyParts); for (int i = 0; i < parts.size(); ++i) parts[i].replace(0, 1, parts[i][0].toUpper()); return parts.join(" "); @@ -92,9 +93,9 @@ QString utils::genRand(int length) { const int randomStringLength = length; QString randomString; - qsrand(cd.toTime_t()); + int rand = QRandomGenerator::global()->generate(); for (int i = 0; i < randomStringLength; ++i) { - int index = qrand() % possibleCharacters.length(); + int index = rand % possibleCharacters.length(); QChar nextChar = possibleCharacters.at(index); randomString.append(nextChar); } @@ -201,6 +202,10 @@ QString utils::appDebugInfo() { << "
    " << "
  • " + QObject::tr("Version") + ": " + QString(VERSIONSTR) + "
  • " + << "
  • " + QObject::tr("Source Branch") + ": " + + QString(GIT_BRANCH) + "
  • " + << "
  • " + QObject::tr("Commit Hash") + ": " + + QString(GIT_HASH) + "
  • " << "
  • " + QObject::tr("Build Date") + ": " + QString::fromLatin1(__DATE__) + "
  • " << "
  • " + QObject::tr("Build Time") + ": " + @@ -236,6 +241,8 @@ void utils::DisplayExceptionErrorDialog(const QString &error_info) { QStringList detailed_text; detailed_text << "Error info: " + error_info << "\nApp version: " + QString(VERSIONSTR) + << "\nSource Branch: " + QString(GIT_BRANCH) + << "\nCommit Hash: " + QString(GIT_HASH) << "\nQt Runtime Version: " + QString(qVersion()) << "\nQt Compiled Version: " + QString(QT_VERSION_STR) << "\nSystem: " + QSysInfo::prettyProductName() -- cgit v1.2.3