pimappservices/calendar/client/src/caldataexchangeimpl.cpp
changeset 0 f979ecb2b13e
equal deleted inserted replaced
-1:000000000000 0:f979ecb2b13e
       
     1 // Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 //
       
    15 
       
    16 #include "caldataexchangeimpl.h"
       
    17 
       
    18 #include <ecom/ecom.h>
       
    19 
       
    20 #include "calcommonimpl.h"
       
    21 #include <caldataexchange.h>
       
    22 #include <caldataformat.h>
       
    23 #include <calentry.h>
       
    24 #include <calsession.h>
       
    25 #include "calsessionimpl.h"
       
    26 
       
    27 CCalDataExchangeImpl::CCalDataExchangeImpl(CCalSession& aSession)
       
    28 	: iSession(aSession)
       
    29 	{
       
    30 	iSession.Impl().IncrementReferenceCount();
       
    31 	iDllLoadFailed = EFalse;
       
    32 	}
       
    33 	
       
    34 CCalDataExchangeImpl::~CCalDataExchangeImpl()
       
    35 	{
       
    36 	iSession.Impl().DecrementReferenceCount();
       
    37 	delete iVCalConverter;
       
    38 	REComSession::FinalClose();
       
    39 	}
       
    40 
       
    41 void CCalDataExchangeImpl::LoadDllL()
       
    42 	{
       
    43 	
       
    44 	iVCalConverter = CAgnVersit::NewL();
       
    45 	User::LeaveIfNull(iVCalConverter);
       
    46 	}
       
    47 	
       
    48 void CCalDataExchangeImpl::ImportL(TUid aDataFormat, RReadStream& aReadStream, RPointerArray<CCalEntry>& aCalEntryArray)
       
    49 	{
       
    50 	// Call Import with no flags set
       
    51 	ImportL(aDataFormat, aReadStream, aCalEntryArray, 0, KMaxTInt);
       
    52 	}
       
    53 
       
    54 void CCalDataExchangeImpl::ImportL(TUid aDataFormat, RReadStream& aReadStream, RPointerArray<CCalEntry>& aCalEntryArray, TInt aFlags)
       
    55 	{
       
    56 	ImportL(aDataFormat, aReadStream, aCalEntryArray, aFlags, KMaxTInt);	
       
    57 	}
       
    58 
       
    59 void CCalDataExchangeImpl::ImportL(TUid aDataFormat, RReadStream& aReadStream, RPointerArray<CCalEntry>& aCalEntryArray, TInt aFlags, TInt aNumEntries)
       
    60 	{
       
    61 	__ASSERT_ALWAYS(aDataFormat == KUidVCalendar, User::Leave(KErrNotSupported));
       
    62 	
       
    63 	RPointerArray<CCalEntry> calEntryArray;
       
    64 	CleanupResetAndDestroyPushL(calEntryArray);
       
    65 	
       
    66 	TBool reachedEndOfStream = EFalse;
       
    67 	TInt entryCount = 0;
       
    68 	TInt err = KErrNone;
       
    69 	
       
    70 	while (!reachedEndOfStream && entryCount < aNumEntries)
       
    71 		{
       
    72 		TRAP(err, ImportVCalL(aFlags, aReadStream, calEntryArray));
       
    73 		const TInt KCount = calEntryArray.Count();
       
    74 
       
    75 		entryCount += KCount;
       
    76 		
       
    77 		if (err == KErrEof)
       
    78 			{
       
    79 			reachedEndOfStream = ETrue;
       
    80 			}
       
    81 		else
       
    82 			{
       
    83 			User::LeaveIfError(err);
       
    84 			}
       
    85 			
       
    86 		for (TInt i = 0; i < KCount; ++i)
       
    87 			{
       
    88 			CCalEntry* calEntry = calEntryArray[i];
       
    89 			aCalEntryArray.AppendL(calEntry);						// aCalEntryArray takes ownership of calEntry
       
    90 			calEntryArray[i]=NULL;
       
    91 			}
       
    92 			
       
    93 		calEntryArray.Reset();
       
    94 		}
       
    95 		
       
    96 	CleanupStack::PopAndDestroy(&calEntryArray);
       
    97 	}  
       
    98 	
       
    99 void CCalDataExchangeImpl::ExportL(TUid aDataFormat, RWriteStream& aWriteStream, RPointerArray<CCalEntry>& aCalEntryArray)
       
   100 	{
       
   101 	__ASSERT_ALWAYS(aDataFormat == KUidVCalendar, User::Leave(KErrNotSupported));	
       
   102 	
       
   103 	if (iDllLoadFailed)
       
   104 		 {
       
   105 		 User::Leave(KErrNotFound);
       
   106 		 }
       
   107 
       
   108 	if (iVCalConverter == NULL)
       
   109 		 {
       
   110 	     LoadDllL();
       
   111 		 }
       
   112 
       
   113 	iVCalConverter->ExportVCalL(aWriteStream, aCalEntryArray, Versit::EUTF8CharSet);
       
   114 	}
       
   115 
       
   116 void CCalDataExchangeImpl::ImportAsyncL(TUid aDataFormat, RReadStream& aReadStream, RPointerArray<CCalEntry>& aCalEntryArray, MCalDataExchangeCallBack& aObserver, TInt aFlags)
       
   117 	{
       
   118 	__ASSERT_ALWAYS(aDataFormat == KUidVCalendar, User::Leave(KErrNotSupported));
       
   119 	if (iDllLoadFailed)
       
   120 		{
       
   121 		 User::Leave(KErrNotFound);
       
   122 		}
       
   123 		
       
   124 	if (iVCalConverter == NULL)
       
   125 		{
       
   126 		LoadDllL();
       
   127 		}
       
   128 	iVCalConverter->ImportVCalAsyncL(aFlags, aReadStream, aCalEntryArray,aObserver);
       
   129 	}
       
   130 
       
   131 void CCalDataExchangeImpl::ExportAsyncL(TUid aDataFormat, RWriteStream& aWriteStream, RPointerArray<CCalEntry>& aCalEntryArray, MCalDataExchangeCallBack& aObserver)
       
   132 	{
       
   133 	__ASSERT_ALWAYS(aDataFormat == KUidVCalendar, User::Leave(KErrNotSupported));
       
   134 	if (iDllLoadFailed)
       
   135 		{
       
   136 		 User::Leave(KErrNotFound);
       
   137 		}
       
   138 		
       
   139 	if (iVCalConverter == NULL)
       
   140 		{
       
   141 		LoadDllL();
       
   142 		}
       
   143 
       
   144 	iVCalConverter->ExportVCalAsyncL(aWriteStream, aCalEntryArray, aObserver, Versit::EUTF8CharSet); // takes ownership of entrylist
       
   145 	}
       
   146 
       
   147 void CCalDataExchangeImpl::ImportVCalL(TInt aFlags, RReadStream& aReadStream, RPointerArray<CCalEntry>& aEntryArray)
       
   148 	{
       
   149 	if (iDllLoadFailed)
       
   150 		{
       
   151 		 User::Leave(KErrNotFound);
       
   152 		}
       
   153 		
       
   154 	if (iVCalConverter == NULL)
       
   155 		{
       
   156 		LoadDllL();
       
   157 		}
       
   158 	iVCalConverter->ImportVCalL(aFlags,aReadStream,aEntryArray);
       
   159 	}
       
   160 	
       
   161 /** Signals the destruction of the plug-in to ECom. */
       
   162 EXPORT_C CAgnVersit::~CAgnVersit()
       
   163 /**
       
   164 @internalAll
       
   165 */
       
   166 	{
       
   167 	REComSession::DestroyedImplementation(iDtor_ID_Key);
       
   168 	}
       
   169 
       
   170 CAgnVersit* CAgnVersit::NewL()
       
   171 	{
       
   172 	RImplInfoPtrArray	implInfoArray;
       
   173 	CleanupResetAndDestroyPushL(implInfoArray);
       
   174 	REComSession::ListImplementationsL(KUidEComAgnVersitInterface,implInfoArray);
       
   175 	//leave if impliInfoArray is empty
       
   176 	const TInt count = implInfoArray.Count();
       
   177 	__ASSERT_ALWAYS(count > 0, User::Leave(KErrNotFound));
       
   178 	// Load the first implementation found for KUidEComAgnVersitInterface which
       
   179 	// should be KUidEComAgnVersitDefaultImplementation unless it is replaced by licensees
       
   180 	const TUid firstImplementationFound = implInfoArray[0]->ImplementationUid();
       
   181 	CleanupStack::PopAndDestroy(&implInfoArray);
       
   182     TAny* ptr = REComSession::CreateImplementationL(firstImplementationFound,
       
   183 								_FOFF(CAgnVersit,iDtor_ID_Key));
       
   184 	return reinterpret_cast<CAgnVersit*>(ptr); 
       
   185 	}
       
   186