phonebookui/pbkcommonui/src/cntnoteeditormodel.cpp
changeset 25 76a2435edfd4
child 27 de1630741fbe
equal deleted inserted replaced
24:0ba2181d7c28 25:76a2435edfd4
       
     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 #include "cntnoteeditormodel.h"
       
    18 #include "cntdetailmodelitem.h"
       
    19 #include <qcontactnote.h>
       
    20 
       
    21 CntNoteEditorModel::CntNoteEditorModel( QContact* aContact ) :
       
    22 CntDetailEditorModel( aContact )
       
    23     {
       
    24     QList<QContactNote> noteList = mContact->details<QContactNote>();
       
    25     if ( noteList.isEmpty() )
       
    26         {
       
    27         QContactNote emptyNote;
       
    28         noteList.append( emptyNote );
       
    29         }
       
    30     
       
    31     HbDataFormModelItem* root = invisibleRootItem();
       
    32     foreach ( QContactNote note, noteList )
       
    33         {
       
    34         CntDetailModelItem* item = new CntDetailModelItem( note, qtTrId("Note") );
       
    35         appendDataFormItem( item, root );
       
    36         }
       
    37     }
       
    38 
       
    39 CntNoteEditorModel::~CntNoteEditorModel()
       
    40     {
       
    41     }
       
    42 
       
    43 void CntNoteEditorModel::insertDetailField()
       
    44 {
       
    45     QContactNote emptyNote;
       
    46     appendDataFormItem( new CntDetailModelItem(emptyNote, qtTrId("Note")), invisibleRootItem() );
       
    47 }
       
    48 
       
    49 void CntNoteEditorModel::saveContactDetails()
       
    50 {
       
    51     HbDataFormModelItem* root = invisibleRootItem();
       
    52       
       
    53     int count( root->childCount() );
       
    54     for ( int i(0); i < count; i++ ) {
       
    55         CntDetailModelItem* detail = static_cast<CntDetailModelItem*>( root->childAt(i) );
       
    56         QContactNote note = detail->detail();
       
    57         if ( note.note().length() > 0 ) {
       
    58             mContact->saveDetail( &note );
       
    59         }
       
    60     }
       
    61 }
       
    62 // End of File