emailservices/nmclientapi/src/nmapimailboxlisting.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 #include "nmapiengine.h"
       
    18 #include "nmapimailboxlisting_p.h"
       
    19 #include "nmapimailboxlisting.h"
       
    20 
       
    21 namespace EmailClientApi
       
    22 {
       
    23 
       
    24 /*!
       
    25  * \class Class for creating list of all mailboxes
       
    26  */
       
    27 
       
    28 /*!
       
    29  * Constructor of class. It set start values.
       
    30  */
       
    31 NmMailboxListing::NmMailboxListing(QObject *parent) :
       
    32     NmMessageTask(parent)
       
    33 {
       
    34     mNmMailboxListingPrivate = new NmMailboxListingPrivate(this);
       
    35     mNmMailboxListingPrivate->mIsRunning = false;
       
    36 }
       
    37 
       
    38 /*!
       
    39  * Destructor of class. It release engine to be safe if manual releasing won't work.
       
    40  */
       
    41 NmMailboxListing::~NmMailboxListing()
       
    42 {
       
    43     if (mNmMailboxListingPrivate->mIsRunning) {
       
    44         mNmMailboxListingPrivate->releaseEngine();
       
    45     }
       
    46     delete mNmMailboxListingPrivate;
       
    47 }
       
    48 
       
    49 /*! 
       
    50  * \brief Returns results after mailboxesListed signal is received.
       
    51  * 
       
    52  *  Caller gets ownership of messages. Returns true if results were available.
       
    53  *  It clears list of mailboxes (in private members) after be called.
       
    54  *  It also at start clear inputlist of NmMailbox.
       
    55  *  
       
    56  *  \return Return true if results were avaible
       
    57  *  \arg List of mailboxes to filled. On start is cleared. 
       
    58  */
       
    59 bool NmMailboxListing::mailboxes(QList<EmailClientApi::NmMailbox> &mailboxes)
       
    60 {
       
    61     mailboxes.clear();
       
    62 
       
    63     bool result = false;
       
    64 
       
    65     if (!mNmMailboxListingPrivate->mIsRunning) {
       
    66         result = false;
       
    67     }
       
    68     else
       
    69         if (mNmMailboxListingPrivate->mMailboxes.isEmpty()) {
       
    70             result = false;
       
    71         }
       
    72         else {
       
    73             mailboxes = mNmMailboxListingPrivate->mMailboxes;
       
    74 
       
    75             mNmMailboxListingPrivate->mMailboxes.clear();
       
    76 
       
    77             result = true;
       
    78         }
       
    79     return result;
       
    80 }
       
    81 
       
    82 /*!
       
    83  * \brief Starts gathering mailbox list.
       
    84  * 
       
    85  * In first turn it will get whole mailboxlist. 
       
    86  * Then it initialize core arguments and emits signal when ready.
       
    87  * 
       
    88  * To asynchronous operation can be used \sa QTimer::singleShot on this method.
       
    89  * Example:
       
    90  * <code> 
       
    91  * QTimer::singleShot(0,nmMailboxListing,SLOT(start());
       
    92  * </code>
       
    93  * 
       
    94  * \return Return true if everything go good and core of listing works good.
       
    95  * 
       
    96  */
       
    97 bool NmMailboxListing::start()
       
    98 {
       
    99     bool result = false;
       
   100     if (mNmMailboxListingPrivate->mIsRunning) {
       
   101         result = true;
       
   102     }
       
   103     else
       
   104         if (!mNmMailboxListingPrivate->initializeEngine()) {
       
   105             QMetaObject::invokeMethod(this, "mailboxesListed", Qt::QueuedConnection, Q_ARG(qint32,
       
   106                 (qint32) MailboxListingFailed));
       
   107             result = false;
       
   108         }
       
   109         else {
       
   110             quint64 mailboxCount = mNmMailboxListingPrivate->grabMailboxes();
       
   111 
       
   112             mNmMailboxListingPrivate->mIsRunning = true;
       
   113 
       
   114             QMetaObject::invokeMethod(this, "mailboxesListed", Qt::QueuedConnection, Q_ARG(qint32,
       
   115                 mailboxCount));
       
   116 
       
   117             result = true;
       
   118         }
       
   119     return result;
       
   120 }
       
   121 
       
   122 /*!
       
   123  * \brief Stop gathering mailbox list.
       
   124  * 
       
   125  * In first it change state of listing.
       
   126  * Then it release engine.
       
   127  * On end it clears list of mailboxes and emits \sa NmMessageTask::canceled() signal.
       
   128  */
       
   129 void NmMailboxListing::cancel()
       
   130 {
       
   131     if (mNmMailboxListingPrivate->mIsRunning) {
       
   132 
       
   133         mNmMailboxListingPrivate->mIsRunning = false;
       
   134         mNmMailboxListingPrivate->releaseEngine();
       
   135         mNmMailboxListingPrivate->mMailboxes.clear();
       
   136 
       
   137         QMetaObject::invokeMethod(this, "canceled", Qt::QueuedConnection);
       
   138     }
       
   139 }
       
   140 
       
   141 /*!
       
   142  * \brief Return info if listing is running
       
   143  * 
       
   144  * \return Return true if listing is running
       
   145  */
       
   146 bool NmMailboxListing::isRunning() const
       
   147 {
       
   148     return mNmMailboxListingPrivate->mIsRunning;
       
   149 }
       
   150 
       
   151 }
       
   152 
       
   153 #include "moc_nmapimailboxlisting.cpp"