Akonadi

searchcreatejob.cpp
1 
2 /*
3  Copyright (c) 2007 Volker Krause <[email protected]>
4  Copyright (c) 2014 Daniel Vrátil <[email protected]>
5 
6  This library is free software; you can redistribute it and/or modify it
7  under the terms of the GNU Library General Public License as published by
8  the Free Software Foundation; either version 2 of the License, or (at your
9  option) any later version.
10 
11  This library is distributed in the hope that it will be useful, but WITHOUT
12  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13  FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
14  License for more details.
15 
16  You should have received a copy of the GNU Library General Public License
17  along with this library; see the file COPYING.LIB. If not, write to the
18  Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
19  02110-1301, USA.
20 */
21 
22 #include "searchcreatejob.h"
23 
24 #include "collection.h"
25 #include "protocolhelper_p.h"
26 #include "job_p.h"
27 #include "searchquery.h"
28 
29 #include "private/protocol_p.h"
30 
31 using namespace Akonadi;
32 
33 class Akonadi::SearchCreateJobPrivate : public JobPrivate
34 {
35 public:
36  SearchCreateJobPrivate(const QString &name, const SearchQuery &query, SearchCreateJob *parent)
37  : JobPrivate(parent)
38  , mName(name)
39  , mQuery(query)
40  {
41  }
42 
43  QString mName;
44  SearchQuery mQuery;
45  QStringList mMimeTypes;
46  QVector<Collection> mCollections;
47  bool mRecursive = false;
48  bool mRemote = false;
49  Collection mCreatedCollection;
50 
51 
52  // JobPrivate interface
53 public:
54  QString jobDebuggingString() const override;
55 };
56 
57 QString Akonadi::SearchCreateJobPrivate::jobDebuggingString() const
58 {
59  QString str = QStringLiteral("Name :%1 ").arg(mName);
60  if (mRecursive) {
61  str += QStringLiteral("Recursive ");
62  }
63  if (mRemote) {
64  str += QStringLiteral("Remote");
65  }
66  return str;
67 }
68 
69 SearchCreateJob::SearchCreateJob(const QString &name, const SearchQuery &searchQuery, QObject *parent)
70  : Job(new SearchCreateJobPrivate(name, searchQuery, this), parent)
71 {
72 }
73 
75 {
76 }
77 
79 {
80  Q_D(SearchCreateJob);
81 
82  d->mCollections = collections;
83 }
84 
86 {
87  return d_func()->mCollections;
88 }
89 
91 {
92  Q_D(SearchCreateJob);
93 
94  d->mMimeTypes = mimeTypes;
95 }
96 
98 {
99  return d_func()->mMimeTypes;
100 }
101 
102 void SearchCreateJob::setRecursive(bool recursive)
103 {
104  Q_D(SearchCreateJob);
105 
106  d->mRecursive = recursive;
107 }
108 
110 {
111  return d_func()->mRecursive;
112 }
113 
115 {
116  Q_D(SearchCreateJob);
117 
118  d->mRemote = enabled;
119 }
120 
122 {
123  return d_func()->mRemote;
124 }
125 
127 {
128  Q_D(SearchCreateJob);
129 
130  auto cmd = Protocol::StoreSearchCommandPtr::create();
131  cmd->setName(d->mName);
132  cmd->setQuery(QString::fromUtf8(d->mQuery.toJSON()));
133  cmd->setMimeTypes(d->mMimeTypes);
134  cmd->setRecursive(d->mRecursive);
135  cmd->setRemote(d->mRemote);
136  if (!d->mCollections.isEmpty()) {
137  QVector<qint64> ids;
138  ids.reserve(d->mCollections.size());
139  for (const Collection &col : qAsConst(d->mCollections)) {
140  ids << col.id();
141  }
142  cmd->setQueryCollections(ids);
143  }
144 
145  d->sendCommand(cmd);
146 }
147 
149 {
150  Q_D(const SearchCreateJob);
151  return d->mCreatedCollection;
152 }
153 
155 {
156  Q_D(SearchCreateJob);
157  if (response->isResponse() && response->type() == Protocol::Command::FetchCollections) {
158  d->mCreatedCollection = ProtocolHelper::parseCollection(
159  Protocol::cmdCast<Protocol::FetchCollectionsResponse>(response));
160  return false;
161  }
162 
163  if (response->isResponse() && response->type() == Protocol::Command::StoreSearch) {
164  return true;
165  }
166 
167  return Job::doHandleResponse(tag, response);
168 }
~SearchCreateJob() override
Destroys the search create job.
void setRecursive(bool recursive)
Sets whether the search should recurse into collections.
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:385
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:76
Base class for all actions in the Akonadi storage.
Definition: job.h:93
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:128
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
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-2020 The KDE developers.
Generated on Mon May 25 2020 22:46:11 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.