calendarengines/caleninterimutils/inc/CalenInterimUtils2Impl.h
changeset 0 f979ecb2b13e
child 48 bf573002ff72
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:     This class implements functions from CCalenInterimUtils2
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #ifndef __CALENINTERIMUTILS2IMPL_H__
       
    20 #define __CALENINTERIMUTILS2IMPL_H__
       
    21 
       
    22 //  INCLUDES
       
    23 #include <e32base.h>
       
    24 #include <calcommon.h>
       
    25 #include "calenecomchangeobserver.h"    // MCalenEComChangeObserver
       
    26 
       
    27 // FORWARD DECLARATIONS
       
    28 class CCalEntry;
       
    29 class CCalAttendee;
       
    30 class CCalUser;
       
    31 class CCalEntryView;
       
    32 class CCalInstanceView;
       
    33 class TCalTime;
       
    34 class TCalRRule;
       
    35 class CCalInstance;
       
    36 class CCalenEComWatcher;    // Watches for installed MR solutions
       
    37 
       
    38 // CLASS DECLARATION
       
    39 
       
    40 /**
       
    41 * This class contains utility methods related to usage of
       
    42 * Calendar Interim API
       
    43 */
       
    44 NONSHARABLE_CLASS(CCalenInterimUtils2Impl) : public CBase,
       
    45                                     public MCalenEComChangeObserver
       
    46     {
       
    47     public: // Construction/destruction
       
    48         /**
       
    49         * Create a new instance of CCalenInterimUtils2
       
    50         */
       
    51         static CCalenInterimUtils2Impl* NewL();
       
    52 
       
    53         /**
       
    54         * Destructor
       
    55         */
       
    56         ~CCalenInterimUtils2Impl();
       
    57 
       
    58     public: // New functions
       
    59         /**
       
    60         * Allocates and returns a new global UID.
       
    61         * @return UID, ownership is transferred to caller
       
    62         */
       
    63         HBufC8* GlobalUidL();
       
    64         
       
    65         /**
       
    66         * Populates empty fields of a child entry with data from
       
    67         * the parent entry.
       
    68         * @param aChild child (modifying) entry to be populated
       
    69         * @param aParent parent (originating) entry
       
    70         */
       
    71         static void PopulateChildFromParentL( CCalEntry& aChild, const CCalEntry& aParent );
       
    72 
       
    73         /**
       
    74         * Checks to see if Meeting Request Viewer functionality
       
    75         * is enabled and is available to use
       
    76         * @return current state of MR Viewers implementation
       
    77         */
       
    78         TBool MRViewersEnabledL(TBool aForceCheck);
       
    79 
       
    80         /**
       
    81         * This function is a wrapper around CCalEntryView::StoreL() and CCalEntryView::UpdateL().
       
    82         * The function makes the appropriate call to either of those functions, depending on several
       
    83         * factors, such as whether the entry is a child or parent, and whether it has exceptions or not.
       
    84         * If aCopyToChildren is set to ETrue, extra logic is applied as follows:
       
    85         * For each exception, for each field, if the field is NOT the reason for the
       
    86         * entry being an exception, copy the new parent's field across to the exception.
       
    87         * @param aEntryView view of the entries
       
    88         * @param aEntry entry to be stored
       
    89         * @param aCopyToChildren whether the extra logic regarding exception data should be run
       
    90         */
       
    91         static void StoreL( CCalEntryView& aEntryView,
       
    92                                      CCalEntry& aEntry,
       
    93                                      TBool aCopyToChildren = EFalse );
       
    94 
       
    95         /**
       
    96         * Checks to see if the given entry has properties consistent with a meeting request.
       
    97         * @param aEntry Entry to test
       
    98         * @return ETrue if the entry is a meeting request, EFalse otherwise
       
    99         */
       
   100         static TBool IsMeetingRequestL( CCalEntry& aEntry );
       
   101 
       
   102         /**
       
   103          * From MCalenEComChangeObserver
       
   104          * Called by when the ecom registry gets changed.
       
   105          */
       
   106         void EComChanged();
       
   107 
       
   108     private: // enumerations
       
   109 
       
   110         enum TDifferenceFlag
       
   111             {
       
   112             EEntryDifferentStartTimeAndEndTime  = 0x001,
       
   113             EEntryDifferentSummary              = 0x002,
       
   114             EEntryDifferentDescription          = 0x004,
       
   115             EEntryDifferentLocation             = 0x08,
       
   116             EEntryDifferenceCount               = 0x010 // Must be last!
       
   117             };
       
   118 
       
   119     private: // New functions
       
   120 
       
   121         void ConstructL();
       
   122 
       
   123         static TInt FindInstanceL( CCalInstanceView& aInstanceView,
       
   124                                    CCalEntry& aEntry,
       
   125                                    const TCalTime& aInstanceDate, 
       
   126                                    RPointerArray<CCalInstance>& aInstances );
       
   127         /**
       
   128         * Helper method which populates child's attendee list if is empty.
       
   129         */
       
   130         static void PopulateAttendeeListL( CCalEntry& aChild,
       
   131                                            const CCalEntry& aParent );
       
   132 
       
   133         /*
       
   134         * Helper which creates a new copy of the given attendee. Item is
       
   135         * left in the cleanup stack.
       
   136         *
       
   137         * @param aSource attendee to copy
       
   138         * @return attendee, ownership is transferred to caller.
       
   139         */
       
   140         static CCalAttendee* CopyAttendeeLC( const CCalAttendee& aSource );
       
   141 
       
   142         /*
       
   143         * Helper which creates a new copy of the given cal user. Item is
       
   144         * left in the cleanup stack.
       
   145         *
       
   146         * @param aSource user to copy
       
   147         * @return user, ownership is transferred to caller.
       
   148         */
       
   149         static CCalUser* CopyUserLC( const CCalUser& aSource );
       
   150 
       
   151         /**
       
   152         * Helper which reads handset's imei. Caller must pass long enough
       
   153         * descriptor (RMobilePhone::KPhoneSerialNumberSize).
       
   154         * @param aImei handset's imei
       
   155         */
       
   156         static void GetImeiL( TDes& aImei );
       
   157 
       
   158         /**
       
   159         * Helper which sets the last modified date of a given entry
       
   160         * and, if aEntry is a meeting request, sets the phone owner of
       
   161         * the entry, if not previously set.
       
   162         * @param aEntry entry to update
       
   163         */
       
   164         static void PrepareForStorageL( CCalEntry& aEntry );
       
   165 
       
   166         /**
       
   167         * Helper which puts the given entry into an entry array and
       
   168         * calls StoreL on it.
       
   169         * @param aEntryView entry view upon which StoreL is performed
       
   170         * @param aEntry entry to store
       
   171         */
       
   172         static void SingleStoreL( CCalEntryView& aEntryView,
       
   173                                   CCalEntry& aEntry );
       
   174 
       
   175         /**
       
   176         * Helper which puts the given entry into an entry array and
       
   177         * calls UpdateL on it.
       
   178         * @param aEntryView entry view upon which UpdateL is performed
       
   179         * @param aEntry entry to store
       
   180         */
       
   181         static void SingleUpdateL( CCalEntryView& aEntryView,
       
   182                                    CCalEntry& aEntry );
       
   183 
       
   184         /**
       
   185         * Check to see if the two given entries' fields are the same.
       
   186         * @param aEntryOne first entry
       
   187         * @param aEntryTwo second entry
       
   188         * @param aFlag Difference flag containing ONE field to copy
       
   189         */
       
   190         static TBool FieldIsTheSameL( CCalEntry& aEntryOne,
       
   191                                       CCalEntry& aEntryTwo,
       
   192                                       TDifferenceFlag aFlag );
       
   193 
       
   194         /**
       
   195         * Copys a single field from one entry to another.
       
   196         * @param aSrc source entry
       
   197         * @param aDst destination entry
       
   198         * @param aField Difference flag containing ONE field to copy
       
   199         */
       
   200         static void CopyFieldL( const CCalEntry& aSrc,
       
   201                                 CCalEntry& aDst,
       
   202                                 TDifferenceFlag aField );
       
   203 
       
   204         /**
       
   205         * Compares the start and end datetimes of two entries
       
   206         * @param aNewEntry The entry to be updated
       
   207         * @param aOldEntry The original entry
       
   208         */
       
   209         static TBool HasTimeOrDateChangedL(const CCalEntry& aNewEntry, const CCalEntry& aOldEntry);
       
   210 
       
   211 
       
   212         /**
       
   213         * Checks to see if any information can be saved from old entries.
       
   214         * Logic of: For every field, if the exception's field is the same field as the old parent
       
   215         * entry's field, and the new parent entry field is different from the old parent entry field,
       
   216         * copy the new parent's field to the exception's field.
       
   217         * @param aEditedEntry entry currently being edited
       
   218         * @param aOldEntries previous array of exception entries, with the parent entry being at position 0.
       
   219         * This can be retrieved using CCalEntryView::FetchL().
       
   220         */
       
   221         static void CopyChildrenExceptionDataL( CCalEntry& aEditedEntry,
       
   222                                                 RPointerArray<CCalEntry>& aOldEntries );
       
   223 
       
   224         /**
       
   225         * Stores each child entry in aEntries in a separate call to CCalEntryView::StoreL().
       
   226         * This function traps and ignores any failures.
       
   227         * @param aEntryView view of the entries
       
   228         * @param aEntry current entry being updated. Used for UID and RecurrenceId.
       
   229         * @param aEntries array of CCalEntries to be stored
       
   230         * @param aResetLocalUid resets local uid of restored child entries
       
   231         */
       
   232         static void StoreEachChildEntryL( CCalEntryView &aEntryView,
       
   233                                           CCalEntry &aEntry,
       
   234                                           RPointerArray<CCalEntry> &aEntries,
       
   235                                           TBool aResetLocalUid);
       
   236 
       
   237         /**
       
   238         * Compares the repeat properties (RDates and RRules) of two entries
       
   239         * @param aNewEntry The entry to be updated
       
   240         * @param aOldEntry The original entry
       
   241         */
       
   242         static TBool HaveRepeatPropertiesChangedL(const CCalEntry& aNewEntry, const CCalEntry& aOldEntry);
       
   243 
       
   244         /**
       
   245         * Return ETrue if the entry is a repeating entry
       
   246         */
       
   247         static TBool IsEntryRepeatingL(const CCalEntry& aEntry);
       
   248         
       
   249         // Just a wrapper for leaves
       
   250         void DoMRViewersEnabledL();
       
   251 	
       
   252 private: 
       
   253     //Default Constructor
       
   254     CCalenInterimUtils2Impl();
       
   255     
       
   256     // Helper functions for GUID generation.
       
   257     static TInt64 GetTicksFromGregorianCalendarStartL();
       
   258     static TInt64 GetImeiAsNodeValueL();
       
   259     static HBufC8* DoCreateUidLC(const TUint32& aClockSeq, const TUint64& aTimeStamp, const TUint64& aNodeValue);
       
   260     static TChar ConvertToCharacterL(TUint8 aChar);
       
   261 
       
   262 private: // Time and date utility functions, copied from commonui to remove dependency
       
   263     static TTimeIntervalMinutes TimeOfDay( const TTime& aDateTime );
       
   264     static TTime BeginningOfDay(const TTime& aStartTime);
       
   265 
       
   266 private: // Member data
       
   267     CCalenEComWatcher* iEcomWatcher;
       
   268     TInt64 iImeiNode;
       
   269     TBool iMrEnabled;
       
   270     TBool iMrEnabledCheck;
       
   271     };
       
   272 
       
   273 #endif // __CALENINTERIMUTILS2IMPL_H__
       
   274 
       
   275 // End of File