kutils: add kaudioplayer KDED module

the module has some use cases, like avoiding linkage to the
kmediaplayer library which links to MPV, which links to FFmpeg.
and since the module is loaded on demand there should be no change
in terms of resources usage untils it is used, in which case it
will use (roughly) the resources of single MPV instance until
kded4 quits.

Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
This commit is contained in:
Ivailo Monev 2016-09-22 02:55:31 +00:00
parent 0c12ff6ce8
commit a622ec8ea3
5 changed files with 123 additions and 0 deletions

View file

@ -43,6 +43,8 @@ install(
${INSTALL_TARGETS_DEFAULT_ARGS}
)
add_subdirectory(kded)
if(ENABLE_TESTING)
add_subdirectory(tests)
endif()

View file

@ -0,0 +1,28 @@
########### next target ###############
set(kded_kaudioplayer_SRCS
kaudioplayer.cpp
${CMAKE_CURRENT_BINARY_DIR}/org.kde.kaudioplayer.xml
)
qt4_generate_dbus_interface(kaudioplayer.h org.kde.kaudioplayer.xml )
kde4_add_plugin(kded_kaudioplayer ${kded_kaudioplayer_SRCS})
target_link_libraries(kded_kaudioplayer ${KDE4_KMEDIAPLAYER_LIBS})
install(
TARGETS kded_kaudioplayer
DESTINATION ${PLUGIN_INSTALL_DIR}
)
install(
FILES kaudioplayer.desktop
DESTINATION ${SERVICES_INSTALL_DIR}/kded
)
install(
FILES ${CMAKE_CURRENT_BINARY_DIR}/org.kde.kaudioplayer.xml
DESTINATION ${DBUS_INTERFACES_INSTALL_DIR}
)

View file

@ -0,0 +1,44 @@
/* This file is part of the KDE libraries
Copyright (C) 2016 Ivailo Monev <xakepa10@gmail.com>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License version 2, as published by the Free Software Foundation.
This library 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
Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#include "kaudioplayer.h"
#include "kpluginfactory.h"
K_PLUGIN_FACTORY(KAudioPlayerModuleFactory, registerPlugin<KAudioPlayerModule>();)
K_EXPORT_PLUGIN(KAudioPlayerModuleFactory("kaudioplayer"))
KAudioPlayerModule::KAudioPlayerModule(QObject *parent, const QList<QVariant>&)
: KDEDModule(parent)
{
}
void KAudioPlayerModule::play(const QString &path)
{
KAudioPlayer* newplayer = new KAudioPlayer(this);
connect(newplayer, SIGNAL(finished()), this, SLOT(_removeFinished()));
newplayer->load(path);
}
void KAudioPlayerModule::_removeFinished()
{
KAudioPlayer* player = qobject_cast<KAudioPlayer*>(sender());
disconnect(player, SIGNAL(finished()), player, SLOT(deleteLater()));
player->deleteLater();
}
#include "moc_kaudioplayer.cpp"

View file

@ -0,0 +1,10 @@
[Desktop Entry]
Name=Audio player
Comment=Audio player service
Type=Service
X-KDE-ServiceTypes=KDEDModule
X-KDE-Library=kaudioplayer
X-KDE-DBus-ModuleName=kaudioplayer
X-KDE-Kded-autoload=false
X-KDE-Kded-load-on-demand=true
OnlyShowIn=KDE;

View file

@ -0,0 +1,39 @@
/* This file is part of the KDE libraries
Copyright (C) 2016 Ivailo Monev <xakepa10@gmail.com>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License version 2, as published by the Free Software Foundation.
This library 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
Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#ifndef KAUDIOPLAYER_KDED_H
#define KAUDIOPLAYER_KDED_H
#include "kdedmodule.h"
#include "kmediaplayer.h"
class KAudioPlayerModule: public KDEDModule
{
Q_OBJECT
Q_CLASSINFO("D-Bus Interface", "org.kde.kaudioplayer")
public:
KAudioPlayerModule(QObject *parent, const QList<QVariant>&);
public Q_SLOTS:
Q_SCRIPTABLE void play(const QString &path);
private Q_SLOTS:
void _removeFinished();
};
#endif // KAUDIOPLAYER_KDED_H