Audacity  2.2.2
Public Member Functions | Private Attributes | List of all members
ImportXMLTagHandler Class Referencefinal

#include <Project.h>

Inheritance diagram for ImportXMLTagHandler:
XMLTagHandler

Public Member Functions

 ImportXMLTagHandler (AudacityProject *pProject)
 
bool HandleXMLTag (const wxChar *tag, const wxChar **attrs) override
 
XMLTagHandlerHandleXMLChild (const wxChar *WXUNUSED(tag)) override
 
- Public Member Functions inherited from XMLTagHandler
 XMLTagHandler ()
 
virtual ~XMLTagHandler ()
 
virtual void HandleXMLEndTag (const wxChar *WXUNUSED(tag))
 
virtual void HandleXMLContent (const wxString &WXUNUSED(content))
 
virtual XMLTagHandlerHandleXMLChild (const wxChar *tag)=0
 
bool ReadXMLTag (const char *tag, const char **attrs)
 
void ReadXMLEndTag (const char *tag)
 
void ReadXMLContent (const char *s, int len)
 
XMLTagHandlerReadXMLChild (const char *tag)
 

Private Attributes

AudacityProjectmProject
 

Detailed Description

Definition at line 143 of file Project.h.

Constructor & Destructor Documentation

ImportXMLTagHandler::ImportXMLTagHandler ( AudacityProject pProject)
inline

Definition at line 146 of file Project.h.

References mProject.

146 { mProject = pProject; }
AudacityProject * mProject
Definition: Project.h:157

Member Function Documentation

XMLTagHandler* ImportXMLTagHandler::HandleXMLChild ( const wxChar *  WXUNUSEDtag)
inlineoverride

Definition at line 149 of file Project.h.

150  { return NULL; }
bool ImportXMLTagHandler::HandleXMLTag ( const wxChar *  tag,
const wxChar **  attrs 
)
overridevirtual

Implements XMLTagHandler.

Definition at line 490 of file Project.cpp.

References Internat::CompatibleToDouble(), AudacityProject::GetDirManager(), GuardedCall(), AudacityProject::Import(), XMLValueChecker::IsGoodFileName(), XMLValueChecker::IsGoodPathName(), XMLValueChecker::IsGoodString(), and mProject.

491 {
492  if (wxStrcmp(tag, wxT("import")) || attrs==NULL || (*attrs)==NULL || wxStrcmp(*attrs++, wxT("filename")))
493  return false;
494  wxString strAttr = *attrs;
495  if (!XMLValueChecker::IsGoodPathName(strAttr))
496  {
497  // Maybe strAttr is just a fileName, not the full path. Try the project data directory.
498  wxFileName fileName(mProject->GetDirManager()->GetProjectDataDir(), strAttr);
499  if (XMLValueChecker::IsGoodFileName(strAttr, fileName.GetPath(wxPATH_GET_VOLUME)))
500  strAttr = fileName.GetFullPath();
501  else
502  {
503  wxLogWarning(wxT("Could not import file: %s"), strAttr);
504  return false;
505  }
506  }
507 
508  WaveTrackArray trackArray;
509 
510  // Guard this call so that C++ exceptions don't propagate through
511  // the expat library
512  GuardedCall(
513  [&] { mProject->Import(strAttr, &trackArray); },
514  [&] (AudacityException*) { trackArray.clear(); }
515  );
516 
517  if (trackArray.empty())
518  return false;
519 
520  // Handle other attributes, now that we have the tracks.
521  attrs++;
522  const wxChar** pAttr;
523  bool bSuccess = true;
524 
525  for (size_t i = 0; i < trackArray.size(); i++)
526  {
527  // Most of the "import" tag attributes are the same as for "wavetrack" tags,
528  // so apply them via WaveTrack::HandleXMLTag().
529  bSuccess = trackArray[i]->HandleXMLTag(wxT("wavetrack"), attrs);
530 
531  // "offset" tag is ignored in WaveTrack::HandleXMLTag except for legacy projects,
532  // so handle it here.
533  double dblValue;
534  pAttr = attrs;
535  while (*pAttr)
536  {
537  const wxChar *attr = *pAttr++;
538  const wxChar *value = *pAttr++;
539  const wxString strValue = value;
540  if (!wxStrcmp(attr, wxT("offset")) &&
541  XMLValueChecker::IsGoodString(strValue) &&
542  Internat::CompatibleToDouble(strValue, &dblValue))
543  trackArray[i]->SetOffset(dblValue);
544  }
545  }
546  return bSuccess;
547 };
root of a hierarchy of classes that are thrown and caught by Audacity.
AudacityProject * mProject
Definition: Project.h:157
static bool IsGoodPathName(const wxString &strPathName)
const std::shared_ptr< DirManager > & GetDirManager()
Definition: Project.cpp:1422
static bool IsGoodString(const wxString &str)
static bool CompatibleToDouble(const wxString &stringToConvert, double *result)
Convert a string to a number.
Definition: Internat.cpp:122
bool Import(const wxString &fileName, WaveTrackArray *pTrackArray=NULL)
Definition: Project.cpp:4344
std::vector< std::shared_ptr< WaveTrack > > WaveTrackArray
Definition: AudioIO.h:65
R GuardedCall(const F1 &body, const F2 &handler=F2::Default(), const F3 &delayedHandler={})
static bool IsGoodFileName(const wxString &strFileName, const wxString &strDirName=wxEmptyString)

Member Data Documentation

AudacityProject* ImportXMLTagHandler::mProject
private

Definition at line 157 of file Project.h.

Referenced by HandleXMLTag(), and ImportXMLTagHandler().


The documentation for this class was generated from the following files: