/////////////////////////////////////////////////////////////////////////////
// Name:        downloadprogresspanel.h
// Purpose:     wxDownloadProgressPanel definition
// Author:      Francesco Montorsi
// Modified by: 
// Created:     15/07/2006 16:25:14
// RCS-ID:      $Id: downloadprogresspanel.h,v 1.3 2007/01/20 22:53:26 frm Exp $
// Copyright:   (c) 2006 Francesco Montorsi
// Licence:     wxWidgets license
/////////////////////////////////////////////////////////////////////////////

#ifndef _PMDOWNLOADPROGRESSPANEL_H_
#define _PMDOWNLOADPROGRESSPANEL_H_

/*!
 * Includes
 */

#include "guipm/progresspanel.h"
#include "wx/hyperlink.h"
#include "wx/animate.h"
#include "wx/oscopectrl.h"


/*!
 * Control identifiers
 */

////@begin control identifiers
#define SYMBOL_WXDOWNLOADPROGRESSPANEL_STYLE 0
#define SYMBOL_WXDOWNLOADPROGRESSPANEL_TITLE _("Dialog")
#define SYMBOL_WXDOWNLOADPROGRESSPANEL_IDNAME wxID_ANY
#define SYMBOL_WXDOWNLOADPROGRESSPANEL_SIZE wxSize(400, 300)
#define SYMBOL_WXDOWNLOADPROGRESSPANEL_POSITION wxDefaultPosition
#define ID_DOWNLOADPROGRESS_TIMELEFT 10015
#define ID_DOWNLOADPROGRESS_ELAPSEDTIME 10042
#define ID_DOWNLOADPROGRESS_SIZE 10070
#define ID_DOWNLOADPROGRESS_SPEED 10071
#define ID_DOWNLOADPROGRESS_SOURCE 10012
#define ID_DOWNLOADPROGRESS_DESTINATION 10044
#define ID_DOWNLOADPROGRESS_ANIMATION 10072
#define ID_DOWNLOADPROGRESS_SPEEDLOG 10073
#define ID_DOWNLOADPROGRESS_GAUGE 10001
////@end control identifiers

#define ID_DOWNLOADPROGRESS_THREAD               11000
#define ID_DOWNLOADPROGRESS_TIMER                11001
#define ID_DOWNLOADPROGRESS_TIMER_INTERVAL       1000   // 1 sec


// ----------------------------------------------------------------------------
// wxDownloadProgressPanel
// ----------------------------------------------------------------------------

class wxDownloadProgressPanel: public wxProgressPanel
{    
    DECLARE_DYNAMIC_CLASS( wxDownloadProgressPanel )
    DECLARE_EVENT_TABLE()

public:
    /// Constructors
    wxDownloadProgressPanel( );
    wxDownloadProgressPanel( wxWindow* parent, wxWindowID id = SYMBOL_WXDOWNLOADPROGRESSPANEL_IDNAME, const wxPoint& pos = SYMBOL_WXDOWNLOADPROGRESSPANEL_POSITION, const wxSize& size = SYMBOL_WXDOWNLOADPROGRESSPANEL_SIZE, long style = SYMBOL_WXDOWNLOADPROGRESSPANEL_STYLE );

    /// Creation
    bool Create( wxWindow* parent, wxWindowID id = SYMBOL_WXDOWNLOADPROGRESSPANEL_IDNAME, const wxPoint& pos = SYMBOL_WXDOWNLOADPROGRESSPANEL_POSITION, const wxSize& size = SYMBOL_WXDOWNLOADPROGRESSPANEL_SIZE, long style = SYMBOL_WXDOWNLOADPROGRESSPANEL_STYLE );

    /// Creates the controls and sizers
    void CreateControls();

    /// Should we show tooltips?
    static bool ShowToolTips();

    virtual ~wxDownloadProgressPanel()
    {
        // if not stopped, stop now
        Stop();
    }


public:     // event handlers

    void OnDownloadUserAbort(wxDownloadEvent &ev);
    void OnDownloadAbort(wxDownloadEvent &ev);
    void OnDownloadComplete(wxDownloadEvent &ev);
    void OnDownloadProgress(wxDownloadEvent &ev);
    void OnTimer(wxTimerEvent &ev);

public:
	
    virtual void Start();
    virtual void Stop();
    virtual bool IsProcessing() const;

    wxString GetLogData() const;
    wxString GetLogLabel() const;

    bool IsSuccessful() const
        { return m_bSuccess; }

	virtual void SetPackage(const wxPackage &pkg);

    void ClearControls();

    // little helper:
    void DoEnd(bool success);

protected:

    // true if last download was successful
    bool m_bSuccess;

    // true if the download thread is currently running
    volatile bool m_bThreadExists;

    // current status of the download thread
    wxDownloadThreadFlag m_flag;

    // the animation which is played when downloading
    wxAnimation m_animation;

    // the timer used to update the oscope control
    wxTimer m_timer;

    // used on timer events to update the oscope control
    wxULongLong m_nLastSpeed;

protected:		// controls

	wxHyperlinkCtrl *m_pSource;
    wxStaticText* m_pRemainingTime;
    wxStaticText* m_pElapsedTime;
    wxStaticText* m_pDestination;
    wxStaticText* m_pSize;
    wxStaticText* m_pSpeed;
    wxGauge* m_pGauge;
    wxAnimationCtrl* m_pAnimation;
    wxOScopeCtrl *m_pOScope;
};

#endif
    // _PMDOWNLOADPROGRESSPANEL_H_
