photosgallery/viewframework/uiutilities/src/glxprogressindicator.cpp
branchRCL_3
changeset 14 ce1c7ad1f18b
child 18 bcb43dc84c44
equal deleted inserted replaced
13:71da52165949 14:ce1c7ad1f18b
       
     1 /*
       
     2 * Copyright (c) 2008-2009 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:    Progressdialog 
       
    15 *
       
    16 */
       
    17 #include "glxprogressindicator.h"
       
    18 #include <glxtracer.h>
       
    19 #include <glxlog.h>
       
    20 #include <StringLoader.h>
       
    21 #include <AknProgressDialog.h>
       
    22 #include <eikprogi.h>
       
    23 #include <e32property.h>
       
    24 #include <glxuiutilities.rsg>
       
    25 #include "glxuiutility.h"
       
    26 const TInt KPeriodicStartDelay = 500000;
       
    27 
       
    28 
       
    29 // ---------------------------------------------------------
       
    30 // CGlxProgressIndicator::NewL
       
    31 // ---------------------------------------------------------
       
    32 //  
       
    33 EXPORT_C CGlxProgressIndicator* CGlxProgressIndicator::NewL
       
    34                     (MDialogDismisedObserver& aGlxGridViewNotifyObserver)
       
    35     {
       
    36     CGlxProgressIndicator* self = CGlxProgressIndicator::NewLC
       
    37                                                 (aGlxGridViewNotifyObserver);
       
    38     CleanupStack::Pop(self);
       
    39     return self;
       
    40     }
       
    41 
       
    42 // ---------------------------------------------------------
       
    43 // CGlxProgressIndicator::NewLC
       
    44 // ---------------------------------------------------------
       
    45 //  
       
    46 CGlxProgressIndicator* CGlxProgressIndicator::NewLC
       
    47                     (MDialogDismisedObserver& aGlxGridViewNotifyObserver)
       
    48     {
       
    49     
       
    50     CGlxProgressIndicator* self = new(ELeave)
       
    51                     CGlxProgressIndicator(aGlxGridViewNotifyObserver);
       
    52     CleanupStack::PushL(self);
       
    53     self->ConstructL();
       
    54     return self;
       
    55     }
       
    56 
       
    57 // ---------------------------------------------------------
       
    58 // CGlxProgressIndicator::CGlxProgressIndicator
       
    59 // ---------------------------------------------------------
       
    60 // 
       
    61 CGlxProgressIndicator::CGlxProgressIndicator
       
    62           (MDialogDismisedObserver& aGlxGridViewNotifyObserver)
       
    63                     :iGlxGridViewNotifyObserver(aGlxGridViewNotifyObserver)
       
    64     {
       
    65     }
       
    66 
       
    67 // ---------------------------------------------------------
       
    68 // CGlxProgressIndicator::~CGlxProgressIndicator
       
    69 // ---------------------------------------------------------
       
    70 //
       
    71 CGlxProgressIndicator::~CGlxProgressIndicator()
       
    72     {
       
    73     if (iProgressbarTicker && iProgressbarTicker->IsActive())
       
    74         {
       
    75         iProgressbarTicker->Cancel();
       
    76         delete iProgressbarTicker;
       
    77         }
       
    78     if(iProgressDialog)
       
    79         {
       
    80         iProgressDialog->ProcessFinishedL();
       
    81         }
       
    82 
       
    83 	// Stop force generation of thumbnails when progress dialog is dismissed
       
    84 	CGlxUiUtility* uiUtility = CGlxUiUtility::UtilityL();
       
    85     CleanupClosePushL(*uiUtility);
       
    86 	if ( uiUtility )
       
    87 		{
       
    88 		uiUtility->StopTNMDaemonL();
       
    89 		}
       
    90     CleanupStack::PopAndDestroy(uiUtility);
       
    91     }
       
    92 
       
    93 // ---------------------------------------------------------
       
    94 // CGlxProgressIndicator::ConstructL
       
    95 // ---------------------------------------------------------
       
    96 //
       
    97 void CGlxProgressIndicator::ConstructL()
       
    98     {
       
    99     CGlxUiUtility* uiUtility = CGlxUiUtility::UtilityL();
       
   100     CleanupClosePushL(*uiUtility);
       
   101     TRAPD(err,uiUtility->StartTNMDaemonL());
       
   102 
       
   103     if(err != KErrNone)
       
   104         {
       
   105         GLX_LOG_INFO1("CGlxProgressIndicator RProperty::Set errorcode %d",err);
       
   106         //need to check what to do in fail cases
       
   107         }
       
   108     if(!iProgressbarTicker)
       
   109         {
       
   110         iProgressbarTicker = CPeriodic::NewL(CActive::EPriorityStandard);
       
   111         }
       
   112 
       
   113     iFinalCount = uiUtility->GetItemsLeftCountL();
       
   114     GLX_LOG_INFO1("final count in viewactivate = %d",iFinalCount);
       
   115     
       
   116 
       
   117     if(iFinalCount)
       
   118         {
       
   119         StartProgressNoteL(iFinalCount,ETrue);
       
   120         if ( !iProgressbarTicker->IsActive())
       
   121             {
       
   122             iProgressbarTicker->Start( KPeriodicStartDelay, KPeriodicStartDelay, TCallBack( 
       
   123                     &PeriodicCallbackL, static_cast<TAny*>( this ) ) );
       
   124             }            
       
   125          }
       
   126     else
       
   127         {
       
   128         GLX_LOG_INFO("Reset the RProperty flag to EFalse");
       
   129         uiUtility->StopTNMDaemonL();
       
   130         }
       
   131     CleanupStack::PopAndDestroy(uiUtility);
       
   132     }
       
   133 
       
   134 
       
   135 // -----------------------------------------------------------------------------
       
   136 // Callback from periodic timer
       
   137 // -----------------------------------------------------------------------------
       
   138 //
       
   139 TInt CGlxProgressIndicator::PeriodicCallbackL(TAny* aPtr )
       
   140     {
       
   141     TRACER("CGlxProgressIndicator::PeriodicCallbackL");
       
   142     static_cast< CGlxProgressIndicator* >( aPtr )->DisplayProgressBarL();
       
   143     return KErrNone;
       
   144     }
       
   145 
       
   146 // -----------------------------------------------------------------------------
       
   147 // Callback from periodic timer-- non static
       
   148 // -----------------------------------------------------------------------------
       
   149 //
       
   150 inline void CGlxProgressIndicator::DisplayProgressBarL()
       
   151     {
       
   152     TRACER("CGlxProgressIndicator::DisplayProgressBarL");
       
   153     CGlxUiUtility* uiUtility = CGlxUiUtility::UtilityL();
       
   154     CleanupClosePushL(*uiUtility);
       
   155     TInt itemsLeft = uiUtility->GetItemsLeftCountL();
       
   156     CleanupStack::PopAndDestroy(uiUtility);
       
   157     GLX_LOG_INFO1("itemsLeft in DisplayProgressBarL = %d",iFinalCount);
       
   158     if(itemsLeft)
       
   159         {
       
   160         UpdateProgressBar();
       
   161         }
       
   162     else
       
   163         {
       
   164         if(iProgressbarTicker->IsActive())
       
   165             {
       
   166             iProgressbarTicker->Cancel();
       
   167             }
       
   168         StartProgressNoteL(iFinalCount,EFalse);
       
   169         }
       
   170     }
       
   171 
       
   172 // -----------------------------------------------------------------------------
       
   173 // StartProgressNoteL
       
   174 // -----------------------------------------------------------------------------
       
   175 //
       
   176 void CGlxProgressIndicator::StartProgressNoteL(TInt aFinalValue,TBool aShow)
       
   177     {
       
   178     TRACER("CGlxProgressIndicator::StartProgressNoteL()");
       
   179     
       
   180     if(aShow)
       
   181         {
       
   182         if(!iProgressDialog)
       
   183             {
       
   184             iProgressDialog = new (ELeave)CAknProgressDialog((reinterpret_cast<CEikDialog**> (&iProgressDialog)),ETrue);
       
   185             }
       
   186         iProgressDialog->PrepareLC(R_PROGRESS_NOTE);
       
   187         
       
   188         iProgressInfo = iProgressDialog->GetProgressInfoL();
       
   189         
       
   190         iProgressDialog->SetCallback(this);
       
   191         
       
   192         HBufC* processingInfo = 
       
   193                     StringLoader::LoadLC(R_GLX_MAIN_LIST_VIEW_PROCESSING_DIALOG);
       
   194         iProgressDialog->SetTextL(*processingInfo);
       
   195         CleanupStack::PopAndDestroy(processingInfo );
       
   196         iProgressInfo->SetFinalValue(aFinalValue);
       
   197         
       
   198         iProgressDialog->RunLD();
       
   199         }
       
   200     else
       
   201         {
       
   202         iProgressDialog->ProcessFinishedL();
       
   203         if(iProgressDialog)
       
   204             {
       
   205             iProgressDialog = NULL;
       
   206             iProgressInfo = NULL;
       
   207             }
       
   208         }
       
   209      
       
   210     }
       
   211     
       
   212 // -----------------------------------------------------------------------------
       
   213 // UpdateProgressBar
       
   214 // -----------------------------------------------------------------------------
       
   215 //
       
   216 void CGlxProgressIndicator::UpdateProgressBar()
       
   217     {   
       
   218     TRACER("CGlxProgressIndicator::UpdateProgressBar()");
       
   219     if(iProgressInfo)
       
   220         {
       
   221         /*
       
   222          * to show a number string in the progress bar use the below code
       
   223          * in rss it should have %d or %N format
       
   224          * TBuf<256> text;
       
   225          * GlxGeneralUiUtilities::FormatString(text,*processingInfo,-1,count,ETrue);
       
   226          * CleanupStack::PopAndDestroy(processingInfo); 
       
   227          */
       
   228         iProgressInfo->SetAndDraw(CalculateDisplayBarIncrementL());
       
   229         }
       
   230     }
       
   231     
       
   232 // -----------------------------------------------------------------------------
       
   233 // DialogDismissedL
       
   234 // -----------------------------------------------------------------------------
       
   235 //  
       
   236 void CGlxProgressIndicator::DialogDismissedL(TInt aButtonId)
       
   237     {
       
   238     TRACER("CGlxProgressIndicator::DialogDismissedL()");
       
   239     CGlxUiUtility* uiUtility = CGlxUiUtility::UtilityL();
       
   240     CleanupClosePushL(*uiUtility);
       
   241     uiUtility->StopTNMDaemonL();
       
   242     CleanupStack::PopAndDestroy(uiUtility);
       
   243     if(iProgressbarTicker)
       
   244         {
       
   245         iProgressbarTicker->Cancel();
       
   246         delete iProgressbarTicker;
       
   247         iProgressbarTicker = NULL;
       
   248         }
       
   249 
       
   250     if (aButtonId == EAknSoftkeyCancel)
       
   251         {
       
   252         // cancel any process in here 
       
   253         iGlxGridViewNotifyObserver.HandleDialogDismissedL();
       
   254         }
       
   255     if(iProgressDialog)
       
   256         {
       
   257         iProgressDialog = NULL;
       
   258         iProgressInfo = NULL;
       
   259         }    
       
   260     }
       
   261 
       
   262 // -----------------------------------------------------------------------------
       
   263 // CalculateDisplayBarIncrementL
       
   264 // -----------------------------------------------------------------------------
       
   265 //  
       
   266 TInt CGlxProgressIndicator::CalculateDisplayBarIncrementL()
       
   267     {
       
   268     TRACER("CGlxProgressIndicator::CalculateDisplayBarIncrement()");
       
   269     CGlxUiUtility* uiUtility = CGlxUiUtility::UtilityL();
       
   270     CleanupClosePushL(*uiUtility);
       
   271     TInt itemsLeft = uiUtility->GetItemsLeftCountL();
       
   272     CleanupStack::PopAndDestroy(uiUtility);
       
   273     GLX_LOG_INFO1("CalculateDisplayBarIncrement = %d ",(iFinalCount - itemsLeft));
       
   274     
       
   275     if(iFinalCount < itemsLeft)
       
   276         {
       
   277         iProgressInfo->SetFinalValue( itemsLeft );
       
   278         iFinalCount = itemsLeft;
       
   279         }
       
   280     
       
   281     return (iFinalCount - itemsLeft);
       
   282     }