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

DlgConnectTo.cpp

Go to the documentation of this file.
00001 //
00002 // DlgConnectTo.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 "DlgConnectTo.h"
00026 
00027 #ifdef _DEBUG
00028 #define new DEBUG_NEW
00029 #undef THIS_FILE
00030 static char THIS_FILE[] = __FILE__;
00031 #endif
00032 
00033 BEGIN_MESSAGE_MAP(CConnectToDlg, CSkinDialog)
00034         //{{AFX_MSG_MAP(CConnectToDlg)
00035         ON_CBN_CLOSEUP(IDC_CONNECT_HOST, OnSelChangeConnectHost)
00036         ON_WM_MEASUREITEM()
00037         ON_WM_DRAWITEM()
00038         ON_CBN_CLOSEUP(IDC_CONNECT_PROTOCOL, OnCloseUpConnectProtocol)
00039         //}}AFX_MSG_MAP
00040 END_MESSAGE_MAP()
00041 
00042 
00044 // CConnectToDlg dialog
00045 
00046 CConnectToDlg::CConnectToDlg(CWnd* pParent, BOOL bBrowseHost) : CSkinDialog(CConnectToDlg::IDD, pParent)
00047 {
00048         //{{AFX_DATA_INIT(CConnectToDlg)
00049         m_sHost = _T("");
00050         m_bNoUltraPeer = FALSE;
00051         m_nPort = 0;
00052         m_nProtocol = -1;
00053         //}}AFX_DATA_INIT
00054         m_bBrowseHost = bBrowseHost;
00055 }
00056 
00057 void CConnectToDlg::DoDataExchange(CDataExchange* pDX)
00058 {
00059         CSkinDialog::DoDataExchange(pDX);
00060         //{{AFX_DATA_MAP(CConnectToDlg)
00061         DDX_Control(pDX, IDC_CONNECT_ADVANCED, m_wndAdvanced);
00062         DDX_Control(pDX, IDC_CONNECT_PROTOCOL, m_wndProtocol);
00063         DDX_Control(pDX, IDC_CONNECT_ULTRAPEER, m_wndUltrapeer);
00064         DDX_Control(pDX, IDC_CONNECT_PROMPT, m_wndPrompt);
00065         DDX_Control(pDX, IDC_CONNECT_PORT, m_wndPort);
00066         DDX_Control(pDX, IDC_CONNECT_HOST, m_wndHost);
00067         DDX_CBString(pDX, IDC_CONNECT_HOST, m_sHost);
00068         DDX_Check(pDX, IDC_CONNECT_ULTRAPEER, m_bNoUltraPeer);
00069         DDX_Text(pDX, IDC_CONNECT_PORT, m_nPort);
00070         DDX_CBIndex(pDX, IDC_CONNECT_PROTOCOL, m_nProtocol);
00071         //}}AFX_DATA_MAP
00072 }
00073 
00075 // CConnectToDlg message handlers
00076 
00077 BOOL CConnectToDlg::OnInitDialog()
00078 {
00079         CSkinDialog::OnInitDialog();
00080 
00081         SkinMe( _T("CConnectToDlg"), m_bBrowseHost ? ID_NETWORK_BROWSE_TO : ID_NETWORK_CONNECT_TO );
00082 
00083         SelectCaption( this, m_bBrowseHost );
00084         SelectCaption( &m_wndPrompt, m_bBrowseHost );
00085 
00086         CBitmap bmImages;
00087         bmImages.LoadBitmap( IDB_PROTOCOLS );
00088         if ( theApp.m_bRTL ) 
00089                 bmImages.m_hObject = CreateMirroredBitmap( (HBITMAP)bmImages.m_hObject );
00090         m_pImages.Create( 16, 16, ILC_COLOR16|ILC_MASK, 7, 1 );
00091         m_pImages.Add( &bmImages, RGB( 0, 255, 0 ) );
00092 
00093         m_wndAdvanced.ShowWindow( m_bBrowseHost ? SW_HIDE : SW_SHOW );
00094         m_wndProtocol.ShowWindow( m_bBrowseHost ? SW_HIDE : SW_SHOW );
00095         m_wndUltrapeer.ShowWindow( m_bBrowseHost ? SW_HIDE : SW_SHOW );
00096         m_wndUltrapeer.EnableWindow( FALSE );
00097 
00098         int nItem, nCount = theApp.GetProfileInt( _T("ConnectTo"), _T("Count"), 0 );
00099 
00100         for ( nItem = 0 ; nItem < nCount ; nItem++ )
00101         {
00102                 CString strItem, strHost;
00103                 strItem.Format( _T("%.3i.Host"), nItem + 1 );
00104                 strHost = theApp.GetProfileString( _T("ConnectTo"), strItem, _T("") );
00105                 if ( strHost.GetLength() )
00106                         m_wndHost.SetItemData( m_wndHost.AddString( strHost ), nItem + 1 );
00107         }
00108 
00109         m_nPort         = Settings.Connection.InPort;
00110         m_nProtocol     = 1;
00111 
00112         UpdateData( FALSE );
00113 
00114         if ( nItem = theApp.GetProfileInt( _T("ConnectTo"), _T("Last.Index"), 0 ) )
00115         {
00116                 LoadItem( nItem );
00117         }
00118 
00119         return TRUE;
00120 }
00121 
00122 void CConnectToDlg::LoadItem(int nItem)
00123 {
00124         CString strItem, strHost;
00125         strItem.Format( _T("%.3i.Host"), nItem );
00126         m_sHost = theApp.GetProfileString( _T("ConnectTo"), strItem, _T("") );
00127         strItem.Format( _T("%.3i.Port"), nItem );
00128         m_nPort = theApp.GetProfileInt( _T("ConnectTo"), strItem, GNUTELLA_DEFAULT_PORT );
00129         strItem.Format( _T("%.3i.Protocol"), nItem );
00130         m_nProtocol = theApp.GetProfileInt( _T("ConnectTo"), strItem, PROTOCOL_G2 );
00131         UpdateData( FALSE );
00132 }
00133 
00134 void CConnectToDlg::OnSelChangeConnectHost()
00135 {
00136         int nSel = m_wndHost.GetCurSel();
00137         if ( nSel < 0 ) return;
00138         LoadItem( m_wndHost.GetItemData( nSel ) );
00139 }
00140 
00141 void CConnectToDlg::OnMeasureItem(int nIDCtl, LPMEASUREITEMSTRUCT lpMeasureItemStruct)
00142 {
00143         lpMeasureItemStruct->itemWidth  = 256;
00144         lpMeasureItemStruct->itemHeight = 18;
00145 }
00146 
00147 void CConnectToDlg::OnDrawItem(int nIDCtl, LPDRAWITEMSTRUCT lpDrawItemStruct)
00148 {
00149         if ( lpDrawItemStruct->itemID == (UINT)-1 ) return;
00150         if ( ( lpDrawItemStruct->itemAction & ODA_SELECT ) == 0 &&
00151                  ( lpDrawItemStruct->itemAction & ODA_DRAWENTIRE ) == 0 ) return;
00152 
00153         CRect rcItem( &lpDrawItemStruct->rcItem );
00154         CPoint pt( rcItem.left + 1, rcItem.top + 1 );
00155         CString str;
00156         CDC dc;
00157 
00158         dc.Attach( lpDrawItemStruct->hDC );
00159         if ( theApp.m_bRTL ) theApp.m_pfnSetLayout( dc.m_hDC, LAYOUT_RTL );
00160 
00161         CFont* pOldFont = (CFont*)dc.SelectObject( &theApp.m_gdiFont );
00162         dc.SetTextColor( GetSysColor( ( lpDrawItemStruct->itemState & ODS_SELECTED )
00163                 ? COLOR_HIGHLIGHTTEXT : COLOR_MENUTEXT ) );
00164 
00165         dc.FillSolidRect( &rcItem,
00166                 GetSysColor( ( lpDrawItemStruct->itemState & ODS_SELECTED )
00167                 ? COLOR_HIGHLIGHT : COLOR_WINDOW ) );
00168         dc.SetBkMode( TRANSPARENT );
00169 
00170         int nImage = (int)lpDrawItemStruct->itemID;
00171 
00172         if ( theApp.m_bRTL ) 
00173                 nImage = m_pImages.GetImageCount() - nImage - 2;
00174         else
00175                 nImage += 1;
00176 
00177         m_pImages.Draw( &dc, nImage, pt,
00178                 ( lpDrawItemStruct->itemState & ODS_SELECTED ) ? ILD_SELECTED : ILD_NORMAL );
00179 
00180         m_wndProtocol.GetLBText( lpDrawItemStruct->itemID, str );
00181 
00182         rcItem.left += 22; rcItem.right -= 2;
00183         dc.DrawText( str, &rcItem, DT_SINGLELINE|DT_LEFT|DT_VCENTER|DT_NOPREFIX );
00184 
00185         dc.SelectObject( pOldFont );
00186         dc.Detach();
00187 }
00188 
00189 void CConnectToDlg::OnCloseUpConnectProtocol()
00190 {
00191         int nPort;
00192 
00193         switch ( m_wndProtocol.GetCurSel() + 1 )
00194         {
00195         case PROTOCOL_G1:
00196                 nPort = GNUTELLA_DEFAULT_PORT;
00197                 m_wndUltrapeer.EnableWindow( TRUE );
00198                 break;
00199         case PROTOCOL_G2:
00200                 nPort = GNUTELLA_DEFAULT_PORT;
00201                 m_wndUltrapeer.EnableWindow( FALSE );
00202                 break;
00203         case PROTOCOL_ED2K:
00204                 nPort = ED2K_DEFAULT_PORT;
00205                 m_wndUltrapeer.EnableWindow( FALSE );
00206                 break;
00207         default:
00208                 return;
00209         }
00210 
00211         CString str;
00212         str.Format( _T("%lu"), nPort );
00213         m_wndPort.SetWindowText( str );
00214         m_wndHost.SetFocus();
00215 }
00216 
00217 void CConnectToDlg::OnOK()
00218 {
00219         UpdateData( TRUE );
00220 
00221         int nColon = m_sHost.Find( ':' );
00222 
00223         if ( nColon > 0 )
00224         {
00225                 CString strPort = m_sHost.Mid( nColon + 1 );
00226                 _stscanf( strPort, _T("%lu"), &m_nPort );
00227                 m_sHost = m_sHost.Left( nColon );
00228 
00229                 m_wndHost.SetWindowText( m_sHost );
00230                 m_wndPort.SetWindowText( strPort );
00231         }
00232 
00233         int nItem = m_wndHost.FindString( -1, m_sHost );
00234 
00235         if ( nItem < 0 )
00236         {
00237                 nItem = theApp.GetProfileInt( _T("ConnectTo"), _T("Count"), 0 ) + 1;
00238                 theApp.WriteProfileInt( _T("ConnectTo"), _T("Count"), nItem );
00239                 theApp.WriteProfileInt( _T("ConnectTo"), _T("Last.Index"), nItem );
00240         }
00241         else
00242         {
00243                 theApp.WriteProfileInt( _T("ConnectTo"), _T("Last.Index"), ++nItem );
00244         }
00245 
00246         CString strItem;
00247         strItem.Format( _T("%.3i.Host"), nItem );
00248         theApp.WriteProfileString( _T("ConnectTo"), strItem, m_sHost );
00249         strItem.Format( _T("%.3i.Port"), nItem );
00250         theApp.WriteProfileInt( _T("ConnectTo"), strItem, m_nPort );
00251         strItem.Format( _T("%.3i.Protocol"), nItem );
00252         theApp.WriteProfileInt( _T("ConnectTo"), strItem, m_nProtocol );
00253 
00254         CSkinDialog::OnOK();
00255 }

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