Skip to content

Commit

Permalink
prevent blanking when map is downloading
Browse files Browse the repository at this point in the history
  • Loading branch information
janbar committed Oct 31, 2023
1 parent 56fd64a commit fae0713
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 10 deletions.
9 changes: 7 additions & 2 deletions gui/controls2_515/MapDownloads.qml
Original file line number Diff line number Diff line change
Expand Up @@ -138,14 +138,19 @@ MapPage {
}

function onModelReset() {
console.log("mapDownloadsModel rows: " + mapDownloadsModel.rowCount());
downloadSection.visible = mapDownloadsModel.rowCount() > 0;
var n = mapDownloadsModel.rowCount();
console.log("mapDownloadsModel rows: " + n);
downloadSection.visible = (n > 0);
PlatformExtras.setPreventBlanking((n > 0), 2); // lock bit 2
}

Component.onCompleted: {
mapDownloadsModel.modelReset.connect(onModelReset);
onModelReset();
}
Component.onDestruction: {
PlatformExtras.setPreventBlanking(false, 2); // lock bit 2
}
}

Row {
Expand Down
5 changes: 1 addition & 4 deletions gui/controls2_515/MapView.qml
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,7 @@ MapPage {

property bool preventBlanking: navigation && !applicationSuspended
onPreventBlankingChanged: {
if (PlatformExtras.preventBlanking !== preventBlanking) {
PlatformExtras.preventBlanking = preventBlanking;
console.log("PreventBlanking: " + preventBlanking);
}
PlatformExtras.setPreventBlanking(preventBlanking, 1); // lock bit 1
}

function showPositionInfo() {
Expand Down
23 changes: 21 additions & 2 deletions src/platformextras.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include <QDir>
#include <QStandardPaths>
#include <QStorageInfo>
#include <QDebug>

#if defined(SAILFISHOS)
#define AUTO_MOUNT "/run/media/"
Expand All @@ -36,6 +37,7 @@
PlatformExtras::PlatformExtras(QObject* parent)
: QObject(parent)
, m_preventBlanking(false)
, m_preventBlankingMask(0)
{
#ifdef HAVE_DBUS
// register dbus service for inhibitor
Expand All @@ -55,7 +57,7 @@ PlatformExtras::PlatformExtras(QObject* parent)
PlatformExtras::~PlatformExtras()
{
// clear inhibitor lock
setPreventBlanking(false);
doPreventBlanking(false);
#ifdef HAVE_DBUS
// free registered DBus services
for (RemoteService* svc : qAsConst(m_remoteServices))
Expand Down Expand Up @@ -122,7 +124,23 @@ QStringList PlatformExtras::getStorageDirs()
return dirs;
}

void PlatformExtras::setPreventBlanking(bool on)
void PlatformExtras::setPreventBlanking(bool on, int mask)
{
if (on)
{
if (!m_preventBlanking)
doPreventBlanking(true);
m_preventBlankingMask |= mask;
}
else
{
m_preventBlankingMask &= (~ mask);
if (m_preventBlankingMask == 0 && m_preventBlanking)
doPreventBlanking(false);
}
}

void PlatformExtras::doPreventBlanking(bool on)
{
if (m_preventBlanking == on)
return;
Expand Down Expand Up @@ -167,5 +185,6 @@ void PlatformExtras::setPreventBlanking(bool on)
#else
qWarning("Inhibitor isn't implemented for this platform");
#endif
qInfo("PreventBlanking: %s", (m_preventBlanking ? "true" : "false"));
emit preventBlanking();
}
7 changes: 5 additions & 2 deletions src/platformextras.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
class PlatformExtras : public QObject
{
Q_OBJECT
Q_PROPERTY(bool preventBlanking READ getPreventBlanking WRITE setPreventBlanking NOTIFY preventBlanking)
Q_PROPERTY(bool preventBlanking READ getPreventBlanking NOTIFY preventBlanking)

public:
explicit PlatformExtras(QObject *parent = nullptr);
Expand Down Expand Up @@ -72,15 +72,18 @@ class PlatformExtras : public QObject
*/
static QStringList getStorageDirs();

Q_INVOKABLE void setPreventBlanking(bool on, int mask);

signals:
void preventBlanking();

private:
bool getPreventBlanking() const { return m_preventBlanking; };

void setPreventBlanking(bool on);
void doPreventBlanking(bool on);

volatile bool m_preventBlanking;
volatile int m_preventBlankingMask;

#ifdef HAVE_DBUS
struct RemoteService {
Expand Down

0 comments on commit fae0713

Please sign in to comment.