emailservices/nmclientapi/src/nmapienvelopelisting.cpp
changeset 49 00c7ae862740
parent 48 10eaf342f539
child 76 38bf5461e270
--- a/emailservices/nmclientapi/src/nmapienvelopelisting.cpp	Tue Jun 29 17:12:28 2010 +0300
+++ b/emailservices/nmclientapi/src/nmapienvelopelisting.cpp	Fri Jul 02 15:55:16 2010 +0300
@@ -29,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:
@@ -64,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<EmailClientApi::NmApiMessageEnvelope> &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);
 }
 
 /*!
@@ -143,8 +93,7 @@
 bool NmApiEnvelopeListing::isRunning() const
 {
     NM_FUNCTION;
-    
-    return mListingPrivate->mIsRunning;
+    return mListingPrivate->isRunning();
 }
 
 }