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 |
|
18 #include "cntaddresseditorview.h" |
|
19 #include "cnteditordataviewitem.h" |
|
20 #include <hbinputstandardfilters.h> |
|
21 |
|
22 CntAddressEditorView::CntAddressEditorView(CntViewManager *viewManager, QGraphicsItem *parent): |
|
23 CntBaseDetailEditorView(viewManager, parent) |
|
24 { |
|
25 setHeader(hbTrId("txt_phob_subtitle_edit_address_details")); |
|
26 } |
|
27 |
|
28 CntAddressEditorView::~CntAddressEditorView() |
|
29 { |
|
30 |
|
31 } |
|
32 |
|
33 void CntAddressEditorView::aboutToCloseView() |
|
34 { |
|
35 for (int i = 0; i < mDetailList.count(); i++) |
|
36 { |
|
37 mContact->saveDetail(mDetailList.at(i)); |
|
38 |
|
39 if (mDetailList.at(i)->value(QContactAddress::FieldPostOfficeBox).isEmpty() && |
|
40 mDetailList.at(i)->value(QContactAddress::FieldStreet).isEmpty() && |
|
41 mDetailList.at(i)->value(QContactAddress::FieldPostcode).isEmpty() && |
|
42 mDetailList.at(i)->value(QContactAddress::FieldLocality).isEmpty() && |
|
43 mDetailList.at(i)->value(QContactAddress::FieldRegion).isEmpty() && |
|
44 mDetailList.at(i)->value(QContactAddress::FieldCountry).isEmpty()) |
|
45 { |
|
46 mContact->removeDetail(mDetailList.at(i)); |
|
47 } |
|
48 } |
|
49 CntBaseDetailEditorView::aboutToCloseView(); |
|
50 } |
|
51 |
|
52 void CntAddressEditorView::initializeForm() |
|
53 { |
|
54 QList<QContactAddress> addressDetails = mContact->details<QContactAddress>(); |
|
55 QContactAddress *address = 0; |
|
56 QContactAddress *addressHome = 0; |
|
57 QContactAddress *addressWork = 0; |
|
58 |
|
59 // we allow one address detail of each type: no context, home and work |
|
60 if (addressDetails.count() > 0) |
|
61 { |
|
62 for(int i = 0;i < addressDetails.count();i++) |
|
63 { |
|
64 QString context; |
|
65 if (addressDetails.at(i).contexts().count()) |
|
66 { |
|
67 context = addressDetails.at(i).contexts().at(0); |
|
68 } |
|
69 |
|
70 if (context.isEmpty() && address == 0) |
|
71 { |
|
72 address = new QContactAddress(addressDetails.at(i)); |
|
73 mDetailList.append(address); |
|
74 } |
|
75 else if (context == QContactDetail::ContextHome && addressHome == 0) |
|
76 { |
|
77 addressHome = new QContactAddress(addressDetails.at(i)); |
|
78 mDetailList.append(addressHome); |
|
79 } |
|
80 else if (context == QContactDetail::ContextWork && addressWork == 0) |
|
81 { |
|
82 addressWork = new QContactAddress(addressDetails.at(i)); |
|
83 mDetailList.append(addressWork); |
|
84 } |
|
85 } |
|
86 } |
|
87 else |
|
88 { |
|
89 address = new QContactAddress(); |
|
90 mDetailList.append(address); |
|
91 |
|
92 addressHome = new QContactAddress(); |
|
93 addressHome->setContexts(QContactDetail::ContextHome); |
|
94 mDetailList.append(addressHome); |
|
95 |
|
96 addressWork = new QContactAddress(); |
|
97 addressWork->setContexts(QContactDetail::ContextWork); |
|
98 mDetailList.append(addressWork); |
|
99 } |
|
100 |
|
101 // check if any of the address details isn't set yet |
|
102 if (address == 0) |
|
103 { |
|
104 address = new QContactAddress(); |
|
105 mDetailList.append(address); |
|
106 } |
|
107 if (addressHome == 0) |
|
108 { |
|
109 addressHome = new QContactAddress(); |
|
110 addressHome->setContexts(QContactDetail::ContextHome); |
|
111 mDetailList.append(addressHome); |
|
112 } |
|
113 if (addressWork == 0) |
|
114 { |
|
115 addressWork = new QContactAddress(); |
|
116 addressWork->setContexts(QContactDetail::ContextWork); |
|
117 mDetailList.append(addressWork); |
|
118 } |
|
119 |
|
120 HbDataFormModelItem *addressType = |
|
121 formModel()->appendDataFormGroup(hbTrId("txt_phob_list_address"), formModel()->invisibleRootItem()); |
|
122 |
|
123 //Details for addressDefault |
|
124 CntEditorDataModelItem *item = new CntEditorDataModelItem(*address, QContactAddress::FieldStreet, CNT_NAMES_EDITOR_MAXLENGTH, |
|
125 static_cast<HbDataFormModelItem::DataItemType>(HbDataFormModelItem::CustomItemBase+1), hbTrId("txt_phob_formlabel_street")); |
|
126 formModel()->appendDataFormItem(item, addressType); |
|
127 |
|
128 item = new CntEditorDataModelItem(*address, QContactAddress::FieldPostOfficeBox, CNT_POBOX_EDITOR_MAXLENGTH, |
|
129 static_cast<HbDataFormModelItem::DataItemType>(HbDataFormModelItem::CustomItemBase+1), hbTrId("P.O. Box")); |
|
130 item->setTextFilter(HbPhoneNumberFilter::instance()); |
|
131 formModel()->appendDataFormItem(item, addressType); |
|
132 |
|
133 item = new CntEditorDataModelItem(*address, QContactAddress::FieldPostcode, CNT_POBOX_EDITOR_MAXLENGTH, |
|
134 static_cast<HbDataFormModelItem::DataItemType>(HbDataFormModelItem::CustomItemBase+1), hbTrId("txt_phob_formlabel_post_code")); |
|
135 item->setTextFilter(HbPhoneNumberFilter::instance()); |
|
136 formModel()->appendDataFormItem(item, addressType); |
|
137 |
|
138 item = new CntEditorDataModelItem(*address, QContactAddress::FieldLocality, CNT_NAMES_EDITOR_MAXLENGTH, |
|
139 static_cast<HbDataFormModelItem::DataItemType>(HbDataFormModelItem::CustomItemBase+1), hbTrId("txt_phob_formlabel_city")); |
|
140 formModel()->appendDataFormItem(item, addressType); |
|
141 |
|
142 item = new CntEditorDataModelItem(*address, QContactAddress::FieldRegion, CNT_NAMES_EDITOR_MAXLENGTH, |
|
143 static_cast<HbDataFormModelItem::DataItemType>(HbDataFormModelItem::CustomItemBase+1), hbTrId("txt_phob_formlabel_province")); |
|
144 formModel()->appendDataFormItem(item, addressType); |
|
145 |
|
146 item = new CntEditorDataModelItem(*address, QContactAddress::FieldCountry, CNT_NAMES_EDITOR_MAXLENGTH, |
|
147 static_cast<HbDataFormModelItem::DataItemType>(HbDataFormModelItem::CustomItemBase+1), hbTrId("txt_phob_formlabel_country")); |
|
148 formModel()->appendDataFormItem(item, addressType); |
|
149 |
|
150 //Details for addressHome |
|
151 HbDataFormModelItem *addressHomeType = |
|
152 formModel()->appendDataFormGroup(hbTrId("txt_phob_subhead_address_home"), formModel()->invisibleRootItem()); |
|
153 |
|
154 item = new CntEditorDataModelItem(*addressHome, QContactAddress::FieldStreet, CNT_NAMES_EDITOR_MAXLENGTH, |
|
155 static_cast<HbDataFormModelItem::DataItemType>(HbDataFormModelItem::CustomItemBase+1), hbTrId("Street (home)")); |
|
156 formModel()->appendDataFormItem(item, addressHomeType); |
|
157 |
|
158 item = new CntEditorDataModelItem(*addressHome, QContactAddress::FieldPostOfficeBox, CNT_POBOX_EDITOR_MAXLENGTH, |
|
159 static_cast<HbDataFormModelItem::DataItemType>(HbDataFormModelItem::CustomItemBase+1), hbTrId("P.O. Box (home)")); |
|
160 item->setTextFilter(HbPhoneNumberFilter::instance()); |
|
161 formModel()->appendDataFormItem(item, addressHomeType); |
|
162 |
|
163 item = new CntEditorDataModelItem(*addressHome, QContactAddress::FieldPostcode, CNT_POBOX_EDITOR_MAXLENGTH, |
|
164 static_cast<HbDataFormModelItem::DataItemType>(HbDataFormModelItem::CustomItemBase+1), hbTrId("Postal code (home)")); |
|
165 item->setTextFilter(HbPhoneNumberFilter::instance()); |
|
166 formModel()->appendDataFormItem(item, addressHomeType); |
|
167 |
|
168 item = new CntEditorDataModelItem(*addressHome, QContactAddress::FieldLocality, CNT_NAMES_EDITOR_MAXLENGTH, |
|
169 static_cast<HbDataFormModelItem::DataItemType>(HbDataFormModelItem::CustomItemBase+1), hbTrId("City (home)")); |
|
170 formModel()->appendDataFormItem(item, addressHomeType); |
|
171 |
|
172 item = new CntEditorDataModelItem(*addressHome, QContactAddress::FieldRegion, CNT_NAMES_EDITOR_MAXLENGTH, |
|
173 static_cast<HbDataFormModelItem::DataItemType>(HbDataFormModelItem::CustomItemBase+1), hbTrId("Region (home)")); |
|
174 formModel()->appendDataFormItem(item, addressHomeType); |
|
175 |
|
176 item = new CntEditorDataModelItem(*addressHome, QContactAddress::FieldCountry, CNT_NAMES_EDITOR_MAXLENGTH, |
|
177 static_cast<HbDataFormModelItem::DataItemType>(HbDataFormModelItem::CustomItemBase+1), hbTrId("Country (home)")); |
|
178 formModel()->appendDataFormItem(item, addressHomeType); |
|
179 |
|
180 //Details for addressWork |
|
181 HbDataFormModelItem *addressWorkType = |
|
182 formModel()->appendDataFormGroup(hbTrId("txt_phob_subhead_address_work"), formModel()->invisibleRootItem()); |
|
183 |
|
184 item = new CntEditorDataModelItem(*addressWork, QContactAddress::FieldStreet, CNT_NAMES_EDITOR_MAXLENGTH, |
|
185 static_cast<HbDataFormModelItem::DataItemType>(HbDataFormModelItem::CustomItemBase+1), hbTrId("Street (work)")); |
|
186 formModel()->appendDataFormItem(item, addressWorkType); |
|
187 |
|
188 item = new CntEditorDataModelItem(*addressWork, QContactAddress::FieldPostOfficeBox, CNT_POBOX_EDITOR_MAXLENGTH, |
|
189 static_cast<HbDataFormModelItem::DataItemType>(HbDataFormModelItem::CustomItemBase+1), hbTrId("P.O. Box (work)")); |
|
190 item->setTextFilter(HbPhoneNumberFilter::instance()); |
|
191 formModel()->appendDataFormItem(item, addressWorkType); |
|
192 |
|
193 item = new CntEditorDataModelItem(*addressWork, QContactAddress::FieldPostcode, CNT_POBOX_EDITOR_MAXLENGTH, |
|
194 static_cast<HbDataFormModelItem::DataItemType>(HbDataFormModelItem::CustomItemBase+1), hbTrId("Postal code (work)")); |
|
195 item->setTextFilter(HbPhoneNumberFilter::instance()); |
|
196 formModel()->appendDataFormItem(item, addressWorkType); |
|
197 |
|
198 item = new CntEditorDataModelItem(*addressWork, QContactAddress::FieldLocality, CNT_NAMES_EDITOR_MAXLENGTH, |
|
199 static_cast<HbDataFormModelItem::DataItemType>(HbDataFormModelItem::CustomItemBase+1), hbTrId("City (work)")); |
|
200 formModel()->appendDataFormItem(item, addressWorkType); |
|
201 |
|
202 item = new CntEditorDataModelItem(*addressWork, QContactAddress::FieldRegion, CNT_NAMES_EDITOR_MAXLENGTH, |
|
203 static_cast<HbDataFormModelItem::DataItemType>(HbDataFormModelItem::CustomItemBase+1), hbTrId("Region (work)")); |
|
204 formModel()->appendDataFormItem(item, addressWorkType); |
|
205 |
|
206 item = new CntEditorDataModelItem(*addressWork, QContactAddress::FieldCountry, CNT_NAMES_EDITOR_MAXLENGTH, |
|
207 static_cast<HbDataFormModelItem::DataItemType>(HbDataFormModelItem::CustomItemBase+1), hbTrId("Country (work)")); |
|
208 formModel()->appendDataFormItem(item, addressWorkType); |
|
209 |
|
210 // Define which address type is expanded, by default normal address is opened |
|
211 if (mParamString.isEmpty()) |
|
212 { |
|
213 dataForm()->setExpanded(formModel()->indexFromItem(addressType), true); |
|
214 // set focus to street detail's lineedit |
|
215 static_cast<CntEditorDataViewItem*>(dataForm()->itemByIndex(formModel()->indexFromItem(addressType->childAt(0))))->focusLineEdit(); |
|
216 } |
|
217 else if (mParamString == QContactDetail::ContextHome) |
|
218 { |
|
219 dataForm()->setExpanded(formModel()->indexFromItem(addressHomeType), true); |
|
220 // set focus to street detail's lineedit |
|
221 static_cast<CntEditorDataViewItem*>(dataForm()->itemByIndex(formModel()->indexFromItem(addressHomeType->childAt(0))))->focusLineEdit(); |
|
222 } |
|
223 else if (mParamString == QContactDetail::ContextWork) |
|
224 { |
|
225 dataForm()->setExpanded(formModel()->indexFromItem(addressWorkType), true); |
|
226 // set focus to street detail's lineedit |
|
227 static_cast<CntEditorDataViewItem*>(dataForm()->itemByIndex(formModel()->indexFromItem(addressWorkType->childAt(0))))->focusLineEdit(); |
|
228 } |
|
229 } |
|
230 |
|