|
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 "cntfamilyeditormodel.h" |
|
18 #include "cntdetailconst.h" |
|
19 #include <qcontactfamily.h> |
|
20 #include <hbdataformmodelitem.h> |
|
21 |
|
22 CntFamilyEditorModel::CntFamilyEditorModel(QContact* aContact) : |
|
23 CntDetailEditorModel(aContact) |
|
24 { |
|
25 QList<QContactFamily> familyList = mContact->details<QContactFamily> (); |
|
26 if (familyList.isEmpty()) { |
|
27 QContactFamily family; |
|
28 familyList << family; |
|
29 } |
|
30 |
|
31 mFamily = familyList.first(); |
|
32 |
|
33 HbDataFormModelItem* spouseItem = new HbDataFormModelItem(HbDataFormModelItem::TextItem, |
|
34 hbTrId("txt_phob_formlabel_spouse")); |
|
35 spouseItem->setContentWidgetData("text", mFamily.spouse()); |
|
36 spouseItem->setContentWidgetData("maxLength", CNT_SPOUSE_MAXLENGTH); |
|
37 |
|
38 HbDataFormModelItem* childrenItem = new HbDataFormModelItem(HbDataFormModelItem::TextItem, |
|
39 hbTrId("txt_phob_formlabel_children")); |
|
40 childrenItem->setContentWidgetData("text", mFamily.children().join(", ")); |
|
41 childrenItem->setContentWidgetData("maxLength", CNT_CHILDREN_MAXLENGTH); |
|
42 |
|
43 HbDataFormModelItem* root = invisibleRootItem(); |
|
44 appendDataFormItem(spouseItem, root); |
|
45 appendDataFormItem(childrenItem, root); |
|
46 } |
|
47 |
|
48 CntFamilyEditorModel::~CntFamilyEditorModel() |
|
49 { |
|
50 } |
|
51 |
|
52 void CntFamilyEditorModel::saveContactDetails() |
|
53 { |
|
54 HbDataFormModelItem* root = invisibleRootItem(); |
|
55 QString spouse = root->childAt(0)->contentWidgetData("text").toString(); |
|
56 QString children = root->childAt(1)->contentWidgetData("text").toString(); |
|
57 |
|
58 if ( spouse != mFamily.spouse() || children != mFamily.children().join(", ")) |
|
59 { |
|
60 mFamily.setSpouse( spouse ); |
|
61 QString children = root->childAt(1)->contentWidgetData("text").toString(); |
|
62 mFamily.setChildren( children.split(", ", QString::SkipEmptyParts) ); |
|
63 |
|
64 mContact->saveDetail( &mFamily ); |
|
65 } |
|
66 |
|
67 if ( mFamily.spouse().isEmpty() && mFamily.children().isEmpty() ) |
|
68 { |
|
69 mContact->removeDetail( &mFamily ); |
|
70 } |
|
71 |
|
72 } |
|
73 |
|
74 QContactDetail CntFamilyEditorModel::detail() const |
|
75 { |
|
76 return mFamily; |
|
77 } |
|
78 // End of File |