00001
00002
00003
00004
00005
00006 #include "stdafx.h"
00007 #include "FdmApp.h"
00008 #include "DownloadProperties_GeneralPage.h"
00009 #include "DownloadProperties.h"
00010 #include "misc.h"
00011 #include "DownloadsWnd.h"
00012 #include "fsDownloadMgr.h"
00013 #include "system.h"
00014 #include "DownloadsWnd.h"
00015 #include "CreateDownloadDlg.h"
00016
00017 extern CDownloadsWnd* _pwndDownloads;
00018
00019 #ifdef _DEBUG
00020 #define new DEBUG_NEW
00021 #undef THIS_FILE
00022 static char THIS_FILE[] = __FILE__;
00023 #endif
00024
00025 IMPLEMENT_DYNCREATE(CDownloadProperties_GeneralPage, CPropertyPage)
00026
00027 CDownloadProperties_GeneralPage::CDownloadProperties_GeneralPage() : CPropertyPage(CDownloadProperties_GeneralPage::IDD)
00028 {
00029 m_psp.dwFlags |= PSP_USETITLE;
00030 m_psp.pszTitle = LS (L_GENERAL);
00031 }
00032
00033 CDownloadProperties_GeneralPage::~CDownloadProperties_GeneralPage()
00034 {
00035 }
00036
00037 void CDownloadProperties_GeneralPage::DoDataExchange(CDataExchange* pDX)
00038 {
00039 CPropertyPage::DoDataExchange(pDX);
00040
00041 DDX_Control(pDX, IDC_GROUPS, m_wndGroups);
00042
00043 }
00044
00045 BEGIN_MESSAGE_MAP(CDownloadProperties_GeneralPage, CPropertyPage)
00046
00047 ON_CBN_SELCHANGE(IDC_GROUPS, OnSelchangeGroups)
00048 ON_EN_CHANGE(IDC_COMMENT, OnChangeComment)
00049 ON_EN_CHANGE(IDC_URL, OnChangeUrl)
00050 ON_EN_CHANGE(IDC_SAVEAS, OnChangeSaveas)
00051 ON_WM_CONTEXTMENU()
00052 ON_COMMAND(ID_WHATISTHIS, OnWhatisthis)
00053 ON_BN_CLICKED(IDC_USELOGIN, OnUselogin)
00054 ON_EN_CHANGE(IDC_USER, OnChangeUser)
00055 ON_EN_CHANGE(IDC_PASSWORD, OnChangePassword)
00056 ON_WM_HELPINFO()
00057
00058 END_MESSAGE_MAP()
00059
00060 #define DNP_OFFSET(member) ( LPBYTE (&dnp.member) - LPBYTE (&dnp) )
00061 #define DNP_SIZEOF(member) ( sizeof (dnp.member) )
00062 #define DNP_EQ(member, bString) DNPEntry_IsAllEqual (m_pvDlds, DNP_OFFSET (member), DNP_SIZEOF (member), bString)
00063 #define DNP_SET(member, bString, NewVal) DNPEntry_SetValue (m_pvDlds, DNP_OFFSET (member), DNP_SIZEOF (member), bString, NewVal);
00064
00065 #define DP_OFFSET(member) ( LPBYTE (&dp.member) - LPBYTE (&dp) )
00066 #define DP_SIZEOF(member) ( sizeof (dp.member) )
00067 #define DP_EQ_EX(memOffset, memSize, bString) DPEntry_IsAllEqual (m_pvDlds, memOffset, memSize, bString)
00068 #define DP_EQ_MASK(member, mask) DPEntry_IsAllEqual_BitMask (m_pvDlds, DP_OFFSET (member), mask)
00069 #define DP_SET_MASK(member, mask) DPEntry_SetValue_BitMask (m_pvDlds, DP_OFFSET (member), mask)
00070 #define DP_UNSET_MASK(member, mask) DPEntry_UnsetValue_BitMask (m_pvDlds, DP_OFFSET (member), mask)
00071
00072 BOOL CDownloadProperties_GeneralPage::OnInitDialog()
00073 {
00074 CPropertyPage::OnInitDialog();
00075
00076 const vmsDownloadSmartPtr dld0 = m_pvDlds->at (0);
00077 const fsDownload_NetworkProperties *dnp0 = dld0->pMgr->GetDownloadMgr ()->GetDNP ();
00078
00079 const int size = m_pvDlds->size ();
00080
00081 if (size == 1)
00082 {
00083 fsURL url;
00084 CHAR szUrl [10000];
00085 DWORD dwLen = sizeof (szUrl);
00086
00087 url.Create (fsNPToScheme (dnp0->enProtocol), dnp0->pszServerName, dnp0->uServerPort,
00088 NULL, NULL, dnp0->pszPathName, szUrl, &dwLen);
00089
00090 SetDlgItemText (IDC_URL, szUrl);
00091 SetDlgItemText (IDC_SAVEAS, m_pvDlds->at (0)->pMgr->GetDownloadMgr ()->GetDP ()->pszFileName);
00092
00093 m_strUrl = szUrl;
00094 }
00095 else
00096 {
00097 GetDlgItem (IDC_URL)->EnableWindow (FALSE);
00098 GetDlgItem (IDC_SAVEAS)->EnableWindow (FALSE);
00099 GetDlgItem (IDC__GENERAL)->EnableWindow (FALSE);
00100 GetDlgItem (IDC__URL)->EnableWindow (FALSE);
00101 GetDlgItem (IDC__SAVEDAS)->EnableWindow (FALSE);
00102 }
00103
00104 m_wndGroups.Fill ();
00105
00106 for (int i = 1; i < size; i++)
00107 {
00108 if (dld0->pGroup->nId != m_pvDlds->at (i)->pGroup->nId)
00109 break;
00110 }
00111
00112 if (i == size)
00113 m_wndGroups.SelectGroup (dld0->pGroup);
00114 else
00115 m_wndGroups.SelectGroup (NULL);
00116
00117 for (i = 1; i < size; i++)
00118 {
00119 if (dld0->strComment != m_pvDlds->at (i)->strComment)
00120 break;
00121 }
00122
00123 if (i == size)
00124 SetDlgItemText (IDC_COMMENT, dld0->strComment);
00125
00126 m_bCommentModified = FALSE;
00127 m_bNeedProcessDownloads = FALSE;
00128
00129 ReadAuthorization ();
00130
00131 ApplyLanguage ();
00132
00133 return TRUE;
00134 }
00135
00136 void CDownloadProperties_GeneralPage::OnSelchangeGroups()
00137 {
00138 SetModified ();
00139 }
00140
00141 void CDownloadProperties_GeneralPage::OnChangeComment()
00142 {
00143 m_bCommentModified = TRUE;
00144 SetModified ();
00145 }
00146
00147 BOOL CDownloadProperties_GeneralPage::OnApply()
00148 {
00149 const int size = m_pvDlds->size ();
00150
00151 if (size == 1)
00152 {
00153 CString strNewUrl;
00154 CString strNewFile;
00155 GetDlgItemText (IDC_URL, strNewUrl);
00156 GetDlgItemText (IDC_SAVEAS, strNewFile);
00157 if (FALSE == CCreateDownloadDlg::_CheckFolderName (this, IDC_SAVEAS))
00158 return FALSE;
00159
00160 if (strNewUrl != m_strUrl)
00161 {
00162 {
00163 fsURL url;
00164
00165 if (url.Crack (strNewUrl) != IR_SUCCESS ||
00166 (url.GetInternetScheme () != INTERNET_SCHEME_FILE && *url.GetHostName () == 0))
00167 {
00168 MessageBox (LS (L_CHECKURL), LS (L_INPERR), MB_ICONEXCLAMATION);
00169 ((CEdit*) GetDlgItem (IDC_URL))->SetSel (0, -1);
00170 GetDlgItem (IDC_URL)->SetFocus ();
00171 return FALSE;
00172 }
00173
00174 m_pvDlds->at (0)->pMgr->GetDownloadMgr ()->CreateByUrl (strNewUrl, TRUE);
00175 if (*m_pvDlds->at (0)->pMgr->GetDownloadMgr ()->GetDNP ()->pszUserName)
00176 ReadAuthorization ();
00177 }
00178 }
00179
00180 fsDownload_Properties *dp = m_pvDlds->at (0)->pMgr->GetDownloadMgr ()->GetDP ();
00181
00182 if (strNewFile != dp->pszFileName)
00183 {
00184 if (FALSE == m_pvDlds->at (0)->pMgr->GetDownloadMgr ()->MoveFile (strNewFile))
00185 {
00186 if (GetLastError () == 0)
00187 {
00188
00189 MessageBox (LS (L_CANTCHANGEFILENAME), LS (L_ERR), MB_ICONERROR);
00190 }
00191 else
00192 {
00193 CString strErr;
00194 CHAR szErr [1000];
00195
00196 fsErrorToStr (szErr, 1000);
00197
00198 strErr.Format ("%s\n\n%s: %s", LS (L_CANTRENAME), LS (L_ERR), szErr);
00199 MessageBox (strErr, LS (L_ERR), MB_ICONERROR);
00200 }
00201 }
00202 }
00203 }
00204
00205 _pwndDownloads->UpdateDownload (m_pvDlds->at (0), TRUE);
00206
00207 vmsDownloadsGroupSmartPtr pGroup = m_wndGroups.GetSelectedGroup ();
00208 if (pGroup != NULL)
00209 {
00210 for (int i = 0; i < size; i++)
00211 {
00212 if (m_pvDlds->at (i)->pGroup->nId != pGroup->nId)
00213 {
00214 m_pvDlds->at (i)->pGroup->cDownloads--;
00215 m_pvDlds->at (i)->pGroup = pGroup;
00216 pGroup->cDownloads++;
00217 m_pvDlds->at (i)->pMgr->GetDownloadMgr ()->MoveToFolder (pGroup->strOutFolder);
00218 }
00219 }
00220
00221 m_bNeedUpdateTasks = TRUE;
00222 _pwndDownloads->UpdateNumbersOfDownloadsInGroups ();
00223 }
00224 else
00225 m_bNeedUpdateTasks = FALSE;
00226
00227 if (m_bCommentModified)
00228 {
00229 CString strComment;
00230 GetDlgItemText (IDC_COMMENT, strComment);
00231
00232 for (int i = 0; i < size; i++)
00233 {
00234 m_pvDlds->at (i)->strComment = strComment;
00235 _pwndDownloads->UpdateDownload (m_pvDlds->at (i));
00236 }
00237
00238 m_bNeedUpdateTasks = TRUE;
00239 }
00240
00241 WriteAuthorization ();
00242
00243 return CPropertyPage::OnApply();
00244 }
00245
00246 void CDownloadProperties_GeneralPage::OnChangeUrl()
00247 {
00248 SetModified ();
00249 }
00250
00251 void CDownloadProperties_GeneralPage::OnChangeSaveas()
00252 {
00253 SetModified ();
00254 }
00255
00256 void CDownloadProperties_GeneralPage::OnContextMenu(CWnd* , CPoint point)
00257 {
00258 PrepareCHMgr (point);
00259 _CHMgr.ShowMenu ();
00260 }
00261
00262 void CDownloadProperties_GeneralPage::OnWhatisthis()
00263 {
00264 _CHMgr.OnWT ();
00265 }
00266
00267 void CDownloadProperties_GeneralPage::ApplyLanguage()
00268 {
00269 fsDlgLngInfo lnginfo [] = {
00270 fsDlgLngInfo (IDC__GENERAL, L_GENERALINFO),
00271 fsDlgLngInfo (IDC__USER, L_USER),
00272 fsDlgLngInfo (IDC__PASSWORD, L_PASSWORD),
00273 fsDlgLngInfo (IDC_USELOGIN, L_LOGINREQ),
00274 fsDlgLngInfo (IDC__SAVEDAS, L_SAVEDAS),
00275 fsDlgLngInfo (IDC__GROUP, L_GROUP),
00276 fsDlgLngInfo (IDC__COMMENT, L_COMMENT, TRUE),
00277 };
00278
00279 _LngMgr.ApplyLanguage (this, lnginfo, sizeof (lnginfo) / sizeof (fsDlgLngInfo), 0);
00280 }
00281
00282 void CDownloadProperties_GeneralPage::ReadAuthorization()
00283 {
00284 fsDownload_NetworkProperties dnp;
00285 fsDownload_NetworkProperties *dnp0 = m_pvDlds->at (0)->pMgr->GetDownloadMgr ()->GetDNP ();
00286
00287 if (DNP_EQ (pszUserName, TRUE))
00288 SetDlgItemText (IDC_USER, dnp0->pszUserName);
00289
00290 if (DNP_EQ (pszPassword, TRUE))
00291 SetDlgItemText (IDC_PASSWORD, dnp0->pszPassword);
00292
00293 BOOL bUse = dnp0->pszUserName [0] != 0;
00294 CheckDlgButton (IDC_USELOGIN, bUse ? BST_CHECKED : BST_UNCHECKED);
00295 for (int i = m_pvDlds->size () - 1; i > 0; i--)
00296 {
00297 BOOL bU = m_pvDlds->at (i)->pMgr->GetDownloadMgr ()->GetDNP ()->pszUserName [0] != 0;
00298
00299 if (bU != bUse)
00300 {
00301 CheckDlgButton (IDC_USELOGIN, BST_INDETERMINATE);
00302 break;
00303 }
00304 }
00305
00306 m_bUserChanged = m_bPasswordChanged = FALSE;
00307
00308 UpdateEnabled ();
00309 }
00310
00311 void CDownloadProperties_GeneralPage::UpdateEnabled()
00312 {
00313 BOOL bE = IsDlgButtonChecked (IDC_USELOGIN) == BST_CHECKED;
00314
00315 GetDlgItem (IDC_USER)->EnableWindow (bE);
00316 GetDlgItem (IDC_PASSWORD)->EnableWindow (bE);
00317 GetDlgItem (IDC__USER)->EnableWindow (bE);
00318 GetDlgItem (IDC__PASSWORD)->EnableWindow (bE);
00319 }
00320
00321 void CDownloadProperties_GeneralPage::OnUselogin()
00322 {
00323 if (IsDlgButtonChecked (IDC_USELOGIN) == BST_INDETERMINATE)
00324 CheckDlgButton (IDC_USELOGIN, BST_UNCHECKED);
00325
00326 UpdateEnabled ();
00327 SetModified ();
00328 }
00329
00330 void CDownloadProperties_GeneralPage::OnChangeUser()
00331 {
00332 SetModified ();
00333 m_bUserChanged = TRUE;
00334 }
00335
00336 void CDownloadProperties_GeneralPage::OnChangePassword()
00337 {
00338 SetModified ();
00339 m_bPasswordChanged = TRUE;
00340 }
00341
00342 void CDownloadProperties_GeneralPage::WriteAuthorization()
00343 {
00344 UINT nChecked = IsDlgButtonChecked (IDC_USELOGIN);
00345 fsDownload_NetworkProperties dnp;
00346 CString str;
00347
00348 switch (nChecked)
00349 {
00350 case BST_CHECKED:
00351 GetDlgItemText (IDC_USER, str);
00352 if (m_bUserChanged || str.GetLength ())
00353 DNP_SET (pszUserName, TRUE, str);
00354
00355 GetDlgItemText (IDC_PASSWORD, str);
00356 if (m_bPasswordChanged || str.GetLength ())
00357 DNP_SET (pszPassword, TRUE, str);
00358 break;
00359
00360 case BST_UNCHECKED:
00361 DNP_SET (pszUserName, TRUE, "");
00362 DNP_SET (pszPassword, TRUE, "");
00363 break;
00364 }
00365 }
00366
00367 BOOL CDownloadProperties_GeneralPage::OnHelpInfo(HELPINFO* pHelpInfo)
00368 {
00369 RECT rc;
00370 CWnd *pItem = GetDlgItem (pHelpInfo->iCtrlId);
00371 if (pItem == NULL)
00372 return TRUE;
00373 pItem->GetWindowRect (&rc);
00374 if (PtInRect (&rc, pHelpInfo->MousePos) == FALSE)
00375 {
00376 pHelpInfo->MousePos.x = rc.left + (rc.right - rc.left) / 2;
00377 pHelpInfo->MousePos.y = rc.top + (rc.bottom - rc.top) / 2;
00378 }
00379 PrepareCHMgr (pHelpInfo->MousePos);
00380 _CHMgr.OnWT ();
00381 return TRUE;
00382 }
00383
00384 void CDownloadProperties_GeneralPage::PrepareCHMgr(CPoint point)
00385 {
00386 fsCtrlContextHelp aCH1 [] = {
00387 fsCtrlContextHelp (IDC__URL, LS (L_ADDROFFILE)),
00388 fsCtrlContextHelp (IDC_URL, LS (L_ADDROFFILE)),
00389 fsCtrlContextHelp (IDC__USER, LS (L_USERHERE)),
00390 fsCtrlContextHelp (IDC_USER, LS (L_USERHERE)),
00391 fsCtrlContextHelp (IDC__PASSWORD, LS (L_PWDHERE)),
00392 fsCtrlContextHelp (IDC_PASSWORD, LS (L_PWDHERE)),
00393 fsCtrlContextHelp (IDC_USELOGIN, LS (L_LOGINHERE)),
00394 fsCtrlContextHelp (IDC__SAVEDAS, LS (L_SAVEDASHERE)),
00395 fsCtrlContextHelp (IDC_SAVEAS, LS (L_SAVEDASHERE)),
00396 fsCtrlContextHelp (IDC__GROUP, LS (L_GROUPHERE)),
00397 fsCtrlContextHelp (IDC_GROUPS, LS (L_GROUPHERE)),
00398 fsCtrlContextHelp (IDC__COMMENT, LS (L_DLDSHORTDESC)),
00399 fsCtrlContextHelp (IDC_COMMENT, LS (L_DLDSHORTDESC)),
00400
00401 };
00402
00403 static fsCtrlContextHelp aCH [sizeof (aCH1) / sizeof (fsCtrlContextHelp)];
00404 CopyMemory (aCH, aCH1, sizeof (aCH));
00405
00406 _CHMgr.PrepareContextMenu (this, point, aCH, sizeof (aCH) / sizeof (fsCtrlContextHelp));
00407 }
00408