phonebookui/pbkcommonui/src/cntemaileditormodel.cpp
changeset 46 efe85016a067
parent 40 b46a585f6909
equal deleted inserted replaced
40:b46a585f6909 46:efe85016a067
    14 * Description:
    14 * Description:
    15 *
    15 *
    16 */
    16 */
    17 #include "cntemaileditormodel.h"
    17 #include "cntemaileditormodel.h"
    18 #include "cntdetailmodelitem.h"
    18 #include "cntdetailmodelitem.h"
       
    19 #include "cntdetailorderinghelper.h"
    19 #include <qcontactemailaddress.h>
    20 #include <qcontactemailaddress.h>
    20 
    21 
    21 CntEmailEditorModel::CntEmailEditorModel( QContact* aContact ) :
    22 CntEmailEditorModel::CntEmailEditorModel( QContact* aContact ) :
    22 CntDetailEditorModel( aContact )
    23 CntDetailEditorModel( aContact )
    23     {
    24     {
    24     QList<QContactEmailAddress> addr = mContact->details<QContactEmailAddress>();
    25     mAddressList = CntDetailOrderingHelper::getOrderedEmailAccounts(*mContact);
    25     if ( addr.isEmpty() )
    26     if ( mAddressList.isEmpty() )
    26         {
    27         {
    27         QContactEmailAddress newAddr;
    28         QContactEmailAddress newAddr;
    28         addr.append( newAddr );
    29         mAddressList.append( newAddr );
    29         }
    30         }
    30     
    31     
    31     foreach ( QContactEmailAddress email, addr )
    32     foreach ( QContactEmailAddress email, mAddressList )
    32         {
    33         {
    33         CntDetailModelItem* item = new CntDetailModelItem( email );
    34         CntDetailModelItem* item = new CntDetailModelItem( email );
    34         appendDataFormItem( item, invisibleRootItem() );
    35         appendDataFormItem( item, invisibleRootItem() );
    35         }
    36         }
    36     }
    37     }
    39 {
    40 {
    40 }
    41 }
    41 
    42 
    42 void CntEmailEditorModel::insertDetailField()
    43 void CntEmailEditorModel::insertDetailField()
    43 {
    44 {
       
    45     // don't put this one in mAddressList since that list is used
       
    46     // to check if there's new items
    44     QContactEmailAddress newAddr;
    47     QContactEmailAddress newAddr;
    45     CntDetailModelItem* item = new CntDetailModelItem( newAddr );
    48     CntDetailModelItem* item = new CntDetailModelItem( newAddr );
    46     appendDataFormItem( item, invisibleRootItem() );
    49     appendDataFormItem( item, invisibleRootItem() );
    47 }
    50 }
    48 
    51 
    50 {
    53 {
    51     HbDataFormModelItem* root = invisibleRootItem();
    54     HbDataFormModelItem* root = invisibleRootItem();
    52     int count( root->childCount() );
    55     int count( root->childCount() );
    53     for ( int i(0); i < count; i++ ) {
    56     for ( int i(0); i < count; i++ ) {
    54         CntDetailModelItem* item = static_cast<CntDetailModelItem*>( root->childAt(i) );
    57         CntDetailModelItem* item = static_cast<CntDetailModelItem*>( root->childAt(i) );
    55         QContactDetail address = item->detail();
    58         QContactEmailAddress address = item->detail();
    56         mContact->saveDetail( &address );
    59         if ( !mAddressList.contains(address) && !address.emailAddress().isEmpty() )
    57         
    60         {
       
    61             mContact->saveDetail( &address );
       
    62             // this is not currently necessary since view is closed after this call.
       
    63             mAddressList.append( address );
       
    64         }
    58         if ( address.value(QContactEmailAddress::FieldEmailAddress).isEmpty() ) {
    65         if ( address.value(QContactEmailAddress::FieldEmailAddress).isEmpty() ) {
    59             mContact->removeDetail( &address );
    66             mContact->removeDetail( &address );
    60         }
    67         }
    61     }
    68     }
    62 }
    69 }