Windows: AFSVolSync creationDate based readonly volume versioning
[openafs.git] / src / WINNT / afssvrcfg / info2_page.cpp
1 /*
2  * Copyright 2000, International Business Machines Corporation and others.
3  * All Rights Reserved.
4  * 
5  * This software has been released under the terms of the IBM Public
6  * License.  For details, see the LICENSE file in the top-level source
7  * directory or online at http://www.openafs.org/dl/license10.html
8  */
9
10 /*
11  * INCLUDES _________________________________________________________________
12  *
13  */
14 #include <winsock2.h>
15 #include <ws2tcpip.h>
16
17 extern "C" {
18 #include <afs/param.h>
19 #include <afs/stds.h>
20 }
21
22 #include "afscfg.h"
23 #include "resource.h"
24
25
26 /*
27  * DEFINITIONS _________________________________________________________________
28  *
29  */
30 static HWND hDlg = 0;                           // HWND for this page's dialog
31
32 #define FIRST_SERVER_STEP               sidSTEP_THREE
33 #define NOT_FIRST_SERVER_STEP   sidSTEP_FOUR
34
35 #define MIN_AFS_UID             1
36 #define MAX_AFS_UID             UD_MAXVAL
37
38
39 /*
40  * PROTOTYPES _________________________________________________________________
41  *
42  */
43 static void OnInitDialog(HWND hwndDlg);
44 static void CheckEnableButtons();
45 static void SavePageInfo();
46 static void ShowPageInfo();
47 static void UseNextUid(BOOL bUseNext);
48
49
50 /*
51  * EXPORTED FUNCTIONS _________________________________________________________________
52  *
53  */
54
55 /*
56  * Dialog Procs _________________________________________________________________
57  *
58  */
59 BOOL CALLBACK InfoPage2DlgProc(HWND hRHS, UINT msg, WPARAM wp, LPARAM lp)
60 {
61     if (WizStep_Common_DlgProc (hRHS, msg, wp, lp))
62         return FALSE;
63
64     switch (msg) {
65     case WM_INITDIALOG:
66         OnInitDialog(hRHS);
67         break;
68
69     case WM_COMMAND:
70         switch (LOWORD(wp)) {
71         case IDC_WIZARD:
72             if (HIWORD(wp) == wcIS_STATE_DISABLED) {
73                 int nState = g_pWiz->GetState();
74
75                 // Disable step 3 if we are not the first server
76                 if (nState == sidSTEP_THREE)
77                     return !g_CfgData.bFirstServer;
78
79                 // Disable step 4 if we are the first server
80                 if (nState == sidSTEP_FOUR)
81                     return g_CfgData.bFirstServer;
82             }
83             break;
84
85         case IDNEXT:
86             SavePageInfo();
87             g_pWiz->SetState (sidSTEP_FIVE);
88             break;
89
90         case IDBACK:
91             SavePageInfo();
92             g_pWiz->SetState (sidSTEP_TWO);
93             break;
94
95         case IDC_USE_NEXT_UID:
96             UseNextUid(TRUE);
97             CheckEnableButtons();
98             break;
99
100         case IDC_USE_THIS_UID:
101             UseNextUid(FALSE);
102             CheckEnableButtons();
103             break;
104
105         case IDC_ADMIN_NAME:
106         case IDC_ADMIN_PW:
107         case IDC_VERIFY_ADMIN_PW:
108         case IDC_HOSTNAME:
109             if (HIWORD(wp) == EN_CHANGE)
110                 CheckEnableButtons();
111             break;
112
113         }
114         break;
115     }   
116
117     return FALSE;
118 }
119
120 /*
121  * STATIC FUNCTIONS _________________________________________________________________
122  *
123  */
124
125 /*
126  * Event Handler Functions _________________________________________________________________
127  *
128  */
129 static void OnInitDialog(HWND hwndDlg)
130 {
131     hDlg = hwndDlg;
132
133     g_pWiz->EnableButtons(BACK_BUTTON);
134
135     SetUpDownRange(hDlg, IDC_AFS_UID_SPINNER, MIN_AFS_UID, MAX_AFS_UID);
136
137     ShowPageInfo();
138
139     g_pWiz->SetDefaultControl(IDC_ADMIN_NAME);
140 }
141
142
143 /*
144  * Utility Functions _________________________________________________________________
145  *
146  */
147 static void CheckEnableButtons()
148 {       
149     BOOL bDisable = FALSE;
150
151     TCHAR szDummy[cchRESOURCE];
152     TCHAR szPW[cchRESOURCE];
153     TCHAR szVerifyPW[cchRESOURCE];
154
155     bDisable |= lstrlen(GetWndText(hDlg, IDC_ADMIN_NAME, szDummy)) == 0;
156
157     bDisable |= lstrlen(GetWndText(hDlg, IDC_ADMIN_PW, szPW)) == 0;
158
159     if (IsWindowEnabled(GetDlgItem(hDlg, IDC_VERIFY_ADMIN_PW))) {
160         GetWndText(hDlg, IDC_VERIFY_ADMIN_PW, szVerifyPW);
161         bDisable |= !lstrlen(szVerifyPW) || lstrcmp(szPW, szVerifyPW);
162     }
163
164     if (IsWindowEnabled(GetDlgItem(hDlg, IDC_ADMIN_UID)))
165         bDisable |= lstrlen(GetWndText(hDlg, IDC_ADMIN_UID, szDummy)) == 0;
166
167     if (IsWindowEnabled(GetDlgItem(hDlg, IDC_HOSTNAME)))
168         bDisable |= lstrlen(GetWndText(hDlg, IDC_HOSTNAME, szDummy)) == 0;
169
170     if (bDisable)
171         g_pWiz->EnableButtons(BACK_BUTTON);
172     else
173         g_pWiz->EnableButtons(BACK_BUTTON | NEXT_BUTTON);
174 }       
175
176 static void SavePageInfo()
177 {
178     TCHAR szText[cchRESOURCE];
179         
180     lstrncpy(g_CfgData.szAdminName, GetWndText(hDlg, IDC_ADMIN_NAME, szText), MAX_ADMIN_NAME_LEN);
181     lstrncpy(g_CfgData.szAdminPW, GetWndText(hDlg, IDC_ADMIN_PW, szText), MAX_ADMIN_PW_LEN);
182
183     if (g_pWiz->GetState() == FIRST_SERVER_STEP) {
184         g_CfgData.bUseNextUid = IsButtonChecked(hDlg, IDC_USE_NEXT_UID);
185         if (!g_CfgData.bUseNextUid)
186             lstrncpy(g_CfgData.szAdminUID, GetWndText(hDlg, IDC_ADMIN_UID, szText), MAX_UID_LEN);
187     }   
188
189     if (g_pWiz->GetState() == NOT_FIRST_SERVER_STEP)
190         lstrncpy(g_CfgData.szCellServDbHostname, GetWndText(hDlg, IDC_HOSTNAME, szText), MAX_MACHINE_NAME_LEN);
191 }       
192
193 static void ShowPageInfo()
194 {
195     SetWndText(hDlg, IDC_ADMIN_NAME, g_CfgData.szAdminName);
196     SetWndText(hDlg, IDC_ADMIN_PW, g_CfgData.szAdminPW);
197     SetWndText(hDlg, IDC_VERIFY_ADMIN_PW, g_CfgData.szAdminPW);
198     SetWndText(hDlg, IDC_HOSTNAME, g_CfgData.szCellServDbHostname);
199
200     if (g_pWiz->GetState() == FIRST_SERVER_STEP) {
201         if (g_CfgData.bUseNextUid)
202             SetCheck(hDlg, IDC_USE_NEXT_UID);
203         else
204             SetCheck(hDlg, IDC_USE_THIS_UID);
205         UseNextUid(g_CfgData.bUseNextUid);
206         SetWndText(hDlg, IDC_ADMIN_UID, g_CfgData.szAdminUID);
207     }
208 }
209
210 static void UseNextUid(BOOL bUseNext)
211 {
212     ENABLE_STATE es = bUseNext ? ES_DISABLE : ES_ENABLE;
213         
214     SetEnable(hDlg, IDC_ADMIN_UID, es);
215     SetEnable(hDlg, IDC_AFS_UID_SPINNER, es);
216 }
217