Akonadi

searchcreatejob.cpp
1 
2 /*
3  SPDX-FileCopyrightText: 2007 Volker Krause <[email protected]>
4  SPDX-FileCopyrightText: 2014 Daniel Vr├ítil <[email protected]>
5 
6  SPDX-License-Identifier: LGPL-2.0-or-later
7 */
8 
9 #include "searchcreatejob.h"
10 
11 #include "job_p.h"
12 #include "protocolhelper_p.h"
13 #include "searchquery.h"
14 
15 #include "private/protocol_p.h"
16 
17 using namespace Akonadi;
18 
19 class Akonadi::SearchCreateJobPrivate : public JobPrivate
20 {
21 public:
22  SearchCreateJobPrivate(const QString &name, const SearchQuery &query, SearchCreateJob *parent)
23  : JobPrivate(parent)
24  , mName(name)
25  , mQuery(query)
26  {
27  }
28 
29  const QString mName;
30  const SearchQuery mQuery;
31  QStringList mMimeTypes;
32  QVector<Collection> mCollections;
33  bool mRecursive = false;
34  bool mRemote = false;
35  Collection mCreatedCollection;
36 
37  // JobPrivate interface
38 public:
39  QString jobDebuggingString() const override;
40 };
41 
42 QString Akonadi::SearchCreateJobPrivate::jobDebuggingString() const
43 {
44  QString str = QStringLiteral("Name :%1 ").arg(mName);
45  if (mRecursive) {
46  str += QStringLiteral("Recursive ");
47  }
48  if (mRemote) {
49  str += QStringLiteral("Remote");
50  }
51  return str;
52 }
53 
54 SearchCreateJob::SearchCreateJob(const QString &name, const SearchQuery &searchQuery, QObject *parent)
55  : Job(new SearchCreateJobPrivate(name, searchQuery, this), parent)
56 {
57 }
58 
60 {
61 }
62 
64 {
66 
67  d->mCollections = collections;
68 }
69 
71 {
72  return d_func()->mCollections;
73 }
74 
76 {
78 
79  d->mMimeTypes = mimeTypes;
80 }
81 
83 {
84  return d_func()->mMimeTypes;
85 }
86 
87 void SearchCreateJob::setRecursive(bool recursive)
88 {
90 
91  d->mRecursive = recursive;
92 }
93 
95 {
96  return d_func()->mRecursive;
97 }
98 
100 {
102 
103  d->mRemote = enabled;
104 }
105 
107 {
108  return d_func()->mRemote;
109 }
110 
112 {
114 
115  auto cmd = Protocol::StoreSearchCommandPtr::create();
116  cmd->setName(d->mName);
117  cmd->setQuery(QString::fromUtf8(d->mQuery.toJSON()));
118  cmd->setMimeTypes(d->mMimeTypes);
119  cmd->setRecursive(d->mRecursive);
120  cmd->setRemote(d->mRemote);
121  if (!d->mCollections.isEmpty()) {
122  QVector<qint64> ids;
123  ids.reserve(d->mCollections.size());
124  for (const Collection &col : std::as_const(d->mCollections)) {
125  ids << col.id();
126  }
127  cmd->setQueryCollections(ids);
128  }
129 
130  d->sendCommand(cmd);
131 }
132 
134 {
135  Q_D(const SearchCreateJob);
136  return d->mCreatedCollection;
137 }
138 
140 {
142  if (response->isResponse() && response->type() == Protocol::Command::FetchCollections) {
143  d->mCreatedCollection = ProtocolHelper::parseCollection(Protocol::cmdCast<Protocol::FetchCollectionsResponse>(response));
144  return false;
145  }
146 
147  if (response->isResponse() && response->type() == Protocol::Command::StoreSearch) {
148  return true;
149  }
150 
151  return Job::doHandleResponse(tag, response);
152 }
~SearchCreateJob() override
Destroys the search create job.
void setRecursive(bool recursive)
Sets whether the search should recurse into collections.
Job that creates a virtual/search collection in the Akonadi storage.
Collection createdCollection() const
Returns the newly created search collection once the job finished successfully.
Represents a collection of PIM items.
Definition: collection.h:61
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
Base class for all actions in the Akonadi storage.
Definition: job.h:80
QString fromUtf8(const char *str, int size)
QStringList searchMimeTypes() const
Returns list of mime types that search results can contain.
void reserve(int size)
A query that can be passed to ItemSearchJob or others.
Definition: searchquery.h:116
void setRemoteSearchEnabled(bool enabled)
Sets whether resources should be queried too.
void doStart() override
Reimplemented from Akonadi::Job.
SearchCreateJob(const QString &name, const SearchQuery &searchQuery, QObject *parent=nullptr)
Creates a search create job.
void setSearchMimeTypes(const QStringList &mimeTypes)
Sets list of mime types of items that search results can contain.
void setSearchCollections(const QVector< Collection > &collections)
Sets list of collections to search in.
bool isRemoteSearchEnabled() const
Returns whether remote search is enabled.
Helper integration between Akonadi and Qt.
QString arg(qlonglong a, int fieldWidth, int base, QChar fillChar) const const
Q_D(Todo)
QVector< Collection > searchCollections() const
Returns list of collections to search in.
bool isRecursive() const
Returns whether the search is recursive.
bool doHandleResponse(qint64 tag, const Protocol::CommandPtr &response) override
Reimplemented from Akonadi::Job.
This file is part of the KDE documentation.
Documentation copyright © 1996-2022 The KDE developers.
Generated on Mon Jan 17 2022 23:08:15 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.