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