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

akonadi

  • sources
  • kde-4.12
  • kdepimlibs
  • 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 
26 #include <QStringList>
27 
28 using namespace Akonadi;
29 
30 Attribute* XmlReader::elementToAttribute(const QDomElement& elem)
31 {
32  if ( elem.isNull() || elem.tagName() != Format::Tag::attribute() )
33  return 0;
34  Attribute *attr = AttributeFactory::createAttribute( elem.attribute( Format::Attr::attributeType() ).toUtf8() );
35  Q_ASSERT( attr );
36  attr->deserialize( elem.text().toUtf8() );
37  return attr;
38 }
39 
40 void XmlReader::readAttributes(const QDomElement& elem, Entity& entity)
41 {
42  if ( elem.isNull() )
43  return;
44  const QDomNodeList children = elem.childNodes();
45  for ( int i = 0; i < children.count(); ++i ) {
46  const QDomElement attrElem = children.at( i ).toElement();
47  Attribute *attr = elementToAttribute( attrElem );
48  if ( attr )
49  entity.addAttribute( attr );
50  }
51 }
52 
53 Collection XmlReader::elementToCollection(const QDomElement& elem)
54 {
55  if ( elem.isNull() || elem.tagName() != Format::Tag::collection() )
56  return Collection();
57 
58  Collection c;
59  c.setRemoteId( elem.attribute( Format::Attr::remoteId() ) );
60  c.setName( elem.attribute( Format::Attr::collectionName() ) );
61  c.setContentMimeTypes( elem.attribute( Format::Attr::collectionContentTypes() ).split( QLatin1Char(',') ) );
62  XmlReader::readAttributes( elem, c );
63 
64  const QDomElement parentElem = elem.parentNode().toElement();
65  if ( !parentElem.isNull() && parentElem.tagName() == Format::Tag::collection() )
66  c.parentCollection().setRemoteId( parentElem.attribute( Format::Attr::remoteId() ) );
67 
68  return c;
69 }
70 
71 Collection::List XmlReader::readCollections(const QDomElement& elem)
72 {
73  Collection::List rv;
74  if ( elem.isNull() )
75  return rv;
76  if ( elem.tagName() == Format::Tag::collection() )
77  rv += elementToCollection( elem );
78  const QDomNodeList children = elem.childNodes();
79  for ( int i = 0; i < children.count(); i++ ) {
80  const QDomElement child = children.at( i ).toElement();
81  if ( child.isNull() || child.tagName() != Format::Tag::collection() )
82  continue;
83  rv += readCollections( child );
84  }
85  return rv;
86 }
87 
88 Item XmlReader::elementToItem(const QDomElement& elem, bool includePayload)
89 {
90  Item item( elem.attribute( Format::Attr::itemMimeType(), QLatin1String("application/octet-stream") ) );
91  item.setRemoteId( elem.attribute( Format::Attr::remoteId() ) );
92  XmlReader::readAttributes( elem, item );
93 
94  const QDomNodeList children = elem.childNodes();
95  for ( int i = 0; i < children.count(); ++i ) {
96  const QDomElement subElem = children.at( i ).toElement();
97  if ( subElem.isNull() )
98  continue;
99  if ( subElem.tagName() == Format::Tag::flag() ) {
100  item.setFlag( subElem.text().toUtf8() );
101  } else if ( includePayload && subElem.tagName() == Format::Tag::payload() ) {
102  const QByteArray payloadData = subElem.text().toUtf8();
103  item.setPayloadFromData( payloadData );
104  }
105  }
106 
107  return item;
108 }
Akonadi::XmlReader::elementToItem
AKONADI_XML_EXPORT Item elementToItem(const QDomElement &elem, bool includePayload=true)
Converts an item element.
Definition: xmlreader.cpp:88
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:40
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:71
Akonadi::Collection
Represents a collection of PIM items.
Definition: collection.h:75
Akonadi::XmlReader::elementToCollection
AKONADI_XML_EXPORT Collection elementToCollection(const QDomElement &elem)
Converts a collection element.
Definition: xmlreader.cpp:53
Akonadi::Entity::setRemoteId
void setRemoteId(const QString &id)
Sets the remote id of the entity.
Definition: entity.cpp:77
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::Attribute
Provides interface for custom attributes for Entity.
Definition: attribute.h:138
Akonadi::Collection::setName
void setName(const QString &name)
Sets the i18n'ed name of the collection.
Definition: collection.cpp:93
Akonadi::Entity::parentCollection
Collection parentCollection() const
Returns the parent collection of this object.
Definition: entity.cpp:186
Akonadi::Entity::addAttribute
void addAttribute(Attribute *attribute)
Adds an attribute to the entity.
Definition: entity.cpp:126
Akonadi::Entity
The base class for Item and Collection.
Definition: entity.h:59
Akonadi::AttributeFactory::createAttribute
static Attribute * createAttribute(const QByteArray &type)
Creates an entity attribute object of the given type.
Definition: attributefactory.cpp:132
Akonadi::XmlReader::elementToAttribute
AKONADI_XML_EXPORT Attribute * elementToAttribute(const QDomElement &elem)
Converts an attribute element.
Definition: xmlreader.cpp:30
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
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 23:00:28 by doxygen 1.8.7 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 API Reference

Skip menu "kdepimlibs API Reference"
  • akonadi
  •   contact
  •   kmime
  •   socialutils
  • kabc
  • kalarmcal
  • kblog
  • kcal
  • kcalcore
  • kcalutils
  • kholidays
  • kimap
  • kldap
  • kmbox
  • kmime
  • kpimidentities
  • kpimtextedit
  • kresources
  • ktnef
  • kxmlrpcclient
  • microblog

Search



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