Update NEWS for 1.6.22
[pkg-k5-afs_openafs.git] / src / WINNT / afssvrmgr / set_prop.cpp
blobb6c37e26016ef00bd9016b1f026bc90d4adcfd77
1 /*
2 * Copyright 2000, International Business Machines Corporation and others.
3 * All Rights Reserved.
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 */
10 #include <winsock2.h>
11 #include <ws2tcpip.h>
13 extern "C" {
14 #include <afs/param.h>
15 #include <afs/stds.h>
18 #include "svrmgr.h"
19 #include "set_prop.h"
20 #include "set_quota.h"
21 #include "svr_general.h"
22 #include "propcache.h"
23 #include "problems.h"
27 * PROTOTYPES _________________________________________________________________
31 BOOL CALLBACK Filesets_General_DlgProc (HWND hDlg, UINT msg, WPARAM wp, LPARAM lp);
33 void Filesets_General_OnInitDialog (HWND hDlg, LPIDENT lpiFileset);
34 void Filesets_General_OnApply (HWND hDlg, LPIDENT lpiFileset);
35 void Filesets_General_OnWarnings (HWND hDlg, LPIDENT lpiFileset);
37 void Filesets_General_OnEndTask_InitDialog (HWND hDlg, LPTASKPACKET ptp, LPIDENT lpi);
41 * ROUTINES ___________________________________________________________________
45 void Filesets_ShowProperties (LPIDENT lpiFileset, size_t nAlerts, BOOL fJumpToThreshold)
47 HWND hCurrent;
48 if ((hCurrent = PropCache_Search (pcSET_PROP, lpiFileset)) != NULL)
50 SetFocus (hCurrent);
52 if (fJumpToThreshold)
54 HWND hTab;
55 if ((hTab = GetDlgItem (hCurrent, IDC_PROPSHEET_TABCTRL)) != NULL)
57 int nTabs = TabCtrl_GetItemCount (hTab);
58 TabCtrl_SetCurSel (hTab, nTabs-1);
60 NMHDR nm;
61 nm.hwndFrom = hTab;
62 nm.idFrom = IDC_PROPSHEET_TABCTRL;
63 nm.code = TCN_SELCHANGE;
64 SendMessage (hCurrent, WM_NOTIFY, 0, (LPARAM)&nm);
68 else
70 TCHAR szCell[ cchNAME ];
71 lpiFileset->GetCellName (szCell);
73 TCHAR szFileset[ cchNAME ];
74 lpiFileset->GetFilesetName (szFileset);
76 LPTSTR pszTitle = FormatString (IDS_SET_PROP_TITLE, TEXT("%s"), szFileset);
77 LPPROPSHEET psh = PropSheet_Create (pszTitle, FALSE);
78 psh->fMadeCaption = TRUE;
80 if (PropSheet_AddProblemsTab (psh, IDD_SET_PROBLEMS, lpiFileset, nAlerts) &&
81 PropSheet_AddTab (psh, IDS_SET_GENERAL_TAB, IDD_SET_GENERAL, (DLGPROC)Filesets_General_DlgProc, (LPARAM)lpiFileset, TRUE))
83 if (fJumpToThreshold)
84 psh->sh.nStartPage = psh->sh.nPages-1;
85 PropSheet_ShowModeless (psh);
91 BOOL CALLBACK Filesets_General_DlgProc (HWND hDlg, UINT msg, WPARAM wp, LPARAM lp)
93 if (AfsAppLib_HandleHelp (IDD_SET_GENERAL, hDlg, msg, wp, lp))
94 return TRUE;
96 if (msg == WM_INITDIALOG)
97 SetWindowLongPtr (hDlg, DWLP_USER, ((LPPROPSHEETPAGE)lp)->lParam);
99 LPIDENT lpi = (LPIDENT)GetWindowLongPtr (hDlg, DWLP_USER);
101 switch (msg)
103 case WM_INITDIALOG_SHEET:
104 PropCache_Add (pcSET_PROP, (LPIDENT)lp, hDlg);
105 break;
107 case WM_DESTROY_SHEET:
108 PropCache_Delete (hDlg);
109 break;
111 case WM_INITDIALOG:
112 Filesets_General_OnInitDialog (hDlg, lpi);
113 StartTask (taskSET_PROP_INIT, hDlg, lpi);
114 NotifyMe (WHEN_OBJECT_CHANGES, lpi, hDlg, 0);
115 break;
117 case WM_DESTROY:
118 DontNotifyMeEver (hDlg);
119 break;
121 case WM_ENDTASK:
122 LPTASKPACKET ptp;
123 if ((ptp = (LPTASKPACKET)lp) != NULL)
125 if (ptp->idTask == taskSET_PROP_INIT)
126 Filesets_General_OnEndTask_InitDialog (hDlg, ptp, lpi);
127 FreeTaskPacket (ptp);
129 break;
131 case WM_NOTIFY_FROM_DISPATCH:
132 StartTask (taskSET_PROP_INIT, hDlg, lpi);
133 Delete ((LPNOTIFYSTRUCT)lp);
134 break;
136 case WM_COMMAND:
137 switch (LOWORD(wp))
139 case IDOK:
140 case IDCANCEL:
141 break;
143 case IDAPPLY:
144 Filesets_General_OnApply (hDlg, lpi);
145 break;
147 case IDC_SET_WARN:
148 case IDC_SET_WARN_SETFULL:
149 case IDC_SET_WARN_SETFULL_DEF:
150 Filesets_General_OnWarnings (hDlg, lpi);
151 PropSheetChanged (hDlg);
152 break;
154 case IDC_SET_WARN_SETFULL_PERCENT:
155 PropSheetChanged (hDlg);
156 break;
158 case IDC_SET_QUOTA:
159 if (Filesets_SetQuota (lpi))
161 // this new task will block until the setquota req is done
162 StartTask (taskSET_PROP_INIT, hDlg, lpi);
164 break;
166 case IDC_SET_LOCK:
167 StartTask (taskSET_LOCK, NULL, lpi);
168 break;
170 case IDC_SET_UNLOCK:
171 StartTask (taskSET_UNLOCK, NULL, lpi);
172 break;
174 break;
177 return FALSE;
181 void Filesets_General_OnInitDialog (HWND hDlg, LPIDENT lpi)
183 TCHAR szText[ cchRESOURCE ];
184 TCHAR szSvrName[ cchNAME ];
185 TCHAR szAggName[ cchNAME ];
186 TCHAR szSetName[ cchNAME ];
187 VOLUMEID vidFileset;
188 lpi->GetServerName (szSvrName);
189 lpi->GetAggregateName (szAggName);
190 lpi->GetFilesetName (szSetName);
191 lpi->GetFilesetID (&vidFileset);
193 GetDlgItemText (hDlg, IDC_SET_NAME, szText, cchRESOURCE);
194 LPTSTR pszText = FormatString (szText, TEXT("%s%s%s"), szSvrName, szAggName, szSetName);
195 SetDlgItemText (hDlg, IDC_SET_NAME, pszText);
196 FreeString (pszText);
198 pszText = FormatString (TEXT("%1"), TEXT("%lu"), vidFileset);
199 SetDlgItemText (hDlg, IDC_SET_ID, pszText);
200 FreeString (pszText);
202 EnableWindow (GetDlgItem (hDlg, IDC_SET_LOCK), FALSE);
203 EnableWindow (GetDlgItem (hDlg, IDC_SET_UNLOCK), FALSE);
204 EnableWindow (GetDlgItem (hDlg, IDC_SET_QUOTA), FALSE);
205 EnableWindow (GetDlgItem (hDlg, IDC_SET_WARN), FALSE);
206 EnableWindow (GetDlgItem (hDlg, IDC_SET_WARN_SETFULL_DEF), FALSE);
207 EnableWindow (GetDlgItem (hDlg, IDC_SET_WARN_SETFULL), FALSE);
208 EnableWindow (GetDlgItem (hDlg, IDC_SET_WARN_SETFULL_PERCENT), FALSE);
209 EnableWindow (GetDlgItem (hDlg, IDC_SET_WARN_SETFULL_DESC), FALSE);
213 void Filesets_General_OnEndTask_InitDialog (HWND hDlg, LPTASKPACKET ptp, LPIDENT lpi)
215 LPTSTR pszText;
217 TCHAR szUnknown[ cchRESOURCE ];
218 GetString (szUnknown, IDS_UNKNOWN);
220 if (!ptp->rc)
222 SetDlgItemText (hDlg, IDC_SET_CREATEDATE, szUnknown);
223 SetDlgItemText (hDlg, IDC_SET_UPDATEDATE, szUnknown);
224 SetDlgItemText (hDlg, IDC_SET_ACCESSDATE, szUnknown);
225 SetDlgItemText (hDlg, IDC_SET_BACKUPDATE, szUnknown);
226 SetDlgItemText (hDlg, IDC_SET_USAGE, szUnknown);
227 SetDlgItemText (hDlg, IDC_SET_STATUS, szUnknown);
228 SetDlgItemText (hDlg, IDC_SET_FILES, szUnknown);
230 TCHAR szSvrName[ cchNAME ];
231 TCHAR szAggName[ cchNAME ];
232 TCHAR szSetName[ cchNAME ];
233 lpi->GetServerName (szSvrName);
234 lpi->GetAggregateName (szAggName);
235 lpi->GetFilesetName (szSetName);
236 ErrorDialog (ptp->status, IDS_ERROR_REFRESH_FILESET_STATUS, TEXT("%s%s%s"), szSvrName, szAggName, szSetName);
238 else
240 TCHAR szText[ cchRESOURCE ];
242 EnableWindow (GetDlgItem (hDlg, IDC_SET_LOCK), TRUE);
243 EnableWindow (GetDlgItem (hDlg, IDC_SET_UNLOCK), TRUE);
244 EnableWindow (GetDlgItem (hDlg, IDC_SET_QUOTA), TRUE);
245 EnableWindow (GetDlgItem (hDlg, IDC_SET_WARN), TRUE);
246 EnableWindow (GetDlgItem (hDlg, IDC_SET_WARN_SETFULL_DEF), TRUE);
247 EnableWindow (GetDlgItem (hDlg, IDC_SET_WARN_SETFULL), TRUE);
248 EnableWindow (GetDlgItem (hDlg, IDC_SET_WARN_SETFULL_PERCENT), TRUE);
249 EnableWindow (GetDlgItem (hDlg, IDC_SET_WARN_SETFULL_DESC), TRUE);
251 if (!FormatTime (szText, TEXT("%s"), &TASKDATA(ptp)->fs.timeCreation))
252 SetDlgItemText (hDlg, IDC_SET_CREATEDATE, szUnknown);
253 else
254 SetDlgItemText (hDlg, IDC_SET_CREATEDATE, szText);
256 if (!FormatTime (szText, TEXT("%s"), &TASKDATA(ptp)->fs.timeLastUpdate))
257 SetDlgItemText (hDlg, IDC_SET_UPDATEDATE, szUnknown);
258 else
259 SetDlgItemText (hDlg, IDC_SET_UPDATEDATE, szText);
261 if (!FormatTime (szText, TEXT("%s"), &TASKDATA(ptp)->fs.timeLastAccess))
262 SetDlgItemText (hDlg, IDC_SET_ACCESSDATE, szUnknown);
263 else
264 SetDlgItemText (hDlg, IDC_SET_ACCESSDATE, szText);
266 if (!FormatTime (szText, TEXT("%s"), &TASKDATA(ptp)->fs.timeLastBackup))
267 SetDlgItemText (hDlg, IDC_SET_BACKUPDATE, szUnknown);
268 else
269 SetDlgItemText (hDlg, IDC_SET_BACKUPDATE, szText);
271 wsprintf (szText, TEXT("%lu"), TASKDATA(ptp)->fs.nFiles);
272 SetDlgItemText (hDlg, IDC_SET_FILES, szText);
274 size_t nAlerts = Alert_GetCount (lpi);
275 if (nAlerts == 1)
277 GetString (szText, IDS_SETSTATUS_1ALERT);
278 SetDlgItemText (hDlg, IDC_SET_STATUS, szText);
280 else if (nAlerts > 1)
282 pszText = FormatString (IDS_SETSTATUS_2ALERT, TEXT("%lu"), nAlerts);
283 SetDlgItemText (hDlg, IDC_SET_STATUS, pszText);
284 FreeString (pszText);
286 else // (nAlerts == 0)
288 if (TASKDATA(ptp)->fs.State & fsBUSY)
289 GetString (szText, IDS_SETSTATUS_BUSY);
290 else if (TASKDATA(ptp)->fs.State & fsSALVAGE)
291 GetString (szText, IDS_SETSTATUS_SALVAGE);
292 else if (TASKDATA(ptp)->fs.State & fsMOVED)
293 GetString (szText, IDS_SETSTATUS_MOVED);
294 else if (TASKDATA(ptp)->fs.State & fsLOCKED)
295 GetString (szText, IDS_SETSTATUS_LOCKED);
296 else if (TASKDATA(ptp)->fs.State & fsNO_VOL)
297 GetString (szText, IDS_SETSTATUS_NO_VOL);
298 else
299 GetString (szText, IDS_STATUS_NOALERTS);
300 SetDlgItemText (hDlg, IDC_SET_STATUS, szText);
303 if (TASKDATA(ptp)->fs.Type == ftREADWRITE)
305 Filesets_DisplayQuota (hDlg, &TASKDATA(ptp)->fs);
307 else
309 if (TASKDATA(ptp)->fs.Type == ftREPLICA)
310 GetString (szText, IDS_USAGE_REPLICA);
311 else // (TASKDATA(ptp)->fs.Type == ftCLONE)
312 GetString (szText, IDS_USAGE_CLONE);
314 pszText = FormatString (szText, TEXT("%.1B"), (double)TASKDATA(ptp)->fs.ckUsed * cb1KB);
315 SetDlgItemText (hDlg, IDC_SET_USAGE, pszText);
316 FreeString (pszText);
318 if (GetDlgItem (hDlg, IDC_SET_USAGEBAR))
320 RECT rUsagebar;
321 GetRectInParent (GetDlgItem (hDlg, IDC_SET_USAGEBAR), &rUsagebar);
323 HFONT hf = (HFONT)SendMessage (GetDlgItem (hDlg, IDC_SET_USAGEBAR), WM_GETFONT, 0, 0);
324 DestroyWindow (GetDlgItem (hDlg, IDC_SET_USAGEBAR));
326 if (TASKDATA(ptp)->fs.Type == ftREPLICA)
327 GetString (szText, IDS_NO_QUOTA_REPLICA);
328 else // (TASKDATA(ptp)->fs.Type == ftCLONE)
329 GetString (szText, IDS_NO_QUOTA_CLONE);
331 HWND hDesc = CreateWindow (TEXT("static"),
332 szText,
333 WS_CHILD | SS_SIMPLE,
334 rUsagebar.left, rUsagebar.top,
335 cxRECT(rUsagebar), cyRECT(rUsagebar),
336 hDlg,
337 (HMENU)-1,
338 THIS_HINST,
340 SendMessage (hDesc, WM_SETFONT, (WPARAM)hf, MAKELPARAM(TRUE,0));
341 ShowWindow (hDesc, SW_SHOW);
344 EnableWindow (GetDlgItem (hDlg, IDC_SET_QUOTA), FALSE);
345 EnableWindow (GetDlgItem (hDlg, IDC_SET_WARN), FALSE);
346 EnableWindow (GetDlgItem (hDlg, IDC_SET_WARN_SETFULL_DEF), FALSE);
347 EnableWindow (GetDlgItem (hDlg, IDC_SET_WARN_SETFULL), FALSE);
348 EnableWindow (GetDlgItem (hDlg, IDC_SET_WARN_SETFULL_PERCENT), FALSE);
349 EnableWindow (GetDlgItem (hDlg, IDC_SET_WARN_SETFULL_DESC), FALSE);
352 if (TASKDATA(ptp)->lpsp->perWarnSetFull == 0)
354 GetString (szText, IDS_SETFULL_WARN_OFF);
355 SetDlgItemText (hDlg, IDC_SET_WARN_SETFULL_DEF, szText);
357 else
359 GetString (szText, IDS_SETFULL_WARN_ON);
360 pszText = FormatString (szText, TEXT("%lu"), TASKDATA(ptp)->lpsp->perWarnSetFull);
361 SetDlgItemText (hDlg, IDC_SET_WARN_SETFULL_DEF, pszText);
362 FreeString (pszText);
365 CheckDlgButton (hDlg, IDC_SET_WARN, (TASKDATA(ptp)->lpfp->perWarnSetFull != 0));
366 if (TASKDATA(ptp)->lpfp->perWarnSetFull != 0)
368 if (TASKDATA(ptp)->lpfp->perWarnSetFull != -1)
369 CheckDlgButton (hDlg, IDC_SET_WARN_SETFULL, TRUE);
370 else
371 CheckDlgButton (hDlg, IDC_SET_WARN_SETFULL_DEF, TRUE);
374 CreateSpinner (GetDlgItem (hDlg, IDC_SET_WARN_SETFULL_PERCENT),
375 10, FALSE, // base, signed
377 (TASKDATA(ptp)->lpfp->perWarnSetFull == 0 || TASKDATA(ptp)->lpfp->perWarnSetFull == -1) ? perDEFAULT_SETFULL_WARNING : TASKDATA(ptp)->lpfp->perWarnSetFull,
378 100); // min, default, max
380 Filesets_General_OnWarnings (hDlg, lpi);
385 void Filesets_General_OnApply (HWND hDlg, LPIDENT lpi)
387 LPSET_PROP_APPLY_PARAMS lpp = New (SET_PROP_APPLY_PARAMS);
389 lpp->lpi = lpi;
390 lpp->fIDC_SET_WARN = IsDlgButtonChecked (hDlg, IDC_SET_WARN);
391 lpp->fIDC_SET_WARN_SETFULL_DEF = IsDlgButtonChecked (hDlg, IDC_SET_WARN_SETFULL_DEF);
392 lpp->wIDC_SET_WARN_SETFULL_PERCENT = (WORD)SP_GetPos (GetDlgItem (hDlg, IDC_SET_WARN_SETFULL_PERCENT));
394 StartTask (taskSET_PROP_APPLY, hDlg, lpp);
398 void Filesets_General_OnWarnings (HWND hDlg, LPIDENT lpi)
400 if (IsWindowEnabled (GetDlgItem (hDlg, IDC_SET_WARN)))
402 if (!IsDlgButtonChecked (hDlg, IDC_SET_WARN))
404 EnableWindow (GetDlgItem (hDlg, IDC_SET_WARN_SETFULL_DEF), FALSE);
405 EnableWindow (GetDlgItem (hDlg, IDC_SET_WARN_SETFULL), FALSE);
406 EnableWindow (GetDlgItem (hDlg, IDC_SET_WARN_SETFULL_PERCENT), FALSE);
407 EnableWindow (GetDlgItem (hDlg, IDC_SET_WARN_SETFULL_DESC), FALSE);
409 else if (IsDlgButtonChecked (hDlg, IDC_SET_WARN_SETFULL))
411 EnableWindow (GetDlgItem (hDlg, IDC_SET_WARN_SETFULL_DEF), TRUE);
412 EnableWindow (GetDlgItem (hDlg, IDC_SET_WARN_SETFULL), TRUE);
413 EnableWindow (GetDlgItem (hDlg, IDC_SET_WARN_SETFULL_PERCENT), TRUE);
414 EnableWindow (GetDlgItem (hDlg, IDC_SET_WARN_SETFULL_DESC), TRUE);
416 else // (IsDlgButtonChecked (hDlg, IDC_SET_WARN_SETFULL_DEF))
418 CheckDlgButton (hDlg, IDC_SET_WARN_SETFULL_DEF, TRUE);
419 EnableWindow (GetDlgItem (hDlg, IDC_SET_WARN_SETFULL_DEF), TRUE);
420 EnableWindow (GetDlgItem (hDlg, IDC_SET_WARN_SETFULL), TRUE);
421 EnableWindow (GetDlgItem (hDlg, IDC_SET_WARN_SETFULL_PERCENT), FALSE);
422 EnableWindow (GetDlgItem (hDlg, IDC_SET_WARN_SETFULL_DESC), FALSE);