summaryrefslogtreecommitdiff
path: root/plugins/ProxySwitch/src/opt.cpp
blob: 917353ea8f90e6375a6a0002d291295d949013d7 (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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
/*
proxySwitch

The plugin watches IP address changes, reports them via popups and adjusts
the proxy settings of Miranda and Internet Explorer accordingly.
*/

#include "stdafx.h"

int help_shown;

static INT_PTR CALLBACK HelpProc(HWND hdlg, UINT msg, WPARAM wParam, LPARAM)
{
	switch (msg) {
	case WM_INITDIALOG:
		TranslateDialogDefault(hdlg);
		return 1;

	case WM_COMMAND:
		if (wParam == IDOK || wParam == IDCANCEL)
			EndDialog(hdlg, 0);
		break;

	case WM_CLOSE:
		EndDialog(hdlg, 0);
		break;
	}

	return 0;
}

INT_PTR CALLBACK OptionsProc(HWND hdlg, UINT msg, WPARAM wparam, LPARAM lparam) 
{
	switch (msg) {

	case WM_INITDIALOG:
		opt_startup = TRUE;
		LoadSettings();
		SetDlgItemText(hdlg, IDC_EDIT_USEPROXY, opt_useProxy);
		SetDlgItemText(hdlg, IDC_EDIT_NOPROXY, opt_noProxy);
		CheckDlgButton(hdlg, IDC_CHECK_MIRANDA, opt_miranda ? BST_CHECKED : BST_UNCHECKED);
		CheckDlgButton(hdlg, IDC_CHECK_IE, opt_ie ? BST_CHECKED : BST_UNCHECKED);
		CheckDlgButton(hdlg, IDC_CHECK_FIREFOX, opt_firefox ? BST_CHECKED : BST_UNCHECKED);
		CheckDlgButton(hdlg, IDC_CHECK_ALWAY_RECONNECT, opt_alwayReconnect ? BST_CHECKED : BST_UNCHECKED);
		SetDlgItemText(hdlg, IDC_EDIT_HIDEINTF, opt_hideIntf);
		SendDlgItemMessage(hdlg, IDC_BGCOLOR, CPM_SETCOLOUR, 0, opt_bgColor);
		SendDlgItemMessage(hdlg, IDC_TEXTCOLOR, CPM_SETCOLOUR, 0, opt_txtColor);
		CheckDlgButton(hdlg, IDC_CHECK_POPUPS, g_plugin.bPopups ? BST_CHECKED : BST_UNCHECKED);
		CheckDlgButton(hdlg, IDC_CHECK_DEFAULTCOLORS, opt_defaultColors ? BST_CHECKED : BST_UNCHECKED);
		CheckDlgButton(hdlg, IDC_CHECK_SHOWPROXYSTATUS, opt_showProxyState ? BST_CHECKED : BST_UNCHECKED);
		EnableWindow(GetDlgItem(hdlg, IDC_CHECK_FIREFOX), Firefox_Installed());
		EnableWindow(GetDlgItem(hdlg, IDC_BGCOLOR), g_plugin.bPopups && !opt_defaultColors);
		EnableWindow(GetDlgItem(hdlg, IDC_TEXTCOLOR), g_plugin.bPopups && !opt_defaultColors);
		EnableWindow(GetDlgItem(hdlg, IDC_CHECK_DEFAULTCOLORS), g_plugin.bPopups);
		EnableWindow(GetDlgItem(hdlg, IDC_CHECK_SHOWPROXYSTATUS), g_plugin.bPopups);
		ShowWindow(GetDlgItem(hdlg, IDC_RESTARTREQUIRED), opt_not_restarted ? SW_SHOW : SW_HIDE);
		TranslateDialogDefault(hdlg);
		opt_startup = FALSE;
		return 1;

	case WM_NOTIFY:
		switch (((LPNMHDR)lparam)->code) {
		case PSN_APPLY:
			ShowWindow(GetDlgItem(hdlg, IDC_RESTARTREQUIRED), opt_not_restarted ? SW_SHOW : SW_HIDE);
			GetDlgItemText(hdlg, IDC_EDIT_NOPROXY, opt_noProxy, MAX_IPLIST_LENGTH);
			GetDlgItemText(hdlg, IDC_EDIT_USEPROXY, opt_useProxy, MAX_IPLIST_LENGTH);
			GetDlgItemText(hdlg, IDC_EDIT_HIDEINTF, opt_hideIntf, MAX_IPLIST_LENGTH);
			opt_miranda = IsDlgButtonChecked(hdlg, IDC_CHECK_MIRANDA);
			opt_ie = IsDlgButtonChecked(hdlg, IDC_CHECK_IE);
			opt_firefox = IsDlgButtonChecked(hdlg, IDC_CHECK_FIREFOX);
			opt_alwayReconnect = IsDlgButtonChecked(hdlg, IDC_CHECK_ALWAY_RECONNECT);
			g_plugin.bPopups = IsDlgButtonChecked(hdlg, IDC_CHECK_POPUPS);
			opt_defaultColors = IsDlgButtonChecked(hdlg, IDC_CHECK_DEFAULTCOLORS);
			opt_showProxyState = IsDlgButtonChecked(hdlg, IDC_CHECK_SHOWPROXYSTATUS);
			opt_bgColor = SendDlgItemMessage(hdlg, IDC_BGCOLOR, CPM_GETCOLOUR, 0, 0);
			opt_txtColor = SendDlgItemMessage(hdlg, IDC_TEXTCOLOR, CPM_GETCOLOUR, 0, 0);
			SaveSettings();
			return 1;
		}
		break;

	case WM_COMMAND:
		if (opt_startup)
			return 0;

		if (HIWORD(wparam) == BN_CLICKED && GetFocus() == (HWND)lparam && LOWORD(wparam) != IDC_BTN_HELP)
			SendMessage(GetParent(hdlg), PSM_CHANGED, 0, 0);

		switch (LOWORD(wparam)) {
		case IDC_BTN_HELP:
			DialogBox(g_plugin.getInst(), MAKEINTRESOURCE(IDD_HELP), 0, HelpProc);
			break;

		case IDC_EDIT_USEPROXY:
		case IDC_EDIT_NOPROXY:
		case IDC_EDIT_HIDEINTF:
			if (HIWORD(wparam) == EN_CHANGE && (HWND)lparam == GetFocus()) 
				SendMessage(GetParent(hdlg), PSM_CHANGED, 0, 0);
			break;

		case IDC_BGCOLOR:
		case IDC_TEXTCOLOR:
			if (HIWORD(wparam) == CPN_COLOURCHANGED)
				SendMessage(GetParent(hdlg), PSM_CHANGED, 0, 0);
			break;

		case IDC_CHECK_DEFAULTCOLORS:
		case IDC_CHECK_POPUPS:
			EnableWindow(GetDlgItem(hdlg, IDC_BGCOLOR), IsDlgButtonChecked(hdlg, IDC_CHECK_POPUPS) && !IsDlgButtonChecked(hdlg, IDC_CHECK_DEFAULTCOLORS));
			EnableWindow(GetDlgItem(hdlg, IDC_TEXTCOLOR), IsDlgButtonChecked(hdlg, IDC_CHECK_POPUPS) && !IsDlgButtonChecked(hdlg, IDC_CHECK_DEFAULTCOLORS));
			EnableWindow(GetDlgItem(hdlg, IDC_CHECK_DEFAULTCOLORS), IsDlgButtonChecked(hdlg, IDC_CHECK_POPUPS));
			EnableWindow(GetDlgItem(hdlg, IDC_CHECK_SHOWPROXYSTATUS), IsDlgButtonChecked(hdlg, IDC_CHECK_POPUPS));
			SendMessage(GetParent(hdlg), PSM_CHANGED, 0, 0);
			break;
		}
		break;

	case WM_CLOSE:
		EndDialog(hdlg, 0);
		break;
	}
	return 0;
}

int OptInit(WPARAM wParam, LPARAM) 
{
	OPTIONSDIALOGPAGE odp = {};
	odp.position = 95600;
	odp.pszTemplate = MAKEINTRESOURCEA(IDD_OPTIONS);
	odp.pfnDlgProc = OptionsProc;
	odp.szGroup.w = LPGENW("Services");
	odp.szTitle.w = LPGENW("ProxySwitch");
	odp.flags = ODPF_BOLDGROUPS | ODPF_UNICODE;
	g_plugin.addOptions(wParam, &odp);

	return 0;
}

void LoadSettings(void) 
{
	ptrW wszStr(g_plugin.getWStringA("UseProxyIPNets"));
	if (!wszStr)
		opt_useProxy[0] = 0;
	else
		wcsncpy_s(opt_useProxy, wszStr, _TRUNCATE);

	wszStr = g_plugin.getWStringA("NoProxyIPNets");
	if (!wszStr)
		opt_noProxy[0] = 0;
	else
		wcsncpy_s(opt_noProxy, wszStr, _TRUNCATE);

	wszStr = g_plugin.getWStringA("HideInterfaces");
	if (!wszStr)
		opt_hideIntf[0] = 0;
	else
		wcsncpy_s(opt_hideIntf, wszStr, _TRUNCATE);
	
	opt_miranda = g_plugin.getByte("ManageMirandaProxy", TRUE);
	opt_ie = g_plugin.getByte("ManageIEProxy", FALSE);
	opt_firefox = g_plugin.getByte("ManageFirefoxProxy", FALSE) && Firefox_Installed();
	opt_alwayReconnect = g_plugin.getByte("AlwaysReconnect", FALSE);
	opt_defaultColors = g_plugin.getByte("PopupDefaultColors", TRUE);
	opt_showProxyState = g_plugin.getByte("ShowProxyStatus", TRUE);
	opt_bgColor = g_plugin.getDword("PopupBgColor", GetSysColor(COLOR_BTNFACE));
	opt_txtColor = g_plugin.getDword("PopupTxtColor", GetSysColor(COLOR_WINDOWTEXT));
}

void SaveSettings(void)
{
	g_plugin.setWString("UseProxyIPNets", opt_useProxy);
	g_plugin.setWString("NoProxyIPNets", opt_noProxy);
	g_plugin.setWString("HideInterfaces", opt_hideIntf);
	g_plugin.setByte("ManageMirandaProxy", (uint8_t)opt_miranda);
	g_plugin.setByte("ManageIEProxy", (uint8_t)opt_ie);
	g_plugin.setByte("ManageFirefoxProxy", (uint8_t)opt_firefox);
	g_plugin.setByte("AlwaysReconnect", (uint8_t)opt_alwayReconnect);
	g_plugin.setByte("PopupDefaultColors", (uint8_t)opt_defaultColors);
	g_plugin.setByte("ShowProxyStatus", (uint8_t)opt_showProxyState);
	g_plugin.setDword("PopupBgColor", (uint32_t)opt_bgColor);
	g_plugin.setDword("PopupTxtColor", (uint32_t)opt_txtColor);
}