File indexing completed on 2024-11-10 04:40:19
0001 /* 0002 SPDX-FileCopyrightText: 2014 Daniel Vrátil <dvratil@redhat.com> 0003 0004 SPDX-License-Identifier: LGPL-2.0-or-later 0005 */ 0006 0007 #include "fakedatastore.h" 0008 #include "akonadischema.h" 0009 #include "dbpopulator.h" 0010 #include "fakeakonadiserver.h" 0011 #include "inspectablenotificationcollector.h" 0012 #include "storage/dbconfig.h" 0013 #include "storage/dbinitializer.h" 0014 0015 #include <QThread> 0016 0017 using namespace Akonadi::Server; 0018 0019 Q_DECLARE_METATYPE(PimItem) 0020 Q_DECLARE_METATYPE(PimItem::List) 0021 Q_DECLARE_METATYPE(Collection) 0022 Q_DECLARE_METATYPE(Flag) 0023 Q_DECLARE_METATYPE(QList<Flag>) 0024 Q_DECLARE_METATYPE(Tag) 0025 Q_DECLARE_METATYPE(QList<Tag>) 0026 Q_DECLARE_METATYPE(MimeType) 0027 Q_DECLARE_METATYPE(QList<QByteArray>) 0028 0029 FakeDataStoreFactory::FakeDataStoreFactory(FakeAkonadiServer *akonadi) 0030 : m_akonadi(akonadi) 0031 { 0032 } 0033 0034 DataStore *FakeDataStoreFactory::createStore() 0035 { 0036 return new FakeDataStore(m_akonadi); 0037 } 0038 0039 FakeDataStore::FakeDataStore(FakeAkonadiServer *akonadi) 0040 : DataStore(akonadi, DbConfig::configuredDatabase()) 0041 , mPopulateDb(true) 0042 { 0043 mNotificationCollector = std::make_unique<InspectableNotificationCollector>(*m_akonadi, this); 0044 } 0045 0046 FakeDataStore::~FakeDataStore() = default; 0047 0048 bool FakeDataStore::init() 0049 { 0050 if (!DataStore::init()) { 0051 return false; 0052 } 0053 0054 if (mPopulateDb) { 0055 DbPopulator dbPopulator; 0056 if (!dbPopulator.run()) { 0057 qWarning() << "Failed to populate database"; 0058 return false; 0059 } 0060 } 0061 0062 return true; 0063 } 0064 0065 bool FakeDataStore::setItemsFlags(const PimItem::List &items, 0066 const QList<Flag> *currentFlags, 0067 const QList<Flag> &flags, 0068 bool *flagsChanged, 0069 const Collection &col, 0070 bool silent) 0071 { 0072 mChanges.insert(QStringLiteral("setItemsFlags"), 0073 QVariantList() << QVariant::fromValue(items) << QVariant::fromValue(flags) << QVariant::fromValue(col) << silent); 0074 return DataStore::setItemsFlags(items, currentFlags, flags, flagsChanged, col, silent); 0075 } 0076 0077 bool FakeDataStore::appendItemsFlags(const PimItem::List &items, 0078 const QList<Flag> &flags, 0079 bool *flagsChanged, 0080 bool checkIfExists, 0081 const Collection &col, 0082 bool silent) 0083 { 0084 mChanges.insert(QStringLiteral("appendItemsFlags"), 0085 QVariantList() << QVariant::fromValue(items) << QVariant::fromValue(flags) << checkIfExists << QVariant::fromValue(col) << silent); 0086 return DataStore::appendItemsFlags(items, flags, flagsChanged, checkIfExists, col, silent); 0087 } 0088 0089 bool FakeDataStore::removeItemsFlags(const PimItem::List &items, const QList<Flag> &flags, bool *flagsChanged, const Collection &col, bool silent) 0090 { 0091 mChanges.insert(QStringLiteral("removeItemsFlags"), 0092 QVariantList() << QVariant::fromValue(items) << QVariant::fromValue(flags) << QVariant::fromValue(col) << silent); 0093 return DataStore::removeItemsFlags(items, flags, flagsChanged, col, silent); 0094 } 0095 0096 bool FakeDataStore::setItemsTags(const PimItem::List &items, const Tag::List &tags, bool *tagsChanged, bool silent) 0097 { 0098 mChanges.insert(QStringLiteral("setItemsTags"), QVariantList() << QVariant::fromValue(items) << QVariant::fromValue(tags) << silent); 0099 return DataStore::setItemsTags(items, tags, tagsChanged, silent); 0100 } 0101 0102 bool FakeDataStore::appendItemsTags(const PimItem::List &items, 0103 const Tag::List &tags, 0104 bool *tagsChanged, 0105 bool checkIfExists, 0106 const Collection &col, 0107 bool silent) 0108 { 0109 mChanges.insert(QStringLiteral("appendItemsTags"), 0110 QVariantList() << QVariant::fromValue(items) << QVariant::fromValue(tags) << checkIfExists << QVariant::fromValue(col) << silent); 0111 return DataStore::appendItemsTags(items, tags, tagsChanged, checkIfExists, col, silent); 0112 } 0113 0114 bool FakeDataStore::removeItemsTags(const PimItem::List &items, const Tag::List &tags, bool *tagsChanged, bool silent) 0115 { 0116 mChanges.insert(QStringLiteral("removeItemsTags"), QVariantList() << QVariant::fromValue(items) << QVariant::fromValue(tags) << silent); 0117 return DataStore::removeItemsTags(items, tags, tagsChanged, silent); 0118 } 0119 0120 bool FakeDataStore::removeItemParts(const PimItem &item, const QSet<QByteArray> &parts) 0121 { 0122 mChanges.insert(QStringLiteral("remoteItemParts"), QVariantList() << QVariant::fromValue(item) << QVariant::fromValue(parts)); 0123 return DataStore::removeItemParts(item, parts); 0124 } 0125 0126 bool FakeDataStore::invalidateItemCache(const PimItem &item) 0127 { 0128 mChanges.insert(QStringLiteral("invalidateItemCache"), QVariantList() << QVariant::fromValue(item)); 0129 return DataStore::invalidateItemCache(item); 0130 } 0131 0132 bool FakeDataStore::appendCollection(Collection &collection, const QStringList &mimeTypes, const QMap<QByteArray, QByteArray> &attributes) 0133 { 0134 mChanges.insert(QStringLiteral("appendCollection"), QVariantList() << QVariant::fromValue(collection) << mimeTypes << QVariant::fromValue(attributes)); 0135 return DataStore::appendCollection(collection, mimeTypes, attributes); 0136 } 0137 0138 bool FakeDataStore::cleanupCollection(Collection &collection) 0139 { 0140 mChanges.insert(QStringLiteral("cleanupCollection"), QVariantList() << QVariant::fromValue(collection)); 0141 return DataStore::cleanupCollection(collection); 0142 } 0143 0144 bool FakeDataStore::moveCollection(Collection &collection, const Collection &newParent) 0145 { 0146 mChanges.insert(QStringLiteral("moveCollection"), QVariantList() << QVariant::fromValue(collection) << QVariant::fromValue(newParent)); 0147 return DataStore::moveCollection(collection, newParent); 0148 } 0149 0150 bool FakeDataStore::appendMimeTypeForCollection(qint64 collectionId, const QStringList &mimeTypes) 0151 { 0152 mChanges.insert(QStringLiteral("appendMimeTypeForCollection"), QVariantList() << collectionId << QVariant::fromValue(mimeTypes)); 0153 return DataStore::appendMimeTypeForCollection(collectionId, mimeTypes); 0154 } 0155 0156 void FakeDataStore::activeCachePolicy(Collection &col) 0157 { 0158 mChanges.insert(QStringLiteral("activeCachePolicy"), QVariantList() << QVariant::fromValue(col)); 0159 return DataStore::activeCachePolicy(col); 0160 } 0161 0162 bool FakeDataStore::appendPimItem(QList<Part> &parts, 0163 const QList<Flag> &flags, 0164 const MimeType &mimetype, 0165 const Collection &collection, 0166 const QDateTime &dateTime, 0167 const QString &remote_id, 0168 const QString &remoteRevision, 0169 const QString &gid, 0170 PimItem &pimItem) 0171 { 0172 mChanges.insert(QStringLiteral("appendPimItem"), 0173 QVariantList() << QVariant::fromValue(mimetype) << QVariant::fromValue(collection) << dateTime << remote_id << remoteRevision << gid); 0174 return DataStore::appendPimItem(parts, flags, mimetype, collection, dateTime, remote_id, remoteRevision, gid, pimItem); 0175 } 0176 0177 bool FakeDataStore::cleanupPimItems(const PimItem::List &items, bool silent) 0178 { 0179 mChanges.insert(QStringLiteral("cleanupPimItems"), QVariantList() << QVariant::fromValue(items) << silent); 0180 return DataStore::cleanupPimItems(items, silent); 0181 } 0182 0183 bool FakeDataStore::unhidePimItem(PimItem &pimItem) 0184 { 0185 mChanges.insert(QStringLiteral("unhidePimItem"), QVariantList() << QVariant::fromValue(pimItem)); 0186 return DataStore::unhidePimItem(pimItem); 0187 } 0188 0189 bool FakeDataStore::unhideAllPimItems() 0190 { 0191 mChanges.insert(QStringLiteral("unhideAllPimItems"), QVariantList()); 0192 return DataStore::unhideAllPimItems(); 0193 } 0194 0195 bool FakeDataStore::addCollectionAttribute(const Collection &col, const QByteArray &key, const QByteArray &value, bool silent) 0196 { 0197 mChanges.insert(QStringLiteral("addCollectionAttribute"), QVariantList() << QVariant::fromValue(col) << key << value << silent); 0198 return DataStore::addCollectionAttribute(col, key, value, silent); 0199 } 0200 0201 bool FakeDataStore::removeCollectionAttribute(const Collection &col, const QByteArray &key) 0202 { 0203 mChanges.insert(QStringLiteral("removeCollectionAttribute"), QVariantList() << QVariant::fromValue(col) << key); 0204 return DataStore::removeCollectionAttribute(col, key); 0205 } 0206 0207 bool FakeDataStore::beginTransaction(const QString &name) 0208 { 0209 mChanges.insert(QStringLiteral("beginTransaction"), QVariantList() << name); 0210 return DataStore::beginTransaction(name); 0211 } 0212 0213 bool FakeDataStore::commitTransaction() 0214 { 0215 mChanges.insert(QStringLiteral("commitTransaction"), QVariantList()); 0216 return DataStore::commitTransaction(); 0217 } 0218 0219 bool FakeDataStore::rollbackTransaction() 0220 { 0221 mChanges.insert(QStringLiteral("rollbackTransaction"), QVariantList()); 0222 return DataStore::rollbackTransaction(); 0223 } 0224 0225 void FakeDataStore::setPopulateDb(bool populate) 0226 { 0227 mPopulateDb = populate; 0228 } 0229 0230 #include "moc_fakedatastore.cpp"