Verified Commit 5c236107 authored by Daniel Vrátil's avatar Daniel Vrátil 🤖
Browse files

Simplify ChangeMediator code

parent f1a31ca9
......@@ -20,21 +20,15 @@
#include "changemediator_p.h"
#include <QApplication>
#include <QCoreApplication>
#include "changenotificationdependenciesfactory_p.h"
#include "notificationsourceinterface.h"
#include "job_p.h"
#include "itemmovejob.h"
#include "collection.h"
#include "item.h"
//static const char mediatorSessionId[] = "MediatorSession"; TODO: remove?
using namespace Akonadi;
Q_GLOBAL_STATIC(ChangeMediator, s_globalChangeMediator)
class GlobalChangeMediator : public ChangeMediator {};
Q_GLOBAL_STATIC(GlobalChangeMediator, s_globalChangeMediator)
ChangeMediator *ChangeMediator::instance()
{
......@@ -48,68 +42,57 @@ ChangeMediator *ChangeMediator::instance()
ChangeMediator::ChangeMediator(QObject *parent)
: QObject(parent)
{
if (qApp) {
this->moveToThread(qApp->thread());
if (auto app = QCoreApplication::instance(); app != nullptr) {
this->moveToThread(app->thread());
}
}
/* static */
void ChangeMediator::registerMonitor(QObject *monitor)
{
QMetaObject::invokeMethod(instance(), "do_registerMonitor", Q_ARG(QObject *, monitor));
QMetaObject::invokeMethod(instance(), [monitor]() {
instance()->m_monitors.push_back(monitor);
});
}
/* static */
void ChangeMediator::unregisterMonitor(QObject *monitor)
{
QMetaObject::invokeMethod(instance(), "do_unregisterMonitor", Q_ARG(QObject *, monitor));
QMetaObject::invokeMethod(instance(), [monitor]() {
instance()->m_monitors.removeAll(monitor);
});
}
/* static */
void ChangeMediator::invalidateCollection(const Akonadi::Collection &collection)
{
QMetaObject::invokeMethod(instance(), "do_invalidateCollection", Q_ARG(Akonadi::Collection, collection));
QMetaObject::invokeMethod(instance(), [colId = collection.id()]() {
for (auto monitor : instance()->m_monitors) {
const bool ok = QMetaObject::invokeMethod(monitor, "invalidateCollectionCache", Q_ARG(qint64, colId));
Q_ASSERT(ok); Q_UNUSED(ok);
}
});
}
/* static */
void ChangeMediator::invalidateItem(const Akonadi::Item &item)
{
QMetaObject::invokeMethod(instance(), "do_invalidateItem", Q_ARG(Akonadi::Item, item));
QMetaObject::invokeMethod(instance(), [itemId = item.id()]() {
for (auto monitor : instance()->m_monitors) {
const bool ok = QMetaObject::invokeMethod(monitor, "invalidateItemCache", Q_ARG(qint64, itemId));
Q_ASSERT(ok); Q_UNUSED(ok);
}
});
}
/* static */
void ChangeMediator::invalidateTag(const Tag &tag)
{
QMetaObject::invokeMethod(instance(), "do_invalidateTag", Q_ARG(Akonadi::Tag, tag));
}
void ChangeMediator::do_registerMonitor(QObject *monitor)
{
m_monitors.append(monitor);
QMetaObject::invokeMethod(instance(), [tagId = tag.id()]() {
for (auto monitor : instance()->m_monitors) {
const bool ok = QMetaObject::invokeMethod(monitor, "invalidateTagCache", Q_ARG(qint64, tagId));
Q_ASSERT(ok); Q_UNUSED(ok);
}
});
}
void ChangeMediator::do_unregisterMonitor(QObject *monitor)
{
m_monitors.removeAll(monitor);
}
void ChangeMediator::do_invalidateCollection(const Akonadi::Collection &collection)
{
for (QObject *monitor : qAsConst(m_monitors)) {
QMetaObject::invokeMethod(monitor, "invalidateCollectionCache", Qt::AutoConnection, Q_ARG(qint64, collection.id()));
}
}
void ChangeMediator::do_invalidateItem(const Akonadi::Item &item)
{
for (QObject *monitor : qAsConst(m_monitors)) {
QMetaObject::invokeMethod(monitor, "invalidateItemCache", Qt::AutoConnection, Q_ARG(qint64, item.id()));
}
}
void ChangeMediator::do_invalidateTag(const Tag &tag)
{
for (QObject *monitor : qAsConst(m_monitors)) {
QMetaObject::invokeMethod(monitor, "invalidateTagCache", Qt::AutoConnection, Q_ARG(qint64, tag.id()));
}
}
......@@ -24,8 +24,6 @@
#include <QList>
#include <QObject>
#include "item.h"
namespace Akonadi
{
......@@ -34,13 +32,12 @@ class JobPrivate;
class Collection;
class Item;
class Tag;
class ChangeMediator : public QObject
{
Q_OBJECT
public:
explicit ChangeMediator(QObject *parent = nullptr);
static ChangeMediator *instance();
static void registerMonitor(QObject *monitor);
......@@ -50,15 +47,9 @@ public:
static void invalidateItem(const Akonadi::Item &item);
static void invalidateTag(const Akonadi::Tag &tag);
private Q_SLOTS:
void do_registerMonitor(QObject *monitor);
void do_unregisterMonitor(QObject *monitor);
void do_invalidateCollection(const Akonadi::Collection &collection);
void do_invalidateItem(const Akonadi::Item &item);
void do_invalidateTag(const Akonadi::Tag &tag);
protected:
explicit ChangeMediator(QObject *parent = nullptr);
private:
QList<QObject *> m_monitors;
};
......
......@@ -36,9 +36,7 @@ class CommandBuffer;
class AKONADI_TESTS_EXPORT ChangeNotificationDependenciesFactory
{
public:
virtual ~ChangeNotificationDependenciesFactory()
{
}
virtual ~ChangeNotificationDependenciesFactory() = default;
virtual Connection *createNotificationConnection(Session *parent, CommandBuffer *commandBuffer);
virtual void destroyNotificationConnection(Session *parent, Connection *connection);
......
Markdown is supported
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