UserAccountsDlg.cpp 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824
  1. /****************************************************************/
  2. /* */
  3. /* UserAccountsDlg.cpp */
  4. /* */
  5. /* Implementation of the CUserAccountsDlg class. */
  6. /* */
  7. /* Programmed by LYFZ van der Meer */
  8. /* Copyright LYFZ Software Solutions 2002 */
  9. /* http://www.LYFZvandermeer.nl */
  10. /* */
  11. /* Last updated: 10 july 2002 */
  12. /* */
  13. /****************************************************************/
  14. #include "stdafx.h"
  15. #include "DBServer.h"
  16. #include "UserAccountsDlg.h"
  17. #include "AddUserDlg.h"
  18. #include "DirectoryDlg.h"
  19. #include "WizardPages.h"
  20. #ifdef _DEBUG
  21. #define new DEBUG_NEW
  22. #undef THIS_FILE
  23. static char THIS_FILE[] = __FILE__;
  24. #endif
  25. extern CDBServer theApp;
  26. CUserAccountsDlg::CUserAccountsDlg(CWnd* pParent /*=NULL*/)
  27. : CDialogResize(CUserAccountsDlg::IDD, pParent)
  28. {
  29. //{{AFX_DATA_INIT(CUserAccountsDlg) IDC_USERS
  30. m_strPassword = _T("");
  31. m_bDisableAccount = FALSE;
  32. //}}AFX_DATA_INIT
  33. m_nPreviousIndex = LB_ERR;
  34. m_hIcon = AfxGetApp()->LoadIcon(IDI_DBServer);
  35. }
  36. CUserAccountsDlg::~CUserAccountsDlg()
  37. {
  38. }
  39. void CUserAccountsDlg::DoDataExchange(CDataExchange* pDX)
  40. {
  41. CDialogResize::DoDataExchange(pDX);
  42. //{{AFX_DATA_MAP(CUserAccountsDlg)
  43. DDX_Control(pDX, IDC_USERS, m_UsersList);
  44. DDX_Control(pDX, IDC_DIR_LIST, m_DirectoryList);
  45. DDX_Text(pDX, IDC_PASSWORD, m_strPassword);
  46. DDX_Check(pDX, IDC_DISABLE_ACCOUNT, m_bDisableAccount);
  47. //}}AFX_DATA_MAP
  48. }
  49. BEGIN_MESSAGE_MAP(CUserAccountsDlg, CDialogResize)
  50. //{{AFX_MSG_MAP(CUserAccountsDlg)
  51. ON_LBN_SELCHANGE(IDC_USER_LIST, OnSelchangeUserlist)
  52. ON_NOTIFY(NM_DBLCLK, IDC_DIR_LIST, OnDblclkDirlist)
  53. ON_BN_CLICKED(IDC_ADD_DIR, OnAddDir)
  54. ON_BN_CLICKED(IDC_EDIT_DIR, OnEditDir)
  55. ON_BN_CLICKED(IDC_DEL_DIR, OnDelDir)
  56. ON_BN_CLICKED(IDC_SET_HOME, OnSetHome)
  57. ON_BN_CLICKED(IDC_ADD_USER, OnAddUser)
  58. ON_BN_CLICKED(IDC_EDIT_USER, OnEditUser)
  59. ON_BN_CLICKED(IDC_DEL_USER, OnDelUser)
  60. ON_UPDATE_COMMAND_UI(IDC_EDIT_USER, OnUpdateControls)
  61. ON_UPDATE_COMMAND_UI(IDC_DISABLE_ACCOUNT, OnUpdateDisableAccount)
  62. ON_NOTIFY(NM_CLICK, IDC_USERS, OnClickUsers)
  63. ON_NOTIFY(LVN_KEYDOWN, IDC_USERS, OnKeydownUsers)
  64. ON_BN_CLICKED(IDC_DISABLE_ACCOUNT, OnDisableAccount)
  65. ON_UPDATE_COMMAND_UI(IDC_DEL_USER, OnUpdateControls)
  66. ON_UPDATE_COMMAND_UI(IDC_PASSWORD, OnUpdateControls)
  67. ON_UPDATE_COMMAND_UI(IDC_DIR_LIST, OnUpdateControls)
  68. ON_UPDATE_COMMAND_UI(IDC_ADD_DIR, OnUpdateControls)
  69. ON_UPDATE_COMMAND_UI(IDC_EDIT_DIR, OnUpdateControls)
  70. ON_UPDATE_COMMAND_UI(IDC_DEL_DIR, OnUpdateControls)
  71. ON_UPDATE_COMMAND_UI(IDC_SET_HOME, OnUpdateControls)
  72. ON_BN_CLICKED(IDC_WIZARD, OnWizard)
  73. //}}AFX_MSG_MAP
  74. END_MESSAGE_MAP()
  75. BEGIN_DLGRESIZE_MAP(CUserAccountsDlg)
  76. DLGRESIZE_CONTROL(IDC_ADD_DIR, DLSZ_MOVE_Y)
  77. DLGRESIZE_CONTROL(IDC_EDIT_DIR, DLSZ_MOVE_Y)
  78. DLGRESIZE_CONTROL(IDC_DEL_DIR, DLSZ_MOVE_X | DLSZ_MOVE_Y)
  79. DLGRESIZE_CONTROL(IDC_SET_HOME, DLSZ_MOVE_X | DLSZ_MOVE_Y)
  80. DLGRESIZE_CONTROL(IDCANCEL, DLSZ_MOVE_X | DLSZ_MOVE_Y)
  81. DLGRESIZE_CONTROL(IDOK, DLSZ_MOVE_X | DLSZ_MOVE_Y)
  82. DLGRESIZE_CONTROL(IDC_DIR_LIST, DLSZ_SIZE_X | DLSZ_SIZE_Y)
  83. DLGRESIZE_CONTROL(IDC_STATIC3, DLSZ_SIZE_X | DLSZ_SIZE_Y)
  84. DLGRESIZE_CONTROL(IDC_STATIC1, DLSZ_SIZE_Y)
  85. DLGRESIZE_CONTROL(IDC_STATIC2, DLSZ_SIZE_X)
  86. DLGRESIZE_CONTROL(IDC_USERS, DLSZ_SIZE_Y)
  87. DLGRESIZE_CONTROL(IDC_ADD_USER, DLSZ_MOVE_Y)
  88. DLGRESIZE_CONTROL(IDC_EDIT_USER, DLSZ_MOVE_Y)
  89. DLGRESIZE_CONTROL(IDC_DEL_USER, DLSZ_MOVE_Y)
  90. DLGRESIZE_CONTROL(IDC_WIZARD, DLSZ_MOVE_Y)
  91. END_DLGRESIZE_MAP()
  92. /********************************************************************/
  93. /* */
  94. /* Function name : OnInitDialog */
  95. /* Description : Initialize dialog */
  96. /* */
  97. /********************************************************************/
  98. BOOL CUserAccountsDlg::OnInitDialog()
  99. {
  100. CDialogResize::OnInitDialog();
  101. InitResizing();
  102. // Set the icon for this dialog.
  103. SetIcon(m_hIcon, TRUE); // Set big icon
  104. SetIcon(m_hIcon, FALSE); // Set small icon
  105. CRect rc;
  106. m_UsersList.GetClientRect(rc);
  107. m_UsersList.InsertColumn(0, "用户", LVCFMT_LEFT, rc.Width()-5);
  108. // fill user list
  109. for (int i=0; i < m_UserArray.GetSize(); i++)
  110. {
  111. int nIndex = m_UsersList.InsertItem(0, m_UserArray[i].m_strName, 2);
  112. m_UsersList.SetItemData(nIndex, i);
  113. }
  114. // setup directory list
  115. m_DirectoryList.InsertColumn(0, "实际目录", LVCFMT_LEFT, 100);
  116. m_DirectoryList.InsertColumn(1, "虚拟目录", LVCFMT_LEFT, 100);
  117. m_DirectoryList.InsertColumn(2, "下载", LVCFMT_LEFT, 10);
  118. m_DirectoryList.InsertColumn(3, "上传", LVCFMT_LEFT, 10);
  119. m_DirectoryList.InsertColumn(4, "改名", LVCFMT_LEFT, 10);
  120. m_DirectoryList.InsertColumn(5, "删除", LVCFMT_LEFT, 10);
  121. m_DirectoryList.InsertColumn(6, "建目录", LVCFMT_LEFT, 10);
  122. // create and attach imagelist
  123. m_ImageList.Create(16, 16, ILC_MASK, 3, 3);
  124. HICON hIcon = AfxGetApp()->LoadIcon(IDI_NONE);
  125. m_ImageList.Add(hIcon);
  126. DestroyIcon(hIcon);
  127. hIcon = AfxGetApp()->LoadIcon(IDI_HOME);
  128. m_ImageList.Add(hIcon);
  129. DestroyIcon(hIcon);
  130. hIcon = AfxGetApp()->LoadIcon(IDI_USER);
  131. m_ImageList.Add(hIcon);
  132. DestroyIcon(hIcon);
  133. m_DirectoryList.SetImageList(&m_ImageList, LVSIL_SMALL);
  134. m_UsersList.SetImageList(&m_ImageList, LVSIL_SMALL);
  135. // select preferred user ?
  136. if (!m_strUserName.IsEmpty())
  137. {
  138. LVFINDINFO info;
  139. info.flags = LVFI_STRING;
  140. info.psz = (LPCTSTR)m_strUserName;
  141. int nIndex = m_UsersList.FindItem(&info);
  142. m_UsersList.SetItemState(nIndex ,LVIS_SELECTED | LVIS_FOCUSED , LVIS_SELECTED | LVIS_FOCUSED);
  143. }
  144. else
  145. {
  146. m_UsersList.SetItemState(0 ,LVIS_SELECTED | LVIS_FOCUSED , LVIS_SELECTED | LVIS_FOCUSED);
  147. }
  148. GetDlgItem(IDC_PASSWORD)->ModifyStyle(NULL, ES_PASSWORD);
  149. ((CEdit *)GetDlgItem(IDC_PASSWORD))->SetPasswordChar('*');
  150. OnSelchangeUserlist();
  151. UpdateDialogControls(this, FALSE);
  152. AutoSizeColumns();
  153. return TRUE;
  154. }
  155. /********************************************************************/
  156. /* */
  157. /* Function name : OnClickUsers */
  158. /* Description : Selection in the user listcontrol has changed. */
  159. /* */
  160. /********************************************************************/
  161. void CUserAccountsDlg::OnClickUsers(NMHDR* pNMHDR, LRESULT* pResult)
  162. {
  163. OnSelchangeUserlist();
  164. *pResult = 0;
  165. }
  166. /********************************************************************/
  167. /* */
  168. /* Function name : OnKeydownUsers */
  169. /* Description : Selection in the user listcontrol has changed. */
  170. /* */
  171. /********************************************************************/
  172. void CUserAccountsDlg::OnKeydownUsers(NMHDR* pNMHDR, LRESULT* pResult)
  173. {
  174. LV_KEYDOWN* pLVKeyDow = (LV_KEYDOWN*)pNMHDR;
  175. // get index of selected item
  176. int nIndex = m_UsersList.GetNextItem(-1, LVNI_ALL | LVNI_SELECTED);
  177. if(nIndex == -1)
  178. return;
  179. if (pLVKeyDow->wVKey == VK_DOWN)
  180. {
  181. if (m_UsersList.GetItemCount()-1 > nIndex)
  182. {
  183. m_UsersList.SetItemState(nIndex + 1, LVIS_SELECTED | LVIS_FOCUSED , LVIS_SELECTED | LVIS_FOCUSED);
  184. }
  185. }
  186. else
  187. if (pLVKeyDow->wVKey == VK_UP)
  188. {
  189. if (nIndex > 0)
  190. {
  191. m_UsersList.SetItemState(nIndex - 1, LVIS_SELECTED | LVIS_FOCUSED , LVIS_SELECTED | LVIS_FOCUSED);
  192. }
  193. }
  194. else
  195. if (pLVKeyDow->wVKey == VK_NEXT)
  196. {
  197. m_UsersList.SetItemState(m_UsersList.GetItemCount()-1, LVIS_SELECTED | LVIS_FOCUSED , LVIS_SELECTED | LVIS_FOCUSED);
  198. }
  199. else
  200. if (pLVKeyDow->wVKey == VK_PRIOR)
  201. {
  202. m_UsersList.SetItemState(0, LVIS_SELECTED | LVIS_FOCUSED , LVIS_SELECTED | LVIS_FOCUSED);
  203. }
  204. OnSelchangeUserlist();
  205. *pResult = 1;
  206. }
  207. /********************************************************************/
  208. /* */
  209. /* Function name : OnSelchangeUserlist */
  210. /* Description : Selection in the user listcontrol has changed. */
  211. /* */
  212. /********************************************************************/
  213. void CUserAccountsDlg::OnSelchangeUserlist()
  214. {
  215. UpdateData();
  216. // save data of previous selected user
  217. if (m_nPreviousIndex != -1)
  218. {
  219. int nOldindex = m_UsersList.GetItemData(m_nPreviousIndex);
  220. m_UserArray[nOldindex].m_strPassword = m_strPassword;
  221. m_UserArray[nOldindex].m_bAccountDisabled = m_bDisableAccount;
  222. }
  223. // get selected user
  224. int nSelIndex = m_UsersList.GetNextItem(-1, LVNI_ALL | LVNI_SELECTED);
  225. if (nSelIndex != -1)
  226. {
  227. int nUserIndex = m_UsersList.GetItemData(nSelIndex);
  228. // update dialog variables
  229. m_strPassword = m_UserArray[nUserIndex].m_strPassword;
  230. m_bDisableAccount = m_UserArray[nUserIndex].m_bAccountDisabled;
  231. m_DirectoryList.DeleteAllItems();
  232. // fill the directory list
  233. for (int i=0; i < m_UserArray[nUserIndex].m_DirectoryArray.GetSize(); i++)
  234. {
  235. int nItem = m_DirectoryList.InsertItem(i, m_UserArray[nUserIndex].m_DirectoryArray[i].m_strDir);
  236. m_DirectoryList.SetItemText(nItem, 1, m_UserArray[nUserIndex].m_DirectoryArray[i].m_strAlias);
  237. m_DirectoryList.SetItemText(nItem, 2, m_UserArray[nUserIndex].m_DirectoryArray[i].m_bAllowDownload ? "Y" : "N");
  238. m_DirectoryList.SetItemText(nItem, 3, m_UserArray[nUserIndex].m_DirectoryArray[i].m_bAllowUpload ? "Y" : "N");
  239. m_DirectoryList.SetItemText(nItem, 4, m_UserArray[nUserIndex].m_DirectoryArray[i].m_bAllowRename ? "Y" : "N");
  240. m_DirectoryList.SetItemText(nItem, 5, m_UserArray[nUserIndex].m_DirectoryArray[i].m_bAllowDelete ? "Y" : "N");
  241. m_DirectoryList.SetItemText(nItem, 6, m_UserArray[nUserIndex].m_DirectoryArray[i].m_bAllowCreateDirectory ? "Y" : "N");
  242. LVITEM lvi;
  243. ZeroMemory(&lvi, sizeof (LV_ITEM));
  244. lvi.mask = LVIF_IMAGE|LVIF_PARAM;
  245. lvi.iItem = nItem;
  246. m_DirectoryList.GetItem(&lvi);
  247. lvi.lParam = i;
  248. lvi.iImage = m_UserArray[nUserIndex].m_DirectoryArray[i].m_bIsHomeDir ? 1 : 0;
  249. m_DirectoryList.SetItem(&lvi);
  250. }
  251. m_nPreviousIndex = nSelIndex;
  252. }
  253. else
  254. {
  255. // nothing selected...
  256. m_DirectoryList.DeleteAllItems();
  257. m_strPassword = "";
  258. m_bDisableAccount = FALSE;
  259. m_nPreviousIndex=-1;
  260. }
  261. UpdateData(FALSE);
  262. UpdateDialogControls(this, FALSE);
  263. AutoSizeColumns();
  264. }
  265. /********************************************************************/
  266. /* */
  267. /* Function name : OnOK */
  268. /* Description : Called when the user clicks the OK button. */
  269. /* */
  270. /********************************************************************/
  271. void CUserAccountsDlg::OnOK()
  272. {
  273. m_UsersList.SetItemState(-1 ,LVIS_SELECTED | LVIS_FOCUSED , LVIS_SELECTED | LVIS_FOCUSED);
  274. // force update
  275. OnSelchangeUserlist();
  276. CDialogResize::OnOK();
  277. }
  278. /********************************************************************/
  279. /* */
  280. /* Function name : OnDblclkDirlist */
  281. /* Description : Double clicked a directy item. */
  282. /* */
  283. /********************************************************************/
  284. void CUserAccountsDlg::OnDblclkDirlist(NMHDR* pNMHDR, LRESULT* pResult)
  285. {
  286. OnEditDir();
  287. *pResult = 0;
  288. }
  289. /********************************************************************/
  290. /* */
  291. /* Function name : OnAddUser */
  292. /* Description : Add a new user account. */
  293. /* */
  294. /********************************************************************/
  295. void CUserAccountsDlg::OnAddUser()
  296. {
  297. CAddUserDlg dlg;
  298. if (dlg.DoModal() == IDOK)
  299. {
  300. for (int i=0; i<m_UsersList.GetItemCount(); i++)
  301. {
  302. CString strName;
  303. strName = m_UsersList.GetItemText(i, 0);
  304. if (strName.CompareNoCase(dlg.m_strName) == 0)
  305. {
  306. AfxMessageBox("此用户已存在!");
  307. return;
  308. }
  309. }
  310. CUser user;
  311. user.m_strName = dlg.m_strName;
  312. user.m_strPassword = "";
  313. int nItem = m_UsersList.InsertItem(0, user.m_strName, 2);
  314. if (nItem <= m_nPreviousIndex)
  315. m_nPreviousIndex++;
  316. int index = m_UserArray.Add(user);
  317. m_UsersList.SetItemData(nItem, index);
  318. m_UsersList.SetItemState(nItem, LVIS_SELECTED | LVIS_FOCUSED , LVIS_SELECTED | LVIS_FOCUSED);
  319. OnSelchangeUserlist();
  320. }
  321. }
  322. /********************************************************************/
  323. /* */
  324. /* Function name : OnEditUser */
  325. /* Description : Edit user account name. */
  326. /* */
  327. /********************************************************************/
  328. void CUserAccountsDlg::OnEditUser()
  329. {
  330. // get selected user
  331. int nSelIndex = m_UsersList.GetNextItem(-1, LVNI_ALL | LVNI_SELECTED);
  332. if(nSelIndex == -1)
  333. return;
  334. int nUserIndex = m_UsersList.GetItemData(nSelIndex);
  335. CAddUserDlg dlg;
  336. dlg.m_strTitle = "Edit User";
  337. dlg.m_strName = m_UserArray[nUserIndex].m_strName;
  338. if (dlg.DoModal() == IDOK)
  339. {
  340. // check if user already exists
  341. for (int i=0; i<m_UsersList.GetItemCount(); i++)
  342. {
  343. if (i != nSelIndex)
  344. {
  345. CString strName;
  346. strName = m_UsersList.GetItemText(i, 0);
  347. if (strName.CompareNoCase(dlg.m_strName) == 0)
  348. {
  349. AfxMessageBox("Sorry, this user already exists!");
  350. return;
  351. }
  352. }
  353. }
  354. m_UserArray[nUserIndex].m_strName = dlg.m_strName;
  355. m_UsersList.DeleteItem(nSelIndex);
  356. nSelIndex = m_UsersList.InsertItem(0, dlg.m_strName, 2);
  357. m_UsersList.SetItemData(nSelIndex, nUserIndex);
  358. m_UsersList.SetItemState(nSelIndex, LVIS_SELECTED | LVIS_FOCUSED , LVIS_SELECTED | LVIS_FOCUSED);
  359. m_nPreviousIndex = nSelIndex;
  360. OnSelchangeUserlist();
  361. }
  362. }
  363. /********************************************************************/
  364. /* */
  365. /* Function name : OnDelUser */
  366. /* Description : Delete user account. */
  367. /* */
  368. /********************************************************************/
  369. void CUserAccountsDlg::OnDelUser()
  370. {
  371. int nSelIndex = m_UsersList.GetNextItem(-1, LVNI_ALL | LVNI_SELECTED);
  372. if(nSelIndex == -1)
  373. return;
  374. int nUserIndex = m_UsersList.GetItemData(nSelIndex);
  375. // remove user from listcontrol
  376. m_UsersList.DeleteItem(nSelIndex);
  377. // remove user from array
  378. m_UserArray.RemoveAt(nUserIndex);
  379. m_nPreviousIndex = -1;
  380. // update item data values
  381. for (int i=0; i<m_UsersList.GetItemCount(); i++)
  382. {
  383. int nItemData = m_UsersList.GetItemData(i);
  384. if (nItemData > nSelIndex)
  385. m_UsersList.SetItemData(i, nItemData-1);
  386. }
  387. OnSelchangeUserlist();
  388. }
  389. /********************************************************************/
  390. /* */
  391. /* Function name : OnAddDir */
  392. /* Description : Add directory entry to user account. */
  393. /* */
  394. /********************************************************************/
  395. void CUserAccountsDlg::OnAddDir()
  396. {
  397. int nSelIndex = m_UsersList.GetNextItem(-1, LVNI_ALL | LVNI_SELECTED);
  398. if(nSelIndex == -1)
  399. return;
  400. CDirectoryDlg dlg;
  401. dlg.m_bIsHomeDir = m_DirectoryList.GetItemCount() ? FALSE : TRUE;
  402. if (dlg.DoModal() == IDOK)
  403. {
  404. int nUserIndex = m_UsersList.GetItemData(nSelIndex);
  405. CDirectory dir;
  406. dir.m_bAllowCreateDirectory = dlg.m_bAllowCreateDirectory;
  407. dir.m_bAllowDelete = dlg.m_bAllowDelete;
  408. dir.m_bAllowDownload = dlg.m_bAllowDownload;
  409. dir.m_bAllowRename = dlg.m_bAllowRename;
  410. dir.m_bAllowUpload = dlg.m_bAllowUpload;
  411. dir.m_bIsHomeDir = FALSE;
  412. dir.m_strDir = dlg.m_strPath;
  413. dir.m_strAlias = dlg.m_strAlias;
  414. dir.m_bIsHomeDir = m_DirectoryList.GetItemCount() ? FALSE : TRUE;
  415. int nIndex = m_UserArray[nUserIndex].m_DirectoryArray.Add(dir);
  416. int nItem = m_DirectoryList.InsertItem(LVIF_TEXT | LVIF_PARAM | LVIF_IMAGE, 0, dlg.m_strPath, 0, 0, dir.m_bIsHomeDir?1:0, nIndex);
  417. m_DirectoryList.SetItemText(nItem, 1, dir.m_strAlias);
  418. m_DirectoryList.SetItemText(nItem, 2, dir.m_bAllowDownload ? "Y" : "N");
  419. m_DirectoryList.SetItemText(nItem, 3, dir.m_bAllowUpload ? "Y" : "N");
  420. m_DirectoryList.SetItemText(nItem, 4, dir.m_bAllowRename ? "Y" : "N");
  421. m_DirectoryList.SetItemText(nItem, 5, dir.m_bAllowDelete ? "Y" : "N");
  422. m_DirectoryList.SetItemText(nItem, 6, dir.m_bAllowCreateDirectory ? "Y" : "N");
  423. m_DirectoryList.SetItemState(nItem, LVIS_SELECTED, LVIS_SELECTED);
  424. }
  425. }
  426. /********************************************************************/
  427. /* */
  428. /* Function name : OnEditDir */
  429. /* Description : Edit directory entry properties. */
  430. /* */
  431. /********************************************************************/
  432. void CUserAccountsDlg::OnEditDir()
  433. {
  434. // get selected user
  435. int nSelIndex = m_UsersList.GetNextItem(-1, LVNI_ALL | LVNI_SELECTED);
  436. if(nSelIndex == -1)
  437. return;
  438. int nUserIndex = m_UsersList.GetItemData(nSelIndex);
  439. // get index of selected directory item
  440. nSelIndex = m_DirectoryList.GetNextItem(-1, LVNI_ALL | LVNI_SELECTED);
  441. if(nSelIndex == -1)
  442. return;
  443. int nDirIndex = m_DirectoryList.GetItemData(nSelIndex);
  444. CDirectoryDlg dlg;
  445. dlg.m_strTitle = "Edit Directory";
  446. dlg.m_bAllowCreateDirectory = m_UserArray[nUserIndex].m_DirectoryArray[nDirIndex].m_bAllowCreateDirectory;
  447. dlg.m_bAllowDelete = m_UserArray[nUserIndex].m_DirectoryArray[nDirIndex].m_bAllowDelete;
  448. dlg.m_bAllowDownload = m_UserArray[nUserIndex].m_DirectoryArray[nDirIndex].m_bAllowDownload;
  449. dlg.m_bAllowRename = m_UserArray[nUserIndex].m_DirectoryArray[nDirIndex].m_bAllowRename;
  450. dlg.m_bAllowUpload = m_UserArray[nUserIndex].m_DirectoryArray[nDirIndex].m_bAllowUpload;
  451. dlg.m_strPath = m_UserArray[nUserIndex].m_DirectoryArray[nDirIndex].m_strDir;
  452. dlg.m_strAlias = m_UserArray[nUserIndex].m_DirectoryArray[nDirIndex].m_strAlias;
  453. dlg.m_bIsHomeDir = m_UserArray[nUserIndex].m_DirectoryArray[nDirIndex].m_bIsHomeDir;
  454. if (!dlg.m_strAlias.IsEmpty())
  455. dlg.m_bVirtualDir = TRUE;
  456. if (dlg.DoModal() == IDOK)
  457. {
  458. m_UserArray[nUserIndex].m_DirectoryArray[nDirIndex].m_bAllowCreateDirectory = dlg.m_bAllowCreateDirectory;
  459. m_UserArray[nUserIndex].m_DirectoryArray[nDirIndex].m_bAllowDelete = dlg.m_bAllowDelete;
  460. m_UserArray[nUserIndex].m_DirectoryArray[nDirIndex].m_bAllowDownload = dlg.m_bAllowDownload;
  461. m_UserArray[nUserIndex].m_DirectoryArray[nDirIndex].m_bAllowRename = dlg.m_bAllowRename;
  462. m_UserArray[nUserIndex].m_DirectoryArray[nDirIndex].m_bAllowUpload = dlg.m_bAllowUpload;
  463. m_UserArray[nUserIndex].m_DirectoryArray[nDirIndex].m_strDir = dlg.m_strPath;
  464. if (dlg.m_bVirtualDir)
  465. m_UserArray[nUserIndex].m_DirectoryArray[nDirIndex].m_strAlias = dlg.m_strAlias;
  466. else
  467. m_UserArray[nUserIndex].m_DirectoryArray[nDirIndex].m_strAlias = "";
  468. m_DirectoryList.SetItemText(nDirIndex, 0, dlg.m_strPath);
  469. m_DirectoryList.SetItemText(nDirIndex, 1, dlg.m_strAlias);
  470. m_DirectoryList.SetItemText(nDirIndex, 2, dlg.m_bAllowDownload ? "Y" : "N");
  471. m_DirectoryList.SetItemText(nDirIndex, 3, dlg.m_bAllowUpload ? "Y" : "N");
  472. m_DirectoryList.SetItemText(nDirIndex, 4, dlg.m_bAllowRename ? "Y" : "N");
  473. m_DirectoryList.SetItemText(nDirIndex, 5, dlg.m_bAllowDelete ? "Y" : "N");
  474. m_DirectoryList.SetItemText(nDirIndex, 6, dlg.m_bAllowCreateDirectory ? "Y" : "N");
  475. OnSelchangeUserlist();
  476. }
  477. }
  478. /********************************************************************/
  479. /* */
  480. /* Function name : OnDelDir */
  481. /* Description : Delete directory entry from user account. */
  482. /* */
  483. /********************************************************************/
  484. void CUserAccountsDlg::OnDelDir()
  485. {
  486. int nSelIndex = m_UsersList.GetNextItem(-1, LVNI_ALL | LVNI_SELECTED);
  487. if(nSelIndex == -1)
  488. return;
  489. // get index of selected user item
  490. int nUserIndex = m_UsersList.GetItemData(nSelIndex);
  491. // get index of selected directory item
  492. nSelIndex = m_DirectoryList.GetNextItem(-1, LVNI_ALL | LVNI_SELECTED);
  493. if(nSelIndex == -1)
  494. return;
  495. int nDirIndex = m_DirectoryList.GetItemData(nSelIndex);
  496. // delete item from list
  497. m_DirectoryList.DeleteItem(nSelIndex);
  498. m_UserArray[nUserIndex].m_DirectoryArray.RemoveAt(nDirIndex);
  499. for (int i=0; i < m_DirectoryList.GetItemCount(); i++)
  500. {
  501. int nItemData = m_DirectoryList.GetItemData(i);
  502. if (nItemData > nDirIndex)
  503. {
  504. m_DirectoryList.SetItemData(i, nItemData-1);
  505. }
  506. }
  507. UpdateDialogControls(this, FALSE);
  508. }
  509. /********************************************************************/
  510. /* */
  511. /* Function name : OnSetHome */
  512. /* Description : Make selected directory the home directory. */
  513. /* */
  514. /********************************************************************/
  515. void CUserAccountsDlg::OnSetHome()
  516. {
  517. int nSelIndex = m_UsersList.GetNextItem(-1, LVNI_ALL | LVNI_SELECTED);
  518. if(nSelIndex == -1)
  519. return;
  520. int nUserIndex = m_UsersList.GetItemData(nSelIndex);
  521. // get index of selected directory item
  522. POSITION pos;
  523. pos = m_DirectoryList.GetFirstSelectedItemPosition();
  524. if (!pos)
  525. return;
  526. int nDirIndex = m_DirectoryList.GetNextSelectedItem(pos);
  527. for (int i=0; i<m_UserArray[nUserIndex].m_DirectoryArray.GetSize(); i++)
  528. {
  529. LVITEM lvi;
  530. ZeroMemory(&lvi, sizeof (LV_ITEM));
  531. lvi.mask = LVIF_IMAGE|LVIF_PARAM;
  532. lvi.iItem = i;
  533. m_DirectoryList.GetItem(&lvi);
  534. if (i == nDirIndex)
  535. {
  536. // set bIsHome flag for selected directory
  537. lvi.iImage = 1;
  538. m_UserArray[nUserIndex].m_DirectoryArray[lvi.lParam].m_bIsHomeDir = TRUE;
  539. }
  540. else
  541. {
  542. // clear old bIsHomeDir flag
  543. lvi.iImage = 0;
  544. m_UserArray[nUserIndex].m_DirectoryArray[lvi.lParam].m_bIsHomeDir = FALSE;
  545. }
  546. m_DirectoryList.SetItem(&lvi);
  547. }
  548. }
  549. void CUserAccountsDlg::OnUpdateControls(CCmdUI* pCmdUI)
  550. {
  551. int nSelIndex = m_UsersList.GetNextItem(-1, LVNI_ALL | LVNI_SELECTED);
  552. if(nSelIndex!=-1)
  553. {
  554. CString str;
  555. str= m_UsersList.GetItemText (nSelIndex, 0);
  556. if(str=="photo1account" || str=="photo2account" || str=="photo3account" || str=="photo4account")
  557. {
  558. pCmdUI->Enable(0);return;
  559. }
  560. }
  561. pCmdUI->Enable(nSelIndex != -1 && !IsDlgButtonChecked(IDC_DISABLE_ACCOUNT));
  562. }
  563. void CUserAccountsDlg::OnUpdateDisableAccount(CCmdUI* pCmdUI)
  564. {
  565. int nSelIndex = m_UsersList.GetNextItem(-1, LVNI_ALL | LVNI_SELECTED);
  566. if(nSelIndex!=-1)
  567. {
  568. CString str;
  569. str= m_UsersList.GetItemText (nSelIndex, 0);
  570. if(str=="photo1account" || str=="photo2account" || str=="photo3account" || str=="photo4account")
  571. {
  572. pCmdUI->Enable(0);return;
  573. }
  574. }
  575. pCmdUI->Enable(nSelIndex != -1);
  576. }
  577. CString CUserAccountsDlg::GetAttributes(CDirectory &dir)
  578. {
  579. CString strResult;
  580. strResult.Format("%c%c%c%c%c", dir.m_bAllowDownload ? 'Y':'-',
  581. dir.m_bAllowUpload ? 'Y':'-',
  582. dir.m_bAllowRename ? 'Y':'-',
  583. dir.m_bAllowDelete ? 'Y':'-',
  584. dir.m_bAllowCreateDirectory ? 'Y':'-');
  585. return strResult;
  586. }
  587. /********************************************************************/
  588. /* */
  589. /* Function name : AutoSizeColumns */
  590. /* Description : Make all columns fit nicely. */
  591. /* */
  592. /********************************************************************/
  593. void CUserAccountsDlg::AutoSizeColumns()
  594. {
  595. // Call this after your the control is filled
  596. m_DirectoryList.SetRedraw(FALSE);
  597. int mincol = 0;
  598. int maxcol = m_DirectoryList.GetHeaderCtrl()->GetItemCount()-1;
  599. int col;
  600. for (col = mincol; col <= maxcol; col++)
  601. {
  602. m_DirectoryList.SetColumnWidth(col,LVSCW_AUTOSIZE);
  603. int wc1 = m_DirectoryList.GetColumnWidth(col);
  604. m_DirectoryList.SetColumnWidth(col,LVSCW_AUTOSIZE_USEHEADER);
  605. int wc2 = m_DirectoryList.GetColumnWidth(col);
  606. // 10 is minumim column width
  607. int wc = max(10, max(wc1,wc2));
  608. m_DirectoryList.SetColumnWidth(col,wc);
  609. }
  610. m_DirectoryList.SetRedraw(TRUE);
  611. }
  612. /********************************************************************/
  613. /* */
  614. /* Function name : OnDisableAccount */
  615. /* Description : Disable account has been clicked */
  616. /* */
  617. /********************************************************************/
  618. void CUserAccountsDlg::OnDisableAccount()
  619. {
  620. UpdateDialogControls(this, FALSE);
  621. }
  622. /********************************************************************/
  623. /* */
  624. /* Function name : OnWizard */
  625. /* Description : Launch New Account Wizard */
  626. /* */
  627. /********************************************************************/
  628. void CUserAccountsDlg::OnWizard()
  629. {
  630. CBitmap bmpHeader, bmpWatermark;
  631. VERIFY(bmpHeader.LoadBitmap(IDB_BANNER));
  632. VERIFY(bmpWatermark.LoadBitmap(IDB_WATERMARK));
  633. // show windows 2000-like wizard
  634. CWizardSheet wizSheet("New Account Wizard", this, 0, bmpWatermark, NULL, bmpHeader);
  635. wizSheet.m_psh.hInstance = ::GetModuleHandle(NULL);
  636. if (wizSheet.DoModal() == ID_WIZFINISH)
  637. {
  638. int nIndex = -1;
  639. int nItem = -1;
  640. // existing account ?
  641. for (int i=0; i<m_UsersList.GetItemCount(); i++)
  642. {
  643. CString strName;
  644. strName = m_UsersList.GetItemText(i, 0);
  645. if (strName.CompareNoCase(wizSheet.m_Page1.m_strAccountName) == 0)
  646. {
  647. nItem = i;
  648. nIndex = m_UsersList.GetItemData(i);
  649. break;
  650. }
  651. }
  652. // add new account
  653. if (nIndex == -1)
  654. {
  655. CUser user;
  656. int nItem = m_UsersList.InsertItem(0, wizSheet.m_Page1.m_strAccountName, 2);
  657. nIndex = m_UserArray.Add(user);
  658. m_UsersList.SetItemData(nItem, nIndex);
  659. }
  660. else
  661. {
  662. // clear old bIsHomeDir flag
  663. for (int i=0; i<m_UserArray[nIndex].m_DirectoryArray.GetSize(); i++)
  664. {
  665. m_UserArray[nIndex].m_DirectoryArray[i].m_bIsHomeDir = FALSE;
  666. }
  667. }
  668. m_UserArray[nIndex].m_bAccountDisabled = FALSE;
  669. m_UserArray[nIndex].m_strName = wizSheet.m_Page1.m_strAccountName;
  670. m_UserArray[nIndex].m_strPassword = wizSheet.m_Page2.m_strPassword;
  671. // add home directory
  672. CDirectory directory;
  673. directory.m_strDir = wizSheet.m_Page3.m_strHomeDirectory;
  674. directory.m_strAlias = "";
  675. directory.m_bIsHomeDir = TRUE;
  676. directory.m_bAllowCreateDirectory = wizSheet.m_Page4.m_bAllowCreateDirectory;
  677. directory.m_bAllowDelete = wizSheet.m_Page4.m_bAllowDelete;
  678. directory.m_bAllowDownload = wizSheet.m_Page4.m_bAllowDownload;
  679. directory.m_bAllowRename = wizSheet.m_Page4.m_bAllowRename;
  680. directory.m_bAllowUpload = wizSheet.m_Page4.m_bAllowUpload;
  681. directory.m_strAlias = "";
  682. m_UserArray[nIndex].m_DirectoryArray.Add(directory);
  683. if (m_nPreviousIndex == nItem)
  684. m_nPreviousIndex = -1;
  685. // select updated account
  686. m_UsersList.SetItemState(nItem, LVIS_SELECTED | LVIS_FOCUSED , LVIS_SELECTED | LVIS_FOCUSED);
  687. OnSelchangeUserlist();
  688. }
  689. }