mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-08-06 14:16:32 +02:00
Add systemd suspend support
This commit is contained in:
@@ -47,10 +47,13 @@ option(WITH_BINARY_ATTICA "Enable support for downloading binary resolvers autom
|
|||||||
option(LEGACY_KDE_INTEGRATION "Install tomahawk.protocol file, deprecated since 4.6.0" OFF)
|
option(LEGACY_KDE_INTEGRATION "Install tomahawk.protocol file, deprecated since 4.6.0" OFF)
|
||||||
option(WITH_KDE4 "Build with support for KDE specific stuff" ON)
|
option(WITH_KDE4 "Build with support for KDE specific stuff" ON)
|
||||||
|
|
||||||
|
find_package(QtSystemd QUIET)
|
||||||
CMAKE_DEPENDENT_OPTION(WITH_UPOWER "Build with support for UPower events" ON
|
CMAKE_DEPENDENT_OPTION(WITH_UPOWER "Build with support for UPower events" ON
|
||||||
"UNIX;NOT APPLE" OFF)
|
"UNIX;NOT APPLE" OFF)
|
||||||
CMAKE_DEPENDENT_OPTION(WITH_GNOMESHORTCUTHANDLER "Build with shortcut handler for GNOME" ON
|
CMAKE_DEPENDENT_OPTION(WITH_GNOMESHORTCUTHANDLER "Build with shortcut handler for GNOME" ON
|
||||||
"UNIX;NOT APPLE" OFF)
|
"UNIX;NOT APPLE" OFF)
|
||||||
|
CMAKE_DEPENDENT_OPTION(WITH_SYSTEMD "Build with support for systemd events" ON
|
||||||
|
"QtSystemd_FOUND" OFF)
|
||||||
|
|
||||||
IF( CMAKE_SYSTEM_PROCESSOR MATCHES "arm" )
|
IF( CMAKE_SYSTEM_PROCESSOR MATCHES "arm" )
|
||||||
message(STATUS "Build of breakpad library disabled on this platform.")
|
message(STATUS "Build of breakpad library disabled on this platform.")
|
||||||
|
@@ -15,6 +15,10 @@ IF( WITH_GNOMESHORTCUTHANDLER )
|
|||||||
SET( tomahawkSources ${tomahawkSources} linux/GnomeShortcutHandler.cpp )
|
SET( tomahawkSources ${tomahawkSources} linux/GnomeShortcutHandler.cpp )
|
||||||
ENDIF( WITH_GNOMESHORTCUTHANDLER )
|
ENDIF( WITH_GNOMESHORTCUTHANDLER )
|
||||||
|
|
||||||
|
IF( WITH_SYSTEMD )
|
||||||
|
SET( tomahawkSources ${tomahawkSources} linux/SystemdHandler.cpp )
|
||||||
|
ENDIF( WITH_SYSTEMD )
|
||||||
|
|
||||||
INSTALL( FILES ${CMAKE_SOURCE_DIR}/data/icons/tomahawk-icon.svg RENAME tomahawk.svg DESTINATION ${CMAKE_INSTALL_DATADIR}/icons/hicolor/scalable/apps )
|
INSTALL( FILES ${CMAKE_SOURCE_DIR}/data/icons/tomahawk-icon.svg RENAME tomahawk.svg DESTINATION ${CMAKE_INSTALL_DATADIR}/icons/hicolor/scalable/apps )
|
||||||
|
|
||||||
INSTALL( FILES ${CMAKE_SOURCE_DIR}/admin/unix/tomahawk.desktop DESTINATION ${CMAKE_INSTALL_DATADIR}/applications )
|
INSTALL( FILES ${CMAKE_SOURCE_DIR}/admin/unix/tomahawk.desktop DESTINATION ${CMAKE_INSTALL_DATADIR}/applications )
|
||||||
|
@@ -185,6 +185,7 @@ TARGET_LINK_LIBRARIES( tomahawk_bin
|
|||||||
${ECHONEST_LIBRARIES}
|
${ECHONEST_LIBRARIES}
|
||||||
${QJSON_LIBRARIES}
|
${QJSON_LIBRARIES}
|
||||||
${TAGLIB_LIBRARIES}
|
${TAGLIB_LIBRARIES}
|
||||||
|
${QTSYSTEMD_LIBRARIES}
|
||||||
)
|
)
|
||||||
|
|
||||||
IF( APPLE )
|
IF( APPLE )
|
||||||
|
@@ -18,6 +18,7 @@
|
|||||||
#cmakedefine WITH_QtSparkle
|
#cmakedefine WITH_QtSparkle
|
||||||
#cmakedefine WITH_UPOWER
|
#cmakedefine WITH_UPOWER
|
||||||
#cmakedefine WITH_GNOMESHORTCUTHANDLER
|
#cmakedefine WITH_GNOMESHORTCUTHANDLER
|
||||||
|
#cmakedefine WITH_SYSTEMD
|
||||||
|
|
||||||
#cmakedefine LIBLASTFM_FOUND
|
#cmakedefine LIBLASTFM_FOUND
|
||||||
#cmakedefine QCA2_FOUND
|
#cmakedefine QCA2_FOUND
|
||||||
|
@@ -92,6 +92,10 @@
|
|||||||
#include "linux/GnomeShortcutHandler.h"
|
#include "linux/GnomeShortcutHandler.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef WITH_SYSTEMD
|
||||||
|
#include "linux/SystemdHandler.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifndef ENABLE_HEADLESS
|
#ifndef ENABLE_HEADLESS
|
||||||
#include <QMessageBox>
|
#include <QMessageBox>
|
||||||
#endif
|
#endif
|
||||||
@@ -568,6 +572,10 @@ TomahawkApp::initEnergyEventHandler()
|
|||||||
UPowerHandler* upower = new UPowerHandler( this );
|
UPowerHandler* upower = new UPowerHandler( this );
|
||||||
upower->registerHandler();
|
upower->registerHandler();
|
||||||
#endif // WITH_UPOWER
|
#endif // WITH_UPOWER
|
||||||
|
|
||||||
|
#ifdef WITH_SYSTEMD
|
||||||
|
new SystemdHandler( this );
|
||||||
|
#endif // WITH_SYSTEMD
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
66
src/tomahawk/linux/SystemdHandler.cpp
Normal file
66
src/tomahawk/linux/SystemdHandler.cpp
Normal file
@@ -0,0 +1,66 @@
|
|||||||
|
/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
|
||||||
|
*
|
||||||
|
* Copyright 2013, Uwe L. Korn <uwelk@xhochy.com>
|
||||||
|
*
|
||||||
|
* Tomahawk 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.
|
||||||
|
*
|
||||||
|
* Tomahawk 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 Tomahawk. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "SystemdHandler.h"
|
||||||
|
|
||||||
|
#include "accounts/AccountManager.h"
|
||||||
|
#include "utils/Logger.h"
|
||||||
|
|
||||||
|
#include <QTimer>
|
||||||
|
#include <QtSystemd/ldmanager.h>
|
||||||
|
|
||||||
|
#define SYSTEMD_RESUME_DELAY 2000
|
||||||
|
|
||||||
|
namespace Tomahawk {
|
||||||
|
|
||||||
|
SystemdHandler::SystemdHandler(QObject *parent) :
|
||||||
|
QObject(parent)
|
||||||
|
{
|
||||||
|
connect( Systemd::Logind::notifier(), SIGNAL( prepareForSleep( bool ) ),
|
||||||
|
SLOT( handleSleep( bool ) ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
SystemdHandler::handleSleep( bool active )
|
||||||
|
{
|
||||||
|
if ( active )
|
||||||
|
{
|
||||||
|
QMutexLocker locker( &m_mutex );
|
||||||
|
tLog( LOGVERBOSE ) << Q_FUNC_INFO << "About to sleep so disconnecting all accounts";
|
||||||
|
Tomahawk::Accounts::AccountManager::instance()->disconnectAll();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
m_mutex.lock();
|
||||||
|
// Delay resuming for other wakeup actions, e.g. reconnecting to the network, to take place.
|
||||||
|
QTimer::singleShot( SYSTEMD_RESUME_DELAY, this, SLOT( actualResume() ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
SystemdHandler::actualResume()
|
||||||
|
{
|
||||||
|
tLog( LOGVERBOSE ) << Q_FUNC_INFO << "Awake from sleep so connecting all accounts";
|
||||||
|
Tomahawk::Accounts::AccountManager::instance()->connectAll();
|
||||||
|
m_mutex.unlock();
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace Tomahawk
|
44
src/tomahawk/linux/SystemdHandler.h
Normal file
44
src/tomahawk/linux/SystemdHandler.h
Normal file
@@ -0,0 +1,44 @@
|
|||||||
|
/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
|
||||||
|
*
|
||||||
|
* Copyright 2013, Uwe L. Korn <uwelk@xhochy.com>
|
||||||
|
*
|
||||||
|
* Tomahawk 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.
|
||||||
|
*
|
||||||
|
* Tomahawk 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 Tomahawk. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef TOMAHAWK_SYSTEMDHANDLER_H
|
||||||
|
#define TOMAHAWK_SYSTEMDHANDLER_H
|
||||||
|
|
||||||
|
#include <QMutex>
|
||||||
|
#include <QObject>
|
||||||
|
|
||||||
|
namespace Tomahawk {
|
||||||
|
|
||||||
|
class SystemdHandler : public QObject
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
public:
|
||||||
|
explicit SystemdHandler(QObject *parent = 0);
|
||||||
|
|
||||||
|
private slots:
|
||||||
|
void handleSleep( bool active );
|
||||||
|
void actualResume();
|
||||||
|
|
||||||
|
private:
|
||||||
|
QMutex m_mutex;
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace Tomahawk
|
||||||
|
|
||||||
|
#endif // TOMAHAWK_SYSTEMDHANDLER_H
|
Reference in New Issue
Block a user