Akonadi

itemdeletehandler.cpp
1/*
2 SPDX-FileCopyrightText: 2009 Volker Krause <vkrause@kde.org>
3
4 SPDX-License-Identifier: LGPL-2.0-or-later
5*/
6
7#include "itemdeletehandler.h"
8
9#include "connection.h"
10#include "storage/datastore.h"
11#include "storage/itemqueryhelper.h"
12#include "storage/selectquerybuilder.h"
13#include "storage/transaction.h"
14
15#include "private/scope_p.h"
16
17using namespace Akonadi;
18using namespace Akonadi::Server;
19
20ItemDeleteHandler::ItemDeleteHandler(AkonadiServer &akonadi)
21 : Handler(akonadi)
22{
23}
24
26{
27 const auto &cmd = Protocol::cmdCast<Protocol::DeleteItemsCommand>(m_command);
28
29 CommandContext context = connection()->context();
30 if (!context.setScopeContext(cmd.scopeContext())) {
31 return failureResponse(QStringLiteral("Invalid scope context"));
32 }
33
35 ItemQueryHelper::scopeToQuery(cmd.items(), context, qb);
36
37 DataStore *store = connection()->storageBackend();
38 Transaction transaction(store, QStringLiteral("REMOVE"));
39
40 if (!qb.exec()) {
41 return failureResponse("Unable to execute query");
42 }
43
44 const QList<PimItem> items = qb.result();
45 if (items.isEmpty()) {
46 return failureResponse("No items found");
47 }
48 if (!store->cleanupPimItems(items)) {
49 return failureResponse("Deletion failed");
50 }
51
52 if (!transaction.commit()) {
53 return failureResponse("Unable to commit transaction");
54 }
55
56 return successResponse<Protocol::DeleteItemsResponse>();
57}
This class handles all the database access.
Definition datastore.h:95
virtual bool cleanupPimItems(const PimItem::List &items, bool silent=false)
Removes the pim item and all referenced data ( e.g.
The handler interfaces describes an entity capable of handling an AkonadiIMAP command.
Definition handler.h:32
bool parseStream() override
Parse and handle the IMAP message using the streaming parser.
bool exec()
Executes the query, returns true on success.
Helper class for creating and executing database SELECT queries.
QList< T > result()
Returns the result of this SELECT query.
Helper class for DataStore transaction handling.
Definition transaction.h:23
bool commit()
Commits the transaction.
void scopeToQuery(const Scope &scope, const CommandContext &context, QueryBuilder &qb)
Add conditions to qb for the given item operation scope scope.
Helper integration between Akonadi and Qt.
bool isEmpty() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Jun 7 2024 11:56:45 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.