Akonadi

parthelper.h
1/***************************************************************************
2 * SPDX-FileCopyrightText: 2009 Andras Mantia <amantia@kde.org> *
3 * *
4 * SPDX-License-Identifier: LGPL-2.0-or-later *
5 ***************************************************************************/
6
7#pragma once
8
9#include "../exception.h"
10#include "entities.h"
11
12class QString;
13class QVariant;
14
15namespace Akonadi
16{
17namespace Server
18{
19AKONADI_EXCEPTION_MAKE_INSTANCE(PartHelperException);
20
21/**
22 * Helper methods that store data in a file instead of the database.
23 *
24 * @author Andras Mantia <amantia@kde.org>
25 *
26 * @todo Use exceptions for error handling in all these methods. Requires that all callers
27 * can handle that first though.
28 */
29namespace PartHelper
30{
31/**
32 * Update payload of an existing part @p part to @p data and size @p dataSize.
33 * Automatically decides whether or not the data should be stored in the database
34 * or the file system.
35 * @throw PartHelperException if file operations failed
36 */
37void update(Part *part, const QByteArray &data, qint64 dataSize);
38
39/**
40 * Adds a new part to the database and if necessary to the filesystem.
41 * @p part must not be in the database yet (ie. valid() == false) and must have
42 * a data size set.
43 */
44bool insert(Part *part, qint64 *insertId = nullptr);
45
46/** Deletes @p part from the database and also removes existing filesystem data if needed. */
47bool remove(Part *part);
48/** Deletes all parts which match the given constraint, including all corresponding filesystem data. */
49bool remove(const QString &column, const QVariant &value);
50
51/** Returns the payload data. */
52QByteArray translateData(const QByteArray &data, Part::Storage storageType);
53/** Convenience overload of the above. */
54QByteArray translateData(const Part &part);
55
56/** Truncate the payload of @p part and update filesystem/database accordingly.
57 * This is more efficient than using update since it does not require the data to be loaded.
58 */
59bool truncate(Part &part);
60
61/** Verifies and if necessary fixes the external reference of this part. */
62bool verify(Part &part);
63
64} // namespace PartHelper
65
66} // namespace Server
67} // namespace Akonadi
bool insert(Part *part, qint64 *insertId=nullptr)
Adds a new part to the database and if necessary to the filesystem.
void update(Part *part, const QByteArray &data, qint64 dataSize)
Update payload of an existing part part to data and size dataSize.
bool truncate(Part &part)
Truncate the payload of part and update filesystem/database accordingly.
QByteArray translateData(const QByteArray &data, Part::Storage storageType)
Returns the payload data.
bool remove(Part *part)
Deletes part from the database and also removes existing filesystem data if needed.
bool verify(Part &part)
Verifies and if necessary fixes the external reference of this part.
Helper integration between Akonadi and Qt.
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 4 2024 16:31:59 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.