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 491 of file Project.cpp.

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

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