internetradio2.0/favoritesdbsrc/irfavoritesdb.cpp
changeset 3 ee64f059b8e1
parent 0 09774dfdd46b
child 5 0930554dc389
equal deleted inserted replaced
2:2e1adbfc62af 3:ee64f059b8e1
    25 #include "irpreset.h"
    25 #include "irpreset.h"
    26 #include "irsettings.h"
    26 #include "irsettings.h"
    27 
    27 
    28 const TInt KNullId = 0;
    28 const TInt KNullId = 0;
    29 const TInt KNineteen = 19;
    29 const TInt KNineteen = 19;
    30 const TInt KFifty = 50;
       
    31 
    30 
    32 namespace PresetHandler
    31 namespace PresetHandler
    33 {
    32 {
    34 //-------------------------------------------------------------------------------
    33 //-------------------------------------------------------------------------------
    35 //TInt OrderByIndex( const CIRPresetImpl& aPreset1, const CIRPresetImpl& aPreset2 )
    34 //TInt OrderByIndex( const CIRPresetImpl& aPreset1, const CIRPresetImpl& aPreset2 )
   104     //resets the preset array
   103     //resets the preset array
   105     iFavPresetList.ResetAndDestroy();
   104     iFavPresetList.ResetAndDestroy();
   106     iFavPresetList.Close();
   105     iFavPresetList.Close();
   107     iServ.Close();
   106     iServ.Close();
   108 
   107 
   109     if (iSettings)
       
   110         {
       
   111     	iSettings->Close();
       
   112         }
       
   113 
       
   114 	IRLOG_DEBUG( "CIRFavoritesDb::~CIRFavoritesDb - Exiting." );
   108 	IRLOG_DEBUG( "CIRFavoritesDb::~CIRFavoritesDb - Exiting." );
   115     }
   109     }
   116 
   110 
   117 
   111 
   118 //---------------------------------------------------------------------------
   112 //---------------------------------------------------------------------------
   144         }
   138         }
   145     }
   139     }
   146     else
   140     else
   147     {
   141     {
   148         searchResult = SearchPreset( aPreset.GetId(), KNullId );
   142         searchResult = SearchPreset( aPreset.GetId(), KNullId );
   149     }
   143         if( KErrNotFound !=  searchResult)
   150     
   144         {
   151     if( KErrNotFound !=  searchResult)
   145             //Eventhough the preset exists in the favorites db, replace the
   152     {
   146             //same with the new preset i.e. aPreset.  Because the db should 
   153         //Eventhough the preset exists in the favorites db, replace the
   147             //contain the updated values of the preset.
   154         //same with the new preset i.e. aPreset.  Because the db should 
   148             ReplacePresetL(aPreset);
   155         //contain the updated values of the preset.
   149             
   156         ReplacePresetL(aPreset);
   150             aRetVal = KErrAlreadyExists;
   157         
   151 
   158         aRetVal = KErrAlreadyExists;
   152             return;
   159 
   153         }
   160         return;
       
   161     }
   154     }
   162 
   155 
   163     if ( EmptyPresetCount()<=0 )
   156     if ( EmptyPresetCount()<=0 )
   164 	{
   157 	{
   165 	 	//max limit reached no more processing
   158 	 	//max limit reached no more processing
   235 EXPORT_C void CIRFavoritesDb::DeletePresetL( TInt aId )
   228 EXPORT_C void CIRFavoritesDb::DeletePresetL( TInt aId )
   236 	{
   229 	{
   237 	IRLOG_DEBUG( "CIRFavoritesDb::DeletePresetL" );
   230 	IRLOG_DEBUG( "CIRFavoritesDb::DeletePresetL" );
   238     iMoveStatus=EFalse;
   231     iMoveStatus=EFalse;
   239 	iServ.DeletePresetL( aId);
   232 	iServ.DeletePresetL( aId);
       
   233 	
       
   234 	TInt count = iFavPresetList.Count();
       
   235 	//when we delete one preset in the server's db, we also
       
   236 	//need to delete it in the favorite list. 
       
   237 	for( TInt i=0; i<count; i++ )
       
   238 	{	     
       
   239 	    if( aId == iFavPresetList[i]->Id())
       
   240 	    {
       
   241 	        iFavPresetList.Remove(i);	         
       
   242 	        break;
       
   243 	    }
       
   244 	}
   240 	IRLOG_DEBUG( "CIRFavoritesDb::DeletePresetL - Exiting." );
   245 	IRLOG_DEBUG( "CIRFavoritesDb::DeletePresetL - Exiting." );
   241 	}
   246 	}
   242 
   247 
   243 //---------------------------------------------------------------------------
   248 //---------------------------------------------------------------------------
   244 //CIRFavoritesDb::GetAllPresetL()
   249 //CIRFavoritesDb::GetAllPresetL()
   583 
   588 
   584 void CIRFavoritesDb::ConstructL()
   589 void CIRFavoritesDb::ConstructL()
   585 	{
   590 	{
   586 	IRLOG_DEBUG( "CIRFavoritesDb::ConstructL" );
   591 	IRLOG_DEBUG( "CIRFavoritesDb::ConstructL" );
   587 	//cenrep handle
   592 	//cenrep handle
   588     iSettings = CIRSettings::OpenL();
   593     CIRSettings *settings = CIRSettings::OpenL();
   589     iSettings->SetMaxPresetCountL(KFifty);
   594     iMaxPresetCount=settings->MaxPresetCount();
       
   595     settings->Close();
       
   596     
   590 	User::LeaveIfError( iServ.Connect() );
   597 	User::LeaveIfError( iServ.Connect() );
   591 	//a session to the client of the preset server
   598 	//a session to the client of the preset server
   592     iServ.GetPresetsL( iFavPresetList, KIRPreset );
   599     iServ.GetPresetsL( iFavPresetList, KIRPreset );
   593     //notifier
   600     //notifier
   594     iNotifier = CPSPresetNotifier::NewL( iServ, *this );
   601     iNotifier = CPSPresetNotifier::NewL( iServ, *this );
   595     //cenrep.
   602     
   596     iMaxPresetCount=iSettings->MaxPresetCount();
       
   597     //initialization of the list for UI use
   603     //initialization of the list for UI use
   598 	//iFavPresetList=new(ELeave)CArrayPtrFlat<CIRPreset>(KGranularity)
   604 	//iFavPresetList=new(ELeave)CArrayPtrFlat<CIRPreset>(KGranularity)
   599 	iMoveStatus=EFalse;
   605 	iMoveStatus=EFalse;
   600 	IRLOG_DEBUG( "CIRFavoritesDb::ConstructL - Exiting." );
   606 	IRLOG_DEBUG( "CIRFavoritesDb::ConstructL - Exiting." );
   601 	}
   607 	}