Standardize License information
[openafs.git] / src / WINNT / afssvrmgr / svr_prune.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 extern "C" {
11 #include <afs/param.h>
12 #include <afs/stds.h>
13 }
14
15 #include "svrmgr.h"
16 #include "svr_prune.h"
17 #include "propcache.h"
18
19 /*
20  * PROTOTYPES _________________________________________________________________
21  *
22  */
23
24 BOOL WINAPI Server_Prune_DlgProc (HWND hDlg, UINT msg, WPARAM wp, LPARAM lp);
25
26 void Server_Prune_OnInitDialog (HWND hDlg, LPSVR_PRUNE_PARAMS lpp);
27 void Server_Prune_OnEndTask_InitDialog (HWND hDlg, LPTASKPACKET ptp, LPSVR_PRUNE_PARAMS lpp);
28 void Server_Prune_EnableOK (HWND hDlg);
29 void Server_Prune_OnOK (HWND hDlg);
30
31
32 /*
33  * ROUTINES ___________________________________________________________________
34  *
35  */
36
37 void Server_Prune (LPIDENT lpiServer, BOOL fBAK, BOOL fOLD, BOOL fCore)
38 {
39    HWND hCurrent;
40
41    if ((hCurrent = PropCache_Search (pcSVR_PRUNE, NULL)) != NULL)
42       {
43       SetFocus (hCurrent);
44       }
45    else
46       {
47       LPSVR_PRUNE_PARAMS lpp = New (SVR_PRUNE_PARAMS);
48       lpp->lpiServer = lpiServer;
49       lpp->fBAK = fBAK;
50       lpp->fOLD = fOLD;
51       lpp->fCore = fCore;
52
53       HWND hDlg = ModelessDialogParam (IDD_SVR_PRUNE, NULL, (DLGPROC)Server_Prune_DlgProc, (LPARAM)lpp);
54       ShowWindow (hDlg, SW_SHOW);
55       }
56 }
57
58
59 BOOL WINAPI Server_Prune_DlgProc (HWND hDlg, UINT msg, WPARAM wp, LPARAM lp)
60 {
61    if (AfsAppLib_HandleHelp (IDD_SVR_PRUNE, hDlg, msg, wp, lp))
62       return TRUE;
63
64    LPSVR_PRUNE_PARAMS lpp;
65
66    if (msg == WM_INITDIALOG)
67       SetWindowLong (hDlg, DWL_USER, lp);
68
69    if ((lpp = (LPSVR_PRUNE_PARAMS)GetWindowLong(hDlg,DWL_USER)) != NULL)
70       {
71       switch (msg)
72          {
73          case WM_INITDIALOG:
74             PropCache_Add (pcSVR_PRUNE, NULL, hDlg);
75             Server_Prune_OnInitDialog (hDlg, lpp);
76             break;
77
78          case WM_ENDTASK:
79             LPTASKPACKET ptp;
80             if ((ptp = (LPTASKPACKET)lp) != NULL)
81                {
82                if (ptp->idTask == taskSVR_ENUM_TO_COMBOBOX)
83                   Server_Prune_OnEndTask_InitDialog (hDlg, ptp, lpp);
84                FreeTaskPacket (ptp);
85                }
86             break;
87
88          case WM_COMMAND:
89             switch (LOWORD(wp))
90                {
91                case IDOK:
92                   Server_Prune_OnOK (hDlg);
93                   // fall through
94
95                case IDCANCEL:
96                   DestroyWindow (hDlg);
97                   break;
98
99                case IDC_OP_DELETE_BAK:
100                case IDC_OP_DELETE_OLD:
101                case IDC_OP_DELETE_CORE:
102                   Server_Prune_EnableOK (hDlg);
103                   break;
104                }
105             break;
106
107          case WM_DESTROY:
108             SetWindowLong (hDlg, DWL_USER, 0);
109             PropCache_Delete (pcSVR_PRUNE, NULL);
110             Delete (lpp);
111             break;
112          }
113       }
114
115    return FALSE;
116 }
117
118
119 void Server_Prune_OnInitDialog (HWND hDlg, LPSVR_PRUNE_PARAMS lpp)
120 {
121    CheckDlgButton (hDlg, IDC_OP_DELETE_BAK,  lpp->fBAK);
122    CheckDlgButton (hDlg, IDC_OP_DELETE_OLD,  lpp->fOLD);
123    CheckDlgButton (hDlg, IDC_OP_DELETE_CORE, lpp->fCore);
124
125    LPSVR_ENUM_TO_COMBOBOX_PACKET lppEnum = New (SVR_ENUM_TO_COMBOBOX_PACKET);
126    lppEnum->hCombo = GetDlgItem (hDlg, IDC_SERVER);
127    lppEnum->lpiSelect = lpp->lpiServer;
128    StartTask (taskSVR_ENUM_TO_COMBOBOX, hDlg, lppEnum);
129
130    EnableWindow (GetDlgItem (hDlg, IDC_SERVER), FALSE);
131    EnableWindow (GetDlgItem (hDlg, IDOK),       FALSE);
132 }
133
134
135 void Server_Prune_OnEndTask_InitDialog (HWND hDlg, LPTASKPACKET ptp, LPSVR_PRUNE_PARAMS lpp)
136 {
137    EnableWindow (GetDlgItem (hDlg, IDC_SERVER), TRUE);
138
139    Server_Prune_EnableOK (hDlg);
140 }
141
142
143 void Server_Prune_EnableOK (HWND hDlg)
144 {
145    LPIDENT lpiServer = NULL;
146
147    if (IsWindowEnabled (GetDlgItem (hDlg, IDC_SERVER)))
148       {
149       lpiServer = (LPIDENT)CB_GetSelectedData (GetDlgItem (hDlg, IDC_SERVER));
150       }
151
152    BOOL fEnable = (lpiServer != NULL) ? TRUE : FALSE;
153
154    if ( !IsDlgButtonChecked (hDlg, IDC_OP_DELETE_BAK) && 
155         !IsDlgButtonChecked (hDlg, IDC_OP_DELETE_OLD) && 
156         !IsDlgButtonChecked (hDlg, IDC_OP_DELETE_CORE) )
157       {
158       fEnable = FALSE;
159       }
160
161    EnableWindow (GetDlgItem (hDlg, IDOK), fEnable);
162 }
163
164
165 void Server_Prune_OnOK (HWND hDlg)
166 {
167    LPSVR_PRUNE_PARAMS lpp = New (SVR_PRUNE_PARAMS);
168    lpp->lpiServer = (LPIDENT)CB_GetSelectedData (GetDlgItem (hDlg, IDC_SERVER));
169    lpp->fBAK = IsDlgButtonChecked (hDlg, IDC_OP_DELETE_BAK);
170    lpp->fOLD = IsDlgButtonChecked (hDlg, IDC_OP_DELETE_OLD);
171    lpp->fCore = IsDlgButtonChecked (hDlg, IDC_OP_DELETE_CORE);
172
173    StartTask (taskSVR_PRUNE, NULL, lpp);
174 }
175