20 #include "itemfetchjob.h"
22 #include "attributefactory.h"
23 #include "collection.h"
24 #include "collectionselectjob_p.h"
25 #include "imapparser_p.h"
26 #include "itemfetchscope.h"
28 #include "protocol_p.h"
29 #include "protocolhelper_p.h"
30 #include "session_p.h"
35 #include <QtCore/QStringList>
36 #include <QtCore/QTimer>
38 using namespace Akonadi;
40 class Akonadi::ItemFetchJobPrivate :
public JobPrivate
51 ~ItemFetchJobPrivate()
59 mEmitTimer =
new QTimer( q );
60 mEmitTimer->setSingleShot(
true );
61 mEmitTimer->setInterval( 100 );
62 q->connect( mEmitTimer, SIGNAL(timeout()), q, SLOT(timeout()) );
63 q->connect( q, SIGNAL(result(KJob*)), q, SLOT(timeout()) );
71 if ( !mPendingItems.isEmpty() ) {
73 emit q->itemsReceived( mPendingItems );
74 mPendingItems.clear();
79 void selectDone( KJob * job );
84 Item::List mRequestedItems;
85 Item::List mResultItems;
87 Item::List mPendingItems;
89 ProtocolHelperValuePool *mValuePool;
92 void ItemFetchJobPrivate::startFetchJob()
95 QByteArray command = newTag();
96 if ( mRequestedItems.isEmpty() ) {
97 command +=
" " AKONADI_CMD_ITEMFETCH
" 1:*";
103 q->setErrorText( QString::fromUtf8( e.
what() ) );
110 if ( protocolVersion() < 30 ) {
112 kDebug() <<
"IGNOREERRORS is not available with this akonadi protocol version";
118 writeData( command );
121 void ItemFetchJobPrivate::selectDone( KJob * job )
129 :
Job( new ItemFetchJobPrivate( this ), parent )
134 d->mCollection = collection;
135 d->mValuePool =
new ProtocolHelperValuePool;
139 :
Job( new ItemFetchJobPrivate( this ), parent )
144 d->mRequestedItems.append( item );
148 :
Job( new ItemFetchJobPrivate( this ), parent )
153 d->mRequestedItems =
items;
157 :
Job( new ItemFetchJobPrivate( this ), parent )
163 d->mRequestedItems.append(
Item(
id));
175 if ( d->mRequestedItems.isEmpty() ) {
177 setErrorText( i18n(
"Cannot list root collection." ) );
182 connect( job, SIGNAL(result(KJob*)), SLOT(selectDone(KJob*)) );
193 int begin = data.indexOf(
"FETCH" );
197 QList<QByteArray> fetchResponse;
198 ImapParser::parseParenthesizedList( data, fetchResponse, begin + 6 );
205 d->mResultItems.append( item );
206 d->mPendingItems.append( item );
207 if ( !d->mEmitTimer->isActive() )
208 d->mEmitTimer->start();
212 kDebug() <<
"Unhandled response: " << tag << data;
219 return d->mResultItems;
240 return d->mFetchScope;
247 d->mCollection = collection;
251 #include "moc_itemfetchjob.cpp"