emailservices/nmclientapi/src/nmapifolderlisting_p.cpp
author Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
Tue, 06 Jul 2010 14:04:34 +0300
changeset 54 997a02608b3a
parent 30 759dc5235cdb
permissions -rw-r--r--
Revision: 201025 Kit: 2010127

/*
 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
 * All rights reserved.
 * This component and the accompanying materials are made available
 * under the terms of "Eclipse Public License v1.0"
 * which accompanies this distribution, and is available
 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
 *
 * Initial Contributors:
 * Nokia Corporation - initial contribution.
 *
 * Contributors:
 *
 * Description:
 *
 */

#include "nmapiheaders.h"


namespace EmailClientApi
{

/*!
   Constructor form NmApiFolderListingPrivate
 */
NmApiFolderListingPrivate::NmApiFolderListingPrivate(quint64 mailboxId, QObject *parent) 
:QObject(parent), 
mMailboxId(mailboxId),
mEngine(NULL),
mIsRunning(false)
{
    NM_FUNCTION;
    mEngine = NmApiEngine::instance();
    Q_CHECK_PTR(mEngine);
}

/*!
   Destructor for NmApiFolderListingPrivate 
 */
NmApiFolderListingPrivate::~NmApiFolderListingPrivate()
{
    NM_FUNCTION;
    NmApiEngine::releaseInstance(mEngine);
}

/*!
   \brief Fetch folders from engine. 
   
   Because it uses NmFolder with sharedData we don't need care about release memory.
   
   \return Count of folders
 */
qint32 NmApiFolderListingPrivate::listFolders()
{
    NM_FUNCTION;
    mIsRunning = true;
    mFolders.clear();
    mEngine->listFolders(mMailboxId, mFolders);
    return mFolders.count();
}

/*! 
   \brief Returns results after listFolders is called.
   
    Caller gets ownership of messages. Returns true if results were available.
    It clears list of folders after be called.
    It also at start clear inputlist of NmFolder.
 */
bool NmApiFolderListingPrivate::folders(QList<EmailClientApi::NmApiFolder> &folders)
{
    NM_FUNCTION;
    bool ret(mIsRunning);
    folders.clear();
    while (!mFolders.isEmpty()) {
        folders << mFolders.takeFirst();
    }
    mIsRunning = false;
    return ret;
}

/*!
   \brief Return info if listing is running
 */
bool NmApiFolderListingPrivate::isRunning() const
{
    NM_FUNCTION;
    return mIsRunning;
}
/*!
   \brief Clears list of folders.
 */
void NmApiFolderListingPrivate::cancel() 
{
    mIsRunning = false;
    mFolders.clear();
}
}