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 144 of file Project.h.

Constructor & Destructor Documentation

ImportXMLTagHandler::ImportXMLTagHandler ( AudacityProject pProject)
inline

Definition at line 147 of file Project.h.

References mProject.

147 { mProject = pProject; }
AudacityProject * mProject
Definition: Project.h:158

Member Function Documentation

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

Definition at line 150 of file Project.h.

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

Implements XMLTagHandler.

Definition at line 483 of file Project.cpp.

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

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

Referenced by HandleXMLTag(), and ImportXMLTagHandler().


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