|
1 /* |
|
2 * Copyright (c) 2006 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: Domain selection query pop-up |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include <akniconutils.h> |
|
20 #include <avkon.mbg> |
|
21 #include <cimpssapsettings.h> |
|
22 #include <cimpssapsettingsstore.h> |
|
23 #include <cimpssapsettingslist.h> |
|
24 |
|
25 #include "ccnuidomainselectionquerydialog.h" |
|
26 |
|
27 _LIT( KListItemFormat, "%d\t%S" ); |
|
28 _LIT( KIMPreviousDomainIndex, "KIMPreviousDomainIndex" ); |
|
29 |
|
30 // ======== MEMBER FUNCTIONS ======== |
|
31 |
|
32 // --------------------------------------------------------------------------- |
|
33 // CCnUiDomainSelectionQueryDialog::CCnUiDomainSelectionQueryDialog |
|
34 // --------------------------------------------------------------------------- |
|
35 // |
|
36 CCnUiDomainSelectionQueryDialog::CCnUiDomainSelectionQueryDialog( |
|
37 TInt* aIndex, CIMPSSAPSettings* aSap ) |
|
38 : CAknListQueryDialog( aIndex ), |
|
39 iOwnershipType( ELbmOwnsItemArray ), |
|
40 iSap( aSap ), |
|
41 iSapOwned( EFalse ) |
|
42 { |
|
43 // No implementation needed |
|
44 } |
|
45 |
|
46 // --------------------------------------------------------------------------- |
|
47 // CCnUiDomainSelectionQueryDialog::ConstructL |
|
48 // --------------------------------------------------------------------------- |
|
49 // |
|
50 void CCnUiDomainSelectionQueryDialog::ConstructL() |
|
51 { |
|
52 TPtrC avkonBmpPath( AknIconUtils::AvkonIconFileName() ); |
|
53 |
|
54 // Create icons for radio button and empty A-column icon |
|
55 AknIconUtils::CreateIconL( |
|
56 iRadioButton, |
|
57 iRadioButtonMask, |
|
58 avkonBmpPath, |
|
59 EMbmAvkonQgn_indi_radiobutt_on, |
|
60 EMbmAvkonQgn_indi_radiobutt_on_mask ); |
|
61 |
|
62 AknIconUtils::CreateIconL( |
|
63 iEmpty, |
|
64 iEmptyMask, |
|
65 avkonBmpPath, |
|
66 EMbmAvkonQgn_indi_radiobutt_off, |
|
67 EMbmAvkonQgn_indi_radiobutt_off_mask ); |
|
68 |
|
69 // Try to find stored SAP, needed for accessing previously |
|
70 // selected domain index when query is displayed again after |
|
71 // user has emptied user id field in id & password query. |
|
72 // If stored SAP is not found iSap is used directly. |
|
73 if ( iSap ) |
|
74 { |
|
75 CIMPSSAPSettingsStore* sapStore = CIMPSSAPSettingsStore::NewLC(); |
|
76 CIMPSSAPSettingsList* sapList = CIMPSSAPSettingsList::NewLC(); |
|
77 sapStore->PopulateSAPSettingsListL( *sapList, EIMPSIMAccessGroup ); |
|
78 |
|
79 // Because logged in SAP has UID of zero, we must |
|
80 // find the correct UID manually from list |
|
81 TInt index = KErrNotFound; |
|
82 TInt retVal = sapList->FindNameL( iSap->SAPName(), index ); |
|
83 |
|
84 if ( index != KErrNotFound && retVal != KErrNotFound ) |
|
85 { |
|
86 // Found it, use it |
|
87 CIMPSSAPSettings* storedSap = CIMPSSAPSettings::NewLC(); |
|
88 |
|
89 TUint32 sapUid = sapList->UidForIndex( index ); |
|
90 sapStore->GetSAPL( sapUid, storedSap ); |
|
91 |
|
92 iSap = storedSap; |
|
93 iSapOwned = ETrue; |
|
94 CleanupStack::Pop( storedSap ); |
|
95 } |
|
96 |
|
97 CleanupStack::PopAndDestroy( 2, sapStore ); |
|
98 } |
|
99 } |
|
100 |
|
101 |
|
102 // --------------------------------------------------------------------------- |
|
103 // CCnUiDomainSelectionQueryDialog::NewL |
|
104 // --------------------------------------------------------------------------- |
|
105 // |
|
106 CCnUiDomainSelectionQueryDialog* CCnUiDomainSelectionQueryDialog::NewL( |
|
107 TInt* aIndex, |
|
108 CIMPSSAPSettings* aSap /*= NULL*/ ) |
|
109 { |
|
110 CCnUiDomainSelectionQueryDialog* self = |
|
111 new ( ELeave ) CCnUiDomainSelectionQueryDialog( aIndex, aSap ); |
|
112 CleanupStack::PushL( self ); |
|
113 self->ConstructL(); |
|
114 CleanupStack::Pop( self ); |
|
115 return self; |
|
116 } |
|
117 |
|
118 // --------------------------------------------------------------------------- |
|
119 // CCnUiDomainSelectionQueryDialog::~CCnUiDomainSelectionQueryDialog |
|
120 // --------------------------------------------------------------------------- |
|
121 // |
|
122 CCnUiDomainSelectionQueryDialog::~CCnUiDomainSelectionQueryDialog() |
|
123 { |
|
124 delete iRadioButton; |
|
125 delete iRadioButtonMask; |
|
126 delete iEmpty; |
|
127 delete iEmptyMask; |
|
128 |
|
129 if ( iOwnershipType == ELbmOwnsItemArray ) |
|
130 { |
|
131 delete iItemTextArray; |
|
132 } |
|
133 |
|
134 if ( iSapOwned ) |
|
135 { |
|
136 delete iSap; |
|
137 } |
|
138 } |
|
139 |
|
140 // --------------------------------------------------------------------------- |
|
141 // From class CAknListQueryDialog. |
|
142 // CCnUiDomainSelectionQueryDialog::OfferKeyEventL |
|
143 // --------------------------------------------------------------------------- |
|
144 // |
|
145 TKeyResponse CCnUiDomainSelectionQueryDialog::OfferKeyEventL( |
|
146 const TKeyEvent& aKeyEvent, TEventCode aType ) |
|
147 { |
|
148 return CAknListQueryDialog::OfferKeyEventL( aKeyEvent, aType ); |
|
149 } |
|
150 |
|
151 // --------------------------------------------------------------------------- |
|
152 // From class CAknListQueryDialog. |
|
153 // CCnUiDomainSelectionQueryDialog::PreLayoutDynInitL |
|
154 // --------------------------------------------------------------------------- |
|
155 // |
|
156 void CCnUiDomainSelectionQueryDialog::PreLayoutDynInitL() |
|
157 { |
|
158 // First call PreLayoutDynInitL from base class |
|
159 CAknListQueryDialog::PreLayoutDynInitL(); |
|
160 |
|
161 TInt prevIndex = 0; |
|
162 |
|
163 // Get previous selected domain from sap |
|
164 if ( iSap ) |
|
165 { |
|
166 TInt sapError; |
|
167 sapError = iSap->GetOpaqueInt( KIMPreviousDomainIndex, prevIndex ); |
|
168 |
|
169 if ( sapError != KErrNotFound && sapError != KErrNone ) |
|
170 { |
|
171 User::Leave( sapError ); |
|
172 } |
|
173 } |
|
174 |
|
175 // Check prevIndex for array boundaries |
|
176 // If resources are changed prevIndex may go out of bounds |
|
177 if ( prevIndex > ( ListBox()->Model()->NumberOfItems() - 1 ) ) |
|
178 { |
|
179 prevIndex = 0; |
|
180 } |
|
181 |
|
182 UpdateRadioButtonL( prevIndex ); |
|
183 ListBox()->SetCurrentItemIndex( prevIndex ); |
|
184 } |
|
185 |
|
186 // --------------------------------------------------------------------------- |
|
187 // From class CAknListQueryDialog. |
|
188 // CCnUiDomainSelectionQueryDialog::OkToExitL |
|
189 // --------------------------------------------------------------------------- |
|
190 // |
|
191 TBool CCnUiDomainSelectionQueryDialog::OkToExitL( TInt aButtonId ) |
|
192 { |
|
193 // Check reaction of query to button id |
|
194 TBool exit = CAknListQueryDialog::OkToExitL( aButtonId ); |
|
195 |
|
196 if ( exit ) |
|
197 { |
|
198 TInt itemIndex = ListBox()->CurrentItemIndex(); |
|
199 |
|
200 // Update radio button before exiting |
|
201 UpdateRadioButtonL( itemIndex, ETrue ); |
|
202 |
|
203 // Update selected domain index to SAP |
|
204 if ( iSap ) |
|
205 { |
|
206 CIMPSSAPSettingsStore* sapStore = CIMPSSAPSettingsStore::NewLC(); |
|
207 CIMPSSAPSettingsList* sapList = CIMPSSAPSettingsList::NewLC(); |
|
208 sapStore->PopulateSAPSettingsListL( *sapList, EIMPSIMAccessGroup ); |
|
209 |
|
210 // Because logged in SAP has UID of zero, we must |
|
211 // find the correct UID manually from list |
|
212 TInt index = KErrNotFound; |
|
213 TInt retVal = sapList->FindNameL( iSap->SAPName(), index ); |
|
214 |
|
215 if ( index != KErrNotFound && retVal != KErrNotFound ) |
|
216 { |
|
217 // Found it, update the correct SAP |
|
218 CIMPSSAPSettings* storedSap = CIMPSSAPSettings::NewLC(); |
|
219 |
|
220 TUint32 sapUid = sapList->UidForIndex( index ); |
|
221 sapStore->GetSAPL( sapUid, storedSap ); |
|
222 storedSap->SetOpaqueInt( KIMPreviousDomainIndex, itemIndex ); |
|
223 sapStore->UpdateOldSAPL( storedSap, sapUid ); |
|
224 |
|
225 CleanupStack::PopAndDestroy( storedSap ); |
|
226 } |
|
227 else |
|
228 { |
|
229 iSap->SetOpaqueInt( KIMPreviousDomainIndex, itemIndex ); |
|
230 } |
|
231 |
|
232 CleanupStack::PopAndDestroy( 2, sapStore ); |
|
233 } |
|
234 } |
|
235 |
|
236 return exit; |
|
237 } |
|
238 |
|
239 // --------------------------------------------------------------------------- |
|
240 // From class CAknListQueryDialog. |
|
241 // CCnUiDomainSelectionQueryDialog::SetItemTextArray |
|
242 // --------------------------------------------------------------------------- |
|
243 // |
|
244 void CCnUiDomainSelectionQueryDialog::SetItemTextArray( MDesCArray* aItemTextArray ) |
|
245 { |
|
246 iItemTextArray = aItemTextArray; |
|
247 |
|
248 // Create array with icon indexes |
|
249 TRAP_IGNORE( |
|
250 TInt itemCount = iItemTextArray->MdcaCount(); |
|
251 |
|
252 CDesCArray* indexedArray = new ( ELeave ) CDesCArrayFlat( itemCount ); |
|
253 CleanupStack::PushL( indexedArray ); |
|
254 |
|
255 for ( TInt i = 0; i < itemCount; ++i ) |
|
256 { |
|
257 TPtrC item = iItemTextArray->MdcaPoint( i ); |
|
258 HBufC* indexedItem = HBufC::NewLC( item.Length() + KListItemFormat().Length() ); |
|
259 TPtr ptr( indexedItem->Des() ); |
|
260 ptr.Format( KListItemFormat, i, &item ); |
|
261 indexedArray->AppendL( *indexedItem ); |
|
262 CleanupStack::PopAndDestroy( indexedItem ); |
|
263 } |
|
264 |
|
265 // Set indexed array for CAknListQueryDialog |
|
266 CAknListQueryDialog::SetItemTextArray( indexedArray ); |
|
267 CAknListQueryDialog::SetOwnershipType( ELbmOwnsItemArray ); |
|
268 CleanupStack::Pop( indexedArray ); |
|
269 ); // TRAP_IGNORE |
|
270 } |
|
271 |
|
272 // --------------------------------------------------------------------------- |
|
273 // From class CAknListQueryDialog. |
|
274 // CCnUiDomainSelectionQueryDialog::SetOwnershipType |
|
275 // --------------------------------------------------------------------------- |
|
276 // |
|
277 void CCnUiDomainSelectionQueryDialog::SetOwnershipType( |
|
278 TListBoxModelItemArrayOwnership aOwnershipType ) |
|
279 { |
|
280 iOwnershipType = aOwnershipType; |
|
281 } |
|
282 |
|
283 // --------------------------------------------------------------------------- |
|
284 // CCnUiDomainSelectionQueryDialog::UpdateRadioButtonL |
|
285 // --------------------------------------------------------------------------- |
|
286 // |
|
287 void CCnUiDomainSelectionQueryDialog::UpdateRadioButtonL( |
|
288 TInt aSelectedIndex, |
|
289 TBool aForceUpdate /*= EFalse*/ ) |
|
290 { |
|
291 TInt itemCount = iItemTextArray->MdcaCount(); |
|
292 |
|
293 CArrayPtr<CGulIcon>* iconsArray = new ( ELeave ) CArrayPtrFlat<CGulIcon>( itemCount ); |
|
294 CleanupStack::PushL( TCleanupItem( DestroyCloseArray, iconsArray ) ); |
|
295 |
|
296 for ( TInt i = 0; i < itemCount; ++i ) |
|
297 { |
|
298 CGulIcon* icon = NULL; |
|
299 |
|
300 if ( i == aSelectedIndex ) |
|
301 { |
|
302 icon = CGulIcon::NewL( iRadioButton, iRadioButtonMask ); |
|
303 } |
|
304 else |
|
305 { |
|
306 icon = CGulIcon::NewL( iEmpty, iEmptyMask ); |
|
307 } |
|
308 |
|
309 // Keep ownership of bitmaps |
|
310 icon->SetBitmapsOwnedExternally( ETrue ); |
|
311 CleanupStack::PushL( icon ); |
|
312 iconsArray->AppendL( icon ); // Ownership transferred |
|
313 CleanupStack::Pop( icon ); |
|
314 } |
|
315 |
|
316 // Set icons to query |
|
317 SetIconArrayL( iconsArray ); |
|
318 CleanupStack::Pop( iconsArray ); // Ownership transferred |
|
319 |
|
320 if ( aForceUpdate ) |
|
321 { |
|
322 // Call DrawNow from list box to avoid flickering of dialog |
|
323 ListBox()->DrawNow(); |
|
324 } |
|
325 } |
|
326 |
|
327 // --------------------------------------------------------------------------- |
|
328 // CCnUiDomainSelectionQueryDialog::DestroyCloseArray |
|
329 // --------------------------------------------------------------------------- |
|
330 // |
|
331 void CCnUiDomainSelectionQueryDialog::DestroyCloseArray( TAny* aObject ) |
|
332 { |
|
333 reinterpret_cast< CArrayPtr<CGulIcon>* >( aObject )->ResetAndDestroy(); |
|
334 } |
|
335 |