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

CtrlLibraryFileView.cpp

Go to the documentation of this file.
00001 //
00002 // CtrlLibraryFileView.cpp
00003 //
00004 //      Date:                   "$Date: 2005/08/01 14:51:54 $"
00005 //      Revision:               "$Revision: 1.22 $"
00006 //  Last change by:     "$Author: rolandas $"
00007 //
00008 // Copyright (c) Shareaza Development Team, 2002-2005.
00009 // This file is part of SHAREAZA (www.shareaza.com)
00010 //
00011 // Shareaza is free software; you can redistribute it
00012 // and/or modify it under the terms of the GNU General Public License
00013 // as published by the Free Software Foundation; either version 2 of
00014 // the License, or (at your option) any later version.
00015 //
00016 // Shareaza is distributed in the hope that it will be useful,
00017 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00018 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00019 // GNU General Public License for more details.
00020 //
00021 // You should have received a copy of the GNU General Public License
00022 // along with Shareaza; if not, write to the Free Software
00023 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00024 //
00025 
00026 #include "StdAfx.h"
00027 #include "Shareaza.h"
00028 #include "Settings.h"
00029 #include "Library.h"
00030 #include "LibraryFolders.h"
00031 #include "SharedFolder.h"
00032 #include "SharedFile.h"
00033 #include "AlbumFolder.h"
00034 #include "FileExecutor.h"
00035 #include "CoolInterface.h"
00036 #include "ShellIcons.h"
00037 #include "Skin.h"
00038 #include "SHA.h"
00039 #include "ED2K.h"
00040 #include "CtrlLibraryFrame.h"
00041 #include "CtrlLibraryFileView.h"
00042 #include "CtrlLibraryTree.h"
00043 #include "CtrlLibraryTip.h"
00044 
00045 #include "DlgFilePropertiesSheet.h"
00046 #include "DlgFileCopy.h"
00047 #include "DlgBitziDownload.h"
00048 #include "DlgURLCopy.h"
00049 #include "DlgURLExport.h"
00050 #include "DlgDeleteFile.h"
00051 #include "DlgTorrentSeed.h"
00052 #include "DlgDecodeMetadata.h"
00053 #include "RelatedSearch.h"
00054 
00055 #ifdef _DEBUG
00056 #define new DEBUG_NEW
00057 #undef THIS_FILE
00058 static char THIS_FILE[] = __FILE__;
00059 #endif
00060 
00061 IMPLEMENT_DYNAMIC(CLibraryFileView, CLibraryView)
00062 
00063 BEGIN_MESSAGE_MAP(CLibraryFileView, CLibraryView)
00064         //{{AFX_MSG_MAP(CLibraryFileView)
00065         ON_WM_CONTEXTMENU()
00066         ON_WM_MOUSEMOVE()
00067         ON_WM_LBUTTONDOWN()
00068         ON_WM_RBUTTONDOWN()
00069         ON_WM_KEYDOWN()
00070         ON_UPDATE_COMMAND_UI(ID_LIBRARY_LAUNCH, OnUpdateLibraryLaunch)
00071         ON_COMMAND(ID_LIBRARY_LAUNCH, OnLibraryLaunch)
00072         ON_UPDATE_COMMAND_UI(ID_LIBRARY_ENQUEUE, OnUpdateLibraryEnqueue)
00073         ON_COMMAND(ID_LIBRARY_ENQUEUE, OnLibraryEnqueue)
00074         ON_UPDATE_COMMAND_UI(ID_LIBRARY_URL, OnUpdateLibraryURL)
00075         ON_COMMAND(ID_LIBRARY_URL, OnLibraryURL)
00076         ON_UPDATE_COMMAND_UI(ID_LIBRARY_MOVE, OnUpdateLibraryMove)
00077         ON_COMMAND(ID_LIBRARY_MOVE, OnLibraryMove)
00078         ON_UPDATE_COMMAND_UI(ID_LIBRARY_COPY, OnUpdateLibraryCopy)
00079         ON_COMMAND(ID_LIBRARY_COPY, OnLibraryCopy)
00080         ON_UPDATE_COMMAND_UI(ID_LIBRARY_DELETE, OnUpdateLibraryDelete)
00081         ON_COMMAND(ID_LIBRARY_DELETE, OnLibraryDelete)
00082         ON_UPDATE_COMMAND_UI(ID_LIBRARY_BITZI_WEB, OnUpdateLibraryBitziWeb)
00083         ON_COMMAND(ID_LIBRARY_BITZI_WEB, OnLibraryBitziWeb)
00084         ON_UPDATE_COMMAND_UI(ID_LIBRARY_BITZI_DOWNLOAD, OnUpdateLibraryBitziDownload)
00085         ON_COMMAND(ID_LIBRARY_BITZI_DOWNLOAD, OnLibraryBitziDownload)
00086         ON_UPDATE_COMMAND_UI(ID_LIBRARY_SHARED_FILE, OnUpdateLibraryShared)
00087         ON_COMMAND(ID_LIBRARY_SHARED_FILE, OnLibraryShared)
00088         ON_UPDATE_COMMAND_UI(ID_LIBRARY_PROPERTIES, OnUpdateLibraryProperties)
00089         ON_COMMAND(ID_LIBRARY_PROPERTIES, OnLibraryProperties)
00090         ON_WM_CREATE()
00091         ON_UPDATE_COMMAND_UI(ID_LIBRARY_UNLINK, OnUpdateLibraryUnlink)
00092         ON_COMMAND(ID_LIBRARY_UNLINK, OnLibraryUnlink)
00093         ON_UPDATE_COMMAND_UI(ID_SEARCH_FOR_THIS, OnUpdateSearchForThis)
00094         ON_COMMAND(ID_SEARCH_FOR_THIS, OnSearchForThis)
00095         ON_UPDATE_COMMAND_UI(ID_SEARCH_FOR_SIMILAR, OnUpdateSearchForSimilar)
00096         ON_COMMAND(ID_SEARCH_FOR_SIMILAR, OnSearchForSimilar)
00097         ON_UPDATE_COMMAND_UI(ID_SEARCH_FOR_ARTIST, OnUpdateSearchForArtist)
00098         ON_COMMAND(ID_SEARCH_FOR_ARTIST, OnSearchForArtist)
00099         ON_UPDATE_COMMAND_UI(ID_SEARCH_FOR_ALBUM, OnUpdateSearchForAlbum)
00100         ON_COMMAND(ID_SEARCH_FOR_ALBUM, OnSearchForAlbum)
00101         ON_UPDATE_COMMAND_UI(ID_SEARCH_FOR_SERIES, OnUpdateSearchForSeries)
00102         ON_COMMAND(ID_SEARCH_FOR_SERIES, OnSearchForSeries)
00103         ON_UPDATE_COMMAND_UI(ID_LIBRARY_CREATETORRENT, OnUpdateLibraryCreateTorrent)
00104         ON_COMMAND(ID_LIBRARY_CREATETORRENT, OnLibraryCreateTorrent)
00105         ON_UPDATE_COMMAND_UI(ID_LIBRARY_REBUILD_ANSI, OnUpdateLibraryRebuildAnsi)
00106         ON_COMMAND(ID_LIBRARY_REBUILD_ANSI, OnLibraryRebuildAnsi)
00107         //}}AFX_MSG_MAP
00108 END_MESSAGE_MAP()
00109 
00110 
00112 // CLibraryFileView construction
00113 
00114 CLibraryFileView::CLibraryFileView()
00115 {
00116         m_pszToolBar = _T("CLibraryFileView");
00117 }
00118 
00119 CLibraryFileView::~CLibraryFileView()
00120 {
00121 }
00122 
00124 // CLibraryFileView selected item interface
00125 
00126 BOOL CLibraryFileView::CheckAvailable(CLibraryTreeItem* pSel)
00127 {
00128         m_bAvailable = FALSE;
00129         if ( pSel == NULL ) return m_bAvailable;
00130         m_bAvailable = TRUE;
00131 
00132         if ( pSel->m_pSelNext == NULL && pSel->m_pVirtual != NULL )
00133         {
00134                 m_bAvailable = ( pSel->m_pVirtual->GetFileCount() > 0 );
00135         }
00136 
00137         return m_bAvailable;
00138 }
00139 
00140 void CLibraryFileView::StartSelectedFileLoop()
00141 {
00142         m_posSel = m_pSelection.GetHeadPosition();
00143 }
00144 
00145 CLibraryFile* CLibraryFileView::GetNextSelectedFile()
00146 {
00147         while ( m_posSel )
00148         {
00149                 CLibraryFile* pFile = Library.LookupFile( m_pSelection.GetNext( m_posSel ) );
00150                 if ( pFile != NULL && pFile->IsAvailable() ) return pFile;
00151         }
00152         
00153         return NULL;
00154 }
00155 
00156 CLibraryFile* CLibraryFileView::GetSelectedFile()
00157 {
00158         if ( m_pSelection.GetCount() == 0 ) return NULL;
00159         CLibraryFile* pFile = Library.LookupFile( m_pSelection.GetHead() );
00160         if ( pFile != NULL && pFile->IsAvailable() ) return pFile;
00161         return NULL;
00162 }
00163 
00165 // CLibraryFileView message handlers
00166 
00167 int CLibraryFileView::OnCreate(LPCREATESTRUCT lpCreateStruct) 
00168 {
00169         if ( CLibraryView::OnCreate( lpCreateStruct ) == -1 ) return -1;
00170         m_bEditing = FALSE;     
00171         return 0;
00172 }
00173 
00174 BOOL CLibraryFileView::PreTranslateMessage(MSG* pMsg) 
00175 {
00176         if ( pMsg->message == WM_KEYDOWN && ! m_bEditing )
00177         {
00178                 switch ( pMsg->wParam )
00179                 {
00180                 case VK_RETURN:
00181                         OnLibraryLaunch();
00182                         return TRUE;
00183                 case VK_DELETE:
00184                         OnLibraryDelete();
00185                         return TRUE;
00186                 }
00187         }
00188         else if ( pMsg->message == WM_SYSKEYDOWN && pMsg->wParam == VK_RETURN )
00189         {
00190                 OnLibraryProperties();
00191                 return TRUE;
00192         }
00193         
00194         return CLibraryView::PreTranslateMessage( pMsg );
00195 }
00196 
00197 void CLibraryFileView::OnContextMenu(CWnd* pWnd, CPoint point) 
00198 {
00199         CString strName( m_pszToolBar );
00200         strName += Settings.Library.ShowVirtual ? _T(".Virtual") : _T(".Physical");
00201         Skin.TrackPopupMenu( strName, point, ID_LIBRARY_LAUNCH );
00202 }
00203 
00204 void CLibraryFileView::OnMouseMove(UINT nFlags, CPoint point) 
00205 {
00206         if ( DWORD nFile = HitTestIndex( point ) )
00207         {
00208                 GetToolTip()->Show( (LPVOID)nFile );
00209         }
00210         else
00211         {
00212                 GetToolTip()->Hide();
00213         }
00214 }
00215 
00216 void CLibraryFileView::OnLButtonDown(UINT nFlags, CPoint point) 
00217 {
00218         GetToolTip()->Hide();
00219 
00220         CWnd::OnLButtonDown( nFlags, point );
00221 }
00222 
00223 void CLibraryFileView::OnRButtonDown(UINT nFlags, CPoint point) 
00224 {
00225         GetToolTip()->Hide();
00226         
00227         CWnd::OnRButtonDown( nFlags, point );
00228 }
00229 
00230 void CLibraryFileView::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags) 
00231 {
00232         GetToolTip()->Hide();
00233         
00234         CWnd::OnKeyDown( nChar, nRepCnt, nFlags );
00235 }
00236 
00238 // CLibraryFileView command handlers
00239 
00240 void CLibraryFileView::OnUpdateLibraryLaunch(CCmdUI* pCmdUI) 
00241 {
00242         pCmdUI->Enable( GetSelectedCount() > 0 );
00243 }
00244 
00245 void CLibraryFileView::OnLibraryLaunch() 
00246 {
00247         CSingleLock pLock( &Library.m_pSection, TRUE );
00248         
00249         StartSelectedFileLoop();
00250 
00251         for ( CLibraryFile* pFile ; pFile = GetNextSelectedFile() ; )
00252         {
00253                 CString strPath = pFile->GetPath();
00254 
00255                 if ( pFile->m_bVerify == TS_FALSE )
00256                 {
00257                         DWORD nIndex = pFile->m_nIndex;
00258                         CString strFormat, strMessage;
00259                         
00260                         LoadString( strFormat, IDS_LIBRARY_VERIFY_FAIL );
00261                         strMessage.Format( strFormat, (LPCTSTR)strPath );
00262                         
00263                         pLock.Unlock();
00264                         UINT nResponse = AfxMessageBox( strMessage, MB_ICONEXCLAMATION|MB_YESNOCANCEL|MB_DEFBUTTON2 );
00265                         if ( nResponse == IDCANCEL ) break;
00266                         pLock.Lock();
00267                         if ( nResponse == IDNO ) continue;
00268                         pLock.Unlock();
00269                         LoadString( strMessage, IDS_LIBRARY_VERIFY_FIX );
00270                         nResponse = AfxMessageBox( strMessage, MB_ICONQUESTION|MB_YESNOCANCEL|MB_DEFBUTTON2 );
00271                         if ( nResponse == IDCANCEL ) break;
00272                         pLock.Lock();
00273                         
00274                         if ( nResponse == IDYES )
00275                         {
00276                                 pFile = Library.LookupFile( nIndex );
00277                                 if ( NULL == pFile ) continue;
00278                                 pFile->m_bVerify = TS_UNKNOWN;
00279                                 Library.Update();
00280                         }
00281                 }
00282                 
00283                 pLock.Unlock();
00284                 
00285                 LPCTSTR pszType = _tcsrchr( strPath, '.' );
00286                 if ( pszType != NULL && _tcsicmp( pszType, _T(".torrent") ) == 0 )
00287                 {
00288                         CTorrentSeedDlg dlg( strPath, FALSE );
00289                         dlg.DoModal();
00290                 }
00291                 else
00292                 {
00293                         if ( ! CFileExecutor::Execute( strPath ) ) break;
00294                 }
00295                 
00296                 pLock.Lock();
00297         }
00298 }
00299 
00300 void CLibraryFileView::OnUpdateLibraryEnqueue(CCmdUI* pCmdUI) 
00301 {
00302         CSingleLock pLock( &Library.m_pSection );
00303         
00304         if ( GetSelectedCount() > 0 && pLock.Lock( 100 ) )
00305         {
00306                 StartSelectedFileLoop();
00307                 
00308                 for ( CLibraryFile* pFile ; pFile = GetNextSelectedFile() ; )
00309                 {
00310                         if ( LPCTSTR pszType = _tcsrchr( pFile->m_sName, '.' ) )
00311                         {
00312                                 CString strType;
00313                                 strType.Format( _T("|%s|"), pszType + 1 );
00314                                 
00315                                 if ( _tcsistr( Settings.MediaPlayer.FileTypes, strType ) != NULL )
00316                                 {
00317                                         pCmdUI->Enable( TRUE );
00318                                         return;
00319                                 }
00320                         }
00321                 }
00322         }
00323         
00324         pCmdUI->Enable( FALSE );
00325 }
00326 
00327 void CLibraryFileView::OnLibraryEnqueue() 
00328 {
00329         CSingleLock pLock( &Library.m_pSection, TRUE );
00330         
00331         StartSelectedFileLoop();
00332         
00333         for ( CLibraryFile* pFile ; pFile = GetNextSelectedFile() ; )
00334         {
00335                 CString strPath = pFile->GetPath();
00336                 pLock.Unlock();
00337                 CFileExecutor::Enqueue( strPath );
00338                 pLock.Lock();
00339         }
00340 }
00341 
00342 void CLibraryFileView::OnUpdateLibraryURL(CCmdUI* pCmdUI) 
00343 {
00344         CString strMessage;
00345 
00346         pCmdUI->Enable( GetSelectedCount() > 0 );
00347         GetSelectedCount() > 1 ? LoadString( strMessage, IDS_LIBRARY_EXPORTURIS ) : LoadString( strMessage, IDS_LIBRARY_COPYURI );
00348         pCmdUI->SetText( strMessage );
00349 }
00350 
00351 void CLibraryFileView::OnLibraryURL() 
00352 {
00353         CSingleLock pLock( &Library.m_pSection, TRUE );
00354         
00355         if ( GetSelectedCount() == 1 )
00356         {
00357                 CLibraryFile* pFile = GetSelectedFile();
00358                 if ( ! pFile ) return;
00359                 
00360                 CURLCopyDlg dlg;
00361                 
00362                 dlg.m_sName = pFile->m_sName;
00363                 dlg.m_bSize = TRUE;
00364                 dlg.m_nSize = pFile->GetSize();
00365                 dlg.m_bSHA1 = pFile->m_bSHA1;
00366                 if ( pFile->m_bSHA1 ) dlg.m_pSHA1 = pFile->m_pSHA1;
00367                 dlg.m_bTiger = pFile->m_bTiger;
00368                 if ( pFile->m_bTiger ) dlg.m_pTiger = pFile->m_pTiger;
00369                 dlg.m_bED2K = pFile->m_bED2K;
00370                 if ( pFile->m_bED2K ) dlg.m_pED2K = pFile->m_pED2K;
00371                 
00372                 pLock.Unlock();
00373                 
00374                 dlg.DoModal();
00375         }
00376         else
00377         {
00378                 CURLExportDlg dlg;
00379                 
00380                 StartSelectedFileLoop();
00381                 
00382                 for ( CLibraryFile* pFile ; pFile = GetNextSelectedFile() ; )
00383                 {
00384                         dlg.AddFile( pFile );
00385                 }
00386 
00387                 pLock.Unlock();
00388 
00389                 if ( dlg.m_pFiles.GetCount() ) dlg.DoModal();
00390         }
00391 }
00392 
00393 void CLibraryFileView::OnUpdateLibraryMove(CCmdUI* pCmdUI) 
00394 {
00395         pCmdUI->Enable( GetSelectedCount() > 0 );
00396 }
00397 
00398 void CLibraryFileView::OnLibraryMove() 
00399 {
00400         CSingleLock pLock( &Library.m_pSection, TRUE );
00401         CFileCopyDlg dlg( NULL, TRUE );
00402         
00403         StartSelectedFileLoop();
00404         
00405         for ( CLibraryFile* pFile ; pFile = GetNextSelectedFile() ; )
00406         {
00407                 dlg.AddFile( pFile );
00408         }
00409         
00410         pLock.Unlock();
00411         
00412         dlg.DoModal();
00413 }
00414 
00415 void CLibraryFileView::OnUpdateLibraryCopy(CCmdUI* pCmdUI) 
00416 {
00417         pCmdUI->Enable( GetSelectedCount() > 0 );
00418 }
00419 
00420 void CLibraryFileView::OnLibraryCopy() 
00421 {
00422         CSingleLock pLock( &Library.m_pSection, TRUE );
00423         CFileCopyDlg dlg( NULL, FALSE );
00424         
00425         StartSelectedFileLoop();
00426         
00427         for ( CLibraryFile* pFile ; pFile = GetNextSelectedFile() ; )
00428         {
00429                 dlg.AddFile( pFile );
00430         }
00431         
00432         pLock.Unlock();
00433         
00434         dlg.DoModal();
00435 }
00436 
00437 void CLibraryFileView::OnUpdateLibraryDelete(CCmdUI* pCmdUI) 
00438 {
00439         pCmdUI->Enable( GetSelectedCount() > 0 );
00440 }
00441 
00442 void CLibraryFileView::OnLibraryDelete() 
00443 {
00444         CSingleLock pLock( &Library.m_pSection, TRUE );
00445         CLibraryList pList;
00446         
00447         StartSelectedFileLoop();
00448         
00449         for ( CLibraryFile* pFile ; pFile = GetNextSelectedFile() ; )
00450         {
00451                 pList.AddTail( pFile->m_nIndex );
00452         }
00453         
00454         while ( !pList.IsEmpty() )
00455         {
00456                 CLibraryFile* pFile = Library.LookupFile( pList.GetHead(), FALSE, TRUE );
00457                 if ( pFile == NULL ) 
00458                 {
00459                         pList.RemoveHead(); // Remove item from list to avoid endless loop
00460                         continue;
00461                 }
00462 
00463                 CDeleteFileDlg dlg( this );
00464                 dlg.m_sName     = pFile->m_sName;
00465                 dlg.m_bAll      = pList.GetCount() > 1;
00466                 
00467                 pLock.Unlock();
00468                 if ( dlg.DoModal() != IDOK ) break;
00469                 pLock.Lock();
00470                 
00471                 for ( int nProcess = dlg.m_bAll ? pList.GetCount() : 1 ; nProcess > 0 && pList.GetCount() > 0 ; nProcess-- )
00472                 {
00473                         if ( pFile = Library.LookupFile( pList.RemoveHead(), FALSE, TRUE ) )
00474                         {
00475                                 dlg.Apply( pFile );
00476                                 pFile->Delete();
00477                         }
00478                 }
00479                 
00480                 Library.Update();
00481         }
00482 }
00483 
00484 void CLibraryFileView::OnUpdateLibraryBitziWeb(CCmdUI* pCmdUI) 
00485 {
00486         pCmdUI->Enable( GetSelectedCount() == 1 && Settings.Library.BitziWebSubmit.GetLength() );
00487 }
00488 
00489 void CLibraryFileView::OnLibraryBitziWeb() 
00490 {
00491         CSingleLock pLock( &Library.m_pSection, TRUE );
00492         
00493         if ( CLibraryFile* pFile = GetSelectedFile() )
00494         {
00495                 DWORD nIndex = pFile->m_nIndex;
00496                 pLock.Unlock();
00497                 CFileExecutor::ShowBitziTicket( nIndex );
00498         }
00499 }
00500 
00501 
00502 void CLibraryFileView::OnUpdateLibraryCreateTorrent(CCmdUI* pCmdUI) 
00503 {
00504         pCmdUI->Enable( GetSelectedCount() == 1 && ( Settings.BitTorrent.DefaultTracker.GetLength() > 5 ) && ( Settings.BitTorrent.TorrentCreatorPath.GetLength() > 5 ) );
00505 }
00506 
00507 void CLibraryFileView::OnLibraryCreateTorrent() 
00508 {
00509         CSingleLock pLock( &Library.m_pSection, TRUE );
00510         
00511         if ( CLibraryFile* pFile = GetSelectedFile() )
00512         {
00513                 CString sCommandLine, sPath = pFile->GetPath();
00514                 pLock.Unlock();
00515 
00516                 if ( sPath.GetLength() > 0 )
00517                 {
00518                         sCommandLine = _T(" -sourcefile \"") + sPath + _T("\" -destination \"") + Settings.Downloads.TorrentPath + _T("\" -tracker \"" + Settings.BitTorrent.DefaultTracker + "\"" );
00519 
00520                         ShellExecute( GetSafeHwnd(), _T("open"), Settings.BitTorrent.TorrentCreatorPath, sCommandLine, NULL, SW_SHOWNORMAL );
00521                 
00522                 }
00523 
00524         }
00525 }
00526 
00527 void CLibraryFileView::OnUpdateLibraryRebuildAnsi(CCmdUI* pCmdUI) 
00528 {
00529         int nSelected = GetSelectedCount();
00530 
00531         StartSelectedFileLoop();
00532 
00533         // Count only selected mp3's which have no custom metadata in XML format
00534         while ( m_posSel )
00535         {
00536                 // Lookup locks library if it finds a file
00537                 CQuickLock oLock( Library.m_pSection );
00538 
00539                 if ( CLibraryFile* pFile = Library.LookupFile( m_pSelection.GetNext( m_posSel ) ) )
00540                 {
00541                         CString strExtension = pFile->m_sName.Right(3);
00542                         CharLower( strExtension.GetBuffer() );
00543                         strExtension.ReleaseBuffer();
00544 
00545                         BOOL bXmlPossiblyModified = FALSE;
00546                         if ( !pFile->m_bMetadataAuto )
00547                         {
00548                                 HANDLE hFile = CreateFile( pFile->m_pFolder->m_sPath + _T("\\") + pFile->m_sName, GENERIC_READ, FILE_SHARE_READ,
00549                                                 NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL );
00550                                 
00551                                 if ( hFile != INVALID_HANDLE_VALUE )
00552                                 {
00553                                         FILETIME pFileDataTime;
00554                                         ULARGE_INTEGER nMetaDataTime;
00555                                         ULARGE_INTEGER nFileDataTime;
00556 
00557                                         GetFileTime( hFile, NULL, NULL, &pFileDataTime );
00558                                         nFileDataTime.HighPart = pFileDataTime.dwHighDateTime;
00559                                         nFileDataTime.LowPart = pFileDataTime.dwLowDateTime;
00560                                         // Convert 100 ns into seconds
00561                                         nFileDataTime.QuadPart /= 10000000;
00562 
00563                                         nMetaDataTime.HighPart = pFile->m_pMetadataTime.dwHighDateTime;
00564                                         nMetaDataTime.LowPart = pFile->m_pMetadataTime.dwLowDateTime;
00565                                         nMetaDataTime.QuadPart /= 10000000;
00566 
00567                                         // assume that XML was not modified during the first 10 sec. of creation
00568                                         if ( nMetaDataTime.HighPart == nFileDataTime.HighPart &&
00569                                                 nMetaDataTime.LowPart - nFileDataTime.LowPart > 10 ) 
00570                                                 bXmlPossiblyModified = TRUE;
00571                                         CloseHandle( hFile );
00572                                 }
00573                         }
00574                         if ( ( strExtension != _T("mp3") ) || bXmlPossiblyModified )
00575                                 nSelected--;
00576                 }
00577         }
00578         pCmdUI->Enable( nSelected > 0 );
00579 }
00580 
00581 void CLibraryFileView::OnLibraryRebuildAnsi() 
00582 {
00583         CDecodeMetadataDlg dlg;
00584 
00585         CSingleLock pLock( &Library.m_pSection, TRUE );
00586 
00587         StartSelectedFileLoop();
00588 
00589         for ( CLibraryFile* pFile ; pFile = GetNextSelectedFile() ; )
00590         {
00591                 CString strExtension = pFile->m_sName.Right(3);
00592                 CharLower( strExtension.GetBuffer() );
00593                 strExtension.ReleaseBuffer();
00594 
00595                 if ( strExtension == _T("mp3") ) dlg.AddFile( pFile );
00596         }
00597 
00598         pLock.Unlock();
00599 
00600         if ( dlg.m_pFiles.GetCount() ) dlg.DoModal();
00601 }
00602 
00603 
00604 void CLibraryFileView::OnUpdateLibraryBitziDownload(CCmdUI* pCmdUI) 
00605 {
00606         pCmdUI->Enable( GetSelectedCount() > 0 && Settings.Library.BitziXML.GetLength() );
00607 }
00608 
00609 void CLibraryFileView::OnLibraryBitziDownload() 
00610 {
00611         if ( ! Settings.Library.BitziOkay )
00612         {
00613                 CString strFormat;
00614                 Skin.LoadString( strFormat, IDS_LIBRARY_BITZI_MESSAGE );
00615                 if ( AfxMessageBox( strFormat, MB_ICONQUESTION|MB_YESNO ) != IDYES ) return;
00616                 Settings.Library.BitziOkay = TRUE;
00617                 Settings.Save();
00618         }
00619 
00620         CSingleLock pLock( &Library.m_pSection, TRUE );
00621         CBitziDownloadDlg dlg;
00622 
00623         StartSelectedFileLoop();
00624 
00625         for ( CLibraryFile* pFile ; pFile = GetNextSelectedFile() ; )
00626         {
00627                 if ( pFile->m_bSHA1 ) dlg.AddFile( pFile->m_nIndex );
00628         }
00629 
00630         pLock.Unlock();
00631 
00632         dlg.DoModal();
00633 }
00634 
00635 void CLibraryFileView::OnUpdateLibraryProperties(CCmdUI* pCmdUI) 
00636 {
00637         pCmdUI->Enable( GetSelectedCount() > 0 );
00638 }
00639 
00640 void CLibraryFileView::OnLibraryProperties() 
00641 {
00642         CSingleLock pLock( &Library.m_pSection, TRUE );
00643         CFilePropertiesSheet dlg;
00644 
00645         StartSelectedFileLoop();
00646 
00647         for ( CLibraryFile* pFile ; pFile = GetNextSelectedFile() ; )
00648         {
00649                 dlg.Add( pFile->m_nIndex );
00650         }
00651 
00652         pLock.Unlock();
00653 
00654         dlg.DoModal();
00655 }
00656 
00657 void CLibraryFileView::OnUpdateLibraryShared(CCmdUI* pCmdUI) 
00658 {
00659         CSingleLock pLock( &Library.m_pSection );
00660         TRISTATE bShared = TS_UNKNOWN;
00661         
00662         if ( GetSelectedCount() > 0 && pLock.Lock( 100 ) )
00663         {
00664                 StartSelectedFileLoop();
00665                 
00666                 for ( CLibraryFile* pFile ; pFile = GetNextSelectedFile() ; )
00667                 {
00668                         if ( bShared == TS_UNKNOWN )
00669                         {
00670                                 bShared = pFile->IsShared() ? TS_TRUE : TS_FALSE;
00671                         }
00672                         else if ( ( bShared == TS_TRUE ) != pFile->IsShared() )
00673                         {
00674                                 pCmdUI->Enable( FALSE );
00675                                 return;
00676                         }
00677                 }
00678         }
00679         
00680         pCmdUI->Enable( GetSelectedCount() > 0 );
00681         pCmdUI->SetCheck( bShared == TS_TRUE );
00682 }
00683 
00684 void CLibraryFileView::OnLibraryShared() 
00685 {
00686         CQuickLock oLock( Library.m_pSection );
00687 
00688         StartSelectedFileLoop();
00689 
00690         for ( CLibraryFile* pFile ; pFile = GetNextSelectedFile() ; )
00691         {
00692                 if ( pFile->IsShared() )
00693                         pFile->m_bShared = pFile->m_pFolder->IsShared() ? TS_FALSE : TS_UNKNOWN;
00694                 else
00695                         pFile->m_bShared = pFile->m_pFolder->IsShared() ? TS_UNKNOWN : TS_TRUE;
00696                 pFile->m_nUpdateCookie++;
00697         }
00698 
00699         Library.Update();
00700 }
00701 
00702 void CLibraryFileView::OnUpdateLibraryUnlink(CCmdUI* pCmdUI) 
00703 {
00704         CLibraryTreeItem* pItem = GetFolderSelection();
00705         pCmdUI->Enable( GetSelectedCount() > 0 && pItem && pItem->m_pVirtual && pItem->m_pSelNext == NULL );
00706 }
00707 
00708 void CLibraryFileView::OnLibraryUnlink() 
00709 {
00710         CSingleLock pLock( &Library.m_pSection, TRUE );
00711 
00712         CLibraryTreeItem* pItem = GetFolderSelection();
00713 
00714         if ( pItem == NULL || pItem->m_pVirtual == NULL || pItem->m_pSelNext != NULL ) return;
00715 
00716         CAlbumFolder* pFolder = pItem->m_pVirtual;
00717         if ( ! LibraryFolders.CheckAlbum( pFolder ) ) return;
00718 
00719         StartSelectedFileLoop();
00720 
00721         for ( CLibraryFile* pFile ; pFile = GetNextSelectedFile() ; )
00722         {
00723                 pFolder->RemoveFile( pFile );
00724         }
00725 }
00726 
00727 void CLibraryFileView::OnUpdateSearchForThis(CCmdUI* pCmdUI) 
00728 {
00729         CSingleLock pLock( &Library.m_pSection, TRUE );
00730         CRelatedSearch pSearch( GetSelectedFile() );
00731         pCmdUI->Enable( pSearch.CanSearchForThis() );
00732 }
00733 
00734 void CLibraryFileView::OnSearchForThis() 
00735 {
00736         CSingleLock pLock( &Library.m_pSection, TRUE );
00737         CRelatedSearch pSearch( GetSelectedFile() );
00738         pLock.Unlock();
00739         pSearch.RunSearchForThis();
00740 }
00741 
00742 void CLibraryFileView::OnUpdateSearchForSimilar(CCmdUI* pCmdUI) 
00743 {
00744         CSingleLock pLock( &Library.m_pSection, TRUE );
00745         CRelatedSearch pSearch( GetSelectedFile() );
00746         pCmdUI->Enable( pSearch.CanSearchForSimilar() );
00747 }
00748 
00749 void CLibraryFileView::OnSearchForSimilar() 
00750 {
00751         CSingleLock pLock( &Library.m_pSection, TRUE );
00752         CRelatedSearch pSearch( GetSelectedFile() );
00753         pLock.Unlock();
00754         pSearch.RunSearchForSimilar();
00755 }
00756 
00757 void CLibraryFileView::OnUpdateSearchForArtist(CCmdUI* pCmdUI) 
00758 {
00759         CSingleLock pLock( &Library.m_pSection, TRUE );
00760         CRelatedSearch pSearch( GetSelectedFile() );
00761         pCmdUI->Enable( pSearch.CanSearchForArtist() );
00762 }
00763 
00764 void CLibraryFileView::OnSearchForArtist() 
00765 {
00766         CSingleLock pLock( &Library.m_pSection, TRUE );
00767         CRelatedSearch pSearch( GetSelectedFile() );
00768         pLock.Unlock();
00769         pSearch.RunSearchForArtist();
00770 }
00771 
00772 void CLibraryFileView::OnUpdateSearchForAlbum(CCmdUI* pCmdUI) 
00773 {
00774         CSingleLock pLock( &Library.m_pSection, TRUE );
00775         CRelatedSearch pSearch( GetSelectedFile() );
00776         pCmdUI->Enable( pSearch.CanSearchForAlbum() );
00777 }
00778 
00779 void CLibraryFileView::OnSearchForAlbum() 
00780 {
00781         CSingleLock pLock( &Library.m_pSection, TRUE );
00782         CRelatedSearch pSearch( GetSelectedFile() );
00783         pLock.Unlock();
00784         pSearch.RunSearchForAlbum();
00785 }
00786 
00787 void CLibraryFileView::OnUpdateSearchForSeries(CCmdUI* pCmdUI) 
00788 {
00789         CSingleLock pLock( &Library.m_pSection, TRUE );
00790         CRelatedSearch pSearch( GetSelectedFile() );
00791         pCmdUI->Enable( pSearch.CanSearchForSeries() );
00792 }
00793 
00794 void CLibraryFileView::OnSearchForSeries() 
00795 {
00796         CSingleLock pLock( &Library.m_pSection, TRUE );
00797         CRelatedSearch pSearch( GetSelectedFile() );
00798         pLock.Unlock();
00799         pSearch.RunSearchForSeries();
00800 }

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