File indexing completed on 2025-01-05 04:46:59

0001 /*
0002     SPDX-FileCopyrightText: 2009 Volker Krause <vkrause@kde.org>
0003 
0004     SPDX-License-Identifier: LGPL-2.0-or-later
0005 */
0006 
0007 #pragma once
0008 
0009 #include <QByteArray>
0010 #include <QDebug>
0011 #include <QList>
0012 #include <QString>
0013 
0014 #include <optional>
0015 
0016 namespace Akonadi
0017 {
0018 namespace Server
0019 {
0020 class ItemRetrievalRequest;
0021 
0022 /// Details of a single item retrieval request
0023 class ItemRetrievalRequest
0024 {
0025 public:
0026     struct Id {
0027         explicit Id(uint32_t value)
0028             : mValue(value)
0029         {
0030         }
0031         bool operator==(Id other) const
0032         {
0033             return mValue == other.mValue;
0034         }
0035 
0036     private:
0037         uint32_t mValue;
0038         Id next()
0039         {
0040             return Id{++mValue};
0041         }
0042 
0043         friend class ItemRetrievalRequest;
0044         friend QDebug operator<<(QDebug, Id);
0045     };
0046 
0047     explicit ItemRetrievalRequest();
0048 
0049     Id id;
0050     QList<qint64> ids;
0051     QString resourceId;
0052     QByteArrayList parts; // list instead of vector to simplify client-side handling
0053 
0054 private:
0055     static Id lastId;
0056 };
0057 
0058 class ItemRetrievalResult
0059 {
0060 public:
0061     explicit ItemRetrievalResult() = default; // don't use, sadly Qt metatype system requires type to be default-constructible
0062     ItemRetrievalResult(ItemRetrievalRequest request)
0063         : request(std::move(request))
0064     {
0065     }
0066 
0067     ItemRetrievalRequest request;
0068 
0069     std::optional<QString> errorMsg{};
0070 };
0071 
0072 inline QDebug operator<<(QDebug dbg, ItemRetrievalRequest::Id id)
0073 {
0074     dbg.nospace() << id.mValue;
0075     return dbg.space();
0076 }
0077 
0078 } // namespace Server
0079 } // namespace Akonadi