meetingui/meetingrequestutils/src/CMRUtilsCalDbBase.cpp
changeset 0 f979ecb2b13e
equal deleted inserted replaced
-1:000000000000 0:f979ecb2b13e
       
     1 /*
       
     2 * Copyright (c) 2005 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:Implementation for meeting request utils calendar 
       
    15 * data base
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 // ----------------------------------------------------------------------------
       
    21 // INCLUDE FILES
       
    22 // ----------------------------------------------------------------------------
       
    23 //
       
    24 #include "CMRUtilsCalDbBase.h"
       
    25 #include "MREntryConsultant.h"
       
    26 #include "MRHelpers.h"
       
    27 #include <ct/RCPointerArray.h>
       
    28 #include <CalEntryView.h>
       
    29 #include <CalInstanceView.h>
       
    30 #include <CalEntry.h>
       
    31 #include <CalInstance.h>
       
    32 #include <CalUser.h>
       
    33 #include <CalRRule.h>
       
    34 #include <CalTime.h>
       
    35 
       
    36 // CONSTANTS
       
    37 /// Unnamed namespace for local definitions
       
    38 namespace {
       
    39 
       
    40 enum TPanicCode
       
    41     {
       
    42     EPanicNonEmptyParamArray = 1
       
    43     };
       
    44 
       
    45 _LIT( KPanicMsg, "CMRUtilsCalDbBase" );
       
    46 
       
    47 void Panic( TPanicCode aReason )
       
    48     {
       
    49     User::Panic( KPanicMsg, aReason );
       
    50     }
       
    51     
       
    52 }  // namespace
       
    53 
       
    54 // ----------------------------------------------------------------------------
       
    55 // MEMBER FUNCTIONS
       
    56 // ----------------------------------------------------------------------------
       
    57 //
       
    58 
       
    59 // ----------------------------------------------------------------------------
       
    60 // CMRUtilsCalDbBase::CMRUtilsCalDbBase
       
    61 //
       
    62 // Constructor.
       
    63 // ----------------------------------------------------------------------------
       
    64 //
       
    65 CMRUtilsCalDbBase::CMRUtilsCalDbBase(
       
    66     MMRUtilsCalDbObserver& aDbObserver,
       
    67     MCalProgressCallBack& aCmdObserver )
       
    68     : iDbObserver( aDbObserver ),
       
    69       iCmdObserver( aCmdObserver ),
       
    70       iDbStatus( MMRUtilsCalDbObserver::EUninitialized )
       
    71     {
       
    72     
       
    73     }
       
    74     
       
    75 // ----------------------------------------------------------------------------
       
    76 // CMRUtilsCalDbBase::~CMRUtilsCalDbBase
       
    77 //
       
    78 // Destructor.
       
    79 // ----------------------------------------------------------------------------
       
    80 //        
       
    81 CMRUtilsCalDbBase::~CMRUtilsCalDbBase()
       
    82     {   
       
    83     // subclasses take care of deleting entry & instance view if they
       
    84     // create them!
       
    85     }
       
    86 
       
    87 // ----------------------------------------------------------------------------
       
    88 // CMRUtilsCalDbBase::EntryView
       
    89 // ----------------------------------------------------------------------------
       
    90 //    
       
    91 const CCalEntryView* CMRUtilsCalDbBase::EntryView() const
       
    92     {
       
    93     return iCalEntryView;
       
    94     }
       
    95 
       
    96 // ----------------------------------------------------------------------------
       
    97 // CMRUtilsCalDbBase::InstanceView
       
    98 // ----------------------------------------------------------------------------
       
    99 //        
       
   100 const CCalInstanceView* CMRUtilsCalDbBase::InstanceView() const
       
   101     {
       
   102     return iCalInstanceView;
       
   103     }
       
   104 
       
   105 // ----------------------------------------------------------------------------
       
   106 // CMRUtilsCalDbBase::Session
       
   107 // ----------------------------------------------------------------------------
       
   108 //        
       
   109 const CCalSession* CMRUtilsCalDbBase::Session() const
       
   110     {
       
   111     return iCalSession;
       
   112     }
       
   113 
       
   114 // ----------------------------------------------------------------------------
       
   115 // CMRUtilsCalDbBase::EntryView
       
   116 // ----------------------------------------------------------------------------
       
   117 //    
       
   118 CCalEntryView* CMRUtilsCalDbBase::EntryView()
       
   119     {
       
   120     return iCalEntryView;
       
   121     }
       
   122 
       
   123 // ----------------------------------------------------------------------------
       
   124 // CMRUtilsCalDbBase::InstanceView
       
   125 // ----------------------------------------------------------------------------
       
   126 //        
       
   127 CCalInstanceView* CMRUtilsCalDbBase::InstanceView()
       
   128     {
       
   129     return iCalInstanceView;
       
   130     }
       
   131 
       
   132 // ----------------------------------------------------------------------------
       
   133 // CMRUtilsCalDbBase::Session
       
   134 // ----------------------------------------------------------------------------
       
   135 //        
       
   136 CCalSession* CMRUtilsCalDbBase::Session()
       
   137     {
       
   138     return iCalSession;
       
   139     }
       
   140     
       
   141 // ----------------------------------------------------------------------------
       
   142 // CMRUtilsCalDbBase::DbStatus
       
   143 // ----------------------------------------------------------------------------
       
   144 //        
       
   145 MMRUtilsCalDbObserver::TDbStatus CMRUtilsCalDbBase::DbStatus()
       
   146     {
       
   147     return iDbStatus;
       
   148     }
       
   149 
       
   150 // ----------------------------------------------------------------------------
       
   151 // CMRUtilsCalDbBase::ResetDbL
       
   152 // ----------------------------------------------------------------------------
       
   153 //        
       
   154 void CMRUtilsCalDbBase::ResetDbL()
       
   155     {
       
   156     // By default database reseting is not supported
       
   157     User::Leave( KErrNotSupported );
       
   158     }
       
   159 
       
   160 // ----------------------------------------------------------------------------
       
   161 // CMRUtilsCalDbBase::FetchWithRangeL
       
   162 // According to UI spec. we only remove a repeating entry if all occurences
       
   163 // are within given timerange. This implementation however considers
       
   164 // originating and modifying entries separately (i.e. modifying entry may
       
   165 // be removed without originating entry being removed ). It is done like this
       
   166 // because 1) it's faster and 2) they are semantically different requests.
       
   167 // ----------------------------------------------------------------------------
       
   168 //
       
   169 void CMRUtilsCalDbBase::FetchWithRangeL(
       
   170     RPointerArray<CCalEntry>& aCalEntryArray,
       
   171     const CalCommon::TCalTimeRange& aCalTimeRange,
       
   172     TBool aFetchFullCopy )
       
   173     {
       
   174     __ASSERT_DEBUG( aCalEntryArray.Count() == 0,
       
   175                     Panic( EPanicNonEmptyParamArray ) );
       
   176     
       
   177     if ( !iCalInstanceView || !iCalEntryView )
       
   178         {
       
   179         User::Leave( KErrNotSupported );
       
   180         }
       
   181         
       
   182     RCPointerArray<CCalInstance> tmpFindArray;
       
   183     CleanupClosePushL( tmpFindArray );    
       
   184 
       
   185     iCalInstanceView->FindInstanceL( tmpFindArray, 
       
   186 					   			     CalCommon::EIncludeAppts, 
       
   187 					   			     aCalTimeRange );
       
   188 					   			     
       
   189     TInt count( tmpFindArray.Count() );
       
   190     for ( TInt i( 0 ); i < count; ++i )
       
   191         {        
       
   192         const CCalEntry& entry( tmpFindArray[i]->Entry() );
       
   193         
       
   194         // This is used to ensure that if entry has already been added we don't
       
   195         // bother to try again:
       
   196         TInt alreadyExistsIndex( aCalEntryArray.FindInOrder( &entry,
       
   197                 TLinearOrder<CCalEntry>( CMRUtilsCalDbBase::Compare ) ) );
       
   198         
       
   199         if ( alreadyExistsIndex < 0 &&
       
   200              IsCompletelyWithinRangeL( entry, aCalTimeRange ) )
       
   201             {
       
   202             // we create a full or a skeleton copy, based on given argument:
       
   203             MRHelpers::TCopyFields copyType( aFetchFullCopy ?
       
   204                 MRHelpers::ECopyFull : MRHelpers::ECopySkeleton );
       
   205             CCalEntry* copy = MRHelpers::CopyEntryLC( entry,
       
   206                                                       entry.MethodL(),
       
   207                                                       copyType );
       
   208             aCalEntryArray.InsertInOrderL( copy, 
       
   209                 TLinearOrder<CCalEntry>( CMRUtilsCalDbBase::Compare ) );
       
   210             CleanupStack::Pop( copy ); // ownership transferred to array
       
   211             }
       
   212         }
       
   213 
       
   214     CleanupStack::PopAndDestroy(); // tmpFindArray
       
   215     }
       
   216   
       
   217 // ----------------------------------------------------------------------------
       
   218 // CMRUtilsCalDbBase::IsCompletelyWithinRangeL
       
   219 // To optimize performance we return from the method immediatelly when EFalse
       
   220 // has been confirmed.
       
   221 // ----------------------------------------------------------------------------
       
   222 //          
       
   223 TBool CMRUtilsCalDbBase::IsCompletelyWithinRangeL(
       
   224     const CCalEntry& aEntry,
       
   225     const CalCommon::TCalTimeRange& aCalTimeRange )
       
   226     {
       
   227     // 1. Check occurrences specified with a recurrence rule:
       
   228 
       
   229     TCalRRule rule;
       
   230     if ( aEntry.GetRRuleL( rule ) )
       
   231         {
       
   232         // In this implementation we don't check if end time of the last
       
   233         // occurrence exceeds the time range, we only check the start/until of
       
   234         // the rule (according to the standard the start time of the rule equals
       
   235         // the start time of the first occurrence).
       
   236         // Furthermore ex-dates are not considered at all.
       
   237                 
       
   238         if ( rule.DtStart().TimeUtcL() < aCalTimeRange.StartTime().TimeUtcL() ||
       
   239              rule.Until().TimeUtcL() > aCalTimeRange.EndTime().TimeUtcL() )
       
   240             {
       
   241             return EFalse;
       
   242             }
       
   243         }
       
   244         
       
   245     // 2. Check occurrences specified with r-dates:
       
   246             
       
   247     RArray<TCalTime> rDateList;   
       
   248     aEntry.GetRDatesL( rDateList );
       
   249     TInt count( rDateList.Count() );
       
   250     for ( TInt i( 0 ); i < count; ++i )
       
   251         {
       
   252         // In this implementation we don't check if end time of r-date
       
   253         // occurence exceeds the time range.        
       
   254         
       
   255         if ( rDateList[i].TimeUtcL() < aCalTimeRange.StartTime().TimeUtcL() ||
       
   256              rDateList[i].TimeUtcL() > aCalTimeRange.EndTime().TimeUtcL() )
       
   257             {
       
   258             rDateList.Close();
       
   259             return EFalse;
       
   260             }
       
   261         }
       
   262     rDateList.Close();        
       
   263     return ETrue;        
       
   264     }
       
   265    
       
   266 // ----------------------------------------------------------------------------
       
   267 // CMRUtilsCalDbBase::Compare
       
   268 // ----------------------------------------------------------------------------
       
   269 //   
       
   270 TInt CMRUtilsCalDbBase::Compare(
       
   271     const CCalEntry& aFirst,
       
   272     const CCalEntry& aSecond )
       
   273     {
       
   274     TInt retVal( 0 ); // default value is that items are equal
       
   275     TRAP_IGNORE( retVal = CompareL( aFirst, aSecond ) );
       
   276     return retVal;
       
   277     }
       
   278     
       
   279 // ----------------------------------------------------------------------------
       
   280 // CMRUtilsCalDbBase::CompareL
       
   281 // ----------------------------------------------------------------------------
       
   282 //   
       
   283 TInt CMRUtilsCalDbBase::CompareL(
       
   284     const CCalEntry& aFirst,
       
   285     const CCalEntry& aSecond )
       
   286     {
       
   287     TInt result( aFirst.UidL().Compare( aSecond.UidL() ) );
       
   288     if ( result == 0 )
       
   289         { // UIDs were identical, how about recurrence id's then:
       
   290         TTime firstRec( aFirst.RecurrenceIdL().TimeUtcL() );
       
   291         TTime secondRec( aSecond.RecurrenceIdL().TimeUtcL() );
       
   292         if ( firstRec > secondRec )
       
   293             {
       
   294             result = 1;
       
   295             }
       
   296         else if ( firstRec < secondRec )
       
   297             {
       
   298             result = -1;
       
   299             }
       
   300         else
       
   301             {
       
   302             result = 0;
       
   303             }
       
   304         }
       
   305     return result;        
       
   306     }
       
   307     
       
   308 // ----------------------------------------------------------------------------
       
   309 // CMRUtilsCalDbBase::Progress
       
   310 // ----------------------------------------------------------------------------
       
   311 //    
       
   312 void CMRUtilsCalDbBase::Progress( TInt /*aPercentageCompleted*/ )
       
   313     {
       
   314     // No interest currently
       
   315     }
       
   316     
       
   317 // ----------------------------------------------------------------------------
       
   318 // CMRUtilsCalDbBase::NotifyProgress
       
   319 // ----------------------------------------------------------------------------
       
   320 //
       
   321 TBool CMRUtilsCalDbBase::NotifyProgress()
       
   322     { 
       
   323     // No interest currently
       
   324     return EFalse;
       
   325     }
       
   326 
       
   327 // End of file