ncdengine/provider/client/src/ncdnodepreviewproxy.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:   Contains CNcdNodePreviewProxy class implementation
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include <f32file.h>
       
    20 #include "ncdnodepreviewproxy.h"
       
    21 #include "ncdnodemetadataproxy.h"
       
    22 #include "ncdnodeproxy.h"
       
    23 #include "ncdoperationimpl.h"
       
    24 #include "ncddownloadoperationproxy.h"
       
    25 #include "ncdoperationmanagerproxy.h"
       
    26 #include "catalogsclientserver.h"
       
    27 #include "ncdnodeidentifier.h"
       
    28 #include "ncdnodefunctionids.h"
       
    29 #include "ncdnodeclassids.h"
       
    30 #include "catalogsinterfaceidentifier.h"
       
    31 #include "catalogsutils.h"
       
    32 #include "catalogsdebug.h"
       
    33 #include "ncdpanics.h"
       
    34 #include "ncderrors.h"
       
    35 
       
    36 
       
    37 // ======== PUBLIC MEMBER FUNCTIONS ========
       
    38 
       
    39 CNcdNodePreviewProxy::CNcdNodePreviewProxy(
       
    40     MCatalogsClientServer& aSession,
       
    41     TInt aHandle,
       
    42     CNcdNodeMetadataProxy& aMetadata )
       
    43 : CNcdInterfaceBaseProxy( aSession, aHandle, &aMetadata ),
       
    44   iMetadata( aMetadata )
       
    45     {
       
    46     }
       
    47 
       
    48 
       
    49 void CNcdNodePreviewProxy::ConstructL()
       
    50     {
       
    51     // Register the interface
       
    52     MNcdNodePreview* interface( this );
       
    53     AddInterfaceL( 
       
    54         CCatalogsInterfaceIdentifier::NewL( interface, this, MNcdNodePreview::KInterfaceUid ) );
       
    55     
       
    56     // Let this leave if internalization fails.
       
    57     InternalizeL();
       
    58     }
       
    59 
       
    60 
       
    61 CNcdNodePreviewProxy* CNcdNodePreviewProxy::NewL(
       
    62     MCatalogsClientServer& aSession,
       
    63     TInt aHandle,
       
    64     CNcdNodeMetadataProxy& aMetadata )
       
    65     {
       
    66     CNcdNodePreviewProxy* self = 
       
    67         CNcdNodePreviewProxy::NewLC( aSession, aHandle, aMetadata );
       
    68     CleanupStack::Pop( self );
       
    69     return self;
       
    70     }
       
    71 
       
    72 CNcdNodePreviewProxy* CNcdNodePreviewProxy::NewLC(
       
    73     MCatalogsClientServer& aSession,
       
    74     TInt aHandle,
       
    75     CNcdNodeMetadataProxy& aMetadata )
       
    76     {
       
    77     CNcdNodePreviewProxy* self = 
       
    78         new( ELeave ) CNcdNodePreviewProxy( aSession, aHandle, aMetadata );
       
    79     // Using PushL because the object does not have any references yet
       
    80     CleanupStack::PushL( self );
       
    81     self->ConstructL();
       
    82     return self;
       
    83     }
       
    84 
       
    85 
       
    86 CNcdNodePreviewProxy::~CNcdNodePreviewProxy()
       
    87     {
       
    88     // Remove interfaces implemented by this class from the interface list.
       
    89     // So, the interface list is up to date when this class object is deleted.
       
    90     RemoveInterface( MNcdNodePreview::KInterfaceUid );
       
    91     
       
    92     
       
    93     // Delete member variables here
       
    94     // Do not delete node and operation manager because
       
    95     // this object does not own them.
       
    96     iPreviewMimeTypes.ResetAndDestroy();
       
    97     }
       
    98 
       
    99 
       
   100 CNcdNodeMetadataProxy& CNcdNodePreviewProxy::MetadataL() const
       
   101     {
       
   102     DLTRACEIN((""));
       
   103 
       
   104    if( IsObsolete() )
       
   105         {
       
   106         DLERROR(("Preview is obsolete. Metadata may not exist."));
       
   107         User::Leave( KNcdErrorObsolete );
       
   108         }
       
   109     
       
   110     DLTRACEOUT((""));
       
   111     
       
   112     return iMetadata;
       
   113     }
       
   114 
       
   115 
       
   116 void CNcdNodePreviewProxy::InternalizeL()
       
   117     {
       
   118     DLTRACEIN((""));
       
   119 
       
   120     HBufC8* data( NULL );
       
   121         
       
   122     // Because we do not know the exact size of the data, use
       
   123     // the alloc method, which creates the buffer of the right size
       
   124     // and sets the pointer to point to the created buffer.
       
   125     // Get all the data that is necessary to internalize this object
       
   126     // from the server side.
       
   127     TInt error(
       
   128         ClientServerSession().
       
   129         SendSyncAlloc( NcdNodeFunctionIds::ENcdInternalize,
       
   130                        KNullDesC8,
       
   131                        data,
       
   132                        Handle(),
       
   133                        0 ) );
       
   134 
       
   135     if ( error == KNcdErrorObsolete )
       
   136         {
       
   137         DLINFO(("Preview was obsolete"));
       
   138         SetObsolete( ETrue );
       
   139         // Remove interfaces implemented by this class from the top parent interface list.
       
   140         // So, the interface list is up to date after this object is removed
       
   141         // from its top parent.
       
   142         RemoveInterface( MNcdNodePreview::KInterfaceUid );
       
   143         // Remove from the parent
       
   144         RemoveFromParent();
       
   145         // Now update the interface for this object just in case somebody needs it.
       
   146         // Register the interface
       
   147         MNcdNodePreview* interface( this );
       
   148         AddInterfaceL( 
       
   149             CCatalogsInterfaceIdentifier::NewL( interface, this, MNcdNodePreview::KInterfaceUid ) );
       
   150         }
       
   151     else
       
   152         {
       
   153         // Just in case it was some times obsolete but not anymore
       
   154         SetObsolete( EFalse );
       
   155         }
       
   156 
       
   157     // If error occurred during data transfer, leave here and forward the error.
       
   158     User::LeaveIfError( error );
       
   159             
       
   160     if ( data == NULL )
       
   161         {
       
   162         DLERROR((""));
       
   163         User::Leave(  KErrNotFound );
       
   164         }
       
   165 
       
   166      CleanupStack::PushL( data );
       
   167 
       
   168      // Read the data from the stream and insert it to the memeber variables
       
   169      RDesReadStream stream( *data );
       
   170      CleanupClosePushL( stream );
       
   171     
       
   172      InternalizeDataL( stream );
       
   173     
       
   174      // Closes the stream
       
   175      CleanupStack::PopAndDestroy( &stream ); 
       
   176      CleanupStack::PopAndDestroy( data );
       
   177 
       
   178     DLTRACEOUT((""));    
       
   179     }
       
   180 
       
   181 
       
   182 TBool CNcdNodePreviewProxy::IsObsolete() const
       
   183     {
       
   184     return iObsolete;
       
   185     }
       
   186 
       
   187 void CNcdNodePreviewProxy::SetObsolete( TBool aObsolete )
       
   188     {
       
   189     iObsolete = aObsolete;
       
   190     }    
       
   191     
       
   192 
       
   193 void CNcdNodePreviewProxy::InternalizeDataL( RReadStream& aStream )
       
   194     {
       
   195     DLTRACEIN((""));
       
   196 
       
   197     // Use catalogsutils.h functions to internalize
       
   198     // memebervariables according to the data received
       
   199     // from the server.
       
   200     // Make sure that the variables are set here in the same
       
   201     // order as they are externalized in the server side.
       
   202     // Small mistake here messes up everything!
       
   203 
       
   204     // First read the class id. Because, it is the first thing in the stream.
       
   205     TInt classId( aStream.ReadInt32L() );
       
   206     
       
   207     if ( classId != NcdNodeClassIds::ENcdNodePreviewClassId )
       
   208         {
       
   209         // classId is not recognized
       
   210         DLERROR(("Class id was not recognized!"));
       
   211         // For testing purposes assert here
       
   212         DASSERT( EFalse );
       
   213         
       
   214         // Otherwise leave is adequate
       
   215         User::Leave( KErrCorrupt );
       
   216         }
       
   217 
       
   218 
       
   219     iPreviewCount = aStream.ReadInt16L();
       
   220     
       
   221     iPreviewMimeTypes.ResetAndDestroy();
       
   222     HBufC* previewMimeType = NULL;
       
   223     
       
   224     for( int i = 0; i < iPreviewCount; i++ )
       
   225         {
       
   226         InternalizeDesL( previewMimeType, aStream );
       
   227         CleanupStack::PushL( previewMimeType );
       
   228         iPreviewMimeTypes.Append( previewMimeType );
       
   229         CleanupStack::Pop( previewMimeType );
       
   230         previewMimeType = NULL;
       
   231         }
       
   232 
       
   233     DLTRACEOUT((""));
       
   234     }
       
   235 
       
   236 TInt CNcdNodePreviewProxy::PreviewCount() const
       
   237     {
       
   238     return iPreviewCount;
       
   239     }
       
   240 
       
   241 TBool CNcdNodePreviewProxy::IsPreviewLoadedL( TInt aIndex ) const
       
   242     {
       
   243     NCD_ASSERT_ALWAYS( 
       
   244         aIndex >= 0 && aIndex < PreviewCount(),
       
   245         ENcdPanicIndexOutOfRange );
       
   246     
       
   247     HBufC8* filenumber = IntToDes8LC( aIndex );
       
   248     TInt isLoaded;
       
   249     
       
   250     User::LeaveIfError(
       
   251         ClientServerSession().
       
   252             SendSync( NcdNodeFunctionIds::ENcdIsPreviewLoaded,
       
   253                       *filenumber,
       
   254                       isLoaded,
       
   255                       Handle()));
       
   256     CleanupStack::PopAndDestroy( filenumber );
       
   257     return isLoaded;
       
   258     }
       
   259 
       
   260 const TDesC& CNcdNodePreviewProxy::PreviewMimeType( TInt aIndex ) const
       
   261     {
       
   262     NCD_ASSERT_ALWAYS( 
       
   263         aIndex >= 0 && aIndex < PreviewCount(),
       
   264         ENcdPanicIndexOutOfRange );
       
   265     
       
   266     return *iPreviewMimeTypes[aIndex];
       
   267     }
       
   268 
       
   269 MNcdDownloadOperation* CNcdNodePreviewProxy::LoadPreviewL( TInt aIndex,
       
   270                                                            MNcdDownloadOperationObserver* aObserver )
       
   271     {
       
   272     DLTRACEIN((""));
       
   273     
       
   274     NCD_ASSERT_ALWAYS( 
       
   275         aIndex >= 0 && aIndex < PreviewCount(),
       
   276         ENcdPanicIndexOutOfRange );
       
   277 
       
   278     CNcdDownloadOperationProxy* download =
       
   279         MetadataL().Node().OperationManager().
       
   280         CreateDownloadOperationL(
       
   281             ENcdPreviewDownload,
       
   282             MetadataL().Node(),
       
   283             KNullDesC,
       
   284             aObserver,
       
   285             aIndex );
       
   286     
       
   287     iOperationObserver = aObserver;
       
   288     DLTRACEOUT((""));
       
   289     return download;
       
   290 
       
   291     }
       
   292 
       
   293 RFile CNcdNodePreviewProxy::PreviewFileL( TInt aIndex ) const
       
   294     {
       
   295     DLTRACEIN(( "aIndex: %i", aIndex ));
       
   296 
       
   297     NCD_ASSERT_ALWAYS( 
       
   298         aIndex >= 0 && aIndex < PreviewCount(),
       
   299         ENcdPanicIndexOutOfRange );
       
   300     
       
   301     // Convert index to a descriptor
       
   302     HBufC8* filenumber = IntToDes8LC( aIndex );
       
   303     
       
   304     /**
       
   305      * Add error handling, is it okay to leave here?
       
   306      */
       
   307     RFile fileHandle = ClientServerSession().SendSyncFileOpenL( 
       
   308         NcdNodeFunctionIds::ENcdPreviewOpenFile,
       
   309         *filenumber,        
       
   310         Handle());
       
   311     
       
   312     CleanupStack::PopAndDestroy( filenumber );
       
   313     
       
   314     DLTRACEOUT((""));
       
   315     return fileHandle;
       
   316     }
       
   317 
       
   318 void CNcdNodePreviewProxy::DownloadProgress( MNcdDownloadOperation& /*aOperation*/,
       
   319     TNcdProgress /*aProgress*/ )
       
   320     {
       
   321     }
       
   322     
       
   323 void CNcdNodePreviewProxy::QueryReceived( MNcdDownloadOperation& /*aOperation*/,
       
   324     MNcdQuery* /*aQuery*/ )
       
   325     {
       
   326     }
       
   327 
       
   328 void CNcdNodePreviewProxy::OperationComplete( MNcdDownloadOperation& /*aOperation*/,
       
   329     TInt /*aError*/ )
       
   330     {
       
   331     DLTRACEIN((""));
       
   332     DLTRACEOUT((""));
       
   333     }
       
   334