omaprovisioning/provisioning/ProvisioningBC/Src/CWPBioControl.cpp
changeset 0 b497e44ab2fc
child 27 5cc2995847ea
equal deleted inserted replaced
-1:000000000000 0:b497e44ab2fc
       
     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: 
       
    15 *     Bio control for Provisioning documents.
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 // INCLUDE FILES
       
    21 #include "CWPBioControl.h"
       
    22 
       
    23 #include <aknnotewrappers.h>
       
    24 #include <msvapi.h>
       
    25 #include <StringLoader.h>
       
    26 #include <CRichBio.h>
       
    27 #include <msgbiocontrolObserver.h>
       
    28 
       
    29 
       
    30 #include <ProvisioningBC.rsg>
       
    31 #include <bldvariant.hrh>
       
    32 #include <msvids.h>
       
    33 #include <biouids.h>
       
    34 #include <featmgr.h>
       
    35 #include <csxhelp/prov.hlp.hrh>
       
    36 #include <sysutil.h>
       
    37 #include "CWPEngine.h"
       
    38 #include "CWPAdapter.h"
       
    39 #include "MWPPhone.h"
       
    40 #include "WPPhoneFactory.h"
       
    41 #include "CWPPushMessage.h"
       
    42 #include "CWPBootstrap.h"
       
    43 #include "CWPSaver.h"
       
    44 #include "ProvisioningUIDs.h"
       
    45 #include "CWPCodeQueryDialog.h"
       
    46 #include "MWPContextManager.h"
       
    47 #include "ProvisioningDebug.h"
       
    48 #include "CWPNameValue.h"
       
    49 #include <aknmessagequerydialog.h> 
       
    50 #include "ProvisioningInternalCRKeys.h"
       
    51 // CONSTANTS
       
    52 /// Strings are loaded from this resource
       
    53 _LIT(KResourceFileName, "provisioningbc.rsc");
       
    54 /// Maximum number of items with same title before they get merged.
       
    55 const TInt KMaxDuplicates = 5;
       
    56 /// Maximum length of PIN code
       
    57 const TInt KMaxPinSize = 20;
       
    58 /// Number of retries for PIN
       
    59 // const TInt KPinRetries = 3; // Removed, because iMtmData1 data member of TMsvEntry in CWPMessage.cpp contains Max tries, default=3.
       
    60 ///NONE
       
    61 _LIT(KNone,"");
       
    62 
       
    63 // ============================ MEMBER FUNCTIONS ===============================
       
    64 
       
    65 // -----------------------------------------------------------------------------
       
    66 // Constructor.
       
    67 // -----------------------------------------------------------------------------
       
    68 //
       
    69 CWPBioControl::CWPBioControl( MMsgBioControlObserver& aObserver,
       
    70                               CMsvSession* aSession,
       
    71                               TMsvId aId,
       
    72                               TMsgBioMode aEditorOrViewerMode,
       
    73                               const RFile* aFile )
       
    74                             : CMsgBioControl( aObserver,
       
    75                                               aSession,
       
    76                                               aId,
       
    77                                               aEditorOrViewerMode,
       
    78                                               aFile )
       
    79     {
       
    80     }
       
    81 
       
    82 // -----------------------------------------------------------------------------
       
    83 // CNSmlDMSyncAppEngine::ConstructL
       
    84 // Symbian 2nd phase constructor can leave.
       
    85 // -----------------------------------------------------------------------------
       
    86 //
       
    87 void CWPBioControl::ConstructL()
       
    88     {
       
    89     FLOG( _L( "[ProvisioningBC] CWPBioControl::ConstructL:" ) );
       
    90     
       
    91     FeatureManager::InitializeLibL();
       
    92 
       
    93     if( IsEditor() ) //This control does not support editing mode.
       
    94         {
       
    95         User::Leave( KErrNotSupported );
       
    96         }
       
    97 
       
    98     LoadResourceL(KResourceFileName);
       
    99     LoadStandardBioResourceL();
       
   100 
       
   101     iEngine = CWPEngine::NewL();
       
   102     iRichBio = new(ELeave) CRichBio( ERichBioModeEditorBase );
       
   103 
       
   104     // this function leaves if not enough data exists
       
   105     RestoreMsgL();
       
   106 
       
   107     // Add items to CRichBio
       
   108     AddItemsL();
       
   109     FLOG( _L( "[ProvisioningBC] CWPBioControl::ConstructL: done" ) );
       
   110     }
       
   111 
       
   112 // -----------------------------------------------------------------------------
       
   113 // CNSmlDMSyncAppEngine::NewL
       
   114 // Two-phased constructor.
       
   115 // -----------------------------------------------------------------------------
       
   116 //
       
   117 EXPORT_C CWPBioControl* CWPBioControl::NewL( MMsgBioControlObserver& aObserver,
       
   118                                              CMsvSession* aSession,
       
   119                                              TMsvId aId,
       
   120                                              TMsgBioMode aEditorOrViewerMode,
       
   121                                              const RFile* aFile )
       
   122     {
       
   123 
       
   124     CWPBioControl* self = new( ELeave ) CWPBioControl( aObserver,
       
   125                                                        aSession,
       
   126                                                        aId,
       
   127                                                        aEditorOrViewerMode,
       
   128                                                        aFile );
       
   129     CleanupStack::PushL( self );
       
   130     self->ConstructL();
       
   131     CleanupStack::Pop();
       
   132     return self;
       
   133     }
       
   134 
       
   135 // -----------------------------------------------------------------------------
       
   136 // Destructor
       
   137 // -----------------------------------------------------------------------------
       
   138 CWPBioControl::~CWPBioControl()
       
   139     {
       
   140     delete iRichBio;
       
   141     delete iEngine;
       
   142     delete iMessage;
       
   143     FeatureManager::UnInitializeLib();
       
   144     }
       
   145 
       
   146 // ----------------------------------------------------------------------------
       
   147 // CWPBioControl::SetAndGetSizeL
       
   148 // ----------------------------------------------------------------------------
       
   149 //
       
   150 void CWPBioControl::SetAndGetSizeL( TSize& aSize )
       
   151     {
       
   152     iRichBio->SetAndGetSizeL( aSize );
       
   153     SetSizeWithoutNotification( aSize );
       
   154     }
       
   155 
       
   156 // ----------------------------------------------------------------------------
       
   157 // CWPBioControl::SetMenuCommandSetL
       
   158 // ----------------------------------------------------------------------------
       
   159 //
       
   160 void CWPBioControl::SetMenuCommandSetL( CEikMenuPane& aMenuPane )
       
   161     {
       
   162     AddMenuItemL( aMenuPane, R_MENU_SAVESETTING, ECmdSaveSettings );
       
   163     }
       
   164 
       
   165 // ----------------------------------------------------------------------------
       
   166 // CWPBioControl::CurrentLineRect
       
   167 // ----------------------------------------------------------------------------
       
   168 //
       
   169 TRect CWPBioControl::CurrentLineRect() const
       
   170     {
       
   171     return iRichBio->CurrentLineRect();
       
   172     }
       
   173 
       
   174 // ----------------------------------------------------------------------------
       
   175 // CWPBioControl::IsFocusChangePossible
       
   176 // ----------------------------------------------------------------------------
       
   177 //
       
   178 TBool CWPBioControl::IsFocusChangePossible(
       
   179                                          TMsgFocusDirection aDirection ) const
       
   180     {
       
   181     if (aDirection == EMsgFocusUp )
       
   182         {
       
   183         return iRichBio->IsCursorLocation( EMsgTop );
       
   184         }
       
   185     else
       
   186         {
       
   187         return EFalse;
       
   188         }
       
   189     }
       
   190 
       
   191 // ----------------------------------------------------------------------------
       
   192 // CWPBioControl::IsCursorLocation
       
   193 // ----------------------------------------------------------------------------
       
   194 //
       
   195 TBool CWPBioControl::IsCursorLocation( TMsgCursorLocation aLocation ) const
       
   196     {
       
   197     return iRichBio->IsCursorLocation( aLocation );
       
   198     }
       
   199 
       
   200 // ----------------------------------------------------------------------------
       
   201 // CWPBioControl::HeaderTextL
       
   202 // ----------------------------------------------------------------------------
       
   203 //
       
   204 HBufC* CWPBioControl::HeaderTextL() const
       
   205     {
       
   206     return StringLoader::LoadL( R_TITLE_PROVISIONING );
       
   207     }
       
   208 
       
   209 // ----------------------------------------------------------------------------
       
   210 // CWPBioControl::HandleBioCommandL()
       
   211 // ----------------------------------------------------------------------------
       
   212 //
       
   213 TBool CWPBioControl::HandleBioCommandL(TInt aCommand)
       
   214     {
       
   215     TBool result( EFalse );
       
   216 
       
   217     if ( aCommand == iBioControlObserver.FirstFreeCommand() + ECmdSaveSettings )
       
   218         {
       
   219         SaveSettingsL();
       
   220         result = ETrue;
       
   221         }
       
   222     return result;
       
   223     }
       
   224 
       
   225 // ----------------------------------------------------------------------------
       
   226 // CWPBioControl::OptionMenuPermissionsL
       
   227 // ----------------------------------------------------------------------------
       
   228 //
       
   229 TUint32 CWPBioControl::OptionMenuPermissionsL() const
       
   230     {
       
   231     TUint32 perm( EMsgBioDelete | EMsgBioMessInfo | EMsgBioMove | EMsgBioExit );
       
   232 
       
   233     if ( FeatureManager::FeatureSupported( KFeatureIdHelp ) )
       
   234         {
       
   235         perm |= EMsgBioHelp;
       
   236         }
       
   237     return perm;
       
   238     }
       
   239 
       
   240 // ----------------------------------------------------------------------------
       
   241 // CWPBioControl::OfferKeyEventL
       
   242 // ----------------------------------------------------------------------------
       
   243 //
       
   244 TKeyResponse CWPBioControl::OfferKeyEventL( const TKeyEvent& aKeyEvent,
       
   245                                             TEventCode aType )
       
   246     {
       
   247     return iRichBio->OfferKeyEventL( aKeyEvent, aType );
       
   248     }
       
   249 
       
   250 // ----------------------------------------------------------------------------
       
   251 // CWPBioControl::GetBioHelpContext
       
   252 // ----------------------------------------------------------------------------
       
   253 //
       
   254 void CWPBioControl::GetHelpContext( TCoeHelpContext& aContext ) const
       
   255     {   
       
   256     if ( FeatureManager::FeatureSupported( KFeatureIdHelp ) )
       
   257         {
       
   258         aContext.iContext = KPROV_HLP_PROVISIONVIEW() ;    
       
   259         aContext.iMajor = TUid::Uid( KProvisioningBCUid3 );
       
   260         }
       
   261     else
       
   262         {
       
   263         CCoeControl::GetHelpContext(aContext);
       
   264         }
       
   265     }
       
   266 
       
   267 // ----------------------------------------------------------------------------
       
   268 // CWPBioControl::CountComponentControls
       
   269 // ----------------------------------------------------------------------------
       
   270 //
       
   271 TInt CWPBioControl::CountComponentControls() const
       
   272     {
       
   273     return 1;
       
   274     }
       
   275 
       
   276 // ----------------------------------------------------------------------------
       
   277 // CWPBioControl::ComponentControl
       
   278 // ----------------------------------------------------------------------------
       
   279 //
       
   280 CCoeControl* CWPBioControl::ComponentControl( TInt /*aIndex*/ ) const
       
   281     {
       
   282     return iRichBio;
       
   283     }
       
   284 
       
   285 // ----------------------------------------------------------------------------
       
   286 // CWPBioControl::SizeChanged()
       
   287 // ----------------------------------------------------------------------------
       
   288 //
       
   289 void CWPBioControl::SizeChanged()
       
   290     {
       
   291     iRichBio->SetExtent( Position(), iRichBio->Size() );
       
   292     }
       
   293 
       
   294 // ----------------------------------------------------------------------------
       
   295 // CWPBioControl::FocusChanged
       
   296 // ----------------------------------------------------------------------------
       
   297 //
       
   298 void CWPBioControl::FocusChanged( TDrawNow aDrawNow )
       
   299     {
       
   300     iRichBio->SetFocus( IsFocused(), aDrawNow );
       
   301     }
       
   302 
       
   303 // ----------------------------------------------------------------------------
       
   304 // CWPBioControl::SetContainerWindowL
       
   305 // ----------------------------------------------------------------------------
       
   306 //
       
   307 void CWPBioControl::SetContainerWindowL( const CCoeControl& aContainer )
       
   308     {
       
   309     CCoeControl::SetContainerWindowL( aContainer );
       
   310     iRichBio->ConstructL(this);
       
   311     }
       
   312 
       
   313 // ----------------------------------------------------------------------------
       
   314 // CWPBioControl ::VirtualHeight
       
   315 // ----------------------------------------------------------------------------
       
   316 //
       
   317 TInt CWPBioControl::VirtualHeight()
       
   318     {
       
   319     return iRichBio->VirtualHeight();
       
   320     }
       
   321 
       
   322 // ----------------------------------------------------------------------------
       
   323 // CWPBioControl ::VirtualVisibleTop
       
   324 // ----------------------------------------------------------------------------
       
   325 //
       
   326 TInt CWPBioControl::VirtualVisibleTop()
       
   327     {
       
   328     return iRichBio->VirtualVisibleTop();
       
   329     }
       
   330 
       
   331 
       
   332 // ----------------------------------------------------------------------------
       
   333 // CWPBioControl ::RestoreMsgL
       
   334 // ----------------------------------------------------------------------------
       
   335 //
       
   336 void CWPBioControl::RestoreMsgL()
       
   337     {
       
   338     FLOG( _L( "[ProvisioningBC] CWPBioControl::RestoreMsgL" ) );
       
   339     
       
   340     // Load the message from Messaging Server
       
   341     CMsvEntry* entry = MsvSession().GetEntryL(iId);
       
   342     CleanupStack::PushL( entry );
       
   343     TMsvEntry tentry( entry->Entry() );
       
   344     iMessage = CWPPushMessage::NewL();
       
   345     CMsvStore* readStore = entry->ReadStoreL();
       
   346     CleanupStack::PushL( readStore );
       
   347     iMessage->RestoreL( *readStore );
       
   348     CleanupStack::PopAndDestroy(); // readStore
       
   349     FLOG( _L( "[ProvisioningBC] CWPBioControl::RestoreMsgL 1" ) );
       
   350     // Fill the engine
       
   351     TRAPD( result, iEngine->ImportDocumentL( iMessage->Body() ) );
       
   352     if( result == KErrCorrupt )
       
   353         {
       
   354         FLOG( _L( "[ProvisioningBC] CWPBioControl::RestoreMsgL KErrMsgBioMessageNotValid " ) );
       
   355         result = KErrMsgBioMessageNotValid;
       
   356         }
       
   357     FTRACE(RDebug::Print(_L("[ProvisioningBC] CWPBioControl::RestoreMsgL result (%d)"), result));
       
   358     User::LeaveIfError( result );
       
   359     
       
   360     FLOG( _L( "[ProvisioningBC] CWPBioControl::RestoreMsgL 2 " ) );
       
   361     TBool preAuthenticated( iMessage->Authenticated() );
       
   362     // If the message was not authenticated, give a warning
       
   363     AuthenticateL( *iMessage );
       
   364     FLOG( _L( "[ProvisioningBC] CWPBioControl::RestoreMsgL 3 " ) );
       
   365     if( !tentry.ReadOnly() && preAuthenticated != iMessage->Authenticated() )
       
   366         {
       
   367         // If the entry can be written to, get its edit store and save
       
   368         // authentication flag. Failing is not dangerous, as the only
       
   369         // effect is that the user has to re-enter the PIN.
       
   370         FLOG( _L( "[ProvisioningBC] CWPBioControl::RestoreMsgL 4 " ) );
       
   371         TRAPD( ignoreError, SaveMessageL() );
       
   372         if ( ignoreError ) ignoreError = 0; // prevent compiler warning	
       
   373         }
       
   374     
       
   375     FLOG( _L( "[ProvisioningBC] CWPBioControl::RestoreMsgL 5 " ) );
       
   376     iEngine->PopulateL();
       
   377     FLOG( _L( "[ProvisioningBC] CWPBioControl::RestoreMsgL 6 " ) );
       
   378     // Empty messages are not supported
       
   379     if( iEngine->ItemCount() == 0 )
       
   380         {
       
   381         FLOG( _L( "[ProvisioningBC] CWPBioControl::RestoreMsgL 7 " ) );
       
   382         User::Leave( KErrMsgBioMessageNotValid );
       
   383         }
       
   384 
       
   385     TPtrC8 orig8( iMessage->Originator() );
       
   386     HBufC* orig16 = HBufC::NewLC( orig8.Length() );
       
   387     orig16->Des().Copy( orig8 );
       
   388     FLOG( _L( "[ProvisioningBC] CWPBioControl::RestoreMsgL 8 " ) );
       
   389     if( iMessage->Authenticated() 
       
   390         && iEngine->ContextExistsL( *orig16 ) )
       
   391         {
       
   392         TUint32 context( iEngine->ContextL( *orig16 ) );
       
   393         iEngine->SetCurrentContextL( context );
       
   394         }
       
   395     else
       
   396         {
       
   397         iEngine->SetCurrentContextL( KWPMgrUidNoContext );
       
   398         }
       
   399 
       
   400     CleanupStack::PopAndDestroy(2); // orig16, entry
       
   401     FLOG( _L( "[ProvisioningBC] CWPBioControl::RestoreMsgL done" ) );
       
   402     }
       
   403 
       
   404 // ----------------------------------------------------------------------------
       
   405 // CWPBioControl ::AuthenticateL
       
   406 // ----------------------------------------------------------------------------
       
   407 //
       
   408 void CWPBioControl::AuthenticateL( CWPPushMessage& aMessage )
       
   409     {
       
   410     if( !aMessage.Authenticated() )
       
   411         {
       
   412         // Try authentication and bootstrap without PIN.
       
   413         
       
   414 	
       
   415 	      MWPPhone* phone = NULL;
       
   416         TBuf<KMaxPinSize> imsi;
       
   417         TRAPD(err, phone = WPPhoneFactory::CreateL());
       
   418 	
       
   419 	     if(err!=KErrNone)
       
   420         {
       
   421 		      imsi = KNone;
       
   422 		
       
   423         }
       
   424         else
       
   425         {
       
   426         	imsi = phone->SubscriberId();
       
   427         }
       
   428         
       
   429         
       
   430         CWPBootstrap* bootstrap = CWPBootstrap::NewL( imsi );
       
   431         
       
   432         if(phone)
       
   433         delete phone;
       
   434 
       
   435 	      CleanupStack::PushL( bootstrap );
       
   436 
       
   437         CWPBootstrap::TBootstrapResult result( bootstrap->BootstrapL( 
       
   438                                                                 aMessage, 
       
   439                                                                 *iEngine, 
       
   440                                                                 KNullDesC ) );
       
   441         if( result == CWPBootstrap::EPinRequired )
       
   442             {
       
   443             	CMsvEntry* entry = MsvSession().GetEntryL(iId);
       
   444 				TInt count = (entry->Entry()).MtmData1();
       
   445             // We need to ask the PIN. Retry max. MtmData1 (=3, default) times if
       
   446             // the user supplies from PIN.
       
   447             TBuf<KMaxPinSize> pin;
       
   448 	            for( TInt i(0); i < count && !aMessage.Authenticated(); i++ )
       
   449                 {
       
   450                 pin.Zero();
       
   451 				CWPCodeQueryDialog* dlg = 
       
   452 				                        new (ELeave) CWPCodeQueryDialog( pin );
       
   453 				if (dlg->ExecuteLD( R_QUERY_PIN ) == 0) //R_DATA_QUERY
       
   454 				    {
       
   455 					    delete entry;
       
   456 					    entry = NULL;
       
   457                     //enable user cancelling at any phase
       
   458                     User::Leave( KLeaveWithoutAlert );
       
   459 				    }
       
   460                 result = bootstrap->BootstrapL( aMessage, *iEngine, pin );
       
   461 
       
   462                 // Wrong PIN. Give a note except on the last time. 
       
   463                 // Then the user will get note 
       
   464                 // R_QUERY_VERIFIC_FAILED_TOTALLY with OK key.
       
   465                 if( result == CWPBootstrap::EAuthenticationFailed 
       
   466 	                    && i < (const_cast <TMsvEntry&> (entry->Entry())).iMtmData1--)
       
   467                     {
       
   468 	                      entry->ChangeL(entry->Entry());
       
   469 						i--;	                    
       
   470 						count = (entry->Entry()).MtmData1(); //(const_cast <TMsvEntry&> (entry->Entry())).iMtmData1;
       
   471                     ErrorNoteL( R_TEXT_WRONG_PIN );
       
   472                     }
       
   473                 }
       
   474 
       
   475             // Still wrong PIN -> tell the user and delete the message.
       
   476             if( !aMessage.Authenticated() )
       
   477                 {
       
   478 					delete entry;
       
   479 					entry = NULL;
       
   480                 CAknNoteDialog* dlg = new(ELeave) CAknNoteDialog;
       
   481                 dlg->ExecuteLD(R_QUERY_VERIFIC_FAILED_TOTALLY);
       
   482                 MsvSession().RemoveEntry( iId );
       
   483                 User::Leave( KLeaveWithoutAlert );
       
   484                 }
       
   485 	             if(entry)
       
   486 	             {
       
   487 	             	delete entry;
       
   488 	             }
       
   489             }
       
   490         if(result == CWPBootstrap::EAuthenticationFailed)
       
   491         {
       
   492         		
       
   493         		CAknMessageQueryDialog* msg =  new(ELeave) CAknMessageQueryDialog;
       
   494         		msg->ExecuteLD(R_MSG_AUTHENTICATION_FAILED);
       
   495 
       
   496 			MsvSession().RemoveEntry( iId );
       
   497         		
       
   498         		User::Leave( KLeaveWithoutAlert );
       
   499         		
       
   500         		
       
   501         }
       
   502         CleanupStack::PopAndDestroy( bootstrap );
       
   503 
       
   504         // If the message is still not authenticated, show a note to user.
       
   505         if( !aMessage.Authenticated() )
       
   506             {   
       
   507             CAknQueryDialog* dlg = CAknQueryDialog::NewL();
       
   508         
       
   509             if ( !dlg->ExecuteLD(R_QUERY_NOTAUTHENTICATED) )
       
   510                 {                
       
   511                 User::Leave( KLeaveWithoutAlert );
       
   512                 }
       
   513             }
       
   514         }
       
   515     if (aMessage.Authenticated() )
       
   516         {
       
   517         //update Cenrep key
       
   518         TBuf8<100> orig;
       
   519         orig.Copy(aMessage.Originator());
       
   520         TRAPD(err, SetCenrepKeyL(orig));
       
   521         User::LeaveIfError(err);
       
   522 
       
   523         }
       
   524     }
       
   525 
       
   526 // ----------------------------------------------------------------------------
       
   527 // CWPBioControl ::AddItemsL
       
   528 // ----------------------------------------------------------------------------
       
   529 //
       
   530 void CWPBioControl::AddItemsL()
       
   531     {
       
   532     // Add help text before the actual items
       
   533     HBufC* help = StringLoader::LoadLC( R_TEXT_HELPTEXT );
       
   534     iRichBio->AddItemL( *help, KNullDesC );
       
   535     CleanupStack::PopAndDestroy(); // help
       
   536 
       
   537     RPointerArray<CWPNameValue>* array = CollectItemsLC();
       
   538     CollateAndAddItemsL( *array );
       
   539     CleanupStack::PopAndDestroy(); // array
       
   540     }
       
   541 
       
   542 // ----------------------------------------------------------------------------
       
   543 // CWPBioControl ::CollectItemsL
       
   544 // ----------------------------------------------------------------------------
       
   545 //
       
   546 RPointerArray<CWPNameValue>* CWPBioControl::CollectItemsLC() const
       
   547     {
       
   548     RPointerArray<CWPNameValue>* array = 
       
   549                                     new(ELeave) RPointerArray<CWPNameValue>;
       
   550     CleanupStack::PushL( TCleanupItem( Cleanup, array ) );
       
   551 
       
   552     TInt count( iEngine->ItemCount() );
       
   553     for( TInt index = 0; index < count; index++ )
       
   554         {
       
   555         const TDesC& text = iEngine->SummaryText( index );
       
   556         const TDesC& title = iEngine->SummaryTitle( index );
       
   557 
       
   558         CWPNameValue* pair = CWPNameValue::NewLC( title, text );
       
   559         User::LeaveIfError( array->Append( pair ) );
       
   560         CleanupStack::Pop( pair );
       
   561         }
       
   562 
       
   563     array->Sort( TLinearOrder<CWPNameValue>( CWPBioControl::Compare ) );
       
   564 
       
   565     return array;
       
   566     }
       
   567 
       
   568 // -----------------------------------------------------------------------------
       
   569 // CWPBioControl::Cleanup
       
   570 // -----------------------------------------------------------------------------
       
   571 //
       
   572 void CWPBioControl::Cleanup( TAny* aAny )
       
   573     {
       
   574     RPointerArray<CWPNameValue>* array = 
       
   575                        reinterpret_cast<RPointerArray<CWPNameValue>*>( aAny );
       
   576     array->ResetAndDestroy();
       
   577     array->Close();
       
   578     delete array;
       
   579     }
       
   580 
       
   581 // -----------------------------------------------------------------------------
       
   582 // CWPBioControl::Compare
       
   583 // -----------------------------------------------------------------------------
       
   584 //
       
   585 TInt CWPBioControl::Compare( const CWPNameValue& aItem1,
       
   586                              const CWPNameValue& aItem2 )
       
   587     {
       
   588     return aItem1.Name().Compare( aItem2.Name() );
       
   589     }
       
   590 
       
   591 // ----------------------------------------------------------------------------
       
   592 // CWPBioControl ::CollateAndAddItemsL
       
   593 // ----------------------------------------------------------------------------
       
   594 //
       
   595 void CWPBioControl::CollateAndAddItemsL( RPointerArray<CWPNameValue>& aItems )
       
   596     {
       
   597     // Add a pivot item
       
   598     CWPNameValue* pivot = CWPNameValue::NewLC( KNullDesC, KNullDesC );
       
   599     User::LeaveIfError( aItems.Append( pivot ) );
       
   600     CleanupStack::Pop( pivot );
       
   601 
       
   602     // Title of the items being currently collected
       
   603     TPtrC currentTitle( KNullDesC );
       
   604     // Items under the same title
       
   605     RArray<TPtrC> pointers;
       
   606     CleanupClosePushL( pointers );
       
   607     for( TInt item = 0; item < aItems.Count(); item++ )
       
   608         {
       
   609         CWPNameValue* pair = aItems[ item ];
       
   610 
       
   611         if( pair->Name().Compare( currentTitle ) != 0 )
       
   612             {
       
   613             // Title has changed. Inserted collected items into rich bio
       
   614             if( pointers.Count() > KMaxDuplicates )
       
   615                 {
       
   616                 // More than KMaxDuplicates items. Put only one line with
       
   617                 // number of items.
       
   618                 HBufC* string = StringLoader::LoadLC( R_TEXT_NUMITEMS,
       
   619 					                                  pointers.Count() );
       
   620                 iRichBio->AddItemL( currentTitle, *string );
       
   621                 CleanupStack::PopAndDestroy( string );
       
   622                 }
       
   623             else
       
   624                 {
       
   625                 // Insert all collected items into rich bio
       
   626                 for( TInt index = 0; index < pointers.Count(); index++ )
       
   627                     {
       
   628                     iRichBio->AddItemL( currentTitle, pointers[index] );
       
   629                     // Make sure title is repeated only once
       
   630                     currentTitle.Set( KNullDesC );
       
   631                     }
       
   632 			    } 
       
   633             // Change the current title and start collecting for it
       
   634             currentTitle.Set( pair->Name() );
       
   635             pointers.Reset();
       
   636             }
       
   637 		if(  pair->Value().Compare( KNullDesC ) != 0  )
       
   638 			{
       
   639 			User::LeaveIfError( pointers.Append( pair->Value() ) );
       
   640 			}
       
   641         }
       
   642     // Delete pivot
       
   643     aItems.Remove( aItems.Count() - 1 );
       
   644     delete pivot;
       
   645     CleanupStack::PopAndDestroy( &pointers );
       
   646     }
       
   647 
       
   648 // ----------------------------------------------------------------------------
       
   649 // CWPBioControl ::SaveSettingsL
       
   650 // ----------------------------------------------------------------------------
       
   651 //
       
   652 void CWPBioControl::SaveSettingsL()
       
   653     {
       
   654     if( SysUtil::FFSSpaceBelowCriticalLevelL( &iEikonEnv->FsSession() ) )
       
   655         {
       
   656         User::Leave( KErrDiskFull );
       
   657         }
       
   658 
       
   659     CAknQueryDialog* dlg = CAknQueryDialog::NewL();
       
   660     
       
   661     if( !iMessage->Saved())
       
   662     {
       
   663     	DoSaveL();
       
   664     	delete dlg;
       
   665     }
       
   666     
       
   667     else
       
   668     if( dlg->ExecuteLD(R_QUERY_ALREADY_SAVED) )
       
   669         {
       
   670         DoSaveL();
       
   671         }
       
   672     iMessage->SetSaved( ETrue );
       
   673     SaveMessageL();
       
   674     }
       
   675 
       
   676 // ----------------------------------------------------------------------------
       
   677 // CWPBioControl ::DoSaveL
       
   678 // ----------------------------------------------------------------------------
       
   679 //
       
   680 void CWPBioControl::DoSaveL()
       
   681     {
       
   682     TInt numSaved( 0 );
       
   683     CWPSaver* saver = new(ELeave) CWPSaver( *iEngine, EFalse );
       
   684     HBufC* text=NULL;
       
   685     TInt err( saver->ExecuteLD( numSaved ) );
       
   686     TInt numAccessDenied = saver->GetNumAccessDenied();
       
   687     TInt itemCount( iEngine->ItemCount() );
       
   688     
       
   689 	if( (numSaved != itemCount) && (iEngine->GetAccessDenied()) )
       
   690     	{
       
   691 	  numSaved = numSaved + 1 - numAccessDenied;
       
   692 	  iEngine->SetAccessDenied(EFalse);
       
   693     	  err= KErrAccessDenied;
       
   694     	}
       
   695     
       
   696     if( err >= 0 )
       
   697         {
       
   698         // Check if any setting can be made default
       
   699         TBool setDefault( EFalse );
       
   700         
       
   701         for( TInt i( 0 ); i < itemCount && !setDefault; i++ )
       
   702             {
       
   703             if( iEngine->CanSetAsDefault( i ) )
       
   704                 {
       
   705                 setDefault = ETrue;
       
   706                 }
       
   707             }
       
   708         
       
   709         // Ask the user if the saved settings should be 
       
   710         // made default.
       
   711        TInt result = KErrNone;
       
   712         if( setDefault )
       
   713             {
       
   714             CAknQueryDialog* dlg = CAknQueryDialog::NewL();
       
   715             
       
   716             if ( dlg->ExecuteLD(R_QUERY_SETDEFAULT) )
       
   717                 {
       
   718                 CWPSaver* setter = new(ELeave) CWPSaver( *iEngine, ETrue );
       
   719                 TInt numSet( 0 );
       
   720                 result = setter->ExecuteLD( numSet );
       
   721                 }             
       
   722             }
       
   723         
       
   724         // All settings saved
       
   725         if (result)
       
   726             {
       
   727             if(numSaved == 0)
       
   728              	text = StringLoader::LoadLC( R_TEXT_NOTSAVED_SINGULAR_ZERO);
       
   729             else if(numSaved == 1)
       
   730             	text = StringLoader::LoadLC( R_TEXT_NOTSAVED_SINGULAR_ONE, numSaved );
       
   731     				else        
       
   732             	text = StringLoader::LoadLC( R_TEXT_NOTSAVED, numSaved );
       
   733             ErrorNoteL( *text );
       
   734             CleanupStack::PopAndDestroy(); // text
       
   735             }
       
   736         else
       
   737             {
       
   738             ConfirmationNoteL( R_TEXT_SAVED );
       
   739             }
       
   740         }
       
   741     else
       
   742         {
       
   743         if( err == EWPAccessPointsProtected )
       
   744             {
       
   745             // Some problem in saving or user cancelled.
       
   746             InformationNoteL( R_TEXT_AP_PROTECTED );
       
   747             }
       
   748         else
       
   749             {
       
   750             // Some problem in saving or user cancelled.
       
   751             if(numSaved == 0)
       
   752              	text = StringLoader::LoadLC( R_TEXT_NOTSAVED_SINGULAR_ZERO);
       
   753             else if(numSaved == 1)
       
   754             	text = StringLoader::LoadLC( R_TEXT_NOTSAVED_SINGULAR_ONE, numSaved );
       
   755     				else        
       
   756             	text = StringLoader::LoadLC( R_TEXT_NOTSAVED, numSaved );
       
   757             ErrorNoteL( *text );
       
   758             CleanupStack::PopAndDestroy( text );
       
   759             }
       
   760         }
       
   761     }
       
   762 
       
   763 // ----------------------------------------------------------------------------
       
   764 // CWPBioControl ::SaveMessageL
       
   765 // ----------------------------------------------------------------------------
       
   766 //
       
   767 void CWPBioControl::SaveMessageL()
       
   768     {
       
   769     CMsvEntry* entry = MsvSession().GetEntryL(iId);
       
   770     CleanupStack::PushL( entry );
       
   771 
       
   772     CMsvStore* editStore = entry->EditStoreL();
       
   773     CleanupStack::PushL( editStore );
       
   774     iMessage->StoreL( *editStore );
       
   775     editStore->CommitL();
       
   776     CleanupStack::PopAndDestroy(2); // editStore, entry
       
   777     }
       
   778 
       
   779 void CWPBioControl::ErrorNoteL(const TDesC& aText)
       
   780     {
       
   781     CAknErrorNote* note = new(ELeave)CAknErrorNote( ETrue );
       
   782     note->ExecuteLD(aText);
       
   783     }
       
   784 
       
   785 // ----------------------------------------------------------------------------
       
   786 // CWPBioControl ::ErrorNoteL
       
   787 // ----------------------------------------------------------------------------
       
   788 //
       
   789 void CWPBioControl::ErrorNoteL(TInt aStringResource)
       
   790     {
       
   791     HBufC* buf = StringLoader::LoadLC(aStringResource);
       
   792     ErrorNoteL(*buf);
       
   793     CleanupStack::PopAndDestroy(buf);
       
   794     }
       
   795 
       
   796 // ----------------------------------------------------------------------------
       
   797 // CWPBioControl ::ConfirmationNoteL
       
   798 // ----------------------------------------------------------------------------
       
   799 //
       
   800 void CWPBioControl::ConfirmationNoteL(TInt aStringResource)
       
   801     {
       
   802     HBufC* buf = StringLoader::LoadLC(aStringResource);
       
   803     ConfirmationNoteL(*buf);
       
   804     CleanupStack::PopAndDestroy(buf);
       
   805     }
       
   806     
       
   807 // ----------------------------------------------------------------------------
       
   808 // CWPBioControl ::InformationNoteL
       
   809 // ----------------------------------------------------------------------------
       
   810 //
       
   811 void CWPBioControl::InformationNoteL(TInt aStringResource)
       
   812     {
       
   813     HBufC* buf = StringLoader::LoadLC(aStringResource);
       
   814     InformationNoteL(*buf);
       
   815     CleanupStack::PopAndDestroy(buf);
       
   816     }
       
   817     
       
   818 // ----------------------------------------------------------------------------
       
   819 // CWPBioControl ::ConfirmationNoteL
       
   820 // ----------------------------------------------------------------------------
       
   821 //
       
   822 void CWPBioControl::ConfirmationNoteL(const TDesC& aText)
       
   823     {
       
   824     CAknConfirmationNote* note = new (ELeave) CAknConfirmationNote;
       
   825     note->ExecuteLD(aText);
       
   826     }
       
   827 
       
   828 // ----------------------------------------------------------------------------
       
   829 // CWPBioControl ::InformationNoteL
       
   830 // ----------------------------------------------------------------------------
       
   831 //
       
   832 void CWPBioControl::InformationNoteL(const TDesC& aText)
       
   833     {
       
   834     CAknInformationNote* note = new (ELeave) CAknInformationNote;
       
   835     note->ExecuteLD(aText);
       
   836     }
       
   837 
       
   838 // ----------------------------------------------------------------------------
       
   839 // CWPBioControl ::SetCenrepKey
       
   840 // ----------------------------------------------------------------------------
       
   841 //
       
   842 void CWPBioControl::SetCenrepKeyL(const TDesC8& aValue)
       
   843     {
       
   844 
       
   845     FLOG( _L( "[ProvisioningBC] CWPBioControl::SetCenrepKeyL" ) );
       
   846 
       
   847     CRepository* rep= NULL;
       
   848     TInt errorStatus = KErrNone;
       
   849 
       
   850     TRAPD( errVal, rep = CRepository::NewL( KCRUidOMAProvisioningLV ))
       
   851     ;
       
   852 
       
   853     if (errVal == KErrNone)
       
   854         {
       
   855         errorStatus = rep->Set(KOMAProvOriginatorContent, aValue);
       
   856         }
       
   857     else
       
   858         {
       
   859         errorStatus = errVal;
       
   860         }
       
   861 
       
   862     if (rep)
       
   863         {
       
   864         delete rep;
       
   865         }
       
   866 
       
   867     if (errorStatus != KErrNone)
       
   868         {
       
   869         User::Leave(errorStatus);
       
   870         }
       
   871 
       
   872     FLOG( _L( "[ProvisioningBC] CWPBioControl::SetCenrepKeyL done" ) );
       
   873 
       
   874     }
       
   875 //  End of File