meetingrequest/mricalviewer/src/cesmrinforecurrencehandler.cpp
branchRCL_3
changeset 25 3533d4323edc
parent 0 8466d47a6819
equal deleted inserted replaced
24:d189ee25cf9d 25:3533d4323edc
       
     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 mrinfo recurrence handler implementation
       
    15 *
       
    16 */
       
    17 
       
    18 #include "emailtrace.h"
       
    19 #include "cesmrinforecurrencehandler.h"
       
    20 #include "tesmrinputparams.h"
       
    21 #include "esmrconfig.hrh"
       
    22 
       
    23 //<cmail>
       
    24 #include "mmrinfoobject.h"
       
    25 #include "mmrrecurrencerule.h"
       
    26 #include "esmrdef.h"
       
    27 //</cmail>
       
    28 #include <calentry.h>
       
    29 #include <calrrule.h>
       
    30 
       
    31 // Unnamed namespace for local definitions
       
    32 namespace {
       
    33 
       
    34 /**
       
    35  * Converts MRINFO day into Symbian date.
       
    36  * @param aDay MRINFO day
       
    37  * @return Symbian date
       
    38  */
       
    39 TDay MRInfoDay( MRRecurrenceRule::TMRRecurrentDay aDay )
       
    40     {
       
    41     TDay day( EMonday );
       
    42 
       
    43     switch( aDay )
       
    44         {
       
    45         case MRRecurrenceRule::EMRRecurrenceMonday:
       
    46             {
       
    47             day = EMonday;
       
    48             break;
       
    49             }
       
    50         case MRRecurrenceRule::EMRRecurrenceTuesday:
       
    51             {
       
    52             day = ETuesday;
       
    53             break;
       
    54             }
       
    55         case MRRecurrenceRule::EMRRecurrenceWednesday:
       
    56             {
       
    57             day = EWednesday;
       
    58             break;
       
    59             }
       
    60         case MRRecurrenceRule::EMRRecurrenceThursday:
       
    61             {
       
    62             day =  EThursday;
       
    63             break;
       
    64             }
       
    65         case MRRecurrenceRule::EMRRecurrenceFriday:
       
    66             {
       
    67             day = EFriday;
       
    68             break;
       
    69             }
       
    70         case MRRecurrenceRule::EMRRecurrenceSaturday:
       
    71             {
       
    72             day = ESaturday;
       
    73             break;
       
    74             }
       
    75         case MRRecurrenceRule::EMRRecurrenceSunday:
       
    76             {
       
    77             day = ESunday;
       
    78             break;
       
    79             }
       
    80         default:
       
    81            break;
       
    82         }
       
    83 
       
    84     return day;
       
    85     }
       
    86 
       
    87 } // namespace
       
    88 
       
    89 // ======== MEMBER FUNCTIONS ========
       
    90 
       
    91 // ---------------------------------------------------------------------------
       
    92 // CESMRInfoRecurrenceHandler::CESMRInfoRecurrenceHandler
       
    93 // ---------------------------------------------------------------------------
       
    94 //
       
    95 inline CESMRInfoRecurrenceHandler::CESMRInfoRecurrenceHandler()
       
    96     {
       
    97     FUNC_LOG;
       
    98     //do nothing
       
    99     }
       
   100 
       
   101 // ---------------------------------------------------------------------------
       
   102 // CESMRInfoRecurrenceHandler::~CESMRInfoRecurrenceHandler
       
   103 // ---------------------------------------------------------------------------
       
   104 //
       
   105 CESMRInfoRecurrenceHandler::~CESMRInfoRecurrenceHandler()
       
   106     {
       
   107     FUNC_LOG;
       
   108     //do nothing
       
   109     }
       
   110 
       
   111 // ---------------------------------------------------------------------------
       
   112 // CESMRInfoRecurrenceHandler::NewL
       
   113 // ---------------------------------------------------------------------------
       
   114 //
       
   115 CESMRInfoRecurrenceHandler* CESMRInfoRecurrenceHandler::NewL()
       
   116     {
       
   117     FUNC_LOG;
       
   118     CESMRInfoRecurrenceHandler* self = NewLC();
       
   119     CleanupStack::Pop( self );
       
   120     return self;
       
   121     }
       
   122 
       
   123 // ---------------------------------------------------------------------------
       
   124 // CESMRInfoRecurrenceHandler::NewLC
       
   125 // ---------------------------------------------------------------------------
       
   126 //
       
   127 CESMRInfoRecurrenceHandler* CESMRInfoRecurrenceHandler::NewLC()
       
   128     {
       
   129     FUNC_LOG;
       
   130     CESMRInfoRecurrenceHandler* self =
       
   131         new (ELeave) CESMRInfoRecurrenceHandler();
       
   132     CleanupStack::PushL( self );
       
   133     self->ConstructL();
       
   134     return self;
       
   135     }
       
   136 
       
   137 // ---------------------------------------------------------------------------
       
   138 // CESMRInfoRecurrenceHandler::ConstructL
       
   139 // ---------------------------------------------------------------------------
       
   140 //
       
   141 void CESMRInfoRecurrenceHandler::ConstructL()
       
   142     {
       
   143     FUNC_LOG;
       
   144     //do nothing
       
   145     }
       
   146 
       
   147 // ---------------------------------------------------------------------------
       
   148 // CESMRInfoRecurrenceHandler::ParseRecurrenceInforationL
       
   149 // ---------------------------------------------------------------------------
       
   150 //
       
   151 void CESMRInfoRecurrenceHandler::ParseRecurrenceInforationL(
       
   152         CCalEntry& aCalEntry,
       
   153         const MMRInfoObject& aInfoObject )
       
   154     {
       
   155     FUNC_LOG;
       
   156 
       
   157     TTime until;
       
   158 
       
   159     aCalEntry.ClearRepeatingPropertiesL();
       
   160     GetRecurrenceL(
       
   161             aCalEntry,
       
   162             aInfoObject );
       
   163 
       
   164     }
       
   165 
       
   166 // ---------------------------------------------------------------------------
       
   167 // CESMRInfoRecurrenceHandler::GetRecurrenceL
       
   168 //
       
   169 // ---------------------------------------------------------------------------
       
   170 //
       
   171 void CESMRInfoRecurrenceHandler::GetRecurrenceL(
       
   172         CCalEntry& aCalEntry,
       
   173         const MMRInfoObject& aInfoObject)
       
   174     {
       
   175     FUNC_LOG;
       
   176 
       
   177     const MRRecurrenceRule& recurrenceRule =
       
   178             aInfoObject.RecurrenceRuleL();
       
   179 
       
   180     MRRecurrenceRule::TMRRecurrenceType rType(
       
   181             recurrenceRule.Type() );
       
   182 
       
   183     if ( MRRecurrenceRule::EMRRecurrenceInvalid != rType )
       
   184         {
       
   185         switch ( rType )
       
   186             {
       
   187             case MRRecurrenceRule::EMRRecurrenceDaily:
       
   188                 {
       
   189                 HandleDailyRecurrenceL(
       
   190                         aCalEntry,
       
   191                         aInfoObject );
       
   192                 }
       
   193                 break;
       
   194 
       
   195             case MRRecurrenceRule::EMRRecurrenceWeekly:
       
   196                 {
       
   197                 HandleWeeklyRecurrenceL(
       
   198                         aCalEntry,
       
   199                         aInfoObject );
       
   200                 }
       
   201                 break;
       
   202 
       
   203             case MRRecurrenceRule::EMRRecurrenceMonthly://fallthrough
       
   204             case MRRecurrenceRule::EMRRecurrenceMonthlyByDay:
       
   205                 {
       
   206                 HandleMonthlyRecurrenceL(
       
   207                         aCalEntry,
       
   208                         aInfoObject );
       
   209                 }
       
   210                 break;
       
   211 
       
   212             case MRRecurrenceRule::EMRRecurrenceYearly:
       
   213                 {
       
   214                 HandleYearlyRecurrenceL(
       
   215                         aCalEntry,
       
   216                         aInfoObject );
       
   217                 }
       
   218                 break;
       
   219             default:
       
   220                break;
       
   221             }
       
   222         }
       
   223 
       
   224     }
       
   225 
       
   226 // ---------------------------------------------------------------------------
       
   227 // CESMRInfoRecurrenceHandler::HandleDailyRecurrenceL
       
   228 // ---------------------------------------------------------------------------
       
   229 //
       
   230 void CESMRInfoRecurrenceHandler::HandleDailyRecurrenceL(
       
   231         CCalEntry& aCalEntry,
       
   232         const MMRInfoObject& aInfoObject )
       
   233     {
       
   234     FUNC_LOG;
       
   235     const MRRecurrenceRule& recurrenceRule =
       
   236             aInfoObject.RecurrenceRuleL();
       
   237 
       
   238     TCalRRule rRule;
       
   239     rRule.SetType( TCalRRule::EDaily );
       
   240 
       
   241     TCalTime meetingStartTime = aCalEntry.StartTimeL();
       
   242     rRule.SetDtStart( meetingStartTime );
       
   243 
       
   244 
       
   245     TTime until( recurrenceRule.RecurrentUntil() );
       
   246     if ( Time::NullTTime() != until )
       
   247         {
       
   248         TDateTime untilDt = until.DateTime();
       
   249 
       
   250         TDateTime endTime =
       
   251             aCalEntry.EndTimeL().TimeLocalL().DateTime();
       
   252         untilDt.SetHour( endTime.Hour() );
       
   253         untilDt.SetMinute( endTime.Minute() );
       
   254         untilDt.SetSecond( endTime.Second() );
       
   255 
       
   256         TCalTime rEndTime;
       
   257         rEndTime.SetTimeLocalL( TTime(untilDt) );
       
   258 
       
   259         rRule.SetUntil( rEndTime );
       
   260         }
       
   261     else
       
   262         {
       
   263         TInt interval( recurrenceRule.RecurrentInterval() );
       
   264         TInt count( recurrenceRule.RecurrentCount() );
       
   265 
       
   266         rRule.SetCount( count );
       
   267         rRule.SetInterval( interval );
       
   268         }
       
   269 
       
   270     aCalEntry.SetRRuleL( rRule );
       
   271     }
       
   272 
       
   273 // ---------------------------------------------------------------------------
       
   274 // CESMRInfoRecurrenceHandler::HandleWeeklyRecurrenceL
       
   275 // ---------------------------------------------------------------------------
       
   276 //
       
   277 void CESMRInfoRecurrenceHandler::HandleWeeklyRecurrenceL(
       
   278         CCalEntry& aCalEntry,
       
   279         const MMRInfoObject& aInfoObject )
       
   280     {
       
   281     FUNC_LOG;
       
   282     const MRRecurrenceRule& recurrenceRule =
       
   283             aInfoObject.RecurrenceRuleL();
       
   284 
       
   285     TCalRRule rRule;
       
   286     rRule.SetType( TCalRRule::EWeekly );
       
   287     TCalTime meetingStartTime = aCalEntry.StartTimeL();
       
   288     rRule.SetDtStart( meetingStartTime );
       
   289     TInt interval( recurrenceRule.RecurrentInterval() );
       
   290 
       
   291     TTime until( recurrenceRule.RecurrentUntil() );
       
   292     if ( Time::NullTTime() != until )
       
   293         {
       
   294         TDateTime untilDt = until.DateTime();
       
   295 
       
   296         TDateTime endTime =
       
   297             aCalEntry.EndTimeL().TimeLocalL().DateTime();
       
   298         untilDt.SetHour( endTime.Hour() );
       
   299         untilDt.SetMinute( endTime.Minute() );
       
   300         untilDt.SetSecond( endTime.Second() );
       
   301 
       
   302         TCalTime rEndTime;
       
   303         rEndTime.SetTimeLocalL( TTime(untilDt) );
       
   304 
       
   305         rRule.SetUntil( rEndTime );
       
   306         
       
   307         rRule.SetInterval( interval );
       
   308         }
       
   309     else
       
   310         {
       
   311         TInt count( recurrenceRule.RecurrentCount() );
       
   312 
       
   313         rRule.SetCount( count );
       
   314         rRule.SetInterval( interval );
       
   315 
       
   316         }
       
   317     const RArray<MRRecurrenceRule::TMRRecurrentDay>&
       
   318     recurrenceDays(
       
   319             recurrenceRule.RecurrentWeekDays() );
       
   320 
       
   321     if ( recurrenceDays.Count() )
       
   322         {
       
   323         RArray<TDay> dDays;
       
   324         CleanupClosePushL( dDays );
       
   325         for ( TInt i(0); i < recurrenceDays.Count(); ++i )
       
   326             {
       
   327             dDays.Append( MRInfoDay( recurrenceDays[i] ) );
       
   328             }
       
   329 
       
   330         rRule.SetByDay( dDays );
       
   331         CleanupStack::PopAndDestroy( &dDays );
       
   332         }
       
   333 
       
   334     aCalEntry.SetRRuleL( rRule );
       
   335     }
       
   336 
       
   337 // ---------------------------------------------------------------------------
       
   338 // CESMRInfoRecurrenceHandler::HandleMonthlyRecurrenceL
       
   339 // ---------------------------------------------------------------------------
       
   340 //
       
   341 void CESMRInfoRecurrenceHandler::HandleMonthlyRecurrenceL(
       
   342         CCalEntry& aCalEntry,
       
   343         const MMRInfoObject& aInfoObject )
       
   344     {
       
   345     FUNC_LOG;
       
   346     const MRRecurrenceRule& recurrenceRule =
       
   347             aInfoObject.RecurrenceRuleL();
       
   348 
       
   349     TCalRRule rRule;
       
   350     rRule.SetType( TCalRRule::EMonthly );
       
   351     TCalTime meetingStartTime = aCalEntry.StartTimeL();
       
   352     rRule.SetDtStart( meetingStartTime );
       
   353 
       
   354     TInt interval( recurrenceRule.RecurrentInterval() );
       
   355 
       
   356     TTime until( recurrenceRule.RecurrentUntil() );
       
   357     if ( Time::NullTTime() != until )
       
   358         {
       
   359         TDateTime untilDt = until.DateTime();
       
   360 
       
   361         TDateTime endTime =
       
   362             aCalEntry.EndTimeL().TimeLocalL().DateTime();
       
   363         untilDt.SetHour( endTime.Hour() );
       
   364         untilDt.SetMinute( endTime.Minute() );
       
   365         untilDt.SetSecond( endTime.Second() );
       
   366 
       
   367         TCalTime rEndTime;
       
   368         rEndTime.SetTimeLocalL( TTime(untilDt) );
       
   369 
       
   370         rRule.SetUntil( rEndTime );
       
   371         }
       
   372     else
       
   373         {
       
   374         TInt count( recurrenceRule.RecurrentCount() );
       
   375         rRule.SetCount( count );
       
   376         rRule.SetInterval( interval );
       
   377         }
       
   378 
       
   379     const RArray<MRRecurrenceRule::TRecurrentDaysofMonth>&
       
   380     recurrenceDays(
       
   381             recurrenceRule.RecurrentDaysofMonth() );
       
   382 
       
   383     const RArray<TInt>& recurrenceDaysInMonth(
       
   384             recurrenceRule.RecurrentMonthDays() );
       
   385 
       
   386     if ( recurrenceDays.Count() )
       
   387         {
       
   388         RArray<TCalRRule::TDayOfMonth> dDays;
       
   389         CleanupClosePushL( dDays );
       
   390         for ( TInt i(0); i < recurrenceDays.Count(); ++i )
       
   391             {
       
   392             TCalRRule::TDayOfMonth dayOfMonth(
       
   393                     MRInfoDay( recurrenceDays[i].iDayOfWeek ),
       
   394                     static_cast<TInt8>( recurrenceDays[i].iWeekOfMonth ) );
       
   395             }
       
   396 
       
   397         rRule.SetByDay( dDays );
       
   398         CleanupStack::PopAndDestroy( &dDays );
       
   399         }
       
   400     else if ( recurrenceDaysInMonth.Count() )
       
   401         {
       
   402         rRule.SetByMonthDay( recurrenceDaysInMonth );
       
   403         }
       
   404 
       
   405     aCalEntry.SetRRuleL( rRule );
       
   406     }
       
   407 
       
   408 // ---------------------------------------------------------------------------
       
   409 // CESMRInfoRecurrenceHandler::HandleYearlyRecurrenceL
       
   410 // ---------------------------------------------------------------------------
       
   411 //
       
   412 void CESMRInfoRecurrenceHandler::HandleYearlyRecurrenceL(
       
   413         CCalEntry& aCalEntry,
       
   414         const MMRInfoObject& aInfoObject )
       
   415     {
       
   416     FUNC_LOG;
       
   417     const MRRecurrenceRule& recurrenceRule =
       
   418             aInfoObject.RecurrenceRuleL();
       
   419 
       
   420     TCalRRule rRule;
       
   421     rRule.SetType( TCalRRule::EYearly );
       
   422     TCalTime meetingStartTime = aCalEntry.StartTimeL();
       
   423     rRule.SetDtStart( meetingStartTime );
       
   424 
       
   425     TInt interval( recurrenceRule.RecurrentInterval() );
       
   426 
       
   427     TTime until( recurrenceRule.RecurrentUntil() );
       
   428     if ( Time::NullTTime() != until )
       
   429         {
       
   430         TDateTime untilDt = until.DateTime();
       
   431 
       
   432         TDateTime endTime =
       
   433             aCalEntry.EndTimeL().TimeLocalL().DateTime();
       
   434         untilDt.SetHour( endTime.Hour() );
       
   435         untilDt.SetMinute( endTime.Minute() );
       
   436         untilDt.SetSecond( endTime.Second() );
       
   437 
       
   438         TCalTime rEndTime;
       
   439         rEndTime.SetTimeLocalL( TTime(untilDt) );
       
   440 
       
   441         rRule.SetUntil( rEndTime );
       
   442         }
       
   443     else
       
   444         {
       
   445         TInt count( recurrenceRule.RecurrentCount() );
       
   446         rRule.SetCount( count );
       
   447         }
       
   448 
       
   449     const RArray<MRRecurrenceRule::TMRRecurrenceMonth>&
       
   450     recurrenceMonths(
       
   451             recurrenceRule.RecurrentMonths() );
       
   452 
       
   453     TInt recurrenceMonthCount( recurrenceMonths.Count() );
       
   454     if ( recurrenceMonthCount )
       
   455         {
       
   456         RArray<TMonth> months;
       
   457         CleanupClosePushL( months );
       
   458         for ( TInt i(0); i < recurrenceMonthCount; ++i )
       
   459             {
       
   460             months.Append(
       
   461                     static_cast<TMonth>(recurrenceMonths[i]) );
       
   462             }
       
   463 
       
   464         rRule.SetByMonth( months );
       
   465         CleanupStack::PopAndDestroy( &months );
       
   466         }
       
   467 
       
   468     aCalEntry.SetRRuleL( rRule );
       
   469     }
       
   470 
       
   471 // EOF
       
   472