|
1 /* |
|
2 * Copyright (c) 2006-2007 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: ?Description |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include <pspresetnotifier.h> |
|
20 #include <pstransaction.h> |
|
21 |
|
22 #include "irdebug.h" |
|
23 #include "irfavoritesdb.h" |
|
24 #include "irisdspreset.h" |
|
25 #include "irpreset.h" |
|
26 #include "irsettings.h" |
|
27 |
|
28 const TInt KNullId = 0; |
|
29 const TInt KNineteen = 19; |
|
30 const TInt KFifty = 50; |
|
31 |
|
32 namespace PresetHandler |
|
33 { |
|
34 //------------------------------------------------------------------------------- |
|
35 //TInt OrderByIndex( const CIRPresetImpl& aPreset1, const CIRPresetImpl& aPreset2 ) |
|
36 //------------------------------------------------------------------------------- |
|
37 // |
|
38 //Sort algorithm |
|
39 // Orders presets by their index. |
|
40 // |
|
41 TInt OrderByIndex( const CIRPreset& aPreset1, const CIRPreset& aPreset2 ) |
|
42 { |
|
43 if ( aPreset1.Index() < aPreset2.Index() ) |
|
44 { |
|
45 return -1; |
|
46 } |
|
47 else if ( aPreset1.Index() > aPreset2.Index() ) |
|
48 { |
|
49 return 1; |
|
50 } |
|
51 else |
|
52 { |
|
53 return 0; |
|
54 } |
|
55 } |
|
56 |
|
57 TInt OrderByPlayedTimes(const CIRPreset& aPreset1, const CIRPreset& aPreset2) |
|
58 { |
|
59 int difference = aPreset1.GetPlayedTimes() - aPreset2.GetPlayedTimes(); |
|
60 if (difference > 0) |
|
61 { |
|
62 return -1; |
|
63 } |
|
64 else if (difference == 0) |
|
65 { |
|
66 return aPreset1.Name().Compare(aPreset2.Name()); |
|
67 } |
|
68 else |
|
69 { |
|
70 return 1; |
|
71 } |
|
72 } |
|
73 } |
|
74 |
|
75 //--------------------------------------------------------------------------- |
|
76 //CIRFavoritesDb::NewL() |
|
77 //standard symbian 1st phase constructor |
|
78 //--------------------------------------------------------------------------- |
|
79 // |
|
80 |
|
81 EXPORT_C CIRFavoritesDb* CIRFavoritesDb::NewL() |
|
82 { |
|
83 IRLOG_DEBUG( "CIRFavoritesDb::NewL" ); |
|
84 CIRFavoritesDb* self = new ( ELeave ) CIRFavoritesDb; |
|
85 CleanupStack::PushL( self ); |
|
86 self->ConstructL(); |
|
87 CleanupStack::Pop( self ); |
|
88 IRLOG_DEBUG( "CIRFavoritesDb::NewL - Exiting." ); |
|
89 return self; |
|
90 } |
|
91 |
|
92 |
|
93 //--------------------------------------------------------------------------- |
|
94 //CIRFavoritesDb::~CIRFavoritesDb() |
|
95 //standard c++ destructor |
|
96 //--------------------------------------------------------------------------- |
|
97 // |
|
98 |
|
99 CIRFavoritesDb::~CIRFavoritesDb() |
|
100 { |
|
101 IRLOG_DEBUG( "CIRFavoritesDb::~CIRFavoritesDb" ); |
|
102 delete iNotifier; |
|
103 iObservers.Close(); |
|
104 //resets the preset array |
|
105 iFavPresetList.ResetAndDestroy(); |
|
106 iFavPresetList.Close(); |
|
107 iServ.Close(); |
|
108 |
|
109 if (iSettings) |
|
110 { |
|
111 iSettings->Close(); |
|
112 } |
|
113 |
|
114 IRLOG_DEBUG( "CIRFavoritesDb::~CIRFavoritesDb - Exiting." ); |
|
115 } |
|
116 |
|
117 |
|
118 //--------------------------------------------------------------------------- |
|
119 //CIRFavoritesDb::AddPresetL() |
|
120 //exported function to add a preset |
|
121 //--------------------------------------------------------------------------- |
|
122 // |
|
123 |
|
124 EXPORT_C void CIRFavoritesDb::AddPresetL(CIRIsdsPreset& aPreset, |
|
125 TInt& aRetVal, TBool /*aIsLogoAvialable*/) |
|
126 { |
|
127 IRLOG_DEBUG( "CIRFavoritesDb::AddPresetL" ); |
|
128 iMoveStatus=EFalse; |
|
129 SortByIndex() ;//sorted by index |
|
130 TBool presetSaved = EFalse; |
|
131 |
|
132 // Check the existence of preset before checking if the list is full |
|
133 // to avoid KErrNoMemory for a preset that exists in the list. |
|
134 TInt searchResult = 0; |
|
135 if (aPreset.GetChannelType() == 0) |
|
136 { |
|
137 searchResult = SearchUserDefinedPreset(aPreset.GetName(), aPreset.GetChannelUrlAtL(0)); |
|
138 //we don't allow user to add presets with the same name |
|
139 if (searchResult >= 0) |
|
140 { |
|
141 ReplaceUserDefinedPresetL(aPreset); |
|
142 aRetVal = KErrAlreadyExists; |
|
143 return; |
|
144 } |
|
145 } |
|
146 else |
|
147 { |
|
148 searchResult = SearchPreset( aPreset.GetId(), KNullId ); |
|
149 } |
|
150 |
|
151 if( KErrNotFound != searchResult) |
|
152 { |
|
153 //Eventhough the preset exists in the favorites db, replace the |
|
154 //same with the new preset i.e. aPreset. Because the db should |
|
155 //contain the updated values of the preset. |
|
156 ReplacePresetL(aPreset); |
|
157 |
|
158 aRetVal = KErrAlreadyExists; |
|
159 |
|
160 return; |
|
161 } |
|
162 |
|
163 if ( EmptyPresetCount()<=0 ) |
|
164 { |
|
165 //max limit reached no more processing |
|
166 aRetVal = KErrNoMemory; |
|
167 return; |
|
168 } |
|
169 |
|
170 // Found the next empty place or replace |
|
171 for ( TInt j=0; j < MaxPresetCount() && !presetSaved; j++ ) |
|
172 { |
|
173 CIRPreset* preset = PresetByIndex( j ); |
|
174 TBool presetExisted = preset ? ETrue : EFalse;//presetExisted=1 if preset exists |
|
175 |
|
176 if ( !preset ) |
|
177 { |
|
178 preset = CreatePresetL( j );//create if preset==NULL |
|
179 } |
|
180 |
|
181 if ( !presetExisted )//crete if preset did not exists |
|
182 { |
|
183 //open a transaction with the preset server |
|
184 CPSTransaction* transaction = preset->CreateTransactionLC(); |
|
185 //Convert to Plugnized Preset |
|
186 //That is accepted by the preset server |
|
187 preset->CIRIsdsPresetToCIRPresetImpl(aPreset); |
|
188 //setname of CPSPresetInterface is called |
|
189 preset->SetNameL( aPreset.GetName() ); |
|
190 //asign the preset id of the fav preset to uniqid value of the preset |
|
191 aPreset.SetUniqId(preset->Id()); |
|
192 transaction->CommitL(); |
|
193 CleanupStack::PopAndDestroy( transaction ); |
|
194 //added to check multiple insertion |
|
195 presetSaved = ETrue; |
|
196 } |
|
197 } |
|
198 |
|
199 aRetVal = KErrNone; |
|
200 IRLOG_DEBUG( "CIRFavoritesDb::AddPresetL - Exiting." ); |
|
201 } |
|
202 |
|
203 //--------------------------------------------------------------------------- |
|
204 //CIRFavoritesDb::AddPresetL() |
|
205 //exported,overloaded function to add a preset manually |
|
206 //converts the minimum data(name ,url) into an preset |
|
207 //--------------------------------------------------------------------------- |
|
208 // |
|
209 |
|
210 EXPORT_C void CIRFavoritesDb::AddPresetL(const TDesC& aName, |
|
211 const TDesC& aURl,TInt& aReturn, TBool /*aIsLogoAvialable*/) |
|
212 { |
|
213 IRLOG_DEBUG( "CIRFavoritesDb::AddPresetL(des des int int)" ); |
|
214 iMoveStatus=EFalse; |
|
215 CIRIsdsPreset* saveItem; |
|
216 saveItem = CIRIsdsPreset::NewL(); |
|
217 saveItem->SetName(aName); |
|
218 saveItem->SetUrlCount(1);//only one url is saved for manually added channel |
|
219 saveItem->SetChannelType(EUserDefined); |
|
220 _LIT(KNotAvailable,"NA"); |
|
221 //bitrate set to zero so that it is accessible to all kinds of bitrate settings |
|
222 saveItem->SetUrlL(KNotAvailable,aURl,0); |
|
223 AddPresetL(*saveItem,aReturn); |
|
224 delete saveItem; |
|
225 IRLOG_DEBUG( "CIRFavoritesDb::AddPresetL(des des int int) - Exiting." ); |
|
226 } |
|
227 |
|
228 |
|
229 //--------------------------------------------------------------------------- |
|
230 //CIRFavoritesDb::DeletePresetL() |
|
231 //exported, function to delete a preset |
|
232 //--------------------------------------------------------------------------- |
|
233 // |
|
234 |
|
235 EXPORT_C void CIRFavoritesDb::DeletePresetL( TInt aId ) |
|
236 { |
|
237 IRLOG_DEBUG( "CIRFavoritesDb::DeletePresetL" ); |
|
238 iMoveStatus=EFalse; |
|
239 iServ.DeletePresetL( aId); |
|
240 IRLOG_DEBUG( "CIRFavoritesDb::DeletePresetL - Exiting." ); |
|
241 } |
|
242 |
|
243 //--------------------------------------------------------------------------- |
|
244 //CIRFavoritesDb::GetAllPresetL() |
|
245 //exported,function to get the list of saved presets in the array iFavPresetList |
|
246 //--------------------------------------------------------------------------- |
|
247 // |
|
248 |
|
249 EXPORT_C void CIRFavoritesDb::GetAllPreset() |
|
250 { |
|
251 IRLOG_DEBUG( "CIRFavoritesDb::GetAllPresetL" ); |
|
252 //sort the array according to the index values |
|
253 SortByIndex(); |
|
254 IRLOG_DEBUG( "CIRFavoritesDb::GetAllPresetL - Exiting." ); |
|
255 } |
|
256 |
|
257 /* |
|
258 * get all presets sorted by played times |
|
259 */ |
|
260 EXPORT_C const RIRPresetArray& CIRFavoritesDb::GetAllSortedPresets() |
|
261 { |
|
262 iFavPresetList.Sort( TLinearOrder<CIRPreset>(PresetHandler::OrderByPlayedTimes)); |
|
263 return iFavPresetList; |
|
264 } |
|
265 |
|
266 //--------------------------------------------------------------------------- |
|
267 //CIRFavoritesDb::SwapPresetsInDbL() |
|
268 //returns the previous preset for a given presetId |
|
269 //--------------------------------------------------------------------------- |
|
270 // |
|
271 |
|
272 EXPORT_C void CIRFavoritesDb::SwapPresetsInDbL( TInt aChannelIdFrom, |
|
273 TInt /*aChannelIdTo*/,TInt /*aChannelIndexFro*/,TInt aChannelIndexTo ) |
|
274 { |
|
275 IRLOG_DEBUG( "CIRFavoritesDb::SwapPresetsInDbL" ); |
|
276 MovePresetL( aChannelIdFrom,aChannelIndexTo); |
|
277 IRLOG_DEBUG( "CIRFavoritesDb::SwapPresetsInDbL - Exiting." ); |
|
278 } |
|
279 |
|
280 //--------------------------------------------------------------------------- |
|
281 //CIRFavoritesDb::MovePresetL() |
|
282 //moves a preset to destination index |
|
283 //--------------------------------------------------------------------------- |
|
284 // |
|
285 |
|
286 void CIRFavoritesDb::MovePresetL( const TInt aId, const TInt aDestinationIndex ) |
|
287 { |
|
288 IRLOG_DEBUG( "CIRFavoritesDb::MovePresetL" ); |
|
289 ASSERT( aDestinationIndex >= 0 && aDestinationIndex < iFavPresetList.Count() ); |
|
290 if( aDestinationIndex < 0 || aDestinationIndex >= iFavPresetList.Count()) |
|
291 { |
|
292 User::Leave(KErrArgument); |
|
293 } |
|
294 |
|
295 TInt fakeIndex=iFavPresetList[aDestinationIndex]->Index(); |
|
296 SetMoveStatus(ETrue); |
|
297 iServ.MovePresetL( aId, fakeIndex ); |
|
298 IRLOG_DEBUG( "CIRFavoritesDb::MovePresetL - Exiting." ); |
|
299 } |
|
300 |
|
301 //--------------------------------------------------------------------------- |
|
302 //CIRFavoritesDb::SetMoveStatus() |
|
303 //sets the status of Move functionality |
|
304 //--------------------------------------------------------------------------- |
|
305 // |
|
306 EXPORT_C void CIRFavoritesDb::SetMoveStatus(TBool aStatus) |
|
307 { |
|
308 iMoveStatus = aStatus; |
|
309 } |
|
310 |
|
311 //--------------------------------------------------------------------------- |
|
312 //CIRFavoritesDb::GetMoveStatus() |
|
313 //returns the status of the Move functionality |
|
314 //--------------------------------------------------------------------------- |
|
315 // |
|
316 EXPORT_C TBool CIRFavoritesDb::GetMoveStatus() |
|
317 { |
|
318 return iMoveStatus; |
|
319 } |
|
320 |
|
321 |
|
322 //--------------------------------------------------------------------------- |
|
323 //CIRFavoritesDb::SearchPreset() |
|
324 //exported, function to find out if a preset exists in the favorites list |
|
325 //--------------------------------------------------------------------------- |
|
326 // |
|
327 |
|
328 EXPORT_C TInt CIRFavoritesDb::SearchPreset( const TInt aIsdsPresetId, |
|
329 const TInt aUniqPresetId) |
|
330 { |
|
331 IRLOG_DEBUG( "CIRFavoritesDb::SearchPreset" ); |
|
332 TInt count = iFavPresetList.Count(); |
|
333 TInt iter; |
|
334 //for isds presets |
|
335 if(aIsdsPresetId!=KNullId) |
|
336 { |
|
337 for(iter=0;iter<count;iter++) |
|
338 { |
|
339 if(iFavPresetList[iter]->GetId() == aIsdsPresetId) |
|
340 { |
|
341 IRLOG_DEBUG( "CIRFavoritesDb::SearchPreset - Exiting (1)." ); |
|
342 return iter; |
|
343 } |
|
344 } |
|
345 } |
|
346 if(aUniqPresetId != KNullId ) |
|
347 //for manually added presets |
|
348 { |
|
349 for(iter=0;iter<count;iter++) |
|
350 { |
|
351 if(aUniqPresetId==iFavPresetList[iter]->Id()) |
|
352 { |
|
353 IRLOG_DEBUG( "CIRFavoritesDb::SearchPreset - Exiting (2)." ); |
|
354 return iter; |
|
355 } |
|
356 } |
|
357 } |
|
358 // both the parameters are null implies that the preset is a non saved station |
|
359 IRLOG_DEBUG( "CIRFavoritesDb::SearchPreset - Exiting (3)." ); |
|
360 return KErrNotFound; |
|
361 } |
|
362 |
|
363 //--------------------------------------------------------------------------- |
|
364 //CIRFavoritesDb::GetPreviousPreset() |
|
365 //exported, function to find out if a preset exists in the favorites list |
|
366 //--------------------------------------------------------------------------- |
|
367 // |
|
368 EXPORT_C TInt CIRFavoritesDb::GetNextPreset(TInt aIndex) |
|
369 { |
|
370 if ( (aIndex==(iFavPresetList.Count()-1))||aIndex==KNineteen ) |
|
371 { |
|
372 return 0; |
|
373 } |
|
374 else |
|
375 { |
|
376 return aIndex+1; |
|
377 } |
|
378 } |
|
379 |
|
380 //--------------------------------------------------------------------------- |
|
381 //CIRFavoritesDb::GetNextPreset() |
|
382 //exported, function to find out if a preset exists in the favorites list |
|
383 //--------------------------------------------------------------------------- |
|
384 // |
|
385 EXPORT_C TInt CIRFavoritesDb::GetPreviousPreset( TInt aIndex ) |
|
386 { |
|
387 if ( aIndex==0 ) |
|
388 { |
|
389 TInt val=(iFavPresetList.Count()-1); |
|
390 return val; |
|
391 } |
|
392 else |
|
393 { |
|
394 return aIndex-1; |
|
395 } |
|
396 } |
|
397 //--------------------------------------------------------------------------- |
|
398 //CIRFavoritesDb::ReplacePresetL() |
|
399 //replaces a preset with a new preset |
|
400 //for presetSync |
|
401 //--------------------------------------------------------------------------- |
|
402 // |
|
403 |
|
404 EXPORT_C void CIRFavoritesDb::ReplacePresetL( CIRIsdsPreset& aNewPreset ) |
|
405 { |
|
406 IRLOG_DEBUG( "CIRFavoritesDb::ReplacePresetL" ); |
|
407 iMoveStatus=EFalse; |
|
408 CIRPreset* preset; |
|
409 TInt index = SearchPreset(aNewPreset.GetId(),KNullId); |
|
410 //actual index |
|
411 if (index >= 0) |
|
412 { |
|
413 ASSERT( index >= 0 || index < iFavPresetList.Count() ); |
|
414 index = iFavPresetList[index]->Index(); |
|
415 preset = PresetByIndex(index); |
|
416 if(preset) |
|
417 { |
|
418 CPSTransaction* transaction = preset->CreateTransactionLC(); |
|
419 //change the preset data and commit |
|
420 preset->CIRIsdsPresetToCIRPresetImpl(aNewPreset); |
|
421 preset->SetChannelType(EIsdsPreset); |
|
422 preset->SetNameL( aNewPreset.GetName() ); |
|
423 transaction->CommitL(); |
|
424 CleanupStack::PopAndDestroy( transaction ); |
|
425 } |
|
426 } |
|
427 IRLOG_DEBUG( "CIRFavoritesDb::ReplacePresetL - Exiting." ); |
|
428 } |
|
429 |
|
430 //--------------------------------------------------------------------------- |
|
431 //CIRFavoritesDb::ReplaceUserDefinedPresetL() |
|
432 //replaces a userdefined preset with a new userdefiend preset |
|
433 //for presetSync |
|
434 //--------------------------------------------------------------------------- |
|
435 // |
|
436 EXPORT_C void CIRFavoritesDb::ReplaceUserDefinedPresetL(CIRIsdsPreset& aNewPreset) |
|
437 { |
|
438 IRLOG_DEBUG( "CIRFavoritesDb::ReplaceUserDefinedPresetL" ); |
|
439 iMoveStatus=EFalse; |
|
440 TInt index = SearchUserDefinedPreset(aNewPreset.GetName(), aNewPreset.GetChannelUrlAtL(0)); |
|
441 |
|
442 if (index >= 0 && index < iFavPresetList.Count()) |
|
443 { |
|
444 CIRPreset* preset = iFavPresetList[index]; |
|
445 if (preset) |
|
446 { |
|
447 CPSTransaction* transaction = preset->CreateTransactionLC(); |
|
448 /** |
|
449 * change the preset data and commit |
|
450 */ |
|
451 preset->CIRIsdsPresetToCIRPresetImpl(aNewPreset); |
|
452 preset->SetChannelType(EUserDefined); |
|
453 preset->SetNameL(aNewPreset.GetName()); |
|
454 preset->SetDescription(aNewPreset.GetShortDescription()); |
|
455 transaction->CommitL(); |
|
456 CleanupStack::PopAndDestroy(transaction); |
|
457 } |
|
458 } |
|
459 IRLOG_DEBUG( "CIRFavoritesDb::ReplaceUserDefinedPresetL - Exiting." ); |
|
460 } |
|
461 |
|
462 |
|
463 |
|
464 |
|
465 |
|
466 |
|
467 //--------------------------------------------------------------------------- |
|
468 //IRFavoritesDb::MakePresetUserDefinedL() |
|
469 //for a favorite preset that has been removed from the isds. |
|
470 //it is made a user defined preset by changing the type to 0. |
|
471 //index value is preseved so that the relative positions in the saved |
|
472 //stations view remains the same. |
|
473 //--------------------------------------------------------------------------- |
|
474 // |
|
475 |
|
476 EXPORT_C void CIRFavoritesDb::MakePresetUserDefinedL( TInt aChannelId, |
|
477 TInt /*aUserDefinedChannelId*/ ) |
|
478 { |
|
479 IRLOG_DEBUG( "CIRFavoritesDb::MakePresetUserDefinedL" ); |
|
480 iMoveStatus=EFalse; |
|
481 //to match the function signature |
|
482 TInt index = SearchPreset(aChannelId,KNullId); |
|
483 CIRPreset* preset; |
|
484 //actual index |
|
485 if (index >= 0) |
|
486 { |
|
487 ASSERT( index >= 0 || index < iFavPresetList.Count() ); |
|
488 index = iFavPresetList[index]->Index(); |
|
489 preset = PresetByIndex(index); |
|
490 if(preset) |
|
491 { |
|
492 CPSTransaction* transaction = preset->CreateTransactionLC(); |
|
493 //convert the flag to user defined and commit |
|
494 preset->SetChannelType(EUserDefined); |
|
495 //assign null id |
|
496 preset->SetId(KNullId); |
|
497 |
|
498 //make logo as null;;;; added for 2.0 |
|
499 _LIT8(KEmpty, ""); |
|
500 RBuf8 tempLogo; |
|
501 tempLogo.Create(KEmpty); |
|
502 preset->SetLogoData(tempLogo); |
|
503 tempLogo.Close(); |
|
504 _LIT(KEmptyString, ""); |
|
505 RBuf tempString; |
|
506 tempString.Create(KEmptyString); |
|
507 //set imgurl to null |
|
508 preset->SetImgUrl(tempString); |
|
509 //set genre to null |
|
510 preset->SetGenreInfo(tempString,tempString); |
|
511 //set language to null |
|
512 preset->SetLang(tempString); |
|
513 //set country to null |
|
514 preset->SetCountryName(tempString); |
|
515 tempString.Close(); |
|
516 //set musicStoreEnabled filed to "no";;;;added for 2.0 |
|
517 _LIT(KNo, "no"); |
|
518 RBuf tempMusicStoreEnabled; |
|
519 tempMusicStoreEnabled.Create(KNo); |
|
520 preset->SetMusicStoreStatus(tempMusicStoreEnabled); |
|
521 tempMusicStoreEnabled.Close(); |
|
522 |
|
523 transaction->CommitL(); |
|
524 CleanupStack::PopAndDestroy( transaction ); |
|
525 } |
|
526 } |
|
527 IRLOG_DEBUG( "CIRFavoritesDb::MakePresetUserDefinedL - Exiting." ); |
|
528 } |
|
529 |
|
530 //--------------------------------------------------------------------------- |
|
531 //const RVRPresetArray& CVRPresetHandler::Presets() const |
|
532 // RIRPresetArray& an array containing all Internet Radio presets. |
|
533 //--------------------------------------------------------------------------- |
|
534 // |
|
535 |
|
536 EXPORT_C const RIRPresetArray& CIRFavoritesDb::Presets() const |
|
537 { |
|
538 IRLOG_DEBUG( "CIRFavoritesDb::Presets" ); |
|
539 //sort by |
|
540 return iFavPresetList; |
|
541 } |
|
542 |
|
543 /* |
|
544 * Increase the played times of a channel if it has been in the favorites |
|
545 * return : KErrNone if success |
|
546 * KErrNotFound if the preset is not in the favorites |
|
547 */ |
|
548 EXPORT_C TInt CIRFavoritesDb::IncreasePlayedTimesL(const CIRIsdsPreset &aIsdsPreset) |
|
549 { |
|
550 //step 1 : search the preset in favorites |
|
551 SortByIndex(); |
|
552 TInt index = 0; |
|
553 if (aIsdsPreset.GetChannelType() == 0) |
|
554 { |
|
555 index = SearchUserDefinedPreset(aIsdsPreset.GetName(), aIsdsPreset.GetChannelUrlAtL(0)); |
|
556 } |
|
557 else |
|
558 { |
|
559 index = SearchPreset(aIsdsPreset.GetId(), KNullId); |
|
560 } |
|
561 |
|
562 if (KErrNotFound == index) |
|
563 { |
|
564 return KErrNotFound; |
|
565 } |
|
566 |
|
567 //step 2 : update the played times of the preset |
|
568 CIRPreset *irPreset = iFavPresetList[index]; |
|
569 //open a transaction with the preset server |
|
570 CPSTransaction* transaction = irPreset->CreateTransactionLC(); |
|
571 irPreset->SetPlayedTimes(irPreset->GetPlayedTimes() + 1); |
|
572 transaction->CommitL(); |
|
573 CleanupStack::PopAndDestroy(transaction); |
|
574 |
|
575 return KErrNone; |
|
576 } |
|
577 |
|
578 //--------------------------------------------------------------------------- |
|
579 //CIRFavoritesDb::ConstructL() |
|
580 //Standard 2nd phase construction |
|
581 //--------------------------------------------------------------------------- |
|
582 // |
|
583 |
|
584 void CIRFavoritesDb::ConstructL() |
|
585 { |
|
586 IRLOG_DEBUG( "CIRFavoritesDb::ConstructL" ); |
|
587 //cenrep handle |
|
588 iSettings = CIRSettings::OpenL(); |
|
589 iSettings->SetMaxPresetCountL(KFifty); |
|
590 User::LeaveIfError( iServ.Connect() ); |
|
591 //a session to the client of the preset server |
|
592 iServ.GetPresetsL( iFavPresetList, KIRPreset ); |
|
593 //notifier |
|
594 iNotifier = CPSPresetNotifier::NewL( iServ, *this ); |
|
595 //cenrep. |
|
596 iMaxPresetCount=iSettings->MaxPresetCount(); |
|
597 //initialization of the list for UI use |
|
598 //iFavPresetList=new(ELeave)CArrayPtrFlat<CIRPreset>(KGranularity) |
|
599 iMoveStatus=EFalse; |
|
600 IRLOG_DEBUG( "CIRFavoritesDb::ConstructL - Exiting." ); |
|
601 } |
|
602 |
|
603 |
|
604 //--------------------------------------------------------------------------- |
|
605 //CIRFavoritesDb::SortByIndex() |
|
606 //sorts the preset list by index |
|
607 //--------------------------------------------------------------------------- |
|
608 // |
|
609 |
|
610 void CIRFavoritesDb::SortByIndex() |
|
611 { |
|
612 IRLOG_DEBUG( "CIRFavoritesDb::SortByIndex" ); |
|
613 //The sort order is determined by an algorithm supplied by the caller |
|
614 //and packaged as a TLinerOrder<T> |
|
615 iFavPresetList.Sort( TLinearOrder<CIRPreset>( PresetHandler::OrderByIndex ) ); |
|
616 IRLOG_DEBUG( "CIRFavoritesDb::SortByIndex - Exiting." ); |
|
617 } |
|
618 |
|
619 //--------------------------------------------------------------------------- |
|
620 //EXPORT_C TInt CIRFavoritesDb::MaxPresetCount() |
|
621 //returns the maximum number of presets that can be stored in the favorites list |
|
622 //--------------------------------------------------------------------------- |
|
623 // |
|
624 |
|
625 EXPORT_C TInt CIRFavoritesDb::MaxPresetCount() |
|
626 { |
|
627 IRLOG_DEBUG( "CIRFavoritesDb::MaxPresetCount" ); |
|
628 return iMaxPresetCount; |
|
629 } |
|
630 |
|
631 //--------------------------------------------------------------------------- |
|
632 //TInt CIRFavoritesDb::EmptyPresetCount() const |
|
633 //Returns the number of empty presets |
|
634 //--------------------------------------------------------------------------- |
|
635 // |
|
636 |
|
637 EXPORT_C TInt CIRFavoritesDb::EmptyPresetCount() const |
|
638 { |
|
639 IRLOG_DEBUG( "CIRFavoritesDb::EmptyPresetCount" ); |
|
640 return iMaxPresetCount - iFavPresetList.Count(); |
|
641 } |
|
642 |
|
643 |
|
644 |
|
645 //--------------------------------------------------------------------------- |
|
646 //TInt CIRFavoritesDb::AddObserver( MPSPresetObserver& aObserver ) |
|
647 //Adds an observer that is notified upon changes in presets. |
|
648 //--------------------------------------------------------------------------- |
|
649 // |
|
650 |
|
651 EXPORT_C TInt CIRFavoritesDb::AddObserver(const MPSPresetObserver& aObserver ) |
|
652 { |
|
653 IRLOG_DEBUG( "CIRFavoritesDb::AddObserver" ); |
|
654 return iObservers.InsertInAddressOrder( &aObserver ); |
|
655 } |
|
656 |
|
657 |
|
658 //--------------------------------------------------------------------------- |
|
659 //TInt CIRPresetHandler::RemoveObserver( MPSPresetObserver& aObserver ) |
|
660 //Removes an observer for a preset. |
|
661 //--------------------------------------------------------------------------- |
|
662 // |
|
663 EXPORT_C void CIRFavoritesDb::RemoveObserver(const MPSPresetObserver& aObserver ) |
|
664 { |
|
665 TInt idx = iObservers.FindInAddressOrder( &aObserver ); |
|
666 |
|
667 if ( idx >= 0 ) |
|
668 { |
|
669 iObservers.Remove( idx ); |
|
670 iObservers.Compress(); |
|
671 } |
|
672 } |
|
673 |
|
674 //--------------------------------------------------------------------------- |
|
675 //TInt CIRFavoritesDb::MatchingPresetId( TInt aId ) |
|
676 //--------------------------------------------------------------------------- |
|
677 // |
|
678 |
|
679 TInt CIRFavoritesDb::MatchingPresetId( TInt aId ) |
|
680 { |
|
681 TInt indx = KErrNotFound; |
|
682 |
|
683 SortByIndex() ; |
|
684 |
|
685 for ( TInt i = 0; i < iFavPresetList.Count(); i++ ) |
|
686 { |
|
687 if (iFavPresetList[i]->Id() == aId ) |
|
688 { |
|
689 indx = iFavPresetList[i]->Index(); |
|
690 /*lint -save -e960 Note -- Violates MISRA Required Rule 58, |
|
691 non-switch break used*/ |
|
692 break; |
|
693 /*lint -restore */ |
|
694 } |
|
695 } |
|
696 |
|
697 return indx; |
|
698 } |
|
699 |
|
700 //--------------------------------------------------------------------------- |
|
701 //TInt CIRFavoritesDb::CreatePresetL( TInt aIndex ) |
|
702 //creates a preset by the index aIndex |
|
703 //--------------------------------------------------------------------------- |
|
704 // |
|
705 |
|
706 CIRPreset* CIRFavoritesDb::CreatePresetL( TInt aIndex ) |
|
707 { |
|
708 IRLOG_DEBUG( "CIRFavoritesDb::CreatePresetL" ); |
|
709 CIRPreset* preset = static_cast<CIRPreset*>( iServ.CreatePresetL( |
|
710 aIndex, KIRPreset) ); |
|
711 CleanupStack::PushL( preset ); |
|
712 iFavPresetList.AppendL( preset ); |
|
713 CleanupStack::Pop( preset ); |
|
714 IRLOG_DEBUG( "CIRFavoritesDb::CreatePresetL - Exiting." ); |
|
715 return preset; |
|
716 } |
|
717 |
|
718 /* |
|
719 * Search a user defined preset by name and url |
|
720 */ |
|
721 TInt CIRFavoritesDb::SearchUserDefinedPreset(const TDesC &aName, const TDesC &aUrl) |
|
722 { |
|
723 TInt count = iFavPresetList.Count(); |
|
724 for (TInt index = 0; index < count; ++index) |
|
725 { |
|
726 CIRPreset *preset = iFavPresetList[index]; |
|
727 const TDesC &name = preset->Name(); |
|
728 TInt urlCount = preset->GetUrlCount(); |
|
729 if(preset->GetUrlCount()>0) |
|
730 { |
|
731 const TDesC &url = preset->GetChannelUrlAt(0); |
|
732 if (preset->GetChannelType() == 0 && |
|
733 name == aName && |
|
734 url == aUrl) |
|
735 { |
|
736 return index; |
|
737 } |
|
738 } |
|
739 else |
|
740 { |
|
741 if (preset->GetChannelType() == 0 && |
|
742 name == aName && |
|
743 aUrl == KNullDesC) |
|
744 { |
|
745 return index; |
|
746 } |
|
747 } |
|
748 } |
|
749 |
|
750 return KErrNotFound; |
|
751 } |
|
752 |
|
753 //--------------------------------------------------------------------------- |
|
754 //CIRFavoritesDb::PresetByIndex(TInt aIndex) |
|
755 // Returns a preset by its id. |
|
756 //--------------------------------------------------------------------------- |
|
757 // |
|
758 EXPORT_C CIRPreset* CIRFavoritesDb::PresetByIndex( TInt aIndex ) |
|
759 { |
|
760 IRLOG_DEBUG( "CIRFavoritesDb::PresetByIndex" ); |
|
761 |
|
762 CIRPreset* preset = NULL; |
|
763 |
|
764 for ( TInt i = 0; i < iFavPresetList.Count(); i++ ) |
|
765 { |
|
766 if (iFavPresetList[i]->Index()==aIndex) |
|
767 { |
|
768 preset = iFavPresetList[i]; |
|
769 /*lint -save -e960 (Note -- Violates MISRA Required Rule 58, non-switch break used)*/ |
|
770 break; |
|
771 /*lint -restore*/ |
|
772 } |
|
773 } |
|
774 IRLOG_DEBUG( "CIRFavoritesDb::PresetByIndex - Exiting." ); |
|
775 return preset; |
|
776 } |
|
777 |
|
778 //--------------------------------------------------------------------------- |
|
779 // CIRFavoritesDb::PresetById(TInt aIndex) |
|
780 //Returns a preset by its id. |
|
781 //--------------------------------------------------------------------------- |
|
782 // |
|
783 EXPORT_C CIRPreset* CIRFavoritesDb::PresetById( TInt aId ) |
|
784 { |
|
785 IRLOG_DEBUG( "CIRFavoritesDb::PresetById" ); |
|
786 |
|
787 CIRPreset* preset = NULL; |
|
788 |
|
789 for ( TInt i = 0; i < iFavPresetList.Count(); i++ ) |
|
790 { |
|
791 if ( iFavPresetList[i]->Id() == aId ) |
|
792 { |
|
793 preset = iFavPresetList[i]; |
|
794 /*lint -save -e960 Note -- Violates MISRA Required Rule 58, |
|
795 non-switch break used*/ |
|
796 break; |
|
797 /*lint -restore */ |
|
798 } |
|
799 } |
|
800 IRLOG_DEBUG( "CIRFavoritesDb::PresetById - Exiting." ); |
|
801 |
|
802 return preset; |
|
803 } |
|
804 |
|
805 |
|
806 //--------------------------------------------------------------------------- |
|
807 //CIRFavoritesDb::HandlePresetChangedL() |
|
808 //function to notify a change in saved presets |
|
809 //preset handler i.e CIRPreset,the reason of change. |
|
810 //--------------------------------------------------------------------------- |
|
811 // |
|
812 EXPORT_C void CIRFavoritesDb::HandlePresetChangedL( TInt aId, |
|
813 TUid aDataHandler, MPSPresetObserver::TPSReason aReason ) |
|
814 { |
|
815 IRLOG_DEBUG( "CIRFavoritesDb::HandlePresetChangedL" ); |
|
816 if ( aDataHandler == KIRPreset ) |
|
817 { |
|
818 switch ( aReason ) |
|
819 { |
|
820 case MPSPresetObserver::EPSCreated: |
|
821 { |
|
822 //call back from the preset client |
|
823 //to append a preset when the preset is added |
|
824 CPSPresetInterface* preset = NULL; |
|
825 preset = PresetById( aId ); |
|
826 if ( !preset ) |
|
827 { |
|
828 preset = iServ.OpenPresetL( aId ); |
|
829 CleanupStack::PushL( preset ); |
|
830 iFavPresetList.AppendL( static_cast<CIRPreset*>( preset ) ); |
|
831 CleanupStack::Pop( preset ); |
|
832 } |
|
833 |
|
834 } |
|
835 break; |
|
836 case MPSPresetObserver::EPSDeleted: |
|
837 { |
|
838 //call back from the preset client |
|
839 //to remove a preset when the preset is deleted |
|
840 for ( TInt i = 0; i < iFavPresetList.Count(); i++ ) |
|
841 { |
|
842 if ( iFavPresetList[i]->Id() == aId ) |
|
843 { |
|
844 delete iFavPresetList[i]; |
|
845 iFavPresetList.Remove( i ); |
|
846 /*lint -save -e960 (Note -- Violates MISRA Required Rule 58, non-switch break used)*/ |
|
847 break; |
|
848 /*lint -restore*/ |
|
849 } |
|
850 } |
|
851 } |
|
852 break; |
|
853 case MPSPresetObserver::EPSModified: |
|
854 break; |
|
855 default: |
|
856 break; |
|
857 } |
|
858 |
|
859 for ( TInt i = 0; i < iObservers.Count(); i++ ) |
|
860 { |
|
861 iObservers[i]->HandlePresetChangedL( aId, aDataHandler, aReason ); |
|
862 } |
|
863 |
|
864 } |
|
865 IRLOG_DEBUG( "CIRFavoritesDb::HandlePresetChangedL - Exiting." ); |
|
866 |
|
867 } |
|
868 |
|
869 |