00001
00002
00003
00004
00005
00006 #include "stdafx.h"
00007 #include "FdmApp.h"
00008 #include "CreateDownloadFromTorrentFileDlg.h"
00009 #include "FolderBrowser.h"
00010 #include "CreateDownloadDlg.h"
00011 #include "ScheduleSheet.h"
00012 #include "BtDldSheet.h"
00013 #include "mfchelp.h"
00014
00015 #ifdef _DEBUG
00016 #define new DEBUG_NEW
00017 #undef THIS_FILE
00018 static char THIS_FILE[] = __FILE__;
00019 #endif
00020
00021 CCreateDownloadFromTorrentFileDlg::CCreateDownloadFromTorrentFileDlg(CWnd* pParent )
00022 : CDialog(CCreateDownloadFromTorrentFileDlg::IDD, pParent)
00023 {
00024
00025 m_strTorrentFile = _T("");
00026
00027
00028 m_bScheduled = FALSE;
00029 m_bPlaceToTop = FALSE;
00030 }
00031
00032 void CCreateDownloadFromTorrentFileDlg::DoDataExchange(CDataExchange* pDX)
00033 {
00034 CDialog::DoDataExchange(pDX);
00035
00036 DDX_Control(pDX, IDC_GROUPS, m_wndGroups);
00037 DDX_Control(pDX, IDC_SETTIME, m_btnSetTime);
00038 DDX_Control(pDX, IDC_OUTFOLDER_SETDEFAULT, m_btnSetDefaultFolder);
00039 DDX_Control(pDX, IDC_CREATEGROUP, m_btnCreateGroup);
00040 DDX_Control(pDX, IDC_CHOOSEFOLDER, m_btnChooseFolder);
00041 DDX_Text(pDX, IDC_TORRENTFILE, m_strTorrentFile);
00042
00043 }
00044
00045 BEGIN_MESSAGE_MAP(CCreateDownloadFromTorrentFileDlg, CDialog)
00046
00047 ON_BN_CLICKED(IDC_USELOGIN, OnUselogin)
00048 ON_BN_CLICKED(IDC_CREATEGROUP, OnCreategroup)
00049 ON_BN_CLICKED(IDC_CHOOSEFOLDER, OnChoosefolder)
00050 ON_BN_CLICKED(IDC_OUTFOLDER_SETDEFAULT, OnOutfolderSetdefault)
00051 ON_BN_CLICKED(IDC_SETTIME, OnSettime)
00052 ON_BN_CLICKED(IDC_ADVANCED, OnAdvanced)
00053
00054 END_MESSAGE_MAP()
00055
00056 BOOL CCreateDownloadFromTorrentFileDlg::OnInitDialog()
00057 {
00058 CDialog::OnInitDialog();
00059
00060 m_btnChooseFolder.SetIcon (SICO (IDI_CHOOSEFOLDER));
00061 m_btnCreateGroup.SetIcon (SICO (IDI_CREATEGROUP));
00062 m_btnSetTime.SetIcon (SICO (IDI_SETTIME));
00063 m_btnSetDefaultFolder.SetIcon (SICO (IDI_SETFOLDERDEFAULT));
00064
00065 m_task.hts.enType = HTS_ONCE;
00066 m_task.hts.last.dwHighDateTime = m_task.hts.last.dwLowDateTime = UINT_MAX;
00067 m_task.dwFlags = SCHEDULE_ENABLED;
00068 SYSTEMTIME time;
00069 GetLocalTime (&time);
00070 if (++time.wHour > 23)
00071 time.wHour = 0;
00072 time.wMinute = 0;
00073 SystemTimeToFileTime (&time, &m_task.hts.next);
00074 m_task.uWaitForConfirmation = 0;
00075
00076 m_wndGroups.Fill ();
00077
00078 CComboBox *pDirs = (CComboBox*) GetDlgItem (IDC_OUTFOLDER);
00079 for (int i = 0; i < _LastFolders.GetRecordCount (); i++)
00080 pDirs->AddString (_LastFolders.GetRecord (i));
00081
00082 CheckRadioButton (IDC_STARTNOW, IDC_STARTSCHEDULE, IDC_STARTNOW);
00083
00084 if (FALSE == m_wndGroups.SelectGroupById (_App.NewDL_GroupId ()))
00085 {
00086 vmsDownloadsGroupSmartPtr pGrp = _DldsGrps.FindGroupByExt ("torrent");
00087 if (pGrp != NULL)
00088 m_wndGroups.SelectGroup (pGrp);
00089 else
00090 m_wndGroups.SelectGroupById (GRP_OTHER_ID);
00091 }
00092
00093 pDirs->SetWindowText (m_wndGroups.GetSelectedGroup ()->strOutFolder);
00094
00095 UINT nAS = _App.Last_Autostart ();
00096 if (nAS == 0)
00097 nAS = IDC_STARTNOW;
00098 else
00099 nAS = nAS == 1 ? IDC_STARTMANUAL : IDC_STARTSCHEDULE;
00100 CheckRadioButton (IDC_STARTNOW, IDC_STARTSCHEDULE, nAS);
00101
00102 ApplyLanguage ();
00103
00104 UpdateEnabled ();
00105
00106 mfcSetForegroundWindow (this);
00107
00108 return TRUE;
00109
00110 }
00111
00112 void CCreateDownloadFromTorrentFileDlg::ApplyLanguage()
00113 {
00114 fsDlgLngInfo lnginfo [] = {
00115 fsDlgLngInfo (IDC_USELOGIN, L_TRACKERLOGINREQ),
00116 fsDlgLngInfo (IDC__USER, L_USER),
00117 fsDlgLngInfo (IDC__PASSWORD, L_PASSWORD),
00118 fsDlgLngInfo (IDC__SAVETO, L_SAVETO),
00119 fsDlgLngInfo (IDC__START, L_START),
00120 fsDlgLngInfo (IDC_STARTNOW, L_AUTOMATICALLY),
00121 fsDlgLngInfo (IDC_STARTMANUAL, L_MANUALLY),
00122 fsDlgLngInfo (IDC_STARTSCHEDULE, L_SCHEDULE),
00123 fsDlgLngInfo (IDC__GROUP, L_GROUP),
00124 fsDlgLngInfo (IDC_ADVANCED, L_ADVANCED),
00125 fsDlgLngInfo (IDCANCEL, L_CANCEL),
00126 fsDlgLngInfo (IDC_PLACEATTOP, L_PLACEDLDATTOP),
00127 fsDlgLngInfo (IDC__COMMENT, L_COMMENT, TRUE),
00128 fsDlgLngInfo (IDC__FILE, L_TORRENTFILE, TRUE),
00129 };
00130
00131 _LngMgr.ApplyLanguage (this, lnginfo, sizeof (lnginfo) / sizeof (fsDlgLngInfo), L_CREATENEWTORRENTDLD);
00132 }
00133
00134 void CCreateDownloadFromTorrentFileDlg::OnUselogin()
00135 {
00136 UpdateEnabled ();
00137 }
00138
00139 void CCreateDownloadFromTorrentFileDlg::UpdateEnabled()
00140 {
00141 BOOL bE = IsDlgButtonChecked (IDC_USELOGIN) == BST_CHECKED;
00142
00143 GetDlgItem (IDC_USER)->EnableWindow (bE);
00144 GetDlgItem (IDC_PASSWORD)->EnableWindow (bE);
00145 GetDlgItem (IDC__USER)->EnableWindow (bE);
00146 GetDlgItem (IDC__PASSWORD)->EnableWindow (bE);
00147 }
00148
00149 void CCreateDownloadFromTorrentFileDlg::OnCreategroup()
00150 {
00151 if (m_wndGroups.CreateNewGroup (m_wndGroups.GetSelectedGroup ()))
00152 {
00153 GetDlgItem (IDC_OUTFOLDER)->SetWindowText (m_wndGroups.GetSelectedGroup ()->strOutFolder);
00154 }
00155 }
00156
00157 void CCreateDownloadFromTorrentFileDlg::OnChoosefolder()
00158 {
00159 CString str = "";
00160 GetDlgItemText (IDC_OUTFOLDER, str);
00161
00162 if (str.GetLength () > 3 && (str [str.GetLength () - 1] == '\\' || str [str.GetLength () - 1] == '/'))
00163 str.GetBuffer (0) [str.GetLength () - 1] = 0;
00164
00165 CFolderBrowser *fb = CFolderBrowser::Create (LS (L_CHOOSEOUTFOLDER), str, NULL, this);
00166 if (fb == NULL)
00167 return;
00168
00169 SetDlgItemText (IDC_OUTFOLDER, fb->GetPath ());
00170 GetDlgItem (IDC_OUTFOLDER)->SetFocus ();
00171 }
00172
00173 void CCreateDownloadFromTorrentFileDlg::OnOutfolderSetdefault()
00174 {
00175 CString strOutFolder;
00176 GetDlgItemText (IDC_OUTFOLDER, strOutFolder);
00177
00178 CCreateDownloadDlg::_SetDownloadOutputFolderAsDefault (this, strOutFolder, m_wndGroups.GetSelectedGroup ());
00179 }
00180
00181 void CCreateDownloadFromTorrentFileDlg::OnSettime()
00182 {
00183 CScheduleSheet sheet (LS (L_SCHEDULEDLDS), this);
00184
00185 sheet.Init (&m_task, FALSE);
00186
00187 if (IDOK == _DlgMgr.DoModal (&sheet))
00188 {
00189 CheckRadioButton (IDC_STARTNOW, IDC_STARTSCHEDULE, IDC_STARTSCHEDULE);
00190 }
00191
00192 GetDlgItem (IDC_STARTSCHEDULE)->SetFocus ();
00193 }
00194
00195 void CCreateDownloadFromTorrentFileDlg::OnAdvanced()
00196 {
00197 CBtDldSheet sheet (LS (L_ADVANCED), this);
00198 DLDS_LIST v;
00199 v.push_back (m_dld);
00200 sheet.Init (&v, BTDS_MISC_PAGE);
00201 _DlgMgr.DoModal (&sheet);
00202 }
00203
00204 void CCreateDownloadFromTorrentFileDlg::OnOK()
00205 {
00206 vmsBtDownloadManager *pMgr = m_dld->pMgr->GetBtDownloadMgr ();
00207
00208 if (IsDlgButtonChecked (IDC_USELOGIN) == BST_CHECKED)
00209 {
00210 CString strUser, strPwd;
00211 GetDlgItemText (IDC_USER, strUser);
00212 GetDlgItemText (IDC_PASSWORD, strPwd);
00213 pMgr->set_TrackerLogin (strUser, strPwd);
00214 }
00215
00216 CString strOutFolder;
00217 GetDlgItemText (IDC_OUTFOLDER, strOutFolder);
00218 fsPathToGoodPath ((LPSTR)(LPCSTR)strOutFolder);
00219
00220 if (FALSE == CCreateDownloadDlg::_CheckFolderName (this, IDC_OUTFOLDER))
00221 return;
00222
00223 if (strOutFolder.GetLength () == 0)
00224 {
00225 MessageBox (LS (L_ENTERFLRNAME), LS (L_INPERR), MB_ICONEXCLAMATION);
00226 GetDlgItem (IDC_OUTFOLDER)->SetFocus ();
00227 return;
00228 }
00229
00230 _LastFolders.AddRecord (strOutFolder);
00231
00232 if (strOutFolder [strOutFolder.GetLength () - 1] != '\\' &&
00233 strOutFolder [strOutFolder.GetLength () - 1] != '/')
00234 strOutFolder += '\\';
00235
00236 if (_App.NewGrp_SelectWay () == NGSW_USE_ALWAYS_SAME_GROUP_WITH_OUTFOLDER_AUTO_UPDATE)
00237 {
00238 vmsDownloadsGroupSmartPtr pGrp = _DldsGrps.FindGroup (_App.NewDL_GroupId ());
00239 if (pGrp != NULL)
00240 pGrp->strOutFolder = strOutFolder;
00241 }
00242
00243 CString strUrl = "file://"; strUrl += m_strTorrentFile;
00244
00245 if (FALSE == pMgr->CreateByTorrentFile (m_strTorrentFile, strOutFolder, strUrl))
00246 {
00247 MessageBox (LS (L_FAILEDTOADDTHISTORRENT), LS (L_ERR), MB_ICONERROR);
00248 EndDialog (IDCANCEL);
00249 return;
00250 }
00251
00252 m_dld->pGroup = m_wndGroups.GetSelectedGroup ();
00253
00254 GetDlgItemText (IDC_COMMENT, m_dld->strComment);
00255 fsString strComment = pMgr->get_TorrentComment ();
00256 if (strComment.IsEmpty () == FALSE)
00257 {
00258 if (m_dld->strComment.IsEmpty () == FALSE)
00259 m_dld->strComment += "\r\n";
00260 m_dld->strComment += strComment;
00261 }
00262
00263 m_bScheduled = IsDlgButtonChecked (IDC_STARTSCHEDULE) == BST_CHECKED;
00264 m_dld->bAutoStart = IsDlgButtonChecked (IDC_STARTNOW) == BST_CHECKED;
00265
00266 m_bPlaceToTop = IsDlgButtonChecked (IDC_PLACEATTOP) == BST_CHECKED;
00267
00268 m_wndGroups.RememberSelectedGroup ();
00269 if (m_dld->bAutoStart)
00270 _App.Last_Autostart (0);
00271 else
00272 _App.Last_Autostart (m_bScheduled ? 2 : 1);
00273
00274 CDialog::OnOK();
00275 }