File indexing completed on 2024-09-15 04:36:26

0001 /*
0002  *  SPDX-FileCopyrightText: 2009 Volker Krause <vkrause@kde.org>
0003  *  SPDX-FileCopyrightText: 2015 Daniel Vrátil <dvratil@redhat.com>
0004  *
0005  *  SPDX-License-Identifier: LGPL-2.0-or-later
0006  */
0007 
0008 // krazy:excludeall=dpointer
0009 
0010 #pragma once
0011 
0012 #include "akonadiprivate_export.h"
0013 
0014 #include <QSharedDataPointer>
0015 
0016 #include <QString>
0017 class QJsonObject;
0018 #include <QStringList>
0019 
0020 namespace Akonadi
0021 {
0022 class ImapSet;
0023 class ImapInterval;
0024 
0025 namespace Protocol
0026 {
0027 class DataStream;
0028 }
0029 
0030 class ScopePrivate;
0031 class AKONADIPRIVATE_EXPORT Scope
0032 {
0033 public:
0034     enum SelectionScope : uchar {
0035         Invalid = 0,
0036         Uid = 1 << 0,
0037         Rid = 1 << 1,
0038         HierarchicalRid = 1 << 2,
0039         Gid = 1 << 3,
0040     };
0041 
0042     class AKONADIPRIVATE_EXPORT HRID
0043     {
0044     public:
0045         HRID();
0046         explicit HRID(qint64 id, const QString &remoteId = QString());
0047         HRID(const HRID &other);
0048         HRID(HRID &&other) noexcept;
0049 
0050         HRID &operator=(const HRID &other);
0051         HRID &operator=(HRID &&other) noexcept;
0052 
0053         ~HRID() = default;
0054 
0055         bool isEmpty() const;
0056         bool operator==(const HRID &other) const;
0057 
0058         void toJson(QJsonObject &json) const;
0059 
0060         qint64 id;
0061         QString remoteId;
0062     };
0063 
0064     explicit Scope();
0065     Scope(SelectionScope scope, const QStringList &ids);
0066 
0067     /* UID */
0068     Scope(qint64 id); // krazy:exclude=explicit
0069     Scope(const ImapSet &uidSet); // krazy:exclude=explicit
0070     Scope(const ImapInterval &interval); // krazy:exclude=explicit
0071     Scope(const QList<qint64> &interval); // krazy:exclude=explicit
0072     Scope(const QList<HRID> &hridChain); // krazy:exclude=explicit
0073 
0074     Scope(const Scope &other);
0075     Scope(Scope &&other) noexcept;
0076     ~Scope();
0077 
0078     Scope &operator=(const Scope &other);
0079     Scope &operator=(Scope &&other) noexcept;
0080 
0081     bool operator==(const Scope &other) const;
0082     bool operator!=(const Scope &other) const;
0083 
0084     SelectionScope scope() const;
0085 
0086     bool isEmpty() const;
0087 
0088     ImapSet uidSet() const;
0089     void setUidSet(const ImapSet &uidSet);
0090 
0091     void setRidSet(const QStringList &ridSet);
0092     QStringList ridSet() const;
0093 
0094     void setHRidChain(const QList<HRID> &ridChain);
0095     QList<HRID> hridChain() const;
0096 
0097     void setGidSet(const QStringList &gidChain);
0098     QStringList gidSet() const;
0099 
0100     qint64 uid() const;
0101     QString rid() const;
0102     QString gid() const;
0103 
0104     void toJson(QJsonObject &json) const;
0105 
0106 private:
0107     QSharedDataPointer<ScopePrivate> d;
0108     friend class ScopePrivate;
0109 
0110     friend Protocol::DataStream &operator<<(Protocol::DataStream &stream, const Akonadi::Scope &scope);
0111     friend Protocol::DataStream &operator>>(Protocol::DataStream &stream, Akonadi::Scope &scope);
0112 };
0113 
0114 } // namespace Akonadi
0115 
0116 Q_DECLARE_TYPEINFO(Akonadi::Scope::HRID, Q_RELOCATABLE_TYPE);
0117 
0118 AKONADIPRIVATE_EXPORT QDebug operator<<(QDebug debug, const Akonadi::Scope &scope);