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