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