Akonadi

searchresultjob.cpp
1 /*
2  SPDX-FileCopyrightText: 2013 Daniel Vrátil <[email protected]>
3 
4  SPDX-License-Identifier: LGPL-2.0-or-later
5 */
6 
7 #include "searchresultjob_p.h"
8 #include "job_p.h"
9 
10 #include "protocolhelper_p.h"
11 #include "private/protocol_p.h"
12 
13 namespace Akonadi
14 {
15 
16 class SearchResultJobPrivate : public Akonadi::JobPrivate
17 {
18 public:
19  explicit SearchResultJobPrivate(SearchResultJob *parent);
20 
22  QByteArray searchId;
23  Collection collection;
24  ImapSet uid;
25 
26  // JobPrivate interface
27 public:
28  QString jobDebuggingString() const override;
29 };
30 
31 QString SearchResultJobPrivate::jobDebuggingString() const
32 {
33  return QStringLiteral("Collection id: %1 Search id: %2").arg(collection.id()).arg(QString::fromLatin1(searchId));
34 }
35 
36 SearchResultJobPrivate::SearchResultJobPrivate(SearchResultJob *parent)
37  : JobPrivate(parent)
38 {
39 }
40 
41 } // namespace Akonadi
42 
43 using namespace Akonadi;
44 
45 SearchResultJob::SearchResultJob(const QByteArray &searchId, const Collection &collection, QObject *parent)
46  : Job(new SearchResultJobPrivate(this), parent)
47 {
48  Q_D(SearchResultJob);
49  Q_ASSERT(collection.isValid());
50 
51  d->searchId = searchId;
52  d->collection = collection;
53 }
54 
55 SearchResultJob::~SearchResultJob()
56 {
57 }
58 
59 void SearchResultJob::setSearchId(const QByteArray &searchId)
60 {
61  Q_D(SearchResultJob);
62  d->searchId = searchId;
63 }
64 
65 QByteArray SearchResultJob::searchId() const
66 {
67  return d_func()->searchId;
68 }
69 
70 void SearchResultJob::setResult(const ImapSet &set)
71 {
72  Q_D(SearchResultJob);
73  d->rid.clear();
74  d->uid = set;
75 }
76 
77 void SearchResultJob::setResult(const QVector<qint64> &ids)
78 {
79  Q_D(SearchResultJob);
80  d->rid.clear();
81  d->uid = ImapSet();
82  d->uid.add(ids);
83 }
84 
85 void SearchResultJob::setResult(const QVector<QByteArray> &remoteIds)
86 {
87  Q_D(SearchResultJob);
88  d->uid = ImapSet();
89  d->rid = remoteIds;
90 }
91 
92 void SearchResultJob::doStart()
93 {
94  Q_D(SearchResultJob);
95 
96  Scope scope;
97  if (!d->rid.isEmpty()) {
98  QStringList ridSet;
99  ridSet.reserve(d->rid.size());
100  for (const QByteArray &rid : qAsConst(d->rid)) {
101  ridSet << QString::fromUtf8(rid);
102  }
103  scope.setRidSet(ridSet);
104  } else {
105  scope.setUidSet(d->uid);
106  }
107  d->sendCommand(Protocol::SearchResultCommandPtr::create(d->searchId, d->collection.id(), scope));
108 }
109 
110 bool SearchResultJob::doHandleResponse(qint64 tag, const Protocol::CommandPtr &response)
111 {
112  if (!response->isResponse() || response->type() != Protocol::Command::SearchResult) {
113  return Job::doHandleResponse(tag, response);
114  }
115 
116  return true;
117 }
bool isValid() const
Returns whether the collection is valid.
Definition: collection.cpp:124
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:372
void reserve(int alloc)
Represents a collection of PIM items.
Definition: collection.h:63
Base class for all actions in the Akonadi storage.
Definition: job.h:80
QString fromUtf8(const char *str, int size)
quint64 tag() const
The tag of the command associated with this handler.
Definition: handler.cpp:194
Helper integration between Akonadi and Qt.
QString arg(qlonglong a, int fieldWidth, int base, QChar fillChar) const const
QString fromLatin1(const char *str, int size)
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Sun Jul 12 2020 23:16:57 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.