Update NEWS for 1.6.22
[pkg-k5-afs_openafs.git] / src / WINNT / afssvrmgr / set_delete.cpp
blob2d893d5cc8b8b8dbc58663f7ce60847798ffb803
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_delete.h"
20 #include "propcache.h"
24 * PROTOTYPES _________________________________________________________________
28 BOOL CALLBACK Filesets_Delete_DlgProc (HWND hDlg, UINT msg, WPARAM wp, LPARAM lp);
29 void Filesets_Delete_OnInitDialog (HWND hDlg, LPIDENT lpi);
30 void Filesets_Delete_OnCheckBoxes (HWND hDlg);
31 void Filesets_Delete_OnEndTask_FindGhost (HWND hDlg, LPTASKPACKET ptp, LPSET_DELETE_PARAMS psdp);
32 void Filesets_Delete_ShrinkWindow (HWND hDlg);
36 * ROUTINES ___________________________________________________________________
40 void Filesets_Delete (LPIDENT lpiFileset)
42 HWND hCurrent;
43 if ((hCurrent = PropCache_Search (pcSET_DELETE, lpiFileset)) != NULL)
45 SetFocus (hCurrent);
47 else
49 LPSET_DELETE_PARAMS psdp = New (SET_DELETE_PARAMS);
50 memset (psdp, 0x00, sizeof(SET_DELETE_PARAMS));
51 psdp->lpiFileset = lpiFileset;
52 psdp->iddHelp = IDD_SET_DELETE;
54 ModelessDialogParam (IDD_SET_DELETE, NULL, (DLGPROC)Filesets_Delete_DlgProc, (LPARAM)psdp);
55 // NOTE: Don't show window!
61 BOOL CALLBACK Filesets_Delete_DlgProc (HWND hDlg, UINT msg, WPARAM wp, LPARAM lp)
63 LPSET_DELETE_PARAMS psdp;
64 if (msg == WM_INITDIALOG)
65 SetWindowLongPtr (hDlg, DWLP_USER, lp);
66 if ((psdp = (LPSET_DELETE_PARAMS)GetWindowLongPtr (hDlg, DWLP_USER)) != NULL)
68 if (AfsAppLib_HandleHelp (psdp->iddHelp, hDlg, msg, wp, lp))
69 return TRUE;
71 switch (msg)
73 case WM_INITDIALOG:
74 PropCache_Add (pcSET_DELETE, psdp->lpiFileset, hDlg);
75 Filesets_Delete_OnInitDialog (hDlg, psdp->lpiFileset);
76 StartTask (taskSET_FIND_GHOST, hDlg, psdp->lpiFileset);
77 break;
79 case WM_ENDTASK:
80 LPTASKPACKET ptp;
81 if ((ptp = (LPTASKPACKET)lp) != NULL)
83 if (ptp->idTask == taskSET_FIND_GHOST)
84 Filesets_Delete_OnEndTask_FindGhost (hDlg, ptp, psdp);
85 FreeTaskPacket (ptp);
87 break;
89 case WM_COMMAND:
90 switch (LOWORD(wp))
92 case IDOK:
93 psdp->fVLDB = IsDlgButtonChecked (hDlg, IDC_DELSET_VLDB);
94 psdp->fServer = IsDlgButtonChecked (hDlg, IDC_DELSET_SERVER);
96 if (psdp->fVLDB || psdp->fServer)
97 StartTask (taskSET_DELETE, NULL, psdp);
98 else
99 Delete (psdp);
100 DestroyWindow (hDlg);
101 break;
103 case IDCANCEL:
104 Delete (psdp);
105 DestroyWindow (hDlg);
106 break;
108 case IDC_DELSET_VLDB:
109 case IDC_DELSET_SERVER:
110 Filesets_Delete_OnCheckBoxes (hDlg);
111 break;
113 break;
115 case WM_DESTROY:
116 PropCache_Delete (hDlg);
117 SetWindowLongPtr (hDlg, DWLP_USER, 0);
118 psdp = NULL;
119 break;
123 return FALSE;
127 void Filesets_Delete_OnInitDialog (HWND hDlg, LPIDENT lpi)
129 TCHAR szServer[ cchNAME ];
130 TCHAR szAggregate[ cchNAME ];
131 TCHAR szFileset[ cchNAME ];
133 lpi->GetServerName (szServer);
134 lpi->GetAggregateName (szAggregate);
135 lpi->GetFilesetName (szFileset);
137 TCHAR szOld[ cchRESOURCE ];
139 GetDlgItemText (hDlg, IDC_DELSET_DESC, szOld, cchRESOURCE);
140 LPTSTR pszNew = FormatString (szOld, TEXT("%s%s%s"), szServer, szAggregate, szFileset);
141 SetDlgItemText (hDlg, IDC_DELSET_DESC, pszNew);
142 FreeString (pszNew);
144 GetDlgItemText (hDlg, IDC_DELSET_SERVER, szOld, cchRESOURCE);
145 pszNew = FormatString (szOld, TEXT("%s%s%s"), szServer, szAggregate, szFileset);
146 SetDlgItemText (hDlg, IDC_DELSET_SERVER, pszNew);
147 FreeString (pszNew);
149 GetDlgItemText (hDlg, IDC_DELSET_VLDB, szOld, cchRESOURCE);
150 pszNew = FormatString (szOld, TEXT("%s%s%s"), szServer, szAggregate, szFileset);
151 SetDlgItemText (hDlg, IDC_DELSET_VLDB, pszNew);
152 FreeString (pszNew);
154 EnableWindow (GetDlgItem (hDlg, IDOK), FALSE);
158 void Filesets_Delete_OnEndTask_FindGhost (HWND hDlg, LPTASKPACKET ptp, LPSET_DELETE_PARAMS psdp)
160 TCHAR szServer[ cchNAME ];
161 TCHAR szAggregate[ cchNAME ];
162 TCHAR szFileset[ cchNAME ];
163 psdp->lpiFileset->GetServerName (szServer);
164 psdp->lpiFileset->GetAggregateName (szAggregate);
165 psdp->lpiFileset->GetFilesetName (szFileset);
167 if (!ptp->rc)
169 ErrorDialog (ptp->status, IDS_ERROR_REFRESH_FILESET_STATUS, TEXT("%s%s%s"), szServer, szAggregate, szFileset);
170 DestroyWindow (hDlg);
172 else if ( (TASKDATA(ptp)->fs.Type == ftREADWRITE) && (TASKDATA(ptp)->fHasReplicas) )
174 ErrorDialog (ptp->status, IDS_ERROR_CANT_DELETE_REPLICATED_FILESET, TEXT("%s%s%s"), szServer, szAggregate, szFileset);
175 DestroyWindow (hDlg);
177 else
179 if (TASKDATA(ptp)->fs.Type == ftREPLICA)
180 psdp->wGhost = GHOST_HAS_SERVER_ENTRY;
181 else if (TASKDATA(ptp)->fs.Type == ftCLONE)
182 psdp->wGhost = GHOST_HAS_SERVER_ENTRY;
183 else
184 psdp->wGhost = TASKDATA(ptp)->wGhost;
186 psdp->fVLDB = (psdp->wGhost & GHOST_HAS_VLDB_ENTRY) ? TRUE : FALSE;
187 psdp->fServer = (psdp->wGhost & GHOST_HAS_SERVER_ENTRY) ? TRUE : FALSE;
189 CheckDlgButton (hDlg, IDC_DELSET_VLDB, psdp->fVLDB);
190 CheckDlgButton (hDlg, IDC_DELSET_SERVER, psdp->fServer);
192 if (TASKDATA(ptp)->fs.Type == ftREPLICA)
194 psdp->iddHelp = IDD_SET_DELREP;
196 LPTSTR pszNew = FormatString (IDS_DELSET_REPLICA_DESC, TEXT("%s%s%s"), szServer, szAggregate, szFileset);
197 SetDlgItemText (hDlg, IDC_DELSET_DESC, pszNew);
198 FreeString (pszNew);
200 Filesets_Delete_ShrinkWindow (hDlg);
202 else if (TASKDATA(ptp)->fs.Type == ftCLONE)
204 psdp->iddHelp = IDD_SET_DELCLONE;
206 LPTSTR pszNew = FormatString (IDS_DELSET_CLONE_DESC, TEXT("%s%s%s"), szServer, szAggregate, szFileset);
207 SetDlgItemText (hDlg, IDC_DELSET_DESC, pszNew);
208 FreeString (pszNew);
210 Filesets_Delete_ShrinkWindow (hDlg);
213 if (!(psdp->wGhost & GHOST_HAS_SERVER_ENTRY))
214 EnableWindow (GetDlgItem (hDlg, IDC_DELSET_SERVER), FALSE);
216 if (!(psdp->wGhost & GHOST_HAS_VLDB_ENTRY))
217 EnableWindow (GetDlgItem (hDlg, IDC_DELSET_VLDB), FALSE);
219 Filesets_Delete_OnCheckBoxes (hDlg);
221 ShowWindow (hDlg, SW_SHOW);
226 void Filesets_Delete_OnCheckBoxes (HWND hDlg)
228 BOOL fEnableOK = TRUE;
229 if ( !IsDlgButtonChecked (hDlg, IDC_DELSET_VLDB) &&
230 !IsDlgButtonChecked (hDlg, IDC_DELSET_SERVER) )
231 fEnableOK = FALSE;
233 EnableWindow (GetDlgItem (hDlg, IDOK), fEnableOK);
237 void Filesets_Delete_ShrinkWindow (HWND hDlg)
239 RECT rDialog;
240 GetWindowRect (hDlg, &rDialog);
242 RECT rCheckbox;
243 GetRectInParent (GetDlgItem (hDlg, IDC_DELSET_VLDB), &rCheckbox);
245 RECT rButton;
246 GetRectInParent (GetDlgItem (hDlg, IDOK), &rButton);
248 LONG cy = rButton.top -rCheckbox.top; // shrink window by this much
250 EnableWindow (GetDlgItem (hDlg, IDC_DELSET_SERVER), FALSE);
251 ShowWindow (GetDlgItem (hDlg, IDC_DELSET_SERVER), SW_HIDE);
253 EnableWindow (GetDlgItem (hDlg, IDC_DELSET_VLDB), FALSE);
254 ShowWindow (GetDlgItem (hDlg, IDC_DELSET_VLDB), SW_HIDE);
256 GetRectInParent (GetDlgItem (hDlg, IDOK), &rButton);
257 SetWindowPos (GetDlgItem (hDlg, IDOK), NULL,
258 rButton.left, rButton.top -cy, 0, 0,
259 SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
261 GetRectInParent (GetDlgItem (hDlg, IDCANCEL), &rButton);
262 SetWindowPos (GetDlgItem (hDlg, IDCANCEL), NULL,
263 rButton.left, rButton.top -cy, 0, 0,
264 SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
266 GetRectInParent (GetDlgItem (hDlg, IDHELP), &rButton);
267 SetWindowPos (GetDlgItem (hDlg, IDHELP), NULL,
268 rButton.left, rButton.top -cy, 0, 0,
269 SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
271 SetWindowPos (hDlg, NULL,
272 0, 0, cxRECT(rDialog), cyRECT(rDialog) -cy,
273 SWP_NOMOVE | SWP_NOZORDER | SWP_NOACTIVATE);