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 "QuerySearch.h"
00026 #include "QueryHit.h"
00027 #include "MatchObjects.h"
00028 #include "Network.h"
00029 #include "Packet.h"
00030 #include "Schema.h"
00031 #include "Library.h"
00032 #include "SharedFile.h"
00033 #include "Downloads.h"
00034 #include "Download.h"
00035 #include "Transfers.h"
00036 #include "Security.h"
00037 #include "ChatWindows.h"
00038 #include "MatchListView.h"
00039 #include "RelatedSearch.h"
00040 #include "SHA.h"
00041 #include "ED2K.h"
00042
00043 #include "Skin.h"
00044 #include "WndMain.h"
00045 #include "WndBaseMatch.h"
00046 #include "WndDownloads.h"
00047 #include "WndSearch.h"
00048 #include "WndLibrary.h"
00049 #include "WndBrowseHost.h"
00050 #include "DlgFilterSearch.h"
00051 #include "DlgNewSearch.h"
00052 #include "DlgHitColumns.h"
00053 #include "DlgURLCopy.h"
00054 #include "DlgExistingFile.h"
00055 #include "CoolMenu.h"
00056
00057 #ifdef _DEBUG
00058 #define new DEBUG_NEW
00059 #undef THIS_FILE
00060 static char THIS_FILE[] = __FILE__;
00061 #endif
00062
00063 IMPLEMENT_DYNCREATE(CBaseMatchWnd, CPanelWnd)
00064
00065 BEGIN_MESSAGE_MAP(CBaseMatchWnd, CPanelWnd)
00066
00067 ON_WM_CREATE()
00068 ON_WM_DESTROY()
00069 ON_WM_SIZE()
00070 ON_WM_TIMER()
00071 ON_WM_CONTEXTMENU()
00072 ON_WM_MEASUREITEM()
00073 ON_WM_DRAWITEM()
00074 ON_UPDATE_COMMAND_UI(ID_SEARCH_DOWNLOAD, OnUpdateSearchDownload)
00075 ON_COMMAND(ID_SEARCH_DOWNLOAD, OnSearchDownload)
00076 ON_UPDATE_COMMAND_UI(ID_SEARCH_DOWNLOADNOW, OnUpdateSearchDownloadNow)
00077 ON_COMMAND(ID_SEARCH_DOWNLOADNOW, OnSearchDownloadNow)
00078 ON_UPDATE_COMMAND_UI(ID_SEARCH_COPY, OnUpdateSearchCopy)
00079 ON_COMMAND(ID_SEARCH_COPY, OnSearchCopy)
00080 ON_UPDATE_COMMAND_UI(ID_SEARCH_CHAT, OnUpdateSearchChat)
00081 ON_COMMAND(ID_SEARCH_CHAT, OnSearchChat)
00082 ON_UPDATE_COMMAND_UI(ID_SEARCH_FILTER, OnUpdateSearchFilter)
00083 ON_COMMAND(ID_SEARCH_FILTER, OnSearchFilter)
00084 ON_UPDATE_COMMAND_UI(ID_SEARCH_FILTER_REMOVE, OnUpdateSearchFilterRemove)
00085 ON_COMMAND(ID_SEARCH_FILTER_REMOVE, OnSearchFilterRemove)
00086 ON_COMMAND(ID_SEARCH_COLUMNS, OnSearchColumns)
00087 ON_UPDATE_COMMAND_UI(ID_LIBRARY_BITZI_WEB, OnUpdateLibraryBitziWeb)
00088 ON_COMMAND(ID_LIBRARY_BITZI_WEB, OnLibraryBitziWeb)
00089 ON_UPDATE_COMMAND_UI(ID_SECURITY_BAN, OnUpdateSecurityBan)
00090 ON_COMMAND(ID_SECURITY_BAN, OnSecurityBan)
00091 ON_UPDATE_COMMAND_UI(ID_HITMONITOR_SEARCH, OnUpdateHitMonitorSearch)
00092 ON_COMMAND(ID_HITMONITOR_SEARCH, OnHitMonitorSearch)
00093 ON_WM_MOUSEWHEEL()
00094 ON_WM_MDIACTIVATE()
00095 ON_WM_NCLBUTTONDOWN()
00096 ON_WM_SETCURSOR()
00097 ON_UPDATE_COMMAND_UI(ID_BROWSE_LAUNCH, OnUpdateBrowseLaunch)
00098 ON_COMMAND(ID_BROWSE_LAUNCH, OnBrowseLaunch)
00099 ON_COMMAND(ID_SEARCH_FILTER_RAW, OnSearchFilterRaw)
00100 ON_UPDATE_COMMAND_UI(ID_SEARCH_FOR_THIS, OnUpdateSearchForThis)
00101 ON_COMMAND(ID_SEARCH_FOR_THIS, OnSearchForThis)
00102 ON_UPDATE_COMMAND_UI(ID_SEARCH_FOR_SIMILAR, OnUpdateSearchForSimilar)
00103 ON_COMMAND(ID_SEARCH_FOR_SIMILAR, OnSearchForSimilar)
00104 ON_UPDATE_COMMAND_UI(ID_SEARCH_FOR_ARTIST, OnUpdateSearchForArtist)
00105 ON_COMMAND(ID_SEARCH_FOR_ARTIST, OnSearchForArtist)
00106 ON_UPDATE_COMMAND_UI(ID_SEARCH_FOR_ALBUM, OnUpdateSearchForAlbum)
00107 ON_COMMAND(ID_SEARCH_FOR_ALBUM, OnSearchForAlbum)
00108 ON_UPDATE_COMMAND_UI(ID_SEARCH_FOR_SERIES, OnUpdateSearchForSeries)
00109 ON_COMMAND(ID_SEARCH_FOR_SERIES, OnSearchForSeries)
00110
00111 ON_EN_KILLFOCUS(IDC_FILTER_BOX, OnKillFocusFilter)
00112 ON_BN_CLICKED(AFX_IDW_TOOLBAR, OnToolbarReturn)
00113 ON_BN_DOUBLECLICKED(AFX_IDW_TOOLBAR, OnToolbarEscape)
00114 ON_UPDATE_COMMAND_UI_RANGE(1000, 1100, OnUpdateBlocker)
00115 END_MESSAGE_MAP()
00116
00117
00119
00120
00121 CBaseMatchWnd::CBaseMatchWnd()
00122 {
00123 m_pMatches = new CMatchList();
00124 m_pCoolMenu = NULL;
00125 m_bContextMenu = FALSE;
00126 m_tContextMenu = 0;
00127 m_bPaused = FALSE;
00128 m_bUpdate = FALSE;
00129 m_bBMWActive = TRUE;
00130 m_nCacheFiles = 0;
00131 }
00132
00133 CBaseMatchWnd::~CBaseMatchWnd()
00134 {
00135 delete m_pMatches;
00136
00137 if ( m_pCoolMenu ) delete m_pCoolMenu;
00138 }
00139
00141
00142
00143 int CBaseMatchWnd::OnCreate(LPCREATESTRUCT lpCreateStruct)
00144 {
00145 if ( CPanelWnd::OnCreate( lpCreateStruct ) == -1 ) return -1;
00146
00147 m_wndList.Create( m_pMatches, this );
00148
00149 if ( ! m_wndToolBar.Create( this, WS_CHILD|WS_VISIBLE|CBRS_NOALIGN, AFX_IDW_TOOLBAR ) ) return -1;
00150 m_wndToolBar.SetBarStyle( m_wndToolBar.GetBarStyle() | CBRS_TOOLTIPS | CBRS_BORDER_TOP );
00151
00152 if ( ! m_wndFilter.Create( WS_CHILD|ES_AUTOHSCROLL, rectDefault, &m_wndToolBar, IDC_FILTER_BOX ) ) return -1;
00153 m_wndFilter.SetFont( &theApp.m_gdiFont );
00154
00155 SetTimer( 2, 500, NULL );
00156
00157 return 0;
00158 }
00159
00160 void CBaseMatchWnd::OnDestroy()
00161 {
00162 KillTimer( 2 );
00163
00164 m_pMatches->m_pSection.Lock();
00165 m_bPaused = TRUE;
00166 m_bUpdate = FALSE;
00167 m_pMatches->m_pSection.Unlock();
00168
00169 CPanelWnd::OnDestroy();
00170 }
00171
00172 BOOL CBaseMatchWnd::OnCmdMsg(UINT nID, int nCode, void* pExtra, AFX_CMDHANDLERINFO* pHandlerInfo)
00173 {
00174 if ( m_wndToolBar.m_hWnd )
00175 {
00176 if ( m_wndToolBar.OnCmdMsg( nID, nCode, pExtra, pHandlerInfo ) ) return TRUE;
00177 }
00178
00179 return CPanelWnd::OnCmdMsg( nID, nCode, pExtra, pHandlerInfo );
00180 }
00181
00182 void CBaseMatchWnd::OnSize(UINT nType, int cx, int cy)
00183 {
00184 CPanelWnd::OnSize( nType, cx, cy );
00185 SizeListAndBar( &m_wndList, &m_wndToolBar );
00186 }
00187
00188 void CBaseMatchWnd::OnContextMenu(CWnd* pWnd, CPoint point)
00189 {
00190 if ( m_wndList.HitTestHeader( point ) && m_wndList.m_pSchema != NULL )
00191 {
00192 CMenu* pMenu = CSchemaColumnsDlg::BuildColumnMenu( m_wndList.m_pSchema,
00193 &m_wndList.m_pColumns );
00194
00195 pMenu->AppendMenu( MF_SEPARATOR, ID_SEPARATOR, (LPCTSTR)NULL );
00196 CString strText;
00197 LoadString( strText, IDS_SCHEMAS );
00198 pMenu->AppendMenu( MF_STRING, ID_SEARCH_COLUMNS, strText + _T("...") );
00199
00200 m_pCoolMenu = new CCoolMenu();
00201 m_pCoolMenu->AddMenu( pMenu, TRUE );
00202 m_pCoolMenu->SetWatermark( Skin.GetWatermark( _T("CCoolMenu") ) );
00203
00204 UINT nCmd = pMenu->TrackPopupMenu( TPM_LEFTALIGN|TPM_LEFTBUTTON|TPM_RIGHTBUTTON|
00205 TPM_RETURNCMD, point.x, point.y, this );
00206
00207 delete pMenu;
00208 delete m_pCoolMenu;
00209 m_pCoolMenu = NULL;
00210
00211 if ( nCmd == ID_SEARCH_COLUMNS )
00212 {
00213 OnSearchColumns();
00214 }
00215 else if ( nCmd )
00216 {
00217 CPtrList pColumns;
00218 CSchemaColumnsDlg::ToggleColumnHelper( m_wndList.m_pSchema,
00219 &m_wndList.m_pColumns, &pColumns, nCmd, TRUE );
00220 m_wndList.SelectSchema( m_wndList.m_pSchema, &pColumns );
00221 }
00222
00223 return;
00224 }
00225
00226 m_tContextMenu = GetTickCount();
00227 m_bContextMenu = TRUE;
00228 SendMessage( WM_CONTEXTMENU, pWnd ? (WPARAM)pWnd->GetSafeHwnd() : 0, MAKELONG( point.x, point.y ) );
00229 m_bContextMenu = FALSE;
00230 }
00231
00232 void CBaseMatchWnd::OnUpdateBlocker(CCmdUI* pCmdUI)
00233 {
00234 if ( m_pCoolMenu ) pCmdUI->Enable( TRUE );
00235 else pCmdUI->ContinueRouting();
00236 }
00237
00238 void CBaseMatchWnd::OnMeasureItem(int nIDCtl, LPMEASUREITEMSTRUCT lpMeasureItemStruct)
00239 {
00240 if ( m_pCoolMenu ) m_pCoolMenu->OnMeasureItem( lpMeasureItemStruct );
00241 }
00242
00243 void CBaseMatchWnd::OnDrawItem(int nIDCtl, LPDRAWITEMSTRUCT lpDrawItemStruct)
00244 {
00245 if ( m_pCoolMenu ) m_pCoolMenu->OnDrawItem( lpDrawItemStruct );
00246 }
00247
00248 void CBaseMatchWnd::OnUpdateSearchDownload(CCmdUI* pCmdUI)
00249 {
00250 pCmdUI->Enable( m_pMatches->GetSelectedCount() > 0 );
00251 }
00252
00253 void CBaseMatchWnd::OnSearchDownload()
00254 {
00255 CSingleLock pSingleLock( &m_pMatches->m_pSection, TRUE );
00256 CPtrList pFiles, pHits;
00257 POSITION pos;
00258
00259 for ( pos = m_pMatches->m_pSelectedFiles.GetHeadPosition() ; pos ; )
00260 {
00261 CMatchFile* pFile = (CMatchFile*)m_pMatches->m_pSelectedFiles.GetNext( pos );
00262
00263 pSingleLock.Unlock();
00264
00265 switch ( CheckExisting( pFile->m_bSHA1, &pFile->m_pSHA1, pFile->m_bTiger, &pFile->m_pTiger, pFile->m_bED2K, &pFile->m_pED2K ) )
00266 {
00267 case 1:
00268 pFiles.AddTail( pFile );
00269 break;
00270 case 3:
00271 return;
00272 }
00273
00274 pSingleLock.Lock();
00275 }
00276
00277 for ( pos = m_pMatches->m_pSelectedHits.GetHeadPosition() ; pos ; )
00278 {
00279 CQueryHit* pHit = (CQueryHit*)m_pMatches->m_pSelectedHits.GetNext( pos );
00280
00281 pSingleLock.Unlock();
00282
00283 switch ( CheckExisting( pHit->m_bSHA1, &pHit->m_pSHA1, pHit->m_bTiger, &pHit->m_pTiger, pHit->m_bED2K, &pHit->m_pED2K ) )
00284 {
00285 case 1:
00286 pHits.AddTail( pHit );
00287 break;
00288 case 3:
00289 return;
00290 }
00291
00292 pSingleLock.Lock();
00293 }
00294
00295 pSingleLock.Unlock();
00296
00297 if ( pFiles.IsEmpty() && pHits.IsEmpty() ) return;
00298
00299 CSyncObject* pSync[2] = { &Network.m_pSection, &Transfers.m_pSection };
00300 CMultiLock pMultiLock( pSync, 2, TRUE );
00301
00302 for ( pos = pFiles.GetHeadPosition() ; pos ; )
00303 {
00304 CMatchFile* pFile = (CMatchFile*)pFiles.GetNext( pos );
00305 if ( m_pMatches->m_pSelectedFiles.Find( pFile ) != NULL ) Downloads.Add( pFile );
00306
00307 }
00308
00309 for ( pos = pHits.GetHeadPosition() ; pos ; )
00310 {
00311 CQueryHit* pHit = (CQueryHit*)pHits.GetNext( pos );
00312 if ( m_pMatches->m_pSelectedHits.Find( pHit ) != NULL )
00313 {
00314 CDownload *pDownload = Downloads.Add( pHit );
00315
00316 if ( pDownload && ( pHit->m_nRating || ! pHit->m_sComments.IsEmpty() ) )
00317 {
00318 pDownload->AddReview( &pHit->m_pAddress, 2, pHit->m_nRating, pHit->m_sNick, pHit->m_sComments );
00319 }
00320 }
00321 }
00322
00323 pMultiLock.Unlock();
00324
00325 m_wndList.Invalidate();
00326
00327 if ( Settings.Search.SwitchToTransfers && ! m_bContextMenu && GetTickCount() - m_tContextMenu > 5000 )
00328 {
00329 GetManager()->Open( RUNTIME_CLASS(CDownloadsWnd) );
00330 }
00331 }
00332
00333 void CBaseMatchWnd::OnUpdateSearchDownloadNow(CCmdUI* pCmdUI)
00334 {
00335 pCmdUI->Enable( m_pMatches->GetSelectedCount() > 0 );
00336 }
00337
00338 void CBaseMatchWnd::OnSearchDownloadNow()
00339 {
00340 CSingleLock pSingleLock( &m_pMatches->m_pSection, TRUE );
00341 CPtrList pFiles, pHits;
00342 POSITION pos;
00343
00344 for ( pos = m_pMatches->m_pSelectedFiles.GetHeadPosition() ; pos ; )
00345 {
00346 CMatchFile* pFile = (CMatchFile*)m_pMatches->m_pSelectedFiles.GetNext( pos );
00347
00348 pSingleLock.Unlock();
00349
00350 switch ( CheckExisting( pFile->m_bSHA1, &pFile->m_pSHA1, pFile->m_bTiger, &pFile->m_pTiger, pFile->m_bED2K, &pFile->m_pED2K ) )
00351 {
00352 case 1:
00353 pFiles.AddTail( pFile );
00354 break;
00355 case 3:
00356 return;
00357 }
00358
00359 pSingleLock.Lock();
00360 }
00361
00362 for ( pos = m_pMatches->m_pSelectedHits.GetHeadPosition() ; pos ; )
00363 {
00364 CQueryHit* pHit = (CQueryHit*)m_pMatches->m_pSelectedHits.GetNext( pos );
00365
00366 pSingleLock.Unlock();
00367
00368 switch ( CheckExisting( pHit->m_bSHA1, &pHit->m_pSHA1, pHit->m_bTiger, &pHit->m_pTiger, pHit->m_bED2K, &pHit->m_pED2K ) )
00369 {
00370 case 1:
00371 pHits.AddTail( pHit );
00372 break;
00373 case 3:
00374 return;
00375 }
00376
00377 pSingleLock.Lock();
00378 }
00379
00380 pSingleLock.Unlock();
00381
00382 if ( pFiles.IsEmpty() && pHits.IsEmpty() ) return;
00383
00384 CSyncObject* pSync[2] = { &Network.m_pSection, &Transfers.m_pSection };
00385 CMultiLock pMultiLock( pSync, 2, TRUE );
00386
00387 for ( pos = pFiles.GetHeadPosition() ; pos ; )
00388 {
00389 CMatchFile* pFile = (CMatchFile*)pFiles.GetNext( pos );
00390 if ( m_pMatches->m_pSelectedFiles.Find( pFile ) != NULL ) Downloads.Add( pFile, TRUE );
00391 }
00392
00393 for ( pos = pHits.GetHeadPosition() ; pos ; )
00394 {
00395 CQueryHit* pHit = (CQueryHit*)pHits.GetNext( pos );
00396 if ( m_pMatches->m_pSelectedHits.Find( pHit ) != NULL ) Downloads.Add( pHit, TRUE );
00397 }
00398
00399 pMultiLock.Unlock();
00400
00401 m_wndList.Invalidate();
00402
00403 if ( Settings.Search.SwitchToTransfers && ! m_bContextMenu && GetTickCount() - m_tContextMenu > 5000 )
00404 {
00405 GetManager()->Open( RUNTIME_CLASS(CDownloadsWnd) );
00406 }
00407 }
00408
00409 int CBaseMatchWnd::CheckExisting(BOOL bSHA1, SHA1* pSHA1, BOOL bTiger, TIGEROOT* pTiger, BOOL bED2K, MD4* pED2K)
00410 {
00411 CSingleLock pLock( &Library.m_pSection );
00412 if ( ! pLock.Lock( 500 ) ) return 1;
00413
00414 CLibraryFile* pFile = NULL;
00415
00416 if ( pFile == NULL && bSHA1 )
00417 pFile = LibraryMaps.LookupFileBySHA1( pSHA1 );
00418 if ( pFile == NULL && bTiger )
00419 pFile = LibraryMaps.LookupFileByTiger( pTiger );
00420 if ( pFile == NULL && bED2K )
00421 pFile = LibraryMaps.LookupFileByED2K( pED2K );
00422
00423 if ( pFile == NULL ) return 1;
00424
00425 DWORD nIndex = pFile->m_nIndex;
00426
00427 CExistingFileDlg dlg( pFile );
00428
00429 pLock.Unlock();
00430
00431 if ( dlg.DoModal() != IDOK ) dlg.m_nAction = 3;
00432
00433 if ( dlg.m_nAction == 0 )
00434 {
00435 if ( CLibraryWnd* pLibrary = (CLibraryWnd*)GetManager()->Open( RUNTIME_CLASS(CLibraryWnd) ) )
00436 {
00437 CQuickLock oLock( Library.m_pSection );
00438 if ( pFile = Library.LookupFile( nIndex ) )
00439 {
00440 pLibrary->Display( pFile );
00441 }
00442 }
00443 }
00444
00445 return dlg.m_nAction;
00446 }
00447
00448 void CBaseMatchWnd::OnUpdateSearchCopy(CCmdUI* pCmdUI)
00449 {
00450 pCmdUI->Enable( m_pMatches->GetSelectedCount() == 1 );
00451 }
00452
00453 void CBaseMatchWnd::OnSearchCopy()
00454 {
00455 CSingleLock pLock( &m_pMatches->m_pSection, TRUE );
00456 CURLCopyDlg dlg;
00457
00458 if ( CMatchFile* pFile = m_pMatches->GetSelectedFile() )
00459 {
00460 dlg.m_sName = pFile->m_pHits->m_sName;
00461 dlg.m_bSize = TRUE;
00462 dlg.m_nSize = pFile->m_nSize;
00463 dlg.m_bSHA1 = pFile->m_bSHA1;
00464 if ( pFile->m_bSHA1 ) dlg.m_pSHA1 = pFile->m_pSHA1;
00465 dlg.m_bTiger = pFile->m_bTiger;
00466 if ( pFile->m_bTiger ) dlg.m_pTiger = pFile->m_pTiger;
00467 dlg.m_bED2K = pFile->m_bED2K;
00468 if ( pFile->m_bED2K ) dlg.m_pED2K = pFile->m_pED2K;
00469
00470 if ( pFile->GetFilteredCount() == 1 )
00471 dlg.m_sHost = pFile->m_pHits->m_sURL;
00472 }
00473 else if ( CQueryHit* pHit = m_pMatches->GetSelectedHit() )
00474 {
00475 dlg.m_sHost = pHit->m_sURL;
00476 dlg.m_sName = pHit->m_sName;
00477 dlg.m_bSize = TRUE;
00478 dlg.m_nSize = pHit->m_nSize;
00479 dlg.m_bSHA1 = pHit->m_bSHA1;
00480 if ( pHit->m_bSHA1 ) dlg.m_pSHA1 = pHit->m_pSHA1;
00481 dlg.m_bTiger = pHit->m_bTiger;
00482 if ( pHit->m_bTiger ) dlg.m_pTiger = pHit->m_pTiger;
00483 dlg.m_bED2K = pHit->m_bED2K;
00484 if ( pHit->m_bED2K ) dlg.m_pED2K = pHit->m_pED2K;
00485 }
00486
00487 pLock.Unlock();
00488 dlg.DoModal();
00489 }
00490
00491 void CBaseMatchWnd::OnUpdateSearchChat(CCmdUI* pCmdUI)
00492 {
00493 CQueryHit* pHit = m_pMatches->GetSelectedHit();
00494 pCmdUI->Enable( pHit != NULL && pHit->m_bChat && Settings.Community.ChatEnable );
00495 }
00496
00497 void CBaseMatchWnd::OnSearchChat()
00498 {
00499 CSingleLock pLock( &m_pMatches->m_pSection, TRUE );
00500
00501 if ( CQueryHit* pHit = m_pMatches->GetSelectedHit() )
00502 {
00503 ChatWindows.OpenPrivate( &pHit->m_pClientID,
00504 &pHit->m_pAddress, pHit->m_nPort, pHit->m_bPush == TS_TRUE, pHit->m_nProtocol, (IN_ADDR*)pHit->m_pClientID.w, (WORD)pHit->m_pClientID.w[1] );
00505 }
00506 }
00507
00508 void CBaseMatchWnd::OnUpdateHitMonitorSearch(CCmdUI* pCmdUI)
00509 {
00510 pCmdUI->Enable( Network.IsWellConnected() && m_pMatches->GetSelectedCount() == 1 );
00511 }
00512
00513 void CBaseMatchWnd::OnHitMonitorSearch()
00514 {
00515 CString strFile;
00516
00517 if ( CMatchFile* pFile = m_pMatches->GetSelectedFile() )
00518 {
00519 strFile = pFile->m_pHits->m_sName;
00520 }
00521 else if ( CQueryHit* pHit = m_pMatches->GetSelectedHit() )
00522 {
00523 strFile = pHit->m_sName;
00524 }
00525
00526 if ( strFile.IsEmpty() ) return;
00527
00528 CQuerySearch* pSearch = new CQuerySearch();
00529 pSearch->m_sSearch = strFile;
00530
00531 CNewSearchDlg dlg( NULL, pSearch );
00532 if ( dlg.DoModal() != IDOK ) return;
00533
00534 new CSearchWnd( dlg.GetSearch() );
00535 }
00536
00537 void CBaseMatchWnd::OnUpdateSecurityBan(CCmdUI* pCmdUI)
00538 {
00539 CQueryHit* pHit = m_pMatches->GetSelectedHit();
00540 pCmdUI->Enable( pHit != NULL );
00541 }
00542
00543 void CBaseMatchWnd::OnSecurityBan()
00544 {
00545 CSingleLock pLock( &Network.m_pSection, TRUE );
00546
00547 if ( CQueryHit* pHit = m_pMatches->GetSelectedHit() )
00548 {
00549 Security.Ban( &pHit->m_pAddress, banSession );
00550 }
00551 }
00552
00553 void CBaseMatchWnd::OnUpdateBrowseLaunch(CCmdUI* pCmdUI)
00554 {
00555 CQueryHit* pHit = m_pMatches->GetSelectedHit();
00556 pCmdUI->Enable( pHit != NULL && pHit->m_bBrowseHost );
00557 }
00558
00559 void CBaseMatchWnd::OnBrowseLaunch()
00560 {
00561 CSingleLock pLock( &m_pMatches->m_pSection, TRUE );
00562
00563 if ( CQueryHit* pHit = m_pMatches->GetSelectedHit() )
00564 {
00565 new CBrowseHostWnd( &pHit->m_pAddress, pHit->m_nPort,
00566 pHit->m_bPush == TS_TRUE, &pHit->m_pClientID );
00567 }
00568 }
00569
00570 void CBaseMatchWnd::OnUpdateLibraryBitziWeb(CCmdUI* pCmdUI)
00571 {
00572 if ( m_pMatches->GetSelectedCount() != 1 || Settings.Library.BitziWebView.IsEmpty() )
00573 {
00574 pCmdUI->Enable( FALSE );
00575 }
00576 else if ( CMatchFile* pFile = m_pMatches->GetSelectedFile() )
00577 {
00578 pCmdUI->Enable( pFile->m_bSHA1 );
00579 }
00580 else if ( CQueryHit* pHit = m_pMatches->GetSelectedHit() )
00581 {
00582 pCmdUI->Enable( pHit->m_bSHA1 );
00583 }
00584 }
00585
00586 void CBaseMatchWnd::OnLibraryBitziWeb()
00587 {
00588 if ( ! Settings.Library.BitziOkay )
00589 {
00590 CString strMessage;
00591 Skin.LoadString( strMessage, IDS_LIBRARY_BITZI_MESSAGE );
00592 if ( AfxMessageBox( strMessage, MB_ICONQUESTION|MB_YESNO ) != IDYES ) return;
00593 Settings.Library.BitziOkay = TRUE;
00594 Settings.Save();
00595 }
00596
00597 if ( m_pMatches->GetSelectedCount() != 1 ) return;
00598
00599 CString strSHA1;
00600
00601 if ( CMatchFile* pFile = m_pMatches->GetSelectedFile() )
00602 {
00603 if ( pFile->m_bSHA1 )
00604 strSHA1 = CSHA::HashToString( &pFile->m_pSHA1 );
00605 }
00606 else if ( CQueryHit* pHit = m_pMatches->GetSelectedHit() )
00607 {
00608 if ( pHit->m_bSHA1 )
00609 strSHA1 = CSHA::HashToString( &pHit->m_pSHA1 );
00610 }
00611
00612 if ( strSHA1.IsEmpty() ) return;
00613
00614 CString strURL = Settings.Library.BitziWebView;
00615 Replace( strURL, _T("(SHA1)"), strSHA1 );
00616 ShellExecute( GetSafeHwnd(), _T("open"), strURL, NULL, NULL, SW_SHOWNORMAL );
00617 }
00618
00619
00620
00621
00622
00623
00624
00625
00626
00627
00628
00629
00630
00631
00632
00633
00634
00635
00636
00637
00638
00639
00640
00641
00642
00643
00644
00645
00646
00647
00648
00649
00650
00651
00652
00653
00654
00655
00656
00657
00658
00659
00660
00661 void CBaseMatchWnd::OnUpdateSearchForThis(CCmdUI* pCmdUI)
00662 {
00663 CSingleLock pLock( &m_pMatches->m_pSection, TRUE );
00664 CRelatedSearch pSearch( m_pMatches->GetSelectedFile( TRUE ) );
00665 pCmdUI->Enable( pSearch.CanSearchForThis() );
00666 }
00667
00668 void CBaseMatchWnd::OnSearchForThis()
00669 {
00670 CSingleLock pLock( &m_pMatches->m_pSection, TRUE );
00671 CRelatedSearch pSearch( m_pMatches->GetSelectedFile( TRUE ) );
00672 pLock.Unlock();
00673 pSearch.RunSearchForThis();
00674 }
00675
00676 void CBaseMatchWnd::OnUpdateSearchForSimilar(CCmdUI* pCmdUI)
00677 {
00678 CSingleLock pLock( &m_pMatches->m_pSection, TRUE );
00679 CRelatedSearch pSearch( m_pMatches->GetSelectedFile( TRUE ) );
00680 pCmdUI->Enable( pSearch.CanSearchForSimilar() );
00681 }
00682
00683 void CBaseMatchWnd::OnSearchForSimilar()
00684 {
00685 CSingleLock pLock( &m_pMatches->m_pSection, TRUE );
00686 CRelatedSearch pSearch( m_pMatches->GetSelectedFile( TRUE ) );
00687 pLock.Unlock();
00688 pSearch.RunSearchForSimilar();
00689 }
00690
00691 void CBaseMatchWnd::OnUpdateSearchForArtist(CCmdUI* pCmdUI)
00692 {
00693 CSingleLock pLock( &m_pMatches->m_pSection, TRUE );
00694 CRelatedSearch pSearch( m_pMatches->GetSelectedFile( TRUE ) );
00695 pCmdUI->Enable( pSearch.CanSearchForArtist() );
00696 }
00697
00698 void CBaseMatchWnd::OnSearchForArtist()
00699 {
00700 CSingleLock pLock( &m_pMatches->m_pSection, TRUE );
00701 CRelatedSearch pSearch( m_pMatches->GetSelectedFile( TRUE ) );
00702 pLock.Unlock();
00703 pSearch.RunSearchForArtist();
00704 }
00705
00706 void CBaseMatchWnd::OnUpdateSearchForAlbum(CCmdUI* pCmdUI)
00707 {
00708 CSingleLock pLock( &m_pMatches->m_pSection, TRUE );
00709 CRelatedSearch pSearch( m_pMatches->GetSelectedFile( TRUE ) );
00710 pCmdUI->Enable( pSearch.CanSearchForAlbum() );
00711 }
00712
00713 void CBaseMatchWnd::OnSearchForAlbum()
00714 {
00715 CSingleLock pLock( &m_pMatches->m_pSection, TRUE );
00716 CRelatedSearch pSearch( m_pMatches->GetSelectedFile( TRUE ) );
00717 pLock.Unlock();
00718 pSearch.RunSearchForAlbum();
00719 }
00720
00721 void CBaseMatchWnd::OnUpdateSearchForSeries(CCmdUI* pCmdUI)
00722 {
00723 CSingleLock pLock( &m_pMatches->m_pSection, TRUE );
00724 CRelatedSearch pSearch( m_pMatches->GetSelectedFile( TRUE ) );
00725 pCmdUI->Enable( pSearch.CanSearchForSeries() );
00726 }
00727
00728 void CBaseMatchWnd::OnSearchForSeries()
00729 {
00730 CSingleLock pLock( &m_pMatches->m_pSection, TRUE );
00731 CRelatedSearch pSearch( m_pMatches->GetSelectedFile( TRUE ) );
00732 pLock.Unlock();
00733 pSearch.RunSearchForSeries();
00734 }
00735
00736 void CBaseMatchWnd::OnUpdateSearchFilter(CCmdUI* pCmdUI)
00737 {
00738 if ( m_pMatches->m_sFilter.GetLength() )
00739 {
00740
00741
00742
00743
00744
00745
00746
00747
00748
00749
00750
00751
00752
00753
00754
00755 pCmdUI->SetCheck( TRUE );
00756 }
00757 else
00758 {
00759
00760 pCmdUI->SetCheck( FALSE );
00761 }
00762 }
00763
00764 void CBaseMatchWnd::OnSearchFilter()
00765 {
00766 CFilterSearchDlg dlg( NULL, m_pMatches );
00767
00768 if ( dlg.DoModal() == IDOK )
00769 {
00770 CWaitCursor pCursor;
00771
00772 m_pMatches->Filter();
00773 m_bUpdate = TRUE;
00774 PostMessage( WM_TIMER, 2 );
00775 }
00776 }
00777
00778 void CBaseMatchWnd::OnSearchFilterRaw()
00779 {
00780 OnSearchFilter();
00781 }
00782
00783 void CBaseMatchWnd::OnUpdateSearchFilterRemove(CCmdUI* pCmdUI)
00784 {
00785 pCmdUI->Enable( m_pMatches->m_sFilter.GetLength() );
00786 }
00787
00788 void CBaseMatchWnd::OnSearchFilterRemove()
00789 {
00790 CWaitCursor pCursor;
00791
00792 m_pMatches->m_sFilter.Empty();
00793 m_pMatches->Filter();
00794 m_bUpdate = TRUE;
00795 PostMessage( WM_TIMER, 2 );
00796 }
00797
00798 void CBaseMatchWnd::OnKillFocusFilter()
00799 {
00800 CString strFilter;
00801 m_wndFilter.GetWindowText( strFilter );
00802
00803 if ( strFilter != m_pMatches->m_sFilter )
00804 {
00805 CWaitCursor pCursor;
00806
00807 m_pMatches->m_sFilter = strFilter;
00808 m_pMatches->Filter();
00809 m_bUpdate = TRUE;
00810 PostMessage( WM_TIMER, 2 );
00811 }
00812 }
00813
00814 void CBaseMatchWnd::OnToolbarReturn()
00815 {
00816 if ( GetFocus() == &m_wndFilter ) OnKillFocusFilter();
00817 }
00818
00819 void CBaseMatchWnd::OnToolbarEscape()
00820 {
00821 if ( GetFocus() == &m_wndFilter )
00822 {
00823 m_wndFilter.SetWindowText( m_pMatches->m_sFilter );
00824 m_wndList.SetFocus();
00825 }
00826 }
00827
00828 void CBaseMatchWnd::OnSearchColumns()
00829 {
00830 CSchemaColumnsDlg dlg;
00831
00832 dlg.m_pSchema = m_wndList.m_pSchema;
00833 dlg.m_pColumns.AddTail( &m_wndList.m_pColumns );
00834
00835 if ( dlg.DoModal() == IDOK )
00836 {
00837 m_wndList.SelectSchema( dlg.m_pSchema, &dlg.m_pColumns );
00838 }
00839 }
00840
00841 BOOL CBaseMatchWnd::OnMouseWheel(UINT nFlags, short zDelta, CPoint pt)
00842 {
00843 m_wndList.PostMessage( WM_MOUSEWHEEL, MAKELONG( nFlags, zDelta ), MAKELONG( pt.x, pt.y ) );
00844 return TRUE;
00845 }
00846
00847 void CBaseMatchWnd::OnMDIActivate(BOOL bActivate, CWnd* pActivateWnd, CWnd* pDeactivateWnd)
00848 {
00849 if ( m_bPanelMode && bActivate )
00850 {
00851 CRect rcParent, rcChild;
00852 GetWindowRect( &rcChild );
00853 GetParent()->GetClientRect( &rcParent );
00854
00855 if ( rcParent.Width() != rcChild.Width() || rcParent.Height() != rcChild.Height() )
00856 {
00857 SetWindowPos( NULL, 0, 0, rcParent.Width(), rcParent.Height(), SWP_FRAMECHANGED );
00858 RedrawWindow( NULL, NULL, RDW_INVALIDATE | RDW_UPDATENOW | RDW_ERASE | RDW_FRAME );
00859 }
00860 }
00861 else if ( ! bActivate )
00862 {
00863 m_bBMWActive = FALSE;
00864 m_pMatches->ClearNew();
00865 m_wndList.Invalidate();
00866 }
00867
00868 m_wndList.EnableTips( bActivate );
00869
00870 CPanelWnd::OnMDIActivate( bActivate, pActivateWnd, pDeactivateWnd );
00871 }
00872
00873 void CBaseMatchWnd::OnTimer(UINT nIDEvent)
00874 {
00875 if ( m_wndFilter.m_hWnd == NULL ) return;
00876
00877 DWORD nNow = GetTickCount();
00878
00879 if ( nIDEvent == 1 )
00880 {
00881 if ( GetFocus() != &m_wndFilter )
00882 {
00883 CString strFilter;
00884 m_wndFilter.GetWindowText( strFilter );
00885
00886 if ( strFilter != m_pMatches->m_sFilter )
00887 {
00888 m_wndFilter.SetWindowText( m_pMatches->m_sFilter );
00889 }
00890 }
00891
00892 BOOL bActive = ( GetMDIFrame()->MDIGetActive() == this );
00893
00894 if ( bActive )
00895 {
00896 if ( HWND hFore = ::GetForegroundWindow() )
00897 {
00898 DWORD nProcessID;
00899 GetWindowThreadProcessId( hFore, &nProcessID );
00900 bActive &= ( nProcessID == GetCurrentProcessId() );
00901 }
00902 }
00903
00904 if ( m_bBMWActive != bActive )
00905 {
00906 m_bBMWActive = bActive;
00907
00908 if ( ! m_bBMWActive )
00909 {
00910 m_pMatches->ClearNew();
00911 m_wndList.Invalidate();
00912 }
00913 }
00914
00915 if ( m_pMatches->m_nFilteredFiles == 0 ) UpdateMessages( FALSE );
00916 }
00917 else if ( ( nIDEvent == 2 && m_bUpdate ) || nIDEvent == 7 )
00918 {
00919 CSingleLock pLock( &m_pMatches->m_pSection );
00920
00921 if ( pLock.Lock( 50 ) )
00922 {
00923 m_bUpdate = FALSE;
00924 m_wndList.Update();
00925 UpdateMessages();
00926
00927 if ( m_pMatches->m_nFilteredFiles != m_nCacheFiles )
00928 {
00929 m_nCacheFiles = m_pMatches->m_nFilteredFiles;
00930 SetAlert();
00931 }
00932 }
00933 else
00934 {
00935 m_bUpdate = TRUE;
00936 PostMessage( WM_TIMER, 2 );
00937 }
00938 }
00939 }
00940
00941 void CBaseMatchWnd::UpdateMessages(BOOL bActive)
00942 {
00943 }
00944
00946
00947
00948 HRESULT CBaseMatchWnd::GetGenericView(IGenericView** ppView)
00949 {
00950 if ( m_pMatches == NULL ) return S_FALSE;
00951 CRuntimeClass* pClass = GetRuntimeClass();
00952 *ppView = CMatchListView::Attach( CString( pClass->m_lpszClassName ), m_pMatches );
00953 return S_OK;
00954 }