Skip to content

Commit

Permalink
[harbour-barcode] Tweaked detection of torch support
Browse files Browse the repository at this point in the history
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
  • Loading branch information
monich committed Oct 19, 2022
1 parent ab376f9 commit 44e3444
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/Settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ THE SOFTWARE.

#include <MGConfItem>

#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"
Expand Down
2 changes: 2 additions & 0 deletions src/Settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ THE SOFTWARE.

#include <QtQml>

#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"
Expand Down
14 changes: 12 additions & 2 deletions src/harbour-barcode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,10 +104,15 @@ int main(int argc, char *argv[])
QScopedPointer<QGuiApplication> 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());
Expand All @@ -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");
Expand Down

0 comments on commit 44e3444

Please sign in to comment.