|
1 /* |
|
2 * Copyright (c) 2002 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: Base class for WAP setting items. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 // INCLUDE FILES |
|
21 #include <e32base.h> |
|
22 #include <msvapi.h> |
|
23 #include <mmsclient.h> |
|
24 #include <mtclreg.h> |
|
25 #include <ApDataHandler.h> |
|
26 #include <ApAccessPointItem.h> |
|
27 #include <ApUtils.h> |
|
28 #include <f32file.h> |
|
29 #include <barsc.h> |
|
30 #include <bautils.h> |
|
31 #include <CWPCharacteristic.h> |
|
32 #include <CWPParameter.h> |
|
33 #include <WPAdapterUtil.h> |
|
34 #include <CWPAdapter.h> |
|
35 #include "CWPWAPItemBAse.h" |
|
36 #include "ProvisioningDebug.h" |
|
37 |
|
38 // CONSTANTS |
|
39 const TInt KNamesGranularity = 1; |
|
40 const TInt KNameMaxLength = 50; |
|
41 |
|
42 // ============================ MEMBER FUNCTIONS =============================== |
|
43 |
|
44 // ----------------------------------------------------------------------------- |
|
45 // CWPWAPItemBase::CWPWAPItemBase |
|
46 // C++ default constructor can NOT contain any code, that |
|
47 // might leave. |
|
48 // ----------------------------------------------------------------------------- |
|
49 // |
|
50 CWPWAPItemBase::CWPWAPItemBase( const TDesC& aTitle, |
|
51 const TDesC& aDefaultName, |
|
52 CWPCharacteristic& aCharacteristic, |
|
53 CCommsDatabase*& aCommsDb, |
|
54 CApDataHandler*& aAPHandler ) |
|
55 : iCharacteristic( aCharacteristic ), |
|
56 iTitle( aTitle ), |
|
57 iDefaultName( aDefaultName ), |
|
58 iCommsDb( aCommsDb ), |
|
59 iAPHandler( aAPHandler ) |
|
60 { |
|
61 } |
|
62 |
|
63 // ----------------------------------------------------------------------------- |
|
64 // CWPWAPItemBase::BaseConstructL |
|
65 // Symbian 2nd phase constructor can leave. |
|
66 // ----------------------------------------------------------------------------- |
|
67 // |
|
68 void CWPWAPItemBase::BaseConstructL() |
|
69 { |
|
70 iCharacteristic.AcceptL( *this ); |
|
71 |
|
72 if( iName == KNullDesC ) |
|
73 { |
|
74 iName.Set( iDefaultName ); |
|
75 } |
|
76 } |
|
77 |
|
78 // ----------------------------------------------------------------------------- |
|
79 // Destructor |
|
80 // ----------------------------------------------------------------------------- |
|
81 CWPWAPItemBase::~CWPWAPItemBase() |
|
82 { |
|
83 delete iAddr; |
|
84 } |
|
85 |
|
86 // ----------------------------------------------------------------------------- |
|
87 // CWPWAPItemBase::VisitL |
|
88 // ----------------------------------------------------------------------------- |
|
89 // |
|
90 void CWPWAPItemBase::VisitL( CWPCharacteristic& aCharacteristic ) |
|
91 { |
|
92 if( aCharacteristic.Type() == KWPResource ) |
|
93 { |
|
94 ResourceL( aCharacteristic ); |
|
95 } |
|
96 } |
|
97 |
|
98 // ----------------------------------------------------------------------------- |
|
99 // CWPWAPItemBase::VisitL |
|
100 // ----------------------------------------------------------------------------- |
|
101 // |
|
102 void CWPWAPItemBase::VisitL( CWPParameter& aParameter ) |
|
103 { |
|
104 switch( aParameter.ID() ) |
|
105 { |
|
106 case EWPParameterName: |
|
107 { |
|
108 iName.Set( aParameter.Value() ); |
|
109 break; |
|
110 } |
|
111 |
|
112 case EWPParameterAddr: |
|
113 { |
|
114 if( !iAddr ) |
|
115 { |
|
116 iAddr = aParameter.Value().AllocL(); |
|
117 } |
|
118 break; |
|
119 } |
|
120 |
|
121 default: |
|
122 { |
|
123 break; |
|
124 } |
|
125 } |
|
126 } |
|
127 |
|
128 // ----------------------------------------------------------------------------- |
|
129 // CWPWAPItemBase::VisitLinkL |
|
130 // ----------------------------------------------------------------------------- |
|
131 // |
|
132 void CWPWAPItemBase::VisitLinkL( CWPCharacteristic& aLink ) |
|
133 { |
|
134 if( !iLink ) |
|
135 { |
|
136 iLink = &aLink; |
|
137 |
|
138 if( iName == KNullDesC ) |
|
139 { |
|
140 // Get the name |
|
141 CArrayFix<TPtrC>* names = new(ELeave) CArrayFixFlat<TPtrC>( KNamesGranularity ); |
|
142 CleanupStack::PushL( names ); |
|
143 aLink.ParameterL( EWPParameterName, names ); |
|
144 if( names->Count() > 0 ) |
|
145 { |
|
146 iName.Set( names->At(0) ); |
|
147 } |
|
148 CleanupStack::PopAndDestroy(); // names |
|
149 } |
|
150 } |
|
151 } |
|
152 |
|
153 // ----------------------------------------------------------------------------- |
|
154 // CWPWAPItemBase::Name |
|
155 // ----------------------------------------------------------------------------- |
|
156 // |
|
157 const TDesC& CWPWAPItemBase::Name() const |
|
158 { |
|
159 return iName; |
|
160 } |
|
161 |
|
162 // ----------------------------------------------------------------------------- |
|
163 // CWPWAPItemBase::Title |
|
164 // ----------------------------------------------------------------------------- |
|
165 // |
|
166 const TDesC& CWPWAPItemBase::Title() const |
|
167 { |
|
168 return iTitle; |
|
169 } |
|
170 |
|
171 // ----------------------------------------------------------------------------- |
|
172 // CWPWAPItemBase::Address |
|
173 // ----------------------------------------------------------------------------- |
|
174 // |
|
175 const TDesC& CWPWAPItemBase::Address() const |
|
176 { |
|
177 if( iAddr ) |
|
178 { |
|
179 return *iAddr; |
|
180 } |
|
181 else |
|
182 { |
|
183 return KNullDesC; |
|
184 } |
|
185 } |
|
186 |
|
187 // ----------------------------------------------------------------------------- |
|
188 // CWPWAPItemBase::SaveData |
|
189 // ----------------------------------------------------------------------------- |
|
190 // |
|
191 const TDesC8& CWPWAPItemBase::SaveData() const |
|
192 { |
|
193 if( iSaveItem().iSaveItemType != KWPWAPItemTypeNone ) |
|
194 { |
|
195 return iSaveItem; |
|
196 } |
|
197 else |
|
198 { |
|
199 return KNullDesC8; |
|
200 } |
|
201 } |
|
202 |
|
203 // ----------------------------------------------------------------------------- |
|
204 // CWPWAPItemBase::CreateDbL |
|
205 // ----------------------------------------------------------------------------- |
|
206 // |
|
207 void CWPWAPItemBase::CreateDbL() |
|
208 { |
|
209 if( !iCommsDb ) |
|
210 { |
|
211 iCommsDb = CCommsDatabase::NewL(); |
|
212 } |
|
213 |
|
214 if( !iAPHandler ) |
|
215 { |
|
216 iAPHandler = CApDataHandler::NewLC( *iCommsDb ); |
|
217 CleanupStack::Pop(); // iAPEngine |
|
218 } |
|
219 } |
|
220 |
|
221 // ----------------------------------------------------------------------------- |
|
222 // CWPWAPItemBase::WriteHomePageL |
|
223 // ----------------------------------------------------------------------------- |
|
224 // |
|
225 void CWPWAPItemBase::WriteHomePageL( CApAccessPointItem& aItem ) |
|
226 { |
|
227 FLOG( _L( "[Provisioning] CWPWAPItemBase::WriteHomePageL:" ) ); |
|
228 |
|
229 if( iAddr ) |
|
230 { |
|
231 if( aItem.ReadTextLengthL( EApWapStartPage ) > 0 ) |
|
232 { |
|
233 FLOG( _L( "[Provisioning] CWPWAPItemBase::WriteHomePageL: EApWapStartPage " ) ); |
|
234 // Make a copy of the AP |
|
235 CApAccessPointItem* newItem = CApAccessPointItem::NewLC(); |
|
236 newItem->CopyFromL( aItem ); |
|
237 |
|
238 // Create a proper name for the copy |
|
239 TBuf<KNameMaxLength> name( iName.Left( KNameMaxLength ) ); |
|
240 MakeValidNameL( name, *iCommsDb ); |
|
241 |
|
242 // Write name |
|
243 User::LeaveIfError( newItem->WriteTextL( EApWapAccessPointName, name ) ); |
|
244 |
|
245 //Write IAP name |
|
246 User::LeaveIfError( newItem->WriteTextL( EApIapName, name ) ); |
|
247 // Write MMSC address |
|
248 User::LeaveIfError( newItem->WriteLongTextL( EApWapStartPage, *iAddr ) ); |
|
249 |
|
250 // Create the new access point |
|
251 TRAPD( err, iUID = iAPHandler->CreateFromDataL( *newItem ) ); |
|
252 |
|
253 FTRACE(RDebug::Print(_L("[Provisioning] CWPWAPItemBase::WriteHomePageL: CreateFromDataL err (%d)"), err)); |
|
254 FTRACE(RDebug::Print(_L("[Provisioning] CWPWAPItemBase::WriteHomePageL: CreateFromDataL iUID (%d)"), iUID)); |
|
255 |
|
256 if( err == KErrLocked ) |
|
257 { |
|
258 err = EWPCommsDBLocked; |
|
259 } |
|
260 User::LeaveIfError( err ); |
|
261 |
|
262 iSaveItem().iSaveItemType = KWPWAPItemTypeAccesspoint; |
|
263 iSaveItem().iUID = iUID; |
|
264 |
|
265 CleanupStack::PopAndDestroy(); // newItem |
|
266 } |
|
267 else |
|
268 { |
|
269 FLOG( _L( "[Provisioning] CWPWAPItemBase::WriteHomePageL: EApWapStartPage 0 " ) ); |
|
270 User::LeaveIfError( aItem.WriteLongTextL( EApWapStartPage, *iAddr ) ); |
|
271 |
|
272 // Update the access point |
|
273 TBool nameChanged( EFalse ); |
|
274 TRAPD( err, iAPHandler->UpdateAccessPointDataL( aItem, nameChanged ) ); |
|
275 FTRACE(RDebug::Print(_L("[Provisioning] CWPWAPItemBase::WriteHomePageL: CreateFromDataL err (%d)"), err)); |
|
276 if( err == KErrLocked ) |
|
277 { |
|
278 err = EWPCommsDBLocked; |
|
279 } |
|
280 User::LeaveIfError( err ); |
|
281 iUID = aItem.WapUid(); |
|
282 FTRACE(RDebug::Print(_L("[Provisioning] CWPWAPItemBase::WriteHomePageL: CreateFromDataL iUID (%d)"), iUID)); |
|
283 } |
|
284 } |
|
285 } |
|
286 |
|
287 // ----------------------------------------------------------------------------- |
|
288 // CWPWAPItemBase::MakeValidNameL |
|
289 // ----------------------------------------------------------------------------- |
|
290 // |
|
291 void CWPWAPItemBase::MakeValidNameL( TDes& aName, CCommsDatabase& aDb ) const |
|
292 { |
|
293 CApUtils* utils = CApUtils::NewLC( aDb ); |
|
294 utils->MakeValidNameL( aName ); |
|
295 CleanupStack::PopAndDestroy(); // utils |
|
296 } |
|
297 |
|
298 // End of File |