]> git.saurik.com Git - apple/mdnsresponder.git/blob - mDNSWindows/ControlPanel/ThirdPage.cpp
mDNSResponder-107.5.tar.gz
[apple/mdnsresponder.git] / mDNSWindows / ControlPanel / ThirdPage.cpp
1 /*
2 * Copyright (c) 2002-2004 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. Please obtain a copy of the License at
10 * http://www.opensource.apple.com/apsl/ and read it before using this
11 * file.
12 *
13 * The Original Code and all software distributed under the License are
14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
18 * Please see the License for the specific language governing rights and
19 * limitations under the License.
20 *
21 * @APPLE_LICENSE_HEADER_END@
22
23 Change History (most recent first):
24
25 $Log: ThirdPage.cpp,v $
26 Revision 1.4 2005/10/05 20:46:50 herscher
27 <rdar://problem/4192011> Move Wide-Area preferences to another part of the registry so they don't removed during an update-install.
28
29 Revision 1.3 2005/03/07 18:27:42 shersche
30 <rdar://problem/4037940> Fix problem when ControlPanel commits changes to the browse domain list
31
32 Revision 1.2 2005/03/03 19:55:22 shersche
33 <rdar://problem/4034481> ControlPanel source code isn't saving CVS log info
34
35
36 */
37
38 #include "ThirdPage.h"
39 #include "resource.h"
40
41 #include "ConfigPropertySheet.h"
42 #include "SharedSecret.h"
43
44 #include <WinServices.h>
45
46 #define MAX_KEY_LENGTH 255
47
48
49 IMPLEMENT_DYNCREATE(CThirdPage, CPropertyPage)
50
51
52 //---------------------------------------------------------------------------------------------------------------------------
53 // CThirdPage::CThirdPage
54 //---------------------------------------------------------------------------------------------------------------------------
55
56 CThirdPage::CThirdPage()
57 :
58 CPropertyPage(CThirdPage::IDD)
59 {
60 //{{AFX_DATA_INIT(CThirdPage)
61 //}}AFX_DATA_INIT
62
63 m_firstTime = true;
64 }
65
66
67 //---------------------------------------------------------------------------------------------------------------------------
68 // CThirdPage::~CThirdPage
69 //---------------------------------------------------------------------------------------------------------------------------
70
71 CThirdPage::~CThirdPage()
72 {
73 }
74
75
76 //---------------------------------------------------------------------------------------------------------------------------
77 // CThirdPage::DoDataExchange
78 //---------------------------------------------------------------------------------------------------------------------------
79
80 void CThirdPage::DoDataExchange(CDataExchange* pDX)
81 {
82 CPropertyPage::DoDataExchange(pDX);
83 //{{AFX_DATA_MAP(CThirdPage)
84 //}}AFX_DATA_MAP
85 DDX_Control(pDX, IDC_BROWSE_LIST, m_browseListCtrl);
86 DDX_Control(pDX, IDC_REMOVE_BROWSE_DOMAIN, m_removeButton);
87 }
88
89 BEGIN_MESSAGE_MAP(CThirdPage, CPropertyPage)
90 //{{AFX_MSG_MAP(CThirdPage)
91 //}}AFX_MSG_MAP
92 ON_BN_CLICKED(IDC_ADD_BROWSE_DOMAIN, OnBnClickedAddBrowseDomain)
93 ON_BN_CLICKED(IDC_REMOVE_BROWSE_DOMAIN, OnBnClickedRemoveBrowseDomain)
94 ON_NOTIFY(LVN_ITEMCHANGED, IDC_BROWSE_LIST, OnLvnItemchangedBrowseList)
95 END_MESSAGE_MAP()
96
97
98 //---------------------------------------------------------------------------------------------------------------------------
99 // CThirdPage::SetModified
100 //---------------------------------------------------------------------------------------------------------------------------
101
102 void CThirdPage::SetModified( BOOL bChanged )
103 {
104 m_modified = bChanged;
105
106 CPropertyPage::SetModified( bChanged );
107 }
108
109
110 //---------------------------------------------------------------------------------------------------------------------------
111 // CThirdPage::OnSetActive
112 //---------------------------------------------------------------------------------------------------------------------------
113
114 BOOL
115 CThirdPage::OnSetActive()
116 {
117 CConfigPropertySheet * psheet;
118 HKEY key = NULL;
119 HKEY subKey = NULL;
120 DWORD dwSize;
121 DWORD enabled;
122 DWORD err;
123 TCHAR subKeyName[MAX_KEY_LENGTH];
124 DWORD cSubKeys = 0;
125 DWORD cbMaxSubKey;
126 DWORD cchMaxClass;
127 int nIndex;
128 DWORD i;
129 BOOL b = CPropertyPage::OnSetActive();
130
131 psheet = reinterpret_cast<CConfigPropertySheet*>(GetParent());
132 require_quiet( psheet, exit );
133
134 m_modified = FALSE;
135
136 if ( m_firstTime )
137 {
138 m_browseListCtrl.SetExtendedStyle((m_browseListCtrl.GetStyle() & (~LVS_EX_GRIDLINES))|LVS_EX_CHECKBOXES | LVS_EX_FULLROWSELECT);
139
140 m_browseListCtrl.InsertColumn(0, L"", LVCFMT_LEFT, 20 );
141 m_browseListCtrl.InsertColumn(1, L"", LVCFMT_LEFT, 345);
142
143 m_firstTime = false;
144 }
145
146 m_initialized = false;
147
148 // Clear out what's there
149
150 m_browseListCtrl.DeleteAllItems();
151
152 // Now populate the browse domain box
153
154 err = RegCreateKey( HKEY_LOCAL_MACHINE, kServiceParametersNode L"\\DynDNS\\Setup\\" kServiceDynDNSBrowseDomains, &key );
155 require_noerr( err, exit );
156
157 // Get information about this node
158
159 err = RegQueryInfoKey( key, NULL, NULL, NULL, &cSubKeys, &cbMaxSubKey, &cchMaxClass, NULL, NULL, NULL, NULL, NULL );
160 require_noerr( err, exit );
161
162 for ( i = 0; i < cSubKeys; i++)
163 {
164 dwSize = MAX_KEY_LENGTH;
165
166 err = RegEnumKeyEx( key, i, subKeyName, &dwSize, NULL, NULL, NULL, NULL );
167 require_noerr( err, exit );
168
169 err = RegOpenKey( key, subKeyName, &subKey );
170 require_noerr( err, exit );
171
172 dwSize = sizeof( DWORD );
173 err = RegQueryValueEx( subKey, L"Enabled", NULL, NULL, (LPBYTE) &enabled, &dwSize );
174 require_noerr( err, exit );
175
176 nIndex = m_browseListCtrl.InsertItem( m_browseListCtrl.GetItemCount(), L"");
177 m_browseListCtrl.SetItemText( nIndex, 1, subKeyName );
178 m_browseListCtrl.SetCheck( nIndex, enabled );
179
180 RegCloseKey( subKey );
181 subKey = NULL;
182 }
183
184 m_browseListCtrl.SortItems( SortFunc, (DWORD_PTR) this );
185
186 m_removeButton.EnableWindow( FALSE );
187
188 exit:
189
190 if ( subKey )
191 {
192 RegCloseKey( subKey );
193 }
194
195 if ( key )
196 {
197 RegCloseKey( key );
198 }
199
200 m_initialized = true;
201
202 return b;
203 }
204
205
206
207 //---------------------------------------------------------------------------------------------------------------------------
208 // CThirdPage::OnOK
209 //---------------------------------------------------------------------------------------------------------------------------
210
211 void
212 CThirdPage::OnOK()
213 {
214 if ( m_modified )
215 {
216 Commit();
217 }
218 }
219
220
221
222 //---------------------------------------------------------------------------------------------------------------------------
223 // CThirdPage::Commit
224 //---------------------------------------------------------------------------------------------------------------------------
225
226 void
227 CThirdPage::Commit()
228 {
229 HKEY key = NULL;
230 HKEY subKey = NULL;
231 TCHAR subKeyName[MAX_KEY_LENGTH];
232 DWORD cSubKeys = 0;
233 DWORD cbMaxSubKey;
234 DWORD cchMaxClass;
235 DWORD dwSize;
236 int i;
237 DWORD err;
238
239 err = RegCreateKey( HKEY_LOCAL_MACHINE, kServiceParametersNode L"\\DynDNS\\Setup\\" kServiceDynDNSBrowseDomains, &key );
240 require_noerr( err, exit );
241
242 // First, remove all the entries that are there
243
244 err = RegQueryInfoKey( key, NULL, NULL, NULL, &cSubKeys, &cbMaxSubKey, &cchMaxClass, NULL, NULL, NULL, NULL, NULL );
245 require_noerr( err, exit );
246
247 for ( i = 0; i < (int) cSubKeys; i++ )
248 {
249 dwSize = MAX_KEY_LENGTH;
250
251 err = RegEnumKeyEx( key, 0, subKeyName, &dwSize, NULL, NULL, NULL, NULL );
252 require_noerr( err, exit );
253
254 err = RegDeleteKey( key, subKeyName );
255 require_noerr( err, exit );
256 }
257
258 // Now re-populate
259
260 for ( i = 0; i < m_browseListCtrl.GetItemCount(); i++ )
261 {
262 DWORD enabled = (DWORD) m_browseListCtrl.GetCheck( i );
263
264 err = RegCreateKey( key, m_browseListCtrl.GetItemText( i, 1 ), &subKey );
265 require_noerr( err, exit );
266
267 err = RegSetValueEx( subKey, L"Enabled", NULL, REG_DWORD, (LPBYTE) &enabled, sizeof( enabled ) );
268 require_noerr( err, exit );
269
270 RegCloseKey( subKey );
271 subKey = NULL;
272 }
273
274 exit:
275
276 if ( subKey )
277 {
278 RegCloseKey( subKey );
279 }
280
281 if ( key )
282 {
283 RegCloseKey( key );
284 }
285 }
286
287
288
289 //---------------------------------------------------------------------------------------------------------------------------
290 // CThirdPage::OnBnClickedAddBrowseDomain
291 //---------------------------------------------------------------------------------------------------------------------------
292
293 void
294 CThirdPage::OnBnClickedAddBrowseDomain()
295 {
296 CAddBrowseDomain dlg( GetParent() );
297
298 if ( ( dlg.DoModal() == IDOK ) && ( dlg.m_text.GetLength() > 0 ) )
299 {
300 int nIndex;
301
302 nIndex = m_browseListCtrl.InsertItem( m_browseListCtrl.GetItemCount(), L"");
303 m_browseListCtrl.SetItemText( nIndex, 1, dlg.m_text );
304 m_browseListCtrl.SetCheck( nIndex, 1 );
305
306 m_browseListCtrl.SortItems( SortFunc, (DWORD_PTR) this );
307
308 m_browseListCtrl.Invalidate();
309
310 SetModified( TRUE );
311 }
312 }
313
314
315 //---------------------------------------------------------------------------------------------------------------------------
316 // CThirdPage::OnBnClickedRemoveBrowseDomain
317 //---------------------------------------------------------------------------------------------------------------------------
318
319 void
320 CThirdPage::OnBnClickedRemoveBrowseDomain()
321 {
322 UINT selectedCount = m_browseListCtrl.GetSelectedCount();
323 int nItem = -1;
324 UINT i;
325
326 // Update all of the selected items.
327
328 for ( i = 0; i < selectedCount; i++ )
329 {
330 nItem = m_browseListCtrl.GetNextItem( -1, LVNI_SELECTED );
331 check( nItem != -1 );
332
333 m_browseListCtrl.DeleteItem( nItem );
334
335 SetModified( TRUE );
336 }
337
338 m_removeButton.EnableWindow( FALSE );
339 }
340
341
342 void
343 CThirdPage::OnLvnItemchangedBrowseList(NMHDR *pNMHDR, LRESULT *pResult)
344 {
345 if ( m_browseListCtrl.GetSelectedCount() )
346 {
347 m_removeButton.EnableWindow( TRUE );
348 }
349
350 if ( m_initialized )
351 {
352 NM_LISTVIEW * pNMListView = (NM_LISTVIEW*)pNMHDR;
353
354 BOOL bPrevState = (BOOL) ( ( ( pNMListView->uOldState & LVIS_STATEIMAGEMASK ) >> 12 ) - 1 );
355
356 if ( bPrevState < 0 )
357 {
358 bPrevState = 0;
359 }
360
361
362 BOOL bChecked = ( BOOL ) ( ( ( pNMListView->uNewState & LVIS_STATEIMAGEMASK ) >> 12) - 1 );
363
364 if ( bChecked < 0 )
365 {
366 bChecked = 0;
367 }
368
369 if ( bPrevState != bChecked )
370 {
371 SetModified( TRUE );
372 }
373 }
374
375 *pResult = 0;
376 }
377
378
379
380 int CALLBACK
381 CThirdPage::SortFunc(LPARAM lParam1, LPARAM lParam2, LPARAM lParamSort)
382 {
383 CString str1;
384 CString str2;
385 int ret = 0;
386
387 CThirdPage * self = reinterpret_cast<CThirdPage*>( lParamSort );
388 require_quiet( self, exit );
389
390 str1 = self->m_browseListCtrl.GetItemText( (int) lParam1, 1 );
391 str2 = self->m_browseListCtrl.GetItemText( (int) lParam2, 1 );
392
393 ret = str1.Compare( str2 );
394
395 exit:
396
397 return ret;
398 }
399
400
401 // CAddBrowseDomain dialog
402
403 IMPLEMENT_DYNAMIC(CAddBrowseDomain, CDialog)
404 CAddBrowseDomain::CAddBrowseDomain(CWnd* pParent /*=NULL*/)
405 : CDialog(CAddBrowseDomain::IDD, pParent)
406 {
407 }
408
409 CAddBrowseDomain::~CAddBrowseDomain()
410 {
411 }
412
413 void CAddBrowseDomain::DoDataExchange(CDataExchange* pDX)
414 {
415 CDialog::DoDataExchange(pDX);
416 DDX_Control(pDX, IDC_COMBO1, m_comboBox);
417 }
418
419
420 BOOL
421 CAddBrowseDomain::OnInitDialog()
422 {
423 CConfigPropertySheet * psheet;
424 CConfigPropertySheet::StringList::iterator it;
425
426 BOOL b = CDialog::OnInitDialog();
427
428 psheet = reinterpret_cast<CConfigPropertySheet*>(GetParent());
429 require_quiet( psheet, exit );
430
431 for ( it = psheet->m_browseDomains.begin(); it != psheet->m_browseDomains.end(); it++ )
432 {
433 CString text = *it;
434
435 if ( m_comboBox.FindStringExact( -1, *it ) == CB_ERR )
436 {
437 m_comboBox.AddString( *it );
438 }
439 }
440
441 exit:
442
443 return b;
444 }
445
446
447 void
448 CAddBrowseDomain::OnOK()
449 {
450 m_comboBox.GetWindowText( m_text );
451
452 CDialog::OnOK();
453 }
454
455
456
457 BEGIN_MESSAGE_MAP(CAddBrowseDomain, CDialog)
458 END_MESSAGE_MAP()
459