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

*/

/* ************************************************************************** */
/* Revision:
### 20131024 JFM
    Verision d'origine.

### YYYMMDD Description du besoin ou du bug
    Description du changement.
 */

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


#ifndef LOGSLISTPAGE_H
#define LOGSLISTPAGE_H

#include "GlobalDefine.h"
#include <QGraphicsWidget>
#include "Guipage.h"
#include <QString>
#include "PushButton.h"
#include "TextButtonWidget.h"
#include "LogMgr.h"
#include <QTableWidget>
#include <QCheckBox>
#include "USBDriveInterface.h"
#include <QCheckBox>

#define MAX_DETECTION_LIST_NBR 7

class CZoneTest;


class CLogFileArchiverThread : public QObject
{
	Q_OBJECT
public:
	CLogFileArchiverThread();
	void SetPathInfo(QString DrivePath,QString StationName);

	CLogMgr *mLogMgrHandle;

public slots:
	void ArchiveLogs();

private:

	QString mDrivePath;
	QString mStationName;


signals:
	void LogArchivingFinished();

};


class CLogsListPage : public CGuiPage
{
Q_OBJECT
public:
    virtual ~CLogsListPage();
	CLogsListPage(QGraphicsWidget *Parent = 0);


	CZoneTest *mProgramHandle;
	CLogMgr *mLogMgrHandle;

    unsigned int RefreshList(bool KeepSelectedCell = false);
	unsigned int BindPointers(CUSBDriveInterface *USBDriveIF);

	virtual void resizeEvent(QGraphicsSceneResizeEvent *event);
	virtual void mousePressEvent(QGraphicsSceneMouseEvent *event);
	virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent *event);

private:

	QGraphicsRectItem *mBackgroundRect;
	CTextButtonWidget *mCancelButton;
	QTableWidget *mLogsTable;
	QGraphicsTextItem *mSummaryText;
	CTextButtonWidget *mViewLogDataButton;
	CTextButtonWidget *mExportCSVLogButton;
	CTextButtonWidget *mArchiveFilesButton;
	QGraphicsTextItem *mInsertUSBKeyText;
    QCheckBox *mShowZT1ItemsChkBx, *mShowZT2ItemsChkBx, *mShowNoDetectionsChkBx, *mRemoveErrorLogsChkBx;
    QTimer *mListParsingTimer;
	CUSBDriveInterface *mUSBDrivePtr;
	QTimer *mUSBRefreshTimer;
	QCheckBox *mEraseFilesCheckbox;

	CLogFileArchiverThread *mLogArchiverWorkerThread;
	QThread *mLogArchiverThread;

	bool mShowZT1Items,mShowZT2Items,mShowNoDetections,mUSBDetected;

	void ClearTable();
	unsigned int ArchiveAllFiles();
	unsigned int DeleteAllFiles();
	void ShowItemSummary(CLogElement*);
	int GetCurSelectedItemIndexInTable(void);


public slots:
	void ButtonClicked(CTextButtonWidget *);
//	void LogsTableCellClicked(int, int);
    void CheckBoxClicked(int);
    void TableDoubleClicked(int,int);
    void ParsingTimerExipred();
	void CheckUSBKey();
	void LogsArchivingFinished();
//	void TableCurItemChanged(QTableWidgetItem*,QTableWidgetItem*);
	void LogsTableCellSelected(/*int, int*/);
    void NewTrainLogFileSaved(QString,bool);

};


#endif // LOGSLISTPAGE_H
