phonebookui/pbkcommonui/src/cntemaileditormodel.cpp
author Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
Thu, 27 May 2010 12:45:19 +0300
changeset 37 fd64c38c277d
parent 31 2a11b5b00470
child 40 b46a585f6909
permissions -rw-r--r--
Revision: 201019 Kit: 2010121

/*
* 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 "cntemaileditormodel.h"
#include "cntdetailmodelitem.h"
#include <qcontactemailaddress.h>

CntEmailEditorModel::CntEmailEditorModel( QContact* aContact ) :
CntDetailEditorModel( aContact )
    {
    QList<QContactEmailAddress> addr = mContact->details<QContactEmailAddress>();
    if ( addr.isEmpty() )
        {
        QContactEmailAddress newAddr;
        addr.append( newAddr );
        }
    
    foreach ( QContactEmailAddress email, addr )
        {
        CntDetailModelItem* item = new CntDetailModelItem( email );
        appendDataFormItem( item, invisibleRootItem() );
        }
    }

CntEmailEditorModel::~CntEmailEditorModel()
    {
    }

void CntEmailEditorModel::insertDetailField()
{
    QContactEmailAddress newAddr;
    CntDetailModelItem* item = new CntDetailModelItem( newAddr );
    appendDataFormItem( item, invisibleRootItem() );
}

void CntEmailEditorModel::saveContactDetails()
{
    HbDataFormModelItem* root = invisibleRootItem();
    int count( root->childCount() );
    for ( int i(0); i < count; i++ ) {
        CntDetailModelItem* item = static_cast<CntDetailModelItem*>( root->childAt(i) );
        QContactDetail address = item->detail();
        mContact->saveDetail( &address );
        
        if ( address.value(QContactEmailAddress::FieldEmailAddress).isEmpty() ) {
            mContact->removeDetail( &address );
        }
    }
}

// End of File