You Are Here:

Community: Wiki

This page was last modified on 18 September 2009, at 16:07.

Saving settings with Dictionary store

From Forum Nokia Wiki

Reviewer Approved   

Dictionary store nearly perfect solution for storing settings data, in general it is simpler to use than other stores, with it you can set your own UID for each stream in the store, thus you can find them easily when reading the setting back.

Following functions are illustrating how to store and load settings items from the store. With Dictionary stores there is small problem which causes the store file size to increase over time, as shown in the SaveValuesL()-function with this example this problem is fixed by deleting the store each time any changes are done.

Streams inside the Dictionary store are accessed by using Dictionary store read/write streams. For internalizing and externalizing you could use << and >> operator, as illustrated with the iName variable, for integers you should use the functions provided by read/write stream as shown with iIndex variable. There are separate functions for 8,16,32 and 64 bit wide signed/unsigned integers as well as for byte buffers.

As illustrated with the iBitmap variable you can also use InternalizeL/ExternalizeL functions provided by the class itself for reading and writing to the Dictionary store.

Note that when opening Dictionary store, you need to know the UID of the store (in example 0xDEADBEEF is used as store UID), using wrong value will cause a leave.

_LIT(KtxDicFileName			,":\\private\\<My SID>\\MyDicFile.ini" );
 
const TInt KIndexUID = 0x1000;
const TInt KImageUID = 0x2000;
const TInt KNameUID = 0x3000;
 
 
class CExampleItem : public CBase
{
public:
CExampleItem(): iIndex(-1){};
~CExampleItem(){ delete iBitmap;};
public:
TInt iIndex;
TBuf<100> iName;
CWsBitmap* iBitmap
};
 
 
 
void LoadValuesL(CExampleItem& aItem)
{
TFindFile AufFolder(CCoeEnv::Static()->FsSession());
if(KErrNone == AufFolder.FindByDir(KtxDicFileName, KNullDesC))
{
CDictionaryFileStore* MyDStore = CDictionaryFileStore::OpenLC(CCoeEnv::Static()->FsSession(),AufFolder.File(), TUid::Uid(0xDEADBEEF));
 
TUid FileUid = {0x0};
FileUid.iUid = KIndexUID;
 
if(aDStore->IsPresentL(FileUid))
{
RDictionaryReadStream in;
in.OpenLC(*aDStore,FileUid);
aItem.iIndex = in.ReadInt32L();
CleanupStack::PopAndDestroy(1);// in
}
 
FileUid.iUid = KNameUID;
if(aDStore->IsPresentL(FileUid))
{
RDictionaryReadStream in;
in.OpenLC(*aDStore,FileUid);
in >> aItem.iName;
CleanupStack::PopAndDestroy(1);// in
}
 
FileUid.iUid = KImageUID;
if(aDStore->IsPresentL(FileUid))
{
aItem.iBitmap = new(ELeave)CWsBitmap(CCoeEnv::Static()->WsSession());
 
RDictionaryReadStream in;
in.OpenLC(*aDStore,FileUid);
aItem.iBitmap->InternalizeL(in);
CleanupStack::PopAndDestroy(1);// in
}
 
CleanupStack::PopAndDestroy(1);// Store
}
}
 
 
void SaveValuesL(CExampleItem& aItem)
{
TFindFile AufFolder(CCoeEnv::Static()->FsSession());
if(KErrNone == AufFolder.FindByDir(KtxDicFileName, KNullDesC))
{
User::LeaveIfError(CCoeEnv::Static()->FsSession().Delete(AufFolder.File()));
 
CDictionaryFileStore* MyDStore = CDictionaryFileStore::OpenLC(CCoeEnv::Static()->FsSession(),AufFolder.File(), TUid::Uid(0xDEADBEEF));
 
TUid FileUid = {0x0};
FileUid.iUid = KIndexUID;
 
RDictionaryWriteStream out1;
out1.AssignLC(*MyDStore,FileUid);
out1.WriteInt32L(aItem.iIndex);
out1.CommitL();
CleanupStack::PopAndDestroy(1);// out1
 
FileUid.iUid = KNameUID;
RDictionaryWriteStream out2;
out2.AssignLC(*MyDStore,FileUid);
out2 << aItem.iName;
out2.CommitL();
CleanupStack::PopAndDestroy(1);// out2
 
FileUid.iUid = KImageUID;
RDictionaryWriteStream out3;
out3.AssignLC(*MyDStore,FileUid);
aItem.iBitmap->ExternalizeL(out3);
out3.CommitL();
CleanupStack::PopAndDestroy(1);// out3
 
MyDStore->CommitL();
CleanupStack::PopAndDestroy(1);// Store
}
}


Other Related Links

Using .ini Files Insert non-formatted text here

Related Wiki Articles

No related wiki articles found

Rate This

 
Bookmark this page: DeliciousDiggFacebookGoogleYahooStumbleUponRedditDiigoTechnocratiTwitter  Share this page Share this page Print this Page Print this page Invite a friend Invite a friend
京ICP备05048969号    Email Newsletters Press Terms & Conditions Privacy Policy Sitemap Contact Us © 2009 Nokia 
RDF Facets: qdcZidentifierQSxhttpE3aE2fE2fwikiE2eforumE2enokiaE2ecomE2findeE78E2ephpE2fTalkE3aE4cargeE5fscreenE5fsaverX qdcZtypeQUqfnZE45E78cludedFromGeneralE4cistingsQ qdcZtypeQUqfntypeZCommunityContentQ qdcZtypeQUqfntypeZE52esourceQ qdcZtypeQUqfntypeZWebpageQ qdcZtypeQUqfntypeZWikiContentQ qdcZtypeQUqmarsZManagedE52esourceQ qdcZtypeQUqwebZInformationE52esourceQ qdcZtypeQUqwebZPageQ qdcZtypeQUqwebZE52esourceQ qdcZtypeQUqrdfsZE52esourceQ qfnZtypeQUqfntypeZCommunityContentQ qfnZtypeQUqfntypeZE52esourceQ qfnZtypeQUqfntypeZWebpageQ qfnZtypeQUqfntypeZWikiContentQ qmarsZlanguageQUxhttpE3aE2fE2fswE2enokiaE2ecomE2flanguageE2d1E2fenX qrdfZtypeQUqfnZE45E78cludedFromGeneralE4cistingsQ qrdfZtypeQUqfntypeZCommunityContentQ qrdfZtypeQUqfntypeZE52esourceQ qrdfZtypeQUqfntypeZWebpageQ qrdfZtypeQUqfntypeZWikiContentQ qrdfZtypeQUqmarsZManagedE52esourceQ qrdfZtypeQUqwebZInformationE52esourceQ qrdfZtypeQUqwebZPageQ qrdfZtypeQUqwebZE52esourceQ qrdfZtypeQUqrdfsZE52esourceQ