|
1 /* |
|
2 * Copyright (c) 2002-2007 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: Phonebook 2 contact editor synchronisation field. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include "CPbk2ContactEditorSyncField.h" |
|
20 |
|
21 // Phonebook 2 |
|
22 #include "MPbk2ContactEditorUiBuilder.h" |
|
23 #include "MPbk2ContactEditorFieldVisitor.h" |
|
24 #include <MPbk2FieldProperty.h> |
|
25 #include <CPbk2PresentationContactField.h> |
|
26 #include <Pbk2UIControls.rsg> |
|
27 #include "Pbk2UIControls.hrh" |
|
28 |
|
29 // Virtual Phonebook |
|
30 #include <MVPbkContactFieldTextData.h> |
|
31 #include <VPbkSyncConstants.h> |
|
32 |
|
33 // System includes |
|
34 #include <eikcapc.h> |
|
35 #include <eikedwin.h> |
|
36 #include <AknUtils.h> |
|
37 #include <badesca.h> |
|
38 #include <barsread.h> |
|
39 #include <AknPopupField.h> |
|
40 #include <AknQueryValueText.h> |
|
41 |
|
42 /// Unnamed namespace for local definitions |
|
43 namespace { |
|
44 const TInt KInitialValue = -1; |
|
45 |
|
46 /** |
|
47 * Synchronisation ordering. |
|
48 */ |
|
49 enum TPbkSyncronizationConf |
|
50 { |
|
51 /// Private |
|
52 EPbk2SyncConfPrivate = 0, |
|
53 /// Public |
|
54 EPbk2SyncConfPublic, |
|
55 /// Disabled |
|
56 EPbk2SyncConfNoSync |
|
57 }; |
|
58 |
|
59 } /// namespace |
|
60 |
|
61 // -------------------------------------------------------------------------- |
|
62 // CPbk2ContactEditorSyncField::CPbk2ContactEditorSyncField |
|
63 // -------------------------------------------------------------------------- |
|
64 // |
|
65 CPbk2ContactEditorSyncField::CPbk2ContactEditorSyncField |
|
66 ( CPbk2PresentationContactField& aContactField, |
|
67 MPbk2ContactEditorUiBuilder& aUiBuilder, |
|
68 CPbk2IconInfoContainer& aIconInfoContainer ) : |
|
69 CPbk2ContactEditorFieldBase( aContactField, aUiBuilder, |
|
70 aIconInfoContainer ), |
|
71 iIsUsingDefaultSyncValue( EFalse ), |
|
72 iInitialSyncConfSelection( KInitialValue ) |
|
73 { |
|
74 } |
|
75 |
|
76 // -------------------------------------------------------------------------- |
|
77 // CPbk2ContactEditorSyncField::~CPbk2ContactEditorSyncField |
|
78 // -------------------------------------------------------------------------- |
|
79 // |
|
80 CPbk2ContactEditorSyncField::~CPbk2ContactEditorSyncField() |
|
81 { |
|
82 delete iSyncArray; |
|
83 delete iSyncTextValues; |
|
84 delete iSyncArrayText; |
|
85 } |
|
86 |
|
87 // -------------------------------------------------------------------------- |
|
88 // CPbk2ContactEditorSyncField::NewLC |
|
89 // -------------------------------------------------------------------------- |
|
90 // |
|
91 CPbk2ContactEditorSyncField* CPbk2ContactEditorSyncField::NewLC |
|
92 ( CPbk2PresentationContactField& aContactField, |
|
93 MPbk2ContactEditorUiBuilder& aUiBuilder, |
|
94 CPbk2IconInfoContainer& aIconInfoContainer ) |
|
95 { |
|
96 CPbk2ContactEditorSyncField* self = |
|
97 new ( ELeave ) CPbk2ContactEditorSyncField( aContactField, |
|
98 aUiBuilder, aIconInfoContainer ); |
|
99 CleanupStack::PushL( self ); |
|
100 self->ConstructL(); |
|
101 return self; |
|
102 } |
|
103 |
|
104 // -------------------------------------------------------------------------- |
|
105 // CPbk2ContactEditorSyncField::ConstructL |
|
106 // -------------------------------------------------------------------------- |
|
107 // |
|
108 void CPbk2ContactEditorSyncField::ConstructL() |
|
109 { |
|
110 // Create text array |
|
111 iSyncArrayText = CEikonEnv::Static()->ReadDesCArrayResourceL |
|
112 ( R_PBK2_SYNC_POPUP_ITEMS ); |
|
113 iSyncArray = CAknQueryValueTextArray::NewL(); |
|
114 iSyncArray->SetArray(*iSyncArrayText); |
|
115 iSyncTextValues = CAknQueryValueText::NewL(); |
|
116 iSyncTextValues->SetArrayL(iSyncArray); |
|
117 |
|
118 // Set selection to correct item, if field contains some |
|
119 DoSetFieldValueAsCurrentSelection(); |
|
120 |
|
121 // Create and insert a line in the dialog |
|
122 iControl = static_cast<CAknPopupField*>(iUiBuilder.CreateLineL( |
|
123 FieldLabel(), ControlId(), EAknCtPopupField)); |
|
124 |
|
125 // Construct the CAknPopupField from resources |
|
126 TResourceReader reader; |
|
127 CEikonEnv::Static()->CreateResourceReaderLC( |
|
128 reader, R_PBK2_SYNCRONIZATION_POPUP_DLG); |
|
129 iControl->ConstructFromResourceL(reader); |
|
130 CleanupStack::PopAndDestroy(1); // R_PBK2_SYNCRONIZATION_POPUP_DLG |
|
131 |
|
132 // Control is now owned by the dialog |
|
133 iControl->SetQueryValueL(iSyncTextValues); |
|
134 |
|
135 iCaptionedCtrl = iUiBuilder.LineControl(ControlId()); |
|
136 iCaptionedCtrl->SetTakesEnterKey(ETrue); |
|
137 iCaptionedCtrl->SetOfferHotKeys(ETrue); |
|
138 } |
|
139 |
|
140 // -------------------------------------------------------------------------- |
|
141 // CPbk2ContactEditorSyncField::SaveFieldL |
|
142 // -------------------------------------------------------------------------- |
|
143 // |
|
144 void CPbk2ContactEditorSyncField::SaveFieldL() |
|
145 { |
|
146 iContactDataHasChanged = EFalse; |
|
147 |
|
148 // Retrieve the selected index |
|
149 const TInt selectedIndex = iSyncTextValues->CurrentValueIndex(); |
|
150 // Retrieve the sync setting text corresponding to the selection |
|
151 const TDesC* syncSetting = &KVPbkContactSyncPrivate; |
|
152 // Map setting indexes to sync settings |
|
153 switch(selectedIndex) |
|
154 { |
|
155 case EPbk2SyncConfPrivate: |
|
156 { |
|
157 syncSetting = &KVPbkContactSyncPrivate; |
|
158 break; |
|
159 } |
|
160 case EPbk2SyncConfPublic: |
|
161 { |
|
162 syncSetting = &KVPbkContactSyncPublic; |
|
163 break; |
|
164 } |
|
165 case EPbk2SyncConfNoSync: |
|
166 { |
|
167 syncSetting = &KVPbkContactSyncNoSync; |
|
168 break; |
|
169 } |
|
170 default: |
|
171 { |
|
172 syncSetting = &KVPbkContactSyncPrivate; |
|
173 break; |
|
174 } |
|
175 } |
|
176 |
|
177 // compare sync setting to existing setting in field |
|
178 MVPbkContactFieldTextData& data = MVPbkContactFieldTextData::Cast( |
|
179 iContactField.FieldData()); |
|
180 TPtrC fieldText(data.Text()); |
|
181 if (fieldText.CompareF(*syncSetting)) |
|
182 { |
|
183 // store the text in the contact item |
|
184 data.SetTextL(*syncSetting); |
|
185 iContactDataHasChanged = ETrue; |
|
186 } |
|
187 } |
|
188 |
|
189 // -------------------------------------------------------------------------- |
|
190 // CPbk2ContactEditorSyncField::FieldDataChanged |
|
191 // -------------------------------------------------------------------------- |
|
192 // |
|
193 TBool CPbk2ContactEditorSyncField::FieldDataChanged() const |
|
194 { |
|
195 TBool result = EFalse; |
|
196 if (iContactDataHasChanged) |
|
197 { |
|
198 if ( iIsUsingDefaultSyncValue && |
|
199 iSyncTextValues->CurrentValueIndex() == |
|
200 iInitialSyncConfSelection ) |
|
201 { |
|
202 // Default value has not been changed |
|
203 result = EFalse; |
|
204 } |
|
205 else |
|
206 { |
|
207 result = ETrue; |
|
208 } |
|
209 } |
|
210 return result; |
|
211 } |
|
212 |
|
213 // -------------------------------------------------------------------------- |
|
214 // CPbk2ContactEditorSyncField::ActivateL |
|
215 // -------------------------------------------------------------------------- |
|
216 // |
|
217 void CPbk2ContactEditorSyncField::ActivateL() |
|
218 { |
|
219 iCaptionedCtrl->ActivateL(); |
|
220 } |
|
221 |
|
222 // -------------------------------------------------------------------------- |
|
223 // CPbk2ContactEditorSyncField::Control |
|
224 // -------------------------------------------------------------------------- |
|
225 // |
|
226 HBufC* CPbk2ContactEditorSyncField::ControlTextL() const |
|
227 { |
|
228 return NULL; |
|
229 } |
|
230 |
|
231 // -------------------------------------------------------------------------- |
|
232 // CPbk2ContactEditorSyncField::Control |
|
233 // -------------------------------------------------------------------------- |
|
234 // |
|
235 CEikEdwin* CPbk2ContactEditorSyncField::Control() const |
|
236 { |
|
237 // Not called by the visitor, doesnt contain a edwin |
|
238 return NULL; |
|
239 } |
|
240 |
|
241 // -------------------------------------------------------------------------- |
|
242 // CPbk2ContactEditorSyncField::AcceptL |
|
243 // -------------------------------------------------------------------------- |
|
244 // |
|
245 void CPbk2ContactEditorSyncField::AcceptL |
|
246 ( MPbk2ContactEditorFieldVisitor& aVisitor ) |
|
247 { |
|
248 aVisitor.VisitL(*this); |
|
249 } |
|
250 |
|
251 // ----------------------------------------------------------------------------- |
|
252 // CPbk2ContactEditorSyncField::ConsumesKeyEvent |
|
253 // ----------------------------------------------------------------------------- |
|
254 // |
|
255 TBool CPbk2ContactEditorSyncField::ConsumesKeyEvent |
|
256 ( const TKeyEvent& aKeyEvent, TEventCode aType ) |
|
257 { |
|
258 TBool ret = EFalse; |
|
259 |
|
260 if (aType == EEventKey && aKeyEvent.iCode == EKeyOK) |
|
261 { |
|
262 ret = ETrue; |
|
263 } |
|
264 |
|
265 return ret; |
|
266 } |
|
267 |
|
268 // -------------------------------------------------------------------------- |
|
269 // CPbk2ContactEditorSyncField::DoSetFieldValueAsCurrentSelection |
|
270 // -------------------------------------------------------------------------- |
|
271 // |
|
272 void CPbk2ContactEditorSyncField::DoSetFieldValueAsCurrentSelection() |
|
273 { |
|
274 TInt selectedIndex = EPbk2SyncConfPrivate; |
|
275 iIsUsingDefaultSyncValue = ETrue; |
|
276 |
|
277 // get the text from the field |
|
278 MVPbkContactFieldTextData& data = MVPbkContactFieldTextData::Cast( |
|
279 iContactField.FieldData()); |
|
280 TPtrC fieldText(data.Text()); |
|
281 // safely detect whether theres syncronization setting in the field |
|
282 if (!fieldText.CompareF(KVPbkContactSyncPrivate)) |
|
283 { |
|
284 selectedIndex = EPbk2SyncConfPrivate; |
|
285 iIsUsingDefaultSyncValue = EFalse; |
|
286 } |
|
287 else if (!fieldText.CompareF(KVPbkContactSyncPublic)) |
|
288 { |
|
289 selectedIndex = EPbk2SyncConfPublic; |
|
290 iIsUsingDefaultSyncValue = EFalse; |
|
291 } |
|
292 else if (!fieldText.CompareF(KVPbkContactSyncNoSync)) |
|
293 { |
|
294 selectedIndex = EPbk2SyncConfNoSync; |
|
295 iIsUsingDefaultSyncValue = EFalse; |
|
296 } |
|
297 |
|
298 // set default value |
|
299 iSyncTextValues->SetCurrentValueIndex(selectedIndex); |
|
300 // store initial sync selection index |
|
301 iInitialSyncConfSelection = selectedIndex; |
|
302 } |
|
303 |
|
304 // -------------------------------------------------------------------------- |
|
305 // CPbk2ContactEditorSyncField::HandleCustomFieldCommandL |
|
306 // -------------------------------------------------------------------------- |
|
307 // |
|
308 TBool CPbk2ContactEditorSyncField::HandleCustomFieldCommandL(TInt aCommand ) |
|
309 { |
|
310 TBool ret(EFalse); |
|
311 |
|
312 if( aCommand == EPbk2CmdEditorChangeSync ) |
|
313 { |
|
314 iControl->ActivateSelectionListL(); |
|
315 ret = ETrue; |
|
316 } |
|
317 |
|
318 return ret; |
|
319 } |
|
320 |
|
321 // End of File |