emailservices/nmclientapi/src/nmapienvelopelisting_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
{
NmApiEnvelopeListingPrivate::NmApiEnvelopeListingPrivate(const quint64 folderId, const quint64 mailboxId, QObject *parent)
:QObject(parent),
mFolderId(folderId), 
mMailboxId(mailboxId), 
mIsRunning(false),
mEngine(NULL)
{
    NM_FUNCTION;
    mEngine = NmApiEngine::instance();
    Q_CHECK_PTR(mEngine);
}

NmApiEnvelopeListingPrivate::~NmApiEnvelopeListingPrivate()
{
    NM_FUNCTION;
    NmApiEngine::releaseInstance(mEngine);
}

/*! 
   \brief Fills envelopes to the input parameter.
   
    Caller gets ownership of envelopes. Returns true if results were available.
 */
bool NmApiEnvelopeListingPrivate::envelopes(QList<EmailClientApi::NmApiMessageEnvelope> &envelopes)
{
    NM_FUNCTION;
    bool ret(mIsRunning);
    envelopes.clear();
    while (!mEnvelopes.isEmpty()) {
        envelopes << mEnvelopes.takeFirst();
    }
    mIsRunning = false;
    return ret;
}

/*!
   \brief It fetches envelopes from engine. 
   
   Because it uses NmApiMessageEnvelope with sharedData we don't need care about release memory.
   
   \return Count of envelopes 
 */
qint32 NmApiEnvelopeListingPrivate::listEnvelopes()
{
    NM_FUNCTION;
    mIsRunning = true;
    mEnvelopes.clear();
    mEngine->listEnvelopes(mMailboxId, mFolderId, mEnvelopes);
    return mEnvelopes.count();
}
/*!
   \brief Return info if listing is running
 */
bool NmApiEnvelopeListingPrivate::isRunning() const
{
    return mIsRunning;
}
/*!
   \brief Clears list of envelopes.
 */
void NmApiEnvelopeListingPrivate::cancel() 
{
    mIsRunning = false;
    mEnvelopes.clear();
}
}