meetingrequest/mragnversit2/src/cesmragnparserruleweekly.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 CESMRAgnParseRRuleWeekly.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include "emailtrace.h"
       
    20 #include "cesmragnparserruleweekly.h"
       
    21 
       
    22 //<cmail>
       
    23 #include "cesmricalvalue.h"
       
    24 //</cmail>
       
    25 #include <calrrule.h>
       
    26 
       
    27 // ======== MEMBER FUNCTIONS ========
       
    28 
       
    29 // ---------------------------------------------------------------------------
       
    30 // CESMRAgnParseRRuleWeekly::~CESMRAgnParseRRuleWeekly
       
    31 // ---------------------------------------------------------------------------
       
    32 //
       
    33 CESMRAgnParseRRuleWeekly::CESMRAgnParseRRuleWeekly( MESMRAgnImpUtil& aAgnImpUtil ):
       
    34                         CESMRAgnParseRRule( aAgnImpUtil )
       
    35     {
       
    36     FUNC_LOG;
       
    37     }
       
    38 
       
    39 // ---------------------------------------------------------------------------
       
    40 // CESMRAgnParseRRuleWeekly::CESMRAgnParseRRuleWeekly
       
    41 // ---------------------------------------------------------------------------
       
    42 //
       
    43 CESMRAgnParseRRuleWeekly::~CESMRAgnParseRRuleWeekly()
       
    44     {
       
    45     FUNC_LOG;
       
    46     }
       
    47 
       
    48 // ---------------------------------------------------------------------------
       
    49 // CESMRAgnParseRRuleWeekly::NewLC
       
    50 // ---------------------------------------------------------------------------
       
    51 //
       
    52 CESMRAgnParseRRule* CESMRAgnParseRRuleWeekly::NewLC( MESMRAgnImpUtil& aAgnImpUtil )
       
    53     {
       
    54     FUNC_LOG;
       
    55 
       
    56     CESMRAgnParseRRule *self = new (ELeave) CESMRAgnParseRRuleWeekly( aAgnImpUtil );
       
    57     CleanupStack::PushL( self );
       
    58 
       
    59     return self;
       
    60     }
       
    61 
       
    62 // ---------------------------------------------------------------------------
       
    63 // CESMRAgnParseRRuleWeekly::DoParseL
       
    64 // ---------------------------------------------------------------------------
       
    65 //
       
    66 TBool CESMRAgnParseRRuleWeekly::DoParseL( CESMRICalRuleSegment& aSegment, TCalRRule& aRule )
       
    67     {
       
    68     FUNC_LOG;
       
    69 
       
    70     TBool parsed = ETrue;
       
    71 
       
    72     switch( aSegment.Type() )
       
    73         {
       
    74         //ESegWkSt
       
    75         case CESMRICalRuleSegment::ESegWkSt :
       
    76             {
       
    77             parsed = SetRRuleWkStL( aSegment, aRule );
       
    78             break;
       
    79             }
       
    80 
       
    81         //ESegByDay
       
    82         case CESMRICalRuleSegment::ESegByDay :
       
    83             {
       
    84             parsed = SetRRuleByDayL( aSegment, aRule );
       
    85             break;
       
    86             }
       
    87         default:
       
    88             {
       
    89             parsed = EFalse;
       
    90             }
       
    91         }
       
    92 
       
    93     return parsed;
       
    94     }
       
    95 
       
    96 // ---------------------------------------------------------------------------
       
    97 // CESMRAgnParseRRuleWeekly::FinalizeParsingL
       
    98 // ---------------------------------------------------------------------------
       
    99 //
       
   100 TBool CESMRAgnParseRRuleWeekly::FinalizeParsingL( TCalRRule& aRule, const TCalTime& aStartTime )
       
   101     {
       
   102     FUNC_LOG;
       
   103 
       
   104     //Call the parent, to set some common values
       
   105     TBool finalized = CESMRAgnParseRRule::FinalizeParsingL( aRule, aStartTime );
       
   106 
       
   107     // If we are yearly or weekly we can only handle ByDay, and need to handle it
       
   108     // differently for each.
       
   109     if ( !( iSetSegs & ESegFlagByDay ) )
       
   110         {
       
   111         RArray<TDay> days;
       
   112         CleanupClosePushL(days);
       
   113         User::LeaveIfError(days.Append(aStartTime.TimeUtcL().DayNoInWeek()));
       
   114         aRule.SetByDay(days);
       
   115         CleanupStack::PopAndDestroy(&days);
       
   116         }
       
   117 
       
   118     return finalized;
       
   119     }
       
   120 
       
   121 // ---------------------------------------------------------------------------
       
   122 // CESMRAgnParseRRuleWeekly::SetRRuleByDayL
       
   123 // ---------------------------------------------------------------------------
       
   124 //
       
   125 TBool CESMRAgnParseRRuleWeekly::SetRRuleByDayL( const CESMRICalRuleSegment& aSegment, TCalRRule& aRule )
       
   126     {
       
   127     FUNC_LOG;
       
   128 
       
   129     TBool parsed = ETrue;
       
   130 
       
   131     RArray<TDay> days;
       
   132     CleanupClosePushL(days);
       
   133 
       
   134     const RPointerArray<CESMRICalValue>& values = aSegment.Values();
       
   135     TInt valCount = values.Count();
       
   136     TDay dayval = EMonday;
       
   137     TInt daypos = 0;
       
   138 
       
   139     for (TInt day = 0; day < valCount; ++day)
       
   140         {
       
   141         values[day]->GetDayL(dayval, daypos);
       
   142 
       
   143         if (daypos == 0)
       
   144             {
       
   145             User::LeaveIfError(days.Append(dayval));
       
   146             }
       
   147         }
       
   148 
       
   149     if( parsed )
       
   150         {
       
   151         aRule.SetByDay(days);
       
   152         iSetSegs |= ESegFlagByDay;
       
   153         }
       
   154 
       
   155     CleanupStack::PopAndDestroy(&days);
       
   156 
       
   157     return parsed;
       
   158     }
       
   159