aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorLibravatar Keshav <keshavnrj@gmail.com>2022-03-14 01:25:47 +0530
committerLibravatar Keshav <keshavnrj@gmail.com>2022-03-14 01:29:33 +0530
commit9308711725629bb9255a209455a22d6e83f57623 (patch)
tree196ebad94bcceffb8cb631e3b801f0ca0b1ae2f8 /src
parent3e96cc6bbade480376ab9d554318a1233578d323 (diff)
downloadwhatsie-9308711725629bb9255a209455a22d6e83f57623.tar.gz
whatsie-9308711725629bb9255a209455a22d6e83f57623.zip
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
Diffstat (limited to 'src')
-rw-r--r--src/WhatsApp.pro16
-rw-r--r--src/main.cpp12
-rw-r--r--src/utils.cpp13
3 files changed, 31 insertions, 10 deletions
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 <QDateTime>
#include <QMessageBox>
#include <QProcessEnvironment>
+#include <QRandomGenerator>
#include <QRegularExpression>
#include <time.h>
@@ -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() {
<< "<ul>"
<< "<li><b>" + QObject::tr("Version") + ":</b> " +
QString(VERSIONSTR) + "</li>"
+ << "<li><b>" + QObject::tr("Source Branch") + ":</b> " +
+ QString(GIT_BRANCH) + "</li>"
+ << "<li><b>" + QObject::tr("Commit Hash") + ":</b> " +
+ QString(GIT_HASH) + "</li>"
<< "<li><b>" + QObject::tr("Build Date") + ":</b> " +
QString::fromLatin1(__DATE__) + "</li>"
<< "<li><b>" + QObject::tr("Build Time") + ":</b> " +
@@ -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()