00001
00002
00003
00004
00005
00006 #include "stdafx.h"
00007 #include "FdmApp.h"
00008 #include "UrlWithLoginDlg.h"
00009 #include "DownloadPropertiesSheet.h"
00010
00011 #ifdef _DEBUG
00012 #define new DEBUG_NEW
00013 #undef THIS_FILE
00014 static char THIS_FILE[] = __FILE__;
00015 #endif
00016
00017 CUrlWithLoginDlg::CUrlWithLoginDlg(CWnd* pParent )
00018 : CDialog(CUrlWithLoginDlg::IDD, pParent)
00019 {
00020 m_CaptionLngID = L_ENTERMIRRURL;
00021 Download_CreateInstance (m_dld);
00022 }
00023
00024 void CUrlWithLoginDlg::DoDataExchange(CDataExchange* pDX)
00025 {
00026 CDialog::DoDataExchange(pDX);
00027
00028
00029
00030 }
00031
00032 BEGIN_MESSAGE_MAP(CUrlWithLoginDlg, CDialog)
00033
00034 ON_BN_CLICKED(IDC_USELOGIN, OnUselogin)
00035 ON_BN_CLICKED(IDC_ADVANCED, OnAdvanced)
00036
00037 END_MESSAGE_MAP()
00038
00039 void CUrlWithLoginDlg::OnOK()
00040 {
00041 if (FALSE == UpdateDNP ())
00042 return;
00043
00044 GetDlgItemText (IDC_URL, m_strUrl);
00045 fsURL url;
00046 if (url.Crack (m_strUrl) != IR_SUCCESS || *url.GetHostName () == 0 || *url.GetPath () == 0)
00047 {
00048 MessageBox (LS (L_CHECKURL), LS (L_INPERR), MB_ICONEXCLAMATION);
00049 GetDlgItem (IDC_URL)->SetFocus ();
00050 return;
00051 }
00052
00053 if (IsDlgButtonChecked (IDC_USELOGIN) == BST_CHECKED)
00054 {
00055 GetDlgItemText (IDC_USER, m_strUser);
00056 GetDlgItemText (IDC_PASSWORD, m_strPassword);
00057
00058 if (m_strUser.GetLength () == 0)
00059 {
00060 MessageBox (LS (L_ENTERUSER), LS (L_INPERR), MB_ICONEXCLAMATION);
00061 GetDlgItem (IDC_USER)->SetFocus ();
00062 return;
00063 }
00064 }
00065 else
00066 {
00067 m_strUser = m_strPassword = "";
00068 }
00069
00070 fsDNP_CloneSettings (&m_dnp, m_dld->pMgr->GetDownloadMgr ()->GetDNP ());
00071
00072 CDialog::OnOK();
00073 }
00074
00075 BOOL CUrlWithLoginDlg::OnInitDialog()
00076 {
00077 CDialog::OnInitDialog();
00078
00079 ZeroMemory (&m_dnp, sizeof (m_dnp));
00080
00081 if (m_strUrl.GetLength () == 0)
00082 {
00083 LPCSTR pszUrl = _ClipbrdMgr.Text ();
00084 if (pszUrl && *pszUrl)
00085 {
00086 fsURL url;
00087 if (url.Crack (pszUrl) == IR_SUCCESS && *url.GetHostName ())
00088 m_strUrl = pszUrl;
00089 }
00090
00091 if (m_strUrl.GetLength () == 0)
00092 m_strUrl = "http://";
00093 }
00094
00095 ASSERT (m_dld->pMgr->GetDownloadMgr () != NULL);
00096
00097 if (IR_SUCCESS != m_dld->pMgr->GetDownloadMgr ()->CreateByUrl (m_strUrl, TRUE))
00098 m_dld->pMgr->GetDownloadMgr ()->CreateByUrl ("http://", TRUE);
00099
00100 SetDlgItemText (IDC_URL, m_strUrl);
00101 ((CEdit*) GetDlgItem (IDC_URL))->SetSel (0, -1);
00102 GetDlgItem (IDC_URL)->SetFocus ();
00103
00104 ApplyLanguage ();
00105 UpdateEnabled ();
00106
00107 return FALSE;
00108 }
00109
00110 void CUrlWithLoginDlg::ApplyLanguage()
00111 {
00112 fsDlgLngInfo lnginfo [] = {
00113 fsDlgLngInfo (IDC_USELOGIN, L_AUTHORIZATION),
00114 fsDlgLngInfo (IDC__USER, L_USER),
00115 fsDlgLngInfo (IDC__PASSWORD, L_PASSWORD),
00116 fsDlgLngInfo (IDC_ADVANCED, L_ADVANCED),
00117 fsDlgLngInfo (IDCANCEL, L_CANCEL),
00118 };
00119
00120 CString str = LS (L_COMMENT); str += ':';
00121 SetDlgItemText (IDC__COMMENT, str);
00122
00123 _LngMgr.ApplyLanguage (this, lnginfo, sizeof (lnginfo) / sizeof (fsDlgLngInfo), m_CaptionLngID);
00124 }
00125
00126 void CUrlWithLoginDlg::OnUselogin()
00127 {
00128 UpdateEnabled ();
00129 }
00130
00131 void CUrlWithLoginDlg::UpdateEnabled()
00132 {
00133 BOOL b = IsDlgButtonChecked (IDC_USELOGIN) == BST_CHECKED;
00134
00135 GetDlgItem (IDC__USER)->EnableWindow (b);
00136 GetDlgItem (IDC_USER)->EnableWindow (b);
00137 GetDlgItem (IDC__PASSWORD)->EnableWindow (b);
00138 GetDlgItem (IDC_PASSWORD)->EnableWindow (b);
00139 }
00140
00141 void CUrlWithLoginDlg::OnAdvanced()
00142 {
00143 if (FALSE == UpdateDNP ())
00144 return;
00145
00146 DLDS_LIST v;
00147 v.push_back (m_dld);
00148
00149 CDownloadPropertiesSheet sheet (LS (L_ADVANCED), this);
00150 sheet.Init (&v, DPS_SHP_PROTOCOL|DPS_SHP_PROXY);
00151 _DlgMgr.OnDoModal (&sheet);
00152 sheet.DoModal ();
00153 _DlgMgr.OnEndDialog (&sheet);
00154 }
00155
00156 BOOL CUrlWithLoginDlg::UpdateDNP()
00157 {
00158 fsDownload_NetworkProperties *dnp = m_dld->pMgr->GetDownloadMgr ()->GetDNP ();
00159
00160 GetDlgItemText (IDC_URL, m_strUrl);
00161
00162 fsURL url;
00163 if (IR_SUCCESS != url.Crack (m_strUrl))
00164 {
00165 WrongURL ();
00166 return FALSE;
00167 }
00168
00169 if (fsDNP_ApplyUrl (dnp, m_strUrl) != IR_SUCCESS)
00170 {
00171 WrongURL ();
00172 return FALSE;
00173 }
00174
00175 return TRUE;
00176 }
00177
00178 void CUrlWithLoginDlg::WrongURL()
00179 {
00180 MessageBox (LS (L_CHECKURL), LS (L_INPERR), MB_ICONEXCLAMATION);
00181 GetDlgItem (IDC_URL)->SetFocus ();
00182 }