00001
00002
00003
00004
00005
00006 #include "stdafx.h"
00007 #include "FdmApp.h"
00008 #include "DownloaderProperties_BtPage.h"
00009 #include "vmsDialogHelper.h"
00010 #include "vmsTorrentExtension.h"
00011
00012 #ifdef _DEBUG
00013 #define new DEBUG_NEW
00014 #undef THIS_FILE
00015 static char THIS_FILE[] = __FILE__;
00016 #endif
00017
00018 IMPLEMENT_DYNCREATE(CDownloaderProperties_BtPage, CPropertyPage)
00019
00020 CDownloaderProperties_BtPage::CDownloaderProperties_BtPage() : CPropertyPage(CDownloaderProperties_BtPage::IDD)
00021 {
00022 m_psp.dwFlags |= PSP_USETITLE;
00023 m_psp.pszTitle = LS (L_BITTORRENT);
00024 m_bDontSetModif = false;
00025 }
00026
00027 CDownloaderProperties_BtPage::~CDownloaderProperties_BtPage()
00028 {
00029 }
00030
00031 void CDownloaderProperties_BtPage::DoDataExchange(CDataExchange* pDX)
00032 {
00033 CPropertyPage::DoDataExchange(pDX);
00034
00035 DDX_Control(pDX, IDC_LIMITDIM, m_wndLimitDim);
00036 DDX_Control(pDX, IDC_TRAFFICMODESTAB, m_tabTrafficModes);
00037
00038 }
00039
00040 BEGIN_MESSAGE_MAP(CDownloaderProperties_BtPage, CPropertyPage)
00041
00042 ON_NOTIFY(TCN_SELCHANGE, IDC_TRAFFICMODESTAB, OnSelchangeTrafficmodestab)
00043 ON_BN_CLICKED(IDC_LIMIT, OnLimit)
00044 ON_BN_CLICKED(IDC_LIMITUPLOADS, OnLimituploads)
00045 ON_BN_CLICKED(IDC_ENABLE, OnEnable)
00046 ON_EN_CHANGE(IDC_LIMITVAL, OnChangeLimitval)
00047 ON_CBN_SELCHANGE(IDC_LIMITDIM, OnSelchangeLimitdim)
00048 ON_EN_CHANGE(IDC_UPLLIMITVAL, OnChangeUpllimitval)
00049 ON_EN_CHANGE(IDC_PORT_FROM, OnChangePortFrom)
00050 ON_EN_CHANGE(IDC_PORT_TO, OnChangePortTo)
00051 ON_BN_CLICKED(IDC_USE_DHT, OnUseDht)
00052 ON_WM_CONTEXTMENU()
00053 ON_WM_HELPINFO()
00054 ON_COMMAND(ID_WHATISTHIS, OnWhatisthis)
00055 ON_BN_CLICKED(IDC_ASSOCWITHTORRENT, OnAssocwithtorrent)
00056 ON_BN_CLICKED(IDC_DISABLE_SEEDING, OnDisableSeeding)
00057
00058 END_MESSAGE_MAP()
00059
00060 BOOL CDownloaderProperties_BtPage::OnInitDialog()
00061 {
00062 CPropertyPage::OnInitDialog();
00063
00064 m_tabTrafficModes.InsertItem (0, LS (L_LIGHT));
00065 m_tabTrafficModes.InsertItem (1, LS (L_MEDIUM));
00066 m_tabTrafficModes.InsertItem (2, LS (L_HEAVY));
00067 m_iOldMode = 0;
00068
00069 CString str;
00070 str.Format ("%s/%s", LS (L_B), LS (L_S)); m_wndLimitDim.AddString (str);
00071 str.Format ("%s/%s", LS (L_KB), LS (L_S)); m_wndLimitDim.AddString (str);
00072 str.Format ("%s/%s", LS (L_MB), LS (L_S)); m_wndLimitDim.AddString (str);
00073 m_wndLimitDim.SetCurSel (0);
00074
00075 UINT aSpinIds [] = {
00076 IDC_UPLLIMITVALSPIN, IDC_PORT_FROM_SPIN, IDC_PORT_TO_SPIN
00077 };
00078 for (int i = 0; i < sizeof (aSpinIds) / sizeof (UINT); i++)
00079 {
00080 CSpinButtonCtrl *pSpin = (CSpinButtonCtrl*) GetDlgItem (aSpinIds [i]);
00081 pSpin->SetRange (1, UD_MAXVAL);
00082 }
00083
00084 for (i = 0; i < 3; i++)
00085 {
00086 m_vModes.push_back (
00087 _inc_ModeStgs (_App.Bittorrent_UploadTrafficLimit (i),
00088 _App.Bittorrent_UploadConnectionLimit (i)));
00089 }
00090 SetDlgItemInt (IDC_UPLLIMITVAL, 1);
00091 ModeToDlg ();
00092
00093 CheckDlgButton (IDC_ENABLE,
00094 _App.Bittorrent_Enable () ? BST_CHECKED : BST_UNCHECKED);
00095
00096 SetDlgItemInt (IDC_PORT_FROM, _App.Bittorrent_ListenPort_From ());
00097 SetDlgItemInt (IDC_PORT_TO, _App.Bittorrent_ListenPort_To ());
00098
00099 CheckDlgButton (IDC_USE_DHT,
00100 _App.Bittorrent_EnableDHT () ? BST_CHECKED : BST_UNCHECKED);
00101
00102 CheckDlgButton (IDC_ASSOCWITHTORRENT,
00103 vmsTorrentExtension::IsAssociatedWithUs () ? BST_CHECKED : BST_UNCHECKED);
00104
00105 CheckDlgButton (IDC_DISABLE_SEEDING,
00106 _App.Bittorrent_DisableSeedingByDef () ? BST_CHECKED : BST_UNCHECKED);
00107
00108 ApplyLanguage ();
00109
00110 UpdateEnabled ();
00111
00112 return TRUE;
00113 }
00114
00115 BOOL CDownloaderProperties_BtPage::OnApply()
00116 {
00117 BOOL bEn = IsDlgButtonChecked (IDC_ENABLE) == BST_CHECKED;
00118 _App.Bittorrent_Enable (bEn);
00119
00120 BOOL bAssoc = IsDlgButtonChecked (IDC_ASSOCWITHTORRENT) == BST_CHECKED;
00121
00122 if (bAssoc == FALSE && vmsTorrentExtension::IsAssociatedWithUs ())
00123 {
00124 vmsTorrentExtension::AssociateWith (_App.Bittorrent_OldTorrentAssociation ());
00125 }
00126 else if (bAssoc && vmsTorrentExtension::IsAssociatedWithUs () == FALSE)
00127 {
00128 _App.Bittorrent_OldTorrentAssociation (vmsTorrentExtension::GetCurrentAssociation ());
00129 vmsTorrentExtension::Associate ();
00130 }
00131
00132 if (bEn == FALSE)
00133 return CPropertyPage::OnApply ();
00134
00135 DlgToMode (m_iOldMode);
00136
00137 for (size_t i = 0; i < m_vModes.size (); i++)
00138 {
00139 _App.Bittorrent_UploadTrafficLimit (i, m_vModes [i].iUplTrafLim);
00140 _App.Bittorrent_UploadConnectionLimit (i, m_vModes [i].iUplConnLim);
00141 }
00142
00143 int portFrom = GetDlgItemInt (IDC_PORT_FROM);
00144 int portTo = GetDlgItemInt (IDC_PORT_TO);
00145 if (portFrom > portTo)
00146 {
00147 int t = portFrom;
00148 portFrom = portTo;
00149 portTo = t;
00150 }
00151 _App.Bittorrent_ListenPort_From (portFrom);
00152 _App.Bittorrent_ListenPort_To (portTo);
00153 _BT.ApplyListenPortSettings ();
00154
00155 _App.Bittorrent_EnableDHT (IsDlgButtonChecked (IDC_USE_DHT) == BST_CHECKED);
00156 _BT.ApplyDHTSettings ();
00157
00158 _App.Bittorrent_DisableSeedingByDef (IsDlgButtonChecked (IDC_DISABLE_SEEDING) == BST_CHECKED);
00159
00160 return CPropertyPage::OnApply();
00161 }
00162
00163 void CDownloaderProperties_BtPage::OnSelchangeTrafficmodestab(NMHDR* pNMHDR, LRESULT* pResult)
00164 {
00165 DlgToMode (m_iOldMode);
00166 m_iOldMode = m_tabTrafficModes.GetCurSel ();
00167 ModeToDlg ();
00168 *pResult = 0;
00169 }
00170
00171 void CDownloaderProperties_BtPage::ModeToDlg()
00172 {
00173 m_bDontSetModif = true;
00174
00175 int mode = m_tabTrafficModes.GetCurSel ();
00176
00177 if (m_vModes [mode].iUplTrafLim != -1)
00178 {
00179 vmsDialogHelper::SetDlgBytesGroup (this, m_vModes [mode].iUplTrafLim,
00180 IDC_LIMITVAL, IDC_LIMITDIM);
00181 CheckDlgButton (IDC_LIMIT, BST_CHECKED);
00182 }
00183 else
00184 {
00185 CheckDlgButton (IDC_LIMIT, BST_UNCHECKED);
00186 }
00187
00188 if (m_vModes [mode].iUplConnLim != -1)
00189 {
00190 SetDlgItemInt (IDC_UPLLIMITVAL, m_vModes [mode].iUplConnLim);
00191 CheckDlgButton (IDC_LIMITUPLOADS, BST_CHECKED);
00192 }
00193 else
00194 {
00195 CheckDlgButton (IDC_LIMITUPLOADS, BST_UNCHECKED);
00196 }
00197
00198 UpdateEnabled ();
00199
00200 m_bDontSetModif = false;
00201 }
00202
00203 void CDownloaderProperties_BtPage::DlgToMode(int mode)
00204 {
00205 if (IsDlgButtonChecked (IDC_LIMIT) == BST_CHECKED)
00206 {
00207 UINT64 u;
00208 vmsDialogHelper::GetDlgBytesGroup (this, IDC_LIMITVAL, IDC_LIMITDIM, &u);
00209 m_vModes [mode].iUplTrafLim = (int)u;
00210 }
00211 else
00212 m_vModes [mode].iUplTrafLim = -1;
00213
00214 if (IsDlgButtonChecked (IDC_LIMITUPLOADS) == BST_CHECKED)
00215 m_vModes [mode].iUplConnLim = GetDlgItemInt (IDC_UPLLIMITVAL);
00216 else
00217 m_vModes [mode].iUplConnLim = -1;
00218 }
00219
00220 void CDownloaderProperties_BtPage::UpdateEnabled()
00221 {
00222 BOOL b = IsDlgButtonChecked (IDC_ENABLE) == BST_CHECKED;
00223
00224 UINT aIDs [] = {
00225 IDC_TRAFFICMODESTAB, IDC_LIMIT, IDC_LIMITVAL, IDC_LIMITDIM,
00226 IDC_LIMITUPLOADS, IDC_UPLLIMITVAL, IDC_UPLLIMITVALSPIN,
00227 IDC__USEPORTS, IDC_PORT_FROM, IDC_PORT_FROM_SPIN, IDC__TO,
00228 IDC_PORT_TO, IDC_PORT_TO_SPIN, IDC_USE_DHT
00229 };
00230 for (int i = 0; i < sizeof (aIDs) / sizeof (UINT); i++)
00231 {
00232 GetDlgItem (aIDs [i])->EnableWindow (b);
00233 }
00234
00235 if (b == FALSE)
00236 return;
00237
00238 b = IsDlgButtonChecked (IDC_LIMIT) == BST_CHECKED;
00239 GetDlgItem (IDC_LIMITVAL)->EnableWindow (b);
00240 GetDlgItem (IDC_LIMITDIM)->EnableWindow (b);
00241
00242 b = IsDlgButtonChecked (IDC_LIMITUPLOADS) == BST_CHECKED;
00243 GetDlgItem (IDC_UPLLIMITVAL)->EnableWindow (b);
00244 GetDlgItem (IDC_UPLLIMITVALSPIN)->EnableWindow (b);
00245 }
00246
00247 void CDownloaderProperties_BtPage::OnLimit()
00248 {
00249 SetModified ();
00250 UpdateEnabled ();
00251 }
00252
00253 void CDownloaderProperties_BtPage::OnLimituploads()
00254 {
00255 SetModified ();
00256 UpdateEnabled ();
00257 }
00258
00259 void CDownloaderProperties_BtPage::OnEnable()
00260 {
00261 SetModified ();
00262 UpdateEnabled ();
00263 }
00264
00265 void CDownloaderProperties_BtPage::OnChangeLimitval()
00266 {
00267 if (m_bDontSetModif == false)
00268 SetModified ();
00269 }
00270
00271 void CDownloaderProperties_BtPage::OnSelchangeLimitdim()
00272 {
00273 if (m_bDontSetModif == false)
00274 SetModified ();
00275 }
00276
00277 void CDownloaderProperties_BtPage::OnChangeUpllimitval()
00278 {
00279 if (m_bDontSetModif == false)
00280 SetModified ();
00281 }
00282
00283 void CDownloaderProperties_BtPage::OnChangePortFrom()
00284 {
00285 SetModified ();
00286 }
00287
00288 void CDownloaderProperties_BtPage::OnChangePortTo()
00289 {
00290 SetModified ();
00291 }
00292
00293 void CDownloaderProperties_BtPage::OnUseDht()
00294 {
00295 SetModified ();
00296 }
00297
00298 void CDownloaderProperties_BtPage::ApplyLanguage()
00299 {
00300 fsDlgLngInfo lnginfo [] = {
00301 fsDlgLngInfo (IDC_ENABLE, L_ENABLEBTSUPPORT),
00302 fsDlgLngInfo (IDC_LIMIT, L_LIMIT_UPLOAD_TRAFFIC),
00303 fsDlgLngInfo (IDC_LIMITUPLOADS, L_LIMIT_UPLOAD_CONNECTIONS),
00304 fsDlgLngInfo (IDC__USEPORTS, L_USE_PORTS_IN_RANGE_FROM, TRUE),
00305 fsDlgLngInfo (IDC__TO, L_TO, TRUE),
00306 fsDlgLngInfo (IDC_USE_DHT, L_ENABLE_DHT),
00307 fsDlgLngInfo (IDC_ASSOCWITHTORRENT, L_ASSOCWITHTORRENT),
00308 fsDlgLngInfo (IDC_DISABLE_SEEDING, L_DISABLE_SEEDING_BYDEF),
00309 };
00310
00311 _LngMgr.ApplyLanguage ( this, lnginfo, sizeof (lnginfo) / sizeof (fsDlgLngInfo), 0);
00312 }
00313
00314 void CDownloaderProperties_BtPage::OnContextMenu(CWnd* , CPoint point)
00315 {
00316 PrepareCHMgr (point);
00317 _CHMgr.ShowMenu ();
00318 }
00319
00320 BOOL CDownloaderProperties_BtPage::OnHelpInfo(HELPINFO* pHelpInfo)
00321 {
00322 RECT rc;
00323 CWnd *pItem = GetDlgItem (pHelpInfo->iCtrlId);
00324 if (pItem == NULL)
00325 return TRUE;
00326 pItem->GetWindowRect (&rc);
00327 if (PtInRect (&rc, pHelpInfo->MousePos) == FALSE)
00328 {
00329 pHelpInfo->MousePos.x = rc.left + (rc.right - rc.left) / 2;
00330 pHelpInfo->MousePos.y = rc.top + (rc.bottom - rc.top) / 2;
00331 }
00332 PrepareCHMgr (pHelpInfo->MousePos);
00333 _CHMgr.OnWT ();
00334 return TRUE;
00335 }
00336
00337 void CDownloaderProperties_BtPage::OnWhatisthis()
00338 {
00339 _CHMgr.OnWT ();
00340 }
00341
00342 void CDownloaderProperties_BtPage::PrepareCHMgr(CPoint point)
00343 {
00344 fsCtrlContextHelp aCH1 [] = {
00345 fsCtrlContextHelp (IDC_ENABLE, LS (L_ENABLEBT_HERE)),
00346 fsCtrlContextHelp (IDC_LIMIT, LS (L_LIMITUPLOADTRAF_HERE)),
00347 fsCtrlContextHelp (IDC_LIMITVAL, LS (L_LIMITUPLOADTRAF_HERE)),
00348 fsCtrlContextHelp (IDC_LIMITDIM, LS (L_DIMHERE)),
00349 fsCtrlContextHelp (IDC_LIMITUPLOADS, LS (L_LIMITUPLOADCONNS_HERE)),
00350 fsCtrlContextHelp (IDC_UPLLIMITVAL, LS (L_LIMITUPLOADCONNS_HERE)),
00351 fsCtrlContextHelp (IDC__USEPORTS, LS (L_BT_USEPORTSINRANGE_HERE)),
00352 fsCtrlContextHelp (IDC_PORT_FROM, LS (L_BT_USEPORTSINRANGE_HERE)),
00353 fsCtrlContextHelp (IDC__TO, LS (L_BT_USEPORTSINRANGE_HERE)),
00354 fsCtrlContextHelp (IDC_PORT_TO, LS (L_BT_USEPORTSINRANGE_HERE)),
00355 fsCtrlContextHelp (IDC_USE_DHT, LS (L_ENABLEDHT_HERE)),
00356 };
00357
00358 static fsCtrlContextHelp aCH [sizeof (aCH1) / sizeof (fsCtrlContextHelp)];
00359 CopyMemory (aCH, aCH1, sizeof (aCH));
00360
00361 _CHMgr.PrepareContextMenu (this, point, aCH, sizeof (aCH) / sizeof (fsCtrlContextHelp));
00362 }
00363
00364 void CDownloaderProperties_BtPage::OnAssocwithtorrent()
00365 {
00366 SetModified ();
00367 }
00368
00369 void CDownloaderProperties_BtPage::OnDisableSeeding()
00370 {
00371 SetModified ();
00372 }