Akonadi

tagdeletehandler.cpp
1/*
2 SPDX-FileCopyrightText: 2014 Daniel Vrátil <dvratil@redhat.com>
3
4 SPDX-License-Identifier: LGPL-2.0-or-later
5*/
6
7#include "tagdeletehandler.h"
8
9#include "storage/datastore.h"
10#include "storage/selectquerybuilder.h"
11#include "storage/tagqueryhelper.h"
12
13#include "private/scope_p.h"
14#include "storage/transaction.h"
15
16using namespace Akonadi;
17using namespace Akonadi::Server;
18
19TagDeleteHandler::TagDeleteHandler(AkonadiServer &akonadi)
20 : Handler(akonadi)
21{
22}
23
24bool TagDeleteHandler::parseStream()
25{
26 const auto &cmd = Protocol::cmdCast<Protocol::DeleteTagCommand>(m_command);
27
28 if (!checkScopeConstraints(cmd.tag(), {Scope::Uid})) {
29 return failureResponse(QStringLiteral("Only UID-based TAGREMOVE is supported"));
30 }
31
33 TagQueryHelper::scopeToQuery(cmd.tag(), connection()->context(), tagQuery);
34 if (!tagQuery.exec()) {
35 return failureResponse(QStringLiteral("Failed to obtain tags"));
36 }
37
38 const Tag::List tags = tagQuery.result();
39
40 Transaction transaction(storageBackend(), QStringLiteral("TagDeleteHandler"));
41
42 if (!storageBackend()->removeTags(tags)) {
43 return failureResponse(QStringLiteral("Failed to remove tags"));
44 }
45
46 if (!transaction.commit()) {
47 return failureResponse(QStringLiteral("Failed to commit transaction"));
48 }
49
50 return successResponse<Protocol::DeleteTagResponse>();
51}
The handler interfaces describes an entity capable of handling an AkonadiIMAP command.
Definition handler.h:32
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
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.
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Sat Dec 21 2024 17:01:42 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.