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

0001 /*
0002  * SPDX-FileCopyrightText: 2015 Daniel Vrátil <dvratil@kde.org>
0003  *
0004  * SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
0005  *
0006  */
0007 
0008 #include "itemchangelog_p.h"
0009 
0010 using namespace Akonadi;
0011 
0012 ItemChangeLog *ItemChangeLog::sInstance = nullptr;
0013 
0014 ItemChangeLog *ItemChangeLog::instance()
0015 {
0016     if (!sInstance) {
0017         sInstance = new ItemChangeLog;
0018     }
0019     return sInstance;
0020 }
0021 
0022 ItemChangeLog::ItemChangeLog()
0023 {
0024 }
0025 
0026 Item::Flags &ItemChangeLog::addedFlags(ItemPrivate *priv)
0027 {
0028     return m_addedFlags[priv];
0029 }
0030 
0031 Item::Flags ItemChangeLog::addedFlags(const ItemPrivate *priv) const
0032 {
0033     return m_addedFlags[const_cast<ItemPrivate *>(priv)];
0034 }
0035 
0036 Item::Flags &ItemChangeLog::deletedFlags(ItemPrivate *priv)
0037 {
0038     return m_deletedFlags[priv];
0039 }
0040 
0041 Item::Flags ItemChangeLog::deletedFlags(const ItemPrivate *priv) const
0042 {
0043     return m_deletedFlags[const_cast<ItemPrivate *>(priv)];
0044 }
0045 
0046 Tag::List &ItemChangeLog::addedTags(ItemPrivate *priv)
0047 {
0048     return m_addedTags[priv];
0049 }
0050 
0051 Tag::List ItemChangeLog::addedTags(const ItemPrivate *priv) const
0052 {
0053     return m_addedTags[const_cast<ItemPrivate *>(priv)];
0054 }
0055 
0056 Tag::List &ItemChangeLog::deletedTags(ItemPrivate *priv)
0057 {
0058     return m_deletedTags[priv];
0059 }
0060 
0061 Tag::List ItemChangeLog::deletedTags(const ItemPrivate *priv) const
0062 {
0063     return m_deletedTags[const_cast<ItemPrivate *>(priv)];
0064 }
0065 
0066 AttributeStorage &ItemChangeLog::attributeStorage(ItemPrivate *priv)
0067 {
0068     return m_attributeStorage[priv];
0069 }
0070 
0071 AttributeStorage ItemChangeLog::attributeStorage(const ItemPrivate *priv) const
0072 {
0073     return m_attributeStorage[const_cast<ItemPrivate *>(priv)];
0074 }
0075 
0076 void ItemChangeLog::removeItem(const ItemPrivate *priv)
0077 {
0078     auto p = const_cast<ItemPrivate *>(priv);
0079     m_addedFlags.remove(p);
0080     m_deletedFlags.remove(p);
0081     m_addedTags.remove(p);
0082     m_deletedTags.remove(p);
0083     m_attributeStorage.remove(p);
0084 }
0085 
0086 void ItemChangeLog::clearItemChangelog(const ItemPrivate *priv)
0087 {
0088     auto p = const_cast<ItemPrivate *>(priv);
0089     m_addedFlags.remove(p);
0090     m_deletedFlags.remove(p);
0091     m_addedTags.remove(p);
0092     m_deletedTags.remove(p);
0093     m_attributeStorage[p].resetChangeLog(); // keep the attributes
0094 }