8 #include "datastream_p_p.h"
12 #include <QJsonObject>
13 #include <QStringList>
15 #include "imapset_p.h"
26 Scope::SelectionScope scope = Scope::Invalid;
34 Scope::HRID::HRID(qint64
id,
const QString &remoteId)
40 Scope::HRID::HRID(
const HRID &other)
42 , remoteId(other.remoteId)
46 Scope::HRID::HRID(HRID &&other) noexcept
49 remoteId.swap(other.remoteId);
52 Scope::HRID &Scope::HRID::operator=(
const HRID &other)
59 remoteId = other.remoteId;
63 Scope::HRID &Scope::HRID::operator=(HRID &&other) noexcept
70 remoteId.swap(other.remoteId);
74 bool Scope::HRID::isEmpty()
const
76 return id <= 0 && remoteId.isEmpty();
79 bool Scope::HRID::operator==(
const HRID &other)
const
81 return id == other.id && remoteId == other.remoteId;
86 json[QStringLiteral(
"ID")] = id;
87 json[QStringLiteral(
"RemoteID")] = remoteId;
95 Scope::Scope(qint64
id)
101 Scope::Scope(
const ImapSet &set)
102 : d(new ScopePrivate)
107 Scope::Scope(
const ImapInterval &interval)
108 : d(new ScopePrivate)
114 : d(new ScopePrivate)
119 Scope::Scope(SelectionScope scope,
const QStringList &ids)
120 : d(new ScopePrivate)
122 Q_ASSERT(scope == Rid || scope == Gid);
126 }
else if (scope == Gid) {
133 : d(new ScopePrivate)
135 d->scope = HierarchicalRid;
139 Scope::Scope(
const Scope &other)
144 Scope::Scope(Scope &&other) noexcept
153 Scope &Scope::operator=(
const Scope &other)
159 Scope &Scope::operator=(Scope &&other) noexcept
165 bool Scope::operator==(
const Scope &other)
const
167 if (d->scope != other.d->scope) {
173 return d->uidSet == other.d->uidSet;
175 return d->gidSet == other.d->gidSet;
177 return d->ridSet == other.d->ridSet;
178 case HierarchicalRid:
179 return d->hridChain == other.d->hridChain;
188 bool Scope::operator!=(
const Scope &other)
const
190 return !(*
this == other);
193 Scope::SelectionScope Scope::scope()
const
198 bool Scope::isEmpty()
const
204 return d->uidSet.isEmpty();
206 return d->ridSet.isEmpty();
207 case HierarchicalRid:
208 return d->hridChain.isEmpty();
210 return d->gidSet.isEmpty();
217 void Scope::setUidSet(
const ImapSet &uidSet)
223 ImapSet Scope::uidSet()
const
241 d->scope = HierarchicalRid;
242 d->hridChain = hridChain;
261 qint64 Scope::uid()
const
263 if (d->uidSet.intervals().size() == 1 && d->uidSet.intervals().at(0).size() == 1) {
264 return d->uidSet.intervals().
at(0).begin();
273 if (d->ridSet.size() != 1) {
275 Q_ASSERT(d->ridSet.size() == 1);
278 return d->ridSet.at(0);
283 if (d->gidSet.size() != 1) {
285 Q_ASSERT(d->gidSet.size() == 1);
288 return d->gidSet.at(0);
295 json[QStringLiteral(
"type")] = QStringLiteral(
"UID");
299 json[QStringLiteral(
"type")] = QStringLiteral(
"RID");
303 json[QStringLiteral(
"type")] = QStringLiteral(
"GID");
306 case Scope::HierarchicalRid: {
307 const auto &chain = hridChain();
309 for (
const auto &hrid : chain) {
314 json[QStringLiteral(
"type")] = QStringLiteral(
"HRID");
315 json[QStringLiteral(
"value")] = hridArray;
318 json[QStringLiteral(
"type")] = QStringLiteral(
"invalid");
319 json[QStringLiteral(
"value")] =
QJsonValue(
static_cast<int>(scope()));
323 Protocol::DataStream &
operator<<(Protocol::DataStream &stream,
const Akonadi::Scope &scope)
325 stream << static_cast<quint8>(scope.d->scope);
326 switch (scope.d->scope) {
330 stream << scope.d->uidSet;
333 stream << scope.d->ridSet;
335 case Scope::HierarchicalRid:
336 stream << scope.d->hridChain;
339 stream << scope.d->gidSet;
346 Protocol::DataStream &
operator<<(Protocol::DataStream &stream,
const Akonadi::Scope::HRID &hrid)
348 return stream << hrid.id << hrid.remoteId;
351 Protocol::DataStream &
operator>>(Protocol::DataStream &stream, Akonadi::Scope::HRID &hrid)
353 return stream >> hrid.id >> hrid.remoteId;
356 Protocol::DataStream &
operator>>(Protocol::DataStream &stream, Akonadi::Scope &scope)
358 scope.d->uidSet = ImapSet();
359 scope.d->ridSet.clear();
360 scope.d->hridChain.clear();
361 scope.d->gidSet.clear();
363 stream >>
reinterpret_cast<quint8 &
>(scope.d->scope);
364 switch (scope.d->scope) {
368 stream >> scope.d->uidSet;
371 stream >> scope.d->ridSet;
373 case Scope::HierarchicalRid:
374 stream >> scope.d->hridChain;
377 stream >> scope.d->gidSet;
390 return dbg.
nospace() <<
"(ID: " << hrid.id <<
", RemoteID: " << hrid.remoteId <<
")";
395 switch (scope.scope()) {
397 return dbg.
nospace() <<
"UID " << scope.uidSet();
399 return dbg.
nospace() <<
"RID " << scope.ridSet();
401 return dbg.
nospace() <<
"GID " << scope.gidSet();
402 case Scope::HierarchicalRid:
403 return dbg.
nospace() <<
"HRID " << scope.hridChain();
405 return dbg.
nospace() <<
"Invalid scope";