📄 connectdlg.cpp
字号:
Serialize(TRUE);
UpdateDialogControls(this, FALSE);
m_listSites.SetCurSel(0);
OnSelchangeSites();
}
/********************************************************************/
/* */
/* Function name : OnUpdateConnect */
/* Description : Enable/Disable Connect-button */
/* */
/********************************************************************/
void CConnectDlg::OnUpdateConnect(CCmdUI* pCmdUI)
{
pCmdUI->Enable(((CEdit*)GetDlgItem(IDC_ADDRESS))->GetWindowTextLength());
}
/********************************************************************/
/* */
/* Function name : OnUpdateSave */
/* Description : Enable/Disable Save-button */
/* */
/********************************************************************/
void CConnectDlg::OnUpdateSave(CCmdUI* pCmdUI)
{
pCmdUI->Enable(m_bModified && m_listSites.GetCurSel() != LB_ERR);
}
/********************************************************************/
/* */
/* Function name : OnUpdateRemove */
/* Description : Enable/Disable Remove-button */
/* */
/********************************************************************/
void CConnectDlg::OnUpdateRemove(CCmdUI* pCmdUI)
{
pCmdUI->Enable(m_listSites.GetCurSel() != LB_ERR);
}
/********************************************************************/
/* */
/* Function name : OnSelchangeSites */
/* Description : Get data from selected site */
/* */
/********************************************************************/
void CConnectDlg::OnSelchangeSites()
{
int nIndex = m_listSites.GetCurSel();
if (nIndex != LB_ERR)
{
int nItem = m_listSites.GetItemData(nIndex);
m_bUsePASVMode = m_SitesArray[nItem].m_bUsePASVMode;
m_nRetries = m_SitesArray[nItem].m_nRetries;
m_nPort = m_SitesArray[nItem].m_nPort;
m_nRetryDelay = m_SitesArray[nItem].m_nRetryDelay;
m_strAddress = m_SitesArray[nItem].m_strAddress;
m_strDescription = m_SitesArray[nItem].m_strDescription;
m_strLocalPath = m_SitesArray[nItem].m_strLocalPath ;
m_strLogin = m_SitesArray[nItem].m_strLogin;
m_bAnonymous = (m_strLogin.CompareNoCase("anonymous") == 0);
if (!m_bAnonymous)
{
GetDlgItem(IDC_PASSWORD)->ModifyStyle(NULL, ES_PASSWORD);
((CEdit *)GetDlgItem(IDC_PASSWORD))->SetPasswordChar('*');
}
else
{
GetDlgItem(IDC_PASSWORD)->ModifyStyle(ES_PASSWORD, NULL);
((CEdit *)GetDlgItem(IDC_PASSWORD))->SetPasswordChar(0);
}
m_strName = m_SitesArray[nItem].m_strName;
m_wndInfobarCtrl.SetText(m_strName);
m_strPassword = m_SitesArray[nItem].m_strPassword;
m_strRemotePath = m_SitesArray[nItem].m_strRemotePath;
UpdateData(FALSE);
UpdateDialogControls(this, FALSE);
AfxGetApp()->WriteProfileInt("Settings", "LastSelectedSite", nIndex);
}
}
/********************************************************************/
/* */
/* Function name : ValidateData */
/* Description : Validate the data that has been entered. */
/* */
/********************************************************************/
BOOL CConnectDlg::ValidateData()
{
UpdateData();
if (m_strName.IsEmpty())
{
GetDlgItem(IDC_NAME)->SetFocus();
return FALSE;
}
return TRUE;
}
/********************************************************************/
/* */
/* Function name : OnBrowse */
/* Description : Browse for local folder */
/* */
/********************************************************************/
void CConnectDlg::OnBrowse()
{
CString strDir = BrowseForFolder(m_hWnd, "Select a directory:", BIF_RETURNONLYFSDIRS);
if (!strDir.IsEmpty())
{
GetDlgItem(IDC_LOCALPATH)->SetWindowText(strDir);
}
}
/********************************************************************/
/* */
/* Function name : OnSomethingChanged */
/* Description : Something has changed... */
/* */
/********************************************************************/
void CConnectDlg::OnSomethingChanged()
{
m_bModified = TRUE;
UpdateDialogControls(this, FALSE);
}
/********************************************************************/
/* */
/* Function name : OnDblclkSites */
/* Description : Item in the list has been double-clicked. */
/* */
/********************************************************************/
void CConnectDlg::OnDblclkSites()
{
OnOK();
}
/********************************************************************/
/* */
/* Function name : OnAnonymous */
/* Description : Item in the list has been double-clicked. */
/* */
/********************************************************************/
void CConnectDlg::OnAnonymous()
{
UpdateData();
if (m_bAnonymous)
{
m_strLogin = "anonymous";
m_strPassword = AfxGetApp()->GetProfileString("Settings", "EmailAddress", "");
GetDlgItem(IDC_PASSWORD)->ModifyStyle(ES_PASSWORD, NULL);
((CEdit *)GetDlgItem(IDC_PASSWORD))->SetPasswordChar(0);
((CEdit *)GetDlgItem(IDC_PASSWORD))->Invalidate();
((CEdit *)GetDlgItem(IDC_PASSWORD))->UpdateWindow();
}
else
{
// get old value
int nIndex = m_listSites.GetCurSel();
if (nIndex != LB_ERR)
{
int nItem = m_listSites.GetItemData(nIndex);
m_strLogin = m_SitesArray[nItem].m_strLogin;
m_strPassword = m_SitesArray[nItem].m_strPassword;
GetDlgItem(IDC_PASSWORD)->ModifyStyle(NULL, ES_PASSWORD);
((CEdit *)GetDlgItem(IDC_PASSWORD))->SetPasswordChar('*');
((CEdit *)GetDlgItem(IDC_PASSWORD))->Invalidate();
((CEdit *)GetDlgItem(IDC_PASSWORD))->UpdateWindow();
}
}
UpdateData(FALSE);
}
/********************************************************************/
/* */
/* Function name : OnChangeName */
/* Description : Profile name has been changed. */
/* */
/********************************************************************/
void CConnectDlg::OnChangeName()
{
OnSomethingChanged();
CString strName;
GetDlgItemText(IDC_NAME, strName);
m_wndInfobarCtrl.SetText(strName);
}
/********************************************************************/
/* */
/* Function name : AddSite */
/* Description : Add site without launching the dialog. */
/* */
/********************************************************************/
BOOL CConnectDlg::AddSite(CFtpSite &pFtpSite)
{
Serialize(FALSE);
int nItem = -1;
for (int i=0; i < m_SitesArray.GetSize(); i++)
{
if (m_SitesArray[i].m_strName.CompareNoCase(pFtpSite.m_strName) == 0)
{
nItem = i;
// update old settings
m_SitesArray[nItem].m_bUsePASVMode = pFtpSite.m_bUsePASVMode;
m_SitesArray[nItem].m_nRetries = pFtpSite.m_nRetries;
m_SitesArray[nItem].m_nPort = pFtpSite.m_nPort;
m_SitesArray[nItem].m_nRetryDelay = pFtpSite.m_nRetryDelay;
m_SitesArray[nItem].m_strAddress = pFtpSite.m_strAddress;
m_SitesArray[nItem].m_strDescription = pFtpSite.m_strDescription;
m_SitesArray[nItem].m_strLocalPath = pFtpSite.m_strLocalPath;
m_SitesArray[nItem].m_strLogin = pFtpSite.m_strLogin;
m_SitesArray[nItem].m_strName = pFtpSite.m_strName;
m_SitesArray[nItem].m_strPassword = pFtpSite.m_strPassword;
m_SitesArray[nItem].m_strRemotePath = pFtpSite.m_strRemotePath;
break;
}
}
if (nItem == -1)
{
nItem = m_SitesArray.Add(pFtpSite);
}
Serialize(TRUE);
return TRUE;
}
/********************************************************************/
/* */
/* Function name : OnWizard */
/* Description : Show wizard to add new site. */
/* */
/********************************************************************/
void CConnectDlg::OnWizard()
{
CBitmap bmpHeader, bmpWatermark;
VERIFY(bmpHeader.LoadBitmap(IDB_BANNER));
VERIFY(bmpWatermark.LoadBitmap(IDB_WATERMARK));
// show windows 2000-like wizard
CWizardSheet wizSheet("Connection Wizard", this, 0, bmpWatermark, NULL, bmpHeader);
wizSheet.m_psh.hInstance = ::GetModuleHandle(NULL);
if (wizSheet.DoModal() == ID_WIZFINISH)
{
CFtpSite ftpSite;
int nIndex = m_listSites.AddString(wizSheet.m_Page1.m_strProfileName);
int nItem = m_SitesArray.Add(ftpSite);
m_listSites.SetItemData(nIndex, nItem);
m_listSites.SetCurSel(nIndex);
m_SitesArray[nItem].m_bUsePASVMode = AfxGetApp()->GetProfileInt("Settings", "DefaultUsePASVMode", 0);;
m_SitesArray[nItem].m_nRetries = AfxGetApp()->GetProfileInt("Settings", "DefaultRetries", 3);
m_SitesArray[nItem].m_nPort = 21;
m_SitesArray[nItem].m_nRetryDelay = AfxGetApp()->GetProfileInt("Settings", "DefaultRetryDelay", 10);
m_SitesArray[nItem].m_strAddress = wizSheet.m_Page2.m_strHostAddress;
m_SitesArray[nItem].m_strDescription = "";
m_SitesArray[nItem].m_strLocalPath = wizSheet.m_Page4.m_strLocalFolder;
m_SitesArray[nItem].m_strLogin = wizSheet.m_Page3.m_strUserName;
m_SitesArray[nItem].m_strName = wizSheet.m_Page1.m_strProfileName;
m_SitesArray[nItem].m_strPassword = wizSheet.m_Page3.m_strPassword;
m_SitesArray[nItem].m_strRemotePath = "";
Serialize(TRUE);
// select new site
m_listSites.SetCurSel(nIndex);
OnSelchangeSites();
// connect to the site
if (wizSheet.m_PageFinish.m_bConnectNow)
{
OnOK();
}
}
}
void CConnectDlg::OnChangeLogin()
{
m_bModified = TRUE;
UpdateDialogControls(this, FALSE);
CString strText;
GetDlgItemText(IDC_LOGIN, strText);
if (strText.CompareNoCase("anonymous") != 0)
{
GetDlgItem(IDC_PASSWORD)->ModifyStyle(NULL, ES_PASSWORD);
((CEdit *)GetDlgItem(IDC_PASSWORD))->SetPasswordChar('*');
((CEdit *)GetDlgItem(IDC_PASSWORD))->Invalidate();
((CEdit *)GetDlgItem(IDC_PASSWORD))->UpdateWindow();
CheckDlgButton(IDC_ANONYMOUS, BST_UNCHECKED);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -