1 /* |
|
2 * Copyright (c) 2005-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: XDM GS plugin Settins list container |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 // INCLUDE FILES |
|
22 #include "XDMExternalInterface.h" |
|
23 |
|
24 #include <aknappui.h> |
|
25 #include <akntitle.h> |
|
26 #include <eikspane.h> |
|
27 #include <barsread.h> |
|
28 #include <eiktxlbm.h> |
|
29 #include <aknlists.h> |
|
30 #include <AknUtils.h> |
|
31 #include <eiksbfrm.h> |
|
32 #include <XdmSettingsApi.h> |
|
33 #include <aknPopup.h> |
|
34 #include <StringLoader.h> |
|
35 #include <XdmSettingsCollection.h> |
|
36 #include <AknQueryDialog.h> |
|
37 #include <aknnotewrappers.h> |
|
38 #include <aknnotedialog.h> |
|
39 |
|
40 #include "XDMPluginSLContainer.h" |
|
41 #include "XDMPluginSettinglist.h" |
|
42 #include "SettingsData.h" |
|
43 |
|
44 #include <csxhelp/xdm.hlp.hrh> |
|
45 |
|
46 // LOCAL CONSTANTS AND MACROS |
|
47 _LIT(KFormatPostfix, "%S(%02d)"); |
|
48 _LIT(KFormatNoPostfix, "%S"); |
|
49 _LIT(KFormatLargePostfix, "%S(%d)"); |
|
50 const TInt KMaxPostfixLength = 5; |
|
51 |
|
52 // --------------------------------------------------------------------------- |
|
53 // CXDMPluginSLContainer::CXDMPluginSLContainer() |
|
54 // --------------------------------------------------------------------------- |
|
55 // |
|
56 CXDMPluginSLContainer::CXDMPluginSLContainer(CAknView* aView) : iView(aView) |
|
57 { |
|
58 } |
|
59 |
|
60 // --------------------------------------------------------------------------- |
|
61 // CXDMPluginSLContainer::ConstructL(const TRect& aRect) |
|
62 // --------------------------------------------------------------------------- |
|
63 // |
|
64 void CXDMPluginSLContainer::ConstructL( const TRect& aRect) |
|
65 { |
|
66 #ifdef _DEBUG |
|
67 RDebug::Print( _L( "[CXDMPluginSLContainer] ConstructL()" ) ); |
|
68 #endif |
|
69 |
|
70 CEikStatusPane* sp = static_cast<CAknAppUi*> |
|
71 ( CEikonEnv::Static()->EikAppUi() )->StatusPane(); |
|
72 CAknTitlePane* title = static_cast<CAknTitlePane*> |
|
73 ( sp->ControlL( TUid::Uid( EEikStatusPaneUidTitle ) ) ); |
|
74 |
|
75 // Set the proper title of this list |
|
76 TResourceReader rReader; |
|
77 iCoeEnv->CreateResourceReaderLC( rReader, R_GS_XDM_MAIN_VIEW_TITLE ); |
|
78 title->SetFromResourceL( rReader ); |
|
79 CleanupStack::PopAndDestroy(); //rReader |
|
80 |
|
81 CreateWindowL(); // Makes the control a window-owning control |
|
82 |
|
83 // construct the data object the settings list will use |
|
84 iData = CSettingsData::NewL(); |
|
85 // construct control and set parent |
|
86 iSettingList = CXDMPluginSettinglist::NewL(*iData); |
|
87 iSettingList->SetContainerWindowL(*this); |
|
88 |
|
89 // CreateResourceReaderLC will allocate a buffer to be used by |
|
90 // the TResourceReader. This buffer is pushed onto the cleanup |
|
91 // stack - not the TResourceReader itself |
|
92 CEikonEnv::Static()->CreateResourceReaderLC(rReader, R_SETTINGS); |
|
93 iSettingList->ConstructFromResourceL(rReader); |
|
94 |
|
95 // Clean up the buffer allocated above, NOT the reader itself. |
|
96 // Cannot use expected item overload of PopAndDestroy() as buffer |
|
97 // is inaccessible. |
|
98 CleanupStack::PopAndDestroy(); |
|
99 iSettingList->ActivateL(); |
|
100 |
|
101 SetRect( aRect ); |
|
102 ActivateL(); |
|
103 |
|
104 #ifdef _DEBUG |
|
105 RDebug::Print( _L( "[CXDMPluginSLContainer] Construct done" ) ); |
|
106 #endif |
|
107 } |
|
108 |
|
109 // --------------------------------------------------------------------------- |
|
110 // CXDMPluginSLContainer::~CXDMPluginSLContainer() |
|
111 // --------------------------------------------------------------------------- |
|
112 // |
|
113 CXDMPluginSLContainer::~CXDMPluginSLContainer() |
|
114 { |
|
115 if (iData) |
|
116 delete iData; |
|
117 if(iSettingList) // if setting list has been created |
|
118 { |
|
119 delete iSettingList; |
|
120 iSettingList = NULL; |
|
121 } |
|
122 } |
|
123 |
|
124 // --------------------------------------------------------------------------- |
|
125 // CXDMPluginSLContainer::SizeChanged() |
|
126 // --------------------------------------------------------------------------- |
|
127 // |
|
128 void CXDMPluginSLContainer::SizeChanged() |
|
129 { |
|
130 iSettingList->SetRect(Rect()); |
|
131 } |
|
132 |
|
133 // --------------------------------------------------------------------------- |
|
134 // CXDMPluginSLContainer::CountComponentControls() const |
|
135 // --------------------------------------------------------------------------- |
|
136 // |
|
137 TInt CXDMPluginSLContainer::CountComponentControls() const |
|
138 { |
|
139 return 1; |
|
140 } |
|
141 |
|
142 // --------------------------------------------------------------------------- |
|
143 // CXDMPluginSLContainer::ComponentControl( TInt aIndex ) const |
|
144 // --------------------------------------------------------------------------- |
|
145 // |
|
146 CCoeControl* CXDMPluginSLContainer::ComponentControl( TInt aIndex ) const |
|
147 { |
|
148 switch ( aIndex ) |
|
149 { |
|
150 case 0: |
|
151 return iSettingList; |
|
152 default: |
|
153 return NULL; |
|
154 } |
|
155 } |
|
156 |
|
157 // --------------------------------------------------------------------------- |
|
158 // CXDMPluginSLContainer::EditCurrentItemL() |
|
159 // --------------------------------------------------------------------------- |
|
160 // |
|
161 void CXDMPluginSLContainer::EditCurrentItemL() |
|
162 { |
|
163 iSettingList->EditCurrentItemL(); |
|
164 } |
|
165 |
|
166 // --------------------------------------------------------------------------- |
|
167 // CXDMPluginSLContainer::OfferKeyEventL() |
|
168 // --------------------------------------------------------------------------- |
|
169 // |
|
170 TKeyResponse CXDMPluginSLContainer::OfferKeyEventL( |
|
171 const TKeyEvent& aKeyEvent, |
|
172 TEventCode aType ) |
|
173 { |
|
174 if (iSettingList) |
|
175 return iSettingList->OfferKeyEventL(aKeyEvent, aType); |
|
176 else |
|
177 return EKeyWasNotConsumed; |
|
178 } |
|
179 |
|
180 // --------------------------------------------------------------------------- |
|
181 // CXDMPluginSLContainer::Draw(const TRect& aRect) const |
|
182 // --------------------------------------------------------------------------- |
|
183 // |
|
184 void CXDMPluginSLContainer::Draw(const TRect& aRect) const |
|
185 { |
|
186 CWindowGc& gc = SystemGc(); |
|
187 gc.Clear(aRect); |
|
188 } |
|
189 |
|
190 // --------------------------------------------------------------------------- |
|
191 // CXDMPluginSLContainer::HandleListBoxEventL() |
|
192 // --------------------------------------------------------------------------- |
|
193 // |
|
194 void CXDMPluginSLContainer::HandleListBoxEventL(CEikListBox* /*aListBox*/, TListBoxEvent aListBoxEvent) |
|
195 { |
|
196 // if the Select Key has been pressed |
|
197 if ((aListBoxEvent == MEikListBoxObserver::EEventEnterKeyPressed) || |
|
198 (aListBoxEvent == MEikListBoxObserver::EEventItemClicked)) |
|
199 { |
|
200 iSettingList->EditCurrentItemL(); |
|
201 } |
|
202 } |
|
203 |
|
204 // --------------------------------------------------------------------------- |
|
205 // CXDMPluginSLContainer::PrepareXDMSetForEditingL(TDesC& aXDMSetName) |
|
206 // --------------------------------------------------------------------------- |
|
207 // |
|
208 void CXDMPluginSLContainer::PrepareXDMSetForEditingL(TDesC& aXDMSetName) |
|
209 { |
|
210 TLex16 myLex; |
|
211 iData->Reset(); |
|
212 |
|
213 iData->iSettingName = aXDMSetName; |
|
214 AknTextUtils::ConvertDigitsTo(iData->iSettingName, EDigitTypeWestern ); |
|
215 iData->iSettingId = GetSettingIdL(iData->iSettingName); |
|
216 |
|
217 CXdmSettingsCollection* xDMSet = NULL; |
|
218 |
|
219 // read the source setting |
|
220 xDMSet = TXdmSettingsApi::SettingsCollectionL(iData->iSettingId); |
|
221 CleanupStack::PushL(xDMSet); |
|
222 |
|
223 iData->iSettingNameDisp = aXDMSetName; |
|
224 iData->iServerAddress = xDMSet->Property(EXdmPropUri); |
|
225 |
|
226 // AccessPoint handling |
|
227 iData->iAccessPointDes = xDMSet->Property(EXdmPropToNapId); |
|
228 myLex.Assign(iData->iAccessPointDes); |
|
229 myLex.Val(iData->iAccessPoint); |
|
230 |
|
231 iSettingList->GetAccessPointNameL(iData->iAccessPoint, iData->iAccessPointName); |
|
232 if ( (iData->iAccessPointName) == KNullDesC) // if name is not found |
|
233 { |
|
234 iData->iAccessPoint = -1; |
|
235 } |
|
236 |
|
237 iData->iUserID = xDMSet->Property(EXdmPropAuthName); |
|
238 iData->iPassword = xDMSet->Property(EXdmPropAuthSecret); |
|
239 |
|
240 CleanupStack::PopAndDestroy(1); //xDMSet |
|
241 iSettingList->LoadSettingsL(); |
|
242 SetTitlePaneTextL(iData->iSettingName); |
|
243 iSettingList->ResetItemIndex(); |
|
244 } |
|
245 |
|
246 // --------------------------------------------------------------------------- |
|
247 // CXDMPluginSLContainer::PrepareXDMSetNewDefaultL() |
|
248 // --------------------------------------------------------------------------- |
|
249 // |
|
250 void CXDMPluginSLContainer::PrepareXDMSetNewDefaultL() |
|
251 { |
|
252 iData->Reset(); |
|
253 |
|
254 HBufC* defName = StringLoader::LoadL( R_STR_XDM_NEW_SET ); |
|
255 CleanupStack::PushL( defName ); |
|
256 |
|
257 TBool changed; |
|
258 |
|
259 HBufC* newName = DoMakeValidNameL(defName, changed); |
|
260 |
|
261 if ( newName ) |
|
262 // name converted to unique |
|
263 { |
|
264 (iData->iSettingName).Copy(newName->Des()); |
|
265 delete newName; |
|
266 } |
|
267 else |
|
268 { |
|
269 (iData->iSettingName).Copy(defName->Des()); |
|
270 } |
|
271 CleanupStack::PopAndDestroy( defName ); |
|
272 |
|
273 iData->iSettingNameDisp = iData->iSettingName; |
|
274 AknTextUtils::LanguageSpecificNumberConversion(iData->iSettingNameDisp); |
|
275 |
|
276 iSettingList->LoadSettingsL(); |
|
277 iSettingList->ResetItemIndex(); |
|
278 iSettingList->DrawNow(); |
|
279 SetTitlePaneTextL(iData->iSettingName); |
|
280 } |
|
281 |
|
282 // --------------------------------------------------------------------------- |
|
283 // CXDMPluginSLContainer::PrepareNewXDMSetFromExistingL(TDesC& aXDMSetName) |
|
284 // --------------------------------------------------------------------------- |
|
285 // |
|
286 void CXDMPluginSLContainer::PrepareNewXDMSetFromExistingL(TDesC& aXDMSetName) |
|
287 { |
|
288 TLex16 myLex; |
|
289 |
|
290 // iData is already resetted in this case and iSettingId has id of |
|
291 // existing list from which data to be copied |
|
292 // we need to find the new name, from given name |
|
293 HBufC* originalName = aXDMSetName.AllocL(); |
|
294 CleanupStack::PushL( originalName ); |
|
295 |
|
296 // aXDMSetName is in disp format, need to convert to western format |
|
297 TPtr corrFormat(originalName->Des()); |
|
298 AknTextUtils::ConvertDigitsTo(corrFormat, EDigitTypeWestern ); |
|
299 |
|
300 TBool changed; |
|
301 |
|
302 HBufC* newName = DoMakeValidNameL(originalName, changed); |
|
303 |
|
304 if ( newName ) |
|
305 // name converted to unique |
|
306 { |
|
307 (iData->iSettingName).Copy(newName->Des()); |
|
308 delete newName; |
|
309 } |
|
310 else |
|
311 { |
|
312 (iData->iSettingName).Copy(originalName->Des()); |
|
313 } |
|
314 |
|
315 CleanupStack::PopAndDestroy( originalName ); |
|
316 |
|
317 |
|
318 CXdmSettingsCollection* xDMSet = NULL; |
|
319 |
|
320 // Displayable name |
|
321 iData->iSettingNameDisp = iData->iSettingName; |
|
322 AknTextUtils::LanguageSpecificNumberConversion(iData->iSettingNameDisp); |
|
323 |
|
324 // read the source setting |
|
325 xDMSet = TXdmSettingsApi::SettingsCollectionL(iData->iSettingId); |
|
326 CleanupStack::PushL(xDMSet); |
|
327 |
|
328 iData->iServerAddress = xDMSet->Property(EXdmPropUri); |
|
329 |
|
330 // AccessPoint handling |
|
331 iData->iAccessPointDes = xDMSet->Property(EXdmPropToNapId); |
|
332 myLex.Assign(iData->iAccessPointDes); |
|
333 myLex.Val(iData->iAccessPoint); |
|
334 |
|
335 iSettingList->GetAccessPointNameL(iData->iAccessPoint, iData->iAccessPointName); |
|
336 if ( (iData->iAccessPointName) == KNullDesC) // if name is not found |
|
337 { |
|
338 iData->iAccessPoint = -1; |
|
339 } |
|
340 |
|
341 iData->iUserID = xDMSet->Property(EXdmPropAuthName); |
|
342 iData->iPassword = xDMSet->Property(EXdmPropAuthSecret); |
|
343 |
|
344 // also overwrite the setting id now since we dont need it anymore |
|
345 iData->iSettingId = -1; |
|
346 CleanupStack::PopAndDestroy(1); //xDMSet |
|
347 iSettingList->LoadSettingsL(); |
|
348 SetTitlePaneTextL(iData->iSettingNameDisp); |
|
349 iSettingList->ResetItemIndex(); |
|
350 } |
|
351 |
|
352 // --------------------------------------------------------------------------- |
|
353 // CXDMPluginSLContainer::DisplayNewXDMSetOptions() |
|
354 // --------------------------------------------------------------------------- |
|
355 // |
|
356 TBool CXDMPluginSLContainer::DisplayNewXDMSetOptionsL() |
|
357 { |
|
358 // First phase construction of menu list |
|
359 CAknSinglePopupMenuStyleListBox* newXDMsetMenuList = |
|
360 new (ELeave) CAknSinglePopupMenuStyleListBox; |
|
361 CleanupStack::PushL(newXDMsetMenuList); |
|
362 |
|
363 // Create a popuplist to show the menu list in |
|
364 CAknPopupList* popupList = CAknPopupList::NewL( |
|
365 newXDMsetMenuList, |
|
366 R_AVKON_SOFTKEYS_OK_CANCEL); |
|
367 |
|
368 CleanupStack::PushL(popupList); |
|
369 |
|
370 // Second phase construction of menulist |
|
371 newXDMsetMenuList->ConstructL(popupList,EAknListBoxMenuList); |
|
372 // Set up scroll bars |
|
373 newXDMsetMenuList->CreateScrollBarFrameL(ETrue); |
|
374 newXDMsetMenuList->ScrollBarFrame()->SetScrollBarVisibilityL( |
|
375 CEikScrollBarFrame::EOff, CEikScrollBarFrame::EAuto); |
|
376 |
|
377 // Set up menu items |
|
378 CTextListBoxModel* model = newXDMsetMenuList->Model(); // not taking ownership |
|
379 model->SetOwnershipType (ELbmOwnsItemArray); // list'll delete with listbox |
|
380 RArray<TInt> settingIDs; |
|
381 CleanupClosePushL(settingIDs); |
|
382 CDesCArray* newXDMsetMenuListArray = NULL; |
|
383 |
|
384 TRAPD(err, newXDMsetMenuListArray = LoadCollectionNamesL(settingIDs, ETrue)); |
|
385 if(err!=KErrNone) |
|
386 { |
|
387 CleanupStack::PopAndDestroy(3); //newXDMsetMenuList, popupList, settingIDs |
|
388 return EFalse; |
|
389 } |
|
390 CleanupStack::PushL(newXDMsetMenuListArray); |
|
391 |
|
392 newXDMsetMenuListArray->Sort(ECmpCollated); |
|
393 model->SetItemTextArray(newXDMsetMenuListArray); |
|
394 CleanupStack::Pop(1); // newXDMsetMenuListArray owned by model |
|
395 CleanupStack::PopAndDestroy(1); //settingIDs |
|
396 |
|
397 // Set title |
|
398 HBufC* title; |
|
399 title = StringLoader::LoadLC(R_STR_XDM_USE_EXISTING); |
|
400 popupList->SetTitleL(*title); |
|
401 CleanupStack::PopAndDestroy(1); //title |
|
402 |
|
403 // Show the menu in the popup list |
|
404 TInt popupOk = popupList->ExecuteLD(); |
|
405 |
|
406 CleanupStack::Pop(popupList); |
|
407 |
|
408 // if the user selected some set |
|
409 if (popupOk) |
|
410 { |
|
411 iData->Reset(); |
|
412 TPtrC setName = newXDMsetMenuListArray->MdcaPoint |
|
413 (newXDMsetMenuList->CurrentItemIndex()); |
|
414 |
|
415 iData->iSettingId = GetSettingIdL(setName); |
|
416 (iData->iSettingNameDisp).Copy(setName); |
|
417 (iData->iSettingName).Copy(setName); |
|
418 AknTextUtils::ConvertDigitsTo(iData->iSettingName, EDigitTypeWestern ); |
|
419 CleanupStack::PopAndDestroy(newXDMsetMenuList); |
|
420 return ETrue; |
|
421 } |
|
422 // otherwise return false |
|
423 CleanupStack::PopAndDestroy(1); //newXDMsetMenuList |
|
424 return EFalse; |
|
425 } |
|
426 |
|
427 // --------------------------------------------------------------------------- |
|
428 // CXDMPluginSLContainer::SetTitlePaneTextL( const TDesC& aTitleText ) const |
|
429 // --------------------------------------------------------------------------- |
|
430 // |
|
431 void CXDMPluginSLContainer::SetTitlePaneTextL( const TDesC& aTitleText ) const |
|
432 { |
|
433 CAknTitlePane* title = static_cast< CAknTitlePane* > |
|
434 ( CEikonEnv::Static()->AppUiFactory()->StatusPane()->ControlL( |
|
435 TUid::Uid( EEikStatusPaneUidTitle ) ) ); |
|
436 if ( !title ) |
|
437 { |
|
438 User::Leave( KErrNotSupported ); |
|
439 } |
|
440 title->SetTextL( aTitleText ); |
|
441 } |
|
442 |
|
443 // --------------------------------------------------------------------------- |
|
444 // CXDMPluginSLContainer::AreCompulsoryItemsFilled() |
|
445 // --------------------------------------------------------------------------- |
|
446 // |
|
447 TBool CXDMPluginSLContainer::AreCompulsoryItemsFilled() |
|
448 { |
|
449 if ( (iData->iAccessPoint > -1) && ((iData->iServerAddress)!=KNullDesC) && |
|
450 ((iData->iUserID)!=KNullDesC) ) |
|
451 { |
|
452 return ETrue; |
|
453 } |
|
454 return EFalse; |
|
455 } |
|
456 |
|
457 // --------------------------------------------------------------------------- |
|
458 // CXDMPluginSLContainer::DisplayDeleteOrDontSaveDialog() |
|
459 // --------------------------------------------------------------------------- |
|
460 // |
|
461 TBool CXDMPluginSLContainer::DisplayDeleteOrDontSaveDialogL() |
|
462 { |
|
463 TBuf<KMaxMessageToDisplayLength> myDisplayMessage; |
|
464 CAknQueryDialog* query = CAknQueryDialog::NewL |
|
465 (CAknQueryDialog::EConfirmationTone); |
|
466 StringLoader::Load ( myDisplayMessage, R_STR_XDM_CONF_COMPULSORY ); |
|
467 return (query->ExecuteLD( R_CONFIRMATION_QUERY, myDisplayMessage )); |
|
468 } |
|
469 |
|
470 // --------------------------------------------------------------------------- |
|
471 // CXDMPluginSLContainer::DeleteXDMSetIfExistL() |
|
472 // --------------------------------------------------------------------------- |
|
473 // |
|
474 void CXDMPluginSLContainer::DeleteXDMSetIfExistL() |
|
475 { |
|
476 TRAPD(err, TXdmSettingsApi::RemoveCollectionL(iData->iSettingId)); |
|
477 if ( (err!=KErrNone) && (err!=KErrNotFound) ) |
|
478 { |
|
479 User::LeaveIfError(err); |
|
480 } |
|
481 } |
|
482 |
|
483 // --------------------------------------------------------------------------- |
|
484 // CXDMPluginSLContainer::IsExitProcessingOKL() |
|
485 // --------------------------------------------------------------------------- |
|
486 // |
|
487 TBool CXDMPluginSLContainer::IsExitProcessingOKL() |
|
488 { |
|
489 if (AreCompulsoryItemsFilled()) |
|
490 { |
|
491 return SaveOrCreateAndSaveXDMSetL(ETrue); |
|
492 } |
|
493 else |
|
494 { |
|
495 if (DisplayDeleteOrDontSaveDialogL()) |
|
496 { |
|
497 DeleteXDMSetIfExistL(); |
|
498 } |
|
499 else |
|
500 { |
|
501 return EFalse; |
|
502 } |
|
503 } |
|
504 return ETrue; |
|
505 } |
|
506 |
|
507 // --------------------------------------------------------------------------- |
|
508 // CXDMPluginSLContainer::SaveSettingsIfPossibleL() |
|
509 // --------------------------------------------------------------------------- |
|
510 // |
|
511 void CXDMPluginSLContainer::SaveSettingsIfPossibleL() |
|
512 { |
|
513 if (AreCompulsoryItemsFilled()) |
|
514 SaveOrCreateAndSaveXDMSetL(EFalse); |
|
515 } |
|
516 |
|
517 // --------------------------------------------------------------------------- |
|
518 // CXDMPluginSLContainer::SaveOrCreateAndSaveXDMSetL() |
|
519 // --------------------------------------------------------------------------- |
|
520 // |
|
521 TBool CXDMPluginSLContainer::SaveOrCreateAndSaveXDMSetL(TBool aShowDialog) |
|
522 { |
|
523 TBool ret = ETrue; |
|
524 CXdmSettingsCollection* myXDMSet(NULL); |
|
525 TInt err(KErrNotFound); // Initialize such that id not found in settings API |
|
526 |
|
527 // take the saveable name |
|
528 iData->iSettingName = iData->iSettingNameDisp; |
|
529 AknTextUtils::ConvertDigitsTo(iData->iSettingName, EDigitTypeWestern ); |
|
530 |
|
531 // check whether this is a new set or an existing set was edited |
|
532 if ((iData->iSettingId) > NULL) // is there is valid id |
|
533 { |
|
534 TRAP(err, myXDMSet = TXdmSettingsApi::SettingsCollectionL |
|
535 (iData->iSettingId)); |
|
536 } |
|
537 if(myXDMSet) |
|
538 { |
|
539 delete myXDMSet; // we dont need it |
|
540 } |
|
541 |
|
542 // check if the setting name is already exist |
|
543 // ask user to change name |
|
544 if (IsXDMSetNameExistL(iData->iSettingName, iData->iSettingId)) |
|
545 { |
|
546 if (!aShowDialog) // if we cant display dialog than return. |
|
547 return EFalse; |
|
548 HBufC* myDisplayMessage = NULL; |
|
549 CAknInformationNote* note = new (ELeave) CAknInformationNote( ETrue ); |
|
550 note->SetTimeout( CAknNoteDialog::ELongTimeout ); |
|
551 myDisplayMessage = StringLoader::LoadLC(R_STR_XDM_NAME_ALREADY_EXIST, iData->iSettingNameDisp); |
|
552 note->ExecuteLD( *myDisplayMessage ); |
|
553 CleanupStack::PopAndDestroy(1); //myDisplayMessage |
|
554 iSettingList->EditItemL(ESettingNameIndex,EFalse); |
|
555 return EFalse; |
|
556 } |
|
557 |
|
558 if(err == KErrNone) // if set exists update it |
|
559 { |
|
560 TXdmSettingsApi::UpdatePropertyL(iData->iSettingId, |
|
561 iData->iSettingName, EXdmPropName); |
|
562 TXdmSettingsApi::UpdatePropertyL(iData->iSettingId, |
|
563 iData->iAccessPointDes, EXdmPropToNapId); |
|
564 TXdmSettingsApi::UpdatePropertyL(iData->iSettingId, |
|
565 iData->iServerAddress, EXdmPropUri); |
|
566 TXdmSettingsApi::UpdatePropertyL(iData->iSettingId, |
|
567 iData->iUserID, EXdmPropAuthName); |
|
568 TXdmSettingsApi::UpdatePropertyL(iData->iSettingId, |
|
569 iData->iPassword, EXdmPropAuthSecret); |
|
570 ret = ETrue; |
|
571 } |
|
572 |
|
573 else if (err == KErrNotFound) // if set doenst exists create and save it |
|
574 { |
|
575 myXDMSet = new (ELeave) CXdmSettingsCollection(); |
|
576 CleanupStack::PushL(myXDMSet); |
|
577 myXDMSet->AppendL(iData->iSettingName, EXdmPropName); |
|
578 myXDMSet->AppendL(iData->iServerAddress, EXdmPropUri); |
|
579 myXDMSet->AppendL(iData->iAccessPointDes, EXdmPropToNapId); |
|
580 myXDMSet->AppendL(iData->iUserID, EXdmPropAuthName); |
|
581 myXDMSet->AppendL(iData->iPassword, EXdmPropAuthSecret); |
|
582 TRAPD(err,TXdmSettingsApi::CreateCollectionL(*myXDMSet)); |
|
583 err = err; //just to satisfy compiler |
|
584 CleanupStack::PopAndDestroy(1); // myXDMSet |
|
585 ret = ETrue; |
|
586 } |
|
587 |
|
588 else |
|
589 { |
|
590 User::LeaveIfError(err); |
|
591 } |
|
592 |
|
593 return ret; |
|
594 } |
|
595 |
|
596 // --------------------------------------------------------------------------- |
|
597 // CXDMPluginSLContainer::GetSettingIdL(TDesC& aXDMSetName) |
|
598 // --------------------------------------------------------------------------- |
|
599 // |
|
600 TInt CXDMPluginSLContainer::GetSettingIdL(TDesC& aXDMSetName) |
|
601 { |
|
602 TInt myId(-1); |
|
603 RArray<TInt> settingIds; |
|
604 CleanupClosePushL(settingIds); |
|
605 CDesCArray* xdmSetList =NULL; |
|
606 |
|
607 TBuf<KMaxSettingSetNameLength> setName = aXDMSetName; |
|
608 AknTextUtils::ConvertDigitsTo(setName, EDigitTypeWestern ); |
|
609 |
|
610 TRAPD(err, xdmSetList = LoadCollectionNamesL(settingIds, EFalse)); |
|
611 if(err!=KErrNone) |
|
612 { |
|
613 CleanupStack::PopAndDestroy(1); //settingIds |
|
614 return myId; |
|
615 } |
|
616 CleanupStack::PushL(xdmSetList); |
|
617 |
|
618 TInt xdmSetListCount = xdmSetList->Count(); |
|
619 for (TInt i = 0; i< xdmSetListCount; i++) |
|
620 { |
|
621 if (!((xdmSetList->MdcaPoint(i)).Compare(setName))) // if equal |
|
622 { |
|
623 myId = settingIds[i]; |
|
624 break; |
|
625 } |
|
626 } |
|
627 CleanupStack::PopAndDestroy(2); //xdmSetList,settingIds |
|
628 return myId; |
|
629 } |
|
630 |
|
631 // --------------------------------------------------------------------------- |
|
632 // CXDMPluginSLContainer::IsXDMSetNameExistL(TDesC& aXDMSetName, TInt32& aSettingId) |
|
633 // --------------------------------------------------------------------------- |
|
634 // |
|
635 TBool CXDMPluginSLContainer::IsXDMSetNameExistL(TDesC& aXDMSetName, TInt32& aSettingId) |
|
636 { |
|
637 TBool ret(EFalse); |
|
638 RArray<TInt> settingIds; |
|
639 CleanupClosePushL(settingIds); |
|
640 CDesCArray* xdmSetList = NULL; |
|
641 |
|
642 TBuf<KMaxSettingSetNameLength> setName = aXDMSetName; |
|
643 AknTextUtils::ConvertDigitsTo(setName, EDigitTypeWestern ); |
|
644 |
|
645 TRAPD(err, xdmSetList = LoadCollectionNamesL(settingIds, EFalse)); |
|
646 if(err!=KErrNone) |
|
647 { |
|
648 CleanupStack::PopAndDestroy(1); //settingIds |
|
649 return EFalse; |
|
650 } |
|
651 CleanupStack::PushL(xdmSetList); |
|
652 |
|
653 TInt xdmSetListCount = xdmSetList->Count(); |
|
654 for (TInt i = 0; i< xdmSetListCount; i++) |
|
655 { |
|
656 if (!((xdmSetList->MdcaPoint(i)).Compare(setName))) // if equal |
|
657 { |
|
658 if (settingIds[i] != aSettingId) // if the set is not itself |
|
659 { |
|
660 ret = ETrue; |
|
661 } |
|
662 } |
|
663 } |
|
664 CleanupStack::PopAndDestroy(2); //xdmSetList,settingIds |
|
665 return ret; |
|
666 } |
|
667 |
|
668 // --------------------------------------------------------------------------- |
|
669 // CXDMPluginSLContainer::LoadCollectionNamesL |
|
670 // --------------------------------------------------------------------------- |
|
671 // |
|
672 CDesCArray* CXDMPluginSLContainer::LoadCollectionNamesL(RArray<TInt>& aSettingIDs |
|
673 , TBool aDisp) |
|
674 { |
|
675 CDesCArray* myArray = TXdmSettingsApi::CollectionNamesLC(aSettingIDs); |
|
676 TBuf<KMaxSettingSetNameLength> name; |
|
677 if(aDisp) // convert all names to disp names |
|
678 { |
|
679 TInt count = myArray->Count(); |
|
680 CDesCArray* dispArray = new CDesCArrayFlat(count+1); |
|
681 CleanupStack::PushL(dispArray); |
|
682 for(TInt i=0;i<count;i++) |
|
683 { |
|
684 name.Copy(myArray->MdcaPoint(i)); |
|
685 AknTextUtils::LanguageSpecificNumberConversion(name); |
|
686 TPtrC16 ptr = name; |
|
687 dispArray->AppendL(ptr); |
|
688 } |
|
689 CleanupStack::Pop(2); |
|
690 return dispArray; |
|
691 } |
|
692 CleanupStack::Pop(1); // myArray |
|
693 return myArray; |
|
694 } |
|
695 |
|
696 // --------------------------------------------------------- |
|
697 // CXDMPluginSLContainer::GetHelpContext |
|
698 // This function is called when Help application is launched |
|
699 // (other items were commented in a header). |
|
700 // --------------------------------------------------------- |
|
701 // |
|
702 void CXDMPluginSLContainer::GetHelpContext( TCoeHelpContext& aContext ) const |
|
703 { |
|
704 aContext.iMajor = KGSXDMPluginUid; |
|
705 aContext.iContext = KXDM_HLP_EDIT_SET; |
|
706 } |
|
707 |
|
708 // --------------------------------------------------------------------------- |
|
709 // CXDMPluginSLContainer::HandleResourceChange() |
|
710 // --------------------------------------------------------------------------- |
|
711 void CXDMPluginSLContainer::HandleResourceChange( TInt aType ) |
|
712 { |
|
713 CCoeControl::HandleResourceChange( aType ); |
|
714 if ( aType == KAknsMessageSkinChange || |
|
715 aType == KEikDynamicLayoutVariantSwitch ) |
|
716 { |
|
717 } |
|
718 } |
|
719 |
|
720 |
|
721 // --------------------------------------------------------------------------- |
|
722 // CXDMPluginSLContainer::HandleResourceChangeManual() |
|
723 // --------------------------------------------------------------------------- |
|
724 void CXDMPluginSLContainer::HandleResourceChangeManual(TInt aType) |
|
725 { |
|
726 TRect mainPaneRect; |
|
727 AknLayoutUtils::LayoutMetricsRect( AknLayoutUtils::EMainPane, |
|
728 mainPaneRect); |
|
729 SetRect( mainPaneRect ); |
|
730 DrawDeferred(); |
|
731 |
|
732 iSettingList->HandleResourceChange(aType); |
|
733 } |
|
734 |
|
735 // --------------------------------------------------------------------------- |
|
736 // CXDMPluginSLContainer::FocusChanged |
|
737 // Set focus on the selected listbox. For animated skins feature. |
|
738 // --------------------------------------------------------------------------- |
|
739 void CXDMPluginSLContainer::FocusChanged(TDrawNow aDrawNow) |
|
740 { |
|
741 if(iSettingList) |
|
742 { |
|
743 iSettingList->SetFocus( IsFocused(), aDrawNow ); |
|
744 } |
|
745 } |
|
746 |
|
747 // --------------------------------------------------------------------------- |
|
748 // CXDMPluginSLContainer::GetCurrentSetName() |
|
749 // See header for details. |
|
750 // --------------------------------------------------------------------------- |
|
751 // |
|
752 TDes& CXDMPluginSLContainer::GetCurrentSetName() |
|
753 { |
|
754 return iData->iSettingName; |
|
755 } |
|
756 |
|
757 // --------------------------------------------------------------------------- |
|
758 // CXDMPluginSLContainer::DoMakeValidNameL() |
|
759 // See header for details. |
|
760 // --------------------------------------------------------------------------- |
|
761 // |
|
762 HBufC* CXDMPluginSLContainer::DoMakeValidNameL(HBufC* aName, TBool& aChanged) |
|
763 { |
|
764 aChanged = EFalse; |
|
765 HBufC* temp = HBufC::NewLC( KMaxSettingSetNameLength ); |
|
766 HBufC* temp2 = HBufC::NewLC( KMaxSettingSetNameLength ); |
|
767 |
|
768 HBufC* corrname = EnsureMaxLengthLC( aName, aChanged); |
|
769 *temp = *corrname; |
|
770 TInt postfix( 0 ); |
|
771 TInt pf( 0 ); |
|
772 TInt i( 0 ); |
|
773 |
|
774 |
|
775 // Load the names |
|
776 RArray<TInt> settingIDs; |
|
777 CleanupClosePushL(settingIDs); |
|
778 CDesCArray* xdmSetList = NULL; |
|
779 |
|
780 TRAPD(err, xdmSetList = LoadCollectionNamesL(settingIDs, EFalse)); |
|
781 if(err!=KErrNone) |
|
782 { |
|
783 CleanupStack::PopAndDestroy(4); //settingIds |
|
784 return corrname; |
|
785 } |
|
786 CleanupStack::PushL(xdmSetList); |
|
787 |
|
788 // do the actual checking of name |
|
789 TInt found(0); |
|
790 TInt pos(0); |
|
791 |
|
792 TPtrC prefix = GetPrefix( *corrname ); |
|
793 |
|
794 postfix = GetPostfix( *temp, prefix ); |
|
795 postfix = -1; |
|
796 do |
|
797 { |
|
798 found = xdmSetList->Find( *temp, pos ); |
|
799 if ( found == KErrNone ) |
|
800 { |
|
801 aChanged = ETrue; |
|
802 postfix++; |
|
803 // check the length of postfix, check text length accordingly |
|
804 pf = postfix; |
|
805 for (i=1; i<10; i++) |
|
806 { |
|
807 pf /= 10; |
|
808 if ( !pf ) |
|
809 break; |
|
810 } |
|
811 TPtr sgdptr( temp->Des() ); |
|
812 TPtr sgdptr2( temp2->Des() ); |
|
813 if ( postfix ) |
|
814 { |
|
815 if ( postfix < 10 ) |
|
816 { |
|
817 sgdptr2 = prefix.Left( KMaxSettingSetNameLength - i - 3 ); |
|
818 } |
|
819 else |
|
820 { |
|
821 sgdptr2 = prefix.Left( KMaxSettingSetNameLength - i - 2 ); |
|
822 } |
|
823 } |
|
824 else |
|
825 { |
|
826 sgdptr2 = prefix.Left( KMaxSettingSetNameLength ); |
|
827 } |
|
828 if ( postfix ) |
|
829 { |
|
830 if ( postfix > 9 ) |
|
831 { |
|
832 sgdptr.Format( KFormatLargePostfix, &sgdptr2, |
|
833 postfix ); |
|
834 } |
|
835 else |
|
836 { |
|
837 sgdptr.Format( KFormatPostfix, &sgdptr2, |
|
838 postfix ); |
|
839 } |
|
840 } |
|
841 else |
|
842 { |
|
843 sgdptr.Format( KFormatNoPostfix, &sgdptr2 ); |
|
844 } |
|
845 } |
|
846 } while (found == KErrNone); |
|
847 |
|
848 CleanupStack::PopAndDestroy(xdmSetList); |
|
849 CleanupStack::PopAndDestroy(1); //settingIds |
|
850 CleanupStack::PopAndDestroy( corrname ); |
|
851 CleanupStack::PopAndDestroy( temp2 ); |
|
852 |
|
853 if ( aChanged ) |
|
854 { |
|
855 CleanupStack::Pop( temp ); |
|
856 } |
|
857 else |
|
858 { |
|
859 CleanupStack::PopAndDestroy( temp ); |
|
860 temp = NULL; |
|
861 } |
|
862 |
|
863 return temp; |
|
864 } |
|
865 |
|
866 // --------------------------------------------------------------------------- |
|
867 // CXDMPluginSLContainer::EnsureMaxLengthLC() |
|
868 // See header for details. |
|
869 // --------------------------------------------------------------------------- |
|
870 HBufC* CXDMPluginSLContainer::EnsureMaxLengthLC( const TDesC* aName, TBool& aChanged) |
|
871 { |
|
872 TInt length = aName->Length(); |
|
873 |
|
874 aChanged = EFalse; |
|
875 |
|
876 if ( !length ) |
|
877 { |
|
878 // Name is required. |
|
879 User::Leave(KErrArgument); |
|
880 } |
|
881 |
|
882 HBufC* corrname; |
|
883 if ( KMaxSettingSetNameLength < length ) |
|
884 { // name too long, truncate. |
|
885 corrname = aName->Left( KMaxSettingSetNameLength ).AllocLC(); |
|
886 aChanged = ETrue; |
|
887 } |
|
888 else |
|
889 { |
|
890 corrname = aName->AllocLC(); |
|
891 corrname->Des().Trim(); |
|
892 if ( corrname->Length() == 0 ) |
|
893 { |
|
894 User::Leave(KErrArgument); |
|
895 } |
|
896 // comes here only if name is valid |
|
897 if ( corrname->Length() != aName->Length() ) |
|
898 { |
|
899 aChanged = ETrue; |
|
900 } |
|
901 } |
|
902 |
|
903 return corrname; |
|
904 } |
|
905 |
|
906 // --------------------------------------------------------------------------- |
|
907 // CXDMPluginSLContainer::GetPrefix() |
|
908 // See header for details. |
|
909 // --------------------------------------------------------------------------- |
|
910 TPtrC CXDMPluginSLContainer::GetPrefix( const TDesC& aName ) |
|
911 { |
|
912 TPtrC prefix = aName; |
|
913 TInt lastBrace = aName.LocateReverse('('); |
|
914 if ( lastBrace != KErrNotFound ) |
|
915 { |
|
916 // aName looks like "<prefix><brace><something>". |
|
917 // See if <something> is an integer number. |
|
918 TPtrC num = aName.Right( aName.Length() - lastBrace - 1 ); |
|
919 TInt val; |
|
920 TLex lex( num ); |
|
921 if ( lex.Val( val ) == KErrNone ) |
|
922 { |
|
923 // Yes, the trailer is an integer. |
|
924 prefix.Set( aName.Left( lastBrace ) ); |
|
925 } |
|
926 } |
|
927 return prefix; |
|
928 } |
|
929 |
|
930 // --------------------------------------------------------------------------- |
|
931 // CXDMPluginSLContainer::GetPostfix() |
|
932 // See header for details. |
|
933 // --------------------------------------------------------------------------- |
|
934 TInt CXDMPluginSLContainer::GetPostfix( const TDesC& aName, const TDesC& aPrefix ) |
|
935 { |
|
936 TInt postfix( KErrNotFound ); |
|
937 TInt nameLength = aName.Length(); |
|
938 TInt prefixLength = aPrefix.Length(); |
|
939 if ( nameLength >= prefixLength && aName.FindF( aPrefix ) == 0 ) |
|
940 { |
|
941 // aName is longer or equal length, and |
|
942 // aPrefix can be found in the beginning of aName. |
|
943 if ( nameLength == prefixLength ) |
|
944 { |
|
945 // They have the same length; they equal. |
|
946 postfix = 0; |
|
947 } |
|
948 else |
|
949 { |
|
950 if ( aName[ prefixLength ] == '(' ) |
|
951 { |
|
952 // (Now we know that aName is longer than aPrefix.) |
|
953 // aName looks like "aPrefix<brace><something>". |
|
954 // See if <something> is an integer number. |
|
955 TPtrC num = aName.Right( nameLength - prefixLength - 1 ); |
|
956 TBuf< KMaxPostfixLength > pf; |
|
957 if (num.Length() <= pf.Length()) |
|
958 pf = num; |
|
959 TInt val; |
|
960 TLex lex( pf ); |
|
961 if ( lex.Val( val ) == KErrNone ) |
|
962 { |
|
963 // Yes, the trailer is an integer. |
|
964 if ( val > 0 ) |
|
965 { |
|
966 postfix = val; |
|
967 } |
|
968 else |
|
969 { |
|
970 // signal that it is invalid... |
|
971 postfix = -1; |
|
972 } |
|
973 } |
|
974 } |
|
975 } |
|
976 } |
|
977 return postfix; |
|
978 } |
|
979 // end of file |
|