Akonadi

tagdeletehandler.cpp
1 /*
2  Copyright (c) 2014 Daniel Vrátil <[email protected]>
3 
4  This library is free software; you can redistribute it and/or modify it
5  under the terms of the GNU Library General Public License as published by
6  the Free Software Foundation; either version 2 of the License, or (at your
7  option) any later version.
8 
9  This library is distributed in the hope that it will be useful, but WITHOUT
10  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11  FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
12  License for more details.
13 
14  You should have received a copy of the GNU Library General Public License
15  along with this library; see the file COPYING.LIB. If not, write to the
16  Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
17  02110-1301, USA.
18 */
19 
20 #include "tagdeletehandler.h"
21 
22 #include "storage/selectquerybuilder.h"
23 #include "storage/queryhelper.h"
24 #include "storage/datastore.h"
25 
26 #include <private/scope_p.h>
27 #include <private/imapset_p.h>
28 
29 using namespace Akonadi;
30 using namespace Akonadi::Server;
31 
32 TagDeleteHandler::TagDeleteHandler(AkonadiServer &akonadi)
33  : Handler(akonadi)
34 {}
35 
36 bool TagDeleteHandler::parseStream()
37 {
38  const auto &cmd = Protocol::cmdCast<Protocol::DeleteTagCommand>(m_command);
39 
40  if (!checkScopeConstraints(cmd.tag(), Scope::Uid)) {
41  return failureResponse(QStringLiteral("Only UID-based TAGREMOVE is supported"));
42  }
43 
44  SelectQueryBuilder<Tag> tagQuery;
45  QueryHelper::setToQuery(cmd.tag().uidSet(), Tag::idFullColumnName(), tagQuery);
46  if (!tagQuery.exec()) {
47  return failureResponse(QStringLiteral("Failed to obtain tags"));
48  }
49 
50  const Tag::List tags = tagQuery.result();
51 
52  if (!storageBackend()->removeTags(tags)) {
53  return failureResponse(QStringLiteral("Failed to remove tags"));
54  }
55 
56  return successResponse<Protocol::DeleteTagResponse>();
57 }
The handler interfaces describes an entity capable of handling an AkonadiIMAP command.
Definition: handler.h:48
QVector< T > result()
Returns the result of this SELECT query.
Helper class for creating and executing database SELECT queries.
Helper integration between Akonadi and Qt.
bool exec()
Executes the query, returns true on success.
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon May 25 2020 22:46:12 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.