meetingrequest/mrservices/src/cesmrcalimportexporter.cpp
changeset 0 8466d47a6819
equal deleted inserted replaced
-1:000000000000 0:8466d47a6819
       
     1 /*
       
     2 * Copyright (c) 2007-2009 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:  ESMR iCal import exporter implementation
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDE FILES
       
    20 #include "emailtrace.h"
       
    21 #include "cesmrcalimportexporter.h"
       
    22 
       
    23 #include <calentry.h>
       
    24 #include <s32mem.h>
       
    25 #include <utf.h>
       
    26 
       
    27 //<cmail>
       
    28 #include "cesmragnexternalinterface.h"
       
    29 //</cmail>
       
    30 
       
    31 /// Unnamed namespace for local definitions
       
    32 namespace {
       
    33 
       
    34 // Literal definition for text/calendar MIME content-type
       
    35 _LIT8( KTextCalendar, "text/calendar" );
       
    36 
       
    37 // Buffer expand size
       
    38 const TInt KBufExpandSize = 64;
       
    39 
       
    40 // Definition for first position
       
    41 const TInt KFirstPos = 0;
       
    42 
       
    43 // Definition for exporting all
       
    44 const TUint KFlagExportAll = 0xFFFFFFFF;
       
    45 
       
    46 // Definition for import flags
       
    47 const TUint KFlagImport = 0;
       
    48 
       
    49 /**
       
    50  * Cleanup operation for RPointerArray.
       
    51  * @param aArray Pointer to RPointerArray.
       
    52  */
       
    53 void PointerArrayCleanup( TAny* aArray )
       
    54     {
       
    55     RPointerArray<CCalEntry>* entryArray =
       
    56         static_cast<RPointerArray<CCalEntry>*>( aArray );
       
    57 
       
    58     entryArray->ResetAndDestroy();
       
    59     entryArray->Close();
       
    60     }
       
    61 
       
    62 }  // namespace
       
    63 
       
    64 // ======== MEMBER FUNCTIONS ========
       
    65 
       
    66 // ---------------------------------------------------------------------------
       
    67 // CESMRCalImportExporter::CESMRCalImportExporter
       
    68 // ---------------------------------------------------------------------------
       
    69 //
       
    70 inline CESMRCalImportExporter::CESMRCalImportExporter()
       
    71     {
       
    72     FUNC_LOG;
       
    73     // No implementation yet
       
    74     }
       
    75 
       
    76 // ---------------------------------------------------------------------------
       
    77 // CESMRCalImportExporter::~CESMRCalImportExporter
       
    78 // ---------------------------------------------------------------------------
       
    79 //
       
    80 EXPORT_C CESMRCalImportExporter::~CESMRCalImportExporter()
       
    81     {
       
    82     FUNC_LOG;
       
    83     delete iImportExporter;
       
    84     }
       
    85 
       
    86 // ---------------------------------------------------------------------------
       
    87 // CESMRCalImportExporter::NewL
       
    88 // ---------------------------------------------------------------------------
       
    89 //
       
    90 EXPORT_C CESMRCalImportExporter* CESMRCalImportExporter::NewL()
       
    91     {
       
    92     FUNC_LOG;
       
    93     CESMRCalImportExporter* self = NewLC();
       
    94     CleanupStack::Pop(self);
       
    95     return self;
       
    96     }
       
    97 
       
    98 // ---------------------------------------------------------------------------
       
    99 // CESMRCalImportExporter::NewLC
       
   100 // ---------------------------------------------------------------------------
       
   101 //
       
   102 EXPORT_C CESMRCalImportExporter* CESMRCalImportExporter::NewLC()
       
   103     {
       
   104     FUNC_LOG;
       
   105     CESMRCalImportExporter* self = new (ELeave) CESMRCalImportExporter();
       
   106     CleanupStack::PushL( self );
       
   107     self->ConstructL();
       
   108     return self;
       
   109     }
       
   110 
       
   111 // ---------------------------------------------------------------------------
       
   112 // CESMRCalImportExporter::ConstructL
       
   113 // ---------------------------------------------------------------------------
       
   114 //
       
   115 void CESMRCalImportExporter::ConstructL()
       
   116     {
       
   117     FUNC_LOG;
       
   118     // Create IMPORT / EXPORTER for text/calendar mime type
       
   119     iImportExporter =
       
   120             CESMRAgnExternalInterface::NewL( KTextCalendar() );
       
   121     }
       
   122 
       
   123 // ---------------------------------------------------------------------------
       
   124 // CESMRCalImportExporter::ExportToICal8L
       
   125 // ---------------------------------------------------------------------------
       
   126 //
       
   127 HBufC8* CESMRCalImportExporter::ExportToICal8L( CCalEntry& aEntry )
       
   128     {
       
   129     FUNC_LOG;
       
   130     HBufC8* buf = ExportToICal8LC( aEntry );
       
   131     CleanupStack::Pop( buf );
       
   132     return buf;
       
   133     }
       
   134 
       
   135 // ---------------------------------------------------------------------------
       
   136 // CESMRCalImportExporter::ExportToICal16L
       
   137 // ---------------------------------------------------------------------------
       
   138 //
       
   139 HBufC* CESMRCalImportExporter::ExportToICal16L( CCalEntry& aEntry )
       
   140     {
       
   141     FUNC_LOG;
       
   142     HBufC* buf = ExportToICal16LC( aEntry );
       
   143     CleanupStack::Pop( buf );
       
   144     return buf;
       
   145     }
       
   146 
       
   147 // ---------------------------------------------------------------------------
       
   148 // CESMRCalImportExporter::ExportToICal16LC
       
   149 // ---------------------------------------------------------------------------
       
   150 //
       
   151 HBufC* CESMRCalImportExporter::ExportToICal16LC( CCalEntry& aEntry )
       
   152     {
       
   153     FUNC_LOG;
       
   154     HBufC8* buf8 = ExportToICal8LC( aEntry );
       
   155     HBufC* buf16 = HBufC::NewLC( buf8->Length() );
       
   156     TPtr16 ptr16( buf16->Des() );
       
   157 
       
   158     TInt err = CnvUtfConverter::ConvertToUnicodeFromUtf8( ptr16, *buf8 );
       
   159     User::LeaveIfError( err );
       
   160     CleanupStack::Pop( buf16 );
       
   161     CleanupStack::PopAndDestroy( buf8 );
       
   162     CleanupStack::PushL( buf16 );
       
   163     return buf16;
       
   164     }
       
   165 
       
   166 // ---------------------------------------------------------------------------
       
   167 // CESMRCalImportExporter::ExportToICalLC
       
   168 // ---------------------------------------------------------------------------
       
   169 //
       
   170 HBufC8* CESMRCalImportExporter::ExportToICal8LC( CCalEntry& aEntry )
       
   171     {
       
   172     FUNC_LOG;
       
   173     CBufFlat* buffer = CBufFlat::NewL(KBufExpandSize);
       
   174     CleanupStack::PushL( buffer );
       
   175 
       
   176     RBufWriteStream wStream(*buffer);
       
   177     wStream.PushL();
       
   178 
       
   179     iImportExporter->ExportL(
       
   180             aEntry,
       
   181             wStream,
       
   182             KFlagExportAll,
       
   183             *this );
       
   184 
       
   185     HBufC8* exportBuffer = buffer->Ptr(KFirstPos).AllocL();
       
   186 
       
   187     wStream.Pop();
       
   188     wStream.Close();
       
   189     CleanupStack::PopAndDestroy( buffer );
       
   190 
       
   191     CleanupStack::PushL( exportBuffer );
       
   192     return exportBuffer;
       
   193     }
       
   194 
       
   195 // ---------------------------------------------------------------------------
       
   196 // CESMRCalImportExporter::ImportFromIcalL
       
   197 // ---------------------------------------------------------------------------
       
   198 //
       
   199 CCalEntry* CESMRCalImportExporter::ImportFromIcalL(const TDes8& aIcal )
       
   200     {
       
   201     FUNC_LOG;
       
   202     CCalEntry* entry = ImportFromIcalLC( aIcal );
       
   203     CleanupStack::Pop( entry );
       
   204     return entry;
       
   205     }
       
   206 
       
   207 // ---------------------------------------------------------------------------
       
   208 // CESMRCalImportExporter::ImportFromIcalLC
       
   209 // ---------------------------------------------------------------------------
       
   210 //
       
   211 CCalEntry* CESMRCalImportExporter::ImportFromIcalLC(const TDes8& aIcal )
       
   212     {
       
   213     FUNC_LOG;
       
   214     CCalEntry* entry = NULL;
       
   215 
       
   216     CBufFlat* buffer = CBufFlat::NewL(KBufExpandSize);
       
   217     CleanupStack::PushL( buffer );
       
   218     buffer->InsertL(KFirstPos, aIcal );
       
   219 
       
   220     RBufReadStream rStream(*buffer);
       
   221     rStream.PushL();
       
   222     RPointerArray<CCalEntry> entries;
       
   223             CleanupStack::PushL(
       
   224                         TCleanupItem(
       
   225                             PointerArrayCleanup,
       
   226                             &entries    ) );
       
   227 
       
   228     iImportExporter->ImportL(
       
   229             entries,
       
   230             rStream,
       
   231             KFlagImport,
       
   232             *this );
       
   233 
       
   234     if ( entries.Count() )
       
   235         {
       
   236         entry = entries[ KFirstPos ];
       
   237         entries.Remove( KFirstPos );
       
   238         }
       
   239 
       
   240     CleanupStack::PopAndDestroy( &entries );
       
   241     rStream.Pop();
       
   242     rStream.Close();
       
   243     CleanupStack::PopAndDestroy( buffer );
       
   244 
       
   245     CleanupStack::PushL( entry );
       
   246     return entry;
       
   247     }
       
   248 
       
   249 // ---------------------------------------------------------------------------
       
   250 // CESMRCalImportExporter::AgnImportErrorL
       
   251 // ---------------------------------------------------------------------------
       
   252 //
       
   253 MESMRAgnImportObserver::TImpResponse CESMRCalImportExporter::AgnImportErrorL(
       
   254             TImpError /*aType*/,
       
   255             const TDesC8& /*aUid*/,
       
   256             const TDesC& /*aContext*/ )
       
   257     {
       
   258     FUNC_LOG;
       
   259     // Ignore error and continue processing
       
   260     return MESMRAgnImportObserver::EImpResponseContinue;
       
   261     }
       
   262 
       
   263 
       
   264 //--------------------------------------------------------------------------
       
   265 // CESMRCalImportExporter::AgnExportErrorL
       
   266 //--------------------------------------------------------------------------
       
   267 //
       
   268 MESMRAgnExportObserver::TExpResponse CESMRCalImportExporter::AgnExportErrorL(
       
   269                 TExpError /*aType*/,
       
   270                 const TDesC8& /*aUid*/,
       
   271                 const TDesC& /*aContext*/ )
       
   272     {
       
   273     FUNC_LOG;
       
   274     // Ignore error and continue processing
       
   275     return MESMRAgnExportObserver::EExpResponseContinue;
       
   276     }
       
   277 
       
   278 // EOF
       
   279