calendarui/organizerplugin/aiagendaplugin2/src/aicalendarplugin2eventitem.cpp
branchRCL_3
changeset 30 bd7edf625bdd
parent 0 f979ecb2b13e
equal deleted inserted replaced
29:12af337248b1 30:bd7edf625bdd
       
     1 /*
       
     2 * Copyright (c) 2005-2006 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:  
       
    15  *
       
    16 */
       
    17 
       
    18 
       
    19 #include "aicalendarplugin2eventitem.h"
       
    20 #include "aicalendarplugin2eventstrings.h"
       
    21 #include "aicalendarplugin2constants.hrh"
       
    22 #include "aicalendarplugin2constantdata.h"
       
    23 #include "aicalendarplugin2contentmodel.h"
       
    24 #include <calinstance.h>
       
    25 #include <Calendar.rsg> // for R_CALEN_QTN_CALE_NO_SUBJECT
       
    26 #include <StringLoader.h> // for loading R_CALEN_QTN_CALE_NO_SUBJECT
       
    27 
       
    28 CAiCalendarPlugin2EventItem* CAiCalendarPlugin2EventItem::NewL(
       
    29                              const CCalInstance& aCalInstance,
       
    30                              CAICalendarPlugin2ConstantData& aConstantData )
       
    31     {
       
    32     CAiCalendarPlugin2EventItem* self = new( ELeave )CAiCalendarPlugin2EventItem;
       
    33     CleanupStack::PushL( self );
       
    34     self->ConstructL( aCalInstance, aConstantData );
       
    35     CleanupStack::Pop( self );
       
    36     return self;
       
    37     }
       
    38 
       
    39 CAiCalendarPlugin2EventItem::CAiCalendarPlugin2EventItem()
       
    40     {
       
    41     }
       
    42 
       
    43 void CAiCalendarPlugin2EventItem::ConstructL(
       
    44                              const CCalInstance& aCalInstance,
       
    45                              CAICalendarPlugin2ConstantData& aConstantData )
       
    46     {
       
    47     iHandleTomorrowItems = ( aConstantData.iDaysToHandleAsNotToday == KAIRangeTomorrowOnly );
       
    48     
       
    49     iNotTodayDayRange = aConstantData.iDaysToHandleAsNotToday;
       
    50 
       
    51     // This needs to be first as data from this is used on the other 2 extractors
       
    52     ExtractEventIdentifiersL( aCalInstance );
       
    53 
       
    54     TTime today;
       
    55     today.HomeTime();
       
    56     const TTime start( aCalInstance.StartTimeL().TimeLocalL() );
       
    57     const TDateTime x = today.DateTime();
       
    58     const TDateTime y = start.DateTime();
       
    59 
       
    60     iEventStrings =
       
    61             CAiCalendarPlugin2EventStrings::NewL( aCalInstance,
       
    62                                                   aConstantData.TimeFormatUsual(),
       
    63                                                   aConstantData.DateFormatWithoutYearWithZero(),
       
    64                                                   aConstantData.iAppendEndTimeToOngoingItems,
       
    65                                                   aConstantData.iUseAlternatePublish,
       
    66                                                   *this );
       
    67     iOpenInViewer = aConstantData.iOpenInViewer;
       
    68     iOpenFirstValid = aConstantData.iOpenFirstValid;
       
    69     iChecksum = CreateChecksumFromString( SecondLineText() );
       
    70     iChecksum += CreateChecksumFromString( FirstLineText() );
       
    71     
       
    72     iUnnamed = StringLoader::LoadL( R_CALEN_QTN_CALE_NO_SUBJECT );
       
    73     }
       
    74 
       
    75 CAiCalendarPlugin2EventItem::~CAiCalendarPlugin2EventItem()
       
    76     {
       
    77     delete iUnnamed;
       
    78     delete iStartTimeSubject;
       
    79     delete iEventStrings;
       
    80     delete iUid;
       
    81     }
       
    82 
       
    83 void CAiCalendarPlugin2EventItem::ExtractEventIdentifiersL( const CCalInstance& aCalInstance )
       
    84     {
       
    85     iType = ExtractTypeL( aCalInstance );
       
    86     iStatus =  aCalInstance.Entry().StatusL();
       
    87     iIconId = IconIdToEvent( iType, iStatus );
       
    88     iLocalUid = aCalInstance.Entry().LocalUidL();
       
    89     iTime = aCalInstance.Time().TimeLocalL();
       
    90     iEndTime = aCalInstance.EndTimeL().TimeLocalL();
       
    91     iLastModifiedTime = aCalInstance.Entry().LastModifiedDateL().TimeUtcL();
       
    92     
       
    93     delete iUid;
       
    94     iUid = NULL;
       
    95     iUid = aCalInstance.Entry().UidL().AllocL();
       
    96     
       
    97     // Multiple-day Todo requires date
       
    98     TTime today;
       
    99     today.HomeTime();
       
   100     if ( iType == EPluginItemToDo )
       
   101     	{
       
   102     	iIsToday = OnSameDay( today, iEndTime );
       
   103     	iIsTomorrow = OnNextDay( today, iEndTime );
       
   104 
       
   105     	if( OnDayRange( today, iEndTime, iNotTodayDayRange ) )
       
   106     		{
       
   107     	    iIsNotTodayEvent = ETrue;
       
   108     	    }
       
   109 
       
   110     	if( iEndTime > today )
       
   111     		{
       
   112     	    iIsFutureEvent = ETrue;
       
   113     		}
       
   114     	}
       
   115             
       
   116     if( !iIsToday )
       
   117         {
       
   118         // Event is not today, and future event. Date needed. Otherwise not.
       
   119         iDateNeeded = ETrue;
       
   120         if( iType != EPluginItemDayNote &&
       
   121             iType != EPluginItemAnniv &&
       
   122             iType != EPluginItemToDo )
       
   123             {
       
   124             iTimeNeeded = ETrue;
       
   125             }
       
   126         }
       
   127     if( iType != EPluginItemDayNote &&
       
   128         iType != EPluginItemAnniv &&
       
   129         iType != EPluginItemToDo &&
       
   130         iIsToday )
       
   131         {
       
   132         iTimeNeeded = ETrue;
       
   133         }
       
   134     }
       
   135     
       
   136 TAICal2PluginItemType CAiCalendarPlugin2EventItem::ExtractTypeL(
       
   137                                 const CCalInstance& aCalInstance )
       
   138     {
       
   139     TTime today;
       
   140     today.HomeTime();
       
   141     const TTime start( aCalInstance.StartTimeL().TimeLocalL() );
       
   142     iIsToday = OnSameDay( today, start );
       
   143     iIsTomorrow = OnNextDay( today, start );
       
   144 
       
   145     if( OnDayRange( today, start, iNotTodayDayRange ) )
       
   146         {
       
   147         iIsNotTodayEvent = ETrue;
       
   148         }
       
   149 
       
   150     if( start > today )
       
   151         {
       
   152         iIsFutureEvent = ETrue;
       
   153         }
       
   154 
       
   155     switch( aCalInstance.Entry().EntryTypeL() )
       
   156         {
       
   157         case CCalEntry::EAppt:
       
   158             {
       
   159             /*
       
   160             UI Spec this priorization is based on:
       
   161 
       
   162             1. Display events which begin within two (2) hours.
       
   163 
       
   164             2. Display events which have begun at the maximum 30 minutes ago.
       
   165             If each ongoing event doesn’t fit to plug-in then events which starting
       
   166             time is closer current time are displayed.
       
   167 
       
   168             3. Display upcoming events (starting time >= current time) which are left.
       
   169 
       
   170             4. Display ongoing events (ending time > current time) which are left.
       
   171             If each ongoing event doesn’t fit to plug-in then events which starting
       
   172             time is closer current time are displayed. This includes long meetings that
       
   173             have lasted for day(s).
       
   174 
       
   175             5. Past events (ending time < current time) are not displayed in the Organizer
       
   176             plug-in. This is a precaution bacause future engine releases dont
       
   177             contain expired events.
       
   178             */
       
   179             const TTimeIntervalMinutes oneMinute( 1 );
       
   180             const TTimeIntervalMinutes thirtyOneMinutes( 31 );
       
   181             const TTimeIntervalHours twoHours( 2 );
       
   182             const TTime end( aCalInstance.EndTimeL().TimeLocalL() );
       
   183 
       
   184             const TBool upcomingEvent2hrs = ( start > today ) &&
       
   185                                             ( start <= ( today + twoHours ) ); // 1.
       
   186 
       
   187             const TBool ongoingEvent = ( ( start >= ( today - thirtyOneMinutes ) ) &&
       
   188                                        ( start <= today ) &&
       
   189                                        ( ( end +  oneMinute ) >= today ) ); // 2.
       
   190 
       
   191             const TBool upcomingEvent = ( start > today + twoHours ); // 3.
       
   192 
       
   193             // This handles properly also the "long meeting" case, where
       
   194             // the meeting has begun yesterday or before that.
       
   195             const TBool olderOngoingEvent = ( ( start < ( today - thirtyOneMinutes ) ) &&
       
   196                                             ( ( end + oneMinute ) >= today ) ); // 4.
       
   197 
       
   198             const TBool expiredEvent = ( end + oneMinute ) < today; // 5.
       
   199 
       
   200             if( expiredEvent )
       
   201                 {
       
   202                 return EPluginItemExpired;
       
   203                 }
       
   204             else if( upcomingEvent2hrs )
       
   205                 {
       
   206                 return EPluginItemMeeting;
       
   207                 }
       
   208             else if( ongoingEvent )
       
   209                 {
       
   210                 return EPluginItemOnGoingEvent;
       
   211                 }
       
   212             else if( upcomingEvent )
       
   213                 {
       
   214                 if( !iIsToday )
       
   215                     {
       
   216                     // Handle the "not today meeting" case
       
   217                     return EPluginItemMeeting;
       
   218                     }
       
   219                 return EPluginItemUpcomingMeeting;
       
   220                 }
       
   221             else if( olderOngoingEvent )
       
   222                 {
       
   223                 return EPluginItemOlderOnGoingEvent;
       
   224                 }
       
   225             else
       
   226                 {
       
   227                 return EPluginItemMeeting;
       
   228                 }
       
   229             }
       
   230 
       
   231         case CCalEntry::EEvent:
       
   232             {
       
   233             return EPluginItemDayNote;
       
   234             }
       
   235 
       
   236         case CCalEntry::EAnniv:
       
   237             {
       
   238             return EPluginItemAnniv;
       
   239             }
       
   240 
       
   241         case CCalEntry::ETodo:
       
   242             {
       
   243             return EPluginItemToDo;
       
   244             }
       
   245 
       
   246         default:
       
   247             return EPluginItemNoEvents;
       
   248         }
       
   249     }
       
   250 
       
   251 TBool CAiCalendarPlugin2EventItem::OnSameDay( const TTime& aX, const TTime& aY )
       
   252     {
       
   253     const TDateTime x = aX.DateTime();
       
   254     const TDateTime y = aY.DateTime();
       
   255 
       
   256     return ( x.Year() == y.Year() )
       
   257         && ( x.Month() == y.Month() )
       
   258         && ( x.Day() == y.Day() );
       
   259     }
       
   260 
       
   261 TBool CAiCalendarPlugin2EventItem::OnNextDay( const TTime& aToday, const TTime& aEventTime )
       
   262     {
       
   263     TTime todayPlusOne( aToday );
       
   264     todayPlusOne += TTimeIntervalDays( 1 );
       
   265 
       
   266     const TDateTime x = todayPlusOne.DateTime();
       
   267     const TDateTime y = aEventTime.DateTime();
       
   268 
       
   269     return ( x.Year() == y.Year() )
       
   270         && ( x.Month() == y.Month() )
       
   271         && ( x.Day() == y.Day() );
       
   272     }
       
   273 
       
   274 TBool CAiCalendarPlugin2EventItem::OnDayRange( const TTime& aToday,
       
   275                                                const TTime& aEventTime,
       
   276                                                TInt aRange )
       
   277     {
       
   278     TTime todayPlusRange( aToday );
       
   279     todayPlusRange += TTimeIntervalDays( aRange + 1 );
       
   280     
       
   281     const TDateTime x( todayPlusRange.DateTime().Year(),
       
   282                        todayPlusRange.DateTime().Month(),
       
   283                        todayPlusRange.DateTime().Day(), 0, 0, 0, 0 );
       
   284     
       
   285     todayPlusRange = x;
       
   286     
       
   287     return ( aEventTime < todayPlusRange );
       
   288     }
       
   289     
       
   290 const TTime CAiCalendarPlugin2EventItem::Time() const
       
   291     {
       
   292     return iTime;
       
   293     }
       
   294 
       
   295 const TTime CAiCalendarPlugin2EventItem::LastModifiedTime() const
       
   296     {
       
   297     return iLastModifiedTime;
       
   298     }
       
   299 
       
   300 TInt CAiCalendarPlugin2EventItem::IconIdToEvent(
       
   301                                 TAICal2PluginItemType aType,
       
   302                                 CCalEntry::TStatus aStatus )
       
   303     {
       
   304     switch( aType )
       
   305         {
       
   306         case EPluginItemMeeting: // fall through
       
   307         case EPluginItemUpcomingMeeting:
       
   308         case EPluginItemOnGoingEvent:
       
   309         case EPluginItemOlderOnGoingEvent:
       
   310             {
       
   311             switch( aStatus )
       
   312                 {
       
   313                 case CCalEntry::ETentative:
       
   314                     {
       
   315                     return EAICalendarPlugin2IconMeetingTentative;
       
   316                     }
       
   317                 case CCalEntry::EConfirmed:
       
   318                     {
       
   319                     return EAICalendarPlugin2IconMeetingAccepted;
       
   320                     }
       
   321                 case CCalEntry::ECancelled:
       
   322                     {
       
   323                     // Should not happen!
       
   324                     return KErrNotFound;
       
   325                     }
       
   326                 default:
       
   327                     {
       
   328                     // fall through
       
   329                     }
       
   330                 }
       
   331             return EAICalendarPlugin2IconAppt;
       
   332             }
       
   333 
       
   334         case EPluginItemDayNote:
       
   335             {
       
   336             return EAICalendarPlugin2IconMemo;
       
   337             }
       
   338 
       
   339         case EPluginItemAnniv:
       
   340             {
       
   341             return EAICalendarPlugin2IconAnniv;
       
   342             }
       
   343         case EPluginItemToDo:
       
   344             {
       
   345             return EAICalendarPlugin2IconTodo;
       
   346             }
       
   347         }
       
   348     return KErrNotFound;
       
   349     }
       
   350 
       
   351 TAiCalendarFocusData CAiCalendarPlugin2EventItem::FocusData()
       
   352     {
       
   353     TAiCalendarFocusData focusData;
       
   354     focusData.iLocalUid = iLocalUid;
       
   355     focusData.iEntryTime = iTime;
       
   356     switch( iType )
       
   357         {
       
   358         case EPluginItemMeeting: // fall through
       
   359         case EPluginItemUpcomingMeeting:
       
   360         case EPluginItemOnGoingEvent:
       
   361         case EPluginItemOlderOnGoingEvent:
       
   362         case EPluginItemDayNote:
       
   363         case EPluginItemAnniv:
       
   364         case EPluginItemToDo:
       
   365             {
       
   366             if( iOpenFirstValid )
       
   367                 {
       
   368                 focusData.iType = EAI2CalOpenOnEventDay;
       
   369                 }
       
   370             else
       
   371                 {
       
   372                 focusData.iType = EAI2CalOpenEvent;
       
   373                 }
       
   374             break;
       
   375             }
       
   376         default:
       
   377             {
       
   378             focusData.iType = EAI2CalOpenToday;
       
   379             break;
       
   380             }
       
   381         }
       
   382     focusData.iOpenInViewer = iOpenInViewer;
       
   383     return focusData;
       
   384     }
       
   385 
       
   386 const TDesC& CAiCalendarPlugin2EventItem::FirstLineText()
       
   387     {
       
   388     return iEventStrings->CombinedTimeString();
       
   389     }
       
   390 
       
   391 const TDesC& CAiCalendarPlugin2EventItem::SecondLineText()
       
   392     {
       
   393     return iEventStrings->CombinedSubjectLocationString();
       
   394     }
       
   395 
       
   396 const TDesC& CAiCalendarPlugin2EventItem::StartTimeText()
       
   397     {
       
   398     return iEventStrings->StartTimeString();
       
   399     }
       
   400 
       
   401 const TDesC& CAiCalendarPlugin2EventItem::EndTimeText()
       
   402     {
       
   403     return iEventStrings->EndTimeString();
       
   404     }
       
   405 
       
   406 const TDesC& CAiCalendarPlugin2EventItem::SubjectText()
       
   407     {
       
   408     return iEventStrings->SubjectString();
       
   409     }
       
   410 
       
   411 const TDesC& CAiCalendarPlugin2EventItem::SubjectTimeString( TBool aAddTime )
       
   412     {
       
   413     delete iStartTimeSubject;
       
   414     iStartTimeSubject = NULL;
       
   415     TInt length = 0;
       
   416     if ( aAddTime )
       
   417         {
       
   418         // +1 for the space
       
   419         length += StartTimeText().Length() + 1;
       
   420         }
       
   421 
       
   422     if( SubjectText() == iUnnamed->Des() &&
       
   423              LocationText().Length() > 0 )
       
   424         {
       
   425         length += ( LocationText().Length() );
       
   426         }
       
   427     else if( SubjectText().Length() > 0 )
       
   428         {
       
   429         length += ( SubjectText().Length() );
       
   430         }
       
   431 
       
   432     iStartTimeSubject = HBufC::New( length );
       
   433     _LIT( KOrgTimeSubjectSeparator, " ");
       
   434     if ( iStartTimeSubject )
       
   435         {
       
   436         TPtr tempPtr = iStartTimeSubject->Des();
       
   437         if ( aAddTime )
       
   438             {
       
   439             tempPtr.Append( StartTimeText() );
       
   440             tempPtr.Append( KOrgTimeSubjectSeparator );            
       
   441             }
       
   442         if( SubjectText() == iUnnamed->Des() &&
       
   443             LocationText().Length() > 0 )
       
   444             {
       
   445             tempPtr.Append( LocationText() );
       
   446             }
       
   447         else if( SubjectText().Length() > 0 )
       
   448             {
       
   449             tempPtr.Append( SubjectText() );
       
   450             }
       
   451             
       
   452         return *iStartTimeSubject;
       
   453         }
       
   454     return KNullDesC;
       
   455     }
       
   456 
       
   457 const TDesC& CAiCalendarPlugin2EventItem::LocationText()
       
   458     {
       
   459     return iEventStrings->LocationString();
       
   460     }
       
   461 
       
   462 TAICal2PluginItemType CAiCalendarPlugin2EventItem::Type() const
       
   463     {
       
   464     return iType;
       
   465     }
       
   466 
       
   467 TInt CAiCalendarPlugin2EventItem::IconId()
       
   468     {
       
   469     return iIconId;
       
   470     }
       
   471 
       
   472 TBool CAiCalendarPlugin2EventItem::IsToday()
       
   473     {
       
   474     return iIsToday;
       
   475     }
       
   476 
       
   477 TBool CAiCalendarPlugin2EventItem::IsNotTodayEvent()
       
   478     {
       
   479     return iIsNotTodayEvent;
       
   480     }
       
   481 
       
   482 TBool CAiCalendarPlugin2EventItem::IsTomorrow()
       
   483     {
       
   484     return iIsTomorrow;
       
   485     }
       
   486 
       
   487 TBool CAiCalendarPlugin2EventItem::IsEndTimeToday()
       
   488     {
       
   489     TTime today;
       
   490     today.HomeTime();
       
   491     return OnSameDay( today, iEndTime );
       
   492     }
       
   493 
       
   494 TBool CAiCalendarPlugin2EventItem::IsFutureEvent()
       
   495     {
       
   496     return iIsFutureEvent;
       
   497     }
       
   498 
       
   499 TBool CAiCalendarPlugin2EventItem::DateNeeded()
       
   500     {
       
   501     return iDateNeeded;
       
   502     }
       
   503 
       
   504 TBool CAiCalendarPlugin2EventItem::TimeNeeded()
       
   505     {
       
   506     return iTimeNeeded;
       
   507     }
       
   508     
       
   509 TInt CAiCalendarPlugin2EventItem::CreateChecksumFromString( const TDesC& aString )
       
   510     {
       
   511     TInt checksum = 0;
       
   512     
       
   513     for ( TInt i = 0; i < aString.Length(); i++ )
       
   514         {
       
   515         checksum += aString[i] * ( i + 1);
       
   516         }
       
   517     return checksum * iType;       
       
   518     }
       
   519 
       
   520 // END OF FILE
       
   521