Akonadi

searchcreatejob.cpp
1
2/*
3 SPDX-FileCopyrightText: 2007 Volker Krause <vkrause@kde.org>
4 SPDX-FileCopyrightText: 2014 Daniel Vrátil <dvratil@redhat.com>
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
17using namespace Akonadi;
18
19class Akonadi::SearchCreateJobPrivate : public JobPrivate
20{
21public:
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 QList<Collection> mCollections;
33 bool mRecursive = false;
34 bool mRemote = false;
35 Collection mCreatedCollection;
36
37 // JobPrivate interface
38public:
39 QString jobDebuggingString() const override;
40};
41
42QString 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
54SearchCreateJob::SearchCreateJob(const QString &name, const SearchQuery &searchQuery, QObject *parent)
55 : Job(new SearchCreateJobPrivate(name, searchQuery, this), parent)
56{
57}
58
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
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 QList<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}
153
154#include "moc_searchcreatejob.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
Job that creates a virtual/search collection in the Akonadi storage.
void setSearchCollections(const QList< Collection > &collections)
Sets list of collections to search in.
QList< Collection > searchCollections() const
Returns list of collections to search in.
Collection createdCollection() const
Returns the newly created search collection once the job finished successfully.
void setSearchMimeTypes(const QStringList &mimeTypes)
Sets list of mime types of items that search results can contain.
QStringList searchMimeTypes() const
Returns list of mime types that search results can contain.
bool isRecursive() const
Returns whether the search is recursive.
void doStart() override
Reimplemented from Akonadi::Job.
SearchCreateJob(const QString &name, const SearchQuery &searchQuery, QObject *parent=nullptr)
Creates a search create job.
void setRemoteSearchEnabled(bool enabled)
Sets whether resources should be queried too.
void setRecursive(bool recursive)
Sets whether the search should recurse into collections.
bool isRemoteSearchEnabled() const
Returns whether remote search is enabled.
~SearchCreateJob() override
Destroys the search create job.
bool doHandleResponse(qint64 tag, const Protocol::CommandPtr &response) override
Reimplemented from Akonadi::Job.
A query that can be passed to ItemSearchJob or others.
Helper integration between Akonadi and Qt.
KSERVICE_EXPORT KService::List query(FilterFunc filterFunc)
QString name(StandardAction id)
void reserve(qsizetype size)
QString arg(Args &&... args) const const
QString fromUtf8(QByteArrayView str)
Q_D(Todo)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Dec 6 2024 12:00:59 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.