From 5c60ecddaa4db927cf246933a5ba9802c3c8a2e8 Mon Sep 17 00:00:00 2001
From: ConfuSomu
Date: Fri, 5 Jan 2024 16:23:11 +0100
Subject: Display commit hash in about dialog
---
CMakeLists.txt | 13 +++++++++++++
src/aboutdialog.cpp | 7 +++++--
src/aboutdialog.ui | 2 +-
3 files changed, 19 insertions(+), 3 deletions(-)
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 83d8b99..551afac 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -17,6 +17,18 @@ find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Widgets Concurrent)
find_package(mastodonpp REQUIRED)
+# Get Git commit hash, from http://xit0.org/2013/04/cmake-use-git-branch-and-commit-details-in-project/
+# Get the latest commit hash of the working branch
+execute_process(
+ COMMAND git log -1 --format=%H
+ WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
+ OUTPUT_VARIABLE GIT_COMMIT_HASH
+ OUTPUT_STRIP_TRAILING_WHITESPACE
+)
+# Put the hash between " so it is a string litteral
+string(PREPEND GIT_COMMIT_HASH "\"")
+string(APPEND GIT_COMMIT_HASH "\"")
+
# add_subdirectory will happen later…
set(PROJECT_SOURCES
src/main.cpp
@@ -95,6 +107,7 @@ else()
endif()
endif()
+target_compile_definitions(ActorViewer PRIVATE GIT_COMMIT_HASH=${GIT_COMMIT_HASH})
target_link_libraries(ActorViewer PRIVATE Qt${QT_VERSION_MAJOR}::Widgets mastodonpp)
set_target_properties(ActorViewer PROPERTIES
diff --git a/src/aboutdialog.cpp b/src/aboutdialog.cpp
index 0a96e59..97e2e90 100644
--- a/src/aboutdialog.cpp
+++ b/src/aboutdialog.cpp
@@ -6,8 +6,11 @@ AboutDialog::AboutDialog(QWidget* parent)
{
ui->setupUi(this);
- // TODO: show version or git build in about text
- //ui->label->setText(ui->label->text().arg("aaa"));
+#ifdef GIT_COMMIT_HASH
+ ui->label->setText(ui->label->text().arg(tr("(commit %1)").arg(GIT_COMMIT_HASH)));
+#else
+ ui->label->setText(ui->label->text().arg(""));
+#endif
// I have been saved by https://stackoverflow.com/a/22565649
// It's not more complicated than that… thankfully
diff --git a/src/aboutdialog.ui b/src/aboutdialog.ui
index dd31ae1..4733bbd 100644
--- a/src/aboutdialog.ui
+++ b/src/aboutdialog.ui
@@ -41,7 +41,7 @@
- <html><head/><body><p><span style=" font-size:16pt; font-weight:600;">ActorViewer</span><span style=" font-weight:600;"> %1</span><br/></p><p>ActorViewer is an application that allow one to browse through Fediverse data exports via the help of a Qt-based user interface. It permits one to filter through different types of posts, search through them and view all embedded content related to an Activity.</p><p>This application is licensed under the GNU General Public License, version 3. Please see the LICENSE file, which lists your rights as a user, available in the source code repository's root directory.</p><p>The source code is available at the following web address: <a href="https://git.twilightsparkle.space/ActorViewer/about/"><span style=" text-decoration: underline; color:#ae82c1;">https://git.twilightsparkle.space/ActorViewer/</span></a></p></body></html>
+ <html><head/><body><p><span style=" font-size:16pt; font-weight:600;">ActorViewer</span><span style=" font-size:8pt;font-weight:600;"> %1</span><br/></p><p>ActorViewer is an application which allows one to browse through Fediverse data exports via the help of a Qt-based user interface. It permits one to filter through different types of posts, search through them and view all embedded content related to an Activity.</p><p>This application is licensed under the GNU General Public License, version 3. Please see the LICENSE file, which lists your rights as a user, available in the source code repository's root directory.</p><p>The source code is available at the following web address: <a href="https://git.twilightsparkle.space/ActorViewer/about/"><span style=" text-decoration: underline; color:#ae82c1;">https://git.twilightsparkle.space/ActorViewer/</span></a></p></body></html>
true
--
cgit v1.2.3-54-g00ecf