Akonadi

xmldocument.h
1 /*
2  SPDX-FileCopyrightText: 2009 Volker Krause <[email protected]>
3 
4  SPDX-License-Identifier: LGPL-2.0-or-later
5 */
6 
7 #pragma once
8 
9 #include "akonadi-xml_export.h"
10 
11 // AkonadiCore
12 #include <akonadi/collection.h>
13 #include <akonadi/item.h>
14 
15 #include <QDomDocument>
16 
17 #include <memory>
18 
19 namespace Akonadi
20 {
21 class XmlDocumentPrivate;
22 
23 /**
24  Represents a document of the KNUT XML serialization format for Akonadi objects.
25 */
26 class AKONADI_XML_EXPORT XmlDocument
27 {
28 public:
29  /**
30  Creates an empty document.
31  */
32  XmlDocument();
33 
34  /**
35  Creates a new XmlDocument object and calls loadFile().
36 
37  @see loadFile()
38  */
39  explicit XmlDocument(const QString &fileName);
40  ~XmlDocument();
41 
42  /**
43  Parses the given XML file and validates it.
44  In case of an error, isValid() will return @c false and
45  lastError() will return an error message.
46 
47  @see isValid(), lastError()
48  */
49  bool loadFile(const QString &fileName);
50 
51  /**
52  Writes the current document into the given file.
53  */
54  bool writeToFile(const QString &fileName) const;
55 
56  /**
57  Returns true if the document could be parsed successfully.
58  @see lastError()
59  */
60  Q_REQUIRED_RESULT bool isValid() const;
61 
62  /**
63  Returns the last error occurred during file loading/parsing.
64  Empty if isValid() returns @c true.
65  @see isValid()
66  */
67  Q_REQUIRED_RESULT QString lastError() const;
68 
69  /**
70  Returns the DOM document for this XML document.
71  */
72  QDomDocument &document() const;
73 
74  /**
75  Returns the DOM element representing @p collection.
76  */
77  Q_REQUIRED_RESULT QDomElement collectionElement(const Collection &collection) const;
78 
79  /**
80  Returns the DOM element representing the item with the given remote id
81  */
82  Q_REQUIRED_RESULT QDomElement itemElementByRemoteId(const QString &rid) const;
83 
84  /**
85  * Returns the DOM element representing the collection with the given remote id
86  */
87  Q_REQUIRED_RESULT QDomElement collectionElementByRemoteId(const QString &rid) const;
88 
89  /**
90  Returns the collection with the given remote id.
91  */
92  Q_REQUIRED_RESULT Collection collectionByRemoteId(const QString &rid) const;
93 
94  /**
95  Returns the item with the given remote id.
96  */
97  Q_REQUIRED_RESULT Item itemByRemoteId(const QString &rid, bool includePayload = true) const;
98 
99  /**
100  Returns the collections defined in this document.
101  */
102  Q_REQUIRED_RESULT Collection::List collections() const;
103 
104  /**
105  Returns the tags defined in this document.
106  */
107  Q_REQUIRED_RESULT Tag::List tags() const;
108 
109  /**
110  Returns the immediate child collections of @p parentCollection.
111  */
112  Q_REQUIRED_RESULT Collection::List childCollections(const Collection &parentCollection) const;
113 
114  /**
115  Returns the items in the given collection.
116  */
117  Q_REQUIRED_RESULT Item::List items(const Collection &collection, bool includePayload = true) const;
118 
119 private:
120  Q_DISABLE_COPY(XmlDocument)
121  std::unique_ptr<XmlDocumentPrivate> const d;
122 };
123 
124 }
125 
Represents a document of the KNUT XML serialization format for Akonadi objects.
Definition: xmldocument.h:26
Represents a collection of PIM items.
Definition: collection.h:61
Represents a PIM item stored in Akonadi storage.
Definition: item.h:104
Helper integration between Akonadi and Qt.
This file is part of the KDE documentation.
Documentation copyright © 1996-2022 The KDE developers.
Generated on Sat Jun 25 2022 06:00:33 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.