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

KDE's Doxygen guidelines are available online.