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

PageSettingsGnutella.cpp

Go to the documentation of this file.
00001 //
00002 // PageSettingsGnutella.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 "WndSettingsSheet.h"
00026 #include "PageSettingsNetworks.h"
00027 #include "PageSettingsGnutella.h"
00028 #include ".\pagesettingsgnutella.h"
00029 
00030 #ifdef _DEBUG
00031 #define new DEBUG_NEW
00032 #undef THIS_FILE
00033 static char THIS_FILE[] = __FILE__;
00034 #endif
00035 
00036 IMPLEMENT_DYNCREATE(CGnutellaSettingsPage, CSettingsPage)
00037 
00038 BEGIN_MESSAGE_MAP(CGnutellaSettingsPage, CSettingsPage)
00039         //{{AFX_MSG_MAP(CGnutellaSettingsPage)
00040         ON_BN_CLICKED(IDC_G2_TODAY, OnG2Today)
00041         ON_BN_CLICKED(IDC_G1_TODAY, OnG1Today)
00042         ON_BN_CLICKED(IDC_G2_ALWAYS, OnG2Always)
00043         //}}AFX_MSG_MAP
00044 END_MESSAGE_MAP()
00045 
00046 
00048 // CGnutellaSettingsPage property page
00049 
00050 CGnutellaSettingsPage::CGnutellaSettingsPage() : CSettingsPage( CGnutellaSettingsPage::IDD )
00051 {
00052         //{{AFX_DATA_INIT(CGnutellaSettingsPage)
00053         m_bG2Today = FALSE;
00054         m_bG1Today = FALSE;
00055         m_bG1Always = FALSE;
00056         m_nG1Hubs = 0;
00057         m_nG1Leafs = 0;
00058         m_nG1Peers = 0;
00059         m_nG2Hubs = 0;
00060         m_nG2Leafs = 0;
00061         m_nG2Peers = 0;
00062         m_bDeflateHub2Hub = FALSE;
00063         m_bDeflateLeaf2Hub = FALSE;
00064         m_bDeflateHub2Leaf = FALSE;
00065         //}}AFX_DATA_INIT
00066 }
00067 
00068 CGnutellaSettingsPage::~CGnutellaSettingsPage()
00069 {
00070 }
00071 
00072 void CGnutellaSettingsPage::DoDataExchange(CDataExchange* pDX)
00073 {
00074         CSettingsPage::DoDataExchange(pDX);
00075         //{{AFX_DATA_MAP(CGnutellaSettingsPage)
00076         DDX_Control(pDX, IDC_G2_PEERS_SPIN, m_wndG2Peers);
00077         DDX_Control(pDX, IDC_G2_LEAFS_SPIN, m_wndG2Leafs);
00078         DDX_Control(pDX, IDC_G2_HUBS_SPIN, m_wndG2Hubs);
00079         DDX_Control(pDX, IDC_G1_PEERS_SPIN, m_wndG1Peers);
00080         DDX_Control(pDX, IDC_G1_LEAFS_SPIN, m_wndG1Leafs);
00081         DDX_Control(pDX, IDC_G1_HUBS_SPIN, m_wndG1Hubs);
00082         DDX_Check(pDX, IDC_G2_TODAY, m_bG2Today);
00083         DDX_Control(pDX, IDC_G2_ALWAYS, m_wndG2Always);
00084         DDX_Check(pDX, IDC_G1_TODAY, m_bG1Today);
00085         DDX_Check(pDX, IDC_G1_ALWAYS, m_bG1Always);
00086         DDX_Text(pDX, IDC_G1_HUBS, m_nG1Hubs);
00087         DDX_Text(pDX, IDC_G1_LEAFS, m_nG1Leafs);
00088         DDX_Text(pDX, IDC_G1_PEERS, m_nG1Peers);
00089         DDX_Text(pDX, IDC_G2_HUBS, m_nG2Hubs);
00090         DDX_Text(pDX, IDC_G2_LEAFS, m_nG2Leafs);
00091         DDX_Text(pDX, IDC_G2_PEERS, m_nG2Peers);
00092         DDX_Check(pDX, IDC_DEFLATE_HUB2HUB, m_bDeflateHub2Hub);
00093         DDX_Check(pDX, IDC_DEFLATE_LEAF2HUB, m_bDeflateLeaf2Hub);
00094         DDX_Check(pDX, IDC_DEFLATE_HUB2LEAF, m_bDeflateHub2Leaf);
00095         DDX_Control(pDX, IDC_G1_CLIENTMODE, m_wndG1ClientMode);
00096         DDX_Control(pDX, IDC_G2_CLIENTMODE, m_wndG2ClientMode);
00097         //}}AFX_DATA_MAP
00098 }
00099 
00101 // CGnutellaSettingsPage message handlers
00102 
00103 BOOL CGnutellaSettingsPage::OnInitDialog() 
00104 {
00105         CSettingsPage::OnInitDialog();
00106         
00107         //Load initial values from the settings variables
00108         m_bG2Today                      = Settings.Gnutella2.EnableToday;
00109         m_bG1Today                      = Settings.Gnutella1.EnableToday;
00110         m_bG1Always                     = Settings.Gnutella1.EnableAlways;
00111         m_bDeflateHub2Hub       = Settings.Gnutella.DeflateHub2Hub;
00112         m_bDeflateLeaf2Hub      = Settings.Gnutella.DeflateLeaf2Hub;
00113         m_bDeflateHub2Leaf      = Settings.Gnutella.DeflateHub2Leaf;
00114         m_nG1Hubs                       = Settings.Gnutella1.NumHubs;
00115         m_nG1Leafs                      = Settings.Gnutella1.NumLeafs;
00116         m_nG1Peers                      = Settings.Gnutella1.NumPeers;
00117         m_nG2Hubs                       = Settings.Gnutella2.NumHubs;
00118         m_nG2Leafs                      = Settings.Gnutella2.NumLeafs;
00119         m_nG2Peers                      = Settings.Gnutella2.NumPeers;
00120         
00121         m_wndG1Peers.SetRange( 0, 64 );
00122         m_wndG1Leafs.SetRange( 0, 1024 );
00123         m_wndG1Hubs.SetRange( 0, 2 );
00124         
00125         m_wndG2Peers.SetRange( 0, 64 );
00126         m_wndG2Leafs.SetRange( 0, 1024 );
00127         m_wndG2Hubs.SetRange( 0, 3 );
00128         
00129         m_wndG1ClientMode.SetItemData( 0, MODE_AUTO );
00130         m_wndG1ClientMode.SetItemData( 1, MODE_LEAF );
00131         m_wndG1ClientMode.SetItemData( 2, MODE_ULTRAPEER );
00132 
00133         m_wndG1ClientMode.SetCurSel( Settings.Gnutella1.ClientMode );
00134 
00135         m_wndG2ClientMode.SetItemData( 0, MODE_AUTO );
00136         m_wndG2ClientMode.SetItemData( 1, MODE_LEAF );
00137         m_wndG2ClientMode.SetItemData( 2, MODE_HUB );
00138 
00139         //********************                                  Temp- until UP mode fixed
00140         Settings.Gnutella1.ClientMode = MODE_LEAF;
00141         m_wndG1ClientMode.EnableWindow( FALSE ); 
00142         m_wndG1ClientMode.SetCurSel( MODE_LEAF );
00143         //********************
00144 
00145         if ( ! theApp.m_bNT )
00146         {       //Win9x systems cannot handle G2 hub mode
00147                 Settings.Gnutella2.ClientMode = MODE_LEAF;
00148                 m_wndG2ClientMode.EnableWindow( FALSE ); 
00149         }
00150         m_wndG2ClientMode.SetCurSel( Settings.Gnutella2.ClientMode );
00151 
00152         m_wndG2Always.SetCheck( BST_INDETERMINATE );
00153         
00154         UpdateData( FALSE );
00155         
00156         return TRUE;
00157 }
00158 
00159 BOOL CGnutellaSettingsPage::OnSetActive() 
00160 {
00161         CNetworksSettingsPage* ppNetworks =
00162                 (CNetworksSettingsPage*)GetPage( RUNTIME_CLASS(CNetworksSettingsPage) );
00163         
00164         if ( ppNetworks->GetSafeHwnd() != NULL )
00165         {
00166                 ppNetworks->UpdateData( TRUE );
00167                 m_bG2Today = ppNetworks->m_bG2Enable;
00168                 m_bG1Today = ppNetworks->m_bG1Enable;
00169                 UpdateData( FALSE );
00170         }
00171         
00172         return CSettingsPage::OnSetActive();
00173 }
00174 
00175 void CGnutellaSettingsPage::OnG2Today() 
00176 {
00177         UpdateData();
00178         
00179         if ( ! m_bG2Today )
00180         {
00181                 CString strMessage;
00182                 LoadString( strMessage, IDS_NETWORK_DISABLE_G2 );
00183                 
00184                 if ( AfxMessageBox( strMessage, MB_ICONEXCLAMATION|MB_YESNO|MB_DEFBUTTON2 ) != IDYES )
00185                 {
00186                         m_bG2Today = TRUE;
00187                         UpdateData( FALSE );
00188                 }
00189         }
00190         
00191         CNetworksSettingsPage* ppNetworks =
00192                 (CNetworksSettingsPage*)GetPage( RUNTIME_CLASS(CNetworksSettingsPage) );
00193         
00194         if ( ppNetworks->GetSafeHwnd() != NULL )
00195         {
00196                 ppNetworks->UpdateData( TRUE );
00197                 ppNetworks->m_bG2Enable = m_bG2Today;
00198                 ppNetworks->UpdateData( FALSE );
00199         }
00200 }
00201 
00202 void CGnutellaSettingsPage::OnG1Today() 
00203 {
00204         UpdateData( TRUE );
00205 
00206         if ( m_bG1Today && ( Settings.GetOutgoingBandwidth() < 2 ) )
00207         {
00208                 CString strMessage;
00209                 LoadString( strMessage, IDS_NETWORK_BANDWIDTH_LOW );
00210                 AfxMessageBox( strMessage, MB_OK );
00211                 m_bG1Today = FALSE;
00212                 UpdateData( FALSE );
00213         }
00214 
00215         CNetworksSettingsPage* ppNetworks =
00216                 (CNetworksSettingsPage*)GetPage( RUNTIME_CLASS(CNetworksSettingsPage) );
00217         
00218         if ( ppNetworks->GetSafeHwnd() != NULL )
00219         {
00220                 UpdateData( TRUE );
00221                 ppNetworks->UpdateData( TRUE );
00222                 ppNetworks->m_bG1Enable = m_bG1Today;
00223                 ppNetworks->UpdateData( FALSE );
00224         }
00225 }
00226 
00227 void CGnutellaSettingsPage::OnOK() 
00228 {
00229         UpdateData();
00230 
00231         // Check if G2 hub mode is forced now, and wasn't forced before.
00232         if ( ( m_wndG2ClientMode.GetCurSel() == MODE_HUB ) && ( Settings.Gnutella2.ClientMode != MODE_HUB ) )   
00233         {
00234                 CString strMessage;
00235                 LoadString( strMessage, IDS_NETWORK_FORCE_HUB );
00236                 // Warn the user, give them a chance to reset it.
00237                 if ( AfxMessageBox( strMessage, MB_ICONEXCLAMATION|MB_YESNO|MB_DEFBUTTON2 ) != IDYES )
00238                 {
00239                         m_wndG2ClientMode.SetCurSel( MODE_AUTO );
00240                         Settings.Gnutella2.ClientMode = MODE_AUTO;
00241                         UpdateData( FALSE );
00242                 }
00243         }
00244 
00245         // Limit networks if low bandwidth
00246         if ( ( Settings.GetOutgoingBandwidth() < 2 ) )
00247         {
00248                 m_bG1Today = m_bG1Always = FALSE;
00249         }
00250 
00251         // Verify good setting to prevent user killing their connection
00252         m_nG1Hubs       = min( m_nG1Hubs, 2 );
00253         m_nG1Leafs      = min( m_nG1Leafs, 1024 );
00254         m_nG1Peers      = min( m_nG1Peers, 64 );
00255         m_nG2Hubs       = min( m_nG2Hubs, 3 );
00256         m_nG2Leafs      = min( m_nG2Leafs, 1024 );
00257         m_nG2Peers      = min( m_nG2Peers, 64 );
00258         
00259         // Load values into the settings variables
00260         Settings.Gnutella2.EnableToday          = m_bG2Today;
00261         Settings.Gnutella1.EnableToday          = m_bG1Today || m_bG1Always;
00262         Settings.Gnutella1.EnableAlways         = m_bG1Always;
00263         Settings.Gnutella.DeflateHub2Hub        = m_bDeflateHub2Hub;
00264         Settings.Gnutella.DeflateLeaf2Hub       = m_bDeflateLeaf2Hub;
00265         Settings.Gnutella.DeflateHub2Leaf       = m_bDeflateHub2Leaf;
00266         Settings.Gnutella1.NumHubs                      = m_nG1Hubs;
00267         Settings.Gnutella1.NumLeafs                     = m_nG1Leafs;
00268         Settings.Gnutella1.NumPeers                     = m_nG1Peers;
00269         Settings.Gnutella2.NumHubs                      = m_nG2Hubs;
00270         Settings.Gnutella2.NumLeafs                     = m_nG2Leafs;
00271         Settings.Gnutella2.NumPeers                     = m_nG2Peers;
00272         
00273         Settings.Gnutella1.ClientMode = m_wndG1ClientMode.GetCurSel(); // Mode is equal to select position
00274         if ( Settings.Gnutella1.ClientMode > MODE_ULTRAPEER ) Settings.Gnutella1.ClientMode = MODE_AUTO;
00275 
00276         if ( Settings.Gnutella1.ClientMode == MODE_ULTRAPEER )
00277         {       // Enforce some minimum values for G1 ultrapeers
00278                 Settings.Gnutella1.NumLeafs             = max( Settings.Gnutella1.NumLeafs, 5 );
00279                 Settings.Gnutella1.NumPeers             = max( Settings.Gnutella1.NumPeers, 4 );
00280         }
00281 
00282         Settings.Gnutella2.ClientMode = m_wndG2ClientMode.GetCurSel(); // Mode is equal to select position
00283         if ( Settings.Gnutella2.ClientMode > MODE_HUB ) Settings.Gnutella2.ClientMode = MODE_AUTO;
00284         
00285         if ( Settings.Gnutella2.ClientMode == MODE_HUB )
00286         {       // Enforce some minimum values for G2 hubs
00287                 Settings.Gnutella2.NumLeafs             = max( Settings.Gnutella2.NumLeafs, 50 );
00288                 Settings.Gnutella2.NumPeers             = max( Settings.Gnutella2.NumPeers, 4 );
00289         }
00290 
00291         // Update display in case settings were changed
00292         UpdateData( FALSE );
00293 
00294         CSettingsPage::OnOK();
00295 }
00296 
00297 void CGnutellaSettingsPage::OnG2Always()
00298 {
00299         m_wndG2Always.SetCheck( BST_INDETERMINATE );
00300 }

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