emailservices/nmclientapi/src/nmapifolderlisting.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 "nmapifolderlisting_p.h"
       
    19 #include "nmapifolderlisting.h"
       
    20 #include <QtCore>
       
    21 
       
    22 namespace EmailClientApi
       
    23 {
       
    24 
       
    25 /*!
       
    26  * \class Class for creating list of all folders
       
    27  */
       
    28 
       
    29 /*!
       
    30  * Constructor of class. It set start values.
       
    31  */
       
    32 NmFolderListing::NmFolderListing(QObject *parent, const quint64 &nmMailboxId) :
       
    33     NmMessageTask(parent)
       
    34 {
       
    35     mFolderListing = new NmFolderListingPrivate(this);
       
    36     mFolderListing->mIsRunning = false;
       
    37     mFolderListing->mMailboxId = nmMailboxId;
       
    38 }
       
    39 
       
    40 /*!
       
    41  * Destructor of class. It release engine to be safe if manual releasing won't work.
       
    42  */
       
    43 NmFolderListing::~NmFolderListing()
       
    44 {
       
    45     if (mFolderListing->mIsRunning) {
       
    46         mFolderListing->releaseEngine();
       
    47     }
       
    48 }
       
    49 
       
    50 /*! 
       
    51  * \brief Returns results after foldersListed signal is received.
       
    52  * 
       
    53  *  Caller gets ownership of messages. Returns true if results were available.
       
    54  *  It clears list of folders after be called.
       
    55  *  It also at start clear inputlist of NmFolder.
       
    56  */
       
    57 bool NmFolderListing::folders(QList<EmailClientApi::NmFolder> &folders)
       
    58 {
       
    59     folders.clear();
       
    60     if (!mFolderListing->mIsRunning || mFolderListing->mFolders.isEmpty()) {
       
    61         return false;
       
    62     }
       
    63     folders = mFolderListing->mFolders;
       
    64     mFolderListing->mFolders.clear();
       
    65     return true;
       
    66 }
       
    67 
       
    68 /*!
       
    69  * \brief Starts gathering folders list.
       
    70  * 
       
    71  * In first turn it will get whole folderlist. and then
       
    72  * it emits information signal \sa folderListed 
       
    73  * 
       
    74  * To asynchronous operation ce be used \sa QTimer::singleShot on this method.
       
    75  * Example:
       
    76  * <code> 
       
    77  * QTimer::singleShot(0,nmFolderListing,SLOT(start());
       
    78  * </code>
       
    79  * 
       
    80  */
       
    81 bool NmFolderListing::start()
       
    82 {
       
    83     if (mFolderListing->mIsRunning) {
       
    84         return true;
       
    85     }
       
    86 
       
    87     if (!mFolderListing->initializeEngine()) {
       
    88         QMetaObject::invokeMethod(this, "foldersListed", Qt::QueuedConnection, Q_ARG(qint32,
       
    89             (qint32) FolderListingFailed));
       
    90         return false;
       
    91     }
       
    92 
       
    93     qint32 folderCount = mFolderListing->grabFolders();
       
    94 
       
    95     mFolderListing->mIsRunning = true;
       
    96     QMetaObject::invokeMethod(this, "foldersListed", Qt::QueuedConnection,
       
    97         Q_ARG(qint32, folderCount));
       
    98 
       
    99     return true;
       
   100 }
       
   101 
       
   102 /*!
       
   103  * \brief Stop gathering folder list.
       
   104  * 
       
   105  * In first it change state of listing.
       
   106  * Then it release engine.
       
   107  * On end it clears list of folders and emits \sa NmMessageTask::canceled() signal.
       
   108  */
       
   109 void NmFolderListing::cancel()
       
   110 {
       
   111     if (!mFolderListing->mIsRunning) {
       
   112         return;
       
   113     }
       
   114 
       
   115     mFolderListing->mIsRunning = false;
       
   116     mFolderListing->releaseEngine();
       
   117     mFolderListing->mFolders.clear();
       
   118 
       
   119     emit canceled();
       
   120 }
       
   121 
       
   122 /*!
       
   123  * \brief Return info if listing is running
       
   124  */
       
   125 bool NmFolderListing::isRunning() const
       
   126 {
       
   127     return mFolderListing->mIsRunning;
       
   128 }
       
   129 
       
   130 }
       
   131 
       
   132 #include "moc_nmapifolderlisting.cpp"