|
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: |
|
15 * |
|
16 */ |
|
17 #include "irsonghistoryinfo.h" |
|
18 #include "irsonghistorydb.h" |
|
19 #include "irqsonghistoryinfo.h" |
|
20 #include "irqisdsdatastructure.h" |
|
21 #include "irqmetadata.h" |
|
22 #include "irqsonghistoryengine.h" |
|
23 |
|
24 // --------------------------------------------------------------------------- |
|
25 // IRQSongHistoryEngine::openInstance() |
|
26 // Static function to get a singleton instance of IRQSongHistoryEngine |
|
27 // @return IRQSongHistoryEngine * |
|
28 // --------------------------------------------------------------------------- |
|
29 // |
|
30 EXPORT_C IRQSongHistoryEngine* IRQSongHistoryEngine::openInstance() |
|
31 { |
|
32 // Get singleton instance |
|
33 IRQSongHistoryEngine* irqSongHistoryEngine = |
|
34 reinterpret_cast<IRQSongHistoryEngine*>(Dll::Tls()); |
|
35 |
|
36 if (NULL == irqSongHistoryEngine) |
|
37 { |
|
38 TRAPD(error, irqSongHistoryEngine = createInstanceL()); |
|
39 if (KErrNone != error) |
|
40 { |
|
41 delete irqSongHistoryEngine; |
|
42 irqSongHistoryEngine = NULL; |
|
43 Dll::SetTls(NULL); |
|
44 } |
|
45 } |
|
46 else |
|
47 { |
|
48 irqSongHistoryEngine->iSingletonInstances++; |
|
49 } |
|
50 |
|
51 return irqSongHistoryEngine; |
|
52 } |
|
53 |
|
54 // --------------------------------------------------------------------------- |
|
55 // IRQSongHistoryEngine::closeInstance() |
|
56 // Close a singleton instance of IRQSongHistoryEngine |
|
57 // --------------------------------------------------------------------------- |
|
58 // |
|
59 EXPORT_C void IRQSongHistoryEngine::closeInstance() |
|
60 { |
|
61 iSingletonInstances--; |
|
62 |
|
63 if (0 == iSingletonInstances) |
|
64 { |
|
65 Dll::SetTls(NULL); |
|
66 delete this; |
|
67 } |
|
68 } |
|
69 |
|
70 // --------------------------------------------------------------------------- |
|
71 // IRQSongHistoryEngine::createInstanceL() |
|
72 // Creates IRQSongHistoryEngine instance |
|
73 // @return IRQSongHistoryEngine* |
|
74 // --------------------------------------------------------------------------- |
|
75 // |
|
76 IRQSongHistoryEngine* IRQSongHistoryEngine::createInstanceL() |
|
77 { |
|
78 IRQSongHistoryEngine* irqSongHistoryEngine = new (ELeave) IRQSongHistoryEngine(); |
|
79 irqSongHistoryEngine->constructL(); |
|
80 User::LeaveIfError(Dll::SetTls(irqSongHistoryEngine)); |
|
81 irqSongHistoryEngine->iSingletonInstances = 1; |
|
82 |
|
83 return irqSongHistoryEngine; |
|
84 } |
|
85 |
|
86 // --------------------------------------------------------------------------- |
|
87 // IRQSongHistoryEngine::constructL() |
|
88 // Two-Phase Constructor. |
|
89 // --------------------------------------------------------------------------- |
|
90 // |
|
91 void IRQSongHistoryEngine::constructL() |
|
92 { |
|
93 iSongHistoryDb = CIRSongHistoryDb::NewL(); |
|
94 } |
|
95 |
|
96 // --------------------------------------------------------------------------- |
|
97 // IRQSongHistoryEngine::IRQSongHistoryEngine() |
|
98 // standard C++ Constructor |
|
99 // --------------------------------------------------------------------------- |
|
100 // |
|
101 IRQSongHistoryEngine::IRQSongHistoryEngine() |
|
102 { |
|
103 } |
|
104 |
|
105 // --------------------------------------------------------------------------- |
|
106 // IRQSongHistoryEngine::~IRQSongHistoryEngine() |
|
107 // standard C++ destructor |
|
108 // --------------------------------------------------------------------------- |
|
109 // |
|
110 IRQSongHistoryEngine::~IRQSongHistoryEngine() |
|
111 { |
|
112 delete iSongHistoryDb; |
|
113 iSongHistoryDb = NULL; |
|
114 } |
|
115 |
|
116 // --------------------------------------------------------------------------- |
|
117 // IRQSongHistoryEngine::handleMetaDataReceivedL() |
|
118 // Invoked when channel name or song & artist name are changed. |
|
119 // --------------------------------------------------------------------------- |
|
120 // |
|
121 EXPORT_C void IRQSongHistoryEngine::handleMetaDataReceived(const IRQMetaData& aMetaData, |
|
122 const IRQPreset& aPreset) |
|
123 { |
|
124 TRAPD(error, handleMetaDataReceivedL(aMetaData, aPreset)); |
|
125 if (KErrNone != error) |
|
126 { |
|
127 |
|
128 } |
|
129 } |
|
130 |
|
131 EXPORT_C void IRQSongHistoryEngine::handleSongMetaDataReceived(const IRQMetaData& aMetaData, |
|
132 QString& aMusicshopStatus) |
|
133 { |
|
134 TRAPD(error, handleSongMetaDataReceivedL(aMetaData,aMusicshopStatus)); |
|
135 if (KErrNone != error) |
|
136 { |
|
137 } |
|
138 } |
|
139 |
|
140 EXPORT_C void IRQSongHistoryEngine::handleSongMetaDataReceivedL(const IRQMetaData& aMetaData, |
|
141 QString& aMusicshopStatus) |
|
142 { |
|
143 TPtrC songName(reinterpret_cast<const TUint16*>(aMetaData.getSongName().utf16()), aMetaData.getSongName().length()); |
|
144 TPtrC artistName(reinterpret_cast<const TUint16*>(aMetaData.getArtistName().utf16()), aMetaData.getArtistName().length()); |
|
145 TPtrC musicFlag(reinterpret_cast<const TUint16*>(aMusicshopStatus.utf16()), aMusicshopStatus.length()); |
|
146 TBool bExceededMax = iSongHistoryDb->AddToSongHistoryDb2L(songName, |
|
147 artistName, |
|
148 musicFlag); |
|
149 } |
|
150 |
|
151 // --------------------------------------------------------------------------- |
|
152 // IRQSongHistoryEngine::handleMetaDataReceivedL() |
|
153 // --------------------------------------------------------------------------- |
|
154 // |
|
155 void IRQSongHistoryEngine::handleMetaDataReceivedL(const IRQMetaData& aMetaData, |
|
156 const IRQPreset& aPreset) |
|
157 { |
|
158 // Read Channel properties |
|
159 TPtrC songName(reinterpret_cast<const TUint16*>(aMetaData.getSongName().utf16()), aMetaData.getSongName().length()); |
|
160 TPtrC artistName(reinterpret_cast<const TUint16*>(aMetaData.getArtistName().utf16()), aMetaData.getArtistName().length()); |
|
161 TPtrC channelUrl(reinterpret_cast<const TUint16*>(aMetaData.getStreamUrl().utf16()), aMetaData.getStreamUrl().length()); |
|
162 TPtrC channelName(reinterpret_cast<const TUint16*>(aPreset.name.utf16()), aPreset.name.length()); |
|
163 TPtrC channelDesc(reinterpret_cast<const TUint16*>(aPreset.description.utf16()), aPreset.description.length()); |
|
164 TPtrC imageUrl(reinterpret_cast<const TUint16*>(aPreset.imgUrl.utf16()), aPreset.imgUrl.length()); |
|
165 TPtrC musicFlag(reinterpret_cast<const TUint16*>(aPreset.musicStoreStatus.utf16()), aPreset.musicStoreStatus.length()); |
|
166 TUint8 channelType = aPreset.type; |
|
167 TUint16 channelId = aPreset.presetId; |
|
168 TUint16 bitrate = aMetaData.getBitrate(); |
|
169 |
|
170 if (channelType == 1) |
|
171 { |
|
172 TInt ret = iSongHistoryDb->GetIdPresentInDbL( channelId ); |
|
173 if(ret) |
|
174 { |
|
175 TInt modified = iSongHistoryDb->UpdateSongHistoryDbL( channelId , |
|
176 channelName ,channelUrl ,imageUrl ,musicFlag); |
|
177 // TODO notify uplayer to change layout? |
|
178 } |
|
179 } |
|
180 else if (channelType != 0) |
|
181 { |
|
182 // the channel type can only be 1 (isds channel) or 0 (user defined channel) |
|
183 channelType = 0; |
|
184 } |
|
185 |
|
186 iSongHistoryDb->SearchAndDeleteRecordL(channelName, channelUrl, channelType); |
|
187 |
|
188 RBuf delSongName; |
|
189 delSongName.CleanupClosePushL(); |
|
190 RBuf delArtistName; |
|
191 delArtistName.CleanupClosePushL(); |
|
192 RBuf delChannelName; |
|
193 delChannelName.CleanupClosePushL(); |
|
194 RBuf delChannelUrl; |
|
195 delChannelUrl.CleanupClosePushL(); |
|
196 TBool bExceededMax = iSongHistoryDb->AddToSongHistoryDbL(songName, |
|
197 artistName, |
|
198 channelName, |
|
199 channelUrl, |
|
200 delSongName, |
|
201 delArtistName, |
|
202 delChannelName, |
|
203 delChannelUrl , |
|
204 channelType, |
|
205 channelId, |
|
206 bitrate, |
|
207 channelDesc, |
|
208 imageUrl, |
|
209 musicFlag); |
|
210 |
|
211 CleanupStack::PopAndDestroy(4, &delSongName); |
|
212 } |
|
213 |
|
214 // --------------------------------------------------------------------------- |
|
215 // IRQSongHistoryEngine::detectSongHistoryItemChangesL() |
|
216 // To detect any change in the song history items. |
|
217 // --------------------------------------------------------------------------- |
|
218 // |
|
219 IRQSongHistoryEngine::TSongHistoryItemChange IRQSongHistoryEngine::detectSongHistoryItemChangesL( |
|
220 const IRQMetaData& aMetaData, const QString& aChannelName) |
|
221 { |
|
222 if(aChannelName.length() == 0) |
|
223 { |
|
224 return EBLANKENTRIES; |
|
225 } |
|
226 |
|
227 RBuf song; |
|
228 song.CleanupClosePushL(); |
|
229 RBuf artist; |
|
230 artist.CleanupClosePushL(); |
|
231 RBuf channel; |
|
232 channel.CleanupClosePushL(); |
|
233 RBuf url; |
|
234 url.CleanupClosePushL(); |
|
235 |
|
236 iSongHistoryDb->GetLastHistoryItemL(song, artist, channel, url); |
|
237 |
|
238 TSongHistoryItemChange retval = ENOCHANGE; |
|
239 |
|
240 QString tmpsong = QString::fromUtf16(song.Ptr(), song.Length()); |
|
241 QString tmpartist = QString::fromUtf16(artist.Ptr(), artist.Length()); |
|
242 QString tmpchannel = QString::fromUtf16(channel.Ptr(), channel.Length()); |
|
243 QString tmpurl = QString::fromUtf16(url.Ptr(), url.Length()); |
|
244 if (tmpsong == aMetaData.getSongName() && tmpartist == aMetaData.getArtistName() |
|
245 && tmpchannel == aChannelName && tmpurl == aMetaData.getStreamUrl()) |
|
246 { |
|
247 retval = ENOCHANGE; |
|
248 } |
|
249 else |
|
250 { |
|
251 retval = ECHANNELCHANGED; |
|
252 } |
|
253 |
|
254 CleanupStack::PopAndDestroy(4, &song); |
|
255 |
|
256 return retval; |
|
257 } |
|
258 |
|
259 // --------------------------------------------------------------------------- |
|
260 // IRQSongHistoryEngine::getAllHistory |
|
261 // Invoked when when UI request. |
|
262 // Getting the data from SongHistoryDb. |
|
263 // --------------------------------------------------------------------------- |
|
264 |
|
265 EXPORT_C void IRQSongHistoryEngine::getAllHistory(QList<IRQSongHistoryInfo *>& aSongHistoryArr) |
|
266 { |
|
267 TRAP_IGNORE(getAllHistoryL(aSongHistoryArr)); |
|
268 } |
|
269 |
|
270 EXPORT_C void IRQSongHistoryEngine::getAllSongHistory(QList<IRQSongInfo *>& aSongHistoryArr) |
|
271 { |
|
272 TRAP_IGNORE(getAllSongHistoryL(aSongHistoryArr)); |
|
273 } |
|
274 |
|
275 // --------------------------------------------------------------------------- |
|
276 // IRQSongHistoryEngine::getAllHistoryL |
|
277 // Invoked when when UI request. |
|
278 // Getting the data from SongHistoryDb. |
|
279 // --------------------------------------------------------------------------- |
|
280 |
|
281 void IRQSongHistoryEngine::getAllHistoryL(QList<IRQSongHistoryInfo *>& aSongHistoryArr) |
|
282 { |
|
283 // clear the array |
|
284 while (!aSongHistoryArr.isEmpty()) |
|
285 { |
|
286 delete aSongHistoryArr.takeFirst(); |
|
287 } |
|
288 |
|
289 int songCount = iSongHistoryDb->CountSongHistoryDb(); |
|
290 |
|
291 if (songCount == 0) |
|
292 { |
|
293 return; |
|
294 } |
|
295 |
|
296 // get song history list |
|
297 RPointerArray<CIRSongHistoryInfo> historyDataArr; |
|
298 for (int arrCount = 0 ; arrCount < songCount ; arrCount++ ) |
|
299 { |
|
300 CIRSongHistoryInfo *songHistory = CIRSongHistoryInfo::NewL(); |
|
301 CleanupStack::PushL(songHistory); |
|
302 historyDataArr.AppendL(songHistory); |
|
303 CleanupStack::Pop(songHistory); |
|
304 } |
|
305 |
|
306 iSongHistoryDb->GetAllSongHistoryListL(historyDataArr); |
|
307 |
|
308 // create IRQSongHistoryInfo array and set |
|
309 QString songName; |
|
310 QString artist; |
|
311 QString streamUrl; |
|
312 QString channelName; |
|
313 int channelType; |
|
314 int channelId; |
|
315 int bitrate; |
|
316 QString channelDesc; |
|
317 QString imageUrl; |
|
318 QString musicStoreStatus; |
|
319 for (int arrCount = 0 ; arrCount < songCount ; arrCount++ ) |
|
320 { |
|
321 songName = QString::fromUtf16(historyDataArr[arrCount]->GetSongInfo().Ptr(), |
|
322 historyDataArr[arrCount]->GetSongInfo().Length()); |
|
323 artist = QString::fromUtf16(historyDataArr[arrCount]->GetArtistInfo().Ptr(), |
|
324 historyDataArr[arrCount]->GetArtistInfo().Length()); |
|
325 streamUrl = QString::fromUtf16(historyDataArr[arrCount]->GetStreamUrl().Ptr(), |
|
326 historyDataArr[arrCount]->GetStreamUrl().Length()); |
|
327 channelName = QString::fromUtf16(historyDataArr[arrCount]->GetChannelName().Ptr(), |
|
328 historyDataArr[arrCount]->GetChannelName().Length()); |
|
329 channelType = historyDataArr[arrCount]->GetChannelType(); |
|
330 channelId = historyDataArr[arrCount]->GetChannelId(); |
|
331 bitrate = historyDataArr[arrCount]->GetBitrate(); |
|
332 channelDesc = QString::fromUtf16(historyDataArr[arrCount]->GetChannelDesc().Ptr(), |
|
333 historyDataArr[arrCount]->GetChannelDesc().Length()); |
|
334 imageUrl = QString::fromUtf16(historyDataArr[arrCount]->GetImageUrl().Ptr(), |
|
335 historyDataArr[arrCount]->GetImageUrl().Length()); |
|
336 musicStoreStatus = QString::fromUtf16(historyDataArr[arrCount]->GetChannelMusicStatus().Ptr(), |
|
337 historyDataArr[arrCount]->GetChannelMusicStatus().Length()); |
|
338 IRQSongHistoryInfo* irqsongHistory = new IRQSongHistoryInfo(); |
|
339 if (NULL == irqsongHistory) |
|
340 { |
|
341 break; |
|
342 } |
|
343 irqsongHistory->setHistoryInfo(artist, songName, streamUrl, channelName, channelDesc |
|
344 , imageUrl, musicStoreStatus, channelType, channelId, bitrate); |
|
345 aSongHistoryArr.append(irqsongHistory); |
|
346 } |
|
347 |
|
348 historyDataArr.ResetAndDestroy(); |
|
349 } |
|
350 |
|
351 // --------------------------------------------------------------------------- |
|
352 // IRQSongHistoryEngine::getAllHistoryL |
|
353 // Invoked when when UI request. |
|
354 // Getting the data from SongHistoryDb. |
|
355 // --------------------------------------------------------------------------- |
|
356 |
|
357 void IRQSongHistoryEngine::getAllSongHistoryL(QList<IRQSongInfo *>& aSongHistoryArr) |
|
358 { |
|
359 // clear the array |
|
360 while (!aSongHistoryArr.isEmpty()) |
|
361 { |
|
362 delete aSongHistoryArr.takeFirst(); |
|
363 } |
|
364 |
|
365 int songCount = iSongHistoryDb->CountSongHistoryDb2(); |
|
366 |
|
367 if (songCount == 0) |
|
368 { |
|
369 return; |
|
370 } |
|
371 |
|
372 // get song history list |
|
373 RPointerArray<CIRSongHistoryInfo> historyDataArr; |
|
374 for (int arrCount = 0 ; arrCount < songCount ; arrCount++ ) |
|
375 { |
|
376 CIRSongHistoryInfo *songHistory = CIRSongHistoryInfo::NewL(); |
|
377 CleanupStack::PushL(songHistory); |
|
378 historyDataArr.AppendL(songHistory); |
|
379 CleanupStack::Pop(songHistory); |
|
380 } |
|
381 |
|
382 iSongHistoryDb->GetAllSongHistoryList2L(historyDataArr); |
|
383 |
|
384 // create IRQSongHistoryInfo array and set |
|
385 QString songName; |
|
386 QString artist; |
|
387 QString musicStoreStatus; |
|
388 |
|
389 for (int arrCount = 0; arrCount < songCount; arrCount++) |
|
390 { |
|
391 songName = QString::fromUtf16( |
|
392 historyDataArr[arrCount]->GetSongInfo().Ptr(), |
|
393 historyDataArr[arrCount]->GetSongInfo().Length()); |
|
394 artist = QString::fromUtf16( |
|
395 historyDataArr[arrCount]->GetArtistInfo().Ptr(), |
|
396 historyDataArr[arrCount]->GetArtistInfo().Length()); |
|
397 musicStoreStatus = QString::fromUtf16( |
|
398 historyDataArr[arrCount]->GetChannelMusicStatus().Ptr(), |
|
399 historyDataArr[arrCount]->GetChannelMusicStatus().Length()); |
|
400 IRQSongInfo* irqsong = new IRQSongInfo(); |
|
401 |
|
402 irqsong->setAllInfo(songName, artist, musicStoreStatus); |
|
403 aSongHistoryArr.append(irqsong); |
|
404 } |
|
405 |
|
406 historyDataArr.ResetAndDestroy(); |
|
407 } |
|
408 // --------------------------------------------------------------------------- |
|
409 // IRQSongHistoryEngine::clearAllHistory |
|
410 // Invoked when when UI request. |
|
411 // Clears the SongHistoryDb. |
|
412 // --------------------------------------------------------------------------- |
|
413 |
|
414 EXPORT_C int IRQSongHistoryEngine::clearAllHistory( ) |
|
415 { |
|
416 return iSongHistoryDb->ClearAllSongHistoryFromDb(); |
|
417 } |
|
418 |
|
419 EXPORT_C int IRQSongHistoryEngine::clearAllSongHistory( ) |
|
420 { |
|
421 return iSongHistoryDb->ClearAllSongHistoryFromDb2(); |
|
422 } |
|
423 |
|
424 // --------------------------------------------------------------------------- |
|
425 // IRQSongHistoryEngine::syncHistory |
|
426 // Invoked when when UI request. |
|
427 // Synchronises the Song history DB with the new data in the ISDS. |
|
428 // --------------------------------------------------------------------------- |
|
429 EXPORT_C void IRQSongHistoryEngine::syncHistory(int aChannelId) |
|
430 { |
|
431 TRAPD(err,iSongHistoryDb->SyncSongHistoryDbL(aChannelId)); |
|
432 if (err) |
|
433 { |
|
434 } |
|
435 } |
|
436 |
|
437 // --------------------------------------------------------------------------- |
|
438 // IRQSongHistoryEngine::updateSongHistoryDb |
|
439 // Invoked when when UI request. |
|
440 // Synchronises the Song history DB with the new data in the ISDS. |
|
441 // --------------------------------------------------------------------------- |
|
442 EXPORT_C void IRQSongHistoryEngine::updateSongHistoryDb(int aChannelId, |
|
443 const QString& aChannelName, |
|
444 const QString& aChannelUrl, |
|
445 const QString& aImageUrl, |
|
446 const QString& aMusicFlag) |
|
447 { |
|
448 TInt ret = KErrNone ; |
|
449 TUint16 channelId = aChannelId; // prevent data overflow |
|
450 |
|
451 TRAPD(err,ret = iSongHistoryDb->GetIdPresentInDbL( channelId )); |
|
452 |
|
453 if (err) |
|
454 { |
|
455 return; |
|
456 } |
|
457 |
|
458 if (ret) |
|
459 { |
|
460 TPtrC channelName(reinterpret_cast<const TUint16*>(aChannelName.utf16())); |
|
461 TPtrC channelUrl(reinterpret_cast<const TUint16*>(aChannelUrl.utf16())); |
|
462 TPtrC imageUrl(reinterpret_cast<const TUint16*>(aImageUrl.utf16())); |
|
463 TPtrC musicFlag(reinterpret_cast<const TUint16*>(aMusicFlag.utf16())); |
|
464 TRAP_IGNORE(iSongHistoryDb->UpdateSongHistoryDbL( channelId , |
|
465 channelName, |
|
466 channelUrl, |
|
467 imageUrl, |
|
468 musicFlag)); |
|
469 } |
|
470 } |
|
471 |
|
472 EXPORT_C bool IRQSongHistoryEngine::deleteOneItem(int aIndex) |
|
473 { |
|
474 int retValue = 0; |
|
475 retValue = iSongHistoryDb->DeleteOneHistory(aIndex); |
|
476 if( KErrNone != retValue ) |
|
477 { |
|
478 return false; |
|
479 } |
|
480 |
|
481 return true; |
|
482 } |