File indexing completed on 2024-11-10 04:40:53

0001 /*
0002     SPDX-FileCopyrightText: 2013 Daniel Vrátil <dvratil@redhat.com>
0003 
0004     SPDX-License-Identifier: LGPL-2.0-or-later
0005 */
0006 
0007 #include "agentsearchinstance.h"
0008 #include "agentsearchinterface.h"
0009 #include "searchtaskmanager.h"
0010 
0011 #include "private/dbus_p.h"
0012 
0013 using namespace Akonadi;
0014 using namespace Akonadi::Server;
0015 
0016 AgentSearchInstance::AgentSearchInstance(const QString &id, SearchTaskManager &manager)
0017     : mId(id)
0018     , mInterface(nullptr)
0019     , mManager(manager)
0020 {
0021 }
0022 
0023 AgentSearchInstance::~AgentSearchInstance()
0024 {
0025     delete mInterface;
0026 }
0027 
0028 bool AgentSearchInstance::init()
0029 {
0030     Q_ASSERT(!mInterface);
0031 
0032     mInterface =
0033         new OrgFreedesktopAkonadiAgentSearchInterface(DBus::agentServiceName(mId, DBus::Agent), QStringLiteral("/Search"), QDBusConnection::sessionBus());
0034 
0035     if (!mInterface || !mInterface->isValid()) {
0036         delete mInterface;
0037         mInterface = nullptr;
0038         return false;
0039     }
0040 
0041     mServiceWatcher = std::make_unique<QDBusServiceWatcher>(DBus::agentServiceName(mId, DBus::Agent),
0042                                                             QDBusConnection::sessionBus(),
0043                                                             QDBusServiceWatcher::WatchForUnregistration);
0044     connect(mServiceWatcher.get(), &QDBusServiceWatcher::serviceUnregistered, this, [this]() {
0045         mManager.unregisterInstance(mId);
0046     });
0047 
0048     return true;
0049 }
0050 
0051 void AgentSearchInstance::search(const QByteArray &searchId, const QString &query, qlonglong collectionId)
0052 {
0053     mInterface->search(searchId, query, collectionId);
0054 }
0055 
0056 OrgFreedesktopAkonadiAgentSearchInterface *AgentSearchInstance::interface() const
0057 {
0058     return mInterface;
0059 }
0060 
0061 #include "moc_agentsearchinstance.cpp"