1 /* -*- Mode: C; tab-width: 4 -*-
2 *
3 * Copyright (c) 2002-2004 Apple Computer, Inc. All rights reserved.
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
18 #include "ServicesPage.h"
19 #include "resource.h"
20
21 #include "ControlPanelExe.h"
22 #include "ConfigPropertySheet.h"
23
24 #include <WinServices.h>
25
26 #define MAX_KEY_LENGTH 255
27
28
IMPLEMENT_DYNCREATE(CServicesPage,CPropertyPage)29 IMPLEMENT_DYNCREATE(CServicesPage, CPropertyPage)
30
31
32 //---------------------------------------------------------------------------------------------------------------------------
33 // CServicesPage::CServicesPage
34 //---------------------------------------------------------------------------------------------------------------------------
35
36 CServicesPage::CServicesPage()
37 :
38 CPropertyPage(CServicesPage::IDD)
39 {
40 //{{AFX_DATA_INIT(CServicesPage)
41 //}}AFX_DATA_INIT
42 }
43
44
45 //---------------------------------------------------------------------------------------------------------------------------
46 // CServicesPage::~CServicesPage
47 //---------------------------------------------------------------------------------------------------------------------------
48
~CServicesPage()49 CServicesPage::~CServicesPage()
50 {
51 }
52
53
54 //---------------------------------------------------------------------------------------------------------------------------
55 // CServicesPage::DoDataExchange
56 //---------------------------------------------------------------------------------------------------------------------------
57
DoDataExchange(CDataExchange * pDX)58 void CServicesPage::DoDataExchange(CDataExchange* pDX)
59 {
60 CPropertyPage::DoDataExchange(pDX);
61 //{{AFX_DATA_MAP(CServicesPage)
62 //}}AFX_DATA_MAP
63 DDX_Control(pDX, IDC_ADVERTISE_SMB, m_SMBCheckBox);
64 DDX_Control(pDX, IDC_POWER_MANAGEMENT, m_powerManagementCheckBox);
65 }
66
BEGIN_MESSAGE_MAP(CServicesPage,CPropertyPage)67 BEGIN_MESSAGE_MAP(CServicesPage, CPropertyPage)
68 //{{AFX_MSG_MAP(CServicesPage)
69 //}}AFX_MSG_MAP
70
71 ON_BN_CLICKED(IDC_ADVERTISE_SMB, &CServicesPage::OnBnClickedAdvertiseSMB)
72 ON_BN_CLICKED(IDC_POWER_MANAGEMENT, &CServicesPage::OnBnClickedPowerManagement)
73
74 END_MESSAGE_MAP()
75
76
77 //---------------------------------------------------------------------------------------------------------------------------
78 // CServicesPage::SetModified
79 //---------------------------------------------------------------------------------------------------------------------------
80
81 void CServicesPage::SetModified( BOOL bChanged )
82 {
83 m_modified = bChanged;
84
85 CPropertyPage::SetModified( bChanged );
86 }
87
88
89 //---------------------------------------------------------------------------------------------------------------------------
90 // CServicesPage::OnSetActive
91 //---------------------------------------------------------------------------------------------------------------------------
92
93 BOOL
OnSetActive()94 CServicesPage::OnSetActive()
95 {
96 CConfigPropertySheet * psheet;
97 HKEY key = NULL;
98 DWORD dwSize;
99 DWORD enabled;
100 DWORD err;
101 BOOL b = CPropertyPage::OnSetActive();
102
103 psheet = reinterpret_cast<CConfigPropertySheet*>(GetParent());
104 require_quiet( psheet, exit );
105
106 m_SMBCheckBox.SetCheck( 0 );
107
108 // Now populate the browse domain box
109
110 err = RegCreateKeyEx( HKEY_LOCAL_MACHINE, kServiceParametersNode L"\\Services\\SMB", 0,
111 NULL, REG_OPTION_NON_VOLATILE, KEY_READ|KEY_WRITE|KEY_WOW64_32KEY, NULL, &key, NULL );
112 require_noerr( err, exit );
113
114 dwSize = sizeof( DWORD );
115 err = RegQueryValueEx( key, L"Advertise", NULL, NULL, (LPBYTE) &enabled, &dwSize );
116 require_noerr( err, exit );
117
118 m_SMBCheckBox.SetCheck( enabled );
119
120 RegCloseKey( key );
121 key = NULL;
122
123 m_powerManagementCheckBox.SetCheck( 0 );
124
125 // Now populate the browse domain box
126
127 err = RegCreateKeyEx( HKEY_LOCAL_MACHINE, kServiceParametersNode L"\\Power Management", 0,
128 NULL, REG_OPTION_NON_VOLATILE, KEY_READ|KEY_WRITE|KEY_WOW64_32KEY, NULL, &key, NULL );
129 require_noerr( err, exit );
130
131 dwSize = sizeof( DWORD );
132 err = RegQueryValueEx( key, L"Enabled", NULL, NULL, (LPBYTE) &enabled, &dwSize );
133 require_noerr( err, exit );
134
135 m_powerManagementCheckBox.SetCheck( enabled );
136
137 exit:
138
139 if ( key )
140 {
141 RegCloseKey( key );
142 }
143
144 return b;
145 }
146
147
148 //---------------------------------------------------------------------------------------------------------------------------
149 // CServicesPage::OnOK
150 //---------------------------------------------------------------------------------------------------------------------------
151
152 void
OnOK()153 CServicesPage::OnOK()
154 {
155 if ( m_modified )
156 {
157 Commit();
158 }
159 }
160
161
162
163 //---------------------------------------------------------------------------------------------------------------------------
164 // CServicesPage::Commit
165 //---------------------------------------------------------------------------------------------------------------------------
166
167 void
Commit()168 CServicesPage::Commit()
169 {
170 HKEY key = NULL;
171 DWORD enabled;
172 DWORD err;
173
174 err = RegCreateKeyEx( HKEY_LOCAL_MACHINE, kServiceParametersNode L"\\Services\\SMB", 0,
175 NULL, REG_OPTION_NON_VOLATILE, KEY_READ|KEY_WRITE|KEY_WOW64_32KEY, NULL, &key, NULL );
176 require_noerr( err, exit );
177
178 enabled = m_SMBCheckBox.GetCheck();
179 err = RegSetValueEx( key, L"Advertise", NULL, REG_DWORD, (LPBYTE) &enabled, sizeof( enabled ) );
180 require_noerr( err, exit );
181
182 RegCloseKey( key );
183 key = NULL;
184
185 err = RegCreateKeyEx( HKEY_LOCAL_MACHINE, kServiceParametersNode L"\\Power Management", 0,
186 NULL, REG_OPTION_NON_VOLATILE, KEY_READ|KEY_WRITE|KEY_WOW64_32KEY, NULL, &key, NULL );
187 require_noerr( err, exit );
188
189 enabled = m_powerManagementCheckBox.GetCheck();
190 err = RegSetValueEx( key, L"Enabled", NULL, REG_DWORD, (LPBYTE) &enabled, sizeof( enabled ) );
191 require_noerr( err, exit );
192
193 exit:
194
195 if ( key )
196 {
197 RegCloseKey( key );
198 }
199 }
200
201
202 //---------------------------------------------------------------------------------------------------------------------------
203 // CServicesPage::OnBnClickedAdvertiseSMB
204 //---------------------------------------------------------------------------------------------------------------------------
205
OnBnClickedAdvertiseSMB()206 void CServicesPage::OnBnClickedAdvertiseSMB()
207 {
208 SetModified( TRUE );
209 }
210
211
212 //---------------------------------------------------------------------------------------------------------------------------
213 // CServicesPage::OnBnClickedPowerManagement
214 //---------------------------------------------------------------------------------------------------------------------------
215
OnBnClickedPowerManagement()216 void CServicesPage::OnBnClickedPowerManagement()
217 {
218 SetModified( TRUE );
219
220 if ( m_powerManagementCheckBox.GetCheck() )
221 {
222 CPowerManagementWarning dlg( GetParent() );
223
224 dlg.DoModal();
225 }
226 }
227
228
229 // CPowerManagementWarning dialog
230
IMPLEMENT_DYNAMIC(CPowerManagementWarning,CDialog)231 IMPLEMENT_DYNAMIC(CPowerManagementWarning, CDialog)
232 CPowerManagementWarning::CPowerManagementWarning(CWnd* pParent /*=NULL*/)
233 : CDialog(CPowerManagementWarning::IDD, pParent)
234 {
235 }
236
~CPowerManagementWarning()237 CPowerManagementWarning::~CPowerManagementWarning()
238 {
239 }
240
DoDataExchange(CDataExchange * pDX)241 void CPowerManagementWarning::DoDataExchange(CDataExchange* pDX)
242 {
243 CDialog::DoDataExchange(pDX);
244 DDX_Control(pDX, IDC_ENERGY_SAVER, m_energySaverIcon);
245 }
246
247
248 BOOL
OnInitDialog()249 CPowerManagementWarning::OnInitDialog()
250 {
251 BOOL b = CDialog::OnInitDialog();
252
253 const HICON hIcon = ( HICON ) ::LoadImage( GetNonLocalizedResources(), MAKEINTRESOURCE( IDI_ENERGY_SAVER ), IMAGE_ICON, 0, 0, 0);
254
255 if ( hIcon )
256 {
257 m_energySaverIcon.SetIcon( hIcon );
258 }
259
260 return b;
261 }
262
263
264 void
OnOK()265 CPowerManagementWarning::OnOK()
266 {
267 CDialog::OnOK();
268 }
269
270
271 BEGIN_MESSAGE_MAP(CPowerManagementWarning, CDialog)
272 END_MESSAGE_MAP()
273
274