|
1 /* |
|
2 * Copyright (c) 2009 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: Implementation of customization components |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include "EmbeddedLinkApp.h" |
|
20 |
|
21 |
|
22 // --------------------------------------------------------- |
|
23 // CEmbeddedLinkApp::NewL |
|
24 // |
|
25 // |
|
26 // --------------------------------------------------------- |
|
27 CEmbeddedLinkApp* CEmbeddedLinkApp::NewL( TInt aId ) |
|
28 { |
|
29 CEmbeddedLinkApp* self = CEmbeddedLinkApp::NewLC( aId ); |
|
30 CleanupStack::Pop( self ); |
|
31 return self; |
|
32 } |
|
33 |
|
34 // --------------------------------------------------------- |
|
35 // CEmbeddedLinkApp::NewLC |
|
36 // |
|
37 // |
|
38 // --------------------------------------------------------- |
|
39 CEmbeddedLinkApp* CEmbeddedLinkApp::NewLC( TInt aId ) |
|
40 { |
|
41 CEmbeddedLinkApp* self = new ( ELeave ) CEmbeddedLinkApp; |
|
42 CleanupStack::PushL( self ); |
|
43 self->ConstructL( aId ); |
|
44 return self; |
|
45 } |
|
46 |
|
47 // --------------------------------------------------------- |
|
48 // CEmbeddedLinkApp::ConstructL |
|
49 // |
|
50 // |
|
51 // --------------------------------------------------------- |
|
52 void CEmbeddedLinkApp::ConstructL( TInt aId ) |
|
53 { |
|
54 User::LeaveIfError( iFavouritesSess.Connect() ); |
|
55 |
|
56 |
|
57 iId=aId; |
|
58 User::LeaveIfError( GetAppName( iAppName ) ); |
|
59 //sf- iFolderUid=0; //sf-FolderUidL(); |
|
60 } |
|
61 |
|
62 // --------------------------------------------------------- |
|
63 // CEmbeddedLinkApp::~CEmbeddedLinkApp |
|
64 // |
|
65 // |
|
66 // --------------------------------------------------------- |
|
67 CEmbeddedLinkApp::~CEmbeddedLinkApp() |
|
68 { |
|
69 iFavouritesSess.Close(); |
|
70 } |
|
71 |
|
72 // --------------------------------------------------------- |
|
73 // CEmbeddedLinkApp::AddLinkL |
|
74 // |
|
75 // |
|
76 // --------------------------------------------------------- |
|
77 TInt CEmbeddedLinkApp::AddLinkL( TDesC& aName, TDesC& aUrl, const TDesC& aUsername, |
|
78 const TDesC& aPassword, TInt aApId ) |
|
79 { |
|
80 TInt err( KErrNone ); |
|
81 |
|
82 RFavouritesDb db; |
|
83 User::LeaveIfError( db.Open( iFavouritesSess, KBrowserBookmarks ) ); |
|
84 CleanupClosePushL<RFavouritesDb>( db ); |
|
85 |
|
86 |
|
87 CFavouritesItem* favItem = CFavouritesItem::NewLC(); |
|
88 |
|
89 favItem->SetNameL( aName ); |
|
90 favItem->SetUrlL( aUrl ); |
|
91 favItem->SetType( CFavouritesItem::EItem ); |
|
92 |
|
93 if ( aUsername != KNullDesC ) |
|
94 { |
|
95 favItem->SetUserNameL( aUsername ); |
|
96 } |
|
97 if ( aPassword != KNullDesC ) |
|
98 { |
|
99 favItem->SetPasswordL( aPassword ); |
|
100 } |
|
101 |
|
102 if ( aApId != KErrNotFound ) |
|
103 { |
|
104 TFavouritesWapAp wapAp; |
|
105 wapAp=aApId; |
|
106 favItem->SetWapAp( wapAp ); |
|
107 } |
|
108 |
|
109 favItem->SetParentFolder( FolderUidL() ); //sf-iFolderUid ); |
|
110 |
|
111 err = db.Add( *favItem, ETrue ); |
|
112 // db->CommitL(); KAATAA !!!!! |
|
113 db.Close(); |
|
114 |
|
115 if ( err == KErrNone ) |
|
116 { |
|
117 err = favItem->Uid(); |
|
118 } |
|
119 else |
|
120 { |
|
121 } |
|
122 |
|
123 CleanupStack::PopAndDestroy( 2 ); //db, favItem |
|
124 |
|
125 return err; |
|
126 } |
|
127 |
|
128 // --------------------------------------------------------- |
|
129 // CEmbeddedLinkApp::GetLinkUidL |
|
130 // |
|
131 // |
|
132 // --------------------------------------------------------- |
|
133 TInt CEmbeddedLinkApp::GetLinkUidL( TDesC& aName, TDesC& /*aAddress*/, TInt folderUid, TInt& aUid ) |
|
134 { |
|
135 RFavouritesDb db; |
|
136 User::LeaveIfError( db.Open( iFavouritesSess, KBrowserBookmarks ) ); |
|
137 CleanupClosePushL<RFavouritesDb>( db ); |
|
138 |
|
139 CArrayFixFlat<TInt>* array = new ( ELeave ) CArrayFixFlat<TInt>( 16 ); |
|
140 CleanupStack::PushL( array ); |
|
141 TInt err = KErrNone; |
|
142 |
|
143 err=db.GetUids( *array, folderUid, CFavouritesItem::EItem, &aName, KFavouritesNullContextId ); |
|
144 |
|
145 if ( err == KErrNone && array->Count() < 2 ) |
|
146 { |
|
147 for ( TInt i = 0; i < array->Count(); i++ ) |
|
148 { |
|
149 aUid=array->At( i ); |
|
150 } |
|
151 } |
|
152 else |
|
153 { |
|
154 err = KErrBadName; |
|
155 } |
|
156 |
|
157 db.Close(); |
|
158 |
|
159 CleanupStack::PopAndDestroy( 2 ); // db, array |
|
160 |
|
161 return err; |
|
162 } |
|
163 |
|
164 // --------------------------------------------------------- |
|
165 // CEmbeddedLinkApp::GetLinkL |
|
166 // |
|
167 // |
|
168 // --------------------------------------------------------- |
|
169 TInt CEmbeddedLinkApp::GetLinkL( TInt aUid, CFavouritesItem& aFavItem ) |
|
170 { |
|
171 TInt err( KErrNone ); |
|
172 |
|
173 RFavouritesDb db; |
|
174 User::LeaveIfError( db.Open( iFavouritesSess, KBrowserBookmarks ) ); |
|
175 CleanupClosePushL<RFavouritesDb>( db ); |
|
176 |
|
177 err=db.Get( aUid, aFavItem ); |
|
178 db.Close(); |
|
179 |
|
180 |
|
181 CleanupStack::PopAndDestroy(); |
|
182 return err; |
|
183 } |
|
184 |
|
185 // --------------------------------------------------------- |
|
186 // CEmbeddedLinkApp::GetLinksL |
|
187 // |
|
188 // |
|
189 // --------------------------------------------------------- |
|
190 TInt CEmbeddedLinkApp::GetLinksL( CFavouritesItemList& aFavItemList ) |
|
191 { |
|
192 TInt err( KErrNone ); |
|
193 |
|
194 CArrayFixFlat<TInt>* array = new (ELeave) CArrayFixFlat<TInt>( 16 ); |
|
195 CleanupStack::PushL( array ); |
|
196 |
|
197 RFavouritesDb db; |
|
198 User::LeaveIfError( db.Open( iFavouritesSess, KBrowserBookmarks ) ); |
|
199 CleanupClosePushL<RFavouritesDb>( db ); |
|
200 |
|
201 err = db.GetUids( *array, KFavouritesNullUid, CFavouritesItem::EFolder, NULL, iId ); // Get all folder uids related to the app |
|
202 |
|
203 |
|
204 if ( err == KErrNone ) // Then get the links in the folder |
|
205 { |
|
206 for ( TInt i = 0; i < array->Count(); i++ ) |
|
207 { |
|
208 err = db.GetAll( aFavItemList, array->At( i ), CFavouritesItem::EItem, NULL, KFavouritesNullContextId ); |
|
209 } |
|
210 } |
|
211 |
|
212 db.Close(); |
|
213 |
|
214 CleanupStack::PopAndDestroy( 2 ); // array, db |
|
215 return err; |
|
216 } |
|
217 |
|
218 // --------------------------------------------------------- |
|
219 // CEmbeddedLinkApp::RemoveLinkL |
|
220 // |
|
221 // |
|
222 // --------------------------------------------------------- |
|
223 TInt CEmbeddedLinkApp::RemoveLinkL( TInt aUid ) |
|
224 { |
|
225 TInt err = KErrNone; |
|
226 |
|
227 RFavouritesDb db; |
|
228 User::LeaveIfError( db.Open( iFavouritesSess, KBrowserBookmarks ) ); |
|
229 CleanupClosePushL<RFavouritesDb>( db ); |
|
230 |
|
231 err = db.Delete( aUid ); |
|
232 db.Close(); |
|
233 |
|
234 |
|
235 CleanupStack::PopAndDestroy(); // db |
|
236 |
|
237 return err; |
|
238 } |
|
239 |
|
240 // --------------------------------------------------------- |
|
241 // CEmbeddedLinkApp::GetAppNameL |
|
242 // |
|
243 // |
|
244 // --------------------------------------------------------- |
|
245 TInt CEmbeddedLinkApp::GetAppName( TDes& aName ) |
|
246 { |
|
247 TInt err( KErrNone ); |
|
248 |
|
249 switch( iId ) |
|
250 { |
|
251 case KFavouritesNullContextId: |
|
252 aName.Copy(_L("Unused")); |
|
253 break; |
|
254 |
|
255 case KFavouritesApplicationContextId: |
|
256 aName.Copy(_L("Application")); |
|
257 break; |
|
258 |
|
259 case KFavouritesImageContextId: |
|
260 aName.Copy(_L("Image")); |
|
261 break; |
|
262 |
|
263 case KFavouritesAudioContextId: |
|
264 aName.Copy(_L("Audio")); |
|
265 break; |
|
266 |
|
267 case KFavouritesVideoContextId: |
|
268 aName.Copy(_L("Video")); |
|
269 break; |
|
270 |
|
271 case KFavouritesGameDataContextId: |
|
272 aName.Copy(_L("GameData")); |
|
273 break; |
|
274 |
|
275 case KFavouritesRingingToneContextId: |
|
276 aName.Copy(_L("RingingTone")); |
|
277 break; |
|
278 |
|
279 case KFavouritesSkinContextId: |
|
280 aName.Copy(_L("Skin")); |
|
281 break; |
|
282 |
|
283 case KFavouritesMusicContextId: |
|
284 aName.Copy(_L("Music")); |
|
285 break; |
|
286 |
|
287 default: |
|
288 err=KErrNotFound; |
|
289 break; |
|
290 } |
|
291 |
|
292 return err; |
|
293 } |
|
294 |
|
295 // --------------------------------------------------------- |
|
296 // CEmbeddedLinkApp::UpdateUrlL |
|
297 // |
|
298 // |
|
299 // --------------------------------------------------------- |
|
300 TInt CEmbeddedLinkApp::UpdateUrlL( const TDesC& aUrl, TInt aUid ) |
|
301 { |
|
302 TInt err( KErrNone ); |
|
303 |
|
304 RFavouritesDb db; |
|
305 User::LeaveIfError( db.Open( iFavouritesSess, KBrowserBookmarks ) ); |
|
306 CleanupClosePushL<RFavouritesDb>( db ); |
|
307 |
|
308 CFavouritesItem* favItem = CFavouritesItem::NewLC(); |
|
309 |
|
310 err = db.Get( aUid, *favItem ); |
|
311 |
|
312 if ( err==KErrNone ) |
|
313 { |
|
314 favItem->SetUrlL( aUrl ); |
|
315 err = db.Update( *favItem, aUid, ETrue ); |
|
316 } |
|
317 |
|
318 db.Close(); |
|
319 |
|
320 CleanupStack::PopAndDestroy( 2 ); //db, favItem |
|
321 |
|
322 return err; |
|
323 } |
|
324 |
|
325 // --------------------------------------------------------- |
|
326 // CEmbeddedLinkApp::UpdateNameL |
|
327 // |
|
328 // |
|
329 // --------------------------------------------------------- |
|
330 TInt CEmbeddedLinkApp::UpdateNameL( const TDesC& aName, TInt aUid ) |
|
331 { |
|
332 TInt err( KErrNone ); |
|
333 |
|
334 RFavouritesDb db; |
|
335 User::LeaveIfError( db.Open( iFavouritesSess, KBrowserBookmarks ) ); |
|
336 CleanupClosePushL<RFavouritesDb>( db ); |
|
337 |
|
338 CFavouritesItem* favItem = CFavouritesItem::NewLC(); |
|
339 |
|
340 err = db.Get( aUid, *favItem ); |
|
341 |
|
342 if ( err == KErrNone ) |
|
343 { |
|
344 favItem->SetNameL( aName ); |
|
345 err = db.Update( *favItem, aUid, ETrue ); |
|
346 } |
|
347 |
|
348 db.Close(); |
|
349 |
|
350 CleanupStack::PopAndDestroy( 2 ); //db, favItem |
|
351 |
|
352 return err; |
|
353 } |
|
354 |
|
355 // --------------------------------------------------------- |
|
356 // CEmbeddedLinkApp::UpdateUserNameL |
|
357 // |
|
358 // |
|
359 // --------------------------------------------------------- |
|
360 TInt CEmbeddedLinkApp::UpdateUserNameL( const TDesC& aUserName, const TInt aUid ) |
|
361 { |
|
362 TInt err( KErrNone ); |
|
363 |
|
364 RFavouritesDb db; |
|
365 User::LeaveIfError( db.Open( iFavouritesSess, KBrowserBookmarks ) ); |
|
366 CleanupClosePushL<RFavouritesDb>( db ); |
|
367 |
|
368 CFavouritesItem* favItem = CFavouritesItem::NewLC(); |
|
369 |
|
370 err = db.Get( aUid, *favItem ); |
|
371 |
|
372 if ( err == KErrNone ) |
|
373 { |
|
374 favItem->SetUserNameL( aUserName ); |
|
375 err = db.Update( *favItem, aUid, ETrue ); |
|
376 } |
|
377 |
|
378 db.Close(); |
|
379 |
|
380 CleanupStack::PopAndDestroy( 2 ); //db, favItem |
|
381 |
|
382 return err; |
|
383 } |
|
384 |
|
385 // --------------------------------------------------------- |
|
386 // CEmbeddedLinkApp::UpdatePasswordL |
|
387 // |
|
388 // |
|
389 // --------------------------------------------------------- |
|
390 TInt CEmbeddedLinkApp::UpdatePasswordL( const TDesC& aPassword, const TInt aUid ) |
|
391 { |
|
392 TInt err( KErrNone ); |
|
393 |
|
394 RFavouritesDb db; |
|
395 User::LeaveIfError( db.Open( iFavouritesSess, KBrowserBookmarks ) ); |
|
396 CleanupClosePushL<RFavouritesDb>( db ); |
|
397 |
|
398 CFavouritesItem* favItem = CFavouritesItem::NewLC(); |
|
399 |
|
400 err = db.Get( aUid, *favItem ); |
|
401 |
|
402 if ( err == KErrNone ) |
|
403 { |
|
404 favItem->SetPasswordL( aPassword ); |
|
405 err = db.Update( *favItem, aUid, ETrue ); |
|
406 } |
|
407 |
|
408 db.Close(); |
|
409 |
|
410 CleanupStack::PopAndDestroy( 2 ); //db, favItem |
|
411 |
|
412 return err; |
|
413 } |
|
414 |
|
415 // --------------------------------------------------------- |
|
416 // CEmbeddedLinkApp::UpdateWapApL |
|
417 // |
|
418 // |
|
419 // --------------------------------------------------------- |
|
420 TInt CEmbeddedLinkApp::UpdateWapApL( const TDesC& aWapAp, const TInt aUid ) |
|
421 { |
|
422 TInt err( KErrNone ); |
|
423 |
|
424 RFavouritesDb db; |
|
425 User::LeaveIfError( db.Open( iFavouritesSess, KBrowserBookmarks ) ); |
|
426 CleanupClosePushL<RFavouritesDb>( db ); |
|
427 |
|
428 CFavouritesItem* favItem = CFavouritesItem::NewLC(); |
|
429 |
|
430 err = db.Get( aUid, *favItem ); |
|
431 |
|
432 if ( err == KErrNone ) |
|
433 { |
|
434 TFavouritesWapAp wapAp; |
|
435 wapAp.SetDefault(); |
|
436 if (aWapAp.Length() > 0) |
|
437 { |
|
438 TUint value = 0; |
|
439 TLex lex( aWapAp ); |
|
440 TInt lexErr = lex.Val( value ); |
|
441 if (lexErr == KErrNone) |
|
442 { |
|
443 wapAp.SetApId( value ); |
|
444 } |
|
445 else |
|
446 { |
|
447 wapAp.SetNull(); |
|
448 } |
|
449 } |
|
450 |
|
451 favItem->SetWapAp( wapAp ); |
|
452 |
|
453 err = db.Update( *favItem, aUid, ETrue ); |
|
454 } |
|
455 |
|
456 db.Close(); |
|
457 |
|
458 CleanupStack::PopAndDestroy( 2 ); //db, favItem |
|
459 |
|
460 return err; |
|
461 } |
|
462 |
|
463 // --------------------------------------------------------- |
|
464 // CEmbeddedLinkApp::GetURI |
|
465 // |
|
466 // |
|
467 // --------------------------------------------------------- |
|
468 TPtrC CEmbeddedLinkApp::GetURI() |
|
469 { |
|
470 return iURI.Ptr(); |
|
471 } |
|
472 |
|
473 // --------------------------------------------------------- |
|
474 // CEmbeddedLinkApp::SetURI |
|
475 // |
|
476 // |
|
477 // --------------------------------------------------------- |
|
478 TInt CEmbeddedLinkApp::SetURI( const TDesC& aURI ) |
|
479 { |
|
480 iURI.Copy(aURI); |
|
481 return KErrNone; |
|
482 } |
|
483 |
|
484 // --------------------------------------------------------- |
|
485 // CEmbeddedLinkApp::AppId |
|
486 // |
|
487 // |
|
488 // --------------------------------------------------------- |
|
489 TInt CEmbeddedLinkApp::AppId() const |
|
490 { |
|
491 return iId; |
|
492 } |
|
493 |
|
494 // --------------------------------------------------------- |
|
495 // CEmbeddedLinkApp::AppName |
|
496 // |
|
497 // |
|
498 // --------------------------------------------------------- |
|
499 TPtrC CEmbeddedLinkApp::AppName() const |
|
500 { |
|
501 return iAppName; |
|
502 } |
|
503 |
|
504 // --------------------------------------------------------- |
|
505 // CEmbeddedLinkApp::FolderUidL |
|
506 // --------------------------------------------------------- |
|
507 TInt CEmbeddedLinkApp::FolderUidL( ) |
|
508 { |
|
509 RFavouritesDb db; |
|
510 User::LeaveIfError( db.Open( iFavouritesSess, KBrowserBookmarks ) ); |
|
511 CleanupClosePushL<RFavouritesDb>( db ); |
|
512 |
|
513 CArrayFixFlat<TInt>* array = new ( ELeave ) CArrayFixFlat<TInt>( 16 ); |
|
514 CleanupStack::PushL( array ); |
|
515 |
|
516 TInt err = KErrNone; |
|
517 |
|
518 err = db.GetUids( *array, KFavouritesNullUid, CFavouritesItem::EFolder, NULL, iId ); |
|
519 |
|
520 User::LeaveIfError( err ); |
|
521 |
|
522 TInt folderUid = 0; |
|
523 |
|
524 if (array->Count() == 0) |
|
525 { |
|
526 //sf- User::Leave( KErrNotFound ); |
|
527 } |
|
528 else |
|
529 { |
|
530 folderUid = (*array)[0]; |
|
531 } |
|
532 |
|
533 db.Close(); |
|
534 |
|
535 CleanupStack::PopAndDestroy( 2 ); //db, array |
|
536 |
|
537 return folderUid; |
|
538 } |