windows-build-updates-20030314
[openafs.git] / src / WINNT / afssvrmgr / dispguts.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 "display.h"
17 #include "dispguts.h"
18 #include "svr_col.h"
19 #include "svr_window.h"
20 #include "svc_col.h"
21 #include "svc_startstop.h"
22 #include "agg_col.h"
23 #include "set_col.h"
24 #include "set_general.h"
25 #include "creds.h"
26
27
28 /*
29  * PROTOTYPES _________________________________________________________________
30  *
31  */
32
33 void Display_Servers_Internal_Clean (LPDISPLAYREQUEST pdr);
34 void Display_Servers_Internal_AddServer (LPDISPLAYREQUEST pdr, LPSERVER lpServer);
35
36 void Display_Services_Internal_Clean (LPDISPLAYREQUEST pdr);
37 void Display_Services_Internal_AddServer (LPDISPLAYREQUEST pdr, LPSERVER lpServer);
38 void Display_Services_Internal_AddService (LPDISPLAYREQUEST pdr, LPSERVICE lpService, HLISTITEM hServer);
39
40 void Display_Aggregates_Internal_Clean (LPDISPLAYREQUEST pdr);
41 void Display_Aggregates_Internal_AddServer (LPDISPLAYREQUEST pdr, LPSERVER lpServer);
42 void Display_Aggregates_Internal_AddAggregate (LPDISPLAYREQUEST pdr, LPAGGREGATE lpAggregate, HLISTITEM hServer);
43
44 void Display_Filesets_Internal_Clean (LPDISPLAYREQUEST pdr);
45 HLISTITEM Display_Filesets_Internal_AddCell (LPDISPLAYREQUEST pdr, LPCELL lpCell);
46 void Display_Filesets_Internal_AddServer (LPDISPLAYREQUEST pdr, LPSERVER lpServer, HLISTITEM hCell);
47 void Display_Filesets_Internal_AddAggregate (LPDISPLAYREQUEST pdr, LPAGGREGATE lpAggregate, HLISTITEM hServer);
48 void Display_Filesets_Internal_AddFileset (LPDISPLAYREQUEST pdr, LPFILESET lpFileset, HLISTITEM hAggregate);
49
50 #define PIF_ALWAYSSHOWICON     0x00000001
51 #define PIF_ONLYONEICON        0x00000002
52 #define PIF_TREEVIEW_ONLY      0x00000004
53 #define PIF_DISALLOW_COLLAPSE  0x00000008
54 void Display_PickImages (int *piFirstImage, int *piSecondImage, int iTypeImage, int iStatusImage, ICONVIEW iv, DWORD dwPickImageFlags = 0);
55 HLISTITEM Display_InsertItem (HWND hList, HLISTITEM hParent, LPTSTR pszText, LPARAM lp, int iImage0 = IMAGE_NOIMAGE, int iImage1 = IMAGE_NOIMAGE, ICONVIEW iv = (ICONVIEW)-1, DWORD dwPickImageFlags = 0);
56
57
58 /*
59  * CELL _______________________________________________________________________
60  *
61  */
62
63 void Display_Cell_Internal (LPDISPLAYREQUEST pdr)
64 {
65    // Update the "Current Cell:" field on g.hMain
66    //
67    TCHAR szCell[ cchNAME ];
68    if (g.lpiCell == NULL)
69       GetString (szCell, IDS_NO_CELL_SELECTED);
70    else
71       g.lpiCell->GetCellName (szCell);
72
73    SetDlgItemText (g.hMain, IDC_CELL, szCell);
74
75    // Update the "AFS Identity:" field on g.hMain
76    //
77    TCHAR szUser[ cchNAME ];
78    SYSTEMTIME stExpire;
79    if (!AfsAppLib_CrackCredentials (g.hCreds, szCell, szUser, &stExpire))
80       {
81       GetString (szUser, IDS_NO_AFS_ID);
82       SetDlgItemText (g.hMain, IDC_AFS_ID, szUser);
83       }
84    else
85       {
86       int ids = (AfsAppLib_IsTimeInFuture (&stExpire)) ? IDS_AFS_ID_WILLEXP : IDS_AFS_ID_DIDEXP;
87       LPTSTR pszText = FormatString (ids, TEXT("%s%t"), szUser, &stExpire);
88       SetDlgItemText (g.hMain, IDC_AFS_ID, pszText);
89       FreeString (pszText);
90       }
91 }
92
93
94 /*
95  * SERVERS ____________________________________________________________________
96  *
97  */
98
99 void Display_Servers_Internal (LPDISPLAYREQUEST pdr)
100 {
101    pdr->hList = GetDlgItem (g.hMain, IDC_SERVERS);
102    pdr->lpvi = (gr.fPreview && !gr.fVert) ? &gr.diHorz.viewSvr : &gr.diVert.viewSvr;
103
104    if (!IsWindow (pdr->hList))
105       return;
106
107    // Fix up the image lists for the Servers window
108    //
109    HIMAGELIST hiSmall;
110    HIMAGELIST hiLarge;
111    FastList_GetImageLists (pdr->hList, &hiSmall, &hiLarge);
112    if (!hiSmall || !hiLarge)
113       {
114       hiSmall = AfsAppLib_CreateImageList (FALSE);
115       hiLarge = AfsAppLib_CreateImageList (TRUE);
116       FastList_SetImageLists (pdr->hList, hiSmall, hiLarge);
117       }
118
119    // Add an entry in the Servers list for each server in the cell.
120    //
121    LPIDENT lpiSelStart = (LPIDENT)FL_GetSelectedData (pdr->hList);
122    BOOL fRefresh = FALSE;
123
124    LPCELL lpCell;
125    if (!g.lpiCell || !(lpCell = g.lpiCell->OpenCell()))
126       {
127       LPTSTR pszCover = FormatString (IDS_ERROR_REFRESH_CELLSERVERS_NOCELL);
128       AfsAppLib_CoverWindow (pdr->hList, pszCover);
129       FreeString (pszCover);
130       }
131    else
132       {
133       BOOL rc = TRUE;
134
135       pdr->lpiToSelect = (LPIDENT)FL_StartChange (pdr->hList, (pdr->lpiNotify) ? FALSE : TRUE);
136       pdr->actOnDone = ACT_ENDCHANGE | ACT_SELPREVIEW;
137
138       // Remove any to-be-replaced old servers
139       //
140       Display_Servers_Internal_Clean (pdr);
141
142       // Add a server entry for each server as appropriate
143       //
144       HENUM hEnum;
145       for (LPSERVER lpServer = lpCell->ServerFindFirst (&hEnum, pdr->lpiNotify, FALSE); lpServer; lpServer = lpCell->ServerFindNext (&hEnum))
146          {
147          Display_Servers_Internal_AddServer (pdr, lpServer);
148          lpServer->Close();
149          }
150
151       if (rc)
152          pdr->actOnDone |= ACT_UNCOVER;
153
154       lpCell->Close();
155       }
156 }
157
158
159 void Display_Servers_Internal_Clean (LPDISPLAYREQUEST pdr)
160 {
161    if (pdr->lpiNotify) // else, we already emptied the list
162       {
163       HLISTITEM hItem;
164       if ((hItem = FastList_FindItem (pdr->hList, (LPARAM)(pdr->lpiNotify))) != NULL)
165          FastList_RemoveItem (pdr->hList, hItem);
166       }
167 }
168
169
170 void Display_Servers_Internal_AddServer (LPDISPLAYREQUEST pdr, LPSERVER lpServer)
171 {
172    ULONG status = 0;
173    SERVERSTATUS ss;
174
175    if (lpServer->GetIdentifier() == pdr->lpiNotify)
176       status = pdr->status;
177
178    if (!status)
179       {
180       lpServer->GetStatus (&ss, FALSE, &status);
181
182       LPSERVER_PREF lpsp;
183       if ((lpsp = (LPSERVER_PREF)lpServer->GetUserParam()) != NULL)
184          memcpy (&lpsp->ssLast, &ss, sizeof(SERVERSTATUS));
185       }
186
187    ICONVIEW ivSvr = Display_GetServerIconView();
188
189    if (status != 0)
190       {
191       LPTSTR pszCol1 = FormatString (TEXT("%1 - %2"), TEXT("%s%e"), Server_GetColumnText (lpServer->GetIdentifier(), svrcolNAME), status);
192
193       Display_InsertItem (pdr->hList,
194                           NULL,
195                           pszCol1,
196                           (LPARAM)lpServer->GetIdentifier(),
197                           imageSERVER, imageSERVER_ALERT, ivSvr);
198
199       FreeString (pszCol1);
200       }
201    else
202       {
203       int iStatusImage = IMAGE_NOIMAGE;
204       if (!lpServer->fIsMonitored())
205          iStatusImage = imageSERVER_UNMON;
206       else if (Server_GetAlertCount (lpServer))
207          iStatusImage = imageSERVER_ALERT;
208
209       Display_InsertItem (pdr->hList,
210                           NULL,
211                           NULL,
212                           (LPARAM)lpServer->GetIdentifier(),
213                           imageSERVER, iStatusImage, ivSvr);
214       }
215 }
216
217
218 /*
219  * SERVICES ___________________________________________________________________
220  *
221  */
222
223 void Display_Services_Internal (LPDISPLAYREQUEST pdr)
224 {
225    pdr->hList = GetDlgItem (pdr->hChild, IDC_SVC_LIST);
226    pdr->lpvi = &gr.viewSvc;
227
228    if (!IsWindow (pdr->hList))
229       return;
230
231    // First off, can we totally ignore this request?
232    //
233    LPIDENT lpiWindow = Server_GetServerForChild (pdr->hChild);
234    if (lpiWindow && pdr->lpiNotify && (lpiWindow != pdr->lpiNotify->GetServer()))
235       return;
236
237    // Fix up the image lists for the Services window
238    //
239    HIMAGELIST hiSmall;
240    FastList_GetImageLists (pdr->hList, &hiSmall, NULL);
241    if (!hiSmall)
242       {
243       hiSmall = AfsAppLib_CreateImageList (FALSE);
244       FastList_SetImageLists (pdr->hList, hiSmall, NULL);
245       }
246
247    // Add either all services, or one server's services, or one service.
248    //
249    LPCELL lpCell;
250    if (g.lpiCell && (lpCell = g.lpiCell->OpenCell()))
251       {
252       pdr->lpiToSelect = (LPIDENT)FL_StartChange (pdr->hList, (pdr->lpiNotify) ? FALSE : TRUE);
253       pdr->actOnDone = ACT_ENDCHANGE;
254
255       // Remove any to-be-replaced old services
256       //
257       Display_Services_Internal_Clean (pdr);
258
259       // Update all appropriate service entries
260       //
261       LPIDENT lpiRefresh = (pdr->lpiNotify) ? pdr->lpiNotify : lpiWindow;
262
263       HENUM hEnum;
264       for (LPSERVER lpServer = lpCell->ServerFindFirst (&hEnum, lpiRefresh, FALSE); lpServer; lpServer = lpCell->ServerFindNext (&hEnum))
265          {
266          if (lpServer->fIsMonitored())
267             Display_Services_Internal_AddServer (pdr, lpServer);
268          lpServer->Close();
269          }
270
271       if (pdr->lpiToSelect)
272          FL_SetSelectedByData (pdr->hList, (LPARAM)pdr->lpiToSelect);
273       lpCell->Close();
274       }
275 }
276
277
278 void Display_Services_Internal_Clean (LPDISPLAYREQUEST pdr)
279 {
280    if (pdr->lpiNotify) // else, we already emptied the list
281       {
282       HLISTITEM hItem;
283       if ((hItem = FastList_FindItem (pdr->hList, (LPARAM)(pdr->lpiNotify))) != NULL)
284          FastList_RemoveItem (pdr->hList, hItem);
285       }
286 }
287
288
289 void Display_Services_Internal_AddServer (LPDISPLAYREQUEST pdr, LPSERVER lpServer)
290 {
291    ULONG status = 0;
292    SERVERSTATUS ss;
293
294    if (lpServer->GetIdentifier() == pdr->lpiNotify)
295       status = pdr->status;
296    if (!status)
297       lpServer->GetStatus (&ss, FALSE, &status);
298
299    LPTSTR pszServerText = NULL;
300    int iStatusImage = imageSERVER;
301    BOOL fContinue = TRUE;
302
303    if (status != 0)
304       {
305       pszServerText = FormatString (TEXT("%1 - %2"), TEXT("%s%e"), Server_GetColumnText (lpServer->GetIdentifier(), svrcolNAME), status);
306       iStatusImage = imageSERVER_ALERT;
307       fContinue = FALSE;
308       }
309    else if (Server_GetAlertCount (lpServer))
310       {
311       pszServerText = FormatString (TEXT("%1 - %2"), TEXT("%s%s"), Server_GetColumnText (lpServer->GetIdentifier(), svrcolNAME), Server_GetColumnText (lpServer->GetIdentifier(), svrcolSTATUS));
312       iStatusImage = imageSERVER_ALERT;
313       }
314
315    HLISTITEM hServer;
316    if ((hServer = FastList_FindItem (pdr->hList, (LPARAM)(lpServer->GetIdentifier()))) == NULL)
317       {
318       hServer = Display_InsertItem (pdr->hList, NULL, pszServerText,
319                                     (LPARAM)lpServer->GetIdentifier(),
320                                     imageSERVER, iStatusImage, gr.ivSet, PIF_ALWAYSSHOWICON | PIF_TREEVIEW_ONLY);
321       }
322    else
323       {
324       int iImage1, iImage2;
325       Display_PickImages (&iImage1, &iImage2, imageSERVER, iStatusImage, gr.ivSet, PIF_ALWAYSSHOWICON | PIF_TREEVIEW_ONLY);
326       FastList_SetItemFirstImage (pdr->hList, hServer, iImage1);
327       FastList_SetItemSecondImage (pdr->hList, hServer, iImage2);
328       FastList_SetItemText (pdr->hList, hServer, 0, pszServerText);
329       }
330
331    if (pszServerText)
332       FreeString (pszServerText);
333
334    if (fContinue)
335       {
336       // Update icons for all appropriate services
337       //
338       LPIDENT lpiSearch = (pdr->lpiNotify && pdr->lpiNotify->fIsService()) ? (pdr->lpiNotify) : NULL;
339
340       HENUM hEnum;
341       for (LPSERVICE lpService = lpServer->ServiceFindFirst (&hEnum, lpiSearch, FALSE); lpService; lpService = lpServer->ServiceFindNext (&hEnum))
342          {
343          Display_Services_Internal_AddService (pdr, lpService, hServer);
344          lpService->Close();
345          }
346       }
347 }
348
349
350 void Display_Services_Internal_AddService (LPDISPLAYREQUEST pdr, LPSERVICE lpService, HLISTITEM hServer)
351 {
352    ULONG status = 0;
353    SERVICESTATUS ss;
354
355    if (lpService->GetIdentifier() == pdr->lpiNotify)
356       status = pdr->status;
357    if (!status)
358       lpService->GetStatus (&ss, FALSE, &status);
359
360    BOOL fShowServerName = !Server_GetServer (pdr->hChild);
361
362    if (status != 0)
363       {
364       LPTSTR pszCol1 = FormatString (TEXT("%1 - %2"), TEXT("%s%e"), Services_GetColumnText (lpService->GetIdentifier(), svccolNAME, fShowServerName), status);
365
366       Display_InsertItem (pdr->hList,
367                           hServer,
368                           pszCol1,
369                           (LPARAM)lpService->GetIdentifier(),
370                           imageSERVICE, imageSERVICE_ALERT, gr.ivSvc);
371
372       FreeString (pszCol1);
373       }
374    else
375       {
376       TCHAR szName[ cchRESOURCE ];
377       lpService->GetName (szName);
378
379       BOOL fIsBOS = !lstrcmpi (szName, TEXT("BOS"));
380
381       LPSERVICE_PREF lpsp;
382       if ((lpsp = (LPSERVICE_PREF)lpService->GetUserParam()) != NULL)
383          memcpy (&lpsp->ssLast, &ss, sizeof(SERVICESTATUS));
384
385       int iTypeImage = imageSERVICE;
386       if (fIsBOS)
387          iTypeImage = imageBOSSERVICE;
388
389       int iStatusImage = IMAGE_NOIMAGE;
390       if (Services_GetAlertCount (lpService))
391          iStatusImage = imageSERVICE_ALERT;
392       else if (!Services_fRunning (lpService))
393          iStatusImage = imageSERVICE_STOPPED;
394       else if (fIsBOS)
395          iStatusImage = imageBOSSERVICE;
396
397       Display_InsertItem (pdr->hList,
398                           hServer,
399                           NULL,
400                           (LPARAM)lpService->GetIdentifier(),
401                           iTypeImage, iStatusImage, gr.ivSvc);
402       }
403 }
404
405
406 /*
407  * AGGREGATES _________________________________________________________________
408  *
409  */
410
411 void Display_Aggregates_Internal (LPDISPLAYREQUEST pdr)
412 {
413    if (pdr->lpvi == NULL)
414       pdr->lpvi = &gr.viewAgg;
415
416    if (!IsWindow (pdr->hList))
417       return;
418
419    TCHAR szClassName[ cchRESOURCE ];
420    if (GetClassName (pdr->hList, szClassName, cchRESOURCE))
421       {
422       if (!lstrcmp (szClassName, WC_FASTLIST))
423          pdr->fList = TRUE;
424       }
425
426    // First off, can we totally ignore this request?
427    //
428    if (pdr->lpiServer && pdr->lpiNotify && (pdr->lpiServer != pdr->lpiNotify->GetServer()))
429       return;
430
431    // Fix up the image lists for the Aggregates window
432    //
433    if (pdr->fList)
434       {
435       HIMAGELIST hiSmall;
436       FastList_GetImageLists (pdr->hList, &hiSmall, NULL);
437       if (!hiSmall)
438          {
439          hiSmall = AfsAppLib_CreateImageList (FALSE);
440          FastList_SetImageLists (pdr->hList, hiSmall, NULL);
441          }
442       }
443
444    // Add either all aggregates, or one server's aggregates, or one aggregate.
445    //
446    LPCELL lpCell;
447    if (g.lpiCell && (lpCell = g.lpiCell->OpenCell()))
448       {
449       LPIDENT lpiSelectedNow;
450       if (pdr->fList)
451          lpiSelectedNow = (LPIDENT)FL_StartChange (pdr->hList, (pdr->lpiNotify) ? FALSE : TRUE);
452       else
453          lpiSelectedNow = (LPIDENT)CB_StartChange (pdr->hList, (pdr->lpiNotify) ? FALSE : TRUE);
454
455       if (!pdr->lpiToSelect)
456          pdr->lpiToSelect = lpiSelectedNow;
457
458       pdr->actOnDone = ACT_ENDCHANGE;
459
460       // Remove any to-be-replaced old services
461       //
462       Display_Aggregates_Internal_Clean (pdr);
463
464       // Update all appropriate aggregate entries
465       //
466       LPIDENT lpiRefresh = (pdr->lpiNotify) ? pdr->lpiNotify : pdr->lpiServer;
467
468       HENUM hEnum;
469       for (LPSERVER lpServer = lpCell->ServerFindFirst (&hEnum, lpiRefresh, FALSE); lpServer; lpServer = lpCell->ServerFindNext (&hEnum))
470          {
471          if (lpServer->fIsMonitored())
472             Display_Aggregates_Internal_AddServer (pdr, lpServer);
473          lpServer->Close();
474          }
475
476       if (pdr->lpiToSelect)
477          {
478          if (pdr->fList)
479             FL_SetSelectedByData (pdr->hList, (LPARAM)pdr->lpiToSelect);
480          else
481             CB_SetSelectedByData (pdr->hList, (LPARAM)pdr->lpiToSelect);
482          }
483       if (!pdr->fList) // combobox?  then always pick *something*...
484          {
485          if (!CB_GetSelectedData (pdr->hList))
486             {
487             pdr->lpiToSelect = (LPIDENT)CB_GetData (pdr->hList, 0);
488             }
489          }
490
491       lpCell->Close();
492       }
493 }
494
495
496 void Display_Aggregates_Internal_Clean (LPDISPLAYREQUEST pdr)
497 {
498    if (pdr->lpiNotify) // else, we already emptied the list
499       {
500       if (pdr->fList)
501          {
502          HLISTITEM hItem;
503          if ((hItem = FastList_FindItem (pdr->hList, (LPARAM)(pdr->lpiNotify))) != NULL)
504             FastList_RemoveItem (pdr->hList, hItem);
505          }
506       else
507          {
508          size_t iMax = SendMessage (pdr->hList, CB_GETCOUNT, 0, 0);
509
510          for (size_t iItem = 0; iItem < iMax; )
511             {
512             BOOL fDelete = FALSE;
513
514             LPIDENT lpiItem;
515             if ((lpiItem = (LPIDENT)CB_GetData (pdr->hList, iItem)) != NULL)
516                {
517                // delete the entry if it's the TBD server or aggregate
518                //
519                if (lpiItem == pdr->lpiNotify)
520                   fDelete = TRUE;
521
522                // delete the entry if it's the server of a TBD aggregate
523                //
524                if (lpiItem == pdr->lpiNotify->GetServer())
525                   fDelete = TRUE;
526
527                // delete the entry if it's an aggregate on the TBD server
528                //
529                if (lpiItem->GetServer() == pdr->lpiNotify)
530                   fDelete = TRUE;
531                }
532
533             if (!fDelete)
534                ++iItem;
535             else
536                {
537                SendMessage (pdr->hList, CB_DELETESTRING, iItem, 0);
538                --iMax;
539                }
540             }
541          }
542       }
543 }
544
545
546 void Display_Aggregates_Internal_AddServer (LPDISPLAYREQUEST pdr, LPSERVER lpServer)
547 {
548    ULONG status = 0;
549    SERVERSTATUS ss;
550
551    if (lpServer->GetIdentifier() == pdr->lpiNotify)
552       status = pdr->status;
553    if (!status)
554       lpServer->GetStatus (&ss, FALSE, &status);
555
556    HLISTITEM hServer = NULL;
557    if (pdr->fList)
558       {
559       LPTSTR pszServerText = NULL;
560       int iStatusImage = imageSERVER;
561
562       if (status != 0)
563          {
564          pszServerText = FormatString (TEXT("%1 - %2"), TEXT("%s%e"), Server_GetColumnText (lpServer->GetIdentifier(), svrcolNAME), status);
565          iStatusImage = imageSERVER_ALERT;
566          }
567       else if (Server_GetAlertCount (lpServer))
568          {
569          pszServerText = FormatString (TEXT("%1 - %2"), TEXT("%s%s"), Server_GetColumnText (lpServer->GetIdentifier(), svrcolNAME), Server_GetColumnText (lpServer->GetIdentifier(), svrcolSTATUS));
570          iStatusImage = imageSERVER_ALERT;
571          }
572
573       if ((hServer = FastList_FindItem (pdr->hList, (LPARAM)(lpServer->GetIdentifier()))) == NULL)
574          {
575          hServer = Display_InsertItem (pdr->hList, NULL, pszServerText,
576                                        (LPARAM)lpServer->GetIdentifier(),
577                                        imageSERVER, iStatusImage, gr.ivSet, PIF_ALWAYSSHOWICON | PIF_TREEVIEW_ONLY);
578          }
579       else
580          {
581          int iImage1, iImage2;
582          Display_PickImages (&iImage1, &iImage2, imageSERVER, iStatusImage, gr.ivSet, PIF_ALWAYSSHOWICON | PIF_TREEVIEW_ONLY);
583          FastList_SetItemFirstImage (pdr->hList, hServer, iImage1);
584          FastList_SetItemSecondImage (pdr->hList, hServer, iImage2);
585          FastList_SetItemText (pdr->hList, hServer, 0, pszServerText);
586          }
587
588       if (pszServerText)
589          FreeString (pszServerText);
590       }
591
592    if ((hServer || !pdr->fList) && !status)
593       {
594       // Update icons for all appropriate aggregates
595       //
596       LPIDENT lpiSearch = (pdr->lpiNotify && pdr->lpiNotify->fIsAggregate()) ? (pdr->lpiNotify) : NULL;
597
598       HENUM hEnum;
599       for (LPAGGREGATE lpAggregate = lpServer->AggregateFindFirst (&hEnum, lpiSearch, FALSE); lpAggregate; lpAggregate = lpServer->AggregateFindNext (&hEnum))
600          {
601          Display_Aggregates_Internal_AddAggregate (pdr, lpAggregate, hServer);
602          lpAggregate->Close();
603          }
604       }
605 }
606
607
608 void Display_Aggregates_Internal_AddAggregate (LPDISPLAYREQUEST pdr, LPAGGREGATE lpAggregate, HLISTITEM hServer)
609 {
610    ULONG status = 0;
611    AGGREGATESTATUS as;
612
613    if (lpAggregate->GetIdentifier() == pdr->lpiNotify)
614       status = pdr->status;
615    if (!status)
616       lpAggregate->GetStatus (&as, FALSE, &status);
617
618    BOOL fShowServerName = !Server_GetServer (pdr->hChild);
619
620    if (status != 0)
621       {
622       LPTSTR pszCol1 = FormatString (TEXT("%1 - %2"), TEXT("%s%e"), Aggregates_GetColumnText (lpAggregate->GetIdentifier(), aggcolNAME, fShowServerName), status);
623
624       if (pdr->fList)
625          {
626          Display_InsertItem (pdr->hList, hServer, pszCol1,
627                              (LPARAM)lpAggregate->GetIdentifier(),
628                              imageAGGREGATE, imageAGGREGATE_ALERT, gr.ivAgg);
629          }
630       else
631          {
632          CB_AddItem (pdr->hList, pszCol1, (LPARAM)lpAggregate->GetIdentifier());
633          }
634
635       FreeString (pszCol1);
636       }
637    else
638       {
639       LPAGGREGATE_PREF lpap;
640       if ((lpap = (LPAGGREGATE_PREF)lpAggregate->GetUserParam()) != NULL)
641          {
642          memcpy (&lpap->asLast, &as, sizeof(AGGREGATESTATUS));
643          lpAggregate->GetDevice (lpap->szDevice);
644          }
645
646       if (pdr->fList)
647          {
648          int iStatusImage = IMAGE_NOIMAGE;
649          if (Aggregates_GetAlertCount (lpAggregate))
650             iStatusImage = imageAGGREGATE_ALERT;
651
652          Display_InsertItem (pdr->hList, hServer, NULL,
653                              (LPARAM)lpAggregate->GetIdentifier(),
654                              imageAGGREGATE, iStatusImage, gr.ivAgg);
655          }
656       else
657          {
658          TCHAR szName[ cchNAME ];
659          lpAggregate->GetIdentifier()->GetAggregateName (szName);
660          CB_AddItem (pdr->hList, szName, (LPARAM)lpAggregate->GetIdentifier());
661          }
662       }
663 }
664
665
666 /*
667  * FILESETS ___________________________________________________________________
668  *
669  */
670
671 void Display_Filesets_Internal (LPDISPLAYREQUEST pdr)
672 {
673    if (pdr->hList == NULL)
674       pdr->hList = GetDlgItem (pdr->hChild, IDC_SET_LIST);
675
676    if (!IsWindow (pdr->hList))
677       return;
678
679    TCHAR szClassName[ cchRESOURCE ];
680    if (GetClassName (pdr->hList, szClassName, cchRESOURCE))
681       {
682       if (!lstrcmp (szClassName, WC_FASTLIST))
683          pdr->fList = TRUE;
684       }
685
686    pdr->lpvi = (pdr->fList) ? &gr.viewSet : NULL;
687
688    // First off, can we totally ignore this request?
689    //
690    if (pdr->lpiServer && pdr->lpiNotify && (pdr->lpiServer != pdr->lpiNotify->GetServer()))
691       return;
692
693    // Fix up the image lists for the Filesets window
694    //
695    if (pdr->fList)
696       {
697       HIMAGELIST hiSmall;
698       FastList_GetImageLists (pdr->hList, &hiSmall, NULL);
699       if (!hiSmall)
700          {
701          hiSmall = AfsAppLib_CreateImageList (FALSE);
702          FastList_SetImageLists (pdr->hList, hiSmall, NULL);
703          }
704       }
705
706    // Add either all filesets, or one server's filesets, or one fileset.
707    //
708    LPCELL lpCell;
709    if (g.lpiCell && (lpCell = g.lpiCell->OpenCell()))
710       {
711       pdr->actOnDone = ACT_ENDCHANGE;
712
713       // Remove any to-be-replaced old services
714       //
715       LPIDENT lpiSelectedNow;
716       if (pdr->fList)
717          lpiSelectedNow = (LPIDENT)FL_StartChange (pdr->hList, (pdr->lpiNotify) ? FALSE : TRUE);
718       else
719          lpiSelectedNow = (LPIDENT)CB_StartChange (pdr->hList, (pdr->lpiNotify) ? FALSE : TRUE);
720       Display_Filesets_Internal_Clean (pdr);
721
722       if (! pdr->lpiToSelect)
723          pdr->lpiToSelect = lpiSelectedNow;
724
725       HLISTITEM hCell;
726       hCell = Display_Filesets_Internal_AddCell (pdr, lpCell);
727
728       // Update all appropriate fileset entries
729       //
730       LPIDENT lpiRefresh = (pdr->lpiNotify) ? pdr->lpiNotify : pdr->lpiServer;
731
732       HENUM hEnum;
733       for (LPSERVER lpServer = lpCell->ServerFindFirst (&hEnum, lpiRefresh, FALSE); lpServer; lpServer = lpCell->ServerFindNext (&hEnum))
734          {
735          if (lpServer->fIsMonitored())
736             Display_Filesets_Internal_AddServer (pdr, lpServer, hCell);
737          lpServer->Close();
738          }
739
740       if (pdr->lpiToSelect)
741          {
742          if (pdr->fList)
743             FL_SetSelectedByData (pdr->hList, (LPARAM)pdr->lpiToSelect);
744          else
745             CB_SetSelectedByData (pdr->hList, (LPARAM)pdr->lpiToSelect);
746          }
747       if (!pdr->fList) // combobox?  then always pick *something*...
748          {
749          if (!CB_GetSelectedData (pdr->hList))
750             {
751             pdr->lpiToSelect = (LPIDENT)CB_GetData (pdr->hList, 0);
752             }
753          }
754
755       lpCell->Close();
756       }
757 }
758
759
760 void Display_Filesets_Internal_Clean (LPDISPLAYREQUEST pdr)
761 {
762    if (pdr->lpiNotify)
763       {
764       if (pdr->fList)
765          {
766          HLISTITEM hItem;
767          if ((hItem = FastList_FindItem (pdr->hList, (LPARAM)pdr->lpiNotify)) != NULL)
768             {
769             FastList_RemoveItem (pdr->hList, hItem);
770             }
771          }
772       else // Must be a combobox
773          {
774          size_t iMax = SendMessage (pdr->hList, CB_GETCOUNT, 0, 0);
775
776          for (size_t iItem = 0; iItem < iMax; )
777             {
778             BOOL fDelete = FALSE;
779
780             LPIDENT lpiItem;
781             if ((lpiItem = (LPIDENT)CB_GetData (pdr->hList, iItem)) != NULL)
782                {
783                if (lpiItem->GetServer() == pdr->lpiNotify)
784                   fDelete = TRUE;
785                if (lpiItem->GetAggregate() == pdr->lpiNotify)
786                   fDelete = TRUE;
787                if (lpiItem == pdr->lpiNotify)
788                   fDelete = TRUE;
789                }
790
791             if (!fDelete)
792                ++iItem;
793             else
794                {
795                SendMessage (pdr->hList, CB_DELETESTRING, iItem, 0);
796                --iMax;
797                }
798             }
799          }
800       }
801 }
802
803
804 HLISTITEM Display_Filesets_Internal_AddCell (LPDISPLAYREQUEST pdr, LPCELL lpCell)
805 {
806    if (!pdr->fList)
807       return NULL;
808
809    HLISTITEM hCell;
810    if ((hCell = FastList_FindItem (pdr->hList, (LPARAM)lpCell->GetIdentifier())) == NULL)
811       {
812       TCHAR szName[ cchNAME ];
813       lpCell->GetName (szName);
814
815       hCell = Display_InsertItem (pdr->hList, NULL, szName,
816                                   (LPARAM)lpCell->GetIdentifier(),
817                                   imageCELL, IMAGE_NOIMAGE, gr.ivSet,
818                                   PIF_ALWAYSSHOWICON | PIF_ONLYONEICON | PIF_TREEVIEW_ONLY | PIF_DISALLOW_COLLAPSE);
819       }
820
821    return hCell;
822 }
823
824
825 void Display_Filesets_Internal_AddServer (LPDISPLAYREQUEST pdr, LPSERVER lpServer, HLISTITEM hCell)
826 {
827    ULONG status = 0;
828    SERVERSTATUS ss;
829
830    if (lpServer->GetIdentifier() == pdr->lpiNotify)
831       status = pdr->status;
832    if (!status)
833       lpServer->GetStatus (&ss, FALSE, &status);
834
835    HLISTITEM hServer = NULL;
836    if (pdr->fList)
837       {
838       LPTSTR pszServerText = NULL;
839       int iStatusImage = imageSERVER;
840
841       if (status != 0)
842          {
843          pszServerText = FormatString (TEXT("%1 - %2"), TEXT("%s%e"), Server_GetColumnText (lpServer->GetIdentifier(), svrcolNAME), status);
844          iStatusImage = imageSERVER_ALERT;
845          }
846       else if (Server_GetAlertCount (lpServer))
847          {
848          pszServerText = FormatString (TEXT("%1 - %2"), TEXT("%s%s"), Server_GetColumnText (lpServer->GetIdentifier(), svrcolNAME), Server_GetColumnText (lpServer->GetIdentifier(), svrcolSTATUS));
849          iStatusImage = imageSERVER_ALERT;
850          }
851
852       if ((hServer = FastList_FindItem (pdr->hList, (LPARAM)(lpServer->GetIdentifier()))) == NULL)
853          {
854          hServer = Display_InsertItem (pdr->hList, hCell, pszServerText,
855                                        (LPARAM)lpServer->GetIdentifier(),
856                                        imageSERVER, iStatusImage, gr.ivSet, PIF_ALWAYSSHOWICON | PIF_TREEVIEW_ONLY);
857          }
858       else
859          {
860          int iImage1, iImage2;
861          Display_PickImages (&iImage1, &iImage2, imageSERVER, iStatusImage, gr.ivSet, PIF_ALWAYSSHOWICON | PIF_TREEVIEW_ONLY);
862          FastList_SetItemFirstImage (pdr->hList, hServer, iImage1);
863          FastList_SetItemSecondImage (pdr->hList, hServer, iImage2);
864          FastList_SetItemText (pdr->hList, hServer, 0, pszServerText);
865          }
866
867       if (pszServerText)
868          FreeString (pszServerText);
869       }
870
871    if (status == 0)
872       {
873       // Update filesets on all appropriate aggregates
874       //
875       LPIDENT lpiSearch = (pdr->lpiNotify && !pdr->lpiNotify->fIsServer()) ? (pdr->lpiNotify->GetAggregate()) : pdr->lpiAggregate;
876
877       HENUM hEnum;
878       for (LPAGGREGATE lpAggregate = lpServer->AggregateFindFirst (&hEnum, lpiSearch, FALSE); lpAggregate; lpAggregate = lpServer->AggregateFindNext (&hEnum))
879          {
880          Display_Filesets_Internal_AddAggregate (pdr, lpAggregate, hServer);
881          lpAggregate->Close();
882          }
883
884       if (pdr->fList && hServer)
885          {
886          BOOL fExpand = TRUE;
887
888          LPSERVER_PREF lpsp;
889          if ((lpsp = (LPSERVER_PREF)lpServer->GetUserParam()) != NULL)
890             fExpand = lpsp->fExpandTree;
891
892          FastList_SetExpanded (pdr->hList, hServer, fExpand);
893          }
894       }
895 }
896
897
898 void Display_Filesets_Internal_AddAggregate (LPDISPLAYREQUEST pdr, LPAGGREGATE lpAggregate, HLISTITEM hServer)
899 {
900    ULONG status = 0;
901    AGGREGATESTATUS as;
902
903    if (lpAggregate->GetIdentifier() == pdr->lpiNotify)
904       status = pdr->status;
905    if (!status)
906       lpAggregate->GetStatus (&as, FALSE, &status);
907
908    HLISTITEM hAggregate = NULL;
909    if (pdr->fList)
910       {
911       LPTSTR pszAggregateText = NULL;
912       int iStatusImage = imageAGGREGATE;
913
914       if (status != 0)
915          {
916          pszAggregateText = FormatString (TEXT("%1 - %2"), TEXT("%s%e"), Aggregates_GetColumnText (lpAggregate->GetIdentifier(), aggcolNAME, FALSE), status);
917          iStatusImage = imageAGGREGATE_ALERT;
918          }
919       else if (Aggregates_GetAlertCount (lpAggregate))
920          {
921          pszAggregateText = FormatString (TEXT("%1 - %2"), TEXT("%s%s"), Aggregates_GetColumnText (lpAggregate->GetIdentifier(), aggcolNAME), Aggregates_GetColumnText (lpAggregate->GetIdentifier(), aggcolSTATUS));
922          iStatusImage = imageAGGREGATE_ALERT;
923          }
924
925       if ((hAggregate = FastList_FindItem (pdr->hList, (LPARAM)lpAggregate->GetIdentifier())) == NULL)
926          {
927          hAggregate = Display_InsertItem (pdr->hList, hServer, pszAggregateText,
928                                           (LPARAM)lpAggregate->GetIdentifier(),
929                                           imageAGGREGATE, iStatusImage, gr.ivSet, PIF_ALWAYSSHOWICON | PIF_TREEVIEW_ONLY);
930          }
931       else
932          {
933          int iImage1, iImage2;
934          Display_PickImages (&iImage1, &iImage2, imageAGGREGATE, iStatusImage, gr.ivSet, PIF_ALWAYSSHOWICON | PIF_TREEVIEW_ONLY);
935          FastList_SetItemFirstImage (pdr->hList, hAggregate, iImage1);
936          FastList_SetItemSecondImage (pdr->hList, hAggregate, iImage2);
937          FastList_SetItemText (pdr->hList, hAggregate, 0, pszAggregateText);
938          }
939
940       if (pszAggregateText)
941          FreeString (pszAggregateText);
942       }
943
944    if (status == 0)
945       {
946       // Update all appropriate filesets from this aggregate
947       //
948       LPIDENT lpiSearch = (pdr->lpiNotify && pdr->lpiNotify->fIsFileset()) ? (pdr->lpiNotify) : NULL;
949
950       HENUM hEnum;
951       for (LPFILESET lpFileset = lpAggregate->FilesetFindFirst (&hEnum, lpiSearch, FALSE); lpFileset; lpFileset = lpAggregate->FilesetFindNext (&hEnum))
952          {
953          Display_Filesets_Internal_AddFileset (pdr, lpFileset, hAggregate);
954          lpFileset->Close();
955          }
956
957       if (pdr->fList && hAggregate)
958          {
959          BOOL fExpand = (hServer == NULL) ? TRUE : FALSE;
960
961          LPAGGREGATE_PREF lpap;
962          if ((lpap = (LPAGGREGATE_PREF)lpAggregate->GetUserParam()) != NULL)
963             fExpand = lpap->fExpandTree;
964
965          FastList_SetExpanded (pdr->hList, hAggregate, fExpand);
966          }
967       }
968 }
969
970
971 void Display_Filesets_Internal_AddFileset (LPDISPLAYREQUEST pdr, LPFILESET lpFileset, HLISTITEM hAggregate)
972 {
973    ULONG status = 0;
974    FILESETSTATUS fs;
975
976    if (lpFileset->GetIdentifier() == pdr->lpiNotify)
977       status = pdr->status;
978    if (!status)
979       lpFileset->GetStatus (&fs, FALSE, &status);
980
981    if (status != 0)
982       {
983       if (pdr->fList)
984          {
985          LPTSTR pszFilesetText = FormatString (TEXT("%1 - %2"), TEXT("%s%e"), Filesets_GetColumnText (lpFileset->GetIdentifier(), setcolNAME), status);
986
987          Display_InsertItem (pdr->hList, hAggregate, pszFilesetText,
988                              (LPARAM)lpFileset->GetIdentifier(),
989                              imageFILESET, imageFILESET_ALERT, gr.ivSet);
990
991          FreeString (pszFilesetText);
992          }
993       }
994    else
995       {
996       if (!pdr->fList)
997          {
998          TCHAR szName[ cchNAME ];
999          lpFileset->GetName (szName);
1000          CB_AddItem (pdr->hList, szName, (LPARAM)lpFileset->GetIdentifier());
1001          }
1002       else
1003          {
1004          LPFILESET_PREF lpfp;
1005          if ((lpfp = (LPFILESET_PREF)lpFileset->GetUserParam()) != NULL)
1006             {
1007             memcpy (&lpfp->fsLast, &fs, sizeof(FILESETSTATUS));
1008             lpfp->lpiRW = lpFileset->GetReadWriteIdentifier();
1009             }
1010
1011          int iStatusImage = IMAGE_NOIMAGE;
1012          if (Filesets_GetAlertCount (lpFileset))
1013             iStatusImage = imageFILESET_ALERT;
1014          else if (Filesets_fIsLocked (&fs))
1015             iStatusImage = imageFILESET_LOCKED;
1016
1017          Display_InsertItem (pdr->hList, hAggregate, NULL,
1018                              (LPARAM)lpFileset->GetIdentifier(),
1019                              imageFILESET, iStatusImage, gr.ivSet);
1020          }
1021       }
1022 }
1023
1024
1025 /*
1026  * REPLICAS ___________________________________________________________________
1027  *
1028  * (lpiNotify is the RW for which to list all replicas)
1029  *
1030  */
1031
1032 void Display_Replicas_Internal (LPDISPLAYREQUEST pdr)
1033 {
1034    if (!IsWindow (pdr->hList))
1035       return;
1036
1037    pdr->lpvi = &gr.viewRep;
1038    pdr->actOnDone = ACT_ENDCHANGE;
1039
1040    LPIDENT lpiRW = pdr->lpiNotify;
1041    VOLUMEID vidReadWrite;
1042    lpiRW->GetFilesetID (&vidReadWrite);
1043
1044    FL_StartChange (pdr->hList, TRUE);
1045
1046    LPCELL lpCell;
1047    if ((lpCell = lpiRW->OpenCell()) != NULL)
1048       {
1049       HENUM heServer;
1050       for (LPSERVER lpServer = lpCell->ServerFindFirst (&heServer); lpServer; lpServer = lpCell->ServerFindNext (&heServer))
1051          {
1052          HENUM heAggregate;
1053          for (LPAGGREGATE lpAggregate = lpServer->AggregateFindFirst (&heAggregate); lpAggregate; lpAggregate = lpServer->AggregateFindNext (&heAggregate))
1054             {
1055             HENUM heFileset;
1056             for (LPFILESET lpFileset = lpAggregate->FilesetFindFirst (&heFileset); lpFileset; lpFileset = lpAggregate->FilesetFindNext (&heFileset))
1057                {
1058                FILESETSTATUS fs;
1059                if (lpFileset->GetStatus (&fs))
1060                   {
1061                   if ( (fs.Type == ftREPLICA) &&
1062                        (!memcmp (&vidReadWrite, &fs.idReadWrite, sizeof(VOLUMEID))) )
1063                      {
1064                      LPFILESET_PREF lpfp;
1065                      if ((lpfp = (LPFILESET_PREF)lpFileset->GetUserParam()) != NULL)
1066                         {
1067                         memcpy (&lpfp->fsLast, &fs, sizeof(FILESETSTATUS));
1068                         lpfp->lpiRW = lpiRW;
1069                         }
1070
1071                      Display_InsertItem (pdr->hList, NULL, NULL,
1072                                          (LPARAM)lpFileset->GetIdentifier());
1073                      }
1074                   }
1075                lpFileset->Close();
1076                }
1077             lpAggregate->Close();
1078             }
1079          lpServer->Close();
1080          }
1081       lpCell->Close();
1082       }
1083 }
1084
1085
1086 /*
1087  * SERVER WINDOWS _____________________________________________________________
1088  *
1089  */
1090
1091 void Display_ServerWindow_Internal (LPDISPLAYREQUEST pdr)
1092 {
1093    Server_SelectServer (pdr->hChild, pdr->lpiServer, TRUE); // redraw svr window
1094 }
1095
1096
1097 /*
1098  * ICON SELECTION _____________________________________________________________
1099  *
1100  */
1101
1102 void Display_PickImages (int *piImage0, int *piImage1, int iTypeImage, int iStatusImage, ICONVIEW iv, DWORD dwFlags)
1103 {
1104    switch (iv)
1105       {
1106       case ivTWOICONS:
1107          *piImage0 = iTypeImage;
1108          *piImage1 = (iStatusImage == IMAGE_NOIMAGE) ? IMAGE_BLANKIMAGE : iStatusImage;
1109          if (*piImage1 == *piImage0)
1110             *piImage1 = IMAGE_BLANKIMAGE;
1111          if (dwFlags & PIF_ONLYONEICON)
1112             *piImage1 = IMAGE_NOIMAGE;
1113          break;
1114
1115       case ivONEICON:
1116          *piImage0 = (iStatusImage == IMAGE_NOIMAGE) ? IMAGE_BLANKIMAGE : iStatusImage;
1117          *piImage1 = IMAGE_NOIMAGE;
1118          dwFlags |= PIF_ALWAYSSHOWICON;
1119          break;
1120
1121       case ivSTATUS:
1122          *piImage0 = (iStatusImage == IMAGE_NOIMAGE) ? IMAGE_BLANKIMAGE : iStatusImage;
1123          *piImage1 = IMAGE_NOIMAGE;
1124          break;
1125
1126       default:
1127          *piImage0 = iTypeImage;
1128          *piImage1 = iStatusImage;
1129          return;
1130       }
1131
1132    if ((dwFlags & PIF_ALWAYSSHOWICON) && ((*piImage0 == IMAGE_NOIMAGE) || (*piImage0 == IMAGE_BLANKIMAGE)))
1133       {
1134       *piImage0 = iTypeImage;
1135       }
1136 }
1137
1138
1139 HLISTITEM Display_InsertItem (HWND hList, HLISTITEM hParent, LPTSTR pszText, LPARAM lp, int iImage0, int iImage1, ICONVIEW iv, DWORD dwPickImageFlags)
1140 {
1141    FASTLISTADDITEM flai;
1142    memset (&flai, 0x00, sizeof(flai));
1143    flai.hParent = hParent;
1144    flai.pszText = pszText;
1145    flai.lParam = lp;
1146    Display_PickImages (&flai.iFirstImage, &flai.iSecondImage, iImage0, iImage1, iv, dwPickImageFlags);
1147
1148    if (dwPickImageFlags & PIF_TREEVIEW_ONLY)
1149       flai.dwFlags |= FLIF_TREEVIEW_ONLY;
1150
1151    if (dwPickImageFlags & PIF_DISALLOW_COLLAPSE)
1152       flai.dwFlags |= FLIF_DISALLOW_COLLAPSE;
1153
1154    return FastList_AddItem (hList, &flai);
1155 }
1156