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