diff -r bf7eb7911fc5 -r 997a02608b3a emailservices/nmclientapi/src/nmapienvelopelisting.cpp --- a/emailservices/nmclientapi/src/nmapienvelopelisting.cpp Wed Jun 23 18:00:21 2010 +0300 +++ b/emailservices/nmclientapi/src/nmapienvelopelisting.cpp Tue Jul 06 14:04:34 2010 +0300 @@ -14,17 +14,8 @@ * Description: * */ - -#include "emailtrace.h" - -#include -#include "nmapienvelopelisting_p.h" - -#include - -#include "nmapiengine.h" - - + +#include "nmapiheaders.h" namespace EmailClientApi { @@ -38,30 +29,20 @@ NmApiMessageTask(parent) { NM_FUNCTION; - - mListingPrivate = new NmApiEnvelopeListingPrivate(this); - mListingPrivate->mailboxId = mailboxId; - mListingPrivate->folderId = folderId; - mListingPrivate->mIsRunning = false; + mListingPrivate = new NmApiEnvelopeListingPrivate(folderId, mailboxId, this); } /*! - Destructor of class. It release engine to be safe if manual releasing won't work. + Destructor of class. */ NmApiEnvelopeListing::~NmApiEnvelopeListing() { NM_FUNCTION; - - if (mListingPrivate->mIsRunning) { - mListingPrivate->releaseEngine(); - } } /*! - \brief Starts gathering envelopes list. - - In first turn it will get whole folderlist. - If start works, it do nothing. + \brief Fetches envelope list. Emits envelopesListed signal when ready. + Results can be fetched with getEnvelopes. To asynchronous operation ce be used \sa QTimer::singleShot on this method. Example: @@ -73,77 +54,37 @@ bool NmApiEnvelopeListing::start() { NM_FUNCTION; - - bool result = false; - if (mListingPrivate->mIsRunning) { - result = true; - } - else { - - bool started = mListingPrivate->initializeEngine(); - if (!started) { - QMetaObject::invokeMethod(this, "envelopesListed", Qt::QueuedConnection, Q_ARG(qint32, - (qint32) EnvelopeListingFailed)); - result = false; - } - else { - qint32 envelopesCount = mListingPrivate->grabEnvelopes(); - - mListingPrivate->mIsRunning = true; - QMetaObject::invokeMethod(this, "envelopesListed", Qt::QueuedConnection, Q_ARG(qint32, + qint32 envelopesCount = mListingPrivate->listEnvelopes(); + QMetaObject::invokeMethod(this, "envelopesListed", Qt::QueuedConnection, Q_ARG(qint32, envelopesCount)); - result = true; - } - } - return result; + return true; } /*! \brief Stop gathering envelope list. - - In first it change state of listing. - Then it release engine. - On end it clears list of envelopes and emits \sa NmApiMessageTask::canceled() signal. + + Clears list of envelopes and emits \sa NmApiMessageTask::canceled() signal. */ void NmApiEnvelopeListing::cancel() { NM_FUNCTION; - - if (mListingPrivate->mIsRunning) { - mListingPrivate->mIsRunning = false; - mListingPrivate->releaseEngine(); - mListingPrivate->mEnvelopes.clear(); + mListingPrivate->cancel(); + emit canceled(); - emit canceled(); - } } /*! \brief Returns results after envelopesListed signal is received. Caller gets ownership of envelopes. Returns true if results were available. - Before calling cancel and start should be called, - because after second calling it return empty list. - It also at start clear inputlist of NmMessageEnvelope. + Before calling start should be called, otherwise will return empty list. + It also clears inputlist of NmMessageEnvelope. */ bool NmApiEnvelopeListing::getEnvelopes(QList &envelopes) { NM_FUNCTION; - - envelopes.clear(); - - bool result = false; - - if (!mListingPrivate->mIsRunning) { - result = false; - } - else { - envelopes = mListingPrivate->mEnvelopes; - mListingPrivate->mEnvelopes.clear(); - result = true; - } - return result; + return mListingPrivate->envelopes(envelopes); } /*! @@ -152,8 +93,7 @@ bool NmApiEnvelopeListing::isRunning() const { NM_FUNCTION; - - return mListingPrivate->mIsRunning; + return mListingPrivate->isRunning(); } }