From 44e3444e2b2d7a112cdd67261c1d68af1936c40a Mon Sep 17 00:00:00 2001 From: Slava Monich Date: Thu, 20 Oct 2022 02:24:48 +0300 Subject: [PATCH] [harbour-barcode] Tweaked detection of torch support The torch doesn't work more often that it does, let's only show the torch button when we know that it actually works. The button can be forced by setting HARBOUR_BARCODE_ENABLE_TORCH environment variable to 1 or /apps/harbour-barcode/enableTorch DConf value to true --- src/Settings.cpp | 2 +- src/Settings.h | 2 ++ src/harbour-barcode.cpp | 14 ++++++++++++-- 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/src/Settings.cpp b/src/Settings.cpp index 5328eab..08df473 100644 --- a/src/Settings.cpp +++ b/src/Settings.cpp @@ -28,7 +28,7 @@ THE SOFTWARE. #include -#define DCONF_PATH_(x) "/apps/harbour-barcode/" x +#define DCONF_PATH_(x) SETTINGS_DCONF_PATH_(x) // New keys (the ones that have only been in dconf) #define KEY_BUZZ_ON_SCAN "buzz_on_scan" diff --git a/src/Settings.h b/src/Settings.h index 396adfa..e1364d9 100644 --- a/src/Settings.h +++ b/src/Settings.h @@ -30,6 +30,8 @@ THE SOFTWARE. #include +#define SETTINGS_DCONF_PATH_(x) "/apps/harbour-barcode/" x + // Old keys (the ones that may need to be imported from the database) #define KEY_SOUND "sound" diff --git a/src/harbour-barcode.cpp b/src/harbour-barcode.cpp index 92c1177..dfee882 100644 --- a/src/harbour-barcode.cpp +++ b/src/harbour-barcode.cpp @@ -104,10 +104,15 @@ int main(int argc, char *argv[]) QScopedPointer app(SailfishApp::application(argc, argv)); bool torchSupported = false; - // Parse Qt version to find out what's supported and what's not const char* qver = qVersion(); HDEBUG("Qt version" << qver); - if (qver) { + + if (qgetenv("HARBOUR_BARCODE_ENABLE_TORCH").toInt() > 0 || + MGConfItem(SETTINGS_DCONF_PATH_("enableTorch")).value().toBool()) { + torchSupported = true; + HDEBUG("Torch support is enabled"); + } else if (qver) { + // Figure out what's supported and what's not const QStringList s(QString(qver).split('.')); if (s.size() >= 3) { int v = QT_VERSION_CHECK(s[0].toInt(), s[1].toInt(), s[2].toInt()); @@ -120,6 +125,11 @@ int main(int argc, char *argv[]) if (flashValues.size() == 1 && flashValues.at(0).toInt() == QCameraExposure::FlashOff) { HDEBUG("Flash disabled by" << qPrintable(flashValuesKey)); + } else if (flashValues.isEmpty()) { + // If this DConf key is missing, assume that the torch + // mode is not supported + HDEBUG("DConf entry" << qPrintable(flashValuesKey) << + "is missing, disabling the torch"); } else { torchSupported = true; HDEBUG("Torch supported");