void CLibraryDetailView::Update()
{
	GET_LIST();
	
	CSchema* pSchema	= SchemaCache.Get( Settings.Library.FilterURI );
	DWORD nCookie		= GetFolderCookie();
	
	if ( Settings.Library.ShowVirtual ) pSchema = NULL;
	
	if ( m_nStyle == LVS_REPORT )
	{
		CLibraryTreeItem* pTree = GetFolderSelection();
		
		if ( pTree != NULL && pTree->m_pVirtual != NULL && pTree->m_pSelNext == NULL &&
			 pTree->m_pVirtual->m_pSchema != NULL )
		{
			CString strURI = pTree->m_pVirtual->m_pSchema->GetContainedURI( CSchema::stFile );
			
			if ( strURI.GetLength() && ( m_pSchema == NULL || m_pSchema->m_sURI != strURI ) )
			{
				if ( CSchema* pSchema = SchemaCache.Get( strURI ) )
				{
					CPtrList pColumns;
					CSchemaColumnsDlg::LoadColumns( pSchema, &pColumns );
					SetViewSchema( pSchema, &pColumns, TRUE, FALSE );
				}
			}
		}
	}

	LDVITEM* pItem = m_pList + m_nList - 1;

	for ( DWORD nCount = m_nList ; nCount ; nCount--, pItem-- )
	{
		CLibraryFile* pFile = Library.LookupFile( pItem->nIndex );
		
		if ( pFile && pFile->m_nSelectCookie == nCookie && pFile->IsAvailable() &&
			 ( ! pSchema || pSchema->Equals( pFile->m_pSchema ) ||
			 ( ! pFile->m_pMetadata && pSchema->FilterType( pFile->m_sName ) ) ) )
		{
			pFile->m_nListCookie = nCookie;
		}
		else
		{
			SelRemove( pItem->nIndex );
			CStringArray* pSaved = pItem->pText;
			CopyMemory( pItem, pItem + 1, sizeof(LDVITEM) * ( m_nList - nCount ) );
			pItem[ m_nList - nCount ].pText = pSaved;
			m_nList--;
		}
	}

	for ( POSITION pos = LibraryMaps.GetFileIterator() ; pos ; )
	{
		CLibraryFile* pFile = LibraryMaps.GetNextFile( pos );

		if ( pFile->m_nSelectCookie == nCookie &&
 			 pFile->m_nListCookie != nCookie &&
			 pFile->IsAvailable() &&
			 ( ! pSchema || pSchema->Equals( pFile->m_pSchema ) ||
			 ( ! pFile->m_pMetadata && pSchema->FilterType( pFile->m_sName ) ) ) )
		{
			if ( m_nList == m_nBuffer )	// MUST EQUAL
			{
				m_nBuffer += 64;
				LDVITEM* pList = new LDVITEM[ m_nBuffer ];
				if ( m_nList ) CopyMemory( pList, m_pList, m_nList * sizeof(LDVITEM) );
				if ( m_pList ) delete [] m_pList;
				ZeroMemory( pList + m_nList, ( m_nBuffer - m_nList ) * sizeof(LDVITEM) );
				m_pList = pList;
			}
			
			m_pList[ m_nList ].nIndex		= pFile->m_nIndex;
			m_pList[ m_nList ].nState		&= ~LDVI_SELECTED;
			m_nList++;
			
			pFile->m_nListCookie = nCookie;
		}
	}
	
	m_nListCookie++;
	
	SortItems();
}
void CLibraryAlbumView::Update()
{
	CLibraryTreeItem* pFolders = GetFolderSelection();

	m_pStaticStyle = m_pStyle;
	m_pStyle = NULL;
	BOOL bGhostFolder = FALSE;

	if ( pFolders != NULL && pFolders->m_pVirtual != NULL && pFolders->m_pSelNext == NULL )
	{
		CAlbumFolder* pFolder = pFolders->m_pVirtual;

		if ( CheckURI( pFolder->m_sSchemaURI, CSchema::uriMusicAlbum ) )
			m_pStyle = CSchema::uriMusicAlbum;
		else if ( CheckURI( pFolder->m_sSchemaURI, CSchema::uriMusicArtist ) )
			m_pStyle = CSchema::uriMusicArtist;
		else if ( CheckURI( pFolder->m_sSchemaURI, CSchema::uriMusicAll ) || CheckURI( pFolder->m_sSchemaURI, CSchema::uriMusicGenre ) )
			m_pStyle = CSchema::uriMusicAll;
		else if ( CheckURI( pFolder->m_sSchemaURI, CSchema::uriGhostFolder ) )
			bGhostFolder = TRUE;
	}

	CSchemaPtr pSchema	= SchemaCache.Get( Settings.Library.FilterURI );
	DWORD nCookie		= GetFolderCookie();
	BOOL bChanged		= m_pStyle != m_pStaticStyle;

	if ( Settings.Library.ShowVirtual )
		pSchema = NULL;

	CLibraryAlbumTrack** pList = m_pList + m_nCount - 1;

	for ( int nItem = m_nCount ; nItem ; nItem--, pList-- )
	{
		CLibraryAlbumTrack* pTrack	= *pList;
		CLibraryFile* pFile			= Library.LookupFile( pTrack->m_nIndex );

		if ( pFile != NULL && pFile->m_nSelectCookie == nCookie &&
			 ( pFile->IsAvailable() || bGhostFolder ) &&
			 ( ! pSchema || pSchema->Equals( pFile->m_pSchema ) ||
			 ( ! pFile->m_pMetadata && pSchema->FilterType( pFile->m_sName ) ) ) )
		{
			bChanged |= pTrack->Update( pFile );
			pFile->m_nListCookie = nCookie;
		}
		else
		{
			if ( pTrack == m_pFocus ) m_pFocus = NULL;
			if ( pTrack == m_pFirst ) m_pFirst = NULL;
			if ( pTrack->m_bSelected ) Select( pTrack, TRI_FALSE );
			delete pTrack;
			MoveMemory( pList, pList + 1, ( m_nCount - nItem ) * sizeof *pList );
			m_nCount--;
			bChanged = TRUE;
		}
	}

	if ( bChanged )
	{
		CRect rcClient;
		GetClientRect( &rcClient );
		int nMax	= m_nCount * m_szTrack.cy;
		m_nScroll	= max( 0, min( m_nScroll, nMax - rcClient.Height() + 1 ) );
	}

	for ( POSITION pos = LibraryMaps.GetFileIterator() ; pos ; )
	{
		CLibraryFile* pFile = LibraryMaps.GetNextFile( pos );

		if ( pFile->m_nSelectCookie == nCookie &&
			 pFile->m_nListCookie != nCookie &&
			 ( pFile->IsAvailable() || bGhostFolder ) &&
			 ( ! pSchema || pSchema->Equals( pFile->m_pSchema ) ||
			 ( ! pFile->m_pMetadata && pSchema->FilterType( pFile->m_sName ) ) ) )
		{
			CLibraryAlbumTrack* pTrack = new CLibraryAlbumTrack( pFile );

			if ( m_nCount == m_nBuffer )
			{
				m_nBuffer += 64;
				CLibraryAlbumTrack** pNewList = new CLibraryAlbumTrack*[ m_nBuffer ];
				if ( m_nCount ) CopyMemory( pNewList, m_pList, m_nCount * sizeof( CLibraryAlbumTrack* ) );
				delete [] m_pList;
				m_pList = pNewList;
			}

			m_pList[ m_nCount++ ] = pTrack;
			pFile->m_nListCookie = nCookie;
			bChanged = TRUE;
		}
	}

	if ( bChanged )
	{
		m_pStaticStyle = m_pStyle;
		qsort( m_pList, m_nCount, sizeof *m_pList, SortList );
		UpdateScroll();
	}
}
Exemplo n.º 3
0
void CLibraryTileView::Update()
{
	CSingleLock oLock( &Library.m_pSection );
	if ( ! oLock.Lock( 250 ) )
	{
		Invalidate();
		return;
	}

	CLibraryTreeItem* pFolders	= GetFolderSelection();
	CAlbumFolder* pFolder		= NULL;

	if ( pFolders == NULL || pFolders->m_pVirtual == NULL )
	{
		pFolder = Library.GetAlbumRoot();
	}
	else
	{
		if ( pFolders->m_pSelNext != NULL || pFolders->m_pVirtual->GetFileCount() > 0 )
		{
			if ( ! empty() )
			{
				clear();
				Invalidate();
			}

			return;
		}

		pFolder = pFolders->m_pVirtual;
	}

	DWORD nCookie = GetFolderCookie();
	bool bChanged = false;

	for ( iterator pTile = begin(); pTile != end(); )
	{
		CAlbumFolder* pAlbum = (*pTile)->GetAlbum();
		if ( pAlbum && pAlbum->GetParent() == pFolder )
		{
			bChanged = (*pTile)->Update() || bChanged;
			pAlbum->m_nListCookie = nCookie;
			++pTile;
		}
		else
		{
			if ( (*pTile)->m_bSelected ) Select( pTile, TRI_FALSE );
			if ( pTile == m_pFocus ) m_pFocus = end();
			if ( pTile == m_pFirst ) m_pFirst = end();

			pTile = m_oList.erase( pTile );

			bChanged = true;
		}
	}

	if ( bChanged )
	{
		CRect rcClient;
		GetClientRect( &rcClient );
		int nMax	= (int)( ( size() + m_nColumns - 1 ) / m_nColumns ) * m_szBlock.cy;
		m_nScroll	= max( 0, min( m_nScroll, nMax - rcClient.Height() + 1 ) );
	}

	for ( POSITION pos = pFolder ? pFolder->GetFolderIterator() : NULL; pos; )
	{
		CAlbumFolder* pChild = pFolder->GetNextFolder( pos );

		if ( pChild->m_nListCookie != nCookie )
		{
			m_oList.push_back( new CLibraryTileItem( pChild ) );

			pChild->m_nListCookie = nCookie;
			bChanged = true;
		}
	}

	if ( bChanged )
	{
		// ToDo: Review if still necessary for modern libs, and no boost::ptr_list
		// Crude workaround broken std::list::sort (vc++7.1):
		// sort() may invalidate at the end iterator
		// As of Boost 1.33.0, ptr_list does not provide
		// iterator versions of sort, which might solve this problem just as well.
		BOOL bFocusAtEnd = m_pFocus == m_oList.end();
		BOOL bFirstAtEnd = m_pFirst == m_oList.end();

		m_oList.sort( SortList() );

		if ( bFocusAtEnd ) m_pFocus = m_oList.end();
		if ( bFirstAtEnd ) m_pFirst = m_oList.end();

		UpdateScroll();
	}
}