24#include <akonadi/attributefactory.h>
25#include <akonadi/tag.h>
31Attribute* XmlReader::elementToAttribute(
const QDomElement& elem)
33 if ( elem.isNull() || elem.tagName() != Format::Tag::attribute() )
35 Attribute *attr = AttributeFactory::createAttribute( elem.attribute( Format::Attr::attributeType() ).toUtf8() );
41void XmlReader::readAttributes(
const QDomElement& elem,
Entity& entity)
45 const QDomNodeList children = elem.childNodes();
46 for (
int i = 0; i < children.count(); ++i ) {
47 const QDomElement attrElem = children.at( i ).toElement();
54Collection XmlReader::elementToCollection(
const QDomElement& elem)
56 if ( elem.isNull() || elem.tagName() != Format::Tag::collection() )
60 c.
setRemoteId( elem.attribute( Format::Attr::remoteId() ) );
61 c.
setName( elem.attribute( Format::Attr::collectionName() ) );
62 c.
setContentMimeTypes( elem.attribute( Format::Attr::collectionContentTypes() ).split( QLatin1Char(
',') ) );
63 XmlReader::readAttributes( elem, c );
65 const QDomElement parentElem = elem.parentNode().toElement();
66 if ( !parentElem.isNull() && parentElem.tagName() == Format::Tag::collection() )
77 if ( elem.tagName() == Format::Tag::collection() )
79 const QDomNodeList children = elem.childNodes();
80 for (
int i = 0; i < children.count(); i++ ) {
81 const QDomElement child = children.at( i ).toElement();
82 if ( child.isNull() || child.tagName() != Format::Tag::collection() )
89Tag XmlReader::elementToTag(
const QDomElement& elem)
91 if ( elem.isNull() || elem.tagName() != Format::Tag::tag() )
95 t.setRemoteId( elem.attribute( Format::Attr::remoteId() ).toUtf8() );
96 t.setName( elem.attribute( Format::Attr::name() ) );
97 t.setGid( elem.attribute( Format::Attr::gid() ).toUtf8() );
98 t.setType( elem.attribute( Format::Attr::type() ).toUtf8() );
111Tag::List XmlReader::readTags(
const QDomElement& elem)
116 if ( elem.tagName() == Format::Tag::tag() )
118 const QDomNodeList children = elem.childNodes();
119 for (
int i = 0; i < children.count(); i++ ) {
120 const QDomElement child = children.at( i ).toElement();
121 if ( child.isNull() || child.tagName() != Format::Tag::tag() )
128Item XmlReader::elementToItem(
const QDomElement& elem,
bool includePayload)
130 Item item( elem.attribute( Format::Attr::itemMimeType(), QLatin1String(
"application/octet-stream") ) );
131 item.setRemoteId( elem.attribute( Format::Attr::remoteId() ) );
132 XmlReader::readAttributes( elem, item );
134 const QDomNodeList children = elem.childNodes();
135 for (
int i = 0; i < children.count(); ++i ) {
136 const QDomElement subElem = children.at( i ).toElement();
137 if ( subElem.isNull() )
139 if ( subElem.tagName() == Format::Tag::flag() ) {
140 item.setFlag( subElem.text().toUtf8() );
141 }
else if ( subElem.tagName() == Format::Tag::tag() ) {
143 tag.setRemoteId( subElem.text().toUtf8() );
145 }
else if ( includePayload && subElem.tagName() == Format::Tag::payload() ) {
146 const QByteArray payloadData = subElem.text().toUtf8();
147 item.setPayloadFromData( payloadData );
Provides interface for custom attributes for Entity.
virtual void deserialize(const QByteArray &data)=0
Sets the data of this attribute, using the same encoding as returned by toByteArray().
Represents a collection of PIM items.
void setName(const QString &name)
Sets the i18n'ed name of the collection.
QList< Collection > List
Describes a list of collections.
void setContentMimeTypes(const QStringList &types)
Sets the list of possible content mime types.
The base class for Item and Collection.
Collection parentCollection() const
Returns the parent collection of this object.
void addAttribute(Attribute *attribute)
Adds an attribute to the entity.
void setRemoteId(const QString &id)
Sets the remote id of the entity.
AKONADI_XML_EXPORT Attribute * elementToAttribute(const QDomElement &elem)
Converts an attribute element.
AKONADI_XML_EXPORT Collection elementToCollection(const QDomElement &elem)
Converts a collection element.
AKONADI_XML_EXPORT Tag elementToTag(const QDomElement &elem)
Converts a tag element.
AKONADI_XML_EXPORT Collection::List readCollections(const QDomElement &elem)
Reads recursively all collections starting from the given DOM element.
AKONADI_XML_EXPORT Tag::List readTags(const QDomElement &elem)
Reads recursively all tags starting from the given DOM element.
FreeBusyManager::Singleton.