00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include "StdAfx.h"
00023 #include "Shareaza.h"
00024 #include "DlgURLCopy.h"
00025 #include "Transfer.h"
00026 #include "Network.h"
00027 #include "SHA.h"
00028 #include "TigerTree.h"
00029 #include "ED2K.h"
00030
00031 #ifdef _DEBUG
00032 #define new DEBUG_NEW
00033 #undef THIS_FILE
00034 static char THIS_FILE[] = __FILE__;
00035 #endif
00036
00037 IMPLEMENT_DYNAMIC(CURLCopyDlg, CSkinDialog)
00038
00039 BEGIN_MESSAGE_MAP(CURLCopyDlg, CSkinDialog)
00040
00041 ON_WM_CTLCOLOR()
00042 ON_WM_SETCURSOR()
00043 ON_WM_LBUTTONDOWN()
00044 ON_BN_CLICKED(IDC_INCLUDE_SELF, OnIncludeSelf)
00045
00046 END_MESSAGE_MAP()
00047
00048
00050
00051
00052 CURLCopyDlg::CURLCopyDlg(CWnd* pParent) : CSkinDialog(CURLCopyDlg::IDD, pParent)
00053 {
00054
00055 m_sHost = _T("");
00056 m_sMagnet = _T("");
00057 m_sED2K = _T("");
00058
00059 m_bSHA1 = m_bTiger = m_bED2K = m_bSize = FALSE;
00060 }
00061
00062 void CURLCopyDlg::DoDataExchange(CDataExchange* pDX)
00063 {
00064 CSkinDialog::DoDataExchange(pDX);
00065
00066 DDX_Control(pDX, IDC_INCLUDE_SELF, m_wndIncludeSelf);
00067 DDX_Control(pDX, IDC_MESSAGE, m_wndMessage);
00068 DDX_Text(pDX, IDC_URL_HOST, m_sHost);
00069 DDX_Text(pDX, IDC_URL_MAGNET, m_sMagnet);
00070 DDX_Text(pDX, IDC_URL_ED2K, m_sED2K);
00071
00072 }
00073
00075
00076
00077 BOOL CURLCopyDlg::OnInitDialog()
00078 {
00079 CSkinDialog::OnInitDialog();
00080
00081 SkinMe( NULL, IDI_WEB_URL );
00082
00083 m_wndIncludeSelf.ShowWindow( ( Network.IsListening() && m_bSHA1 && m_sHost.IsEmpty() )
00084 ? SW_SHOW : SW_HIDE );
00085
00086 OnIncludeSelf();
00087
00088 return TRUE;
00089 }
00090
00091 void CURLCopyDlg::OnIncludeSelf()
00092 {
00093 CString strURN;
00094
00095 if ( m_bTiger && m_bSHA1 )
00096 {
00097 strURN = _T("urn:bitprint:")
00098 + CSHA::HashToString( &m_pSHA1 ) + '.'
00099 + CTigerNode::HashToString( &m_pTiger );
00100 }
00101 else if ( m_bSHA1 )
00102 {
00103 strURN = CSHA::HashToString( &m_pSHA1, TRUE );
00104 }
00105 else if ( m_bED2K )
00106 {
00107 strURN = CED2K::HashToString( &m_pED2K, TRUE );
00108 }
00109
00110 m_sMagnet = _T("magnet:?");
00111
00112 if ( strURN.GetLength() )
00113 {
00114 m_sMagnet += _T("xt=") + strURN;
00115 }
00116
00117 if ( m_sName.GetLength() )
00118 {
00119 CString strName = CTransfer::URLEncode( m_sName );
00120
00121 if ( strURN.GetLength() )
00122 {
00123 m_sMagnet += _T("&dn=") + strName;
00124 }
00125 else
00126 {
00127 m_sMagnet += _T("kt=") + strName;
00128 }
00129 }
00130
00131 if ( m_wndIncludeSelf.GetCheck() && strURN.GetLength() )
00132 {
00133 CString strURL;
00134
00135 strURL.Format( _T("http://%s:%i/uri-res/N2R?%s"),
00136 (LPCTSTR)CString( inet_ntoa( Network.m_pHost.sin_addr ) ),
00137 htons( Network.m_pHost.sin_port ),
00138 (LPCTSTR)strURN );
00139
00140 m_sMagnet += _T("&xs=") + CTransfer::URLEncode( strURL );
00141 }
00142
00143 if ( m_bED2K && m_bSize && m_sName.GetLength() )
00144 {
00145 m_sED2K.Format( _T("ed2k://|file|%s|%I64i|%s|/"),
00146 (LPCTSTR)CConnection::URLEncode( m_sName ),
00147 m_nSize,
00148 (LPCTSTR)CED2K::HashToString( &m_pED2K ) );
00149 }
00150
00151 UpdateData( FALSE );
00152 }
00153
00154 HBRUSH CURLCopyDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
00155 {
00156 HBRUSH hbr = CSkinDialog::OnCtlColor(pDC, pWnd, nCtlColor);
00157
00158 if ( pWnd && pWnd != &m_wndMessage )
00159 {
00160 TCHAR szName[32];
00161 GetClassName( pWnd->GetSafeHwnd(), szName, 32 );
00162
00163 if ( ! _tcsicmp( szName, _T("Static") ) )
00164 {
00165 pDC->SetTextColor( RGB( 0, 0, 255 ) );
00166 pDC->SelectObject( &theApp.m_gdiFontLine );
00167 }
00168 }
00169
00170 return hbr;
00171 }
00172
00173 BOOL CURLCopyDlg::OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message)
00174 {
00175 CPoint point;
00176 GetCursorPos( &point );
00177
00178 for ( pWnd = GetWindow( GW_CHILD ) ; pWnd ; pWnd = pWnd->GetNextWindow() )
00179 {
00180 TCHAR szName[32];
00181 GetClassName( pWnd->GetSafeHwnd(), szName, 32 );
00182
00183 if ( ! _tcsicmp( szName, _T("Static") ) && pWnd != &m_wndMessage )
00184 {
00185 CString strText;
00186 CRect rc;
00187
00188 pWnd->GetWindowRect( &rc );
00189
00190 if ( rc.PtInRect( point ) )
00191 {
00192 pWnd->GetWindowText( strText );
00193
00194 if ( strText.GetLength() )
00195 {
00196 SetCursor( theApp.LoadCursor( IDC_HAND ) );
00197 return TRUE;
00198 }
00199 }
00200 }
00201 }
00202
00203 return CSkinDialog::OnSetCursor( pWnd, nHitTest, message );
00204 }
00205
00206 void CURLCopyDlg::OnLButtonDown(UINT nFlags, CPoint point)
00207 {
00208 ClientToScreen( &point );
00209
00210 for ( CWnd* pWnd = GetWindow( GW_CHILD ) ; pWnd ; pWnd = pWnd->GetNextWindow() )
00211 {
00212 TCHAR szName[32];
00213 GetClassName( pWnd->GetSafeHwnd(), szName, 32 );
00214
00215 if ( ! _tcsicmp( szName, _T("Static") ) && pWnd != &m_wndMessage )
00216 {
00217 CRect rc;
00218 pWnd->GetWindowRect( &rc );
00219
00220 if ( rc.PtInRect( point ) )
00221 {
00222 CString strURL;
00223
00224 pWnd->GetWindowText( strURL );
00225 if ( strURL.IsEmpty() ) return;
00226
00227 SetClipboardText( strURL );
00228
00229 CSkinDialog::OnOK();
00230 return;
00231 }
00232 }
00233 }
00234
00235 CSkinDialog::OnLButtonDown( nFlags, point );
00236 }
00237
00238 BOOL CURLCopyDlg::SetClipboardText(CString& strText)
00239 {
00240 if ( ! AfxGetMainWnd()->OpenClipboard() ) return FALSE;
00241
00242 USES_CONVERSION;
00243 EmptyClipboard();
00244
00245 if ( theApp.m_bNT )
00246 {
00247 LPCWSTR pszWide = T2CW( (LPCTSTR)strText );
00248 HANDLE hMem = GlobalAlloc( GMEM_MOVEABLE|GMEM_DDESHARE, ( wcslen(pszWide) + 1 ) * sizeof(WCHAR) );
00249 LPVOID pMem = GlobalLock( hMem );
00250 CopyMemory( pMem, pszWide, ( wcslen(pszWide) + 1 ) * sizeof(WCHAR) );
00251 GlobalUnlock( hMem );
00252 SetClipboardData( CF_UNICODETEXT, hMem );
00253 }
00254 else
00255 {
00256 LPCSTR pszASCII = T2CA( (LPCTSTR)strText );
00257 HANDLE hMem = GlobalAlloc( GMEM_MOVEABLE|GMEM_DDESHARE, strlen(pszASCII) + 1 );
00258 LPVOID pMem = GlobalLock( hMem );
00259 CopyMemory( pMem, pszASCII, strlen(pszASCII) + 1 );
00260 GlobalUnlock( hMem );
00261 SetClipboardData( CF_TEXT, hMem );
00262 }
00263
00264 CloseClipboard();
00265
00266 return TRUE;
00267 }
00268