meetingrequest/mrgui/mrfieldbuilderpluginextension/src/cesmrconflictpopup.cpp
branchRCL_3
changeset 64 3533d4323edc
child 80 726fba06891a
equal deleted inserted replaced
63:d189ee25cf9d 64:3533d4323edc
       
     1 /*
       
     2 * Copyright (c) 2009 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:  ESMR Conflict popup implementation
       
    15 *
       
    16 */
       
    17 #include "cesmrconflictpopup.h"
       
    18 #include "mesmrcalentry.h"
       
    19 #include "mesmrmeetingrequestentry.h"
       
    20 
       
    21 #include <AknInfoPopupNoteController.h>
       
    22 #include <StringLoader.h>
       
    23 #include <eikenv.h>
       
    24 #include <esmrgui.rsg>
       
    25 #include <avkon.rsg>
       
    26 #include <ct/rcpointerarray.h>
       
    27 #include <AknUtils.h>
       
    28 #include <aknlayoutscalable_avkon.cdl.h>
       
    29 #include <layoutmetadata.cdl.h>
       
    30 
       
    31 #include "emailtrace.h"
       
    32 
       
    33 // Unnamed namespace for local definitions
       
    34 namespace{
       
    35 
       
    36 const TInt KTimeDelayBeforeShow(0);  // 0 Seconds
       
    37 const TInt KTimeForView(5000);          // 5 Seconds
       
    38 const TInt KTimeStringLength(20);
       
    39 const TInt KArrayGranularity( 4 );
       
    40 
       
    41 const TInt KPortraitWindowVariety( 4 );
       
    42 const TInt KLandscapeWindowVariety( 7 );
       
    43 const TInt KTextLineVariety( 5 );
       
    44 
       
    45 const TInt KNumTitleLines( 1 );
       
    46 const TInt KNumLocationLines( 2 );
       
    47 
       
    48 /**
       
    49  * Clips given text and allocates new buffer if needed.
       
    50  * @param aSource text to clip
       
    51  * @param aNumLines number of popup note lines available for visual text.
       
    52  * @return new buffer or NULL if aSource must not be clipped
       
    53  */
       
    54 
       
    55 HBufC* ClipTextL( const TDesC& aSource, TInt aNumLines )
       
    56     {
       
    57     TRect mainPane;
       
    58     AknLayoutUtils::LayoutMetricsRect(
       
    59                 AknLayoutUtils::EMainPane,
       
    60                 mainPane );
       
    61 
       
    62     // Get the correct popup window text line layout
       
    63     TInt windowVariety( KPortraitWindowVariety );
       
    64     if ( Layout_Meta_Data::IsLandscapeOrientation() )
       
    65         {
       
    66         windowVariety = KLandscapeWindowVariety;
       
    67         }
       
    68 
       
    69     TAknWindowComponentLayout popupNoteWindow =
       
    70             AknLayoutScalable_Avkon::popup_preview_text_window( windowVariety );
       
    71     TAknLayoutRect popupNoteRect;
       
    72     popupNoteRect.LayoutRect( mainPane, popupNoteWindow );
       
    73 
       
    74     TAknTextComponentLayout popupNoteTextLine =
       
    75             AknLayoutScalable_Avkon::popup_preview_text_window_t3( KTextLineVariety );
       
    76     TAknLayoutText textLayout;
       
    77     textLayout.LayoutText( popupNoteRect.Rect(), popupNoteTextLine );
       
    78 
       
    79     TInt lineWidth( textLayout.TextRect().Width() );
       
    80     const CFont* font = textLayout.Font();
       
    81 
       
    82     HBufC* text = NULL;
       
    83 
       
    84     if ( font->TextWidthInPixels( aSource ) > lineWidth )
       
    85         {
       
    86         // Text must be clipped to fit
       
    87         // Allocate result buffer and reserve space for line feeds
       
    88         text = HBufC::NewLC(
       
    89                 aSource.Length() + aNumLines );
       
    90 
       
    91         CArrayFix<TInt>* lineWidthArray =
       
    92                 new( ELeave ) CArrayFixFlat<TInt>( aNumLines );
       
    93         CleanupStack::PushL( lineWidthArray );
       
    94         for ( TInt i = 0; i < aNumLines; ++i )
       
    95             {
       
    96             lineWidthArray->AppendL( lineWidth );
       
    97             }
       
    98 
       
    99         CPtrC16Array* strings = new( ELeave ) CPtrC16Array( aNumLines );
       
   100         CleanupStack::PushL( strings );
       
   101         TPtr des( text->Des() );
       
   102 
       
   103         // Wrap string
       
   104         AknTextUtils::WrapToStringAndClipL(
       
   105                 aSource,
       
   106                 *lineWidthArray,
       
   107                 *font,
       
   108                 des );
       
   109 
       
   110         // Trim trailing line feeds
       
   111         des.TrimRight();
       
   112 
       
   113         CleanupStack::PopAndDestroy( 2, lineWidthArray );
       
   114         CleanupStack::Pop( text );
       
   115         }
       
   116 
       
   117     return text;
       
   118     }
       
   119 
       
   120 
       
   121 }//namespace
       
   122 
       
   123 // ======== MEMBER FUNCTIONS ========
       
   124 
       
   125 // ---------------------------------------------------------------------------
       
   126 // CESMRConflictPopup::NewL
       
   127 // ---------------------------------------------------------------------------
       
   128 //
       
   129 CESMRConflictPopup* CESMRConflictPopup::NewL( MESMRCalEntry& aEntry)
       
   130     {
       
   131     FUNC_LOG;
       
   132     CESMRConflictPopup* self = new (ELeave) CESMRConflictPopup();
       
   133     CleanupStack::PushL( self );
       
   134     self->ConstructL(aEntry);
       
   135     CleanupStack::Pop( self );
       
   136     return self;
       
   137     }
       
   138 
       
   139 // ---------------------------------------------------------------------------
       
   140 // CESMRConflictPopup::CESMRConflictPopup
       
   141 // ---------------------------------------------------------------------------
       
   142 //
       
   143 CESMRConflictPopup::CESMRConflictPopup()
       
   144     {
       
   145     FUNC_LOG;
       
   146     //do nothing
       
   147     }
       
   148 
       
   149 // ---------------------------------------------------------------------------
       
   150 // CESMRConflictPopup::~CESMRConflictPopup
       
   151 // ---------------------------------------------------------------------------
       
   152 //
       
   153 CESMRConflictPopup::~CESMRConflictPopup()
       
   154     {
       
   155     FUNC_LOG;
       
   156     delete iNote;
       
   157     }
       
   158 
       
   159 // ---------------------------------------------------------------------------
       
   160 // CESMRConflictPopup::ConstructL
       
   161 // ---------------------------------------------------------------------------
       
   162 //
       
   163 void CESMRConflictPopup::ConstructL(MESMRCalEntry& aEntry)
       
   164     {
       
   165     FUNC_LOG;
       
   166     if ( MESMRCalEntry::EESMRCalEntryMeetingRequest == aEntry.Type() )
       
   167         {
       
   168         iEntry = static_cast<MESMRMeetingRequestEntry*>(&aEntry);
       
   169         }
       
   170     else
       
   171         {
       
   172         User::Leave( KErrNotSupported );
       
   173         }
       
   174 
       
   175     iNote = CAknInfoPopupNoteController::NewL();
       
   176 
       
   177     InitializeL();
       
   178 
       
   179     }
       
   180 
       
   181 // ---------------------------------------------------------------------------
       
   182 // CESMRConflictPopup::PrepareDisplayStringL
       
   183 // ---------------------------------------------------------------------------
       
   184 //
       
   185 void CESMRConflictPopup::PrepareDisplayStringL()
       
   186     {
       
   187     FUNC_LOG;
       
   188     RCPointerArray<CCalEntry> entryArray;
       
   189     CleanupClosePushL( entryArray );
       
   190 
       
   191     TInt ret = iEntry->FetchConflictingEntriesL( entryArray );
       
   192     if( ret == KErrNotFound )
       
   193         {
       
   194         User::Leave( KErrNotFound );
       
   195         }
       
   196 
       
   197     // Pointer descriptor for R_QTN_MEET_REQ_CONFLICT_UNNAMED
       
   198     TPtrC unnamedTitle( KNullDesC );
       
   199 
       
   200     // Actual title to shown in popup
       
   201     TPtrC meetingTitle( KNullDesC );
       
   202 
       
   203     // Location to show in popup
       
   204     TPtrC meetingLocation( KNullDesC );
       
   205 
       
   206     TTime startTime;
       
   207     TTime endTime;
       
   208 
       
   209     CCoeEnv* env = CCoeEnv::Static();
       
   210 
       
   211     if ( entryArray.Count() > 0 )
       
   212         {// there is atleast one entry
       
   213         // get the first conflicting entry and set the string for display
       
   214         meetingTitle.Set( entryArray[ 0 ]->SummaryL() );
       
   215         meetingLocation.Set( entryArray[ 0 ]->LocationL() );
       
   216 
       
   217         if ( ( meetingLocation.Length() == 0 ) && ( meetingTitle.Length() == 0 ) )
       
   218         	{
       
   219             // if no title, set unnamed text:
       
   220             HBufC* title = StringLoader::LoadLC(
       
   221                     R_QTN_MEET_REQ_CONFLICT_UNNAMED,
       
   222                     env );
       
   223             unnamedTitle.Set( *title );
       
   224             meetingTitle.Set( unnamedTitle );
       
   225             }
       
   226 
       
   227         startTime = entryArray[ 0 ]->StartTimeL().TimeLocalL();
       
   228         endTime = entryArray[ 0 ]->EndTimeL().TimeLocalL();
       
   229         }
       
   230 
       
   231     HBufC*  conflictLabel = StringLoader::LoadLC(
       
   232             R_QTN_MEET_REQ_CONFLICTS_WITH_LABEL,
       
   233             env );
       
   234 
       
   235     HBufC* timeFormatString = StringLoader::LoadLC(
       
   236             R_QTN_TIME_USUAL_WITH_ZERO,
       
   237             env );
       
   238 
       
   239     TBuf<KTimeStringLength> startBuf;
       
   240     TBuf<KTimeStringLength> endBuf;
       
   241 
       
   242     startTime.FormatL( startBuf, *timeFormatString );
       
   243     endTime.FormatL( endBuf, *timeFormatString );
       
   244 
       
   245     CPtrC16Array* strings = new( ELeave ) CPtrC16Array( KArrayGranularity );
       
   246     CleanupStack::PushL( strings );
       
   247     strings->AppendL( startBuf ); //start time string
       
   248     strings->AppendL( endBuf ); //end time string
       
   249 
       
   250     HBufC* finalTimeBuf =
       
   251         StringLoader::LoadLC(
       
   252                 R_QTN_MEET_REQ_TIME_SEPARATOR,
       
   253                 *strings,
       
   254                 env );
       
   255 
       
   256     if ( meetingLocation.Length() > 0 )
       
   257         {
       
   258         // format Meeting location
       
   259         HBufC* formatText = StringLoader::LoadLC(
       
   260                 R_MEET_REQ_CONFLICT_LOCATION_FORMAT,
       
   261                 meetingLocation,
       
   262                 env );
       
   263         meetingLocation.Set( *formatText );
       
   264         }
       
   265 
       
   266     // Format final display string
       
   267     strings->Reset();
       
   268     strings->AppendL( *conflictLabel );
       
   269     strings->AppendL( *finalTimeBuf );
       
   270 
       
   271     HBufC* titleBuf = NULL;
       
   272     HBufC* locationBuf = NULL;
       
   273 
       
   274     if ( meetingTitle.Length() > 0 )
       
   275         {
       
   276         // Prepare title
       
   277         titleBuf = ClipTextL( meetingTitle, KNumTitleLines );
       
   278         if ( titleBuf )
       
   279             {
       
   280             CleanupStack::PushL( titleBuf );
       
   281             meetingTitle.Set( *titleBuf );
       
   282             }
       
   283         strings->AppendL( meetingTitle );
       
   284 
       
   285         // Prepare location
       
   286         locationBuf = ClipTextL( meetingLocation, KNumLocationLines );
       
   287         if ( locationBuf )
       
   288             {
       
   289             CleanupStack::PushL( locationBuf );
       
   290             meetingLocation.Set( *locationBuf );
       
   291             }
       
   292         strings->AppendL( meetingLocation );
       
   293         }
       
   294     else
       
   295         {
       
   296         // Prepare location
       
   297         locationBuf = ClipTextL(
       
   298                 meetingLocation,
       
   299                 KNumTitleLines + KNumLocationLines );
       
   300         if ( locationBuf )
       
   301             {
       
   302             CleanupStack::PushL( locationBuf );
       
   303             meetingLocation.Set( *locationBuf );
       
   304             }
       
   305         strings->AppendL( meetingLocation );
       
   306         strings->AppendL( KNullDesC() );
       
   307         }
       
   308 
       
   309     HBufC* displayString = StringLoader::LoadLC(
       
   310             R_MEET_REQ_CONFLICT_TEXT_FORMAT,
       
   311             *strings,
       
   312             env );
       
   313 
       
   314     // Trim trailing white space
       
   315     displayString->Des().TrimRight();
       
   316 
       
   317     // Set display string to popup note
       
   318     iNote->SetTextL( *displayString );
       
   319 
       
   320     // Clean allocated buffers
       
   321     CleanupStack::PopAndDestroy( displayString );
       
   322     if ( locationBuf )
       
   323         {
       
   324         CleanupStack::PopAndDestroy( locationBuf );
       
   325         }
       
   326     if ( titleBuf )
       
   327         {
       
   328         CleanupStack::PopAndDestroy( titleBuf );
       
   329         }
       
   330     if ( meetingLocation.Length() > 0 )
       
   331         {
       
   332         CleanupStack::PopAndDestroy(); // R_MEET_REQ_CONFLICT_LOCATION_FORMAT
       
   333         }
       
   334     CleanupStack::PopAndDestroy( finalTimeBuf );
       
   335     CleanupStack::PopAndDestroy( strings );
       
   336     CleanupStack::PopAndDestroy( timeFormatString );
       
   337     CleanupStack::PopAndDestroy( conflictLabel );
       
   338     if ( unnamedTitle.Length() > 0 )
       
   339         {
       
   340         CleanupStack::PopAndDestroy(); // R_QTN_MEET_REQ_CONFLICT_UNNAMED
       
   341         }
       
   342     CleanupStack::PopAndDestroy( &entryArray );
       
   343     }
       
   344 
       
   345 
       
   346 // ---------------------------------------------------------------------------
       
   347 // CESMRConflictPopup::ShowPopup
       
   348 // ---------------------------------------------------------------------------
       
   349 //
       
   350 void CESMRConflictPopup::ShowPopup()
       
   351     {
       
   352     FUNC_LOG;
       
   353         TRAPD( error, PrepareDisplayStringL());
       
   354         if ( error != KErrNone )
       
   355             {
       
   356             CEikonEnv::Static()-> // codescanner::eikonenvstatic
       
   357                 HandleError(error);
       
   358             }
       
   359         iNote->ShowInfoPopupNote();
       
   360     }
       
   361 
       
   362 
       
   363 // ---------------------------------------------------------------------------
       
   364 // CESMRConflictPopup::InitializeL
       
   365 // ---------------------------------------------------------------------------
       
   366 //
       
   367 void CESMRConflictPopup::InitializeL()
       
   368     {
       
   369     FUNC_LOG;
       
   370     iNote->SetTimeDelayBeforeShow(KTimeDelayBeforeShow); // 2 Seconds
       
   371     iNote->SetTimePopupInView(KTimeForView); // 5 Seconds
       
   372     }
       
   373 
       
   374 // EOF
       
   375