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