KItinerary

file.h
1/*
2 SPDX-FileCopyrightText: 2019 Volker Krause <vkrause@kde.org>
3
4 SPDX-License-Identifier: LGPL-2.0-or-later
5*/
6
7#pragma once
8
9#include "kitinerary_export.h"
10
11#include <QList>
12
13#include <memory>
14
15namespace KPkPass {
16class Pass;
17}
18
19class QIODevice;
20class QString;
21class QVariant;
22
23namespace KItinerary {
24
25class FilePrivate;
26
27/** A file containing a bundle of reservations and associated documents.
28 * This is used to export or transfer a set of reservation-related documents
29 * while keeping the associations between them.
30 *
31 * A KItinerary::File can contain the following elements:
32 * - JSON-LD reservation objects (see KItinerary::Reservation). Each reservation has a UUID.
33 * - PkPass files. Their identifier is determined by their pass type identifier and their serial number.
34 * - JSON-LD document objects (see KItinerary::CreativeWork) and their associated file content. Each document has a UUID.
35 * - Application-specific data in custom namespaces.
36 */
37class KITINERARY_EXPORT File
38{
39public:
40 explicit File();
41 /** Create a File instance for the file named @p fileName. */
42 explicit File(const QString &fileName);
43 /** Create a File instance for the given i/o device. */
44 explicit File(QIODevice *device);
45 File(const File&) = delete;
46 File(File&&);
47 ~File();
48 File& operator=(const File&) = delete;
49 File& operator=(File&&);
50
51 /** Sets the file name. Needs to be done before calling open(). */
52 void setFileName(const QString &fileName);
53
54 enum OpenMode { Read, Write };
55 /** Open the file for reading or writing. A filename needs to be set before calling this.
56 * All read/write operations require the file to be open as a precondition.
57 */
58 bool open(OpenMode mode) const;
59 /** Error message in case opening the file failed. */
60 QString errorString() const;
61 /** Save and close the file. Automatically called from the dtor. */
62 void close();
63
64 /** Lists the identifiers of all reservations in this file. */
65 QList<QString> reservations() const;
66 /** Loads the reservation with the given identifier. */
67 QVariant reservation(const QString &resId) const;
68 /** Add a reservation to this file. A new unique identifier will be generated for the reservation. */
69 void addReservation(const QVariant &res);
70 /** Add a reservation to this file. The given identifier will be used. */
71 void addReservation(const QString &id, const QVariant &res);
72
73 /** Returns the pass identifier used in here for @p pass. */
74 static QString passId(const KPkPass::Pass *pass);
75 static QString passId(const QString &passTypeIdenfier, const QString &serialNumber);
76
77 /** Lists all pkpass files in this file. */
78 QList<QString> passes() const;
79 /** Pass data for the given pass id. */
80 QByteArray passData(const QString &passId) const;
81 /** Add a pkpass file to this file. */
82 void addPass(KPkPass::Pass *pass, const QByteArray &rawData);
83 /** Add a pkpass file with the given pass id. */
84 void addPass(const QString &passId, const QByteArray &rawData);
85
86 /** Makes sure the resulting file name is something that can safely be used without messing up the
87 * file system or archive structure.
88 */
89 static QString normalizeDocumentFileName(const QString &name);
90
91 /** Lists all document identifiers. */
92 QList<QString> documents() const;
93 /** Loads the document meta data of document @p id. */
94 QVariant documentInfo(const QString &id) const;
95 /** Loads the content of document @p id. */
96 QByteArray documentData(const QString &id) const;
97 /** Adds a document and associated meta data to the file. */
98 void addDocument(const QString &id, const QVariant &docInfo, const QByteArray &docData);
99
100 /** List custom data in the given namespace. */
101 QList<QString> listCustomData(const QString &scope) const;
102 /** Returns the custom data in the given namespace and with the given id. */
103 QByteArray customData(const QString &scope, const QString &id) const;
104 /** Adds a custom data element with identifier @p id in to namespace @p scope. */
105 void addCustomData(const QString &scope, const QString &id, const QByteArray &data);
106
107private:
108 std::unique_ptr<FilePrivate> d;
109};
110
111}
112
A file containing a bundle of reservations and associated documents.
Definition file.h:38
Classes for reservation/travel data models, data extraction and data augmentation.
Definition berelement.h:17
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Tue Mar 26 2024 11:14:49 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.