|
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 QStringList children = mFamily.children(); |
|
33 |
|
34 HbDataFormModelItem* spouseItem = new HbDataFormModelItem(HbDataFormModelItem::TextItem, |
|
35 qtTrId("Spouse")); |
|
36 spouseItem->setContentWidgetData("text", mFamily.spouse()); |
|
37 spouseItem->setContentWidgetData("maxLength", CNT_SPOUSE_MAXLENGTH); |
|
38 |
|
39 HbDataFormModelItem* childrenItem = new HbDataFormModelItem(HbDataFormModelItem::TextItem, |
|
40 qtTrId("Children")); |
|
41 childrenItem->setContentWidgetData("text", children.join(", ")); |
|
42 childrenItem->setContentWidgetData("maxLength", CNT_CHILDREN_MAXLENGTH); |
|
43 |
|
44 HbDataFormModelItem* root = invisibleRootItem(); |
|
45 appendDataFormItem(spouseItem, root); |
|
46 appendDataFormItem(childrenItem, root); |
|
47 } |
|
48 |
|
49 CntFamilyEditorModel::~CntFamilyEditorModel() |
|
50 { |
|
51 } |
|
52 |
|
53 void CntFamilyEditorModel::saveContactDetails() |
|
54 { |
|
55 HbDataFormModelItem* root = invisibleRootItem(); |
|
56 mFamily.setSpouse( root->childAt(0)->contentWidgetData("text").toString() ); |
|
57 |
|
58 QString children = root->childAt(1)->contentWidgetData("text").toString(); |
|
59 mFamily.setChildren( children.split(", ", QString::SkipEmptyParts) ); |
|
60 |
|
61 if ( !mFamily.isEmpty() ) { |
|
62 mContact->saveDetail( &mFamily ); |
|
63 } |
|
64 } |
|
65 // End of File |