xdmprotocols/LocalProtocol/src/LocalDirectory.cpp
branchGCC_SURGE
changeset 28 d9861ae9169c
parent 23 77cb48a03620
parent 26 04ca1926b01c
equal deleted inserted replaced
23:77cb48a03620 28:d9861ae9169c
     1 /*
       
     2 * Copyright (c) 2005 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description: CLocalDirectory
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 
       
    21 // INCLUDE FILES
       
    22 #include <utf.h>
       
    23 #include <f32file.h>
       
    24 #include "LocalProtocol.h"
       
    25 #include "LocalDocument.h"
       
    26 #include "LocalDirectory.h"
       
    27 #include "XdmDocumentNode.h"
       
    28 #include "XdmNodeAttribute.h"
       
    29 #include "LocalDirectoryEntry.h"
       
    30 
       
    31 
       
    32 // ----------------------------------------------------------
       
    33 // CLocalDirectory::CLocalDirectory
       
    34 // 
       
    35 // ----------------------------------------------------------
       
    36 //
       
    37 CLocalDirectory::CLocalDirectory( CXdmEngine& aXdmEngine,
       
    38                                   CLocalProtocol& aLocalProtocol ) : 
       
    39                                   CXdmDirectory( aXdmEngine ),
       
    40                                   iLocalProtocol( aLocalProtocol )                                              
       
    41     { 
       
    42     }
       
    43 
       
    44 // ----------------------------------------------------------
       
    45 // CLocalDirectory::NewL
       
    46 // 
       
    47 // ----------------------------------------------------------
       
    48 //
       
    49 CLocalDirectory* CLocalDirectory::NewL( const TDesC& aFilePath,
       
    50                                         CXdmEngine& aXdmEngine,
       
    51                                         CLocalProtocol& aLocalProtocol )
       
    52     {
       
    53     CLocalDirectory* self = new ( ELeave ) CLocalDirectory( aXdmEngine, aLocalProtocol );
       
    54     CleanupStack::PushL( self );
       
    55     self->BaseConstructL( aFilePath );
       
    56     self->ConstructL();
       
    57     CleanupStack::Pop();
       
    58     return self;
       
    59     }
       
    60 
       
    61 // ----------------------------------------------------
       
    62 // CLocalDirectory::~CLocalDirectory
       
    63 // 
       
    64 // ----------------------------------------------------
       
    65 //
       
    66 CLocalDirectory::~CLocalDirectory()
       
    67     {
       
    68     #ifdef _DEBUG
       
    69         iLocalProtocol.WriteToLog( _L8( "CLocalDirectory::~CLocalDirectory()" ) );
       
    70     #endif
       
    71     Cancel();
       
    72     iEntryArray.ResetAndDestroy();
       
    73     iEntryArray.Close();
       
    74     }
       
    75     
       
    76 // ----------------------------------------------------------
       
    77 // CLocalDirectory::ConstructL
       
    78 // 
       
    79 // ----------------------------------------------------------
       
    80 //
       
    81 void CLocalDirectory::ConstructL()
       
    82     {
       
    83     RefreshEntryArrayL();
       
    84     CActiveScheduler::Add( this );
       
    85     }
       
    86 
       
    87 // ----------------------------------------------------------
       
    88 // CLocalDirectory::RefreshEntryArrayL
       
    89 // 
       
    90 // ----------------------------------------------------------
       
    91 //
       
    92 void CLocalDirectory::RefreshEntryArrayL()
       
    93     {
       
    94     CDir* directory = NULL;
       
    95     iEntryArray.ResetAndDestroy();
       
    96     TPtrC path = iDirectoryPath->Des();
       
    97     RFs& session = CLocalProtocol::FileSession();
       
    98     User::LeaveIfError( session.GetDir( path, KEntryAttNormal, ESortByExt, directory ) );
       
    99     CleanupStack::PushL( directory );
       
   100     TInt count = directory->Count();
       
   101     FindTimeStampFilesL( directory );
       
   102     MatchWithStampFilesL( directory );
       
   103     CleanupStack::PopAndDestroy();  //directory
       
   104     }
       
   105 
       
   106 // ----------------------------------------------------------
       
   107 // CLocalDirectory::FindTimeStampFilesL
       
   108 // 
       
   109 // ----------------------------------------------------------
       
   110 //
       
   111 void CLocalDirectory::FindTimeStampFilesL( const CDir* aDirectory )
       
   112     {
       
   113     #ifdef _DEBUG
       
   114         iLocalProtocol.WriteToLog( _L8( "CLocalDirectory::FindTimeStampFilesL()" ) );
       
   115     #endif
       
   116     TBool ready = EFalse;
       
   117     TInt count = aDirectory->Count();
       
   118     for( TInt i = 0;!ready && i < count;i++ )
       
   119         {
       
   120         TPtrC name = ( *aDirectory )[i].iName;
       
   121         TInt index = name.Find( KTimeStampFileExt );
       
   122         if( index > 0 )
       
   123             {
       
   124             TInt stampIndex = i;
       
   125             CLocalDirectoryEntry* entry = NULL;
       
   126             while( !ready )
       
   127                 {
       
   128                 entry = CLocalDirectoryEntry::NewL( name );
       
   129                 CleanupStack::PushL( entry );
       
   130                 User::LeaveIfError( iEntryArray.Append( entry ) );
       
   131                 CleanupStack::Pop();  //entry
       
   132                 stampIndex++;
       
   133                 if( stampIndex < count )
       
   134                     {
       
   135                     name.Set( ( *aDirectory )[stampIndex].iName );
       
   136                     index = name.Find( KTimeStampFileExt );
       
   137                     if( index <= 0 )
       
   138                         ready = ETrue;
       
   139                     }
       
   140                 else ready = ETrue;
       
   141                 }
       
   142             }
       
   143         }
       
   144     }
       
   145 
       
   146 // ----------------------------------------------------------
       
   147 // CLocalDirectory::MatchWithStampFilesL
       
   148 // 
       
   149 // ----------------------------------------------------------
       
   150 //
       
   151 void CLocalDirectory::MatchWithStampFilesL( const CDir* aDirectory )
       
   152     {
       
   153     #ifdef _DEBUG
       
   154         iLocalProtocol.WriteToLog( _L8( "CLocalDirectory::MatchWithStampFilesL()" ) );
       
   155     #endif
       
   156     TInt count = aDirectory->Count();
       
   157     for( TInt i = 0;i < count;i++ )
       
   158         {
       
   159         TPtrC name = ( *aDirectory )[i].iName;
       
   160         TInt index = name.Find( KTimeStampFileExt );
       
   161         if( index > 0 )
       
   162             continue;
       
   163         else 
       
   164             {
       
   165             TBool ready = EFalse;
       
   166             TInt count = iEntryArray.Count();
       
   167             for( TInt i = 0;!ready && i < count;i++ )
       
   168                 ready = iEntryArray[i]->OfferEntryL( name );
       
   169             }
       
   170         }
       
   171     }
       
   172 
       
   173 // ----------------------------------------------------------
       
   174 // CLocalDirectory::DocumentCount
       
   175 // 
       
   176 // ----------------------------------------------------------
       
   177 //
       
   178 TInt CLocalDirectory::DocumentCount()
       
   179     {
       
   180     #ifdef _DEBUG
       
   181         iLocalProtocol.WriteToLog( _L8( "CLocalDirectory::DocumentCount()" ) );
       
   182     #endif
       
   183     RefreshEntryArrayL();
       
   184     return iEntryArray.Count();
       
   185     }
       
   186 
       
   187 // ----------------------------------------------------
       
   188 // CLocalDocument::DocumentTypeL
       
   189 // 
       
   190 // ----------------------------------------------------
       
   191 //
       
   192 TXdmDocType CLocalDirectory::DocumentTypeL( TInt /*aIndex*/ ) const
       
   193     {
       
   194     return EXdmDocGeneral;
       
   195     }
       
   196        
       
   197 // ----------------------------------------------------------
       
   198 // CLocalDirectory::Document
       
   199 // 
       
   200 // ----------------------------------------------------------
       
   201 //
       
   202 TPtrC CLocalDirectory::Document( TInt aIndex ) const
       
   203     {
       
   204     #ifdef _DEBUG
       
   205         iLocalProtocol.WriteToLog( _L8( "CLocalDirectory::Document()" ) );
       
   206     #endif
       
   207     return aIndex < 0 || aIndex > iEntryArray.Count() ? TPtrC() :
       
   208            iEntryArray[aIndex]->EntryName();
       
   209     }
       
   210 
       
   211 // ----------------------------------------------------------
       
   212 // CLocalDirectory::ConstructL
       
   213 // 
       
   214 // ----------------------------------------------------------
       
   215 //
       
   216 TPtrC CLocalDirectory::DirectoryPath() const
       
   217     {
       
   218     return iDirectoryPath != NULL ? iDirectoryPath->Des() : TPtrC();
       
   219     }
       
   220 
       
   221 // ----------------------------------------------------------
       
   222 // CXcapDirectory::SaveRequestData
       
   223 // 
       
   224 // ----------------------------------------------------------
       
   225 //
       
   226 void CLocalDirectory::SaveRequestData( TDirUpdatePhase aUpdatePhase,
       
   227                                        TRequestStatus& aClientStatus )
       
   228     {
       
   229     iUpdatePhase = aUpdatePhase;
       
   230     iClientStatus = &aClientStatus;
       
   231     }
       
   232                
       
   233 // ----------------------------------------------------------
       
   234 // CLocalDirectory::StartUpdateL
       
   235 // 
       
   236 // ----------------------------------------------------------
       
   237 //
       
   238 void CLocalDirectory::StartUpdateL()
       
   239     
       
   240     {
       
   241     #ifdef _DEBUG
       
   242         iLocalProtocol.WriteToLog( _L8( "CLocalDirectory::StartUpdateL()" ) );
       
   243     #endif
       
   244     switch( iUpdatePhase )
       
   245         {
       
   246         case EUpdateDocumentList:
       
   247             RefreshEntryArrayL();
       
   248             User::RequestComplete( iClientStatus, KErrNone );
       
   249             break;
       
   250         case ERefreshDocuments:
       
   251             User::RequestComplete( iClientStatus, KErrNone );
       
   252         default:
       
   253             break;
       
   254         } 
       
   255     }
       
   256 
       
   257 // ---------------------------------------------------------
       
   258 // CLocalDirectory::RunL()
       
   259 // 
       
   260 // ---------------------------------------------------------
       
   261 //
       
   262 void CLocalDirectory::RunL()
       
   263     {
       
   264     #ifdef _DEBUG
       
   265         iLocalProtocol.WriteToLog( _L8( "CLocalDirectory::RunL() - Request: %d" ), iStatus.Int() );
       
   266     #endif
       
   267     }
       
   268 
       
   269 // ----------------------------------------------------
       
   270 // CLocalDirectory::CancelUpdate
       
   271 // 
       
   272 // ----------------------------------------------------
       
   273 //
       
   274 void CLocalDirectory::CancelUpdate()
       
   275     {
       
   276     #ifdef _DEBUG
       
   277         iLocalProtocol.WriteToLog( _L8( "CLocalDirectory::CancelUpdate()" ) );
       
   278     #endif
       
   279     Cancel();
       
   280     }
       
   281     
       
   282 // ---------------------------------------------------------
       
   283 // CLocalDirectory::DoCancel
       
   284 // 
       
   285 // ---------------------------------------------------------
       
   286 //
       
   287 void CLocalDirectory::DoCancel()
       
   288     {
       
   289     #ifdef _DEBUG
       
   290         iLocalProtocol.WriteToLog( _L8( "CLocalDirectory::DoCancel()" ) );
       
   291     #endif
       
   292     switch( iUpdatePhase )
       
   293         {
       
   294         case EDirPhaseIdle:
       
   295             break;
       
   296         case EUpdateDocumentList:
       
   297             break;
       
   298         case ERefreshDocuments:
       
   299             break;
       
   300         default:
       
   301             break;
       
   302         }
       
   303     User::RequestComplete( iClientStatus, KErrCancel );
       
   304     }
       
   305 
       
   306 
       
   307 
       
   308