mirror of
https://invent.kde.org/network/falkon.git
synced 2024-12-19 10:16:34 +01:00
Some parts of IdleInhibitor dbus thing
Signed-off-by: Juraj Oravec <jurajoravec@mailo.com>
This commit is contained in:
parent
ca6f2bb2dc
commit
90dc78f639
@ -250,6 +250,7 @@ set(SRCS ${SRCS}
|
||||
tools/html5permissions/html5permissionsmanager.cpp
|
||||
tools/html5permissions/html5permissionsnotification.cpp
|
||||
tools/iconprovider.cpp
|
||||
tools/idleinhibitor.cpp
|
||||
tools/listitemdelegate.cpp
|
||||
tools/mactoolbutton.cpp
|
||||
tools/menubar.cpp
|
||||
@ -484,6 +485,7 @@ set(SRCS ${SRCS}
|
||||
tools/html5permissions/html5permissionsmanager.h
|
||||
tools/html5permissions/html5permissionsnotification.h
|
||||
tools/iconprovider.h
|
||||
tools/idleinhibitor.h
|
||||
tools/listitemdelegate.h
|
||||
tools/mactoolbutton.h
|
||||
tools/menubar.h
|
||||
|
92
src/lib/tools/idleinhibitor.cpp
Normal file
92
src/lib/tools/idleinhibitor.cpp
Normal file
@ -0,0 +1,92 @@
|
||||
/* ============================================================
|
||||
* Falkon - Qt web browser
|
||||
* Copyright (C) 2024 Juraj Oravec <jurajoravec@mailo.com>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
* ============================================================ */
|
||||
|
||||
#include "idleinhibitor.h"
|
||||
|
||||
#include <QDBusInterface>
|
||||
#include <QDBusReply>
|
||||
|
||||
IdleInhibitor::IdleInhibitor()
|
||||
: m_dbusCookie(0)
|
||||
, m_active(false)
|
||||
{
|
||||
}
|
||||
|
||||
void IdleInhibitor::inhibit()
|
||||
{
|
||||
if (m_dbusCookie != 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
#if defined(Q_OS_UNIX) && !defined(DISABLE_DBUS)
|
||||
QDBusInterface dbus(QSL("org.freedesktop.ScreenSaver"), QSL("/org/freedesktop/ScreenSaver"), QSL("org.freedesktop.ScreenSaver"), QDBusConnection::sessionBus());
|
||||
if (!dbus.isValid()) {
|
||||
qInfo() << "Dbus ionterface 'org.freedesktop.ScreenSaver' is not available.";
|
||||
return;
|
||||
}
|
||||
|
||||
QDBusReply <quint32> reply = dbus.call(QSL("Inhibit"), QL1S(Qz::APPNAME), tr("Media playback"));
|
||||
if (reply.isValid()) {
|
||||
m_dbusCookie = reply.value();
|
||||
setActive(true);
|
||||
}
|
||||
else {
|
||||
qWarning() << "IdleInhibitor DBus error:" << reply.error();
|
||||
setActive(false);
|
||||
}
|
||||
#endif /* Q_OS_UNIX && !DISABLE_DBUS */
|
||||
}
|
||||
|
||||
void IdleInhibitor::unInhibit()
|
||||
{
|
||||
if ((m_dbusCookie == 0) && !m_activeTabs.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
#if defined(Q_OS_UNIX) && !defined(DISABLE_DBUS)
|
||||
QDBusInterface dbus(QSL("org.freedesktop.ScreenSaver"), QSL("/org/freedesktop/ScreenSaver"), QSL("org.freedesktop.ScreenSaver"), QDBusConnection::sessionBus());
|
||||
if (!dbus.isValid()) {
|
||||
qInfo() << "IdleInhibitor: Dbus ionterface 'org.freedesktop.ScreenSaver' is not available.";
|
||||
setActive(false);
|
||||
return;
|
||||
}
|
||||
|
||||
QDBusReply <quint32> reply = dbus.call(QSL("UnInhibit"), m_dbusCookie);
|
||||
QDBusError err = dbus.lastError();
|
||||
if (err.isValid()) {
|
||||
qWarning() << "IdleInhibitor DBus error:" << reply.error();
|
||||
}
|
||||
|
||||
setActive(false);
|
||||
#endif /* Q_OS_UNIX && !DISABLE_DBUS */
|
||||
}
|
||||
|
||||
bool IdleInhibitor::active() const
|
||||
{
|
||||
return m_active;
|
||||
}
|
||||
|
||||
void IdleInhibitor::setActive(bool active)
|
||||
{
|
||||
if (m_active == active) {
|
||||
return;
|
||||
}
|
||||
|
||||
m_active = active;
|
||||
Q_EMIT activeChanged(m_active);
|
||||
}
|
53
src/lib/tools/idleinhibitor.h
Normal file
53
src/lib/tools/idleinhibitor.h
Normal file
@ -0,0 +1,53 @@
|
||||
/* ============================================================
|
||||
* Falkon - Qt web browser
|
||||
* Copyright (C) 2024 Juraj Oravec <jurajoravec@mailo.com>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
* ============================================================ */
|
||||
|
||||
#ifndef IDLEINHIBITOR_H
|
||||
#define IDLEINHIBITOR_H
|
||||
|
||||
#include "qzcommon.h"
|
||||
|
||||
#include <QObject>
|
||||
#include <QList>
|
||||
|
||||
class WebTab;
|
||||
|
||||
class FALKON_EXPORT IdleInhibitor : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_PROPERTY(bool active READ active WRITE setActive NOTIFY activeChanged)
|
||||
|
||||
public:
|
||||
IdleInhibitor();
|
||||
|
||||
bool active() const;
|
||||
|
||||
Q_SIGNALS:
|
||||
void activeChanged(bool active);
|
||||
|
||||
private:
|
||||
void inhibit();
|
||||
void unInhibit();
|
||||
|
||||
void setActive(bool active);
|
||||
|
||||
QList<WebTab*> m_activeTabs;
|
||||
quint32 m_dbusCookie;
|
||||
bool m_active;
|
||||
};
|
||||
|
||||
#endif /* IDLEINHIBITOR_H */
|
Loading…
Reference in New Issue
Block a user