File indexing completed on 2025-01-05 04:47:12
0001 /* 0002 SPDX-FileCopyrightText: 2009 Volker Krause <vkrause@kde.org> 0003 0004 SPDX-License-Identifier: LGPL-2.0-or-later 0005 */ 0006 0007 #pragma once 0008 0009 #include "akonadi-xml_export.h" 0010 0011 // AkonadiCore 0012 #include "akonadi/collection.h" 0013 #include "akonadi/item.h" 0014 0015 #include <QDomDocument> 0016 0017 #include <memory> 0018 0019 namespace Akonadi 0020 { 0021 class XmlDocumentPrivate; 0022 0023 /** 0024 Represents a document of the KNUT XML serialization format for Akonadi objects. 0025 */ 0026 class AKONADI_XML_EXPORT XmlDocument 0027 { 0028 public: 0029 /** 0030 Creates an empty document. 0031 */ 0032 XmlDocument(); 0033 0034 /** 0035 Creates a new XmlDocument object and calls loadFile(). 0036 0037 @see loadFile() 0038 */ 0039 explicit XmlDocument(const QString &fileName, const QString &xsdFile = {}); 0040 ~XmlDocument(); 0041 0042 /** 0043 Parses the given XML file and validates it. 0044 In case of an error, isValid() will return @c false and 0045 lastError() will return an error message. 0046 0047 @see isValid(), lastError() 0048 */ 0049 bool loadFile(const QString &fileName, const QString &xsdFile = {}); 0050 0051 /** 0052 Writes the current document into the given file. 0053 */ 0054 bool writeToFile(const QString &fileName) const; 0055 0056 /** 0057 Returns true if the document could be parsed successfully. 0058 @see lastError() 0059 */ 0060 [[nodiscard]] bool isValid() const; 0061 0062 /** 0063 Returns the last error occurred during file loading/parsing. 0064 Empty if isValid() returns @c true. 0065 @see isValid() 0066 */ 0067 [[nodiscard]] QString lastError() const; 0068 0069 /** 0070 Returns the DOM document for this XML document. 0071 */ 0072 QDomDocument &document() const; 0073 0074 /** 0075 Returns the DOM element representing @p collection. 0076 */ 0077 [[nodiscard]] QDomElement collectionElement(const Collection &collection) const; 0078 0079 /** 0080 Returns the DOM element representing the item with the given remote id 0081 */ 0082 [[nodiscard]] QDomElement itemElementByRemoteId(const QString &rid) const; 0083 0084 /** 0085 * Returns the DOM element representing the collection with the given remote id 0086 */ 0087 [[nodiscard]] QDomElement collectionElementByRemoteId(const QString &rid) const; 0088 0089 /** 0090 Returns the collection with the given remote id. 0091 */ 0092 [[nodiscard]] Collection collectionByRemoteId(const QString &rid) const; 0093 0094 /** 0095 Returns the item with the given remote id. 0096 */ 0097 [[nodiscard]] Item itemByRemoteId(const QString &rid, bool includePayload = true) const; 0098 0099 /** 0100 Returns the collections defined in this document. 0101 */ 0102 [[nodiscard]] Collection::List collections() const; 0103 0104 /** 0105 Returns the tags defined in this document. 0106 */ 0107 [[nodiscard]] Tag::List tags() const; 0108 0109 /** 0110 Returns the immediate child collections of @p parentCollection. 0111 */ 0112 [[nodiscard]] Collection::List childCollections(const Collection &parentCollection) const; 0113 0114 /** 0115 Returns the items in the given collection. 0116 */ 0117 [[nodiscard]] Item::List items(const Collection &collection, bool includePayload = true) const; 0118 0119 private: 0120 Q_DISABLE_COPY(XmlDocument) 0121 std::unique_ptr<XmlDocumentPrivate> const d; 0122 }; 0123 0124 }