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

CtrlLibraryTreeView.cpp

Go to the documentation of this file.
00001 //
00002 // CtrlLibraryTreeView.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 "Library.h"
00026 #include "LibraryFolders.h"
00027 #include "SharedFile.h"
00028 #include "SharedFolder.h"
00029 #include "AlbumFolder.h"
00030 #include "FileExecutor.h"
00031 #include "CtrlLibraryTreeView.h"
00032 #include "CtrlLibraryFrame.h"
00033 #include "CtrlCoolBar.h"
00034 #include "Schema.h"
00035 #include "Skin.h"
00036 
00037 #include "DlgFolderScan.h"
00038 #include "DlgFolderProperties.h"
00039 #include "DlgFilePropertiesSheet.h"
00040 #include "DlgFileCopy.h"
00041 #include "DlgCollectionExport.h"
00042 
00043 #ifdef _DEBUG
00044 #define new DEBUG_NEW
00045 #undef THIS_FILE
00046 static char THIS_FILE[] = __FILE__;
00047 #endif
00048 
00049 IMPLEMENT_DYNAMIC(CLibraryTreeView, CLibraryTreeCtrl)
00050 
00051 BEGIN_MESSAGE_MAP(CLibraryTreeView, CLibraryTreeCtrl)
00052         //{{AFX_MSG_MAP(CLibraryTreeView)
00053         ON_WM_CONTEXTMENU()
00054         ON_WM_LBUTTONDBLCLK()
00055         ON_UPDATE_COMMAND_UI(ID_LIBRARY_PARENT, OnUpdateLibraryParent)
00056         ON_COMMAND(ID_LIBRARY_PARENT, OnLibraryParent)
00057         ON_UPDATE_COMMAND_UI(ID_LIBRARY_EXPLORE, OnUpdateLibraryExplore)
00058         ON_COMMAND(ID_LIBRARY_EXPLORE, OnLibraryExplore)
00059         ON_UPDATE_COMMAND_UI(ID_LIBRARY_SCAN, OnUpdateLibraryScan)
00060         ON_COMMAND(ID_LIBRARY_SCAN, OnLibraryScan)
00061         ON_UPDATE_COMMAND_UI(ID_LIBRARY_SHARED_FOLDER, OnUpdateLibraryShared)
00062         ON_COMMAND(ID_LIBRARY_SHARED_FOLDER, OnLibraryShared)
00063         ON_COMMAND(ID_LIBRARY_ADD, OnLibraryAdd)
00064         ON_UPDATE_COMMAND_UI(ID_LIBRARY_REMOVE, OnUpdateLibraryRemove)
00065         ON_COMMAND(ID_LIBRARY_REMOVE, OnLibraryRemove)
00066         ON_UPDATE_COMMAND_UI(ID_LIBRARY_FOLDER_PROPERTIES, OnUpdateLibraryFolderProperties)
00067         ON_COMMAND(ID_LIBRARY_FOLDER_PROPERTIES, OnLibraryFolderProperties)
00068         ON_UPDATE_COMMAND_UI(ID_LIBRARY_FOLDER_NEW, OnUpdateLibraryFolderNew)
00069         ON_COMMAND(ID_LIBRARY_FOLDER_NEW, OnLibraryFolderNew)
00070         ON_UPDATE_COMMAND_UI(ID_LIBRARY_FOLDER_DELETE, OnUpdateLibraryFolderDelete)
00071         ON_COMMAND(ID_LIBRARY_FOLDER_DELETE, OnLibraryFolderDelete)
00072         ON_UPDATE_COMMAND_UI(ID_LIBRARY_FOLDER_METADATA, OnUpdateLibraryFolderMetadata)
00073         ON_COMMAND(ID_LIBRARY_FOLDER_METADATA, OnLibraryFolderMetadata)
00074         ON_UPDATE_COMMAND_UI(ID_LIBRARY_FOLDER_ENQUEUE, OnUpdateLibraryFolderEnqueue)
00075         ON_COMMAND(ID_LIBRARY_FOLDER_ENQUEUE, OnLibraryFolderEnqueue)
00076         ON_WM_CREATE()
00077         ON_UPDATE_COMMAND_UI(ID_LIBRARY_FOLDER_FILE_PROPERTIES, OnUpdateLibraryFolderFileProperties)
00078         ON_COMMAND(ID_LIBRARY_FOLDER_FILE_PROPERTIES, OnLibraryFolderFileProperties)
00079         ON_UPDATE_COMMAND_UI(ID_LIBRARY_REBUILD, OnUpdateLibraryRebuild)
00080         ON_COMMAND(ID_LIBRARY_REBUILD, OnLibraryRebuild)
00081         //}}AFX_MSG_MAP
00082         ON_UPDATE_COMMAND_UI(ID_LIBRARY_EXPORT_COLLECTION, OnUpdateLibraryExportCollection)
00083         ON_COMMAND(ID_LIBRARY_EXPORT_COLLECTION, OnLibraryExportCollection)
00084 END_MESSAGE_MAP()
00085 
00086 
00088 // CLibraryTreeView construction
00089 
00090 CLibraryTreeView::CLibraryTreeView()
00091 {
00092         m_bVirtual = -1;
00093 }
00094 
00095 CLibraryTreeView::~CLibraryTreeView()
00096 {
00097 }
00098 
00100 // CLibraryTreeView root update
00101 
00102 void CLibraryTreeView::SetVirtual(BOOL bVirtual)
00103 {
00104         if ( bVirtual == m_bVirtual ) return;
00105 
00106         m_bVirtual = bVirtual;
00107         SetToolTip( m_bVirtual ? (CCoolTipCtrl*)&m_wndAlbumTip : (CCoolTipCtrl*)&m_wndFolderTip );
00108 
00109         Clear();
00110 }
00111 
00112 void CLibraryTreeView::Update(DWORD nSelectCookie)
00113 {
00114         if ( m_bVirtual )
00115         {
00116                 UpdateVirtual( nSelectCookie );
00117         }
00118         else
00119         {
00120                 UpdatePhysical( nSelectCookie );
00121         }
00122 }
00123 
00124 void CLibraryTreeView::PostUpdate()
00125 {
00126         GetOwner()->PostMessage( WM_COMMAND, ID_LIBRARY_REFRESH );
00127 }
00128 
00130 // CLibraryTreeView update physical
00131 
00132 void CLibraryTreeView::UpdatePhysical(DWORD nSelectCookie)
00133 {
00134         DWORD nCleanCookie = m_nCleanCookie++;
00135         BOOL bChanged = FALSE;
00136 
00137         for ( POSITION pos = LibraryFolders.GetFolderIterator() ; pos ; )
00138         {
00139                 CLibraryFolder* pFolder = LibraryFolders.GetNextFolder( pos );
00140 
00141                 CLibraryTreeItem** pChild = m_pRoot->m_pList;
00142 
00143         int nChild = m_pRoot->m_nCount;
00144                 for ( ; nChild ; nChild--, pChild++ )
00145                 {
00146                         CLibraryFolder* pOld = (*pChild)->m_pPhysical;
00147 
00148                         if ( pOld == pFolder )
00149                         {
00150                                 bChanged |= Update( pFolder, *pChild, m_pRoot, TRUE, TRUE,
00151                                         nCleanCookie, nSelectCookie, FALSE );
00152                                 break;
00153                         }
00154                 }
00155 
00156                 if ( nChild == 0 )
00157                 {
00158                         bChanged |= Update( pFolder, NULL, m_pRoot, TRUE, TRUE,
00159                                 nCleanCookie, nSelectCookie, FALSE );
00160                 }
00161         }
00162 
00163         bChanged |= CleanItems( m_pRoot, nCleanCookie, TRUE );
00164 
00165         if ( bChanged )
00166         {
00167                 UpdateScroll();
00168                 Invalidate();
00169                 NotifySelection();
00170         }
00171 }
00172 
00173 BOOL CLibraryTreeView::Update(CLibraryFolder* pFolder, CLibraryTreeItem* pItem, CLibraryTreeItem* pParent, BOOL bVisible, BOOL bShared, DWORD nCleanCookie, DWORD nSelectCookie, BOOL bRecurse)
00174 {
00175         BOOL bChanged = FALSE;
00176 
00177         if ( pFolder->m_bShared == TS_TRUE ) bShared = TRUE;
00178         else if ( pFolder->m_bShared == TS_FALSE ) bShared = FALSE;
00179 
00180         if ( pItem == NULL )
00181         {
00182                 pItem = pParent->Add( pFolder->m_sName );
00183                 if ( bVisible ) m_nTotal++;
00184 
00185                 pItem->m_bExpanded      = pFolder->m_bExpanded;
00186                 pItem->m_pPhysical      = pFolder;
00187                 pItem->m_sText          = pFolder->m_sName;
00188                 pItem->m_bShared        = bShared;
00189                 pItem->m_bBold          = ( pFolder->m_sPath.CompareNoCase( Settings.Downloads.CompletePath ) == 0 );
00190 
00191                 if ( pFolder->m_pParent == NULL )
00192                 {
00193                         if ( pFolder->m_sPath.Find( _T(":\\") ) == 1 || pFolder->m_sPath.GetLength() == 2 )
00194                         {
00195                                 CString strDrive;
00196                                 strDrive.Format( _T(" (%c:)"), pFolder->m_sPath[0] );
00197                                 pItem->m_sText += strDrive;
00198                         }
00199                         else
00200                         {
00201                                 pItem->m_sText += _T(" (Net)");
00202                         }
00203                 }
00204 
00205                 bChanged = bVisible;
00206         }
00207         else
00208         {
00209                 if ( pFolder->m_pParent == NULL )
00210                 {
00211                         BOOL bBold = ( pFolder->m_sPath.CompareNoCase( Settings.Downloads.CompletePath ) == 0 );
00212 
00213                         if ( bBold != pItem->m_bBold )
00214                         {
00215                                 pItem->m_bBold = bBold;
00216                                 bChanged |= bVisible;
00217                         }
00218                 }
00219 
00220                 if ( pItem->m_bShared != bShared )
00221                 {
00222                         pItem->m_bShared = bShared;
00223                         bChanged |= bVisible;
00224                 }
00225         }
00226 
00227         pItem->m_nCleanCookie = nCleanCookie;
00228 
00229         bVisible = bVisible && pItem->m_bExpanded;
00230 
00231         if ( nSelectCookie )
00232         {
00233                 if ( bRecurse || pItem->m_bSelected )
00234                 {
00235                         CLibraryFile* pFile;
00236                         CString strTemp;
00237 
00238                         for ( POSITION pos = pFolder->m_pFiles.GetStartPosition() ; pos ; )
00239                         {
00240                                 pFolder->m_pFiles.GetNextAssoc( pos, strTemp, (CObject*&)pFile );
00241                                 pFile->m_nSelectCookie = nSelectCookie;
00242                         }
00243 
00244                         pFolder->m_nSelectCookie = nSelectCookie;
00245                         bRecurse |= ( ! pItem->m_bExpanded );
00246                 }
00247         }
00248 
00249         nCleanCookie = m_nCleanCookie++;
00250 
00251         for ( POSITION pos = pFolder->GetFolderIterator() ; pos ; )
00252         {
00253                 CLibraryFolder* pSub = pFolder->GetNextFolder( pos );
00254 
00255                 CLibraryTreeItem** pChild = pItem->m_pList;
00256 
00257         int nChild = pItem->m_nCount;
00258                 for ( ; nChild ; nChild--, pChild++ )
00259                 {
00260                         CLibraryFolder* pOld = (*pChild)->m_pPhysical;
00261 
00262                         if ( pOld == pSub )
00263                         {
00264                                 bChanged |= Update( pSub, *pChild, pItem, bVisible, bShared,
00265                                         nCleanCookie, nSelectCookie, bRecurse );
00266                                 break;
00267                         }
00268                 }
00269 
00270                 if ( nChild == 0 )
00271                 {
00272                         bChanged |= Update( pSub, NULL, pItem, bVisible, bShared,
00273                                 nCleanCookie, nSelectCookie, bRecurse );
00274                 }
00275         }
00276 
00277         bChanged |= CleanItems( pItem, nCleanCookie, bVisible );
00278 
00279         pItem->m_nCookie = pFolder->m_nUpdateCookie;
00280 
00281         return bChanged;
00282 }
00283 
00285 // CLibraryTreeView update virtual
00286 
00287 void CLibraryTreeView::UpdateVirtual(DWORD nSelectCookie)
00288 {
00289         BOOL bChanged = Update( Library.GetAlbumRoot(), m_pRoot, NULL, TRUE, 0, nSelectCookie );
00290 
00291         if ( bChanged )
00292         {
00293                 UpdateScroll();
00294                 if (m_hWnd) Invalidate();
00295                 NotifySelection();
00296         }
00297 }
00298 
00299 BOOL CLibraryTreeView::Update(CAlbumFolder* pFolder, CLibraryTreeItem* pItem, CLibraryTreeItem* pParent, BOOL bVisible, DWORD nCleanCookie, DWORD nSelectCookie)
00300 {
00301         BOOL bChanged = FALSE;
00302 
00303         if ( pItem != NULL && pParent != NULL && pItem->m_sText != pFolder->m_sName )
00304         {
00305                 // CleanCookie is not updated so it will be dropped later
00306                 pItem = NULL;
00307         }
00308 
00309         if ( pItem == NULL )
00310         {
00311                 pItem = pParent->Add( pFolder->m_sName );
00312                 if ( bVisible ) m_nTotal++;
00313 
00314                 pItem->m_bExpanded      = pFolder->m_bExpanded;
00315                 pItem->m_pVirtual       = pFolder;
00316                 pItem->m_sText          = pFolder->m_sName;
00317                 pItem->m_nIcon16        = pFolder->m_pSchema ? pFolder->m_pSchema->m_nIcon16 : -1;
00318                 pItem->m_bBold          = pItem->m_bCollection = pFolder->m_bCollSHA1;
00319 
00320                 bChanged = bVisible;
00321         }
00322         else
00323         {
00324                 if ( pFolder->m_pSchema != NULL && pItem->m_nIcon16 != pFolder->m_pSchema->m_nIcon16 )
00325                 {
00326                         pItem->m_nIcon16 = pFolder->m_pSchema->m_nIcon16;
00327                         bChanged = bVisible;
00328                 }
00329 
00330                 if ( pItem->m_bCollection != pFolder->m_bCollSHA1 )
00331                 {
00332                         pItem->m_bBold = pItem->m_bCollection = pFolder->m_bCollSHA1;
00333                         bChanged = bVisible;
00334                 }
00335         }
00336 
00337         pItem->m_nCleanCookie = nCleanCookie;
00338 
00339         bVisible = bVisible && pItem->m_bExpanded;
00340 
00341         if ( nSelectCookie && pItem->m_bSelected )
00342         {
00343                 for ( POSITION pos = pFolder->m_pFiles.GetHeadPosition() ; pos ; )
00344                 {
00345                         CLibraryFile* pFile = (CLibraryFile*)pFolder->m_pFiles.GetNext( pos );
00346                         pFile->m_nSelectCookie = nSelectCookie;
00347                 }
00348 
00349                 pFolder->m_nSelectCookie = nSelectCookie;
00350         }
00351 
00352         nCleanCookie = m_nCleanCookie++;
00353 
00354         for ( POSITION pos = pFolder->GetFolderIterator() ; pos ; )
00355         {
00356                 CAlbumFolder* pSub = pFolder->GetNextFolder( pos );
00357 
00358                 CLibraryTreeItem** pChild = pItem->m_pList;
00359 
00360         int nChild = pItem->m_nCount;
00361                 for ( ; nChild ; nChild--, pChild++ )
00362                 {
00363                         CAlbumFolder* pOld = (*pChild)->m_pVirtual;
00364 
00365                         if ( pOld == pSub )
00366                         {
00367                                 bChanged |= Update( pSub, *pChild, pItem, bVisible,
00368                                         nCleanCookie, nSelectCookie );
00369                                 break;
00370                         }
00371                 }
00372 
00373                 if ( nChild == 0 )
00374                 {
00375                         bChanged |= Update( pSub, NULL, pItem, bVisible,
00376                                 nCleanCookie, nSelectCookie );
00377                 }
00378         }
00379 
00380         bChanged |= CleanItems( pItem, nCleanCookie, bVisible );
00381 
00382         pItem->m_nCookie = pFolder->m_nUpdateCookie;
00383 
00384         return bChanged;
00385 }
00386 
00388 // CLibraryTreeView folder selection
00389 
00390 BOOL CLibraryTreeView::SelectFolder(LPVOID pSearch)
00391 {
00392         CLibraryTreeItem* pItem = GetFolderItem( pSearch );
00393         if ( pItem == NULL ) return FALSE;
00394 
00395         if ( m_nSelected == 1 && pItem->m_bSelected )
00396         {
00397                 Highlight( pItem );
00398                 return TRUE;
00399         }
00400 
00401         DeselectAll( pItem, NULL, FALSE );
00402         Select( pItem, TS_TRUE, FALSE );
00403         Highlight( pItem );
00404         NotifySelection();
00405 
00406         return TRUE;
00407 }
00408 
00410 // CLibraryTreeView drag drop
00411 
00412 BOOL CLibraryTreeView::DropShowTarget(CLibraryList* pList, const CPoint& point)
00413 {
00414         CPoint ptLocal( point );
00415         ScreenToClient( &ptLocal );
00416 
00417         CRect rcClient, rcItem;
00418         GetClientRect( &rcClient );
00419 
00420         CLibraryTreeItem* pHit = HitTest( ptLocal, &rcItem );
00421 
00422         if ( pHit && ! rcItem.PtInRect( ptLocal ) ) pHit = NULL;
00423 
00424         if ( m_pDropItem != pHit )
00425         {
00426                 m_pDropItem = pHit;
00427                 CImageList::DragShowNolock( FALSE );
00428                 RedrawWindow();
00429                 CImageList::DragShowNolock( TRUE );
00430         }
00431 
00432         if ( rcClient.PtInRect( ptLocal ) )
00433         {
00434                 if ( ptLocal.y < rcClient.top + 8 )
00435                 {
00436                         CImageList::DragShowNolock( FALSE );
00437                         ScrollBy( -16 );
00438                         UpdateWindow();
00439                         CImageList::DragShowNolock( TRUE );
00440                 }
00441                 else if ( ptLocal.y >= rcClient.bottom - 8 )
00442                 {
00443                         CImageList::DragShowNolock( FALSE );
00444                         ScrollBy( 16 );
00445                         UpdateWindow();
00446                         CImageList::DragShowNolock( TRUE );
00447                 }
00448         }
00449 
00450         return ( m_pDropItem != NULL );
00451 }
00452 
00453 BOOL CLibraryTreeView::DropObjects(CLibraryList* pList, BOOL bCopy, CSingleLock& oLock)
00454 {
00455         if ( m_pDropItem == NULL ) return FALSE;
00456 
00457         CWaitCursor pCursor;
00458 
00459         if ( pList == NULL )
00460         {
00461         }
00462         else if ( m_pDropItem->m_pPhysical != NULL )
00463         {
00464                 CFileCopyDlg dlg( NULL, ! bCopy );
00465 
00466                 for ( POSITION pos = pList->GetHeadPosition() ; pos ; )
00467                 {
00468                         DWORD nObject = pList->GetNext( pos );
00469 
00470                         if ( CLibraryFile* pFile = Library.LookupFile( nObject ) )
00471                         {
00472                                 if ( pFile->m_pFolder != m_pDropItem->m_pPhysical )
00473                                         dlg.AddFile( pFile );
00474                         }
00475                 }
00476 
00477                 dlg.m_sTarget = m_pDropItem->m_pPhysical->m_sPath;
00478                 m_pDropItem = NULL;
00479 
00480                 if ( oLock.IsLocked() )
00481                 {
00482                         oLock.Unlock();
00483                         dlg.DoModal();
00484                         oLock.Lock();
00485                 }
00486                 else
00487                 {
00488                         dlg.DoModal();
00489                 }
00490         }
00491         else if ( m_pDropItem->m_pVirtual != NULL )
00492         {
00493                 for ( POSITION pos = pList->GetHeadPosition() ; pos ; )
00494                 {
00495                         DWORD nObject = pList->GetNext( pos );
00496 
00497                         if ( CLibraryFile* pFile = Library.LookupFile( nObject ) )
00498                         {
00499                                 m_pDropItem->m_pVirtual->AddFile( pFile );
00500 
00501                                 for ( CLibraryTreeItem* pItem = m_pSelFirst ; pItem && ! bCopy ;
00502                                                 pItem = pItem->m_pSelNext )
00503                                 {
00504                                         if ( pItem->m_pVirtual != NULL && pItem != m_pDropItem )
00505                                         {
00506                                                 if ( LibraryFolders.CheckAlbum( pItem->m_pVirtual ) )
00507                                                 {
00508                                                         pItem->m_pVirtual->RemoveFile( pFile );
00509                                                 }
00510                                         }
00511                                 }
00512                         }
00513                         else if ( LibraryFolders.CheckAlbum( (CAlbumFolder*)nObject ) )
00514                         {
00515                                 CAlbumFolder* pFolder = (CAlbumFolder*)nObject;
00516 
00517                                 if ( pFolder != m_pDropItem->m_pVirtual &&
00518                                          pFolder->m_pParent != m_pDropItem->m_pVirtual &&
00519                                          pFolder->CheckFolder( m_pDropItem->m_pVirtual, TRUE ) == FALSE )
00520                                 {
00521                                         pFolder->m_pParent->OnFolderDelete( pFolder );
00522                                         pFolder->m_pParent = m_pDropItem->m_pVirtual;
00523                                         pFolder->m_pParent->m_pFolders.AddTail( pFolder );
00524                                         pFolder->m_pParent->m_nUpdateCookie++;
00525                                         Library.m_nUpdateCookie++;
00526                                 }
00527                         }
00528                 }
00529         }
00530 
00531         m_pDropItem = NULL;
00532         Invalidate();
00533 
00534         return TRUE;
00535 }
00536 
00538 // CLibraryTreeView message handlers
00539 
00540 int CLibraryTreeView::OnCreate(LPCREATESTRUCT lpCreateStruct)
00541 {
00542         if ( CLibraryTreeCtrl::OnCreate( lpCreateStruct ) == -1 ) return -1;
00543 
00544         m_wndFolderTip.Create( this );
00545         m_wndAlbumTip.Create( this );
00546 
00547         return 0;
00548 }
00549 
00550 BOOL CLibraryTreeView::PreTranslateMessage(MSG* pMsg)
00551 {
00552         if ( m_bVirtual )
00553         {
00554                 if ( pMsg->message == WM_KEYDOWN && pMsg->wParam == VK_DELETE )
00555                 {
00556                         OnLibraryFolderDelete();
00557                         return TRUE;
00558                 }
00559                 else if ( pMsg->message == WM_SYSKEYDOWN && pMsg->wParam == VK_RETURN )
00560                 {
00561                         OnLibraryFolderProperties();
00562                         return TRUE;
00563                 }
00564         }
00565         else
00566         {
00567                 if ( pMsg->message == WM_KEYDOWN && pMsg->wParam == VK_RETURN )
00568                 {
00569                         OnLibraryExplore();
00570                         return TRUE;
00571                 }
00572         }
00573 
00574         return CLibraryTreeCtrl::PreTranslateMessage( pMsg );
00575 }
00576 
00577 void CLibraryTreeView::OnContextMenu(CWnd* pWnd, CPoint point)
00578 {
00579         if ( m_bVirtual )
00580         {
00581                 Skin.TrackPopupMenu( _T("CLibraryTree.Virtual"), point, ID_LIBRARY_FOLDER_PROPERTIES );
00582         }
00583         else
00584         {
00585                 Skin.TrackPopupMenu( _T("CLibraryTree.Physical"), point, ID_LIBRARY_EXPLORE );
00586         }
00587 }
00588 
00589 void CLibraryTreeView::OnLButtonDblClk(UINT nFlags, CPoint point)
00590 {
00591         CLibraryTreeCtrl::OnLButtonDblClk( nFlags, point );
00592 
00593         if ( m_pFocus == NULL && ! m_bVirtual )
00594         {
00595                 SelectAll();
00596                 NotifySelection();
00597         }
00598 }
00599 
00600 void CLibraryTreeView::OnUpdateLibraryParent(CCmdUI* pCmdUI)
00601 {
00602         CLibraryFrame* pFrame = (CLibraryFrame*)GetParent();
00603         ASSERT_KINDOF(CLibraryFrame, pFrame);
00604 
00605         CCoolBarCtrl* pBar = &pFrame->m_wndViewTop;
00606         CCoolBarItem* pItem = pBar->GetID( ID_LIBRARY_PARENT );
00607 
00608         BOOL bAvailable = ( m_nSelected == 1 );
00609 
00610         if ( pItem == pCmdUI ) pItem->Show( bAvailable );
00611         pCmdUI->Enable( bAvailable );
00612 }
00613 
00614 void CLibraryTreeView::OnLibraryParent()
00615 {
00616         CLibraryTreeItem* pNew = NULL;
00617 
00618         if ( m_nSelected == 1 && m_pSelFirst->m_pParent != m_pRoot )
00619         {
00620                 pNew = m_pSelFirst->m_pParent;
00621         }
00622 
00623         DeselectAll( pNew );
00624 
00625         if ( pNew != NULL )
00626         {
00627                 Select( pNew );
00628                 Highlight( pNew );
00629         }
00630 
00631         Invalidate();
00632         NotifySelection();
00633 }
00634 
00636 // CLibraryTreeView physical command handlers
00637 
00638 void CLibraryTreeView::OnUpdateLibraryExplore(CCmdUI* pCmdUI)
00639 {
00640         pCmdUI->Enable( ! m_bVirtual && m_nSelected == 1 );
00641 }
00642 
00643 void CLibraryTreeView::OnLibraryExplore()
00644 {
00645         if ( m_bVirtual || m_nSelected != 1 || m_pSelFirst == NULL ) return;
00646 
00647         CSingleLock pLock( &Library.m_pSection, TRUE );
00648         if ( ! LibraryFolders.CheckFolder( m_pSelFirst->m_pPhysical, TRUE ) ) return;
00649         CString strPath = m_pSelFirst->m_pPhysical->m_sPath;
00650         pLock.Unlock();
00651 
00652         CFileExecutor::Execute( strPath, TRUE );
00653 }
00654 
00655 void CLibraryTreeView::OnUpdateLibraryScan(CCmdUI* pCmdUI)
00656 {
00657         pCmdUI->Enable( ! m_bVirtual && m_nSelected > 0 );
00658 }
00659 
00660 void CLibraryTreeView::OnLibraryScan()
00661 {
00662         CSingleLock pLock( &Library.m_pSection, TRUE );
00663 
00664         for ( CLibraryTreeItem* pItem = m_pSelFirst ; pItem ; pItem = pItem->m_pSelNext )
00665         {
00666                 if ( LibraryFolders.CheckFolder( pItem->m_pPhysical, TRUE ) ) pItem->m_pPhysical->Scan();
00667         }
00668 }
00669 
00670 void CLibraryTreeView::OnUpdateLibraryShared(CCmdUI* pCmdUI)
00671 {
00672         CSingleLock pLock( &Library.m_pSection );
00673         if ( ! pLock.Lock( 50 ) ) return;
00674 
00675         TRISTATE bShared = TS_UNKNOWN;
00676 
00677         for ( CLibraryTreeItem* pItem = m_pSelFirst ; pItem ; pItem = pItem->m_pSelNext )
00678         {
00679                 if ( LibraryFolders.CheckFolder( pItem->m_pPhysical, TRUE ) )
00680                 {
00681                         if ( bShared == TS_UNKNOWN )
00682                         {
00683                                 bShared = pItem->m_pPhysical->IsShared() ? TS_TRUE : TS_FALSE;
00684                         }
00685                         else if ( ( bShared == TS_TRUE ) != pItem->m_pPhysical->IsShared() )
00686                         {
00687                                 pCmdUI->Enable( FALSE );
00688                                 return;
00689                         }
00690                 }
00691         }
00692 
00693         pCmdUI->Enable( m_nSelected > 0 );
00694         pCmdUI->SetCheck( bShared == TS_TRUE );
00695 }
00696 
00697 void CLibraryTreeView::OnLibraryShared()
00698 {
00699         {
00700                 CQuickLock oLock( Library.m_pSection );
00701 
00702                 for ( CLibraryTreeItem* pItem = m_pSelFirst ; pItem ; pItem = pItem->m_pSelNext )
00703                 {
00704                         if ( LibraryFolders.CheckFolder( pItem->m_pPhysical, TRUE ) )
00705                         {
00706                                 BOOL bShared = pItem->m_pPhysical->IsShared();
00707                                 pItem->m_pPhysical->m_bShared = TS_UNKNOWN;
00708 
00709                                 if ( bShared )
00710                                         pItem->m_pPhysical->m_bShared = pItem->m_pPhysical->IsShared() ? TS_FALSE : TS_UNKNOWN;
00711                                 else
00712                                         pItem->m_pPhysical->m_bShared = pItem->m_pPhysical->IsShared() ? TS_UNKNOWN : TS_TRUE;
00713                                 pItem->m_pPhysical->m_nUpdateCookie++;
00714                         }
00715                 }
00716 
00717                 Library.Update();
00718         }
00719         PostUpdate();
00720 }
00721 
00722 void CLibraryTreeView::OnUpdateLibraryRemove(CCmdUI* pCmdUI)
00723 {
00724         CSingleLock pLock( &Library.m_pSection );
00725         if ( ! pLock.Lock( 50 ) ) return;
00726 
00727         for ( CLibraryTreeItem* pItem = m_pSelFirst ; pItem ; pItem = pItem->m_pSelNext )
00728         {
00729                 if ( LibraryFolders.CheckFolder( pItem->m_pPhysical, TRUE ) )
00730                 {
00731                         if ( pItem->m_pPhysical->m_pParent == NULL )
00732                         {
00733                                 pCmdUI->Enable( TRUE );
00734                                 return;
00735                         }
00736                 }
00737         }
00738 
00739         pCmdUI->Enable( FALSE );
00740 }
00741 
00742 void CLibraryTreeView::OnLibraryRemove()
00743 {
00744         CSingleLock pLock( &Library.m_pSection, TRUE );
00745 
00746         for ( CLibraryTreeItem* pItem = m_pSelFirst ; pItem ; pItem = pItem->m_pSelNext )
00747         {
00748                 if ( LibraryFolders.CheckFolder( pItem->m_pPhysical, TRUE ) )
00749                 {
00750                         if ( pItem->m_pPhysical->m_pParent == NULL )
00751                         {
00752                                 LibraryFolders.RemoveFolder( pItem->m_pPhysical );
00753                         }
00754                 }
00755         }
00756 
00757         Library.Save();
00758         PostUpdate();
00759 }
00760 
00761 void CLibraryTreeView::OnLibraryAdd()
00762 {
00763         TCHAR szPath[MAX_PATH];
00764         LPITEMIDLIST pPath;
00765         LPMALLOC pMalloc;
00766         BROWSEINFO pBI;
00767 
00768         ZeroMemory( &pBI, sizeof(pBI) );
00769         pBI.hwndOwner           = AfxGetMainWnd()->GetSafeHwnd();
00770         pBI.pszDisplayName      = szPath;
00771         pBI.lpszTitle           = _T("Select folder to share:");
00772         pBI.ulFlags                     = BIF_RETURNONLYFSDIRS | BIF_NEWDIALOGSTYLE;
00773 
00774         pPath = SHBrowseForFolder( &pBI );
00775 
00776         if ( pPath == NULL ) return;
00777 
00778         SHGetPathFromIDList( pPath, szPath );
00779         SHGetMalloc( &pMalloc );
00780         pMalloc->Free( pPath );
00781 
00782         CFolderScanDlg dlgScan;
00783 
00784         LibraryFolders.AddFolder( szPath );
00785 
00786         dlgScan.DoModal();
00787 }
00788 
00790 // CLibraryTreeView virtual command handlers
00791 
00792 void CLibraryTreeView::OnUpdateLibraryFolderEnqueue(CCmdUI* pCmdUI)
00793 {
00794         CSingleLock oLock( &Library.m_pSection );
00795         if ( !oLock.Lock( 50 ) ) return;
00796 
00797         for ( CLibraryTreeItem* pItem = m_pSelFirst ; pItem ; pItem = pItem->m_pSelNext )
00798         {
00799                 if ( LibraryFolders.CheckAlbum( pItem->m_pVirtual ) && pItem->m_pVirtual->GetFileCount() > 0 )
00800                 {
00801                         pCmdUI->Enable( TRUE );
00802                         return;
00803                 }
00804         }
00805 
00806         pCmdUI->Enable( FALSE );
00807 }
00808 
00809 void CLibraryTreeView::OnLibraryFolderEnqueue()
00810 {
00811         CStringList pList;
00812 
00813         {
00814                 CSingleLock oLock( &Library.m_pSection );
00815                 if ( !oLock.Lock( 50 ) ) return;
00816 
00817                 for ( CLibraryTreeItem* pItem = m_pSelFirst ; pItem ; pItem = pItem->m_pSelNext )
00818                 {
00819                         if ( LibraryFolders.CheckAlbum( pItem->m_pVirtual ) )
00820                         {
00821                                 for ( POSITION pos = pItem->m_pVirtual->GetFileIterator() ; pos ; )
00822                                 {
00823                                         CLibraryFile* pFile = pItem->m_pVirtual->GetNextFile( pos );
00824                                         pList.AddTail( pFile->GetPath() );
00825                                 }
00826                         }
00827                 }
00828         }
00829 
00830         for ( POSITION pos = pList.GetHeadPosition() ; pos ; )
00831         {
00832                 CString strPath = pList.GetNext( pos );
00833                 CFileExecutor::Enqueue( strPath );
00834         }
00835 }
00836 
00837 void CLibraryTreeView::OnUpdateLibraryFolderMetadata(CCmdUI* pCmdUI)
00838 {
00839         pCmdUI->Enable( m_nSelected > 0 && m_pSelFirst->m_pVirtual != NULL );
00840 }
00841 
00842 void CLibraryTreeView::OnLibraryFolderMetadata()
00843 {
00844         CQuickLock oLock( Library.m_pSection );
00845 
00846         for ( CLibraryTreeItem* pItem = m_pSelFirst ; pItem ; pItem = pItem->m_pSelNext )
00847         {
00848                 CAlbumFolder* pFolder = pItem->m_pVirtual;
00849                 if ( LibraryFolders.CheckAlbum( pFolder ) ) pFolder->MetaToFiles( TRUE );
00850         }
00851 
00852         Library.Update();
00853 }
00854 
00855 void CLibraryTreeView::OnUpdateLibraryFolderDelete(CCmdUI* pCmdUI)
00856 {
00857         pCmdUI->Enable( m_nSelected > 0 && m_pSelFirst->m_pVirtual != NULL );
00858 }
00859 
00860 void CLibraryTreeView::OnLibraryFolderDelete()
00861 {
00862         if ( m_pSelFirst == NULL || m_pSelFirst->m_pVirtual == NULL ) return;
00863 
00864         CString strFormat, strMessage;
00865         Skin.LoadString( strFormat, IDS_LIBRARY_FOLDER_DELETE );
00866         strMessage.Format( strFormat, m_nSelected );
00867 
00868         if ( AfxMessageBox( strMessage, MB_ICONQUESTION|MB_OKCANCEL ) != IDOK ) return;
00869 
00870         {
00871                 CQuickLock oLock( Library.m_pSection );
00872 
00873                 for ( CLibraryTreeItem* pItem = m_pSelFirst ; pItem ; pItem = pItem->m_pSelNext )
00874                 {
00875                         CAlbumFolder* pFolder = pItem->m_pVirtual;
00876                         if ( LibraryFolders.CheckAlbum( pFolder ) ) pFolder->Delete();
00877                 }
00878         }
00879 
00880         NotifySelection();
00881 }
00882 
00883 void CLibraryTreeView::OnUpdateLibraryFolderNew(CCmdUI* pCmdUI)
00884 {
00885         pCmdUI->Enable( m_nSelected == 0 || ( m_nSelected == 1 && m_pSelFirst->m_pVirtual != NULL ) );
00886 }
00887 
00888 void CLibraryTreeView::OnLibraryFolderNew()
00889 {
00890         if ( m_pSelFirst != NULL && m_pSelFirst->m_pVirtual == NULL ) return;
00891 
00892         CAlbumFolder* pFolder;
00893         {
00894                 CQuickLock oLock( Library.m_pSection );
00895 
00896                 pFolder = Library.GetAlbumRoot();
00897 
00898                 if ( m_pSelFirst ) pFolder = m_pSelFirst->m_pVirtual;
00899 
00900                 pFolder = pFolder->AddFolder( NULL, _T("New Folder") );
00901 
00902                 if ( m_pSelFirst ) Expand( m_pSelFirst, TS_TRUE, FALSE );
00903 
00904                 NotifySelection();
00905 
00906                 if ( CLibraryTreeItem* pItem = GetFolderItem( pFolder ) )
00907                 {
00908                         Select( pItem, TS_TRUE, FALSE );
00909                         DeselectAll( pItem, NULL, FALSE );
00910                 }
00911         }
00912 
00913         Invalidate();
00914 
00915         if ( pFolder ) PostMessage( WM_COMMAND, ID_LIBRARY_FOLDER_PROPERTIES );
00916 }
00917 
00918 void CLibraryTreeView::OnUpdateLibraryRebuild(CCmdUI* pCmdUI)
00919 {
00920         pCmdUI->Enable( m_nSelected > 0 );
00921 }
00922 
00923 void CLibraryTreeView::OnLibraryRebuild()
00924 {
00925         CSingleLock oLock( &Library.m_pSection );
00926         if ( !oLock.Lock( 50 ) ) return;
00927 
00928         CLibraryList pList;
00929 
00930         for ( CLibraryTreeItem* pItem = m_pSelFirst ; pItem ; pItem = pItem->m_pSelNext )
00931         {
00932                 pItem->GetFileList( &pList, TRUE );
00933         }
00934 
00935         for ( POSITION pos = pList.GetIterator() ; pos ; )
00936         {
00937                 if ( CLibraryFile* pFile = pList.GetNextFile( pos ) )
00938                 {
00939                         pFile->Rebuild();
00940                 }
00941         }
00942 
00943         Library.Update();
00944 }
00945 
00946 void CLibraryTreeView::OnUpdateLibraryFolderProperties(CCmdUI* pCmdUI)
00947 {
00948         pCmdUI->Enable( m_nSelected == 1 && m_pSelFirst->m_pVirtual != NULL );
00949 }
00950 
00951 void CLibraryTreeView::OnLibraryFolderProperties()
00952 {
00953         if ( m_pSelFirst == NULL || m_pSelFirst->m_pVirtual == NULL ) return;
00954 
00955         CAlbumFolder* pFolder = m_pSelFirst->m_pVirtual;
00956 
00957         CFolderPropertiesDlg dlg( NULL, pFolder );
00958 
00959         if ( dlg.DoModal() == IDOK )
00960         {
00961                 NotifySelection();
00962 
00963                 if ( CLibraryTreeItem* pItem = GetFolderItem( pFolder ) )
00964                 {
00965                         Select( pItem, TS_TRUE, FALSE );
00966                         DeselectAll( pItem, NULL, FALSE );
00967                         Invalidate();
00968                         NotifySelection();
00969                 }
00970         }
00971 }
00972 
00973 void CLibraryTreeView::OnUpdateLibraryFolderFileProperties(CCmdUI* pCmdUI)
00974 {
00975         pCmdUI->Enable( m_nSelected > 0 );
00976 }
00977 
00978 void CLibraryTreeView::OnLibraryFolderFileProperties()
00979 {
00980         CSingleLock pLock( &Library.m_pSection, TRUE );
00981         CLibraryList pList;
00982 
00983         for ( CLibraryTreeItem* pItem = m_pSelFirst ; pItem ; pItem = pItem->m_pSelNext )
00984         {
00985                 pItem->GetFileList( &pList, TRUE );
00986         }
00987 
00988         pLock.Unlock();
00989 
00990         CFilePropertiesSheet dlg;
00991         dlg.Add( &pList );
00992         dlg.DoModal();
00993 }
00994 
00995 void CLibraryTreeView::OnUpdateLibraryExportCollection(CCmdUI *pCmdUI)
00996 {
00997         pCmdUI->Enable( m_bVirtual && m_nSelected == 1 );
00998 }
00999 
01000 void CLibraryTreeView::OnLibraryExportCollection()
01001 {
01002         if ( m_pSelFirst == NULL || m_pSelFirst->m_pSelNext != NULL ) return;
01003         if ( m_pSelFirst->m_pVirtual == NULL ) return;
01004         if ( m_pSelFirst->m_pVirtual->m_pXML == NULL ) return;
01005 
01006         CCollectionExportDlg dlg( m_pSelFirst->m_pVirtual );
01007         dlg.DoModal();
01008 }

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