Akonadi

xmldocument.h
1/*
2 SPDX-FileCopyrightText: 2009 Volker Krause <vkrause@kde.org>
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
19namespace Akonadi
20{
21class XmlDocumentPrivate;
22
23/**
24 Represents a document of the KNUT XML serialization format for Akonadi objects.
25*/
26class AKONADI_XML_EXPORT XmlDocument
27{
28public:
29 /**
30 Creates an empty document.
31 */
33
34 /**
35 Creates a new XmlDocument object and calls loadFile().
36
37 @see loadFile()
38 */
39 explicit XmlDocument(const QString &fileName, const QString &xsdFile = {});
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, const QString &xsdFile = {});
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 [[nodiscard]] 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 [[nodiscard]] 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 [[nodiscard]] QDomElement collectionElement(const Collection &collection) const;
78
79 /**
80 Returns the DOM element representing the item with the given remote id
81 */
82 [[nodiscard]] QDomElement itemElementByRemoteId(const QString &rid) const;
83
84 /**
85 * Returns the DOM element representing the collection with the given remote id
86 */
87 [[nodiscard]] QDomElement collectionElementByRemoteId(const QString &rid) const;
88
89 /**
90 Returns the collection with the given remote id.
91 */
92 [[nodiscard]] Collection collectionByRemoteId(const QString &rid) const;
93
94 /**
95 Returns the item with the given remote id.
96 */
97 [[nodiscard]] Item itemByRemoteId(const QString &rid, bool includePayload = true) const;
98
99 /**
100 Returns the collections defined in this document.
101 */
102 [[nodiscard]] Collection::List collections() const;
103
104 /**
105 Returns the tags defined in this document.
106 */
107 [[nodiscard]] Tag::List tags() const;
108
109 /**
110 Returns the immediate child collections of @p parentCollection.
111 */
112 [[nodiscard]] Collection::List childCollections(const Collection &parentCollection) const;
113
114 /**
115 Returns the items in the given collection.
116 */
117 [[nodiscard]] Item::List items(const Collection &collection, bool includePayload = true) const;
118
119private:
120 Q_DISABLE_COPY(XmlDocument)
121 std::unique_ptr<XmlDocumentPrivate> const d;
122};
123
124}
Represents a collection of PIM items.
Definition collection.h:62
Represents a PIM item stored in Akonadi storage.
Definition item.h:100
Represents a document of the KNUT XML serialization format for Akonadi objects.
Definition xmldocument.h:27
Helper integration between Akonadi and Qt.
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Oct 4 2024 11:57:21 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.