2 * Copyright 2000, International Business Machines Corporation and others.
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
14 #include <afs/param.h>
19 #include "svr_hosts.h"
20 #include "propcache.h"
25 * DEFINITIONS ________________________________________________________________
33 } SVR_HOSTS_PARAMS
, *LPSVR_HOSTS_PARAMS
;
38 TCHAR szHost
[ cchNAME
];
39 } SVR_ADDHOST_PARAMS
, *LPSVR_ADDHOST_PARAMS
;
43 * PROTOTYPES _________________________________________________________________
47 void Server_Hosts_Free (LPSVR_HOSTS_PARAMS lpp
);
49 BOOL CALLBACK
Server_Hosts_DlgProc (HWND hDlg
, UINT msg
, WPARAM wp
, LPARAM lp
);
51 void Server_Hosts_OnInitDialog (HWND hDlg
, LPSVR_HOSTS_PARAMS lpp
);
52 void Server_Hosts_OnEndTask_ListOpen (HWND hDlg
, LPSVR_HOSTS_PARAMS lpp
, LPTASKPACKET ptp
);
53 void Server_Hosts_OnApply (HWND hDlg
, LPSVR_HOSTS_PARAMS lpp
);
54 void Server_Hosts_OnSelect (HWND hDlg
, LPSVR_HOSTS_PARAMS lpp
);
55 void Server_Hosts_OnAddEntry (HWND hDlg
, LPSVR_HOSTS_PARAMS lpp
);
56 void Server_Hosts_OnDelEntry (HWND hDlg
, LPSVR_HOSTS_PARAMS lpp
);
58 BOOL CALLBACK
Server_AddHost_DlgProc (HWND hDlg
, UINT msg
, WPARAM wp
, LPARAM lp
);
59 void Server_AddHost_OnInitDialog (HWND hDlg
, LPSVR_ADDHOST_PARAMS lpp
);
60 void Server_AddHost_EnableOK (HWND hDlg
);
64 * ROUTINES ___________________________________________________________________
68 void Server_Hosts (LPIDENT lpiServer
)
71 if ((hCurrent
= PropCache_Search (pcSVR_HOSTS
, lpiServer
)) != NULL
)
77 LPSVR_HOSTS_PARAMS lpp
= New (SVR_HOSTS_PARAMS
);
78 memset (lpp
, 0x00, sizeof(SVR_HOSTS_PARAMS
));
79 lpp
->lpiServer
= lpiServer
;
81 TCHAR szServer
[ cchNAME
];
82 lpiServer
->GetServerName (szServer
);
83 LPTSTR pszTitle
= FormatString (IDS_SVR_HOSTS_TITLE
, TEXT("%s"), szServer
);
84 LPPROPSHEET psh
= PropSheet_Create (pszTitle
, FALSE
);
85 PropSheet_AddTab (psh
, IDS_SVR_HOST_TAB
, IDD_SVR_HOSTS
, (DLGPROC
)Server_Hosts_DlgProc
, (LONG_PTR
)lpp
, TRUE
);
86 PropSheet_ShowModeless (psh
);
87 FreeString (pszTitle
);
92 void Server_Hosts_Free (LPSVR_HOSTS_PARAMS lpp
)
95 AfsClass_HostList_Free (lpp
->lpList
);
100 BOOL CALLBACK
Server_Hosts_DlgProc (HWND hDlg
, UINT msg
, WPARAM wp
, LPARAM lp
)
102 if (AfsAppLib_HandleHelp (IDD_SVR_HOSTS
, hDlg
, msg
, wp
, lp
))
105 LPSVR_HOSTS_PARAMS lpp
;
106 if ((msg
== WM_INITDIALOG_SHEET
) || (msg
== WM_DESTROY_SHEET
))
107 lpp
= (LPSVR_HOSTS_PARAMS
)lp
;
109 lpp
= (LPSVR_HOSTS_PARAMS
)PropSheet_FindTabParam (hDlg
);
113 case WM_INITDIALOG_SHEET
:
114 PropCache_Add (pcSVR_HOSTS
, lpp
->lpiServer
, hDlg
);
117 case WM_DESTROY_SHEET
:
118 PropCache_Delete (hDlg
);
122 Server_Hosts_OnInitDialog (hDlg
, lpp
);
126 Server_Hosts_Free (lpp
);
131 if ((ptp
= (LPTASKPACKET
)lp
) != NULL
)
133 if (ptp
->idTask
== taskSVR_HOSTLIST_OPEN
)
134 Server_Hosts_OnEndTask_ListOpen (hDlg
, lpp
, ptp
);
135 FreeTaskPacket (ptp
);
143 Server_Hosts_OnApply (hDlg
, lpp
);
147 Server_Hosts_OnAddEntry (hDlg
, lpp
);
148 PropSheetChanged (hDlg
);
151 case IDC_HOST_REMOVE
:
152 Server_Hosts_OnDelEntry (hDlg
, lpp
);
153 PropSheetChanged (hDlg
);
159 switch (((LPNMHDR
)lp
)->code
)
162 if (((LPNMHDR
)lp
)->hwndFrom
== GetDlgItem (hDlg
, IDC_HOST_LIST
))
164 Server_Hosts_OnSelect (hDlg
, lpp
);
175 void Server_Hosts_OnInitDialog (HWND hDlg
, LPSVR_HOSTS_PARAMS lpp
)
177 TCHAR szServer
[ cchNAME
];
178 lpp
->lpiServer
->GetServerName (szServer
);
180 LPTSTR pszText
= FormatString (IDS_HOST_TITLE
, TEXT("%s"), szServer
);
181 SetDlgItemText (hDlg
, IDC_HOST_TITLE
, pszText
);
182 FreeString (pszText
);
184 HWND hList
= GetDlgItem (hDlg
, IDC_HOST_LIST
);
186 // We'll need an imagelist, if we want icons in the list.
189 if ((hLarge
= ImageList_Create (32, 32, ILC_COLOR4
| ILC_MASK
, 1, 1)) != 0)
190 AfsAppLib_AddToImageList (hLarge
, IDI_SERVER
, TRUE
);
193 if ((hSmall
= ImageList_Create (16, 16, ILC_COLOR4
| ILC_MASK
, 1, 1)) != 0)
194 AfsAppLib_AddToImageList (hSmall
, IDI_SERVER
, FALSE
);
196 FastList_SetImageLists (hList
, hSmall
, hLarge
);
198 // Start loading the host list
200 StartTask (taskSVR_HOSTLIST_OPEN
, hDlg
, lpp
->lpiServer
);
202 EnableWindow (hList
, FALSE
);
203 EnableWindow (GetDlgItem (hDlg
, IDC_HOST_ADD
), FALSE
);
204 EnableWindow (GetDlgItem (hDlg
, IDC_HOST_REMOVE
), FALSE
);
208 void Server_Hosts_OnEndTask_ListOpen (HWND hDlg
, LPSVR_HOSTS_PARAMS lpp
, LPTASKPACKET ptp
)
210 HWND hList
= GetDlgItem (hDlg
, IDC_HOST_LIST
);
212 lpp
->lpList
= TASKDATA(ptp
)->lpHostList
;
216 FL_StartChange (hList
, TRUE
);
220 for (size_t iEntry
= 0; iEntry
< lpp
->lpList
->cEntries
; ++iEntry
)
222 LPHOSTLISTENTRY pEntry
= &lpp
->lpList
->aEntries
[ iEntry
];
223 if (pEntry
->szHost
[0] == TEXT('\0'))
226 FL_AddItem (hList
, 1, (LPARAM
)iEntry
, 0, pEntry
->szHost
);
230 FL_EndChange (hList
, 0);
231 EnableWindow (hList
, (lpp
->lpList
!= NULL
));
232 EnableWindow (GetDlgItem (hDlg
, IDC_HOST_ADD
), (lpp
->lpList
!= NULL
));
234 Server_Hosts_OnSelect (hDlg
, lpp
);
238 void Server_Hosts_OnSelect (HWND hDlg
, LPSVR_HOSTS_PARAMS lpp
)
240 HWND hList
= GetDlgItem (hDlg
, IDC_HOST_LIST
);
242 BOOL fEnableRemove
= TRUE
;
244 if (!IsWindowEnabled (hList
))
245 fEnableRemove
= FALSE
;
247 if (FastList_FindFirstSelected (hList
) == NULL
)
248 fEnableRemove
= FALSE
;
250 EnableWindow (GetDlgItem (hDlg
, IDC_HOST_REMOVE
), fEnableRemove
);
254 void Server_Hosts_OnApply (HWND hDlg
, LPSVR_HOSTS_PARAMS lpp
)
256 if (IsWindowEnabled (GetDlgItem (hDlg
, IDC_HOST_LIST
)))
258 // Increment the reference counter on this host list before handing
259 // it off to the Save task. When the Save task is done, it will attempt
260 // to free the list--which will decrement the counter again, and
261 // actually free the list if the counter hits zero.
263 InterlockedIncrement (&lpp
->lpList
->cRef
);
264 StartTask (taskSVR_HOSTLIST_SAVE
, NULL
, lpp
->lpList
);
269 void Server_Hosts_OnAddEntry (HWND hDlg
, LPSVR_HOSTS_PARAMS lpp
)
271 LPSVR_ADDHOST_PARAMS pAdd
= New (SVR_ADDHOST_PARAMS
);
272 memset (pAdd
, 0x00, sizeof(pAdd
));
273 pAdd
->lpiServer
= lpp
->lpiServer
;
275 if (ModalDialogParam (IDD_SVR_ADDHOST
, hDlg
, (DLGPROC
)Server_AddHost_DlgProc
, (LPARAM
)pAdd
) == IDOK
)
278 for (iEntry
= 0; iEntry
< lpp
->lpList
->cEntries
; ++iEntry
)
280 LPHOSTLISTENTRY pEntry
= &lpp
->lpList
->aEntries
[ iEntry
];
281 if (pEntry
->szHost
[0] == TEXT('\0'))
283 if (!lstrcmpi (pEntry
->szHost
, pAdd
->szHost
))
287 if (iEntry
>= lpp
->lpList
->cEntries
)
289 iEntry
= AfsClass_HostList_AddEntry (lpp
->lpList
, pAdd
->szHost
);
292 HWND hList
= GetDlgItem (hDlg
, IDC_HOST_LIST
);
293 FL_StartChange (hList
, FALSE
);
296 if ((hItem
= FastList_FindItem (hList
, (LPARAM
)iEntry
)) == NULL
)
298 hItem
= FL_AddItem (hList
, 1, (LPARAM
)iEntry
, 0, pAdd
->szHost
);
301 FL_EndChange (hList
, (LPARAM
)hItem
);
308 void Server_Hosts_OnDelEntry (HWND hDlg
, LPSVR_HOSTS_PARAMS lpp
)
310 HWND hList
= GetDlgItem (hDlg
, IDC_HOST_LIST
);
311 FL_StartChange (hList
, FALSE
);
314 while ((hItem
= FastList_FindFirstSelected (hList
)) != NULL
)
316 size_t iEntry
= (size_t)FL_GetData (hList
, hItem
);
317 AfsClass_HostList_DelEntry (lpp
->lpList
, iEntry
);
318 FastList_RemoveItem (hList
, hItem
);
321 FL_EndChange (hList
);
325 BOOL CALLBACK
Server_AddHost_DlgProc (HWND hDlg
, UINT msg
, WPARAM wp
, LPARAM lp
)
327 if (AfsAppLib_HandleHelp (IDD_SVR_ADDHOST
, hDlg
, msg
, wp
, lp
))
330 if (msg
== WM_INITDIALOG
)
331 SetWindowLongPtr (hDlg
, DWLP_USER
, lp
);
333 LPSVR_ADDHOST_PARAMS lpp
;
334 if ((lpp
= (LPSVR_ADDHOST_PARAMS
)GetWindowLongPtr (hDlg
, DWLP_USER
)) != NULL
)
339 Server_AddHost_OnInitDialog (hDlg
, lpp
);
346 GetDlgItemText (hDlg
, IDC_ADDHOST_HOST
, lpp
->szHost
, cchNAME
);
347 EndDialog (hDlg
, LOWORD(wp
));
351 EndDialog (hDlg
, LOWORD(wp
));
354 case IDC_ADDHOST_HOST
:
355 Server_AddHost_EnableOK (hDlg
);
366 void Server_AddHost_OnInitDialog (HWND hDlg
, LPSVR_ADDHOST_PARAMS lpp
)
368 TCHAR szDesc
[ cchRESOURCE
];
369 GetDlgItemText (hDlg
, IDC_ADDHOST_DESC
, szDesc
, cchRESOURCE
);
371 TCHAR szServer
[ cchNAME
];
372 lpp
->lpiServer
->GetServerName (szServer
);
374 LPTSTR pszDesc
= FormatString (szDesc
, TEXT("%s"), szServer
);
375 SetDlgItemText (hDlg
, IDC_ADDHOST_DESC
, pszDesc
);
376 FreeString (pszDesc
);
378 Server_AddHost_EnableOK (hDlg
);
382 void Server_AddHost_EnableOK (HWND hDlg
)
384 TCHAR szHost
[ cchNAME
];
385 GetDlgItemText (hDlg
, IDC_ADDHOST_HOST
, szHost
, cchNAME
);
387 EnableWindow (GetDlgItem (hDlg
, IDOK
), (szHost
[0] != TEXT('\0')) ? TRUE
: FALSE
);