Skip to content
Snippets Groups Projects
Commit c36d5cc3 authored by Albert  Babí Oller's avatar Albert Babí Oller Committed by Amin Bandali
Browse files

callview: inhibit screen saver while in a call

Gitlab: #272

Change-Id: I25c1a9547b526f8889231a9d5061e63c349c39f1
parent e93854e1
No related branches found
No related tags found
No related merge requests found
......@@ -69,7 +69,8 @@ set(COMMON_SOURCES
${SRC_DIR}/utilsadapter.cpp
${SRC_DIR}/dbuserrorhandler.cpp
${SRC_DIR}/xrectsel.c
${SRC_DIR}/moderatorlistmodel.cpp)
${SRC_DIR}/moderatorlistmodel.cpp
${SRC_DIR}/screensaver.cpp)
set(COMMON_HEADERS
${SRC_DIR}/avatarimageprovider.h
......@@ -120,7 +121,8 @@ set(COMMON_HEADERS
${SRC_DIR}/utilsadapter.h
${SRC_DIR}/dbuserrorhandler.h
${SRC_DIR}/xrectsel.h
${SRC_DIR}/moderatorlistmodel.h)
${SRC_DIR}/moderatorlistmodel.h
${SRC_DIR}/screensaver.h)
find_package(PkgConfig REQUIRED)
pkg_check_modules(LIBNM libnm)
......
......@@ -159,6 +159,7 @@ HEADERS += \
src/avatarimageprovider.h \
src/moderatorlistmodel.h \
src/networkmanager.h \
src/screensaver.h \
src/smartlistmodel.h \
src/updatemanager.h \
src/utils.h \
......@@ -210,6 +211,7 @@ SOURCES += \
src/moderatorlistmodel.cpp \
src/networkmanager.cpp \
src/runguard.cpp \
src/screensaver.cpp \
src/updatemanager.cpp \
src/webchathelpers.cpp \
src/main.cpp \
......
......@@ -432,6 +432,7 @@ CallAdapter::connectCallModel(const QString& accountId)
}
}
}
preventScreenSaver(false);
break;
}
case lrc::api::call::Status::CONNECTED:
......@@ -441,6 +442,7 @@ CallAdapter::connectCallModel(const QString& accountId)
accInfo.conversationModel->selectConversation(convInfo.uid);
}
updateCall(convInfo.uid, accountId);
preventScreenSaver(true);
break;
}
case lrc::api::call::Status::PAUSED:
......@@ -865,3 +867,14 @@ CallAdapter::setTime(const QString& accountId, const QString& convUid)
emit updateTimeText(timeString);
}
}
void
CallAdapter::preventScreenSaver(bool state)
{
if (state) {
if (!screenSaver.isInhibited())
screenSaver.inhibit();
} else if (screenSaver.isInhibited()) {
screenSaver.uninhibit();
}
};
......@@ -22,6 +22,7 @@
#include "lrcinstance.h"
#include "qmladapterbase.h"
#include "globalsystemtray.h"
#include "screensaver.h"
#include <QObject>
#include <QString>
......@@ -129,4 +130,7 @@ private:
void updateCallOverlay(const lrc::api::conversation::Info& convInfo);
void setTime(const QString& accountId, const QString& convUid);
QTimer* oneSecondTimer_;
ScreenSaver screenSaver;
void preventScreenSaver(bool state);
};
/*!
* Copyright (C) 2021 by Savoir-faire Linux
* Author: Albert Babí <albert.babi@savoirfairelinux.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 "screensaver.h"
#include <QDebug>
ScreenSaver::ScreenSaver(QObject* parent)
#ifdef Q_OS_LINUX
: QObject(parent),
sessionBus_(QDBusConnection::sessionBus()),
screenSaverInterface_(nullptr)
{
request_ = 0u;
createInterface();
}
#else
: QObject(parent) {}
#endif
#ifdef Q_OS_LINUX
bool
ScreenSaver::createInterface(void)
{
if (!sessionBus_.isConnected()) {
qWarning() << "dbus not connected";
return false;
}
for(int i = 0; i <= N_SERVICES ; i++) {
screenSaverInterface_ = new QDBusInterface(services_[i],
paths_[i],
services_[i],
sessionBus_);
if (screenSaverInterface_->isValid()) {
qDebug() << "Screen saver dbus interface: " << services_[i];
return true;
}
}
qWarning() << "Cannot find dbus interface for screen saver";
screenSaverInterface_ = nullptr;
return false;
}
#endif
bool
ScreenSaver::inhibit(void)
{
if (isInhibited()) {
qDebug() << "Screen saver already inhibited";
return false;
}
#ifdef Q_OS_LINUX
if (!screenSaverInterface_) {
if (!createInterface()) {
return false;
}
}
QDBusReply<uint> reply =
screenSaverInterface_->call("Inhibit", "jami-qt", "In a call");
if (reply.isValid()) {
qDebug() << "Screen saver inhibited";
request_ = static_cast<uint>(reply.value());
return true;
} else {
QDBusError error = reply.error();
qDebug() << "Error inhibiting screen saver: "
<< error.message()
<< error.name();
}
#endif
return false;
}
bool
ScreenSaver::uninhibit(void)
{
if (!isInhibited()) {
qDebug() << "Screen saver is not inhibited";
return false;
}
#ifdef Q_OS_LINUX
if (!screenSaverInterface_) {
if (!createInterface()) {
return false;
}
}
QDBusReply<void> reply =
screenSaverInterface_->call("UnInhibit", static_cast<uint>(request_));
if (reply.isValid()) {
qDebug() << "Screen saver uninhibited";
request_ = 0u;
return true;
} else {
QDBusError error = reply.error();
qDebug() << "Error uninhibiting screen saver: "
<< error.message()
<< error.name();
}
request_ = 0u;
#endif
return false;
}
bool
ScreenSaver::isInhibited(void)
{
#ifdef Q_OS_LINUX
return request_ != 0u;
#endif
return false;
}
/*!
* Copyright (C) 2021 by Savoir-faire Linux
* Author: Albert Babí <albert.babi@savoirfairelinux.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/>.
*/
#pragma once
#include <QObject>
#ifdef Q_OS_LINUX
#include <QDBusInterface>
#include <QDBusReply>
#define N_SERVICES 3
#endif
class ScreenSaver : public QObject
{
Q_OBJECT
public:
explicit ScreenSaver(QObject* parent = nullptr);
virtual ~ScreenSaver() = default;
bool inhibit(void);
bool uninhibit(void);
bool isInhibited(void);
#ifdef Q_OS_LINUX
private:
bool createInterface(void);
QString services_[N_SERVICES] = { "org.freedesktop.ScreenSaver",
"org.gnome.ScreenSaver",
"org.mate.ScreenSaver" };
QString paths_[N_SERVICES] = { "/org/freedesktop/ScreenSaver",
"/org/gnome/ScreenSaver",
"/org/mate/ScreenSaver" };
uint request_;
QDBusConnection sessionBus_;
QDBusInterface* screenSaverInterface_;
#endif
};
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment