/*******************************************************************************
*                                                                              *
* Société de Transports de Montréal.                                    	   *
* 2012                                                                         *
*                                                                              *
* Projet Zones Tests                                                           *
*                                                                              *
*                                                                              *
*                                                                              *
*******************************************************************************/
/*
    Description:
    Description du fichier si nécessaire.
    
*/

/* ************************************************************************** */
/* Revision:
### 20121210 JFM
    Verision d'origine.
    
### YYYYMMDD Description du besoin ou du bug
    Description du changement.
 */

/* ************************************************************************** */

#ifndef OUTILZT_H
#define OUTILZT_H
#include "MainPanel.h"
#include "LogMgr.h"
#include "ZTData.h"
#include "Settings.h"
#include "TCPProtocol.h"
#include "ZTLogFilesMgr.h"



class COutilZT : public QObject
{
    Q_OBJECT
public:

    typedef enum
    {
        MODE_DATABASE,
        MODE_NETWORK,
        MODE_ZTLOG,
        MODE_INVALID
    }OutilZTMode;


    COutilZT();
    ~COutilZT();

    unsigned int Start();

    QString GetLogDataPath();
    QString GetTrainLogsTempPath();
    void CleanTrainLogsTempPath();

    static QString GetStationName(int StationID);

    bool IsEngMode(){return mIsEngMode;}

    //CLogList requests
    void LogViewRequest(CLogElement* Element, CLogsListPage* caller);
    unsigned int SetLogProtection(bool protection, CLogElement* Element, CLogsListPage *caller);

    //CLogView requests
    void LogViewCloseRequest(CLogViewPage *caller);

    //CMainPage requests
    void ShowOptionsRequest();
    void HideOptionsRequest();
    void ShowDatabaseMgrRequest();
    void HideDatabaseMgrRequest();

    void EnterDatabaseModeRequest();
    void EnterNetworkModeRequest();
    void EnterZTLogModeRequest();
    void ShowZTLogRequest(QString Log, QString FocusText, int line = -1);

    //Networkmode page requests
    void ShowNetworkModeLogViewRequest();
    void HideNetworkModeLogViewRequest();
    void ShowRemoteTrainLogsViewPages();
    void ShowRemoteControlPage();
    void ShowRemoteLiveZTPage();

    //Settings page requests
    unsigned int DataSourceDirChanged(QString NewPath);
    unsigned int NetworkDataChanged();

    //DatabaseManager page requests
    unsigned int LogsDatabaseChanged(QStringList *NewLogs);
    unsigned int ZTLogFilesChanged();
    unsigned int RebuildDatabaseFile();

    //LogManager requests
    unsigned int LogsDatabaseLoaded(CLogMgr *Caller, int Status);
    unsigned int UpdateLogsList(CLogMgr *Caller);
    unsigned int DatabaseFetchingBegin(CLogMgr *Caller);
    unsigned int DatabaseFetchingTick(CLogMgr *Caller,int Index);



    //ZTLogFilesPage requests
    unsigned int ShowZTLogFile(QString FilePath);

    //ZTLogFilesMgr requests
    unsigned int ZTLogFilesDatabaseLoaded(CZTLogFilesMgr *Caller, int Status);
    unsigned int ZTLogFilesFetchingBegin(CZTLogFilesMgr *Caller);
    unsigned int ZTLogFilesFetchingTick(CZTLogFilesMgr *Caller, int Index, QString File = "");


    //Network requests
    unsigned int ConnectToZTRequest();
    unsigned int DisconnectZTRequest();
    unsigned int RxStationName(QString StationName);
    unsigned int RefreshRemoteZTStatusRequest();
    unsigned int RxZTStatus(const CTCPZTStatus &status);
    unsigned int DownloadZTLogRequest();
    unsigned int RxZTLog(QString ZTLog);
    unsigned int DownloadTrainLogsRequest();
    unsigned int DownloadTrainLogsBegin(int NbLogs);
    unsigned int RxTrainLogData(QString FileName);
    unsigned int RxTrainLogsDownloadFinished();
    unsigned int DeleteRemoteZTLogRequest();
    unsigned int RemoteZTLogDeleted(bool Success);
    unsigned int SetZTFunctionsStatus(CTCPZTFunctionsStatus status);
    unsigned int SetZTFunctionsSatusDone(bool succes);


    bool mIsEngMode;
    bool mCanImport;
    bool mRebuildingDB;


private:
    unsigned int InitZT();

    Panel panel;
    CLogMgr mDatabaseModeLogManager;
    CLogMgr mNetworkModeLogManager;
    CSettingsFileMgr mSettingsFileMgr;
    CSettingsData mSettingsData;
    CZTLogFilesMgr mZTLogFilesManager;

    OutilZTMode mOutilZTMode;


protected:
	bool eventFilter(QObject *obj, QEvent *event);

};

#endif // OUTILZT_H
