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

PageSettingsRemote.cpp

Go to the documentation of this file.
00001 //
00002 // PageSettingsRemote.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 "Handshakes.h"
00027 #include "PageSettingsRemote.h"
00028 #include "SHA.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_DYNAMIC(CRemoteSettingsPage, CSettingsPage)
00037 
00038 BEGIN_MESSAGE_MAP(CRemoteSettingsPage, CSettingsPage)
00039         ON_BN_CLICKED(IDC_REMOTE_ENABLE, OnBnClickedRemoteEnable)
00040         ON_EN_CHANGE(IDC_REMOTE_USERNAME, OnBnClickedRemoteEnable)
00041         ON_EN_CHANGE(IDC_REMOTE_PASSWORD, OnNewPassword)
00042         ON_WM_CTLCOLOR()
00043         ON_WM_SETCURSOR()
00044         ON_WM_LBUTTONUP()
00045 END_MESSAGE_MAP()
00046 
00047 
00049 // CRemoteSettingsPage construction
00050 
00051 CRemoteSettingsPage::CRemoteSettingsPage() : CSettingsPage( CRemoteSettingsPage::IDD )
00052 {
00053         m_bEnable = FALSE;
00054 }
00055 
00056 CRemoteSettingsPage::~CRemoteSettingsPage()
00057 {
00058 }
00059 
00060 void CRemoteSettingsPage::DoDataExchange(CDataExchange* pDX)
00061 {
00062         CSettingsPage::DoDataExchange(pDX);
00063         DDX_Check(pDX, IDC_REMOTE_ENABLE, m_bEnable);
00064         DDX_Control(pDX, IDC_REMOTE_URL, m_wndURL);
00065         DDX_Control(pDX, IDC_REMOTE_USERNAME, m_wndUsername);
00066         DDX_Text(pDX, IDC_REMOTE_USERNAME, m_sUsername);
00067         DDX_Control(pDX, IDC_REMOTE_PASSWORD, m_wndPassword);
00068         DDX_Text(pDX, IDC_REMOTE_PASSWORD, m_sPassword);
00069 }
00070 
00072 // CRemoteSettingsPage message handlers
00073 
00074 BOOL CRemoteSettingsPage::OnInitDialog()
00075 {
00076         CSettingsPage::OnInitDialog();
00077 
00078         m_bEnable       = m_bOldEnable          = Settings.Remote.Enable;
00079         m_sUsername     = m_sOldUsername        = Settings.Remote.Username;
00080         m_sOldPassword                                  = Settings.Remote.Password;
00081 
00082         if ( ! m_sOldPassword.IsEmpty() ) m_sPassword = _T("      ");
00083 
00084         UpdateData( FALSE );
00085         OnBnClickedRemoteEnable();
00086 
00087         return TRUE;
00088 }
00089 
00090 void CRemoteSettingsPage::OnNewPassword()
00091 {
00092         UpdateData();
00093 
00094         if ( m_sPassword.GetLength() < 3 )              // Password too short
00095         {
00096                 Settings.Remote.Password = m_sOldPassword;
00097         }
00098         else if ( m_sPassword == _T("      ") ) // Password hasn't been edited
00099         {
00100                 Settings.Remote.Password = m_sOldPassword;
00101         }
00102         else
00103         {
00104                 CSHA pSHA1;
00105                 pSHA1.Add( (LPCTSTR)m_sPassword, m_sPassword.GetLength() * sizeof(TCHAR) );
00106                 pSHA1.Finish();
00107                 Settings.Remote.Password = pSHA1.GetHashString( FALSE );
00108         }
00109 
00110         OnBnClickedRemoteEnable();
00111 }
00112 
00113 void CRemoteSettingsPage::OnBnClickedRemoteEnable()
00114 {
00115         UpdateData();
00116 
00117         Settings.Remote.Enable          = m_bEnable;
00118         Settings.Remote.Username        = m_sUsername;
00119 
00120         m_wndUsername.EnableWindow( m_bEnable );
00121         m_wndPassword.EnableWindow( m_bEnable );
00122 
00123         CString strURL;
00124 
00125         if ( m_bEnable && ! m_sUsername.IsEmpty() && ! Settings.Remote.Password.IsEmpty() )
00126         {
00127                 if ( Network.IsListening() )
00128                 {
00129                         strURL.Format( _T("http://%s:%i/remote/"),
00130                                 (LPCTSTR)CString( inet_ntoa( Network.m_pHost.sin_addr ) ),
00131                                 (int)ntohs( Network.m_pHost.sin_port ) );
00132                         m_wndURL.EnableWindow( TRUE );
00133                 }
00134                 else if ( Handshakes.IsListening() && Network.m_pHost.sin_port != 0 )
00135                 {
00136                         strURL.Format( _T("http://localhost:%i/remote/"),
00137                                 (int)ntohs( Network.m_pHost.sin_port ) );
00138                         m_wndURL.EnableWindow( TRUE );
00139                 }
00140                 else
00141                 {
00142                         LoadString( strURL, IDS_REMOTE_UNAVAILABLE );
00143                         m_wndURL.EnableWindow( FALSE );
00144                 }
00145         }
00146         else if ( m_bEnable )
00147         {
00148                 LoadString( strURL, IDS_REMOTE_ENABLED );
00149                 m_wndURL.EnableWindow( FALSE );
00150         }
00151         else
00152         {
00153                 LoadString( strURL, IDS_REMOTE_DISABLED );
00154                 m_wndURL.EnableWindow( FALSE );
00155         }
00156 
00157         m_wndURL.SetWindowText( strURL );
00158 
00159 }
00160 
00161 HBRUSH CRemoteSettingsPage::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
00162 {
00163         HBRUSH hbr = CSettingsPage::OnCtlColor( pDC, pWnd, nCtlColor );
00164 
00165         if ( pWnd == &m_wndURL && m_wndURL.IsWindowEnabled() )
00166         {
00167                 pDC->SelectObject( &theApp.m_gdiFontLine );
00168                 pDC->SetTextColor( RGB( 0, 0, 255 ) );
00169         }
00170 
00171         return hbr;
00172 }
00173 
00174 BOOL CRemoteSettingsPage::OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message)
00175 {
00176         CPoint point;
00177         GetCursorPos( &point );
00178         CRect rect;
00179         m_wndURL.GetWindowRect( &rect );
00180 
00181         if ( rect.PtInRect( point ) && m_wndURL.IsWindowEnabled() )
00182         {
00183                 SetCursor( AfxGetApp()->LoadCursor( IDC_HAND ) );
00184                 return TRUE;
00185         }
00186         else
00187         {
00188                 return CSettingsPage::OnSetCursor( pWnd, nHitTest, message );
00189         }
00190 }
00191 
00192 void CRemoteSettingsPage::OnLButtonUp(UINT nFlags, CPoint point)
00193 {
00194         CRect rect;
00195         m_wndURL.GetWindowRect( &rect );
00196         ScreenToClient( &rect );
00197 
00198         if ( rect.PtInRect( point ) && m_wndURL.IsWindowEnabled() )
00199         {
00200                 CString strURL;
00201                 m_wndURL.GetWindowText( strURL );
00202                 ShellExecute( GetSafeHwnd(), NULL, strURL, NULL, NULL, SW_SHOWNORMAL );
00203         }
00204 
00205         CSettingsPage::OnLButtonUp( nFlags, point );
00206 }
00207 
00208 void CRemoteSettingsPage::OnCancel()
00209 {
00210         Settings.Remote.Enable          = m_bOldEnable;
00211         Settings.Remote.Username        = m_sOldUsername;
00212         Settings.Remote.Password        = m_sOldPassword;
00213 
00214         CSettingsPage::OnCancel();
00215 }

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