[RAPPS] Replaced my @gmail.com email with @reactos,org one & Removed my copyright...
[reactos.git] / reactos / base / applications / rapps / settingsdlg.cpp
1 /*
2 * PROJECT: ReactOS Applications Manager
3 * LICENSE: GPL-2.0+ (https://spdx.org/licenses/GPL-2.0+)
4 * FILE: base/applications/rapps/settingsdlg.cpp
5 * PURPOSE: Settings Dialog
6 * COPYRIGHT: Copyright 2009 Dmitry Chapyshev (dmitry@reactos.org)
7 * Copyright 2017 Alexander Shaposhnikov (sanchaez@reactos.org)
8 */
9 #include "defines.h"
10
11 #include "dialogs.h"
12
13 SETTINGS_INFO NewSettingsInfo;
14
15 BOOL ChooseFolder(HWND hwnd)
16 {
17 BOOL bRet = FALSE;
18 BROWSEINFOW bi;
19 ATL::CStringW szChooseFolderText;
20
21 szChooseFolderText.LoadStringW(IDS_CHOOSE_FOLDER_TEXT);
22
23 ZeroMemory(&bi, sizeof(bi));
24 bi.hwndOwner = hwnd;
25 bi.pidlRoot = NULL;
26 bi.lpszTitle = szChooseFolderText.GetString();
27 bi.ulFlags = BIF_USENEWUI | BIF_DONTGOBELOWDOMAIN | BIF_RETURNONLYFSDIRS | /* BIF_BROWSEFILEJUNCTIONS | */ BIF_VALIDATE;
28
29 if (SUCCEEDED(CoInitializeEx(NULL, COINIT_APARTMENTTHREADED)))
30 {
31 ATL::CStringW szBuf;
32
33 LPITEMIDLIST lpItemList = SHBrowseForFolderW(&bi);
34 if (lpItemList && SHGetPathFromIDListW(lpItemList, szBuf.GetBuffer(MAX_PATH)))
35 {
36 szBuf.ReleaseBuffer();
37 if (!szBuf.IsEmpty())
38 {
39 SetDlgItemTextW(hwnd, IDC_DOWNLOAD_DIR_EDIT, szBuf.GetString());
40 bRet = TRUE;
41 }
42 }
43 else
44 {
45 szBuf.ReleaseBuffer();
46 }
47
48 CoTaskMemFree(lpItemList);
49 CoUninitialize();
50 }
51
52 return bRet;
53 }
54
55 namespace
56 {
57 inline BOOL IsCheckedDlgItem(HWND hDlg, INT nIDDlgItem)
58 {
59 return (SendDlgItemMessageW(hDlg, nIDDlgItem, BM_GETCHECK, 0, 0) == BST_CHECKED) ? TRUE : FALSE;
60 }
61
62 VOID InitSettingsControls(HWND hDlg, PSETTINGS_INFO Info)
63 {
64 SendDlgItemMessageW(hDlg, IDC_SAVE_WINDOW_POS, BM_SETCHECK, Info->bSaveWndPos, 0);
65 SendDlgItemMessageW(hDlg, IDC_UPDATE_AVLIST, BM_SETCHECK, Info->bUpdateAtStart, 0);
66 SendDlgItemMessageW(hDlg, IDC_LOG_ENABLED, BM_SETCHECK, Info->bLogEnabled, 0);
67 SendDlgItemMessageW(hDlg, IDC_DEL_AFTER_INSTALL, BM_SETCHECK, Info->bDelInstaller, 0);
68
69 SetWindowTextW(GetDlgItem(hDlg, IDC_DOWNLOAD_DIR_EDIT),
70 Info->szDownloadDir);
71
72 CheckRadioButton(hDlg, IDC_PROXY_DEFAULT, IDC_USE_PROXY, IDC_PROXY_DEFAULT + Info->Proxy);
73
74 if (IDC_PROXY_DEFAULT + Info->Proxy == IDC_USE_PROXY)
75 {
76 EnableWindow(GetDlgItem(hDlg, IDC_PROXY_SERVER), TRUE);
77 EnableWindow(GetDlgItem(hDlg, IDC_NO_PROXY_FOR), TRUE);
78 }
79
80 SetWindowTextW(GetDlgItem(hDlg, IDC_PROXY_SERVER), Info->szProxyServer);
81 SetWindowTextW(GetDlgItem(hDlg, IDC_NO_PROXY_FOR), Info->szNoProxyFor);
82 }
83
84 INT_PTR CALLBACK SettingsDlgProc(HWND hDlg, UINT Msg, WPARAM wParam, LPARAM lParam)
85 {
86 switch (Msg)
87 {
88 case WM_INITDIALOG:
89 {
90 NewSettingsInfo = SettingsInfo;
91 InitSettingsControls(hDlg, &SettingsInfo);
92 }
93 break;
94
95 case WM_COMMAND:
96 {
97 switch (LOWORD(wParam))
98 {
99 case IDC_CHOOSE:
100 ChooseFolder(hDlg);
101 break;
102
103 case IDC_SAVE_WINDOW_POS:
104 NewSettingsInfo.bSaveWndPos = IsCheckedDlgItem(hDlg, IDC_SAVE_WINDOW_POS);
105 break;
106
107 case IDC_UPDATE_AVLIST:
108 NewSettingsInfo.bUpdateAtStart = IsCheckedDlgItem(hDlg, IDC_UPDATE_AVLIST);
109 break;
110
111 case IDC_LOG_ENABLED:
112 NewSettingsInfo.bLogEnabled = IsCheckedDlgItem(hDlg, IDC_LOG_ENABLED);
113 break;
114
115 case IDC_DEL_AFTER_INSTALL:
116 NewSettingsInfo.bDelInstaller = IsCheckedDlgItem(hDlg, IDC_DEL_AFTER_INSTALL);
117 break;
118
119 case IDC_PROXY_DEFAULT:
120 NewSettingsInfo.Proxy = 0;
121 EnableWindow(GetDlgItem(hDlg, IDC_PROXY_SERVER), FALSE);
122 EnableWindow(GetDlgItem(hDlg, IDC_NO_PROXY_FOR), FALSE);
123 break;
124
125 case IDC_NO_PROXY:
126 NewSettingsInfo.Proxy = 1;
127 EnableWindow(GetDlgItem(hDlg, IDC_PROXY_SERVER), FALSE);
128 EnableWindow(GetDlgItem(hDlg, IDC_NO_PROXY_FOR), FALSE);
129 break;
130
131 case IDC_USE_PROXY:
132 NewSettingsInfo.Proxy = 2;
133 EnableWindow(GetDlgItem(hDlg, IDC_PROXY_SERVER), TRUE);
134 EnableWindow(GetDlgItem(hDlg, IDC_NO_PROXY_FOR), TRUE);
135 break;
136
137 case IDC_DEFAULT_SETTINGS:
138 FillDefaultSettings(&NewSettingsInfo);
139 InitSettingsControls(hDlg, &NewSettingsInfo);
140 break;
141
142 case IDOK:
143 {
144 ATL::CStringW szDir;
145 ATL::CStringW szProxy;
146 ATL::CStringW szNoProxy;
147 DWORD dwAttr;
148
149 GetWindowTextW(GetDlgItem(hDlg, IDC_DOWNLOAD_DIR_EDIT),
150 szDir.GetBuffer(MAX_PATH), MAX_PATH);
151 szDir.ReleaseBuffer();
152
153 GetWindowTextW(GetDlgItem(hDlg, IDC_PROXY_SERVER),
154 szProxy.GetBuffer(MAX_PATH), MAX_PATH);
155 szProxy.ReleaseBuffer();
156 ATL::CStringW::CopyChars(NewSettingsInfo.szProxyServer,
157 _countof(NewSettingsInfo.szProxyServer),
158 szProxy.GetString(),
159 szProxy.GetLength() + 1);
160
161 GetWindowTextW(GetDlgItem(hDlg, IDC_NO_PROXY_FOR),
162 szNoProxy.GetBuffer(MAX_PATH), MAX_PATH);
163 szNoProxy.ReleaseBuffer();
164 ATL::CStringW::CopyChars(NewSettingsInfo.szNoProxyFor,
165 _countof(NewSettingsInfo.szNoProxyFor),
166 szNoProxy.GetString(),
167 szNoProxy.GetLength() + 1);
168
169 dwAttr = GetFileAttributesW(szDir.GetString());
170 if (dwAttr != INVALID_FILE_ATTRIBUTES &&
171 (dwAttr & FILE_ATTRIBUTE_DIRECTORY))
172 {
173 ATL::CStringW::CopyChars(NewSettingsInfo.szDownloadDir,
174 _countof(NewSettingsInfo.szDownloadDir),
175 szDir.GetString(),
176 szDir.GetLength() + 1);
177 }
178 else
179 {
180 ATL::CStringW szMsgText;
181 szMsgText.LoadStringW(IDS_CHOOSE_FOLDER_ERROR);
182
183 if (MessageBoxW(hDlg, szMsgText.GetString(), NULL, MB_YESNO) == IDYES)
184 {
185 if (CreateDirectoryW(szDir.GetString(), NULL))
186 {
187 EndDialog(hDlg, LOWORD(wParam));
188 }
189 }
190 else
191 {
192 SetFocus(GetDlgItem(hDlg, IDC_DOWNLOAD_DIR_EDIT));
193 break;
194 }
195 }
196
197 SettingsInfo = NewSettingsInfo;
198 SaveSettings(GetParent(hDlg));
199 EndDialog(hDlg, LOWORD(wParam));
200 }
201 break;
202
203 case IDCANCEL:
204 EndDialog(hDlg, LOWORD(wParam));
205 break;
206 }
207 }
208 break;
209 }
210
211 return FALSE;
212 }
213 }
214
215 VOID CreateSettingsDlg(HWND hwnd)
216 {
217 DialogBoxW(hInst,
218 MAKEINTRESOURCEW(IDD_SETTINGS_DIALOG),
219 hwnd,
220 SettingsDlgProc);
221 }