• Skip to content
  • Skip to link menu
  • KDE API Reference
  • kdepimlibs-4.14.10 API Reference
  • KDE Home
  • Contact Us
 

akonadi

  • akonadi
  • xml
xmlreader.cpp
1/*
2 Copyright (c) 2009 Volker Krause <vkrause@kde.org>
3 Copyright (c) 2009 Igor Trindade Oliveira <igor_trindade@yahoo.com.br>
4
5 This library is free software; you can redistribute it and/or modify it
6 under the terms of the GNU Library General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or (at your
8 option) any later version.
9
10 This library is distributed in the hope that it will be useful, but WITHOUT
11 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
13 License for more details.
14
15 You should have received a copy of the GNU Library General Public License
16 along with this library; see the file COPYING.LIB. If not, write to the
17 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
18 02110-1301, USA.
19*/
20
21#include "xmlreader.h"
22#include "format_p.h"
23
24#include <akonadi/attributefactory.h>
25#include <akonadi/tag.h>
26
27#include <QStringList>
28
29using namespace Akonadi;
30
31Attribute* XmlReader::elementToAttribute(const QDomElement& elem)
32{
33 if ( elem.isNull() || elem.tagName() != Format::Tag::attribute() )
34 return 0;
35 Attribute *attr = AttributeFactory::createAttribute( elem.attribute( Format::Attr::attributeType() ).toUtf8() );
36 Q_ASSERT( attr );
37 attr->deserialize( elem.text().toUtf8() );
38 return attr;
39}
40
41void XmlReader::readAttributes(const QDomElement& elem, Entity& entity)
42{
43 if ( elem.isNull() )
44 return;
45 const QDomNodeList children = elem.childNodes();
46 for ( int i = 0; i < children.count(); ++i ) {
47 const QDomElement attrElem = children.at( i ).toElement();
48 Attribute *attr = elementToAttribute( attrElem );
49 if ( attr )
50 entity.addAttribute( attr );
51 }
52}
53
54Collection XmlReader::elementToCollection(const QDomElement& elem)
55{
56 if ( elem.isNull() || elem.tagName() != Format::Tag::collection() )
57 return Collection();
58
59 Collection c;
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 );
64
65 const QDomElement parentElem = elem.parentNode().toElement();
66 if ( !parentElem.isNull() && parentElem.tagName() == Format::Tag::collection() )
67 c.parentCollection().setRemoteId( parentElem.attribute( Format::Attr::remoteId() ) );
68
69 return c;
70}
71
72Collection::List XmlReader::readCollections(const QDomElement& elem)
73{
74 Collection::List rv;
75 if ( elem.isNull() )
76 return rv;
77 if ( elem.tagName() == Format::Tag::collection() )
78 rv += elementToCollection( elem );
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() )
83 continue;
84 rv += readCollections( child );
85 }
86 return rv;
87}
88
89Tag XmlReader::elementToTag(const QDomElement& elem)
90{
91 if ( elem.isNull() || elem.tagName() != Format::Tag::tag() )
92 return Tag();
93
94 Tag t;
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() );
99
100 //TODO Implement rid parent support in TagCreateJob first
101 // const QDomElement parentElem = elem.parentNode().toElement();
102 // if ( !parentElem.isNull() && parentElem.tagName() == Format::Tag::tag() ) {
103 // Tag parent;
104 // parent.setRemoteId( parentElem.attribute( Format::Attr::remoteId() ).toLatin1() );
105 // t.setParent( parent );
106 // }
107
108 return t;
109}
110
111Tag::List XmlReader::readTags(const QDomElement& elem)
112{
113 Tag::List rv;
114 if ( elem.isNull() )
115 return rv;
116 if ( elem.tagName() == Format::Tag::tag() )
117 rv += elementToTag( elem );
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() )
122 continue;
123 rv += readTags( child );
124 }
125 return rv;
126}
127
128Item XmlReader::elementToItem(const QDomElement& elem, bool includePayload)
129{
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 );
133
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() )
138 continue;
139 if ( subElem.tagName() == Format::Tag::flag() ) {
140 item.setFlag( subElem.text().toUtf8() );
141 } else if ( subElem.tagName() == Format::Tag::tag() ) {
142 Tag tag;
143 tag.setRemoteId( subElem.text().toUtf8() );
144 item.setTag( tag );
145 } else if ( includePayload && subElem.tagName() == Format::Tag::payload() ) {
146 const QByteArray payloadData = subElem.text().toUtf8();
147 item.setPayloadFromData( payloadData );
148 }
149 }
150
151 return item;
152}
Akonadi::AttributeFactory::createAttribute
static Attribute * createAttribute(const QByteArray &type)
Creates an entity attribute object of the given type.
Definition: attributefactory.cpp:147
Akonadi::Attribute
Provides interface for custom attributes for Entity.
Definition: attribute.h:139
Akonadi::Attribute::deserialize
virtual void deserialize(const QByteArray &data)=0
Sets the data of this attribute, using the same encoding as returned by toByteArray().
Akonadi::Collection
Represents a collection of PIM items.
Definition: collection.h:76
Akonadi::Collection::setName
void setName(const QString &name)
Sets the i18n'ed name of the collection.
Definition: collection.cpp:93
Akonadi::Collection::List
QList< Collection > List
Describes a list of collections.
Definition: collection.h:81
Akonadi::Collection::setContentMimeTypes
void setContentMimeTypes(const QStringList &types)
Sets the list of possible content mime types.
Definition: collection.cpp:120
Akonadi::Entity
The base class for Item and Collection.
Definition: entity.h:60
Akonadi::Entity::parentCollection
Collection parentCollection() const
Returns the parent collection of this object.
Definition: entity.cpp:185
Akonadi::Entity::addAttribute
void addAttribute(Attribute *attribute)
Adds an attribute to the entity.
Definition: entity.cpp:127
Akonadi::Entity::setRemoteId
void setRemoteId(const QString &id)
Sets the remote id of the entity.
Definition: entity.cpp:77
Akonadi::Tag
An Akonadi Tag.
Definition: tag.h:44
Akonadi::XmlReader::elementToAttribute
AKONADI_XML_EXPORT Attribute * elementToAttribute(const QDomElement &elem)
Converts an attribute element.
Definition: xmlreader.cpp:31
Akonadi::XmlReader::elementToItem
AKONADI_XML_EXPORT Item elementToItem(const QDomElement &elem, bool includePayload=true)
Converts an item element.
Definition: xmlreader.cpp:128
Akonadi::XmlReader::readAttributes
AKONADI_XML_EXPORT void readAttributes(const QDomElement &elem, Entity &entity)
Reads all attributes that are immediate children of elem and adds them to entity.
Definition: xmlreader.cpp:41
Akonadi::XmlReader::elementToCollection
AKONADI_XML_EXPORT Collection elementToCollection(const QDomElement &elem)
Converts a collection element.
Definition: xmlreader.cpp:54
Akonadi::XmlReader::elementToTag
AKONADI_XML_EXPORT Tag elementToTag(const QDomElement &elem)
Converts a tag element.
Definition: xmlreader.cpp:89
Akonadi::XmlReader::readCollections
AKONADI_XML_EXPORT Collection::List readCollections(const QDomElement &elem)
Reads recursively all collections starting from the given DOM element.
Definition: xmlreader.cpp:72
Akonadi::XmlReader::readTags
AKONADI_XML_EXPORT Tag::List readTags(const QDomElement &elem)
Reads recursively all tags starting from the given DOM element.
Definition: xmlreader.cpp:111
Akonadi
FreeBusyManager::Singleton.
Definition: actionstatemanager_p.h:28
This file is part of the KDE documentation.
Documentation copyright © 1996-2022 The KDE developers.
Generated on Thu Jul 21 2022 00:00:00 by doxygen 1.9.5 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

akonadi

Skip menu "akonadi"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • Modules
  • Related Pages

kdepimlibs-4.14.10 API Reference

Skip menu "kdepimlibs-4.14.10 API Reference"
  • akonadi
  •   contact
  •   kmime
  •   socialutils
  • kabc
  • kalarmcal
  • kblog
  • kcal
  • kcalcore
  • kcalutils
  • kholidays
  • kimap
  • kioslave
  •   imap4
  •   mbox
  •   nntp
  • kldap
  • kmbox
  • kmime
  • kontactinterface
  • kpimidentities
  • kpimtextedit
  • kpimutils
  • kresources
  • ktnef
  • kxmlrpcclient
  • mailtransport
  • microblog
  • qgpgme
  • syndication
  •   atom
  •   rdf
  •   rss2
Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal