meetingrequest/mrgui/src/cesmrconfirmationquery.cpp
branchRCL_3
changeset 12 4ce476e64c59
parent 11 0396474f30f5
child 13 8592a65ad3fb
equal deleted inserted replaced
11:0396474f30f5 12:4ce476e64c59
     1 /*
       
     2 * Copyright (c) 2002-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:  Class is responsible of showing confirmation queries
       
    15 *
       
    16 */
       
    17 
       
    18 // INCLUDE FILES
       
    19 #include "emailtrace.h"
       
    20 #include "cesmrconfirmationquery.h"
       
    21 
       
    22 //<cmail>
       
    23 #include "esmrdef.h"
       
    24 //</cmail>
       
    25 #include <AknQueryDialog.h>
       
    26 #include <bautils.h>
       
    27 #include <esmrgui.rsg>
       
    28 #include <eikenv.h>
       
    29 #include <avkon.rsg>
       
    30 #include <data_caging_path_literals.hrh>
       
    31 #include <StringLoader.h>
       
    32 #include <AknBidiTextUtils.h>//line wrapping and mirroring
       
    33 #include <aknlayoutscalable_apps.cdl.h> //xml layout data for applications
       
    34 #include <aknlayoutscalable_avkon.cdl.h> //xml layout data of avkon components
       
    35 #include "esmrhelper.h"//locateresourcefile
       
    36 
       
    37 // Unnamed namespace for local definitions
       
    38 namespace {
       
    39 
       
    40 #ifdef _DEBUG
       
    41 
       
    42 // Definition for panic text
       
    43 _LIT( KESMRConfirmationQueryPanicTxt, "ESMRConfirmationQueryPanic" );
       
    44 
       
    45 /** Panic code enumaration */
       
    46 enum TESMRConfirmationQueryPanic
       
    47     {
       
    48     EESMRInvalidIdentifier = 0  // Invalid identifier
       
    49     };
       
    50 
       
    51 void Panic( TESMRConfirmationQueryPanic aPanic )
       
    52     {
       
    53     User::Panic( KESMRConfirmationQueryPanicTxt, aPanic );
       
    54     }
       
    55 
       
    56 #endif
       
    57 
       
    58 _LIT(KResourceFileName,"esmrgui.rsc");
       
    59 
       
    60 const TInt KVariantIndex(2); //a LAF variant value required for pop up window
       
    61 const TInt KRequiredLinesPlus(2); //minimum lines needed for aknbiditextutils API array set up
       
    62 const TInt KActualLine(0); //minimum lines needed for aknbiditextutils API array set up
       
    63 const TInt KDummyLineForcedByAPI(1); //minimum lines needed for aknbiditextutils API array set up
       
    64 } // namespace
       
    65 
       
    66 // ======== MEMBER FUNCTIONS ========
       
    67 
       
    68 // -----------------------------------------------------------------------------
       
    69 // CESMRConfirmationQuery::CESMRConfirmationQuery
       
    70 // C++ default constructor can NOT contain any code, that
       
    71 // might leave.
       
    72 // -----------------------------------------------------------------------------
       
    73 //
       
    74 CESMRConfirmationQuery::CESMRConfirmationQuery(
       
    75             TESMRConfirmationQueryType aType) :
       
    76     iType(aType)
       
    77     {
       
    78     FUNC_LOG;
       
    79     //do nothing
       
    80     }
       
    81 
       
    82 // -----------------------------------------------------------------------------
       
    83 // CESMRConfirmationQuery::~CESMRConfirmationQuery
       
    84 // -----------------------------------------------------------------------------
       
    85 //
       
    86 CESMRConfirmationQuery::~CESMRConfirmationQuery()
       
    87     {
       
    88     FUNC_LOG;
       
    89     iEnv->DeleteResourceFile(iResourceOffset);
       
    90     }
       
    91 
       
    92 // -----------------------------------------------------------------------------
       
    93 // CESMRConfirmationQuery::ConstructL
       
    94 // -----------------------------------------------------------------------------
       
    95 //
       
    96 void CESMRConfirmationQuery::ConstructL()
       
    97     {
       
    98     FUNC_LOG;
       
    99     TFileName filename;
       
   100 
       
   101     //cache the Eikon pointer, as Static() is slow
       
   102     iEnv = CEikonEnv::Static(); // codescanner::eikonenvstatic
       
   103 
       
   104     ESMRHelper::LocateResourceFile(
       
   105             KResourceFileName,
       
   106             KDC_RESOURCE_FILES_DIR,
       
   107             filename,
       
   108             &iEnv->FsSession() );
       
   109 
       
   110     //for localization
       
   111     BaflUtils::NearestLanguageFile(iEnv->FsSession(),filename);
       
   112     iResourceOffset = iEnv->AddResourceFileL(filename);
       
   113     }
       
   114 
       
   115 // -----------------------------------------------------------------------------
       
   116 // CESMRConfirmationQuery::ExecuteLD
       
   117 // -----------------------------------------------------------------------------
       
   118 //
       
   119 TBool CESMRConfirmationQuery::ExecuteLD()
       
   120     {
       
   121     FUNC_LOG;
       
   122     HBufC* noteText = NULL;
       
   123     switch ( iType )
       
   124         {
       
   125         case EESMRDeleteMR:
       
   126             {
       
   127             noteText =
       
   128                 iEnv->AllocReadResourceAsDes16LC(
       
   129                         R_QTN_MEET_REQ_DELETE_QUERY);
       
   130             break;
       
   131             }
       
   132         case EESMRSendCancellationInfoToParticipants:
       
   133             {
       
   134             noteText =
       
   135                 iEnv->AllocReadResourceAsDes16LC(
       
   136                         R_QTN_MEET_REQ_SEND_CANCELLATION_QUERY);
       
   137             break;
       
   138             }
       
   139         case EESMRRemoveAppointment:
       
   140             {
       
   141             noteText =
       
   142                 iEnv->AllocReadResourceAsDes16LC(
       
   143                         R_QTN_MEET_REQ_REMOVE_APPOINTMENT_QUERY);
       
   144             break;
       
   145             }
       
   146         case EESMRSaveChanges:
       
   147             {
       
   148             noteText =
       
   149                 iEnv->AllocReadResourceAsDes16LC(
       
   150                         R_QTN_FORM_QUEST_SAVE_CHANGES);
       
   151             break;
       
   152             }
       
   153         case EESMRDeleteEntry:
       
   154             {
       
   155             noteText =
       
   156                 iEnv->AllocReadResourceAsDes16LC(
       
   157                         R_QTN_MEET_REQ_DELETE_QUERY);
       
   158             break;
       
   159             }
       
   160         case EESMRSendDecline:
       
   161             {
       
   162             noteText =
       
   163                 iEnv->AllocReadResourceAsDes16LC(
       
   164                         R_QTN_MEET_REQ_DECLINE_QUERY );
       
   165             }
       
   166             break;
       
   167         case EESMRSaveAnnivChangedStartDay:
       
   168             {
       
   169             noteText =
       
   170                 iEnv->AllocReadResourceAsDes16LC(
       
   171                         R_QTN_MEET_REQ_QUEST_CHANGE_START_DAY );
       
   172             }
       
   173             break;
       
   174         case EESMRAttachments:
       
   175             {
       
   176             noteText =
       
   177                 iEnv->AllocReadResourceAsDes16LC(
       
   178                         R_QTN_MEET_REQ_NOTE_ATTACHMENTS );
       
   179             }
       
   180             break;
       
   181         case EESMRCancelDownloadingAttachment:
       
   182             {
       
   183             noteText =
       
   184                 iEnv->AllocReadResourceAsDes16LC(
       
   185                         R_QTN_MEET_REQ_VIEWER_CANCEL_DOWNLOAD_QUERY );
       
   186             }
       
   187             break;
       
   188         case EESMRCancelDownloadingAllAttachments:
       
   189             {
       
   190             noteText =
       
   191                 iEnv->AllocReadResourceAsDes16LC(
       
   192                         R_QTN_MEET_REQ_VIEWER_CANCEL_DOWNLOADS_QUERY );
       
   193             }
       
   194             break;
       
   195         case EESMRSaveMeetingChangedStartDay:
       
   196             {
       
   197             noteText =
       
   198                 iEnv->AllocReadResourceAsDes16LC(
       
   199                         R_QTN_MEET_REQ_QUEST_CHANGE_START_DAY );
       
   200             }
       
   201             break;
       
   202         case EESMRAssignUpdatedLocation:
       
   203             {
       
   204             noteText =
       
   205                 iEnv->AllocReadResourceAsDes16LC(
       
   206                         R_QTN_MEET_REQ_ASSIGN_UPDATED_LOCATION );
       
   207             }
       
   208             break;
       
   209         default:
       
   210             {
       
   211             #ifdef _DEBUG
       
   212             // Invalid identifier --> panic
       
   213             Panic( EESMRInvalidIdentifier );
       
   214             #endif
       
   215             }
       
   216             break;
       
   217         }
       
   218 
       
   219     TBool response(EFalse);
       
   220     if ( noteText )
       
   221     	{
       
   222 		CAknQueryDialog* dlg = CAknQueryDialog::NewL();
       
   223 		if( dlg->ExecuteLD(R_MR_CONFIRMATION_QUERY, *noteText) )
       
   224 			{
       
   225 			response = ETrue;
       
   226 			}
       
   227 		CleanupStack::PopAndDestroy(noteText);
       
   228     	}
       
   229 
       
   230     delete this;
       
   231     return response;
       
   232     }
       
   233 
       
   234 // -----------------------------------------------------------------------------
       
   235 // CESMRConfirmationQuery::ExecuteL
       
   236 // -----------------------------------------------------------------------------
       
   237 //
       
   238 EXPORT_C TBool CESMRConfirmationQuery::ExecuteL( TESMRConfirmationQueryType aType)
       
   239     {
       
   240     FUNC_LOG;
       
   241     CESMRConfirmationQuery* query = new (ELeave) CESMRConfirmationQuery(aType);
       
   242     CleanupStack::PushL( query );
       
   243     query->ConstructL( );
       
   244     TBool ret = query->ExecuteLD();
       
   245     CleanupStack::Pop( query );
       
   246     return ret;
       
   247     }
       
   248 
       
   249 // -----------------------------------------------------------------------------
       
   250 // CESMRConfirmationQuery::ExecuteL
       
   251 // -----------------------------------------------------------------------------
       
   252 //
       
   253 TBool CESMRConfirmationQuery::ExecuteL( const TDesC& aLocation )
       
   254     {
       
   255     FUNC_LOG;
       
   256     CESMRConfirmationQuery* query = new (ELeave) CESMRConfirmationQuery(EESMRDeleteMR);
       
   257     CleanupStack::PushL( query );
       
   258     query->ConstructL( );
       
   259 
       
   260     HBufC* location = NULL;
       
   261     
       
   262     if ( aLocation.Length() > 0 )
       
   263         {
       
   264         location = query->TruncateTextToLAFNoteL( aLocation );
       
   265         CleanupDeletePushL( location );
       
   266         }
       
   267     else
       
   268         {
       
   269         // Allocate dummy buffer for query.
       
   270         location = aLocation.AllocLC();
       
   271         }
       
   272     
       
   273     HBufC* noteText = StringLoader::LoadLC( R_MEET_REQ_REPLACE_PREVIOUS_LOCATION, *location );
       
   274     
       
   275     TBool response = EFalse;
       
   276     
       
   277     CAknQueryDialog* dlg = CAknQueryDialog::NewL();
       
   278     if( dlg->ExecuteLD( R_MR_CONFIRMATION_QUERY, *noteText) )
       
   279         {
       
   280         response = ETrue;
       
   281         }
       
   282     
       
   283     CleanupStack::PopAndDestroy( noteText );
       
   284     CleanupStack::PopAndDestroy( location );    
       
   285     CleanupStack::Pop( query );
       
   286     return response;
       
   287     }
       
   288 
       
   289 // -----------------------------------------------------------------------------
       
   290 // CESMRConfirmationQuery::TruncateTextToLAFNoteL
       
   291 // -----------------------------------------------------------------------------
       
   292 //
       
   293 HBufC* CESMRConfirmationQuery::TruncateTextToLAFNoteL( const TDesC& aLocation )
       
   294     {
       
   295     FUNC_LOG;
       
   296     //wrap long string into array of individual lines
       
   297     CArrayFixFlat<TPtrC>* textLines = new(ELeave)CArrayFixFlat<TPtrC>( KRequiredLinesPlus );
       
   298     CleanupStack::PushL( textLines );
       
   299     
       
   300     //layout stuff to fetch list font and list line width
       
   301     TAknLayoutText fontType;
       
   302 
       
   303     TSize main_pane_Size;
       
   304     AknLayoutUtils::LayoutMetricsSize( AknLayoutUtils::EMainPane, main_pane_Size );
       
   305     TRect main_pane( main_pane_Size );
       
   306 
       
   307     fontType.LayoutText( main_pane, AknLayoutScalable_Avkon::popup_note_window_t4( KVariantIndex ).LayoutLine() );
       
   308 
       
   309     TInt lineWidth = fontType.TextRect().Width();
       
   310  
       
   311     //extra bidi space for the two lines. second line is not actually used in the query but is required by the API
       
   312     HBufC* locationText = HBufC::NewLC( aLocation.Length() + KAknBidiExtraSpacePerLine + KAknBidiExtraSpacePerLine);
       
   313     TPtr locationTextPtr = locationText->Des();
       
   314     locationTextPtr.Append(aLocation);
       
   315     
       
   316     // First wrap, then do formatting.
       
   317     CArrayFixFlat<TInt>* lineWidths = new( ELeave )CArrayFixFlat<TInt>( KRequiredLinesPlus );
       
   318     CleanupStack::PushL( lineWidths );
       
   319     lineWidths->InsertL( KActualLine, lineWidth );
       
   320     lineWidths->InsertL( KDummyLineForcedByAPI, lineWidth );
       
   321     
       
   322     TBool useEllipsis(ETrue);
       
   323 
       
   324     // measure, wrap and truncate location item.
       
   325     AknBidiTextUtils::ConvertToVisualAndWrapToArrayL(
       
   326             locationTextPtr,
       
   327             *lineWidths,
       
   328             *fontType.Font(),
       
   329             *textLines,
       
   330             useEllipsis );
       
   331     
       
   332     //place result to new created target buffer
       
   333     HBufC* target = HBufC::NewL( textLines->At(KActualLine).Length() );
       
   334     target->Des().Append(textLines->At( KActualLine ));
       
   335     
       
   336     CleanupStack::PopAndDestroy( lineWidths );
       
   337     CleanupStack::PopAndDestroy( locationText );
       
   338     CleanupStack::PopAndDestroy( textLines );
       
   339     delete this;
       
   340     return target;
       
   341     }
       
   342 
       
   343 //  End of File
       
   344