meetingrequest/mragnversit2/src/cesmragnparserrule.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: This file implements class CESMRAgnParseRRule.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 #include "emailtrace.h"
       
    21 #include "cesmragnparserrule.h"
       
    22 
       
    23 //<cmail>
       
    24 
       
    25 #include <calrrule.h>
       
    26 #include "cesmricalvalue.h"         // for cesmricalvalue
       
    27 //</cmail>
       
    28 
       
    29 // ======== MEMBER FUNCTIONS ========
       
    30 
       
    31 // ---------------------------------------------------------------------------
       
    32 // CESMRAgnParseRRule::CESMRAgnParseRRule
       
    33 // ---------------------------------------------------------------------------
       
    34 //
       
    35 CESMRAgnParseRRule::CESMRAgnParseRRule( MESMRAgnImpUtil& aAgnImpUtil ) :
       
    36                             iAgnImpUtil( aAgnImpUtil ),
       
    37                             iSetSegs( 0 )
       
    38     {
       
    39     FUNC_LOG;
       
    40     //do nothing
       
    41     }
       
    42 
       
    43 // ---------------------------------------------------------------------------
       
    44 // CESMRAgnParseRRule::~CESMRAgnParseRRule
       
    45 // ---------------------------------------------------------------------------
       
    46 //
       
    47 CESMRAgnParseRRule::~CESMRAgnParseRRule()
       
    48     {
       
    49     FUNC_LOG;
       
    50     //do nothing
       
    51     }
       
    52 
       
    53 // ---------------------------------------------------------------------------
       
    54 // CESMRAgnParseRRule::ParseL
       
    55 // ---------------------------------------------------------------------------
       
    56 //
       
    57 TBool CESMRAgnParseRRule::ParseL( TCalRRule& aRule, RPointerArray<CESMRICalRuleSegment>& aRecRules,
       
    58                               const TCalTime& aStartTime, const TDesC8& aUid,
       
    59                               const RPointerArray<CESMRICalValue>& aRulevalues )
       
    60     {
       
    61     FUNC_LOG;
       
    62 
       
    63     aRule.SetDtStart( aStartTime );
       
    64 
       
    65     TInt recCount = aRecRules.Count();
       
    66     TBool parsed = EFalse;
       
    67 
       
    68     //Loop through the CESMRICalRuleSegments
       
    69     for (TInt rnum = 0; rnum < aRecRules.Count(); ++rnum)
       
    70         {
       
    71         parsed = EFalse;
       
    72 
       
    73         CESMRICalRuleSegment* segment = aRecRules[rnum];
       
    74 
       
    75         if (segment->Values().Count() < 1  && aRulevalues.Count() > 0 )
       
    76             {
       
    77             iAgnImpUtil.ReportErrorL( MESMRAgnImportObserver::EImpErrorMissingData, aUid,
       
    78                                       aRulevalues[0]->TextL() );
       
    79             // On continue, all we have is FREQ=DAILY.
       
    80             }
       
    81 
       
    82         //Try to parse it with specific parser
       
    83         TRAPD( error, parsed = DoParseL( *segment, aRule ) );
       
    84 
       
    85         //if the keyword was not parsed, try to parse it
       
    86         if( error == KErrNone && !parsed )
       
    87             {
       
    88             //Update aRule with CESMRICalRuleSegment
       
    89             switch (segment->Type())
       
    90                 {
       
    91                 case CESMRICalRuleSegment::ESegFreq :
       
    92                     break;
       
    93 
       
    94                 //Set Until
       
    95                 case CESMRICalRuleSegment::ESegUntil :
       
    96                     {
       
    97                     SetRRuleUntilL( *segment, aRule );
       
    98                     break;
       
    99                     }
       
   100 
       
   101                 //Set Count
       
   102                 case CESMRICalRuleSegment::ESegCount :
       
   103                     {
       
   104                     aRule.SetCount(segment->Values()[0]->IntegerL());
       
   105                     break;
       
   106                     }
       
   107 
       
   108                 //Set Interval
       
   109                 case CESMRICalRuleSegment::ESegInterval :
       
   110                     {
       
   111                     aRule.SetInterval(segment->Values()[0]->IntegerL());
       
   112                     break;
       
   113                     }
       
   114 
       
   115                 //Not supported keywords by freq, report error
       
   116                 case CESMRICalRuleSegment::ESegByPos :      // not supported by freq, fall through
       
   117                 case CESMRICalRuleSegment::ESegBySecond :   // not supported by freq, fall through
       
   118                 case CESMRICalRuleSegment::ESegByMinute :   // not supported by freq, fall through
       
   119                 case CESMRICalRuleSegment::ESegByHour :     // not supported by freq, fall through
       
   120                 case CESMRICalRuleSegment::ESegByYearDay :  // not supported by freq, fall through
       
   121                 case CESMRICalRuleSegment::ESegByWeekNo :   // not supported by freq, fall through
       
   122                 case CESMRICalRuleSegment::ESegExtension :  // not supported by freq, fall through
       
   123                 case CESMRICalRuleSegment::ESegWkSt :       // not supported by freq, fall through
       
   124                 case CESMRICalRuleSegment::ESegByDay :      // not supported by freq, fall through
       
   125                 case CESMRICalRuleSegment::ESegByMonthDay : // not supported by freq, fall through
       
   126                 case CESMRICalRuleSegment::ESegByMonth :    // not supported by freq, fall through
       
   127                 default:
       
   128                     {
       
   129                     if(aRulevalues.Count() > 0)
       
   130                         {
       
   131                         iAgnImpUtil.ReportErrorL( MESMRAgnImportObserver::EImpErrorNotSupported, aUid,
       
   132                                               aRulevalues[0]->TextL() );
       
   133                         }
       
   134                     }
       
   135                 }
       
   136             }
       
   137 
       
   138         //TRAP returned error
       
   139         else if( error != KErrNone )
       
   140             {
       
   141             if( error == KErrAbort )//KErrAbort, report error and stop parsing
       
   142                 {
       
   143                 
       
   144                 if(aRulevalues.Count() > 0)
       
   145                 	{
       
   146                     iAgnImpUtil.ReportErrorL( MESMRAgnImportObserver::EImpErrorNotSupported, aUid,
       
   147                                           aRulevalues[0]->TextL(), EFalse );
       
   148                 	}
       
   149                 }
       
   150             else //Otherwise leave with error
       
   151                 {
       
   152                 User::Leave( error );
       
   153                 }
       
   154             }
       
   155 
       
   156         }//for end
       
   157 
       
   158 
       
   159     //Finalize parsing
       
   160     parsed = FinalizeParsingL( aRule, aStartTime );
       
   161 
       
   162     return parsed;
       
   163     }
       
   164 
       
   165 // ---------------------------------------------------------------------------
       
   166 // CESMRAgnParseRRule::DoParseL
       
   167 // ---------------------------------------------------------------------------
       
   168 //
       
   169 TBool CESMRAgnParseRRule::DoParseL( CESMRICalRuleSegment& /*aSegment*/, TCalRRule& /*aRule*/ )
       
   170     {
       
   171     FUNC_LOG;
       
   172 
       
   173     return EFalse;
       
   174     }
       
   175 
       
   176 // ---------------------------------------------------------------------------
       
   177 // CESMRAgnParseRRule::FinalizeParsingL
       
   178 // ---------------------------------------------------------------------------
       
   179 //
       
   180 TBool CESMRAgnParseRRule::FinalizeParsingL( TCalRRule& aRule, const TCalTime& /*aStartTime*/ )
       
   181     {
       
   182     FUNC_LOG;
       
   183 
       
   184     TBool finalized = ETrue;
       
   185 
       
   186     // Agenda requires that all RRULES have an interval of some sort.
       
   187     // An interval of 1 is the default.
       
   188     if (aRule.Interval() < 1)
       
   189         {
       
   190         aRule.SetInterval(1);
       
   191         }
       
   192 
       
   193     return finalized;
       
   194     }
       
   195 
       
   196 // ---------------------------------------------------------------------------
       
   197 // CESMRAgnParseRRule::SetRRuleUntilL
       
   198 // ---------------------------------------------------------------------------
       
   199 //
       
   200 TBool CESMRAgnParseRRule::SetRRuleUntilL( const CESMRICalRuleSegment& aSegment, TCalRRule& aRule )
       
   201     {
       
   202     FUNC_LOG;
       
   203 
       
   204     TTime time;
       
   205     TCalTime calTime;
       
   206 
       
   207      // adding time and date information to the Repeat Until field
       
   208   CESMRICalValue::TTimeZoneType type = CESMRICalValue::EUtcTime;
       
   209     aSegment.Values()[0]->GetDateTimeL(time, type);
       
   210 
       
   211     calTime.SetTimeUtcL(time);
       
   212     aRule.SetUntil(calTime);
       
   213 
       
   214     return ETrue;
       
   215     }
       
   216 
       
   217 // ---------------------------------------------------------------------------
       
   218 // CESMRAgnParseRRule::SetRRuleWkStL
       
   219 // ---------------------------------------------------------------------------
       
   220 //
       
   221 TBool CESMRAgnParseRRule::SetRRuleWkStL( const CESMRICalRuleSegment& aSegment, TCalRRule& aRule )
       
   222     {
       
   223     FUNC_LOG;
       
   224 
       
   225     TDay dayval;
       
   226     TInt daypos;
       
   227     aSegment.Values()[0]->GetDayL(dayval, daypos);
       
   228     aRule.SetWkSt(dayval);
       
   229 
       
   230     return ETrue;
       
   231     }
       
   232 
       
   233 // ---------------------------------------------------------------------------
       
   234 // CESMRAgnParseRRule::SetRRuleByDayL
       
   235 // ---------------------------------------------------------------------------
       
   236 //
       
   237 TBool CESMRAgnParseRRule::SetRRuleByDayL( const CESMRICalRuleSegment& aSegment, TCalRRule& aRule )
       
   238     {
       
   239     FUNC_LOG;
       
   240 
       
   241     RArray<TCalRRule::TDayOfMonth> daysOfMonth;
       
   242     CleanupClosePushL(daysOfMonth);
       
   243 
       
   244     const RPointerArray<CESMRICalValue>& values = aSegment.Values();
       
   245 
       
   246     TInt valCount = values.Count();
       
   247     TDay dayval = EMonday;
       
   248     TInt daypos = 0;
       
   249 
       
   250     for (TInt day = 0; day < valCount; ++day)
       
   251         {
       
   252         values[day]->GetDayL(dayval, daypos);
       
   253         if ((daypos == -1) || ((daypos >= 1) && (daypos <= KMaxWeekDayNum)))
       
   254             {
       
   255             User::LeaveIfError(daysOfMonth.Append(TCalRRule::TDayOfMonth(dayval, daypos)));
       
   256             }
       
   257         else if (daypos == 0)
       
   258             //BYDAY applies to every day in month
       
   259             {
       
   260             User::LeaveIfError(daysOfMonth.Append(TCalRRule::TDayOfMonth(dayval, 1)));
       
   261             User::LeaveIfError(daysOfMonth.Append(TCalRRule::TDayOfMonth(dayval, 2)));
       
   262             User::LeaveIfError(daysOfMonth.Append(TCalRRule::TDayOfMonth(dayval, 3)));
       
   263             User::LeaveIfError(daysOfMonth.Append(TCalRRule::TDayOfMonth(dayval, 4)));
       
   264             User::LeaveIfError(daysOfMonth.Append(TCalRRule::TDayOfMonth(dayval, -1)));
       
   265             }
       
   266         else
       
   267             {
       
   268             //Invalid day - unrecoverable
       
   269             User::Leave( KErrAbort );
       
   270             }
       
   271         }
       
   272 
       
   273     aRule.SetByDay(daysOfMonth);
       
   274     CleanupStack::PopAndDestroy(&daysOfMonth);
       
   275     iSetSegs |= ESegFlagByDay;
       
   276 
       
   277     return ETrue;
       
   278     }
       
   279 
       
   280 // ---------------------------------------------------------------------------
       
   281 // CESMRAgnParseRRule::SetRRuleByMonthL
       
   282 // ---------------------------------------------------------------------------
       
   283 //
       
   284 TBool CESMRAgnParseRRule::SetRRuleByMonthL( const CESMRICalRuleSegment& aSegment, TCalRRule& aRule )
       
   285     {
       
   286     FUNC_LOG;
       
   287 
       
   288     RArray<TMonth> theMonths;
       
   289     CleanupClosePushL(theMonths);
       
   290     const RPointerArray<CESMRICalValue>& values = aSegment.Values();
       
   291     TInt valCount = values.Count();
       
   292 
       
   293     for (TInt month = 0; month < valCount; ++month)
       
   294         {
       
   295         User::LeaveIfError(theMonths.Append(values[month]->MonthL()));
       
   296         }
       
   297 
       
   298     iSetSegs |= ESegFlagByMonth;
       
   299     aRule.SetByMonth(theMonths);
       
   300     CleanupStack::PopAndDestroy(&theMonths);
       
   301 
       
   302     return ETrue;
       
   303     }
       
   304 
       
   305 // ---------------------------------------------------------------------------
       
   306 // CESMRAgnParseRRule::SetRRuleByMonthDayL
       
   307 // ---------------------------------------------------------------------------
       
   308 //
       
   309 TBool CESMRAgnParseRRule::SetRRuleByMonthDayL( const CESMRICalRuleSegment& aSegment, TCalRRule& aRule )
       
   310     {
       
   311     FUNC_LOG;
       
   312 
       
   313     RArray<TInt> days;
       
   314     CleanupClosePushL(days);
       
   315     const RPointerArray<CESMRICalValue>& values = aSegment.Values();
       
   316     TInt valCount = values.Count();
       
   317 
       
   318     for (TInt day = 0; day < valCount; ++day)
       
   319         {
       
   320         //dates are represented as day - 1 (0 = 1) in TDateTime
       
   321         User::LeaveIfError(days.Append(values[day]->IntegerL() - 1 ));
       
   322         }
       
   323 
       
   324     aRule.SetByMonthDay(days);
       
   325     CleanupStack::PopAndDestroy(&days);
       
   326     iSetSegs |= ESegFlagByMonthDay;
       
   327 
       
   328     return ETrue;
       
   329     }
       
   330