#ifndef TESTER_H
#define TESTER_H

#include <QtGui/QMainWindow>
#include "ui_tester.h"
#include "NpClient.h"
#include "GridsView.h"
#include "NuuoGLRenderer.h"
#include <vector>
#include <list>

#ifdef WIN32
#include "PlaySnd/IPlaySound.h"
#endif

class CGridsView;
class NuuoGLRenderer;
class Tester;

struct stSession
{
    Np_ID id;
    void* session;
    Tester* pInst;
    int width;
    int height;
};

class ExportCbInfo
{
public: 
    Np_ID id;
    Np_ExportError error; 
    unsigned int percent;
    int iFormatChangedIndex;

    ExportCbInfo(Np_ID _id, Np_ExportError _error, unsigned int _percent, int _iFormatChangedIndex)
    : id(_id)
    , error(_error)
    , percent(_percent)
    , iFormatChangedIndex(_iFormatChangedIndex)
    {
    }
};

class Tester : public QMainWindow
{
    Q_OBJECT

public:
    Tester(QWidget *parent = 0, Qt::WFlags flags = 0);
    ~Tester();

/************************************************************************/
/*  Functions                                                           */
/************************************************************************/
    void convertTime(QDateTime src, Np_DateTime& dst);
    void showResult(Np_Result_t result);
    void showText(QString text);
    void showLog(Np_Log log);
    void showCfgLog(Np_ConfigurationLog log);
    void showOpLog(Np_OperationLog log);
    void showRecordDateList(Np_RecordDateList dateList);
    void showRecordLogItem(Np_RecordLogItem logItem);
    void showRecordLogs(Np_RecordLogList logList);
    void showSchduleType(Np_ScheduleType schType);
    void showScheduleLogItem(Np_ScheduleLogItem logItem);
    void showScheduleLogs(Np_ScheduleLogList logList);
    void showTime(QString title, Np_DateTime time);
    void showEvent(Np_Event event);
    void showEventList(Np_EventList eventList);
    void showWString(QString title,std::wstring str);
    void showID(QString title,Np_ID ID);
    void showSubDevice(Np_SubDevice device);
    void showDevice(Np_Device device);
    void showDeviceGroup(Np_DeviceGroup group);
    void showDeviceList(Np_DeviceList list);
    void showStreamProfile(Np_StreamProfile streamProfile);
    void showSensorProfile(Np_SensorProfile sensorProfile);
    void showSensorProfileList(Np_SensorProfileList sensorProfileList);
    void showPTZCapability(Np_SubDevice device);
    void showPTZPreset(Np_PTZPreset ptzPreset);
    void showPTZPresetList(Np_PTZPresetList ptzPresetList);
    void SetPBFileOpen(bool bFileOpen);
    void PutExportCbInfo(Np_ID id, Np_ExportError error, unsigned int percent, int iFormateChangedIndex);
    CGridsView* m_pGridsView;    
    NuuoGLRenderer* m_pRender;    
    Np_PixelFormat m_videoPixelFmt;

public slots:
/************************************************************************/
/*  General Tab Slot                                                    */
/************************************************************************/

    void onCreateHandle();
    void onGetDeviceList();
    void onGetLog();
    void onGetRecordDateList();
    void onGetRecordLogs();
    void onGetScheduleLogs();
    void onQueryEvents();
    void onSubscribeEvent();
    void onUnsubscribeEvent();
    void onDestroyHandle();
    void onTestGeneral();
    void onSnapShot();
    void onSnapShotPath();

/************************************************************************/
/*  Liveview Tab Slot                                                   */
/************************************************************************/

    void onCreateLVPlayer();
    void onAttachSession();
    void onDetachSession();
    void onSetAudioOn();
    void onSetAudioOff();
    void onDestroyLVPlayer();
    void onTestLiveview();
    void onPTZLeft();
    void onPTZDown();
    void onPTZUp();
    void onPTZRight();
    void onPTZHome();
    void onZoomIn();
    void onZoomOut();
    void onFocusFar();
    void onFocusNear();
    void onGetPTZPreset();
    void onPresetGo();
    void onPresetSet();
    void onPresetClear();
    void onGetDIStatus();
    void onGetDOStatus();
    void onControlDigitalOutput();
    void onGetSensorProfileList();
/************************************************************************/
/*  Playback Tab Slot                                                   */
/************************************************************************/

    void onCreatePBPlayer();
    void onAttachPBSession();
    void onDetachPBSession();
    void onPBSeek();
    void onPBOpenRecord();
    void onPBSetSpeed();
    void onPBPause();
    void onPBPlay();
    void onPBReverse();
    void onPBForward();
    void onPBBackward();
    void onPBNext();
    void onPBPrevious();    
    void onDestroyPBPlayer();   
    void onTestPlayBack();
    void onPBExport();
    void onPBStopExport();
    void onPBExportPath();

/************************************************************************/
/*  timer                                                               */
/************************************************************************/

    void OnUpdateFrame();
    void OnUpdateUI();
    void OnUpdateExportStatus();
    //slot end
private:
    void StopPTZ(Np_PTZControlParam ptzControlParam, const Np_PTZContinuousMove& ptzMoveCommand);
    void SetPlaybackButtonStatus(bool bFileOpen);
    void SetLiveviewPTZUIStatus(const Np_ID* camID);
    void TesterSleep(long long mSec);
    void AdjustTesterUI();
    void SetExportProfileList();
    void AddWaterMarkAfterExport(Np_ID id, int iFormatChangedIndex);
    QString GetCameraName(Np_ID id);

private:
    QTimer m_FrameUpdateTimer;
    QTimer m_UpdateUItimer;
    Ui::TesterClass ui;
    void* m_handle;
    void* m_eventsession;
    void* m_lvplayer;    
    void* m_pbplayer;
    std::vector<stSession*> m_pbsessions;
    bool  m_bPBFileOpen;

    std::vector<stSession*> m_lvsessions;
    Np_DeviceList           m_deviceList;

    std::list<ExportCbInfo> m_exptcbinfos;
    QMutex                  m_exptcbmutex;
    stSession               m_exptctx;
    bool  m_bExporting;
#ifdef WIN32
public:
    IPlaySound*		m_SoundDev;
#endif
};

#endif // TESTER_H
