phonebookui/pbkcommonui/src/cnturleditormodel.cpp
branchRCL_3
changeset 62 5b6f26637ad3
equal deleted inserted replaced
58:d4f567ce2e7c 62:5b6f26637ad3
       
     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 "cnturleditormodel.h"
       
    18 #include "cntdetailmodelitem.h"
       
    19 #include "cntdetailorderinghelper.h"
       
    20 
       
    21 #include <qcontacturl.h>
       
    22 
       
    23 CntUrlEditorModel::CntUrlEditorModel(QContact* aContact) :
       
    24     CntDetailEditorModel(aContact)
       
    25 {
       
    26     mUrlList = CntDetailOrderingHelper::getOrderedUrls(*mContact);
       
    27     if (mUrlList.isEmpty()) {
       
    28         QContactUrl url;
       
    29         url.setSubType(QContactUrl::SubTypeHomePage);
       
    30         mUrlList.append(url);
       
    31     }
       
    32 
       
    33     foreach( QContactUrl contactUrl, mUrlList ) {
       
    34         CntDetailModelItem* item = new CntDetailModelItem(contactUrl);
       
    35         appendDataFormItem(item, invisibleRootItem());
       
    36     }
       
    37 }
       
    38 
       
    39 CntUrlEditorModel::~CntUrlEditorModel()
       
    40 {
       
    41 }
       
    42 
       
    43 void CntUrlEditorModel::insertDetailField()
       
    44 {
       
    45     QContactUrl url;
       
    46     url.setSubType(QContactUrl::SubTypeHomePage);
       
    47     mUrlList.append( url );
       
    48     appendDataFormItem( new CntDetailModelItem(url), invisibleRootItem() );
       
    49 }
       
    50 
       
    51 void CntUrlEditorModel::saveContactDetails()
       
    52 {
       
    53     HbDataFormModelItem* root = invisibleRootItem();
       
    54 
       
    55     int count(root->childCount());
       
    56     for (int i(0); i < count; i++) {
       
    57         CntDetailModelItem* detail = static_cast<CntDetailModelItem*> (root->childAt(i));
       
    58         QContactDetail url = detail->detail();
       
    59         
       
    60         if ( !mUrlList.contains(url) )
       
    61         {
       
    62             mContact->saveDetail( &url );
       
    63         }
       
    64         
       
    65         if ( url.value(QContactUrl::FieldUrl).isEmpty() )
       
    66         {
       
    67             mContact->removeDetail( &url );
       
    68         }
       
    69     }
       
    70 }
       
    71 
       
    72 QContactDetail CntUrlEditorModel::detail() const 
       
    73 {
       
    74     QListIterator<QContactUrl> urlList(mContact->details<QContactUrl>());
       
    75     urlList.toBack(); // go through backwards, so the newest item will be returned
       
    76     while ( urlList.hasPrevious() )
       
    77     {
       
    78         QContactUrl url = urlList.previous();
       
    79         if ( !url.value(QContactUrl::FieldUrl).isEmpty() )
       
    80         {
       
    81             return url;
       
    82         }
       
    83     }
       
    84     return QContactEmailAddress(); // return empty address if none found
       
    85 }
       
    86 // End of File
       
    87