- Sync with trunk up to r46941.
[reactos.git] / base / applications / rapps / settingsdlg.c
1 /*
2 * PROJECT: ReactOS Applications Manager
3 * LICENSE: GPL - See COPYING in the top level directory
4 * FILE: base/applications/rapps/settingsdlg.c
5 * PURPOSE: Settings Dialog
6 * PROGRAMMERS: Dmitry Chapyshev (dmitry@reactos.org)
7 */
8
9 #include "rapps.h"
10
11 SETTINGS_INFO NewSettingsInfo;
12
13 #define IS_CHECKED(a, b) \
14 a = (SendDlgItemMessage(hDlg, b, BM_GETCHECK, 0, 0) == BST_CHECKED) ? TRUE : FALSE
15
16 BOOL
17 ChooseFolder(HWND hwnd)
18 {
19 BROWSEINFO fi;
20 LPCITEMIDLIST lpItemList;
21 WCHAR szPath[MAX_PATH], szBuf[MAX_STR_LEN];
22
23 LoadStringW(hInst, IDS_CHOOSE_FOLDER_TEXT, szBuf, sizeof(szBuf) / sizeof(TCHAR));
24
25 ZeroMemory(&fi, sizeof(BROWSEINFO));
26 fi.hwndOwner = hwnd;
27 fi.lpszTitle = szBuf;
28 fi.ulFlags = BIF_DONTGOBELOWDOMAIN | BIF_RETURNONLYFSDIRS | BIF_BROWSEFORCOMPUTER | BIF_NEWDIALOGSTYLE;
29 fi.lpfn = NULL;
30 fi.lParam = -1;
31 fi.iImage = 0;
32
33 if (!(lpItemList = SHBrowseForFolder(&fi))) return FALSE;
34 SHGetPathFromIDList(lpItemList, szPath);
35
36 if (wcslen(szPath) == 0) return FALSE;
37 SetDlgItemTextW(hwnd, IDC_DOWNLOAD_DIR_EDIT, szPath);
38
39 return TRUE;
40 }
41
42 static VOID
43 InitSettingsControls(HWND hDlg, SETTINGS_INFO Info)
44 {
45 SendDlgItemMessage(hDlg, IDC_SAVE_WINDOW_POS, BM_SETCHECK, Info.bSaveWndPos, 0);
46 SendDlgItemMessage(hDlg, IDC_UPDATE_AVLIST, BM_SETCHECK, Info.bUpdateAtStart, 0);
47 SendDlgItemMessage(hDlg, IDC_LOG_ENABLED, BM_SETCHECK, Info.bLogEnabled, 0);
48 SendDlgItemMessage(hDlg, IDC_DEL_AFTER_INSTALL, BM_SETCHECK, Info.bDelInstaller, 0);
49
50 SetWindowTextW(GetDlgItem(hDlg, IDC_DOWNLOAD_DIR_EDIT),
51 Info.szDownloadDir);
52 }
53
54 static
55 INT_PTR CALLBACK
56 SettingsDlgProc(HWND hDlg, UINT Msg, WPARAM wParam, LPARAM lParam)
57 {
58 switch (Msg)
59 {
60 case WM_INITDIALOG:
61 {
62 NewSettingsInfo = SettingsInfo;
63 InitSettingsControls(hDlg, SettingsInfo);
64 }
65 break;
66
67 case WM_COMMAND:
68 {
69 switch (LOWORD(wParam))
70 {
71 case IDC_CHOOSE:
72 ChooseFolder(hDlg);
73 break;
74
75 case IDC_SAVE_WINDOW_POS:
76 IS_CHECKED(NewSettingsInfo.bSaveWndPos, IDC_SAVE_WINDOW_POS);
77 break;
78
79 case IDC_UPDATE_AVLIST:
80 IS_CHECKED(NewSettingsInfo.bUpdateAtStart, IDC_UPDATE_AVLIST);
81 break;
82
83 case IDC_LOG_ENABLED:
84 IS_CHECKED(NewSettingsInfo.bLogEnabled, IDC_LOG_ENABLED);
85 break;
86
87 case IDC_DEL_AFTER_INSTALL:
88 IS_CHECKED(NewSettingsInfo.bDelInstaller, IDC_DEL_AFTER_INSTALL);
89 break;
90
91 case IDC_DEFAULT_SETTINGS:
92 FillDafaultSettings(&NewSettingsInfo);
93 InitSettingsControls(hDlg, NewSettingsInfo);
94 break;
95
96 case IDOK:
97 {
98 WCHAR szDir[MAX_PATH];
99 DWORD dwAttr;
100
101 GetWindowTextW(GetDlgItem(hDlg, IDC_DOWNLOAD_DIR_EDIT),
102 szDir, MAX_PATH);
103
104 dwAttr = GetFileAttributesW(szDir);
105 if (dwAttr != INVALID_FILE_ATTRIBUTES &&
106 (dwAttr & FILE_ATTRIBUTE_DIRECTORY))
107 {
108 wcscpy(NewSettingsInfo.szDownloadDir, szDir);
109 }
110 else
111 {
112 WCHAR szMsgText[MAX_STR_LEN];
113
114 LoadStringW(hInst,
115 IDS_CHOOSE_FOLDER_ERROR,
116 szMsgText, sizeof(szMsgText) / sizeof(WCHAR));
117
118 MessageBoxW(hDlg, szMsgText, NULL, MB_OK | MB_ICONERROR);
119 SetFocus(GetDlgItem(hDlg, IDC_DOWNLOAD_DIR_EDIT));
120 break;
121 }
122
123 SettingsInfo = NewSettingsInfo;
124 SaveSettings(GetParent(hDlg));
125 EndDialog(hDlg, LOWORD(wParam));
126 }
127 break;
128
129 case IDCANCEL:
130 EndDialog(hDlg, LOWORD(wParam));
131 break;
132 }
133 }
134 break;
135 }
136
137 return FALSE;
138 }
139
140 VOID
141 CreateSettingsDlg(HWND hwnd)
142 {
143 DialogBoxW(hInst,
144 MAKEINTRESOURCEW(IDD_SETTINGS_DIALOG),
145 hwnd,
146 SettingsDlgProc);
147 }