move dbus names to unique namespace -> dbusidlehandler.cc & other minor updates
fix InhibitwhilePlaying signals
This commit is contained in:
parent
b13f0690c8
commit
9f121f4a9d
52
src/ui/dbusidlehandler.cc
Normal file
52
src/ui/dbusidlehandler.cc
Normal file
@ -0,0 +1,52 @@
|
||||
/* 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/>.
|
||||
*/
|
||||
|
||||
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";
|
||||
}
|
@ -34,7 +34,7 @@ void DBusIdleHandler::Inhibit(const char* reason) {
|
||||
QDBusInterface iface(service_, path_,
|
||||
interface_, QDBusConnection::sessionBus());
|
||||
QDBusReply<quint32> 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<bool> reply;
|
||||
if (service_ == IdleHandler::kGnomePowermanagerService) {
|
||||
if (service_ == "org.gnome.SessionManager") {
|
||||
reply = iface.call("IsInhibited", quint32(Inhibit_Suspend));
|
||||
} else {
|
||||
reply = iface.call("HasInhibit");
|
||||
|
@ -20,6 +20,8 @@
|
||||
#include "idlehandler.h"
|
||||
#include "core/logging.h"
|
||||
|
||||
#include "dbusidlehandler.cc"
|
||||
|
||||
#include <QtGlobal>
|
||||
|
||||
#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;
|
||||
|
||||
|
@ -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;
|
||||
|
@ -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_;
|
||||
}
|
||||
|
@ -33,7 +33,7 @@ class MacIdleHandler : public IdleHandler {
|
||||
|
||||
private:
|
||||
IOPMAssertionID assertion_id_;
|
||||
static bool is_inhibit_;
|
||||
bool is_inhibit_;
|
||||
};
|
||||
|
||||
#endif // MACIDLEHANDLER_H
|
||||
|
@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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
|
||||
|
@ -7,7 +7,7 @@
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>596</width>
|
||||
<height>684</height>
|
||||
<height>754</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
@ -70,16 +70,7 @@
|
||||
<item>
|
||||
<widget class="QWidget" name="fading_options" native="true">
|
||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||
<property name="leftMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="topMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="rightMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="bottomMargin">
|
||||
<property name="margin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<item>
|
||||
@ -185,8 +176,11 @@
|
||||
<layout class="QVBoxLayout" name="verticalLayout_4">
|
||||
<item>
|
||||
<widget class="QCheckBox" name="inhibit_suspend_while_playing">
|
||||
<property name="toolTip">
|
||||
<string>If enabled, Clementine will prevent the system from automatically suspending if it is playing a track</string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Inhibit suspend while playing</string>
|
||||
<string>Inhibit automatic suspend if playing</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
@ -212,16 +206,7 @@
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<layout class="QFormLayout" name="formLayout_4">
|
||||
<property name="leftMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="topMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="rightMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="bottomMargin">
|
||||
<property name="margin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<item row="0" column="0">
|
||||
|
@ -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;
|
||||
|
@ -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_) {
|
||||
|
@ -32,7 +32,7 @@ class WindowsIdleHandler : public IdleHandler {
|
||||
|
||||
private:
|
||||
EXECUTION_STATE previous_state_;
|
||||
static bool is_inhibit_;
|
||||
bool is_inhibit_;
|
||||
};
|
||||
|
||||
#endif // WINDOWSIDLEHANDLER_H
|
||||
|
Loading…
x
Reference in New Issue
Block a user