Add an option to inhibit suspend while playing

minor modifications
This commit is contained in:
narunlifescience 2015-12-10 00:43:52 -06:00
parent 84a52893b4
commit b13f0690c8
20 changed files with 487 additions and 223 deletions

View File

@ -343,6 +343,7 @@ set(SOURCES
ui/globalshortcutgrabber.cpp
ui/globalshortcutssettingspage.cpp
ui/iconloader.cpp
ui/idlehandler.cpp
ui/mainwindow.cpp
ui/networkproxysettingspage.cpp
ui/networkremotesettingspage.cpp
@ -351,7 +352,6 @@ set(SOURCES
ui/organiseerrordialog.cpp
ui/playbacksettingspage.cpp
ui/qtsystemtrayicon.cpp
ui/screensaver.cpp
ui/settingsdialog.cpp
ui/settingspage.cpp
ui/standarditemiconloader.cpp
@ -860,7 +860,7 @@ optional_source(APPLE
engines/osxdevicefinder.cpp
networkremote/bonjour.mm
ui/globalshortcutgrabber.mm
ui/macscreensaver.cpp
ui/macidlehandler.cpp
ui/macsystemtrayicon.mm
widgets/osd_mac.mm
HEADERS
@ -875,7 +875,7 @@ optional_source(WIN32
SOURCES
engines/directsounddevicefinder.cpp
networkremote/tinysvcmdns.cpp
ui/windowsscreensaver.cpp
ui/windowsidlehandler.cpp
widgets/osd_win.cpp
INCLUDE_DIRECTORIES
${CMAKE_SOURCE_DIR}/3rdparty/tinysvcmdns
@ -981,7 +981,7 @@ optional_source(HAVE_DBUS
core/mpris1.cpp
core/mpris2.cpp
networkremote/avahi.cpp
ui/dbusscreensaver.cpp
ui/dbusidlehandler.cpp
HEADERS
core/mpris.h
core/mpris1.h

View File

@ -0,0 +1,78 @@
/* This file is part of Clementine.
Copyright 2010, David Sansome <me@davidsansome.com>
Copyright 2015, Arun Narayanankutty <n.arun.lifescience@gmail.com>
Clementine 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.
Clementine 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 Clementine. If not, see <http://www.gnu.org/licenses/>.
*/
#include "dbusidlehandler.h"
#include <QCoreApplication>
#include <QDBusInterface>
#include <QDBusReply>
#include <stdint.h>
#include "core/logging.h"
DBusIdleHandler::DBusIdleHandler(const QString& service, const QString& path,
const QString& interface)
: service_(service), path_(path), interface_(interface) {}
void DBusIdleHandler::Inhibit(const char* reason) {
QDBusInterface iface(service_, path_,
interface_, QDBusConnection::sessionBus());
QDBusReply<quint32> reply;
if (service_ == IdleHandler::kGnomePowermanagerService) {
reply =
iface.call("Inhibit", QCoreApplication::applicationName(),
quint32(0), QObject::tr(reason),
quint32(Inhibit_Suspend));
} else {
reply =
iface.call("Inhibit", QCoreApplication::applicationName(),
QObject::tr("reason"));
}
if (reply.isValid()) {
cookie_ = reply.value();
} else {
qLog(Warning) << "Failed to inhibit screensaver/suspend dbus service: "
<< service_ << " path: " << path_ << " interface: "
<< interface_;
}
}
void DBusIdleHandler::Uninhibit() {
QDBusInterface iface(service_, path_,
interface_, QDBusConnection::sessionBus());
if (service_ == IdleHandler::kGnomePowermanagerService) {
iface.call("Uninhibit", cookie_);
} else {
iface.call("UnInhibit", cookie_);
}
}
bool DBusIdleHandler::Isinhibited() {
QDBusInterface iface(service_, path_,
interface_, QDBusConnection::sessionBus());
QDBusReply<bool> reply;
if (service_ == IdleHandler::kGnomePowermanagerService) {
reply = iface.call("IsInhibited", quint32(Inhibit_Suspend));
} else {
reply = iface.call("HasInhibit");
}
return reply;
}

View File

@ -1,5 +1,6 @@
/* This file is part of Clementine.
Copyright 2010, David Sansome <me@davidsansome.com>
Copyright 2015, Arun Narayanankutty <n.arun.lifescience@gmail.com>
Clementine is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@ -15,22 +16,28 @@
along with Clementine. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef DBUSSCREENSAVER_H
#define DBUSSCREENSAVER_H
#ifndef DBUSIDLEHANDLER_H
#define DBUSIDLEHANDLER_H
#include "screensaver.h"
#include "idlehandler.h"
#include <QString>
class DBusScreensaver : public Screensaver {
class DBusIdleHandler : public IdleHandler {
public:
DBusScreensaver(const QString& service, const QString& path,
DBusIdleHandler(const QString& service, const QString& path,
const QString& interface);
void Inhibit();
void Uninhibit();
void Inhibit(const char* reason) override;
void Uninhibit() override;
bool Isinhibited() override;
private:
enum GnomeIdleHandlerFlags {
Inhibit_Suspend = 4,
Inhibit_Mark_Idle = 8
};
QString service_;
QString path_;
QString interface_;
@ -38,4 +45,4 @@ class DBusScreensaver : public Screensaver {
quint32 cookie_;
};
#endif
#endif // DBUSIDLEHANDLER_H

View File

@ -1,43 +0,0 @@
/* This file is part of Clementine.
Copyright 2010, David Sansome <me@davidsansome.com>
Clementine 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.
Clementine 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 Clementine. If not, see <http://www.gnu.org/licenses/>.
*/
#include "dbusscreensaver.h"
#include <QCoreApplication>
#include <QDBusInterface>
#include <QDBusReply>
DBusScreensaver::DBusScreensaver(const QString& service, const QString& path,
const QString& interface)
: service_(service), path_(path), interface_(interface) {}
void DBusScreensaver::Inhibit() {
QDBusInterface gnome_screensaver("org.gnome.ScreenSaver", "/",
"org.gnome.ScreenSaver");
QDBusReply<quint32> reply =
gnome_screensaver.call("Inhibit", QCoreApplication::applicationName(),
QObject::tr("Visualizations"));
if (reply.isValid()) {
cookie_ = reply.value();
}
}
void DBusScreensaver::Uninhibit() {
QDBusInterface gnome_screensaver("org.gnome.ScreenSaver", "/",
"org.gnome.ScreenSaver");
gnome_screensaver.call("UnInhibit", cookie_);
}

126
src/ui/idlehandler.cpp Normal file
View File

@ -0,0 +1,126 @@
/* This file is part of Clementine.
Copyright 2010, David Sansome <me@davidsansome.com>
Copyright 2015, Arun Narayanankutty <n.arun.lifescience@gmail.com>
Clementine 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.
Clementine 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 Clementine. If not, see <http://www.gnu.org/licenses/>.
*/
#include "config.h"
#include "idlehandler.h"
#include "core/logging.h"
#include <QtGlobal>
#ifdef HAVE_DBUS
#include "dbusidlehandler.h"
#include <QDBusConnection>
#include <QDBusConnectionInterface>
#endif
#ifdef Q_OS_DARWIN
#include "macidlehandler.h"
#endif
#ifdef Q_OS_WIN32
#include "windowsidlehandler.h"
#endif
const char* IdleHandler::kGnomeScreensaverService
= "org.gnome.ScreenSaver";
const char* IdleHandler::kGnomeScreensaverPath
= "/";
const char* IdleHandler::kGnomeScreensaverInterface
= "org.gnome.ScreenSaver";
const char* IdleHandler::kFreedesktopScreensaverService
= "org.freedesktop.ScreenSaver";
const char* IdleHandler::kFreedesktopScreensaverPath
= "/ScreenSaver";
const char* IdleHandler::kFreedesktopScreensaverInterface
= "org.freedesktop.ScreenSaver";
const char* IdleHandler::kGnomePowermanagerService
= "org.gnome.SessionManager";
const char* IdleHandler::kGnomePowermanagerPath
= "/org/gnome/SessionManager";
const char* IdleHandler::kGnomePowermanagerInterface
= "org.gnome.SessionManager";
const char* IdleHandler::kFreedesktopPowermanagerService
= "org.freedesktop.PowerManagement";
const char* IdleHandler::kFreedesktopPowermanagerPath
= "/org/freedesktop/PowerManagement/Inhibit";
const char* IdleHandler::kFreedesktopPowermanagerInterface
= "org.freedesktop.PowerManagement.Inhibit";
IdleHandler* IdleHandler::screensaver_ = 0;
IdleHandler* IdleHandler::suspend_ = 0;
IdleHandler::Inhibitor IdleHandler::inbtr_;
IdleHandler* IdleHandler::GetScreensaver() {
inbtr_ = Screensaver;
if (!screensaver_) {
#if defined(HAVE_DBUS)
// For gnome
if (QDBusConnection::sessionBus().interface()->isServiceRegistered(
kGnomeScreensaverService)) {
screensaver_ = new DBusIdleHandler(kGnomeScreensaverService,
kGnomeScreensaverPath,
kGnomeScreensaverInterface);
} else if (QDBusConnection::sessionBus().interface()->isServiceRegistered(
kFreedesktopScreensaverService)) /* For KDE, XFCE & others */ {
screensaver_ = new DBusIdleHandler(kFreedesktopScreensaverService,
kFreedesktopScreensaverPath,
kFreedesktopScreensaverInterface);
} else {
qLog(Warning) << "no supported dbus screensaver service available";
}
#elif defined(Q_OS_DARWIN)
screensaver_ = new MacIdleHandler();
#elif defined(Q_OS_WIN32)
screensaver_ = new WindowsIdleHandler();
#endif
}
return screensaver_;
}
IdleHandler* IdleHandler::GetSuspend() {
inbtr_ = Suspend;
if (!suspend_) {
#if defined(HAVE_DBUS)
// For gnome
if (QDBusConnection::sessionBus().interface()->isServiceRegistered(
kGnomePowermanagerService)) {
suspend_ = new DBusIdleHandler(kGnomePowermanagerService,
kGnomePowermanagerPath,
kGnomePowermanagerInterface);
} else if (QDBusConnection::sessionBus().interface()->isServiceRegistered(
kFreedesktopPowermanagerService)) /* For KDE, XFCE & others */ {
suspend_ = new DBusIdleHandler(kFreedesktopPowermanagerService,
kFreedesktopPowermanagerPath,
kFreedesktopPowermanagerInterface);
} else {
qLog(Warning) << "no supported dbus powermanager service available";
}
#elif defined(Q_OS_DARWIN)
suspend_ = new MacIdleHandler();
#elif defined(Q_OS_WIN32)
suspend_ = new WindowsIdleHandler();
#endif
}
return suspend_;
}

61
src/ui/idlehandler.h Normal file
View File

@ -0,0 +1,61 @@
/* This file is part of Clementine.
Copyright 2010, David Sansome <me@davidsansome.com>
Copyright 2015, Arun Narayanankutty <n.arun.lifescience@gmail.com>
Clementine 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.
Clementine 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 Clementine. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef IDLEHANDLER_H
#define IDLEHANDLER_H
class IdleHandler {
public:
virtual ~IdleHandler() {}
static const char* kGnomeScreensaverService;
static const char* kGnomeScreensaverPath;
static const char* kGnomeScreensaverInterface;
static const char* kGnomePowermanagerService;
static const char* kGnomePowermanagerPath;
static const char* kGnomePowermanagerInterface;
static const char* kFreedesktopScreensaverService;
static const char* kFreedesktopScreensaverPath;
static const char* kFreedesktopScreensaverInterface;
static const char* kFreedesktopPowermanagerService;
static const char* kFreedesktopPowermanagerPath;
static const char* kFreedesktopPowermanagerInterface;
virtual void Inhibit(const char* reason) = 0;
virtual void Uninhibit() = 0;
virtual bool Isinhibited() = 0;
static IdleHandler* GetScreensaver();
static IdleHandler* GetSuspend();
enum Inhibitor
{
Screensaver = 0,
Suspend = 1
};
static Inhibitor inbtr_;
private:
static IdleHandler* screensaver_;
static IdleHandler* suspend_;
};
#endif // IDLEHANDLER_H

View File

@ -1,5 +1,6 @@
/* This file is part of Clementine.
Copyright 2010, David Sansome <me@davidsansome.com>
Copyright 2015, Arun Narayanankutty <n.arun.lifescience@gmail.com>
Clementine is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@ -15,20 +16,43 @@
along with Clementine. If not, see <http://www.gnu.org/licenses/>.
*/
#include "macscreensaver.h"
#include "macidlehandler.h"
#include <IOKit/pwr_mgt/IOPMLib.h>
#include <QtDebug>
#include "core/logging.h"
#include "core/utilities.h"
MacScreensaver::MacScreensaver() : assertion_id_(0) {}
bool MacIdleHandler::is_inhibit_;
void MacScreensaver::Inhibit() {
IOPMAssertionCreateWithName(
kIOPMAssertPreventUserIdleDisplaySleep, kIOPMAssertionLevelOn,
CFSTR("Showing full-screen Clementine visualisations"), &assertion_id_);
MacIdleHandler::MacIdleHandler() : assertion_id_(0) {
is_inhibit_ = false;
}
void MacScreensaver::Uninhibit() { IOPMAssertionRelease(assertion_id_); }
void MacIdleHandler::Inhibit(const char* reason) {
IOReturn reply = IOPMAssertionCreateWithName(
kIOPMAssertPreventUserIdleDisplaySleep, kIOPMAssertionLevelOn,
CFSTR(reason), &assertion_id_);
if (reply == kIOReturnSuccess) {
is_inhibit_ = true;
} else {
qLog(Warning) << "Failed to inhibit screensaver/suspend";
}
}
void MacIdleHandler::Uninhibit() {
IOReturn reply = IOPMAssertionRelease(assertion_id_);
if (reply == kIOReturnSuccess) {
is_inhibit_ = false;
} else {
qLog(Warning) << "Failed to uninhibit screensaver/suspend";
}
}
bool WindowsIdleHandler::Isinhibited() {
return is_inhibit_;
}

View File

@ -1,5 +1,6 @@
/* This file is part of Clementine.
Copyright 2010, David Sansome <me@davidsansome.com>
Copyright 2015, Arun Narayanankutty <n.arun.lifescience@gmail.com>
Clementine is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@ -15,22 +16,24 @@
along with Clementine. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef MACSCREENSAVER_H
#define MACSCREENSAVER_H
#ifndef MACIDLEHANDLER_H
#define MACIDLEHANDLER_H
#include "screensaver.h"
#include "idlehandler.h"
#include <IOKit/pwr_mgt/IOPMLib.h>
class MacScreensaver : public Screensaver {
class MacIdleHandler : public IdleHandler {
public:
MacScreensaver();
MacIdleHandler();
void Inhibit();
void Uninhibit();
void Inhibit(const char* reason) override;
void Uninhibit() override;
bool Isinhibited() override;
private:
IOPMAssertionID assertion_id_;
static bool is_inhibit_;
};
#endif
#endif // MACIDLEHANDLER_H

View File

@ -195,7 +195,9 @@ MainWindow::MainWindow(Application* app, SystemTrayIcon* tray_icon, OSD* osd,
saved_playback_state_(Engine::Empty),
doubleclick_addmode_(AddBehaviour_Append),
doubleclick_playmode_(PlayBehaviour_IfStopped),
menu_playmode_(PlayBehaviour_IfStopped) {
menu_playmode_(PlayBehaviour_IfStopped),
idlehandler_(IdleHandler::GetSuspend()),
is_suspend_inhibited(false) {
qLog(Debug) << "Starting";
connect(app, SIGNAL(ErrorAdded(QString)), SLOT(ShowErrorDialog(QString)));
@ -1007,6 +1009,11 @@ void MainWindow::ReloadSettings() {
PlaylistAddBehaviour_Play).toInt());
menu_playmode_ =
PlayBehaviour(s.value("menu_playmode", PlayBehaviour_IfStopped).toInt());
s.endGroup();
s.beginGroup(Engine::Base::kSettingsGroup);
inhibit_suspend_while_playing_status_ =
s.value("InhibitSuspendWhilePlaying", false).toBool();
}
void MainWindow::ReloadAllSettings() {
@ -1047,6 +1054,7 @@ void MainWindow::MediaStopped() {
ui_->track_slider->SetStopped();
tray_icon_->SetProgress(0);
tray_icon_->SetStopped();
HandleInhibitSuspendWhilePlaying(false);
}
void MainWindow::MediaPaused() {
@ -1061,6 +1069,7 @@ void MainWindow::MediaPaused() {
track_slider_timer_->stop();
tray_icon_->SetPaused();
HandleInhibitSuspendWhilePlaying(false);
}
void MainWindow::MediaPlaying() {
@ -1089,6 +1098,7 @@ void MainWindow::MediaPlaying() {
track_position_timer_->start();
track_slider_timer_->start();
UpdateTrackPosition();
HandleInhibitSuspendWhilePlaying(true);
}
void MainWindow::VolumeChanged(int volume) {
@ -2417,6 +2427,11 @@ void MainWindow::EnsureSettingsDialogCreated() {
SLOT(SetWiimotedevInterfaceActived(bool)));
#endif
// Handle Suspend ststus
connect(settings_dialog_.get(),
SIGNAL(InhibitSuspendWhilePlaying(bool)),
SLOT(HandleInhibitSuspendWhilePlaying(bool)));
// Allows custom notification preview
connect(settings_dialog_.get(),
SIGNAL(NotificationPreview(OSD::Behaviour, QString, QString)),
@ -2792,3 +2807,16 @@ void MainWindow::keyPressEvent(QKeyEvent* event) {
QMainWindow::keyPressEvent(event);
}
}
void MainWindow::HandleInhibitSuspendWhilePlaying(bool status) {
if (idlehandler_) {
if (inhibit_suspend_while_playing_status_ &&
!is_suspend_inhibited && status) {
idlehandler_->Inhibit("Clementine is playing");
is_suspend_inhibited = idlehandler_->Isinhibited();
} else if (is_suspend_inhibited && !status){
idlehandler_->Uninhibit();
is_suspend_inhibited = idlehandler_->Isinhibited();
}
}
}

View File

@ -30,6 +30,7 @@
#include "engines/engine_fwd.h"
#include "library/librarymodel.h"
#include "playlist/playlistitem.h"
#include "ui/idlehandler.h"
#include "ui/settingsdialog.h"
class About;
@ -64,6 +65,7 @@ class PlaylistBackend;
class PlaylistListContainer;
class PlaylistManager;
class QueueManager;
class IdleHandler;
class InternetItem;
class InternetModel;
class InternetViewContainer;
@ -278,6 +280,8 @@ signals:
void ShowConsole();
void HandleInhibitSuspendWhilePlaying(bool status);
private:
void ConnectInfoView(SongInfoBase* view);
@ -373,6 +377,9 @@ signals:
PlayBehaviour menu_playmode_;
BackgroundStreams* background_streams_;
IdleHandler* idlehandler_;
bool inhibit_suspend_while_playing_status_;
bool is_suspend_inhibited;
};
#endif // MAINWINDOW_H

View File

@ -87,6 +87,8 @@ void PlaybackSettingsPage::Load() {
s.value("FadeoutPauseEnabled", false).toBool());
ui_->fading_pause_duration->setValue(
s.value("FadeoutPauseDuration", 250).toInt());
ui_->inhibit_suspend_while_playing->setChecked(
s.value("InhibitSuspendWhilePlaying", false).toBool());
s.endGroup();
s.beginGroup(GstEngine::kSettingsGroup);
@ -134,6 +136,8 @@ void PlaybackSettingsPage::Save() {
s.setValue("NoCrossfadeSameAlbum", ui_->fading_samealbum->isChecked());
s.setValue("FadeoutPauseEnabled", ui_->fadeout_pause->isChecked());
s.setValue("FadeoutPauseDuration", ui_->fading_pause_duration->value());
s.setValue("InhibitSuspendWhilePlaying",
ui_->inhibit_suspend_while_playing->isChecked());
s.endGroup();
GstEngine::OutputDetails details =
@ -154,6 +158,10 @@ void PlaybackSettingsPage::Save() {
ui_->sample_rate->itemData(ui_->sample_rate->currentIndex()).toInt());
s.setValue("bufferminfill", ui_->buffer_min_fill->value());
s.endGroup();
//Emit inhibit suspend while playing signal
emit InhibitSuspendWhilePlaying(
ui_->inhibit_suspend_while_playing->isChecked());
}
void PlaybackSettingsPage::RgPreampChanged(int value) {

View File

@ -7,7 +7,7 @@
<x>0</x>
<y>0</y>
<width>596</width>
<height>667</height>
<height>684</height>
</rect>
</property>
<property name="windowTitle">
@ -25,7 +25,7 @@
</widget>
</item>
<item>
<widget class="QGroupBox" name="groupBox">
<widget class="QGroupBox" name="fading_groupBox">
<property name="title">
<string>Fading</string>
</property>
@ -70,7 +70,16 @@
<item>
<widget class="QWidget" name="fading_options" native="true">
<layout class="QHBoxLayout" name="horizontalLayout">
<property name="margin">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
@ -168,6 +177,22 @@
</layout>
</widget>
</item>
<item>
<widget class="QGroupBox" name="power_management_groupBox">
<property name="title">
<string>System Power Management Options</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_4">
<item>
<widget class="QCheckBox" name="inhibit_suspend_while_playing">
<property name="text">
<string>Inhibit suspend while playing</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QGroupBox" name="replaygain_group">
<property name="title">
@ -187,7 +212,16 @@
<bool>false</bool>
</property>
<layout class="QFormLayout" name="formLayout_4">
<property name="margin">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item row="0" column="0">

View File

@ -1,66 +0,0 @@
/* This file is part of Clementine.
Copyright 2010, David Sansome <me@davidsansome.com>
Clementine 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.
Clementine 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 Clementine. If not, see <http://www.gnu.org/licenses/>.
*/
#include "config.h"
#include "screensaver.h"
#include <QtGlobal>
#ifdef HAVE_DBUS
#include "dbusscreensaver.h"
#include <QDBusConnection>
#include <QDBusConnectionInterface>
#endif
#ifdef Q_OS_DARWIN
#include "macscreensaver.h"
#endif
#ifdef Q_OS_WIN32
#include "windowsscreensaver.h"
#endif
#include <QtDebug>
const char* Screensaver::kGnomeService = "org.gnome.ScreenSaver";
const char* Screensaver::kGnomePath = "/";
const char* Screensaver::kGnomeInterface = "org.gnome.ScreenSaver";
const char* Screensaver::kKdeService = "org.kde.ScreenSaver";
const char* Screensaver::kKdePath = "/ScreenSaver/";
const char* Screensaver::kKdeInterface = "org.freedesktop.ScreenSaver";
Screensaver* Screensaver::screensaver_ = 0;
Screensaver* Screensaver::GetScreensaver() {
if (!screensaver_) {
#if defined(HAVE_DBUS)
if (QDBusConnection::sessionBus().interface()->isServiceRegistered(
kGnomeService)) {
screensaver_ =
new DBusScreensaver(kGnomeService, kGnomePath, kGnomeInterface);
} else if (QDBusConnection::sessionBus().interface()->isServiceRegistered(
kKdeService)) {
screensaver_ = new DBusScreensaver(kKdeService, kKdePath, kKdeInterface);
}
#elif defined(Q_OS_DARWIN)
screensaver_ = new MacScreensaver();
#elif defined(Q_OS_WIN32)
screensaver_ = new WindowsScreensaver();
#endif
}
return screensaver_;
}

View File

@ -1,42 +0,0 @@
/* This file is part of Clementine.
Copyright 2010, David Sansome <me@davidsansome.com>
Clementine 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.
Clementine 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 Clementine. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef SCREENSAVER_H
#define SCREENSAVER_H
class Screensaver {
public:
virtual ~Screensaver() {}
static const char* kGnomeService;
static const char* kGnomePath;
static const char* kGnomeInterface;
static const char* kKdeService;
static const char* kKdePath;
static const char* kKdeInterface;
virtual void Inhibit() = 0;
virtual void Uninhibit() = 0;
static Screensaver* GetScreensaver();
private:
static Screensaver* screensaver_;
};
#endif

View File

@ -119,6 +119,7 @@ class SettingsDialog : public QDialog {
signals:
void NotificationPreview(OSD::Behaviour, QString, QString);
void SetWiimotedevInterfaceActived(bool);
void InhibitSuspendWhilePlaying(bool);
private slots:
void CurrentItemChanged(QTreeWidgetItem* item);

View File

@ -45,6 +45,7 @@ class SettingsPage : public QWidget {
signals:
void NotificationPreview(OSD::Behaviour, QString, QString);
void SetWiimotedevInterfaceActived(bool);
void InhibitSuspendWhilePlaying(bool);
private:
SettingsDialog* dialog_;

View File

@ -0,0 +1,64 @@
/* This file is part of Clementine.
Copyright 2015, John Maguire <john.maguire@gmail.com>
Copyright 2015, Arun Narayanankutty <n.arun.lifescience@gmail.com>
Clementine 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.
Clementine 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 Clementine. If not, see <http://www.gnu.org/licenses/>.
*/
#include "windowsidlehandler.h"
#include "core/logging.h"
// TODO: use PowerCreateRequest on Win7+
bool WindowsIdleHandler::is_inhibit_;
WindowsIdleHandler::WindowsIdleHandler() : previous_state_(0) {
is_inhibit_ = false;
}
void WindowsIdleHandler::Inhibit(const char*) {
switch (IdleHandler::inbtr_) {
case IdleHandler::Screensaver :
// resetting the display idle timer.
previous_state_ =
SetThreadExecutionState(ES_CONTINUOUS | ES_DISPLAY_REQUIRED);
break;
case IdleHandler::Suspend :
// resetting the system idle timer.
previous_state_ =
SetThreadExecutionState(ES_CONTINUOUS | ES_SYSTEM_REQUIRED);
break;
}
if (previous_state_! = 0) {
is_inhibit_ = true;
} else {
qLog(Warning) << "Failed to inhibit screensaver/suspend";
}
}
void WindowsIdleHandler::Uninhibit() {
previous_state_ =
SetThreadExecutionState(ES_CONTINUOUS | previous_state_);
if (previous_state_! = 0) {
is_inhibit_ = false;
} else {
qLog(Warning) << "Failed to uninhibit screensaver/suspend";
}
}
bool WindowsIdleHandler::Isinhibited() {
return is_inhibit_;
}

View File

@ -1,5 +1,6 @@
/* This file is part of Clementine.
Copyright 2015, John Maguire <john.maguire@gmail.com>
Copyright 2015, Arun Narayanankutty <n.arun.lifescience@gmail.com>
Clementine is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@ -14,22 +15,24 @@
You should have received a copy of the GNU General Public License
along with Clementine. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef WINDOWSSCREENSAVER_H
#define WINDOWSSCREENSAVER_H
#ifndef WINDOWSIDLEHANDLER_H
#define WINDOWSIDLEHANDLER_H
#include "screensaver.h"
#include "idlehandler.h"
#include <windows.h>
class WindowsScreensaver : public Screensaver {
class WindowsIdleHandler : public IdleHandler {
public:
WindowsScreensaver();
WindowsIdleHandler();
void Inhibit() override;
void Inhibit(const char*) override;
void Uninhibit() override;
bool Isinhibited() override;
private:
EXECUTION_STATE previous_state_;
static bool is_inhibit_;
};
#endif // WINDOWSSCREENSAVER_H
#endif // WINDOWSIDLEHANDLER_H

View File

@ -1,30 +0,0 @@
/* This file is part of Clementine.
Copyright 2015, John Maguire <john.maguire@gmail.com>
Clementine 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.
Clementine 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 Clementine. If not, see <http://www.gnu.org/licenses/>.
*/
#include "windowsscreensaver.h"
WindowsScreensaver::WindowsScreensaver() : previous_state_(0) {}
void WindowsScreensaver::Inhibit() {
// TODO: use PowerCreateRequest on Win7+
previous_state_ =
SetThreadExecutionState(ES_CONTINUOUS | ES_DISPLAY_REQUIRED);
}
void WindowsScreensaver::Uninhibit() {
SetThreadExecutionState(ES_CONTINUOUS | previous_state_);
}

View File

@ -22,7 +22,7 @@
#include "visualisationselector.h"
#include "engines/gstengine.h"
#include "ui/iconloader.h"
#include "ui/screensaver.h"
#include "ui/idlehandler.h"
#include <QGLWidget>
#include <QGraphicsProxyWidget>
@ -265,9 +265,9 @@ void VisualisationContainer::keyReleaseEvent(QKeyEvent* event) {
void VisualisationContainer::ToggleFullscreen() {
setWindowState(windowState() ^ Qt::WindowFullScreen);
Screensaver* screensaver = Screensaver::GetScreensaver();
IdleHandler* screensaver = IdleHandler::GetScreensaver();
if (screensaver)
isFullScreen() ? screensaver->Inhibit() : screensaver->Uninhibit();
isFullScreen() ? screensaver->Inhibit("Visualisation") : screensaver->Uninhibit();
}
void VisualisationContainer::SetFps(int fps) {