#ifndef RECORDPLUGIN_H__
#define	RECORDPLUGIN_H__

#include "ritkApplicationPlugin.h"
#include "RecordPluginWidget.h"

#include "ritkRImageFileWriter.h"

/**	@class	RecordPlugin
 *	@author	Jakob Wasza
 *	@brief	Plugin that provides recording functionalities
 *
 *	@details
 *	Plugin that is used to record a range image sequence or to capture
 *	a background image using long-time exposure (time averaging).
 */
class RecordPlugin : public ritk::ApplicationPlugin
{
	Q_OBJECT

public:
	/// Constructor
	RecordPlugin();
	/// Destructor
	~RecordPlugin();

	/// Get the name @sa Plugin::GetName
	QString GetName();

	/// Get the plugins GUI @sa Plugin::GetPluginGUI
	QWidget *GetPluginGUI();

	/// Intercept the event.
	void ProcessEvent(ritk::Event::Pointer EventP);

signals:
	/// Signals the widget to update its frame counter
	void SetFrameCounter(long Num);
	/// Signal to update preview widget
	void UpdatePreviewWidget();

protected slots:
	/// Start recording
	void StartRecording();
	/// Stop recording
	void StopRecording();
	/// Preview mode
	void SetPreview(bool Enable);
	/// Connected to the snapshot button
	void DoSnapshot();
	void UpdateFilename(int state);
	void UpdateRadioButton(QString);

	/// Connected to the PNGs button
	void WritePNGs(bool value);
	void SavePNG();

	/// Save current frame as *.txt
	void WriteTXTs(bool value);
	void SaveTXT();

	/// Save current frame as *.txt
	void SaveFrameTXT();
	/// Connected to the widgets set output directory push button
	void PushButtonSetOutputDirectoryClicked();

protected:
	/// Our widget
	RecordPluginWidget *m_Widget;

	/// Mutex used to lock member access
	QMutex m_MemberMutex;

	/// Flag that indicates whether preview is enabled
	bool m_PreviewFlag;

	/// Flag that indicates whether the stream should be saved as pngs, too
	bool m_PNGFlag;
	bool m_TXTFlag;

	/// Flag that indicates whether we're recording
	bool m_RecordFlag;
	bool m_FirstFilenameChange;

	/// The current filename for recording
	QString m_RecordFileName;

	/// The current filename for snapshots
	QString m_PNGTXTFileName;

	/// User defined filename string
	QString m_CustomFileName;

	/// The current directory for recording
	QString m_DirectoryName;

	/// Counter for the frame number for recording
	long m_RecordFrameCounter;
	
	/// The current range image
	ritk::RImageF2::ConstPointer m_CurrentFrame;

	///
	int m_FilenameState;


	/**	@name	The file writers */
	//@{
	typedef ritk::RImageFileWriterF2 WriterType;
	typedef WriterType::Pointer WriterPointer;
	WriterPointer m_RecordWriter;
	WriterPointer m_FrameWriterTXT;
	//@}

	/// The output directory for saving a frame
	QString m_OutputDirectory;
	
};

#endif // RECORDPLUGIN_H__