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