Akonadi

itemdeletehandler.cpp
1 /*
2  Copyright (c) 2009 Volker Krause <[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 "itemdeletehandler.h"
21 
22 #include "connection.h"
23 #include "storage/datastore.h"
24 #include "storage/itemqueryhelper.h"
25 #include "storage/selectquerybuilder.h"
26 #include "storage/transaction.h"
27 
28 #include <private/scope_p.h>
29 
30 using namespace Akonadi;
31 using namespace Akonadi::Server;
32 
33 ItemDeleteHandler::ItemDeleteHandler(AkonadiServer &akonadi)
34  : Handler(akonadi)
35 {}
36 
37 bool ItemDeleteHandler::parseStream()
38 {
39  const auto &cmd = Protocol::cmdCast<Protocol::DeleteItemsCommand>(m_command);
40 
41  CommandContext context = connection()->context();
42  if (!context.setScopeContext(cmd.scopeContext())) {
43  return failureResponse(QStringLiteral("Invalid scope context"));
44  }
45 
47  ItemQueryHelper::scopeToQuery(cmd.items(), context, qb);
48 
49  DataStore *store = connection()->storageBackend();
50  Transaction transaction(store, QStringLiteral("REMOVE"));
51 
52  if (!qb.exec()) {
53  return failureResponse("Unable to execute query");
54  }
55 
56  const QVector<PimItem> items = qb.result();
57  if (items.isEmpty()) {
58  return failureResponse("No items found");
59  }
60  if (!store->cleanupPimItems(items)) {
61  return failureResponse("Deletion failed");
62  }
63 
64  if (!transaction.commit()) {
65  return failureResponse("Unable to commit transaction");
66  }
67 
68  return successResponse<Protocol::DeleteItemsResponse>();
69 }
The handler interfaces describes an entity capable of handling an AkonadiIMAP command.
Definition: handler.h:48
Helper class for DataStore transaction handling.
Definition: transaction.h:37
QVector< T > result()
Returns the result of this SELECT query.
bool commit()
Commits the transaction.
Definition: transaction.cpp:42
Helper class for creating and executing database SELECT queries.
Definition: item.h:44
bool isEmpty() const const
Helper integration between Akonadi and Qt.
This class handles all the database access.
Definition: datastore.h:102
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:10 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.