emailservices/nmclientapi/src/nmapienvelopelisting.cpp
changeset 18 578830873419
child 20 ecc8def7944a
equal deleted inserted replaced
4:e7aa27f58ae1 18:578830873419
       
     1 /*
       
     2  * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
       
     3  * All rights reserved.
       
     4  * This component and the accompanying materials are made available
       
     5  * under the terms of "Eclipse Public License v1.0"
       
     6  * which accompanies this distribution, and is available
       
     7  * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8  *
       
     9  * Initial Contributors:
       
    10  * Nokia Corporation - initial contribution.
       
    11  *
       
    12  * Contributors:
       
    13  *
       
    14  * Description:
       
    15  *
       
    16  */
       
    17 
       
    18 #include "nmapienvelopelisting_p.h"
       
    19 #include "nmapienvelopelisting.h"
       
    20 #include "nmapiengine.h"
       
    21 
       
    22 namespace EmailClientApi
       
    23 {
       
    24 /*!
       
    25  * Constructor of class. It set start values.
       
    26  */
       
    27 NmEnvelopeListing::NmEnvelopeListing(
       
    28     QObject *parent,
       
    29     const quint64 folderId,
       
    30     const quint64 mailboxId) :
       
    31     NmMessageTask(parent)
       
    32 {
       
    33     mListingPrivate = new NmEnvelopeListingPrivate(this);
       
    34     mListingPrivate->mailboxId = mailboxId;
       
    35     mListingPrivate->folderId = folderId;
       
    36     mListingPrivate->mIsRunning = false;
       
    37 }
       
    38 
       
    39 /*!
       
    40  * Destructor of class. It release engine to be safe if manual releasing won't work.
       
    41  */
       
    42 NmEnvelopeListing::~NmEnvelopeListing()
       
    43 {
       
    44     if (mListingPrivate->mIsRunning) {
       
    45         mListingPrivate->releaseEngine();
       
    46     }
       
    47 }
       
    48 
       
    49 /*!
       
    50  * \brief Starts gathering envelopes list.
       
    51  * 
       
    52  * In first turn it will get whole folderlist. 
       
    53  * If start works, it do nothing.
       
    54  * 
       
    55  * To asynchronous operation ce be used \sa QTimer::singleShot on this method.
       
    56  * Example:
       
    57  * <code> 
       
    58  * QTimer::singleShot(0,nmEnvelopeListing,SLOT(start());
       
    59  * </code>
       
    60  * 
       
    61  */
       
    62 bool NmEnvelopeListing::start()
       
    63 {
       
    64     bool result = false;
       
    65 
       
    66     if (mListingPrivate->mIsRunning) {
       
    67         result = true;
       
    68     }
       
    69     else {
       
    70 
       
    71         bool started = mListingPrivate->initializeEngine();
       
    72         if (!started) {
       
    73             QMetaObject::invokeMethod(this, "envelopesListed", Qt::QueuedConnection, Q_ARG(qint32,
       
    74                 (qint32) EnvelopeListingFailed));
       
    75             result = false;
       
    76         }
       
    77         else {
       
    78             qint32 envelopesCount = mListingPrivate->grabEnvelopes();
       
    79 
       
    80             mListingPrivate->mIsRunning = true;
       
    81             QMetaObject::invokeMethod(this, "envelopesListed", Qt::QueuedConnection, Q_ARG(qint32,
       
    82                 envelopesCount));
       
    83             result = true;
       
    84         }
       
    85     }
       
    86     return result;
       
    87 }
       
    88 
       
    89 /*!
       
    90  * \brief Stop gathering envelope list.
       
    91  * 
       
    92  * In first it change state of listing.
       
    93  * Then it release engine.
       
    94  * On end it clears list of envelopes and emits \sa NmMessageTask::canceled() signal.
       
    95  */
       
    96 void NmEnvelopeListing::cancel()
       
    97 {
       
    98     if (mListingPrivate->mIsRunning) {
       
    99         mListingPrivate->mIsRunning = false;
       
   100         mListingPrivate->releaseEngine();
       
   101         mListingPrivate->mEnvelopes.clear();
       
   102 
       
   103         emit canceled();
       
   104     }
       
   105 }
       
   106 
       
   107 /*! 
       
   108  * \brief Returns results after envelopesListed signal is received.
       
   109  * 
       
   110  *  Caller gets ownership of envelopes. Returns true if results were available.
       
   111  *  It clears list of envelopes after be called.
       
   112  *  It also at start clear inputlist of NmMessageEnvelope.
       
   113  */
       
   114 bool NmEnvelopeListing::envelopes(QList<EmailClientApi::NmMessageEnvelope> &envelopes)
       
   115 {
       
   116     envelopes.clear();
       
   117 
       
   118     bool result = false;
       
   119 
       
   120     if (!mListingPrivate->mIsRunning) {
       
   121         result = false;
       
   122     }
       
   123     else {
       
   124         envelopes = mListingPrivate->mEnvelopes;
       
   125         mListingPrivate->mEnvelopes.clear();
       
   126         result = true;
       
   127     }
       
   128     return result;
       
   129 }
       
   130 
       
   131 /*!
       
   132  * \brief Return info if listing is running
       
   133  */
       
   134 bool NmEnvelopeListing::isRunning() const
       
   135 {
       
   136     return mListingPrivate->mIsRunning;
       
   137 }
       
   138 }
       
   139 
       
   140 #include "moc_nmapienvelopelisting.cpp"