phonebookui/pbkcommonui/src/cntcompanyeditormodel.cpp
changeset 25 76a2435edfd4
child 31 2a11b5b00470
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 "cntcompanyeditormodel.h"
       
    18 #include "cntdetailconst.h"
       
    19 #include <qcontactorganization.h>
       
    20 
       
    21 CntCompanyEditorModel::CntCompanyEditorModel(QContact* aContact) :
       
    22     CntDetailEditorModel(aContact)
       
    23 {
       
    24     QList<QContactOrganization> orgList = mContact->details<QContactOrganization> ();
       
    25     if (orgList.isEmpty()) {
       
    26         QContactOrganization organization;
       
    27         orgList << organization;
       
    28     }
       
    29 
       
    30     mCompany = orgList.first();
       
    31 
       
    32     HbDataFormModelItem* organization = new HbDataFormModelItem(HbDataFormModelItem::TextItem,
       
    33         qtTrId("Company"));
       
    34     organization->setContentWidgetData("text", mCompany.name());
       
    35     organization->setContentWidgetData("maxLength", CNT_ORGANIZATION_MAXLENGTH);
       
    36 
       
    37     HbDataFormModelItem* jobTitle = new HbDataFormModelItem(HbDataFormModelItem::TextItem, qtTrId(
       
    38         "Job title"));
       
    39     jobTitle->setContentWidgetData("text", mCompany.title());
       
    40     jobTitle->setContentWidgetData("maxLength", CNT_JOBTITLE_MAXLENGTH);
       
    41 
       
    42     HbDataFormModelItem* department = new HbDataFormModelItem(HbDataFormModelItem::TextItem,
       
    43         qtTrId("Department"));
       
    44     department->setContentWidgetData("text", mCompany.department());
       
    45     department->setContentWidgetData("maxLength", CNT_DEPARTMENT_MAXLENGTH);
       
    46 
       
    47     HbDataFormModelItem* assistant = new HbDataFormModelItem(HbDataFormModelItem::TextItem, qtTrId(
       
    48         "Assistant name"));
       
    49     assistant->setContentWidgetData("text", mCompany.assistantName());
       
    50     assistant->setContentWidgetData("maxLength", CNT_ASSISTANT_MAXLENGTH);
       
    51 
       
    52     HbDataFormModelItem* root = invisibleRootItem();
       
    53     appendDataFormItem(organization, root);
       
    54     appendDataFormItem(jobTitle, root);
       
    55     appendDataFormItem(department, root);
       
    56     appendDataFormItem(assistant, root);
       
    57 }
       
    58 
       
    59 CntCompanyEditorModel::~CntCompanyEditorModel()
       
    60 {
       
    61 }
       
    62 
       
    63 void CntCompanyEditorModel::saveContactDetails()
       
    64 {
       
    65     HbDataFormModelItem* root = invisibleRootItem();
       
    66     if (!root->childAt(0)->contentWidgetData("text").toString().isEmpty())
       
    67         mCompany.setName( root->childAt(0)->contentWidgetData("text").toString() );
       
    68     else
       
    69         mCompany.setName(QString());
       
    70     if (!root->childAt(1)->contentWidgetData("text").toString().isEmpty())
       
    71         mCompany.setTitle( root->childAt(1)->contentWidgetData("text").toString() );
       
    72     else
       
    73         mCompany.setTitle(QString());
       
    74     if (!root->childAt(2)->contentWidgetData("text").toString().isEmpty())
       
    75         mCompany.setDepartment( root->childAt(2)->contentWidgetData("text").toString().split(", ") );
       
    76     else
       
    77         mCompany.setDepartment(QStringList());
       
    78     if (!root->childAt(3)->contentWidgetData("text").toString().isEmpty())
       
    79         mCompany.setAssistantName( root->childAt(3)->contentWidgetData("text").toString() );
       
    80     else
       
    81         mCompany.setAssistantName(QString());
       
    82     
       
    83     if ( !mCompany.isEmpty() ) {
       
    84         mContact->saveDetail( &mCompany );
       
    85     }
       
    86 }
       
    87 
       
    88 // End of File