Akonadi

searchresulthandler.cpp
1/*
2 * SPDX-FileCopyrightText: 2013 Daniel Vrátil <dvratil@redhat.com>
3 *
4 * SPDX-License-Identifier: LGPL-2.1-or-later
5 *
6 */
7
8#include "searchresulthandler.h"
9
10#include "akonadi.h"
11#include "connection.h"
12#include "search/searchtaskmanager.h"
13#include "storage/itemqueryhelper.h"
14#include "storage/querybuilder.h"
15
16#include "private/scope_p.h"
17
18using namespace Akonadi;
19using namespace Akonadi::Server;
20
21SearchResultHandler::SearchResultHandler(AkonadiServer &akonadi)
22 : Handler(akonadi)
23{
24}
25
27{
28 const auto &cmd = Protocol::cmdCast<Protocol::SearchResultCommand>(m_command);
29
30 if (!checkScopeConstraints(cmd.result(), {Scope::Uid, Scope::Rid})) {
31 return fail(cmd.searchId(), QStringLiteral("Only UID or RID scopes are allowed in SEARECH_RESULT"));
32 }
33
34 QSet<qint64> ids;
35 if (cmd.result().scope() == Scope::Rid && !cmd.result().isEmpty()) {
36 QueryBuilder qb(PimItem::tableName());
37 qb.addColumn(PimItem::idFullColumnName());
38 ItemQueryHelper::remoteIdToQuery(cmd.result().ridSet(), connection()->context(), qb);
39 qb.addValueCondition(PimItem::collectionIdFullColumnName(), Query::Equals, cmd.collectionId());
40
41 if (!qb.exec()) {
42 return fail(cmd.searchId(), QStringLiteral("Failed to convert RID to UID"));
43 }
44
45 QSqlQuery query = qb.query();
46 while (query.next()) {
47 ids << query.value(0).toLongLong();
48 }
49 query.finish();
50 } else if (cmd.result().scope() == Scope::Uid && !cmd.result().isEmpty()) {
51 const auto uidSet = cmd.result().uidSet();
52 ids = QSet<qint64>(uidSet.begin(), uidSet.end());
53 }
54 akonadi().agentSearchManager().pushResults(cmd.searchId(), ids, connection());
55
56 return successResponse<Protocol::SearchResultResponse>();
57}
58
59bool SearchResultHandler::fail(const QByteArray &searchId, const QString &error)
60{
61 akonadi().agentSearchManager().pushResults(searchId, QSet<qint64>(), connection());
62 return failureResponse(error);
63}
The handler interfaces describes an entity capable of handling an AkonadiIMAP command.
Definition handler.h:32
Helper class to construct arbitrary SQL queries.
void addValueCondition(const QString &column, Query::CompareOperator op, const QVariant &value, ConditionType type=WhereCondition)
Add a WHERE or HAVING condition which compares a column with a given value.
bool exec()
Executes the query, returns true on success.
QSqlQuery & query()
Returns the query, only valid after exec().
void addColumn(const QString &col)
Adds the given column to a select query.
bool parseStream() override
Parse and handle the IMAP message using the streaming parser.
void remoteIdToQuery(const QStringList &rids, const CommandContext &context, QueryBuilder &qb)
Add conditions to qb for the given remote identifier rid.
Helper integration between Akonadi and Qt.
T value(qsizetype i) const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Tue Mar 26 2024 11:13:38 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.