From 8e4a3a799a2fb76a4dff8aaccc7d44027eb84f1b Mon Sep 17 00:00:00 2001
From: Alexander Golubev <fatzer2@gmail.com>
Date: Mon, 28 Jul 2025 21:01:51 +0300
Subject: Fix normalize/normalize-audio discovery

Look for both binary names "normalize-audio" (Debian) and "normalize"
(all the rest distributions) when looking for the executable.

Bug: https://mirror.git.trinitydesktop.org/gitea/TDE/k3b/issues/58
Signed-off-by: Alexander Golubev <fatzer2@gmail.com>
---
 libk3b/core/k3bdefaultexternalprograms.cpp | 31 +++++++++++++++++++++++++-----
 libk3b/core/k3bdefaultexternalprograms.h   | 16 +++++++++++++++
 2 files changed, 42 insertions(+), 5 deletions(-)

diff --git a/libk3b/core/k3bdefaultexternalprograms.cpp b/libk3b/core/k3bdefaultexternalprograms.cpp
index a5ba55a..7fbace6 100644
--- a/libk3b/core/k3bdefaultexternalprograms.cpp
+++ b/libk3b/core/k3bdefaultexternalprograms.cpp
@@ -712,20 +712,41 @@ K3bNormalizeProgram::K3bNormalizeProgram()
 {
 }
 
+TQStringList K3bNormalizeProgram::binNames() const {
+  TQStringList rv;
+  rv << "normalize-audio" << "normalize";
+  return rv;
+}
 
 bool K3bNormalizeProgram::scan( const TQString& p )
 {
   if( p.isEmpty() )
     return false;
 
-  TQString path = p;
-  TQFileInfo fi( path );
+  bool found = false;
+
+  TQFileInfo fi( p );
   if( fi.isDir() ) {
-    if( path[path.length()-1] != '/' )
-      path.append("/");
-    path.append("normalize-audio");
+
+    for(const auto & name: binNames()) {
+      TQString path = p;
+      if( path[path.length()-1] != '/' )
+        path.append("/");
+      path.append(name);
+
+      if( verifyAddBin(path) )
+        found = true;
+    }
+  } else {
+    if( verifyAddBin(p) )
+      found = true;
   }
 
+  return found;
+}
+
+
+bool K3bNormalizeProgram::verifyAddBin( const TQString& path ) {
   if( !TQFile::exists( path ) )
     return false;
 
diff --git a/libk3b/core/k3bdefaultexternalprograms.h b/libk3b/core/k3bdefaultexternalprograms.h
index bc4d41c..daca769 100644
--- a/libk3b/core/k3bdefaultexternalprograms.h
+++ b/libk3b/core/k3bdefaultexternalprograms.h
@@ -102,6 +102,22 @@ class LIBK3B_EXPORT K3bNormalizeProgram : public K3bExternalProgram
   K3bNormalizeProgram();
 
   bool scan( const TQString& );
+ protected:
+  /**
+   * Returns list of names the executable of this program could be called
+   */
+  TQStringList binNames() const;
+
+  /**
+   * Verifies if binary on the given path suitable to be used by k3b and
+   * addBin()s it if so
+   */
+  bool verifyAddBin( const TQString& path );
+
+  /**
+   * @note: it would make sense to make binNames() and verifyBin() virtuals in
+   * K3bExternalProgram and reimplement scan() in a more generic way.
+   */
 };
 
 
-- 
cgit v1.2.3

