Initial IBM OpenAFS 1.0 tree
[openafs.git] / src / WINNT / afssvrmgr / svr_general.cpp
1 extern "C" {
2 #include <afs/param.h>
3 #include <afs/stds.h>
4 }
5
6 #include "svrmgr.h"
7 #include "svr_general.h"
8 #include "propcache.h"
9 #include "display.h"
10
11
12 /*
13  * SERVER PREFERENCES _________________________________________________________
14  *
15  */
16
17 PVOID Server_LoadPreferences (LPIDENT lpiServer)
18 {
19    LPSERVER_PREF psp = New (SERVER_PREF);
20
21    if (!RestorePreferences (lpiServer, psp, sizeof(SERVER_PREF)))
22       {
23       Alert_SetDefaults (&psp->oa);
24
25       psp->perWarnAggFull = perDEFAULT_AGGFULL_WARNING;
26       psp->perWarnSetFull = perDEFAULT_SETFULL_WARNING;
27       psp->fWarnSvcStop = fDEFAULT_SVCSTOP_WARNING;
28       psp->fWarnSvrTimeout = TRUE;
29       psp->fWarnSetNoVLDB = TRUE;
30       psp->fWarnSetNoServ = TRUE;
31       psp->fWarnAggNoServ = TRUE;
32       psp->fWarnAggAlloc = FALSE;
33
34       psp->rLast.right = 0;
35       psp->fOpen = FALSE;
36       psp->fExpandTree = TRUE;
37       }
38
39    psp->fIsMonitored = TRUE; // until dispatch.cpp sets it otherwise
40
41    Alert_Initialize (&psp->oa);
42    return psp;
43 }
44
45
46 BOOL Server_SavePreferences (LPIDENT lpiServer)
47 {
48    BOOL rc = FALSE;
49
50    PVOID psp = lpiServer->GetUserParam();
51    if (psp != NULL)
52       {
53       rc = StorePreferences (lpiServer, psp, sizeof(SERVER_PREF));
54       }
55
56    return rc;
57 }
58
59
60 /*
61  * ROUTINES ___________________________________________________________________
62  *
63  */
64
65 void Server_ShowPopupMenu (HWND hList, POINT ptList, POINT ptScreen)
66 {
67    if (!ptScreen.x && !ptScreen.y)
68       {
69       RECT rWindow;
70       GetWindowRect (hList, &rWindow);
71       ptScreen.x = rWindow.left + (rWindow.right -rWindow.left)/2;
72       ptScreen.y = rWindow.top + (rWindow.bottom -rWindow.top)/2;
73       Server_ShowParticularPopupMenu (hList, ptScreen, NULL);
74       }
75    else if (FL_HitTestForHeaderBar (hList, ptList))
76       {
77       HMENU hm = TaLocale_LoadMenu (MENU_COLUMNS);
78       DisplayContextMenu (hm, ptScreen, hList);
79       }
80    else
81       {
82       LPIDENT lpiServer = NULL;
83
84       HLISTITEM hItem;
85       if ((hItem = FastList_ItemFromPoint (hList, &ptList, TRUE)) != NULL)
86          lpiServer = (LPIDENT)FL_GetData (hList, hItem);
87
88       if (lpiServer && (lpiServer != (LPIDENT)FL_GetSelectedData (hList)))
89          lpiServer = NULL;
90
91       Server_ShowParticularPopupMenu (hList, ptScreen, lpiServer);
92       }
93 }
94
95
96 void Server_ShowParticularPopupMenu (HWND hParent, POINT ptScreen, LPIDENT lpiServer)
97 {
98    HMENU hm;
99    
100    if (lpiServer == NULL)
101       hm = TaLocale_LoadMenu (MENU_SVR_NONE);
102    else
103       hm = TaLocale_LoadMenu (MENU_SVR);
104
105    if (hm != NULL)
106       {
107       if (lpiServer == NULL)
108          {
109          int lvs = (gr.fPreview && !gr.fVert) ? gr.diHorz.viewSvr.lvsView : gr.diVert.viewSvr.lvsView;
110          HMENU hmView = GetSubMenu (hm, 0);
111
112          CheckMenuRadioItem (hmView,
113                              M_SVR_VIEW_LARGE, M_SVR_VIEW_REPORT,
114                              ( (lvs == FLS_VIEW_SMALL) ? M_SVR_VIEW_SMALL :
115                                (lvs == FLS_VIEW_LIST)  ? M_SVR_VIEW_REPORT :
116                                                          M_SVR_VIEW_LARGE ),
117                              MF_BYCOMMAND);
118
119          ICONVIEW ivSvr = Display_GetServerIconView();
120
121          CheckMenuRadioItem (hmView,
122                              M_SVR_VIEW_ONEICON, M_SVR_VIEW_STATUS,
123                              (ivSvr == ivTWOICONS) ? M_SVR_VIEW_TWOICONS :
124                              (ivSvr == ivONEICON)  ? M_SVR_VIEW_ONEICON : M_SVR_VIEW_STATUS,
125                              MF_BYCOMMAND);
126
127          if (lvs != FLS_VIEW_LIST)
128             {
129             EnableMenu (hmView, M_SVR_VIEW_ONEICON,  FALSE);
130             EnableMenu (hmView, M_SVR_VIEW_TWOICONS, FALSE);
131             EnableMenu (hmView, M_SVR_VIEW_STATUS,   FALSE);
132             }
133
134          if (!PropCache_Search (pcSERVER, ANYVALUE))
135             EnableMenu (hmView, M_SVR_CLOSEALL, FALSE);
136          }
137       else
138          {
139          BOOL fOpenNow = (BOOL)!!(PropCache_Search (pcSERVER, lpiServer));
140
141          LPSERVER_PREF lpsp;
142          if ( ((lpsp = (LPSERVER_PREF)lpiServer->GetUserParam()) == NULL) ||
143               (lpsp->fIsMonitored) )
144             {
145             EnableMenu (hm, M_SVR_OPEN,  !fOpenNow);
146             EnableMenu (hm, M_SVR_CLOSE,  fOpenNow);
147             CheckMenu (hm, M_SVR_MONITOR, TRUE);
148             }
149          else
150             {
151             if (!fOpenNow)
152                EnableMenu (hm, M_SVR_CLOSE, FALSE);
153             if (fOpenNow || !gr.fOpenMonitors)
154                EnableMenu (hm, M_SVR_OPEN, FALSE);
155
156             CheckMenu (hm, M_SVR_MONITOR, FALSE);
157
158             EnableMenu (hm, M_SVR_SECURITY,  FALSE);
159             EnableMenu (hm, M_SALVAGE,  FALSE);
160             EnableMenu (hm, M_SET_CLONE,  FALSE);
161             EnableMenu (hm, M_SET_UNLOCK, FALSE);
162             EnableMenu (hm, M_SYNCVLDB,   FALSE);
163             }
164          }
165
166       DisplayContextMenu (hm, ptScreen, hParent);
167       }
168 }
169