emailservices/nmclientapi/src/nmapifolderlisting_p.cpp
branchRCL_3
changeset 63 d189ee25cf9d
equal deleted inserted replaced
61:dcf0eedfc1a3 63:d189ee25cf9d
       
     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 "nmapiheaders.h"
       
    19 
       
    20 
       
    21 namespace EmailClientApi
       
    22 {
       
    23 
       
    24 /*!
       
    25    Constructor form NmApiFolderListingPrivate
       
    26  */
       
    27 NmApiFolderListingPrivate::NmApiFolderListingPrivate(quint64 mailboxId, QObject *parent) 
       
    28 :QObject(parent), 
       
    29 mMailboxId(mailboxId),
       
    30 mEngine(NULL),
       
    31 mIsRunning(false)
       
    32 {
       
    33     NM_FUNCTION;
       
    34     mEngine = NmApiEngine::instance();
       
    35     Q_CHECK_PTR(mEngine);
       
    36 }
       
    37 
       
    38 /*!
       
    39    Destructor for NmApiFolderListingPrivate 
       
    40  */
       
    41 NmApiFolderListingPrivate::~NmApiFolderListingPrivate()
       
    42 {
       
    43     NM_FUNCTION;
       
    44     NmApiEngine::releaseInstance(mEngine);
       
    45 }
       
    46 
       
    47 /*!
       
    48    \brief Fetch folders from engine. 
       
    49    
       
    50    Because it uses NmFolder with sharedData we don't need care about release memory.
       
    51    
       
    52    \return Count of folders
       
    53  */
       
    54 qint32 NmApiFolderListingPrivate::listFolders()
       
    55 {
       
    56     NM_FUNCTION;
       
    57     mIsRunning = true;
       
    58     mFolders.clear();
       
    59     mEngine->listFolders(mMailboxId, mFolders);
       
    60     return mFolders.count();
       
    61 }
       
    62 
       
    63 /*! 
       
    64    \brief Returns results after listFolders is called.
       
    65    
       
    66     Caller gets ownership of messages. Returns true if results were available.
       
    67     It clears list of folders after be called.
       
    68     It also at start clear inputlist of NmFolder.
       
    69  */
       
    70 bool NmApiFolderListingPrivate::folders(QList<EmailClientApi::NmApiFolder> &folders)
       
    71 {
       
    72     NM_FUNCTION;
       
    73     bool ret(mIsRunning);
       
    74     folders.clear();
       
    75     while (!mFolders.isEmpty()) {
       
    76         folders << mFolders.takeFirst();
       
    77     }
       
    78     mIsRunning = false;
       
    79     return ret;
       
    80 }
       
    81 
       
    82 /*!
       
    83    \brief Return info if listing is running
       
    84  */
       
    85 bool NmApiFolderListingPrivate::isRunning() const
       
    86 {
       
    87     NM_FUNCTION;
       
    88     return mIsRunning;
       
    89 }
       
    90 /*!
       
    91    \brief Clears list of folders.
       
    92  */
       
    93 void NmApiFolderListingPrivate::cancel() 
       
    94 {
       
    95     mIsRunning = false;
       
    96     mFolders.clear();
       
    97 }
       
    98 }
       
    99