calendarengines/agnversit2/src/AgnRRuleImporter.cpp
changeset 0 f979ecb2b13e
equal deleted inserted replaced
-1:000000000000 0:f979ecb2b13e
       
     1 /*
       
     2 * Copyright (c) 2007-2007 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:   This file contains implementation of iCal parser 
       
    15 *                which parses for RRULE prperrty to create create 
       
    16 *                corresponging TCalRRule.
       
    17 *
       
    18 */
       
    19 
       
    20 
       
    21 
       
    22 #include "AgnRRuleImporter.h"
       
    23 
       
    24 #include "calendarengines_debug.h"
       
    25 
       
    26 // Agenda includes.
       
    27 #include <calrrule.h>			   // For CCalRRule
       
    28 
       
    29 // Versit includes.
       
    30 #include "ICalKeyWords.h"		   // For CICalKeyWords
       
    31 #include "ICalProperty.h"		   // For CICalProperty
       
    32 #include "ICalValue.h"			   // For CICalValue
       
    33 
       
    34 
       
    35 #include "CleanupPointerArray.h"   // For TCleanupPointerArray
       
    36 
       
    37 // RRule Parser includes
       
    38 #include "AgnParseRRuleYearly.h"  // For CAgnParseRRuleYearly
       
    39 #include "AgnParseRRuleMonthly.h" // For CAgnParseRRuleMonthly
       
    40 #include "AgnParseRRuleWeekly.h"  // For CAgnParseRRuleWeekly
       
    41 #include "AgnParseRRuleDaily.h"   // For CAgnParseRRuleDaily
       
    42 
       
    43 /**
       
    44 Constructor
       
    45 @param aAgnImpUtil AgnVersit2Importer utility functions
       
    46 */
       
    47 CAgnRRuleImporter::CAgnRRuleImporter( MAgnImpUtil& aAgnImpUtil ): iAgnImpUtil( aAgnImpUtil )
       
    48     {
       
    49     TRACE_ENTRY_POINT;
       
    50     TRACE_EXIT_POINT;
       
    51     }
       
    52 
       
    53 //Destructor
       
    54 CAgnRRuleImporter::~CAgnRRuleImporter()
       
    55     {
       
    56     TRACE_ENTRY_POINT;
       
    57     TRACE_EXIT_POINT;
       
    58     }
       
    59 
       
    60 /**
       
    61 Constructs a new CAgnRRuleImporter and returns it. 
       
    62 @param aAgnImpUtil AgnVersit2Importer utility functions
       
    63 @return a new CAgnParseRRuleYearly.
       
    64 */
       
    65 CAgnRRuleImporter* CAgnRRuleImporter::NewL( MAgnImpUtil& aAgnImpUtil )
       
    66     {
       
    67     TRACE_ENTRY_POINT;
       
    68     CAgnRRuleImporter *self = CAgnRRuleImporter::NewLC( aAgnImpUtil );
       
    69     CleanupStack::Pop(self);
       
    70     
       
    71     TRACE_EXIT_POINT;
       
    72     return self;     
       
    73     }
       
    74     
       
    75 /**
       
    76 Constructs a new CAgnRRuleImporter and returns it. 
       
    77 The object is left on the cleanup stack.
       
    78 @param aAgnImpUtil AgnVersit2Importer utility functions
       
    79 @return a new CAgnParseRRuleYearly.
       
    80 */
       
    81 CAgnRRuleImporter* CAgnRRuleImporter::NewLC( MAgnImpUtil& aAgnImpUtil )
       
    82     {
       
    83     TRACE_ENTRY_POINT;
       
    84     
       
    85     CAgnRRuleImporter *self = new (ELeave)CAgnRRuleImporter( aAgnImpUtil );
       
    86     CleanupStack::PushL(self);
       
    87     self->ConstructL();
       
    88     
       
    89     TRACE_EXIT_POINT;
       
    90     return self;     
       
    91     }
       
    92 
       
    93 //Two phase constructor
       
    94 void CAgnRRuleImporter::ConstructL()
       
    95     {
       
    96     TRACE_ENTRY_POINT;
       
    97     TRACE_EXIT_POINT;
       
    98     }
       
    99 
       
   100 /**
       
   101 A function to translate an RRULE property into a TCalRRule for Agenda.
       
   102 @param aProperty The RRULE property to translate.
       
   103 @param aEntry The entry to add the rules to.
       
   104 @param aStartTime The DTSTART of the parent component.
       
   105 @return ETrue if the rule is imported, else EFalse.
       
   106 */
       
   107 TBool CAgnRRuleImporter::ImportL( const CICalProperty& aProperty, CCalEntry& aEntry, const TCalTime& aStartTime )
       
   108     {
       
   109     TRACE_ENTRY_POINT;
       
   110    
       
   111     //===============================
       
   112     //Frequency and recurrency rules
       
   113     //===============================
       
   114     const RPointerArray<CICalValue>& rulevalues = aProperty.Values();
       
   115 	
       
   116 	// There should never be less than 1 value.
       
   117 	if (rulevalues.Count() < 1)
       
   118 		{
       
   119 		// We can't continue so abort.
       
   120 		iAgnImpUtil.ReportErrorL(MAgnImportObserver::EImpErrorMissingData, aEntry.UidL(), KICalRRule, EFalse);
       
   121 		}
       
   122 
       
   123     CICalRuleSegment::TFreq freq = CICalRuleSegment::EFreqDaily;
       
   124 	RPointerArray<CICalRuleSegment> recRules;
       
   125 	CleanupPointerArrayPushL(recRules);
       
   126 
       
   127 	// At this point we take ownership of the things which rules contains:
       
   128 	rulevalues[0]->GetRecurrenceRuleL(recRules);
       
   129 
       
   130 	// An RRule must have a frequency.
       
   131 	TInt pos = iAgnImpUtil.FindRuleSegment(recRules, CICalRuleSegment::ESegFreq);
       
   132 	
       
   133 	if (pos != KErrNotFound)
       
   134 		{
       
   135 		ASSERT(recRules.Count() >= pos + 1);
       
   136 		freq = recRules[pos]->FreqL();
       
   137 		}
       
   138 	else
       
   139 		{
       
   140 		iAgnImpUtil.ReportErrorL(MAgnImportObserver::EImpErrorMissingData, aEntry.UidL(), rulevalues[0]->TextL());
       
   141 		// On continue, EFreqDaily will be used.
       
   142 		}
       
   143 
       
   144     //===================================
       
   145     // Create Parser and parse the rrule
       
   146     //===================================
       
   147     TBool parsed = EFalse;
       
   148     TCalRRule rule;
       
   149     
       
   150     //Create parser and parse the recurrency rule
       
   151     CAgnParseRRule* parser = CreateParserLC( freq, rule );
       
   152     
       
   153     if( parser )
       
   154         {
       
   155         //if parser returns true the RRule was parsed successfully
       
   156         parsed = parser->ParseL( rule, recRules, aStartTime, aEntry.UidL(), rulevalues );
       
   157         CleanupStack::PopAndDestroy( parser );
       
   158         }
       
   159     else
       
   160         {
       
   161         parsed = EFalse;
       
   162         iAgnImpUtil.ReportErrorL(MAgnImportObserver::EImpErrorNotSupported, aEntry.UidL(), rulevalues[0]->TextL());
       
   163 		}
       
   164     
       
   165    	//=================================
       
   166     // Update aEntry if parsed is true
       
   167     //=================================
       
   168     if ( parsed )
       
   169 		{
       
   170 		aEntry.SetRRuleL(rule);
       
   171 		}
       
   172 
       
   173     CleanupStack::PopAndDestroy(&recRules);
       
   174     
       
   175     TRACE_EXIT_POINT;
       
   176 	return parsed;
       
   177     }
       
   178 
       
   179 /**
       
   180 Factory method to create the RRule parser
       
   181 @param aFreq The RRULE frequency
       
   182 @param aRule rule to add the frequency to
       
   183 @return returns NULL if parser for CICalRuleSegment::TFreq type not found, otherwise parser
       
   184 */
       
   185 CAgnParseRRule* CAgnRRuleImporter::CreateParserLC( const CICalRuleSegment::TFreq aFreq, TCalRRule& aRule )
       
   186     {
       
   187     TRACE_ENTRY_POINT;
       
   188     
       
   189     CAgnParseRRule* parser; 
       
   190     
       
   191     switch ( aFreq )
       
   192 		{
       
   193 		//Daily
       
   194 		case CICalRuleSegment::EFreqDaily :
       
   195 		    {
       
   196 		    aRule.SetType(TCalRRule::EDaily);
       
   197 		    parser = CAgnParseRRuleDaily::NewLC( iAgnImpUtil );
       
   198 			break;
       
   199 		    }
       
   200 		//Weekly
       
   201 		case CICalRuleSegment::EFreqWeekly :
       
   202 			{
       
   203 			aRule.SetType(TCalRRule::EWeekly);
       
   204 			parser = CAgnParseRRuleWeekly::NewLC( iAgnImpUtil );
       
   205 			break;
       
   206 			}
       
   207         //Monthly			
       
   208 		case CICalRuleSegment::EFreqMonthly :
       
   209 		    {
       
   210 		    aRule.SetType(TCalRRule::EMonthly);
       
   211 		    parser = CAgnParseRRuleMonthly::NewLC( iAgnImpUtil );
       
   212 			break;
       
   213 		    }
       
   214 		//Yearly
       
   215 		case CICalRuleSegment::EFreqYearly :
       
   216 		    {
       
   217 		    aRule.SetType(TCalRRule::EYearly);
       
   218 		    parser = CAgnParseRRuleYearly::NewLC( iAgnImpUtil );
       
   219 			break;
       
   220 		    }
       
   221 		//Not supported
       
   222 		case CICalRuleSegment::EFreqSecondly :	// Not supported, fall through...
       
   223 		case CICalRuleSegment::EFreqMinutely :	// Not supported, fall through...
       
   224 		case CICalRuleSegment::EFreqHourly :	// Not supported, fall through...
       
   225 		default :
       
   226 		    {
       
   227 		   	parser = NULL;
       
   228 			}
       
   229 			
       
   230 		}
       
   231 	
       
   232 	TRACE_EXIT_POINT;
       
   233 	return parser;
       
   234     }