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

PageSettingsConnection.cpp

Go to the documentation of this file.
00001 //
00002 // PageSettingsConnection.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 "PageSettingsConnection.h"
00026 #include "DlgHelp.h"
00027 
00028 #ifdef _DEBUG
00029 #define new DEBUG_NEW
00030 #undef THIS_FILE
00031 static char THIS_FILE[] = __FILE__;
00032 #endif
00033 
00034 IMPLEMENT_DYNCREATE(CConnectionSettingsPage, CSettingsPage)
00035 
00036 BEGIN_MESSAGE_MAP(CConnectionSettingsPage, CSettingsPage)
00037         //{{AFX_MSG_MAP(CConnectionSettingsPage)
00038         ON_CBN_EDITCHANGE(IDC_INBOUND_HOST, OnEditChangeInboundHost)
00039         ON_CBN_CLOSEUP(IDC_INBOUND_HOST, OnCloseUpInboundHost)
00040         ON_EN_CHANGE(IDC_INBOUND_PORT, OnChangeInboundPort)
00041         ON_BN_CLICKED(IDC_INBOUND_RANDOM, OnInboundRandom)
00042         //}}AFX_MSG_MAP
00043         ON_WM_SHOWWINDOW()
00044 END_MESSAGE_MAP()
00045 
00046 
00048 // CConnectionSettingsPage property page
00049 
00050 CConnectionSettingsPage::CConnectionSettingsPage() : CSettingsPage(CConnectionSettingsPage::IDD)
00051 {
00052         //{{AFX_DATA_INIT(CConnectionSettingsPage)
00053         m_bIgnoreLocalIP = FALSE;
00054         m_bInBind = FALSE;
00055         m_sInHost = _T("");
00056         m_nInPort = 0;
00057         m_sOutHost = _T("");
00058         m_nTimeoutConnection = 0;
00059         m_nTimeoutHandshake = 0;
00060         m_sOutSpeed = _T("");
00061         m_sInSpeed = _T("");
00062         m_bInRandom = FALSE;
00063         //}}AFX_DATA_INIT
00064 }
00065 
00066 CConnectionSettingsPage::~CConnectionSettingsPage()
00067 {
00068 }
00069 
00070 void CConnectionSettingsPage::DoDataExchange(CDataExchange* pDX)
00071 {
00072         CSettingsPage::DoDataExchange(pDX);
00073         //{{AFX_DATA_MAP(CConnectionSettingsPage)
00074         DDX_Control(pDX, IDC_INBOUND_PORT, m_wndInPort);
00075         DDX_Control(pDX, IDC_INBOUND_SPEED, m_wndInSpeed);
00076         DDX_Control(pDX, IDC_OUTBOUND_SPEED, m_wndOutSpeed);
00077         DDX_Control(pDX, IDC_INBOUND_HOST, m_wndInHost);
00078         DDX_Control(pDX, IDC_INBOUND_BIND, m_wndInBind);
00079         DDX_Control(pDX, IDC_TIMEOUT_HANDSHAKE_SPIN, m_wndTimeoutHandshake);
00080         DDX_Control(pDX, IDC_TIMEOUT_CONNECTION_SPIN, m_wndTimeoutConnection);
00081         DDX_Check(pDX, IDC_IGNORE_LOCAL, m_bIgnoreLocalIP);
00082         DDX_Check(pDX, IDC_INBOUND_BIND, m_bInBind);
00083         DDX_CBString(pDX, IDC_INBOUND_HOST, m_sInHost);
00084         DDX_Text(pDX, IDC_INBOUND_PORT, m_nInPort);
00085         DDX_CBString(pDX, IDC_OUTBOUND_HOST, m_sOutHost);
00086         DDX_Text(pDX, IDC_TIMEOUT_CONNECTION, m_nTimeoutConnection);
00087         DDX_Text(pDX, IDC_TIMEOUT_HANDSHAKE, m_nTimeoutHandshake);
00088         DDX_Control(pDX, IDC_CAN_ACCEPT, m_wndCanAccept);
00089         DDX_CBString(pDX, IDC_OUTBOUND_SPEED, m_sOutSpeed);
00090         DDX_CBString(pDX, IDC_INBOUND_SPEED, m_sInSpeed);
00091         DDX_Check(pDX, IDC_INBOUND_RANDOM, m_bInRandom);
00092         //}}AFX_DATA_MAP
00093 }
00094 
00096 // CConnectionSettingsPage message handlers
00097 
00098 BOOL CConnectionSettingsPage::OnInitDialog()
00099 {
00100         CSettingsPage::OnInitDialog();
00101 
00102         CString strAutomatic = GetInOutHostTranslation();
00103         CComboBox* pOutHost = (CComboBox*) GetDlgItem( IDC_OUTBOUND_HOST );
00104 
00105         // update all dropdowns
00106         m_wndInHost.DeleteString( 0 );
00107         m_wndInHost.AddString( strAutomatic );
00108         pOutHost->DeleteString( 0 );
00109         pOutHost->AddString( strAutomatic );
00110 
00111         // Firewall status
00112         CString str;
00113         LoadString( str, IDS_GENERAL_NO );
00114         m_wndCanAccept.AddString( str );
00115         LoadString( str, IDS_GENERAL_YES );
00116         m_wndCanAccept.AddString( str );
00117         LoadString( str, IDS_GENERAL_AUTO );
00118         m_wndCanAccept.AddString( str );
00119 
00120         m_wndCanAccept.SetCurSel( Settings.Connection.FirewallStatus );
00121 
00122         //m_bCanAccept                  = Settings.Connection.FirewallStatus == CONNECTION_OPEN;
00123         m_sInHost                               = Settings.Connection.InHost;
00124         m_nInPort                               = Settings.Connection.InPort;
00125         m_bInBind                               = Settings.Connection.InBind;
00126         m_sOutHost                              = Settings.Connection.OutHost;
00127         m_bIgnoreLocalIP                = Settings.Connection.IgnoreLocalIP;
00128         m_nTimeoutConnection    = Settings.Connection.TimeoutConnect / 1000;
00129         m_nTimeoutHandshake             = Settings.Connection.TimeoutHandshake / 1000;
00130 
00131         if ( m_sInHost.IsEmpty() ) m_sInHost = strAutomatic;
00132         if ( m_sOutHost.IsEmpty() ) m_sOutHost = strAutomatic;
00133 
00134         m_bInRandom = ( m_nInPort == 0 );
00135 
00136         m_wndTimeoutConnection.SetRange( 1, 480 );
00137         m_wndTimeoutHandshake.SetRange( 1, 480 );
00138 
00139         UpdateData( FALSE );
00140 
00141         m_wndInBind.EnableWindow( m_sInHost != strAutomatic);
00142 
00143         return TRUE;
00144 }
00145 
00146 CString CConnectionSettingsPage::FormatSpeed(DWORD nSpeed)
00147 {
00148         return Settings.SmartVolume( nSpeed, TRUE, TRUE );
00149 }
00150 
00151 DWORD CConnectionSettingsPage::ParseSpeed(LPCTSTR psz)
00152 {
00153         return (DWORD)Settings.ParseVolume( psz, TRUE ) / 1024;
00154 }
00155 
00156 void CConnectionSettingsPage::OnEditChangeInboundHost()
00157 {
00158         CString strAutomatic = GetInOutHostTranslation();
00159 
00160         UpdateData();
00161 
00162         m_wndInBind.EnableWindow( m_sInHost != strAutomatic );
00163 }
00164 
00165 void CConnectionSettingsPage::OnCloseUpInboundHost()
00166 {
00167         m_wndInBind.EnableWindow( m_wndInHost.GetCurSel() != 0 );
00168 }
00169 
00170 void CConnectionSettingsPage::OnChangeInboundPort()
00171 {
00172         UpdateData();
00173         BOOL bRandom = m_nInPort == 0;
00174 
00175         if ( bRandom != m_bInRandom )
00176         {
00177                 m_bInRandom = bRandom;
00178                 UpdateData( FALSE );
00179         }
00180 }
00181 
00182 void CConnectionSettingsPage::OnInboundRandom()
00183 {
00184         UpdateData();
00185 
00186         if ( m_bInRandom && m_nInPort != 0 )
00187         {
00188                 m_nInPort = 0;
00189                 UpdateData( FALSE );
00190         }
00191 }
00192 
00193 BOOL CConnectionSettingsPage::OnKillActive()
00194 {
00195         UpdateData();
00196 
00197         if ( ParseSpeed( m_sInSpeed ) == 0 )
00198         {
00199                 CString strMessage;
00200                 LoadString( strMessage, IDS_SETTINGS_NEED_BANDWIDTH );
00201                 AfxMessageBox( strMessage, MB_ICONEXCLAMATION );
00202                 m_wndInSpeed.SetFocus();
00203                 return FALSE;
00204         }
00205 
00206         if ( ParseSpeed( m_sOutSpeed ) == 0 )
00207         {
00208                 CString strMessage;
00209                 LoadString( strMessage, IDS_SETTINGS_NEED_BANDWIDTH );
00210                 AfxMessageBox( strMessage, MB_ICONEXCLAMATION );
00211                 m_wndOutSpeed.SetFocus();
00212                 return FALSE;
00213         }
00214 
00215         return CSettingsPage::OnKillActive();
00216 }
00217 
00218 void CConnectionSettingsPage::OnOK()
00219 {
00220         UpdateData();
00221 
00222         CString strAutomatic = GetInOutHostTranslation();
00223 
00224         if ( m_sInHost.CompareNoCase( strAutomatic ) == 0 )
00225                 m_sInHost.Empty();
00226         if ( m_sOutHost.CompareNoCase( strAutomatic ) == 0 )
00227                 m_sOutHost.Empty();
00228 
00229         Settings.Connection.FirewallStatus              = m_wndCanAccept.GetCurSel();
00230         Settings.Connection.InHost                              = m_sInHost;
00231         Settings.Connection.InPort                              = m_nInPort;
00232         Settings.Connection.InBind                              = m_bInBind;
00233         Settings.Connection.OutHost                             = m_sOutHost;
00234         Settings.Connection.InSpeed                             = ParseSpeed( m_sInSpeed );
00235         Settings.Connection.OutSpeed                    = ParseSpeed( m_sOutSpeed );
00236         Settings.Connection.IgnoreLocalIP               = m_bIgnoreLocalIP;
00237         Settings.Connection.TimeoutConnect              = m_nTimeoutConnection * 1000;
00238         Settings.Connection.TimeoutHandshake    = m_nTimeoutHandshake  * 1000;
00239 
00240         /*
00241         // Correct the upload limit (if required)
00242         if ( Settings.Bandwidth.Uploads )
00243         {
00244                 Settings.Bandwidth.Uploads = min ( Settings.Bandwidth.Uploads, ( ( Settings.Connection.OutSpeed / 8 ) * 1024 ) );
00245         }
00246         */
00247 
00248 
00249         UpdateData();
00250 
00251         // Warn the user about upload limiting and ed2k/BT downloads
00252         if ( ( ! Settings.Live.UploadLimitWarning ) &&
00253                  ( Settings.eDonkey.EnableToday || Settings.eDonkey.EnableAlways || Settings.BitTorrent.AdvancedInterface || Settings.BitTorrent.AdvancedInterfaceSet ) ) 
00254         {
00255                 DWORD nDownload = max( Settings.Bandwidth.Downloads, ( ( Settings.Connection.InSpeed  / 8 ) * 1024 ) );
00256                 DWORD nUpload = ( ( Settings.Connection.OutSpeed / 8 ) * 1024 );
00257                 if ( Settings.Bandwidth.Uploads > 0 ) nUpload =  min( Settings.Bandwidth.Uploads, nUpload );
00258                 
00259                 if ( ( nUpload * 16 ) < ( nDownload ) )
00260                 {
00261                         CHelpDlg::Show( _T("GeneralHelp.UploadWarning") );
00262                         Settings.Live.UploadLimitWarning = TRUE;
00263                 }
00264         }
00265         CSettingsPage::OnOK();
00266 }
00267 
00268 CString CConnectionSettingsPage::GetInOutHostTranslation()
00269 {
00270         CString strAutomatic, strInCombo, strOutCombo, strNew;
00271 
00272         LoadString( strAutomatic, IDS_SETTINGS_AUTOMATIC_IP );
00273 
00274         m_wndInHost.GetLBText( 0, strInCombo );
00275         CComboBox* pOutHost = (CComboBox*) GetDlgItem( IDC_OUTBOUND_HOST );
00276         pOutHost->GetLBText( 0, strOutCombo );
00277 
00278         // get non-english string if any
00279         strNew = strInCombo.CompareNoCase( _T("Automatic") ) == 0 ? strOutCombo : strInCombo;
00280         return strAutomatic.CompareNoCase( _T("Automatic") ) == 0 ? strNew : strAutomatic;
00281 }
00282 
00283 void CConnectionSettingsPage::OnShowWindow(BOOL bShow, UINT nStatus)
00284 {
00285         CSettingsPage::OnShowWindow(bShow, nStatus);
00286         if ( bShow )
00287         {
00288                 // Update speed units
00289                 m_sOutSpeed     = FormatSpeed( Settings.Connection.OutSpeed );
00290                 m_sInSpeed      = FormatSpeed( Settings.Connection.InSpeed );
00291 
00292                 // Dropdown
00293                 m_wndInSpeed.ResetContent();
00294                 m_wndOutSpeed.ResetContent();
00295                 const DWORD nSpeeds[] = { 28, 33, 56, 64, 128, 350, 576, 768, 1544, 3072, 45000, 100000, 155000, 0 };
00296                 for ( int nSpeed = 0 ; nSpeeds[ nSpeed ] ; nSpeed++ )
00297                 {
00298                         CString str = FormatSpeed( nSpeeds[ nSpeed ] );
00299                         m_wndInSpeed.AddString( str );
00300                         m_wndOutSpeed.AddString( str );
00301                 }
00302 
00303                 UpdateData( FALSE );
00304         }
00305 }

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