Akonadi
8 #include "akonadicore_debug.h"
10 #include "itemserializer_p.h"
11 #include "private/protocol_p.h"
16 #include <QReadWriteLock>
17 #include <QScopedValueRollback>
18 #include <QStringList>
30 return ::qHash(item.
id());
37 : d_ptr(new ItemPrivate)
42 : d_ptr(new ItemPrivate(id))
47 : d_ptr(new ItemPrivate)
60 d_ptr->mId = identifier;
70 d_ptr->mRemoteId =
id;
75 return d_ptr->mRemoteId;
85 return d_ptr->mRemoteRevision;
90 return (d_ptr->mId >= 0);
96 return (!
isValid() && !other.
isValid()) || (d_ptr->mId == other.d_ptr->mId);
101 return (isValid() || other.
isValid()) && (d_ptr->mId != other.d_ptr->mId);
106 if (
this != &other) {
115 return d_ptr->mId < other.d_ptr->mId;
120 ItemChangeLog::instance()->attributeStorage(d_ptr).addAttribute(attr);
125 ItemChangeLog::instance()->attributeStorage(d_ptr).removeAttribute(type);
130 return ItemChangeLog::instance()->attributeStorage(d_ptr).hasAttribute(type);
135 return ItemChangeLog::instance()->attributeStorage(d_ptr).attributes();
140 ItemChangeLog::instance()->attributeStorage(d_ptr).clearAttributes();
145 return ItemChangeLog::instance()->attributeStorage(d_ptr).attribute(type);
150 return ItemChangeLog::instance()->attributeStorage(d_ptr).attribute(type);
155 if (!d_ptr->mParent) {
158 return *(d_ptr->mParent);
163 if (!d_ptr->mParent) {
164 return *(s_defaultParentCollection);
166 return *(d_ptr->mParent);
177 return d_ptr->mFlags;
182 d_ptr->mFlags.insert(name);
183 if (!d_ptr->mFlagsOverwritten) {
184 Item::Flags &deletedFlags = ItemChangeLog::instance()->deletedFlags(d_ptr);
185 auto iter = deletedFlags.
find(name);
186 if (iter != deletedFlags.
end()) {
187 deletedFlags.
erase(iter);
189 ItemChangeLog::instance()->addedFlags(d_ptr).insert(name);
196 d_ptr->mFlags.remove(name);
197 if (!d_ptr->mFlagsOverwritten) {
198 Item::Flags &addedFlags = ItemChangeLog::instance()->addedFlags(d_ptr);
199 auto iter = addedFlags.
find(name);
200 if (iter != addedFlags.
end()) {
201 addedFlags.
erase(iter);
203 ItemChangeLog::instance()->deletedFlags(d_ptr).insert(name);
210 d_ptr->mFlags =
flags;
211 d_ptr->mFlagsOverwritten =
true;
216 d_ptr->mFlags.clear();
217 d_ptr->mFlagsOverwritten =
true;
222 return d_ptr->mModificationTime;
227 d_ptr->mModificationTime = datetime;
232 return d_ptr->mFlags.contains(name);
235 void Item::setTags(
const Tag::List &list)
238 d_ptr->mTagsOverwritten =
true;
241 void Item::setTag(
const Tag &tag)
244 if (!d_ptr->mTagsOverwritten) {
245 Tag::List &deletedTags = ItemChangeLog::instance()->deletedTags(d_ptr);
249 ItemChangeLog::instance()->addedTags(d_ptr).push_back(tag);
254 void Item::clearTags()
256 d_ptr->mTags.clear();
257 d_ptr->mTagsOverwritten =
true;
260 void Item::clearTag(
const Tag &tag)
262 d_ptr->mTags.removeOne(tag);
263 if (!d_ptr->mTagsOverwritten) {
264 Tag::List &addedTags = ItemChangeLog::instance()->addedTags(d_ptr);
268 ItemChangeLog::instance()->deletedTags(d_ptr).push_back(tag);
273 bool Item::hasTag(
const Tag &tag)
const
275 return d_ptr->mTags.contains(tag);
285 return d_ptr->mRelations;
290 return ItemSerializer::parts(*
this);
297 ItemSerializer::serialize(*
this,
FullPayload, data, version);
303 ItemSerializer::deserialize(*
this,
FullPayload, data, 0, ItemSerializer::Internal);
308 d_ptr->mClearPayload =
true;
313 return d_ptr->mRevision;
318 d_ptr->mRevision = rev;
323 return d_ptr->mCollectionId;
328 d_ptr->mCollectionId = collectionId;
333 return d_ptr->mMimeType;
339 d_ptr->mSizeChanged =
true;
364 d_ptr->mVirtualReferences = collections;
369 return d_ptr->mVirtualReferences;
374 return d_ptr->hasMetaTypeId(-1);
382 query.addQueryItem(QStringLiteral(
"type"),
mimeType());
407 Internal::PayloadBase *Item::payloadBaseV2(
int spid,
int mtid)
const
409 return d_ptr->payloadBaseImpl(spid, mtid);
412 bool Item::ensureMetaTypeId(
int mtid)
const
415 if (d_ptr->mPayloads.empty()) {
420 if (d_ptr->hasMetaTypeId(mtid)) {
426 if (d_ptr->mConversionInProgress) {
433 Item converted = ItemSerializer::convert(*
this, mtid);
434 return d_ptr->movePayloadFrom(converted.d_ptr, mtid);
435 }
catch (
const std::exception &e) {
436 qCWarning(AKONADICORE_LOG) <<
"Item payload conversion threw:" << e.what();
439 qCCritical(AKONADICORE_LOG,
"conversion threw something not derived from std::exception: fix the program!");
444 static QString format_type(
int spid,
int mtid)
449 static QString format_types(
const PayloadContainer &container)
452 result.
reserve(container.size());
453 for (
auto it = container.begin(), end = container.end(); it != end; ++it) {
454 result.
push_back(format_type(it->sharedPointerId, it->metaTypeId));
462 return QStringLiteral(
"itemId: %1").
arg(
id);
464 return QStringLiteral(
"Item is not valid");
468 void Item::throwPayloadException(
int spid,
int mtid)
const
470 const auto reason = format_reason(
isValid(),
id());
472 if (d_ptr->mPayloads.empty()) {
473 qCDebug(AKONADICORE_LOG) <<
"Throwing PayloadException for Item" <<
id() <<
": No payload set";
474 throw PayloadException(QStringLiteral(
"No Item payload set (%1)").arg(reason));
476 const auto requestedType = format_type(spid, mtid);
477 const auto presentType = format_types(d_ptr->mPayloads);
478 qCDebug(AKONADICORE_LOG) <<
"Throwing PayloadException for Item" <<
id() <<
": Wrong payload type (requested:" << requestedType
479 <<
"; present: " << presentType <<
"), item mime type is" <<
mimeType();
480 throw PayloadException(QStringLiteral(
"Wrong Item payload type (requested: %1; present: %2, %3)").arg(requestedType, presentType, reason));
484 void Item::setPayloadBaseV2(
int spid,
int mtid, std::unique_ptr<Internal::PayloadBase> &p)
486 d_ptr->setPayloadBaseImpl(spid, mtid, p,
false);
489 void Item::addPayloadBaseVariant(
int spid,
int mtid, std::unique_ptr<Internal::PayloadBase> &p)
const
491 d_ptr->setPayloadBaseImpl(spid, mtid, p,
true);
496 return d_ptr->mCachedPayloadParts;
501 d_ptr->mCachedPayloadParts = cachedParts;
506 return ItemSerializer::availableParts(*
this);
512 result.
reserve(d_ptr->mPayloads.size());
514 for (
auto it = d_ptr->mPayloads.begin(), end = d_ptr->mPayloads.end(); it != end; ++it) {
515 result.
insert(std::upper_bound(result.
begin(), result.
end(), it->metaTypeId), it->metaTypeId);
525 ItemSerializer::deserialize(*
this,
"RFC822", filePath.
toUtf8(), 0, ItemSerializer::Foreign);
526 d_ptr->mPayloadPath = filePath;
531 return d_ptr->mPayloadPath;
537 qCDebug(AKONADICORE_LOG) <<
"mimeType() = " <<
mimeType() <<
"; other.mimeType() = " << other.
mimeType();
538 qCDebug(AKONADICORE_LOG) <<
"id() = " <<
id() <<
"; other.id() = " << other.
id();
539 Q_ASSERT_X(
false,
"Item::apply",
"mimetype or id mismatch");
546 setTags(other.tags());
552 ItemChangeLog *changelog = ItemChangeLog::instance();
553 changelog->attributeStorage(d_ptr) = changelog->attributeStorage(other.d_ptr);
555 ItemSerializer::apply(*
this, other);
556 d_ptr->resetChangeLog();
bool isValid() const
Returns whether the item is valid.
@ UrlWithMimeType
A url with identifier and mimetype.
void setSize(qint64 size)
Set the size of the item in bytes.
void setRevision(int revision)
Sets the revision number of the item.
const T * attribute() const
Returns the attribute of the requested type or 0 if it is not available.
Collection::List virtualReferences() const
Lists virtual collections that this item is linked to.
bool hasFlag(const QByteArray &name) const
Returns whether the flag with the given name is set in the item.
QString number(int n, int base)
void setPayloadFromData(const QByteArray &data)
Sets the payload based on the canonical representation normally used for data of this mime type.
QSet::iterator erase(QSet::iterator pos)
UrlType
Describes the type of url which is returned in url().
Flags flags() const
Returns all flags of this item.
QString scheme() const const
static const char FullPayload[]
Describes the part name that is used to fetch the full payload of an item.
QSet::iterator find(const T &value)
qlonglong toLongLong(bool *ok, int base) const const
QDateTime modificationTime() const
Returns the timestamp of the last modification of this item.
void setParentCollection(const Collection &parent)
Set the parent collection of this object.
Represents a collection of PIM items.
bool operator!=(const Item &other) const
Returns whether the item's id does not equal the id of the other item.
void setVirtualReferences(const Collection::List &collections)
Sets the virtual collections that this item is linked into.
void setMimeType(const QString &mimeType)
Sets the mime type of the item to mimeType.
void push_back(const T &value)
void clearAttributes()
Removes and deletes all attributes of the item.
Provides interface for custom attributes for Entity.
void setGid(const QString &gid)
Sets the gid of the entity.
int revision() const
Returns the revision number of the item.
bool contains(const T &value) const const
bool hasAttribute() const
Returns whether the item has an attribute of the requested type.
bool hasPayload() const
Returns whether the item has a payload object.
QList< int > availablePayloadMetaTypeIds() const
Returns a list of metatype-ids, describing the different variants of payload that are currently conta...
Q_GLOBAL_STATIC(Internal::StaticControl, s_instance) class ControlPrivate
void setScheme(const QString &scheme)
~Item()
Destroys the item.
qint64 size() const
Returns the size of the items in bytes.
bool operator==(const Item &other) const
Returns whether this item's id equals the id of the other item.
qint64 Id
Describes the unique id type.
QString mimeType() const
Returns the mime type of the item.
Attribute::List attributes() const
Returns a list of all attributes of the item.
QUrl url(UrlType type=UrlShort) const
Returns the url of the item.
void setModificationTime(const QDateTime &datetime)
Sets the timestamp of the last modification of this item.
Collection::Id storageCollectionId() const
Returns the unique identifier of the collection this item is stored in.
QString remoteRevision() const
Returns the remote revision of the item.
QString gid() const
Returns the gid of the entity.
static Item fromUrl(const QUrl &url)
Creates an item from the given url.
bool removeOne(const T &value)
QByteArray toUtf8() const const
Collection parentCollection() const
Returns the parent collection of this object.
void setRemoteId(const QString &id)
Sets the remote id of the item.
Item & operator=(const Item &other)
Assigns the other to this item and returns a reference to this item.
QString join(const QString &separator) const const
void removeAttribute()
Removes and deletes the attribute of the requested type.
QString payloadPath() const
Returns path to the payload file set by setPayloadPath()
void setPayloadPath(const QString &filePath)
Sets a path to a file with full payload.
void insert(int i, const T &value)
void setQuery(const QString &query, QUrl::ParsingMode mode)
void setRemoteRevision(const QString &revision)
Sets the remote revision of the item.
Id id() const
Returns the unique identifier of the item.
Relation::List relations() const
Returns all relations of this item.
QString arg(qlonglong a, int fieldWidth, int base, QChar fillChar) const const
bool operator<(const Item &other) const
void addAttribute(Attribute *attribute)
Adds an attribute to the item.
void clearPayload()
Marks that the payload shall be cleared from the cache when this item is passed to an ItemModifyJob t...
QSet< QByteArray > availablePayloadParts() const
Returns the parts available for this item.
const char * name(StandardAction id)
void clearFlags()
Removes all flags from the item.
Item()
Creates a new item.
QSet< QByteArray > cachedPayloadParts() const
Returns the parts available for this item in the cache.
QByteArray payloadData() const
Returns the full payload in its canonical representation, e.g.
QString queryItemValue(const QString &key, QUrl::ComponentFormattingOptions encoding) const const
void setFlags(const Flags &flags)
Overwrites all flags of the item by the given flags.
QSet< QByteArray > loadedPayloadParts() const
Returns the list of loaded payload parts.
void apply(const Item &other)
Applies the parts of Item other to this item.
void clearFlag(const QByteArray &name)
Removes the flag with the given name from the item.
void setFlag(const QByteArray &name)
Sets the flag with the given name in the item.
void setId(Id identifier)
Sets the unique identifier of the item.
qint64 Id
Describes the unique id type.
QString remoteId() const
Returns the remote id of the item.
Represents a PIM item stored in Akonadi storage.
Helper integration between Akonadi and Qt.
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Sun Oct 1 2023 04:01:48 by
doxygen 1.8.17 written
by
Dimitri van Heesch, © 1997-2006
KDE's Doxygen guidelines are available online.