1 /* |
|
2 * Copyright (c) 2007-2008 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: Receives and stores Destination network settings. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 #include <e32base.h> |
|
22 #include <CWPAdapter.h> |
|
23 #include <CWPCharacteristic.h> |
|
24 #include <CWPParameter.h> |
|
25 #include <wpdestinationnwadapter.rsg> |
|
26 #include <e32des8.h> |
|
27 #include <WPAdapterUtil.h> // Adapter utils |
|
28 #include <utf.h> // Unicode conversion |
|
29 #include <cmmanagerext.h> |
|
30 #include <cmdestinationext.h> |
|
31 #include <cmconnectionmethodext.h> |
|
32 #include <cmmanagerdef.h> |
|
33 |
|
34 #include "cwpdestinationnwadapter.h" |
|
35 #include "wpdestinationnwdebug.h" |
|
36 |
|
37 _LIT( KDestinationNwAdapterName, "WPDestinationNwAdapter"); |
|
38 _LIT( KDestinationNwAppID, "w904C" ); // OMA CP registration document. |
|
39 _LIT8( KDestinationNwAppID8, "w904C" ); // OMA CP registration document. |
|
40 |
|
41 |
|
42 // --------------------------------------------------------------------------- |
|
43 // CWPDestinationNwAdapter::CWPDestinationNwAdapter |
|
44 // --------------------------------------------------------------------------- |
|
45 // |
|
46 CWPDestinationNwAdapter::CWPDestinationNwAdapter() : CWPAdapter() |
|
47 { |
|
48 } |
|
49 |
|
50 // --------------------------------------------------------------------------- |
|
51 // CWPDestinationNwAdapter::ConstructL |
|
52 // --------------------------------------------------------------------------- |
|
53 // |
|
54 void CWPDestinationNwAdapter::ConstructL() |
|
55 { |
|
56 DBG_PRINT( "CWPDestinationNwAdapter::ConstructL - begin" ); |
|
57 TFileName fileName; |
|
58 Dll::FileName( fileName ); |
|
59 // Read settings title from localization file. The title is shown to UI |
|
60 // when OMA CP message is provisioned using WAPPUSH. |
|
61 iDefaultTitle = WPAdapterUtil::ReadHBufCL( |
|
62 fileName, |
|
63 KDestinationNwAdapterName, |
|
64 R_QTN_SM_HEAD_DESTINATION_NETWORK ); |
|
65 // Read default settings name from localization file. |
|
66 iDefaultName = WPAdapterUtil::ReadHBufCL( |
|
67 fileName, |
|
68 KDestinationNwAdapterName, |
|
69 R_QTN_SM_DEFAULT_NAME_DESTINATION_NETWORK ); |
|
70 DBG_PRINT( "CWPDestinationNwAdapter::ConstructL - end" ); |
|
71 } |
|
72 |
|
73 // --------------------------------------------------------------------------- |
|
74 // CWPDestinationNwAdapter::NewL |
|
75 // --------------------------------------------------------------------------- |
|
76 // |
|
77 CWPDestinationNwAdapter* CWPDestinationNwAdapter::NewL() |
|
78 { |
|
79 CWPDestinationNwAdapter* self = new (ELeave) |
|
80 CWPDestinationNwAdapter; |
|
81 CleanupStack::PushL( self ); |
|
82 self->ConstructL(); |
|
83 CleanupStack::Pop( self ); |
|
84 return self; |
|
85 } |
|
86 |
|
87 // --------------------------------------------------------------------------- |
|
88 // CWPDestinationNwAdapter::~CWPDestinationNwAdapter |
|
89 // --------------------------------------------------------------------------- |
|
90 // |
|
91 CWPDestinationNwAdapter::~CWPDestinationNwAdapter() |
|
92 { |
|
93 DBG_PRINT( "CWPDestinationNwAdapter::~CWPDestinationNwAdapter - begin" ); |
|
94 delete iDefaultTitle; |
|
95 delete iDefaultName; |
|
96 iItems.ResetAndDestroy(); |
|
97 iItems.Close(); |
|
98 DBG_PRINT( "CWPDestinationNwAdapter::~CWPDestinationNwAdapter - end" ); |
|
99 } |
|
100 |
|
101 // --------------------------------------------------------------------------- |
|
102 // CWPDestinationNwAdapter::Des8ToUint32L() |
|
103 // Converts an 8 bit descriptor to TUint32. |
|
104 // --------------------------------------------------------------------------- |
|
105 // |
|
106 TUint32 CWPDestinationNwAdapter::Des8ToUint32L( const TDesC8& aDes ) |
|
107 { |
|
108 TLex8 lex( aDes ); |
|
109 TUint32 value( 0 ); |
|
110 User::LeaveIfError( lex.Val( value, EDecimal ) ); |
|
111 return value; |
|
112 } |
|
113 |
|
114 // --------------------------------------------------------------------------- |
|
115 // CWPDestinationNwAdapter::ItemCount |
|
116 // From class CWPAdapter. |
|
117 // Checks the number of settings items. |
|
118 // --------------------------------------------------------------------------- |
|
119 // |
|
120 TInt CWPDestinationNwAdapter::ItemCount() const |
|
121 { |
|
122 return iItems.Count(); |
|
123 } |
|
124 |
|
125 // --------------------------------------------------------------------------- |
|
126 // From class CWPAdapter. |
|
127 // CWPDestinationNwAdapter::SummaryTitle |
|
128 // Returns the summary title. |
|
129 // --------------------------------------------------------------------------- |
|
130 // |
|
131 const TDesC16& CWPDestinationNwAdapter::SummaryTitle( TInt /*aIndex*/ ) const |
|
132 { |
|
133 return *iDefaultTitle; |
|
134 } |
|
135 |
|
136 // --------------------------------------------------------------------------- |
|
137 // CWPDestinationNwAdapter::SummaryText |
|
138 // From class CWPAdapter. |
|
139 // Returns the summary text of a destination network. |
|
140 // --------------------------------------------------------------------------- |
|
141 // |
|
142 const TDesC16& CWPDestinationNwAdapter::SummaryText( TInt aIndex ) const |
|
143 { |
|
144 if ( !iItems[aIndex]->SettingsName().Length() ) |
|
145 { |
|
146 return *iDefaultName; |
|
147 } |
|
148 return iItems[aIndex]->SettingsName(); |
|
149 } |
|
150 |
|
151 // --------------------------------------------------------------------------- |
|
152 // CWPDestinationNwAdapter::SaveL |
|
153 // From class CWPAdapter. |
|
154 // Calls settings items saving method. |
|
155 // --------------------------------------------------------------------------- |
|
156 // |
|
157 void CWPDestinationNwAdapter::SaveL( TInt aIndex ) |
|
158 { |
|
159 __ASSERT_ALWAYS( aIndex >= 0 && aIndex < iItems.Count(), |
|
160 User::Leave( KErrArgument ) ); |
|
161 |
|
162 iItems[aIndex]->SaveL(); |
|
163 } |
|
164 |
|
165 // --------------------------------------------------------------------------- |
|
166 // CWPDestinationNwAdapter::CanSetAsDefault |
|
167 // From class CWPAdapter. |
|
168 // Not supported; always return EFalse. |
|
169 // --------------------------------------------------------------------------- |
|
170 // |
|
171 TBool CWPDestinationNwAdapter::CanSetAsDefault( TInt /*aIndex*/ ) const |
|
172 { |
|
173 return EFalse; |
|
174 } |
|
175 |
|
176 // --------------------------------------------------------------------------- |
|
177 // CWPDestinationNwAdapter::DetailsL |
|
178 // From class CWPAdapter. |
|
179 // Not supported. |
|
180 // --------------------------------------------------------------------------- |
|
181 // |
|
182 TInt CWPDestinationNwAdapter::DetailsL( TInt /*aItem*/, |
|
183 MWPPairVisitor& /*aVisitor */ ) |
|
184 { |
|
185 return KErrNotSupported; |
|
186 } |
|
187 |
|
188 // --------------------------------------------------------------------------- |
|
189 // CWPDestinationNwAdapter::VisitL |
|
190 // From class CWPAdapter. |
|
191 // OMA CP characteristics are handled in this method. |
|
192 // --------------------------------------------------------------------------- |
|
193 // |
|
194 void CWPDestinationNwAdapter::VisitL( |
|
195 CWPCharacteristic& aCharacteristic ) |
|
196 { |
|
197 DBG_PRINT( "CWPDestinationNwAdapter::VisitL( characteristic ) - begin" ); |
|
198 switch ( aCharacteristic.Type() ) |
|
199 { |
|
200 // This adapter only handles APPLICATION characteristic. |
|
201 case KWPApplication: |
|
202 { |
|
203 iCurrentItem = CWPDestinationNwItem::NewL(); |
|
204 // Set default name for destination - replaced later if a name |
|
205 // has been provisioned. |
|
206 iCurrentItem->SetSettingsNameL( iDefaultName->Des() ); |
|
207 aCharacteristic.AcceptL( *this ); |
|
208 |
|
209 // Settings are for Destination network - append current item to |
|
210 // item array to be saved later. |
|
211 if ( 0 == iAppId.Compare( KDestinationNwAppID() ) ) |
|
212 { |
|
213 iItems.AppendL( iCurrentItem ); |
|
214 } |
|
215 // Settings are not for Destination network. |
|
216 else |
|
217 { |
|
218 delete iCurrentItem; |
|
219 iCurrentItem = NULL; |
|
220 } |
|
221 break; |
|
222 } |
|
223 // All other than APPLICATION are ignored. |
|
224 default: |
|
225 break; |
|
226 } |
|
227 DBG_PRINT( "CWPDestinationNwAdapter::VisitL( characteristic ) - end" ); |
|
228 } |
|
229 |
|
230 // --------------------------------------------------------------------------- |
|
231 // CWPDestinationNwAdapter::VisitL |
|
232 // From class CWPAdapter. |
|
233 // Destination network parameters are handled in this method. |
|
234 // --------------------------------------------------------------------------- |
|
235 // |
|
236 void CWPDestinationNwAdapter::VisitL( CWPParameter& aParameter ) |
|
237 { |
|
238 DBG_PRINT( "CWPDestinationNwAdapter::VisitL( parameter ) - begin" ); |
|
239 // tmpValue holds the value converted from Unicode to UTF8. |
|
240 HBufC8* tmpValue = HBufC8::NewLC( aParameter.Value().Length() ); // CS:1 |
|
241 TPtr8 ptrTmpValue( tmpValue->Des() ); |
|
242 CnvUtfConverter::ConvertFromUnicodeToUtf8( ptrTmpValue, |
|
243 aParameter.Value() ); |
|
244 |
|
245 switch ( aParameter.ID() ) |
|
246 { |
|
247 // APPLICATION/APPID |
|
248 case EWPParameterAppID: |
|
249 { |
|
250 iAppId.Set( aParameter.Value() ); |
|
251 break; |
|
252 } |
|
253 |
|
254 // APPLICATION/NAME |
|
255 case EWPParameterName: |
|
256 { |
|
257 if ( iCurrentItem ) |
|
258 { |
|
259 iCurrentItem->SetSettingsNameL( aParameter.Value() ); |
|
260 } |
|
261 break; |
|
262 } |
|
263 |
|
264 // APPLICATION/APPREF |
|
265 case EWPParameterAppRef: |
|
266 { |
|
267 if ( iCurrentItem ) |
|
268 { |
|
269 iCurrentItem->SetAppRefL( tmpValue->Des() ); |
|
270 } |
|
271 break; |
|
272 } |
|
273 |
|
274 // Other settings are ignored. |
|
275 default: |
|
276 { |
|
277 break; |
|
278 } |
|
279 } |
|
280 CleanupStack::PopAndDestroy( tmpValue ); // CS:0 |
|
281 DBG_PRINT( "CWPDestinationNwAdapter::VisitL( parameter ) - end" ); |
|
282 } |
|
283 |
|
284 // --------------------------------------------------------------------------- |
|
285 // CWPDestinationNwAdapter::VisitLinkL |
|
286 // |
|
287 // --------------------------------------------------------------------------- |
|
288 // |
|
289 void CWPDestinationNwAdapter::VisitLinkL( CWPCharacteristic& aLink ) |
|
290 { |
|
291 if ( KWPNapDef == aLink.Type() && iCurrentItem ) |
|
292 { |
|
293 iCurrentItem->AddNapDefL( &aLink ); |
|
294 } |
|
295 } |
|
296 |
|
297 // --------------------------------------------------------------------------- |
|
298 // CWPDestinationNwAdapter::GetSavingInfoL |
|
299 // APPID is set to [0], APPREF to [1] and saving info (storage ID) to [2]. |
|
300 // --------------------------------------------------------------------------- |
|
301 // |
|
302 void CWPDestinationNwAdapter::GetSavingInfoL( TInt aIndex, |
|
303 RPointerArray<HBufC8>& aSavingInfo ) |
|
304 { |
|
305 __ASSERT_ALWAYS( aIndex >= 0 && aIndex < iItems.Count(), |
|
306 User::Leave( KErrArgument ) ); |
|
307 |
|
308 aSavingInfo.AppendL( KDestinationNwAppID8().AllocL() ); |
|
309 aSavingInfo.AppendL( iItems[aIndex]->AppRef().AllocL() ); |
|
310 aSavingInfo.AppendL( iItems[aIndex]->SaveData().AllocL() ); |
|
311 } |
|
312 |
|
313 // --------------------------------------------------------------------------- |
|
314 // CWPDestinationNwAdapter::ContextExtension |
|
315 // From class MWPContextExtension. |
|
316 // Returns a pointer to context extension. |
|
317 // --------------------------------------------------------------------------- |
|
318 // |
|
319 TInt CWPDestinationNwAdapter::ContextExtension( |
|
320 MWPContextExtension*& aExtension ) |
|
321 { |
|
322 aExtension = this; |
|
323 return KErrNone; |
|
324 } |
|
325 |
|
326 // --------------------------------------------------------------------------- |
|
327 // CWPDestinationNwAdapter::SaveDataL |
|
328 // From class MWPContextExtension. |
|
329 // Returns ID of saved data. |
|
330 // --------------------------------------------------------------------------- |
|
331 // |
|
332 const TDesC8& CWPDestinationNwAdapter::SaveDataL( TInt aIndex ) const |
|
333 { |
|
334 __ASSERT_ALWAYS( aIndex >= 0 && aIndex < iItems.Count(), |
|
335 User::Leave( KErrArgument ) ); |
|
336 |
|
337 return iItems[aIndex]->SaveData(); |
|
338 } |
|
339 |
|
340 // --------------------------------------------------------------------------- |
|
341 // CWPDestinationNwAdapter::DeleteL |
|
342 // From class MWPContextExtension. |
|
343 // Deletes a Destination network. |
|
344 // --------------------------------------------------------------------------- |
|
345 // |
|
346 void CWPDestinationNwAdapter::DeleteL( const TDesC8& aSaveData ) |
|
347 { |
|
348 DBG_PRINT( "CWPDestinationNwAdapter::DeleteL - begin" ); |
|
349 RCmManagerExt cmManager; |
|
350 cmManager.OpenL(); |
|
351 CleanupClosePushL( cmManager ); // CS:1 |
|
352 TUint32 destinationId = Des8ToUint32L( aSaveData ); |
|
353 RCmDestinationExt destination = cmManager.DestinationL( destinationId ); |
|
354 CleanupClosePushL( destination ); // CS:2 |
|
355 const TInt cmCount = destination.ConnectionMethodCount(); |
|
356 // First remove IAPs from destination network because this adapter must |
|
357 // not delete IAPs. |
|
358 for ( TInt counter = 0; counter < cmCount; counter++ ) |
|
359 { |
|
360 destination.RemoveConnectionMethodL( |
|
361 destination.ConnectionMethodL( 0 ) ); |
|
362 destination.UpdateL(); |
|
363 } |
|
364 CleanupStack::Pop( &destination ); // CS:1 |
|
365 destination.DeleteLD(); |
|
366 CleanupStack::PopAndDestroy( &cmManager ); // CS:0 |
|
367 DBG_PRINT( "CWPDestinationNwAdapter::DeleteL - end" ); |
|
368 } |
|
369 |
|
370 // --------------------------------------------------------------------------- |
|
371 // CWPDestinationNwAdapter::Uid |
|
372 // From class MWPContextExtension. |
|
373 // Returns the UID of this adapter. |
|
374 // --------------------------------------------------------------------------- |
|
375 // |
|
376 TUint32 CWPDestinationNwAdapter::Uid() const |
|
377 { |
|
378 return iDtor_ID_Key.iUid; |
|
379 } |
|
380 // End of file. |
|