// AdvancedSettingsDlg.cpp : implementation file
//

#include "stdafx.h"
#include "afxres.h"
#include "palmtool.h"
#include "UdpSocket.h"
#include "tcpsocket.h"
#include "AdvancedSettingsDlg.h"

#include "p_util.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CAdvancedSettingsDlg dialog


CAdvancedSettingsDlg::CAdvancedSettingsDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CAdvancedSettingsDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CAdvancedSettingsDlg)
	m_iRingVol = 0;
	m_iSpeakerIn = 0;
	//}}AFX_DATA_INIT
}


void CAdvancedSettingsDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CAdvancedSettingsDlg)
	DDX_Control(pDX, IDC_RINGTYPE, m_ctlRingType);
	DDX_Control(pDX, IDC_RING_VOL, m_ctlRingVol);
	DDX_Slider(pDX, IDC_RING_VOL, m_iRingVol);
	DDX_Control(pDX, IDC_HANDFREE_INPUT, m_ctlSpeakerIn);
	DDX_Slider(pDX, IDC_HANDFREE_INPUT, m_iSpeakerIn);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CAdvancedSettingsDlg, CDialog)
	//{{AFX_MSG_MAP(CAdvancedSettingsDlg)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CAdvancedSettingsDlg message handlers

BOOL CAdvancedSettingsDlg::OnInitDialog() 
{
	CDialog::OnInitDialog();
	
	int i;

	for(i = 0; i < RING_TYPE_MAX; i++)
	{
		m_ctlRingType.AddString((char *)(g_cRingTypeDisplay[0] + i * RING_TYPE_DISPLAY_LEN));
	}

	/* 0x00000f:           ring type */
    m_ctlRingType.SetCurSel(AfxGetApp()->GetProfileInt(_T("PhoneSettings"), _T("RingType"), 0));

	/* 0x000033:           Initial ring vol */
	m_iRingVol = AfxGetApp()->GetProfileInt(_T("PhoneSettings"), _T("RingVol"), 31);
	m_ctlRingVol.SetRange(0, 31);
	m_ctlRingVol.SetTic(1);

	/* 0x000034:           Initial Handfree input */
	m_iSpeakerIn = AfxGetApp()->GetProfileInt(_T("PhoneSettings"), _T("SpeakerIn"), 15);
	m_ctlSpeakerIn.SetRange(0, 15);
	m_ctlSpeakerIn.SetTic(1);

	UpdateData(FALSE);
	
	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}

void CAdvancedSettingsDlg::OnOK() 
{
	UpdateData();

	/* 0x00000f:           ring type */
    AfxGetApp()->WriteProfileInt(_T("PhoneSettings"), _T("RingType"), (int)m_ctlRingType.GetCurSel());

	/* 0x000033:           Initial handfree output vol */
	AfxGetApp()->WriteProfileInt(_T("PhoneSettings"), _T("RingVol"), m_iRingVol);

	/* 0x000034:           Initial handfree input vol */
	AfxGetApp()->WriteProfileInt(_T("PhoneSettings"), _T("SpeakerIn"), m_iSpeakerIn);

	CDialog::OnOK();
}
