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

akonadi

  • akonadi
itemsearchjob.cpp
1 /*
2  Copyright (c) 2009 Tobias Koenig <tokoe@kde.org>
3 
4  This library is free software; you can redistribute it and/or modify it
5  under the terms of the GNU Library General Public License as published by
6  the Free Software Foundation; either version 2 of the License, or (at your
7  option) any later version.
8 
9  This library is distributed in the hope that it will be useful, but WITHOUT
10  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11  FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
12  License for more details.
13 
14  You should have received a copy of the GNU Library General Public License
15  along with this library; see the file COPYING.LIB. If not, write to the
16  Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
17  02110-1301, USA.
18 */
19 
20 #include "itemsearchjob.h"
21 
22 #include "imapparser_p.h"
23 #include "itemfetchscope.h"
24 #include "job_p.h"
25 #include "protocolhelper_p.h"
26 
27 #include <QtCore/QTimer>
28 
29 using namespace Akonadi;
30 
31 class Akonadi::ItemSearchJobPrivate : public JobPrivate
32 {
33  public:
34  ItemSearchJobPrivate( ItemSearchJob *parent, const QString &query )
35  : JobPrivate( parent ), mQuery( query ), mEmitTimer( 0 )
36  {
37  }
38 
39  void timeout()
40  {
41  Q_Q( Akonadi::ItemSearchJob );
42 
43  mEmitTimer->stop(); // in case we are called by result()
44  if ( !mPendingItems.isEmpty() ) {
45  if ( !q->error() )
46  emit q->itemsReceived( mPendingItems );
47  mPendingItems.clear();
48  }
49  }
50 
51  Q_DECLARE_PUBLIC( ItemSearchJob )
52 
53  QString mQuery;
54  Item::List mItems;
55  ItemFetchScope mFetchScope;
56  Item::List mPendingItems; // items pending for emitting itemsReceived()
57  QTimer* mEmitTimer;
58 };
59 
60 ItemSearchJob::ItemSearchJob( const QString & query, QObject * parent )
61  : Job( new ItemSearchJobPrivate( this, query ), parent )
62 {
63  Q_D( ItemSearchJob );
64 
65  d->mEmitTimer = new QTimer( this );
66  d->mEmitTimer->setSingleShot( true );
67  d->mEmitTimer->setInterval( 100 );
68  connect( d->mEmitTimer, SIGNAL(timeout()), this, SLOT(timeout()) );
69  connect( this, SIGNAL(result(KJob*)), this, SLOT(timeout()) );
70 }
71 
72 ItemSearchJob::~ItemSearchJob()
73 {
74 }
75 
76 void ItemSearchJob::setQuery( const QString &query )
77 {
78  Q_D( ItemSearchJob );
79 
80  d->mQuery = query;
81 }
82 
83 void ItemSearchJob::setFetchScope( const ItemFetchScope &fetchScope )
84 {
85  Q_D( ItemSearchJob );
86 
87  d->mFetchScope = fetchScope;
88 }
89 
90 ItemFetchScope &ItemSearchJob::fetchScope()
91 {
92  Q_D( ItemSearchJob );
93 
94  return d->mFetchScope;
95 }
96 
97 void ItemSearchJob::doStart()
98 {
99  Q_D( ItemSearchJob );
100 
101  QByteArray command = d->newTag() + " SEARCH ";
102  command += ImapParser::quote( d->mQuery.toUtf8() );
103  command += ' ' + ProtocolHelper::itemFetchScopeToByteArray( d->mFetchScope );
104  command += '\n';
105  d->writeData( command );
106 }
107 
108 void ItemSearchJob::doHandleResponse( const QByteArray & tag, const QByteArray & data )
109 {
110  Q_D( ItemSearchJob );
111 
112  if ( tag == "*" ) {
113  int begin = data.indexOf( "SEARCH" );
114  if ( begin >= 0 ) {
115 
116  // split fetch response into key/value pairs
117  QList<QByteArray> fetchResponse;
118  ImapParser::parseParenthesizedList( data, fetchResponse, begin + 7 );
119 
120  Item item;
121  ProtocolHelper::parseItemFetchResult( fetchResponse, item );
122  if ( !item.isValid() )
123  return;
124 
125  d->mItems.append( item );
126  d->mPendingItems.append( item );
127  if ( !d->mEmitTimer->isActive() )
128  d->mEmitTimer->start();
129  return;
130  }
131  }
132  kDebug() << "Unhandled response: " << tag << data;
133 }
134 
135 Item::List ItemSearchJob::items() const
136 {
137  Q_D( const ItemSearchJob );
138 
139  return d->mItems;
140 }
141 
142 QUrl ItemSearchJob::akonadiItemIdUri()
143 {
144  return QUrl( QLatin1String( "http://akonadi-project.org/ontologies/aneo#akonadiItemId" ) );
145 }
146 
147 #include "moc_itemsearchjob.cpp"
This file is part of the KDE documentation.
Documentation copyright © 1996-2013 The KDE developers.
Generated on Sat Jul 13 2013 01:27:38 by doxygen 1.8.3.1 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.10.5 API Reference

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