omads/omadsappui/AspSyncUtil/src/AspProgressDialog.cpp
branchRCL_3
changeset 52 4f0867e42d62
parent 0 dab8a81a92de
equal deleted inserted replaced
51:8e7494275d3a 52:4f0867e42d62
       
     1 /*
       
     2 * Copyright (c) 2005 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 *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDE FILES
       
    20 #include "AspProgressDialog.h"
       
    21 #include "AspSyncUtil.rh"
       
    22 #include "AspUtil.h"
       
    23 #include "AspDebug.h"
       
    24 #include "AspDefines.h"
       
    25 #include "AspResHandler.h"
       
    26 #include "AspDialogUtil.h"
       
    27 
       
    28 
       
    29 #include <eikprogi.h>
       
    30 #include <notecontrol.h>
       
    31 
       
    32 
       
    33 
       
    34 // ============================ MEMBER FUNCTIONS ===============================
       
    35 
       
    36 
       
    37 
       
    38 /*******************************************************************************
       
    39  * class CAspProgressDialog
       
    40  *******************************************************************************/
       
    41 
       
    42 
       
    43 // -----------------------------------------------------------------------------
       
    44 // CAspProgressDialog::CAspProgressDialog
       
    45 //
       
    46 // -----------------------------------------------------------------------------
       
    47 //
       
    48 CAspProgressDialog::CAspProgressDialog(MAspProgressDialogObserver* aObserver) : iObserver(aObserver)
       
    49     {
       
    50     FLOG( _L("CAspProgressDialog: CAspProgressDialog") );
       
    51     }
       
    52 
       
    53 
       
    54 // -----------------------------------------------------------------------------
       
    55 // CAspProgressDialog::NewL
       
    56 //
       
    57 // -----------------------------------------------------------------------------
       
    58 //
       
    59 CAspProgressDialog* CAspProgressDialog::NewL(MAspProgressDialogObserver* aObserver)
       
    60     {
       
    61     FLOG( _L("CAspProgressDialog::NewL START") );
       
    62 
       
    63     CAspProgressDialog* self = new (ELeave) CAspProgressDialog(aObserver);
       
    64     CleanupStack::PushL(self);
       
    65     self->ConstructL();
       
    66     CleanupStack::Pop(self);
       
    67 
       
    68     FLOG( _L("CAspProgressDialog::NewL END") );
       
    69     return(self);
       
    70     }
       
    71 
       
    72 
       
    73 // -----------------------------------------------------------------------------
       
    74 // CAspProgressDialog::ConstructL
       
    75 //
       
    76 // -----------------------------------------------------------------------------
       
    77 //
       
    78 void CAspProgressDialog::ConstructL()
       
    79     {
       
    80     FLOG( _L("CAspProgressDialog::ConstructL START") );
       
    81 
       
    82 	iLastText = KNullDesC;
       
    83 	iAnimation = EFalse;
       
    84 	iResHandler = CAspResHandler::NewL();
       
    85 	iProgressDialogRunning = EFalse;
       
    86     
       
    87 	FLOG( _L("CAspProgressDialog::ConstructL END") );
       
    88     } 
       
    89 
       
    90 
       
    91 // -----------------------------------------------------------------------------
       
    92 // Destructor
       
    93 //
       
    94 // -----------------------------------------------------------------------------
       
    95 //
       
    96 CAspProgressDialog::~CAspProgressDialog()
       
    97     {
       
    98     FLOG( _L("CAspProgressDialog::~CAspProgressDialog START") );
       
    99 
       
   100 	delete iResHandler;
       
   101     delete iProgressDialog;
       
   102 
       
   103 	FLOG( _L("CAspProgressDialog::~CAspProgressDialog END") );
       
   104     }
       
   105 
       
   106 
       
   107 // -----------------------------------------------------------------------------
       
   108 // CAspProgressDialog::LaunchProgressDialogL
       
   109 //
       
   110 // -----------------------------------------------------------------------------
       
   111 //
       
   112 void CAspProgressDialog::LaunchProgressDialogL(const TDesC& aLabel, TAknsItemID aId, const TDesC& aFileName, TInt aFileBitmapId, TInt aFileMaskId)
       
   113 	{
       
   114     FLOG( _L("CAspProgressDialog::LaunchProgressDialogL START") );
       
   115 
       
   116 	iProgressDialog = new(ELeave) CAspProgressDialog2(reinterpret_cast<CEikDialog**>(&iProgressDialog), iApplicationId);
       
   117     
       
   118 	iProgressDialog->PrepareLC(R_ASP_PROGRESS_NOTE);
       
   119     iProgressDialog->SetTextL(aLabel);
       
   120 	
       
   121 	CEikImage* image = TDialogUtil::CreateImageLC(aId, aFileName, aFileBitmapId, aFileMaskId);
       
   122     iProgressDialog->SetImageL(image);
       
   123 	CleanupStack::Pop(image);
       
   124 
       
   125     // get reference to progress info bar
       
   126     iProgressInfo = iProgressDialog->GetProgressInfoL();
       
   127     iProgressDialog->SetCallback(this);
       
   128     
       
   129     iProgressDialog->RunLD();
       
   130     iProgressDialogRunning = ETrue;
       
   131 
       
   132 	FLOG( _L("CAspProgressDialog::LaunchProgressDialogL END") );
       
   133 	}
       
   134 
       
   135 
       
   136 // -----------------------------------------------------------------------------
       
   137 // CAspProgressDialog::CancelProgressDialogL
       
   138 //
       
   139 // -----------------------------------------------------------------------------
       
   140 //
       
   141 void CAspProgressDialog::CancelProgressDialogL()
       
   142     {
       
   143     FLOG( _L("CAspProgressDialog::CancelProgressDialogL START") );
       
   144 
       
   145 	if (!iProgressDialogRunning)
       
   146 		{
       
   147 		return; // dialog is already closed
       
   148 		}
       
   149 		
       
   150 	if(iProgressDialog)
       
   151         {        
       
   152         iProgressDialog->ProcessFinishedL();
       
   153         iProgressDialogRunning = EFalse;
       
   154         }    
       
   155 
       
   156 	FLOG( _L("CAspProgressDialog::CancelProgressDialogL END") );
       
   157     }
       
   158 
       
   159 // -----------------------------------------------------------------------------
       
   160 // CAspProgressDialog::ProgressDialog
       
   161 //
       
   162 // -----------------------------------------------------------------------------
       
   163 //
       
   164 CAspProgressDialog2* CAspProgressDialog::ProgressDialog()
       
   165 	{
       
   166 	return iProgressDialog;
       
   167 	}
       
   168 
       
   169 // -----------------------------------------------------------------------------
       
   170 // CAspProgressDialog::UpdateTextL
       
   171 //
       
   172 // -----------------------------------------------------------------------------
       
   173 //
       
   174 void CAspProgressDialog::UpdateTextL(const TDesC& aText)
       
   175     {
       
   176     FLOG( _L("CAspProgressDialog::UpdateTextL START") );
       
   177 
       
   178 	__ASSERT_DEBUG(iProgressDialog, TUtil::Panic(KErrGeneral));
       
   179 
       
   180 	if (iLastText.Compare(aText) == 0)
       
   181 		{
       
   182 		return;  // text has not changed
       
   183 		}
       
   184     
       
   185     iProgressDialog->SetTextL(aText);
       
   186 	TUtil::StrCopy(iLastText, aText);
       
   187 	
       
   188 	FLOG( _L("aText is '%S'"), &aText );
       
   189 
       
   190 	FLOG( _L("CAspProgressDialog::UpdateTextL END") );
       
   191     }
       
   192 
       
   193 
       
   194 // -----------------------------------------------------------------------------
       
   195 // CAspProgressDialog::SetProgress
       
   196 //
       
   197 // -----------------------------------------------------------------------------
       
   198 //
       
   199 void CAspProgressDialog::SetProgress(TInt aValue)
       
   200     {
       
   201     FLOG( _L("CAspProgressDialog::SetProgress START") );
       
   202     
       
   203 	__ASSERT_DEBUG(iProgressDialog  && iProgressInfo, TUtil::Panic(KErrGeneral));
       
   204 
       
   205 	CEikProgressInfo::SInfo info = iProgressInfo->Info();
       
   206 
       
   207 	TInt val = aValue;
       
   208 	if (val > info.iFinalValue)
       
   209 		{
       
   210 		val = info.iFinalValue;
       
   211 		}
       
   212 	
       
   213 	iProgressInfo->SetAndDraw(val);
       
   214 	
       
   215 	FLOG( _L("aValue is %d"), aValue );
       
   216     
       
   217 	FLOG( _L("CAspProgressDialog::SetProgress END") );
       
   218     }
       
   219 
       
   220 
       
   221 // -----------------------------------------------------------------------------
       
   222 // CAspProgressDialog::SetFinalProgress
       
   223 //
       
   224 // -----------------------------------------------------------------------------
       
   225 //
       
   226 void CAspProgressDialog::SetFinalProgress(TInt aFinalValue)
       
   227 	{
       
   228     FLOG( _L("CAspProgressDialog::SetFinalProgress START") );
       
   229     
       
   230     __ASSERT_DEBUG(iProgressInfo, TUtil::Panic(KErrGeneral));
       
   231 
       
   232     if (aFinalValue < 0)
       
   233     	{
       
   234     	iProgressInfo->SetFinalValue(0);
       
   235     	}
       
   236     else
       
   237     	{
       
   238     	iProgressInfo->SetFinalValue(aFinalValue);
       
   239     	}
       
   240     	
       
   241 	iProgressInfo->SetAndDraw(0);
       
   242 
       
   243 	FLOG( _L("aFinalValue is %d"), aFinalValue );
       
   244 	
       
   245 	FLOG( _L("CAspProgressDialog::SetFinalProgress END") );
       
   246 	}
       
   247 
       
   248 
       
   249 // -----------------------------------------------------------------------------
       
   250 // CAspProgressDialog::NoteControl
       
   251 //
       
   252 // -----------------------------------------------------------------------------
       
   253 //
       
   254 CAknNoteControl* CAspProgressDialog::NoteControl()
       
   255 	{
       
   256     CAknNoteControl* note = STATIC_CAST(CAknNoteControl*, iProgressDialog->ControlOrNull(EAspSyncProgressNote));
       
   257 
       
   258 	__ASSERT_DEBUG(note, TUtil::Panic(KErrGeneral));
       
   259 
       
   260 	return note;
       
   261 	}
       
   262 
       
   263 
       
   264 // -----------------------------------------------------------------------------
       
   265 // CAspProgressDialog::CancelAnimation
       
   266 //
       
   267 // -----------------------------------------------------------------------------
       
   268 //
       
   269 void CAspProgressDialog::CancelAnimation()
       
   270 	{
       
   271 	FLOG( _L("CAspProgressDialog::CancelAnimation START") );
       
   272 	
       
   273 	NoteControl()->CancelAnimation();
       
   274 	iAnimation = EFalse;
       
   275 
       
   276 	FLOG( _L("CAspProgressDialog::CancelAnimation END") );
       
   277 	}
       
   278 
       
   279 
       
   280 // ----------------------------------------------------------------------------
       
   281 // CAspProgressDialog::StartAnimationL
       
   282 //
       
   283 // ----------------------------------------------------------------------------
       
   284 //
       
   285 void CAspProgressDialog::StartAnimationL()
       
   286 	{
       
   287 	FLOG( _L("CAspProgressDialog::StartAnimationL START") );
       
   288 	
       
   289 	if (!iAnimation)
       
   290 		{
       
   291 		NoteControl()->StartAnimationL();
       
   292 		iAnimation = ETrue;
       
   293 		
       
   294 		FLOG( _L("animation started") );
       
   295 		}
       
   296 		
       
   297     FLOG( _L("CAspProgressDialog::StartAnimationL END") );
       
   298 	}
       
   299 
       
   300 
       
   301 // -----------------------------------------------------------------------------
       
   302 // CAspProgressDialog::DialogDismissedL (From MProgressDialogCallback)
       
   303 //
       
   304 // -----------------------------------------------------------------------------
       
   305 //
       
   306 void CAspProgressDialog::DialogDismissedL(TInt aButtonId)
       
   307     {
       
   308     FLOG( _L("CAspProgressDialog::DialogDismissedL START" ) );
       
   309   
       
   310     if (!iObserver)
       
   311 		{
       
   312 		FLOG( _L("### no observer ###") );
       
   313 		FLOG( _L("CAspProgressDialog::DialogDismissedL END") );
       
   314 		return; // no observer
       
   315 		}
       
   316 	
       
   317 	// end key handling
       
   318 	if (aButtonId == EKeyPhoneEnd)
       
   319 	    {
       
   320         TRAP_IGNORE(iObserver->HandleDialogEventL(EKeyPhoneEnd));
       
   321         }
       
   322 
       
   323 	// this dialog only sends one cancel event - other events are ignored 
       
   324 	if (aButtonId == EEikBidCancel)
       
   325 		{
       
   326         TRAP_IGNORE(iObserver->HandleDialogEventL(EEikBidCancel));
       
   327         }
       
   328 
       
   329     FLOG( _L("CAspProgressDialog::DialogDismissedL END") );
       
   330     }
       
   331 
       
   332 
       
   333 // -----------------------------------------------------------------------------
       
   334 // CAspProgressDialog::HideButtonL
       
   335 //
       
   336 // -----------------------------------------------------------------------------
       
   337 //
       
   338 void CAspProgressDialog::HideButtonL()
       
   339     {
       
   340     const TInt KLastButtonIndex = 2;
       
   341     
       
   342    	CEikButtonGroupContainer& container = iProgressDialog->ButtonGroupContainer();
       
   343 	
       
   344 	container.RemoveCommandFromStack(KLastButtonIndex, EAknSoftkeyCancel);
       
   345 	container.AddCommandToStackL(KLastButtonIndex, EAknSoftkeyEmpty, KNullDesC);
       
   346 	container.DrawDeferred();
       
   347     }
       
   348 
       
   349 
       
   350 // ----------------------------------------------------------------------------
       
   351 // CAspProgressDialog::SetApplicationId
       
   352 // 
       
   353 // ----------------------------------------------------------------------------
       
   354 //
       
   355 void CAspProgressDialog::SetApplicationId(TInt aApplicationId)
       
   356 	{
       
   357 	iApplicationId = aApplicationId;
       
   358 	}
       
   359 
       
   360 
       
   361 
       
   362 
       
   363 
       
   364 /*******************************************************************************
       
   365  * class CAspProgressDialog2
       
   366  *******************************************************************************/
       
   367 
       
   368 
       
   369 // -----------------------------------------------------------------------------
       
   370 // CAspProgressDialog2::CAspProgressDialog2
       
   371 //
       
   372 // -----------------------------------------------------------------------------
       
   373 //
       
   374 CAspProgressDialog2::CAspProgressDialog2(CEikDialog** aSelfPtr, TInt aApplicationId)
       
   375  : CAknProgressDialog(aSelfPtr)
       
   376 	{
       
   377 	FLOG( _L("CAspProgressDialog2::CAspProgressDialog2 START") );
       
   378 	
       
   379     iCloseEventReceived = EFalse;
       
   380     iCancelEventReceived = EFalse;
       
   381     iClosed = EFalse;
       
   382     iCanceled = EFalse;
       
   383 	iApplicationId = aApplicationId;
       
   384 	
       
   385 	if (iApplicationId != EApplicationIdSync)
       
   386 		{
       
   387 		// to make sure that wserv does not change our priority even we lose foreground.
       
   388 	    // this is needed for receiving event EKeyPhoneEnd without delay.
       
   389 	    
       
   390 	    RWsSession& wsSession = iEikonEnv->WsSession();
       
   391 	    wsSession.ComputeMode(RWsSession::EPriorityControlDisabled);
       
   392 	    
       
   393 	    FLOG( _L("RWsSession::ComputeMode(RWsSession::EPriorityControlDisabled)") );
       
   394 	    
       
   395 		}
       
   396 		
       
   397 	FLOG( _L("CAspProgressDialog2::CAspProgressDialog2 END") );
       
   398 	}
       
   399 
       
   400 
       
   401 // -----------------------------------------------------------------------------
       
   402 // Destructor
       
   403 //
       
   404 // -----------------------------------------------------------------------------
       
   405 //
       
   406 CAspProgressDialog2::~CAspProgressDialog2()
       
   407     {
       
   408     FLOG( _L("CAspProgressDialog2::~CAspProgressDialog2 START") );
       
   409 
       
   410 	if (iApplicationId != EApplicationIdSync)
       
   411 		{
       
   412 		RWsSession& wsSession = iEikonEnv->WsSession();
       
   413 	    wsSession.ComputeMode(RWsSession::EPriorityControlComputeOff);
       
   414 	    
       
   415 	    FLOG( _L("RWsSession::ComputeMode(RWsSession::EPriorityControlComputeOff)") );
       
   416 		}
       
   417 
       
   418     if (iAvkonAppUi)
       
   419         {
       
   420         iAvkonAppUi->RemoveFromStack(this);
       
   421         }
       
   422 
       
   423 	FLOG( _L("CAspProgressDialog2::~CAspProgressDialog2 END") );
       
   424     }
       
   425 
       
   426 
       
   427 // -----------------------------------------------------------------------------
       
   428 // CAspProgressDialog2::OkToExitL
       
   429 //
       
   430 // -----------------------------------------------------------------------------
       
   431 //
       
   432 TBool CAspProgressDialog2::OkToExitL(TInt aButtonId)
       
   433     {
       
   434     FLOG( _L("CAspProgressDialog2::OkToExitL START") );
       
   435     
       
   436     // close key handling
       
   437     if (iCloseEventReceived && !iClosed)
       
   438         {
       
   439    	    if (iCallback)
       
   440    	    	{
       
   441    	    	TRAP_IGNORE(iCallback->DialogDismissedL(EKeyPhoneEnd));
       
   442    	    	
       
   443    	    	FLOG( _L("CAspProgressDialog2::OkToExitL: close handling done") );
       
   444   	    	}
       
   445    		    
       
   446         if (iAvkonAppUi)
       
   447             {
       
   448             // prevent further close events
       
   449             iAvkonAppUi->RemoveFromStack(this);
       
   450             }
       
   451             
       
   452         FLOG( _L("CAspProgressDialog2::OkToExitL END") );
       
   453 
       
   454         iClosed = ETrue;
       
   455         return ETrue;
       
   456         }
       
   457 
       
   458     // cancel key handling
       
   459     if (aButtonId == EEikBidCancel && iCancelEventReceived && !iCanceled && !iClosed)
       
   460         {
       
   461         if (iCallback)
       
   462         	{
       
   463         	TRAP_IGNORE(iCallback->DialogDismissedL(EEikBidCancel));
       
   464         	
       
   465         	FLOG( _L("CAspProgressDialog2::OkToExitL: cancel key handling done") );
       
   466         	}
       
   467         
       
   468 		FLOG( _L("CAspProgressDialog2::OkToExitL END") );
       
   469 		
       
   470 		iCanceled = ETrue;
       
   471 		return EFalse; // leave dialog open - let observer close it
       
   472 		}
       
   473 
       
   474 
       
   475     FLOG( _L("CAspProgressDialog2::OkToExitL END") );
       
   476     
       
   477     return CAknProgressDialog::OkToExitL(aButtonId);
       
   478     }
       
   479 
       
   480 
       
   481 // ----------------------------------------------------------------------------
       
   482 // CAspProgressDialog2::OfferKeyEventL
       
   483 // 
       
   484 // ----------------------------------------------------------------------------
       
   485 //
       
   486 TKeyResponse CAspProgressDialog2::OfferKeyEventL(const TKeyEvent& aKeyEvent,TEventCode aType)
       
   487 	{
       
   488 	FLOG( _L("CAspProgressDialog2::OfferKeyEventL START") );
       
   489 	
       
   490 	if (aKeyEvent.iScanCode == EStdKeyDevice1)
       
   491 		{
       
   492 		iCancelEventReceived = ETrue;
       
   493 		FLOG( _L("CAspProgressDialog2::OfferKeyEventL: EStdKeyDevice1 received") );
       
   494      	}
       
   495 		
       
   496 
       
   497 	if (aType == EEventKey)
       
   498 		{
       
   499 		switch (aKeyEvent.iCode)
       
   500 			{
       
   501 
       
   502             case EKeyEscape:  // iCode 27 (0x1b)
       
   503             	{
       
   504             	iCloseEventReceived = ETrue;
       
   505             	FLOG( _L("CAspProgressDialog2::OfferKeyEventL: EKeyEscape received") );
       
   506             	break;
       
   507             	}
       
   508             	
       
   509             case EKeyPhoneEnd:
       
   510              	{
       
   511              	iCloseEventReceived = ETrue;
       
   512                 FLOG( _L("CAspProgressDialog2::OfferKeyEventL: EKeyPhoneEnd received") );
       
   513                 break;
       
   514                	}
       
   515 
       
   516             default:
       
   517                 FLOG( _L("event key code is %d"),  aKeyEvent.iCode);        
       
   518 			    break;
       
   519 			}
       
   520 		}
       
   521 
       
   522 
       
   523     FLOG( _L("CAspProgressDialog2::OfferKeyEventL END") );
       
   524     
       
   525 	return CAknProgressDialog::OfferKeyEventL(aKeyEvent, aType);
       
   526 	}
       
   527 
       
   528 
       
   529 
       
   530 
       
   531 //  End of File