calendarui/globaldata/src/calenvcalexport.cpp
changeset 0 f979ecb2b13e
equal deleted inserted replaced
-1:000000000000 0:f979ecb2b13e
       
     1 /*
       
     2 * Copyright (c) 2002 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:   Exports Agenda entry to vCalendar data
       
    15  *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 //debug
       
    21 #include "calendarui_debug.h"
       
    22 
       
    23 // INCLUDE FILES
       
    24 #include "calenvcalexport.h"
       
    25 
       
    26 #include <Calendar.rsg>
       
    27 
       
    28 #include <calentry.h>
       
    29 #include <CalenExporter.h>
       
    30 
       
    31 #include <bldvariant.hrh> // For FeatureIds (lint warns without)
       
    32 #include <eikenv.h>
       
    33 #include <featmgr.h>
       
    34 #include <StringLoader.h>
       
    35 #include <vtoken.h>
       
    36 #include <s32mem.h>
       
    37 
       
    38 // LOCAL CONSTANTS AND MACROS
       
    39 const TInt KDynBufExpandSize(100);
       
    40 
       
    41 // ============================ MEMBER FUNCTIONS ===============================
       
    42 
       
    43 // ----------------------------------------------------------------------------
       
    44 // TCalenVCalExport::TCalenVCalExport
       
    45 // C++ default constructor can NOT contain any code, that
       
    46 // might leave.
       
    47 // (other items were commented in a header).
       
    48 // ----------------------------------------------------------------------------
       
    49 //
       
    50 TCalenVCalExport::TCalenVCalExport(CCalSession& aCalSession, 
       
    51                                    RFs& aFileServerSession) 
       
    52     : iSession(aCalSession),
       
    53       iFs(aFileServerSession)
       
    54     {
       
    55     TRACE_ENTRY_POINT;
       
    56     TRACE_EXIT_POINT;
       
    57     }
       
    58 
       
    59 // ----------------------------------------------------------------------------
       
    60 // TCalenVCalExport::ExportVCalL
       
    61 // Export an entry
       
    62 // (other items were commented in a header).
       
    63 // ----------------------------------------------------------------------------
       
    64 
       
    65 HBufC8* TCalenVCalExport::ExportVCalLC(CCalEntry& aEntry)
       
    66     {
       
    67     TRACE_ENTRY_POINT;
       
    68     
       
    69     const TDesC& subject=aEntry.SummaryL();
       
    70 
       
    71     TBool emptySubject = subject.Length() ==0;
       
    72     if (emptySubject)
       
    73         {
       
    74         // If subject is empty, we add <unnamed> text to it
       
    75         HBufC* unnamed = StringLoader::LoadLC(R_CALEN_QTN_CALE_NO_SUBJECT, 
       
    76                                               CEikonEnv::Static());
       
    77         aEntry.SetSummaryL(*unnamed);
       
    78         CleanupStack::PopAndDestroy(unnamed);
       
    79         }
       
    80 
       
    81     CBufFlat* buf = CBufFlat::NewL(KDynBufExpandSize);
       
    82     CleanupStack::PushL(buf);
       
    83     ConvertVCalL(buf, aEntry);
       
    84 
       
    85     HBufC8* result = HBufC8::NewL( buf->Size() );
       
    86     result->Des().Copy(buf->Ptr(0));
       
    87     CleanupStack::PopAndDestroy(buf);
       
    88     CleanupStack::PushL(result);
       
    89     
       
    90     TRACE_EXIT_POINT;
       
    91     return result;
       
    92     }
       
    93 
       
    94 // ---------------------------------------------------------
       
    95 // TCalenVCalExpor::ConvertVCalL
       
    96 // Converts from an Agnend entry to vCal data
       
    97 // (other items were commented in a header).
       
    98 // ---------------------------------------------------------
       
    99 //
       
   100 void TCalenVCalExport::ConvertVCalL(CBufFlat* aBuf, CCalEntry& aEntry)
       
   101     {
       
   102     TRACE_ENTRY_POINT;
       
   103     
       
   104     // CCalEntry is converted to VCal
       
   105     RBufWriteStream writeStream;
       
   106     writeStream.Open(*aBuf);
       
   107     CleanupClosePushL(writeStream);
       
   108     CCalenExporter* exporter=CCalenExporter::NewL(iSession);
       
   109     CleanupStack::PushL(exporter);
       
   110     exporter->ExportVCalL( aEntry, writeStream);
       
   111     CleanupStack::PopAndDestroy(exporter);
       
   112     CleanupStack::PopAndDestroy(&writeStream);
       
   113     
       
   114     TRACE_EXIT_POINT;
       
   115     }
       
   116 
       
   117 // ---------------------------------------------------------
       
   118 // TCalenVCalExpor::ConvertICalL
       
   119 // Converts from an Agnend entry to iCal data
       
   120 // (other items were commented in a header).
       
   121 // ---------------------------------------------------------
       
   122 //
       
   123 void TCalenVCalExport::ConvertICalL(CBufFlat* aBuf, CCalEntry& aEntry)
       
   124     {
       
   125     TRACE_ENTRY_POINT;
       
   126     
       
   127     // CCalEntry is converted to iCal
       
   128     RBufWriteStream writeStream;
       
   129     writeStream.Open(*aBuf);
       
   130     CleanupClosePushL(writeStream);
       
   131     CCalenExporter* exporter=CCalenExporter::NewL(iSession);
       
   132     CleanupStack::PushL(exporter);
       
   133     exporter->ExportICalL( aEntry, writeStream);
       
   134     CleanupStack::PopAndDestroy(exporter);
       
   135     CleanupStack::PopAndDestroy(&writeStream);
       
   136     
       
   137     TRACE_EXIT_POINT;
       
   138     }
       
   139 
       
   140 //  End of File