Skip to content

Commit

Permalink
try to fix issue #60
Browse files Browse the repository at this point in the history
  • Loading branch information
janbar committed Oct 17, 2023
1 parent 901261c commit 9b23c98
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 11 deletions.
14 changes: 12 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ option(INSTALL_TESTS "Install the tests on make install" OFF)
option(BUILD_DEVICE_MOBILE "Enable behaviors for mobile devices" OFF)

set(APP_VERSION "1.10.4")
set(APP_VERSION_CODE 59)
set(APP_VERSION_CODE 60)
set(APP_ID "io.github.janbar.osmin")
set(APP_NAME "osmin")

Expand Down Expand Up @@ -110,7 +110,11 @@ find_package(Qt5QuickControls2 ${QT_MIN_VERSION} REQUIRED)

if(ANDROID)
find_package(Qt5AndroidExtras REQUIRED)
elseif(UNIX AND NOT APPLE)
find_library(DBUS_LIBRARIES dbus-1 REQUIRED)
find_package(Qt5DBus REQUIRED)
endif()

find_package(Qt5Widgets REQUIRED)
find_package(Qt5Xml REQUIRED)
find_package(Qt5Svg REQUIRED)
Expand Down Expand Up @@ -199,12 +203,18 @@ if(ANDROID)
add_definitions(-frtti) # dynamic_cast: https://github.com/android/ndk/issues/519
target_link_libraries(osmin Qt5::QuickControls2 Qt5::AndroidExtras android log Qt5::RemoteObjects Qt5::Positioning
Qt5::Qml Qt5::Quick Qt5::Widgets Qt5::Gui Qt5::Xml Qt5::Svg Qt5::Network Qt5::Sensors Qt5::Multimedia Qt5::Core)
else()
elseif(APPLE)
if(BUILD_DEVICE_MOBILE)
add_definitions(-DDEVICE_MOBILE)
endif()
target_link_libraries(osmin Qt5::QuickControls2 Qt5::RemoteObjects Qt5::Positioning
Qt5::Qml Qt5::Quick Qt5::Widgets Qt5::Gui Qt5::Xml Qt5::Svg Qt5::Network Qt5::Sensors Qt5::Multimedia Qt5::Core)
elseif(UNIX)
if(BUILD_DEVICE_MOBILE)
add_definitions(-DDEVICE_MOBILE)
endif()
target_link_libraries(osmin Qt5::QuickControls2 Qt5::DBus Qt5::RemoteObjects Qt5::Positioning
Qt5::Qml Qt5::Quick Qt5::Widgets Qt5::Gui Qt5::Xml Qt5::Svg Qt5::Network Qt5::Sensors Qt5::Multimedia Qt5::Core)
endif()

if(ANDROID)
Expand Down
51 changes: 42 additions & 9 deletions src/platformextras.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,24 +20,29 @@
#include <QDir>
#include <QStandardPaths>
#include <QStorageInfo>
#ifdef Q_OS_ANDROID
#include <QtAndroid>
#include <QAndroidJniEnvironment>
#endif

#ifdef SAILFISHOS
#if defined(SAILFISHOS)
#define AUTO_MOUNT "/run/media/"
#else
#ifdef Q_OS_ANDROID

#elif defined(Q_OS_ANDROID)
#include <QtAndroid>
#include <QAndroidJniEnvironment>
#define AUTO_MOUNT "/storage/"

#elif defined(Q_OS_LINUX)
#include <QtDBus>
#define AUTO_MOUNT "/media/"

#else
#define AUTO_MOUNT "/media/"
#endif
#endif

PlatformExtras::PlatformExtras(QObject* parent)
: QObject(parent)
, m_preventBlanking(false)
#ifdef Q_OS_LINUX
, m_cookie(0)
#endif
{
}

Expand Down Expand Up @@ -96,9 +101,11 @@ QStringList PlatformExtras::getStorageDirs()

void PlatformExtras::setPreventBlanking(bool on)
{
if (m_preventBlanking == on)
return;
m_preventBlanking = on;

#ifdef Q_OS_ANDROID
#if defined(Q_OS_ANDROID)
{
QtAndroid::runOnAndroidThread([on]
{
Expand All @@ -110,5 +117,31 @@ void PlatformExtras::setPreventBlanking(bool on)
window.callMethod<void>("clearFlags", "(I)V", FLAG_KEEP_SCREEN_ON);
});
}

#elif defined(Q_OS_LINUX)
QDBusConnection bus = QDBusConnection::sessionBus();
if(bus.isConnected())
{
QDBusInterface interface("org.freedesktop.ScreenSaver", "/org/freedesktop/ScreenSaver",
"org.freedesktop.ScreenSaver", bus);
if (interface.isValid())
{
if(on)
{
QDBusReply<uint> reply = interface.call("Inhibit", "osmin", "navigation enabled");
if (reply.isValid())
m_cookie = reply.value();
else
{
QDBusError error = reply.error();
qWarning("%s: %s", error.name().toUtf8().constData(), error.message().toUtf8().constData());
}
}
else
{
interface.call("UnInhibit", m_cookie);
}
}
}
#endif
}
4 changes: 4 additions & 0 deletions src/platformextras.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@ class PlatformExtras : public QObject
void setPreventBlanking(bool on);

bool m_preventBlanking;

#ifdef Q_OS_LINUX
uint m_cookie;
#endif
};

#endif // PLATFORM_EXTRAS_H

0 comments on commit 9b23c98

Please sign in to comment.