ncdengine/provider/server/src/ncdfilestoragefilehandler.cpp
changeset 0 ba25891c3a9e
equal deleted inserted replaced
-1:000000000000 0:ba25891c3a9e
       
     1 /*
       
     2 * Copyright (c) 2006 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:   Implements CNcdFileStorageFileHandler class
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include "ncdfilestoragefilehandler.h"
       
    20 #include "ncdproviderdefines.h"
       
    21 #include "catalogsdebug.h"
       
    22 #include "ncdstorageclient.h"
       
    23 #include "ncdstorage.h"
       
    24 #include "ncdfilestorage.h"
       
    25 #include "catalogsutils.h"
       
    26 
       
    27 // ======== MEMBER FUNCTIONS ========
       
    28 
       
    29 // ---------------------------------------------------------------------------
       
    30 // NewL
       
    31 // ---------------------------------------------------------------------------
       
    32 //
       
    33 CNcdFileStorageFileHandler* CNcdFileStorageFileHandler::NewL( 
       
    34     MNcdStorageClient& aStorageClient )
       
    35     {
       
    36     CNcdFileStorageFileHandler* self = new( ELeave ) 
       
    37         CNcdFileStorageFileHandler( aStorageClient );
       
    38     CleanupStack::PushL( self );
       
    39     self->ConstructL();
       
    40     CleanupStack::Pop();
       
    41     return self;
       
    42     }
       
    43     
       
    44 
       
    45 // ---------------------------------------------------------------------------
       
    46 // Destructor
       
    47 // ---------------------------------------------------------------------------
       
    48 //    
       
    49 CNcdFileStorageFileHandler::~CNcdFileStorageFileHandler()
       
    50     {
       
    51     DLTRACE(("--><--"));
       
    52     }
       
    53     
       
    54     
       
    55 // ---------------------------------------------------------------------------
       
    56 // MoveL
       
    57 // ---------------------------------------------------------------------------
       
    58 //
       
    59 void CNcdFileStorageFileHandler::MoveFileL( const TDesC& aSourceFile,
       
    60     const TDesC& aNamespaceOrDir, const TDesC& /* aIdOrName */,
       
    61     TBool aOverwrite )
       
    62     {    
       
    63     DLTRACEIN(( _L("Src: %S, dir: %S"), &aSourceFile,
       
    64         &aNamespaceOrDir ) );
       
    65     
       
    66     // Get storage or create it if it doesn't exist
       
    67     MNcdStorage& storage = StorageL( aNamespaceOrDir );
       
    68     
       
    69     MNcdFileStorage& fs = storage.FileStorageL( 
       
    70         NcdProviderDefines::KDefaultFileStorageUid );
       
    71     
       
    72     
       
    73     fs.AddFileL( aSourceFile, aOverwrite );
       
    74     DLTRACEOUT( ( "" ) );
       
    75     }
       
    76 
       
    77 
       
    78 // ---------------------------------------------------------------------------
       
    79 // Constructor
       
    80 // ---------------------------------------------------------------------------
       
    81 //
       
    82 CNcdFileStorageFileHandler::CNcdFileStorageFileHandler( 
       
    83     MNcdStorageClient& aStorageClient ) : 
       
    84     iStorageClient( aStorageClient )
       
    85     {    
       
    86     }
       
    87 
       
    88 
       
    89 // ---------------------------------------------------------------------------
       
    90 // ConstructL
       
    91 // ---------------------------------------------------------------------------
       
    92 //
       
    93 void CNcdFileStorageFileHandler::ConstructL()
       
    94     {
       
    95     }
       
    96     
       
    97 
       
    98 // ---------------------------------------------------------------------------
       
    99 // Ensures the storage exists
       
   100 // ---------------------------------------------------------------------------
       
   101 //
       
   102 MNcdStorage& CNcdFileStorageFileHandler::StorageL( const TDesC& aNamespace )
       
   103     {
       
   104     DLTRACEIN((""));
       
   105     MNcdStorage* storage = NULL;
       
   106     // Search for the storage
       
   107     TRAPD( err,                 
       
   108         storage = &iStorageClient.StorageL( aNamespace ) );
       
   109 
       
   110     if ( err == KErrNone ) 
       
   111         {
       
   112         DLTRACEOUT((""));
       
   113         return *storage;
       
   114         }
       
   115     else if ( err != KErrNotFound ) 
       
   116         {
       
   117         DLTRACEOUT(("Leaving with: %d", err));
       
   118         User::Leave( err );    
       
   119         }
       
   120 
       
   121     // Create the namespace
       
   122     return iStorageClient.CreateStorageL( aNamespace );    
       
   123     }