8#include "datastream_p_p.h"
10#include "shared/akranges.h"
16using namespace AkRanges;
27 Scope::SelectionScope scope = Scope::Invalid;
35Scope::HRID::HRID(qint64
id,
const QString &remoteId)
41bool Scope::HRID::isEmpty()
const
43 return id <= 0 && remoteId.
isEmpty();
48 json[QStringLiteral(
"ID")] = id;
49 json[QStringLiteral(
"RemoteID")] = remoteId;
57Scope::Scope(
const Scope &) =
default;
58Scope::Scope(Scope &&) noexcept = default;
60Scope::Scope(std::initializer_list<qint64> ids)
63 setUidSet(std::move(ids));
66Scope::Scope(qint64
id)
78Scope::Scope(SelectionScope scope,
const QStringList &ids)
81 Q_ASSERT(scope == Rid || scope == Gid);
85 }
else if (scope == Gid) {
94 d->scope = HierarchicalRid;
98Scope::~Scope() =
default;
100Scope &Scope::operator=(
const Scope &) =
default;
101Scope &Scope::operator=(Scope &&) noexcept = default;
103bool Scope::operator==(const Scope &other)
const
105 if (d->scope != other.d->scope) {
111 return d->uidSet == other.d->uidSet;
113 return d->gidSet == other.d->gidSet;
115 return d->ridSet == other.d->ridSet;
116 case HierarchicalRid:
117 return d->hridChain == other.d->hridChain;
126bool Scope::operator!=(
const Scope &other)
const
128 return !(*
this == other);
131Scope::SelectionScope Scope::scope()
const
136bool Scope::isEmpty()
const
142 return d->uidSet.isEmpty();
144 return d->ridSet.isEmpty();
145 case HierarchicalRid:
146 return d->hridChain.isEmpty();
148 return d->gidSet.isEmpty();
177void Scope::setHRidChain(
const QList<HRID> &hridChain)
179 d->scope = HierarchicalRid;
180 d->hridChain = hridChain;
199qint64 Scope::uid()
const
201 if (d->uidSet.size() != 1) {
203 Q_ASSERT(d->uidSet.size() == 1);
207 return d->uidSet.
front();
212 if (d->ridSet.size() != 1) {
214 Q_ASSERT(d->ridSet.size() == 1);
217 return d->ridSet.
at(0);
222 if (d->gidSet.size() != 1) {
224 Q_ASSERT(d->gidSet.size() == 1);
227 return d->gidSet.
at(0);
234 json[QStringLiteral(
"type")] = QStringLiteral(
"UID");
241 json[QStringLiteral(
"type")] = QStringLiteral(
"RID");
245 json[QStringLiteral(
"type")] = QStringLiteral(
"GID");
248 case Scope::HierarchicalRid: {
249 const auto &chain = hridChain();
251 for (
const auto &hrid : chain) {
256 json[QStringLiteral(
"type")] = QStringLiteral(
"HRID");
257 json[QStringLiteral(
"value")] = hridArray;
260 json[QStringLiteral(
"type")] = QStringLiteral(
"invalid");
261 json[QStringLiteral(
"value")] =
QJsonValue(
static_cast<int>(scope()));
265Protocol::DataStream &
operator<<(Protocol::DataStream &stream,
const Akonadi::Scope &scope)
267 stream << static_cast<quint8>(scope.d->scope);
268 switch (scope.d->scope) {
272 stream << scope.d->uidSet;
275 stream << scope.d->ridSet;
277 case Scope::HierarchicalRid:
278 stream << scope.d->hridChain;
281 stream << scope.d->gidSet;
288Protocol::DataStream &
operator<<(Protocol::DataStream &stream,
const Akonadi::Scope::HRID &hrid)
290 return stream << hrid.id << hrid.remoteId;
293Protocol::DataStream &
operator>>(Protocol::DataStream &stream, Akonadi::Scope::HRID &hrid)
295 return stream >> hrid.id >> hrid.remoteId;
298Protocol::DataStream &
operator>>(Protocol::DataStream &stream, Akonadi::Scope &scope)
300 scope.d->uidSet.clear();
301 scope.d->ridSet.clear();
302 scope.d->hridChain.clear();
303 scope.d->gidSet.clear();
305 stream >>
reinterpret_cast<quint8 &
>(scope.d->scope);
306 switch (scope.d->scope) {
310 stream >> scope.d->uidSet;
313 stream >> scope.d->ridSet;
315 case Scope::HierarchicalRid:
316 stream >> scope.d->hridChain;
319 stream >> scope.d->gidSet;
332 return dbg.
nospace() <<
"(ID: " << hrid.id <<
", RemoteID: " << hrid.remoteId <<
")";
337 switch (scope.scope()) {
339 return dbg.
nospace() <<
"Scope(UID, " << scope.uidSet() <<
")";
341 return dbg.
nospace() <<
"Scope(RID, " << scope.ridSet() <<
")";
343 return dbg.
nospace() <<
"Scope(GID, " << scope.gidSet() <<
")";
344 case Scope::HierarchicalRid:
345 return dbg.
nospace() <<
"Scope(HRID, " << scope.hridChain() <<
")";
347 return dbg.
nospace() <<
"Scope(Invalid)";
Helper integration between Akonadi and Qt.
KCALENDARCORE_EXPORT QDataStream & operator>>(QDataStream &in, const KCalendarCore::Alarm::Ptr &)
QDebug operator<<(QDebug dbg, const PerceptualColor::MultiSpinBoxSection &value)
void append(const QJsonValue &value)
QJsonArray fromStringList(const QStringList &list)
QJsonArray fromVariantList(const QVariantList &list)
const QChar at(qsizetype position) const const
bool isEmpty() const const