profilesservices/MediaFileList/Src/mediafilewaitnote.cpp
changeset 18 e3554c9069b6
parent 4 3f8368f032cf
child 19 30540fccecae
equal deleted inserted replaced
4:3f8368f032cf 18:e3554c9069b6
     1 /*
       
     2 * Copyright (c) 2007 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:   Waiting note for query
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 // INCLUDE FILES
       
    21 #include "mediafilewaitnote.h"
       
    22 #include <mediafilelist.rsg>
       
    23 
       
    24 #include <eikprogi.h>
       
    25 #include <notecontrol.h>
       
    26 #include <aknappui.h>   // macro iAvkonAppUi
       
    27 
       
    28 
       
    29 
       
    30 
       
    31 
       
    32 /*******************************************************************************
       
    33  * class CMediaFileWaitNote
       
    34  *******************************************************************************/
       
    35 
       
    36 
       
    37 // -----------------------------------------------------------------------------
       
    38 // CMediaFileWaitNote::CMediaFileWaitNote
       
    39 //
       
    40 // -----------------------------------------------------------------------------
       
    41 //
       
    42 CMediaFileWaitNote::CMediaFileWaitNote( MMediaFileWaitNoteObserver* aObserver )
       
    43 : iObserver( aObserver )
       
    44     {
       
    45     }
       
    46 
       
    47 
       
    48 // -----------------------------------------------------------------------------
       
    49 // CMediaFileWaitNote::NewL
       
    50 //
       
    51 // -----------------------------------------------------------------------------
       
    52 //
       
    53 CMediaFileWaitNote* CMediaFileWaitNote::NewL( MMediaFileWaitNoteObserver* aObserver )
       
    54     {
       
    55     CMediaFileWaitNote* self = new (ELeave) CMediaFileWaitNote( aObserver );
       
    56     CleanupStack::PushL( self );
       
    57     self->ConstructL();
       
    58     CleanupStack::Pop( self );
       
    59 
       
    60     return( self );
       
    61     }
       
    62 
       
    63 
       
    64 // -----------------------------------------------------------------------------
       
    65 // CMediaFileWaitNote::ConstructL
       
    66 //
       
    67 // -----------------------------------------------------------------------------
       
    68 //
       
    69 void CMediaFileWaitNote::ConstructL()
       
    70     {
       
    71     iObserverCallNeeded = ETrue;
       
    72     iDialogDismissed = EFalse;
       
    73     iLastText = KNullDesC;
       
    74 	iAnimation = EFalse;
       
    75     iImageFile = KNullDesC;
       
    76     } 
       
    77 
       
    78 
       
    79 // -----------------------------------------------------------------------------
       
    80 // Destructor
       
    81 //
       
    82 // -----------------------------------------------------------------------------
       
    83 //
       
    84 CMediaFileWaitNote::~CMediaFileWaitNote()
       
    85     {
       
    86     delete iProgressDialog;
       
    87     }
       
    88 
       
    89 
       
    90 // -----------------------------------------------------------------------------
       
    91 // CMediaFileWaitNote::LaunchL
       
    92 //
       
    93 // -----------------------------------------------------------------------------
       
    94 //
       
    95 void CMediaFileWaitNote::LaunchL( const TDesC& aLabel )
       
    96     {
       
    97     if ( iProgressDialog )
       
    98         {
       
    99         // CAknNoteDialog::~CAknNoteDialog sets iProgressDialog to NULL after:
       
   100         // 1. CAknProgressDialog::ProcessFinishedL is called
       
   101         // 2. dialog is closed using Cancel button
       
   102         return;
       
   103         }
       
   104     
       
   105     iObserverCallNeeded = ETrue;
       
   106     iDialogDismissed = EFalse;
       
   107     
       
   108     iProgressDialog = new(ELeave) 
       
   109     CAknProgressDialog( reinterpret_cast<CEikDialog**>(&iProgressDialog), EFalse );
       
   110     
       
   111     iProgressDialog->PrepareLC( R_MEDIA_FILE_WAIT_NOTE );
       
   112     iProgressDialog->SetTextL( aLabel );
       
   113     
       
   114     if ( iImageFile.Length() > 0 )
       
   115         {
       
   116         CEikImage* image = TMFDialogUtil::CreateImageLC( iImageId, iImageFile,
       
   117                            iBitmapId,  iBitmapMaskId );
       
   118         iProgressDialog->SetImageL( image );
       
   119         CleanupStack::Pop( image );
       
   120         }
       
   121 
       
   122     // get reference to progress info bar
       
   123     //iProgressInfo = iProgressDialog->GetProgressInfoL();
       
   124 
       
   125     iProgressDialog->SetCallback( this );
       
   126     
       
   127     iProgressDialog->RunLD();
       
   128     }
       
   129 
       
   130 
       
   131 // -----------------------------------------------------------------------------
       
   132 // CMediaFileWaitNote::SetImageL
       
   133 //
       
   134 // -----------------------------------------------------------------------------
       
   135 //
       
   136 void CMediaFileWaitNote::SetImageL( TAknsItemID aId, const TDesC& aImageFile,
       
   137                                     TInt aBitmapId, TInt aBitmapMaskId )
       
   138 	{
       
   139 	if ( aImageFile.Length() > iImageFile.MaxLength() )
       
   140         {
       
   141         return;
       
   142         }
       
   143     iImageFile = aImageFile;
       
   144 	iImageId = aId;
       
   145 	iBitmapId = aBitmapId;
       
   146 	iBitmapMaskId = aBitmapMaskId;
       
   147     }
       
   148 
       
   149 
       
   150 // -----------------------------------------------------------------------------
       
   151 // CMediaFileWaitNote::CancelProgressDialogL
       
   152 //
       
   153 // -----------------------------------------------------------------------------
       
   154 //
       
   155 void CMediaFileWaitNote::CancelProgressDialogL()
       
   156     {
       
   157     // this function is called from CMediaFileDialog so there is no need 
       
   158     // to notify observer (CMediaFileDialog)
       
   159     iObserverCallNeeded = EFalse;
       
   160     
       
   161     if ( iDialogDismissed )
       
   162         {
       
   163         return; // dialog is already closed
       
   164         }
       
   165     
       
   166 	if ( !iProgressDialog )
       
   167 		{
       
   168 		return; // dialog is already closed
       
   169 		}
       
   170 		
       
   171 	iProgressDialog->ProcessFinishedL();
       
   172     }
       
   173 
       
   174 
       
   175 // -----------------------------------------------------------------------------
       
   176 // CMediaFileWaitNote::SetTextL
       
   177 //
       
   178 // -----------------------------------------------------------------------------
       
   179 //
       
   180 void CMediaFileWaitNote::SetTextL( const TDesC& aText )
       
   181     {
       
   182     if ( !iProgressDialog )
       
   183         {
       
   184         return;
       
   185         }
       
   186 
       
   187     if ( iLastText.Compare( aText ) == 0 )
       
   188 		{
       
   189 		return;  // text has not changed
       
   190 		}
       
   191     
       
   192     iProgressDialog->SetTextL( aText );
       
   193 	TMFDialogUtil::StrCopy( iLastText, aText );
       
   194     }
       
   195 
       
   196 
       
   197 // -----------------------------------------------------------------------------
       
   198 // CMediaFileWaitNote::SetProgress
       
   199 //
       
   200 // -----------------------------------------------------------------------------
       
   201 //
       
   202 void CMediaFileWaitNote::SetProgress( TInt aValue )
       
   203     {
       
   204 	if ( !iProgressDialog  || !iProgressInfo )
       
   205 	    {
       
   206 	    return;
       
   207 	    }
       
   208 
       
   209 	CEikProgressInfo::SInfo info = iProgressInfo->Info();
       
   210 
       
   211 	TInt val = aValue;
       
   212 	if ( val > info.iFinalValue )
       
   213 		{
       
   214 		val = info.iFinalValue;
       
   215 		}
       
   216 	
       
   217 	iProgressInfo->SetAndDraw( val );
       
   218     }
       
   219 
       
   220 
       
   221 // -----------------------------------------------------------------------------
       
   222 // CMediaFileWaitNote::SetFinalProgress
       
   223 //
       
   224 // -----------------------------------------------------------------------------
       
   225 //
       
   226 void CMediaFileWaitNote::SetFinalProgress( TInt aFinalValue )
       
   227 	{
       
   228     if ( !iProgressDialog  || !iProgressInfo )
       
   229         {
       
   230         return;
       
   231         }
       
   232 
       
   233     if ( aFinalValue < 0 )
       
   234     	{
       
   235     	iProgressInfo->SetFinalValue( 0 );
       
   236     	}
       
   237     else
       
   238     	{
       
   239     	iProgressInfo->SetFinalValue( aFinalValue );
       
   240     	}
       
   241     	
       
   242 	iProgressInfo->SetAndDraw( 0 );
       
   243 	}
       
   244 
       
   245 
       
   246 // -----------------------------------------------------------------------------
       
   247 // CMediaFileWaitNote::NoteControl
       
   248 //
       
   249 // -----------------------------------------------------------------------------
       
   250 //
       
   251 CAknNoteControl* CMediaFileWaitNote::NoteControl()
       
   252 	{
       
   253 	if ( !iProgressDialog )
       
   254 	    {
       
   255 	    return NULL;
       
   256 	    }
       
   257     CAknNoteControl* note = STATIC_CAST(CAknNoteControl*, iProgressDialog->ControlOrNull(EGeneralNote));
       
   258 
       
   259     return note;
       
   260 	}
       
   261 
       
   262 
       
   263 // -----------------------------------------------------------------------------
       
   264 // CMediaFileWaitNote::CancelAnimation
       
   265 //
       
   266 // -----------------------------------------------------------------------------
       
   267 //
       
   268 void CMediaFileWaitNote::CancelAnimation()
       
   269 	{
       
   270     iAnimation = EFalse;
       
   271 	CAknNoteControl* note = NoteControl();
       
   272 	if ( note )
       
   273 	    {
       
   274 	    note->CancelAnimation();
       
   275 	    }
       
   276     }
       
   277 
       
   278 
       
   279 // ----------------------------------------------------------------------------
       
   280 // CMediaFileWaitNote::StartAnimationL
       
   281 //
       
   282 // ----------------------------------------------------------------------------
       
   283 //
       
   284 void CMediaFileWaitNote::StartAnimationL()
       
   285 	{
       
   286     if ( !iAnimation )
       
   287 		{
       
   288 	    CAknNoteControl* note = NoteControl();
       
   289 	    if ( note )
       
   290 	        {
       
   291 	        note->StartAnimationL();
       
   292 	        iAnimation = ETrue;
       
   293 	        }
       
   294 		}
       
   295     }
       
   296 
       
   297 
       
   298 // -----------------------------------------------------------------------------
       
   299 // CMediaFileWaitNote::DialogDismissedL (From MProgressDialogCallback)
       
   300 //
       
   301 // -----------------------------------------------------------------------------
       
   302 //
       
   303 void CMediaFileWaitNote::DialogDismissedL( TInt aButtonId )
       
   304     {
       
   305     iDialogDismissed = ETrue;
       
   306     
       
   307     if ( !iObserver )
       
   308 		{
       
   309 		return;
       
   310 		}
       
   311 	
       
   312     if ( !iObserverCallNeeded )
       
   313         {
       
   314         return;
       
   315         }
       
   316     
       
   317     TRAP_IGNORE( iObserver->HandleWaitNoteL( aButtonId ) );
       
   318     }
       
   319 
       
   320 
       
   321 // -----------------------------------------------------------------------------
       
   322 // CMediaFileWaitNote::HideButtonL
       
   323 //
       
   324 // -----------------------------------------------------------------------------
       
   325 //
       
   326 void CMediaFileWaitNote::HideButtonL()
       
   327     {
       
   328     const TInt KLastButtonIndex = 2;
       
   329     
       
   330    	if ( !iProgressDialog )
       
   331    	    {
       
   332    	    return;
       
   333    	    }
       
   334    	
       
   335     CEikButtonGroupContainer& container = iProgressDialog->ButtonGroupContainer();
       
   336 	
       
   337 	container.RemoveCommandFromStack( KLastButtonIndex, EAknSoftkeyCancel );
       
   338 	container.AddCommandToStackL( KLastButtonIndex, EAknSoftkeyEmpty, KNullDesC );
       
   339 	container.DrawDeferred();
       
   340     }
       
   341 
       
   342 
       
   343 
       
   344 //  End of File