internetradio2.0/songhistoryinc/irsonghistorydb.h
changeset 0 09774dfdd46b
child 5 0930554dc389
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:  Song History database used for stroing song history entries.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 /* ---------------------------------------------------------------------------
       
    20 *  Version history:
       
    21 *  Template version:
       
    22 *  <ccm_history>
       
    23 *
       
    24 *  Version: 3, Thu Apr 14 12:00:00 2008 by Rohit
       
    25 *  Ref:
       
    26 *  Pc lint fixes
       
    27 *
       
    28 *  Version: 2, Thu Apr 10 20:00:00 2008 by Rohit
       
    29 *  Ref:
       
    30 *  Implemented SongHistory changes for channelwise songs
       
    31 *
       
    32 *  </ccm_history>
       
    33 * ============================================================================
       
    34 */
       
    35 
       
    36 #ifndef CIRSONGHISTORYDB_H
       
    37 #define CIRSONGHISTORYDB_H
       
    38 
       
    39 #include <d32dbms.h>
       
    40 #include "irsettings.h"
       
    41 
       
    42 class CIRSongHistoryInfo;
       
    43 class CIRSettings;
       
    44  
       
    45 
       
    46 // Maximum no of entries to be stored in the history list.
       
    47 const TInt KMaxNoChannelHistoryDbEntries = 30;
       
    48 const TInt KMaxNoSongHistoryDbEntries = 100;
       
    49 
       
    50 // Maximum length of Dbms field string
       
    51 const TInt KIRDbMaxStrLen = 255;
       
    52 
       
    53 const TInt KIRDbMaxChType = 2;
       
    54 
       
    55 
       
    56 
       
    57 NONSHARABLE_CLASS(CIRSongHistoryDb) : public RDbNamedDatabase
       
    58 	{
       
    59 //member functions
       
    60 public:
       
    61 
       
    62 	/**
       
    63 	* Function : NewL()
       
    64 	* Two phased construction
       
    65 	* @return instance of CIRSongHistoryDb
       
    66 	*/
       
    67 		static CIRSongHistoryDb* NewL();
       
    68 
       
    69 	/**
       
    70 	* Function : NewLC()
       
    71 	* Two phased construction
       
    72 	* @return instance of CIRSongHistoryDb
       
    73 	*/
       
    74 		static CIRSongHistoryDb* NewLC();
       
    75 
       
    76 	/**
       
    77 	* Function : ~CIRSongHistoryDb()
       
    78 	* default destructor
       
    79 	*/
       
    80 		~CIRSongHistoryDb();
       
    81 
       
    82 
       
    83 
       
    84 	/**
       
    85 	* Function : AddToSongHistoryDbL()
       
    86 	* adds the song history entry into data base
       
    87 	* @param various channel information 
       
    88 	*/
       
    89 	TBool AddToSongHistoryDbL( const TDesC& aSongName,
       
    90 								const TDesC& aArtistName, 
       
    91 								const TDesC& aChannelName, 
       
    92 								const TDesC& aChannelUrl,
       
    93 								RBuf& aDelSongName, 
       
    94 								RBuf& aDelArtistname, 
       
    95 								RBuf& aDelChannelName, 
       
    96 								RBuf& aDelChannelUrl,
       
    97 								TInt  aChannelType,
       
    98 								TInt aChannelId,
       
    99 								TInt aBitrate,
       
   100 								const TDesC& aChannelDesc,
       
   101 								const TDesC& aImageUrl,
       
   102 								const TDesC& aMusicFlag);
       
   103 	 /**
       
   104 	 * Function : AddToSongHistoryDb2L()
       
   105 	 * adds the song history entry into data base
       
   106 	 * @param various song information 
       
   107 	 */
       
   108 	 TBool AddToSongHistoryDb2L( const TDesC& aSongName,
       
   109 	                             const TDesC& aArtistName, 	                                
       
   110 	                             const TDesC& aMusicFlag);
       
   111 
       
   112 
       
   113 	/**
       
   114 	* CIRSongHistoryDb::GetAllSongHistoryListL()
       
   115 	* gets all the song history entries  into an array
       
   116 	* @param aSongHistoryEntries is the array which is to be filled by the SongHistoryDb. 
       
   117 	*/
       
   118 
       
   119 		void GetAllSongHistoryListL(RPointerArray<CIRSongHistoryInfo>& aSongHistoryEntries);
       
   120     /**
       
   121 	* CIRSongHistoryDb::GetAllSongHistoryList2L()
       
   122 	* gets all the song history entries  into an array
       
   123 	* @param aSongEntries is the array which is to be filled by the SongHistoryDb. 
       
   124 	*/
       
   125 		void GetAllSongHistoryList2L(RPointerArray<CIRSongHistoryInfo>& aSongEntries);
       
   126 	/**
       
   127 	* Function : ClearAllSongHistoryFromDb
       
   128 	* delete all the song entries from the database.
       
   129 	*/
       
   130 
       
   131 		TInt ClearAllSongHistoryFromDb();
       
   132 		
       
   133 	/**
       
   134 	* Function : ClearAllSongHistoryFromDb2
       
   135 	* delete all the song entries from the database.
       
   136 	*/
       
   137 		TInt ClearAllSongHistoryFromDb2();
       
   138 
       
   139 	/**
       
   140 	* Function : CountSongHistoryDb()
       
   141 	* count the database entries
       
   142 	*/
       
   143 
       
   144 		TInt CountSongHistoryDb();
       
   145 		
       
   146 	/**
       
   147 	* Function : CountSongHistoryDb2()
       
   148 	* count the database entries
       
   149 	*/
       
   150 		TInt CountSongHistoryDb2();
       
   151 
       
   152 	/**
       
   153 	* Function : GetLastHistoryItemL()
       
   154 	* Gives the last added entry in the database
       
   155 	* @param Channel data to be filled .
       
   156 	*/
       
   157 	void GetLastHistoryItemL(RBuf& aSongName, RBuf& aArtistName,
       
   158 					 RBuf& aChannelName, RBuf& aChannelUrl);
       
   159 
       
   160 	/**
       
   161 	* Function : GetChannelSongsCount()
       
   162 	* Returns SongsCount for given channel
       
   163 	*/
       
   164 	TUint GetChannelSongsCountL( const RBuf& aChannelName, const RBuf& aChannelUrl );
       
   165 	
       
   166 	/**
       
   167 	* Function : GetChannelSongsCount()
       
   168 	* Updates the song history DB when there is a channel removed in the isds.
       
   169 	*/
       
   170     void SyncSongHistoryDbL(TInt aChannelId) ;
       
   171     
       
   172 	/**
       
   173 	* Function : GetIdPresentInDb()
       
   174 	* Gets whether the particular channel ID is present in history DB or not. 
       
   175 	*/
       
   176     TBool GetIdPresentInDbL(TInt aChannelId) ;
       
   177     
       
   178 	/**
       
   179 	* Function : UpdateSongHistoryDb()
       
   180 	* Updates the song history DB when there is a channel change in the isds.
       
   181 	*/
       
   182     TInt UpdateSongHistoryDbL( TInt aChannelId,
       
   183     	                      const TDesC& aChannelName, 
       
   184 						      const TDesC& aChannelUrl,
       
   185 						      const TDesC& aImageUrl,
       
   186 							  const TDesC& aMusicFlag);
       
   187 
       
   188     /*
       
   189      * search if a record already exists in database. If yes, delete it.
       
   190      */
       
   191     void SearchAndDeleteRecordL(const TDesC& aChannelName, const TDesC& aChannelUrl,
       
   192                                 TInt aChannelType);
       
   193     
       
   194     /*
       
   195      * delete a recorder by the index
       
   196      * */
       
   197     TInt DeleteOneHistory(TInt aIndex);
       
   198     
       
   199 
       
   200 private:
       
   201 
       
   202 	/**
       
   203 	* Function : ConstructL()
       
   204 	* two phase construction
       
   205 	*/
       
   206     void ConstructL();
       
   207 
       
   208     /**
       
   209 	* Function : CloseSongHistoryDb()
       
   210 	* Closes the database
       
   211 	*/
       
   212 	void CloseSongHistoryDb();
       
   213 
       
   214 	/**
       
   215 	* Function : CreateSongHistoryTablesL()
       
   216 	* creates songhistory table with three columns
       
   217 	* log data
       
   218 	* ---------------------------------------------------------------------------
       
   219 	* SongHistoryTable
       
   220 	*---------------------------
       
   221 	*| SongName | ArtistName | ChannelName | ChannelUrl | ChannelType | ChannelId | Bitrate | ChannelDesc | ImageUrl
       
   222 	*---------------------------
       
   223 	*|EDbColText| EDbColText | EDbColText | EDbColText | EDbColUint8 | EDbColUint16 | EDbColUint16 | EDbColText | EDbColText
       
   224 	*----------------------------------------------------------------------------
       
   225 	*/
       
   226 	void CreateSongHistoryTablesL();
       
   227 	
       
   228     /**
       
   229 	* Function : CreateSongHistoryTables2L()
       
   230 	* creates songhistory table with three columns
       
   231 	* log data
       
   232 	* ---------------------------------------------------------------------------
       
   233 	* SongHistoryTable
       
   234 	*---------------------------
       
   235 	*| SongName | ArtistName | MusicStatusFlag
       
   236 	*---------------------------
       
   237 	*|EDbColText| EDbColText | EDbColText |
       
   238 	*----------------------------------------------------------------------------
       
   239 	*/
       
   240 	void CreateSongHistoryTables2L();
       
   241 
       
   242    /**
       
   243 	* Function : CreateDbCondition()
       
   244 	* Creates  the dbms file conditionally(only if not yet created)
       
   245 	* @param aSongHistoryDbFile the Database file name
       
   246 	*/
       
   247 	void CreateDbCondition(const TFileName& aSongHistoryDbFile);
       
   248 
       
   249 
       
   250 	/**
       
   251 	* Function : OpenSongHistoryDbL()
       
   252 	* @param aSongHistoryDbFile the Database file name
       
   253 	* opening the data base
       
   254 	*/
       
   255 	void OpenSongHistoryDbL(const TFileName& aSongHistoryDbFile);
       
   256 
       
   257 	/**
       
   258 	* Function : CreateSongHistoryDb()
       
   259 	* creates the dbms files
       
   260 	* @param aSongHistoryDbFile database filename
       
   261 	*/
       
   262 	TInt CreateSongHistoryDb(const TFileName& aSongHistoryDbFile);
       
   263 	
       
   264 	/**
       
   265 	 * to wrapper the delete leaving
       
   266 	 */
       
   267 	TInt DeleteOneHistoryL(TInt aIndex);
       
   268 
       
   269 	/**
       
   270 	* Data-structure to hold unique channel info
       
   271 	*/
       
   272 	class CIRChannelInfo : public CBase
       
   273 	{
       
   274 	public:
       
   275 		~CIRChannelInfo()
       
   276 		{
       
   277 			iChannelUrl.Close();
       
   278 			iChannelName.Close();
       
   279 		}
       
   280 		RBuf iChannelUrl;
       
   281 		RBuf iChannelName;
       
   282 		TInt iChannelType;
       
   283 	};
       
   284 	
       
   285 
       
   286 
       
   287 	/**
       
   288 	* Comparer function to compare two CIRChannelInfo's
       
   289 	*/
       
   290 	static TBool CompareChannelInfos(const CIRChannelInfo& aFirst, const CIRChannelInfo& aSecond);
       
   291 	 
       
   292 //data members
       
   293 
       
   294 private:
       
   295 
       
   296 	//	File session
       
   297 
       
   298     RFs iFsSession;
       
   299 
       
   300 
       
   301      //	Table which stores History information
       
   302 
       
   303     RDbTable iSongHistoryTable;
       
   304 
       
   305     // only save the song info for the song history view.
       
   306 	RDbTable iSongHistoryTable2;
       
   307 
       
   308     };
       
   309 
       
   310 #endif  //CIRSONGHISTORYDB_H
       
   311 
       
   312 
       
   313 
       
   314 
       
   315 
       
   316 
       
   317 
       
   318