Exemplo n.º 1
0
BOOL CAlbumFolder::MetaToFiles(BOOL bAggressive)
{
	if ( m_pSchema == NULL || m_pXML == NULL ) return FALSE;

	for ( POSITION pos = GetFileIterator() ; pos ; )
	{
		CLibraryFile* pFile	= GetNextFile( pos );
		CSchema* pSchema	= pFile->m_pSchema;

		if ( pSchema == NULL ) continue;

		if ( CSchemaChild* pChild = m_pSchema->GetContained( pSchema->m_sURI ) )
		{
			CXMLElement* pXML = pFile->m_pMetadata->Clone();

			if ( pChild->MemberCopy( m_pXML, pXML, TRUE, bAggressive ) )
			{
				CXMLElement* pRoot = pSchema->Instantiate( TRUE );
				pRoot->AddElement( pXML );
				pFile->SetMetadata( pRoot );
				delete pRoot;
			}
			else
			{
				delete pXML;
			}
		}
	}

	return TRUE;
}
BOOL CFileMetadataPage::OnInitDialog()
{
	CFilePropertiesPage::OnInitDialog();

	CLibraryList* pFiles = GetList();

	CRect rcClient, rcCombo;
	CString strText;
	GetClientRect( &rcClient );

	m_wndSchemas.GetWindowRect( &rcCombo );
	ScreenToClient( &rcCombo );
	rcCombo.top = rcCombo.bottom + 8;
	rcCombo.bottom = rcClient.bottom - 8;

	m_wndData.Create( WS_CHILD|WS_VISIBLE|WS_BORDER|WS_TABSTOP, rcCombo, this, IDC_METADATA );
	LoadString ( strText, IDS_SEARCH_NO_METADATA );
	m_wndSchemas.m_sNoSchemaText = strText;

	BOOL bCollection = FALSE;
	CSchema* pSchema = NULL;

	{
		CQuickLock oLock( Library.m_pSection );

		for ( POSITION pos = pFiles->GetIterator() ; pos ; )
		{
			if ( CLibraryFile* pFile = pFiles->GetNextFile( pos ) )
			{
				CSchema* pThisSchema = pFile->m_pSchema;

				if ( pThisSchema != NULL && pThisSchema->m_nType == CSchema::stFolder ) bCollection = TRUE;

				if ( pSchema == NULL )
				{
					pSchema = pThisSchema;
				}
				else if ( pSchema != pThisSchema )
				{
					pSchema = NULL;
					break;
				}
			}
		}
	}

	m_wndSchemas.Load( pSchema != NULL ? pSchema->m_sURI : _T(""), bCollection ? -1 : 0 );
	OnSelChangeSchemas();

	if ( pSchema != NULL )
	{
		CXMLElement* pContainer	= pSchema->Instantiate( TRUE );
		CXMLElement* pXML		= pContainer->AddElement( pSchema->m_sSingular );

		{
			CQuickLock oLock( Library.m_pSection );

			for ( POSITION pos1 = pFiles->GetIterator() ; pos1 ; )
			{
				if ( CLibraryFile* pFile = pFiles->GetNextFile( pos1 ) )
				{
					if ( pFile->m_pMetadata != NULL && pSchema->Equals( pFile->m_pSchema ) )
					{
						for ( POSITION pos2 = pSchema->GetMemberIterator() ; pos2 ; )
						{
							CSchemaMember* pMember = pSchema->GetNextMember( pos2 );
							CString strOld = pMember->GetValueFrom( pXML, _T("(~ns~)") );
							CString strNew = pMember->GetValueFrom( pFile->m_pMetadata /* , _T("(~ns~)") */ );

							if ( strNew != _T("(~ns~)") && strOld != _T("(~mt~)") )
							{
								if ( strOld == _T("(~ns~)") )
								{
									pXML->AddAttribute( pMember->m_sName, strNew );
								}
								else if ( strOld != strNew )
								{
									pXML->AddAttribute( pMember->m_sName, _T("(~mt~)") );
								}
							}
						}
					}
				}
			}
		}

		m_wndData.UpdateData( pXML, FALSE );
		delete pContainer;
	}

	return TRUE;
}