pnpmobileservices/pnpms/PnP/PnpProvisioningAppSrc/PnpProvisioningDocument.cpp
changeset 0 3ce708148e4d
child 2 a5fecba4b1e4
equal deleted inserted replaced
-1:000000000000 0:3ce708148e4d
       
     1 /*
       
     2 * Copyright (c) 2004-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: Implementation of PnPMS components
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDE FILES
       
    20 #include <AknGlobalNote.h>              // for CAknGlobalNote
       
    21 #include <AknGlobalConfirmationQuery.h> // for CAknGlobalConfirmationQuery
       
    22 #include <textresolver.h>
       
    23 #include <AknQueryDialog.h>
       
    24 #include <aknnotewrappers.h>
       
    25 #include <StringLoader.h>
       
    26 #include <PnpProvisioning.rsg>
       
    27 #include <apgcli.h>
       
    28 #include <e32uid.h>
       
    29 #include <CWPEngine.h>      // Using WAP provisioning engine
       
    30 #include <e32math.h>
       
    31 
       
    32 #include "PnpProvisioningDocument.h"
       
    33 #include "PnpProvisioningAppUi.h"
       
    34 #include "NHeadWrapperParser.h"
       
    35 #include "PnpLogger.h"
       
    36 #include "PnpProvisioningSaver.h"
       
    37 
       
    38 
       
    39 
       
    40 
       
    41 
       
    42 // ================= MEMBER FUNCTIONS =======================
       
    43 
       
    44 // constructor
       
    45 CPnpProvisioningDocument::CPnpProvisioningDocument(CEikApplication& aApp)
       
    46 : CAknDocument(aApp)    
       
    47     {
       
    48     LOGSTRING( "CPnpProvisioningDocument()" );
       
    49     }
       
    50 
       
    51 // destructor
       
    52 CPnpProvisioningDocument::~CPnpProvisioningDocument()
       
    53     {
       
    54     LOGSTRING( "~CPnpProvisioningDocument()" );
       
    55     delete iProvisioningData;
       
    56     delete iNHwrParser;
       
    57     //delete iPeriodic;
       
    58     LOGSTRING( "~CPnpProvisioningDocument() done" );
       
    59     }
       
    60 
       
    61 // EPOC default constructor can leave.
       
    62 void CPnpProvisioningDocument::ConstructL()
       
    63     {
       
    64     LOGSTRING( "CPnpProvisioningDocument::ConstructL" );
       
    65     }
       
    66 
       
    67 // Two-phased constructor.
       
    68 CPnpProvisioningDocument* CPnpProvisioningDocument::NewL(
       
    69         CEikApplication& aApp)     // CPnpProvisioningApp reference
       
    70     {
       
    71     LOGSTRING( "CPnpProvisioningDocument::NewL" );
       
    72     CPnpProvisioningDocument* self = new (ELeave) CPnpProvisioningDocument( aApp );
       
    73     CleanupStack::PushL( self );
       
    74     self->ConstructL();
       
    75     CleanupStack::Pop();
       
    76 
       
    77     return self;
       
    78     }
       
    79     
       
    80 // ----------------------------------------------------
       
    81 // CPnpProvisioningDocument::CreateAppUiL()
       
    82 // constructs CPnpProvisioningAppUi
       
    83 // ----------------------------------------------------
       
    84 //
       
    85 CEikAppUi* CPnpProvisioningDocument::CreateAppUiL()
       
    86     {
       
    87     LOGSTRING( "CreateAppUiL" );
       
    88     iAppUi = new (ELeave) CPnpProvisioningAppUi;
       
    89     return iAppUi;
       
    90     }
       
    91 
       
    92 
       
    93 void CPnpProvisioningDocument::OpenFileL( CFileStore*& /*aFileStore*/, RFile& aFile )
       
    94     {
       
    95     LOGSTRING( "CPnpProvisioningDocument::OpenFileL (CFileStore*& /*aFileStore*/, RFile& aFile)" );
       
    96     TFileName fileName;
       
    97     aFile.Name( fileName );
       
    98     LOGTEXT( fileName );
       
    99 
       
   100     TRAPD( err, DoHandleFileL( aFile ) );
       
   101     if( err != KErrNone )
       
   102         {
       
   103         LOGSTRING2( "error in DoHandleFileL: %i", err );
       
   104         User::Leave( err );
       
   105         }
       
   106     iReady = ETrue;
       
   107     }
       
   108 
       
   109 
       
   110 // ----------------------------------------------------
       
   111 // CPnpProvisioningDocument::OpenFileL
       
   112 // Overrides CAknDocument::OpenFileL to support document file
       
   113 // ----------------------------------------------------
       
   114 //
       
   115 CFileStore* CPnpProvisioningDocument::OpenFileL(TBool aDoOpen,const TDesC& aFilename,RFs& aFs)
       
   116     {
       
   117     LOGSTRING( "CPnpProvisioningDocument::OpenFileL (TBool aDoOpen,const TDesC& aFilename,RFs& aFs)" );
       
   118 
       
   119     CFileStore* store = NULL;
       
   120     store = CAknDocument::OpenFileL( aDoOpen, aFilename, aFs );
       
   121     LOGSTRING2( "store:%i", store );
       
   122     LOGSTRING2( "aDoOpen:%i", aDoOpen );
       
   123     
       
   124     iReady = ETrue;
       
   125 
       
   126     return store;
       
   127     }
       
   128 
       
   129 // ----------------------------------------------------
       
   130 // CPnpProvisioningDocument::RestoreL()
       
   131 // restore data from persistent store
       
   132 // ----------------------------------------------------
       
   133 //      
       
   134 void CPnpProvisioningDocument::RestoreL(const CStreamStore& /*aStore*/, const CStreamDictionary& /*aStreamDic*/)
       
   135     {
       
   136     }
       
   137 
       
   138 // ----------------------------------------------------
       
   139 // CPnpProvisioningDocument::StoreL()
       
   140 // store data to persistent store
       
   141 // ----------------------------------------------------
       
   142 //          
       
   143 void CPnpProvisioningDocument::StoreL(CStreamStore& /*aStore*/, CStreamDictionary& /*aStreamDic*/) const
       
   144     {
       
   145     }
       
   146 
       
   147 // ----------------------------------------------------
       
   148 // CPnpProvisioningDocument::HandleFileL
       
   149 // ----------------------------------------------------
       
   150 void CPnpProvisioningDocument::HandleFileL(TBool aDoOpen,const TDesC& aFilename,RFs& aFs)
       
   151     {
       
   152     LOGSTRING( "CPnpProvisioningDocument::HandleFileL" );
       
   153     LOGSTRING( "aFilename:" );
       
   154     LOGTEXT( aFilename );
       
   155 
       
   156     if(aDoOpen)
       
   157         {
       
   158         LOGSTRING( "aDoOpen" );
       
   159 
       
   160         RFile file;
       
   161         if(file.Open(aFs, aFilename,EFileRead)==KErrNone)
       
   162             {
       
   163             LOGSTRING( "File opened" );
       
   164             CleanupClosePushL( file );
       
   165             DoHandleFileL( file );
       
   166             CleanupStack::PopAndDestroy(); // file.Close();
       
   167             }
       
   168         }
       
   169     else
       
   170         {
       
   171         LOGSTRING( "aDoOpen was false" );
       
   172         User::Leave( KErrGeneral );
       
   173         }
       
   174     LOGSTRING( "Exiting HandleFileL" );
       
   175     }
       
   176 
       
   177 // ----------------------------------------------------
       
   178 // CPnpProvisioningDocument::DoHandleFileL
       
   179 // ----------------------------------------------------
       
   180 void CPnpProvisioningDocument::DoHandleFileL( RFile& aFile )
       
   181     {
       
   182     LOGSTRING( "CPnpProvisioningDocument::DoHandleFileL" );
       
   183     TInt filesize = 0;
       
   184     aFile.Size( filesize );
       
   185     delete iProvisioningData;
       
   186     iProvisioningData = 0;
       
   187     iProvisioningData = HBufC8::NewL( filesize );
       
   188     TPtr8 ptr = iProvisioningData->Des();
       
   189     User::LeaveIfError( aFile.Read( ptr, filesize ) );
       
   190     LOGSTRING( "Exiting DoHandleFileL" );
       
   191     }
       
   192 
       
   193 // ----------------------------------------------------
       
   194 // CPnpProvisioningDocument::SaveSettingsL
       
   195 // ----------------------------------------------------
       
   196 
       
   197 THttpProvStates::TProvisioningStatus CPnpProvisioningDocument::SaveSettingsL()
       
   198     {
       
   199     LOGSTRING( "CPnpProvisioningDocument::SaveSettingsL" ); 
       
   200     
       
   201     THttpProvStates::TProvisioningStatus status = THttpProvStates::EStatusOk;
       
   202 
       
   203     if( !iProvisioningData )
       
   204         {
       
   205         User::Leave( THttpProvStates::EStatusWrapperParsingFailed );
       
   206         }
       
   207 
       
   208     iNHwrParser = CNHeadWrapperParser::NewL( *iProvisioningData );
       
   209     TInt err = iNHwrParser->Parse();
       
   210     if( err != THttpProvStates::EStatusOk )
       
   211         {
       
   212         LOGSTRING2( "err from parse:%i", err ); 
       
   213         User::Leave( err );
       
   214         }
       
   215 
       
   216     TPtrC8 content = iNHwrParser->GetContentL();
       
   217 
       
   218     // Create WPEngine
       
   219     CWPEngine* wpengine = CWPEngine::NewL();
       
   220     CleanupStack::PushL( wpengine );
       
   221 
       
   222     LOGSTRING( "wpengine->ImportDocumentL" );
       
   223     TRAPD( result, wpengine->ImportDocumentL( content ) );
       
   224     User::LeaveIfError( result );
       
   225     LOGSTRING( "wpengine->ImportDocumentL ok" );
       
   226 
       
   227     LOGSTRING( "wpengine->PopulateL" );
       
   228     wpengine->PopulateL();
       
   229     LOGSTRING( "wpengine->PopulateL success" );
       
   230 
       
   231     // Empty messages are not supported
       
   232     if( wpengine->ItemCount() == 0 )
       
   233         {
       
   234         LOGSTRING("No items in provisioning message!");
       
   235         User::Leave( THttpProvStates::EStatusWrapperParsingFailed );
       
   236         }
       
   237         
       
   238 
       
   239     TInt numSaved( 0 );
       
   240     CPnpProvisioningSaver* saver = new(ELeave) CPnpProvisioningSaver( *wpengine, EFalse );
       
   241     TInt retValue( KErrNone );
       
   242     LOGSTRING("saver created");
       
   243     // dismiss waitdialog, saver will show own waitdialog
       
   244     iAppUi->WaitDialogDismissedL(EAknSoftkeyEmpty);
       
   245   
       
   246     TRAPD( saverErr, retValue = saver->ExecuteLD( numSaved ) );
       
   247     
       
   248     if( retValue == KErrCancel )
       
   249         {
       
   250         User::Leave( THttpProvStates::EStatusRejected ); // User cancelled
       
   251         }
       
   252     else if( saverErr != KErrNone || retValue != KErrNone )
       
   253         {
       
   254         User::Leave( THttpProvStates::EStatusStorageFailed );
       
   255         }    
       
   256 
       
   257     // check if service activation is enabled if yes then display notes specific to application
       
   258     // settings
       
   259 	TBool activate(EFalse);
       
   260      
       
   261     // If activation enable follow different UI Flow
       
   262     // UI Flow requires changes if any other application requires
       
   263     // service UI flow to be changed as of now applicable only for
       
   264     // Email service activation
       
   265     activate =  iAppUi -> ServiceActivationEnabledL();
       
   266 
       
   267 
       
   268     LOGSTRING( "saver executed" );
       
   269     if( numSaved >= 0 )
       
   270         {
       
   271         LOGSTRING( "numSaved >= 0" );
       
   272         // Check if any setting should be made default
       
   273         TBool setAsDefault( EFalse );
       
   274         TInt itemCount( wpengine->ItemCount() );
       
   275         for( TInt i( 0 ); i < itemCount && !setAsDefault; i++ )
       
   276             {
       
   277             // 1. Set as default if there was no "Provisioning Activation" header
       
   278             // in the head wrapper or if the header asks to make the settings default
       
   279             // 2. Also check if the settings _can_ be set as default at all
       
   280             if( wpengine->CanSetAsDefault( i ) )
       
   281                 {
       
   282                 LOGSTRING( "set as default" );
       
   283                 setAsDefault = ETrue;
       
   284                 }
       
   285             }
       
   286 
       
   287         // The default value is "ask from user" (if there is no Provisioning-Activation
       
   288         // header in the head wrapper, it should be asked from the user)
       
   289         TProvisioningActivation activation = iNHwrParser->GetProvisioningActivation();
       
   290 
       
   291         if( activation == EProvisioningActivationOff )
       
   292             {
       
   293             setAsDefault = EFalse;
       
   294             }
       
   295         else if( activation == EProvisioningActivationUser )
       
   296             {
       
   297             LOGSTRING( "Ask confirmation for saving as default" );
       
   298 	     		
       
   299 	     		if(!activate)
       
   300  	     		{
       
   301             // Ask confirmation from the user before saving as default settings
       
   302             HBufC* msgDefault = CEikonEnv::Static()->AllocReadResourceLC(
       
   303                 R_TEXT_SET_DEFAULT ); 
       
   304                 
       
   305             CAknGlobalConfirmationQuery* query2 = CAknGlobalConfirmationQuery::NewL();
       
   306             CleanupStack::PushL( query2 );
       
   307             TRequestStatus status2;
       
   308             query2->ShowConfirmationQueryL(
       
   309                 status2, 
       
   310                 *msgDefault, 
       
   311                 R_AVKON_SOFTKEYS_YES_NO__YES,
       
   312                 R_QGN_NOTE_QUERY_ANIM);
       
   313                 
       
   314             User::WaitForRequest( status2 );
       
   315             CleanupStack::PopAndDestroy( 2 );
       
   316             
       
   317             if( status2 != EAknSoftkeyYes )
       
   318                 {
       
   319                 setAsDefault = EFalse; // User rejected
       
   320                 }
       
   321 	      	}
       
   322 	      	else // service activation enabled
       
   323 	      	{
       
   324 			   	setAsDefault = ETrue;	
       
   325 	      	}
       
   326             }
       
   327 
       
   328         if( setAsDefault )
       
   329             {
       
   330             LOGSTRING( "create setter" );
       
   331             CPnpProvisioningSaver* setter = new(ELeave) CPnpProvisioningSaver( *wpengine, ETrue );          
       
   332             TInt numSet( 0 );
       
   333             LOGSTRING( "setter->ExecuteLD" );
       
   334             setter->ExecuteLD( numSet );
       
   335             }
       
   336 
       
   337 		// Display note to user that settings are saved successfully
       
   338 		// This note is generic not incase service activation is disabled
       
   339 		if(!activate)
       
   340 		{
       
   341         // All settings saved
       
   342         HBufC* msgTextSaved = CEikonEnv::Static()->
       
   343             AllocReadResourceLC( R_TEXT_SAVED ); 
       
   344 
       
   345         CAknGlobalNote* globalNote = CAknGlobalNote::NewL();
       
   346         CleanupStack::PushL( globalNote );
       
   347         globalNote->ShowNoteL( EAknGlobalInformationNote , *msgTextSaved );
       
   348         CleanupStack::PopAndDestroy( 2 );
       
   349         }
       
   350         else
       
   351         {
       
   352         CPnpServiceActivation *service = CPnpServiceActivation::NewLC();
       
   353         service->DisplayAppSpecNoteL();
       
   354         CleanupStack::PopAndDestroy();
       
   355        	}
       
   356          
       
   357     }
       
   358     else
       
   359         {
       
   360         User::Leave( THttpProvStates::EStatusStorageFailed );
       
   361         }
       
   362 
       
   363     LOGSTRING( "exiting SaveSettingsL" );
       
   364     CleanupStack::PopAndDestroy(wpengine);
       
   365     LOGSTRING( "PopAndDestroy(wpengine) done" );
       
   366 
       
   367     return status;
       
   368     }
       
   369 
       
   370 const TDesC8& CPnpProvisioningDocument::GetReportUrlL()
       
   371     {
       
   372     if( !iNHwrParser )
       
   373         {
       
   374         User::Leave( KErrNotFound );
       
   375         }
       
   376     return( iNHwrParser->GetReportUrlL() );
       
   377     }
       
   378 
       
   379 // End of File