calendarui/commonutils/src/calenagendautils.cpp
branchRCL_3
changeset 29 12af337248b1
parent 0 f979ecb2b13e
child 30 bd7edf625bdd
equal deleted inserted replaced
28:96907930389d 29:12af337248b1
     9 * Initial Contributors:
     9 * Initial Contributors:
    10 * Nokia Corporation - initial contribution.
    10 * Nokia Corporation - initial contribution.
    11 *
    11 *
    12 * Contributors:
    12 * Contributors:
    13 *
    13 *
    14 * Description:   Static utility functions. 
    14 * Description:  Static utility functions. 
    15  *                - date utils to help comparisions and calculations with
    15  *                - date utils to help comparisions and calculations with
    16  *                  dates and times. 
    16  *                  dates and times. 
    17  *
    17  *
    18 */
    18 */
    19 
    19 
    20 
    20 
       
    21 //INCLUDE FILES
       
    22 #include <QList>
       
    23 #include <QDateTime>
    21 
    24 
    22 #include <calinstance.h>
       
    23 #include <calinstanceview.h>
       
    24 #include <calrrule.h>
       
    25 #include <calenagendautils.h>
       
    26 #include <calendateutils.h>
       
    27 
       
    28 //debug
       
    29 #include "calendarui_debug.h"
    25 #include "calendarui_debug.h"
    30 #include "vstaticutils.h"
    26 #include "calenagendautils.h"
       
    27 #include "calendateutils.h"
    31 
    28 
    32 // ============================ MEMBER FUNCTIONS ==============================
    29 // ============================ MEMBER FUNCTIONS ==============================
    33 // ============================ CalenAgendaUtils ==============================
    30 // ============================ CalenAgendaUtils ==============================
    34 
    31 
    35 // -----------------------------------------------------------------------------
    32 // -----------------------------------------------------------------------------
    36 // CalenAgendaUtils::FindEventsForDayRangeL
    33 // CalenAgendaUtils::EndsAtStartOfDay
    37 // ?implementation_description
    34 // ?implementation_description
    38 // (other items were commented in a header).
    35 // (other items were commented in a header).
    39 // -----------------------------------------------------------------------------
    36 // -----------------------------------------------------------------------------
    40 //
    37 //
    41 EXPORT_C void CalenAgendaUtils::FindEventsForDayRangeL( CCalInstanceView* aInstanceView, 
    38  bool CalenAgendaUtils::endsAtStartOfDay( AgendaEntry& entry,
    42                                                         RPointerArray<CCalInstance>& aList, 
    39                                           const QDateTime& day )
    43                                                         const CalCommon::TCalViewFilter& aFilter, 
       
    44                                                         const TTime& aStartDay,
       
    45                                                         const TTime& aEndDay )
       
    46     {
    40     {
    47     TRACE_ENTRY_POINT;
    41     TRACE_ENTRY_POINT;
    48     
    42     
    49     TCalTime dummy;
    43     const QDateTime dayStart = CalenDateUtils::beginningOfDay( day );
    50     CalCommon::TCalTimeRange dayRange( dummy, dummy );
    44     const QDateTime startTime( entry.startTime() );
    51 
    45     const QDateTime endTime( entry.endTime() );
    52     CalenDateUtils::GetDayRangeL( aStartDay, aEndDay, dayRange );
       
    53 
       
    54     if(CalenDateUtils::IsValidDay(aStartDay))
       
    55     {
       
    56         aInstanceView->FindInstanceL( aList, aFilter, dayRange );    
       
    57     }
       
    58     
       
    59     TRACE_EXIT_POINT;
       
    60     }
       
    61 
       
    62 // -----------------------------------------------------------------------------
       
    63 // CalenAgendaUtils::FindTodosForDayRangeL
       
    64 // ?implementation_description
       
    65 // (other items were commented in a header).
       
    66 // -----------------------------------------------------------------------------
       
    67 //
       
    68 EXPORT_C void CalenAgendaUtils::FindTodosForDayRangeL( CCalInstanceView* aInstanceView, 
       
    69                                                        RPointerArray<CCalInstance>& aList, 
       
    70                                                        const TTime& aStartDay,
       
    71                                                        const TTime& aEndDay )
       
    72     {
       
    73     TRACE_ENTRY_POINT;
       
    74     
       
    75     const TCalTime dummy;
       
    76     CalCommon::TCalTimeRange dayRange( dummy, dummy );
       
    77     CalenDateUtils::GetDayRangeL( aStartDay, aEndDay, dayRange );
       
    78 
       
    79     TTime today;  today.HomeTime();
       
    80     const TTime tomorrow( today + TTimeIntervalDays(1) );
       
    81 
       
    82     const TTime rangeStart( dayRange.StartTime().TimeLocalL() );  // at 00:00.00
       
    83     const TTime rangeEnd( dayRange.EndTime().TimeLocalL() ); // at 23:59.59
       
    84 
       
    85     // fetch past uncompleted to-dos for today if today is included in the range
       
    86     if( rangeStart <= today && today <= rangeEnd )
       
    87         {
       
    88         // today includes today's to-dos + all past incompleted todos
       
    89         CalenDateUtils::GetDayRangeL( TCalTime::MinTime(), today, dayRange );
       
    90 
       
    91         if(CalenDateUtils::IsValidDay(aStartDay))
       
    92         {
       
    93         aInstanceView->FindInstanceL( aList, 
       
    94                                       CalCommon::EIncludeIncompletedTodos | 
       
    95                                       // only fetch the first instance for repeating to-dos!
       
    96                                       CalCommon::EIncludeRptsNextInstanceOnly, 
       
    97                                       dayRange );
       
    98         }
       
    99         // reset the time range for the remaining days
       
   100         CalenDateUtils::GetDayRangeL( tomorrow, aEndDay, dayRange );
       
   101         }
       
   102 
       
   103     // today already fetched, fetch the remaining range if any...
       
   104     // (including all the instances of repeating to-dos)
       
   105     if( rangeEnd > tomorrow )
       
   106         {
       
   107         aInstanceView->FindInstanceL( aList, 
       
   108                                       CalCommon::EIncludeIncompletedTodos, 
       
   109                                       dayRange );
       
   110         }
       
   111     
       
   112     TRACE_EXIT_POINT;
       
   113     }
       
   114 
       
   115 // -----------------------------------------------------------------------------
       
   116 // CalenAgendaUtils::RemoveEntriesStartingAtMidnight
       
   117 // ?implementation_description
       
   118 // (other items were commented in a header).
       
   119 // -----------------------------------------------------------------------------
       
   120 //
       
   121 EXPORT_C void CalenAgendaUtils::RemoveEntriesEndingAtMidnightL( RPointerArray<CCalInstance>& aList, 
       
   122                                                                 const TTime& aDay )
       
   123     {
       
   124     TRACE_ENTRY_POINT;
       
   125 
       
   126     // Remove events starting before aDay and ending at midnight
       
   127     TInt i( 0 );
       
   128 
       
   129     while( i < aList.Count() )
       
   130         {
       
   131         CCalInstance* item = aList[i];
       
   132 
       
   133         if( EndsAtStartOfDayL( item, aDay ) )
       
   134             {
       
   135             aList.Remove( i );
       
   136             delete item; // remember to delete before we lose the pointer
       
   137             }
       
   138         else
       
   139             {
       
   140             ++i;
       
   141             }
       
   142         }
       
   143     
       
   144     TRACE_EXIT_POINT;
       
   145     }
       
   146 
       
   147 // -----------------------------------------------------------------------------
       
   148 // CalenAgendaUtils::CreateEntryIdListForDayL
       
   149 // ?implementation_description
       
   150 // (other items were commented in a header).
       
   151 // -----------------------------------------------------------------------------
       
   152 //
       
   153 EXPORT_C void CalenAgendaUtils::CreateEntryIdListForDayL( RPointerArray<CCalInstance>& aList, 
       
   154                                                           CCalInstanceView* aInstanceView, 
       
   155                                                           const TTime& aDay, 
       
   156                                                           const TBool aSortForPopup, 
       
   157                                                           const TBool aIncludeToDos )
       
   158     {
       
   159     TRACE_ENTRY_POINT;
       
   160     
       
   161     const CalCommon::TCalViewFilter filter = CalCommon::EIncludeAppts    | 
       
   162                                              CalCommon::EIncludeReminder | 
       
   163                                              CalCommon::EIncludeEvents   | 
       
   164                                              CalCommon::EIncludeAnnivs;
       
   165 
       
   166     CalenAgendaUtils::FindEventsForDayRangeL( aInstanceView, aList, filter, aDay, aDay );
       
   167 
       
   168     CalenAgendaUtils::RemoveEntriesEndingAtMidnightL( aList, aDay );
       
   169 
       
   170     if( aIncludeToDos )
       
   171         {
       
   172         CalenAgendaUtils::FindTodosForDayRangeL( aInstanceView, aList, aDay, aDay );
       
   173         }
       
   174 
       
   175     if( aSortForPopup )
       
   176         {
       
   177         CalenAgendaUtils::SortPopupInstanceList( aList );
       
   178         }
       
   179     else
       
   180         {
       
   181         CalenAgendaUtils::SortInstanceList( aList );
       
   182         }
       
   183      
       
   184     TRACE_EXIT_POINT;
       
   185     }
       
   186 
       
   187 // -----------------------------------------------------------------------------
       
   188 // CalenAgendaUtils::EndsAtStartOfDayL
       
   189 // ?implementation_description
       
   190 // (other items were commented in a header).
       
   191 // -----------------------------------------------------------------------------
       
   192 //
       
   193 EXPORT_C TBool CalenAgendaUtils::EndsAtStartOfDayL( CCalInstance* aInstance,
       
   194                                                     const TTime& aDay )
       
   195     {
       
   196     TRACE_ENTRY_POINT;
       
   197     
       
   198     const TTime dayStart = CalenDateUtils::BeginningOfDay( aDay );
       
   199     const TTime startTime( aInstance->Time().TimeLocalL() );
       
   200     TTimeIntervalMinutes duration;
       
   201     aInstance->Entry().EndTimeL().TimeLocalL().MinutesFrom( aInstance->Entry().StartTimeL().TimeLocalL(), duration );
       
   202     const TTime endTime( startTime +duration );
       
   203 
    46 
   204     const TBool result( endTime > startTime && endTime == dayStart );
    47     const TBool result( endTime > startTime && endTime == dayStart );
   205 
    48 
   206     TRACE_EXIT_POINT;
    49     TRACE_EXIT_POINT;
   207     return result;
    50     return result;
   208     }
    51     }
   209 
    52 
   210 // -----------------------------------------------------------------------------
    53  // ---------------------------------------------------------------------------
   211 // CalenAgendaUtils::SortInstanceList
    54  // CalenAgendaUtils::IsAllDayEvent
   212 // ?implementation_description
    55  // Allday event is an event  with a duration of n*24h.
   213 // (other items were commented in a header).
    56  // ---------------------------------------------------------------------------
   214 // -----------------------------------------------------------------------------
    57  //
   215 //
    58  bool CalenAgendaUtils::isAlldayEvent( const AgendaEntry& entry )
   216 EXPORT_C void CalenAgendaUtils::SortInstanceList( RPointerArray<CCalInstance>& aInstanceList )
    59      {
   217     {
    60      
   218     TRACE_ENTRY_POINT;
    61      TRACE_ENTRY_POINT;
   219     
       
   220     TLinearOrder<CCalInstance> instanceListOrder( CalenAgendaUtils::EntryCompare );
       
   221     aInstanceList.Sort( instanceListOrder );
       
   222     
       
   223     TRACE_EXIT_POINT;
       
   224     }
       
   225 
    62 
   226 // -----------------------------------------------------------------------------
    63      bool allDayEvent( false );
   227 // CalenAgendaUtils::SortInstanceList
    64      if (AgendaEntry::TypeAppoinment == entry.type() ||
   228 // ?implementation_description
    65              AgendaEntry::TypeEvent == entry.type()) {    
   229 // (other items were commented in a header).
    66          QDateTime startTime = entry.startTime();
   230 // -----------------------------------------------------------------------------
    67          QDateTime stopTime  = entry.endTime();
   231 //
    68      
   232 EXPORT_C void CalenAgendaUtils::SortPopupInstanceList( RPointerArray<CCalInstance>& aInstanceList )
    69          int differenceInDays = startTime.daysTo(stopTime);
   233     {
    70          if( startTime != stopTime && 
   234     TRACE_ENTRY_POINT;
    71                  startTime == CalenDateUtils::beginningOfDay( startTime ) && 
   235     
    72                  stopTime == CalenDateUtils::beginningOfDay( stopTime ) && 
   236     TLinearOrder<CCalInstance> instanceListOrder( CalenAgendaUtils::PopupEntryCompare );
    73                  differenceInDays >= 1 )
   237     aInstanceList.Sort( instanceListOrder );
    74              {
   238     
    75              allDayEvent = true;
   239     TRACE_EXIT_POINT;
    76              }
   240     }
    77          else
   241 
    78              {
   242 TInt CalenAgendaUtils::EntryCompare(const CCalInstance& aInstance1, const CCalInstance& aInstance2)
    79              allDayEvent = false;
   243     {
    80              }
   244     TRACE_ENTRY_POINT;
    81      }
   245         
    82      
   246     TInt res = KErrArgument;
    83      TRACE_EXIT_POINT;
   247     TRAP_IGNORE( ( res = DoEntryCompareL( aInstance1, aInstance2 ) ) );
    84      return allDayEvent;
   248     
    85      }
   249     TRACE_EXIT_POINT;    
       
   250     return res;
       
   251     }
       
   252 // -----------------------------------------------------------------------------
       
   253 // CalenAgendaUtils::DoEntryCompareL
       
   254 // Common compare for all calendar entries. Order as follows:
       
   255 //  1. ETodo
       
   256 //  2. EEvent
       
   257 //  3. EAnniv
       
   258 //  4. EAppt, EReminder
       
   259 // -----------------------------------------------------------------------------
       
   260 //
       
   261 TInt CalenAgendaUtils::DoEntryCompareL( const CCalInstance& aInstance1,
       
   262                                         const CCalInstance& aInstance2 )
       
   263     {
       
   264     TRACE_ENTRY_POINT;
       
   265     
       
   266     TInt ret( EEqual );
       
   267 
       
   268     const CCalEntry& entry1 = aInstance1.Entry();
       
   269     const CCalEntry& entry2 = aInstance2.Entry();
       
   270     const CCalEntry::TType type1 = entry1.EntryTypeL();
       
   271     const CCalEntry::TType type2 = entry2.EntryTypeL();
       
   272 
       
   273     // types are equal (reminders are handled as meetings)
       
   274     if( type1 == type2 ||
       
   275       ((type1 == CCalEntry::EAppt && type2 == CCalEntry::EReminder)  || 
       
   276       (type2 == CCalEntry::EAppt && type1 == CCalEntry::EReminder)) )
       
   277         {
       
   278         switch( type1 )
       
   279             {
       
   280             case CCalEntry::ETodo:
       
   281                 ret = CalenAgendaUtils::CompareToDosL( entry1, entry2 );
       
   282                 break;
       
   283 
       
   284             case CCalEntry::EAnniv:
       
   285             case CCalEntry::EEvent:
       
   286                 ret = CalenAgendaUtils::CompareNonTimedNotesL( aInstance1, aInstance2 );
       
   287                 break;
       
   288 
       
   289             case CCalEntry::EReminder:
       
   290             case CCalEntry::EAppt:
       
   291                 ret = CalenAgendaUtils::CompareTimedNotesL( aInstance1, aInstance2 );
       
   292                 break;
       
   293 
       
   294             default:
       
   295                 ASSERT(EFalse);
       
   296             }
       
   297         }
       
   298         else // types are different
       
   299         {
       
   300 #ifdef RD_CALENDAR_PREVIEW
       
   301         switch( type1 )
       
   302             {
       
   303             case CCalEntry::ETodo:
       
   304                 // to-dos come always first...
       
   305                 ret = ELessThan;
       
   306                 break;
       
   307                 
       
   308             case CCalEntry::EAnniv:
       
   309                 // ...and then anniversaries...
       
   310                 if( type2 == CCalEntry::ETodo )
       
   311                     {
       
   312                     ret = EGreaterThan;            
       
   313                     }
       
   314                 else
       
   315                     {
       
   316                     ret = ELessThan;            
       
   317                     } 
       
   318                 break;
       
   319                 
       
   320             case CCalEntry::EEvent:
       
   321                 // ...then day notes...
       
   322                 if( (type2 == CCalEntry::ETodo) || (type2 == CCalEntry::EAnniv)) 
       
   323                     {
       
   324                     ret = EGreaterThan;            
       
   325                     }
       
   326                 else
       
   327                     {
       
   328                     ret = ELessThan;            
       
   329                     }
       
   330                 break;
       
   331                 
       
   332             case CCalEntry::EReminder:
       
   333             case CCalEntry::EAppt:
       
   334                 // ...and finally timed notes...
       
   335                 ret = EGreaterThan;
       
   336                 break;
       
   337             default:
       
   338                 ASSERT(EFalse);
       
   339             }                
       
   340 #else // !RD_CALENDAR_PREVIEW
       
   341         switch( type1 )
       
   342             {
       
   343             case CCalEntry::ETodo:
       
   344                 // to-dos come always first...
       
   345                 ret = ELessThan;
       
   346                 break;
       
   347 
       
   348             case CCalEntry::EEvent:
       
   349                 // ...then day notes...
       
   350                 if( type2 == CCalEntry::ETodo )
       
   351                     {
       
   352                     ret = EGreaterThan;
       
   353                     }
       
   354                 else
       
   355                     {
       
   356                     ret = ELessThan;
       
   357                     }                             
       
   358                 break;
       
   359 
       
   360             case CCalEntry::EAnniv:
       
   361                 // ...and anniversaries...
       
   362                 if( (type2 == CCalEntry::ETodo) || (type2 == CCalEntry::EEvent)) 
       
   363                     {
       
   364                     ret = EGreaterThan;                    
       
   365                     }
       
   366                 else
       
   367                     {
       
   368                     ret = ELessThan;                    
       
   369                     }
       
   370                 break;
       
   371 
       
   372             case CCalEntry::EReminder:
       
   373             case CCalEntry::EAppt:
       
   374                 // ...and finally timed notes.
       
   375                 ret = EGreaterThan;
       
   376                 break;
       
   377 
       
   378             default:
       
   379                 ASSERT(EFalse);
       
   380             }
       
   381 #endif // RD_CALENDAR_PREVIEW
       
   382         }
       
   383     
       
   384     TRACE_EXIT_POINT;
       
   385     return ret;
       
   386     }
       
   387 
       
   388 TInt CalenAgendaUtils::PopupEntryCompare( const CCalInstance& aInstance1,
       
   389                                           const CCalInstance& aInstance2 )
       
   390     {
       
   391     TRACE_ENTRY_POINT;
       
   392         
       
   393     TInt res = KErrArgument;
       
   394     TRAP_IGNORE( ( res = DoPopupEntryCompareL( aInstance1, aInstance2 ) ) );
       
   395     
       
   396     TRACE_EXIT_POINT;    
       
   397     return res;
       
   398     }
       
   399 
       
   400 // -----------------------------------------------------------------------------
       
   401 // CalenAgendaUtils::DoPopupEntryCompareL
       
   402 // Compare for calendar pop-up. Order as follows:
       
   403 //  1. ETodo
       
   404 //  2. EAnniv
       
   405 //  3. EEvent
       
   406 //  4. EAppt, EReminder
       
   407 // (other items were commented in a header).
       
   408 // -----------------------------------------------------------------------------
       
   409 //
       
   410 TInt CalenAgendaUtils::DoPopupEntryCompareL( const CCalInstance& aInstance1,
       
   411                                              const CCalInstance& aInstance2 )
       
   412     {
       
   413     TRACE_ENTRY_POINT;
       
   414     
       
   415     TInt ret( EEqual );
       
   416     const CCalEntry& entry1 = aInstance1.Entry();
       
   417     const CCalEntry& entry2 = aInstance2.Entry();
       
   418     const CCalEntry::TType type1 = entry1.EntryTypeL();
       
   419     const CCalEntry::TType type2 = entry2.EntryTypeL();
       
   420 
       
   421     // types are equal (reminders are handled as meetings)
       
   422     if( type1 == type2 ||
       
   423         ((type1 == CCalEntry::EAppt && type2 == CCalEntry::EReminder)  || 
       
   424         (type2 == CCalEntry::EAppt && type1 == CCalEntry::EReminder)) )
       
   425         {
       
   426         switch( type1 )
       
   427             {
       
   428             case CCalEntry::ETodo:
       
   429                 ret = CalenAgendaUtils::CompareToDosL( entry1, entry2 );
       
   430                 break;
       
   431 
       
   432             case CCalEntry::EAnniv:
       
   433             case CCalEntry::EEvent:
       
   434                 ret = CalenAgendaUtils::CompareNonTimedNotesL( aInstance1, aInstance2 );
       
   435                 break;
       
   436 
       
   437             case CCalEntry::EReminder:
       
   438             case CCalEntry::EAppt:
       
   439                 ret = CalenAgendaUtils::CompareTimedNotesL( aInstance1, aInstance2 );
       
   440                 break;
       
   441 
       
   442             default:
       
   443                 ASSERT(EFalse);
       
   444             }
       
   445         }
       
   446      else // types are different
       
   447      {
       
   448          switch( type1 )
       
   449             {
       
   450             case CCalEntry::ETodo:
       
   451             // to-dos come always first...
       
   452             ret = ELessThan;
       
   453                 break;
       
   454 
       
   455             case CCalEntry::EAnniv:
       
   456             // ...and then anniversaries...
       
   457             if( type2 == CCalEntry::ETodo )
       
   458                 {
       
   459                 ret = EGreaterThan;            
       
   460                 }
       
   461             else
       
   462                 {
       
   463                 ret = ELessThan;            
       
   464                 } 
       
   465                 break;
       
   466 
       
   467             case CCalEntry::EEvent:
       
   468             // ...then day notes...
       
   469             if( (type2 == CCalEntry::ETodo) || (type2 == CCalEntry::EAnniv)) 
       
   470                 {
       
   471                 ret = EGreaterThan;            
       
   472                 }
       
   473             else
       
   474                 {
       
   475                 ret = ELessThan;            
       
   476                 }
       
   477             break;
       
   478 
       
   479             case CCalEntry::EReminder:
       
   480             case CCalEntry::EAppt:
       
   481                 // ...and finally timed notes...
       
   482                 ret = EGreaterThan;
       
   483                 break;
       
   484 
       
   485             default:
       
   486                 ASSERT(EFalse);
       
   487             }
       
   488         }
       
   489     
       
   490     TRACE_EXIT_POINT;
       
   491     return ret;
       
   492     }
       
   493 
       
   494 // -----------------------------------------------------------------------------
       
   495 // CalenAgendaUtils::CompareToDos
       
   496 // Compares two to-do entries. Sort criteria:
       
   497 //  1. Status: ETodoNeedsAction before ETodoCompleted
       
   498 //  2. Due date: oldest first (1.1.2005 before 2.1.2005 )
       
   499 //  3. Priority: highest first (1 before 2 )
       
   500 //  4. Last modified: oldest first (1.1.2005 09:00 before 1.1.2005 10:00 )
       
   501 // (other items were commented in a header).
       
   502 // -----------------------------------------------------------------------------
       
   503 //
       
   504 TInt CalenAgendaUtils::CompareToDosL( const CCalEntry& aEntry1,
       
   505                                       const CCalEntry& aEntry2 )
       
   506     {
       
   507     TRACE_ENTRY_POINT;
       
   508 
       
   509     TInt ret( EEqual );
       
   510     CCalEntry::TStatus status1 = aEntry1.StatusL();
       
   511     CCalEntry::TStatus status2 = aEntry2.StatusL();
       
   512 
       
   513     if( status1 == CCalEntry::ENullStatus )
       
   514         {
       
   515         status1 = CCalEntry::ETodoNeedsAction;
       
   516         }
       
   517     
       
   518     if( status2 == CCalEntry::ENullStatus )
       
   519         {
       
   520         status2 = CCalEntry::ETodoNeedsAction;
       
   521         }
       
   522 
       
   523     if( status1 == status2 )
       
   524         {
       
   525         TTime time1 = aEntry1.EndTimeL().TimeUtcL();
       
   526         TTime time2 = aEntry2.EndTimeL().TimeUtcL();
       
   527 
       
   528         if( time1 == time2 )
       
   529             {
       
   530             const TUint pri1( aEntry1.PriorityL() );
       
   531             const TUint pri2( aEntry2.PriorityL() );
       
   532 
       
   533             if( pri1 == pri2 )
       
   534                 {
       
   535                 time1 = aEntry1.LastModifiedDateL().TimeUtcL();
       
   536                 time2 = aEntry2.LastModifiedDateL().TimeUtcL();
       
   537 
       
   538                 if( time1 == time2 )
       
   539                     {
       
   540                     ret = EEqual;
       
   541                     }
       
   542                 else if( time1 > time2 )
       
   543                     {
       
   544                     ret = EGreaterThan; // oldest first
       
   545                     }
       
   546                 else
       
   547                     {
       
   548                     ret = ELessThan;
       
   549                     }
       
   550                 }
       
   551             else
       
   552                 {
       
   553                 if( pri1 > pri2 )
       
   554                     {
       
   555                     ret = EGreaterThan;
       
   556                     }
       
   557                 else
       
   558                     {
       
   559                     ret = ELessThan;
       
   560                     }
       
   561                 }
       
   562             }
       
   563         else
       
   564             {
       
   565             if( time1 > time2 )
       
   566                 {
       
   567                 ret = EGreaterThan;
       
   568                 }
       
   569             else
       
   570                 {
       
   571                 ret = ELessThan;
       
   572                 }
       
   573             }
       
   574         }
       
   575     else
       
   576         {
       
   577         if( status1 == CCalEntry::ETodoCompleted )
       
   578             {
       
   579             ret = EGreaterThan;
       
   580             }
       
   581         else
       
   582             {
       
   583             ret = ELessThan;
       
   584             }
       
   585         }
       
   586     
       
   587     TRACE_EXIT_POINT;
       
   588     return ret;
       
   589     }
       
   590 
       
   591 // -----------------------------------------------------------------------------
       
   592 // CalenAgendaUtils::CompareNonTimedNotes
       
   593 // Compares two non-timed notes. Sort criteria:
       
   594 //  1. start time: oldest first
       
   595 //  2. last modified:  oldest first
       
   596 // (other items were commented in a header).
       
   597 // -----------------------------------------------------------------------------
       
   598 //
       
   599 TInt CalenAgendaUtils::CompareNonTimedNotesL( const CCalInstance& aInstance1,
       
   600                                               const CCalInstance& aInstance2 )
       
   601     {
       
   602     TRACE_ENTRY_POINT;
       
   603     
       
   604     TInt ret( EEqual );
       
   605     TTime time1 = aInstance1.Time().TimeUtcL();
       
   606     TTime time2 = aInstance2.Time().TimeUtcL();
       
   607 
       
   608     if( time1 == time2 )
       
   609         {
       
   610         time1 = aInstance1.Entry().LastModifiedDateL().TimeUtcL();
       
   611         time2 = aInstance2.Entry().LastModifiedDateL().TimeUtcL();
       
   612 
       
   613         if( time1 == time2 )
       
   614             {
       
   615             ret = EEqual;
       
   616             }
       
   617         else if( time1 > time2 )
       
   618             {
       
   619             ret = EGreaterThan; // oldest first
       
   620             }
       
   621         else
       
   622             {
       
   623             ret = ELessThan;
       
   624             }
       
   625         }
       
   626     else
       
   627         {
       
   628         if( time1 < time2 )
       
   629             {
       
   630             ret = ELessThan;
       
   631             }
       
   632         else
       
   633             {
       
   634             ret = EGreaterThan;
       
   635             }
       
   636         }
       
   637     
       
   638     TRACE_EXIT_POINT;
       
   639     return ret;
       
   640     }
       
   641 
       
   642 // -----------------------------------------------------------------------------
       
   643 // CalenAgendaUtils::CompareTimedNotes
       
   644 // Compares two non-timed notes. Sort criteria:
       
   645 //  1. start time: oldest first
       
   646 //  2. duration: shortest first
       
   647 //  3. last modified: oldest first
       
   648 // (other items were commented in a header).
       
   649 // -----------------------------------------------------------------------------
       
   650 //
       
   651 TInt CalenAgendaUtils::CompareTimedNotesL( const CCalInstance& aInstance1,
       
   652                                            const CCalInstance& aInstance2 )
       
   653     {
       
   654     TRACE_ENTRY_POINT;
       
   655     
       
   656     TInt ret( EEqual );
       
   657     TTime time1 = aInstance1.Time().TimeUtcL();
       
   658     TTime time2 = aInstance2.Time().TimeUtcL();
       
   659 
       
   660     if( time1 == time2 )
       
   661         {
       
   662         TTimeIntervalMinutes duration1;
       
   663         TTimeIntervalMinutes duration2;
       
   664         aInstance1.EndTimeL().TimeUtcL().MinutesFrom( aInstance1.StartTimeL().TimeUtcL(), duration1 );
       
   665         aInstance2.EndTimeL().TimeUtcL().MinutesFrom( aInstance2.StartTimeL().TimeUtcL(), duration2 );
       
   666 
       
   667         if( duration1 == duration2 )
       
   668             {
       
   669             time1 = aInstance1.Entry().LastModifiedDateL().TimeUtcL();
       
   670             time2 = aInstance2.Entry().LastModifiedDateL().TimeUtcL();
       
   671 
       
   672             if( time1 == time2 )
       
   673                 {
       
   674                 ret = EEqual;
       
   675                 }
       
   676             else if( time1 > time2 )
       
   677                 {
       
   678                 ret = EGreaterThan; // oldest first
       
   679                 }
       
   680             else
       
   681                 {
       
   682                 ret = ELessThan;
       
   683                 }
       
   684             }
       
   685         else
       
   686             {
       
   687             if( duration1 < duration2 )
       
   688                 {
       
   689                 ret = ELessThan;
       
   690                 }
       
   691             else
       
   692                 {
       
   693                 ret = EGreaterThan;
       
   694                 }
       
   695             }
       
   696         }
       
   697     else
       
   698         {
       
   699         if( time1 < time2 )
       
   700             {
       
   701             ret = ELessThan;
       
   702             }
       
   703         else
       
   704             {
       
   705             ret = EGreaterThan;
       
   706             }
       
   707         }
       
   708     
       
   709     TRACE_EXIT_POINT;
       
   710     return ret;
       
   711     }
       
   712 
       
   713 EXPORT_C TTimeIntervalMinutes CalenAgendaUtils::DurationL( const CCalEntry& aEntry )
       
   714     {
       
   715     TRACE_ENTRY_POINT;
       
   716     
       
   717     TTimeIntervalMinutes duration;
       
   718 
       
   719     const TTime start = aEntry.StartTimeL().TimeUtcL();
       
   720     const TTime end = aEntry.EndTimeL().TimeUtcL(); 
       
   721     end.MinutesFrom( start, duration );
       
   722     
       
   723     TRACE_EXIT_POINT;
       
   724     return duration;
       
   725     }
       
   726 
       
   727 
       
   728 EXPORT_C TTime CalenAgendaUtils::EntryTimeL( const CCalEntry& aEntry )
       
   729     {
       
   730     TRACE_ENTRY_POINT;
       
   731 
       
   732     // FIXME: instance time!
       
   733     TTime entryTime; 
       
   734     
       
   735     if( aEntry.EntryTypeL() == CCalEntry::ETodo )
       
   736         {
       
   737         entryTime = aEntry.EndTimeL().TimeLocalL();
       
   738         }
       
   739     else
       
   740         {
       
   741         entryTime = aEntry.StartTimeL().TimeLocalL();
       
   742         }
       
   743     
       
   744     if ( entryTime == Time::NullTTime() )
       
   745         {
       
   746         TTime today; 
       
   747         today.HomeTime();                
       
   748         entryTime = today;
       
   749         }
       
   750     
       
   751     //FIXME: should we add one more step
       
   752     // entryTime = CalenDateUtils::LimitToValidRange( entryTime );
       
   753     TRACE_EXIT_POINT;
       
   754     return entryTime;
       
   755     }
       
   756 
       
   757 EXPORT_C TBool CalenAgendaUtils::IsTimedEntryL( CCalEntry::TType aType ) 
       
   758     {
       
   759     TRACE_ENTRY_POINT;
       
   760 
       
   761     TRACE_EXIT_POINT;
       
   762     return aType == CCalEntry::EAppt || aType == CCalEntry::EReminder;
       
   763     }
       
   764 
       
   765 // ---------------------------------------------------------
       
   766 // CCalenDayOnlyEventContainer::IsRepeatingL
       
   767 // (other items were commented in a header).
       
   768 // ---------------------------------------------------------
       
   769 //
       
   770 EXPORT_C TBool CalenAgendaUtils::IsRepeatingL( const CCalEntry& aEntry )
       
   771     {    
       
   772     TRACE_ENTRY_POINT;
       
   773     
       
   774     TBool isRepeating = EFalse;
       
   775     RArray<TCalTime> rdates;
       
   776     CleanupClosePushL( rdates );
       
   777     aEntry.GetRDatesL( rdates );
       
   778     TBool isRDate = rdates.Count() > 0;
       
   779     CleanupStack::PopAndDestroy(); // rdates
       
   780 
       
   781     TCalRRule newRule;
       
   782 
       
   783     if ( ( isRDate ) || ( aEntry.GetRRuleL(newRule) && newRule.Type() != TCalRRule::EInvalid ) )
       
   784         {
       
   785         isRepeating = ETrue;
       
   786         }
       
   787     
       
   788     TRACE_EXIT_POINT;
       
   789     return isRepeating;
       
   790     }
       
   791 
       
   792 EXPORT_C TBool CalenAgendaUtils::IsEmptyText(const TDesC& aDes)
       
   793     {
       
   794     TRACE_ENTRY_POINT;
       
   795     
       
   796     TBool empty = ETrue;
       
   797     TInt length = aDes.Length();
       
   798     for(TUint i = 0; i < length; ++i)
       
   799         {
       
   800         if( !VersitUtils::IsWhiteSpace(aDes.operator[](i)) )
       
   801             {
       
   802             empty = EFalse;
       
   803             break;
       
   804             }
       
   805         }
       
   806         
       
   807     TRACE_EXIT_POINT;
       
   808     return empty;
       
   809     }
       
   810 
    86 
   811 //  End of File
    87 //  End of File