calendarui/views/src/calenpreviewdata.cpp
changeset 0 f979ecb2b13e
equal deleted inserted replaced
-1:000000000000 0:f979ecb2b13e
       
     1 /*
       
     2 * Copyright (c) 2002 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:  The model part of popup
       
    15 */
       
    16 
       
    17 #include <calinstance.h>
       
    18 #include <calenagendautils.h>
       
    19 #include <caleninstanceid.h>            // TCalenInstanceId
       
    20 #include <calenviewutils.h>
       
    21 #include <calenservices.h>
       
    22 #include <centralrepository.h>
       
    23 #include <calcalendarinfo.h>
       
    24 
       
    25 #include "calendarui_debug.h"
       
    26 #include "calenpreviewdata.h"
       
    27 #include "calenpreviewlayoutmanager.h"
       
    28 #include "calenpreviewentry.h"
       
    29 #include "calenglobaldata.h"
       
    30 #include "calendateutils.h"
       
    31 #include "CalendarPrivateCRKeys.h"
       
    32 #include "calenglobaldata.h"
       
    33 #include "calennativeview.h"
       
    34 
       
    35 // ---------------------------------------------------------------------------
       
    36 // ?classname::?member_function
       
    37 // ?implementation_description
       
    38 // (other items were commented in a header).
       
    39 // ---------------------------------------------------------------------------
       
    40 //
       
    41 CCalenPreviewData::CCalenPreviewData(
       
    42     CCalenPreviewLayoutManager *aLayoutManager,
       
    43     MCalenServices& aServices,
       
    44     TInt aMaxInstances)
       
    45     : iLayoutManager(aLayoutManager), 
       
    46       iNotShownEntries(EFalse),
       
    47       iMaxInstances(aMaxInstances),
       
    48       iServices( aServices )
       
    49     {
       
    50     TRACE_ENTRY_POINT;
       
    51     TRACE_EXIT_POINT;
       
    52     }
       
    53 
       
    54 // ---------------------------------------------------------------------------
       
    55 // ?classname::?member_function
       
    56 // ?implementation_description
       
    57 // (other items were commented in a header).
       
    58 // ---------------------------------------------------------------------------
       
    59 //
       
    60 void CCalenPreviewData::ConstructL(const TTime& aDay)
       
    61     {
       
    62     TRACE_ENTRY_POINT;
       
    63     FindInstancesL(aDay);
       
    64     TRACE_EXIT_POINT;
       
    65     }
       
    66 
       
    67 // ---------------------------------------------------------------------------
       
    68 // ?classname::?member_function
       
    69 // ?implementation_description
       
    70 // (other items were commented in a header).
       
    71 // ---------------------------------------------------------------------------
       
    72 //
       
    73 CCalenPreviewData* CCalenPreviewData::NewL(
       
    74     CCalenPreviewLayoutManager *aLayoutManager,
       
    75     MCalenServices& aServices,
       
    76     TInt aMaxInstances,
       
    77     TTime aFocusedTime)
       
    78     {
       
    79     TRACE_ENTRY_POINT;
       
    80 
       
    81     CCalenPreviewData* self = new( ELeave ) CCalenPreviewData(aLayoutManager,
       
    82                                                               aServices,
       
    83                                                               aMaxInstances);
       
    84     CleanupStack::PushL( self );
       
    85     self->ConstructL(aFocusedTime);
       
    86     CleanupStack::Pop( self );
       
    87     
       
    88     TRACE_EXIT_POINT;
       
    89     return self;
       
    90     }
       
    91 // ---------------------------------------------------------------------------
       
    92 // ?classname::?member_function
       
    93 // ?implementation_description
       
    94 // (other items were commented in a header).
       
    95 // ---------------------------------------------------------------------------
       
    96 //
       
    97 CCalenPreviewData* CCalenPreviewData::NewL(
       
    98     CCalenPreviewLayoutManager *aLayoutManager,
       
    99     MCalenServices& aServices,
       
   100     TInt aMaxInstances,
       
   101     CCalInstance* aInst)
       
   102     {
       
   103     TRACE_ENTRY_POINT;
       
   104 
       
   105     CCalenPreviewData* self = new( ELeave ) CCalenPreviewData(aLayoutManager,
       
   106                                                               aServices, 
       
   107                                                               aMaxInstances);
       
   108     CleanupStack::PushL( self );
       
   109     self->iSingleInstance = ETrue;
       
   110     self->iInstances.Append(aInst);
       
   111     CleanupStack::Pop( self );
       
   112     
       
   113     TRACE_EXIT_POINT;
       
   114     return self;
       
   115     }
       
   116 
       
   117 // ---------------------------------------------------------------------------
       
   118 // ?classname::?member_function
       
   119 // ?implementation_description
       
   120 // (other items were commented in a header).
       
   121 // ---------------------------------------------------------------------------
       
   122 //
       
   123 CCalenPreviewData::~CCalenPreviewData()
       
   124     {
       
   125     TRACE_ENTRY_POINT;
       
   126     if(iLayoutManager)
       
   127         iLayoutManager->SetLinesUsed(0);
       
   128     /* Single instance is not owned by CalenPreviewData 
       
   129        so it is not deleted here*/
       
   130     iTodoPriorityOrder.Close();
       
   131     if(!iSingleInstance)
       
   132         iInstances.ResetAndDestroy();
       
   133     iInstances.Close();
       
   134     iEntries.ResetAndDestroy();
       
   135     iEntries.Close();
       
   136     TRACE_EXIT_POINT;
       
   137     }
       
   138 
       
   139 // ---------------------------------------------------------------------------
       
   140 // ?classname::?member_function
       
   141 // ?implementation_description
       
   142 // (other items were commented in a header).
       
   143 // ---------------------------------------------------------------------------
       
   144 //
       
   145 TInt CCalenPreviewData::InstanceCount() const
       
   146     {
       
   147     TRACE_ENTRY_POINT;
       
   148     TRACE_EXIT_POINT;
       
   149     return iInstances.Count();
       
   150     }
       
   151 
       
   152 TInt CCalenPreviewData::EntryCount() const
       
   153     {
       
   154     TRACE_ENTRY_POINT;
       
   155     TRACE_EXIT_POINT;
       
   156     return iEntries.Count();
       
   157     }
       
   158 
       
   159 // ---------------------------------------------------------------------------
       
   160 // ?classname::?member_function
       
   161 // ?implementation_description
       
   162 // (other items were commented in a header).
       
   163 // ---------------------------------------------------------------------------
       
   164 //
       
   165 TBool CCalenPreviewData::NotShownEntries() const
       
   166     {
       
   167     TRACE_ENTRY_POINT;
       
   168     TRACE_EXIT_POINT;
       
   169     return iNotShownEntries;
       
   170     }
       
   171 
       
   172 // ---------------------------------------------------------------------------
       
   173 // ?classname::?member_function
       
   174 // ?implementation_description
       
   175 // (other items were commented in a header).
       
   176 // ---------------------------------------------------------------------------
       
   177 //
       
   178 void CCalenPreviewData::SetToday(TBool aToday) 
       
   179     {
       
   180     TRACE_ENTRY_POINT;
       
   181     iToday = aToday;
       
   182     TRACE_EXIT_POINT;
       
   183     }
       
   184 // ---------------------------------------------------------------------------
       
   185 // ?classname::?member_function
       
   186 // ?implementation_description
       
   187 // (other items were commented in a header).
       
   188 // ---------------------------------------------------------------------------
       
   189 //
       
   190 TBool CCalenPreviewData::Today() 
       
   191     {
       
   192     TRACE_ENTRY_POINT;
       
   193     TRACE_EXIT_POINT;
       
   194     return iToday;
       
   195     }
       
   196 
       
   197 // ---------------------------------------------------------------------------
       
   198 // CCalenPreviewData::RemoveInstancesL
       
   199 // ?implementation_description
       
   200 // (other items were commented in a header).
       
   201 // ---------------------------------------------------------------------------
       
   202 //
       
   203 void CCalenPreviewData::RemoveInstancesL(const CCalEntry::TType aType)
       
   204     {
       
   205     TRACE_ENTRY_POINT;
       
   206     
       
   207     TInt i( iInstances.Count() - 1 );
       
   208 
       
   209     if(aType == CCalEntry::ETodo)
       
   210         {
       
   211         for(TInt i(0); i < iTodoPriorityOrder.Count() && iInstances.Count() > iMaxInstances; i++)
       
   212             {
       
   213             for(TInt j(0); j < iInstances.Count() && iInstances.Count() > iMaxInstances; j++)
       
   214                 {
       
   215                 if( iTodoPriorityOrder[i] == iInstances[j] )
       
   216                     {
       
   217                     delete iInstances[j];
       
   218                     iInstances.Remove(j);
       
   219                     iTodoPriorityOrder.Remove(i);
       
   220                     i--;
       
   221                     iNotShownEntries = ETrue;
       
   222                     break;
       
   223                     }   
       
   224                 }
       
   225             }
       
   226         }
       
   227     else
       
   228         {
       
   229         TInt i( iInstances.Count() - 1 );
       
   230         while( i >= 0 && 
       
   231                iInstances.Count() > iMaxInstances )
       
   232             {
       
   233             if( iInstances[i]->Entry().EntryTypeL() == aType )
       
   234                 {
       
   235                 delete iInstances[i];
       
   236                 iInstances.Remove(i);
       
   237                 iNotShownEntries = ETrue;
       
   238                 }
       
   239             i--;
       
   240             }
       
   241         }
       
   242     
       
   243     TRACE_EXIT_POINT;
       
   244     }
       
   245 
       
   246 // ---------------------------------------------------------------------------
       
   247 // CCalenPreviewData::RemoveInstances
       
   248 // ?implementation_description
       
   249 // (other items were commented in a header).
       
   250 // ---------------------------------------------------------------------------
       
   251 //
       
   252 void CCalenPreviewData::RemoveInstances()
       
   253     {
       
   254     TRACE_ENTRY_POINT;
       
   255     
       
   256     TInt i( 0 );
       
   257 
       
   258     while( iInstances.Count() > iMaxInstances )
       
   259         {
       
   260         i = iInstances.Count() - 1;
       
   261         delete iInstances[i];
       
   262         iInstances.Remove( i );
       
   263         iNotShownEntries = ETrue;
       
   264         }
       
   265 
       
   266     TRACE_EXIT_POINT;
       
   267     }
       
   268 
       
   269 // ---------------------------------------------------------------------------
       
   270 // CCalenPreviewData::RemoveInstance
       
   271 // ?implementation_description
       
   272 // (other items were commented in a header).
       
   273 // ---------------------------------------------------------------------------
       
   274 //
       
   275 void CCalenPreviewData::RemoveInstance(TInt aIndex)
       
   276     {
       
   277     TRACE_ENTRY_POINT;
       
   278     
       
   279     if( aIndex < iInstances.Count() && aIndex >= 0 )
       
   280         {
       
   281         delete iInstances[aIndex];
       
   282         iInstances.Remove(aIndex);
       
   283         }
       
   284 
       
   285     TRACE_EXIT_POINT;
       
   286     }
       
   287 
       
   288 // ---------------------------------------------------------------------------
       
   289 // CCalenPreviewData::DeleteInstances
       
   290 // ?implementation_description
       
   291 // (other items were commented in a header).
       
   292 // ---------------------------------------------------------------------------
       
   293 //
       
   294 void CCalenPreviewData::DeleteInstances()
       
   295     {
       
   296     TRACE_ENTRY_POINT;
       
   297     iInstances.ResetAndDestroy();
       
   298     TRACE_EXIT_POINT;
       
   299     }
       
   300 
       
   301 // ---------------------------------------------------------------------------
       
   302 // CCalenPopupDataBuilder::FindInstancesL
       
   303 // ?implementation_description
       
   304 // (other items were commented in a header).
       
   305 // ---------------------------------------------------------------------------
       
   306 //
       
   307 void CCalenPreviewData::FindInstancesL(const TTime& aDay)
       
   308     {
       
   309     TRACE_ENTRY_POINT;
       
   310 
       
   311     iInstances.ResetAndDestroy();
       
   312     
       
   313     RArray<TInt> colIdArray;
       
   314     CCalenNativeView::GetActiveCollectionidsL( iServices, colIdArray );
       
   315                 
       
   316     if(colIdArray.Count() > 0)
       
   317         {  
       
   318           CalenAgendaUtils::CreateEntryIdListForDayL( iInstances,
       
   319                                 iServices.InstanceViewL(colIdArray),
       
   320                                 aDay,
       
   321                               ETrue/*custom sort for popup*/ );
       
   322           
       
   323         }
       
   324     else
       
   325           {
       
   326           CalenAgendaUtils::CreateEntryIdListForDayL( iInstances,
       
   327                                             iServices.InstanceViewL(),
       
   328                                             aDay,
       
   329                                           ETrue/*custom sort for popup*/ );      
       
   330           }
       
   331     
       
   332     colIdArray.Reset();
       
   333     TRACE_EXIT_POINT;  
       
   334     }
       
   335 
       
   336 // ---------------------------------------------------------------------------
       
   337 // CCalenPreviewData::GetInstance
       
   338 // ?implementation_description
       
   339 // (other items were commented in a header).
       
   340 // ---------------------------------------------------------------------------
       
   341 //
       
   342 CCalInstance* CCalenPreviewData::Instance(TInt aIndex)
       
   343     {
       
   344     TRACE_ENTRY_POINT;
       
   345     TRACE_EXIT_POINT;
       
   346     return iInstances[aIndex];
       
   347     }
       
   348 // ---------------------------------------------------------------------------
       
   349 // CCalenPreviewData::GetInstance
       
   350 // ?implementation_description
       
   351 // (other items were commented in a header).
       
   352 // ---------------------------------------------------------------------------
       
   353 //
       
   354 CCalenPreviewEntry* CCalenPreviewData::Entry(TInt aIndex)
       
   355     {
       
   356     TRACE_ENTRY_POINT;
       
   357     TRACE_EXIT_POINT;
       
   358     return iEntries[aIndex];
       
   359     }
       
   360 
       
   361 // ---------------------------------------------------------------------------
       
   362 // ?classname::?member_function
       
   363 // ?implementation_description
       
   364 // (other items were commented in a header).
       
   365 // ---------------------------------------------------------------------------
       
   366 //
       
   367 void CCalenPreviewData::CreateEntriesL(const TTime& aDay)
       
   368     {
       
   369     TRACE_ENTRY_POINT;
       
   370     TInt rowsUsed(0);
       
   371     CCalenPreviewEntry* temp = NULL;
       
   372     
       
   373     /* Calculate need for each row */    
       
   374     TInt maxRows = iLayoutManager->UsePreview() ? 
       
   375     (iMaxInstances - iInstances.Count() + 1) : 1;
       
   376     
       
   377     TInt count = iInstances.Count();
       
   378     if(iInstances.Count() > 0)
       
   379         {
       
   380         RPointerArray<CCalCalendarInfo> calendarInfoList;
       
   381         iServices.GetAllCalendarInfoL(calendarInfoList);
       
   382         CleanupClosePushL(calendarInfoList); 
       
   383         
       
   384         for( TInt i(0); i < iInstances.Count(); i++)
       
   385             {
       
   386             CCalEntry& aEntry = iInstances[i]->Entry();
       
   387             TCalCollectionId colId = iInstances[i]->InstanceIdL().iCollectionId;
       
   388             HBufC* calendarFileName = iServices.GetCalFileNameForCollectionId(colId).AllocLC();
       
   389             TInt calIndex = calendarInfoList.Find(*calendarFileName, 
       
   390                         CCalenPreviewData::CalendarInfoIdentifierL);
       
   391             CleanupStack::PopAndDestroy(calendarFileName);
       
   392             if(calIndex != KErrNotFound && calendarInfoList[calIndex]->Enabled())
       
   393                 {
       
   394                 temp = CCalenPreviewEntry::NewL(iInstances[i], iLayoutManager,
       
   395                 aDay, maxRows,calendarInfoList[calIndex]->Color().Value());
       
   396                 iEntries.AppendL(temp);
       
   397                 rowsUsed += temp->LineCount();
       
   398                 }
       
   399             }
       
   400         CleanupStack::PopAndDestroy(&calendarInfoList);
       
   401         }
       
   402     else if(iLayoutManager->UsePreview())
       
   403         {
       
   404         /* Create entry for empty text */
       
   405         temp = CCalenPreviewEntry::NewL(
       
   406         iLayoutManager,
       
   407         CCalenPreviewEntry::ECalenPreviewEntryEmpty,0);
       
   408         iEntries.AppendL(temp);
       
   409         rowsUsed += temp->LineCount();
       
   410         }
       
   411 
       
   412     /* Calculate row division */
       
   413     TInt rows = maxRows;
       
   414     while(rowsUsed > iMaxInstances)
       
   415         {
       
   416         RemoveLine( CCalEntry::ETodo, rowsUsed, rows );
       
   417         if(rowsUsed == iMaxInstances)
       
   418             break;
       
   419         RemoveLine( CCalEntry::EAnniv, rowsUsed, rows );
       
   420         if(rowsUsed == iMaxInstances)
       
   421             break;
       
   422         RemoveLine( CCalEntry::EEvent, rowsUsed, rows );
       
   423         if(rowsUsed == iMaxInstances)
       
   424             break;
       
   425 
       
   426         RemoveMeetingLineL( rowsUsed, rows );
       
   427         rows--;
       
   428         }
       
   429 
       
   430     for(TInt i(0); i < iEntries.Count(); i++)
       
   431         {
       
   432         TBool lastLine(EFalse);
       
   433         if( i == iEntries.Count() - 1 &&
       
   434             NotShownEntries())
       
   435             lastLine = ETrue;
       
   436         iEntries[i]->FormatTextL(lastLine);
       
   437         }
       
   438 
       
   439     iLayoutManager->SetLinesUsed(rowsUsed);
       
   440     TRACE_EXIT_POINT;
       
   441     }
       
   442 
       
   443 void CCalenPreviewData::RemoveLine(const CCalEntry::TType aType,
       
   444                                    TInt& aRowsUsed, TInt aRows)
       
   445     {
       
   446     TRACE_ENTRY_POINT;
       
   447 
       
   448     if(aType == CCalEntry::ETodo)
       
   449         {
       
   450         // use todo priority list
       
   451         for(TInt i(0); i < iTodoPriorityOrder.Count() && aRowsUsed > iMaxInstances; i++)
       
   452             {
       
   453             for(TInt j(0); j < iInstances.Count() && aRowsUsed > iMaxInstances; j++)
       
   454                 {
       
   455                 if( iTodoPriorityOrder[i] == iInstances[j] &&
       
   456                     iEntries[j]->LineCount() == aRows && 
       
   457                     iEntries[j]->RemoveLine())
       
   458                     {
       
   459                     aRowsUsed--;
       
   460                     break;
       
   461                     }
       
   462                 }   
       
   463             }
       
   464         }
       
   465     else
       
   466         {
       
   467         for(TInt i = iEntries.Count()-1; 
       
   468             i >= 0 && aRowsUsed > iMaxInstances; i--)
       
   469             {
       
   470             if( iEntries[i]->EventType() == aType &&
       
   471                 iEntries[i]->LineCount() == aRows && 
       
   472                 iEntries[i]->RemoveLine())
       
   473                 {
       
   474                 aRowsUsed--;
       
   475                 }
       
   476             }
       
   477         }
       
   478     TRACE_EXIT_POINT;
       
   479     }
       
   480 
       
   481 void CCalenPreviewData::RemoveMeetingLineL(TInt& aRowsUsed, TInt aRows)
       
   482     {
       
   483     TRACE_ENTRY_POINT;
       
   484 
       
   485     if(iToday)
       
   486         {
       
   487         // Past events
       
   488         for(TInt i(0); i < iEntries.Count() && aRowsUsed > iMaxInstances; i++)
       
   489             {
       
   490             if( ( iEntries[i]->EventType() == CCalEntry::EAppt ||
       
   491                   iEntries[i]->EventType() == CCalEntry::EReminder ) &&
       
   492                 iInstances[i]->EndTimeL().TimeLocalL() < iCurrent)
       
   493                 {
       
   494                 if(iEntries[i]->LineCount() == aRows && 
       
   495                    iEntries[i]->RemoveLine())
       
   496                     {
       
   497                     aRowsUsed--;
       
   498                     }
       
   499                 }
       
   500             }
       
   501         // Ongoing meetings, start time less than 30 from current time
       
   502         TTime range(iCurrent - TTimeIntervalMinutes(iRange));
       
   503         for(TInt i(0); i < iEntries.Count() && aRowsUsed > iMaxInstances; i++)
       
   504             {
       
   505             if( (iEntries[i]->EventType() == CCalEntry::EAppt ||
       
   506                  iEntries[i]->EventType() == CCalEntry::EReminder) &&
       
   507                 iInstances[i]->EndTimeL().TimeLocalL() > iCurrent &&
       
   508                 iInstances[i]->StartTimeL().TimeLocalL() < range)
       
   509                 {
       
   510                 if(iEntries[i]->LineCount() == aRows && 
       
   511                    iEntries[i]->RemoveLine())
       
   512                     {
       
   513                     aRowsUsed--;
       
   514                     }
       
   515                 }
       
   516             }
       
   517         // Upcoming events
       
   518         for(TInt i(iEntries.Count()-1); i >= 0  && aRowsUsed > iMaxInstances; i--)
       
   519             {
       
   520             if( (iEntries[i]->EventType() == CCalEntry::EAppt ||
       
   521                  iEntries[i]->EventType() == CCalEntry::EReminder) &&
       
   522                 iInstances[i]->StartTimeL().TimeLocalL() > iCurrent)
       
   523                 {
       
   524                 if(iEntries[i]->LineCount() == aRows && 
       
   525                    iEntries[i]->RemoveLine())
       
   526                     {
       
   527                     aRowsUsed--;
       
   528                     }
       
   529                 }
       
   530             }
       
   531         // Ongoing in range
       
   532         for(TInt i(0); i < iEntries.Count() && aRowsUsed > iMaxInstances; i++)
       
   533             {
       
   534             if( (iEntries[i]->EventType() == CCalEntry::EAppt ||
       
   535                  iEntries[i]->EventType() == CCalEntry::EReminder) &&
       
   536                 iInstances[i]->StartTimeL().TimeLocalL() > range && 
       
   537                 iInstances[i]->StartTimeL().TimeLocalL() < iCurrent &&
       
   538                 iInstances[i]->EndTimeL().TimeLocalL() > iCurrent)
       
   539                 {
       
   540                 if(iEntries[i]->LineCount() == aRows && 
       
   541                    iEntries[i]->RemoveLine())
       
   542                     {
       
   543                     aRowsUsed--;
       
   544                     }
       
   545                 }
       
   546             }
       
   547         }
       
   548     else
       
   549         {
       
   550         for(TInt i = iEntries.Count()-1; i >= 0 && aRowsUsed > iMaxInstances; i--)
       
   551             {
       
   552             if( iEntries[i]->EventType() == CCalEntry::EAppt ||
       
   553                 iEntries[i]->EventType() == CCalEntry::EReminder)
       
   554                 {
       
   555                 if(iEntries[i]->LineCount() == aRows && 
       
   556                    iEntries[i]->RemoveLine())
       
   557                     {
       
   558                     aRowsUsed--;
       
   559                     }
       
   560                 }
       
   561             }
       
   562         }
       
   563     TRACE_EXIT_POINT;
       
   564     }
       
   565 
       
   566 void CCalenPreviewData::PrioritizeTodosL()
       
   567     {
       
   568     TRACE_ENTRY_POINT;
       
   569     for(TInt i(0); i < iInstances.Count(); i++)
       
   570         {
       
   571         if( iInstances[i]->Entry().EntryTypeL() == CCalEntry::ETodo )
       
   572             {
       
   573             iTodoPriorityOrder.AppendL(iInstances[i]);
       
   574             }
       
   575         }
       
   576 
       
   577     TLinearOrder<CCalInstance> instanceListOrder( CCalenPreviewData::TodoPrioCompare );
       
   578     iTodoPriorityOrder.Sort( instanceListOrder );
       
   579     TRACE_EXIT_POINT;
       
   580     }
       
   581 
       
   582 void CCalenPreviewData::SetTimedRangeL(const TTime aCurrent, const TInt aRange)
       
   583     {
       
   584     TRACE_ENTRY_POINT;
       
   585     iCurrent = aCurrent;
       
   586     iRange = aRange;
       
   587     TRACE_EXIT_POINT;
       
   588     }
       
   589 
       
   590 TInt CCalenPreviewData::TodoPrioCompare(const CCalInstance& aInstance_1, 
       
   591                                         const CCalInstance& aInstance_2)
       
   592     {
       
   593     TRACE_ENTRY_POINT;
       
   594 
       
   595     const CCalEntry& entry_1 = aInstance_1.Entry();
       
   596     const CCalEntry& entry_2 = aInstance_2.Entry();
       
   597 
       
   598     TInt res = KErrArgument;
       
   599     PIM_TRAPD_HANDLE( (res = DoTodoPrioCompareL(entry_1, entry_2)) );
       
   600     
       
   601     TRACE_EXIT_POINT;    
       
   602     return res;
       
   603     }
       
   604 
       
   605 TInt CCalenPreviewData::DoTodoPrioCompareL(const CCalEntry& aEntry_1, 
       
   606                                            const CCalEntry& aEntry_2)
       
   607     {
       
   608     TRACE_ENTRY_POINT;
       
   609 
       
   610     TInt ret( 0 );
       
   611     CCalEntry::TStatus status_1 = aEntry_1.StatusL();
       
   612     CCalEntry::TStatus status_2 = aEntry_2.StatusL();
       
   613 
       
   614     if( status_1 == CCalEntry::ENullStatus )  status_1 = CCalEntry::ETodoNeedsAction;
       
   615     if( status_2 == CCalEntry::ENullStatus )  status_2 = CCalEntry::ETodoNeedsAction;
       
   616 
       
   617     if( status_1 == status_2 )
       
   618         {
       
   619         TTime time_1 = aEntry_1.EndTimeL().TimeUtcL();
       
   620         TTime time_2 = aEntry_2.EndTimeL().TimeUtcL();
       
   621         
       
   622         if( time_1 == time_2 )
       
   623             {
       
   624             const TUint pri_1( aEntry_1.PriorityL() );
       
   625             const TUint pri_2( aEntry_2.PriorityL() );
       
   626             
       
   627             if( pri_1 == pri_2 )
       
   628                 {
       
   629                 time_1 = aEntry_1.LastModifiedDateL().TimeUtcL();
       
   630                 time_2 = aEntry_2.LastModifiedDateL().TimeUtcL();
       
   631                 
       
   632                 if( time_1 == time_2 )     ret = 0;
       
   633                 else if( time_1 > time_2 ) ret = -1;
       
   634                 else                       ret = 1;
       
   635                 }
       
   636             else
       
   637                 {
       
   638                 if( pri_1 > pri_2 ) ret = -1;
       
   639                 else                ret = 1;
       
   640                 }
       
   641             }
       
   642         else
       
   643             {
       
   644             if( time_1 > time_2 ) ret = 1;
       
   645             else                  ret = -1;
       
   646             }
       
   647         }
       
   648     else
       
   649         {
       
   650         if( status_1 == CCalEntry::ETodoCompleted ) ret = 1;
       
   651         else                                        ret = -1;
       
   652         }
       
   653     TRACE_EXIT_POINT;
       
   654     return ret;
       
   655     }
       
   656 
       
   657 // --------------------------------------------------------------------------
       
   658 // CCalenPreviewData::ProcessMonthInstancesL
       
   659 // ?implementation_description
       
   660 // (other items were commented in a header).
       
   661 // --------------------------------------------------------------------------
       
   662 //
       
   663 void CCalenPreviewData::ProcessMonthInstancesL(const TTime aRangeStart, 
       
   664                                                const TBool aIsToday)
       
   665     {
       
   666     TRACE_ENTRY_POINT;
       
   667     /**
       
   668      * Priority order
       
   669      * by types:
       
   670      *  1. EAppt (and EReminder)
       
   671      *  2. ETodo
       
   672      *  3. EAnniv
       
   673      *  4. EEvent 
       
   674      * by properties:
       
   675      *  1. date/time (start time for EAppt and EReminder)
       
   676      *  2. by duration (shotest 1st) (only EAppt and EReminder) 
       
   677      *     FIXME: AL - EReminder has no duration...do we prefer EAppts?
       
   678      *  3. priority (only ETodo)
       
   679      *  4. by modified date (oldest 1st)
       
   680      **/
       
   681 
       
   682     // remove all excess entries
       
   683 
       
   684     PrioritizeTodosL();    
       
   685 
       
   686     if( iInstances.Count() > iMaxInstances )
       
   687         {
       
   688         RemoveInstancesL( CCalEntry::ETodo );
       
   689 
       
   690         RemoveInstancesL( CCalEntry::EAnniv );
       
   691         RemoveInstancesL( CCalEntry::EEvent );
       
   692  
       
   693         
       
   694         TInt i( 0 );
       
   695         // ...next, all 'expired' timed notes (applies only for 'today')...
       
   696         while( i < iInstances.Count() && 
       
   697                iInstances.Count() > iMaxInstances && 
       
   698                aIsToday )
       
   699             {
       
   700             CCalInstance* inst = iInstances[i];
       
   701             CCalEntry& entry = inst->Entry();
       
   702             CCalEntry::TType type = entry.EntryTypeL();
       
   703             TTime entryStart(0);
       
   704 
       
   705             TBool timedEntry( type == CCalEntry::EAppt || 
       
   706                               type == CCalEntry::EReminder );
       
   707 
       
   708             // StartTimeL for undated to-dos will leave w/ KErrArgument!
       
   709             if( timedEntry )
       
   710                 {
       
   711                 entryStart = inst->StartTimeL().TimeLocalL();
       
   712                 }
       
   713             //  past or (timed entry AND out of time range)
       
   714             if( timedEntry && 
       
   715                 ( inst->EndTimeL().TimeLocalL() < iCurrent || 
       
   716                   entryStart < aRangeStart ) )
       
   717                 {
       
   718                 RemoveInstance(i);
       
   719                 iNotShownEntries = ETrue;
       
   720                 }
       
   721             else
       
   722                 {
       
   723                 i++;
       
   724                 }
       
   725             }
       
   726         // ...and finally all timed notes that doesn't fit
       
   727         RemoveInstances();
       
   728         }
       
   729     
       
   730     TRACE_EXIT_POINT;
       
   731     }
       
   732 
       
   733 // --------------------------------------------------------------------------
       
   734 // CCalenPreviewData::ProcessWeekInstancesL
       
   735 // ?implementation_description
       
   736 // (other items were commented in a header).
       
   737 // --------------------------------------------------------------------------
       
   738 //
       
   739 void CCalenPreviewData::ProcessWeekInstancesL(const TTime aStart, 
       
   740                                               const TTime aEnd)
       
   741     {
       
   742     TRACE_ENTRY_POINT;
       
   743 
       
   744     TInt i( 0 );
       
   745 
       
   746     // remove entries that do not intersect with the time range
       
   747     while( i < iInstances.Count() )
       
   748         {
       
   749         CCalEntry& entry = iInstances[i]->Entry();
       
   750         CCalEntry::TType type = entry.EntryTypeL();
       
   751         TTime entryStart( TInt64(0) );
       
   752         TTime entryEnd( TInt64(0) );
       
   753 
       
   754         TBool timedEntry( type == CCalEntry::EAppt || type == CCalEntry::EReminder 
       
   755                           || CalenViewUtils::IsAlldayEventL( *( iInstances[i] ) ) );
       
   756 
       
   757         // calling StartTimeL for undated to-do will leave w/ KErrArgument!
       
   758         if( timedEntry )
       
   759             {
       
   760             entryStart = iInstances[i]->StartTimeL().TimeLocalL();
       
   761             entryEnd = iInstances[i]->EndTimeL().TimeLocalL();
       
   762             }
       
   763 
       
   764         // (timed entry AND doesn't intersect with the time range)
       
   765         //  OR
       
   766         // (non-timed entry)
       
   767         if( !timedEntry ||
       
   768             (timedEntry && !CalenDateUtils::TimeRangesIntersect(aStart, aEnd, entryStart, entryEnd)) )
       
   769             {
       
   770             RemoveInstance(i);
       
   771             }
       
   772         else
       
   773             {
       
   774             i++;
       
   775             }
       
   776         }
       
   777 
       
   778     // remove timed notes that doesn't fit (starting from bottom)
       
   779     RemoveInstances();
       
   780     
       
   781     TRACE_EXIT_POINT;
       
   782     }
       
   783 
       
   784 // -----------------------------------------------------------------------------
       
   785 // CCalenPreviewData::CalendarInfoIdentifierL
       
   786 // Returns the multiple DB information.
       
   787 // -----------------------------------------------------------------------------
       
   788 //
       
   789 TBool CCalenPreviewData::CalendarInfoIdentifierL( const HBufC* aName,
       
   790                                         const CCalCalendarInfo& aCalendarInfo)
       
   791     {
       
   792     TRACE_ENTRY_POINT;
       
   793     TBool retVal = EFalse;
       
   794     HBufC* calendarFileName = aCalendarInfo.FileNameL().AllocLC();
       
   795     retVal = calendarFileName->CompareF(*aName);
       
   796     CleanupStack::PopAndDestroy(calendarFileName);
       
   797     TRACE_EXIT_POINT;
       
   798     return (!retVal);
       
   799     }
       
   800 
       
   801 //  End of File