2 * Copyright 2000, International Business Machines Corporation and others.
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
11 #include <afs/param.h>
15 #include "TaAfsUsrMgr.h"
21 * DEFINITIONS ________________________________________________________________
25 #define ID_ACTION_TIMER 100
40 { IDS_ACTCOL_OPERATION, 100 }, // actcolOPERATIONS
41 { IDS_ACTCOL_ELAPSED, 100 }, // actcolELAPSED
44 #define nACTIONCOLUMNS (sizeof(ACTIONCOLUMNS)/sizeof(ACTIONCOLUMNS[0]))
46 #define cxMIN_ACTION 75
47 #define cyMIN_ACTION 50
51 * VARIABLES __________________________________________________________________
58 LPASACTIONLIST pActionList;
61 rwWindowData awdActions[] = {
62 { IDC_ACTION_DESC, raSizeX | raRepaint },
63 { IDC_ACTION_LIST, raSizeX | raSizeY, MAKELONG(cxMIN_ACTION,cyMIN_ACTION) },
69 * PROTOTYPES _________________________________________________________________
73 void TicksToElapsedTime (LPSYSTEMTIME pst, DWORD dwTicks);
74 LPTSTR GetActionDescription (LPASACTION pAction);
76 BOOL CALLBACK Actions_DlgProc (HWND hDlg, UINT msg, WPARAM wp, LPARAM lp);
77 void Actions_OnEndTask_GetActions (LPTASKPACKET ptp);
78 void Actions_Refresh (void);
82 * ROUTINES ___________________________________________________________________
86 void TicksToElapsedTime (LPSYSTEMTIME pst, DWORD dwTicks)
88 #define msecSECOND (1000L)
89 #define msecMINUTE (1000L * 60L)
90 #define msecHOUR (1000L * 60L * 60L)
91 #define msecDAY (1000L * 60L * 60L * 24L)
93 memset (pst, 0x00, sizeof(SYSTEMTIME));
95 pst->wDay = (int)( dwTicks / msecDAY );
97 pst->wHour = (int)( dwTicks / msecHOUR );
99 pst->wMinute = (int)( dwTicks / msecMINUTE );
100 dwTicks %= msecMINUTE;
101 pst->wSecond = (int)( dwTicks / msecSECOND );
102 dwTicks %= msecSECOND;
103 pst->wMilliseconds = (int)( dwTicks );
107 void FixActionTime (DWORD *pcsec)
109 DWORD dwTickNow = GetTickCount();
110 DWORD cTickActive = 1000L * (*pcsec);
111 (*pcsec) = dwTickNow - cTickActive;
115 void Actions_SetDefaultView (LPVIEWINFO lpvi)
117 lpvi->lvsView = FLS_VIEW_LIST;
118 lpvi->nColsAvail = nACTIONCOLUMNS;
120 for (size_t iCol = 0; iCol < nACTIONCOLUMNS; ++iCol)
122 lpvi->cxColumns[ iCol ] = ACTIONCOLUMNS[ iCol ].cxWidth;
123 lpvi->idsColumns[ iCol ] = ACTIONCOLUMNS[ iCol ].idsColumn;
126 lpvi->iSort = actcolELAPSED | COLUMN_SORTREV;
128 lpvi->nColsShown = 2;
129 lpvi->aColumns[0] = (int)actcolOPERATION;
130 lpvi->aColumns[1] = (int)actcolELAPSED;
134 void Actions_OpenWindow (void)
136 if (!IsWindow (l.hAction))
138 l.hAction = ModelessDialog (IDD_ACTIONS, NULL, (DLGPROC)Actions_DlgProc);
139 ShowWindow (l.hAction, SW_SHOW);
140 Actions_WindowToTop (TRUE);
145 void Actions_CloseWindow (void)
147 if (IsWindow (l.hAction))
149 DestroyWindow (l.hAction);
155 void Actions_WindowToTop (BOOL fTop)
157 if (IsWindow(l.hAction))
161 SetWindowPos (l.hAction, HWND_TOPMOST, 0, 0, 0, 0,
162 SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE);
166 SetWindowPos (l.hAction, g.hMain, 0, 0, 0, 0,
167 SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE);
173 BOOL CALLBACK Actions_DlgProc (HWND hDlg, UINT msg, WPARAM wp, LPARAM lp)
175 if (Display_HandleColumnNotify (hDlg, msg, wp, lp, &gr.viewAct))
178 if (msg == WM_INITDIALOG)
185 HWND hList = GetDlgItem (hDlg, IDC_ACTION_LIST);
186 FL_RestoreView (hList, &gr.viewAct);
188 if (gr.rActions.right == 0)
189 GetWindowRect (hDlg, &gr.rActions);
190 ResizeWindow (hDlg, awdActions, rwaMoveToHere, &gr.rActions);
192 SetTimer (hDlg, ID_ACTION_TIMER, 1000, NULL); // timer message every sec
194 StartTask (taskGET_ACTIONS, l.hAction);
195 gr.fShowActions = TRUE;
200 gr.fShowActions = FALSE;
203 KillTimer (hDlg, ID_ACTION_TIMER);
206 asc_ActionListFree (&l.pActionList);
210 if ((FastList_GetItemCount (GetDlgItem (hDlg, IDC_ACTION_LIST))) || (l.pActionList && l.pActionList->cEntries))
215 // if (lp==0), we're minimizing--don't call ResizeWindow().
219 ResizeWindow (hDlg, awdActions, rwaFixupGuts);
220 GetWindowRect (hDlg, &gr.rActions);
225 GetWindowRect (hDlg, &gr.rActions);
230 if ((ptp = (LPTASKPACKET)lp) != NULL)
232 if (ptp->idTask == taskGET_ACTIONS)
233 Actions_OnEndTask_GetActions (ptp);
234 FreeTaskPacket (ptp);
243 DestroyWindow (hDlg);
253 void Actions_OnNotify (WPARAM wp, LPARAM lp)
255 LPASACTION pAction = (LPASACTION)lp;
256 BOOL fFinished = (BOOL)wp;
260 // We've just been told something happened;
262 switch (pAction->Action)
265 // If we get a Finished Refreshing notification, it's a safe bet
266 // that the admin server has done a significant refresh to its
267 // cache; so, we'll use that as a trigger to repopulate the lists
268 // on the main dialog.
271 Display_PopulateList();
275 // If the Actions window is being displayed, use this notification
276 // to update our stored list-of-actions.
278 if (IsWindow (l.hAction))
281 FixActionTime (&pAction->csecActive);
284 asc_ActionListCreate (&l.pActionList);
289 asc_ActionListRemoveEntry (&l.pActionList, pAction->idAction);
290 else if (!asc_ActionListTest (&l.pActionList, pAction->idAction))
291 asc_ActionListAddEntry (&l.pActionList, pAction);
302 void Actions_OnEndTask_GetActions (LPTASKPACKET ptp)
306 asc_ActionListFree (&l.pActionList);
308 if (ptp->rc && TASKDATA(ptp)->pActionList)
310 l.pActionList = TASKDATA(ptp)->pActionList;
311 TASKDATA(ptp)->pActionList = NULL; // don't let FreeTaskPacket free this
313 // Zip through the listed actions and change the reported csec-elapsed
314 // into an estimated starting tick.
316 for (size_t ii = 0; ii < l.pActionList->cEntries; ++ii)
318 FixActionTime (&l.pActionList->aEntries[ ii ].Action.csecActive);
325 void Actions_Refresh (void)
328 TCHAR szText[ cchRESOURCE ];
331 if ((hList = GetDlgItem (l.hAction, IDC_ACTION_LIST)) != NULL)
333 LPARAM lpOld = FL_StartChange (hList, TRUE);
337 for (size_t ii = 0; ii < l.pActionList->cEntries; ++ii)
340 if ((pszDesc = GetActionDescription (&l.pActionList->aEntries[ ii ].Action)) != NULL)
343 TicksToElapsedTime (&st, GetTickCount() - l.pActionList->aEntries[ ii ].Action.csecActive);
344 FormatElapsed (szText, TEXT("%s"), &st);
346 FASTLISTADDITEM flai;
347 memset (&flai, 0x00, sizeof(flai));
349 flai.iFirstImage = IMAGE_NOIMAGE;
350 flai.iSecondImage = IMAGE_NOIMAGE;
351 flai.pszText = pszDesc;
352 flai.lParam = (LPARAM)ii;
353 flai.dwFlags = FLIF_DISALLOW_SELECT;
356 if ((hItem = FastList_AddItem (hList, &flai)) != NULL)
357 FastList_SetItemText (hList, hItem, 1, szText);
361 FreeString (pszDesc);
366 FL_EndChange (hList, lpOld);
370 GetString (szText, IDS_ACTION_DESC_NONE);
371 else if (nItems == 1)
372 GetString (szText, IDS_ACTION_DESC_ONE);
373 else // (nItems >= 2)
374 GetString (szText, IDS_ACTION_DESC_MULT);
375 SetDlgItemText (l.hAction, IDC_ACTION_DESC, szText);
379 LPTSTR GetActionDescription (LPASACTION pAction)
381 LPTSTR pszDesc = NULL;
384 ASOBJPROP Properties;
385 ASOBJPROP Properties2;
387 switch (pAction->Action)
390 if (asc_ObjectPropertiesGet_Fast (g.idClient, g.idCell, pAction->u.Refresh.idScope, &Properties, &status))
392 if (Properties.Type == TYPE_CELL)
393 pszDesc = FormatString (IDS_ACTION_REFRESH_CELL, TEXT("%s"), Properties.szName);
394 else if (Properties.Type == TYPE_SERVER)
395 pszDesc = FormatString (IDS_ACTION_REFRESH_SERVER, TEXT("%s"), Properties.szName);
400 if (asc_ObjectPropertiesGet_Fast (g.idClient, g.idCell, pAction->u.Refresh.idScope, &Properties, &status))
402 if (Properties.Type == TYPE_CELL)
403 pszDesc = FormatString (IDS_ACTION_SCOUT_CELL, TEXT("%s"), Properties.szName);
404 else if (Properties.Type == TYPE_SERVER)
405 pszDesc = FormatString (IDS_ACTION_SCOUT_SERVER, TEXT("%s"), Properties.szName);
409 case ACTION_USER_CHANGE:
410 if (asc_ObjectPropertiesGet_Fast (g.idClient, g.idCell, pAction->u.User_Change.idUser, &Properties, &status))
412 pszDesc = FormatString (IDS_ACTION_USER_CHANGE, TEXT("%s"), Properties.szName);
416 case ACTION_USER_PW_CHANGE:
417 if (asc_ObjectPropertiesGet_Fast (g.idClient, g.idCell, pAction->u.User_Pw_Change.idUser, &Properties, &status))
419 pszDesc = FormatString (IDS_ACTION_USER_PW_CHANGE, TEXT("%s"), Properties.szName);
423 case ACTION_USER_UNLOCK:
424 if (asc_ObjectPropertiesGet_Fast (g.idClient, g.idCell, pAction->u.User_Unlock.idUser, &Properties, &status))
426 pszDesc = FormatString (IDS_ACTION_USER_UNLOCK, TEXT("%s"), Properties.szName);
430 case ACTION_USER_CREATE:
431 pszDesc = FormatString (IDS_ACTION_USER_CREATE, TEXT("%s"), pAction->u.User_Create.szUser);
434 case ACTION_USER_DELETE:
435 if (asc_ObjectPropertiesGet_Fast (g.idClient, g.idCell, pAction->u.User_Delete.idUser, &Properties, &status))
437 pszDesc = FormatString (IDS_ACTION_USER_DELETE, TEXT("%s"), Properties.szName);
441 case ACTION_GROUP_CHANGE:
442 if (asc_ObjectPropertiesGet_Fast (g.idClient, g.idCell, pAction->u.Group_Change.idGroup, &Properties, &status))
444 pszDesc = FormatString (IDS_ACTION_GROUP_CHANGE, TEXT("%s"), Properties.szName);
448 case ACTION_GROUP_MEMBER_ADD:
449 if (asc_ObjectPropertiesGet_Fast (g.idClient, g.idCell, pAction->u.Group_Member_Add.idGroup, &Properties, &status))
451 if (asc_ObjectPropertiesGet_Fast (g.idClient, g.idCell, pAction->u.Group_Member_Add.idUser, &Properties2, &status))
453 pszDesc = FormatString (IDS_ACTION_GROUP_MEMBER_ADD, TEXT("%s%s"), Properties.szName, Properties2.szName);
458 case ACTION_GROUP_MEMBER_REMOVE:
459 if (asc_ObjectPropertiesGet_Fast (g.idClient, g.idCell, pAction->u.Group_Member_Remove.idGroup, &Properties, &status))
461 if (asc_ObjectPropertiesGet_Fast (g.idClient, g.idCell, pAction->u.Group_Member_Remove.idUser, &Properties2, &status))
463 pszDesc = FormatString (IDS_ACTION_GROUP_MEMBER_REMOVE, TEXT("%s%s"), Properties.szName, Properties2.szName);
468 case ACTION_GROUP_RENAME:
469 if (asc_ObjectPropertiesGet_Fast (g.idClient, g.idCell, pAction->u.Group_Rename.idGroup, &Properties, &status))
471 pszDesc = FormatString (IDS_ACTION_GROUP_RENAME, TEXT("%s%s"), Properties.szName, pAction->u.Group_Rename.szNewName);
475 case ACTION_GROUP_CREATE:
476 pszDesc = FormatString (IDS_ACTION_GROUP_CREATE, TEXT("%s"), pAction->u.Group_Create.szGroup);
479 case ACTION_GROUP_DELETE:
480 if (asc_ObjectPropertiesGet_Fast (g.idClient, g.idCell, pAction->u.Group_Delete.idGroup, &Properties, &status))
482 pszDesc = FormatString (IDS_ACTION_GROUP_DELETE, TEXT("%s"), Properties.szName);
486 case ACTION_CELL_CHANGE:
487 if (asc_ObjectPropertiesGet_Fast (g.idClient, g.idCell, g.idCell, &Properties, &status))
489 pszDesc = FormatString (IDS_ACTION_CELL_CHANGE, TEXT("%s"), Properties.szName);