DlgDownloadSetup.cpp
上传用户:lds876
上传日期:2013-05-25
资源大小:567k
文件大小:7k
源码类别:

P2P编程

开发平台:

Visual C++

  1. // DlgDownloadSetup.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. #include "testbt.h"
  5. #include "DlgDownloadSetup.h"
  6. #include "FileBase.h"
  7. #ifdef _DEBUG
  8. #define new DEBUG_NEW
  9. #undef THIS_FILE
  10. static char THIS_FILE[] = __FILE__;
  11. #endif
  12. /////////////////////////////////////////////////////////////////////////////
  13. // CDlgDownloadSetup dialog
  14. CDlgDownloadSetup::CDlgDownloadSetup(CWnd* pParent /*=NULL*/)
  15. : CPropertyPage(CDlgDownloadSetup::IDD)
  16. {
  17. //{{AFX_DATA_INIT(CDlgDownloadSetup)
  18. //}}AFX_DATA_INIT
  19. // m_bCompleteKeepSeed = FALSE;
  20. m_lConnectErrorMax = 200;
  21. m_lConnectIntval = 10;
  22. m_lDownloadAllCount = 10;
  23. }
  24. void CDlgDownloadSetup::DoDataExchange(CDataExchange* pDX)
  25. {
  26. CPropertyPage::DoDataExchange(pDX);
  27. //{{AFX_DATA_MAP(CDlgDownloadSetup)
  28. DDX_Control(pDX, IDC_STATIC_UP_SPEED_INFO, m_stUpSpeedInfo);
  29. DDX_Control(pDX, IDC_GROUP_UPLOAD_SPEED, m_gpUpSpeed);
  30. DDX_Control(pDX, IDC_GROUP_CON_SETUP, m_gpConSetup);
  31. DDX_Control(pDX, IDC_SPIN_COMPLETE_KEEP_SEED_HOUR, m_spinCompleteKeepSeedHour);
  32. DDX_Control(pDX, IDC_SPIN_DOWNLOAD_ALL_COUNT, m_spinDownloadAllCount);
  33. DDX_Control(pDX, IDC_SPIN_CONNECT_INTVAL, m_spinConnectIntval);
  34. DDX_Control(pDX, IDC_SPIN_CONNECT_ERR_MAX, m_spinConnectErrMax);
  35. DDX_Control(pDX, IDC_COMBO_DOWN_SPEED, m_cbDownSpeed);
  36. DDX_Control(pDX, IDC_SPIN_PORT_MAX, m_spinPortMax);
  37. DDX_Control(pDX, IDC_SPIN_PORT_MIN, m_spinPortMin);
  38. //}}AFX_DATA_MAP
  39. // DDX_Check(pDX, IDC_CHECK_KEEP_SEED, m_bCompleteKeepSeed);
  40. }
  41. BEGIN_MESSAGE_MAP(CDlgDownloadSetup, CPropertyPage)
  42. //{{AFX_MSG_MAP(CDlgDownloadSetup)
  43. ON_CBN_SELCHANGE(IDC_COMBO_DOWN_SPEED, OnSelchangeComboDownSpeed)
  44. //}}AFX_MSG_MAP
  45. // ON_BN_CLICKED(IDC_CHECK_KEEP_SEED, OnCheckKeepSeed)
  46. END_MESSAGE_MAP()
  47. /////////////////////////////////////////////////////////////////////////////
  48. // CDlgDownloadSetup message handlers
  49. BOOL CDlgDownloadSetup::OnInitDialog() 
  50. {
  51. CPropertyPage::OnInitDialog();
  52. //
  53. // Up speed setup.
  54. //
  55. m_spinPortMin.SetBuddy(GetDlgItem(IDC_EDIT_PORT_MIN));
  56. m_spinPortMax.SetBuddy(GetDlgItem(IDC_EDIT_PORT_MAX));
  57. m_spinPortMin.SetRange(1, 31000);
  58. m_spinPortMax.SetRange(1, 32000);
  59. m_spinConnectIntval.SetBuddy(GetDlgItem(IDC_EDIT_CONNECT_INTVAL));
  60. m_spinConnectErrMax.SetBuddy(GetDlgItem(IDC_EDIT_CONNECT_ERR_MAX));
  61. m_spinDownloadAllCount.SetBuddy(GetDlgItem(IDC_EDIT_DOWNLOAD_ALL_COUNT));
  62. m_spinConnectIntval.SetRange(0, 500);
  63. m_spinConnectErrMax.SetRange(1, 10000);
  64. m_spinDownloadAllCount.SetRange(1, 1000);
  65. m_spinCompleteKeepSeedHour.SetBuddy(GetDlgItem(IDC_EDIT_COMPLETE_KEEP_SEED_HOUR));
  66. m_spinCompleteKeepSeedHour.SetRange(0, 1000);
  67. for (int i=0; i<CSpeedParameters::eSpeedModeAll; i++)
  68. {
  69. m_cbDownSpeed.AddString(CSpeedParameters::m_strArrSpeedMode[i]);
  70. m_cbDownSpeed.SetItemData(m_cbDownSpeed.GetCount()-1, i);
  71. }
  72. return TRUE;  // return TRUE unless you set the focus to a control
  73.               // EXCEPTION: OCX Property Pages should return FALSE
  74. }
  75. bool CDlgDownloadSetup::Apply()
  76. {
  77. UpdateData();
  78. int lower=0, upper=0;
  79. m_lPortMin = LOWORD(m_spinPortMin.GetPos());
  80. m_lPortMax = LOWORD(m_spinPortMax.GetPos());
  81. m_spinPortMin.GetRange(lower, upper);
  82. m_lPortMin = max(lower, m_lPortMin);
  83. m_lPortMin = min(upper, m_lPortMin);
  84. m_spinPortMax.GetRange(lower, upper);
  85. m_lPortMax = max(lower, m_lPortMax);
  86. m_lPortMax = min(upper, m_lPortMax);
  87. m_lPortMax = max(m_lPortMin + 100, m_lPortMax);
  88. // get pos.
  89. m_lConnectErrorMax = LOWORD(m_spinConnectErrMax.GetPos());
  90. m_lConnectIntval = LOWORD(m_spinConnectIntval.GetPos());
  91. m_lDownloadAllCount = LOWORD(m_spinDownloadAllCount.GetPos());
  92. m_lCompleteKeepSeedHour = LOWORD(m_spinCompleteKeepSeedHour.GetPos());
  93. // normalize.
  94. m_spinConnectErrMax.GetRange(lower, upper);
  95. m_lConnectErrorMax = max(lower, m_lConnectErrorMax);
  96. m_lConnectErrorMax = min(upper, m_lConnectErrorMax);
  97. m_spinConnectIntval.GetRange(lower, upper);
  98. m_lConnectIntval = max(lower, m_lConnectIntval);
  99. m_lConnectIntval = min(upper, m_lConnectIntval);
  100. m_spinDownloadAllCount.GetRange(lower, upper);
  101. m_lDownloadAllCount = max(lower, m_lDownloadAllCount);
  102. m_lDownloadAllCount = min(upper, m_lDownloadAllCount);
  103. m_spinCompleteKeepSeedHour.GetRange(lower, upper);
  104. m_lCompleteKeepSeedHour = max(lower, m_lCompleteKeepSeedHour);
  105. m_lCompleteKeepSeedHour = min(upper, m_lCompleteKeepSeedHour);
  106. // update auto.
  107. // m_bCompleteKeepSeed = 
  108. m_lDownSpeed = m_cbDownSpeed.GetItemData(m_cbDownSpeed.GetCurSel());
  109. return true;
  110. }
  111. void CDlgDownloadSetup::SetData(CSetupRegister *pSetupRegister)
  112. {
  113. m_lDownSpeed = pSetupRegister->m_lDownSpeed;
  114. m_lPortMin = pSetupRegister->m_lPortMin;
  115. m_lPortMax = pSetupRegister->m_lPortMax;
  116. m_lConnectErrorMax = pSetupRegister->m_lConnectErrorMax;
  117. m_lConnectIntval = pSetupRegister->m_lConnectIntval;
  118. m_lDownloadAllCount = pSetupRegister->m_lDownloadAllCount;
  119. // m_bCompleteKeepSeed = pSetupRegister->m_bCompleteKeepSeed;
  120. m_lCompleteKeepSeedHour = pSetupRegister->m_lCompleteKeepSeedHour;
  121. m_spinPortMin.SetPos(m_lPortMin);
  122. m_spinPortMax.SetPos(m_lPortMax);
  123. m_spinConnectErrMax.SetPos(m_lConnectErrorMax);
  124. m_spinConnectIntval.SetPos(m_lConnectIntval);
  125. m_spinDownloadAllCount.SetPos(m_lDownloadAllCount);
  126. m_spinCompleteKeepSeedHour.SetPos(m_lCompleteKeepSeedHour);
  127. m_cbDownSpeed.SetCurSel(0);
  128. for (int i=0; m_cbDownSpeed.GetCount(); i++)
  129. {
  130. if (m_cbDownSpeed.GetItemData(i) == m_lDownSpeed)
  131. {
  132. m_cbDownSpeed.SetCurSel(i);
  133. break;
  134. }
  135. }
  136. UpdateData(false);
  137. OnCheckKeepSeed();
  138. OnSelchangeComboDownSpeed();
  139. }
  140. void CDlgDownloadSetup::GetData(CSetupRegister *pSetupRegister)
  141. {
  142. pSetupRegister->m_lDownSpeed = m_lDownSpeed;
  143. pSetupRegister->m_lPortMin = m_lPortMin ;
  144. pSetupRegister->m_lPortMax = m_lPortMax;
  145. pSetupRegister->m_lConnectErrorMax = m_lConnectErrorMax;
  146. pSetupRegister->m_lConnectIntval = m_lConnectIntval;
  147. pSetupRegister->m_lDownloadAllCount = m_lDownloadAllCount;
  148. pSetupRegister->m_lCompleteKeepSeedHour = m_lCompleteKeepSeedHour;
  149. // pSetupRegister->m_bCompleteKeepSeed = m_bCompleteKeepSeed != 0;
  150. }
  151. void CDlgDownloadSetup::OnOK() 
  152. {
  153. GetParent()->SendMessage(WM_COMMAND, IDOK, 0);
  154. CPropertyPage::OnOK();
  155. }
  156. void CDlgDownloadSetup::OnCancel() 
  157. {
  158. GetParent()->SendMessage(WM_COMMAND, IDCANCEL, 0);
  159. CPropertyPage::OnCancel();
  160. }
  161. void CDlgDownloadSetup::OnCheckKeepSeed() 
  162. {
  163. UpdateData();
  164. // m_spinCompleteKeepSeedHour.EnableWindow(m_bCompleteKeepSeed);
  165. // GetDlgItem(IDC_EDIT_COMPLETE_KEEP_SEED_HOUR)->EnableWindow(m_bCompleteKeepSeed);
  166. }
  167. void CDlgDownloadSetup::OnSelchangeComboDownSpeed() 
  168. {
  169. long lCurSel = m_cbDownSpeed.GetCurSel();
  170. if (lCurSel < 0 || lCurSel >= CSpeedParameters::eSpeedModeAll)
  171. {
  172. ASSERT(FALSE);
  173. return;
  174. }
  175. CString strText;
  176. strText.Format("最大上传速度(0代表无限速): %dKB, 最大上传连接:%d", CSpeedParameters::m_lArrSpeedVal[lCurSel], CSpeedParameters::m_lArrPeerVal[lCurSel]);
  177. m_stUpSpeedInfo.SetWindowText(strText);
  178. }