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 11 SETTINGS_INFO NewSettingsInfo; 12 13 BOOL ChooseFolder(HWND hwnd) 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 27 if (SUCCEEDED(CoInitializeEx(NULL, COINIT_APARTMENTTHREADED))) 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 { 37 SetDlgItemTextW(hwnd, IDC_DOWNLOAD_DIR_EDIT, szBuf.GetString()); 38 bRet = TRUE; 39 } 40 } 41 else 42 { 43 szBuf.ReleaseBuffer(); 44 } 45 46 CoTaskMemFree(lpItemList); 47 CoUninitialize(); 48 } 49 50 return bRet; 51 } 52 53 namespace 54 { 55 inline BOOL IsCheckedDlgItem(HWND hDlg, INT nIDDlgItem) 56 { 57 return (SendDlgItemMessageW(hDlg, nIDDlgItem, BM_GETCHECK, 0, 0) == BST_CHECKED) ? TRUE : FALSE; 58 } 59 60 VOID InitSettingsControls(HWND hDlg, PSETTINGS_INFO Info) 61 { 62 SendDlgItemMessageW(hDlg, IDC_SAVE_WINDOW_POS, BM_SETCHECK, Info->bSaveWndPos, 0); 63 SendDlgItemMessageW(hDlg, IDC_UPDATE_AVLIST, BM_SETCHECK, Info->bUpdateAtStart, 0); 64 SendDlgItemMessageW(hDlg, IDC_LOG_ENABLED, BM_SETCHECK, Info->bLogEnabled, 0); 65 SendDlgItemMessageW(hDlg, IDC_DEL_AFTER_INSTALL, BM_SETCHECK, Info->bDelInstaller, 0); 66 67 SetWindowTextW(GetDlgItem(hDlg, IDC_DOWNLOAD_DIR_EDIT), 68 Info->szDownloadDir); 69 70 CheckRadioButton(hDlg, IDC_PROXY_DEFAULT, IDC_USE_PROXY, IDC_PROXY_DEFAULT + Info->Proxy); 71 72 if (IDC_PROXY_DEFAULT + Info->Proxy == IDC_USE_PROXY) 73 { 74 EnableWindow(GetDlgItem(hDlg, IDC_PROXY_SERVER), TRUE); 75 EnableWindow(GetDlgItem(hDlg, IDC_NO_PROXY_FOR), TRUE); 76 } 77 78 SetWindowTextW(GetDlgItem(hDlg, IDC_PROXY_SERVER), Info->szProxyServer); 79 SetWindowTextW(GetDlgItem(hDlg, IDC_NO_PROXY_FOR), Info->szNoProxyFor); 80 } 81 82 INT_PTR CALLBACK SettingsDlgProc(HWND hDlg, UINT Msg, WPARAM wParam, LPARAM lParam) 83 { 84 switch (Msg) 85 { 86 case WM_INITDIALOG: 87 { 88 NewSettingsInfo = SettingsInfo; 89 InitSettingsControls(hDlg, &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 113 case IDC_DEL_AFTER_INSTALL: 114 NewSettingsInfo.bDelInstaller = IsCheckedDlgItem(hDlg, IDC_DEL_AFTER_INSTALL); 115 break; 116 117 case IDC_PROXY_DEFAULT: 118 NewSettingsInfo.Proxy = 0; 119 EnableWindow(GetDlgItem(hDlg, IDC_PROXY_SERVER), FALSE); 120 EnableWindow(GetDlgItem(hDlg, IDC_NO_PROXY_FOR), FALSE); 121 break; 122 123 case IDC_NO_PROXY: 124 NewSettingsInfo.Proxy = 1; 125 EnableWindow(GetDlgItem(hDlg, IDC_PROXY_SERVER), FALSE); 126 EnableWindow(GetDlgItem(hDlg, IDC_NO_PROXY_FOR), FALSE); 127 break; 128 129 case IDC_USE_PROXY: 130 NewSettingsInfo.Proxy = 2; 131 EnableWindow(GetDlgItem(hDlg, IDC_PROXY_SERVER), TRUE); 132 EnableWindow(GetDlgItem(hDlg, IDC_NO_PROXY_FOR), TRUE); 133 break; 134 135 case IDC_DEFAULT_SETTINGS: 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 147 GetWindowTextW(GetDlgItem(hDlg, IDC_DOWNLOAD_DIR_EDIT), 148 szDir.GetBuffer(MAX_PATH), MAX_PATH); 149 szDir.ReleaseBuffer(); 150 151 GetWindowTextW(GetDlgItem(hDlg, IDC_PROXY_SERVER), 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 159 GetWindowTextW(GetDlgItem(hDlg, IDC_NO_PROXY_FOR), 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 { 190 SetFocus(GetDlgItem(hDlg, IDC_DOWNLOAD_DIR_EDIT)); 191 break; 192 } 193 } 194 195 SettingsInfo = NewSettingsInfo; 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 213 VOID CreateSettingsDlg(HWND hwnd) 214 { 215 DialogBoxW(hInst, 216 MAKEINTRESOURCEW(IDD_SETTINGS_DIALOG), 217 hwnd, 218 SettingsDlgProc); 219 } 220