Commit 14d486fd authored by Matthieu Gallien's avatar Matthieu Gallien 🎵
Browse files

implement interface of Baloo to watch renamed files

parent e49e6f46
......@@ -16,6 +16,10 @@ set(playListTest_SOURCES
if (KF5Baloo_FOUND)
if (Qt5DBus_FOUND)
qt5_add_dbus_adaptor(playListTest_SOURCES
${CMAKE_INSTALL_PREFIX}/${KDE_INSTALL_DBUSINTERFACEDIR}/org.kde.BalooWatcherApplication.xml
baloo/localbaloofilelisting.h LocalBalooFileListing)
set(playListTest_SOURCES
${playListTest_SOURCES}
../src/baloo/baloolistener.cpp
......@@ -89,6 +93,10 @@ set(playListControlerTest_SOURCES
if (KF5Baloo_FOUND)
if (Qt5DBus_FOUND)
qt5_add_dbus_adaptor(playListControlerTest_SOURCES
${CMAKE_INSTALL_PREFIX}/${KDE_INSTALL_DBUSINTERFACEDIR}/org.kde.BalooWatcherApplication.xml
baloo/localbaloofilelisting.h LocalBalooFileListing)
set(playListControlerTest_SOURCES
${playListControlerTest_SOURCES}
../src/baloo/baloolistener.cpp
......@@ -150,6 +158,10 @@ set(managemediaplayercontrolTest_SOURCES
if (KF5Baloo_FOUND)
if (Qt5DBus_FOUND)
qt5_add_dbus_adaptor(managemediaplayercontrolTest_SOURCES
${CMAKE_INSTALL_PREFIX}/${KDE_INSTALL_DBUSINTERFACEDIR}/org.kde.BalooWatcherApplication.xml
baloo/localbaloofilelisting.h LocalBalooFileListing)
set(managemediaplayercontrolTest_SOURCES
${managemediaplayercontrolTest_SOURCES}
../src/baloo/baloolistener.cpp
......@@ -212,6 +224,10 @@ set(manageheaderbarTest_SOURCES
if (KF5Baloo_FOUND)
if (Qt5DBus_FOUND)
qt5_add_dbus_adaptor(manageheaderbarTest_SOURCES
${CMAKE_INSTALL_PREFIX}/${KDE_INSTALL_DBUSINTERFACEDIR}/org.kde.BalooWatcherApplication.xml
baloo/localbaloofilelisting.h LocalBalooFileListing)
set(manageheaderbarTest_SOURCES
${manageheaderbarTest_SOURCES}
../src/baloo/baloolistener.cpp
......@@ -282,6 +298,10 @@ set(mediaplaylistTest_SOURCES
if (KF5Baloo_FOUND)
if (Qt5DBus_FOUND)
qt5_add_dbus_adaptor(mediaplaylistTest_SOURCES
${CMAKE_INSTALL_PREFIX}/${KDE_INSTALL_DBUSINTERFACEDIR}/org.kde.BalooWatcherApplication.xml
baloo/localbaloofilelisting.h LocalBalooFileListing)
set(mediaplaylistTest_SOURCES
${mediaplaylistTest_SOURCES}
../src/baloo/baloolistener.cpp
......
......@@ -63,6 +63,10 @@ if (Qt5Quick_FOUND AND Qt5Widgets_FOUND)
baloo/localbaloofilelisting.cpp
baloo/baloolistener.cpp
)
qt5_add_dbus_adaptor(elisa_SOURCES
${CMAKE_INSTALL_PREFIX}/${KDE_INSTALL_DBUSINTERFACEDIR}/org.kde.BalooWatcherApplication.xml
baloo/localbaloofilelisting.h LocalBalooFileListing)
endif()
endif()
......
......@@ -30,7 +30,8 @@ public:
};
BalooListener::BalooListener(QObject *parent) : AbstractFileListener(new LocalBalooFileListing, parent), d(new BalooListenerPrivate)
BalooListener::BalooListener(QObject *parent)
: AbstractFileListener(new LocalBalooFileListing, parent), d(new BalooListenerPrivate)
{
}
......
......@@ -21,6 +21,8 @@
#include "musicaudiotrack.h"
#include "baloowatcherapplicationadaptor.h"
#include <Baloo/Query>
#include <Baloo/File>
......@@ -29,6 +31,7 @@
#include <QDBusConnection>
#include <QDBusMessage>
#include <QDBusServiceWatcher>
#include <QThread>
#include <QHash>
......@@ -55,12 +58,40 @@ public:
QAtomicInt mStopRequest = 0;
BalooWatcherApplicationAdaptor *mDbusAdaptor = nullptr;
QDBusServiceWatcher mServiceWatcher;
bool mIsRegistered = false;
bool mIsRegistering = false;
};
LocalBalooFileListing::LocalBalooFileListing(QObject *parent) : AbstractFileListing(QStringLiteral("baloo"), parent), d(new LocalBalooFileListingPrivate)
LocalBalooFileListing::LocalBalooFileListing(QObject *parent)
: AbstractFileListing(QStringLiteral("baloo"), parent), d(new LocalBalooFileListingPrivate)
{
d->mQuery.addType(QStringLiteral("Audio"));
setHandleNewFiles(false);
d->mDbusAdaptor = new BalooWatcherApplicationAdaptor(this);
auto sessionBus = QDBusConnection::sessionBus();
sessionBus.registerObject(QStringLiteral("/org/kde/BalooWatcherApplication"), d->mDbusAdaptor, QDBusConnection::ExportAllContents);
connect(&d->mServiceWatcher, &QDBusServiceWatcher::serviceRegistered,
this, &LocalBalooFileListing::serviceRegistered);
connect(&d->mServiceWatcher, &QDBusServiceWatcher::serviceOwnerChanged,
this, &LocalBalooFileListing::serviceOwnerChanged);
connect(&d->mServiceWatcher, &QDBusServiceWatcher::serviceUnregistered,
this, &LocalBalooFileListing::serviceUnregistered);
d->mServiceWatcher.setConnection(sessionBus);
d->mServiceWatcher.addWatchedService(QStringLiteral("org.kde.baloo"));
if (sessionBus.interface()->isServiceRegistered(QStringLiteral("org.kde.baloo"))) {
registerToBaloo();
}
}
LocalBalooFileListing::~LocalBalooFileListing()
......@@ -87,21 +118,107 @@ void LocalBalooFileListing::newBalooFile(const QString &fileName)
}
}
void LocalBalooFileListing::executeInit()
void LocalBalooFileListing::registeredToBaloo(QDBusPendingCallWatcher *watcher)
{
qDebug() << "LocalBalooFileListing::registeredToBaloo";
if (!watcher) {
return;
}
QDBusPendingReply<> reply = *watcher;
if (reply.isError()) {
d->mIsRegistered = false;
} else {
d->mIsRegistered = true;
}
d->mIsRegistering = false;
watcher->deleteLater();
}
void LocalBalooFileListing::registerToBaloo()
{
if (d->mIsRegistering) {
qDebug() << "LocalBalooFileListing::registerToBaloo" << "already registering";
return;
}
qDebug() << "LocalBalooFileListing::registerToBaloo";
d->mIsRegistering = true;
auto sessionBus = QDBusConnection::sessionBus();
sessionBus.connect(QStringLiteral("org.kde.baloo"), QStringLiteral("/fileindexer"),
QStringLiteral("org.kde.baloo.fileindexer"), QStringLiteral("finishedIndexingFile"), this, SLOT(newBalooFile(QString)));
auto methodCall = QDBusMessage::createMethodCall(QStringLiteral("org.kde.baloo"), QStringLiteral("/fileindexer"),
QStringLiteral("org.kde.baloo.fileindexer"), QStringLiteral("registerMonitor"));
qDebug() << "LocalBalooFileListing::registerToBaloo" << "call registerMonitor";
auto answer = sessionBus.call(methodCall);
if (answer.type() != QDBusMessage::ReplyMessage) {
qDebug() << "LocalBalooFileListing::executeInit" << answer.errorName() << answer.errorMessage();
}
sessionBus.connect(QStringLiteral("org.kde.baloo"), QStringLiteral("/fileindexer"),
QStringLiteral("org.kde.baloo.fileindexer"), QStringLiteral("finishedIndexingFile"), this, SLOT(newBalooFile(QString)));
QDBusMessage registerBalooWatcher = QDBusMessage::createMethodCall(QStringLiteral("org.kde.baloo"),
QStringLiteral("/"),
QStringLiteral("org.kde.baloo.main"),
QStringLiteral("registerBalooWatcher"));
registerBalooWatcher.setArguments({QStringLiteral("org.mpris.MediaPlayer2.elisa/org/kde/BalooWatcherApplication")});
auto pendingCall = sessionBus.asyncCall(registerBalooWatcher);
qDebug() << "LocalBalooFileListing::registerToBaloo" << "call registerBalooWatcher";
auto pendingCallWatcher = new QDBusPendingCallWatcher(pendingCall);
connect(pendingCallWatcher, &QDBusPendingCallWatcher::finished, this, &LocalBalooFileListing::registeredToBaloo);
if (pendingCallWatcher->isFinished()) {
registeredToBaloo(pendingCallWatcher);
}
}
void LocalBalooFileListing::renamedFiles(const QString &from, const QString &to, const QStringList &listFiles)
{
qDebug() << "LocalBalooFileListing::renamedFiles" << from << to << listFiles;
}
void LocalBalooFileListing::serviceOwnerChanged(const QString &serviceName, const QString &oldOwner, const QString &newOwner)
{
Q_UNUSED(oldOwner);
Q_UNUSED(newOwner);
qDebug() << "LocalBalooFileListing::serviceOwnerChanged" << serviceName << oldOwner << newOwner;
if (serviceName == QStringLiteral("org.kde.baloo") && !newOwner.isEmpty()) {
d->mIsRegistered = false;
registerToBaloo();
}
}
void LocalBalooFileListing::serviceRegistered(const QString &serviceName)
{
qDebug() << "LocalBalooFileListing::serviceRegistered" << serviceName;
if (serviceName == QStringLiteral("org.kde.baloo")) {
registerToBaloo();
}
}
void LocalBalooFileListing::serviceUnregistered(const QString &serviceName)
{
qDebug() << "LocalBalooFileListing::serviceUnregistered" << serviceName;
if (serviceName == QStringLiteral("org.kde.baloo")) {
d->mIsRegistered = false;
}
}
void LocalBalooFileListing::executeInit()
{
}
void LocalBalooFileListing::triggerRefreshOfContent()
......
......@@ -32,6 +32,7 @@
class LocalBalooFileListingPrivate;
class MusicAudioTrack;
class QDBusPendingCallWatcher;
class LocalBalooFileListing : public AbstractFileListing
{
......@@ -50,12 +51,24 @@ Q_SIGNALS:
public Q_SLOTS:
void renamedFiles(const QString &from, const QString &to, const QStringList &listFiles);
void serviceOwnerChanged(const QString &serviceName, const QString &oldOwner, const QString &newOwner);
void serviceRegistered(const QString &serviceName);
void serviceUnregistered(const QString &serviceName);
private Q_SLOTS:
void newBalooFile(const QString &fileName);
void registeredToBaloo(QDBusPendingCallWatcher *watcher);
private:
void registerToBaloo();
void executeInit() override;
void triggerRefreshOfContent() override;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment