aboutsummaryrefslogtreecommitdiffstats
path: root/win32/PropConn.cpp
blob: 15d4a90aebdea20432a0d55c0c32b5eb88b2eeb2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
// PropConn.cpp : implementation file
//

#define BITLBEE_CORE
#include "bitlbeewin.h"
#include "PropConn.h"

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

/////////////////////////////////////////////////////////////////////////////
// CPropConn dialog


CPropConn::CPropConn(CWnd* pParent /*=NULL*/)
	: CPropertyPage(CPropConn::IDD)
{
	//{{AFX_DATA_INIT(CPropConn)
	//}}AFX_DATA_INIT
}


void CPropConn::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CPropConn)
	DDX_Control(pDX, IDC_PROXYPORT, m_proxyport);
	DDX_Control(pDX, IDC_PROXYTYPE, m_proxytype);
	DDX_Control(pDX, IDC_PROXY_ENABLED, m_proxy_enabled);
	DDX_Control(pDX, IDC_PROXY_AUTH_ENABLED, m_proxy_auth_enabled);
	DDX_Control(pDX, IDC_PROXYPASS, m_proxypass);
	DDX_Control(pDX, IDC_PROXYHOST, m_proxyhost);
	DDX_Control(pDX, IDC_PROXYUSER, m_proxyuser);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CPropConn, CPropertyPage)
	//{{AFX_MSG_MAP(CPropConn)
	ON_BN_CLICKED(IDC_PROXY_AUTH_ENABLED, OnProxyAuthEnabled)
	ON_BN_CLICKED(IDC_PROXY_ENABLED, OnProxyEnabled)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CPropConn message handlers

void CPropConn::OnProxyAuthEnabled() 
{
	m_proxyuser.EnableWindow(m_proxy_enabled.GetCheck() && m_proxy_auth_enabled.GetCheck());
	m_proxypass.EnableWindow(m_proxy_enabled.GetCheck() && m_proxy_auth_enabled.GetCheck());
}

void CPropConn::OnProxyEnabled() 
{
	// TODO: Add your control notification handler code here
	m_proxyhost.EnableWindow(m_proxy_enabled.GetCheck());
	m_proxytype.EnableWindow(m_proxy_enabled.GetCheck());
	m_proxyport.EnableWindow(m_proxy_enabled.GetCheck());
	m_proxy_auth_enabled.EnableWindow(m_proxy_enabled.GetCheck());

	if(m_proxy_enabled.GetCheck() && (m_proxytype.GetCurSel() < 0 || m_proxytype.GetCurSel() > 2)) 
	{
		m_proxytype.SetCurSel(0);
	}

	OnProxyAuthEnabled();
}

void CPropConn::OnOK() 
{
	if(!m_proxy_enabled.GetCheck()) {
		proxytype = PROXY_NONE;
		return;
	}

	CString tmp;
	m_proxyhost.GetWindowText(tmp);
	strcpy(proxyhost, tmp);

	m_proxyport.GetWindowText(tmp);
	proxyport = atoi(tmp);

	proxytype = m_proxytype.GetCurSel()+1;

	if(!m_proxy_auth_enabled.GetCheck()) {
		strcpy(proxyuser, "");
		strcpy(proxypass, "");
		return;
	}

	m_proxyuser.GetWindowText(tmp);
	strcpy(proxyuser, tmp);
	m_proxypass.GetWindowText(tmp);
	strcpy(proxypass, tmp);
	
	CPropertyPage::OnOK();
}

BOOL CPropConn::OnInitDialog() 
{
	char pp[20];
	CPropertyPage::OnInitDialog();

	m_proxyhost.SetWindowText(proxyhost);
	m_proxyuser.SetWindowText(proxyuser);
	m_proxypass.SetWindowText(proxypass);
	g_snprintf(pp, 20, "%d", proxyport);
	m_proxyport.SetWindowText(pp);

	m_proxytype.AddString("SOCKS 4");
	m_proxytype.AddString("SOCKS 5");
	m_proxytype.AddString("HTTP");
	m_proxytype.SetCurSel(proxytype-1);

	m_proxy_enabled.SetCheck(proxytype == PROXY_NONE?0:1); 
	m_proxy_auth_enabled.SetCheck(strcmp(proxyuser, "")?1:0);

	OnProxyEnabled();
	
	return TRUE;  
}