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: Engine class to notify channel name/metadata changes to SongHistoryDb and UI |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 /* --------------------------------------------------------------------------- |
|
20 * Version history: |
|
21 * Template version: |
|
22 * <ccm_history> |
|
23 * |
|
24 * Version: 3, Thu Apr 14 12:00:00 2008 by Rohit |
|
25 * Ref: |
|
26 * Pc lint fixes |
|
27 * |
|
28 * Version: 2, Thu Apr 10 20:00:00 2008 by Rohit |
|
29 * Ref: |
|
30 * Implemented SongHistory changes for channelwise songs |
|
31 * |
|
32 * </ccm_history> |
|
33 * ============================================================================ |
|
34 */ |
|
35 |
|
36 #include "irpubsubkeys.h" |
|
37 #include "irsonghistoryengine.h" |
|
38 #include "uinotifyhandler.h" |
|
39 #include "irsonghistoryengpubsub.h" |
|
40 #include "irmetadata.h" |
|
41 #include "irdebug.h" |
|
42 |
|
43 class CIRSongHistoryDb; |
|
44 |
|
45 |
|
46 // --------------------------------------------------------------------------- |
|
47 // CIRSongHistoryEngine::CIRSongHistoryEngine |
|
48 // Default Constructor. |
|
49 // --------------------------------------------------------------------------- |
|
50 // |
|
51 CIRSongHistoryEngine::CIRSongHistoryEngine(MSongHistoryUINotifyHandler& aUiObserver ) |
|
52 :iUiObserver( aUiObserver ) |
|
53 { |
|
54 } |
|
55 |
|
56 // --------------------------------------------------------------------------- |
|
57 // CIRSongHistoryEngine::ConstructL |
|
58 // Second-phase constructor |
|
59 // --------------------------------------------------------------------------- |
|
60 // |
|
61 void CIRSongHistoryEngine::ConstructL() |
|
62 { |
|
63 IRLOG_DEBUG( "CIRSongHistoryEngine::ConstructL" ); |
|
64 |
|
65 iSongHistoryDb = CIRSongHistoryDb::NewL(); |
|
66 |
|
67 |
|
68 |
|
69 //Subsciber for the meta data |
|
70 iMetaDataSub = CIRSongHistoryEngPubSub::NewL( *this, |
|
71 KUidActiveInternetRadioApp,KIRPSMetaData, RProperty::ELargeText) ; |
|
72 |
|
73 IRLOG_DEBUG( "CIRSongHistoryEngine::ConstructL - Exiting." ); |
|
74 } |
|
75 |
|
76 |
|
77 // --------------------------------------------------------------------------- |
|
78 // CIRSongHistoryEngine::NewL() |
|
79 // Static constructor. |
|
80 // --------------------------------------------------------------------------- |
|
81 // |
|
82 EXPORT_C CIRSongHistoryEngine* CIRSongHistoryEngine::NewL( |
|
83 MSongHistoryUINotifyHandler & aUiObserver) |
|
84 { |
|
85 IRLOG_DEBUG( "CIRSongHistoryEngine::NewL - Entering" ); |
|
86 CIRSongHistoryEngine* self = NewLC( aUiObserver); |
|
87 CleanupStack::Pop( self ); |
|
88 IRLOG_DEBUG( "CIRSongHistoryEngine::NewL - Exiting." ); |
|
89 return self; |
|
90 } |
|
91 |
|
92 |
|
93 // --------------------------------------------------------------------------- |
|
94 // CIRSongHistoryEngine::NewLC() |
|
95 // Static constructor. |
|
96 // --------------------------------------------------------------------------- |
|
97 // |
|
98 |
|
99 EXPORT_C CIRSongHistoryEngine* CIRSongHistoryEngine::NewLC( |
|
100 MSongHistoryUINotifyHandler & aUiObserver) |
|
101 { |
|
102 IRLOG_DEBUG( "CIRSongHistoryEngine::NewLC - Entering" ); |
|
103 CIRSongHistoryEngine* self = new ( ELeave ) CIRSongHistoryEngine( aUiObserver ); |
|
104 CleanupStack::PushL( self ); |
|
105 self->ConstructL(); |
|
106 IRLOG_DEBUG( "CIRSongHistoryEngine::NewLC - Exiting." ); |
|
107 return self; |
|
108 } |
|
109 |
|
110 |
|
111 // --------------------------------------------------------------------------- |
|
112 // CIRSongHistoryEngine::~CIRSongHistoryEngine() |
|
113 // standard C++ destructor |
|
114 // --------------------------------------------------------------------------- |
|
115 // |
|
116 EXPORT_C CIRSongHistoryEngine::~CIRSongHistoryEngine() |
|
117 { |
|
118 IRLOG_DEBUG( "CIRSongHistoryEngine::~CIRSongHistoryEngine - Entering" ); |
|
119 |
|
120 delete iSongHistoryDb; |
|
121 delete iChannelNameSub; |
|
122 delete iMetaDataSub; |
|
123 |
|
124 IRLOG_DEBUG( "CIRSongHistoryEngine::~CIRSongHistoryEngine - Exiting." ); |
|
125 } |
|
126 |
|
127 |
|
128 // --------------------------------------------------------------------------- |
|
129 // CIRSongHistoryEngine::HandleMetaDataReceivedL() |
|
130 // Invoked when any listened P&S key is changed. |
|
131 // --------------------------------------------------------------------------- |
|
132 // |
|
133 |
|
134 EXPORT_C void CIRSongHistoryEngine::HandleMetaDataReceivedL( const CIRMetaData& aMetaData ) |
|
135 { |
|
136 IRLOG_DEBUG( "CIRSongHistoryEngine::HandleMetaDataChangeL - Entering" ); |
|
137 |
|
138 // Read Channel Name |
|
139 RBuf channelName; |
|
140 |
|
141 TBuf<KMAXLENGTH> channelNameBuffer; |
|
142 RProperty::Get ( KUidActiveInternetRadioApp, KIRPSDataChannel, channelNameBuffer); |
|
143 channelName.Create(channelNameBuffer.Length()); |
|
144 channelName.CleanupClosePushL(); |
|
145 channelName.Copy(channelNameBuffer); |
|
146 |
|
147 TInt channelType; |
|
148 RProperty::Get ( KUidActiveInternetRadioApp, KIRPSChannelType, channelType); |
|
149 |
|
150 TInt channelId; |
|
151 RProperty::Get ( KUidActiveInternetRadioApp, KIRPSChannelId, channelId); |
|
152 |
|
153 // Read Channel Url |
|
154 RBuf channelUrl; |
|
155 |
|
156 TBuf<KMAXLENGTH> channelUrlBuffer; |
|
157 RProperty::Get ( KUidActiveInternetRadioApp, KIRPSChannelUrl, channelUrlBuffer); |
|
158 channelUrl.Create(channelUrlBuffer.Length()); |
|
159 channelUrl.CleanupClosePushL(); |
|
160 channelUrl.Copy(channelUrlBuffer); |
|
161 |
|
162 |
|
163 |
|
164 RBuf channelDesc; |
|
165 |
|
166 TBuf<KMAXLENGTH> channelDescBuffer; |
|
167 |
|
168 RProperty::Get ( KUidActiveInternetRadioApp, KIRPSDataChannelDesc, channelDescBuffer); |
|
169 channelDesc.Create(channelDescBuffer.Length()); |
|
170 channelDesc.CleanupClosePushL(); |
|
171 channelDesc.Copy(channelDescBuffer); |
|
172 |
|
173 RBuf imageUrl; |
|
174 imageUrl.Create(KNullDesC().Length()); |
|
175 imageUrl.CleanupClosePushL(); |
|
176 imageUrl.Copy(KNullDesC); |
|
177 |
|
178 RBuf musicFlag; |
|
179 |
|
180 TBuf<KMAXLENGTH> musicFlagBuffer; |
|
181 |
|
182 if(channelType==1) |
|
183 { |
|
184 RProperty::Get ( KUidActiveInternetRadioApp, KIRPSChannelMusicFlag, musicFlagBuffer); |
|
185 musicFlag.Create(musicFlagBuffer.Length()); |
|
186 musicFlag.CleanupClosePushL(); |
|
187 musicFlag.Copy(musicFlagBuffer); |
|
188 } |
|
189 else |
|
190 { |
|
191 musicFlag.Create(KNullDesC().Length()); |
|
192 musicFlag.CleanupClosePushL(); |
|
193 musicFlag.Copy(KNullDesC); |
|
194 } |
|
195 |
|
196 if(channelType==1) |
|
197 { |
|
198 TInt ret = iSongHistoryDb->GetIdPresentInDbL( channelId ); |
|
199 if(ret) |
|
200 { |
|
201 TInt modified = iSongHistoryDb->UpdateSongHistoryDbL( channelId , |
|
202 channelName ,channelUrl ,imageUrl ,musicFlag); |
|
203 if(modified) |
|
204 { |
|
205 iUiObserver.ChannelChangedL( aMetaData.Song(),aMetaData.Artist(), |
|
206 channelName, channelUrl ); |
|
207 } |
|
208 } |
|
209 |
|
210 } |
|
211 |
|
212 TSongHistoryItemChange changeCode = DetectSongHistoryItemChangesL(aMetaData, |
|
213 channelName, channelUrl); |
|
214 |
|
215 if(changeCode==EBLANKENTRIES || changeCode == ENOCHANGE ) |
|
216 { |
|
217 |
|
218 CleanupStack::PopAndDestroy(&musicFlag); |
|
219 CleanupStack::PopAndDestroy(&imageUrl); |
|
220 CleanupStack::PopAndDestroy(&channelDesc); |
|
221 CleanupStack::PopAndDestroy(&channelUrl); |
|
222 CleanupStack::PopAndDestroy(&channelName); |
|
223 return; |
|
224 } |
|
225 |
|
226 RBuf delSongName; |
|
227 delSongName.CleanupClosePushL(); |
|
228 RBuf delArtistName; |
|
229 delArtistName.CleanupClosePushL(); |
|
230 RBuf delChannelName; |
|
231 delChannelName.CleanupClosePushL(); |
|
232 RBuf delChannelUrl; |
|
233 delChannelUrl.CleanupClosePushL(); |
|
234 TBool bExceededMax = iSongHistoryDb->AddToSongHistoryDbL( aMetaData.Song(), |
|
235 aMetaData.Artist(), |
|
236 channelName, |
|
237 channelUrl, |
|
238 delSongName, |
|
239 delArtistName, |
|
240 delChannelName, |
|
241 delChannelUrl , |
|
242 channelType, |
|
243 channelId, |
|
244 64, |
|
245 channelDesc, |
|
246 imageUrl, |
|
247 musicFlag |
|
248 ); |
|
249 if( bExceededMax ) |
|
250 { |
|
251 if( 0 == iSongHistoryDb->GetChannelSongsCountL(delChannelName,delChannelUrl) ) |
|
252 { |
|
253 iUiObserver.RemoveChannelEntry(delSongName, delArtistName, delChannelName, delChannelUrl); |
|
254 } |
|
255 else |
|
256 { |
|
257 iUiObserver.RemoveSongEntry(delSongName, delArtistName, delChannelName, delChannelUrl); |
|
258 } |
|
259 } |
|
260 |
|
261 |
|
262 if( changeCode == ECHANNELCHANGED ) // channel change detected |
|
263 { |
|
264 iUiObserver.ChannelChangedL( aMetaData.Song(),aMetaData.Artist(), channelName, channelUrl ); |
|
265 } |
|
266 else // same channel playing next song |
|
267 { |
|
268 iUiObserver.NextSongReceivedL( aMetaData.Song(),aMetaData.Artist(), channelName, channelUrl ); |
|
269 } |
|
270 |
|
271 CleanupStack::PopAndDestroy(&delChannelUrl); |
|
272 CleanupStack::PopAndDestroy(&delChannelName); |
|
273 CleanupStack::PopAndDestroy(&delArtistName); |
|
274 CleanupStack::PopAndDestroy(&delSongName); |
|
275 |
|
276 CleanupStack::PopAndDestroy(&musicFlag); |
|
277 CleanupStack::PopAndDestroy(&imageUrl); |
|
278 CleanupStack::PopAndDestroy(&channelDesc); |
|
279 CleanupStack::PopAndDestroy(&channelUrl); |
|
280 CleanupStack::PopAndDestroy(&channelName); |
|
281 |
|
282 |
|
283 IRLOG_DEBUG( "CIRSongHistoryEngine::HandleMetaDataChangeL - Exiting." ); |
|
284 } |
|
285 // --------------------------------------------------------------------------- |
|
286 // CIRSongHistoryEngine::DetectSongHistoryItemChangesL() |
|
287 // To detect any change in the song history items. |
|
288 // --------------------------------------------------------------------------- |
|
289 // |
|
290 |
|
291 TSongHistoryItemChange CIRSongHistoryEngine::DetectSongHistoryItemChangesL( |
|
292 const CIRMetaData& aMetaData, const RBuf& aChannelName, const RBuf& aChannelUrl) |
|
293 { |
|
294 if(aChannelName.Length() == 0) |
|
295 { |
|
296 return EBLANKENTRIES; |
|
297 } |
|
298 |
|
299 //If the meta data is not available |
|
300 if(((aMetaData.Song()).Length() == 0) && ((aMetaData.Artist()).Length() == 0)) |
|
301 { |
|
302 return EBLANKENTRIES; |
|
303 } |
|
304 |
|
305 RBuf song; |
|
306 song.CleanupClosePushL(); |
|
307 RBuf artist; |
|
308 artist.CleanupClosePushL(); |
|
309 RBuf channel; |
|
310 channel.CleanupClosePushL(); |
|
311 RBuf url; |
|
312 url.CleanupClosePushL(); |
|
313 |
|
314 TRAPD( error, iSongHistoryDb->GetLastHistoryItemL(song, artist, channel, url)); |
|
315 if( error ) |
|
316 { |
|
317 IRLOG_DEBUG( "CIRSongHistoryEngine::DetectSongHistoryItemChangesL() - Failed while GetLastHistoryItemL()" ); |
|
318 } |
|
319 |
|
320 TSongHistoryItemChange retval = ENOCHANGE; // pc-lint # 644 fix |
|
321 |
|
322 if((song == aMetaData.Song() ) && (artist == aMetaData.Artist()) && |
|
323 (channel == aChannelName) && (url == aChannelUrl)) |
|
324 { |
|
325 retval = ENOCHANGE; |
|
326 } |
|
327 else if( channel != aChannelName || url != aChannelUrl ) |
|
328 { |
|
329 retval = ECHANNELCHANGED; |
|
330 } |
|
331 else if( song != aMetaData.Song() || artist != aMetaData.Artist() ) |
|
332 { |
|
333 retval = EMETADATACHANGED; |
|
334 } |
|
335 else |
|
336 { |
|
337 // pc-lint # 961 fix |
|
338 } |
|
339 |
|
340 CleanupStack::PopAndDestroy(&url); |
|
341 CleanupStack::PopAndDestroy(&channel); |
|
342 CleanupStack::PopAndDestroy(&artist); |
|
343 CleanupStack::PopAndDestroy(&song); |
|
344 |
|
345 return retval; |
|
346 } |
|
347 |
|
348 |
|
349 // --------------------------------------------------------------------------- |
|
350 // CIRSongHistoryEngine::HandlePropertyChangeErrorL |
|
351 // Invoked when an error has occured while fetching the new value of any listened P&S key. |
|
352 // --------------------------------------------------------------------------- |
|
353 // |
|
354 void CIRSongHistoryEngine::HandlePropertyChangeErrorL( const TUid& /*aCategory*/, |
|
355 TUint /*aKey*/, TInt aError ) |
|
356 { |
|
357 IRLOG_DEBUG( "CIRSongHistoryEngine::HandlePropertyChangeErrorL" ); |
|
358 if (aError < 0) |
|
359 { |
|
360 //Some action has to be taken |
|
361 } |
|
362 IRLOG_DEBUG( "CIRSongHistoryEngine::HandlePropertyChangeErrorL" ); |
|
363 } |
|
364 |
|
365 |
|
366 // --------------------------------------------------------------------------- |
|
367 // CIRSongHistoryEngine::HandlePropertyChangeL |
|
368 // Invoked when any listened P&S key is changed. |
|
369 // --------------------------------------------------------------------------- |
|
370 |
|
371 void CIRSongHistoryEngine::HandlePropertyChangeL( const TUid& aCategory, |
|
372 TUint aKey, const TDesC8& aText ) |
|
373 { |
|
374 IRLOG_DEBUG( "CIRSongHistoryEngine::HandlePropertyChangeL" ); |
|
375 if ( aCategory == KUidActiveInternetRadioApp ) |
|
376 { |
|
377 if( aKey == KIRPSDataChannel ) |
|
378 { |
|
379 } |
|
380 else if( aKey == KIRPSMetaData ) |
|
381 { |
|
382 CIRMetaData* metaData = CIRMetaData::NewL( aText ); |
|
383 CleanupStack::PushL( metaData ); |
|
384 HandleMetaDataReceivedL( *metaData ); |
|
385 CleanupStack::PopAndDestroy( metaData ); |
|
386 } |
|
387 else |
|
388 { |
|
389 // To avoid PC lint error |
|
390 } |
|
391 } |
|
392 IRLOG_DEBUG( "CIRSongHistoryEngine::HandlePropertyChangeL - Exiting." ); |
|
393 } |
|
394 |
|
395 |
|
396 // --------------------------------------------------------------------------- |
|
397 // CIRSongHistoryEngine::GetAllHistoryL |
|
398 // Invoked when when UI request. |
|
399 // Getting the data from SongHistoryDb. |
|
400 // --------------------------------------------------------------------------- |
|
401 |
|
402 EXPORT_C void CIRSongHistoryEngine::GetAllHistoryL( |
|
403 RPointerArray<CIRSongHistoryInfo>& aSongHistoryInfo ) |
|
404 { |
|
405 iSongHistoryDb->GetAllSongHistoryListL(aSongHistoryInfo); |
|
406 |
|
407 } |
|
408 |
|
409 |
|
410 // --------------------------------------------------------------------------- |
|
411 // CIRSongHistoryEngine::ClearAllHistory |
|
412 // Invoked when when UI request. |
|
413 // Clears the SongHistoryDb. |
|
414 // --------------------------------------------------------------------------- |
|
415 |
|
416 EXPORT_C TInt CIRSongHistoryEngine::ClearAllHistory( ) |
|
417 { |
|
418 TInt ret = 0; |
|
419 ret = iSongHistoryDb->ClearAllSongHistoryFromDb(); |
|
420 return ret; |
|
421 } |
|
422 |
|
423 EXPORT_C TInt CIRSongHistoryEngine::DeleteOneHistory(TInt aIndex) |
|
424 { |
|
425 return iSongHistoryDb->DeleteOneHistory(aIndex); |
|
426 } |
|
427 |
|
428 |
|
429 // --------------------------------------------------------------------------- |
|
430 // CIRSongHistoryEngine::GetHistoryCount |
|
431 // Invoked when when UI request. |
|
432 // Gets the count of the SongHistoryDb. |
|
433 // --------------------------------------------------------------------------- |
|
434 |
|
435 EXPORT_C TInt CIRSongHistoryEngine::GetHistoryCount() |
|
436 { |
|
437 TInt HistoryCount = 0; |
|
438 HistoryCount = iSongHistoryDb->CountSongHistoryDb(); |
|
439 return HistoryCount; |
|
440 } |
|
441 |
|
442 // --------------------------------------------------------------------------- |
|
443 // CIRSongHistoryEngine::SyncHistory |
|
444 // Invoked when when UI request. |
|
445 // Synchronises the Song history DB with the new data in the ISDS. |
|
446 // --------------------------------------------------------------------------- |
|
447 |
|
448 EXPORT_C TInt CIRSongHistoryEngine::SyncHistory(TInt aChannelId) |
|
449 { |
|
450 IRLOG_DEBUG( "CIRSongHistoryEngine::SyncHistory - Entering." ); |
|
451 TRAPD(err,iSongHistoryDb->SyncSongHistoryDbL(aChannelId)); |
|
452 if(err) |
|
453 { |
|
454 |
|
455 } |
|
456 IRLOG_DEBUG( "CIRSongHistoryEngine::SyncHistory - Exiting." ); |
|
457 return KErrNone; |
|
458 } |
|
459 // --------------------------------------------------------------------------- |
|
460 // CIRSongHistoryEngine::UpdateSongHistoryDB |
|
461 // Invoked when when UI request. |
|
462 // Synchronises the Song history DB with the new data in the ISDS. |
|
463 // --------------------------------------------------------------------------- |
|
464 |
|
465 EXPORT_C void CIRSongHistoryEngine::UpdateSongHistoryDb(TInt aChannelId, |
|
466 const TDesC& aChannelName, |
|
467 const TDesC& aChannelUrl, |
|
468 const TDesC& aMusicFlag) |
|
469 { |
|
470 IRLOG_DEBUG( "CIRSongHistoryEngine::UpdateSongHistoryDb - Entering." ); |
|
471 TInt ret = KErrNone ; |
|
472 TRAPD(err,ret = iSongHistoryDb->GetIdPresentInDbL( aChannelId )); |
|
473 if(err) |
|
474 { |
|
475 return; |
|
476 } |
|
477 if(ret) |
|
478 { |
|
479 TRAPD(err,iSongHistoryDb->UpdateSongHistoryDbL( aChannelId , |
|
480 aChannelName , |
|
481 aChannelUrl , |
|
482 aChannelUrl, |
|
483 aMusicFlag)); |
|
484 if(err) |
|
485 { |
|
486 return ; |
|
487 } |
|
488 } |
|
489 |
|
490 IRLOG_DEBUG( "CIRSongHistoryEngine::UpdateSongHistoryDb - Exiting." ); |
|
491 } |
|