emailservices/nmclientapi/src/nmapimailboxlisting_p.cpp
changeset 76 38bf5461e270
parent 48 10eaf342f539
equal deleted inserted replaced
74:6c59112cfd31 76:38bf5461e270
    15  *
    15  *
    16  */
    16  */
    17 
    17 
    18 #include "nmapiheaders.h"
    18 #include "nmapiheaders.h"
    19 
    19 
    20 
       
    21 namespace EmailClientApi
    20 namespace EmailClientApi
    22 {
    21 {
    23 NmApiMailboxListingPrivate::NmApiMailboxListingPrivate(QObject *parent) :
    22 NmApiMailboxListingPrivate::NmApiMailboxListingPrivate(QObject *parent) 
    24     QObject(parent), mNmApiEngine(NULL)
    23 :QObject(parent), 
       
    24 mEngine(NULL), 
       
    25 mIsRunning(false)
    25 {
    26 {
    26     NM_FUNCTION;
    27     NM_FUNCTION;
       
    28     mEngine = NmApiEngine::instance();
    27 }
    29 }
    28 
    30 
    29 NmApiMailboxListingPrivate::~NmApiMailboxListingPrivate()
    31 NmApiMailboxListingPrivate::~NmApiMailboxListingPrivate()
    30 {
    32 {
    31     NM_FUNCTION;
    33     NM_FUNCTION;
       
    34     NmApiEngine::releaseInstance(mEngine);
    32 }
    35 }
    33 
    36 
    34 /*!
    37 /*!
    35    \brief It initialize engine for email operations. 
    38    \brief Get mailboxes from engine.    
    36    
    39    \return Count of mailboxes 
    37    When use initializeEngine need to remember release it.
       
    38    It return value if initialization go good.
       
    39    \sa releaseEngine 
       
    40    \return Return true if engine is good initilialized.
       
    41  */
    40  */
    42 bool NmApiMailboxListingPrivate::initializeEngine()
    41 qint32 NmApiMailboxListingPrivate::listMailboxes()
    43 {
    42 {
    44     NM_FUNCTION;
    43     NM_FUNCTION;
       
    44     mIsRunning = true;
       
    45     mMailboxes.clear();
       
    46     mEngine->listMailboxes(mMailboxes);
       
    47     return mMailboxes.count();
       
    48 }
       
    49 
       
    50 /*! 
       
    51    \brief Returns results after mailboxesListed signal is received.
       
    52    
       
    53     Caller gets ownership of mailboxes. Returns true if results were available.
       
    54     It clears list of mailboxes (in private members) after be called.
       
    55     It also at start clear inputlist of NmApiMailbox.
    45     
    56     
    46     if (!mNmApiEngine) {
    57     \return Return true if results were avaible
    47         mNmApiEngine = NmApiEngine::instance();
    58     \param mailboxes List of mailboxes to filled. On start is cleared. 
       
    59  */
       
    60 bool NmApiMailboxListingPrivate::mailboxes(QList<NmApiMailbox> &mailboxes)
       
    61 {
       
    62     mailboxes.clear();
       
    63 
       
    64 
       
    65     bool ret(mIsRunning);
       
    66     mailboxes.clear();
       
    67     while (!mMailboxes.isEmpty()) {
       
    68         mailboxes << mMailboxes.takeFirst();
    48     }
    69     }
    49 
    70     mIsRunning = false;
    50     return mNmApiEngine ? true : false;
    71     return ret;
       
    72 }
       
    73 /*!
       
    74    \brief Return info if listing is running
       
    75  */
       
    76 bool NmApiMailboxListingPrivate::isRunning() const
       
    77 {
       
    78     NM_FUNCTION;
       
    79     return mIsRunning;
    51 }
    80 }
    52 
    81 
    53 /*!
    82 /*!
    54    \brief It release engine for email operations.
    83    \brief Clears list of mailboxes.
    55    
       
    56    \sa initializeEngine
       
    57  */
    84  */
    58 void NmApiMailboxListingPrivate::releaseEngine()
    85 void NmApiMailboxListingPrivate::cancel() 
    59 {
    86 {
    60     NM_FUNCTION;
    87     mIsRunning = false;
    61     
       
    62     NmApiEngine::releaseInstance(mNmApiEngine);
       
    63 }
       
    64 
       
    65 /*!
       
    66    \brief It grab mailboxes from engine. 
       
    67    
       
    68    When it start grabing, it release all old.
       
    69    Because it uses NmApiMailbox with sharedData we don't need care about release memory.
       
    70    
       
    71    \return Count of mailboxes or "-1" if there is no engine
       
    72  */
       
    73 qint32 NmApiMailboxListingPrivate::grabMailboxes()
       
    74 {
       
    75     NM_FUNCTION;
       
    76     
       
    77     if (!mNmApiEngine) {
       
    78         return -1;
       
    79     }
       
    80     
       
    81     mMailboxes.clear();
    88     mMailboxes.clear();
    82 
       
    83     mNmApiEngine->listMailboxes(mMailboxes);
       
    84     return mMailboxes.count();
       
    85 }
    89 }
    86 }
    90 }