os/mm/mmlibs/mmfw/tsrc/mmvalidationsuite/mmvalidationsuiteapp/src/SettingsManager.cpp
Update contrib.
1 // Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies).
2 // All rights reserved.
3 // This component and the accompanying materials are made available
4 // under the terms of "Eclipse Public License v1.0"
5 // which accompanies this distribution, and is available
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
15 // Part of the MVS Application for TechView
18 #include "SettingsManager.h"
20 #include "MVSConfigAudioFormatDialog.h"
21 #include "MVSConfigVideoFormatDialog.h"
23 _LIT(KFullPathOfFileStore,"C:\\private\\102737E8\\MvsSettings.dat");
25 CSettingsManager::CSettingsManager()
26 :iStore(0),iHasSettings(1)
31 CSettingsManager::~CSettingsManager()
33 iFsSession.Close(); //close the file session
42 void CSettingsManager::ConstructL()
44 User::LeaveIfError(iFsSession.Connect()); // start a file session
47 CSettingsManager* CSettingsManager::NewL()
49 CSettingsManager* self = new(ELeave) CSettingsManager();
50 CleanupStack::PushL(self);
52 CleanupStack::Pop(self);
57 TBool CSettingsManager::OpenStore2ReadLC()
60 iFsSession.Parse(KFullPathOfFileStore,fileStoreName);
62 iStore = CPermanentFileStore::OpenLC(iFsSession,
63 fileStoreName.FullName(),
69 void CSettingsManager::OpenStore2WriteLC()
71 TPath privatePath(KFullPathOfFileStore);
72 iFsSession.PrivatePath(privatePath);
74 iFsSession.MkDirAll(KFullPathOfFileStore);
75 iFsSession.Parse(KFullPathOfFileStore,fileStoreName);
79 iStore = CPermanentFileStore::OpenLC(iFsSession,
80 fileStoreName.FullName(),
85 iStore = CPermanentFileStore::CreateLC(iFsSession,
86 fileStoreName.FullName(),
90 iStore->SetTypeL(KPermanentFileStoreLayoutUid);
94 TBool CSettingsManager::HasSettings()
99 void CSettingsManager::ReadGeneralSettingsL(CMVSAppUi* aAppUI)
104 RStoreReadStream instream;
105 iRootId = iStore->Root();
106 instream.OpenLC(*iStore,iRootId); //open root stream for reading
107 instream >> iGenSettingsId;
108 CleanupStack::PopAndDestroy();
110 //check for the validity of the streamid
111 if(!iGenSettingsId.Value())
113 CleanupStack::PopAndDestroy();
117 //open the stream for general settings
118 instream.OpenLC(*iStore,iGenSettingsId);
119 aAppUI->InternalizeL(instream);
120 CleanupStack::PopAndDestroy(2);
124 void CSettingsManager::WriteGeneralSettingsL(CMVSAppUi* aAppUI)
128 RStoreWriteStream outstream;
130 if already there is stream id for general settings open the existing
131 stream; otherwise create new stream id
133 TBool updation = iGenSettingsId.Value();
136 outstream.ReplaceLC(*iStore,iGenSettingsId);
140 iGenSettingsId = outstream.CreateLC(*iStore);
143 //write the general settings
144 aAppUI->ExternalizeL(outstream);
146 CleanupStack::PopAndDestroy();
150 outstream.ReplaceLC(*iStore,iStore->Root());
152 TStreamId tempStreamId(0);
153 WriteIndexL(outstream,tempUid,tempStreamId);
154 CleanupStack::PopAndDestroy();
157 iStore->CommitL();// commit the changes to the store
158 CleanupStack::PopAndDestroy(); //for iStore
159 iFsSession.Close(); //close the file session
163 *This function assumes that the index doesn't exist
165 void CSettingsManager::MakeSeedIndexL()
168 RStoreWriteStream outstream;
169 TStreamId invalidId(0); //caution: confirm the reliability of this value
170 iRootId = outstream.CreateLC(*iStore);
172 //write an invalid stream index for general settings i.e.iGenSettingsId
173 outstream << invalidId;
175 //write no. of controllers as 0
176 outstream.WriteInt8L(0);
178 outstream.CommitL(); //commit stream changes
179 CleanupStack::PopAndDestroy();
181 iStore->SetRootL(iRootId);
182 iStore->CommitL(); //commit changes to store
184 CleanupStack::PopAndDestroy(); //for iStore
187 // the stream should be in the beginning of controller section
188 void CSettingsManager::ReadControllerTableL(RReadStream& aStream)
190 iControllerCnt = aStream.ReadInt8L();
193 iArrStreamId.Reset();
194 //read the available pairs of Uid - Streamd Ids.
195 for(TInt8 i = 0; i < iControllerCnt;i++)
197 iArrUid.AppendL(TUid::Uid(aStream.ReadInt32L()));
199 iArrStreamId.AppendL(tempId);
204 TBool CSettingsManager::IsControllerAvailableL(const TUid& aUid,
205 TStreamId& aStreamId)
207 // if there is no Store fiel return false
211 RStoreReadStream instream;
212 iRootId = iStore->Root();
213 instream.OpenLC(*iStore,iRootId); //open root stream for reading
214 instream >> iGenSettingsId; //read this to move to controller section
215 ReadControllerTableL(instream);
216 CleanupStack::PopAndDestroy(2);
217 for(TUint8 i = 0; i < iControllerCnt; i++)
219 if(iArrUid[i] == aUid)
221 aStreamId = iArrStreamId[i];
229 TInt CSettingsManager::ReadAudioDataL(CMVSConfigAudioFormatDialog* aAudioFormatDlg,
232 TStreamId controllerId;
233 // if the controller settings is not available return
234 if(!IsControllerAvailableL(aUid,controllerId))
237 //open the store to read
241 //open the stream of the given controller for reading
242 RStoreReadStream instream;
243 instream.OpenLC(*iStore,controllerId);
244 aAudioFormatDlg->InternalizeL(instream);
245 CleanupStack::PopAndDestroy(2);
249 void CSettingsManager::WriteAudioDataL(CMVSConfigAudioFormatDialog* aAudioFormat,
252 TStreamId controllerId;
253 RStoreWriteStream outstream;
254 TBool existingController = IsControllerAvailableL(aUid,controllerId);
256 if(!existingController)
258 //if controller settings is not available create new stream
259 controllerId = outstream.CreateLC(*iStore);
261 else //open the existing for updation
263 outstream.ReplaceLC(*iStore,controllerId);
265 aAudioFormat->ExternalizeL(outstream);
267 CleanupStack::PopAndDestroy();
270 if there is no updation for controller i.e. new controller settings
273 if(!existingController)
275 outstream.ReplaceLC(*iStore,iRootId);
276 WriteIndexL(outstream,aUid,controllerId);
277 CleanupStack::PopAndDestroy();
280 CleanupStack::PopAndDestroy(); //for iStore
283 void CSettingsManager::WriteIndexL(RWriteStream& aStream,
285 TStreamId& aStreamId)
287 TBool bNewPlugin = aStreamId.Value();
288 TUint8 uchExistingPluginCnt = iControllerCnt;
290 aStream << iGenSettingsId;
297 aStream.WriteInt8L(iControllerCnt);
299 //write the uid-streamid for existing plugins
300 for(TUint8 i = 0; i < uchExistingPluginCnt; i++)
302 aStream.WriteInt32L(iArrUid[i].iUid); //write uid
303 aStream << iArrStreamId[i]; //write streamid
312 //write uid-streamId for new plugin
313 aStream.WriteInt32L(aUid.iUid); //write uid
314 aStream << aStreamId; //write streamid
316 iArrUid.AppendL(aUid);
317 iArrStreamId.AppendL(aStreamId);
322 TBool CSettingsManager::ReadVideoDataL(CMVSConfigVideoFormatDialog* aVideoFormatDlg,
325 TStreamId controllerId;
326 // if the controller settings is not available return
327 if(!IsControllerAvailableL(aUid,controllerId))
330 //open the store to read
334 //open the stream of the given controller for reading
335 RStoreReadStream instream;
336 instream.OpenLC(*iStore,controllerId);
337 aVideoFormatDlg->InternalizeL(instream);
338 CleanupStack::PopAndDestroy(2);
343 void CSettingsManager::WriteVideoDataL( CMVSConfigVideoFormatDialog* aVideoFormatDlg,
346 TStreamId controllerId;
347 RStoreWriteStream outstream;
348 TBool existingController = IsControllerAvailableL(aUid,controllerId);
350 if(!existingController)
352 //if controller settings is not available create new stream
353 controllerId = outstream.CreateLC(*iStore);
355 else //open the existing for updation
357 outstream.ReplaceLC(*iStore,controllerId);
359 aVideoFormatDlg->ExternalizeL(outstream);
361 CleanupStack::PopAndDestroy();
364 if there is no updation for controller i.e. new controller settings
367 if(!existingController)
369 outstream.ReplaceLC(*iStore,iRootId);
370 WriteIndexL(outstream,aUid,controllerId);
371 CleanupStack::PopAndDestroy();
374 CleanupStack::PopAndDestroy(); //for iStore
377 TBool CSettingsManager::FileExists()
379 TParse fileStoreName;
380 iFsSession.Parse(KFullPathOfFileStore,fileStoreName);
381 //check whether a settings file already exists
383 if(file.Open(iFsSession,fileStoreName.FullName(),EFileRead)!= KErrNone) // if the file doesn't exist already