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 } else if (cmd.result().scope() == Scope::Uid && !cmd.result().isEmpty()) {
50 const auto uidSet = cmd.result().uidSet();
51 ids = QSet<qint64>(uidSet.begin(), uidSet.end());
52 }
53 akonadi().agentSearchManager().pushResults(cmd.searchId(), ids, connection());
54
55 return successResponse<Protocol::SearchResultResponse>();
56}
57
58bool SearchResultHandler::fail(const QByteArray &searchId, const QString &error)
59{
60 akonadi().agentSearchManager().pushResults(searchId, QSet<qint64>(), connection());
61 return failureResponse(error);
62}
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 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.