os/mm/mmlibs/mmfw/tsrc/mmvalidationsuite/mmvalidationsuiteapp/src/SettingsManager.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
sl@0
     1
// Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies).
sl@0
     2
// All rights reserved.
sl@0
     3
// This component and the accompanying materials are made available
sl@0
     4
// under the terms of "Eclipse Public License v1.0"
sl@0
     5
// which accompanies this distribution, and is available
sl@0
     6
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
sl@0
     7
//
sl@0
     8
// Initial Contributors:
sl@0
     9
// Nokia Corporation - initial contribution.
sl@0
    10
//
sl@0
    11
// Contributors:
sl@0
    12
//
sl@0
    13
// Description:
sl@0
    14
// SettingsManage.cpp
sl@0
    15
// Part of the MVS Application for TechView
sl@0
    16
//
sl@0
    17
sl@0
    18
#include "SettingsManager.h"
sl@0
    19
#include "MVSAppUI.h"
sl@0
    20
#include "MVSConfigAudioFormatDialog.h"
sl@0
    21
#include "MVSConfigVideoFormatDialog.h"
sl@0
    22
sl@0
    23
_LIT(KFullPathOfFileStore,"C:\\private\\102737E8\\MvsSettings.dat");	
sl@0
    24
sl@0
    25
CSettingsManager::CSettingsManager()
sl@0
    26
:iStore(0),iHasSettings(1)
sl@0
    27
	{	
sl@0
    28
	
sl@0
    29
	}
sl@0
    30
sl@0
    31
CSettingsManager::~CSettingsManager()
sl@0
    32
	{
sl@0
    33
	iFsSession.Close();  //close the file session
sl@0
    34
	iArrUid.Close();
sl@0
    35
	iArrStreamId.Close();
sl@0
    36
	if(iStore)
sl@0
    37
		{
sl@0
    38
		
sl@0
    39
		}
sl@0
    40
	}
sl@0
    41
sl@0
    42
void CSettingsManager::ConstructL()
sl@0
    43
	{
sl@0
    44
	User::LeaveIfError(iFsSession.Connect()); // start a file session
sl@0
    45
	}
sl@0
    46
	
sl@0
    47
CSettingsManager* CSettingsManager::NewL()
sl@0
    48
	{
sl@0
    49
	CSettingsManager* self = new(ELeave) CSettingsManager();
sl@0
    50
	CleanupStack::PushL(self);
sl@0
    51
	self->ConstructL();
sl@0
    52
	CleanupStack::Pop(self);
sl@0
    53
	return self;
sl@0
    54
	}
sl@0
    55
sl@0
    56
sl@0
    57
TBool CSettingsManager::OpenStore2ReadLC()
sl@0
    58
	{
sl@0
    59
	TParse	fileStoreName;
sl@0
    60
	iFsSession.Parse(KFullPathOfFileStore,fileStoreName);
sl@0
    61
	
sl@0
    62
	iStore = CPermanentFileStore::OpenLC(iFsSession,
sl@0
    63
										fileStoreName.FullName(),
sl@0
    64
										EFileRead );
sl@0
    65
	iHasSettings = ETrue;
sl@0
    66
	return iHasSettings;
sl@0
    67
	}
sl@0
    68
sl@0
    69
void CSettingsManager::OpenStore2WriteLC()
sl@0
    70
	{
sl@0
    71
	TPath privatePath(KFullPathOfFileStore);
sl@0
    72
	iFsSession.PrivatePath(privatePath);
sl@0
    73
	TParse	fileStoreName;
sl@0
    74
	iFsSession.MkDirAll(KFullPathOfFileStore);
sl@0
    75
	iFsSession.Parse(KFullPathOfFileStore,fileStoreName);
sl@0
    76
	
sl@0
    77
	if(iHasSettings)
sl@0
    78
		{
sl@0
    79
		iStore = CPermanentFileStore::OpenLC(iFsSession,
sl@0
    80
											fileStoreName.FullName(),
sl@0
    81
											EFileWrite );
sl@0
    82
		}
sl@0
    83
	else
sl@0
    84
		{
sl@0
    85
		iStore = CPermanentFileStore::CreateLC(iFsSession,
sl@0
    86
											fileStoreName.FullName(),
sl@0
    87
											EFileWrite );
sl@0
    88
		}
sl@0
    89
	
sl@0
    90
	iStore->SetTypeL(KPermanentFileStoreLayoutUid);	 	
sl@0
    91
	}
sl@0
    92
sl@0
    93
sl@0
    94
TBool CSettingsManager::HasSettings()
sl@0
    95
	{
sl@0
    96
	return iHasSettings;
sl@0
    97
	}
sl@0
    98
sl@0
    99
void CSettingsManager::ReadGeneralSettingsL(CMVSAppUi* aAppUI)
sl@0
   100
	{
sl@0
   101
	if(!FileExists())
sl@0
   102
		return;
sl@0
   103
	OpenStore2ReadLC();
sl@0
   104
	RStoreReadStream instream;
sl@0
   105
	iRootId = iStore->Root();
sl@0
   106
	instream.OpenLC(*iStore,iRootId); //open root stream for reading
sl@0
   107
	instream >> iGenSettingsId;
sl@0
   108
	CleanupStack::PopAndDestroy();			
sl@0
   109
	
sl@0
   110
	//check for the validity of the streamid
sl@0
   111
	if(!iGenSettingsId.Value())
sl@0
   112
		{
sl@0
   113
		CleanupStack::PopAndDestroy();
sl@0
   114
		return;
sl@0
   115
		}
sl@0
   116
	
sl@0
   117
	//open the stream for general settings
sl@0
   118
	instream.OpenLC(*iStore,iGenSettingsId); 
sl@0
   119
	aAppUI->InternalizeL(instream);
sl@0
   120
	CleanupStack::PopAndDestroy(2);	
sl@0
   121
	}
sl@0
   122
sl@0
   123
sl@0
   124
void CSettingsManager::WriteGeneralSettingsL(CMVSAppUi* aAppUI)
sl@0
   125
	{	
sl@0
   126
	OpenStore2WriteLC();
sl@0
   127
	
sl@0
   128
	RStoreWriteStream outstream;
sl@0
   129
	/*
sl@0
   130
	if already there is stream id for general settings open the existing
sl@0
   131
	stream; otherwise create new stream id 
sl@0
   132
	*/
sl@0
   133
	TBool updation = iGenSettingsId.Value();
sl@0
   134
	if(updation)
sl@0
   135
		{
sl@0
   136
		outstream.ReplaceLC(*iStore,iGenSettingsId);
sl@0
   137
		}
sl@0
   138
	else
sl@0
   139
		{
sl@0
   140
		iGenSettingsId = outstream.CreateLC(*iStore);
sl@0
   141
		}
sl@0
   142
	
sl@0
   143
	//write the general settings
sl@0
   144
	aAppUI->ExternalizeL(outstream);
sl@0
   145
	outstream.CommitL();
sl@0
   146
	CleanupStack::PopAndDestroy();
sl@0
   147
	
sl@0
   148
	if(!updation)
sl@0
   149
		{
sl@0
   150
		outstream.ReplaceLC(*iStore,iStore->Root());
sl@0
   151
		TUid tempUid;
sl@0
   152
		TStreamId tempStreamId(0);
sl@0
   153
		WriteIndexL(outstream,tempUid,tempStreamId);
sl@0
   154
		CleanupStack::PopAndDestroy();	
sl@0
   155
		}		
sl@0
   156
						
sl@0
   157
	iStore->CommitL();// commit the changes to the store
sl@0
   158
	CleanupStack::PopAndDestroy(); //for iStore 
sl@0
   159
	iFsSession.Close(); //close the file session
sl@0
   160
	}	  
sl@0
   161
sl@0
   162
/*
sl@0
   163
 *This function assumes that the index doesn't exist
sl@0
   164
 */
sl@0
   165
void CSettingsManager::MakeSeedIndexL()
sl@0
   166
	{
sl@0
   167
	OpenStore2WriteLC();
sl@0
   168
	RStoreWriteStream outstream;
sl@0
   169
	TStreamId invalidId(0); //caution: confirm the reliability of this value
sl@0
   170
	iRootId = outstream.CreateLC(*iStore);		
sl@0
   171
	
sl@0
   172
	//write an invalid  stream index for general settings i.e.iGenSettingsId
sl@0
   173
	outstream << invalidId;	 
sl@0
   174
		
sl@0
   175
	//write no. of controllers as 0
sl@0
   176
	outstream.WriteInt8L(0);
sl@0
   177
	
sl@0
   178
	outstream.CommitL(); //commit stream changes
sl@0
   179
	CleanupStack::PopAndDestroy();
sl@0
   180
	
sl@0
   181
	iStore->SetRootL(iRootId);
sl@0
   182
	iStore->CommitL(); //commit changes to store
sl@0
   183
	
sl@0
   184
	CleanupStack::PopAndDestroy(); //for iStore	
sl@0
   185
	}
sl@0
   186
sl@0
   187
// the stream should be in the beginning of controller section
sl@0
   188
void CSettingsManager::ReadControllerTableL(RReadStream& aStream)
sl@0
   189
	{
sl@0
   190
	iControllerCnt = aStream.ReadInt8L();	
sl@0
   191
	TStreamId tempId;
sl@0
   192
	iArrUid.Reset();
sl@0
   193
	iArrStreamId.Reset();
sl@0
   194
	//read the available pairs of Uid - Streamd Ids.
sl@0
   195
	for(TInt8 i = 0; i < iControllerCnt;i++)
sl@0
   196
		{
sl@0
   197
		iArrUid.AppendL(TUid::Uid(aStream.ReadInt32L()));
sl@0
   198
		aStream >> tempId;
sl@0
   199
		iArrStreamId.AppendL(tempId);
sl@0
   200
		}
sl@0
   201
	}
sl@0
   202
sl@0
   203
sl@0
   204
TBool CSettingsManager::IsControllerAvailableL(const TUid& aUid,
sl@0
   205
													  TStreamId&  aStreamId)
sl@0
   206
	{
sl@0
   207
	 // if there is no Store fiel return false
sl@0
   208
	if(!FileExists())
sl@0
   209
		return 0;
sl@0
   210
	OpenStore2ReadLC();
sl@0
   211
	RStoreReadStream instream;
sl@0
   212
	iRootId = iStore->Root();
sl@0
   213
	instream.OpenLC(*iStore,iRootId); //open root stream for reading
sl@0
   214
	instream >> iGenSettingsId;	 //read this to move to controller section
sl@0
   215
	ReadControllerTableL(instream);
sl@0
   216
	CleanupStack::PopAndDestroy(2);			
sl@0
   217
	for(TUint8 i = 0; i < iControllerCnt; i++)
sl@0
   218
		{
sl@0
   219
		if(iArrUid[i] == aUid)
sl@0
   220
			{
sl@0
   221
		  	aStreamId = iArrStreamId[i];
sl@0
   222
		  	return 1;	
sl@0
   223
			}					
sl@0
   224
	 	}
sl@0
   225
	return 0;
sl@0
   226
	}
sl@0
   227
sl@0
   228
sl@0
   229
TInt CSettingsManager::ReadAudioDataL(CMVSConfigAudioFormatDialog* aAudioFormatDlg,
sl@0
   230
 							                 const TUid& aUid)
sl@0
   231
	{
sl@0
   232
	TStreamId controllerId;
sl@0
   233
	// if the controller settings is not available return
sl@0
   234
	if(!IsControllerAvailableL(aUid,controllerId))
sl@0
   235
		return 0;
sl@0
   236
	
sl@0
   237
	//open the store to read
sl@0
   238
	if(!FileExists())
sl@0
   239
		return 0;
sl@0
   240
	OpenStore2ReadLC();
sl@0
   241
	//open the stream of the given controller for reading
sl@0
   242
	RStoreReadStream instream;
sl@0
   243
	instream.OpenLC(*iStore,controllerId);
sl@0
   244
	aAudioFormatDlg->InternalizeL(instream);
sl@0
   245
	CleanupStack::PopAndDestroy(2);
sl@0
   246
	return 1;
sl@0
   247
	}
sl@0
   248
sl@0
   249
void CSettingsManager::WriteAudioDataL(CMVSConfigAudioFormatDialog* aAudioFormat,
sl@0
   250
					  				const TUid& aUid)
sl@0
   251
	{
sl@0
   252
	TStreamId controllerId;		
sl@0
   253
	RStoreWriteStream outstream;
sl@0
   254
	TBool existingController = IsControllerAvailableL(aUid,controllerId);
sl@0
   255
	OpenStore2WriteLC();	
sl@0
   256
	if(!existingController)
sl@0
   257
		{
sl@0
   258
		//if controller settings is not available create new stream
sl@0
   259
		controllerId = outstream.CreateLC(*iStore);		
sl@0
   260
		}
sl@0
   261
	else //open the existing for updation
sl@0
   262
		{
sl@0
   263
		outstream.ReplaceLC(*iStore,controllerId); 				
sl@0
   264
		}
sl@0
   265
	aAudioFormat->ExternalizeL(outstream);
sl@0
   266
	outstream.CommitL();
sl@0
   267
	CleanupStack::PopAndDestroy();
sl@0
   268
	
sl@0
   269
    /*
sl@0
   270
    if there is no updation for controller i.e. new controller settings 
sl@0
   271
    is entered
sl@0
   272
    */
sl@0
   273
	if(!existingController)
sl@0
   274
		{
sl@0
   275
		outstream.ReplaceLC(*iStore,iRootId); 					
sl@0
   276
		WriteIndexL(outstream,aUid,controllerId);
sl@0
   277
		CleanupStack::PopAndDestroy();		
sl@0
   278
		}
sl@0
   279
	iStore->CommitL();
sl@0
   280
	CleanupStack::PopAndDestroy(); //for iStore
sl@0
   281
	}	
sl@0
   282
sl@0
   283
void CSettingsManager::WriteIndexL(RWriteStream& aStream,
sl@0
   284
								  const TUid& aUid,
sl@0
   285
								  TStreamId& aStreamId)
sl@0
   286
	{
sl@0
   287
	TBool bNewPlugin = aStreamId.Value();
sl@0
   288
	TUint8 uchExistingPluginCnt = iControllerCnt;
sl@0
   289
	//write root index
sl@0
   290
	aStream << iGenSettingsId;
sl@0
   291
	
sl@0
   292
	if(bNewPlugin)
sl@0
   293
		{
sl@0
   294
		iControllerCnt++;		
sl@0
   295
		}
sl@0
   296
	
sl@0
   297
	aStream.WriteInt8L(iControllerCnt);
sl@0
   298
	
sl@0
   299
	//write the uid-streamid for existing plugins
sl@0
   300
	for(TUint8 i = 0; i < uchExistingPluginCnt; i++)
sl@0
   301
		{
sl@0
   302
		aStream.WriteInt32L(iArrUid[i].iUid); //write uid
sl@0
   303
		aStream << 	iArrStreamId[i];	 //write streamid
sl@0
   304
		}
sl@0
   305
	
sl@0
   306
	if(!bNewPlugin)
sl@0
   307
		{
sl@0
   308
		aStream.CommitL();
sl@0
   309
		return;	
sl@0
   310
		}
sl@0
   311
	
sl@0
   312
	//write uid-streamId for new plugin
sl@0
   313
	aStream.WriteInt32L(aUid.iUid); //write uid
sl@0
   314
	aStream << aStreamId;			//write streamid
sl@0
   315
		
sl@0
   316
	iArrUid.AppendL(aUid);
sl@0
   317
	iArrStreamId.AppendL(aStreamId);	
sl@0
   318
	aStream.CommitL();		
sl@0
   319
	}
sl@0
   320
sl@0
   321
sl@0
   322
TBool CSettingsManager::ReadVideoDataL(CMVSConfigVideoFormatDialog* aVideoFormatDlg,
sl@0
   323
 							          const TUid& aUid)
sl@0
   324
	{
sl@0
   325
	TStreamId controllerId;
sl@0
   326
	// if the controller settings is not available return
sl@0
   327
	if(!IsControllerAvailableL(aUid,controllerId))
sl@0
   328
		return 0;
sl@0
   329
	
sl@0
   330
	//open the store to read
sl@0
   331
	if(!FileExists())
sl@0
   332
		return 0;
sl@0
   333
	OpenStore2ReadLC();
sl@0
   334
	//open the stream of the given controller for reading
sl@0
   335
	RStoreReadStream instream;
sl@0
   336
	instream.OpenLC(*iStore,controllerId);
sl@0
   337
	aVideoFormatDlg->InternalizeL(instream);
sl@0
   338
	CleanupStack::PopAndDestroy(2); 
sl@0
   339
	return 1;
sl@0
   340
	}
sl@0
   341
sl@0
   342
sl@0
   343
void  CSettingsManager::WriteVideoDataL( CMVSConfigVideoFormatDialog* aVideoFormatDlg,
sl@0
   344
						 				const TUid& aUid)
sl@0
   345
	{
sl@0
   346
	TStreamId controllerId;		
sl@0
   347
	RStoreWriteStream outstream;
sl@0
   348
	TBool existingController = IsControllerAvailableL(aUid,controllerId);
sl@0
   349
	OpenStore2WriteLC();	
sl@0
   350
	if(!existingController)
sl@0
   351
		{
sl@0
   352
		//if controller settings is not available create new stream
sl@0
   353
		controllerId = outstream.CreateLC(*iStore);		
sl@0
   354
		}
sl@0
   355
	else //open the existing for updation
sl@0
   356
		{
sl@0
   357
		outstream.ReplaceLC(*iStore,controllerId); 				
sl@0
   358
		}
sl@0
   359
	aVideoFormatDlg->ExternalizeL(outstream);
sl@0
   360
	outstream.CommitL();
sl@0
   361
	CleanupStack::PopAndDestroy();
sl@0
   362
	
sl@0
   363
    /*
sl@0
   364
    if there is no updation for controller i.e. new controller settings 
sl@0
   365
    is entered
sl@0
   366
    */
sl@0
   367
	if(!existingController)
sl@0
   368
		{
sl@0
   369
		outstream.ReplaceLC(*iStore,iRootId); 					
sl@0
   370
		WriteIndexL(outstream,aUid,controllerId);
sl@0
   371
		CleanupStack::PopAndDestroy();		
sl@0
   372
		}
sl@0
   373
	iStore->CommitL();
sl@0
   374
	CleanupStack::PopAndDestroy(); //for iStore	
sl@0
   375
	}
sl@0
   376
sl@0
   377
TBool CSettingsManager::FileExists()
sl@0
   378
	{
sl@0
   379
	TParse fileStoreName;
sl@0
   380
	iFsSession.Parse(KFullPathOfFileStore,fileStoreName);
sl@0
   381
	//check whether a settings file already exists
sl@0
   382
	RFile file;
sl@0
   383
	if(file.Open(iFsSession,fileStoreName.FullName(),EFileRead)!= KErrNone) // if the file doesn't exist already
sl@0
   384
		{
sl@0
   385
		iHasSettings = 0;
sl@0
   386
		return EFalse;
sl@0
   387
		}
sl@0
   388
	file.Close();
sl@0
   389
	return ETrue;
sl@0
   390
	}