1 /* |
|
2 * Copyright (c) 2002-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: One browser setting item. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 // INCLUDE FILES |
|
21 #include <e32base.h> |
|
22 #include <msvapi.h> |
|
23 #include <CWPCharacteristic.h> |
|
24 #include <CWPParameter.h> |
|
25 #include <CWPAdapter.h> |
|
26 #include <centralrepository.h> |
|
27 #include <browseruisdkcrkeys.h> |
|
28 #include "CWPWAPBrowserItem.h" |
|
29 #include "WPWAPItemFactory.h" |
|
30 #include "ProvisioningDebug.h" |
|
31 |
|
32 // CONSTANTS |
|
33 /// Delay to wait for WmlBrowser to catch up with changes in CommsDb. Microseconds. |
|
34 const TInt KWmlDelay = 4*500000; |
|
35 // Force browser to use User Defined AP |
|
36 const TInt KUserDefined = 0; |
|
37 |
|
38 // ----------------------------------------------------------------------------- |
|
39 // CWPWAPBrowserItem::CWPWAPBrowserItem |
|
40 // C++ default constructor can NOT contain any code, that |
|
41 // might leave. |
|
42 // ----------------------------------------------------------------------------- |
|
43 // |
|
44 CWPWAPBrowserItem::CWPWAPBrowserItem( TBool aFirst, |
|
45 const TDesC& aTitle, |
|
46 const TDesC& aBookmarkTitle, |
|
47 const TDesC& aDefaultName, |
|
48 const TDesC& aDefaultBookmarkName, |
|
49 CWPCharacteristic& aCharacteristic, |
|
50 CCommsDatabase*& aCommsDb, |
|
51 RCmManagerExt*& aCmManager, |
|
52 RFavouritesDb aBookmarkDb |
|
53 ) |
|
54 : CWPWAPItemBase( aTitle, |
|
55 aDefaultName, |
|
56 aCharacteristic, |
|
57 aCommsDb, |
|
58 aCmManager ), |
|
59 iDefaultBookmarkName( aDefaultBookmarkName ), |
|
60 iBookmarkTitle( aBookmarkTitle ), |
|
61 iDb( aBookmarkDb ), |
|
62 iFirst( aFirst ) |
|
63 { |
|
64 } |
|
65 |
|
66 // ----------------------------------------------------------------------------- |
|
67 // CWPWAPBrowserItem::ConstructL |
|
68 // Symbian 2nd phase constructor can leave. |
|
69 // ----------------------------------------------------------------------------- |
|
70 // |
|
71 void CWPWAPBrowserItem::ConstructL() |
|
72 { |
|
73 BaseConstructL(); |
|
74 } |
|
75 |
|
76 // ----------------------------------------------------------------------------- |
|
77 // CWPWAPBrowserItem::NewL |
|
78 // Two-phased constructor. |
|
79 // ----------------------------------------------------------------------------- |
|
80 // |
|
81 CWPWAPBrowserItem* CWPWAPBrowserItem::NewL( TBool aFirst, |
|
82 const TDesC& aTitle, |
|
83 const TDesC& aBookmarkTitle, |
|
84 const TDesC& aDefaultName, |
|
85 const TDesC& aDefaultBookmarkName, |
|
86 CWPCharacteristic& aCharacteristic, |
|
87 CCommsDatabase*& aCommsDb, |
|
88 RCmManagerExt*& aCmManager, |
|
89 RFavouritesDb aBookmarkDb |
|
90 ) |
|
91 { |
|
92 CWPWAPBrowserItem* self = new(ELeave) CWPWAPBrowserItem( aFirst, |
|
93 aTitle, |
|
94 aBookmarkTitle, |
|
95 aDefaultName, |
|
96 aDefaultBookmarkName, |
|
97 aCharacteristic, |
|
98 aCommsDb, |
|
99 aCmManager, |
|
100 aBookmarkDb ); |
|
101 CleanupStack::PushL(self); |
|
102 self->ConstructL(); |
|
103 CleanupStack::Pop(self); |
|
104 return self; |
|
105 } |
|
106 |
|
107 // ----------------------------------------------------------------------------- |
|
108 // Destructor |
|
109 // ----------------------------------------------------------------------------- |
|
110 CWPWAPBrowserItem::~CWPWAPBrowserItem() |
|
111 { |
|
112 iBookmarks.ResetAndDestroy(); |
|
113 } |
|
114 |
|
115 // ----------------------------------------------------------------------------- |
|
116 // CWPWAPBrowserItem::SaveL |
|
117 // ----------------------------------------------------------------------------- |
|
118 // |
|
119 void CWPWAPBrowserItem::SaveL() |
|
120 { |
|
121 CreateDbL(); |
|
122 |
|
123 TPckg<TUint32> uid( iUID ); |
|
124 // Check if the iLink->Data() contains an item of the same size as uid. |
|
125 // This is an extra check to ensure that iLink->Data() contains a packaged |
|
126 // TUin32. |
|
127 if( iLink && iLink->Data().Length() == uid.MaxLength() ) |
|
128 { |
|
129 uid.Copy( iLink->Data() ); |
|
130 } |
|
131 RCmConnectionMethodExt cm; |
|
132 cm = iCmManager->ConnectionMethodL( iUID ); |
|
133 CleanupClosePushL( cm ); |
|
134 if( iAddr ) |
|
135 { |
|
136 // Update the access point startpage |
|
137 WriteHomePageL( cm ); |
|
138 } |
|
139 CleanupStack::PopAndDestroy(); // cm |
|
140 } |
|
141 |
|
142 // ----------------------------------------------------------------------------- |
|
143 // CWPWAPBrowserItem::CanSetAsDefault |
|
144 // ----------------------------------------------------------------------------- |
|
145 // |
|
146 TBool CWPWAPBrowserItem::CanSetAsDefault() const |
|
147 { |
|
148 return iUID != KWPWAPNoUID; |
|
149 } |
|
150 |
|
151 // ----------------------------------------------------------------------------- |
|
152 // CWPWAPBrowserItem::SetAsDefaultL |
|
153 // ----------------------------------------------------------------------------- |
|
154 // |
|
155 void CWPWAPBrowserItem::SetAsDefaultL() |
|
156 { |
|
157 FLOG( _L( "[Provisioning] CWPWAPBrowserItem::SetAsDefaultL:" ) ); |
|
158 |
|
159 /* CreateDbL(); |
|
160 TRAPD( err, iAPHandler->SetAsDefaultL( (TInt)iUID, EIspTypeWAPOnly) ); |
|
161 if( err == KErrLocked ) |
|
162 { |
|
163 err = EWPCommsDBLocked; |
|
164 } |
|
165 // This function need to leave at the end of the function |
|
166 // otherwise we dont set the default AP when db is locked |
|
167 //User::LeaveIfError( err ); |
|
168 |
|
169 // There's some delay before the WmlBrowser can find the stored |
|
170 // accesspoint from CommsDb so therefore we wait for a while before |
|
171 // telling the WmlBrowser that default accesspoint should be changed. |
|
172 // The value 500000 is chosen just by trying out. |
|
173 User::After( KWmlDelay ); |
|
174 |
|
175 CRepository* repository = CRepository::NewLC( KCRUidBrowser ); |
|
176 FTRACE(RDebug::Print( |
|
177 _L("[Provisioning] CWPWAPBrowserItem::SetAsDefaultL: AP:(%d)"), |
|
178 (TInt)iUID)); |
|
179 |
|
180 // Force the browser to use the User Defined AP selection mode. |
|
181 User::LeaveIfError( repository->Set( KBrowserAccessPointSelectionMode, |
|
182 KUserDefined ) ); |
|
183 // This sets the accesspoint default for browser. |
|
184 User::LeaveIfError( repository->Set( KBrowserDefaultAccessPoint, |
|
185 (TInt)iUID ) ); |
|
186 |
|
187 //Set the HomePage to default |
|
188 if(iUID) |
|
189 { |
|
190 User::LeaveIfError( repository->Set( KBrowserNGHomepageType, EBrowserCenRepAccessPoint) ); |
|
191 } |
|
192 |
|
193 CleanupStack::PopAndDestroy(); // repository |
|
194 FLOG( _L( "[Provisioning] CWPWAPBrowserItem::SetAsDefaultL: Set Done" ) ); |
|
195 |
|
196 User::LeaveIfError( err );*/ |
|
197 } |
|
198 |
|
199 // ----------------------------------------------------------------------------- |
|
200 // CWPWAPBrowserItem::ValidateL |
|
201 // ----------------------------------------------------------------------------- |
|
202 // |
|
203 TBool CWPWAPBrowserItem::ValidateL() |
|
204 { |
|
205 return iLink != NULL; |
|
206 } |
|
207 |
|
208 // ----------------------------------------------------------------------------- |
|
209 // CWPWAPBrowserItem::ResourceL |
|
210 // ----------------------------------------------------------------------------- |
|
211 // |
|
212 void CWPWAPBrowserItem::ResourceL( CWPCharacteristic& aResource ) |
|
213 { |
|
214 MWPWAPItemBase* item = WPWAPItemFactory::CreateBookmarkLC( |
|
215 iBookmarkTitle, |
|
216 iDefaultBookmarkName, |
|
217 aResource, |
|
218 iLink, |
|
219 iDb ); |
|
220 |
|
221 if( item->CanSetAsDefault() && !iAddr ) |
|
222 { |
|
223 iAddr = item->Address().AllocL(); |
|
224 CleanupStack::PopAndDestroy(); // item |
|
225 } |
|
226 else |
|
227 { |
|
228 User::LeaveIfError( iBookmarks.Append( item ) ); |
|
229 CleanupStack::Pop(); // item |
|
230 } |
|
231 } |
|
232 |
|
233 // ----------------------------------------------------------------------------- |
|
234 // CWPWAPBrowserItem::AddL |
|
235 // ----------------------------------------------------------------------------- |
|
236 // |
|
237 void CWPWAPBrowserItem::AddL( RPointerArray<MWPWAPItemBase>& aShownItems, |
|
238 RPointerArray<MWPWAPItemBase>& aHiddenItems ) |
|
239 { |
|
240 for( TInt i( iBookmarks.Count()-1 ); i >= 0 ; i-- ) |
|
241 { |
|
242 MWPWAPItemBase* item = iBookmarks[i]; |
|
243 |
|
244 if( item->ValidateL() ) |
|
245 { |
|
246 // Transfer ownership of iBookmarks[i] to aItems |
|
247 iBookmarks[i]->AddL( aShownItems, aHiddenItems ); |
|
248 } |
|
249 else |
|
250 { |
|
251 // invalid items get deleted |
|
252 delete item; |
|
253 } |
|
254 iBookmarks.Remove( i ); |
|
255 } |
|
256 |
|
257 // Only first browser item is shown to the user. |
|
258 if( iFirst ) |
|
259 { |
|
260 User::LeaveIfError( aShownItems.Append( this ) ); |
|
261 } |
|
262 else |
|
263 { |
|
264 User::LeaveIfError( aHiddenItems.Append( this ) ); |
|
265 } |
|
266 } |
|
267 |
|
268 // End of File |
|