1 /* |
|
2 * Copyright (c) 2006-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: Implementation of the songhistory database |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 /* --------------------------------------------------------------------------- |
|
20 * Version history: |
|
21 * Template version: |
|
22 * <ccm_history> |
|
23 * |
|
24 * |
|
25 * Version: 3, Thu Apr 14 12:00:00 2008 by Rohit |
|
26 * Ref: |
|
27 * Pc lint fixes |
|
28 * |
|
29 * Version: 2, Thu Apr 10 20:00:00 2008 by Rohit |
|
30 * Ref: |
|
31 * Implemented SongHistory changes for channelwise songs |
|
32 * |
|
33 * </ccm_history> |
|
34 * ============================================================================ |
|
35 */ |
|
36 |
|
37 #include <bautils.h> |
|
38 #include <badesca.h> // CDesCArrayFlat |
|
39 #include <s32file.h> // CFileStore & CPermanentFileStore |
|
40 #include <bautils.h> // file helpers |
|
41 #include <eikenv.h> |
|
42 |
|
43 #include "irsonghistorydb.h" |
|
44 #include "irsonghistoryinfo.h" |
|
45 #include "irdebug.h" |
|
46 #include "irsettings.h" |
|
47 |
|
48 |
|
49 |
|
50 _LIT( KSongHistoryDBTable, "ChannelHistoryTable" ); |
|
51 _LIT( KSongHistoryDBTable2, "SongHistoryTable" ); |
|
52 _LIT( KSongHistoryDBSongNameColumn, "SongName" ); |
|
53 _LIT( KSongHistoryDBArtistNameColumn, "ArtistName" ); |
|
54 _LIT( KSongHistoryDBChannelNameColumn, "ChannelName" ); |
|
55 _LIT( KSongHistoryDBChannelUrlColumn, "ChannelUrl" ); |
|
56 _LIT( KSongHistoryDBChannelTypeColumn, "ChannelType" ); |
|
57 _LIT( KSongHistoryDBChannelIdColumn, "ChannelId" ); |
|
58 _LIT( KSongHistoryDBBitrateColumn, "Bitrate" ); |
|
59 _LIT( KSongHistoryDBChannelDescColumn, "ChannelDescription" ); |
|
60 _LIT( KSongHistoryDBImageUrlColumn, "ImageUrl" ); |
|
61 _LIT( KSongHistoryDBGenreNameColumn, "GenreName" ); |
|
62 _LIT( KSongHistoryDBCountryNameColumn, "CountryName" ); |
|
63 _LIT( KSongHistoryDBLanguageNameColumn, "LanguageName" ); |
|
64 _LIT( KSongHistoryDBMusicStatusColumn, "MusicStoreStatus" ); |
|
65 |
|
66 _LIT(KSongHistoryDbFile,"songhistoryDb.db"); |
|
67 _LIT(KNo , "No") ; |
|
68 |
|
69 const TInt KMaxSize = 255; |
|
70 |
|
71 const TInt KMaxColumnLength = 255; |
|
72 TBool CIRSongHistoryDb::CompareChannelInfos(const CIRChannelInfo& aFirst, |
|
73 const CIRChannelInfo& aSecond) |
|
74 { |
|
75 return ( aFirst.iChannelName == aSecond.iChannelName && |
|
76 aFirst.iChannelUrl == aSecond.iChannelUrl && |
|
77 aFirst.iChannelType == aSecond.iChannelType); |
|
78 } |
|
79 |
|
80 |
|
81 |
|
82 // ======== MEMBER FUNCTIONS ======== |
|
83 |
|
84 // --------------------------------------------------------------------------- |
|
85 // Function : NewL() |
|
86 // two phased construction |
|
87 // --------------------------------------------------------------------------- |
|
88 // |
|
89 CIRSongHistoryDb* CIRSongHistoryDb::NewL() |
|
90 { |
|
91 IRLOG_DEBUG( "CIRSongHistoryDb::NewL" ); |
|
92 CIRSongHistoryDb* self=CIRSongHistoryDb::NewLC(); |
|
93 CleanupStack::Pop(self); |
|
94 IRLOG_DEBUG( "CIRSongHistoryDb::NewL - Exiting." ); |
|
95 return self; |
|
96 } |
|
97 |
|
98 |
|
99 // --------------------------------------------------------------------------- |
|
100 // Function : NewLC() |
|
101 // Two phased construction |
|
102 // --------------------------------------------------------------------------- |
|
103 // |
|
104 CIRSongHistoryDb* CIRSongHistoryDb::NewLC() |
|
105 { |
|
106 IRLOG_DEBUG( "CIRSongHistoryDb::NewLC" ); |
|
107 CIRSongHistoryDb *self=new(ELeave)CIRSongHistoryDb; |
|
108 CleanupStack::PushL(self); |
|
109 self->ConstructL(); |
|
110 IRLOG_DEBUG( "CIRSongHistoryDb::NewLC - Exiting." ); |
|
111 return self; |
|
112 } |
|
113 |
|
114 |
|
115 // --------------------------------------------------------------------------- |
|
116 // CIRSongHistoryDb::~CIRSongHistoryDb() |
|
117 // default destructor |
|
118 // --------------------------------------------------------------------------- |
|
119 // |
|
120 CIRSongHistoryDb::~CIRSongHistoryDb() |
|
121 { |
|
122 IRLOG_DEBUG( "CIRSongHistoryDb::~CIRSongHistoryDb" ); |
|
123 |
|
124 CloseSongHistoryDb(); |
|
125 iFsSession.Close(); |
|
126 IRLOG_DEBUG( "CIRSongHistoryDb::~CIRSongHistoryDb - Exiting." ); |
|
127 } |
|
128 |
|
129 // --------------------------------------------------------------------------- |
|
130 // CIRSongHistoryDb::CreateDbCondition() |
|
131 // Creates both the dbms files conditionally(only if not yet created) |
|
132 // calls CreateSongHistoryDb() |
|
133 // --------------------------------------------------------------------------- |
|
134 // |
|
135 void CIRSongHistoryDb::CreateDbCondition(const TFileName& aSongHistoryDbFile) |
|
136 { |
|
137 IRLOG_DEBUG( "CIRSongHistoryDb::CreateDbCondition" ); |
|
138 |
|
139 |
|
140 if( !BaflUtils::FileExists(iFsSession, aSongHistoryDbFile) ) |
|
141 { |
|
142 TInt error = CreateSongHistoryDb(aSongHistoryDbFile); |
|
143 if( error ) |
|
144 { |
|
145 IRLOG_DEBUG( "CIRSongHistoryDb::CreateDbCondition - Exiting (1)." ); |
|
146 |
|
147 } |
|
148 } |
|
149 IRLOG_DEBUG( "CIRSongHistoryDb::CreateDbCondition - Exiting (2)." ); |
|
150 |
|
151 } |
|
152 |
|
153 // --------------------------------------------------------------------------- |
|
154 // CIRSongHistoryDb:AddToSongHistoryDbL() |
|
155 // adds the session log entry into data base |
|
156 // Returns ETure if songHistory count exceeds 30, else EFalse |
|
157 // --------------------------------------------------------------------------- |
|
158 // |
|
159 TBool CIRSongHistoryDb::AddToSongHistoryDbL(const TDesC& aSongName, |
|
160 const TDesC& aArtistName, |
|
161 const TDesC& aChannelName, |
|
162 const TDesC& aChannelUrl, |
|
163 RBuf& aDelSongName, |
|
164 RBuf& aDelArtistName, |
|
165 RBuf& aDelChannelName, |
|
166 RBuf& aDelChannelUrl, |
|
167 TInt aChannelType, |
|
168 TInt aChannelId, |
|
169 TInt aBitrate, |
|
170 const TDesC& aChannelDesc, |
|
171 const TDesC& aImageUrl, |
|
172 const TDesC& aGenreName, |
|
173 const TDesC& aCountryName, |
|
174 const TDesC& aLanguageName, |
|
175 const TDesC& aMusicFlag |
|
176 ) |
|
177 { |
|
178 IRLOG_DEBUG( "CIRSongHistoryDb::AddSongHistoryStartL" ); |
|
179 |
|
180 TBool bRetval = EFalse; |
|
181 TInt error= 0; |
|
182 |
|
183 iSongHistoryTable.Reset(); |
|
184 |
|
185 //if song history entries are greater than or equal to 30 |
|
186 if( iSongHistoryTable.CountL() >= KMaxNoChannelHistoryDbEntries ) |
|
187 { |
|
188 //first row is selected |
|
189 iSongHistoryTable.FirstL(); |
|
190 |
|
191 //the current row is selected |
|
192 iSongHistoryTable.GetL(); |
|
193 |
|
194 //delete that entry |
|
195 CDbColSet* columns = iSongHistoryTable.ColSetL(); |
|
196 TInt songColumn = columns->ColNo( KSongHistoryDBSongNameColumn ); |
|
197 TInt artistColumn = columns->ColNo( KSongHistoryDBArtistNameColumn ); |
|
198 TInt channelColumn = columns->ColNo( KSongHistoryDBChannelNameColumn ); |
|
199 TInt channelUrlColumn = columns->ColNo( KSongHistoryDBChannelUrlColumn ); |
|
200 |
|
201 delete columns; |
|
202 columns = NULL; |
|
203 |
|
204 aDelSongName.Create(iSongHistoryTable.ColDes( songColumn )); |
|
205 aDelArtistName.Create(iSongHistoryTable.ColDes( artistColumn )); |
|
206 aDelChannelName.Create(iSongHistoryTable.ColDes( channelColumn )); |
|
207 aDelChannelUrl.Create(iSongHistoryTable.ColDes( channelUrlColumn )); |
|
208 |
|
209 iSongHistoryTable.DeleteL(); |
|
210 Compact(); |
|
211 |
|
212 bRetval = ETrue; |
|
213 } |
|
214 |
|
215 CDbColSet* columns = iSongHistoryTable.ColSetL(); |
|
216 CleanupStack::PushL(columns); |
|
217 |
|
218 const TPtrC &songName = aSongName.Left(KIRDbMaxStrLen); |
|
219 const TPtrC &artistName = aArtistName.Left(KIRDbMaxStrLen); |
|
220 const TPtrC &channelName = aChannelName.Left(KIRDbMaxStrLen); |
|
221 const TPtrC &channelUrl = aChannelUrl.Left(KIRDbMaxStrLen); |
|
222 const TPtrC &channelDesc = aChannelDesc.Left(KIRDbMaxStrLen); |
|
223 const TPtrC &imageUrl = aImageUrl.Left(KIRDbMaxStrLen); |
|
224 const TPtrC &genreName = aGenreName.Left(KIRDbMaxStrLen); |
|
225 const TPtrC &countryName = aCountryName.Left(KIRDbMaxStrLen); |
|
226 const TPtrC &languageName = aLanguageName.Left(KIRDbMaxStrLen); |
|
227 |
|
228 TInt songLen = aSongName.Length(); |
|
229 TInt artistLen = aArtistName.Length(); |
|
230 if( songLen + artistLen > KMaxSize ) |
|
231 { |
|
232 IRLOG_DEBUG3( "CIRSongHistoryDb::AddSongHistoryStartL - LONG METADATA %d, %d", songLen, artistLen ); |
|
233 } |
|
234 |
|
235 TRAP(error,//trap start |
|
236 |
|
237 iSongHistoryTable.InsertL(); |
|
238 iSongHistoryTable.SetColL(columns->ColNo( KSongHistoryDBSongNameColumn ), songName); |
|
239 iSongHistoryTable.SetColL(columns->ColNo( KSongHistoryDBArtistNameColumn ), artistName); |
|
240 iSongHistoryTable.SetColL(columns->ColNo( KSongHistoryDBChannelNameColumn ), channelName); |
|
241 iSongHistoryTable.SetColL(columns->ColNo( KSongHistoryDBChannelUrlColumn ), channelUrl); |
|
242 iSongHistoryTable.SetColL(columns->ColNo( KSongHistoryDBChannelTypeColumn ), aChannelType); |
|
243 iSongHistoryTable.SetColL(columns->ColNo( KSongHistoryDBChannelIdColumn ), aChannelId); |
|
244 iSongHistoryTable.SetColL(columns->ColNo( KSongHistoryDBBitrateColumn ), aBitrate); |
|
245 iSongHistoryTable.SetColL(columns->ColNo( KSongHistoryDBChannelDescColumn ), channelDesc); |
|
246 iSongHistoryTable.SetColL(columns->ColNo( KSongHistoryDBImageUrlColumn ), imageUrl); |
|
247 iSongHistoryTable.SetColL(columns->ColNo( KSongHistoryDBGenreNameColumn ), genreName); |
|
248 iSongHistoryTable.SetColL(columns->ColNo( KSongHistoryDBCountryNameColumn ), countryName); |
|
249 iSongHistoryTable.SetColL(columns->ColNo( KSongHistoryDBLanguageNameColumn ), languageName); |
|
250 iSongHistoryTable.SetColL(columns->ColNo( KSongHistoryDBMusicStatusColumn ), aMusicFlag); |
|
251 iSongHistoryTable.PutL(); |
|
252 ); |
|
253 |
|
254 CleanupStack::PopAndDestroy(columns); |
|
255 if( error!=KErrNone ) |
|
256 { |
|
257 User::LeaveIfError(error); |
|
258 } |
|
259 |
|
260 iSongHistoryTable.Reset(); |
|
261 IRLOG_DEBUG( "CIRSongHistoryDb::AddSongHistoryStartL - Exiting." ); |
|
262 |
|
263 return bRetval; |
|
264 } |
|
265 |
|
266 // --------------------------------------------------------------------------- |
|
267 // CIRSongHistoryDb:AddToSongHistoryDb2L() |
|
268 // adds the history song into the db |
|
269 // Returns ETure if songHistory count exceeds 100, else EFalse |
|
270 // --------------------------------------------------------------------------- |
|
271 |
|
272 TBool CIRSongHistoryDb::AddToSongHistoryDb2L( const TDesC& aSongName, |
|
273 const TDesC& aArtistName, |
|
274 const TDesC& aChannelName, |
|
275 const TDesC& aMusicFlag) |
|
276 { |
|
277 IRLOG_DEBUG( "CIRSongHistoryDb::AddToSongHistoryDb2L" ); |
|
278 |
|
279 TBool bRetval = EFalse; |
|
280 TInt error= 0; |
|
281 TInt songCompareFlag = 0; |
|
282 TInt artistCompareFlag = 0; |
|
283 |
|
284 |
|
285 iSongHistoryTable2.Reset(); |
|
286 |
|
287 CDbColSet* columns = iSongHistoryTable2.ColSetL(); |
|
288 CleanupStack::PushL(columns); |
|
289 |
|
290 /* the following is to judge wether the song is already in the db */ |
|
291 if ( iSongHistoryTable2.CountL() >= 1 ) |
|
292 { |
|
293 TInt songNameColumn = columns->ColNo( KSongHistoryDBSongNameColumn ); |
|
294 TInt artistNameColumn = columns->ColNo( KSongHistoryDBArtistNameColumn ); |
|
295 |
|
296 for ( iSongHistoryTable2.LastL(); iSongHistoryTable2.AtRow(); iSongHistoryTable2.PreviousL() ) |
|
297 { |
|
298 iSongHistoryTable2.GetL(); |
|
299 RBuf songName; |
|
300 RBuf artistName; |
|
301 |
|
302 songName.Create(iSongHistoryTable2.ColDes( songNameColumn )); |
|
303 songName.CleanupClosePushL(); |
|
304 |
|
305 artistName.Create(iSongHistoryTable2.ColDes( artistNameColumn )); |
|
306 artistName.CleanupClosePushL(); |
|
307 |
|
308 songCompareFlag = (songName).Compare(aSongName); |
|
309 artistCompareFlag = (artistName).Compare(aArtistName); |
|
310 |
|
311 CleanupStack::PopAndDestroy(&artistName); |
|
312 CleanupStack::PopAndDestroy(&songName); |
|
313 |
|
314 if( 0 == songCompareFlag && 0 == artistCompareFlag ) |
|
315 { |
|
316 CleanupStack::PopAndDestroy(columns); |
|
317 iSongHistoryTable2.Reset(); |
|
318 return bRetval; |
|
319 } |
|
320 } |
|
321 } |
|
322 /* end */ |
|
323 |
|
324 //if song history entries are greater than or equal to 100 |
|
325 if( iSongHistoryTable2.CountL() >= KMaxNoSongHistoryDbEntries ) |
|
326 { |
|
327 //first row is selected |
|
328 iSongHistoryTable2.FirstL(); |
|
329 //the current row is selected |
|
330 iSongHistoryTable2.GetL(); |
|
331 //delete the current row |
|
332 iSongHistoryTable2.DeleteL(); |
|
333 Compact(); |
|
334 bRetval = ETrue; |
|
335 } |
|
336 |
|
337 const TPtrC &songName = aSongName.Left(KIRDbMaxStrLen); |
|
338 const TPtrC &artistName = aArtistName.Left(KIRDbMaxStrLen); |
|
339 const TPtrC &channelName = aChannelName.Left(KIRDbMaxStrLen); |
|
340 const TPtrC &musicFlag = aMusicFlag.Left(KIRDbMaxStrLen); |
|
341 |
|
342 |
|
343 TInt songLen = aSongName.Length(); |
|
344 TInt artistLen = aArtistName.Length(); |
|
345 if( songLen + artistLen > KMaxSize || aChannelName.Length() > KMaxSize) |
|
346 { |
|
347 IRLOG_DEBUG3( "CIRSongHistoryDb::AddToSongHistoryDb2L - too long song info: %d or channel info: %d", songLen+artistLen, aChannelName.Length() ); |
|
348 } |
|
349 |
|
350 TRAP(error,//trap start |
|
351 |
|
352 iSongHistoryTable2.InsertL(); |
|
353 iSongHistoryTable2.SetColL(columns->ColNo( KSongHistoryDBSongNameColumn ), songName); |
|
354 iSongHistoryTable2.SetColL(columns->ColNo( KSongHistoryDBArtistNameColumn ), artistName); |
|
355 iSongHistoryTable2.SetColL(columns->ColNo( KSongHistoryDBChannelNameColumn ), channelName); |
|
356 iSongHistoryTable2.SetColL(columns->ColNo( KSongHistoryDBMusicStatusColumn ), musicFlag); |
|
357 iSongHistoryTable2.PutL(); |
|
358 ); |
|
359 |
|
360 CleanupStack::PopAndDestroy(columns); |
|
361 if( error!=KErrNone ) |
|
362 { |
|
363 User::LeaveIfError(error); |
|
364 } |
|
365 |
|
366 iSongHistoryTable2.Reset(); |
|
367 IRLOG_DEBUG( "CIRSongHistoryDb::AddSongHistoryStartL - Exiting." ); |
|
368 |
|
369 return bRetval; |
|
370 } |
|
371 |
|
372 // --------------------------------------------------------------------------- |
|
373 // CIRSongHistoryDb::GetAllSongHistoryListL() |
|
374 // gets all the song history entries into an array |
|
375 // --------------------------------------------------------------------------- |
|
376 // |
|
377 void CIRSongHistoryDb::GetAllSongHistoryListL(RPointerArray<CIRSongHistoryInfo>& aHistoryDataArr) |
|
378 { |
|
379 IRLOG_DEBUG( "CIRSongHistoryDb::GetAllSongHistoryListL" ); |
|
380 |
|
381 if(iSongHistoryTable.CountL() < 1) |
|
382 { |
|
383 return; |
|
384 } |
|
385 |
|
386 CDbColSet* columns = iSongHistoryTable.ColSetL(); |
|
387 TInt songColumn = columns->ColNo( KSongHistoryDBSongNameColumn ); |
|
388 TInt artistColumn = columns->ColNo( KSongHistoryDBArtistNameColumn ); |
|
389 TInt channelColumn = columns->ColNo( KSongHistoryDBChannelNameColumn ); |
|
390 TInt channelUrlColumn = columns->ColNo( KSongHistoryDBChannelUrlColumn ); |
|
391 TInt channelTypeColumn = columns->ColNo( KSongHistoryDBChannelTypeColumn ); |
|
392 TInt channelIdColumn = columns->ColNo( KSongHistoryDBChannelIdColumn ); |
|
393 TInt bitrateColumn = columns->ColNo( KSongHistoryDBBitrateColumn ); |
|
394 TInt channelDescColumn = columns->ColNo( KSongHistoryDBChannelDescColumn ); |
|
395 TInt imageUrlColumn = columns->ColNo( KSongHistoryDBImageUrlColumn ); |
|
396 TInt genreNameColumn = columns->ColNo( KSongHistoryDBGenreNameColumn ); |
|
397 TInt countryNameColumn = columns->ColNo( KSongHistoryDBCountryNameColumn ); |
|
398 TInt languageNameColumn = columns->ColNo( KSongHistoryDBLanguageNameColumn ); |
|
399 TInt musicStatusColumn = columns->ColNo( KSongHistoryDBMusicStatusColumn ); |
|
400 |
|
401 delete columns; |
|
402 columns = NULL; |
|
403 |
|
404 TInt song = 0; |
|
405 |
|
406 |
|
407 for ( iSongHistoryTable.LastL(); iSongHistoryTable.AtRow(); iSongHistoryTable.PreviousL() ) |
|
408 { |
|
409 iSongHistoryTable.GetL(); |
|
410 |
|
411 RBuf songName; |
|
412 RBuf artistName; |
|
413 RBuf channelName; |
|
414 RBuf channelUrl; |
|
415 TInt channelType; |
|
416 TInt channelId; |
|
417 TInt bitrate; |
|
418 RBuf channelDesc; |
|
419 RBuf imageUrl; |
|
420 RBuf genreName; |
|
421 RBuf countryName; |
|
422 RBuf languageName; |
|
423 RBuf channelMusicStatus; |
|
424 |
|
425 songName.CreateL(iSongHistoryTable.ColDes( songColumn )); |
|
426 songName.CleanupClosePushL(); |
|
427 |
|
428 artistName.CreateL(iSongHistoryTable.ColDes( artistColumn )); |
|
429 artistName.CleanupClosePushL(); |
|
430 |
|
431 channelName.CreateL(iSongHistoryTable.ColDes( channelColumn )); |
|
432 channelName.CleanupClosePushL(); |
|
433 |
|
434 channelUrl.CreateL(iSongHistoryTable.ColDes( channelUrlColumn )); |
|
435 channelUrl.CleanupClosePushL(); |
|
436 |
|
437 channelType=iSongHistoryTable.ColUint8( channelTypeColumn ); |
|
438 |
|
439 channelId=iSongHistoryTable.ColUint16( channelIdColumn ); |
|
440 |
|
441 bitrate=iSongHistoryTable.ColUint16( bitrateColumn ); |
|
442 |
|
443 channelDesc.CreateL(iSongHistoryTable.ColDes( channelDescColumn )); |
|
444 channelDesc.CleanupClosePushL(); |
|
445 |
|
446 imageUrl.CreateL(iSongHistoryTable.ColDes( imageUrlColumn )); |
|
447 imageUrl.CleanupClosePushL(); |
|
448 |
|
449 genreName.CreateL(iSongHistoryTable.ColDes( genreNameColumn )); |
|
450 genreName.CleanupClosePushL(); |
|
451 |
|
452 countryName.CreateL(iSongHistoryTable.ColDes( countryNameColumn )); |
|
453 countryName.CleanupClosePushL(); |
|
454 |
|
455 languageName.CreateL(iSongHistoryTable.ColDes( languageNameColumn )); |
|
456 languageName.CleanupClosePushL(); |
|
457 |
|
458 channelMusicStatus.CreateL(iSongHistoryTable.ColDes( musicStatusColumn )); |
|
459 channelMusicStatus.CleanupClosePushL(); |
|
460 |
|
461 aHistoryDataArr[song]->SetHistoryInfo(songName, artistName, channelUrl, |
|
462 channelName,channelType,channelId,bitrate,channelDesc , |
|
463 imageUrl, genreName, countryName, languageName, channelMusicStatus); |
|
464 ++song; |
|
465 CleanupStack::PopAndDestroy(&channelMusicStatus); |
|
466 CleanupStack::PopAndDestroy(&languageName); |
|
467 CleanupStack::PopAndDestroy(&countryName); |
|
468 CleanupStack::PopAndDestroy(&genreName); |
|
469 CleanupStack::PopAndDestroy(&imageUrl); |
|
470 CleanupStack::PopAndDestroy(&channelDesc); |
|
471 CleanupStack::PopAndDestroy(&channelUrl); |
|
472 CleanupStack::PopAndDestroy(&channelName); |
|
473 CleanupStack::PopAndDestroy(&artistName); |
|
474 CleanupStack::PopAndDestroy(&songName); |
|
475 } |
|
476 |
|
477 |
|
478 IRLOG_DEBUG( "CIRSongHistoryDb::GetAllSongHistoryListL - Exiting." ); |
|
479 } |
|
480 |
|
481 |
|
482 // --------------------------------------------------------------------------- |
|
483 // CIRSongHistoryDb::GetAllSongHistoryList2L() |
|
484 // gets all the song history entries into an array |
|
485 // --------------------------------------------------------------------------- |
|
486 // |
|
487 void CIRSongHistoryDb::GetAllSongHistoryList2L(RPointerArray<CIRSongHistoryInfo>& aSongEntries) |
|
488 { |
|
489 IRLOG_DEBUG( "CIRSongHistoryDb::GetAllSongHistoryList2L" ); |
|
490 |
|
491 if(iSongHistoryTable2.CountL() < 1) |
|
492 { |
|
493 return; |
|
494 } |
|
495 |
|
496 CDbColSet* columns = iSongHistoryTable2.ColSetL(); |
|
497 TInt songColumn = columns->ColNo( KSongHistoryDBSongNameColumn ); |
|
498 TInt artistColumn = columns->ColNo( KSongHistoryDBArtistNameColumn ); |
|
499 TInt channelNameColumn = columns->ColNo( KSongHistoryDBChannelNameColumn ); |
|
500 TInt musicStatusColumn = columns->ColNo( KSongHistoryDBMusicStatusColumn ); |
|
501 |
|
502 delete columns; |
|
503 columns = NULL; |
|
504 |
|
505 TInt song = 0; |
|
506 |
|
507 for ( iSongHistoryTable2.LastL(); iSongHistoryTable2.AtRow(); iSongHistoryTable2.PreviousL() ) |
|
508 { |
|
509 iSongHistoryTable2.GetL(); |
|
510 |
|
511 RBuf songName; |
|
512 RBuf artistInfo, channelName; |
|
513 RBuf musicStatus; |
|
514 |
|
515 songName.Create(iSongHistoryTable2.ColDes( songColumn )); |
|
516 songName.CleanupClosePushL(); |
|
517 |
|
518 artistInfo.Create(iSongHistoryTable2.ColDes( artistColumn )); |
|
519 artistInfo.CleanupClosePushL(); |
|
520 |
|
521 channelName.Create(iSongHistoryTable2.ColDes( channelNameColumn )); |
|
522 channelName.CleanupClosePushL(); |
|
523 |
|
524 musicStatus.Create(iSongHistoryTable2.ColDes(musicStatusColumn)); |
|
525 musicStatus.CleanupClosePushL(); |
|
526 |
|
527 aSongEntries[song]->SetSongName(songName); |
|
528 aSongEntries[song]->SetArtist(artistInfo); |
|
529 aSongEntries[song]->SetChannelName(channelName); |
|
530 aSongEntries[song]->SetChannelMusicStatus(musicStatus); |
|
531 ++song; |
|
532 |
|
533 CleanupStack::PopAndDestroy(&musicStatus); |
|
534 CleanupStack::PopAndDestroy(&channelName); |
|
535 CleanupStack::PopAndDestroy(&artistInfo); |
|
536 CleanupStack::PopAndDestroy(&songName); |
|
537 } |
|
538 |
|
539 IRLOG_DEBUG( "CIRSongHistoryDb::GetAllSongHistoryListL - Exiting." ); |
|
540 } |
|
541 |
|
542 // --------------------------------------------------------------------------- |
|
543 // Function : ClearAllSongHistoryFromDb |
|
544 // delete all the entries from the database. |
|
545 // --------------------------------------------------------------------------- |
|
546 // |
|
547 TInt CIRSongHistoryDb::ClearAllSongHistoryFromDb(/*RPointerArray<CIRSongHistoryInfo>& aSongHistoryInfoArr*/) |
|
548 { |
|
549 |
|
550 TInt error = KErrNone; |
|
551 |
|
552 IRLOG_DEBUG( "CIRSongHistoryDb::ClearAllSongHistoryFromDb - Entering" ); |
|
553 TRAP(error, iSongHistoryTable.FirstL()); |
|
554 if(error != KErrNone) |
|
555 { |
|
556 return error; |
|
557 } |
|
558 |
|
559 while (iSongHistoryTable.AtRow()) |
|
560 { |
|
561 TRAPD(error, |
|
562 iSongHistoryTable.GetL(); |
|
563 iSongHistoryTable.DeleteL(); |
|
564 iSongHistoryTable.NextL();); |
|
565 if(error) |
|
566 { |
|
567 Compact(); |
|
568 return error; |
|
569 } |
|
570 } |
|
571 |
|
572 Compact(); |
|
573 IRLOG_DEBUG( "CIRSongHistoryDb::ClearAllSongHistoryFromDb - Exiting." ); |
|
574 return KErrNone; |
|
575 |
|
576 } |
|
577 |
|
578 TInt CIRSongHistoryDb::DeleteOneHistory(TInt aIndex) |
|
579 { |
|
580 IRLOG_DEBUG( "CIRSongHistoryDb::DeleteOneHistory - Entering" ); |
|
581 |
|
582 TInt retValue = 0; |
|
583 TRAPD(error,(retValue = DeleteOneHistoryL(aIndex))); |
|
584 |
|
585 if( KErrNone != error ) |
|
586 { |
|
587 return error; |
|
588 } |
|
589 |
|
590 if( KErrNone != retValue) |
|
591 { |
|
592 return retValue; |
|
593 } |
|
594 IRLOG_DEBUG( "CIRSongHistoryDb::DeleteOneHistory - exiting" ); |
|
595 return KErrNone; |
|
596 } |
|
597 |
|
598 TInt CIRSongHistoryDb::DeleteOneHistoryL(TInt aIndex) |
|
599 { |
|
600 IRLOG_DEBUG( "CIRSongHistoryDb::DeleteOneHistoryL - Entering" ); |
|
601 TInt totalCount = iSongHistoryTable.CountL(); |
|
602 if (aIndex < 0 || aIndex >= totalCount) |
|
603 { |
|
604 return KErrArgument; |
|
605 } |
|
606 |
|
607 iSongHistoryTable.LastL(); |
|
608 TInt tempIndex = 0; |
|
609 while (tempIndex < aIndex) |
|
610 { |
|
611 TRAPD(error,iSongHistoryTable.PreviousL()); |
|
612 if (KErrNone != error) |
|
613 { |
|
614 Compact(); |
|
615 return error; |
|
616 } |
|
617 tempIndex++; |
|
618 } |
|
619 |
|
620 iSongHistoryTable.GetL(); |
|
621 iSongHistoryTable.DeleteL(); |
|
622 IRLOG_DEBUG( "CIRSongHistoryDb::DeleteOneHistoryL - exiting" ); |
|
623 return KErrNone; |
|
624 } |
|
625 |
|
626 TInt CIRSongHistoryDb::DeleteOneSongHistory(TInt aIndex) |
|
627 { |
|
628 IRLOG_DEBUG( "CIRSongHistoryDb::DeleteOneSongHistory - Entering" ); |
|
629 |
|
630 TInt retValue = 0; |
|
631 TRAPD(error,(retValue = DeleteOneSongHistoryL(aIndex))); |
|
632 |
|
633 if( KErrNone != error ) |
|
634 { |
|
635 return error; |
|
636 } |
|
637 |
|
638 if( KErrNone != retValue) |
|
639 { |
|
640 return retValue; |
|
641 } |
|
642 IRLOG_DEBUG( "CIRSongHistoryDb::DeleteOneSongHistory - exiting" ); |
|
643 return KErrNone; |
|
644 } |
|
645 |
|
646 TInt CIRSongHistoryDb::DeleteOneSongHistoryL(TInt aIndex) |
|
647 { |
|
648 IRLOG_DEBUG( "CIRSongHistoryDb::DeleteOneSongHistoryL - Entering" ); |
|
649 TInt totalCount = iSongHistoryTable2.CountL(); |
|
650 if (aIndex < 0 || aIndex >= totalCount) |
|
651 { |
|
652 return KErrArgument; |
|
653 } |
|
654 |
|
655 iSongHistoryTable2.LastL(); |
|
656 TInt tempIndex = 0; |
|
657 while (tempIndex < aIndex) |
|
658 { |
|
659 TRAPD(error,iSongHistoryTable2.PreviousL()); |
|
660 if (KErrNone != error) |
|
661 { |
|
662 Compact(); |
|
663 return error; |
|
664 } |
|
665 tempIndex++; |
|
666 } |
|
667 |
|
668 iSongHistoryTable2.GetL(); |
|
669 iSongHistoryTable2.DeleteL(); |
|
670 IRLOG_DEBUG( "CIRSongHistoryDb::DeleteOneSongHistoryL - exiting" ); |
|
671 return KErrNone; |
|
672 } |
|
673 |
|
674 // --------------------------------------------------------------------------- |
|
675 // Function : ClearAllSongHistoryFromDb2 |
|
676 // delete all the entries from the database. |
|
677 // --------------------------------------------------------------------------- |
|
678 // |
|
679 TInt CIRSongHistoryDb::ClearAllSongHistoryFromDb2() |
|
680 { |
|
681 |
|
682 TInt error = KErrNone; |
|
683 |
|
684 IRLOG_DEBUG( "CIRSongHistoryDb::ClearAllSongHistoryFromDb2 - Entering" ); |
|
685 TRAP(error, iSongHistoryTable2.FirstL()); |
|
686 if(error != KErrNone) |
|
687 { |
|
688 return error; |
|
689 } |
|
690 |
|
691 while (iSongHistoryTable2.AtRow()) |
|
692 { |
|
693 TRAPD(error, |
|
694 iSongHistoryTable2.GetL(); |
|
695 iSongHistoryTable2.DeleteL(); |
|
696 iSongHistoryTable2.NextL();); |
|
697 if(error) |
|
698 { |
|
699 Compact(); |
|
700 return error; |
|
701 } |
|
702 |
|
703 } |
|
704 Compact(); |
|
705 IRLOG_DEBUG( "CIRSongHistoryDb::ClearAllSongHistoryFromDb - Exiting." ); |
|
706 return KErrNone; |
|
707 |
|
708 } |
|
709 |
|
710 // --------------------------------------------------------------------------- |
|
711 // CIRSongHistoryDb::ConstructL() |
|
712 // Standard 2nd phase construction |
|
713 // --------------------------------------------------------------------------- |
|
714 // |
|
715 void CIRSongHistoryDb::ConstructL() |
|
716 { |
|
717 IRLOG_DEBUG( "CIRSongHistoryDb::ConstructL" ); |
|
718 User::LeaveIfError(iFsSession.Connect()); |
|
719 |
|
720 CIRSettings* settings = CIRSettings::OpenL(); |
|
721 |
|
722 TFileName songHistoryDbFile = settings->PrivatePath(); |
|
723 songHistoryDbFile.Append(KSongHistoryDbFile); |
|
724 |
|
725 CreateDbCondition(songHistoryDbFile); |
|
726 OpenSongHistoryDbL(songHistoryDbFile); |
|
727 |
|
728 settings->Close(); |
|
729 |
|
730 IRLOG_DEBUG( "CIRSongHistoryDb::ConstructL- Exiting." ); |
|
731 } |
|
732 |
|
733 // --------------------------------------------------------------------------- |
|
734 // CIRSongHistoryDb::CloseSongHistoryDb() |
|
735 // Closes the database |
|
736 // --------------------------------------------------------------------------- |
|
737 // |
|
738 void CIRSongHistoryDb::CloseSongHistoryDb() |
|
739 { |
|
740 IRLOG_DEBUG( "CIRSongHistoryDb::CloseSongHistoryDb" ); |
|
741 iSongHistoryTable.Close(); |
|
742 iSongHistoryTable2.Close(); |
|
743 Close(); |
|
744 IRLOG_DEBUG( "CIRSongHistoryDb::CloseSongHistoryDb - Exiting." ); |
|
745 } |
|
746 |
|
747 |
|
748 /** |
|
749 * Function : CreateSongHistoryTablesL() |
|
750 * creates songhistory table with three columns |
|
751 * log data |
|
752 * --------------------------------------------------------------------------- |
|
753 * SongHistoryTable |
|
754 *--------------------------- |
|
755 *| SongName | ArtistName | ChannelName | ChannelUrl | ChannelType | ChannelId | Bitrate | ChannelDesc | ImageUrl | GenreName | CountryName | LanguageName | MusicStatus |
|
756 *--------------------------- |
|
757 *|EDbColText| EDbColText | EDbColText | EDbColText | EDbColUint8 | EDbColUint16 | EDbColUint16 | EDbColText | EDbColText | EDbColText | EDbColText | EDbColText | EDbColText |
|
758 *---------------------------------------------------------------------------- |
|
759 */ |
|
760 void CIRSongHistoryDb::CreateSongHistoryTablesL() |
|
761 { |
|
762 IRLOG_DEBUG( "CIRSongHistoryDb::CreateSongHistoryTablesL" ); |
|
763 CDbColSet* columns = CDbColSet::NewLC(); |
|
764 |
|
765 TRAPD( error, |
|
766 columns->AddL( TDbCol( KSongHistoryDBSongNameColumn, EDbColText, KMaxColumnLength ) ); |
|
767 columns->AddL( TDbCol( KSongHistoryDBArtistNameColumn, EDbColText, KMaxColumnLength) ); |
|
768 columns->AddL( TDbCol( KSongHistoryDBChannelNameColumn, EDbColText, KMaxColumnLength ) ); |
|
769 columns->AddL( TDbCol( KSongHistoryDBChannelUrlColumn, EDbColText, KMaxColumnLength ) ); |
|
770 columns->AddL( TDbCol( KSongHistoryDBChannelTypeColumn, EDbColUint8 ) ); |
|
771 columns->AddL( TDbCol( KSongHistoryDBChannelIdColumn, EDbColUint16 ) ); |
|
772 columns->AddL( TDbCol( KSongHistoryDBBitrateColumn, EDbColUint16 ) ); |
|
773 columns->AddL( TDbCol( KSongHistoryDBChannelDescColumn, EDbColText, KMaxColumnLength ) ); |
|
774 columns->AddL( TDbCol( KSongHistoryDBImageUrlColumn, EDbColText, KMaxColumnLength ) ); |
|
775 columns->AddL( TDbCol( KSongHistoryDBGenreNameColumn, EDbColText, KMaxColumnLength ) ); |
|
776 columns->AddL( TDbCol( KSongHistoryDBCountryNameColumn, EDbColText, KMaxColumnLength ) ); |
|
777 columns->AddL( TDbCol( KSongHistoryDBLanguageNameColumn, EDbColText, KMaxColumnLength ) ); |
|
778 columns->AddL( TDbCol( KSongHistoryDBMusicStatusColumn, EDbColText, KMaxColumnLength ) ); |
|
779 ); |
|
780 User::LeaveIfError( error ); |
|
781 |
|
782 User::LeaveIfError( CreateTable( KSongHistoryDBTable, *columns ) ); |
|
783 |
|
784 CleanupStack::PopAndDestroy( columns ); |
|
785 IRLOG_DEBUG( "CIRSongHistoryDb::CreateSongHistoryTablesL - Exiting." ); |
|
786 } |
|
787 |
|
788 /** |
|
789 * Function : CreateSongHistoryTables2L() |
|
790 * creates songhistory table with three columns |
|
791 * log data |
|
792 * --------------------------------------------------------------------------- |
|
793 * SongHistoryTable |
|
794 *--------------------------- |
|
795 *| SongName | ArtistName | ChannelName | MusicStatusFlag |
|
796 *--------------------------- |
|
797 *|EDbColText| EDbColText | EDbColText | EDbColText |
|
798 *---------------------------------------------------------------------------- |
|
799 */ |
|
800 void CIRSongHistoryDb::CreateSongHistoryTables2L() |
|
801 { |
|
802 IRLOG_DEBUG( "CIRSongHistoryDb::CreateSongHistoryTablesL" ); |
|
803 CDbColSet* columns = CDbColSet::NewLC(); |
|
804 |
|
805 TRAPD( error, |
|
806 columns->AddL( TDbCol( KSongHistoryDBSongNameColumn, EDbColText, KMaxColumnLength ) ); |
|
807 columns->AddL( TDbCol( KSongHistoryDBArtistNameColumn, EDbColText, KMaxColumnLength) ); |
|
808 columns->AddL( TDbCol( KSongHistoryDBChannelNameColumn, EDbColText, KMaxColumnLength) ); |
|
809 columns->AddL( TDbCol( KSongHistoryDBMusicStatusColumn, EDbColText, KMaxColumnLength ) ); |
|
810 ); |
|
811 User::LeaveIfError( error ); |
|
812 |
|
813 User::LeaveIfError( CreateTable( KSongHistoryDBTable2, *columns ) ); |
|
814 |
|
815 CleanupStack::PopAndDestroy( columns ); |
|
816 IRLOG_DEBUG( "CIRSongHistoryDb::CreateSongHistoryTablesL - Exiting." ); |
|
817 } |
|
818 |
|
819 |
|
820 |
|
821 // --------------------------------------------------------------------------- |
|
822 // CIRSongHistoryDb::OpenSongHistoryDbL() |
|
823 // opening the data base |
|
824 // --------------------------------------------------------------------------- |
|
825 // |
|
826 void CIRSongHistoryDb::OpenSongHistoryDbL(const TFileName& aSongHistoryDbFile) |
|
827 { |
|
828 IRLOG_DEBUG( "CIRSongHistoryDb::OpenSongHistoryDbL" ); |
|
829 CloseSongHistoryDb(); //Ensure that the database is closed before trying to open it. |
|
830 |
|
831 |
|
832 TInt error = KErrNone; |
|
833 |
|
834 error = Open(iFsSession,aSongHistoryDbFile); |
|
835 if( error!=KErrNone ) |
|
836 { |
|
837 //if database is failed to open then |
|
838 //function leaves |
|
839 IRLOG_ERROR2( "CIRSongHistoryDb::OpenSongHistoryDbL - Opening session database failed (%d)", error ); |
|
840 User::LeaveIfError(error); |
|
841 } |
|
842 if( IsDamaged() || !InTransaction() ) |
|
843 { |
|
844 //if data base is damaged then |
|
845 //it tried to recover |
|
846 //if recovery is not possible function leaves |
|
847 error = Recover(); |
|
848 if ( KErrNone == error) |
|
849 { |
|
850 //if recovered data base is compacted |
|
851 error = Compact(); |
|
852 } |
|
853 User::LeaveIfError(error); |
|
854 } |
|
855 |
|
856 //open the table |
|
857 error = iSongHistoryTable.Open(*this, KSongHistoryDBTable, iSongHistoryTable.EUpdatable); |
|
858 if( error ) |
|
859 { |
|
860 User::LeaveIfError(error); |
|
861 } |
|
862 |
|
863 error = iSongHistoryTable2.Open(*this, KSongHistoryDBTable2, iSongHistoryTable2.EUpdatable); |
|
864 if( error ) |
|
865 { |
|
866 iSongHistoryTable.Close(); |
|
867 User::LeaveIfError(error); |
|
868 } |
|
869 |
|
870 IRLOG_DEBUG( "CIRSongHistoryDb::OpenSongHistoryDbL - Exiting." ); |
|
871 } |
|
872 |
|
873 |
|
874 // --------------------------------------------------------------------------- |
|
875 // CIRSongHistoryDb::CreateSongHistoryDb() |
|
876 // @database filename |
|
877 // --------------------------------------------------------------------------- |
|
878 // |
|
879 TInt CIRSongHistoryDb::CreateSongHistoryDb(const TFileName& aSongHistoryDbFile ) |
|
880 { |
|
881 IRLOG_DEBUG( "CIRSongHistoryDb::CreateSongHistoryDb" ); |
|
882 |
|
883 |
|
884 TInt error = Replace(iFsSession,aSongHistoryDbFile); |
|
885 if ( error != KErrNone ) |
|
886 { |
|
887 IRLOG_ERROR2( "CIRSongHistoryDb::CreateSongHistoryDb - Creating history database failed (%d)", error ); |
|
888 return error; |
|
889 } |
|
890 |
|
891 TRAPD(err1,CreateSongHistoryTablesL()); |
|
892 if(err1) |
|
893 { |
|
894 return err1; |
|
895 } |
|
896 |
|
897 //if error, no handling |
|
898 TRAPD(err2, CreateSongHistoryTables2L()); |
|
899 if( err2 ) |
|
900 { |
|
901 return err2; |
|
902 } |
|
903 IRLOG_DEBUG( "CIRSongHistoryDb::CreateSongHistoryDb - Exiting." ); |
|
904 return KErrNone; |
|
905 } |
|
906 |
|
907 |
|
908 // --------------------------------------------------------------------------- |
|
909 // CIRSongHistoryDb::CountSongHistoryDb() |
|
910 // count the database entries |
|
911 // --------------------------------------------------------------------------- |
|
912 // |
|
913 |
|
914 TInt CIRSongHistoryDb::CountSongHistoryDb() |
|
915 { |
|
916 IRLOG_DEBUG( "CIRSongHistoryDb::CountSongHistoryDb" ); |
|
917 TInt historyCount = 0; |
|
918 iSongHistoryTable.Reset(); |
|
919 TRAPD(error,historyCount= iSongHistoryTable.CountL()); |
|
920 if(error) |
|
921 { |
|
922 |
|
923 } |
|
924 IRLOG_DEBUG( "CIRSongHistoryDb::CountSongHistoryDb - Exiting." ); |
|
925 return historyCount; |
|
926 |
|
927 } |
|
928 |
|
929 // --------------------------------------------------------------------------- |
|
930 // CIRSongHistoryDb::CountSongHistoryDb2() |
|
931 // count the database entries |
|
932 // --------------------------------------------------------------------------- |
|
933 // |
|
934 TInt CIRSongHistoryDb::CountSongHistoryDb2() |
|
935 { |
|
936 IRLOG_DEBUG( "CIRSongHistoryDb::CountSongHistoryDb" ); |
|
937 TInt historyCount = 0; |
|
938 iSongHistoryTable2.Reset(); |
|
939 TRAPD(error,historyCount= iSongHistoryTable2.CountL()); |
|
940 if(error) |
|
941 { |
|
942 historyCount = -1; |
|
943 } |
|
944 IRLOG_DEBUG( "CIRSongHistoryDb::CountSongHistoryDb - Exiting." ); |
|
945 return historyCount; |
|
946 } |
|
947 // --------------------------------------------------------------------------- |
|
948 // CIRSongHistoryDb::GetLastHistoryItemL() |
|
949 // Gets the last song history item |
|
950 // --------------------------------------------------------------------------- |
|
951 // |
|
952 void CIRSongHistoryDb::GetLastHistoryItemL(RBuf& aSongName, RBuf& aArtistName, |
|
953 RBuf& aChannelName, RBuf& aChannelUrl) |
|
954 { |
|
955 if( iSongHistoryTable.IsEmptyL() || iSongHistoryTable.LastL() == EFalse) |
|
956 { |
|
957 return; |
|
958 } |
|
959 |
|
960 iSongHistoryTable.GetL(); |
|
961 |
|
962 CDbColSet* columns = iSongHistoryTable.ColSetL(); |
|
963 TInt songColumn = columns->ColNo( KSongHistoryDBSongNameColumn ); |
|
964 TInt artistColumn = columns->ColNo( KSongHistoryDBArtistNameColumn ); |
|
965 TInt channelColumn = columns->ColNo( KSongHistoryDBChannelNameColumn ); |
|
966 TInt channelUrlColumn = columns->ColNo( KSongHistoryDBChannelUrlColumn ); |
|
967 |
|
968 delete columns; |
|
969 columns = NULL; |
|
970 |
|
971 aSongName.Create(iSongHistoryTable.ColDes( songColumn )); |
|
972 aArtistName.Create(iSongHistoryTable.ColDes( artistColumn )); |
|
973 aChannelName.Create(iSongHistoryTable.ColDes( channelColumn )); |
|
974 aChannelUrl.Create(iSongHistoryTable.ColDes( channelUrlColumn )); |
|
975 |
|
976 |
|
977 iSongHistoryTable.Reset(); |
|
978 } |
|
979 // --------------------------------------------------------------------------- |
|
980 // CIRSongHistoryDb::GetChannelSongsCountL() |
|
981 // Gets the channel's song count. |
|
982 // --------------------------------------------------------------------------- |
|
983 // |
|
984 |
|
985 TUint CIRSongHistoryDb::GetChannelSongsCountL( const RBuf& aChannelName, const RBuf& aChannelUrl ) |
|
986 { |
|
987 _LIT( strQuery, "Select SongName from SongHistoryTable where ChannelName='%S' AND ChannelUrl='%S'"); |
|
988 |
|
989 TBuf<KMaxSize> bufQuery; |
|
990 bufQuery.Format( strQuery, &aChannelName, &aChannelUrl ); |
|
991 |
|
992 TDbQuery querySearchChannel( bufQuery ); |
|
993 RDbView dbView; |
|
994 |
|
995 TInt error = dbView.Prepare( *this, querySearchChannel ); |
|
996 User::LeaveIfError(error); |
|
997 |
|
998 error = dbView.Evaluate(); // 0, evaluation is complete |
|
999 User::LeaveIfError(error); |
|
1000 |
|
1001 TInt cRows = dbView.CountL(); |
|
1002 |
|
1003 dbView.Close(); |
|
1004 |
|
1005 return cRows; |
|
1006 } |
|
1007 |
|
1008 // --------------------------------------------------------------------------- |
|
1009 // CIRSongHistoryDb::SyncSongHistoryDb() |
|
1010 // Synchronises the History DB with removed channel entry in the ISDS |
|
1011 // --------------------------------------------------------------------------- |
|
1012 // |
|
1013 |
|
1014 void CIRSongHistoryDb::SyncSongHistoryDbL(TInt aChannelId) |
|
1015 { |
|
1016 IRLOG_DEBUG( "CIRSongHistoryDb::SyncSongHistoryDbL" ); |
|
1017 |
|
1018 |
|
1019 if(iSongHistoryTable.CountL() < 1) |
|
1020 { |
|
1021 return; |
|
1022 } |
|
1023 |
|
1024 CDbColSet* columns = iSongHistoryTable.ColSetL(); |
|
1025 TInt songColumn = columns->ColNo( KSongHistoryDBSongNameColumn ); |
|
1026 TInt artistColumn = columns->ColNo( KSongHistoryDBArtistNameColumn ); |
|
1027 TInt channelColumn = columns->ColNo( KSongHistoryDBChannelNameColumn ); |
|
1028 TInt channelUrlColumn = columns->ColNo( KSongHistoryDBChannelUrlColumn ); |
|
1029 TInt channelTypeColumn = columns->ColNo( KSongHistoryDBChannelTypeColumn ); |
|
1030 TInt channelIdColumn = columns->ColNo( KSongHistoryDBChannelIdColumn ); |
|
1031 TInt bitrateColumn = columns->ColNo( KSongHistoryDBBitrateColumn ); |
|
1032 TInt channelDescColumn = columns->ColNo( KSongHistoryDBChannelDescColumn ); |
|
1033 TInt imageUrlColumn = columns->ColNo( KSongHistoryDBImageUrlColumn ); |
|
1034 TInt genreNameColumn = columns->ColNo( KSongHistoryDBGenreNameColumn ); |
|
1035 TInt countryNameColumn = columns->ColNo( KSongHistoryDBCountryNameColumn ); |
|
1036 TInt languageNameColumn = columns->ColNo( KSongHistoryDBLanguageNameColumn ); |
|
1037 TInt musicStatusColumn = columns->ColNo( KSongHistoryDBMusicStatusColumn ); |
|
1038 |
|
1039 delete columns; |
|
1040 columns = NULL; |
|
1041 |
|
1042 // Find out the channel to be changed |
|
1043 for ( iSongHistoryTable.LastL(); iSongHistoryTable.AtRow(); iSongHistoryTable.PreviousL() ) |
|
1044 { |
|
1045 iSongHistoryTable.GetL(); |
|
1046 // Extracting the values from the database. |
|
1047 TInt channelId; |
|
1048 RBuf imageUrl, genreName, countryName, languageName; |
|
1049 RBuf channelMusicStatus; |
|
1050 |
|
1051 channelId=iSongHistoryTable.ColUint16( channelIdColumn ); |
|
1052 imageUrl.Create(iSongHistoryTable.ColDes( imageUrlColumn )); |
|
1053 imageUrl.CleanupClosePushL(); |
|
1054 genreName.Create(iSongHistoryTable.ColDes( genreNameColumn )); |
|
1055 genreName.CleanupClosePushL(); |
|
1056 countryName.Create(iSongHistoryTable.ColDes( countryNameColumn )); |
|
1057 countryName.CleanupClosePushL(); |
|
1058 languageName.Create(iSongHistoryTable.ColDes( languageNameColumn )); |
|
1059 languageName.CleanupClosePushL(); |
|
1060 channelMusicStatus.Create(iSongHistoryTable.ColDes( musicStatusColumn )); |
|
1061 channelMusicStatus.CleanupClosePushL(); |
|
1062 |
|
1063 |
|
1064 if(aChannelId == channelId) |
|
1065 { |
|
1066 iSongHistoryTable.UpdateL(); |
|
1067 iSongHistoryTable.SetColL(channelTypeColumn, 0); |
|
1068 iSongHistoryTable.SetColL(channelIdColumn, 0); |
|
1069 iSongHistoryTable.SetColL(imageUrlColumn, KNo); |
|
1070 iSongHistoryTable.SetColL(genreNameColumn, KNo); |
|
1071 iSongHistoryTable.SetColL(countryNameColumn, KNo); |
|
1072 iSongHistoryTable.SetColL(languageNameColumn, KNo); |
|
1073 iSongHistoryTable.SetColL(musicStatusColumn, KNo); |
|
1074 iSongHistoryTable.PutL(); |
|
1075 } |
|
1076 CleanupStack::PopAndDestroy(&channelMusicStatus); |
|
1077 CleanupStack::PopAndDestroy(&languageName); |
|
1078 CleanupStack::PopAndDestroy(&countryName); |
|
1079 CleanupStack::PopAndDestroy(&genreName); |
|
1080 CleanupStack::PopAndDestroy(&imageUrl); |
|
1081 } |
|
1082 iSongHistoryTable.Reset(); |
|
1083 |
|
1084 IRLOG_DEBUG( "CIRSongHistoryDb::SyncSongHistoryDbL - Exiting." ); |
|
1085 } |
|
1086 |
|
1087 // --------------------------------------------------------------------------- |
|
1088 // CIRSongHistoryDb::GetIdPresentInDb() |
|
1089 // Gets whether that particular channel id is present in Db or not. |
|
1090 // --------------------------------------------------------------------------- |
|
1091 // |
|
1092 |
|
1093 TBool CIRSongHistoryDb::GetIdPresentInDbL(TInt aChannelId) |
|
1094 { |
|
1095 IRLOG_DEBUG( "CIRSongHistoryDb::GetIdPresentInDbL" ); |
|
1096 |
|
1097 TBool value = EFalse; |
|
1098 |
|
1099 if(iSongHistoryTable.CountL() < 1) |
|
1100 { |
|
1101 return value; |
|
1102 } |
|
1103 |
|
1104 CDbColSet* columns = iSongHistoryTable.ColSetL(); |
|
1105 TInt channelIdColumn = columns->ColNo( KSongHistoryDBChannelIdColumn ); |
|
1106 |
|
1107 delete columns; |
|
1108 columns = NULL; |
|
1109 |
|
1110 // Find out the channel to be changed |
|
1111 for ( iSongHistoryTable.LastL(); iSongHistoryTable.AtRow(); iSongHistoryTable.PreviousL() ) |
|
1112 { |
|
1113 iSongHistoryTable.GetL(); |
|
1114 TInt channelId; |
|
1115 |
|
1116 channelId=iSongHistoryTable.ColUint16( channelIdColumn ); |
|
1117 if(aChannelId == channelId) |
|
1118 { |
|
1119 value = ETrue; |
|
1120 } |
|
1121 |
|
1122 } |
|
1123 |
|
1124 iSongHistoryTable.Reset(); |
|
1125 |
|
1126 IRLOG_DEBUG( "CIRSongHistoryDb::GetIdPresentInDbL - Exiting." ); |
|
1127 return value ; |
|
1128 } |
|
1129 |
|
1130 |
|
1131 |
|
1132 // --------------------------------------------------------------------------- |
|
1133 // CIRSongHistoryDb::UpdateSongHistoryDb() |
|
1134 // Updates the song history DB when there is a channel change in the isds. |
|
1135 // --------------------------------------------------------------------------- |
|
1136 // |
|
1137 |
|
1138 TInt CIRSongHistoryDb::UpdateSongHistoryDbL( TInt aChannelId, |
|
1139 const TDesC& aChannelUrl, |
|
1140 const TDesC& aImageUrl, |
|
1141 const TDesC& aGenreName, |
|
1142 const TDesC& aCountryName, |
|
1143 const TDesC& aLanguageName, |
|
1144 const TDesC& aMusicFlag) |
|
1145 { |
|
1146 IRLOG_DEBUG( "CIRSongHistoryDb::UpdateSongHistoryDbL" ); |
|
1147 |
|
1148 TBool channelChanged = EFalse ; |
|
1149 TInt compFlagUrl ; |
|
1150 TInt compFlagImageUrl, compFlagGenreName, compFlagCountryName, compFlagLanguageName; |
|
1151 TInt compFlagMusic ; |
|
1152 TInt compUrlChange ; |
|
1153 |
|
1154 if(iSongHistoryTable.CountL() < 1) |
|
1155 { |
|
1156 return EFalse; |
|
1157 } |
|
1158 |
|
1159 CDbColSet* columns = iSongHistoryTable.ColSetL(); |
|
1160 TInt channelUrlColumn = columns->ColNo( KSongHistoryDBChannelUrlColumn ); |
|
1161 TInt channelTypeColumn = columns->ColNo( KSongHistoryDBChannelTypeColumn ); |
|
1162 TInt channelIdColumn = columns->ColNo( KSongHistoryDBChannelIdColumn ); |
|
1163 TInt channelDescColumn = columns->ColNo( KSongHistoryDBChannelDescColumn ); |
|
1164 TInt imageUrlColumn = columns->ColNo( KSongHistoryDBImageUrlColumn ); |
|
1165 TInt genreNameColumn = columns->ColNo( KSongHistoryDBGenreNameColumn ); |
|
1166 TInt countryNameColumn = columns->ColNo( KSongHistoryDBCountryNameColumn ); |
|
1167 TInt languageNameColumn = columns->ColNo( KSongHistoryDBLanguageNameColumn ); |
|
1168 TInt musicStatusColumn = columns->ColNo( KSongHistoryDBMusicStatusColumn ); |
|
1169 |
|
1170 delete columns; |
|
1171 columns = NULL; |
|
1172 |
|
1173 // Find out the channel to be changed |
|
1174 |
|
1175 for ( iSongHistoryTable.LastL(); iSongHistoryTable.AtRow(); iSongHistoryTable.PreviousL() ) |
|
1176 { |
|
1177 iSongHistoryTable.GetL(); |
|
1178 // Extracting the values from the database. |
|
1179 RBuf channelUrl; |
|
1180 RBuf imageUrl, genreName, countryName, languageName; |
|
1181 TInt channelId; |
|
1182 RBuf channelMusicStatus; |
|
1183 |
|
1184 channelUrl.Create(iSongHistoryTable.ColDes( channelUrlColumn )); |
|
1185 channelUrl.CleanupClosePushL(); |
|
1186 |
|
1187 imageUrl.Create(iSongHistoryTable.ColDes( imageUrlColumn )); |
|
1188 imageUrl.CleanupClosePushL(); |
|
1189 genreName.Create(iSongHistoryTable.ColDes( genreNameColumn )); |
|
1190 genreName.CleanupClosePushL(); |
|
1191 countryName.Create(iSongHistoryTable.ColDes( countryNameColumn )); |
|
1192 countryName.CleanupClosePushL(); |
|
1193 languageName.Create(iSongHistoryTable.ColDes( languageNameColumn )); |
|
1194 languageName.CleanupClosePushL(); |
|
1195 |
|
1196 channelId=iSongHistoryTable.ColUint16( channelIdColumn ); |
|
1197 |
|
1198 channelMusicStatus.Create(iSongHistoryTable.ColDes( musicStatusColumn )); |
|
1199 channelMusicStatus.CleanupClosePushL(); |
|
1200 |
|
1201 if(aChannelId == channelId) |
|
1202 { |
|
1203 compFlagUrl = (channelUrl).Compare(aChannelUrl); |
|
1204 compFlagImageUrl = (imageUrl).Compare(aImageUrl); |
|
1205 compFlagGenreName = (genreName).Compare(aGenreName); |
|
1206 compFlagCountryName = (countryName).Compare(aCountryName); |
|
1207 compFlagLanguageName = (languageName).Compare(aLanguageName); |
|
1208 compFlagMusic = (channelMusicStatus).Compare(aMusicFlag); |
|
1209 compUrlChange = (aChannelUrl).Compare(KNo); |
|
1210 |
|
1211 if(compFlagUrl && compUrlChange) |
|
1212 { |
|
1213 iSongHistoryTable.UpdateL(); |
|
1214 iSongHistoryTable.SetColL(channelUrlColumn, aChannelUrl); |
|
1215 iSongHistoryTable.PutL(); |
|
1216 channelChanged = ETrue ; |
|
1217 } |
|
1218 if(compFlagImageUrl) |
|
1219 { |
|
1220 iSongHistoryTable.UpdateL(); |
|
1221 iSongHistoryTable.SetColL(imageUrlColumn, aImageUrl); |
|
1222 iSongHistoryTable.PutL(); |
|
1223 channelChanged = ETrue ; |
|
1224 } |
|
1225 if(compFlagGenreName) |
|
1226 { |
|
1227 iSongHistoryTable.UpdateL(); |
|
1228 iSongHistoryTable.SetColL(genreNameColumn, aGenreName); |
|
1229 iSongHistoryTable.PutL(); |
|
1230 channelChanged = ETrue ; |
|
1231 } |
|
1232 if(compFlagCountryName) |
|
1233 { |
|
1234 iSongHistoryTable.UpdateL(); |
|
1235 iSongHistoryTable.SetColL(countryNameColumn, aCountryName); |
|
1236 iSongHistoryTable.PutL(); |
|
1237 channelChanged = ETrue ; |
|
1238 } |
|
1239 if(compFlagLanguageName) |
|
1240 { |
|
1241 iSongHistoryTable.UpdateL(); |
|
1242 iSongHistoryTable.SetColL(languageNameColumn, aLanguageName); |
|
1243 iSongHistoryTable.PutL(); |
|
1244 channelChanged = ETrue ; |
|
1245 } |
|
1246 if(compFlagMusic) |
|
1247 { |
|
1248 iSongHistoryTable.UpdateL(); |
|
1249 iSongHistoryTable.SetColL(musicStatusColumn, aMusicFlag); |
|
1250 iSongHistoryTable.PutL(); |
|
1251 channelChanged = ETrue ; |
|
1252 } |
|
1253 |
|
1254 } |
|
1255 CleanupStack::PopAndDestroy(&channelMusicStatus); |
|
1256 CleanupStack::PopAndDestroy(&languageName); |
|
1257 CleanupStack::PopAndDestroy(&countryName); |
|
1258 CleanupStack::PopAndDestroy(&genreName); |
|
1259 CleanupStack::PopAndDestroy(&imageUrl); |
|
1260 CleanupStack::PopAndDestroy(&channelUrl); |
|
1261 |
|
1262 } |
|
1263 iSongHistoryTable.Reset(); |
|
1264 IRLOG_DEBUG( "CIRSongHistoryDb::UpdateSongHistoryDbL - Exiting." ); |
|
1265 return channelChanged; |
|
1266 } |
|
1267 |
|
1268 void CIRSongHistoryDb::SearchAndDeleteRecordL(const TDesC& aChannelName, const TDesC& aChannelUrl, |
|
1269 TInt aChannelType, TInt aPresetId) |
|
1270 { |
|
1271 CDbColSet* columns = iSongHistoryTable.ColSetL(); |
|
1272 TInt channelNameColumn = columns->ColNo( KSongHistoryDBChannelNameColumn ); |
|
1273 TInt channelUrlColumn = columns->ColNo( KSongHistoryDBChannelUrlColumn ); |
|
1274 TInt channelTypeColumn = columns->ColNo( KSongHistoryDBChannelTypeColumn ); |
|
1275 TInt channelIdColumn = columns->ColNo(KSongHistoryDBChannelIdColumn); |
|
1276 |
|
1277 delete columns; |
|
1278 columns = NULL; |
|
1279 |
|
1280 for (iSongHistoryTable.LastL(); iSongHistoryTable.AtRow(); iSongHistoryTable.PreviousL()) |
|
1281 { |
|
1282 iSongHistoryTable.GetL(); |
|
1283 TPtrC channelName = iSongHistoryTable.ColDes(channelNameColumn); |
|
1284 TPtrC channelUrl = iSongHistoryTable.ColDes(channelUrlColumn); |
|
1285 TInt channelType = iSongHistoryTable.ColInt(channelTypeColumn); |
|
1286 TInt channelId = iSongHistoryTable.ColInt(channelIdColumn); |
|
1287 |
|
1288 if (0 == aChannelType) |
|
1289 { |
|
1290 //user-defined channel |
|
1291 if (aChannelName == channelName && aChannelUrl == channelUrl) |
|
1292 { |
|
1293 iSongHistoryTable.DeleteL(); |
|
1294 break; |
|
1295 } |
|
1296 } |
|
1297 else |
|
1298 { |
|
1299 //channel from ISDS server |
|
1300 if (aChannelName == channelName && aPresetId == channelId) |
|
1301 { |
|
1302 iSongHistoryTable.DeleteL(); |
|
1303 break; |
|
1304 } |
|
1305 } |
|
1306 } |
|
1307 |
|
1308 iSongHistoryTable.Reset(); |
|
1309 } |
|