-
Notifications
You must be signed in to change notification settings - Fork 12
/
BtDld_Seeding.cpp
178 lines (149 loc) · 5.07 KB
/
BtDld_Seeding.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
/*
Free Download Manager Copyright (c) 2003-2016 FreeDownloadManager.ORG
*/
#include "stdafx.h"
#include "fdm.h"
#include "BtDld_Seeding.h"
#include "QueryStoringServiceInfoGuard.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
IMPLEMENT_DYNCREATE(CBtDld_Seeding, CPropertyPage)
CBtDld_Seeding::CBtDld_Seeding() : CPropertyPage(CBtDld_Seeding::IDD)
{
m_psp.dwFlags |= PSP_USETITLE;
m_psp.pszTitle = LS (L_SEEDING);
}
CBtDld_Seeding::~CBtDld_Seeding()
{
}
void CBtDld_Seeding::DoDataExchange(CDataExchange* pDX)
{
CPropertyPage::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CBtDld_Seeding)
DDX_Control(pDX, IDC_RATIO_LIST, m_wndRatio);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CBtDld_Seeding, CPropertyPage)
//{{AFX_MSG_MAP(CBtDld_Seeding)
ON_BN_CLICKED(IDC_ENABLE_SEEDING, OnEnableSeeding)
ON_BN_CLICKED(IDC_UNLIMITED_SEEDING, OnUnlimitedSeeding)
ON_BN_CLICKED(IDC_LIMIT_BY_RATIO, OnLimitByRatio)
ON_CBN_SELCHANGE(IDC_RATIO_LIST, OnSelchangeRatioList)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
BOOL CBtDld_Seeding::OnInitDialog()
{
CPropertyPage::OnInitDialog();
int iEnableSeeding = m_pvDlds->at (0)->pMgr->GetBtDownloadMgr ()->isSeedingEnabled () ? 1 : 0;
float fReqRatio = m_pvDlds->at (0)->pMgr->GetBtDownloadMgr ()->getRequiredRatio ();
for (size_t i = 1; i < m_pvDlds->size (); i++)
{
int iEnableSeeding2 = m_pvDlds->at (i)->pMgr->GetBtDownloadMgr ()->isSeedingEnabled () ? 1 : 0;
float fReqRatio2 = m_pvDlds->at (i)->pMgr->GetBtDownloadMgr ()->getRequiredRatio ();
if (iEnableSeeding != iEnableSeeding2)
iEnableSeeding = 2;
if (fReqRatio2 != fReqRatio)
fReqRatio2 = -1;
if (iEnableSeeding == 2 && fReqRatio2 == -1)
break;
}
if (iEnableSeeding == 2)
CheckDlgButton (IDC_ENABLE_SEEDING, BST_INDETERMINATE);
else
CheckDlgButton (IDC_ENABLE_SEEDING, iEnableSeeding ? BST_CHECKED : BST_UNCHECKED);
m_wndRatio.AddString (_T("100 %")); m_wndRatio.SetItemData (m_wndRatio.GetCount () - 1, 100);
m_wndRatio.AddString (_T("150 %")); m_wndRatio.SetItemData (m_wndRatio.GetCount () - 1, 150);
m_wndRatio.AddString (_T("200 %")); m_wndRatio.SetItemData (m_wndRatio.GetCount () - 1, 200);
m_wndRatio.AddString (_T("300 %")); m_wndRatio.SetItemData (m_wndRatio.GetCount () - 1, 300);
m_wndRatio.AddString (_T("500 %")); m_wndRatio.SetItemData (m_wndRatio.GetCount () - 1, 500);
m_wndRatio.AddString (_T("1000 %")); m_wndRatio.SetItemData (m_wndRatio.GetCount () - 1, 1000);
m_wndRatio.SetCurSel (1);
if (fReqRatio != -1)
{
CheckRadioButton (IDC_UNLIMITED_SEEDING, IDC_LIMIT_BY_RATIO,
fReqRatio ? IDC_LIMIT_BY_RATIO : IDC_UNLIMITED_SEEDING);
}
if (fReqRatio)
{
m_wndRatio.SetCurSel (-1);
for (int i = 0; i < m_wndRatio.GetCount (); i++)
{
if (m_wndRatio.GetItemData (i) == UINT (fReqRatio * 100))
{
m_wndRatio.SetCurSel (i);
break;
}
}
}
ApplyLanguage ();
UpdateEnabled ();
return TRUE;
}
void CBtDld_Seeding::ApplyLanguage()
{
fsDlgLngInfo lnginfo [] = {
fsDlgLngInfo (IDC_ENABLE_SEEDING, L_ENABLE_SEEDING_HR),
fsDlgLngInfo (IDC_UNLIMITED_SEEDING, L_UNLIMITED_SEEDING),
fsDlgLngInfo (IDC_LIMIT_BY_RATIO, L_LIMIT_BY_RATIO),
fsDlgLngInfo (IDC_STATIC0, L_SEED_UNTIL_RATIO_WILL_BE),
};
_LngMgr.ApplyLanguage (this, lnginfo, sizeof (lnginfo) / sizeof (fsDlgLngInfo), 0);
}
void CBtDld_Seeding::UpdateEnabled()
{
BOOL b = IsDlgButtonChecked (IDC_ENABLE_SEEDING) != BST_UNCHECKED;
GetDlgItem (IDC_UNLIMITED_SEEDING)->EnableWindow (b);
GetDlgItem (IDC_LIMIT_BY_RATIO)->EnableWindow (b);
BOOL b2 = IsDlgButtonChecked (IDC_LIMIT_BY_RATIO) == BST_CHECKED;
GetDlgItem (IDC_STATIC0)->EnableWindow (b && b2);
GetDlgItem (IDC_RATIO_LIST)->EnableWindow (b && b2);
}
void CBtDld_Seeding::OnEnableSeeding()
{
if (IsDlgButtonChecked (IDC_ENABLE_SEEDING) == BST_INDETERMINATE)
CheckDlgButton (IDC_ENABLE_SEEDING, BST_UNCHECKED);
SetModified ();
UpdateEnabled ();
}
void CBtDld_Seeding::OnUnlimitedSeeding()
{
SetModified ();
UpdateEnabled ();
}
void CBtDld_Seeding::OnLimitByRatio()
{
SetModified ();
UpdateEnabled ();
}
BOOL CBtDld_Seeding::OnApply()
{
if (IsDlgButtonChecked (IDC_ENABLE_SEEDING) != BST_INDETERMINATE)
{
BOOL b = IsDlgButtonChecked (IDC_ENABLE_SEEDING) == BST_CHECKED;
for (size_t i = 0; i < m_pvDlds->size (); i++)
m_pvDlds->at (i)->pMgr->GetBtDownloadMgr ()->EnableSeeding (b);
}
if (IsDlgButtonChecked (IDC_UNLIMITED_SEEDING) == BST_CHECKED)
{
for (size_t i = 0; i < m_pvDlds->size (); i++)
m_pvDlds->at (i)->pMgr->GetBtDownloadMgr ()->setRequiredRatio (0);
}
else if (IsDlgButtonChecked (IDC_LIMIT_BY_RATIO) == BST_CHECKED)
{
int nCur = m_wndRatio.GetCurSel ();
if (nCur != CB_ERR)
{
float fReqRatio = (float)m_wndRatio.GetItemData (nCur) / 100.0f;
for (size_t i = 0; i < m_pvDlds->size (); i++)
m_pvDlds->at (i)->pMgr->GetBtDownloadMgr ()->setRequiredRatio (fReqRatio);
}
}
return CPropertyPage::OnApply();
}
void CBtDld_Seeding::OnSelchangeRatioList()
{
SetModified ();
}