Akonadi

collectiondeletehandler.cpp
1/*
2 SPDX-FileCopyrightText: 2006 Volker Krause <vkrause@kde.org>
3
4 SPDX-License-Identifier: LGPL-2.0-or-later
5*/
6
7#include "collectiondeletehandler.h"
8
9#include "connection.h"
10#include "handlerhelper.h"
11#include "storage/datastore.h"
12#include "storage/transaction.h"
13
14#include "private/scope_p.h"
15
16using namespace Akonadi;
17using namespace Akonadi::Server;
18
19CollectionDeleteHandler::CollectionDeleteHandler(AkonadiServer &akonadi)
20 : Handler(akonadi)
21{
22}
23
24bool CollectionDeleteHandler::deleteRecursive(Collection &col)
25{
26 Collection::List children = col.children();
27 for (Collection &child : children) {
28 if (!deleteRecursive(child)) {
29 return false;
30 }
31 }
32
33 DataStore *db = connection()->storageBackend();
34 return db->cleanupCollection(col);
35}
36
38{
39 const auto &cmd = Protocol::cmdCast<Protocol::DeleteCollectionCommand>(m_command);
40
41 Collection collection = HandlerHelper::collectionFromScope(cmd.collection(), connection()->context());
42 if (!collection.isValid()) {
43 return failureResponse(QStringLiteral("No such collection."));
44 }
45
46 // handle virtual folders
47 if (collection.resource().name() == QLatin1StringView(AKONADI_SEARCH_RESOURCE)) {
48 // don't delete virtual root
49 if (collection.parentId() == 0) {
50 return failureResponse(QStringLiteral("Cannot delete virtual root collection"));
51 }
52 }
53
54 Transaction transaction(storageBackend(), QStringLiteral("DELETE"));
55
56 if (!deleteRecursive(collection)) {
57 return failureResponse(QStringLiteral("Unable to delete collection"));
58 }
59
60 if (!transaction.commit()) {
61 return failureResponse(QStringLiteral("Unable to commit transaction"));
62 }
63
64 return successResponse<Protocol::DeleteCollectionResponse>();
65}
Represents a collection of PIM items.
Definition collection.h:62
bool parseStream() override
Parse and handle the IMAP message using the streaming parser.
This class handles all the database access.
Definition datastore.h:95
virtual bool cleanupCollection(Collection &collection)
removes the given collection and all its content
The handler interfaces describes an entity capable of handling an AkonadiIMAP command.
Definition handler.h:32
Helper class for DataStore transaction handling.
Definition transaction.h:23
bool commit()
Commits the transaction.
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 18 2024 12:08:30 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.