// ContentsDlg.cpp : Implementation file
//

#include "stdafx.h"
#include "remotetest.h"
#include "ContentsDlg.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CContentsDlg  dialog


CContentsDlg::CContentsDlg(CVAIBO *vaibo, CWnd* pParent /*=NULL*/)
	: CDialog(CContentsDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CContentsDlg)
	m_strMWCID = _T("");
	//}}AFX_DATA_INIT
	m_vaibo = vaibo;
}


void CContentsDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CContentsDlg)
	DDX_Text(pDX, IDC_EDIT_MWCID, m_strMWCID);
	DDV_MaxChars(pDX, m_strMWCID, 16);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CContentsDlg, CDialog)
	//{{AFX_MSG_MAP(CContentsDlg)
	ON_BN_CLICKED(IDC_BTN_CONTENTS_PLAY, OnBtnContentsPlay)
	ON_BN_CLICKED(IDC_BTN_MWC_BROWSE, OnBtnMwcBrowse)
	ON_BN_CLICKED(IDC_BTN_AUDIO_BROWSE, OnBtnAudioBrowse)
	ON_BN_CLICKED(IDC_BTN_LED_BROWSE, OnBtnLedBrowse)
	ON_BN_CLICKED(IDC_BTN_MOTION_BROWSE, OnBtnMotionBrowse)
	ON_BN_CLICKED(IDC_BTN_AUDIO_SEND, OnBtnAudioSend)
	ON_BN_CLICKED(IDC_BTN_LED_SEND, OnBtnLedSend)
	ON_BN_CLICKED(IDC_BTN_MOTION_SEND, OnBtnMotionSend)
	ON_BN_CLICKED(IDC_BTN_MWC_SEND, OnBtnMwcSend)
	ON_BN_CLICKED(IDC_BTN_CONTENTS_UPDATE, OnBtnContentsUpdate)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CContentsDlg message handlers

void CContentsDlg::OnBtnContentsPlay()
{
	UpdateData(TRUE);
	if (m_vaibo->PlayContents(atoi(m_strMWCID)) == VAIBO_LIMIT_MWCID) {
		AfxMessageBox(_T("Invalid MWCID"));
	}
	UpdateData(FALSE);
}

void CContentsDlg::OnBtnMwcBrowse()
{
	CString		strFile;
	CFileDialog	dlg(TRUE, "MWC", NULL, OFN_FILEMUSTEXIST, NULL, this );

	if ( dlg.DoModal() == IDOK ) {
		strFile = dlg.GetPathName();
		editSendMWCFile().SetWindowText( strFile );
	}
}

void CContentsDlg::OnBtnAudioBrowse()
{
	CString		strFile;
	CFileDialog	dlg(TRUE, "ODA", NULL, OFN_FILEMUSTEXIST, NULL, this );

	if ( dlg.DoModal() == IDOK ) {
		strFile = dlg.GetPathName();
		editSendAUDIOFile().SetWindowText( strFile );
	}
}

void CContentsDlg::OnBtnLedBrowse()
{
	CString		strFile;
	CFileDialog	dlg(TRUE, "ODA", NULL, OFN_FILEMUSTEXIST, NULL, this );

	if ( dlg.DoModal() == IDOK ) {
		strFile = dlg.GetPathName();
		editSendLEDFile().SetWindowText( strFile );
	}
}

void CContentsDlg::OnBtnMotionBrowse()
{
	CString		strFile;
	CFileDialog	dlg(TRUE, "ODA", NULL, OFN_FILEMUSTEXIST, NULL, this );

	if ( dlg.DoModal() == IDOK ) {
		strFile = dlg.GetPathName();
		editSendMOTIONFile().SetWindowText( strFile );
	}
}

void CContentsDlg::OnButtonSendMwc()
{
	CString			strFile;
	int				err;
	CFile			file;
	unsigned long	size;

	editSendMWCFile().GetWindowText( strFile );
	if ( strFile.GetLength() < 1 ) {
		return;
	}

	if ( !file.Open( strFile, CFile::modeRead ) ) {
		return;
	}
	size = file.GetLength();
	file.Close();

	err = m_vaibo->FTPMMSendMWCFile(strFile);
	if ( err != VAIBO_NOERROR ) {
		AfxMessageBox(IDS_SENDCONTENTS_ERR);
		return;
	}
}

void CContentsDlg::OnBtnAudioSend()
{
	CString			strFile;
	int				err;
	CFile			file;
	unsigned long	size;

	editSendAUDIOFile().GetWindowText( strFile );
	if ( strFile.GetLength() < 1 ) {
		return;
	}

	if ( !file.Open( strFile, CFile::modeRead ) ) {
		return;
	}
	size = file.GetLength();
	file.Close();

	err = m_vaibo->FTPMMSendAUDIOFile(strFile);
	if ( err != VAIBO_NOERROR ) {
		AfxMessageBox(IDS_SENDCONTENTS_ERR);
		return;
	}
}

void CContentsDlg::OnBtnLedSend()
{
	CString			strFile;
	int				err;
	CFile			file;
	unsigned long	size;

	editSendLEDFile().GetWindowText( strFile );
	if ( strFile.GetLength() < 1 ) {
		return;
	}

	if ( !file.Open( strFile, CFile::modeRead ) ) {
		return;
	}
	size = file.GetLength();
	file.Close();

	err = m_vaibo->FTPMMSendLEDFile(strFile);
	if ( err != VAIBO_NOERROR ) {
		AfxMessageBox(IDS_SENDCONTENTS_ERR);
		return;
	}
}

void CContentsDlg::OnBtnMotionSend()
{
	CString			strFile;
	int				err;
	CFile			file;
	unsigned long	size;

	editSendMOTIONFile().GetWindowText( strFile );
	if ( strFile.GetLength() < 1 ) {
		return;
	}

	if ( !file.Open( strFile, CFile::modeRead ) ) {
		return;
	}
	size = file.GetLength();
	file.Close();

	err = m_vaibo->FTPMMSendMOTIONFile(strFile);
	if ( err != VAIBO_NOERROR ) {
		AfxMessageBox(IDS_SENDCONTENTS_ERR);
		return;
	}
}

void CContentsDlg::OnBtnMwcSend()
{
	CString			strFile;
	int				err;
	CFile			file;
	unsigned long	size;

	editSendMWCFile().GetWindowText( strFile );
	if ( strFile.GetLength() < 1 ) {
		return;
	}

	if ( !file.Open( strFile, CFile::modeRead ) ) {
		return;
	}
	size = file.GetLength();
	file.Close();

	err = m_vaibo->FTPMMSendMWCFile(strFile);
	if ( err != VAIBO_NOERROR ) {
		AfxMessageBox(IDS_SENDCONTENTS_ERR);
		return;
	}
}

void CContentsDlg::OnBtnContentsUpdate()
{
	UpdateData(TRUE);
	m_vaibo->UpdateContents();
	UpdateData(FALSE);
}
