photosgallery/viewframework/uiutilities/src/glxprogressindicator.cpp
branchRCL_3
changeset 26 5b3385a43d68
child 27 34937ec34dac
equal deleted inserted replaced
25:8e5f6eea9c9f 26:5b3385a43d68
       
     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     TRACER("CGlxProgressIndicator::NewL()");
       
    37     CGlxProgressIndicator* self = CGlxProgressIndicator::NewLC(
       
    38             aGlxGridViewNotifyObserver);
       
    39     CleanupStack::Pop(self);
       
    40     return self;
       
    41     }
       
    42 
       
    43 // ---------------------------------------------------------
       
    44 // CGlxProgressIndicator::NewLC
       
    45 // ---------------------------------------------------------
       
    46 //  
       
    47 CGlxProgressIndicator* CGlxProgressIndicator::NewLC(
       
    48         MDialogDismisedObserver& aGlxGridViewNotifyObserver)
       
    49     {
       
    50     TRACER("CGlxProgressIndicator::NewLC()");
       
    51     CGlxProgressIndicator* self = new (ELeave) CGlxProgressIndicator(
       
    52             aGlxGridViewNotifyObserver);
       
    53     CleanupStack::PushL(self);
       
    54     self->ConstructL();
       
    55     return self;
       
    56     }
       
    57 
       
    58 // ---------------------------------------------------------
       
    59 // CGlxProgressIndicator::CGlxProgressIndicator
       
    60 // ---------------------------------------------------------
       
    61 // 
       
    62 CGlxProgressIndicator::CGlxProgressIndicator(
       
    63         MDialogDismisedObserver& aGlxGridViewNotifyObserver) :
       
    64     iGlxGridViewNotifyObserver(aGlxGridViewNotifyObserver)
       
    65     {
       
    66     }
       
    67 
       
    68 // ---------------------------------------------------------
       
    69 // CGlxProgressIndicator::~CGlxProgressIndicator
       
    70 // ---------------------------------------------------------
       
    71 //
       
    72 CGlxProgressIndicator::~CGlxProgressIndicator()
       
    73     {
       
    74     TRACER("CGlxProgressIndicator::~CGlxProgressIndicator()");
       
    75     if (iProgressbarTicker)
       
    76         {
       
    77         iProgressbarTicker->Cancel();
       
    78         delete iProgressbarTicker;
       
    79         iProgressbarTicker = NULL;
       
    80         }
       
    81 
       
    82     // Stop force generation of thumbnails when progress dialog is dismissed
       
    83     if (iUiUtility)
       
    84         {
       
    85         iUiUtility->StopTNMDaemon();
       
    86         iUiUtility->Close();
       
    87         }
       
    88     }
       
    89 
       
    90 // ---------------------------------------------------------
       
    91 // CGlxProgressIndicator::ConstructL
       
    92 // ---------------------------------------------------------
       
    93 //
       
    94 void CGlxProgressIndicator::ConstructL()
       
    95     {
       
    96     TRACER("CGlxProgressIndicator::ConstructL()");
       
    97     
       
    98     iUiUtility = CGlxUiUtility::UtilityL();
       
    99     
       
   100     iUiUtility->StartTNMDaemon();
       
   101 
       
   102     if (!iProgressbarTicker)
       
   103         {
       
   104         iProgressbarTicker = CPeriodic::NewL(CActive::EPriorityStandard);
       
   105         }
       
   106 
       
   107     iFinalCount = iUiUtility->GetItemsLeftCount();
       
   108     GLX_LOG_INFO1("final count in viewactivate = %d",iFinalCount);
       
   109     }
       
   110 
       
   111 
       
   112 // -----------------------------------------------------------------------------
       
   113 // Callback from periodic timer
       
   114 // -----------------------------------------------------------------------------
       
   115 //
       
   116 TInt CGlxProgressIndicator::PeriodicCallbackL(TAny* aPtr )
       
   117     {
       
   118     TRACER("CGlxProgressIndicator::PeriodicCallbackL");
       
   119     static_cast<CGlxProgressIndicator*> (aPtr)->DisplayProgressBarL();
       
   120     return KErrNone;
       
   121     }
       
   122 
       
   123 // -----------------------------------------------------------------------------
       
   124 // Callback from periodic timer-- non static
       
   125 // -----------------------------------------------------------------------------
       
   126 //
       
   127 inline void CGlxProgressIndicator::DisplayProgressBarL()
       
   128     {
       
   129     TRACER("CGlxProgressIndicator::DisplayProgressBarL");
       
   130     TInt itemsLeft = iUiUtility->GetItemsLeftCount();
       
   131     GLX_LOG_INFO2("DisplayProgressBarL itemsLeft (%d),iFinalCount (%d) ",
       
   132             itemsLeft,iFinalCount);
       
   133     UpdateProgressBar();
       
   134     if (!itemsLeft && (itemsLeft != KErrNotReady))
       
   135         {
       
   136         // stop TNM daemon once all the imgs are processed.
       
   137         iUiUtility->StopTNMDaemon();
       
   138         if (iProgressbarTicker->IsActive())
       
   139             {
       
   140             iProgressbarTicker->Cancel();
       
   141             }
       
   142         StartProgressNoteL(iFinalCount, EFalse);
       
   143         }
       
   144     }
       
   145 
       
   146 // -----------------------------------------------------------------------------
       
   147 // StartProgressNoteL
       
   148 // -----------------------------------------------------------------------------
       
   149 //
       
   150 void CGlxProgressIndicator::StartProgressNoteL(TInt aFinalValue, TBool aShow)
       
   151     {
       
   152     TRACER("CGlxProgressIndicator::StartProgressNoteL()");
       
   153     //for MMC insert case need to know the count.so start Daemon.
       
   154     iUiUtility->StartTNMDaemon();
       
   155 
       
   156     TInt itemsLeft = iUiUtility->GetItemsLeftCount();
       
   157     if (aShow)
       
   158         {
       
   159         if (!iProgressDialog)
       
   160             {
       
   161             iProgressDialog = new (ELeave) CAknProgressDialog(
       
   162                     (reinterpret_cast<CEikDialog**> (&iProgressDialog)),
       
   163                     ETrue);
       
   164             }
       
   165         iProgressDialog->PrepareLC(R_PROGRESS_NOTE);
       
   166 
       
   167         iProgressInfo = iProgressDialog->GetProgressInfoL();
       
   168 
       
   169         iProgressDialog->SetCallback(this);
       
   170 
       
   171         HBufC* processingInfo = StringLoader::LoadLC(
       
   172                 R_GLX_MAIN_LIST_VIEW_PROCESSING_DIALOG);
       
   173         iProgressDialog->SetTextL(*processingInfo);
       
   174         CleanupStack::PopAndDestroy(processingInfo);
       
   175         iProgressInfo->SetFinalValue(aFinalValue);
       
   176         iProgressInfo->SetAndDraw(iFinalCount - itemsLeft);
       
   177         iProgressDialog->RunLD();
       
   178         }
       
   179     else
       
   180         {
       
   181         iProgressDialog->ProcessFinishedL();
       
   182         iGlxGridViewNotifyObserver.HandleDialogDismissedL();
       
   183         if (iProgressDialog)
       
   184             {
       
   185             iProgressDialog = NULL;
       
   186             iProgressInfo = NULL;
       
   187             }
       
   188         }
       
   189     }
       
   190     
       
   191 // -----------------------------------------------------------------------------
       
   192 // UpdateProgressBar
       
   193 // -----------------------------------------------------------------------------
       
   194 //
       
   195 void CGlxProgressIndicator::UpdateProgressBar()
       
   196     {
       
   197     TRACER("CGlxProgressIndicator::UpdateProgressBar()");
       
   198     if (iProgressInfo)
       
   199         {
       
   200         /*
       
   201          * to show a number string in the progress bar use the below code
       
   202          * in rss it should have %d or %N format
       
   203          * TBuf<256> text;
       
   204          * GlxGeneralUiUtilities::FormatString(text,*processingInfo,-1,count,ETrue);
       
   205          * CleanupStack::PopAndDestroy(processingInfo); 
       
   206          */
       
   207         iProgressInfo->SetAndDraw(CalculateDisplayBarIncrement());
       
   208         }
       
   209     }
       
   210     
       
   211 // -----------------------------------------------------------------------------
       
   212 // DialogDismissedL
       
   213 // -----------------------------------------------------------------------------
       
   214 //  
       
   215 void CGlxProgressIndicator::DialogDismissedL(TInt /*aButtonId*/)
       
   216     {
       
   217     TRACER("CGlxProgressIndicator::DialogDismissedL()");
       
   218     if (iProgressbarTicker)
       
   219         {
       
   220         iProgressbarTicker->Cancel();
       
   221         delete iProgressbarTicker;
       
   222         iProgressbarTicker = NULL;
       
   223         }
       
   224     iProgressDialog = NULL;
       
   225     iProgressInfo = NULL;
       
   226     }
       
   227 
       
   228 // -----------------------------------------------------------------------------
       
   229 // CalculateDisplayBarIncrement
       
   230 // -----------------------------------------------------------------------------
       
   231 //  
       
   232 TInt CGlxProgressIndicator::CalculateDisplayBarIncrement()
       
   233     {
       
   234     TRACER("CGlxProgressIndicator::CalculateDisplayBarIncrement()");
       
   235 
       
   236     TInt itemsLeft = iUiUtility->GetItemsLeftCount();
       
   237 
       
   238     if ((iFinalCount < itemsLeft) && (itemsLeft != KErrNotReady))
       
   239         {
       
   240         iProgressInfo->SetFinalValue(itemsLeft);
       
   241         iFinalCount = itemsLeft;
       
   242         }
       
   243     GLX_LOG_INFO1("CalculateDisplayBarIncrement = %d ",
       
   244             (iFinalCount - itemsLeft));
       
   245     // If TNM is still in harvesting mode, return 0.
       
   246     // When the actual count is coming return the difference to update the info-bar
       
   247     
       
   248     GLX_LOG_INFO1("CalculateDisplayBarIncrement = %d ",(iFinalCount - itemsLeft));
       
   249     return ((itemsLeft == KErrNotReady) ? 0 :(iFinalCount - itemsLeft));
       
   250     }
       
   251 
       
   252 // -----------------------------------------------------------------------------
       
   253 // ShowProgressbar
       
   254 // -----------------------------------------------------------------------------
       
   255 //
       
   256 void EXPORT_C CGlxProgressIndicator::ShowProgressbarL()
       
   257     {
       
   258     TRACER("CGlxProgressIndicator::ShowProgressbarL");
       
   259     TInt itemsLeft = iUiUtility->GetItemsLeftCount();
       
   260     GLX_DEBUG3("ShowProgressbarL itemsLeft(%d), iFinalCount(%d)", itemsLeft,
       
   261             iFinalCount);
       
   262 
       
   263     if (iFinalCount < itemsLeft)
       
   264         {
       
   265         /*
       
   266          *if user is in List view and inserts the MMC,update the total count 
       
   267          */
       
   268         iFinalCount = itemsLeft;
       
   269         }
       
   270 
       
   271     if ((itemsLeft == KErrNotReady) || iFinalCount)
       
   272         {
       
   273         StartProgressNoteL(iFinalCount, ETrue);
       
   274         if (!iProgressbarTicker)
       
   275             {
       
   276             iProgressbarTicker = CPeriodic::NewL(CActive::EPriorityStandard);
       
   277             }
       
   278         if (!iProgressbarTicker->IsActive())
       
   279             {
       
   280             iProgressbarTicker->Start(KPeriodicStartDelay,
       
   281                     KPeriodicStartDelay, TCallBack(&PeriodicCallbackL,
       
   282                             static_cast<TAny*> (this)));
       
   283             }
       
   284         }
       
   285     else
       
   286         {
       
   287         GLX_LOG_INFO("Reset the RProperty flag to EFalse");
       
   288         iUiUtility->StopTNMDaemon();
       
   289         }
       
   290     }
       
   291 
       
   292 // -----------------------------------------------------------------------------
       
   293 // DismissProgressDialog
       
   294 // -----------------------------------------------------------------------------
       
   295 //
       
   296 EXPORT_C void CGlxProgressIndicator::DismissProgressDialog()
       
   297     {
       
   298     TRACER("CGlxProgressIndicator::DismissProgressDialog");
       
   299 
       
   300     if (iProgressDialog)
       
   301         {
       
   302         TRAP_IGNORE(iProgressDialog->ProcessFinishedL());
       
   303         }
       
   304     }
       
   305 
       
   306 // -----------------------------------------------------------------------------
       
   307 // ControlTNDaemon
       
   308 // -----------------------------------------------------------------------------
       
   309 //
       
   310 EXPORT_C void CGlxProgressIndicator::ControlTNDaemon(TBool aStatus)
       
   311     {
       
   312     TRACER("CGlxProgressIndicator::ControlTNDaemon");
       
   313     GLX_DEBUG2("CGlxProgressIndicator::ControlTNDaemon(%d)", aStatus);
       
   314     if (aStatus)
       
   315         {
       
   316         iUiUtility->StartTNMDaemon();
       
   317         }
       
   318     else
       
   319         {
       
   320         iUiUtility->StopTNMDaemon();
       
   321         }
       
   322     }