emailservices/nmclientapi/src/nmapienvelopelisting_p.cpp
branchGCC_SURGE
changeset 55 cdd802add233
parent 54 997a02608b3a
equal deleted inserted replaced
28:011f79704660 55:cdd802add233
    12  * Contributors:
    12  * Contributors:
    13  *
    13  *
    14  * Description:
    14  * Description:
    15  *
    15  *
    16  */
    16  */
    17 #include "nmapiengine.h"
       
    18 #include "nmapienvelopelisting_p.h"
       
    19 
    17 
    20 #include <nmapimailbox.h>
    18 #include "nmapiheaders.h"
    21 #include <nmapimessageenvelope.h>
       
    22 
    19 
    23 
    20 
    24 
    21 
    25 namespace EmailClientApi
    22 namespace EmailClientApi
    26 {
    23 {
    27 NmApiEnvelopeListingPrivate::NmApiEnvelopeListingPrivate(QObject *parent) :
    24 NmApiEnvelopeListingPrivate::NmApiEnvelopeListingPrivate(const quint64 folderId, const quint64 mailboxId, QObject *parent)
    28     QObject(parent), mEngine(NULL)
    25 :QObject(parent),
       
    26 mFolderId(folderId), 
       
    27 mMailboxId(mailboxId), 
       
    28 mIsRunning(false),
       
    29 mEngine(NULL)
    29 {
    30 {
    30 
    31     NM_FUNCTION;
       
    32     mEngine = NmApiEngine::instance();
       
    33     Q_CHECK_PTR(mEngine);
    31 }
    34 }
    32 
    35 
    33 NmApiEnvelopeListingPrivate::~NmApiEnvelopeListingPrivate()
    36 NmApiEnvelopeListingPrivate::~NmApiEnvelopeListingPrivate()
    34 {
    37 {
    35     releaseEngine();
    38     NM_FUNCTION;
       
    39     NmApiEngine::releaseInstance(mEngine);
       
    40 }
       
    41 
       
    42 /*! 
       
    43    \brief Fills envelopes to the input parameter.
       
    44    
       
    45     Caller gets ownership of envelopes. Returns true if results were available.
       
    46  */
       
    47 bool NmApiEnvelopeListingPrivate::envelopes(QList<EmailClientApi::NmApiMessageEnvelope> &envelopes)
       
    48 {
       
    49     NM_FUNCTION;
       
    50     bool ret(mIsRunning);
       
    51     envelopes.clear();
       
    52     while (!mEnvelopes.isEmpty()) {
       
    53         envelopes << mEnvelopes.takeFirst();
       
    54     }
       
    55     mIsRunning = false;
       
    56     return ret;
    36 }
    57 }
    37 
    58 
    38 /*!
    59 /*!
    39    \brief It initialize engine for email operations. 
    60    \brief It fetches envelopes from engine. 
    40    
    61    
    41    When use initializeEngine need to remember release it.
       
    42    It return value if initialization go good.
       
    43    \sa releaseEngine 
       
    44  */
       
    45 bool NmApiEnvelopeListingPrivate::initializeEngine()
       
    46 {
       
    47     mEngine = NmApiEngine::instance();
       
    48     return mEngine ? true : false;
       
    49 }
       
    50 
       
    51 /*!
       
    52    \brief It release engine for email operations.
       
    53    
       
    54    \sa initializeEngine
       
    55  */
       
    56 void NmApiEnvelopeListingPrivate::releaseEngine()
       
    57 {
       
    58     NmApiEngine::releaseInstance(mEngine);
       
    59 }
       
    60 
       
    61 /*!
       
    62    \brief It grab envelopes from engine. 
       
    63    
       
    64    When it start grabing, it release all old.
       
    65    Because it uses NmApiMessageEnvelope with sharedData we don't need care about release memory.
    62    Because it uses NmApiMessageEnvelope with sharedData we don't need care about release memory.
    66    
    63    
    67    \return Count of envelopes or "-1" if there is no engine initialised
    64    \return Count of envelopes 
    68  */
    65  */
    69 qint32 NmApiEnvelopeListingPrivate::grabEnvelopes()
    66 qint32 NmApiEnvelopeListingPrivate::listEnvelopes()
    70 {
    67 {
    71     if(!mEngine){
    68     NM_FUNCTION;
    72         return -1;
    69     mIsRunning = true;
    73     }
       
    74     
       
    75     mEnvelopes.clear();
    70     mEnvelopes.clear();
    76     mEngine->listEnvelopes(mailboxId, folderId, mEnvelopes);
    71     mEngine->listEnvelopes(mMailboxId, mFolderId, mEnvelopes);
    77     return mEnvelopes.count();
    72     return mEnvelopes.count();
       
    73 }
       
    74 /*!
       
    75    \brief Return info if listing is running
       
    76  */
       
    77 bool NmApiEnvelopeListingPrivate::isRunning() const
       
    78 {
       
    79     return mIsRunning;
       
    80 }
       
    81 /*!
       
    82    \brief Clears list of envelopes.
       
    83  */
       
    84 void NmApiEnvelopeListingPrivate::cancel() 
       
    85 {
       
    86     mIsRunning = false;
       
    87     mEnvelopes.clear();
    78 }
    88 }
    79 }
    89 }
    80 
    90