00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include "StdAfx.h"
00023 #include "Shareaza.h"
00024 #include "Settings.h"
00025 #include "UploadQueue.h"
00026 #include "UploadQueues.h"
00027 #include "DlgQueueProperties.h"
00028 #include "LiveList.h"
00029
00030 #ifdef _DEBUG
00031 #define new DEBUG_NEW
00032 #undef THIS_FILE
00033 static char THIS_FILE[] = __FILE__;
00034 #endif
00035
00036 BEGIN_MESSAGE_MAP(CQueuePropertiesDlg, CSkinDialog)
00037
00038 ON_BN_CLICKED(IDC_MINIMUM_CHECK, OnMinimumCheck)
00039 ON_BN_CLICKED(IDC_MAXIMUM_CHECK, OnMaximumCheck)
00040 ON_BN_CLICKED(IDC_PROTOCOLS_CHECK, OnProtocolsCheck)
00041 ON_BN_CLICKED(IDC_MARKED_CHECK, OnMarkedCheck)
00042 ON_BN_CLICKED(IDC_ROTATE_ENABLE, OnRotateEnable)
00043 ON_WM_HSCROLL()
00044 ON_EN_CHANGE(IDC_TRANSFERS_MAX, OnChangeTransfersMax)
00045 ON_BN_CLICKED(IDC_MATCH_CHECK, OnMatchCheck)
00046
00047 END_MESSAGE_MAP()
00048
00049
00051
00052
00053 CQueuePropertiesDlg::CQueuePropertiesDlg(CUploadQueue* pQueue, BOOL bEnable, CWnd* pParent) : CSkinDialog(CQueuePropertiesDlg::IDD, pParent)
00054 {
00055 ASSERT( pQueue != NULL );
00056 m_pQueue = pQueue;
00057 m_bEnableOverride = bEnable;
00058
00059
00060 m_nCapacity = 0;
00061 m_bMaxSize = FALSE;
00062 m_sMaxSize = _T("");
00063 m_bMinSize = FALSE;
00064 m_sMinSize = _T("");
00065 m_bMarked = FALSE;
00066 m_sName = _T("");
00067 m_bPartial = FALSE;
00068 m_bProtocols = FALSE;
00069 m_bRotate = FALSE;
00070 m_bReward = FALSE;
00071 m_nRotateTime = 0;
00072 m_nTransfersMax = 0;
00073 m_nTransfersMin = 0;
00074 m_bMatch = FALSE;
00075 m_sMatch = _T("");
00076 m_bEnable = FALSE;
00077 m_sMarked = _T("");
00078
00079 }
00080
00081 void CQueuePropertiesDlg::DoDataExchange(CDataExchange* pDX)
00082 {
00083 CSkinDialog::DoDataExchange(pDX);
00084
00085 DDX_Control(pDX, IDC_MATCH_TEXT, m_wndMatch);
00086 DDX_Control(pDX, IDC_BANDWIDTH_POINTS, m_wndBandwidthPoints);
00087 DDX_Control(pDX, IDC_BANDWIDTH_VALUE, m_wndBandwidthValue);
00088 DDX_Control(pDX, IDC_TRANSFERS_MIN_SPIN, m_wndTransfersMin);
00089 DDX_Control(pDX, IDC_TRANSFERS_MAX_SPIN, m_wndTransfersMax);
00090 DDX_Control(pDX, IDC_ROTATE_TIME_SPIN, m_wndRotateTimeSpin);
00091 DDX_Control(pDX, IDC_ROTATE_TIME, m_wndRotateTime);
00092 DDX_Control(pDX, IDC_PROTOCOLS_LIST, m_wndProtocols);
00093 DDX_Control(pDX, IDC_MINIMUM_VALUE, m_wndMinSize);
00094 DDX_Control(pDX, IDC_MAXIMUM_VALUE, m_wndMaxSize);
00095 DDX_Control(pDX, IDC_MARKED_LIST, m_wndMarked);
00096 DDX_Control(pDX, IDC_CAPACITY_SPIN, m_wndCapacity);
00097 DDX_Control(pDX, IDC_BANDWIDTH_SLIDER, m_wndBandwidthSlider);
00098 DDX_Text(pDX, IDC_CAPACITY, m_nCapacity);
00099 DDX_Check(pDX, IDC_MAXIMUM_CHECK, m_bMaxSize);
00100 DDX_Text(pDX, IDC_MAXIMUM_VALUE, m_sMaxSize);
00101 DDX_Check(pDX, IDC_MINIMUM_CHECK, m_bMinSize);
00102 DDX_Text(pDX, IDC_MINIMUM_VALUE, m_sMinSize);
00103 DDX_Check(pDX, IDC_MARKED_CHECK, m_bMarked);
00104 DDX_Text(pDX, IDC_NAME, m_sName);
00105 DDX_Check(pDX, IDC_PARTIAL_ENABLE, m_bPartial);
00106 DDX_Check(pDX, IDC_PROTOCOLS_CHECK, m_bProtocols);
00107 DDX_Check(pDX, IDC_ROTATE_ENABLE, m_bRotate);
00108 DDX_Text(pDX, IDC_ROTATE_TIME, m_nRotateTime);
00109 DDX_Text(pDX, IDC_TRANSFERS_MAX, m_nTransfersMax);
00110 DDX_Text(pDX, IDC_TRANSFERS_MIN, m_nTransfersMin);
00111 DDX_Check(pDX, IDC_REWARD_ENABLE, m_bReward);
00112 DDX_Check(pDX, IDC_MATCH_CHECK, m_bMatch);
00113 DDX_Text(pDX, IDC_MATCH_TEXT, m_sMatch);
00114 DDX_Check(pDX, IDC_ENABLE, m_bEnable);
00115 DDX_CBString(pDX, IDC_MARKED_LIST, m_sMarked);
00116
00117 }
00118
00120
00121
00122 BOOL CQueuePropertiesDlg::OnInitDialog()
00123 {
00124 CSkinDialog::OnInitDialog();
00125
00126 SkinMe( _T("CQueuePropertiesDlg"), ID_VIEW_UPLOADS );
00127
00128 m_wndTransfersMin.SetRange( 1, 128 );
00129 m_wndTransfersMax.SetRange( 1, 512 );
00130 m_wndRotateTimeSpin.SetRange( 30, 15 * 60 );
00131
00132 CBitmap bmProtocols;
00133 bmProtocols.LoadBitmap( IDB_PROTOCOLS );
00134 if ( theApp.m_bRTL )
00135 bmProtocols.m_hObject = CreateMirroredBitmap( (HBITMAP)bmProtocols.m_hObject );
00136
00137 m_gdiProtocols.Create( 16, 16, ILC_COLOR32|ILC_MASK, 7, 1 );
00138 m_gdiProtocols.Add( &bmProtocols, RGB( 0, 255, 0 ) );
00139
00140 m_wndProtocols.SendMessage( LVM_SETEXTENDEDLISTVIEWSTYLE, LVS_EX_CHECKBOXES, LVS_EX_CHECKBOXES );
00141 m_wndProtocols.SetImageList( &m_gdiProtocols, LVSIL_SMALL );
00142 m_wndProtocols.InsertItem( LVIF_TEXT|LVIF_IMAGE|LVIF_PARAM, 0, _T("HTTP"), 0, 0, PROTOCOL_HTTP, PROTOCOL_HTTP );
00143 m_wndProtocols.InsertItem( LVIF_TEXT|LVIF_IMAGE|LVIF_PARAM, 1, _T("ED2K"), 0, 0, PROTOCOL_ED2K, PROTOCOL_ED2K );
00144
00145 CSingleLock pLock( &UploadQueues.m_pSection, TRUE );
00146
00147 if ( ! UploadQueues.Check( m_pQueue ) )
00148 {
00149 PostMessage( WM_CLOSE );
00150 return TRUE;
00151 }
00152
00153 m_sName = m_pQueue->m_sName;
00154
00155 m_bPartial = m_pQueue->m_bPartial;
00156
00157 if ( m_bMinSize = ( m_pQueue->m_nMinSize > 0 ) )
00158 {
00159 m_sMinSize = Settings.SmartVolume( m_pQueue->m_nMinSize, FALSE );
00160 }
00161 else
00162 {
00163 m_sMinSize = Settings.SmartVolume( 0, FALSE );
00164 }
00165
00166 if ( m_bMaxSize = ( m_pQueue->m_nMaxSize < SIZE_UNKNOWN ) )
00167 {
00168 m_sMaxSize = Settings.SmartVolume( m_pQueue->m_nMaxSize, FALSE );
00169 }
00170 else
00171 {
00172 m_sMaxSize = Settings.SmartVolume( 0, FALSE );
00173 }
00174
00175 m_bMarked = ( m_pQueue->m_sShareTag.GetLength() > 0 );
00176 m_sMarked = m_pQueue->m_sShareTag;
00177
00178 m_bMatch = ( m_pQueue->m_sNameMatch.GetLength() > 0 );
00179 m_sMatch = m_pQueue->m_sNameMatch;
00180
00181 m_bProtocols = ( m_pQueue->m_nProtocols != 0 );
00182
00183 if ( ! m_bProtocols || ( m_pQueue->m_nProtocols & (1<<PROTOCOL_HTTP) ) )
00184 m_wndProtocols.SetItemState( 0, INDEXTOSTATEIMAGEMASK(2), LVIS_STATEIMAGEMASK );
00185 if ( ! m_bProtocols || ( m_pQueue->m_nProtocols & (1<<PROTOCOL_ED2K) ) )
00186 m_wndProtocols.SetItemState( 1, INDEXTOSTATEIMAGEMASK(2), LVIS_STATEIMAGEMASK );
00187
00188 m_bEnable = m_pQueue->m_bEnable || m_bEnableOverride;
00189
00190 m_nCapacity = max( m_pQueue->m_nCapacity, m_pQueue->m_nMaxTransfers );
00191 m_nTransfersMin = m_pQueue->m_nMinTransfers;
00192 m_nTransfersMax = m_pQueue->m_nMaxTransfers;
00193
00194 m_bRotate = m_pQueue->m_bRotate;
00195 m_nRotateTime = m_pQueue->m_nRotateTime;
00196
00197 m_bReward = m_pQueue->m_bRewardUploaders;
00198
00199 DWORD nTotal = Settings.Connection.OutSpeed * 1024 / 8;
00200 DWORD nLimit = Settings.Bandwidth.Uploads;
00201
00202 if ( nLimit == 0 || nLimit > nTotal ) nLimit = nTotal;
00203 int nOtherPoints = UploadQueues.GetTotalBandwidthPoints( !( m_pQueue->m_nProtocols & (1<<PROTOCOL_ED2K) ) ) - m_pQueue->m_nBandwidthPoints;
00204
00205 if ( nOtherPoints < 0 ) nOtherPoints = 0;
00206
00207 m_wndBandwidthSlider.SetRange( 1, max( 100, nOtherPoints * 3 ) );
00208 m_wndBandwidthSlider.SetPos( m_pQueue->m_nBandwidthPoints );
00209
00210 UpdateData( FALSE );
00211
00212 m_wndMinSize.EnableWindow( m_bMinSize );
00213 m_wndMaxSize.EnableWindow( m_bMaxSize );
00214 m_wndMarked.EnableWindow( m_bMarked );
00215 m_wndMatch.EnableWindow( m_bMatch );
00216 m_wndProtocols.EnableWindow( m_bProtocols );
00217 m_wndRotateTime.EnableWindow( m_bRotate );
00218 m_wndRotateTimeSpin.EnableWindow( m_bRotate );
00219 m_wndCapacity.SetRange32( m_nTransfersMax, 4096 );
00220 OnHScroll( 0, 0, NULL );
00221
00222
00223 if ( Settings.General.GUIMode == GUI_BASIC )
00224 {
00225 if ( !( Settings.eDonkey.EnableAlways | Settings.eDonkey.EnableToday ) )
00226 {
00227 m_bProtocols = FALSE;
00228 m_wndProtocols.EnableWindow( FALSE );
00229 m_wndProtocols.ShowWindow( FALSE );
00230
00231 (GetProtocolCheckbox())->EnableWindow( FALSE );
00232 (GetProtocolCheckbox())->ShowWindow( FALSE );
00233 }
00234 }
00235
00236 return TRUE;
00237 }
00238
00239 void CQueuePropertiesDlg::OnMinimumCheck()
00240 {
00241 UpdateData();
00242 m_wndMinSize.EnableWindow( m_bMinSize );
00243 }
00244
00245 void CQueuePropertiesDlg::OnMaximumCheck()
00246 {
00247 UpdateData();
00248 m_wndMaxSize.EnableWindow( m_bMaxSize );
00249 }
00250
00251 void CQueuePropertiesDlg::OnMarkedCheck()
00252 {
00253 UpdateData();
00254 m_wndMarked.EnableWindow( m_bMarked );
00255 }
00256
00257 void CQueuePropertiesDlg::OnMatchCheck()
00258 {
00259 UpdateData();
00260 m_wndMatch.EnableWindow( m_bMatch );
00261 }
00262
00263 void CQueuePropertiesDlg::OnProtocolsCheck()
00264 {
00265 if ( Settings.General.GUIMode == GUI_BASIC )
00266 if ( !( Settings.eDonkey.EnableAlways | Settings.eDonkey.EnableToday ) )
00267 return;
00268
00269 UpdateData();
00270 m_wndProtocols.EnableWindow( m_bProtocols );
00271 }
00272
00273 void CQueuePropertiesDlg::OnChangeTransfersMax()
00274 {
00275 if ( m_wndBandwidthValue.m_hWnd != NULL )
00276 {
00277 UpdateData();
00278 m_nCapacity = max( m_nCapacity, m_nTransfersMax );
00279 m_wndCapacity.SetRange( m_nTransfersMax, 1024 );
00280 UpdateData( FALSE );
00281 }
00282 }
00283
00284 void CQueuePropertiesDlg::OnRotateEnable()
00285 {
00286 UpdateData();
00287 m_wndRotateTime.EnableWindow( m_bRotate );
00288 m_wndRotateTimeSpin.EnableWindow( m_bRotate );
00289 }
00290
00291 void CQueuePropertiesDlg::OnHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)
00292 {
00293 DWORD nTotal = Settings.Connection.OutSpeed * 1024 / 8;
00294 DWORD nLimit = Settings.Bandwidth.Uploads;
00295
00296 if ( nLimit == 0 || nLimit > nTotal ) nLimit = nTotal;
00297
00298 int nOtherPoints = UploadQueues.GetTotalBandwidthPoints( !( m_pQueue->m_nProtocols & (1<<PROTOCOL_ED2K) ) ) - m_pQueue->m_nBandwidthPoints;
00299 if ( nOtherPoints < 0 ) nOtherPoints = 0;
00300
00301 int nLocalPoints = m_wndBandwidthSlider.GetPos();
00302 int nTotalPoints = nLocalPoints + nOtherPoints;
00303
00304 DWORD nBandwidth = nLimit * nLocalPoints / max( 1, nTotalPoints );
00305
00306 CString str;
00307 str.Format( _T("%.2f%% (%lu/%lu)"), 100.0 * nBandwidth / nLimit,
00308 nLocalPoints, nTotalPoints );
00309
00310 m_wndBandwidthPoints.SetWindowText( str );
00311 m_wndBandwidthValue.SetWindowText( Settings.SmartVolume( nBandwidth * 8, FALSE, TRUE ) + '+' );
00312 }
00313
00314 void CQueuePropertiesDlg::OnOK()
00315 {
00316 UpdateData();
00317
00318 CSingleLock pLock( &UploadQueues.m_pSection, TRUE );
00319
00320 if ( ! UploadQueues.Check( m_pQueue ) )
00321 {
00322 CSkinDialog::OnCancel();
00323 return;
00324 }
00325
00326 m_pQueue->m_sName = m_sName;
00327
00328 m_pQueue->m_bPartial = m_bPartial;
00329
00330 if ( m_bMinSize )
00331 {
00332 m_pQueue->m_nMinSize = Settings.ParseVolume( m_sMinSize, FALSE );
00333 }
00334 else
00335 {
00336 m_pQueue->m_nMinSize = 0;
00337 }
00338
00339 if ( m_bMaxSize )
00340 {
00341 m_pQueue->m_nMaxSize = Settings.ParseVolume( m_sMaxSize, FALSE );
00342 if ( m_pQueue->m_nMaxSize == 0 ) m_pQueue->m_nMaxSize = SIZE_UNKNOWN;
00343 }
00344 else
00345 {
00346 m_pQueue->m_nMaxSize = SIZE_UNKNOWN;
00347 }
00348
00349 if ( m_bMarked )
00350 {
00351 m_pQueue->m_sShareTag = m_sMarked;
00352 }
00353 else
00354 {
00355 m_pQueue->m_sShareTag.Empty();
00356 }
00357
00358 if ( m_bMatch )
00359 {
00360 m_pQueue->m_sNameMatch = m_sMatch;
00361 }
00362 else
00363 {
00364 m_pQueue->m_sNameMatch.Empty();
00365 }
00366
00367 m_pQueue->m_nProtocols = 0;
00368
00369 if ( m_bProtocols )
00370 {
00371 if ( m_wndProtocols.GetItemState( 0, LVIS_STATEIMAGEMASK ) == INDEXTOSTATEIMAGEMASK(2) )
00372 m_pQueue->m_nProtocols |= (1<<PROTOCOL_HTTP);
00373 if ( m_wndProtocols.GetItemState( 1, LVIS_STATEIMAGEMASK ) == INDEXTOSTATEIMAGEMASK(2) )
00374 m_pQueue->m_nProtocols |= (1<<PROTOCOL_ED2K);
00375
00376 if ( m_pQueue->m_nProtocols == ( (1<<PROTOCOL_HTTP)|(1<<PROTOCOL_ED2K) ) )
00377 m_pQueue->m_nProtocols = 0;
00378 }
00379
00380 if ( ( m_pQueue->m_nProtocols & (1<<PROTOCOL_ED2K) ) )
00381 m_pQueue->m_nCapacity = min( m_nCapacity, 4096 );
00382 else
00383 m_pQueue->m_nCapacity = min( m_nCapacity, 64 );
00384
00385 m_pQueue->m_bEnable = m_bEnable;
00386 m_pQueue->m_nMinTransfers = max( 1, m_nTransfersMin );
00387 m_pQueue->m_nMaxTransfers = max( m_nTransfersMin, m_nTransfersMax );
00388
00389 m_pQueue->m_bRotate = m_bRotate;
00390 m_pQueue->m_nRotateTime = max(30, m_nRotateTime );
00391
00392 m_pQueue->m_nBandwidthPoints = m_wndBandwidthSlider.GetPos();
00393
00394 m_pQueue->m_bRewardUploaders = m_bReward;
00395
00396 CSkinDialog::OnOK();
00397 }