PageRenderTime 25ms CodeModel.GetById 10ms app.highlight 13ms RepoModel.GetById 0ms 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
  4#include "stdafx.h"
  5#include "bmed.h"
  6#include "BookmarkProperties.h"
  7#include <Strn.h>
  8
  9#ifdef _DEBUG
 10#define new DEBUG_NEW
 11#undef THIS_FILE
 12static char THIS_FILE[] = __FILE__;
 13#endif
 14
 15/////////////////////////////////////////////////////////////////////////////
 16// CBookmarkProperties dialog
 17
 18
 19CBookmarkProperties::CBookmarkProperties(BookmarkPtr bmp, CWnd* pParent /*=NULL*/)
 20	: CDialog(CBookmarkProperties::IDD, pParent)
 21{
 22	m_bmp = bmp;
 23
 24	//{{AFX_DATA_INIT(CBookmarkProperties)
 25	m_account = _T("");
 26	m_bookmarkName = _T("");
 27	m_comment = _T("");
 28	m_hostName = _T("");
 29	m_localDir = _T("");
 30	m_password = _T("");
 31	m_portNumber = 0;
 32	m_remoteDir = _T("");
 33	m_user = _T("");
 34	m_typeBinary = -1;
 35	//}}AFX_DATA_INIT
 36
 37	ASSERT(bmp->deleted == 0);
 38
 39	m_account = bmp->acct;
 40	m_bookmarkName = bmp->bookmarkName;
 41	m_comment = bmp->comment;
 42	m_hostName = bmp->name;
 43	m_localDir = bmp->ldir;
 44	m_password = bmp->pass;
 45	m_portNumber = (UINT) bmp->port;
 46	m_remoteDir = bmp->dir;
 47	m_user = bmp->user;
 48
 49	if (m_portNumber == 0)
 50		m_portNumber = 21;
 51
 52	// This looks odd, but what we pass to DDX is 0 for the first
 53	// radio button (binary), or 1 for the second button (ASCII).
 54	//
 55	m_typeBinary = (bmp->xferType == 'A') ? 1 : 0;
 56
 57	m_passwordWarning = FALSE;
 58}
 59
 60
 61void CBookmarkProperties::DoDataExchange(CDataExchange* pDX)
 62{
 63	CDialog::DoDataExchange(pDX);
 64	//{{AFX_DATA_MAP(CBookmarkProperties)
 65	DDX_Control(pDX, IDC_PASSWORD, m_passwordEdit);
 66	DDX_Text(pDX, IDC_ACCOUNT, m_account);
 67	DDV_MaxChars(pDX, m_account, 63);
 68	DDX_Text(pDX, IDC_BOOKMARK_NAME, m_bookmarkName);
 69	DDV_MaxChars(pDX, m_bookmarkName, 15);
 70	DDX_Text(pDX, IDC_COMMENT, m_comment);
 71	DDV_MaxChars(pDX, m_comment, 127);
 72	DDX_Text(pDX, IDC_HOSTNAME, m_hostName);
 73	DDV_MaxChars(pDX, m_hostName, 63);
 74	DDX_Text(pDX, IDC_LOCAL_DIR, m_localDir);
 75	DDV_MaxChars(pDX, m_localDir, 159);
 76	DDX_Text(pDX, IDC_PASSWORD, m_password);
 77	DDV_MaxChars(pDX, m_password, 63);
 78	DDX_Text(pDX, IDC_PORT, m_portNumber);
 79	DDV_MinMaxUInt(pDX, m_portNumber, 1, 65535);
 80	DDX_Text(pDX, IDC_REMOTE_DIR, m_remoteDir);
 81	DDV_MaxChars(pDX, m_remoteDir, 159);
 82	DDX_Text(pDX, IDC_USER, m_user);
 83	DDV_MaxChars(pDX, m_user, 63);
 84	DDX_Radio(pDX, IDC_BINARY, m_typeBinary);
 85	//}}AFX_DATA_MAP
 86}
 87
 88
 89BEGIN_MESSAGE_MAP(CBookmarkProperties, CDialog)
 90	//{{AFX_MSG_MAP(CBookmarkProperties)
 91	ON_EN_CHANGE(IDC_USER, OnChangeUser)
 92	ON_EN_KILLFOCUS(IDC_PASSWORD, OnKillfocusPassword)
 93	//}}AFX_MSG_MAP
 94END_MESSAGE_MAP()
 95
 96/////////////////////////////////////////////////////////////////////////////
 97// CBookmarkProperties message handlers
 98
 99
100void CBookmarkProperties::EnablePasswordFieldAccordingToUserField(CString &user)
101{
102	if ((user.IsEmpty() == FALSE) && (user != "anonymous") && (user != "ftp"))
103		m_passwordEdit.EnableWindow(TRUE);
104	else
105		m_passwordEdit.EnableWindow(FALSE);
106}	// EnablePasswordFieldAccordingToUserField
107
108
109
110
111BOOL CBookmarkProperties::OnInitDialog() 
112{
113	CDialog::OnInitDialog();
114
115	EnablePasswordFieldAccordingToUserField(m_user);
116	
117	return TRUE;  // return TRUE unless you set the focus to a control
118	              // EXCEPTION: OCX Property Pages should return FALSE
119}	// OnInitDialog
120
121
122
123
124void CBookmarkProperties::OnChangeUser() 
125{
126	CString user;
127
128	GetDlgItemText(IDC_USER, user);
129	EnablePasswordFieldAccordingToUserField(user);
130}	// OnChangeUser
131
132
133
134
135void CBookmarkProperties::OnKillfocusPassword() 
136{
137	CString pass, user;
138	
139	if (m_passwordWarning == FALSE) {
140		GetDlgItemText(IDC_USER, user);
141		GetDlgItemText(IDC_PASSWORD, pass);
142		
143		if ((user.IsEmpty() == FALSE) && (user != "anonymous") && (user != "ftp") && (pass.IsEmpty() == FALSE)) {
144			m_passwordWarning = TRUE;
145			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.");
146		}
147	}
148}	// OnKillfocusPassword
149
150
151
152
153void CBookmarkProperties::OnOK() 
154{
155	CDialog::OnOK();
156
157	BookmarkPtr bmp = m_bmp;
158
159	if ((m_user == "anonymous") || (m_user == "ftp"))
160		m_user.Empty();
161
162	STRNCPY(bmp->acct, (LPCSTR) m_account);
163	STRNCPY(bmp->bookmarkName, (LPCSTR) m_bookmarkName);
164	STRNCPY(bmp->comment, (LPCSTR) m_comment);
165	STRNCPY(bmp->name, (LPCSTR) m_hostName);
166	STRNCPY(bmp->ldir, (LPCSTR) m_localDir);
167	STRNCPY(bmp->pass, (LPCSTR) m_password);
168	bmp->port = (unsigned short) m_portNumber;
169	STRNCPY(bmp->dir, (LPCSTR) m_remoteDir);
170	STRNCPY(bmp->user, (LPCSTR) m_user);
171	bmp->xferType = (m_typeBinary == 1) ? 'A' : 'I';
172
173	// Whenever the record could be changed, purge
174	// the (pretty much worthless) last IP address
175	// field, in case the hostname is different.
176	//
177	bmp->lastIP[0] = 0;
178
179	if (m_portNumber == 21)
180		bmp->port = 0;
181}	// OnOK