calendarui/organizerplugin/aiagendaplugin2/src/aicalendarplugin2eventstrings.cpp
changeset 0 f979ecb2b13e
equal deleted inserted replaced
-1:000000000000 0:f979ecb2b13e
       
     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 #include "aicalendarplugin2eventstrings.h"
       
    19 #include "aicalendarplugin2eventitem.h"
       
    20 #include "aicalendarplugin2constants.hrh"
       
    21 #include "aicalendarplugin2eventitem.h"
       
    22 #include "calendar.hrh" // for ECalendMax###
       
    23 #include <Calendar.rsg> // for R_CALEN_QTN_CALE_NO_SUBJECT
       
    24 #include <StringLoader.h> // for loading R_CALEN_QTN_CALE_NO_SUBJECT
       
    25 #include <calinstance.h>
       
    26 #include <AknBidiTextUtils.h>
       
    27 #include <AknUtils.h>
       
    28 
       
    29 // Local function
       
    30 
       
    31 const TDesC& ReturnProperReference( const HBufC* aBuffer )
       
    32     {
       
    33     if( aBuffer )
       
    34         return *aBuffer;
       
    35     else
       
    36         return KNullDesC;
       
    37     }
       
    38 
       
    39 // Class methods
       
    40 
       
    41 CAiCalendarPlugin2EventStrings* CAiCalendarPlugin2EventStrings::NewL(
       
    42                                             const CCalInstance& aInstance,
       
    43                                             const TDesC& aTimeFormat,
       
    44                                             const TDesC& aDateFormat,
       
    45                                             TBool aAppendEndTimeToOngoingEvents,
       
    46                                             TBool aUseAlternate,
       
    47                                             CAiCalendarPlugin2EventItem& aOwner )
       
    48     {
       
    49     CAiCalendarPlugin2EventStrings* self = new( ELeave )CAiCalendarPlugin2EventStrings(
       
    50                                                         aAppendEndTimeToOngoingEvents,
       
    51                                                         aUseAlternate,
       
    52                                                         aOwner );
       
    53     CleanupStack::PushL( self );
       
    54     self->ConstructL( aInstance, aTimeFormat, aDateFormat );
       
    55     CleanupStack::Pop( self );
       
    56     return self;
       
    57     }
       
    58 
       
    59 CAiCalendarPlugin2EventStrings::CAiCalendarPlugin2EventStrings(
       
    60                                             TBool aAppendEndTimeToOngoingEvents,
       
    61                                             TBool aUseAlternate,
       
    62                                             CAiCalendarPlugin2EventItem& aOwner )
       
    63   : iAppendEndTimeToOngoingEvents( aAppendEndTimeToOngoingEvents ),
       
    64     iUseAlternatePublish( aUseAlternate ),
       
    65     iOwner( aOwner )
       
    66     {
       
    67     }
       
    68 
       
    69 CAiCalendarPlugin2EventStrings::~CAiCalendarPlugin2EventStrings()
       
    70     {
       
    71     delete iLocation;
       
    72     delete iSubject;
       
    73     delete iSubjectLocationConstruct;
       
    74     delete iTimeConstruct;
       
    75     delete iStartTime;
       
    76     delete iEndTime;
       
    77     delete iEndDate;
       
    78     delete iDate;
       
    79     }
       
    80 
       
    81 void CAiCalendarPlugin2EventStrings::ConstructL(
       
    82                                             const CCalInstance& aCalInstance,
       
    83                                             const TDesC& aTimeFormat,
       
    84                                             const TDesC& aDateFormat )
       
    85     {
       
    86     ExtractDatesL( aCalInstance,
       
    87                    aDateFormat );
       
    88         
       
    89     // First reserve base lenght for space characted and extra control
       
    90     // characters.
       
    91     iBaseLength = KAICal2LenSpaceChar + KAknBidiExtraSpacePerLine;
       
    92     if( iDate )
       
    93         {
       
    94         // Add to baselenght the date if needed.
       
    95         iBaseLength += iDate->Length();
       
    96         }
       
    97         
       
    98     ExtractTimeL( aCalInstance,
       
    99                   aTimeFormat );
       
   100                   
       
   101     ExtractSubjectAndLocationL( aCalInstance );
       
   102     
       
   103     if( iUseAlternatePublish )
       
   104         {
       
   105         MakeAlternateStringsL();
       
   106         }
       
   107     }
       
   108 
       
   109 void CAiCalendarPlugin2EventStrings::ExtractDatesL(
       
   110                                             const CCalInstance& aCalInstance,
       
   111                                             const TDesC& aFormat)
       
   112     {
       
   113     if( iOwner.DateNeeded() ||
       
   114         ( ( iOwner.Type() == EPluginItemOlderOnGoingEvent ||
       
   115             iOwner.Type() == EPluginItemOnGoingEvent ||
       
   116             iOwner.Type() == EPluginItemMeeting ||
       
   117             iOwner.Type() == EPluginItemUpcomingMeeting ) &&
       
   118           !iOwner.IsEndTimeToday() ) )
       
   119         {
       
   120         TTime start = aCalInstance.StartTimeL().TimeLocalL();
       
   121         const TTime end = aCalInstance.EndTimeL().TimeLocalL();
       
   122 
       
   123         if( iOwner.Type() == EPluginItemToDo )
       
   124             {
       
   125             start = end;
       
   126             }
       
   127 
       
   128         iDate = HBufC::NewL( KAICal2SizeDateShort );
       
   129         TPtr bufPtr = iDate->Des();
       
   130 
       
   131         start.FormatL( bufPtr, aFormat );
       
   132 
       
   133         iEndDate = HBufC::NewL( KAICal2SizeDateShort );
       
   134         TPtr bufPtr2 = iEndDate->Des();
       
   135 
       
   136         end.FormatL( bufPtr2, aFormat );
       
   137         }
       
   138     }
       
   139 
       
   140 void CAiCalendarPlugin2EventStrings::ExtractTimeL( const CCalInstance& aCalInstance,
       
   141                                                    const TDesC& aFormat )
       
   142     {
       
   143     TTime adjustedStartTime( aCalInstance.StartTimeL().TimeLocalL() );
       
   144     const TTime unadjustedStartTime( aCalInstance.StartTimeL().TimeLocalL() );
       
   145     TTime end( aCalInstance.EndTimeL().TimeLocalL() );
       
   146     TTime today;
       
   147     today.HomeTime();
       
   148 
       
   149     if( iOwner.Type() == EPluginItemToDo )
       
   150         {
       
   151         adjustedStartTime = end;
       
   152         }
       
   153 
       
   154     // Locale instance for digit type check
       
   155     TLocale locale;
       
   156     TDigitType digitType = locale.DigitType();
       
   157     // Constants
       
   158     //_LIT(KPDF, "\x202C"); // Pop directional formatting
       
   159     //_LIT(KRLM, "\x200F"); // R to L marker
       
   160     //_LIT(KRLE, "\x202B"); // R to L embedding
       
   161     //_LIT(KLRM, "\x200E"); // L to R marker
       
   162     //_LIT(KLRE, "\x202A"); // L to R embedding
       
   163 
       
   164     // skip for "not today" items...
       
   165     if( ! ( !CAiCalendarPlugin2EventItem::OnSameDay( today, adjustedStartTime ) &&
       
   166         adjustedStartTime > today ) )
       
   167         {
       
   168         // handle events starting/ending on a different day
       
   169         if( !CAiCalendarPlugin2EventItem::OnSameDay( adjustedStartTime, today) &&
       
   170             adjustedStartTime < today ) // starts before
       
   171             {
       
   172             TDateTime todayStart;
       
   173             todayStart = today.DateTime();
       
   174             todayStart.SetHour( ECalenMinHour );
       
   175             todayStart.SetMinute( ECalenMinMinute );
       
   176             todayStart.SetSecond( ECalenMinSecond );
       
   177             todayStart.SetMicroSecond( 0 );
       
   178 
       
   179             adjustedStartTime = todayStart;  // start today at 00:00 
       
   180             }
       
   181         }
       
   182 
       
   183     iTimeConstruct = HBufC::NewL( KAICal2SizeTimeFormatUsual + iBaseLength );
       
   184     iStartTime = HBufC::NewL( KAICal2SizeTimeFormatUsual + iBaseLength );
       
   185     iEndTime = HBufC::NewL( KAICal2SizeTimeFormatUsual + iBaseLength );
       
   186 
       
   187     TPtr constructTimePtr = iTimeConstruct->Des();
       
   188     TPtr startTimePtr = iStartTime->Des();
       
   189     TPtr endTimePtr = iEndTime->Des();
       
   190     
       
   191     // If Arabic digits. Start RLO and RLE
       
   192     if (AknLayoutUtils::LayoutMirrored()) 
       
   193         {
       
   194         //constructTimePtr.Append(KRLM);
       
   195         }
       
   196     else
       
   197         {
       
   198         //constructTimePtr.Append(KLRM);
       
   199         //constructTimePtr.Append(KLRE);
       
   200         }
       
   201 
       
   202     // Now do the following:
       
   203     // if date+time needed:
       
   204     //      time construct has "date time - time"
       
   205     //      start time has "date starttime"
       
   206     //      end time has "date endtime"
       
   207 
       
   208     // if only date needed:
       
   209     //      time construct has "date"
       
   210     //      start time has "date"
       
   211     //      end time has "date"
       
   212     
       
   213     // if only time needed:
       
   214     //      time construct has "time - time"
       
   215     //      start time has "starttime"
       
   216     //      end time has "endtime"
       
   217     
       
   218     if( iOwner.DateNeeded() && iDate && iEndDate )
       
   219         {
       
   220         constructTimePtr.Append( iDate->Des() );
       
   221         startTimePtr.Append( iDate->Des() );
       
   222         endTimePtr.Append( iEndDate->Des() );
       
   223         }
       
   224     TBuf<KAICal2SizeTimeFormatUsual> timeBuf;
       
   225     if( iOwner.TimeNeeded() )
       
   226         {
       
   227         // No start time for event that started before today
       
   228         if( CAiCalendarPlugin2EventItem::OnSameDay( unadjustedStartTime, today) ||
       
   229             ( unadjustedStartTime > today ) )
       
   230             {
       
   231             unadjustedStartTime.FormatL( timeBuf, aFormat );  // start time
       
   232             }
       
   233         
       
   234         if( iOwner.DateNeeded() && iDate && iEndDate && timeBuf.Length() > 0 )
       
   235             {
       
   236             // start date appeded, append space
       
   237             constructTimePtr.Append( KAICal2SpaceChar );
       
   238             startTimePtr.Append( KAICal2SpaceChar );
       
   239             }
       
   240 
       
   241         if (AknLayoutUtils::LayoutMirrored()) 
       
   242             {
       
   243             //constructTimePtr.Append(KLRM);
       
   244             }
       
   245             
       
   246         constructTimePtr.Append( timeBuf );
       
   247         startTimePtr.Append( timeBuf );
       
   248         
       
   249         end.FormatL( timeBuf, aFormat );  // end time
       
   250 
       
   251 
       
   252         if( ( unadjustedStartTime != end ) )
       
   253             {
       
   254             constructTimePtr.Append( KAICal2HyphenChar );  // -
       
   255             }
       
   256         
       
   257         // Start new RLE
       
   258         if( AknLayoutUtils::LayoutMirrored() )
       
   259             {
       
   260             //constructTimePtr.Append(KRLM);
       
   261             //constructTimePtr.Append(KRLE);
       
   262             }
       
   263         else
       
   264             {
       
   265             //constructTimePtr.Append(KLRM);
       
   266             //constructTimePtr.Append(KLRE);
       
   267             }
       
   268         TBool endDateAppended = EFalse;
       
   269         if( ( ( iOwner.Type() == EPluginItemOlderOnGoingEvent ||
       
   270                 iOwner.Type() == EPluginItemOnGoingEvent ||
       
   271                 ( iOwner.Type() == EPluginItemMeeting && iOwner.IsToday() ) ||
       
   272                 iOwner.Type() == EPluginItemUpcomingMeeting ) &&
       
   273             !iOwner.IsEndTimeToday() )/* && !iOwner.DateNeeded()*/ && iEndDate )
       
   274             {
       
   275             endDateAppended = ETrue;
       
   276             constructTimePtr.Append( iEndDate->Des() );  // add end date
       
   277                if( !iOwner.DateNeeded() )
       
   278                 {
       
   279                 endTimePtr.Append( iEndDate->Des() );
       
   280                 }
       
   281             }
       
   282 
       
   283         TBool appendEndTime = EFalse;
       
   284 
       
   285         // The following code may be  abit confusing. But so is the spec about this matter.        
       
   286         if( iAppendEndTimeToOngoingEvents )
       
   287             {
       
   288             if( !iOwner.IsFutureEvent() )
       
   289                 {
       
   290                 if( ( iOwner.Type() == EPluginItemOlderOnGoingEvent && iOwner.IsEndTimeToday() ) ||
       
   291                     ( iOwner.Type() == EPluginItemOnGoingEvent && iOwner.IsEndTimeToday()  ) )
       
   292                     {
       
   293                     appendEndTime = ETrue;
       
   294                     }
       
   295                 }
       
   296            }
       
   297        if( iOwner.IsEndTimeToday() )
       
   298             {
       
   299             if( !iOwner.IsFutureEvent() || iOwner.IsToday() )
       
   300                 {
       
   301                 appendEndTime = ETrue;
       
   302                 }
       
   303             }
       
   304 
       
   305         if( ( iOwner.Type() == EPluginItemMeeting || 
       
   306               iOwner.Type() == EPluginItemUpcomingMeeting ) && iOwner.IsEndTimeToday() )
       
   307             {
       
   308             appendEndTime = ETrue;
       
   309             }
       
   310 
       
   311         if( unadjustedStartTime == end )
       
   312             {
       
   313             appendEndTime = EFalse;
       
   314             }
       
   315 
       
   316         if( appendEndTime )
       
   317             {
       
   318             if( endDateAppended )
       
   319                 {
       
   320                 // Append space char
       
   321                 constructTimePtr.Append( KAICal2SpaceChar );
       
   322                 }
       
   323             constructTimePtr.Append( timeBuf );  // add end time
       
   324             endTimePtr.Append( timeBuf );
       
   325             }
       
   326         }
       
   327 
       
   328     // End of LR or RL embeddings
       
   329     //constructTimePtr.Append(KPDF);
       
   330         
       
   331     if( iOwner.DateNeeded() || iOwner.TimeNeeded() )
       
   332         {
       
   333         AknTextUtils::LanguageSpecificNumberConversion( constructTimePtr );            
       
   334         AknTextUtils::LanguageSpecificNumberConversion( startTimePtr );            
       
   335         AknTextUtils::LanguageSpecificNumberConversion( endTimePtr );
       
   336         }
       
   337     }
       
   338 
       
   339 void CAiCalendarPlugin2EventStrings::ExtractSubjectAndLocationL(
       
   340                                     const CCalInstance& aCalInstance )
       
   341     {
       
   342     // SUBJECT STRING
       
   343     iSubject = ExtractSubjectL( aCalInstance );
       
   344 
       
   345     // LOCATION STRING
       
   346     iLocation = ExtractLocationL( aCalInstance );
       
   347     TInt bufLength = iSubject->Length();
       
   348 
       
   349     if( User::Language() == ELangArabic )
       
   350         {
       
   351         bufLength += KAICal2ArabicSummaryLocationSeparator().Length();
       
   352         }
       
   353     else
       
   354         {
       
   355         bufLength += KAICal2WesternSummaryLocationSeparator().Length();
       
   356         }
       
   357 
       
   358     bufLength += iLocation->Length() + ( KAICal2MaxItemSize * KAknBidiExtraSpacePerLine );
       
   359 
       
   360     if( !iOwner.IsToday() &&
       
   361         ( ( iOwner.Type() == EPluginItemToDo ) ||
       
   362           ( iOwner.Type() == EPluginItemDayNote ) ||
       
   363           ( iOwner.Type() == EPluginItemAnniv ) ) )
       
   364         {
       
   365         // Add extra space for not today nontimed events
       
   366         bufLength += CombinedTimeString().Length() + KAICal2LenSpaceChar;
       
   367         }
       
   368     else if( ( iOwner.Type() == EPluginItemMeeting ||
       
   369           iOwner.Type() >= EPluginItemUpcomingMeeting ) &&
       
   370         !iUseAlternatePublish )
       
   371         {
       
   372         // Multiline cale
       
   373         bufLength += CombinedTimeString().Length() + KAICal2LenSpaceChar;
       
   374         }
       
   375 
       
   376     // COMBINE TEXT
       
   377     iSubjectLocationConstruct = HBufC::NewL( bufLength );
       
   378     TPtr textStrPtr = iSubjectLocationConstruct->Des();
       
   379 
       
   380     if( !iOwner.IsToday() &&
       
   381         ( ( iOwner.Type() == EPluginItemToDo ) ||
       
   382           ( iOwner.Type() == EPluginItemDayNote ) ||
       
   383           ( iOwner.Type() == EPluginItemAnniv ) ) )
       
   384         {
       
   385         textStrPtr.Append( CombinedTimeString() );
       
   386         textStrPtr.Append( KAICal2SpaceChar );
       
   387         delete iTimeConstruct;
       
   388         iTimeConstruct = NULL;
       
   389         }
       
   390     else if( ( iOwner.Type() == EPluginItemMeeting ||
       
   391           iOwner.Type() >= EPluginItemUpcomingMeeting ) &&
       
   392         !iUseAlternatePublish )
       
   393         {
       
   394         // Multiline cale
       
   395         textStrPtr.Append( CombinedTimeString() );
       
   396         textStrPtr.Append( KAICal2SpaceChar );
       
   397         }
       
   398 
       
   399     textStrPtr.Append( iSubject->Des() );
       
   400 
       
   401     if( iSubject->Length() && iLocation->Length() )
       
   402         {
       
   403         // If both subject/summary and location exist, add a separator between them
       
   404         if( User::Language() == ELangArabic )
       
   405             {
       
   406             textStrPtr.Append( KAICal2ArabicSummaryLocationSeparator );
       
   407             }
       
   408         else
       
   409             {
       
   410             textStrPtr.Append( KAICal2WesternSummaryLocationSeparator );
       
   411             }
       
   412         }
       
   413 
       
   414     // After the subject (and separator) append the location
       
   415     textStrPtr.Append( iLocation->Des() );
       
   416     }
       
   417     
       
   418 HBufC* CAiCalendarPlugin2EventStrings::ExtractSubjectL( const CCalInstance& aCalInstance )
       
   419     {
       
   420     const CCalEntry& entry = aCalInstance.Entry();
       
   421 
       
   422     HBufC* subject = NULL;
       
   423     if( entry.SummaryL().Length() != 0 )
       
   424         {
       
   425         subject = entry.SummaryL().AllocL();
       
   426         }
       
   427     else
       
   428         {
       
   429         subject = StringLoader::LoadL( R_CALEN_QTN_CALE_NO_SUBJECT );
       
   430         }
       
   431 
       
   432     TPtr buf = subject->Des();
       
   433     AknTextUtils::ReplaceCharacters( buf, KAICal2ReplaceWhitespaceChars, TChar(' ') );
       
   434 
       
   435     // remove all leading and trailing spaces
       
   436     buf.TrimAll();
       
   437 
       
   438     return subject;
       
   439     }
       
   440 
       
   441 HBufC* CAiCalendarPlugin2EventStrings::ExtractLocationL( const CCalInstance& aCalInstance )
       
   442     {
       
   443     const CCalEntry& entry = aCalInstance.Entry();
       
   444 
       
   445     HBufC* location = entry.LocationL().AllocL();
       
   446     TPtr buf = location->Des();
       
   447     AknTextUtils::ReplaceCharacters( buf, KAICal2ReplaceWhitespaceChars, TChar(' ') );
       
   448 
       
   449     // remove all leading and trailing spaces
       
   450     buf.TrimAll();
       
   451 
       
   452     return location;
       
   453     }
       
   454     
       
   455 void CAiCalendarPlugin2EventStrings::MakeAlternateStringsL()
       
   456     {
       
   457     // Rearrange strings
       
   458     if( iOwner.Type() == EPluginItemUpcomingMeeting ||
       
   459         iOwner.Type() == EPluginItemOnGoingEvent ||
       
   460         ( iOwner.Type() == EPluginItemMeeting &&
       
   461           iOwner.IsToday() ) )
       
   462         {
       
   463         if( iLocation->Length() ) // location defined
       
   464             {
       
   465             // Multiline cale
       
   466             HBufC* newS = HBufC::NewL( iTimeConstruct->Length() + iSubjectLocationConstruct->Length() + KAICal2SpaceChar().Length() );
       
   467             newS->Des().Append( *iTimeConstruct );
       
   468             newS->Des().Append( KAICal2SpaceChar );
       
   469             newS->Des().Append( *iSubjectLocationConstruct );
       
   470             
       
   471             delete iSubjectLocationConstruct;
       
   472             iSubjectLocationConstruct = newS;
       
   473             }
       
   474         else // location NOT defined
       
   475             {
       
   476             // Append subject to time construct
       
   477             iTimeConstruct = iTimeConstruct->ReAllocL(
       
   478                         iTimeConstruct->Length() +
       
   479                         KAICal2SpaceChar().Length() +
       
   480                         iSubject->Length() );
       
   481             iTimeConstruct->Des().Append( KAICal2SpaceChar );
       
   482             iTimeConstruct->Des().Append( *iSubject );
       
   483             
       
   484             // Clean S&L construct
       
   485             delete iSubjectLocationConstruct;
       
   486             iSubjectLocationConstruct = NULL;
       
   487             }
       
   488         }
       
   489     else if( iOwner.Type() == EPluginItemOlderOnGoingEvent ||
       
   490              ( iOwner.Type() == EPluginItemMeeting &&
       
   491                !iOwner.IsToday() ) )
       
   492         {
       
   493         // Append S&L to time construct
       
   494         iTimeConstruct = iTimeConstruct->ReAllocL(
       
   495                     iTimeConstruct->Length() +
       
   496                     KAICal2SpaceChar().Length() +
       
   497                     iSubjectLocationConstruct->Length() );
       
   498         iTimeConstruct->Des().Append( KAICal2SpaceChar );
       
   499         iTimeConstruct->Des().Append( *iSubjectLocationConstruct );
       
   500         
       
   501         // Clean S&L construct
       
   502         delete iSubjectLocationConstruct;
       
   503         iSubjectLocationConstruct = NULL;
       
   504         }
       
   505     }
       
   506 
       
   507 const TDesC& CAiCalendarPlugin2EventStrings::CombinedTimeString()
       
   508     {
       
   509     return ReturnProperReference( iTimeConstruct );
       
   510     }
       
   511         
       
   512 const TDesC& CAiCalendarPlugin2EventStrings::StartTimeString()
       
   513     {
       
   514     return ReturnProperReference( iStartTime );
       
   515     }
       
   516 
       
   517 const TDesC& CAiCalendarPlugin2EventStrings::EndTimeString()
       
   518     {
       
   519     return ReturnProperReference( iEndTime );
       
   520     }
       
   521     
       
   522 const TDesC& CAiCalendarPlugin2EventStrings::CombinedSubjectLocationString()
       
   523     {
       
   524     return ReturnProperReference( iSubjectLocationConstruct );
       
   525     }
       
   526         
       
   527 const TDesC& CAiCalendarPlugin2EventStrings::SubjectString()
       
   528     {
       
   529     return ReturnProperReference( iSubject );
       
   530     }
       
   531 
       
   532 const TDesC& CAiCalendarPlugin2EventStrings::LocationString()
       
   533     {
       
   534     return ReturnProperReference( iLocation );
       
   535     }
       
   536     
       
   537