• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdepimlibs API Reference
  • KDE Home
  • Contact Us
 

akonadi

  • sources
  • kde-4.14
  • kdepimlibs
  • akonadi
searchcreatejob.cpp
1 
2 /*
3  Copyright (c) 2007 Volker Krause <vkrause@kde.org>
4  Copyright (c) 2014 Daniel Vrátil <dvratil@redhat.com>
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 "imapparser_p.h"
26 #include "protocolhelper_p.h"
27 #include "job_p.h"
28 #include "searchquery.h"
29 #include <akonadi/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  , mRecursive(false)
41  , mRemote(false)
42  {
43  }
44 
45  QString mName;
46  SearchQuery mQuery;
47  QStringList mMimeTypes;
48  Collection::List mCollections;
49  bool mRecursive;
50  bool mRemote;
51  Collection mCreatedCollection;
52 };
53 
54 SearchCreateJob::SearchCreateJob(const QString &name, const QString &query, QObject *parent)
55  : Job(new SearchCreateJobPrivate(name, SearchQuery::fromJSON(query.toLatin1()), this), parent)
56 {
57 }
58 
59 SearchCreateJob::SearchCreateJob(const QString &name, const SearchQuery &searchQuery, QObject *parent)
60  : Job(new SearchCreateJobPrivate(name, searchQuery, this), parent)
61 {
62 }
63 
64 SearchCreateJob::~SearchCreateJob()
65 {
66 }
67 
68 void SearchCreateJob::setQueryLanguage(const QString &queryLanguage)
69 {
70  Q_UNUSED(queryLanguage);
71 }
72 
73 void SearchCreateJob::setSearchCollections(const Collection::List &collections)
74 {
75  Q_D(SearchCreateJob);
76 
77  d->mCollections = collections;
78 }
79 
80 Collection::List SearchCreateJob::searchCollections() const
81 {
82  return d_func()->mCollections;
83 }
84 
85 void SearchCreateJob::setSearchMimeTypes(const QStringList &mimeTypes)
86 {
87  Q_D(SearchCreateJob);
88 
89  d->mMimeTypes = mimeTypes;
90 }
91 
92 QStringList SearchCreateJob::searchMimeTypes() const
93 {
94  return d_func()->mMimeTypes;
95 }
96 
97 void SearchCreateJob::setRecursive(bool recursive)
98 {
99  Q_D(SearchCreateJob);
100 
101  d->mRecursive = recursive;
102 }
103 
104 bool SearchCreateJob::isRecursive() const
105 {
106  return d_func()->mRecursive;
107 }
108 
109 void SearchCreateJob::setRemoteSearchEnabled(bool enabled)
110 {
111  Q_D(SearchCreateJob);
112 
113  d->mRemote = enabled;
114 }
115 
116 bool SearchCreateJob::isRemoteSearchEnabled() const
117 {
118  return d_func()->mRemote;
119 }
120 
121 void SearchCreateJob::doStart()
122 {
123  Q_D(SearchCreateJob);
124 
125  QByteArray command = d->newTag() + " SEARCH_STORE ";
126  command += ImapParser::quote(d->mName.toUtf8());
127  command += ' ';
128  command += ImapParser::quote(d->mQuery.toJSON());
129  command += " (";
130  command += QByteArray(AKONADI_PARAM_PERSISTENTSEARCH_QUERYLANG) + " \"ASQL\" "; // Akonadi Search Query Language ;-)
131  if (!d->mCollections.isEmpty()) {
132  command += QByteArray(AKONADI_PARAM_PERSISTENTSEARCH_QUERYCOLLECTIONS) + " (";
133  QList<QByteArray> ids;
134  Q_FOREACH (const Collection &col, d->mCollections) {
135  ids << QByteArray::number(col.id());
136  }
137  command += ImapParser::join(ids, " ");
138  command += ") ";
139  }
140  if (d->mRecursive) {
141  command += QByteArray(AKONADI_PARAM_RECURSIVE) + " ";
142  }
143  if (d->mRemote) {
144  command += QByteArray(AKONADI_PARAM_REMOTE) + " ";
145  }
146  command += QByteArray(AKONADI_PARAM_MIMETYPE) + " (";
147  command += d->mMimeTypes.join(QLatin1String(" ")).toLatin1();
148  command += ") )";
149  command += '\n';
150  d->writeData(command);
151 }
152 
153 Akonadi::Collection SearchCreateJob::createdCollection() const
154 {
155  Q_D(const SearchCreateJob);
156  return d->mCreatedCollection;
157 }
158 
159 void SearchCreateJob::doHandleResponse(const QByteArray &tag, const QByteArray &data)
160 {
161  Q_D(SearchCreateJob);
162  if (tag == "*") {
163  ProtocolHelper::parseCollection(data, d->mCreatedCollection);
164  return;
165  }
166  kDebug() << "Unhandled response: " << tag << data;
167 }
Akonadi::SearchCreateJob::setSearchCollections
void setSearchCollections(const Collection::List &collections)
Sets list of collections to search in.
Definition: searchcreatejob.cpp:73
Akonadi::SearchCreateJob::doStart
void doStart()
Reimplemented from Akonadi::Job.
Definition: searchcreatejob.cpp:121
Akonadi::SearchCreateJob::setRecursive
void setRecursive(bool recursive)
Sets whether the search should recurse into collections.
Definition: searchcreatejob.cpp:97
QByteArray
Akonadi::SearchCreateJob::~SearchCreateJob
~SearchCreateJob()
Destroys the search create job.
Definition: searchcreatejob.cpp:64
Akonadi::SearchCreateJob
Job that creates a virtual/search collection in the Akonadi storage.
Definition: searchcreatejob.h:62
Akonadi::SearchCreateJob::createdCollection
Collection createdCollection() const
Returns the newly created search collection once the job finished successfully.
Definition: searchcreatejob.cpp:153
Akonadi::Collection
Represents a collection of PIM items.
Definition: collection.h:75
Akonadi::Job
Base class for all actions in the Akonadi storage.
Definition: job.h:86
Akonadi::ProtocolHelper::parseCollection
static int parseCollection(const QByteArray &data, Collection &collection, int start=0)
Parse a collection description.
Definition: protocolhelper.cpp:145
Akonadi::SearchCreateJob::doHandleResponse
void doHandleResponse(const QByteArray &tag, const QByteArray &data)
Reimplemented from Akonadi::Job.
Definition: searchcreatejob.cpp:159
QObject
QByteArray::number
QByteArray number(int n, int base)
QString
QList
Akonadi::Entity::id
Id id() const
Returns the unique identifier of the entity.
Definition: entity.cpp:72
QStringList
Akonadi::SearchCreateJob::searchMimeTypes
QStringList searchMimeTypes() const
Returns list of mime types that search results can contain.
Definition: searchcreatejob.cpp:92
Akonadi::SearchQuery
A query that can be passed to ItemSearchJob or others.
Definition: searchquery.h:128
Akonadi::SearchCreateJob::SearchCreateJob
AKONADI_DEPRECATED SearchCreateJob(const QString &name, const QString &query, QObject *parent=0)
Creates a search create job.
Definition: searchcreatejob.cpp:54
Akonadi::SearchCreateJob::setRemoteSearchEnabled
void setRemoteSearchEnabled(bool enabled)
Sets whether resources should be queried too.
Definition: searchcreatejob.cpp:109
Akonadi::SearchCreateJob::searchCollections
Collection::List searchCollections() const
Returns list of collections to search in.
Definition: searchcreatejob.cpp:80
Akonadi::SearchCreateJob::setSearchMimeTypes
void setSearchMimeTypes(const QStringList &mimeTypes)
Sets list of mime types of items that search results can contain.
Definition: searchcreatejob.cpp:85
QLatin1String
Akonadi::SearchCreateJob::isRemoteSearchEnabled
bool isRemoteSearchEnabled() const
Returns whether remote search is enabled.
Definition: searchcreatejob.cpp:116
Akonadi::JobPrivate
Definition: job_p.h:31
Akonadi::SearchCreateJob::setQueryLanguage
AKONADI_DEPRECATED void setQueryLanguage(const QString &queryLanguage)
Sets the query language.
Definition: searchcreatejob.cpp:68
Akonadi::SearchCreateJob::isRecursive
bool isRecursive() const
Returns whether the search is recursive.
Definition: searchcreatejob.cpp:104
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:38:03 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

akonadi

Skip menu "akonadi"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • Modules
  • Related Pages

kdepimlibs API Reference

Skip menu "kdepimlibs API Reference"
  • akonadi
  •   contact
  •   kmime
  •   socialutils
  • kabc
  • kalarmcal
  • kblog
  • kcal
  • kcalcore
  • kcalutils
  • kholidays
  • kimap
  • kioslave
  •   imap4
  •   mbox
  •   nntp
  • kldap
  • kmbox
  • kmime
  • kontactinterface
  • kpimidentities
  • kpimtextedit
  • kpimutils
  • kresources
  • ktnef
  • kxmlrpcclient
  • mailtransport
  • microblog
  • qgpgme
  • syndication
  •   atom
  •   rdf
  •   rss2

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal