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"
33 #include <KLocalizedString>
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 );
81 QString jobDebuggingString() const {
82 if ( mRequestedItems.isEmpty() ) {
83 return QString::fromLatin1(
"All items from collection %1" ).arg( mCollection.id() );
88 return QString::fromUtf8( e.
what() );
96 Item::List mRequestedItems;
97 Item::List mResultItems;
99 Item::List mPendingItems;
101 ProtocolHelperValuePool *mValuePool;
104 void ItemFetchJobPrivate::startFetchJob()
107 QByteArray command = newTag();
108 if ( mRequestedItems.isEmpty() ) {
109 command +=
" " AKONADI_CMD_ITEMFETCH
" 1:*";
115 q->setErrorText( QString::fromUtf8( e.
what() ) );
122 if ( protocolVersion() < 30 ) {
124 kDebug() <<
"IGNOREERRORS is not available with this akonadi protocol version";
130 writeData( command );
133 void ItemFetchJobPrivate::selectDone( KJob * job )
141 :
Job( new ItemFetchJobPrivate( this ), parent )
146 d->mCollection = collection;
147 d->mValuePool =
new ProtocolHelperValuePool;
151 :
Job( new ItemFetchJobPrivate( this ), parent )
156 d->mRequestedItems.append( item );
160 :
Job( new ItemFetchJobPrivate( this ), parent )
165 d->mRequestedItems =
items;
169 :
Job( new ItemFetchJobPrivate( this ), parent )
175 d->mRequestedItems.append(
Item(
id));
187 if ( d->mRequestedItems.isEmpty() ) {
189 setErrorText( i18n(
"Cannot list root collection." ) );
194 connect( job, SIGNAL(result(KJob*)), SLOT(selectDone(KJob*)) );
205 int begin = data.indexOf(
"FETCH" );
209 QList<QByteArray> fetchResponse;
210 ImapParser::parseParenthesizedList( data, fetchResponse, begin + 6 );
217 d->mResultItems.append( item );
218 d->mPendingItems.append( item );
219 if ( !d->mEmitTimer->isActive() )
220 d->mEmitTimer->start();
224 kDebug() <<
"Unhandled response: " << tag << data;
231 return d->mResultItems;
252 return d->mFetchScope;
259 d->mCollection = collection;
263 #include "moc_itemfetchjob.cpp"