#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QMainWindow>

#include "common.h"
#include "commondata.h"

#include "qrtspthread.h"
#include "sthreadimagesave.h"
#include "sthreadwatchvideolink.h"

#include <QTimer>
#include "dialogprogress.h"

#include "dialogmisscapture.h"

#include "formscreensaver.h"

#include <QElapsedTimer>


#include "sthreadwatchport.h"

QT_BEGIN_NAMESPACE
namespace Ui { class MainWindow; }
QT_END_NAMESPACE

class MainWindow : public QMainWindow
{
    Q_OBJECT

public:
    MainWindow(QWidget *parent = nullptr);
    ~MainWindow();

    void DeleteUI();

    void SetDisplayType(int nType);

    void SetRTSPThread(QRTSPThread* pThread);
    void SetThreadCaptureImage(SThreadImageSave* pThread);
    void SetThreadSendDICOM(SThreadSendDICOM* pThread);

    void UpdateSendInfo(int nCount, int nTotalCount);
    void UpdateSendComplete();

    void UpdateMakeDICOMInfo(int nCurrent, int nTotal);


    static MainWindow* GetMainWindow();
    static CommonData* GetCommonData();

    void ClearHistoryView();

    QWidget* GetFormCapture();

    int GetCurrentWidgetID();

    virtual void keyReleaseEvent(QKeyEvent *event);



    void ResetScreenSaverTimer();
    void StartScreenSaverTimer();
    void StopScreenSaverTimer();


    void SetDisplayError(int nTypeError);

    void MountDiskUSB(QString strDeviceMount, QString strLocationMount);
    void UmountDiskUSB(QString strLocationMount);

    void CommandSudo(QString strCommand);

public:
    virtual void resizeEvent(QResizeEvent *event);

public slots:
    void SetDisplayError(QString strError);

    void ViewDialogMissCapture();
    void CaptureHandSwitch();
    void CaptureFootSwitch();
    void UpdateSendFailed();
    void UpdateAutoSendDICOMFailed();
    void BackupNetworkShareFolder(QString strFilename);
    void ChangeMenu(int nID);
    void ExitCapture();
    void ErrorCapture();
    void ExitViewer();
    void DeferredInit();

    void CheckDiskUSB();

    void ViewerChangeFocusCheck();

    void Exit();

    void WatchPowerButton();

    void CompleteCleanStorage();

    void MissCapture();

    void CompleteAcquisitionFromHistory();
    void LoadInfoAcquisitionFromHistory(int nCurrent, int nTotal);

    void CheckShowScreenSaver();

    void WriteLogTimer();

signals:
    void SendCaptureHandSwitch();
    void SendCaptureFootSwitch();

protected:
    SThreadWatchPort* m_pThreadWatch;
    FormScreenSaver* m_pScreenSaver;
    int m_nDisplayType;
    QTimer m_TimerScreenSaver;
    QTimer m_Timer;
    QTimer m_TimerWatchPowerButton;
    QTimer m_TimerMissCapture;
    QTimer m_TimerLog;
    QTimer m_TimerCheckDiskUSB;
    bool m_bMountDiskUSB;
    QElapsedTimer m_TimeCheckScreenSaver;
    static MainWindow* m_pMainWindow;

    static CommonData* m_pCommonData;

    vector<QWidget*> m_ListWidget;
    int m_nCurrentMenuID;
    int m_nCurrentWidgetID;

    DialogProgress* m_pDialogStorageClean;

    DialogMissCapture* m_pDialogMissCapture;

    int m_nTypeError;

    QProcess* m_pProcessNode;

private:
    Ui::MainWindow *ui;
};
#endif // MAINWINDOW_H
