Akonadi

searchresultjob.cpp
1/*
2 SPDX-FileCopyrightText: 2013 Daniel Vrátil <dvratil@redhat.com>
3
4 SPDX-License-Identifier: LGPL-2.0-or-later
5*/
6
7#include "job_p.h"
8#include "searchresultjob_p.h"
9
10#include "private/protocol_p.h"
11
12namespace Akonadi
13{
14class SearchResultJobPrivate : public Akonadi::JobPrivate
15{
16public:
17 explicit SearchResultJobPrivate(SearchResultJob *parent);
18
20 QList<qint64> uid;
21 QByteArray searchId;
22 Collection collection;
23
24 // JobPrivate interface
25public:
26 QString jobDebuggingString() const override;
27};
28
29QString SearchResultJobPrivate::jobDebuggingString() const
30{
31 return QStringLiteral("Collection id: %1 Search id: %2").arg(collection.id()).arg(QString::fromLatin1(searchId));
32}
33
34SearchResultJobPrivate::SearchResultJobPrivate(SearchResultJob *parent)
35 : JobPrivate(parent)
36{
37}
38
39} // namespace Akonadi
40
41using namespace Akonadi;
42
43SearchResultJob::SearchResultJob(const QByteArray &searchId, const Collection &collection, QObject *parent)
44 : Job(new SearchResultJobPrivate(this), parent)
45{
46 Q_D(SearchResultJob);
47 Q_ASSERT(collection.isValid());
48
49 d->searchId = searchId;
50 d->collection = collection;
51}
52
53SearchResultJob::~SearchResultJob()
54{
55}
56
57void SearchResultJob::setSearchId(const QByteArray &searchId)
58{
59 Q_D(SearchResultJob);
60 d->searchId = searchId;
61}
62
63QByteArray SearchResultJob::searchId() const
64{
65 return d_func()->searchId;
66}
67
68void SearchResultJob::setResult(const QList<qint64> &ids)
69{
70 Q_D(SearchResultJob);
71 d->rid.clear();
72 d->uid = ids;
73}
74
75void SearchResultJob::setResult(const QList<QByteArray> &remoteIds)
76{
77 Q_D(SearchResultJob);
78 d->uid.clear();
79 d->rid = remoteIds;
80}
81
82void SearchResultJob::doStart()
83{
84 Q_D(SearchResultJob);
85
86 Scope scope;
87 if (!d->rid.isEmpty()) {
88 QStringList ridSet;
89 ridSet.reserve(d->rid.size());
90 for (const QByteArray &rid : std::as_const(d->rid)) {
91 ridSet << QString::fromUtf8(rid);
92 }
93 scope.setRidSet(ridSet);
94 } else {
95 scope.setUidSet(d->uid);
96 }
97 d->sendCommand(Protocol::SearchResultCommandPtr::create(d->searchId, d->collection.id(), scope));
98}
99
100bool SearchResultJob::doHandleResponse(qint64 tag, const Protocol::CommandPtr &response)
101{
102 if (!response->isResponse() || response->type() != Protocol::Command::SearchResult) {
103 return Job::doHandleResponse(tag, response);
104 }
105
106 return true;
107}
108
109#include "moc_searchresultjob_p.cpp"
Represents a collection of PIM items.
Definition collection.h:62
Base class for all actions in the Akonadi storage.
Definition job.h:81
virtual bool doHandleResponse(qint64 tag, const Protocol::CommandPtr &response)
This method should be reimplemented in the concrete jobs in case you want to handle incoming data.
Definition job.cpp:381
Helper integration between Akonadi and Qt.
void reserve(qsizetype size)
QString arg(Args &&... args) const const
QString fromLatin1(QByteArrayView str)
QString fromUtf8(QByteArrayView str)
Q_D(Todo)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 18 2024 12:08:29 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.