voipplugins/voipadapters/voipxmlprovisioning/provisioningappui/Src/VoIPProvisioningAppUi.cpp
changeset 2 7b872347d83b
child 10 ed1e38b404e5
equal deleted inserted replaced
1:bfb1de3eac8e 2:7b872347d83b
       
     1 /*
       
     2 * Copyright (c) 2009-2010 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:  Application UI implementation.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDES
       
    20 #include <EIKDOC.H>
       
    21 #include <stringloader.h>
       
    22 #include <AknQueryDialog.h>
       
    23 #include <VoIPProvisioningApp.rsg>
       
    24 #include <aknnotewrappers.h>
       
    25 #include <apgcli.h> // RApaLsSession
       
    26 #include <bautils.h>
       
    27 #include <xspviewservices.h>
       
    28 #include <BrowserUiSDKCRKeys.h>
       
    29 #include <pathinfo.h>
       
    30 #include <DriveInfo.h>
       
    31 #include <zipfile.h>
       
    32 #include <zipfilememberinputstream.h>
       
    33 #include <aknwaitdialog.h>
       
    34 
       
    35 #include "voipxmlparser.h"
       
    36 #include "VoIPProvisioningAppUi.h"
       
    37 #include "VoIPProvisioningApp.h"
       
    38 #include "VoIPProvisioningDocument.h"
       
    39 
       
    40 const TInt KOneSecond( 1000000 );
       
    41 const TUid KMecoServiceTabUid = {0x20012423};
       
    42 const TInt KFiveTimes( 5 );
       
    43 _LIT( KDownloadFileName, "tempbranddatapackage.zip" );
       
    44 _LIT( KBrandMifPath,     ":\\private\\102828DD\\import\\" );
       
    45 _LIT( KBrandInstallPath, ":\\private\\102828DD\\import\\install\\" );
       
    46 _LIT( KBrandXmlPath,     ":\\private\\102828E1\\import\\" );
       
    47 _LIT( KXmlExtension,     ".xml" );
       
    48 _LIT( KMifExtension,     ".mif" );
       
    49 _LIT( KInstallExtension, ".install" );
       
    50 _LIT8( KZipExtension,    ".zip" );
       
    51 
       
    52 // ----------------------------------------------------------------------------
       
    53 // CVoIPProvisioningAppUi::CVoIPProvisioningAppUi
       
    54 // ----------------------------------------------------------------------------
       
    55 //
       
    56 CVoIPProvisioningAppUi::CVoIPProvisioningAppUi()
       
    57     {
       
    58     }
       
    59 
       
    60 // ----------------------------------------------------------------------------
       
    61 // CVoIPProvisioningAppUi::ConstructL
       
    62 // ----------------------------------------------------------------------------
       
    63 
       
    64 void CVoIPProvisioningAppUi::ConstructL()
       
    65     {
       
    66     // Call base classes ConstructL method.
       
    67     BaseConstructL( ENoScreenFurniture | EAknEnableMSK );
       
    68 
       
    69     StatusPane()->MakeVisible( EFalse );
       
    70     HideApplicationFromFSW( ETrue );
       
    71 
       
    72     iBrandPackageName.Copy( PathInfo::PhoneMemoryRootPath() );
       
    73     iBrandPackageName.Append( PathInfo::OthersPath() );
       
    74     iBrandPackageName.Append( KDownloadFileName );
       
    75     }
       
    76 
       
    77 // ----------------------------------------------------------------------------
       
    78 // CVoIPProvisioningAppUi::~CVoIPProvisioningAppUi
       
    79 // ----------------------------------------------------------------------------
       
    80 //
       
    81 CVoIPProvisioningAppUi::~CVoIPProvisioningAppUi()
       
    82     {
       
    83     iDownloadMgr.Close();
       
    84     if ( iWaitDialog )
       
    85         {
       
    86         TRAP_IGNORE( iWaitDialog->ProcessFinishedL() );
       
    87         iWaitDialog = NULL;
       
    88         }
       
    89     }
       
    90 
       
    91 // ----------------------------------------------------------------------------
       
    92 // CVoIPProvisioningAppUi::ProcessCommandParametersL
       
    93 // ----------------------------------------------------------------------------
       
    94 //
       
    95 TBool CVoIPProvisioningAppUi::ProcessCommandParametersL(
       
    96     TApaCommand /*aCommand*/, TFileName& /*aDocumentName*/,
       
    97     const TDesC8& /*aTail*/ )
       
    98     {
       
    99     // Always return ETrue to make CVoIPProvisioningDocument's
       
   100     // OpenFileL to be called.
       
   101     return ETrue;
       
   102     }
       
   103 
       
   104 // ----------------------------------------------------------------------------
       
   105 // CVoIPProvisioningAppUi::HandleFileL
       
   106 // ----------------------------------------------------------------------------
       
   107 //
       
   108 void CVoIPProvisioningAppUi::HandleFileL( RFile& aFile )
       
   109     {
       
   110     RFile file;
       
   111     User::LeaveIfError( file.Duplicate( aFile ) );
       
   112     CVoipXmlParser* parser = CVoipXmlParser::NewLC(); // CS:1
       
   113     TBuf8<KMaxFileName> brandUrl( KNullDesC8 );
       
   114     HBufC* queryText = parser->ReadDescriptionLC( aFile, brandUrl ); // CS:2
       
   115     if ( !queryText->Des().Length() )
       
   116         {
       
   117         CleanupStack::PopAndDestroy( queryText );
       
   118         queryText = NULL;
       
   119         queryText = StringLoader::LoadLC( R_VOIP_DEFAULT_SAVE_QUERY );
       
   120         }
       
   121     CAknQueryDialog* query = CAknQueryDialog::NewL();
       
   122     CleanupStack::PushL( query ); // CS:3
       
   123     query->SetPromptL( queryText->Des() );
       
   124     TBool launchTab( EFalse );
       
   125     TUint32 serviceTabId;
       
   126     if ( query->ExecuteLD( R_VOIP_PROVISIONING_QUERY_INSTALL_SERVICE ) )
       
   127         {
       
   128         iWaitDialog = new( ELeave ) CAknWaitDialog( 
       
   129             REINTERPRET_CAST( CEikDialog**, &iWaitDialog ) );
       
   130         iWaitDialog->SetTone( CAknNoteDialog::ENoTone );
       
   131         iWaitDialog->ExecuteLD( R_WAITNOTE_CONFIGURE );
       
   132 
       
   133         FetchBrandingDataL( brandUrl );
       
   134 
       
   135         // Start phonebook into backgound.
       
   136         RxSPViewServices viewServices;
       
   137         CleanupClosePushL( viewServices ); // CS:4
       
   138         TInt viewSrvErr = viewServices.Open();
       
   139         if ( KErrServerTerminated == viewSrvErr || KErrNotFound == viewSrvErr )
       
   140             {
       
   141             viewServices.Close();
       
   142             viewSrvErr = viewServices.Open();
       
   143             }
       
   144         if ( KErrNone == viewSrvErr )
       
   145             {
       
   146             viewServices.Close();
       
   147             }
       
   148 
       
   149         // Ownership of file is trasferred.
       
   150         TInt error = parser->ImportDocument( file, serviceTabId );
       
   151         if ( KErrNone == error )
       
   152             {
       
   153             iWaitDialog->ProcessFinishedL();
       
   154             iWaitDialog = NULL;
       
   155             ShowDoneNoteL();
       
   156             launchTab = ETrue;
       
   157             }
       
   158         else
       
   159             {
       
   160             iWaitDialog->ProcessFinishedL();
       
   161             iWaitDialog = NULL;
       
   162             ShowFailNoteL();
       
   163             }
       
   164         CleanupStack::PopAndDestroy( &viewServices ); // CS:3
       
   165         }
       
   166     CleanupStack::Pop( query ); // CS:2
       
   167     // queryText, parser
       
   168     CleanupStack::PopAndDestroy( 2, parser ); // CS:0
       
   169 
       
   170     // Launch service tab.
       
   171     if ( launchTab )
       
   172         {
       
   173         TInt err = KErrNotFound;
       
   174         TInt counter( 0 );
       
   175         RxSPViewServices viewServices;
       
   176         CleanupClosePushL( viewServices ); // CS:1
       
   177         while ( KErrNone != err && KFiveTimes > counter )
       
   178             {
       
   179             err = viewServices.Activate( 
       
   180                 KMecoServiceTabUid.iUid, (TInt32)serviceTabId );
       
   181             if ( KErrServerTerminated == err || KErrNotFound == err )
       
   182                 {
       
   183                 err = viewServices.Activate( 
       
   184                     KMecoServiceTabUid.iUid, (TInt32)serviceTabId );
       
   185                 }
       
   186             // Wait...
       
   187             User::After( KOneSecond );
       
   188             counter++;
       
   189             }
       
   190 
       
   191         CleanupStack::PopAndDestroy( &viewServices ); // CS:0
       
   192         TApaTaskList taskList( CEikonEnv::Static()->WsSession() );
       
   193         TApaTask browserTask = taskList.FindApp( KCRUidBrowser );
       
   194         if ( browserTask.Exists() )
       
   195             {
       
   196             browserTask.EndTask();
       
   197             }
       
   198         }
       
   199 
       
   200     if ( iWaitDialog )
       
   201         {
       
   202         iWaitDialog->ProcessFinishedL();
       
   203         iWaitDialog = NULL;
       
   204         }
       
   205 
       
   206     iDownloadMgr.Close();
       
   207 #ifndef __EUNIT_TESTING
       
   208     User::Exit( KErrNone );
       
   209 #endif
       
   210     }
       
   211 
       
   212 // ----------------------------------------------------------------------------
       
   213 // CVoIPProvisioningAppUi::ShowFailNoteL
       
   214 // ----------------------------------------------------------------------------
       
   215 //
       
   216 void CVoIPProvisioningAppUi::ShowFailNoteL() const
       
   217     {
       
   218     HBufC* text = StringLoader::LoadLC( R_VOIP_INVALID_DATA );
       
   219     CAknErrorNote* note = new (ELeave) CAknErrorNote( R_AKN_ERROR_NOTE );
       
   220     note->ExecuteLD( *text );
       
   221     CleanupStack::PopAndDestroy( text );
       
   222     }
       
   223 
       
   224 // ----------------------------------------------------------------------------
       
   225 // CVoIPProvisioningAppUi::ShowDoneNoteL
       
   226 // ----------------------------------------------------------------------------
       
   227 //
       
   228 void CVoIPProvisioningAppUi::ShowDoneNoteL() const
       
   229     {
       
   230     HBufC* text = StringLoader::LoadLC( R_VOIP_INSTALLED );
       
   231     CAknInformationNote* note =
       
   232         new (ELeave) CAknInformationNote( R_AKN_INFORMATION_NOTE );
       
   233     note->ExecuteLD( *text );
       
   234     CleanupStack::PopAndDestroy( text );
       
   235     }
       
   236 
       
   237 // ---------------------------------------------------------------------------
       
   238 // From base class MHttpDownloadMgrObserver.
       
   239 // Handles download manager events.
       
   240 // ---------------------------------------------------------------------------
       
   241 //
       
   242 void CVoIPProvisioningAppUi::HandleDMgrEventL( RHttpDownload& aDownload,
       
   243     THttpDownloadEvent aEvent )
       
   244     {
       
   245     if ( EHttpDlPaused == aEvent.iDownloadState && 
       
   246         EHttpContentTypeReceived == aEvent.iProgressState )
       
   247         {
       
   248         TInt32 length;
       
   249         TInt err = aDownload.GetIntAttribute( EDlAttrLength, length );
       
   250         if ( KDefaultContentLength != length && 0 < length )
       
   251             {
       
   252             // Continue.
       
   253             aDownload.Start();
       
   254             }
       
   255         else
       
   256             {
       
   257             CActiveScheduler::Stop();
       
   258             aDownload.Delete();
       
   259             }
       
   260         }
       
   261     else if ( EHttpDlCompleted == aEvent.iDownloadState )
       
   262         {
       
   263         CActiveScheduler::Stop();
       
   264         // We don't need the leave code; un-branded service is OK.
       
   265         TRAP_IGNORE( UncompressFilesL() );
       
   266         aDownload.Delete();
       
   267         }
       
   268     else if ( EHttpDlFailed == aEvent.iDownloadState )
       
   269         {
       
   270         CActiveScheduler::Stop();
       
   271         aDownload.Delete();
       
   272         }
       
   273     else if ( EHttpDlInprogress == aEvent.iDownloadState && 
       
   274         EHttpProgDisconnected == aEvent.iProgressState )
       
   275         {
       
   276         CActiveScheduler::Stop();
       
   277         aDownload.Delete();
       
   278         }
       
   279     }
       
   280 
       
   281 // ---------------------------------------------------------------------------
       
   282 // Starts branding data download.
       
   283 // ---------------------------------------------------------------------------
       
   284 //
       
   285 TInt CVoIPProvisioningAppUi::FetchBrandingDataL( const TDesC8& aUrl )
       
   286     {
       
   287     if ( !aUrl.Length() || KErrNotFound == aUrl.Find( KZipExtension ) )
       
   288         {
       
   289         return KErrNotFound;
       
   290         }
       
   291     iDownloadMgr.ConnectL( KUidVoIPProvisioningAppUid, *this, EFalse );
       
   292     RHttpDownload& download = iDownloadMgr.CreateDownloadL( aUrl );
       
   293     download.SetStringAttribute( EDlAttrDestFilename, iBrandPackageName );
       
   294     TInt err = download.Start();
       
   295     CActiveScheduler::Start();
       
   296     return err;
       
   297     }
       
   298 
       
   299 // ---------------------------------------------------------------------------
       
   300 // Uncompresses files from a zip file.
       
   301 // ---------------------------------------------------------------------------
       
   302 //
       
   303 void CVoIPProvisioningAppUi::UncompressFilesL()
       
   304     {
       
   305     RFs fs;
       
   306     User::LeaveIfError( fs.Connect() );
       
   307     CleanupClosePushL( fs ); // CS:1
       
   308     CZipFile* zipfile = CZipFile::NewL( fs, iBrandPackageName );
       
   309     CleanupStack::PushL( zipfile ); // CS:2
       
   310     CZipFileMemberIterator* iterator = zipfile->GetMembersL();
       
   311     CleanupStack::PushL( iterator ); // CS:3
       
   312     CZipFileMember* fileMember = iterator->NextL();
       
   313     TChar drive;
       
   314     DriveInfo::GetDefaultDrive( DriveInfo::EDefaultPhoneMemory, drive );
       
   315 
       
   316     RFile output;
       
   317     CleanupClosePushL( output ); // CS:4
       
   318 
       
   319     while ( fileMember )
       
   320         {
       
   321         TFileName memberFileName = *fileMember->Name();
       
   322         TFileName outputPath;
       
   323         outputPath.Append( drive );
       
   324         if ( KErrNotFound != memberFileName.Find( KXmlExtension ) )
       
   325             {
       
   326             outputPath.Append( KBrandXmlPath );
       
   327             outputPath.Append( memberFileName );
       
   328             }
       
   329         else if ( KErrNotFound != memberFileName.Find( KInstallExtension ))
       
   330             {
       
   331             outputPath.Append( KBrandInstallPath );
       
   332             outputPath.Append( memberFileName );
       
   333             }
       
   334         else if ( KErrNotFound != memberFileName.Find( KMifExtension ))
       
   335             {
       
   336             outputPath.Append( KBrandMifPath );
       
   337             outputPath.Append( memberFileName );
       
   338             }
       
   339         else
       
   340             {
       
   341             // Ignore this file and get next file from zip.
       
   342             fileMember = iterator->NextL();
       
   343             break;
       
   344             }
       
   345 
       
   346         TInt err = fs.MkDirAll( outputPath );
       
   347         err = output.Replace( fs, outputPath, EFileShareAny|EFileWrite );
       
   348 
       
   349         TUint32 size = fileMember->UncompressedSize();
       
   350         RBuf8 outputData;
       
   351         outputData.CreateL( size );
       
   352         CleanupClosePushL( outputData ); // CS:5
       
   353         RZipFileMemberReaderStream* stream;
       
   354         zipfile->GetInputStreamL( fileMember, stream );
       
   355         CleanupStack::PushL( stream ); // CS:6
       
   356 
       
   357         err = stream->Read( outputData, size );
       
   358         err = output.Write( outputData );
       
   359 
       
   360         output.Flush();
       
   361 
       
   362         // stream, &outputData
       
   363         CleanupStack::PopAndDestroy( 2, &outputData ); // CS:4
       
   364 
       
   365         fileMember = iterator->NextL();
       
   366         }
       
   367     // &output, iterator, zipfile, &fs
       
   368     CleanupStack::PopAndDestroy( 3, zipfile ); // CS:1
       
   369 
       
   370     // Finally, delete temp zip file.
       
   371     fs.Delete( iBrandPackageName );    
       
   372     CleanupStack::PopAndDestroy( &fs ); // CS:0
       
   373     }
       
   374 
       
   375 // End of file.