File indexing completed on 2024-05-19 05:11:42

0001 /*
0002     SPDX-FileCopyrightText: 2007 Till Adam <adam@kde.org>
0003 
0004     SPDX-License-Identifier: LGPL-2.0-or-later
0005 */
0006 
0007 #pragma once
0008 
0009 #include <QMutex>
0010 #include <QObject>
0011 
0012 #include <Akonadi/GidExtractorInterface>
0013 #include <Akonadi/ItemSerializerPlugin>
0014 
0015 namespace Akonadi
0016 {
0017 /**
0018  * Levare QString implicit sharing to decrease memory consumption.
0019  *
0020  * This class is thread safe. Apparently required for usage in
0021  * legacy KRes compat bridges.
0022  */
0023 class StringPool
0024 {
0025 public:
0026     /**
0027      * Lookup @p value in the pool and return the known value
0028      * to reuse it and leverage the implicit sharing. Otherwise
0029      * add the value to the pool and return it again.
0030      */
0031     QString sharedValue(const QString &value);
0032 
0033 private:
0034     QMutex m_mutex;
0035     QSet<QString> m_pool;
0036 };
0037 
0038 class SerializerPluginMail : public QObject, public ItemSerializerPlugin, public GidExtractorInterface
0039 {
0040     Q_OBJECT
0041     Q_INTERFACES(Akonadi::ItemSerializerPlugin Akonadi::GidExtractorInterface)
0042     Q_PLUGIN_METADATA(IID "org.kde.akonadi.SerializerPluginMail")
0043 public:
0044     bool deserialize(Item &item, const QByteArray &label, QIODevice &data, int version) override;
0045     void serialize(const Item &item, const QByteArray &label, QIODevice &data, int &version) override;
0046     QSet<QByteArray> parts(const Item &item) const override;
0047     QString extractGid(const Item &item) const override;
0048 
0049 private:
0050     StringPool m_stringPool;
0051 };
0052 }