00001
00002
00003
00004
00005
00006 #include "stdafx.h"
00007 #include "FdmApp.h"
00008 #include "BtDld_General.h"
00009 #include "FolderBrowser.h"
00010
00011 #ifdef _DEBUG
00012 #define new DEBUG_NEW
00013 #undef THIS_FILE
00014 static char THIS_FILE[] = __FILE__;
00015 #endif
00016
00017 IMPLEMENT_DYNCREATE(CBtDld_General, CPropertyPage)
00018
00019 CBtDld_General::CBtDld_General() : CPropertyPage(CBtDld_General::IDD)
00020 {
00021
00022
00023
00024 m_psp.dwFlags |= PSP_USETITLE;
00025 m_psp.pszTitle = LS (L_GENERAL);
00026 m_bNeedUpdateTasks = FALSE;
00027 m_bCommentModified = FALSE;
00028 }
00029
00030 CBtDld_General::~CBtDld_General()
00031 {
00032 }
00033
00034 void CBtDld_General::DoDataExchange(CDataExchange* pDX)
00035 {
00036 CPropertyPage::DoDataExchange(pDX);
00037
00038 DDX_Control(pDX, IDC_CHOOSEFOLDER, m_btnChooseFolder);
00039 DDX_Control(pDX, IDC_GROUPS, m_wndGroups);
00040
00041 }
00042
00043 BEGIN_MESSAGE_MAP(CBtDld_General, CPropertyPage)
00044
00045 ON_BN_CLICKED(IDC_USELOGIN, OnUselogin)
00046 ON_EN_CHANGE(IDC_COMMENT, OnChangeComment)
00047 ON_BN_CLICKED(IDC_CHOOSEFOLDER, OnChoosefolder)
00048
00049 END_MESSAGE_MAP()
00050
00051 BOOL CBtDld_General::OnInitDialog()
00052 {
00053 CPropertyPage::OnInitDialog();
00054
00055 m_btnChooseFolder.SetIcon (SICO (IDI_CHOOSEFOLDER));
00056
00057 if (m_pvDlds->size () == 1)
00058 {
00059 SetDlgItemText (IDC_URL, m_pvDlds->at (0)->pMgr->GetBtDownloadMgr ()->get_TorrentUrl ());
00060 }
00061 else
00062 {
00063 GetDlgItem (IDC_URL)->EnableWindow (FALSE);
00064 GetDlgItem (IDC__GENERAL)->EnableWindow (FALSE);
00065 GetDlgItem (IDC__TORRENTURL)->EnableWindow (FALSE);
00066 }
00067
00068 m_wndGroups.Fill ();
00069
00070 vmsDownloadSmartPtr dld0 = m_pvDlds->at (0);
00071
00072 for (size_t i = 1; i < m_pvDlds->size (); i++)
00073 {
00074 if (dld0->pGroup->nId != m_pvDlds->at (i)->pGroup->nId)
00075 break;
00076 }
00077
00078 if (i == m_pvDlds->size ())
00079 m_wndGroups.SelectGroup (dld0->pGroup);
00080
00081 for (i = 1; i < m_pvDlds->size (); i++)
00082 {
00083 if (dld0->strComment != m_pvDlds->at (i)->strComment)
00084 break;
00085 }
00086
00087 if (i == m_pvDlds->size ())
00088 SetDlgItemText (IDC_COMMENT, dld0->strComment);
00089
00090 fsString strUser0, strPwd0;
00091 dld0->pMgr->GetBtDownloadMgr ()->get_TrackerLogin (strUser0, strPwd0);
00092 for (i = 1; i < m_pvDlds->size (); i++)
00093 {
00094 fsString strU, strP;
00095 m_pvDlds->at (i)->pMgr->GetBtDownloadMgr ()->get_TrackerLogin (strU, strP);
00096 if (strUser0 != strU || strPwd0 != strP)
00097 break;
00098 }
00099 if (i == m_pvDlds->size ())
00100 {
00101 CheckDlgButton (IDC_USELOGIN, strUser0.IsEmpty () ? BST_UNCHECKED : BST_CHECKED);
00102 SetDlgItemText (IDC_USER, strUser0);
00103 SetDlgItemText (IDC_PASSWORD, strPwd0);
00104 }
00105 else
00106 {
00107 CheckDlgButton (IDC_USELOGIN, BST_INDETERMINATE);
00108 }
00109
00110 ReadSavedIn ();
00111
00112 UpdateEnabled ();
00113
00114 ApplyLanguage ();
00115
00116 return TRUE;
00117 }
00118
00119 void CBtDld_General::UpdateEnabled()
00120 {
00121 BOOL bE = IsDlgButtonChecked (IDC_USELOGIN) == BST_CHECKED;
00122
00123 GetDlgItem (IDC_USER)->EnableWindow (bE);
00124 GetDlgItem (IDC_PASSWORD)->EnableWindow (bE);
00125 GetDlgItem (IDC__USER)->EnableWindow (bE);
00126 GetDlgItem (IDC__PASSWORD)->EnableWindow (bE);
00127 }
00128
00129 void CBtDld_General::OnUselogin()
00130 {
00131 if (IsDlgButtonChecked (IDC_USELOGIN) == BST_INDETERMINATE)
00132 CheckDlgButton (IDC_USELOGIN, BST_UNCHECKED);
00133
00134 UpdateEnabled ();
00135 }
00136
00137 BOOL CBtDld_General::OnApply()
00138 {
00139 vmsDownloadsGroupSmartPtr pGroup = m_wndGroups.GetSelectedGroup ();
00140 if (pGroup != NULL)
00141 {
00142 for (size_t i = 0; i < m_pvDlds->size (); i++)
00143 {
00144 if (m_pvDlds->at (i)->pGroup->nId != pGroup->nId)
00145 {
00146 m_pvDlds->at (i)->pGroup->cDownloads--;
00147 m_pvDlds->at (i)->pGroup = pGroup;
00148 pGroup->cDownloads++;
00149 m_pvDlds->at (i)->pMgr->MoveToFolder (pGroup->strOutFolder);
00150 }
00151 }
00152
00153 m_bNeedUpdateTasks = TRUE;
00154 _pwndDownloads->UpdateNumbersOfDownloadsInGroups ();
00155 }
00156 else
00157 m_bNeedUpdateTasks = FALSE;
00158
00159 if (m_bCommentModified)
00160 {
00161 CString strComment;
00162 GetDlgItemText (IDC_COMMENT, strComment);
00163
00164 for (size_t i = 0; i < m_pvDlds->size (); i++)
00165 {
00166 m_pvDlds->at (i)->strComment = strComment;
00167 _pwndDownloads->UpdateDownload (m_pvDlds->at (i));
00168 }
00169
00170 m_bNeedUpdateTasks = TRUE;
00171 }
00172
00173 UINT u = IsDlgButtonChecked (IDC_USELOGIN);
00174 if (u != BST_INDETERMINATE)
00175 {
00176 CString strU, strP;
00177 if (u == BST_CHECKED)
00178 {
00179 GetDlgItemText (IDC_USER, strU);
00180 GetDlgItemText (IDC_PASSWORD, strP);
00181 }
00182 for (size_t i = 0; i < m_pvDlds->size (); i++)
00183 m_pvDlds->at (i)->pMgr->GetBtDownloadMgr ()->set_TrackerLogin (strU, strP);
00184 }
00185
00186 return CPropertyPage::OnApply();
00187 }
00188
00189 void CBtDld_General::OnChangeComment()
00190 {
00191 m_bCommentModified = TRUE;
00192 }
00193
00194 void CBtDld_General::OnChoosefolder()
00195 {
00196 CString str = "";
00197 GetDlgItemText (IDC_SAVEIN, str);
00198
00199 if ((GetFileAttributes (str) & FILE_ATTRIBUTE_DIRECTORY) == 0)
00200 {
00201 char sz [MY_MAX_PATH];
00202 fsGetPath (str, sz);
00203 str = sz;
00204 }
00205
00206 if (str.GetLength () > 3 &&
00207 (str [str.GetLength () - 1] == '\\' || str [str.GetLength () - 1] == '/'))
00208 {
00209 str.GetBuffer (0) [str.GetLength () - 1] = 0;
00210 str.ReleaseBuffer ();
00211 }
00212
00213 CFolderBrowser *fb = CFolderBrowser::Create (LS (L_CHOOSEOUTFOLDER), str, NULL, this);
00214 if (fb == NULL)
00215 return;
00216
00217 for (size_t i = 0; i < m_pvDlds->size (); i++)
00218 m_pvDlds->at (i)->pMgr->MoveToFolder (fb->GetPath ());
00219
00220 ReadSavedIn ();
00221 }
00222
00223 void CBtDld_General::ReadSavedIn()
00224 {
00225 vmsDownloadSmartPtr dld0 = m_pvDlds->at (0);
00226
00227 CString str0 = dld0->pMgr->get_OutputFilePathName ();
00228
00229 for (size_t i = 1; i < m_pvDlds->size (); i++)
00230 {
00231 if (str0 != m_pvDlds->at (i)->pMgr->get_OutputFilePathName ())
00232 break;
00233 }
00234
00235 if (i == m_pvDlds->size ())
00236 SetDlgItemText (IDC_SAVEIN, str0);
00237 }
00238
00239 void CBtDld_General::ApplyLanguage()
00240 {
00241 fsDlgLngInfo lnginfo [] = {
00242 fsDlgLngInfo (IDC__TORRENTURL, L_TORRENTFILEURL, TRUE),
00243 fsDlgLngInfo (IDC__GENERAL, L_GENERALINFO),
00244 fsDlgLngInfo (IDC__USER, L_USER),
00245 fsDlgLngInfo (IDC__PASSWORD, L_PASSWORD),
00246 fsDlgLngInfo (IDC_USELOGIN, L_LOGINREQ),
00247 fsDlgLngInfo (IDC__SAVEDIN, L_SAVEDAS),
00248 fsDlgLngInfo (IDC__GROUP, L_GROUP),
00249 fsDlgLngInfo (IDC__COMMENT, L_COMMENT, TRUE),
00250 };
00251
00252 _LngMgr.ApplyLanguage (this, lnginfo, sizeof (lnginfo) / sizeof (fsDlgLngInfo), 0);
00253 }