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

PageSettingsBitTorrent.cpp

Go to the documentation of this file.
00001 //
00002 // PageSettingsBitTorrent.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 "WndMain.h"
00026 //#include "Library.h"
00027 //#include "LibraryHistory.h"
00028 #include "PageSettingsBitTorrent.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(CBitTorrentSettingsPage, CSettingsPage)
00037 
00038 BEGIN_MESSAGE_MAP(CBitTorrentSettingsPage, CSettingsPage)
00039         //{{AFX_MSG_MAP(CBitTorrentSettingsPage)
00040         ON_BN_CLICKED(IDC_TORRENT_AUTOCLEAR, OnTorrentsAutoClear)
00041         ON_BN_CLICKED(IDC_TORRENTS_BROWSE, OnTorrentsBrowse)
00042         ON_BN_CLICKED(IDC_TORRENTS_TORRENTMAKERBROWSE, OnMakerBrowse)
00043         //}}AFX_MSG_MAP
00044 END_MESSAGE_MAP()
00045 
00046 
00048 // CBitTorrentSettingsPage property page
00049 
00050 CBitTorrentSettingsPage::CBitTorrentSettingsPage() : CSettingsPage(CBitTorrentSettingsPage::IDD)
00051 {
00052         //{{AFX_DATA_INIT(CBitTorrentSettingsPage)
00053         m_bTorrentInterface     = FALSE;
00054         m_bEndGame                      = FALSE;
00055         m_nLinks                        = 0;
00056         m_nDownloads            = 0;
00057         m_bAutoClear            = FALSE;
00058         m_nClearPercentage      = 0;
00059         m_bPrefBTSources        = TRUE;
00060         m_sTracker                      = _T("");
00061         m_sTorrentPath          = _T("");
00062         m_sMakerPath            = _T("");
00063         //}}AFX_DATA_INIT
00064 }
00065 
00066 CBitTorrentSettingsPage::~CBitTorrentSettingsPage()
00067 {
00068 }
00069 
00070 void CBitTorrentSettingsPage::DoDataExchange(CDataExchange* pDX)
00071 {
00072         CSettingsPage::DoDataExchange(pDX);
00073         //{{AFX_DATA_MAP(CBitTorrentSettingsPage)
00074         DDX_Check(pDX, IDC_TORRENT_INTERFACE, m_bTorrentInterface);
00075         DDX_Check(pDX, IDC_TORRENT_ENDGAME, m_bEndGame);
00076         DDX_Text(pDX, IDC_TORRENT_CLIENTLINKS, m_nLinks);
00077         DDX_Control(pDX, IDC_TORRENT_LINKS_SPIN, m_wndLinksSpin);
00078         DDX_Text(pDX, IDC_TORRENT_DOWNLOADS, m_nDownloads);
00079         DDX_Control(pDX, IDC_TORRENT_DOWNLOADS_SPIN, m_wndDownloadsSpin);
00080         DDX_Check(pDX, IDC_TORRENT_AUTOCLEAR, m_bAutoClear);
00081         DDX_Control(pDX, IDC_TORRENT_CLEAR_PERCENTAGE, m_wndClearPercentage);
00082         DDX_Control(pDX, IDC_TORRENT_CLEAR_SPIN, m_wndClearPercentageSpin);
00083         DDX_Text(pDX, IDC_TORRENT_CLEAR_PERCENTAGE, m_nClearPercentage);
00084         DDX_Check(pDX, IDC_TORRENT_PREFERENCE, m_bPrefBTSources);
00085         DDX_Text(pDX, IDC_TORRENT_DEFAULTTRACKER, m_sTracker);
00086         DDX_Control(pDX, IDC_TORRENTS_BROWSE, m_wndTorrentPath);
00087         DDX_Text(pDX, IDC_TORRENTS_FOLDER, m_sTorrentPath);
00088         DDX_Control(pDX, IDC_TORRENTS_TORRENTMAKERBROWSE, m_wndMakerPath);
00089         DDX_Text(pDX, IDC_TORRENTS_TORRENTMAKER, m_sMakerPath);
00090         //}}AFX_DATA_MAP
00091 }
00092 
00094 // CBitTorrentSettingsPage message handlers
00095 
00096 BOOL CBitTorrentSettingsPage::OnInitDialog() 
00097 {
00098         CSettingsPage::OnInitDialog();
00099         m_bTorrentInterface = Settings.BitTorrent.AdvancedInterface;
00100         m_bEndGame                      = Settings.BitTorrent.Endgame;
00101         m_nLinks                        = Settings.BitTorrent.DownloadConnections;
00102         m_sTracker                      = Settings.BitTorrent.DefaultTracker;
00103         m_sTorrentPath          = Settings.Downloads.TorrentPath;
00104         m_nDownloads            = Settings.BitTorrent.DownloadTorrents;
00105         m_sMakerPath            = Settings.BitTorrent.TorrentCreatorPath;
00106         m_bAutoClear            = Settings.BitTorrent.AutoClear;
00107         m_nClearPercentage      = Settings.BitTorrent.ClearRatio;
00108         m_bPrefBTSources        = Settings.BitTorrent.PreferenceBTSources;
00109 
00110         m_wndTorrentPath.SetIcon( IDI_BROWSE );
00111         m_wndMakerPath.SetIcon( IDI_BROWSE );
00112 
00113         m_wndClearPercentage.EnableWindow( m_bAutoClear );
00114 
00115         DWORD nMaxTorrents = ( Settings.GetOutgoingBandwidth() / 2 ) + 2;
00116         nMaxTorrents = min (DWORD(10), nMaxTorrents);
00117 
00118         m_wndClearPercentageSpin.SetRange( 100, 999 );
00119 
00120         m_wndLinksSpin.SetRange( 0, 200 );
00121         m_wndDownloadsSpin.SetRange( 0, (WORD)nMaxTorrents );
00122         UpdateData( FALSE );
00123 
00124         return TRUE;
00125 }
00126 
00127 BOOL CBitTorrentSettingsPage::OnSetActive() 
00128 {
00129         DWORD nMaxTorrents = ( Settings.GetOutgoingBandwidth() / 2 ) + 2;
00130         nMaxTorrents = min (DWORD(10), nMaxTorrents);
00131 
00132         m_nDownloads    = min( m_nDownloads, (int)nMaxTorrents );
00133         m_wndDownloadsSpin.SetRange( 0, (WORD)nMaxTorrents );
00134 
00135         UpdateData( FALSE );
00136 
00137         return CSettingsPage::OnSetActive();
00138 }
00139 
00140 void CBitTorrentSettingsPage::OnTorrentsAutoClear() 
00141 {
00142         UpdateData();
00143         m_wndClearPercentage.EnableWindow( m_bAutoClear );
00144         m_wndClearPercentageSpin.EnableWindow( m_bAutoClear );
00145 }
00146 
00147 void CBitTorrentSettingsPage::OnTorrentsBrowse() 
00148 {
00149         TCHAR szPath[MAX_PATH];
00150         LPITEMIDLIST pPath;
00151         LPMALLOC pMalloc;
00152         BROWSEINFO pBI;
00153                 
00154         ZeroMemory( &pBI, sizeof(pBI) );
00155         pBI.hwndOwner           = AfxGetMainWnd()->GetSafeHwnd();
00156         pBI.pszDisplayName      = szPath;
00157         pBI.lpszTitle           = _T("Select folder for torrents:");
00158         pBI.ulFlags                     = BIF_RETURNONLYFSDIRS;
00159         
00160         pPath = SHBrowseForFolder( &pBI );
00161 
00162         if ( pPath == NULL ) return;
00163 
00164         SHGetPathFromIDList( pPath, szPath );
00165         SHGetMalloc( &pMalloc );
00166         pMalloc->Free( pPath );
00167         pMalloc->Release();
00168         
00169         UpdateData( TRUE );
00170         m_sTorrentPath = szPath;
00171         UpdateData( FALSE );
00172 }
00173 
00174 void CBitTorrentSettingsPage::OnMakerBrowse() 
00175 {
00176         CFileDialog dlg( TRUE, _T("exe"), _T("TorrentWizard.exe") , OFN_HIDEREADONLY|OFN_FILEMUSTEXIST,
00177                 _T("Executable Files|*.exe;*.com|All Files|*.*||"), this );
00178         
00179         if ( dlg.DoModal() != IDOK ) return;
00180         
00181         UpdateData( TRUE );
00182         m_sMakerPath = dlg.GetPathName();
00183         UpdateData( FALSE );
00184 }
00185 
00186 void CBitTorrentSettingsPage::OnOK() 
00187 {
00188         BOOL bRedraw = FALSE;
00189         UpdateData( TRUE );
00190 
00191         m_nClearPercentage = min (m_nClearPercentage, 999);
00192         m_nClearPercentage = max (m_nClearPercentage, 100);
00193 
00194         if ( ! theApp.m_bNT )
00195         {
00196                 // Win9x is unable to handle high numbers of connections
00197                 m_nLinks = min ( m_nLinks, 80 );
00198         }
00199         else
00200         {
00201                 // For other systems we can guestimate a good value based on available bandwidth
00202         if ( Settings.GetOutgoingBandwidth() < 16 )
00203                 m_nLinks = min ( m_nLinks, 200 );
00204         else if ( Settings.GetOutgoingBandwidth() < 32 )
00205                 m_nLinks = min ( m_nLinks, 300 );
00206         else if ( Settings.GetOutgoingBandwidth() < 64 )
00207                 m_nLinks = min ( m_nLinks, 500 );
00208         else
00209                 m_nLinks = min ( m_nLinks, 800 );
00210         }
00211 
00212         m_nDownloads = min( m_nDownloads, (int)( ( Settings.GetOutgoingBandwidth() / 2 ) + 2 ) );
00213 
00214         UpdateData( FALSE );
00215 
00216         if ( Settings.BitTorrent.AdvancedInterface != m_bTorrentInterface ) bRedraw = TRUE;
00217 
00218         Settings.BitTorrent.AdvancedInterface   = m_bTorrentInterface;
00219         Settings.BitTorrent.Endgame                             = m_bEndGame;
00220         Settings.BitTorrent.DownloadConnections = m_nLinks;
00221         Settings.BitTorrent.DownloadTorrents    = m_nDownloads;
00222         Settings.BitTorrent.AutoClear                   = m_bAutoClear;
00223         Settings.BitTorrent.ClearRatio                  = m_nClearPercentage;
00224         Settings.BitTorrent.PreferenceBTSources = m_bPrefBTSources;
00225         Settings.BitTorrent.DefaultTracker              = m_sTracker;
00226         Settings.Downloads.TorrentPath                  = m_sTorrentPath;
00227         Settings.BitTorrent.TorrentCreatorPath  = m_sMakerPath;
00228 
00229         /*
00230         // Redraw the GUI to make torrents box show/hide if we need to
00231         if ( bRedraw ) 
00232         {
00233                 CMainWnd* pMainWnd = (CMainWnd*)AfxGetMainWnd();
00234                 pMainWnd->SetGUIMode( Settings.General.GUIMode, FALSE );
00235         }
00236         */
00237 
00238         CSettingsPage::OnOK();
00239 }

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