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 "Settings.h"
00025 #include "GProfile.h"
00026 #include "MatchObjects.h"
00027 #include "Schema.h"
00028 #include "SchemaCache.h"
00029 #include "HostBrowser.h"
00030 #include "RichDocument.h"
00031 #include "WndBrowseHost.h"
00032 #include "DlgHitColumns.h"
00033 #include "ChatWindows.h"
00034 #include "Skin.h"
00035
00036 #ifdef _DEBUG
00037 #define new DEBUG_NEW
00038 #undef THIS_FILE
00039 static char THIS_FILE[] = __FILE__;
00040 #endif
00041
00042 IMPLEMENT_DYNCREATE(CBrowseHostWnd, CBaseMatchWnd)
00043
00044 BEGIN_MESSAGE_MAP(CBrowseHostWnd, CBaseMatchWnd)
00045 ON_WM_CREATE()
00046 ON_WM_DESTROY()
00047 ON_WM_CONTEXTMENU()
00048 ON_WM_NCLBUTTONUP()
00049 ON_WM_SIZE()
00050 ON_LBN_SELCHANGE(IDC_MATCHES, OnSelChangeMatches)
00051 ON_UPDATE_COMMAND_UI(ID_BROWSE_STOP, OnUpdateBrowseHostStop)
00052 ON_COMMAND(ID_BROWSE_STOP, OnBrowseHostStop)
00053 ON_COMMAND(ID_BROWSE_REFRESH, OnBrowseHostRefresh)
00054 ON_UPDATE_COMMAND_UI(ID_BROWSE_PROFILE, OnUpdateBrowseProfile)
00055 ON_COMMAND(ID_BROWSE_PROFILE, OnBrowseProfile)
00056 ON_UPDATE_COMMAND_UI(ID_BROWSE_FILES, OnUpdateBrowseFiles)
00057 ON_COMMAND(ID_BROWSE_FILES, OnBrowseFiles)
00058 ON_UPDATE_COMMAND_UI(ID_SEARCH_CHAT, OnUpdateSearchChat)
00059 ON_COMMAND(ID_SEARCH_CHAT, OnSearchChat)
00060 END_MESSAGE_MAP()
00061
00062
00064
00065
00066 CBrowseHostWnd::CBrowseHostWnd(SOCKADDR_IN* pAddress, GGUID* pClientID)
00067 {
00068 m_pBrowser = new CHostBrowser( this, &pAddress->sin_addr, htons( pAddress->sin_port ), FALSE, pClientID );
00069 Create( IDR_BROWSEHOSTFRAME );
00070 }
00071
00072 CBrowseHostWnd::CBrowseHostWnd(IN_ADDR* pAddress, WORD nPort, BOOL bMustPush, GGUID* pClientID)
00073 {
00074 m_pBrowser = new CHostBrowser( this, pAddress, nPort, bMustPush, pClientID );
00075 Create( IDR_BROWSEHOSTFRAME );
00076 }
00077
00078 CBrowseHostWnd::~CBrowseHostWnd()
00079 {
00080 if ( m_pBrowser ) delete m_pBrowser;
00081 }
00082
00084
00085
00086 int CBrowseHostWnd::OnCreate(LPCREATESTRUCT lpCreateStruct)
00087 {
00088 if ( CBaseMatchWnd::OnCreate( lpCreateStruct ) == -1 ) return -1;
00089
00090 if ( CSchema* pSchema = SchemaCache.Get( Settings.Search.BlankSchemaURI ) )
00091 {
00092 CPtrList pColumns;
00093 CSchemaColumnsDlg::LoadColumns( pSchema, &pColumns );
00094 m_wndList.SelectSchema( pSchema, &pColumns );
00095 }
00096
00097 m_wndHeader.Create( this );
00098 m_wndProfile.Create( this );
00099 m_wndFrame.Create( this, &m_wndList );
00100
00101 LoadState( _T("CBrowseHostWnd"), TRUE );
00102
00103 m_pBrowser->Browse();
00104
00105 OnSkinChange();
00106
00107 m_bOnFiles = FALSE;
00108
00109 return 0;
00110 }
00111
00112 void CBrowseHostWnd::OnDestroy()
00113 {
00114 m_pBrowser->Stop();
00115
00116 delete m_pBrowser;
00117 m_pBrowser = NULL;
00118
00119 if ( m_wndList.m_pSchema != NULL )
00120 Settings.Search.BlankSchemaURI = m_wndList.m_pSchema->m_sURI;
00121 else
00122 Settings.Search.BlankSchemaURI.Empty();
00123
00124 SaveState( _T("CBrowseHostWnd") );
00125
00126 CBaseMatchWnd::OnDestroy();
00127 }
00128
00129 void CBrowseHostWnd::OnSkinChange()
00130 {
00131 CBaseMatchWnd::OnSkinChange();
00132
00133 Skin.CreateToolBar( _T("CBrowseHostWnd"), &m_wndToolBar );
00134 m_wndFrame.OnSkinChange();
00135 m_wndHeader.OnSkinChange();
00136 m_wndProfile.OnSkinChange();
00137
00138 UpdateMessages();
00139 }
00140
00141 BOOL CBrowseHostWnd::OnCmdMsg(UINT nID, int nCode, void* pExtra, AFX_CMDHANDLERINFO* pHandlerInfo)
00142 {
00143 if ( m_wndHeader.m_hWnd != NULL )
00144 {
00145 if ( m_wndHeader.OnCmdMsg( nID, nCode, pExtra, pHandlerInfo ) ) return TRUE;
00146 }
00147
00148 if ( m_wndProfile.m_hWnd != NULL )
00149 {
00150 if ( m_wndProfile.OnCmdMsg( nID, nCode, pExtra, pHandlerInfo ) ) return TRUE;
00151 }
00152
00153 if ( m_wndFrame.m_hWnd != NULL )
00154 {
00155 if ( m_wndFrame.OnCmdMsg( nID, nCode, pExtra, pHandlerInfo ) ) return TRUE;
00156 }
00157
00158 return CBaseMatchWnd::OnCmdMsg( nID, nCode, pExtra, pHandlerInfo );
00159 }
00160
00161 void CBrowseHostWnd::OnSize(UINT nType, int cx, int cy)
00162 {
00163 CPanelWnd::OnSize( nType, cx, cy );
00164
00165 CRect rc;
00166 GetClientRect( &rc );
00167
00168 rc.top += 64;
00169 rc.bottom -= 28;
00170
00171 m_wndHeader.SetWindowPos( NULL, rc.left, 0, rc.Width(), rc.top, SWP_NOZORDER );
00172 m_wndToolBar.SetWindowPos( NULL, rc.left, rc.bottom, rc.Width(), 28, SWP_NOZORDER );
00173 m_wndProfile.SetWindowPos( NULL, rc.left, rc.top, rc.Width(), rc.Height(), SWP_NOZORDER );
00174 m_wndFrame.SetWindowPos( NULL, rc.left, rc.top, rc.Width(), rc.Height(), SWP_NOZORDER );
00175 }
00176
00177 void CBrowseHostWnd::OnContextMenu(CWnd* pWnd, CPoint point)
00178 {
00179 if ( m_bContextMenu )
00180 {
00181 TrackPopupMenu( _T("CBrowseHostWnd"), point, ID_SEARCH_DOWNLOAD );
00182 }
00183 else
00184 {
00185 CBaseMatchWnd::OnContextMenu( pWnd, point );
00186 }
00187 }
00188
00189 void CBrowseHostWnd::OnUpdateBrowseProfile(CCmdUI* pCmdUI)
00190 {
00191 pCmdUI->SetCheck( m_wndProfile.IsWindowVisible() );
00192 }
00193
00194 void CBrowseHostWnd::OnBrowseProfile()
00195 {
00196 m_wndProfile.SetWindowPos( &wndTop, 0, 0, 0, 0, SWP_NOMOVE|SWP_NOSIZE|SWP_SHOWWINDOW );
00197 m_wndFrame.ShowWindow( SW_HIDE );
00198 m_wndProfile.Update( m_pBrowser );
00199 }
00200
00201 void CBrowseHostWnd::OnUpdateBrowseFiles(CCmdUI* pCmdUI)
00202 {
00203 pCmdUI->SetCheck( m_wndList.IsWindowVisible() );
00204 }
00205
00206 void CBrowseHostWnd::OnBrowseFiles()
00207 {
00208 m_wndFrame.SetWindowPos( &wndTop, 0, 0, 0, 0, SWP_NOMOVE|SWP_NOSIZE|SWP_SHOWWINDOW );
00209 m_wndProfile.ShowWindow( SW_HIDE );
00210 m_bOnFiles = TRUE;
00211 }
00212
00213 void CBrowseHostWnd::OnUpdateBrowseHostStop(CCmdUI* pCmdUI)
00214 {
00215 pCmdUI->Enable( m_pBrowser->IsBrowsing() );
00216 }
00217
00218 void CBrowseHostWnd::OnBrowseHostStop()
00219 {
00220 m_pBrowser->Stop();
00221 }
00222
00223 void CBrowseHostWnd::OnBrowseHostRefresh()
00224 {
00225 m_pBrowser->Stop();
00226 m_pBrowser->Browse();
00227
00228 m_wndList.DestructiveUpdate();
00229 m_pMatches->Clear();
00230
00231 m_bUpdate = TRUE;
00232 PostMessage( WM_TIMER, 2 );
00233 }
00234
00235 void CBrowseHostWnd::OnUpdateSearchChat(CCmdUI* pCmdUI)
00236 {
00237 pCmdUI->Enable( m_pBrowser && m_pBrowser->m_bCanChat );
00238 }
00239
00240 void CBrowseHostWnd::OnSearchChat()
00241 {
00242 if ( m_pBrowser != NULL )
00243 {
00244 ChatWindows.OpenPrivate( &m_pBrowser->m_pClientID,
00245 &m_pBrowser->m_pAddress, m_pBrowser->m_nPort, m_pBrowser->m_bMustPush, m_pBrowser->m_nProtocol );
00246 }
00247 }
00248
00249 void CBrowseHostWnd::OnSelChangeMatches()
00250 {
00251 m_wndFrame.OnSelChangeMatches();
00252 }
00253
00255
00256
00257 void CBrowseHostWnd::UpdateMessages(BOOL bActive)
00258 {
00259 CString strCaption, strOld;
00260
00261 m_wndHeader.Update( m_pBrowser );
00262
00263 LoadString( strCaption, IDR_BROWSEHOSTFRAME );
00264 if ( theApp.m_bRTL ) strCaption = _T("\x200F") + strCaption + _T("\x202E");
00265 strCaption += _T(" : ");
00266 if ( theApp.m_bRTL ) strCaption += _T("\x202A\x200E");
00267
00268 if ( m_pBrowser->m_pProfile != NULL && m_pBrowser->m_pProfile->IsValid() )
00269 {
00270 strOld.Format( _T("%s (%s:%lu)"),
00271 (LPCTSTR)m_pBrowser->m_pProfile->GetNick(),
00272 (LPCTSTR)CString( inet_ntoa( m_pBrowser->m_pAddress ) ),
00273 m_pBrowser->m_nPort );
00274 strCaption += strOld;
00275 }
00276 else
00277 {
00278 strOld.Format( _T("%s:%lu"),
00279 (LPCTSTR)CString( inet_ntoa( m_pBrowser->m_pAddress ) ),
00280 m_pBrowser->m_nPort );
00281 strCaption += strOld;
00282 }
00283
00284 if ( m_pMatches->m_nFilteredFiles || m_pMatches->m_nFilteredHits )
00285 {
00286 strOld.Format( _T(" [%lu/%lu]"),
00287 m_pMatches->m_nFilteredFiles, m_pMatches->m_nFilteredHits );
00288 if ( theApp.m_bRTL ) strOld = _T("\x202D") + strOld + _T(" ");
00289 strCaption += strOld;
00290 }
00291
00292 GetWindowText( strOld );
00293
00294 if ( strOld != strCaption ) SetWindowText( strCaption );
00295
00296 if ( m_pMatches->m_nFilteredFiles == 0 )
00297 {
00298 if ( m_pMatches->m_nFiles > 0 )
00299 {
00300 m_wndList.SetMessage( IDS_SEARCH_FILTERED, FALSE );
00301 return;
00302 }
00303
00304 switch ( m_pBrowser->m_nState )
00305 {
00306 case CHostBrowser::hbsNull:
00307 m_wndList.SetMessage( m_pBrowser->m_bConnect ? IDS_BROWSE_NOT_SUPPORTED : IDS_BROWSE_CANT_CONNECT );
00308 break;
00309 case CHostBrowser::hbsConnecting:
00310 m_wndList.SetMessage( m_pBrowser->m_tPushed ? IDS_BROWSE_PUSHED : IDS_BROWSE_CONNECTING );
00311 break;
00312 case CHostBrowser::hbsRequesting:
00313 case CHostBrowser::hbsHeaders:
00314 m_wndList.SetMessage( IDS_BROWSE_REQUESTING );
00315 break;
00316 case CHostBrowser::hbsContent:
00317 LoadString( strOld, IDS_BROWSE_DOWNLOADING );
00318 strCaption.Format( strOld, m_pBrowser->GetProgress() * 100.0f );
00319 m_wndList.SetMessage( strCaption );
00320 break;
00321 }
00322 }
00323 }
00324
00325 void CBrowseHostWnd::OnProfileReceived()
00326 {
00327 if ( ! m_bPaused && m_hWnd != NULL && m_wndProfile.m_hWnd != NULL)
00328 {
00329 if ( m_bOnFiles == FALSE || m_wndProfile.IsWindowVisible() )
00330 {
00331 PostMessage( WM_COMMAND, ID_BROWSE_PROFILE );
00332 }
00333
00334 m_bUpdate = TRUE;
00335 }
00336 }
00337
00338 void CBrowseHostWnd::OnBrowseHits(CQueryHit* pHits)
00339 {
00340 if ( m_bPaused || m_hWnd == NULL ) return;
00341
00342 CSingleLock pLock( &m_pMatches->m_pSection );
00343
00344 if ( pLock.Lock( 100 ) && ! m_bPaused )
00345 {
00346 m_pMatches->AddHits( pHits );
00347 m_bUpdate = TRUE;
00348 }
00349 }
00350
00351 void CBrowseHostWnd::OnHeadPacket(CG2Packet* pPacket)
00352 {
00353 if ( m_bPaused || m_hWnd == NULL ) return;
00354
00355 m_wndProfile.OnHeadPacket( pPacket );
00356 }
00357
00358 void CBrowseHostWnd::OnPhysicalTree(CG2Packet* pPacket)
00359 {
00360 if ( m_bPaused || m_hWnd == NULL ) return;
00361
00362 m_wndFrame.OnPhysicalTree( pPacket );
00363 }
00364
00365 void CBrowseHostWnd::OnVirtualTree(CG2Packet* pPacket)
00366 {
00367 if ( m_bPaused || m_hWnd == NULL ) return;
00368
00369 m_wndFrame.OnVirtualTree( pPacket );
00370 }
00371
00372 BOOL CBrowseHostWnd::OnPush(GGUID* pClientID, CConnection* pConnection)
00373 {
00374 return m_pBrowser != NULL && m_pBrowser->OnPush( pClientID, pConnection );
00375 }