idlehomescreen/widgetmanager/src/wmpersistentwidgetorder.cpp
branchRCL_3
changeset 11 ff572dfe6d86
parent 9 f966699dea19
equal deleted inserted replaced
9:f966699dea19 11:ff572dfe6d86
    21 #include <s32std.h> // streams
    21 #include <s32std.h> // streams
    22 #include <driveinfo.h>
    22 #include <driveinfo.h>
    23 #include <sysutil.h> 
    23 #include <sysutil.h> 
    24 
    24 
    25 #include "wmwidgetdata.h"
    25 #include "wmwidgetdata.h"
       
    26 #include "wmwidgetorderdata.h"
    26 #include "wmpersistentwidgetorder.h"
    27 #include "wmpersistentwidgetorder.h"
    27 
    28 
    28 // CONSTANTS
    29 // CONSTANTS
    29 _LIT( KStoreFileName, "wmlistorder.dat" );
    30 _LIT( KStoreFileName, "wmlistorder.dat" );
    30 
    31 
    65 // ---------------------------------------------------------
    66 // ---------------------------------------------------------
    66 //
    67 //
    67 CWmPersistentWidgetOrder::~CWmPersistentWidgetOrder()
    68 CWmPersistentWidgetOrder::~CWmPersistentWidgetOrder()
    68     {
    69     {
    69     CleanupArray();
    70     CleanupArray();
       
    71     iTagArray.Close();
    70     }
    72     }
    71 
    73 
    72 // ---------------------------------------------------------
    74 // ---------------------------------------------------------
    73 // CWmPersistentWidgetOrder::LoadL
    75 // CWmPersistentWidgetOrder::LoadL
    74 // ---------------------------------------------------------
    76 // ---------------------------------------------------------
   105 
   107 
   106 // ---------------------------------------------------------
   108 // ---------------------------------------------------------
   107 // CWmPersistentWidgetOrder::StoreL
   109 // CWmPersistentWidgetOrder::StoreL
   108 // ---------------------------------------------------------
   110 // ---------------------------------------------------------
   109 //
   111 //
   110 void CWmPersistentWidgetOrder::StoreL( const RWidgetDataValues& aArray )
   112 void CWmPersistentWidgetOrder::StoreL( const ROrderArray& aArray )
   111     {
   113     {
       
   114 
   112     // 1. create stream for storing the data to a file
   115     // 1. create stream for storing the data to a file
   113     TFileName storeFileName;
   116     TFileName storeFileName;
   114     GetStoreFileNameL( storeFileName );
   117     GetStoreFileNameL( storeFileName );
   115     CPermanentFileStore* fileStore = NULL;
   118     CPermanentFileStore* fileStore = NULL;
   116     fileStore = CPermanentFileStore::ReplaceLC(
   119     fileStore = CPermanentFileStore::ReplaceLC(
   117             iFs, storeFileName, EFileWrite );
   120             iFs, storeFileName, EFileWrite );
   118     fileStore->SetTypeL( KPermanentFileStoreLayoutUid );
   121     
   119     RStoreWriteStream writer;
   122     if ( fileStore )
   120     TStreamId id = writer.CreateLC( *fileStore );
   123         {
   121     // 2. write all content to the stream
   124         fileStore->SetTypeL( KPermanentFileStoreLayoutUid );
   122     writer.WriteInt32L( aArray.Count() );
   125         RStoreWriteStream writer;
   123     for( TInt i=0; i<aArray.Count(); ++i )
   126         TStreamId id = writer.CreateLC( *fileStore );
   124         {
   127         
   125         CWmWidgetData* data = aArray[i];
   128         // 2. write all content to the stream
   126         if ( !data || !data->IsValid() )
   129         writer.WriteInt32L( aArray.Count() );
       
   130         for( TInt i=0; i<aArray.Count(); ++i )
   127             {
   131             {
   128             User::Leave( KErrArgument ); 
   132             CWmWidgetOrderData* data = aArray[i];
       
   133             
       
   134             if ( !data  )
       
   135                 {
       
   136                 User::Leave( KErrArgument ); 
       
   137                 }
       
   138             TInt32 uid = data->Uid().iUid;
       
   139             const TDesC16& publisherId = data->PublisherId();
       
   140             writer.WriteInt32L( uid );
       
   141             writer.WriteInt32L( publisherId.Length() );
       
   142             writer.WriteL( publisherId, publisherId.Length() );
       
   143             
   129             }
   144             }
   130         TInt32 uid = data->Uid().iUid;
   145         // 3. check available space and commit the stream
   131         const TDesC16& publisherId = data->HsContentInfo().PublisherId();
   146         TInt streamsize = writer.Sink()->SizeL();
   132         writer.WriteInt32L( uid );
   147         TBool belowCriticalLevel = SysUtil::DiskSpaceBelowCriticalLevelL(
   133         writer.WriteInt32L( publisherId.Length() );
   148                 &iFs, streamsize, EDriveC );
   134         writer.WriteL( publisherId, publisherId.Length() );
   149         
   135         }
   150         if( !belowCriticalLevel )
   136     // 3. check available space and commit the stream
   151             {
   137     TInt streamsize = writer.Sink()->SizeL();
   152             writer.CommitL();
   138     TBool belowCriticalLevel = SysUtil::DiskSpaceBelowCriticalLevelL(
   153             fileStore->SetRootL(id);
   139             &iFs, streamsize, EDriveC );
   154             fileStore->CommitL();        
   140     if( !belowCriticalLevel )
   155             }
   141         {
   156         
   142         writer.CommitL();
   157         // 4. cleanup
   143         fileStore->SetRootL(id);
   158         CleanupStack::PopAndDestroy( &writer );        
   144         fileStore->CommitL();        
   159         CleanupStack::PopAndDestroy( fileStore );
   145         }
   160         }
   146     // 4. cleanup
   161     
   147     CleanupStack::PopAndDestroy( &writer );
       
   148     CleanupStack::PopAndDestroy( fileStore );
       
   149     }
   162     }
   150 
   163 
   151 // ---------------------------------------------------------
   164 // ---------------------------------------------------------
   152 // CWmPersistentWidgetOrder::CleanupArray
   165 // CWmPersistentWidgetOrder::CleanupArray
   153 // ---------------------------------------------------------
   166 // ---------------------------------------------------------
   155 void CWmPersistentWidgetOrder::CleanupArray()
   168 void CWmPersistentWidgetOrder::CleanupArray()
   156     {
   169     {
   157     for( TInt i=0; i<iTagArray.Count(); ++i )
   170     for( TInt i=0; i<iTagArray.Count(); ++i )
   158         {
   171         {
   159         delete iTagArray[i].iPublisherId;
   172         delete iTagArray[i].iPublisherId;
   160         iTagArray[i].iPublisherId = 0;
   173         iTagArray[i].iPublisherId = NULL;
   161         }
   174         }
   162     iTagArray.Close();
   175     iTagArray.Reset();
   163     }
   176     }
   164 
   177 
   165 // ---------------------------------------------------------
   178 // ---------------------------------------------------------
   166 // CWmPersistentWidgetOrder::GetStoreFileNameL
   179 // CWmPersistentWidgetOrder::GetStoreFileNameL
   167 // ---------------------------------------------------------
   180 // ---------------------------------------------------------
   209     {
   222     {
   210     return iTagArray.Count() == 0;
   223     return iTagArray.Count() == 0;
   211     }
   224     }
   212 
   225 
   213 // ---------------------------------------------------------
   226 // ---------------------------------------------------------
       
   227 // CWmPersistentWidgetOrder::IndexOf
       
   228 // ---------------------------------------------------------
       
   229 //
       
   230 TInt CWmPersistentWidgetOrder::IndexOf( 
       
   231         const CWmWidgetOrderData& aWidgetOrder ) const
       
   232     {
       
   233     TInt found = KErrNotFound;
       
   234     for( TInt i=0; i<iTagArray.Count() && found<0; ++i )
       
   235         {
       
   236         if ( iTagArray[i].Matches( aWidgetOrder ) )
       
   237             found = i;
       
   238         }
       
   239     return found;
       
   240     }
       
   241 
       
   242 // ---------------------------------------------------------
   214 // CWmPersistentWidgetOrder::Tag::Tag
   243 // CWmPersistentWidgetOrder::Tag::Tag
   215 // ---------------------------------------------------------
   244 // ---------------------------------------------------------
   216 //
   245 //
   217 CWmPersistentWidgetOrder::Tag::Tag(
   246 CWmPersistentWidgetOrder::Tag::Tag(
   218         TInt32 aUid, HBufC16* aPublisherId )
   247         TInt32 aUid, HBufC16* aPublisherId )
   230     {
   259     {
   231     return ( aWidgetData.Uid().iUid == iUid &&
   260     return ( aWidgetData.Uid().iUid == iUid &&
   232             aWidgetData.HsContentInfo().PublisherId() == *iPublisherId );
   261             aWidgetData.HsContentInfo().PublisherId() == *iPublisherId );
   233     }
   262     }
   234 
   263 
       
   264 // ---------------------------------------------------------
       
   265 // CWmPersistentWidgetOrder::Tag::Matches
       
   266 // ---------------------------------------------------------
       
   267 //
       
   268 TBool CWmPersistentWidgetOrder::Tag::Matches(
       
   269         const CWmWidgetOrderData& aWidgetOrder ) const
       
   270     {
       
   271     return ( aWidgetOrder.Uid().iUid == iUid &&
       
   272             aWidgetOrder.PublisherId() == *iPublisherId );
       
   273     }
   235 
   274 
   236 // end of file
   275 // end of file