// DlgRTSPLauncher.cpp : 구현 파일입니다.
//

#include "stdafx.h"
#include "NZSDK_Sample.h"
#include "DlgRTSPLauncher.h"


// CDlgRTSPLauncher 대화 상자입니다.

IMPLEMENT_DYNAMIC(CDlgRTSPLauncher, CDialog)

CDlgRTSPLauncher::CDlgRTSPLauncher(CWnd* pParent /*=NULL*/)
	: CDialog(CDlgRTSPLauncher::IDD, pParent)
{
	for( int i=0; i<MAX_VIEWER; i++ )
		m_viewer[i].Create( CDlgRTSPViewer::IDD );
}

CDlgRTSPLauncher::~CDlgRTSPLauncher()
{
}

BOOL CDlgRTSPLauncher::OnInitDialog()
{
	CDialog::OnInitDialog();

	((CEdit*)GetDlgItem(IDC_EDIT_ADDR))->SetWindowText(_T("192.168.1.203"));
	((CEdit*)GetDlgItem(IDC_EDIT_RTSP_PORT))->SetWindowText(_T("554"));
	//((CEdit*)GetDlgItem(IDC_EDIT_URL))->SetWindowText(_T("1/stream1"));
	((CEdit*)GetDlgItem(IDC_EDIT_URL))->SetWindowText(_T("8/stream1"));
	((CEdit*)GetDlgItem(IDC_EDIT_ID))->SetWindowText(_T("admin"));
	((CEdit*)GetDlgItem(IDC_EDIT_PW))->SetWindowText(_T("admin"));

	return TRUE;  // return TRUE  unless you set the focus to a control
}

void CDlgRTSPLauncher::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
}


BEGIN_MESSAGE_MAP(CDlgRTSPLauncher, CDialog)
	ON_BN_CLICKED(IDC_BUTTON_LAUNCH, OnBnClickedBtnLaunch)
END_MESSAGE_MAP()


// CDlgRTSPLauncher 메시지 처리기입니다.

void CDlgRTSPLauncher::OnBnClickedBtnLaunch()
{
	CString addr, port, url, id, pw;

	GetDlgItem(IDC_EDIT_ADDR)->GetWindowText(addr);
	GetDlgItem(IDC_EDIT_RTSP_PORT)->GetWindowText(port);
	GetDlgItem(IDC_EDIT_URL)->GetWindowText(url);
	GetDlgItem(IDC_EDIT_ID)->GetWindowText(id);
	GetDlgItem(IDC_EDIT_PW)->GetWindowText(pw);

	int index = -1;
	for( int i=0; i<MAX_VIEWER; i++ )
	{
		if( !m_viewer[i].m_running )
		{
			index = i;
			break;
		}
	}

	if( index >= 0 )
	{
		m_viewer[index].Run( addr, port, url, id, pw );
		m_viewer[index].ShowWindow( SW_SHOW );
	}
}

void CDlgRTSPLauncher::OnCancel()
{
	CDialog::OnCancel();
}


void CDlgRTSPLauncher::OnOK()
{
	OnBnClickedBtnLaunch();
}