File indexing completed on 2025-01-05 04:59:40
0001 /* 0002 * SPDX-FileCopyrightText: 2015 Kevin Ottens <ervin@kde.org> 0003 * SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL 0004 */ 0005 0006 0007 #include "akonadilivequeryintegrator.h" 0008 0009 using namespace Akonadi; 0010 0011 LiveQueryIntegrator::LiveQueryIntegrator(const SerializerInterface::Ptr &serializer, 0012 const MonitorInterface::Ptr &monitor, 0013 QObject *parent) 0014 : QObject(parent), 0015 m_serializer(serializer), 0016 m_monitor(monitor) 0017 { 0018 connect(m_monitor.data(), &MonitorInterface::collectionSelectionChanged, 0019 this, &LiveQueryIntegrator::onCollectionSelectionChanged); 0020 0021 connect(m_monitor.data(), &MonitorInterface::collectionAdded, this, &LiveQueryIntegrator::onCollectionAdded); 0022 connect(m_monitor.data(), &MonitorInterface::collectionRemoved, this, &LiveQueryIntegrator::onCollectionRemoved); 0023 connect(m_monitor.data(), &MonitorInterface::collectionChanged, this, &LiveQueryIntegrator::onCollectionChanged); 0024 0025 connect(m_monitor.data(), &MonitorInterface::itemAdded, this, &LiveQueryIntegrator::onItemAdded); 0026 connect(m_monitor.data(), &MonitorInterface::itemRemoved, this, &LiveQueryIntegrator::onItemRemoved); 0027 connect(m_monitor.data(), &MonitorInterface::itemChanged, this, &LiveQueryIntegrator::onItemChanged); 0028 } 0029 0030 void LiveQueryIntegrator::addRemoveHandler(const LiveQueryIntegrator::CollectionRemoveHandler &handler) 0031 { 0032 m_collectionRemoveHandlers << handler; 0033 } 0034 0035 void LiveQueryIntegrator::addRemoveHandler(const LiveQueryIntegrator::ItemRemoveHandler &handler) 0036 { 0037 m_itemRemoveHandlers << handler; 0038 } 0039 0040 void LiveQueryIntegrator::onCollectionSelectionChanged() 0041 { 0042 foreach (const auto &weak, m_itemInputQueries) { 0043 auto query = weak.toStrongRef(); 0044 if (query) 0045 query->reset(); 0046 } 0047 } 0048 0049 void LiveQueryIntegrator::onCollectionAdded(const Collection &collection) 0050 { 0051 foreach (const auto &weak, m_collectionInputQueries) { 0052 auto query = weak.toStrongRef(); 0053 if (query) 0054 query->onAdded(collection); 0055 } 0056 } 0057 0058 void LiveQueryIntegrator::onCollectionRemoved(const Collection &collection) 0059 { 0060 foreach (const auto &weak, m_collectionInputQueries) { 0061 auto query = weak.toStrongRef(); 0062 if (query) 0063 query->onRemoved(collection); 0064 } 0065 0066 foreach (const auto &handler, m_collectionRemoveHandlers) 0067 handler(collection); 0068 0069 cleanupQueries(); 0070 } 0071 0072 void LiveQueryIntegrator::onCollectionChanged(const Collection &collection) 0073 { 0074 foreach (const auto &weak, m_collectionInputQueries) { 0075 auto query = weak.toStrongRef(); 0076 if (query) 0077 query->onChanged(collection); 0078 } 0079 } 0080 0081 void LiveQueryIntegrator::onItemAdded(const Item &item) 0082 { 0083 foreach (const auto &weak, m_itemInputQueries) { 0084 auto query = weak.toStrongRef(); 0085 if (query) 0086 query->onAdded(item); 0087 } 0088 } 0089 0090 void LiveQueryIntegrator::onItemRemoved(const Item &item) 0091 { 0092 foreach (const auto &weak, m_itemInputQueries) { 0093 auto query = weak.toStrongRef(); 0094 if (query) 0095 query->onRemoved(item); 0096 } 0097 0098 foreach (const auto &handler, m_itemRemoveHandlers) 0099 handler(item); 0100 0101 cleanupQueries(); 0102 } 0103 0104 void LiveQueryIntegrator::onItemChanged(const Item &item) 0105 { 0106 foreach (const auto &weak, m_itemInputQueries) { 0107 auto query = weak.toStrongRef(); 0108 if (query) 0109 query->onChanged(item); 0110 } 0111 } 0112 0113 void LiveQueryIntegrator::cleanupQueries() 0114 { 0115 m_collectionInputQueries.removeAll(Domain::LiveQueryInput<Collection>::WeakPtr()); 0116 m_itemInputQueries.removeAll(Domain::LiveQueryInput<Item>::WeakPtr()); 0117 } 0118 0119 #include "moc_akonadilivequeryintegrator.cpp"