From 9f121f4a9d34820280ca11f4131a7e9fb9099f3f Mon Sep 17 00:00:00 2001 From: narunlifescience Date: Thu, 10 Dec 2015 07:15:30 -0600 Subject: [PATCH] move dbus names to unique namespace -> dbusidlehandler.cc & other minor updates fix InhibitwhilePlaying signals --- src/ui/dbusidlehandler.cc | 52 ++++++++++++++++++++++++++++++++++ src/ui/dbusidlehandler.cpp | 6 ++-- src/ui/idlehandler.cpp | 30 ++------------------ src/ui/idlehandler.h | 16 ----------- src/ui/macidlehandler.cpp | 9 ++---- src/ui/macidlehandler.h | 2 +- src/ui/mainwindow.cpp | 30 ++++++++++++-------- src/ui/mainwindow.h | 3 +- src/ui/playbacksettingspage.ui | 29 +++++-------------- src/ui/settingsdialog.cpp | 2 ++ src/ui/windowsidlehandler.cpp | 7 ++--- src/ui/windowsidlehandler.h | 2 +- 12 files changed, 93 insertions(+), 95 deletions(-) create mode 100644 src/ui/dbusidlehandler.cc diff --git a/src/ui/dbusidlehandler.cc b/src/ui/dbusidlehandler.cc new file mode 100644 index 000000000..400427e49 --- /dev/null +++ b/src/ui/dbusidlehandler.cc @@ -0,0 +1,52 @@ +/* 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 . +*/ + +namespace { + + // Gnome screensaver + const char* kGnomeScreensaverService + = "org.gnome.ScreenSaver"; + const char* kGnomeScreensaverPath + = "/"; + const char* kGnomeScreensaverInterface + = "org.gnome.ScreenSaver"; + + // Freedesktop screensaver + const char* kFreedesktopScreensaverService + = "org.freedesktop.ScreenSaver"; + const char* kFreedesktopScreensaverPath + = "/ScreenSaver"; + const char* kFreedesktopScreensaverInterface + = "org.freedesktop.ScreenSaver"; + + // Gnome powermanager + const char* kGnomePowermanagerService + = "org.gnome.SessionManager"; + const char* kGnomePowermanagerPath + = "/org/gnome/SessionManager"; + const char* kGnomePowermanagerInterface + = "org.gnome.SessionManager"; + + // Freedesktop powermanager + const char* kFreedesktopPowermanagerService + = "org.freedesktop.PowerManagement"; + const char* kFreedesktopPowermanagerPath + = "/org/freedesktop/PowerManagement/Inhibit"; + const char* kFreedesktopPowermanagerInterface + = "org.freedesktop.PowerManagement.Inhibit"; +} diff --git a/src/ui/dbusidlehandler.cpp b/src/ui/dbusidlehandler.cpp index 45412f1ac..080419ece 100644 --- a/src/ui/dbusidlehandler.cpp +++ b/src/ui/dbusidlehandler.cpp @@ -34,7 +34,7 @@ void DBusIdleHandler::Inhibit(const char* reason) { QDBusInterface iface(service_, path_, interface_, QDBusConnection::sessionBus()); QDBusReply reply; - if (service_ == IdleHandler::kGnomePowermanagerService) { + if (service_ == "org.gnome.SessionManager") { reply = iface.call("Inhibit", QCoreApplication::applicationName(), quint32(0), QObject::tr(reason), @@ -57,7 +57,7 @@ void DBusIdleHandler::Inhibit(const char* reason) { void DBusIdleHandler::Uninhibit() { QDBusInterface iface(service_, path_, interface_, QDBusConnection::sessionBus()); - if (service_ == IdleHandler::kGnomePowermanagerService) { + if (service_ == "org.gnome.SessionManager") { iface.call("Uninhibit", cookie_); } else { iface.call("UnInhibit", cookie_); @@ -68,7 +68,7 @@ bool DBusIdleHandler::Isinhibited() { QDBusInterface iface(service_, path_, interface_, QDBusConnection::sessionBus()); QDBusReply reply; - if (service_ == IdleHandler::kGnomePowermanagerService) { + if (service_ == "org.gnome.SessionManager") { reply = iface.call("IsInhibited", quint32(Inhibit_Suspend)); } else { reply = iface.call("HasInhibit"); diff --git a/src/ui/idlehandler.cpp b/src/ui/idlehandler.cpp index fc803d177..35d8317e5 100644 --- a/src/ui/idlehandler.cpp +++ b/src/ui/idlehandler.cpp @@ -20,6 +20,8 @@ #include "idlehandler.h" #include "core/logging.h" +#include "dbusidlehandler.cc" + #include #ifdef HAVE_DBUS @@ -36,34 +38,6 @@ #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; diff --git a/src/ui/idlehandler.h b/src/ui/idlehandler.h index c08df2a8c..77442d9e9 100644 --- a/src/ui/idlehandler.h +++ b/src/ui/idlehandler.h @@ -23,22 +23,6 @@ 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; diff --git a/src/ui/macidlehandler.cpp b/src/ui/macidlehandler.cpp index 8b4ffeb33..8e313abc7 100644 --- a/src/ui/macidlehandler.cpp +++ b/src/ui/macidlehandler.cpp @@ -25,11 +25,8 @@ #include "core/logging.h" #include "core/utilities.h" -bool MacIdleHandler::is_inhibit_; - -MacIdleHandler::MacIdleHandler() : assertion_id_(0) { - is_inhibit_ = false; -} +MacIdleHandler::MacIdleHandler() : assertion_id_(0), + is_inhibit_(false) {} void MacIdleHandler::Inhibit(const char* reason) { IOReturn reply = IOPMAssertionCreateWithName( @@ -53,6 +50,6 @@ void MacIdleHandler::Uninhibit() { } } -bool WindowsIdleHandler::Isinhibited() { +bool MacIdleHandler::Isinhibited() { return is_inhibit_; } diff --git a/src/ui/macidlehandler.h b/src/ui/macidlehandler.h index 06d0b0474..d1e73a28b 100644 --- a/src/ui/macidlehandler.h +++ b/src/ui/macidlehandler.h @@ -33,7 +33,7 @@ class MacIdleHandler : public IdleHandler { private: IOPMAssertionID assertion_id_; - static bool is_inhibit_; + bool is_inhibit_; }; #endif // MACIDLEHANDLER_H diff --git a/src/ui/mainwindow.cpp b/src/ui/mainwindow.cpp index 8e2b9a14a..a0e7d1ba2 100644 --- a/src/ui/mainwindow.cpp +++ b/src/ui/mainwindow.cpp @@ -197,7 +197,7 @@ MainWindow::MainWindow(Application* app, SystemTrayIcon* tray_icon, OSD* osd, doubleclick_playmode_(PlayBehaviour_IfStopped), menu_playmode_(PlayBehaviour_IfStopped), idlehandler_(IdleHandler::GetSuspend()), - is_suspend_inhibited(false) { + is_suspend_inhibited_(false) { qLog(Debug) << "Starting"; connect(app, SIGNAL(ErrorAdded(QString)), SLOT(ShowErrorDialog(QString))); @@ -977,6 +977,12 @@ 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(); @@ -1009,11 +1015,6 @@ 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() { @@ -2427,10 +2428,10 @@ void MainWindow::EnsureSettingsDialogCreated() { SLOT(SetWiimotedevInterfaceActived(bool))); #endif - // Handle Suspend ststus + // Handle suspend status connect(settings_dialog_.get(), SIGNAL(InhibitSuspendWhilePlaying(bool)), - SLOT(HandleInhibitSuspendWhilePlaying(bool))); + SLOT(InhibitSuspendWhilePlaying(bool))); // Allows custom notification preview connect(settings_dialog_.get(), @@ -2808,15 +2809,20 @@ void MainWindow::keyPressEvent(QKeyEvent* 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) { + !is_suspend_inhibited_ && status) { idlehandler_->Inhibit("Clementine is playing"); - is_suspend_inhibited = idlehandler_->Isinhibited(); - } else if (is_suspend_inhibited && !status){ + is_suspend_inhibited_ = idlehandler_->Isinhibited(); + } else if (is_suspend_inhibited_ && !status){ idlehandler_->Uninhibit(); - is_suspend_inhibited = idlehandler_->Isinhibited(); + is_suspend_inhibited_ = idlehandler_->Isinhibited(); } } } diff --git a/src/ui/mainwindow.h b/src/ui/mainwindow.h index 42cf7e201..2abacf456 100644 --- a/src/ui/mainwindow.h +++ b/src/ui/mainwindow.h @@ -280,6 +280,7 @@ signals: void ShowConsole(); + void InhibitSuspendWhilePlaying(bool status); void HandleInhibitSuspendWhilePlaying(bool status); private: @@ -379,7 +380,7 @@ signals: BackgroundStreams* background_streams_; IdleHandler* idlehandler_; bool inhibit_suspend_while_playing_status_; - bool is_suspend_inhibited; + bool is_suspend_inhibited_; }; #endif // MAINWINDOW_H diff --git a/src/ui/playbacksettingspage.ui b/src/ui/playbacksettingspage.ui index e2ebe07b5..a6174cb07 100644 --- a/src/ui/playbacksettingspage.ui +++ b/src/ui/playbacksettingspage.ui @@ -7,7 +7,7 @@ 0 0 596 - 684 + 754 @@ -70,16 +70,7 @@ - - 0 - - - 0 - - - 0 - - + 0 @@ -185,8 +176,11 @@ + + If enabled, Clementine will prevent the system from automatically suspending if it is playing a track + - Inhibit suspend while playing + Inhibit automatic suspend if playing @@ -212,16 +206,7 @@ false - - 0 - - - 0 - - - 0 - - + 0 diff --git a/src/ui/settingsdialog.cpp b/src/ui/settingsdialog.cpp index 2cb7e1b7b..1ed4c8e13 100644 --- a/src/ui/settingsdialog.cpp +++ b/src/ui/settingsdialog.cpp @@ -245,6 +245,8 @@ 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/windowsidlehandler.cpp b/src/ui/windowsidlehandler.cpp index 26f303828..f0f95584f 100644 --- a/src/ui/windowsidlehandler.cpp +++ b/src/ui/windowsidlehandler.cpp @@ -22,11 +22,8 @@ // TODO: use PowerCreateRequest on Win7+ -bool WindowsIdleHandler::is_inhibit_; - -WindowsIdleHandler::WindowsIdleHandler() : previous_state_(0) { - is_inhibit_ = false; -} +WindowsIdleHandler::WindowsIdleHandler() : previous_state_(0), + is_inhibit_(false) {} void WindowsIdleHandler::Inhibit(const char*) { switch (IdleHandler::inbtr_) { diff --git a/src/ui/windowsidlehandler.h b/src/ui/windowsidlehandler.h index 78a0fe46d..d7ce8f980 100644 --- a/src/ui/windowsidlehandler.h +++ b/src/ui/windowsidlehandler.h @@ -32,7 +32,7 @@ class WindowsIdleHandler : public IdleHandler { private: EXECUTION_STATE previous_state_; - static bool is_inhibit_; + bool is_inhibit_; }; #endif // WINDOWSIDLEHANDLER_H