phonebookui/pbkcommonui/src/cntnameeditormodel.cpp
changeset 25 76a2435edfd4
child 37 fd64c38c277d
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 "cntnameeditormodel.h"
       
    18 #include "cntdetailconst.h"
       
    19 #include <qcontactname.h>
       
    20 #include <qcontactnickname.h>
       
    21 
       
    22 CntNameEditorModel::CntNameEditorModel(QContact* aContact) :
       
    23     CntDetailEditorModel(aContact)
       
    24 {
       
    25     QList<QContactName> nameList = mContact->details<QContactName> ();
       
    26     if (nameList.isEmpty()) {
       
    27         QContactName emptyName;
       
    28         nameList.append(emptyName);
       
    29     }
       
    30 
       
    31     QList<QContactNickname> nickList = mContact->details<QContactNickname> ();
       
    32     if (nickList.isEmpty()) {
       
    33         QContactNickname nick;
       
    34         nickList.append(nick);
       
    35     }
       
    36 
       
    37     // Only one name and nickname is supported
       
    38     iName = nameList.first();
       
    39     iNick = nickList.first();
       
    40 
       
    41     HbDataFormModelItem::DataItemType text = HbDataFormModelItem::TextItem;
       
    42     HbDataFormModelItem* firstname = new HbDataFormModelItem(text, qtTrId("First name"));
       
    43     HbDataFormModelItem* lastname = new HbDataFormModelItem(text, qtTrId("Last name"));
       
    44     HbDataFormModelItem* middlename = new HbDataFormModelItem(text,qtTrId("Middle name"));
       
    45     HbDataFormModelItem* nickname = new HbDataFormModelItem(text, qtTrId("Nick name"));
       
    46     HbDataFormModelItem* prefix = new HbDataFormModelItem(text, qtTrId("Prefix"));
       
    47     HbDataFormModelItem* suffix = new HbDataFormModelItem(text, qtTrId("Suffix"));
       
    48 
       
    49     firstname->setContentWidgetData("text", iName.firstName());
       
    50     firstname->setContentWidgetData("maxLength", CNT_FIRSTNAME_MAXLENGTH);
       
    51     lastname->setContentWidgetData("text", iName.lastName());
       
    52     lastname->setContentWidgetData("maxLength", CNT_LASTNAME_MAXLENGTH);
       
    53     middlename->setContentWidgetData("text", iName.middleName());
       
    54     middlename->setContentWidgetData("maxLength", CNT_MIDDLENAME_MAXLENGTH);
       
    55     nickname->setContentWidgetData("text", iNick.nickname());
       
    56     nickname->setContentWidgetData("maxLength", CNT_NICKNAME_MAXLENGTH);
       
    57     prefix->setContentWidgetData("text", iName.prefix());
       
    58     prefix->setContentWidgetData("maxLength", CNT_PREFIX_MAXLENGTH);
       
    59     suffix->setContentWidgetData("text", iName.suffix());
       
    60     suffix->setContentWidgetData("maxLength", CNT_SUFFIX_MAXLENGTH);
       
    61 
       
    62     HbDataFormModelItem* root = invisibleRootItem();
       
    63     appendDataFormItem(firstname, root);
       
    64     appendDataFormItem(lastname, root);
       
    65     appendDataFormItem(middlename, root);
       
    66     appendDataFormItem(nickname, root);
       
    67     appendDataFormItem(prefix, root);
       
    68     appendDataFormItem(suffix, root);
       
    69 }
       
    70 
       
    71 CntNameEditorModel::~CntNameEditorModel()
       
    72 {
       
    73 }
       
    74 
       
    75 void CntNameEditorModel::saveContactDetails()
       
    76 {
       
    77     HbDataFormModelItem* root = invisibleRootItem();
       
    78     iName.setFirstName( root->childAt( 0 )->contentWidgetData("text").toString().trimmed() );
       
    79     iName.setLastName( root->childAt( 1 )->contentWidgetData("text").toString().trimmed() );
       
    80     iName.setMiddleName( root->childAt( 2 )->contentWidgetData("text").toString().trimmed() );
       
    81     iNick.setNickname( root->childAt( 3 )->contentWidgetData("text").toString().trimmed() );
       
    82     iName.setPrefix( root->childAt( 4 )->contentWidgetData("text").toString().trimmed() );
       
    83     iName.setSuffix( root->childAt( 5 )->contentWidgetData("text").toString().trimmed() );
       
    84     
       
    85     mContact->saveDetail( &iName );
       
    86     mContact->saveDetail( &iNick );
       
    87     
       
    88     // remove empty details
       
    89     if (iName.firstName().isEmpty() &&
       
    90             iName.lastName().isEmpty() &&
       
    91             iName.middleName().isEmpty() &&
       
    92             iName.prefix().isEmpty() &&
       
    93             iName.suffix().isEmpty())
       
    94             {
       
    95             mContact->removeDetail( &iName );
       
    96             }
       
    97     if(iNick.nickname().isEmpty())
       
    98         {
       
    99         mContact->removeDetail( &iNick );
       
   100         }
       
   101 }
       
   102 
       
   103 // End of File