Main Page | Namespace List | Class Hierarchy | Class List | Directories | File List | Namespace Members | Class Members | File Members

WizardConnectionPage.cpp

Go to the documentation of this file.
00001 //
00002 // WizardConnectionPage.cpp
00003 //
00004 // Copyright (c) Shareaza Development Team, 2002-2005.
00005 // This file is part of SHAREAZA (www.shareaza.com)
00006 //
00007 // Shareaza is free software; you can redistribute it
00008 // and/or modify it under the terms of the GNU General Public License
00009 // as published by the Free Software Foundation; either version 2 of
00010 // the License, or (at your option) any later version.
00011 //
00012 // Shareaza is distributed in the hope that it will be useful,
00013 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00014 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015 // GNU General Public License for more details.
00016 //
00017 // You should have received a copy of the GNU General Public License
00018 // along with Shareaza; if not, write to the Free Software
00019 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00020 //
00021 
00022 #include "StdAfx.h"
00023 #include "Shareaza.h"
00024 #include "Settings.h"
00025 #include "Network.h"
00026 #include "WizardSheet.h"
00027 #include "WizardConnectionPage.h"
00028 #include "UploadQueues.h"
00029 #include "Skin.h"
00030 #include "DlgHelp.h"
00031 #include "HostCache.h"
00032 #include "DiscoveryServices.h"
00033 
00034 #ifdef _DEBUG
00035 #define new DEBUG_NEW
00036 #undef THIS_FILE
00037 static char THIS_FILE[] = __FILE__;
00038 #endif
00039 
00040 IMPLEMENT_DYNCREATE(CWizardConnectionPage, CWizardPage)
00041 
00042 BEGIN_MESSAGE_MAP(CWizardConnectionPage, CWizardPage)
00043         //{{AFX_MSG_MAP(CWizardConnectionPage)
00044         ON_CBN_SELCHANGE(IDC_CONNECTION_TYPE, OnSelChangeConnectionType)
00045         ON_CBN_EDITCHANGE(IDC_CONNECTION_SPEED, OnEditChangeConnectionSpeed)
00046         ON_CBN_SELCHANGE(IDC_CONNECTION_SPEED, OnSelChangeConnectionSpeed)
00047         ON_CBN_SELCHANGE(IDC_CONNECTION_GROUP, OnSelChangeConnectionGroup)
00048         //}}AFX_MSG_MAP
00049 END_MESSAGE_MAP()
00050 
00051 
00053 // CWizardConnectionPage property page
00054 
00055 CWizardConnectionPage::CWizardConnectionPage() : CWizardPage(CWizardConnectionPage::IDD)
00056 {
00057         //{{AFX_DATA_INIT(CWizardConnectionPage)
00058         //}}AFX_DATA_INIT
00059 }
00060 
00061 CWizardConnectionPage::~CWizardConnectionPage()
00062 {
00063 }
00064 
00065 void CWizardConnectionPage::DoDataExchange(CDataExchange* pDX)
00066 {
00067         CPropertyPage::DoDataExchange(pDX);
00068         //{{AFX_DATA_MAP(CWizardConnectionPage)
00069         DDX_Control(pDX, IDC_CONNECTION_LAN_SELECT, m_wndLanSelect);
00070         DDX_Control(pDX, IDC_CONNECTION_LAN_LABEL, m_wndLanLabel);
00071         DDX_Control(pDX, IDC_CONNECTION_HOME_SELECT, m_wndHomeSelect);
00072         DDX_Control(pDX, IDC_CONNECTION_HOME_LABEL, m_wndHomeLabel);
00073         DDX_Control(pDX, IDC_CONNECTION_GROUP, m_wndGroup);
00074         DDX_Control(pDX, IDC_CONNECTION_SPEED, m_wndSpeed);
00075         DDX_Control(pDX, IDC_CONNECTION_TYPE, m_wndType);
00076         //}}AFX_DATA_MAP
00077 }
00078 
00080 // CWizardConnectionPage message handlers
00081 
00082 BOOL CWizardConnectionPage::OnInitDialog() 
00083 {
00084         CPropertyPage::OnInitDialog();
00085         
00086         Skin.Apply( _T("CWizardConnectionPage"), this );
00087         
00088         m_wndGroup.SetCurSel( 0 );
00089         
00090         m_wndType.SetItemData( 0, 0 );
00091         m_wndType.SetItemData( 1, 56 );         // Dial up Modem;
00092         m_wndType.SetItemData( 2, 128 );        // ISDN
00093         m_wndType.SetItemData( 3, 256);         // ADSL (256K)
00094         m_wndType.SetItemData( 4, 512);         // ADSL (512K)
00095         m_wndType.SetItemData( 5, 768);         // ADSL (768K)
00096         m_wndType.SetItemData( 6, 1536 );       // ADSL (1.5M)
00097         m_wndType.SetItemData( 7, 4096 );       // ADSL (4.0M)
00098         m_wndType.SetItemData( 8, 8192 );       // ADSL2 (8.0M)
00099         m_wndType.SetItemData( 9, 12288 );      // ADSL2 (12.0M)
00100         m_wndType.SetItemData(10, 24576 );      // ADSL2+ (24.0M)
00101         m_wndType.SetItemData(11, 1550 );       // Cable Modem/SDSL
00102         m_wndType.SetItemData(12, 1544 );       // T1
00103         m_wndType.SetItemData(13, 45000 );      // T3
00104         m_wndType.SetItemData(14, 100000 );     // LAN
00105         m_wndType.SetItemData(15, 155000 );     // OC3
00106         //; Dial up Modem; ISDN; ADSL (256K); ADSL (512K); ADSL (768K); ADSL (1.5M); ADSL (4.0M); ADSL2 (8.0M); ADSL2 (12.0M); ADSL2+ (24.0M); Cable Modem/SDSL; T1; T3; LAN; OC3;
00107         
00108         CString strSpeed;
00109         strSpeed.Format( _T(" %lu.0 kbps"), Settings.Connection.InSpeed );
00110         m_wndSpeed.SetWindowText( strSpeed );
00111 
00112         //; 28.8 kbps; 33.6 kbps; 56.6 kbps; 64.0 kbps; 128 kbps; 256 kbps; 384 kbps; 512 kbps; 1024 kbps; 1536 kbps; 2048 kbps; 3072 kbps; 4096 kbps; 5120 kbps; 8192 kbps; 12288 kbps;
00113         
00114         return TRUE;
00115 }
00116 
00117 BOOL CWizardConnectionPage::OnSetActive() 
00118 {
00119         SetWizardButtons( PSWIZB_BACK | PSWIZB_NEXT );
00120         return CWizardPage::OnSetActive();
00121 }
00122 
00123 void CWizardConnectionPage::OnSelChangeConnectionGroup() 
00124 {
00125         int nGroup = m_wndGroup.GetCurSel();
00126         
00127         m_wndHomeLabel.ShowWindow( nGroup == 1 ? SW_SHOW : SW_HIDE );
00128         m_wndHomeSelect.ShowWindow( nGroup == 1 ? SW_SHOW : SW_HIDE );
00129         m_wndLanLabel.ShowWindow( nGroup > 1 ? SW_SHOW : SW_HIDE );
00130         m_wndLanSelect.ShowWindow( nGroup > 1 ? SW_SHOW : SW_HIDE );
00131         
00132         m_wndHomeSelect.SetCurSel( 2 );
00133         m_wndLanSelect.SetCurSel( nGroup == 2 ? 0 : 1 );
00134         
00135         m_wndSpeed.SetWindowText( _T("") );
00136         m_wndSpeed.SetCurSel( -1 );
00137         m_wndSpeed.EnableWindow( FALSE );
00138         m_wndType.EnableWindow( TRUE );
00139         m_wndType.SetCurSel( nGroup == 1 ? 1 : 8 );
00140 }
00141 
00142 void CWizardConnectionPage::OnSelChangeConnectionType() 
00143 {
00144         m_wndSpeed.EnableWindow( m_wndType.GetCurSel() < 1 );
00145         if ( m_wndType.GetCurSel() > 0 ) m_wndSpeed.SetWindowText( _T("") );
00146 }
00147 
00148 void CWizardConnectionPage::OnEditChangeConnectionSpeed()
00149 {
00150         CString strSpeed;
00151         m_wndSpeed.GetWindowText( strSpeed );
00152         m_wndType.EnableWindow( strSpeed.IsEmpty() );
00153         if ( strSpeed.GetLength() ) m_wndType.SetCurSel( -1 );
00154 }
00155 
00156 void CWizardConnectionPage::OnSelChangeConnectionSpeed()
00157 {
00158         m_wndType.EnableWindow( m_wndSpeed.GetCurSel() < 1 );
00159         if ( m_wndSpeed.GetCurSel() > 0 ) m_wndType.SetCurSel( -1 );
00160 }
00161 
00162 LRESULT CWizardConnectionPage::OnWizardNext() 
00163 {
00164         if ( GetAsyncKeyState( VK_SHIFT ) & 0x8000 ) return 0;
00165         
00166         int nGroup = m_wndGroup.GetCurSel();
00167         
00168         if ( nGroup <= 0 )
00169         {
00170                 CString strMessage;
00171                 LoadString( strMessage, IDS_WIZARD_NEED_CONNECTION );
00172                 AfxMessageBox( strMessage, MB_ICONEXCLAMATION );
00173                 return -1;
00174         }
00175         else if ( nGroup == 1 )
00176         {
00177                 CString strFormat, strMessage;
00178                 
00179                 switch ( m_wndHomeSelect.GetCurSel() )
00180                 {
00181                 case 0:
00182                         Settings.Connection.FirewallStatus      = CONNECTION_OPEN;
00183                         if ( Settings.Connection.InPort == 6346 )
00184                                 Settings.Connection.InPort      = Network.RandomPort();
00185                         break;
00186                 case 1:
00187                         Settings.Connection.FirewallStatus      = CONNECTION_OPEN;
00188                         // Settings.Connection.InPort           = 6346;
00189                         LoadString( strFormat, IDS_WIZARD_PORT_FORWARD );
00190                         strMessage.Format( strFormat, Settings.Connection.InPort );
00191                         AfxMessageBox( strMessage, MB_ICONINFORMATION );
00192                         break;
00193                 case 2:
00194                         Settings.Connection.FirewallStatus      = CONNECTION_FIREWALLED;
00195                         Settings.Connection.InPort                      = 6346;
00196                         break;
00197                 case 3:
00198                         Settings.Connection.FirewallStatus      = CONNECTION_AUTO;
00199                         Settings.Connection.InPort                      = 6346;
00200                         break;
00201                 }
00202         }
00203         else
00204         {
00205                 switch ( m_wndLanSelect.GetCurSel() )
00206                 {
00207                 case 0:
00208                         Settings.Connection.FirewallStatus      = CONNECTION_OPEN;
00209                         if ( Settings.Connection.InPort == 6346 )
00210                                 Settings.Connection.InPort      = Network.RandomPort();
00211                         break;
00212                 case 1:
00213                         Settings.Connection.FirewallStatus      = CONNECTION_FIREWALLED;
00214                         Settings.Connection.InPort                      = 6346;
00215                         break;
00216                 case 2:
00217                         Settings.Connection.FirewallStatus      = CONNECTION_AUTO;
00218                         Settings.Connection.InPort                      = 6346;
00219                         break;
00220                 }
00221         }
00222         
00223         int nIndex      = m_wndType.GetCurSel();
00224         int nSpeed      = 0;
00225         
00226         if ( nIndex > 0 )
00227         {
00228                 nSpeed = m_wndType.GetItemData( nIndex );
00229         }
00230         else
00231         {
00232                 CString strSpeed;
00233                 m_wndSpeed.GetWindowText( strSpeed );
00234                 
00235                 if ( _stscanf( strSpeed, _T("%lu"), &nSpeed ) != 1 || nSpeed <= 0 )
00236                 {
00237                         LoadString( strSpeed, IDS_WIZARD_NEED_SPEED );
00238                         AfxMessageBox( strSpeed, MB_ICONEXCLAMATION );
00239                         return -1;
00240                 }
00241         }
00242         
00243         Settings.Connection.InSpeed             = nSpeed;
00244 
00245         if( nSpeed <= 56 )                                                              // Dial up modem
00246                 Settings.Connection.OutSpeed = 32;
00247         else if( nSpeed <= 128 )                                                // ISDN
00248                 Settings.Connection.OutSpeed = nSpeed;
00249         else if( nSpeed == 384 )                                                // 384/128 DSL (Europe)
00250                 Settings.Connection.OutSpeed = 128;
00251         else if( nSpeed <= 700 )                                                // ADSL (4:1)
00252                 Settings.Connection.OutSpeed = nSpeed / 4;
00253         else if( nSpeed <  1544 )                                               // ADSL (6:1)
00254                 Settings.Connection.OutSpeed = nSpeed / 6;
00255         else if( nSpeed == 1544 )                                               // T1 (1:1)
00256                 Settings.Connection.OutSpeed = nSpeed;
00257         else if( nSpeed <= 4000 )                                               // Cable (2:1)
00258                 Settings.Connection.OutSpeed = nSpeed / 2;
00259         else if( nSpeed <= 8192 )                                               // ADSL2 (8:1)
00260                 Settings.Connection.OutSpeed = nSpeed / 8;
00261         else if( nSpeed <= 12288 )                                              // ADSL2 (10:1)
00262                 Settings.Connection.OutSpeed = nSpeed / 10;
00263         else if( nSpeed <= 24576 )                                              // ADSL2+ (12:1)
00264                 Settings.Connection.OutSpeed = nSpeed / 12;
00265         else                                                                                    // High capacity lines. (LAN, etc)
00266                 Settings.Connection.OutSpeed = nSpeed;
00267 
00268         // Set upload limit to 90% of capacity, trimmed down to the nearest KB. (Usually works out at ~85% total)
00269         Settings.Bandwidth.Uploads = (DWORD)( Settings.Connection.OutSpeed * 0.9 );
00270         Settings.Bandwidth.Uploads >>= 3;
00271         Settings.Bandwidth.Uploads *= 1024;
00272         
00273         if ( nSpeed > 750 )
00274         {
00275                 Settings.Gnutella2.NumPeers = max( Settings.Gnutella2.NumPeers, 4 );
00276         }
00277         
00278         Settings.eDonkey.MaxLinks = ( nSpeed < 100 || ! theApp.m_bNT ) ? 35 : 250;
00279         
00280         if ( nSpeed > 2500 && theApp.m_bNT && ( !theApp.m_bLimitedConnections || Settings.General.IgnoreXPsp2 ) )
00281         {       // Very high capacity connection
00282                 Settings.Downloads.MaxFiles                             = 32;
00283                 Settings.Downloads.MaxTransfers                 = 200;
00284                 Settings.Downloads.MaxFileTransfers             = 32;
00285                 Settings.Downloads.MaxConnectingSources = 32;
00286                 Settings.Downloads.MaxFileSearches              = 3;
00287 
00288                 Settings.Gnutella2.NumLeafs                             = 400; //Can probably support more leaves
00289                 Settings.BitTorrent.DownloadTorrents    = 4;    // Should be able to handle several torrents
00290         }
00291         else if ( nSpeed > 768 && theApp.m_bNT )
00292         {       // Fast broadband
00293                 Settings.Downloads.MaxFiles                             = 26;
00294                 Settings.Downloads.MaxTransfers                 = 100;
00295                 Settings.Downloads.MaxFileTransfers             = 10;
00296                 Settings.Downloads.MaxConnectingSources = 28;
00297                 Settings.Downloads.MaxFileSearches              = 2;
00298         }
00299         else if ( nSpeed > 256 && theApp.m_bNT )
00300         {       // Slower broadband
00301                 Settings.Downloads.MaxFiles                             = 20;
00302                 Settings.Downloads.MaxTransfers                 = 64;
00303                 Settings.Downloads.MaxFileTransfers             = 8;
00304                 Settings.Downloads.MaxConnectingSources = 24;
00305                 Settings.Downloads.MaxFileSearches              = 1;
00306                 Settings.Search.GeneralThrottle                 = 250;
00307         }
00308         else if ( nSpeed > 80 && theApp.m_bNT )
00309         {       // IDSN, Dual modems, etc
00310                 Settings.Downloads.MaxFiles                             = 14;
00311                 Settings.Downloads.MaxTransfers                 = 32;
00312                 Settings.Downloads.MaxFileTransfers             = 6;
00313                 Settings.Downloads.MaxConnectingSources = 20;
00314                 Settings.Downloads.MaxFileSearches              = 0;
00315                 Settings.Search.GeneralThrottle                 = 250;  // Slow searches a little so we don't get flooded
00316         }
00317         else
00318         {       // Modem users / Win9x
00319                 Settings.Downloads.MaxFiles                             = 8;
00320                 Settings.Downloads.MaxTransfers                 = 24;
00321                 Settings.Downloads.MaxFileTransfers             = 4;
00322                 Settings.Downloads.MaxConnectingSources = 16;
00323                 Settings.Downloads.MaxFileSearches              = 0;
00324                 Settings.Downloads.SourcesWanted                = 200;  // Don't bother requesting so many sources
00325                 Settings.Search.GeneralThrottle                 = 300;  // Slow searches a little so we don't get flooded
00326 
00327                 Settings.BitTorrent.DownloadTorrents    = 1;    // Best not to try too many torrents
00328         }
00329         
00330         UploadQueues.CreateDefault();
00331 
00332         if ( ( theApp.m_bLimitedConnections ) && ( ! Settings.General.IgnoreXPsp2 ) ) 
00333         {       // Window XP Service Pack 2
00334                 theApp.Message( MSG_ERROR, _T("Warning  - Windows XP Service Pack 2 detected. Performance may be reduced.") );
00335                 Settings.Downloads.ConnectThrottle              = max( Settings.Downloads.ConnectThrottle, DWORD(800) );
00336                 Settings.Connection.ConnectThrottle             = max( Settings.Connection.ConnectThrottle, DWORD(250) );
00337                 Settings.Gnutella.ConnectFactor                 = min( Settings.Gnutella.ConnectFactor, DWORD(3) );
00338                 Settings.Gnutella2.NumHubs                              = min( Settings.Gnutella2.NumHubs, 2 );
00339                 Settings.Gnutella1.EnableAlways                 = FALSE;
00340                 Settings.Gnutella1.EnableToday                  = FALSE;
00341                 Settings.Downloads.MaxConnectingSources = 8;
00342                 Settings.Connection.RequireForTransfers = TRUE;
00343                 Settings.Connection.SlowConnect                 = TRUE;
00344                 //Settings.Connection.TimeoutConnect    = 30000;
00345                 //Settings.Connection.TimeoutHandshake  = 60000;
00346 
00347                 CHelpDlg::Show( _T("GeneralHelp.XPsp2") );
00348         }
00349 
00350         // Update the G2 host cache (if necessary)
00351         if ( HostCache.Gnutella2.CountHosts() < 25 ) DiscoveryServices.QueryForHosts( PROTOCOL_G2 );
00352 
00353         // Load default ed2k server list (if necessary)
00354         if ( HostCache.eDonkey.CountHosts() < 8 ) HostCache.eDonkey.LoadDefaultED2KServers();
00355         
00356         return 0;
00357 }
00358 

Generated on Thu Dec 15 10:39:51 2005 for Shareaza 2.2.1.0 by  doxygen 1.4.2