diff options
| author | trialuser02 <trialuser02@90c681e8-e032-0410-971d-27865f9a5e38> | 2019-11-30 14:00:51 +0000 |
|---|---|---|
| committer | trialuser02 <trialuser02@90c681e8-e032-0410-971d-27865f9a5e38> | 2019-11-30 14:00:51 +0000 |
| commit | f5761dff49b1b10de89de2de9516a3b4c8ace044 (patch) | |
| tree | 01b165ba297d29f71f9874c65ac4072feed61141 /src/plugins/General | |
| parent | 4a09d498cd18c91074703d9af3823965b2add659 (diff) | |
| download | qmmp-f5761dff49b1b10de89de2de9516a3b4c8ace044.tar.gz qmmp-f5761dff49b1b10de89de2de9516a3b4c8ace044.tar.bz2 qmmp-f5761dff49b1b10de89de2de9516a3b4c8ace044.zip | |
added sleep mode inhibition plugin
git-svn-id: http://svn.code.sf.net/p/qmmp-dev/code/trunk/qmmp@9118 90c681e8-e032-0410-971d-27865f9a5e38
Diffstat (limited to 'src/plugins/General')
6 files changed, 241 insertions, 1 deletions
diff --git a/src/plugins/General/General.pro b/src/plugins/General/General.pro index 630434dff..1f4290b30 100644 --- a/src/plugins/General/General.pro +++ b/src/plugins/General/General.pro @@ -16,7 +16,8 @@ SUBDIRS += statusicon \ unix:SUBDIRS += mpris \ kdenotify \ converter \ - gnomehotkey + gnomehotkey \ + sleepinhibitor contains(CONFIG, UDISKS2_PLUGIN){ unix:SUBDIRS += udisks2 diff --git a/src/plugins/General/sleepinhibitor/sleepinhibitor.cpp b/src/plugins/General/sleepinhibitor/sleepinhibitor.cpp new file mode 100644 index 000000000..7e28e7d7d --- /dev/null +++ b/src/plugins/General/sleepinhibitor/sleepinhibitor.cpp @@ -0,0 +1,63 @@ +/*************************************************************************** + * Copyright (C) 2019 by Ilya Kotov * + * forkotov02@ya.ru * + * * + * This program 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 2 of the License, or * + * (at your option) any later version. * + * * + * This program 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 this program; if not, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * + ***************************************************************************/ + +#include <QDBusInterface> +#include <QDBusConnection> +#include <QDBusReply> +#include <qmmp/soundcore.h> +#include "sleepinhibitor.h" + +SleepInhibitor::SleepInhibitor(QObject *parent) : QObject(parent) +{ + m_interface = new QDBusInterface(QLatin1String("org.freedesktop.login1"), + QLatin1String("/org/freedesktop/login1"), + QLatin1String("org.freedesktop.login1.Manager"), + QDBusConnection::systemBus(), this); + connect(SoundCore::instance(), SIGNAL(stateChanged(Qmmp::State)), SLOT(onStateChanged(Qmmp::State))); +} + +SleepInhibitor::~SleepInhibitor() +{} + +void SleepInhibitor::onStateChanged(Qmmp::State state) +{ + if(state == Qmmp::Playing) + inhibit(); + else if(state == Qmmp::Stopped) + uninhibit(); +} + +void SleepInhibitor::inhibit() +{ + if(m_lock) + return; + + static const QString what = QStringLiteral("sleep:idle"); + static const QString who = QStringLiteral("fly-music"); + static const QString why = QStringLiteral("Playing audio"); + static const QString mode = QStringLiteral("block"); + QDBusReply<QDBusUnixFileDescriptor> fd = m_interface->call(QStringLiteral("Inhibit"), what, who, why, mode); + m_lock.reset(new QDBusUnixFileDescriptor(fd)); +} + +void SleepInhibitor::uninhibit() +{ + m_lock.reset(nullptr); +} diff --git a/src/plugins/General/sleepinhibitor/sleepinhibitor.h b/src/plugins/General/sleepinhibitor/sleepinhibitor.h new file mode 100644 index 000000000..7d8fa0907 --- /dev/null +++ b/src/plugins/General/sleepinhibitor/sleepinhibitor.h @@ -0,0 +1,51 @@ +/*************************************************************************** + * Copyright (C) 2019 by Ilya Kotov * + * forkotov02@ya.ru * + * * + * This program 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 2 of the License, or * + * (at your option) any later version. * + * * + * This program 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 this program; if not, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * + ***************************************************************************/ +#ifndef SLEEPINHIBITOR_H +#define SLEEPINHIBITOR_H + +#include <memory> +#include <QDBusUnixFileDescriptor> +#include <qmmp/qmmp.h> + +class QDBusInterface; + +/** + @author Ilya Kotov <forkotov02@ya.ru> +*/ +class SleepInhibitor : public QObject +{ + Q_OBJECT +public: + SleepInhibitor(QObject *parent = nullptr); + + ~SleepInhibitor(); + +private slots: + void onStateChanged(Qmmp::State state); + +private: + void inhibit(); + void uninhibit(); + + QDBusInterface *m_interface; + std::unique_ptr<QDBusUnixFileDescriptor> m_lock; +}; + +#endif diff --git a/src/plugins/General/sleepinhibitor/sleepinhibitor.pro b/src/plugins/General/sleepinhibitor/sleepinhibitor.pro new file mode 100644 index 000000000..9d292044d --- /dev/null +++ b/src/plugins/General/sleepinhibitor/sleepinhibitor.pro @@ -0,0 +1,22 @@ +include(../../plugins.pri) + +TARGET =$$PLUGINS_PREFIX/General/sleepinhibitor + +QT += dbus + +TEMPLATE = lib +LIBS += $${QMMPUI_LIB} + + +HEADERS += sleepinhibitorfactory.h \ + sleepinhibitor.h + +SOURCES += sleepinhibitorfactory.cpp \ + sleepinhibitor.cpp + +#RESOURCES = translations/translations.qrc + +unix { + target.path = $$PLUGIN_DIR/General + INSTALLS += target +} diff --git a/src/plugins/General/sleepinhibitor/sleepinhibitorfactory.cpp b/src/plugins/General/sleepinhibitor/sleepinhibitorfactory.cpp new file mode 100644 index 000000000..2b7d3b707 --- /dev/null +++ b/src/plugins/General/sleepinhibitor/sleepinhibitorfactory.cpp @@ -0,0 +1,59 @@ +/*************************************************************************** + * Copyright (C) 2019 by Ilya Kotov * + * forkotov02@ya.ru * + * * + * This program 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 2 of the License, or * + * (at your option) any later version. * + * * + * This program 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 this program; if not, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * + ***************************************************************************/ + + +#include <QMessageBox> +#include "sleepinhibitor.h" +#include "sleepinhibitorfactory.h" + +GeneralProperties SleepInhibitFactory::properties() const +{ + GeneralProperties properties; + properties.name = tr("Sleep Mode Inhibition Plugin"); + properties.shortName = "sleepinhibitor"; + properties.hasAbout = true; + properties.hasSettings = false; + properties.visibilityControl = false; + return properties; +} + +QObject *SleepInhibitFactory::create(QObject *parent) +{ + return new SleepInhibitor(parent); +} + +QDialog *SleepInhibitFactory::createConfigDialog(QWidget *parent) +{ + Q_UNUSED(parent); + return nullptr; +} + +void SleepInhibitFactory::showAbout(QWidget *parent) +{ + QMessageBox::about(parent, tr("About Sleep Mode Inhibit Plugin"), + tr("Qmmp Sleep Mode Inhibit Plugin")+"\n"+ + tr("This plugin inhibits sleep mode while audio playback") + "\n" + + tr("Written by: Ilya Kotov <forkotov02@ya.ru>")); +} + +QString SleepInhibitFactory::translation() const +{ + return QLatin1String(":/sleepinhibitor_plugin_"); +} diff --git a/src/plugins/General/sleepinhibitor/sleepinhibitorfactory.h b/src/plugins/General/sleepinhibitor/sleepinhibitorfactory.h new file mode 100644 index 000000000..7e0701254 --- /dev/null +++ b/src/plugins/General/sleepinhibitor/sleepinhibitorfactory.h @@ -0,0 +1,44 @@ +/*************************************************************************** + * Copyright (C) 2019 by Ilya Kotov * + * forkotov02@ya.ru * + * * + * This program 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 2 of the License, or * + * (at your option) any later version. * + * * + * This program 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 this program; if not, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * + ***************************************************************************/ +#ifndef SLEEPINHIBITORFACTORY_H +#define SLEEPINHIBITORFACTORY_H + +/** + @author Ilya Kotov <forkotov02@ya.ru> +*/ +#include <QObject> +#include <QDialog> +#include <qmmpui/general.h> +#include <qmmpui/generalfactory.h> + +class SleepInhibitFactory : public QObject, public GeneralFactory +{ +Q_OBJECT +Q_PLUGIN_METADATA(IID "org.qmmp.qmmpui.GeneralFactoryInterface.1.0") +Q_INTERFACES(GeneralFactory) +public: + GeneralProperties properties() const override; + QObject *create(QObject *parent) override; + QDialog *createConfigDialog(QWidget *parent) override; + void showAbout(QWidget *parent) override; + QString translation() const override; +}; + +#endif |
