phonebookui/pbkcommonui/src/cntcompanyeditormodel.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 "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         hbTrId("txt_phob_formlabel_company"));
       
    34     organization->setContentWidgetData("text", mCompany.name());
       
    35     organization->setContentWidgetData("maxLength", CNT_ORGANIZATION_MAXLENGTH);
       
    36 
       
    37     HbDataFormModelItem* jobTitle = new HbDataFormModelItem(HbDataFormModelItem::TextItem, 
       
    38         hbTrId("txt_phob_formlabel_job_title"));
       
    39     jobTitle->setContentWidgetData("text", mCompany.title());
       
    40     jobTitle->setContentWidgetData("maxLength", CNT_JOBTITLE_MAXLENGTH);
       
    41 
       
    42     HbDataFormModelItem* department = new HbDataFormModelItem(HbDataFormModelItem::TextItem,
       
    43         hbTrId("txt_phob_formlabel_department"));
       
    44     department->setContentWidgetData("text", mCompany.department());
       
    45     department->setContentWidgetData("maxLength", CNT_DEPARTMENT_MAXLENGTH);
       
    46 
       
    47     HbDataFormModelItem* assistant = new HbDataFormModelItem(HbDataFormModelItem::TextItem, 
       
    48         hbTrId("txt_phob_formlabel_assistant"));
       
    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     QString name = root->childAt(0)->contentWidgetData("text").toString();
       
    67     QString title = root->childAt(1)->contentWidgetData("text").toString();
       
    68     QString department = root->childAt(2)->contentWidgetData("text").toString();
       
    69     QString assistant = root->childAt(3)->contentWidgetData("text").toString();
       
    70     
       
    71     if ( mCompany.name() != name ||
       
    72          mCompany.title() != title || 
       
    73          mCompany.department().join(", ") != department ||
       
    74          mCompany.assistantName() != assistant )
       
    75     {
       
    76         mCompany.setName( name );
       
    77         mCompany.setTitle( title );
       
    78         mCompany.setDepartment( department.split(", ", QString::SkipEmptyParts) );
       
    79         mCompany.setAssistantName( assistant );
       
    80         mContact->saveDetail( &mCompany );
       
    81     }
       
    82     
       
    83     if ( mCompany.name().isEmpty() && 
       
    84          mCompany.title().isEmpty() &&
       
    85          mCompany.department().isEmpty() &&
       
    86          mCompany.assistantName().isEmpty() )
       
    87     {
       
    88         mContact->removeDetail( &mCompany );
       
    89     }
       
    90 }
       
    91 
       
    92 QContactDetail CntCompanyEditorModel::detail() const
       
    93 {
       
    94     return mCompany;
       
    95 }
       
    96 // End of File