/*
 * GlDialogPostepu.h
 * Autor: Pawe Gala
 */

#ifndef __GLDIALOGPOSTEPU_H__
#define __GLDIALOGPOSTEPU_H__

#include "GlobalneOknoDialogowe.h"


class CAknGlobalProgressDialog;

class CGlDialogPostepu : public CGlobalneOknoDialogowe
    {
public:    // Konstruktory dwufazowe i destruktor
    static CGlDialogPostepu* NewL( TUint aId, MObserwatorDialogu& aObserwator );
    static CGlDialogPostepu* NewLC( TUint aId, MObserwatorDialogu& aObserwator );
    
    ~CGlDialogPostepu();
    
public:
    void WyswietlDialogL( TInt aPrzyciskiResId, const TDesC& aTekst );
    void UaktualnijPostepL( TInt aWartoscAktualna, TInt aWartoscKoncowa );
    void ZadanieWykonane();
    
private:   // Odziedziczone z CGlobalneOknoDialogowe
    void DoCancel();
    
private:   // Konstruktory pierwszej i drugiej fazy
    CGlDialogPostepu( TUint aId, MObserwatorDialogu& aObserwator );
    void ConstructL();
    
private:   // Pola
    CAknGlobalProgressDialog* iGlProgressDialog;
    };

#endif /* __GLDIALOGPOSTEPU_H__ */


/*
 * GlDialogPostepu.cpp
 * Autor: Pawe Gala
 */

#include <aknglobalprogressdialog.h>
#include "GlDialogPostepu.h"


CGlDialogPostepu* CGlDialogPostepu::NewL( TUint aId, MObserwatorDialogu& aObserwator )
    {
    CGlDialogPostepu* self = CGlDialogPostepu::NewLC( aId, aObserwator );
    CleanupStack::Pop( self );
    return self;
    }

CGlDialogPostepu* CGlDialogPostepu::NewLC( TUint aId, MObserwatorDialogu& aObserwator )
    {
    CGlDialogPostepu* self = new( ELeave ) CGlDialogPostepu( aId, aObserwator );
    CleanupStack::PushL( self );
    self->ConstructL();
    return self;
    }
    
CGlDialogPostepu::CGlDialogPostepu( TUint aId, MObserwatorDialogu& aObserwator )
:CGlobalneOknoDialogowe( aId, aObserwator )
    {
    }

CGlDialogPostepu::~CGlDialogPostepu()
    {
    Cancel();
    delete iGlProgressDialog;
    }

void CGlDialogPostepu::ConstructL()
    {
    iGlProgressDialog = CAknGlobalProgressDialog::NewL();
    }
    
void CGlDialogPostepu::WyswietlDialogL( TInt aPrzyciskiResId, const TDesC& aTekst )
    {
    iGlProgressDialog->ShowProgressDialogL( iStatus, aTekst, aPrzyciskiResId );
    SetActive();
    }

void CGlDialogPostepu::UaktualnijPostepL( TInt aWartoscAktualna, TInt aWartoscKoncowa )
    {
    __ASSERT_DEBUG( aWartoscAktualna > 0, User::Leave( KErrArgument ) );
    __ASSERT_DEBUG( aWartoscKoncowa > 0, User::Leave( KErrArgument ) );
    
    iGlProgressDialog->UpdateProgressDialog( aWartoscAktualna, aWartoscKoncowa );
    }

void CGlDialogPostepu::ZadanieWykonane()
    {
    iGlProgressDialog->ProcessFinished();
    }
    
void CGlDialogPostepu::DoCancel()
    {
    iGlProgressDialog->CancelProgressDialog();
    }


// ----------------
// Uycie klasy CGlDialogOstrzegawczy
// ----------------

#include <avkon.rsg>
#include "GlDialogPostepu.h"

// Wymagana biblioteka: aknnotify.lib
// ...

const TUint KIdDialogu = 5;
iDialog = CGlDialogPostepu::NewL( KIdDialogu, *iObserwatorDialogu );

_LIT( KTekst, "Verification in progress..." );
iDialog->WyswietlDialogL( R_AVKON_SOFTKEYS_CANCEL, KTekst );

// ...

// Do 100%
for( TInt i=1; i <= 100; i++ )
    {
    NastepnyKrokWeryfikacji(); // 1%
    iDialog->UaktualnijPostepL( i, 100 );
    }

// Zamykamy dialog.
iDialog->ZadanieWykonane();
