From c9b0bb20449ab4e45d500701c6070fd5ccf3034b Mon Sep 17 00:00:00 2001 From: John Maguire Date: Fri, 8 Jan 2016 15:09:07 +0000 Subject: [PATCH] Revert "Add an option to inhibit suspend while playing" --- src/CMakeLists.txt | 8 +- src/ui/dbusidlehandler.cpp | 78 ---------- src/ui/dbusscreensaver.cpp | 43 ++++++ .../{dbusidlehandler.h => dbusscreensaver.h} | 23 ++- src/ui/idlehandler.cpp | 134 ------------------ ...{macidlehandler.cpp => macscreensaver.cpp} | 33 +---- src/ui/{macidlehandler.h => macscreensaver.h} | 19 ++- src/ui/mainwindow.cpp | 36 +---- src/ui/mainwindow.h | 8 -- src/ui/playbacksettingspage.cpp | 8 -- src/ui/playbacksettingspage.ui | 23 +-- src/ui/screensaver.cpp | 66 +++++++++ src/ui/{idlehandler.h => screensaver.h} | 40 +++--- src/ui/settingsdialog.cpp | 2 - src/ui/settingsdialog.h | 1 - src/ui/settingspage.h | 1 - src/ui/windowsidlehandler.cpp | 61 -------- src/ui/windowsscreensaver.cpp | 30 ++++ ...dowsidlehandler.h => windowsscreensaver.h} | 17 +-- src/visualisations/visualisationcontainer.cpp | 6 +- 20 files changed, 194 insertions(+), 443 deletions(-) delete mode 100644 src/ui/dbusidlehandler.cpp create mode 100644 src/ui/dbusscreensaver.cpp rename src/ui/{dbusidlehandler.h => dbusscreensaver.h} (65%) delete mode 100644 src/ui/idlehandler.cpp rename src/ui/{macidlehandler.cpp => macscreensaver.cpp} (52%) rename src/ui/{macidlehandler.h => macscreensaver.h} (69%) create mode 100644 src/ui/screensaver.cpp rename src/ui/{idlehandler.h => screensaver.h} (52%) delete mode 100644 src/ui/windowsidlehandler.cpp create mode 100644 src/ui/windowsscreensaver.cpp rename src/ui/{windowsidlehandler.h => windowsscreensaver.h} (70%) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index d6472db29..d738e1302 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -344,7 +344,6 @@ set(SOURCES ui/globalshortcutgrabber.cpp ui/globalshortcutssettingspage.cpp ui/iconloader.cpp - ui/idlehandler.cpp ui/mainwindow.cpp ui/networkproxysettingspage.cpp ui/networkremotesettingspage.cpp @@ -353,6 +352,7 @@ set(SOURCES ui/organiseerrordialog.cpp ui/playbacksettingspage.cpp ui/qtsystemtrayicon.cpp + ui/screensaver.cpp ui/settingsdialog.cpp ui/settingspage.cpp ui/standarditemiconloader.cpp @@ -863,7 +863,7 @@ optional_source(APPLE engines/osxdevicefinder.cpp networkremote/bonjour.mm ui/globalshortcutgrabber.mm - ui/macidlehandler.cpp + ui/macscreensaver.cpp ui/macsystemtrayicon.mm widgets/osd_mac.mm HEADERS @@ -878,7 +878,7 @@ optional_source(WIN32 SOURCES engines/directsounddevicefinder.cpp networkremote/tinysvcmdns.cpp - ui/windowsidlehandler.cpp + ui/windowsscreensaver.cpp widgets/osd_win.cpp INCLUDE_DIRECTORIES ${CMAKE_SOURCE_DIR}/3rdparty/tinysvcmdns @@ -984,7 +984,7 @@ optional_source(HAVE_DBUS core/mpris1.cpp core/mpris2.cpp networkremote/avahi.cpp - ui/dbusidlehandler.cpp + ui/dbusscreensaver.cpp HEADERS core/mpris.h core/mpris1.h diff --git a/src/ui/dbusidlehandler.cpp b/src/ui/dbusidlehandler.cpp deleted file mode 100644 index 45412f1ac..000000000 --- a/src/ui/dbusidlehandler.cpp +++ /dev/null @@ -1,78 +0,0 @@ -/* This file is part of Clementine. - Copyright 2010, David Sansome - Copyright 2015, Arun Narayanankutty - - 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 . -*/ - -#include "dbusidlehandler.h" - -#include -#include -#include - -#include - -#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 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 reply; - if (service_ == IdleHandler::kGnomePowermanagerService) { - reply = iface.call("IsInhibited", quint32(Inhibit_Suspend)); - } else { - reply = iface.call("HasInhibit"); - } - - return reply; -} diff --git a/src/ui/dbusscreensaver.cpp b/src/ui/dbusscreensaver.cpp new file mode 100644 index 000000000..21fa3a9de --- /dev/null +++ b/src/ui/dbusscreensaver.cpp @@ -0,0 +1,43 @@ +/* This file is part of Clementine. + Copyright 2010, David Sansome + + 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 . +*/ + +#include "dbusscreensaver.h" + +#include +#include +#include + +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 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_); +} diff --git a/src/ui/dbusidlehandler.h b/src/ui/dbusscreensaver.h similarity index 65% rename from src/ui/dbusidlehandler.h rename to src/ui/dbusscreensaver.h index f213ba0b0..4cae2a16c 100644 --- a/src/ui/dbusidlehandler.h +++ b/src/ui/dbusscreensaver.h @@ -1,6 +1,5 @@ /* This file is part of Clementine. Copyright 2010, David Sansome - Copyright 2015, Arun Narayanankutty Clementine is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -16,28 +15,22 @@ along with Clementine. If not, see . */ -#ifndef DBUSIDLEHANDLER_H -#define DBUSIDLEHANDLER_H +#ifndef DBUSSCREENSAVER_H +#define DBUSSCREENSAVER_H -#include "idlehandler.h" +#include "screensaver.h" #include -class DBusIdleHandler : public IdleHandler { +class DBusScreensaver : public Screensaver { public: - DBusIdleHandler(const QString& service, const QString& path, + DBusScreensaver(const QString& service, const QString& path, const QString& interface); - void Inhibit(const char* reason) override; - void Uninhibit() override; - bool Isinhibited() override; + void Inhibit(); + void Uninhibit(); private: - enum GnomeIdleHandlerFlags { - Inhibit_Suspend = 4, - Inhibit_Mark_Idle = 8 - }; - QString service_; QString path_; QString interface_; @@ -45,4 +38,4 @@ class DBusIdleHandler : public IdleHandler { quint32 cookie_; }; -#endif // DBUSIDLEHANDLER_H +#endif diff --git a/src/ui/idlehandler.cpp b/src/ui/idlehandler.cpp deleted file mode 100644 index 1672c043b..000000000 --- a/src/ui/idlehandler.cpp +++ /dev/null @@ -1,134 +0,0 @@ -/* This file is part of Clementine. - Copyright 2010, David Sansome - Copyright 2015, Arun Narayanankutty - - 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 . -*/ - -#include "config.h" -#include "idlehandler.h" -#include "core/logging.h" - -#include - -#ifdef HAVE_DBUS -#include "dbusidlehandler.h" -#include -#include -#endif - -#ifdef Q_OS_DARWIN -#include "macidlehandler.h" -#endif - -#ifdef Q_OS_WIN32 -#include "windowsidlehandler.h" -#endif - -// Services -const char* IdleHandler::kGnomeScreensaverService - = "org.gnome.ScreenSaver"; -const char* IdleHandler::kFreedesktopScreensaverService - = "org.freedesktop.ScreenSaver"; -const char* IdleHandler::kGnomePowermanagerService - = "org.gnome.SessionManager"; -const char* IdleHandler::kFreedesktopPowermanagerService - = "org.freedesktop.PowerManagement"; - -namespace { - // Gnome Screensaver - const char* kGnomeScreensaverPath - = "/"; - const char* kGnomeScreensaverInterface - = "org.gnome.ScreenSaver"; - - // Freedesktop screensaver - const char* kFreedesktopScreensaverPath - = "/ScreenSaver"; - const char* kFreedesktopScreensaverInterface - = "org.freedesktop.ScreenSaver"; - - // Gnome powermanager - const char* kGnomePowermanagerPath - = "/org/gnome/SessionManager"; - const char* kGnomePowermanagerInterface - = "org.gnome.SessionManager"; - - // Freedesktop powermanager - const char* kFreedesktopPowermanagerPath - = "/org/freedesktop/PowerManagement/Inhibit"; - const char* 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_; -} diff --git a/src/ui/macidlehandler.cpp b/src/ui/macscreensaver.cpp similarity index 52% rename from src/ui/macidlehandler.cpp rename to src/ui/macscreensaver.cpp index 8e313abc7..9bf3d076d 100644 --- a/src/ui/macidlehandler.cpp +++ b/src/ui/macscreensaver.cpp @@ -1,6 +1,5 @@ /* This file is part of Clementine. Copyright 2010, David Sansome - Copyright 2015, Arun Narayanankutty Clementine is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -16,40 +15,20 @@ along with Clementine. If not, see . */ -#include "macidlehandler.h" +#include "macscreensaver.h" #include #include -#include "core/logging.h" #include "core/utilities.h" -MacIdleHandler::MacIdleHandler() : assertion_id_(0), - is_inhibit_(false) {} +MacScreensaver::MacScreensaver() : assertion_id_(0) {} -void MacIdleHandler::Inhibit(const char* reason) { - IOReturn reply = IOPMAssertionCreateWithName( +void MacScreensaver::Inhibit() { + IOPMAssertionCreateWithName( kIOPMAssertPreventUserIdleDisplaySleep, kIOPMAssertionLevelOn, - CFSTR(reason), &assertion_id_); - - if (reply == kIOReturnSuccess) { - is_inhibit_ = true; - } else { - qLog(Warning) << "Failed to inhibit screensaver/suspend"; - } + CFSTR("Showing full-screen Clementine visualisations"), &assertion_id_); } -void MacIdleHandler::Uninhibit() { - IOReturn reply = IOPMAssertionRelease(assertion_id_); - - if (reply == kIOReturnSuccess) { - is_inhibit_ = false; - } else { - qLog(Warning) << "Failed to uninhibit screensaver/suspend"; - } -} - -bool MacIdleHandler::Isinhibited() { - return is_inhibit_; -} +void MacScreensaver::Uninhibit() { IOPMAssertionRelease(assertion_id_); } diff --git a/src/ui/macidlehandler.h b/src/ui/macscreensaver.h similarity index 69% rename from src/ui/macidlehandler.h rename to src/ui/macscreensaver.h index d1e73a28b..ac0251c3e 100644 --- a/src/ui/macidlehandler.h +++ b/src/ui/macscreensaver.h @@ -1,6 +1,5 @@ /* This file is part of Clementine. Copyright 2010, David Sansome - Copyright 2015, Arun Narayanankutty Clementine is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -16,24 +15,22 @@ along with Clementine. If not, see . */ -#ifndef MACIDLEHANDLER_H -#define MACIDLEHANDLER_H +#ifndef MACSCREENSAVER_H +#define MACSCREENSAVER_H -#include "idlehandler.h" +#include "screensaver.h" #include -class MacIdleHandler : public IdleHandler { +class MacScreensaver : public Screensaver { public: - MacIdleHandler(); + MacScreensaver(); - void Inhibit(const char* reason) override; - void Uninhibit() override; - bool Isinhibited() override; + void Inhibit(); + void Uninhibit(); private: IOPMAssertionID assertion_id_; - bool is_inhibit_; }; -#endif // MACIDLEHANDLER_H +#endif diff --git a/src/ui/mainwindow.cpp b/src/ui/mainwindow.cpp index e8a642978..68eeeb8d8 100644 --- a/src/ui/mainwindow.cpp +++ b/src/ui/mainwindow.cpp @@ -195,9 +195,7 @@ 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), - idlehandler_(IdleHandler::GetSuspend()), - is_suspend_inhibited_(false) { + menu_playmode_(PlayBehaviour_IfStopped) { qLog(Debug) << "Starting"; connect(app, SIGNAL(ErrorAdded(QString)), SLOT(ShowErrorDialog(QString))); @@ -1011,12 +1009,6 @@ MainWindow::MainWindow(Application* app, SystemTrayIcon* tray_icon, OSD* osd, new WiimotedevShortcuts(osd_, this, app_->player())); #endif - settings_.endGroup(); - - settings_.beginGroup(Engine::Base::kSettingsGroup); - inhibit_suspend_while_playing_status_ = - settings_.value("InhibitSuspendWhilePlaying", false).toBool(); - CheckFullRescanRevisions(); LoadPlaybackStatus(); @@ -1090,7 +1082,6 @@ void MainWindow::MediaStopped() { ui_->track_slider->SetStopped(); tray_icon_->SetProgress(0); tray_icon_->SetStopped(); - HandleInhibitSuspendWhilePlaying(false); } void MainWindow::MediaPaused() { @@ -1106,7 +1097,6 @@ void MainWindow::MediaPaused() { track_slider_timer_->stop(); tray_icon_->SetPaused(); - HandleInhibitSuspendWhilePlaying(false); } void MainWindow::MediaPlaying() { @@ -1136,7 +1126,6 @@ void MainWindow::MediaPlaying() { track_position_timer_->start(); track_slider_timer_->start(); UpdateTrackPosition(); - HandleInhibitSuspendWhilePlaying(true); } void MainWindow::VolumeChanged(int volume) { @@ -2468,11 +2457,6 @@ void MainWindow::EnsureSettingsDialogCreated() { SLOT(SetWiimotedevInterfaceActived(bool))); #endif - // Handle suspend status - connect(settings_dialog_.get(), - SIGNAL(InhibitSuspendWhilePlaying(bool)), - SLOT(InhibitSuspendWhilePlaying(bool))); - // Allows custom notification preview connect(settings_dialog_.get(), SIGNAL(NotificationPreview(OSD::Behaviour, QString, QString)), @@ -2854,21 +2838,3 @@ void MainWindow::keyPressEvent(QKeyEvent* event) { QMainWindow::keyPressEvent(event); } } - -void MainWindow::InhibitSuspendWhilePlaying(bool status) { - inhibit_suspend_while_playing_status_ = status; - HandleInhibitSuspendWhilePlaying(status); -} - -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(); - } - } -} diff --git a/src/ui/mainwindow.h b/src/ui/mainwindow.h index 2abacf456..3176dd9f8 100644 --- a/src/ui/mainwindow.h +++ b/src/ui/mainwindow.h @@ -30,7 +30,6 @@ #include "engines/engine_fwd.h" #include "library/librarymodel.h" #include "playlist/playlistitem.h" -#include "ui/idlehandler.h" #include "ui/settingsdialog.h" class About; @@ -65,7 +64,6 @@ class PlaylistBackend; class PlaylistListContainer; class PlaylistManager; class QueueManager; -class IdleHandler; class InternetItem; class InternetModel; class InternetViewContainer; @@ -280,9 +278,6 @@ signals: void ShowConsole(); - void InhibitSuspendWhilePlaying(bool status); - void HandleInhibitSuspendWhilePlaying(bool status); - private: void ConnectInfoView(SongInfoBase* view); @@ -378,9 +373,6 @@ signals: PlayBehaviour menu_playmode_; BackgroundStreams* background_streams_; - IdleHandler* idlehandler_; - bool inhibit_suspend_while_playing_status_; - bool is_suspend_inhibited_; }; #endif // MAINWINDOW_H diff --git a/src/ui/playbacksettingspage.cpp b/src/ui/playbacksettingspage.cpp index e5a883e7c..957317377 100644 --- a/src/ui/playbacksettingspage.cpp +++ b/src/ui/playbacksettingspage.cpp @@ -87,8 +87,6 @@ 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); @@ -136,8 +134,6 @@ 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 = @@ -158,10 +154,6 @@ 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) { diff --git a/src/ui/playbacksettingspage.ui b/src/ui/playbacksettingspage.ui index a6174cb07..d2b405b66 100644 --- a/src/ui/playbacksettingspage.ui +++ b/src/ui/playbacksettingspage.ui @@ -7,7 +7,7 @@ 0 0 596 - 754 + 667 @@ -25,7 +25,7 @@ - + Fading @@ -168,25 +168,6 @@ - - - - System Power Management Options - - - - - - If enabled, Clementine will prevent the system from automatically suspending if it is playing a track - - - Inhibit automatic suspend if playing - - - - - - diff --git a/src/ui/screensaver.cpp b/src/ui/screensaver.cpp new file mode 100644 index 000000000..af55ab8e1 --- /dev/null +++ b/src/ui/screensaver.cpp @@ -0,0 +1,66 @@ +/* This file is part of Clementine. + Copyright 2010, David Sansome + + 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 . +*/ + +#include "config.h" +#include "screensaver.h" + +#include + +#ifdef HAVE_DBUS +#include "dbusscreensaver.h" +#include +#include +#endif + +#ifdef Q_OS_DARWIN +#include "macscreensaver.h" +#endif + +#ifdef Q_OS_WIN32 +#include "windowsscreensaver.h" +#endif + +#include + +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_; +} diff --git a/src/ui/idlehandler.h b/src/ui/screensaver.h similarity index 52% rename from src/ui/idlehandler.h rename to src/ui/screensaver.h index 8aaf18999..a33eeb5f3 100644 --- a/src/ui/idlehandler.h +++ b/src/ui/screensaver.h @@ -1,6 +1,5 @@ /* This file is part of Clementine. Copyright 2010, David Sansome - Copyright 2015, Arun Narayanankutty Clementine is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -16,35 +15,28 @@ along with Clementine. If not, see . */ -#ifndef IDLEHANDLER_H -#define IDLEHANDLER_H +#ifndef SCREENSAVER_H +#define SCREENSAVER_H -class IdleHandler { +class Screensaver { public: - virtual ~IdleHandler() {} + virtual ~Screensaver() {} - virtual void Inhibit(const char* reason) = 0; + 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; - virtual bool Isinhibited() = 0; - static IdleHandler* GetScreensaver(); - static IdleHandler* GetSuspend(); - - enum Inhibitor - { - Screensaver = 0, - Suspend = 1 - }; - static Inhibitor inbtr_; - - static const char* kGnomeScreensaverService; - static const char* kFreedesktopScreensaverService; - static const char* kGnomePowermanagerService; - static const char* kFreedesktopPowermanagerService; + static Screensaver* GetScreensaver(); private: - static IdleHandler* screensaver_; - static IdleHandler* suspend_; + static Screensaver* screensaver_; }; -#endif // IDLEHANDLER_H +#endif diff --git a/src/ui/settingsdialog.cpp b/src/ui/settingsdialog.cpp index 1ed4c8e13..2cb7e1b7b 100644 --- a/src/ui/settingsdialog.cpp +++ b/src/ui/settingsdialog.cpp @@ -245,8 +245,6 @@ void SettingsDialog::AddPage(Page id, SettingsPage* page, SIGNAL(NotificationPreview(OSD::Behaviour, QString, QString))); connect(page, SIGNAL(SetWiimotedevInterfaceActived(bool)), SIGNAL(SetWiimotedevInterfaceActived(bool))); - connect(page, SIGNAL(InhibitSuspendWhilePlaying(bool)), - SIGNAL(InhibitSuspendWhilePlaying(bool))); // Create the list item QTreeWidgetItem* item = new QTreeWidgetItem; diff --git a/src/ui/settingsdialog.h b/src/ui/settingsdialog.h index 9f97e5b41..14bb9765b 100644 --- a/src/ui/settingsdialog.h +++ b/src/ui/settingsdialog.h @@ -119,7 +119,6 @@ class SettingsDialog : public QDialog { signals: void NotificationPreview(OSD::Behaviour, QString, QString); void SetWiimotedevInterfaceActived(bool); - void InhibitSuspendWhilePlaying(bool); private slots: void CurrentItemChanged(QTreeWidgetItem* item); diff --git a/src/ui/settingspage.h b/src/ui/settingspage.h index 32783d204..99e33014d 100644 --- a/src/ui/settingspage.h +++ b/src/ui/settingspage.h @@ -45,7 +45,6 @@ class SettingsPage : public QWidget { signals: void NotificationPreview(OSD::Behaviour, QString, QString); void SetWiimotedevInterfaceActived(bool); - void InhibitSuspendWhilePlaying(bool); private: SettingsDialog* dialog_; diff --git a/src/ui/windowsidlehandler.cpp b/src/ui/windowsidlehandler.cpp deleted file mode 100644 index f0f95584f..000000000 --- a/src/ui/windowsidlehandler.cpp +++ /dev/null @@ -1,61 +0,0 @@ -/* This file is part of Clementine. - Copyright 2015, John Maguire - Copyright 2015, Arun Narayanankutty - - 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 . -*/ - -#include "windowsidlehandler.h" - -#include "core/logging.h" - -// TODO: use PowerCreateRequest on Win7+ - -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_; -} diff --git a/src/ui/windowsscreensaver.cpp b/src/ui/windowsscreensaver.cpp new file mode 100644 index 000000000..850ba3866 --- /dev/null +++ b/src/ui/windowsscreensaver.cpp @@ -0,0 +1,30 @@ +/* This file is part of Clementine. + Copyright 2015, John Maguire + + 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 . +*/ + +#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_); +} diff --git a/src/ui/windowsidlehandler.h b/src/ui/windowsscreensaver.h similarity index 70% rename from src/ui/windowsidlehandler.h rename to src/ui/windowsscreensaver.h index d7ce8f980..fc3bd8f07 100644 --- a/src/ui/windowsidlehandler.h +++ b/src/ui/windowsscreensaver.h @@ -1,6 +1,5 @@ /* This file is part of Clementine. Copyright 2015, John Maguire - Copyright 2015, Arun Narayanankutty 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,24 +14,22 @@ You should have received a copy of the GNU General Public License along with Clementine. If not, see . */ -#ifndef WINDOWSIDLEHANDLER_H -#define WINDOWSIDLEHANDLER_H +#ifndef WINDOWSSCREENSAVER_H +#define WINDOWSSCREENSAVER_H -#include "idlehandler.h" +#include "screensaver.h" #include -class WindowsIdleHandler : public IdleHandler { +class WindowsScreensaver : public Screensaver { public: - WindowsIdleHandler(); + WindowsScreensaver(); - void Inhibit(const char*) override; + void Inhibit() override; void Uninhibit() override; - bool Isinhibited() override; private: EXECUTION_STATE previous_state_; - bool is_inhibit_; }; -#endif // WINDOWSIDLEHANDLER_H +#endif // WINDOWSSCREENSAVER_H diff --git a/src/visualisations/visualisationcontainer.cpp b/src/visualisations/visualisationcontainer.cpp index 3df111ffd..361ee2007 100644 --- a/src/visualisations/visualisationcontainer.cpp +++ b/src/visualisations/visualisationcontainer.cpp @@ -22,7 +22,7 @@ #include "visualisationselector.h" #include "engines/gstengine.h" #include "ui/iconloader.h" -#include "ui/idlehandler.h" +#include "ui/screensaver.h" #include #include @@ -265,9 +265,9 @@ void VisualisationContainer::keyReleaseEvent(QKeyEvent* event) { void VisualisationContainer::ToggleFullscreen() { setWindowState(windowState() ^ Qt::WindowFullScreen); - IdleHandler* screensaver = IdleHandler::GetScreensaver(); + Screensaver* screensaver = Screensaver::GetScreensaver(); if (screensaver) - isFullScreen() ? screensaver->Inhibit("Visualisation") : screensaver->Uninhibit(); + isFullScreen() ? screensaver->Inhibit() : screensaver->Uninhibit(); } void VisualisationContainer::SetFps(int fps) {