iaupdate/IAD/updater/src/iaupdaterdialog.cpp
changeset 0 ba25891c3a9e
child 25 7333d7932ef7
equal deleted inserted replaced
-1:000000000000 0:ba25891c3a9e
       
     1 /*
       
     2 * Copyright (c) 2007-2008 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:   This file contains the implementation of CDialogWrapper
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 #include <AknGlobalNote.h>
       
    21 #include <avkon.rsg>
       
    22 #include <bautils.h>
       
    23 #include <data_caging_path_literals.hrh> 
       
    24 #include <iaupdater.rsg>
       
    25 #include <StringLoader.h>
       
    26 #include <AknUtils.h>   //For AknTextUtils
       
    27 
       
    28 #include "iaupdaterdialog.h"
       
    29 #include "iaupdaterdefs.h"
       
    30 #include "iaupdatercancelobserver.h"
       
    31 #include "iaupdatedebug.h"
       
    32 
       
    33 
       
    34 // ======== LOCAL FUNCTIONS ========
       
    35 
       
    36 // ======== MEMBER FUNCTIONS ========
       
    37 
       
    38 
       
    39 // -----------------------------------------------------------------------------
       
    40 // CIAUpdaterDialog::CIAUpdaterDialog
       
    41 // C++ default constructor 
       
    42 // -----------------------------------------------------------------------------
       
    43 //
       
    44 CIAUpdaterDialog::CIAUpdaterDialog( RFs& aFs, 
       
    45                                     MIAUpdaterCancelObserver& aObserver )
       
    46 : CActive( CActive::EPriorityStandard ),
       
    47   iFs( aFs ),
       
    48   iObserver ( &aObserver ) 
       
    49     {
       
    50     CActiveScheduler::Add( this );
       
    51     }
       
    52 
       
    53 
       
    54 // -----------------------------------------------------------------------------
       
    55 // CIAUpdaterDialog::NewL
       
    56 // Two-phased constructor.
       
    57 // -----------------------------------------------------------------------------
       
    58 //
       
    59 CIAUpdaterDialog* CIAUpdaterDialog::NewL( RFs& aFs, 
       
    60                                           MIAUpdaterCancelObserver& aObserver )
       
    61     {
       
    62     CIAUpdaterDialog* self =
       
    63         CIAUpdaterDialog::NewLC( aFs, aObserver );
       
    64     CleanupStack::Pop( self );
       
    65     return self;    
       
    66     }
       
    67 
       
    68 
       
    69 // -----------------------------------------------------------------------------
       
    70 // CIAUpdaterDialog::NewLC
       
    71 // Two-phased constructor.
       
    72 // -----------------------------------------------------------------------------
       
    73 //
       
    74 CIAUpdaterDialog* CIAUpdaterDialog::NewLC( RFs& aFs, 
       
    75                                            MIAUpdaterCancelObserver& aObserver )
       
    76     {
       
    77     CIAUpdaterDialog* self = 
       
    78         new( ELeave ) CIAUpdaterDialog( aFs, aObserver );
       
    79     CleanupStack::PushL( self );
       
    80     self->ConstructL();
       
    81     return self;    
       
    82     }
       
    83 
       
    84 
       
    85 // -----------------------------------------------------------------------------
       
    86 // CIAUpdaterDialog::ConstructL
       
    87 // Symbian 2nd phase constructor can leave.
       
    88 // -----------------------------------------------------------------------------
       
    89 //
       
    90 void CIAUpdaterDialog::ConstructL()
       
    91     {
       
    92     IAUPDATE_TRACE("[IAUpdater] CIAUpdaterDialog::ConstructL begin");
       
    93     
       
    94     // Get resource file path
       
    95     TFileName fileName;
       
    96     fileName.Copy( TParsePtrC( RProcess().FileName() ).Drive() );
       
    97     fileName.Append( KDC_APP_RESOURCE_DIR );
       
    98     fileName.Append( IAUpdaterDefs::KIAUpdaterResourceFile );
       
    99     
       
   100     // Get language of resource file        
       
   101     BaflUtils::NearestLanguageFile( iFs, fileName );
       
   102 
       
   103     // Open resource file
       
   104     iResourceFile.OpenL( iFs, fileName );
       
   105     iResourceFile.ConfirmSignatureL();    
       
   106 
       
   107     IAUPDATE_TRACE("[IAUpdater] CIAUpdaterDialog::ConstructL end");
       
   108     }
       
   109 
       
   110  
       
   111 // -----------------------------------------------------------------------------
       
   112 // CIAUpdaterDialog::~CIAUpdaterDialog()
       
   113 // C++ Destructor
       
   114 // -----------------------------------------------------------------------------
       
   115 //
       
   116 CIAUpdaterDialog::~CIAUpdaterDialog()
       
   117     {
       
   118     Cancel();
       
   119     delete iNote;
       
   120     iResourceFile.Close();    
       
   121     }
       
   122 
       
   123 
       
   124 // -----------------------------------------------------------------------------
       
   125 // CIAUpdaterDialog::ShowWaitingNoteL  
       
   126 // Show global waiting note during installing.
       
   127 // -----------------------------------------------------------------------------
       
   128 // 
       
   129 void CIAUpdaterDialog::ShowWaitingNoteL( const TDesC& aName, TInt aIndex, TInt aTotalCount )
       
   130 	{	
       
   131 	IAUPDATE_TRACE("[IAUpdater] CIAUpdaterDialog::ShowWaitingNoteL begin");
       
   132 	if ( iNoteId == 0 )
       
   133 		{ 		                             
       
   134 	    IAUPDATE_TRACE("[IAUpdater] Creating global waiting note.");
       
   135 	
       
   136         // Get localiced string from resc. file. 
       
   137         HBufC* string = ReadResourceLC( R_IAUPDATER_INSTALLING ); 
       
   138                                           
       
   139         HBufC* temp1 = HBufC::NewLC( string->Length() + aName.Length() );          
       
   140         TPtr temp1Ptr = temp1->Des();
       
   141         
       
   142         // Add pkg's name to string (U0).
       
   143         StringLoader::Format( temp1Ptr, *string, 0, aName );
       
   144                                         
       
   145         // Increase buffer length for the number.        
       
   146         HBufC* temp2 = 
       
   147             HBufC::NewLC( temp1->Length() + IAUpdaterDefs::KIAUpdaterParamLen );        
       
   148         TPtr temp2Ptr = temp2->Des();
       
   149          
       
   150         // Add index number to string (N1) 
       
   151         StringLoader::Format( temp2Ptr, *temp1, 1, aIndex );
       
   152                         
       
   153         // Increase buffer length for the number.  
       
   154         HBufC* finalString = 
       
   155             HBufC::NewLC( temp2->Length() + IAUpdaterDefs::KIAUpdaterParamLen );        
       
   156         TPtr finalPtr = finalString->Des();
       
   157         
       
   158         // Add max count number to string (N2) 
       
   159         StringLoader::Format( finalPtr, *temp2, 2, aTotalCount );
       
   160         
       
   161         AknTextUtils::DisplayTextLanguageSpecificNumberConversion( finalPtr );         
       
   162         if ( !iNote )
       
   163             {
       
   164         	iNote = CAknGlobalNote::NewL();   
       
   165     	    iNote->SetSoftkeys( R_AVKON_SOFTKEYS_CANCEL );
       
   166             }
       
   167      	
       
   168 	    IAUPDATE_TRACE("[IAUpdater] Showing global waiting note.");
       
   169     	iNoteId = iNote->ShowNoteL( iStatus, EAknGlobalWaitNote, *finalString );
       
   170     	SetActive();    	    	
       
   171      
       
   172     	CleanupStack::PopAndDestroy( finalString );
       
   173     	CleanupStack::PopAndDestroy( temp2 );
       
   174     	CleanupStack::PopAndDestroy( temp1 );
       
   175     	CleanupStack::PopAndDestroy( string );
       
   176 		}
       
   177 	IAUPDATE_TRACE("[IAUpdater] CIAUpdaterDialog::ShowWaitingNoteL end");
       
   178 	}
       
   179 
       
   180 	
       
   181 // -----------------------------------------------------------------------------
       
   182 // CIAUpdaterDialog::CancelWaitingNoteL  
       
   183 // Cancel global waiting note after installing.
       
   184 // -----------------------------------------------------------------------------
       
   185 // 
       
   186 void CIAUpdaterDialog::CancelWaitingNoteL()
       
   187 	{
       
   188     IAUPDATE_TRACE("[IAUpdater] CIAUpdaterDialog::CancelWaitingNoteL begin");
       
   189 	
       
   190 	if ( iNoteId != 0 )
       
   191 		{
       
   192         IAUPDATE_TRACE("[IAUpdater] Cancel waiting note.");
       
   193 	    iNote->CancelNoteL( iNoteId );
       
   194 	    iNoteId = 0;
       
   195 		}
       
   196 
       
   197     IAUPDATE_TRACE("[IAUpdater] CIAUpdaterDialog::CancelWaitingNoteL end");
       
   198 	}
       
   199 
       
   200 	
       
   201 // -----------------------------------------------------------------------------	
       
   202 // CIAUpdaterDialog::LoadResourceLC
       
   203 // Read resource string.
       
   204 // -----------------------------------------------------------------------------
       
   205 // 
       
   206 HBufC* CIAUpdaterDialog::ReadResourceLC( TInt aResourceId )
       
   207     {
       
   208     TResourceReader reader;
       
   209     HBufC8* buff = iResourceFile.AllocReadLC( aResourceId );    
       
   210     reader.SetBuffer( buff );
       
   211     HBufC* text = reader.ReadHBufCL();
       
   212     CleanupStack::PopAndDestroy( buff );
       
   213     CleanupStack::PushL( text );
       
   214 
       
   215     return text;
       
   216     }
       
   217     
       
   218     
       
   219 // ---------------------------------------------------------------------------
       
   220 // CIAUpdaterDialog:::DoCancel
       
   221 // 
       
   222 // ---------------------------------------------------------------------------
       
   223 // 
       
   224 void CIAUpdaterDialog::DoCancel()
       
   225     {
       
   226     TRAP_IGNORE( CancelWaitingNoteL() );
       
   227     }
       
   228 
       
   229 // ---------------------------------------------------------------------------
       
   230 // CIAUpdateNetworkRegistration::RunL()
       
   231 // 
       
   232 // ---------------------------------------------------------------------------
       
   233 //
       
   234 void CIAUpdaterDialog::RunL()
       
   235     {
       
   236     IAUPDATE_TRACE_1("[IAUpdater] CIAUpdaterDialog::RunL() iStatus : %d", iStatus.Int() );
       
   237     iNoteId = 0;
       
   238     if ( iStatus.Int() == EAknSoftkeyCancel )
       
   239         {
       
   240     	iObserver->UserCancel();
       
   241         }
       
   242     else
       
   243         {
       
   244         iObserver->UserExit();	
       
   245         }
       
   246     }
       
   247 
       
   248 // ======== GLOBAL FUNCTIONS ========
       
   249 
       
   250 //  EOF