ReactOS  0.4.12-dev-18-gf469aca
settingsdlg.cpp
Go to the documentation of this file.
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 "rapps.h"
10 
12 
14 {
15  BOOL bRet = FALSE;
16  BROWSEINFOW bi;
17  ATL::CStringW szChooseFolderText;
18 
19  szChooseFolderText.LoadStringW(IDS_CHOOSE_FOLDER_TEXT);
20 
21  ZeroMemory(&bi, sizeof(bi));
22  bi.hwndOwner = hwnd;
23  bi.pidlRoot = NULL;
24  bi.lpszTitle = szChooseFolderText.GetString();
25  bi.ulFlags = BIF_USENEWUI | BIF_DONTGOBELOWDOMAIN | BIF_RETURNONLYFSDIRS | /* BIF_BROWSEFILEJUNCTIONS | */ BIF_VALIDATE;
26 
28  {
29  ATL::CStringW szBuf;
30 
31  LPITEMIDLIST lpItemList = SHBrowseForFolderW(&bi);
32  if (lpItemList && SHGetPathFromIDListW(lpItemList, szBuf.GetBuffer(MAX_PATH)))
33  {
34  szBuf.ReleaseBuffer();
35  if (!szBuf.IsEmpty())
36  {
38  bRet = TRUE;
39  }
40  }
41  else
42  {
43  szBuf.ReleaseBuffer();
44  }
45 
46  CoTaskMemFree(lpItemList);
48  }
49 
50  return bRet;
51 }
52 
53 namespace
54 {
56  {
57  return (SendDlgItemMessageW(hDlg, nIDDlgItem, BM_GETCHECK, 0, 0) == BST_CHECKED) ? TRUE : FALSE;
58  }
59 
61  {
66 
68  Info->szDownloadDir);
69 
71 
72  if (IDC_PROXY_DEFAULT + Info->Proxy == IDC_USE_PROXY)
73  {
76  }
77 
80  }
81 
83  {
84  switch (Msg)
85  {
86  case WM_INITDIALOG:
87  {
88  NewSettingsInfo = SettingsInfo;
90  }
91  break;
92 
93  case WM_COMMAND:
94  {
95  switch (LOWORD(wParam))
96  {
97  case IDC_CHOOSE:
98  ChooseFolder(hDlg);
99  break;
100 
101  case IDC_SAVE_WINDOW_POS:
102  NewSettingsInfo.bSaveWndPos = IsCheckedDlgItem(hDlg, IDC_SAVE_WINDOW_POS);
103  break;
104 
105  case IDC_UPDATE_AVLIST:
106  NewSettingsInfo.bUpdateAtStart = IsCheckedDlgItem(hDlg, IDC_UPDATE_AVLIST);
107  break;
108 
109  case IDC_LOG_ENABLED:
110  NewSettingsInfo.bLogEnabled = IsCheckedDlgItem(hDlg, IDC_LOG_ENABLED);
111  break;
112 
114  NewSettingsInfo.bDelInstaller = IsCheckedDlgItem(hDlg, IDC_DEL_AFTER_INSTALL);
115  break;
116 
117  case IDC_PROXY_DEFAULT:
118  NewSettingsInfo.Proxy = 0;
121  break;
122 
123  case IDC_NO_PROXY:
124  NewSettingsInfo.Proxy = 1;
127  break;
128 
129  case IDC_USE_PROXY:
130  NewSettingsInfo.Proxy = 2;
133  break;
134 
136  FillDefaultSettings(&NewSettingsInfo);
137  InitSettingsControls(hDlg, &NewSettingsInfo);
138  break;
139 
140  case IDOK:
141  {
142  ATL::CStringW szDir;
143  ATL::CStringW szProxy;
144  ATL::CStringW szNoProxy;
145  DWORD dwAttr;
146 
148  szDir.GetBuffer(MAX_PATH), MAX_PATH);
149  szDir.ReleaseBuffer();
150 
152  szProxy.GetBuffer(MAX_PATH), MAX_PATH);
153  szProxy.ReleaseBuffer();
154  ATL::CStringW::CopyChars(NewSettingsInfo.szProxyServer,
155  _countof(NewSettingsInfo.szProxyServer),
156  szProxy.GetString(),
157  szProxy.GetLength() + 1);
158 
160  szNoProxy.GetBuffer(MAX_PATH), MAX_PATH);
161  szNoProxy.ReleaseBuffer();
162  ATL::CStringW::CopyChars(NewSettingsInfo.szNoProxyFor,
163  _countof(NewSettingsInfo.szNoProxyFor),
164  szNoProxy.GetString(),
165  szNoProxy.GetLength() + 1);
166 
167  dwAttr = GetFileAttributesW(szDir.GetString());
168  if (dwAttr != INVALID_FILE_ATTRIBUTES &&
169  (dwAttr & FILE_ATTRIBUTE_DIRECTORY))
170  {
171  ATL::CStringW::CopyChars(NewSettingsInfo.szDownloadDir,
172  _countof(NewSettingsInfo.szDownloadDir),
173  szDir.GetString(),
174  szDir.GetLength() + 1);
175  }
176  else
177  {
178  ATL::CStringW szMsgText;
179  szMsgText.LoadStringW(IDS_CHOOSE_FOLDER_ERROR);
180 
181  if (MessageBoxW(hDlg, szMsgText.GetString(), NULL, MB_YESNO) == IDYES)
182  {
183  if (CreateDirectoryW(szDir.GetString(), NULL))
184  {
185  EndDialog(hDlg, LOWORD(wParam));
186  }
187  }
188  else
189  {
191  break;
192  }
193  }
194 
196  SaveSettings(GetParent(hDlg));
197  EndDialog(hDlg, LOWORD(wParam));
198  }
199  break;
200 
201  case IDCANCEL:
202  EndDialog(hDlg, LOWORD(wParam));
203  break;
204  }
205  }
206  break;
207  }
208 
209  return FALSE;
210  }
211 }
212 
214 {
217  hwnd,
219 }
int GetLength() const
Definition: atlsimpstr.h:356
BOOL WINAPI CreateDirectoryW(IN LPCWSTR lpPathName, IN LPSECURITY_ATTRIBUTES lpSecurityAttributes)
Definition: dir.c:90
BOOL bUpdateAtStart
Definition: winmain.h:8
const DOCKBAR PVOID HWND HWND * hwnd
Definition: tooldock.h:22
#define IDC_USE_PROXY
Definition: resource.h:53
#define TRUE
Definition: types.h:120
#define IDOK
Definition: winuser.h:824
VOID WINAPI CoTaskMemFree(LPVOID ptr)
Definition: ifs.c:422
#define IDYES
Definition: winuser.h:829
#define _countof(array)
Definition: fontsub.cpp:30
#define IDC_DOWNLOAD_DIR_EDIT
Definition: resource.h:43
BOOL WINAPI SHGetPathFromIDListW(LPCITEMIDLIST pidl, LPWSTR pszPath)
Definition: pidl.c:1280
#define CALLBACK
Definition: compat.h:27
HWND hwndOwner
Definition: shlobj.h:991
#define ZeroMemory
Definition: winbase.h:1635
_In_ int nIDDlgItem
Definition: winuser.h:4488
HWND WINAPI SetFocus(_In_opt_ HWND)
BOOL WINAPI SetWindowTextW(_In_ HWND, _In_opt_ LPCWSTR)
SETTINGS_INFO NewSettingsInfo
Definition: settingsdlg.cpp:11
#define IDC_UPDATE_AVLIST
Definition: resource.h:42
VOID CreateSettingsDlg(HWND hwnd)
int32_t INT_PTR
Definition: typedefs.h:62
#define IDS_CHOOSE_FOLDER_ERROR
Definition: resource.h:99
int32_t INT
Definition: typedefs.h:56
BOOL WINAPI EndDialog(_In_ HWND, _In_ INT_PTR)
WPARAM wParam
Definition: combotst.c:138
struct TraceInfo Info
#define IDD_SETTINGS_DIALOG
Definition: resource.h:58
struct @1571 Msg[]
UINT_PTR WPARAM
Definition: windef.h:207
WCHAR szDownloadDir[MAX_PATH]
Definition: winmain.h:10
BOOL WINAPI SetDlgItemTextW(_In_ HWND, _In_ int, _In_ LPCWSTR)
void SaveSettings(void)
Definition: settings.c:113
INT_PTR CALLBACK SettingsDlgProc(HWND hDlg, UINT Msg, WPARAM wParam, LPARAM lParam)
Definition: settingsdlg.cpp:82
#define IDC_CHOOSE
Definition: resource.h:46
#define IDC_LOG_ENABLED
Definition: resource.h:45
void ReleaseBuffer(_In_ int nNewLength=-1)
Definition: atlsimpstr.h:372
#define MB_YESNO
Definition: winuser.h:811
LONG_PTR LPARAM
Definition: windef.h:208
DWORD WINAPI GetFileAttributesW(LPCWSTR lpFileName)
Definition: fileinfo.c:802
#define BIF_DONTGOBELOWDOMAIN
Definition: shlobj.h:1009
smooth NULL
Definition: ftsmooth.c:416
#define IDS_CHOOSE_FOLDER_TEXT
Definition: resource.h:98
SETTINGS_INFO SettingsInfo
Definition: winmain.cpp:19
#define IDC_PROXY_DEFAULT
Definition: resource.h:51
#define BM_GETCHECK
Definition: winuser.h:1879
VOID FillDefaultSettings(PSETTINGS_INFO pSettingsInfo)
Definition: winmain.cpp:46
#define DialogBoxW(i, t, p, f)
Definition: winuser.h:4268
#define FILE_ATTRIBUTE_DIRECTORY
Definition: nt_native.h:705
LPCWSTR lpszTitle
Definition: shlobj.h:994
#define IDC_DEL_AFTER_INSTALL
Definition: resource.h:44
LPCITEMIDLIST pidlRoot
Definition: shlobj.h:992
#define BM_SETCHECK
Definition: winuser.h:1882
unsigned int BOOL
Definition: ntddk_ex.h:94
int WINAPI MessageBoxW(_In_opt_ HWND, _In_opt_ LPCWSTR, _In_opt_ LPCWSTR, _In_ UINT)
HWND WINAPI GetDlgItem(_In_opt_ HWND, _In_ int)
BOOL IsCheckedDlgItem(HWND hDlg, INT nIDDlgItem)
Definition: settingsdlg.cpp:55
#define IDC_NO_PROXY_FOR
Definition: resource.h:55
#define IDC_DEFAULT_SETTINGS
Definition: resource.h:47
#define MAX_PATH
Definition: compat.h:26
PCXSTR GetString() const
Definition: atlsimpstr.h:361
unsigned int UINT
Definition: ndis.h:50
unsigned long DWORD
Definition: ntddk_ex.h:95
LRESULT WINAPI SendDlgItemMessageW(_In_ HWND, _In_ int, _In_ UINT, _In_ WPARAM, _In_ LPARAM)
#define BIF_USENEWUI
Definition: shlobj.h:1015
#define INVALID_FILE_ATTRIBUTES
Definition: vfdcmd.c:23
#define WM_COMMAND
Definition: winuser.h:1716
VOID InitSettingsControls(HWND hDlg, PSETTINGS_INFO Info)
Definition: settingsdlg.cpp:60
BOOL WINAPI EnableWindow(_In_ HWND, _In_ BOOL)
LPITEMIDLIST WINAPI SHBrowseForFolderW(LPBROWSEINFOW lpbi)
Definition: brsfolder.c:1156
BOOL ChooseFolder(HWND hwnd)
Definition: settingsdlg.cpp:13
bool IsEmpty() const
Definition: atlsimpstr.h:379
HWND WINAPI GetParent(_In_ HWND)
WCHAR szProxyServer[MAX_PATH]
Definition: winmain.h:20
HINSTANCE hInst
Definition: dxdiag.c:13
UINT ulFlags
Definition: shlobj.h:995
BOOL bLogEnabled
Definition: winmain.h:9
#define BIF_RETURNONLYFSDIRS
Definition: shlobj.h:1008
int WINAPI GetWindowTextW(HWND hWnd, LPWSTR lpString, int nMaxCount)
Definition: window.c:1378
void WINAPI DECLSPEC_HOTPATCH CoUninitialize(void)
Definition: compobj.c:1994
#define IDC_SAVE_WINDOW_POS
Definition: resource.h:41
#define IDC_NO_PROXY
Definition: resource.h:52
HRESULT WINAPI DECLSPEC_HOTPATCH CoInitializeEx(LPVOID lpReserved, DWORD dwCoInit)
Definition: compobj.c:1938
static void __cdecl CopyChars(_Out_writes_to_(nDestLen, nChars) XCHAR *pchDest, _In_ size_t nDestLen, _In_reads_opt_(nChars) const XCHAR *pchSrc, _In_ int nChars)
Definition: atlsimpstr.h:423
BOOL bDelInstaller
Definition: winmain.h:11
#define BST_CHECKED
Definition: winuser.h:197
#define IDC_PROXY_SERVER
Definition: resource.h:54
#define BIF_VALIDATE
Definition: shlobj.h:1013
BOOL bSaveWndPos
Definition: winmain.h:7
WCHAR szNoProxyFor[MAX_PATH]
Definition: winmain.h:21
BOOL WINAPI CheckRadioButton(_In_ HWND, _In_ int, _In_ int, _In_ int)
#define MAKEINTRESOURCEW(i)
Definition: winuser.h:582
#define IDCANCEL
Definition: winuser.h:825
ITEMIDLIST UNALIGNED * LPITEMIDLIST
Definition: shtypes.idl:41
#define WM_INITDIALOG
Definition: winuser.h:1715
LPARAM lParam
Definition: combotst.c:139
#define LOWORD(l)
Definition: pedump.c:82
#define SUCCEEDED(hr)
Definition: intsafe.h:57