Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

517 lines
12 KiB

  1. /**********************************************************************/
  2. /** Microsoft Windows NT **/
  3. /** Copyright(c) Microsoft Corp., 1991 **/
  4. /**********************************************************************/
  5. /*
  6. curusers.cxx
  7. Contain the dialog for enumerating current users to a volume
  8. FILE HISTORY:
  9. NarenG 11/13/92 Modified for AFPMGR
  10. */
  11. #define INCL_WINDOWS_GDI
  12. #define INCL_WINDOWS
  13. #define INCL_DOSERRORS
  14. #define INCL_NETERRORS
  15. #define INCL_NETSHARE
  16. #define INCL_NETSERVER
  17. #define INCL_NETCONS
  18. #define INCL_NETLIB
  19. #include <lmui.hxx>
  20. #define INCL_BLT_WINDOW
  21. #define INCL_BLT_DIALOG
  22. #define INCL_BLT_CONTROL
  23. #define INCL_BLT_MISC
  24. #define INCL_BLT_CLIENT
  25. #define INCL_BLT_MSGPOPUP
  26. #include <blt.hxx>
  27. extern "C"
  28. {
  29. #include <afpmgr.h>
  30. #include <macfile.h>
  31. }
  32. #include <string.hxx>
  33. #include <uitrace.hxx>
  34. #include <ellipsis.hxx>
  35. #include <strnumer.hxx>
  36. #include <ctime.hxx>
  37. #include <intlprof.hxx>
  38. #include "curusers.hxx"
  39. /*******************************************************************
  40. NAME: CURRENT_USERS_WARNING_DIALOG::CURRENT_USERS_WARNING_DIALOG
  41. SYNOPSIS: Constructor
  42. ENTRY: hwndParent - hwnd of Parent Window
  43. pAfpConnections - pointer to a list of current users.
  44. nConnections - number of current users
  45. pszServerName - Server Name
  46. pszvolumeName - volume Name
  47. ulHelpContextBase - the base help context
  48. EXIT:
  49. RETURNS:
  50. NOTES:
  51. HISTORY:
  52. NarenG 11/13/92 Modified for AFPMGR
  53. ********************************************************************/
  54. CURRENT_USERS_WARNING_DIALOG::CURRENT_USERS_WARNING_DIALOG(
  55. HWND hwndParent,
  56. AFP_SERVER_HANDLE hServer,
  57. PAFP_CONNECTION_INFO pAfpConnections,
  58. DWORD nConnections,
  59. const TCHAR *pszVolumeName )
  60. : DIALOG_WINDOW( IDD_CURRENT_USERS_WARNING_DLG, hwndParent ),
  61. _sltVolumeText( this, IDCU_SLT_VOL_TEXT ),
  62. _lbUsers( this, IDCU_LB_CURRENT_USERS ),
  63. _hServer( hServer )
  64. {
  65. //
  66. // Make sure everything constructed OK
  67. //
  68. if ( QueryError() != NERR_Success )
  69. return;
  70. APIERR err;
  71. ALIAS_STR nlsVolume( pszVolumeName );
  72. RESOURCE_STR nlsVolumeText( IDS_VOLUME_CURRENT_USERS_TEXT );
  73. if (( err = nlsVolumeText.InsertParams( nlsVolume )) != NERR_Success )
  74. {
  75. ReportError( err );
  76. return;
  77. }
  78. _sltVolumeText.SetText( nlsVolumeText );
  79. err = BASE_ELLIPSIS::Init();
  80. if( err != NO_ERROR )
  81. {
  82. ReportError( err );
  83. return;
  84. }
  85. if ( ( err = _lbUsers.Fill( pAfpConnections,
  86. nConnections) ) != NERR_Success )
  87. {
  88. ReportError( err );
  89. return;
  90. }
  91. }
  92. /*******************************************************************
  93. NAME: CURRENT_USERS_WARNING_DIALOG :: ~CURRENT_USERS_WARNING_DIALOG
  94. SYNOPSIS: CURRENT_USERS_WARNING_DIALOG class destructor.
  95. EXIT: The object is destroyed.
  96. HISTORY:
  97. NarenG 02-Oct-1993 Stole from Server Manager and folded
  98. BASE_RES_DIALOG and FILES_DIALOG into one.
  99. ********************************************************************/
  100. CURRENT_USERS_WARNING_DIALOG :: ~CURRENT_USERS_WARNING_DIALOG()
  101. {
  102. BASE_ELLIPSIS::Term();
  103. } // CURRENT_USERS_WARNING_DIALOG :: ~CURRENT_USERS_WARNING_DIALOG
  104. /*******************************************************************
  105. NAME: CURRENT_USERS_WARNING_DIALOG::QueryHelpContext
  106. SYNOPSIS: Get the help context of the dialog
  107. ENTRY:
  108. EXIT:
  109. RETURNS: Returns the help context
  110. NOTES:
  111. HISTORY:
  112. NarenG 11/13/92 Modified for AFPMGR
  113. ********************************************************************/
  114. ULONG CURRENT_USERS_WARNING_DIALOG::QueryHelpContext( VOID )
  115. {
  116. return HC_CURRENT_USERS_WARNING_DIALOG;
  117. }
  118. /*******************************************************************
  119. NAME: CURRENT_USERS_WARNING_DIALOG :: OnCommand
  120. SYNOPSIS: This method is called whenever a WM_COMMAND message
  121. is sent to the dialog procedure.
  122. ENTRY: cid - The control ID from the
  123. generating control.
  124. EXIT: The command has been handled.
  125. RETURNS: BOOL - TRUE if we handled the command.
  126. FALSE if we did not handle
  127. the command.
  128. HISTORY:
  129. NarenG 12/15/92 Created
  130. ********************************************************************/
  131. BOOL CURRENT_USERS_WARNING_DIALOG :: OnCommand( const CONTROL_EVENT & event )
  132. {
  133. DWORD err;
  134. if( event.QueryCid() == IDYES )
  135. {
  136. AUTO_CURSOR;
  137. INT nCount = _lbUsers.QueryCount();
  138. for ( INT Index = 0; Index < nCount; Index++ )
  139. {
  140. CURRENT_USERS_LBI * pculbi = _lbUsers.QueryItem( Index );
  141. //
  142. // Blow away this connection
  143. //
  144. err = :: AfpAdminConnectionClose( _hServer, pculbi->QueryId() );
  145. if ( ( err != NO_ERROR ) && ( err != AFPERR_InvalidId ) )
  146. {
  147. break;
  148. }
  149. }
  150. if ( ( err != NO_ERROR ) && ( err != AFPERR_InvalidId ) )
  151. {
  152. ::MsgPopup( this, AFPERR_TO_STRINGID( err ) );
  153. Dismiss( FALSE );
  154. return FALSE;
  155. }
  156. Dismiss( TRUE );
  157. return TRUE;
  158. }
  159. if( event.QueryCid() == IDNO )
  160. {
  161. Dismiss( FALSE );
  162. return FALSE;
  163. }
  164. return DIALOG_WINDOW::OnCommand( event );
  165. }
  166. /*******************************************************************
  167. NAME: CURRENT_USERS_LISTBOX::CURRENT_USERS_LISTBOX
  168. SYNOPSIS: Constructor - list box used in CURRENT_USERS_WARNING_DIALOG
  169. ENTRY: powin - owner window
  170. cid - resource id of the listbox
  171. EXIT:
  172. RETURNS:
  173. NOTES: This is a read-only listbox.
  174. HISTORY:
  175. NarenG 11/13/92 Modified for AFPMGR
  176. ********************************************************************/
  177. CURRENT_USERS_LISTBOX::CURRENT_USERS_LISTBOX( OWNER_WINDOW *powin,
  178. CID cid )
  179. : BLT_LISTBOX( powin, cid, TRUE )
  180. {
  181. //
  182. // Make sure everything constructed OK
  183. //
  184. if ( QueryError() != NERR_Success )
  185. return;
  186. APIERR err = DISPLAY_TABLE::CalcColumnWidths( _adx,
  187. COLS_CU_LB_USERS,
  188. powin,
  189. cid,
  190. FALSE);
  191. if ( err != NERR_Success )
  192. {
  193. ReportError( err );
  194. return;
  195. }
  196. }
  197. /*******************************************************************
  198. NAME: CURRENT_USERS_LISTBOX::Fill
  199. SYNOPSIS: Fills the listbox with the current users.
  200. ENTRY: pAfpConnections - Pointer to connections info
  201. nConnections - Number of connections.
  202. EXIT:
  203. RETURNS:
  204. NOTES: This is a read-only listbox.
  205. HISTORY:
  206. NarenG 11/13/92 Modified for AFPMGR
  207. ********************************************************************/
  208. APIERR CURRENT_USERS_LISTBOX::Fill( PAFP_CONNECTION_INFO pAfpConnections,
  209. DWORD nConnections )
  210. {
  211. APIERR err = NERR_Success;
  212. //
  213. // Gather all connections to the volume that the user wants to delete.
  214. //
  215. SetRedraw( FALSE );
  216. while ( ( err == NERR_Success ) && ( nConnections-- ) )
  217. {
  218. CURRENT_USERS_LBI *pCurUserslbi = new CURRENT_USERS_LBI(
  219. pAfpConnections->afpconn_username,
  220. pAfpConnections->afpconn_num_opens,
  221. pAfpConnections->afpconn_time,
  222. pAfpConnections->afpconn_id );
  223. if ( AddItem( pCurUserslbi ) < 0 )
  224. {
  225. err = ERROR_NOT_ENOUGH_MEMORY;
  226. }
  227. pAfpConnections++;
  228. }
  229. Invalidate( TRUE );
  230. SetRedraw( TRUE );
  231. return err;
  232. }
  233. /*******************************************************************
  234. NAME: CURRENT_USERS_LBI::CURRENT_USERS_LBI
  235. SYNOPSIS: List box items used in CURRENT_USERS_WARNING_DIALOG
  236. ENTRY: pszUserName - Pointer to the current username
  237. dwNumOpens - Number of files opened by this users.
  238. dwTime - Time since connected.
  239. EXIT:
  240. RETURNS:
  241. NOTES:
  242. HISTORY:
  243. NarenG 11/13/92 Modified for AFPMGR
  244. ********************************************************************/
  245. CURRENT_USERS_LBI::CURRENT_USERS_LBI( const TCHAR * pszUserName,
  246. DWORD dwNumOpens,
  247. DWORD dwTime,
  248. DWORD dwId )
  249. : _nlsUserName(),
  250. _dwNumOpens( dwNumOpens ),
  251. _ulTime( dwTime ),
  252. _dwId( dwId )
  253. {
  254. //
  255. // Make sure everything constructed OK
  256. //
  257. if ( QueryError() != NERR_Success )
  258. return;
  259. APIERR err = _nlsUserName.QueryError();
  260. if ( err != NERR_Success )
  261. {
  262. ReportError( err );
  263. return;
  264. }
  265. //
  266. // Fill in Guest for username if it is null
  267. //
  268. if ( pszUserName == NULL )
  269. {
  270. err = _nlsUserName.Load( IDS_GUEST );
  271. }
  272. else
  273. {
  274. err = _nlsUserName.CopyFrom( pszUserName );
  275. }
  276. }
  277. /*******************************************************************
  278. NAME: CURRENT_USERS_LBI::Paint
  279. SYNOPSIS: Redefine Paint() method of LBI class
  280. ENTRY:
  281. EXIT:
  282. RETURNS:
  283. NOTES:
  284. HISTORY:
  285. NarenG 11/13/92 Modified for AFPMGR
  286. ********************************************************************/
  287. VOID CURRENT_USERS_LBI::Paint( LISTBOX *plb,
  288. HDC hdc,
  289. const RECT *prect,
  290. GUILTT_INFO *pGUILTT ) const
  291. {
  292. APIERR err;
  293. DEC_STR nlsNumOpens( _dwNumOpens );
  294. NLS_STR nlsTime;
  295. if ( ((err = nlsNumOpens.QueryError()) != NERR_Success )
  296. || ((err = nlsTime.QueryError()) != NERR_Success )
  297. || ((err = ConvertTime( _ulTime, &nlsTime )) != NERR_Success )
  298. )
  299. {
  300. ::MsgPopup( plb->QueryOwnerHwnd(), err);
  301. return;
  302. }
  303. STR_DTE_ELLIPSIS strdteUserName( _nlsUserName.QueryPch(),
  304. plb, ELLIPSIS_RIGHT );
  305. STR_DTE strdteNumOpens( nlsNumOpens.QueryPch() );
  306. STR_DTE strdteTime( nlsTime.QueryPch() );
  307. DISPLAY_TABLE dt( COLS_CU_LB_USERS,
  308. ((CURRENT_USERS_LISTBOX *) plb)->QueryColumnWidths() );
  309. dt[0] = &strdteUserName;
  310. dt[1] = &strdteNumOpens;
  311. dt[2] = &strdteTime;
  312. dt.Paint( plb, hdc, prect, pGUILTT );
  313. }
  314. /*******************************************************************
  315. NAME: CURRENT_USERS_LBI::ConvertTime
  316. SYNOPSIS: Convert the time given from ULONG (seconds) to a string
  317. to be shown. It complies with the internationalization
  318. of time using INTL_PROFILE.
  319. ENTRY:
  320. EXIT:
  321. RETURNS:
  322. NOTES:
  323. HISTORY:
  324. NarenG 11/13/92 Modified for AFPMGR
  325. ********************************************************************/
  326. #define SECONDS_PER_DAY 86400
  327. #define SECONDS_PER_HOUR 3600
  328. #define SECONDS_PER_MINUTE 60
  329. APIERR CURRENT_USERS_LBI::ConvertTime( ULONG ulTime, NLS_STR *pnlsTime) const
  330. {
  331. INTL_PROFILE intlProf;
  332. INT nDay = (INT) ulTime / SECONDS_PER_DAY;
  333. ulTime %= SECONDS_PER_DAY;
  334. INT nHour = (INT) ulTime / SECONDS_PER_HOUR;
  335. ulTime %= SECONDS_PER_HOUR;
  336. INT nMinute = (INT) ulTime / SECONDS_PER_MINUTE;
  337. INT nSecond = (INT) ulTime % SECONDS_PER_MINUTE;
  338. return intlProf.QueryDurationStr( nDay, nHour, nMinute,
  339. nSecond, pnlsTime);
  340. }
  341. /*******************************************************************
  342. NAME: CURRENT_USERS_LBI::Compare
  343. SYNOPSIS: Redefine Compare() method of LBI class
  344. ENTRY:
  345. EXIT:
  346. RETURNS:
  347. NOTES:
  348. HISTORY:
  349. NarenG 11/13/92 Modified for AFPMGR
  350. ********************************************************************/
  351. INT CURRENT_USERS_LBI::Compare( const LBI *plbi ) const
  352. {
  353. return( _nlsUserName._stricmp(
  354. ((const CURRENT_USERS_LBI *) plbi)->_nlsUserName ));
  355. }