PageRenderTime 52ms CodeModel.GetById 25ms RepoModel.GetById 1ms app.codeStats 0ms

/ncftp-3.2.5/win/bmed/BookmarkProperties.cpp

#
C++ | 181 lines | 117 code | 44 blank | 20 comment | 27 complexity | 9716db25ec2fb75630af3f4450cea407 MD5 | raw file
Possible License(s): AGPL-3.0
  1. // BookmarkProperties.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. #include "bmed.h"
  5. #include "BookmarkProperties.h"
  6. #include <Strn.h>
  7. #ifdef _DEBUG
  8. #define new DEBUG_NEW
  9. #undef THIS_FILE
  10. static char THIS_FILE[] = __FILE__;
  11. #endif
  12. /////////////////////////////////////////////////////////////////////////////
  13. // CBookmarkProperties dialog
  14. CBookmarkProperties::CBookmarkProperties(BookmarkPtr bmp, CWnd* pParent /*=NULL*/)
  15. : CDialog(CBookmarkProperties::IDD, pParent)
  16. {
  17. m_bmp = bmp;
  18. //{{AFX_DATA_INIT(CBookmarkProperties)
  19. m_account = _T("");
  20. m_bookmarkName = _T("");
  21. m_comment = _T("");
  22. m_hostName = _T("");
  23. m_localDir = _T("");
  24. m_password = _T("");
  25. m_portNumber = 0;
  26. m_remoteDir = _T("");
  27. m_user = _T("");
  28. m_typeBinary = -1;
  29. //}}AFX_DATA_INIT
  30. ASSERT(bmp->deleted == 0);
  31. m_account = bmp->acct;
  32. m_bookmarkName = bmp->bookmarkName;
  33. m_comment = bmp->comment;
  34. m_hostName = bmp->name;
  35. m_localDir = bmp->ldir;
  36. m_password = bmp->pass;
  37. m_portNumber = (UINT) bmp->port;
  38. m_remoteDir = bmp->dir;
  39. m_user = bmp->user;
  40. if (m_portNumber == 0)
  41. m_portNumber = 21;
  42. // This looks odd, but what we pass to DDX is 0 for the first
  43. // radio button (binary), or 1 for the second button (ASCII).
  44. //
  45. m_typeBinary = (bmp->xferType == 'A') ? 1 : 0;
  46. m_passwordWarning = FALSE;
  47. }
  48. void CBookmarkProperties::DoDataExchange(CDataExchange* pDX)
  49. {
  50. CDialog::DoDataExchange(pDX);
  51. //{{AFX_DATA_MAP(CBookmarkProperties)
  52. DDX_Control(pDX, IDC_PASSWORD, m_passwordEdit);
  53. DDX_Text(pDX, IDC_ACCOUNT, m_account);
  54. DDV_MaxChars(pDX, m_account, 63);
  55. DDX_Text(pDX, IDC_BOOKMARK_NAME, m_bookmarkName);
  56. DDV_MaxChars(pDX, m_bookmarkName, 15);
  57. DDX_Text(pDX, IDC_COMMENT, m_comment);
  58. DDV_MaxChars(pDX, m_comment, 127);
  59. DDX_Text(pDX, IDC_HOSTNAME, m_hostName);
  60. DDV_MaxChars(pDX, m_hostName, 63);
  61. DDX_Text(pDX, IDC_LOCAL_DIR, m_localDir);
  62. DDV_MaxChars(pDX, m_localDir, 159);
  63. DDX_Text(pDX, IDC_PASSWORD, m_password);
  64. DDV_MaxChars(pDX, m_password, 63);
  65. DDX_Text(pDX, IDC_PORT, m_portNumber);
  66. DDV_MinMaxUInt(pDX, m_portNumber, 1, 65535);
  67. DDX_Text(pDX, IDC_REMOTE_DIR, m_remoteDir);
  68. DDV_MaxChars(pDX, m_remoteDir, 159);
  69. DDX_Text(pDX, IDC_USER, m_user);
  70. DDV_MaxChars(pDX, m_user, 63);
  71. DDX_Radio(pDX, IDC_BINARY, m_typeBinary);
  72. //}}AFX_DATA_MAP
  73. }
  74. BEGIN_MESSAGE_MAP(CBookmarkProperties, CDialog)
  75. //{{AFX_MSG_MAP(CBookmarkProperties)
  76. ON_EN_CHANGE(IDC_USER, OnChangeUser)
  77. ON_EN_KILLFOCUS(IDC_PASSWORD, OnKillfocusPassword)
  78. //}}AFX_MSG_MAP
  79. END_MESSAGE_MAP()
  80. /////////////////////////////////////////////////////////////////////////////
  81. // CBookmarkProperties message handlers
  82. void CBookmarkProperties::EnablePasswordFieldAccordingToUserField(CString &user)
  83. {
  84. if ((user.IsEmpty() == FALSE) && (user != "anonymous") && (user != "ftp"))
  85. m_passwordEdit.EnableWindow(TRUE);
  86. else
  87. m_passwordEdit.EnableWindow(FALSE);
  88. } // EnablePasswordFieldAccordingToUserField
  89. BOOL CBookmarkProperties::OnInitDialog()
  90. {
  91. CDialog::OnInitDialog();
  92. EnablePasswordFieldAccordingToUserField(m_user);
  93. return TRUE; // return TRUE unless you set the focus to a control
  94. // EXCEPTION: OCX Property Pages should return FALSE
  95. } // OnInitDialog
  96. void CBookmarkProperties::OnChangeUser()
  97. {
  98. CString user;
  99. GetDlgItemText(IDC_USER, user);
  100. EnablePasswordFieldAccordingToUserField(user);
  101. } // OnChangeUser
  102. void CBookmarkProperties::OnKillfocusPassword()
  103. {
  104. CString pass, user;
  105. if (m_passwordWarning == FALSE) {
  106. GetDlgItemText(IDC_USER, user);
  107. GetDlgItemText(IDC_PASSWORD, pass);
  108. if ((user.IsEmpty() == FALSE) && (user != "anonymous") && (user != "ftp") && (pass.IsEmpty() == FALSE)) {
  109. m_passwordWarning = TRUE;
  110. AfxMessageBox("Warning: You have entered a password for a non-anonymous user account. This password will be stored in plain-text on disk -- leave the password field blank for better security. NcFTP will prompt you when it needs a password, so there is no need to store your password.");
  111. }
  112. }
  113. } // OnKillfocusPassword
  114. void CBookmarkProperties::OnOK()
  115. {
  116. CDialog::OnOK();
  117. BookmarkPtr bmp = m_bmp;
  118. if ((m_user == "anonymous") || (m_user == "ftp"))
  119. m_user.Empty();
  120. STRNCPY(bmp->acct, (LPCSTR) m_account);
  121. STRNCPY(bmp->bookmarkName, (LPCSTR) m_bookmarkName);
  122. STRNCPY(bmp->comment, (LPCSTR) m_comment);
  123. STRNCPY(bmp->name, (LPCSTR) m_hostName);
  124. STRNCPY(bmp->ldir, (LPCSTR) m_localDir);
  125. STRNCPY(bmp->pass, (LPCSTR) m_password);
  126. bmp->port = (unsigned short) m_portNumber;
  127. STRNCPY(bmp->dir, (LPCSTR) m_remoteDir);
  128. STRNCPY(bmp->user, (LPCSTR) m_user);
  129. bmp->xferType = (m_typeBinary == 1) ? 'A' : 'I';
  130. // Whenever the record could be changed, purge
  131. // the (pretty much worthless) last IP address
  132. // field, in case the hostname is different.
  133. //
  134. bmp->lastIP[0] = 0;
  135. if (m_portNumber == 21)
  136. bmp->port = 0;
  137. } // OnOK