#ifndef MULTI_IPNC_DEMO_H
#define MULTI_IPNC_DEMO_H

#include <QtGui/QMainWindow>
#include <QtGui/QStandardItem>
#include <QtGui/QMenu>
#include <QtCore/QEvent>
#include <QtCore/QTimer>
#include <QList>
#include "ui_multi_ipnc_demo.h"
#include "nss_toolkit.h"
#include "demo_util.h"
#include "q_video_widget.h"
#include "q_debugview.h"
#include "qremote_playback.h"
#include "modify_device.h"
#include "app_settings.h"

#include <string>

#define MAX_STREAM_PER_CHANNEL (2)
#define MAX_CHANNEL (2)

class multi_ipnc_demo : public QMainWindow,
    public QVideoPanelLabel::VideoPanelDelegate
{
    Q_OBJECT

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

    static void Init(multi_ipnc_demo* ins) {instance_ = ins;}

    void PlayVideo(NsstChannel* nsst_channel);

    void CloseVideo(NsstChannel* nsst_channel);

    DEVICE_ID device_id() const { return device_id_; }

    static multi_ipnc_demo* instance() {return instance_;}

    AppSettings::DeviceInfo* device_info() { return &device_info_; }

    void ShowStatus(STATUS_LOG_LEVEL level,const QString& qstr);
signals:
    void SignalOnLogin(int,int,int);

    void SignalOnSDKCommonEvent(int event_type,NsstEventCommonParam* event_param);

public slots:
    void OnTreeContextMenuRequested(const QPoint &pos);

    void OnlineTreeViewDoubleClick(const QModelIndex & index);

    void OnlineTreeViewClick(const QModelIndex & index);

    void OnVideoPanelMousePress(QVideoPanelLabel* panel_label);

    void OnVideoPanelDblClick(QVideoPanelLabel* panel_label);

    void OnFullScreenClick();

    void OnVideoStatusShowHideClick();

    void OnDebugViewClick();
    void OnUpgradeClick();
    void OnPlaybackClick();

    void OnShowFPSClick();
    void OnCloseFPSClick();

    void OnTestMediaClick();
    void OnStopTestMediaClick();

    void OnClickUrl(const QUrl & url);

    void OnPTZUpPress();
    void OnPTZDownPress();
    void OnPTZLeftPress();
    void OnPTZRightPress();
    void OnPTZLeftTopPress();
    void OnPTZLeftDownPress();
    void OnPTZRightTopPress();
    void OnPTZRightDownPress();
    void OnPTZIrisOnPress();
    void OnPTZIrisOffPress();
    void OnPTZWiperOnPress();
    void OnPTZWiperOffPress();
    void OnPTZLightOnPress();
    void OnPTZLightOffPress();

    void DoPTZStop();

    void OnPTZAutoClick();

    void SlotShowModifyDeviceInfo();

    void SlotOnCallPreset();

    void SlotOnAddPreset();

    void SlotOnDeletePreset();

    void SlotOnZoomBig();

    void SlotOnZoomSmall();

    void SlotOnFocusNear();

    void SlotOnFocusFar();

    void SlotOnFTPAnonyChanged(int state);

    void DoLogin();
    void DoLogout();

    void DoConnect();
    void DoDisconnect();

    void DoConnectAll();
    void DoDisconnectAll();

    void DoOpenAudio();
    void DoCloseAudio();

    void DoStartTalk();
    void DoStopTalk();

    void DoRestartRecvMessage();

    void SlotOnVideoKeyPress(int key);

    void SlotOnSDKCommonEvent(int event_type,NsstEventCommonParam* event_param);

    void SlotOnGetCameraParams();
    void SetCameraParams();

    void SlotOnGetNetConfig();
    void SlotOnSetNetConfig();

    void SlotOnGetMac();
    void SlotOnSetMac();

    void SlotOnGetVAConfig();
    void SlotOnSetVAConfig();

    void SlotOnGetDeviceDetails();

    void SlotOnGetTimeConfig();
    void SlotOnSetTimeConfig();

    void SlotOnSetEZoom();
    void SlotOnResetEZoom();

    void SlotOnGetFocusConfig();
    void SlotSetFocusConfig(int val);

    void SlotOnVAPageChanged(int index);
    void SlotOnCameraPageChanged(int index);
    void SlotOnTabPageChanged(int index);

    void SlotOnExposureModeChanged(int val);
    
    void SlotOnGetIrisConfig();
    void SlotOnSetIrisConfig();

    void SlotOnGetDenoiseConfig();

    void SlotOnGetWhiteBalance();
    void SlotOnSetWhiteBalance();

    void SlotOnGetCameraOthers();
    void SlotOnSetCameraOthers();

    void SlotOnGetAudioInput();
    void SlotOnSetAudioInput();

    void SlotOnGetOSD();
    void SlotOnSetOSD();
    
    void SlotOnGetDDNS();
    void SlotOnSetDDNS();

    void SlotOnGetPPPoE();
    void SlotOnSetPPPoE();

    void SlotOnGetFtp();
    void SlotOnSetFtp();

    void SlotOnGetUPnP();
    void SlotOnSetUPnP();

    void SlotOnGetPort();
    void SlotOnSetPort();

    void SlotOnGetEmail();
    void SlotOnSetEmail();

    void SlotOnGetAuth();
    void SlotOnSetAuth();

    void SlotOnGetIPFilter();
    void SetIPFilter();
    void SlotOnDeleteIPFilter();
    void SlotOnAddIPFilter();

    void SlotOnSaveSchedule();

    void SlotSaveMotionTrigger();

    void SlotOnClearMotionArea();
    void SlotOnSaveMotionArea();

    void SlotOnSetIRLed();

    void SlotOnStartSeq();
    void SlotOnStopSeq();
    void SlotOnSaveSeq();
    void SlotOnDelSeq();
    void SlotOnClearSeq();
    void SlotOnAddSeq();
    void SlotOnSeqListChanged(int index);
    void SlotOnDDNSAliasChanged(int index);

    void SlotOnStartPattern();
    void SlotOnStopPattern();
    void SlotOnStartRecordPattern();
    void SlotOnStopRecordPattern();
    void PTZPattern(int control);

    void SlotOnStartScan();
    void SlotOnStopScan();
    void SlotOnSetScanLeft();
    void SlotOnSetScanRight();
    void SlotOnDeleteScan();
    void PTZScan(int control);

    void SlotSetUser();
    void SlotDeleteUser();
    void SlotGetUsers();
    void SlotClickUserList(int row, int column);

    void SlotOnTboxPTZChanged(int index);

    void SlotOnSyncTime(int state);

    void SlotOnSliderSpeedChanged(int speed);

    void HandleAlarmSchedule(int val);
    void HandleAlarmScheduleType(int val);

    void SlotOnBrightnessChanged(int val);
    void SlotOnContrastChanged(int val);
    void SlotOnSaturationChanged(int val);
    void SlotOnSharpnessChanged(int val);
    void SlotOnHueChanged(int val);

    void SlotOnWBGainChanged(int val);

    void SlotOnVDenoiseChanged(int val);

    void SlotOnDayNightChanged(int val);
    void SlotOnWDRChanged(int val);
    void SlotOnMirrorChanged(int val);
    void SlotOnVideoStandardChanged(int val);
    void SlotOnLocalOutputChanged(int val);

    void SlotOnSaveRecSchedule();
    void HandleRecordSchedule(int val);
    void HandleRecordScheduleType(int val);

    void SlotOnVideoPanelWheel(int channel,int delta);

    void SlotOnReboot();
    void SlotOnSimpleRestore();
    void SlotOnCompleteRestore();

    void SlotOnCaptureQuotaChanged(int val);
    void SlotOnSaveCaptureConfig();

    void SlotOnGetPortInput(int val);
    void SlotOnGetPortOutput(int val);
    void SlotOnGetException(int val);
    void SlotSavePortInput();
    void SlotSavePortOutput();
    void SlotSaveException();
    void RebuildPortChannel();

    void SlotOnFormatDevices();
    void SlotOnSaveQuota();
    void SlotOnGetStoragePage();
    void CloseGetStoragePage();
    void TimerGetStorageDevices();

    void OnTimerTestMedia();

    void PTZControl(int action);
private:
    Ui::multi_ipnc_demoClass ui;

    QDebugview* qdbg_;

    QRemotePlayback* ui_playback_;

    bool grid_show_full_;

    bool ptz_auto_;

    bool client_show_full_;

    modify_device  ui_modify_device_;

    NsstDeviceDetails  device_details_;

    QList<QCheckBox*> motion_trigger_output_;
    QList<QCheckBox*> exp_trigger_output_;
    QList<QCheckBox*> portin_trigger_output_;
    QList<QTimeEdit*> schedule_start_;
    QList<QTimeEdit*> schedule_end_;
    QList<QCheckBox*> schedule_copy_;

    QList<QTimeEdit*> rec_schedule_start_;
    QList<QTimeEdit*> rec_schedule_end_;
    QList<QCheckBox*> rec_schedule_copy_;
    QList<QComboBox*> rec_type_group_;

    static multi_ipnc_demo*  instance_;

    NsstDDNS* ddnslist_;

    QVideoWidget*  video_widget_[MAX_CHANNEL][MAX_STREAM_PER_CHANNEL];

    //QList<QStandardItem*> row_items_;
    QStandardItemModel* standard_model_;

    int sel_channel_;
    int sel_stream_;

    AppSettings::DeviceInfo  device_info_;

    QTimer* timer_move_stop_;

    QTimer* timer_restart_recv_message_;

    QTimer* timer_get_storage_devices_;

    QTimer* timer_test_media_;

    QStandardItem* first_item_;

    DEVICE_ID device_id_;

    QMenu* menu_device_;
    QMenu* menu_channel_;

    NsstPTZParam ptz_status_;

    int ptz_channel_;

    NsstAlarmSchedule alarm_schedule_[NS_ALARM_TYPE_COUNT];

    NsstRecordSchedule  record_schedule_;

    //////////////////////////////////////////////////////////////////////////

    void CreateDevice();

    void ReleaseDevice();

    bool GetSelectedStreamInfo(NsstChannel* nsst_channel);

    void InitObject();

    void CloseOSDDraw();
    void CloseAlarmGridDraw();

    void ShowCommonLog(NsstEventCommonParam* event_param,const QString& log);

    void HandleAlarmTrigger(NsstAlarmTrigger* trigger,int channel);
    void HandleMotionTrigger(NsstAlarmTrigger* trigger,int channel);
    void HandleMaskTrigger(NsstAlarmTrigger* trigger,int channel);
    void HandlePortInputTrigger(NsstAlarmTrigger* trigger,int channel);
    void HandleExceptionTrigger(NsstAlarmTrigger* trigger,int channel);
    //////////////////////////////////////////////////////////////////////////
    virtual void resizeEvent(QResizeEvent *);
    virtual void closeEvent(QCloseEvent *);
};

#endif // MULTI_IPNC_DEMO_H
