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

akonadi

  • 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 
65 SearchCreateJob::~SearchCreateJob()
66 {
67 }
68 
69 void SearchCreateJob::setQueryLanguage( const QString &queryLanguage )
70 {
71  Q_UNUSED( queryLanguage );
72 }
73 
74 void SearchCreateJob::setSearchCollections( const Collection::List &collections )
75 {
76  Q_D( SearchCreateJob );
77 
78  d->mCollections = collections;
79 }
80 
81 Collection::List SearchCreateJob::searchCollections() const
82 {
83  return d_func()->mCollections;
84 }
85 
86 void SearchCreateJob::setSearchMimeTypes( const QStringList &mimeTypes )
87 {
88  Q_D( SearchCreateJob );
89 
90  d->mMimeTypes = mimeTypes;
91 }
92 
93 QStringList SearchCreateJob::searchMimeTypes() const
94 {
95  return d_func()->mMimeTypes;
96 }
97 
98 void SearchCreateJob::setRecursive( bool recursive )
99 {
100  Q_D( SearchCreateJob );
101 
102  d->mRecursive = recursive;
103 }
104 
105 bool SearchCreateJob::isRecursive() const
106 {
107  return d_func()->mRecursive;
108 }
109 
110 void SearchCreateJob::setRemoteSearchEnabled( bool enabled )
111 {
112  Q_D( SearchCreateJob );
113 
114  d->mRemote = enabled;
115 }
116 
117 bool SearchCreateJob::isRemoteSearchEnabled() const
118 {
119  return d_func()->mRemote;
120 }
121 
122 void SearchCreateJob::doStart()
123 {
124  Q_D( SearchCreateJob );
125 
126  QByteArray command = d->newTag() + " SEARCH_STORE ";
127  command += ImapParser::quote( d->mName.toUtf8() );
128  command += ' ';
129  command += ImapParser::quote( d->mQuery.toJSON() );
130  command += " (";
131  command += QByteArray( AKONADI_PARAM_PERSISTENTSEARCH_QUERYLANG ) + " \"ASQL\" "; // Akonadi Search Query Language ;-)
132  if ( !d->mCollections.isEmpty() ) {
133  command += QByteArray( AKONADI_PARAM_PERSISTENTSEARCH_QUERYCOLLECTIONS ) + " (";
134  QList<QByteArray> ids;
135  Q_FOREACH ( const Collection &col, d->mCollections ) {
136  ids << QByteArray::number( col.id() );
137  }
138  command += ImapParser::join( ids, " " );
139  command += ") ";
140  }
141  if ( d->mRecursive ) {
142  command += QByteArray( AKONADI_PARAM_RECURSIVE ) + " ";
143  }
144  if ( d->mRemote ) {
145  command += QByteArray( AKONADI_PARAM_REMOTE ) + " ";
146  }
147  command += QByteArray( AKONADI_PARAM_MIMETYPE ) + " (";
148  command += d->mMimeTypes.join( QLatin1String( " " ) ).toLatin1();
149  command += ") )";
150  command += '\n';
151  d->writeData( command );
152 }
153 
154 Akonadi::Collection SearchCreateJob::createdCollection() const
155 {
156  Q_D( const SearchCreateJob );
157  return d->mCreatedCollection;
158 }
159 
160 void SearchCreateJob::doHandleResponse( const QByteArray &tag, const QByteArray &data )
161 {
162  Q_D( SearchCreateJob );
163  if ( tag == "*" ) {
164  ProtocolHelper::parseCollection( data, d->mCreatedCollection );
165  return;
166  }
167  kDebug() << "Unhandled response: " << tag << data;
168 }
169 
Akonadi::SearchCreateJob::setSearchCollections
void setSearchCollections(const Collection::List &collections)
Sets list of collections to search in.
Definition: searchcreatejob.cpp:74
Akonadi::SearchCreateJob::doStart
void doStart()
Reimplemented from Akonadi::Job.
Definition: searchcreatejob.cpp:122
Akonadi::SearchCreateJob::setRecursive
void setRecursive(bool recursive)
Sets whether the search should recurse into collections.
Definition: searchcreatejob.cpp:98
Akonadi::SearchCreateJob::~SearchCreateJob
~SearchCreateJob()
Destroys the search create job.
Definition: searchcreatejob.cpp:65
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:154
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:129
Akonadi::SearchCreateJob::doHandleResponse
void doHandleResponse(const QByteArray &tag, const QByteArray &data)
Reimplemented from Akonadi::Job.
Definition: searchcreatejob.cpp:160
Akonadi::Entity::id
Id id() const
Returns the unique identifier of the entity.
Definition: entity.cpp:72
Akonadi::SearchCreateJob::searchMimeTypes
QStringList searchMimeTypes() const
Returns list of mime types that search results can contain.
Definition: searchcreatejob.cpp:93
Akonadi::SearchQuery
A query that can be passed to ItemSearchJob or others.
Definition: searchquery.h:129
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:110
Akonadi::SearchCreateJob::searchCollections
Collection::List searchCollections() const
Returns list of collections to search in.
Definition: searchcreatejob.cpp:81
Akonadi::SearchCreateJob::setSearchMimeTypes
void setSearchMimeTypes(const QStringList &mimeTypes)
Sets list of mime types of items that search results can contain.
Definition: searchcreatejob.cpp:86
Akonadi::SearchCreateJob::isRemoteSearchEnabled
bool isRemoteSearchEnabled() const
Returns whether remote search is enabled.
Definition: searchcreatejob.cpp:117
Akonadi::JobPrivate
Definition: job_p.h:31
Akonadi::SearchCreateJob::setQueryLanguage
AKONADI_DEPRECATED void setQueryLanguage(const QString &queryLanguage)
Sets the query language.
Definition: searchcreatejob.cpp:69
Akonadi::SearchCreateJob::isRecursive
bool isRecursive() const
Returns whether the search is recursive.
Definition: searchcreatejob.cpp:105
Akonadi::Collection::List
QList< Collection > List
Describes a list of collections.
Definition: collection.h:81
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Mon Jul 21 2014 08:03:55 by doxygen 1.8.6 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-4.13.3 API Reference

Skip menu "kdepimlibs-4.13.3 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
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