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
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
|
/*
FTP File YM plugin
Copyright (C) 2007-2010 Jan Holub
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation version 2
of the License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "stdafx.h"
Options *Options::instance = NULL;
Options &opt = Options::getInstance();
extern DeleteTimer &deleteTimer;
extern ServerList &ftpList;
extern void PrebuildMainMenu();
void Options::deinit()
{
delete this;
}
void Options::loadOptions()
{
selected = db_get_b(0, MODULE, "Selected", 0);
defaultFTP = db_get_b(0, MODULE, "Default", 0);
bAutosend = db_get_b(0, MODULE, "Autosend", 0) ? true : false;
bCloseDlg = db_get_b(0, MODULE, "CloseDlg", 0) ? true : false;
bCopyLink = db_get_b(0, MODULE, "CopyLink", 1) ? true : false;
bUseSubmenu = db_get_b(0, MODULE, "UseSubmenu", 1) ? true : false;
bHideInactive = db_get_b(0, MODULE, "HideInactive", 1) ? true : false;
bAutoDelete = db_get_b(0, MODULE, "DeleteTimer", 0) ? true : false;
iDeleteTime = db_get_dw(0, MODULE, "AutoDeleteTime", 60);
timeRange = (ETimeRange)db_get_b(0, MODULE, "TimeRange", TR_MINUTES);
iCompressionLevel = db_get_b(0, MODULE, "CompressionLevel", 6);
bSetZipName = db_get_b(0, MODULE, "SetZipName", 0) ? true : false;
}
void Options::saveOptions() const
{
db_set_b(0, MODULE, "Autosend", bAutosend ? 1 : 0);
db_set_b(0, MODULE, "CopyLink", bCopyLink ? 1 : 0);
db_set_b(0, MODULE, "UseSubmenu", bUseSubmenu ? 1 : 0);
db_set_b(0, MODULE, "HideInactive", bHideInactive ? 1 : 0);
db_set_b(0, MODULE, "CloseDlg", bCloseDlg ? 1 : 0);
db_set_b(0, MODULE, "DeleteTimer", bAutoDelete ? 1 : 0);
db_set_dw(0, MODULE, "AutoDeleteTime", iDeleteTime);
db_set_b(0, MODULE, "TimeRange", (int)timeRange);
db_set_b(0, MODULE, "CompressionLevel", iCompressionLevel);
db_set_b(0, MODULE, "SetZipName", bSetZipName ? 1 : 0);
}
void Options::enableItems(HWND hwndDlg, bool state)
{
EnableWindow(GetDlgItem(hwndDlg, IDC_DEFAULT), state);
EnableWindow(GetDlgItem(hwndDlg, IDC_PROTOLIST), state);
EnableWindow(GetDlgItem(hwndDlg, IDC_SERVER), state);
EnableWindow(GetDlgItem(hwndDlg, IDC_USER), state);
EnableWindow(GetDlgItem(hwndDlg, IDC_PASSWORD), state);
EnableWindow(GetDlgItem(hwndDlg, IDC_DIR), state);
EnableWindow(GetDlgItem(hwndDlg, IDC_URL), state);
EnableWindow(GetDlgItem(hwndDlg, IDC_PORT), state);
EnableWindow(GetDlgItem(hwndDlg, IDC_CHMOD), state);
EnableWindow(GetDlgItem(hwndDlg, IDC_PASSIVE), state);
}
INT_PTR CALLBACK Options::DlgProcOptsAccounts(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
{
switch (msg) {
case WM_INITDIALOG:
TranslateDialogDefault(hwndDlg);
{
for (int i = 0; i < ServerList::FTP_COUNT; i++)
ComboBox_AddString(GetDlgItem(hwndDlg, IDC_FTPLIST), ftpList[i]->m_stzName);
ComboBox_SetCurSel(GetDlgItem(hwndDlg, IDC_FTPLIST), opt.selected);
CheckDlgButton(hwndDlg, IDC_DEFAULT, opt.selected == opt.defaultFTP ? BST_CHECKED : BST_UNCHECKED);
ServerList::FTP *ftp = ftpList.getSelected();
ComboBox_AddString(GetDlgItem(hwndDlg, IDC_PROTOLIST), TranslateT("FTP (Standard)"));
ComboBox_AddString(GetDlgItem(hwndDlg, IDC_PROTOLIST), TranslateT("FTP+SSL (Explicit)"));
ComboBox_AddString(GetDlgItem(hwndDlg, IDC_PROTOLIST), TranslateT("FTP+SSL (Implicit)"));
ComboBox_AddString(GetDlgItem(hwndDlg, IDC_PROTOLIST), TranslateT("SFTP (Secure FTP over SSH)"));
ComboBox_SetCurSel(GetDlgItem(hwndDlg, IDC_PROTOLIST), ftp->m_ftpProto);
SetDlgItemTextA(hwndDlg, IDC_SERVER, ftp->m_szServer);
SetDlgItemTextA(hwndDlg, IDC_USER, ftp->m_szUser);
SetDlgItemTextA(hwndDlg, IDC_PASSWORD, ftp->m_szPass);
SetDlgItemTextA(hwndDlg, IDC_DIR, ftp->m_szDir);
SetDlgItemTextA(hwndDlg, IDC_URL, ftp->m_szUrl);
SetDlgItemTextA(hwndDlg, IDC_CHMOD, ftp->m_szChmod);
SetDlgItemInt(hwndDlg, IDC_PORT, ftp->m_iPort, FALSE);
CheckDlgButton(hwndDlg, IDC_PASSIVE, ftp->m_bPassive ? BST_CHECKED : BST_UNCHECKED);
CheckDlgButton(hwndDlg, IDC_ENABLED, ftp->m_bEnabled ? BST_CHECKED : BST_UNCHECKED);
enableItems(hwndDlg, ftp->m_bEnabled);
}
return TRUE;
case WM_COMMAND:
if (HIWORD(wParam) == BN_CLICKED) {
if (LOWORD(wParam) == IDC_ENABLED)
enableItems(hwndDlg, IsDlgButtonChecked(hwndDlg, IDC_ENABLED) == BST_CHECKED ? true : false);
}
else if (HIWORD(wParam) == CBN_SELCHANGE) {
if (LOWORD(wParam) == IDC_FTPLIST) {
opt.selected = (BYTE)ComboBox_GetCurSel(GetDlgItem(hwndDlg, IDC_FTPLIST));
CheckDlgButton(hwndDlg, IDC_DEFAULT, opt.selected == opt.defaultFTP ? BST_CHECKED : BST_UNCHECKED);
ServerList::FTP *ftp = ftpList.getSelected();
SendDlgItemMessage(hwndDlg, IDC_PROTOLIST, CB_SETCURSEL, ftp->m_ftpProto, 0);
SetDlgItemTextA(hwndDlg, IDC_SERVER, ftp->m_szServer);
SetDlgItemTextA(hwndDlg, IDC_USER, ftp->m_szUser);
SetDlgItemTextA(hwndDlg, IDC_PASSWORD, ftp->m_szPass);
SetDlgItemTextA(hwndDlg, IDC_DIR, ftp->m_szDir);
SetDlgItemTextA(hwndDlg, IDC_URL, ftp->m_szUrl);
SetDlgItemTextA(hwndDlg, IDC_CHMOD, ftp->m_szChmod);
SetDlgItemInt(hwndDlg, IDC_PORT, ftp->m_iPort, FALSE);
CheckDlgButton(hwndDlg, IDC_PASSIVE, ftp->m_bPassive ? BST_CHECKED : BST_UNCHECKED);
CheckDlgButton(hwndDlg, IDC_ENABLED, ftp->m_bEnabled ? BST_CHECKED : BST_UNCHECKED);
enableItems(hwndDlg, ftp->m_bEnabled);
}
else if (LOWORD(wParam) == IDC_PROTOLIST) {
int sel = ComboBox_GetCurSel(GetDlgItem(hwndDlg, IDC_PROTOLIST));
switch (sel) {
case ServerList::FTP::FT_STANDARD:
case ServerList::FTP::FT_SSL_EXPLICIT: SetDlgItemInt(hwndDlg, IDC_PORT, 21, FALSE); break;
case ServerList::FTP::FT_SSL_IMPLICIT: SetDlgItemInt(hwndDlg, IDC_PORT, 990, FALSE); break;
case ServerList::FTP::FT_SSH: SetDlgItemInt(hwndDlg, IDC_PORT, 22, FALSE); break;
}
}
}
if (HIWORD(wParam) == BN_CLICKED || HIWORD(wParam) == EN_CHANGE || HIWORD(wParam) == CBN_SELCHANGE || HIWORD(wParam) == CBN_EDITCHANGE)
SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0);
return TRUE;
case WM_NOTIFY:
if (((LPNMHDR)lParam)->code == PSN_APPLY) {
if (IsDlgButtonChecked(hwndDlg, IDC_DEFAULT))
opt.defaultFTP = opt.selected;
ServerList::FTP *ftp = ftpList.getSelected();
GetDlgItemText(hwndDlg, IDC_FTPLIST, ftp->m_stzName, _countof(ftp->m_stzName));
GetDlgItemTextA(hwndDlg, IDC_SERVER, ftp->m_szServer, _countof(ftp->m_szServer));
GetDlgItemTextA(hwndDlg, IDC_USER, ftp->m_szUser, _countof(ftp->m_szUser));
GetDlgItemTextA(hwndDlg, IDC_PASSWORD, ftp->m_szPass, _countof(ftp->m_szPass));
GetDlgItemTextA(hwndDlg, IDC_DIR, ftp->m_szDir, _countof(ftp->m_szDir));
GetDlgItemTextA(hwndDlg, IDC_URL, ftp->m_szUrl, _countof(ftp->m_szUrl));
GetDlgItemTextA(hwndDlg, IDC_CHMOD, ftp->m_szChmod, _countof(ftp->m_szChmod));
ftp->m_ftpProto = (ServerList::FTP::EProtoType)ComboBox_GetCurSel(GetDlgItem(hwndDlg, IDC_PROTOLIST));
ftp->m_iPort = GetDlgItemInt(hwndDlg, IDC_PORT, 0, 0);
ftp->m_bPassive = IsDlgButtonChecked(hwndDlg, IDC_PASSIVE) ? true : false;
ftp->m_bEnabled = IsDlgButtonChecked(hwndDlg, IDC_ENABLED) ? true : false;
ComboBox_DeleteString(GetDlgItem(hwndDlg, IDC_FTPLIST), opt.selected);
ComboBox_InsertString(GetDlgItem(hwndDlg, IDC_FTPLIST), opt.selected, ftp->m_stzName);
ComboBox_SetCurSel(GetDlgItem(hwndDlg, IDC_FTPLIST), opt.selected);
ftpList.saveToDb();
PrebuildMainMenu();
}
return TRUE;
}
return FALSE;
}
INT_PTR CALLBACK Options::DlgProcOptsAdvanced(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
{
switch (msg) {
case WM_INITDIALOG:
TranslateDialogDefault(hwndDlg);
CheckDlgButton(hwndDlg, IDC_URL_AUTOSEND, opt.bAutosend ? BST_CHECKED : BST_UNCHECKED);
CheckDlgButton(hwndDlg, IDC_URL_COPYTOML, opt.bCopyLink ? BST_CHECKED : BST_UNCHECKED);
CheckDlgButton(hwndDlg, IDC_USESUBMENU, opt.bUseSubmenu ? BST_CHECKED : BST_UNCHECKED);
CheckDlgButton(hwndDlg, IDC_HIDEINACTIVE, opt.bHideInactive ? BST_CHECKED : BST_UNCHECKED);
CheckDlgButton(hwndDlg, IDC_CLOSEDLG, opt.bCloseDlg ? BST_CHECKED : BST_UNCHECKED);
CheckDlgButton(hwndDlg, IDC_AUTODELETE, opt.bAutoDelete ? BST_CHECKED : BST_UNCHECKED);
SendDlgItemMessage(hwndDlg, IDC_LEVEL_SPIN, UDM_SETRANGE, 0, (LPARAM)MAKELONG(9, 0));
SetDlgItemInt(hwndDlg, IDC_LEVEL, opt.iCompressionLevel, FALSE);
CheckDlgButton(hwndDlg, IDC_SETZIPNAME, opt.bSetZipName ? BST_CHECKED : BST_UNCHECKED);
SendDlgItemMessage(hwndDlg, IDC_DELETETIME_SPIN, UDM_SETRANGE, 0, (LPARAM)MAKELONG(UD_MAXVAL, 1));
SetDlgItemInt(hwndDlg, IDC_DELETETIME, opt.iDeleteTime, FALSE);
SendDlgItemMessage(hwndDlg, IDC_RANGE, CB_ADDSTRING, 0, (LPARAM)TranslateT("minutes"));
SendDlgItemMessage(hwndDlg, IDC_RANGE, CB_ADDSTRING, 0, (LPARAM)TranslateT("hours"));
SendDlgItemMessage(hwndDlg, IDC_RANGE, CB_ADDSTRING, 0, (LPARAM)TranslateT("days"));
SendDlgItemMessage(hwndDlg, IDC_RANGE, CB_SETCURSEL, (int)opt.timeRange, 0);
EnableWindow(GetDlgItem(hwndDlg, IDC_DELETETIME), opt.bAutoDelete);
EnableWindow(GetDlgItem(hwndDlg, IDC_RANGE), opt.bAutoDelete);
return TRUE;
case WM_COMMAND:
if (HIWORD(wParam) == BN_CLICKED && LOWORD(wParam) == IDC_AUTODELETE) {
EnableWindow(GetDlgItem(hwndDlg, IDC_DELETETIME), IsDlgButtonChecked(hwndDlg, IDC_AUTODELETE));
EnableWindow(GetDlgItem(hwndDlg, IDC_RANGE), IsDlgButtonChecked(hwndDlg, IDC_AUTODELETE));
}
if (HIWORD(wParam) == BN_CLICKED || HIWORD(wParam) == EN_CHANGE)
SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0);
return TRUE;
case WM_NOTIFY:
if (((LPNMHDR)lParam)->code == PSN_APPLY) {
opt.bAutosend = IsDlgButtonChecked(hwndDlg, IDC_URL_AUTOSEND) ? true : false;
opt.bCopyLink = IsDlgButtonChecked(hwndDlg, IDC_URL_COPYTOML) ? true : false;
opt.bUseSubmenu = IsDlgButtonChecked(hwndDlg, IDC_USESUBMENU) ? true : false;
opt.bHideInactive = IsDlgButtonChecked(hwndDlg, IDC_HIDEINACTIVE) ? true : false;
opt.bCloseDlg = IsDlgButtonChecked(hwndDlg, IDC_CLOSEDLG) ? true : false;
opt.bAutoDelete = IsDlgButtonChecked(hwndDlg, IDC_AUTODELETE) ? true : false;
opt.iCompressionLevel = GetDlgItemInt(hwndDlg, IDC_LEVEL, 0, FALSE);
opt.bSetZipName = IsDlgButtonChecked(hwndDlg, IDC_SETZIPNAME) ? true : false;
opt.iDeleteTime = GetDlgItemInt(hwndDlg, IDC_DELETETIME, 0, FALSE);
opt.timeRange = (Options::ETimeRange)SendDlgItemMessage(hwndDlg, IDC_RANGE, CB_GETCURSEL, 0, 0);
opt.saveOptions();
if (opt.bAutoDelete) deleteTimer.start();
else deleteTimer.stop();
PrebuildMainMenu();
}
return TRUE;
}
return FALSE;
}
int Options::InitOptions(WPARAM wParam, LPARAM)
{
OPTIONSDIALOGPAGE odp = { 0 };
odp.position = 100000000;
odp.hInstance = hInst;
odp.flags = ODPF_BOLDGROUPS | ODPF_UNICODE;
odp.pwszTitle = LPGENW("FTP File");
odp.pwszGroup = LPGENW("Services");
odp.pwszTab = LPGENW("Accounts");
odp.pszTemplate = MAKEINTRESOURCEA(IDD_OPT_FTPFILE);
odp.pfnDlgProc = Options::DlgProcOptsAccounts;
Options_AddPage(wParam, &odp);
odp.pwszTab = LPGENW("Advanced");
odp.pszTemplate = MAKEINTRESOURCEA(IDD_OPT_ADVANCED);
odp.pfnDlgProc = Options::DlgProcOptsAdvanced;
Options_AddPage(wParam, &odp);
return 0;
}
|