1
0
mirror of https://github.com/cookiengineer/audacity synced 2025-07-17 17:17:40 +02:00

Reduced some repetitive code. Added credit for Mark Young.

Also added i18n-hint on translation and a couple of TODOs for further improvement.
This commit is contained in:
James Crook 2016-04-01 11:13:32 +01:00
parent 7429848573
commit b764c465d0
3 changed files with 32 additions and 216 deletions

View File

@ -120,6 +120,7 @@ void AboutDialog::CreateCreditsList()
AddCredit(wxString(wxT("Jun Wan, ")) + _("developer"), roleContributor); AddCredit(wxString(wxT("Jun Wan, ")) + _("developer"), roleContributor);
AddCredit(wxString(wxT("Daniel Winzen, ")) + _("developer"), roleContributor); AddCredit(wxString(wxT("Daniel Winzen, ")) + _("developer"), roleContributor);
AddCredit(wxString(wxT("Tom Woodhams, ")) + _("developer"), roleContributor); AddCredit(wxString(wxT("Tom Woodhams, ")) + _("developer"), roleContributor);
AddCredit(wxString(wxT("Mark Young, ")) + _("developer"), roleContributor);
AddCredit(wxString(wxT("Wing Yu, ")) + _("developer"), roleContributor); AddCredit(wxString(wxT("Wing Yu, ")) + _("developer"), roleContributor);
// Translators // Translators

View File

@ -327,7 +327,6 @@ void TimerRecordDialog::OnOK(wxCommandEvent& WXUNUSED(event))
} }
} }
if (m_pTimerAutoExportCheckBoxCtrl->IsChecked()) { if (m_pTimerAutoExportCheckBoxCtrl->IsChecked()) {
if (!m_fnAutoExportFile.IsOk() || m_fnAutoExportFile.IsDir()) { if (!m_fnAutoExportFile.IsOk() || m_fnAutoExportFile.IsDir()) {
wxMessageBox(_("Automatic Export path is invalid."), wxMessageBox(_("Automatic Export path is invalid."),
_("Error in Automatic Export"), wxICON_EXCLAMATION | wxOK); _("Error in Automatic Export"), wxICON_EXCLAMATION | wxOK);
@ -344,34 +343,19 @@ void TimerRecordDialog::OnOK(wxCommandEvent& WXUNUSED(event))
} }
void TimerRecordDialog::EnableDisableAutoControls(bool bEnable, int iControlGoup) { void TimerRecordDialog::EnableDisableAutoControls(bool bEnable, int iControlGoup) {
if (iControlGoup == CONTROL_GROUP_EXPORT) { if (iControlGoup == CONTROL_GROUP_EXPORT) {
// Enable or Disable the Export controls m_pTimerExportPathTextCtrl->Enable( bEnable );
if (bEnable) { m_pTimerExportPathButtonCtrl->Enable( bEnable);
m_pTimerExportPathTextCtrl->Enable(); } else if (iControlGoup == CONTROL_GROUP_SAVE) {
m_pTimerExportPathButtonCtrl->Enable(); m_pTimerSavePathTextCtrl->Enable( bEnable);
} m_pTimerSavePathButtonCtrl->Enable(bEnable );
else {
m_pTimerExportPathTextCtrl->Disable();
m_pTimerExportPathButtonCtrl->Disable();
}
}
else if (iControlGoup == CONTROL_GROUP_SAVE) {
// Enable or Disable the Save controls
if (bEnable) {
m_pTimerSavePathTextCtrl->Enable();
m_pTimerSavePathButtonCtrl->Enable();
}
else {
m_pTimerSavePathTextCtrl->Disable();
m_pTimerSavePathButtonCtrl->Disable();
}
} }
// Enable or disable the Choice box - if there is no Save or Export then this will be disabled // Enable or disable the Choice box - if there is no Save or Export then this will be disabled
if (m_pTimerAutoSaveCheckBoxCtrl->GetValue() || m_pTimerAutoExportCheckBoxCtrl->GetValue()) { if (m_pTimerAutoSaveCheckBoxCtrl->GetValue() || m_pTimerAutoExportCheckBoxCtrl->GetValue()) {
m_pTimerAfterCompleteChoiceCtrl->Enable(); m_pTimerAfterCompleteChoiceCtrl->Enable();
} } else {
else {
m_pTimerAfterCompleteChoiceCtrl->SetSelection(POST_TIMER_RECORD_NOTHING); m_pTimerAfterCompleteChoiceCtrl->SetSelection(POST_TIMER_RECORD_NOTHING);
m_pTimerAfterCompleteChoiceCtrl->Disable(); m_pTimerAfterCompleteChoiceCtrl->Disable();
} }
@ -392,8 +376,7 @@ void TimerRecordDialog::UpdateTextBoxControls() {
bool TimerRecordDialog::HaveFilesToRecover() bool TimerRecordDialog::HaveFilesToRecover()
{ {
wxDir dir(FileNames::AutoSaveDir()); wxDir dir(FileNames::AutoSaveDir());
if (!dir.IsOpened()) if (!dir.IsOpened()) {
{
wxMessageBox(_("Could not enumerate files in auto save directory."), wxMessageBox(_("Could not enumerate files in auto save directory."),
_("Error"), wxICON_STOP); _("Error"), wxICON_STOP);
return false; return false;
@ -437,13 +420,10 @@ int TimerRecordDialog::RunWaitDialog()
if (m_DateTime_Start > wxDateTime::UNow()) if (m_DateTime_Start > wxDateTime::UNow())
updateResult = this->WaitForStart(); updateResult = this->WaitForStart();
if (updateResult != eProgressSuccess) if (updateResult != eProgressSuccess) {
{
// Don't proceed, but don't treat it as canceled recording. User just canceled waiting. // Don't proceed, but don't treat it as canceled recording. User just canceled waiting.
return POST_TIMER_RECORD_CANCEL_WAIT; return POST_TIMER_RECORD_CANCEL_WAIT;
} } else {
else
{
// Record for specified time. // Record for specified time.
pProject->OnRecord(); pProject->OnRecord();
bool bIsRecording = true; bool bIsRecording = true;
@ -466,8 +446,7 @@ int TimerRecordDialog::RunWaitDialog()
this->OnTimer(dummyTimerEvent); this->OnTimer(dummyTimerEvent);
// Loop for progress display during recording. // Loop for progress display during recording.
while (bIsRecording && (updateResult == eProgressSuccess)) while (bIsRecording && (updateResult == eProgressSuccess)) {
{
wxMilliSleep(kTimerInterval); wxMilliSleep(kTimerInterval);
updateResult = progress.Update(); updateResult = progress.Update();
bIsRecording = (wxDateTime::UNow() <= m_DateTime_End); // Call UNow() again for extra accuracy... bIsRecording = (wxDateTime::UNow() <= m_DateTime_End); // Call UNow() again for extra accuracy...
@ -486,15 +465,14 @@ int TimerRecordDialog::RunWaitDialog()
} }
int TimerRecordDialog::ExecutePostRecordActions(bool bWasStopped) { int TimerRecordDialog::ExecutePostRecordActions(bool bWasStopped) {
// We no longer automatically (and silently) call ->Save() when the // MY: We no longer automatically (and silently) call ->Save() when the
// timer recording is completed! // timer recording is completed. We can now Save and/or Export depending
// We can now Save and/or Export depending on the options selected by // on the options selected by the user.
// the user.
// Once completed, we can also close Audacity, restart the system or // Once completed, we can also close Audacity, restart the system or
// shutdown the system. // shutdown the system.
// If there was any error with the auto save or export then we will not do // If there was any error with the auto save or export then we will not do
// the actions requested and instead present an error mesasge to the user. // the actions requested and instead present an error mesasge to the user.
// Finally, if there is no post-record action selected then we will output // Finally, if there is no post-record action selected then we output
// a dialog detailing what has been carried out instead. // a dialog detailing what has been carried out instead.
AudacityProject* pProject = GetActiveProject(); AudacityProject* pProject = GetActiveProject();
@ -511,8 +489,7 @@ int TimerRecordDialog::ExecutePostRecordActions(bool bWasStopped) {
// MY: If this project has already been saved then simply execute a Save here // MY: If this project has already been saved then simply execute a Save here
if (m_bProjectAlreadySaved) { if (m_bProjectAlreadySaved) {
bSaveOK = pProject->Save(); bSaveOK = pProject->Save();
} } else {
else {
bSaveOK = pProject->SaveFromTimerRecording(m_fnAutoSaveFile); bSaveOK = pProject->SaveFromTimerRecording(m_fnAutoSaveFile);
} }
} }
@ -539,8 +516,7 @@ int TimerRecordDialog::ExecutePostRecordActions(bool bWasStopped) {
if (bSaveOK) { if (bSaveOK) {
sMessage.Printf("%s\n\nRecording saved: %s", sMessage.Printf("%s\n\nRecording saved: %s",
sMessage, m_fnAutoSaveFile.GetFullPath()); sMessage, m_fnAutoSaveFile.GetFullPath());
} } else {
else {
sMessage.Printf("%s\n\nError saving recording.", sMessage); sMessage.Printf("%s\n\nError saving recording.", sMessage);
} }
} }
@ -548,8 +524,7 @@ int TimerRecordDialog::ExecutePostRecordActions(bool bWasStopped) {
if (bExportOK) { if (bExportOK) {
sMessage.Printf("%s\n\nRecording exported: %s", sMessage.Printf("%s\n\nRecording exported: %s",
sMessage, m_fnAutoExportFile.GetFullPath()); sMessage, m_fnAutoExportFile.GetFullPath());
} } else {
else {
sMessage.Printf("%s\n\nError exporting recording.", sMessage); sMessage.Printf("%s\n\nError exporting recording.", sMessage);
} }
} }
@ -566,8 +541,7 @@ int TimerRecordDialog::ExecutePostRecordActions(bool bWasStopped) {
// Show Error Message Box // Show Error Message Box
wxMessageBox(sMessage, _("Error"), wxICON_EXCLAMATION | wxOK); wxMessageBox(sMessage, _("Error"), wxICON_EXCLAMATION | wxOK);
} } else {
else {
if (bWasStopped && (iOverriddenAction != POST_TIMER_RECORD_NOTHING)) { if (bWasStopped && (iOverriddenAction != POST_TIMER_RECORD_NOTHING)) {
sMessage.Printf("%s\n\n'%s' has been cancelled as the recording was stopped.", sMessage.Printf("%s\n\n'%s' has been cancelled as the recording was stopped.",
@ -919,21 +893,27 @@ int TimerRecordDialog::WaitForStart()
return updateResult; return updateResult;
} }
// TODO: Rather than two flags, an enum with the possibilities would be better.
int TimerRecordDialog::PreActionDelay(int iActionIndex, bool bSaved, bool bExported) int TimerRecordDialog::PreActionDelay(int iActionIndex, bool bSaved, bool bExported)
{ {
wxString sMessage; wxString sMessage;
wxString sAction = m_pTimerAfterCompleteChoiceCtrl->GetString(iActionIndex); wxString sAction = m_pTimerAfterCompleteChoiceCtrl->GetString(iActionIndex);
wxString sDone = ""; wxString sDone = "";
if (bSaved && bExported) { if (bSaved && bExported) {
sDone = "Saved and Exported"; sDone = _("Saved and Exported");
} }
else if (bSaved) { else if (bSaved) {
sDone = "Saved"; sDone = _("Saved");
} }
else if (bExported) { else if (bExported) {
sDone = "Exported"; sDone = _("Exported");
} }
sMessage.Printf(_("Timer Recording completed: Recording has been %s as instructed.\n\n'%s' will occur shortly...\n"), // TODO: The wording will sound better if there are complete messages for
// the will-occur-shortly messages.
/* i18n-hint: The first %s will be a translation of 'Saved', 'Exported' or
* 'Saved and Exported'. The second %s will be 'Exit Audacity'
* 'Restart System' or 'Shutdown System' */
sMessage.Printf(_("Timer Recording completed: Recording has been %s.\n\n'%s' will occur shortly...\n"),
sDone, sAction); sDone, sAction);
wxDateTime dtNow = wxDateTime::UNow(); wxDateTime dtNow = wxDateTime::UNow();

View File

@ -954,173 +954,8 @@ bool Exporter::SetAutoExportOptions(AudacityProject *project) {
mFormat = -1; mFormat = -1;
mProject = project; mProject = project;
wxString maskString; if( GetFilename()==false )
wxString defaultFormat = gPrefs->Read(wxT("/Export/Format"), return false;
wxT("WAV"));
mFilterIndex = 0;
for (size_t i = 0; i < mPlugins.GetCount(); i++) {
for (int j = 0; j < mPlugins[i]->GetFormatCount(); j++)
{
maskString += mPlugins[i]->GetMask(j) + wxT("|");
if (mPlugins[i]->GetFormat(j) == defaultFormat) {
mFormat = i;
mSubFormat = j;
}
if (mFormat == -1) mFilterIndex++;
}
}
if (mFormat == -1)
{
mFormat = 0;
mFilterIndex = 0;
}
maskString.RemoveLast();
mFilename.SetPath(gPrefs->Read(wxT("/Export/Path"), ::wxGetCwd()));
mFilename.SetName(mProject->GetName());
while (true) {
// Must reset each iteration
mBook = NULL;
FileDialog fd(mProject,
mFileDialogTitle,
mFilename.GetPath(),
mFilename.GetFullName(),
maskString,
wxFD_SAVE | wxRESIZE_BORDER);
mDialog = &fd;
mDialog->PushEventHandler(this);
fd.SetUserPaneCreator(CreateUserPaneCallback, (wxUIntPtr) this);
fd.SetFilterIndex(mFilterIndex);
int result = fd.ShowModal();
mDialog->PopEventHandler();
if (result == wxID_CANCEL) {
return false;
}
mFilename = fd.GetPath();
if (mFilename == wxT("")) {
return false;
}
mFormat = fd.GetFilterIndex();
mFilterIndex = fd.GetFilterIndex();
int c = 0;
for (size_t i = 0; i < mPlugins.GetCount(); i++)
{
for (int j = 0; j < mPlugins[i]->GetFormatCount(); j++)
{
if (mFilterIndex == c)
{
mFormat = i;
mSubFormat = j;
}
c++;
}
}
wxString ext = mFilename.GetExt();
wxString defext = mPlugins[mFormat]->GetExtension(mSubFormat).Lower();
//
// Check the extension - add the default if it's not there,
// and warn user if it's abnormal.
//
if (ext.IsEmpty()) {
//
// Make sure the user doesn't accidentally save the file
// as an extension with no name, like just plain ".wav".
//
if (mFilename.GetName().Left(1) == wxT(".")) {
wxString prompt = _("Are you sure you want to export the file as \"") +
mFilename.GetFullName() +
wxT("\"?\n");
int action = wxMessageBox(prompt,
_("Warning"),
wxYES_NO | wxICON_EXCLAMATION);
if (action != wxYES) {
continue;
}
}
mFilename.SetExt(defext);
}
else if (!mPlugins[mFormat]->CheckFileName(mFilename, mSubFormat))
{
continue;
}
else if (!ext.IsEmpty() && !mPlugins[mFormat]->IsExtension(ext, mSubFormat) && ext.CmpNoCase(defext)) {
wxString prompt;
prompt.Printf(_("You are about to export a %s file with the name \"%s\".\n\n\
Normally these files end in \".%s\", and some programs\n\
will not open files with nonstandard extensions.\n\n\
Are you sure you want to export the file under this name?"),
mPlugins[mFormat]->GetFormat(mSubFormat).c_str(),
mFilename.GetFullName().c_str(),
defext.c_str());
int action = wxMessageBox(prompt,
_("Warning"),
wxYES_NO | wxICON_EXCLAMATION);
if (action != wxYES) {
continue;
}
}
if (mFilename.GetFullPath().Length() >= 256) {
wxMessageBox(_("Sorry, pathnames longer than 256 characters not supported."));
continue;
}
// Check to see if we are writing to a path that a missing aliased file existed at.
// This causes problems for the exporter, so we don't allow it.
// Overwritting non-missing aliased files is okay.
// Also, this can only happen for uncompressed audio.
bool overwritingMissingAlias;
overwritingMissingAlias = false;
for (size_t i = 0; i < gAudacityProjects.GetCount(); i++) {
AliasedFileArray aliasedFiles;
FindDependencies(gAudacityProjects[i], &aliasedFiles);
size_t j;
for (j = 0; j< aliasedFiles.GetCount(); j++) {
if (mFilename.GetFullPath() == aliasedFiles[j].mFileName.GetFullPath() &&
!mFilename.FileExists()) {
// Warn and return to the dialog
wxMessageBox(_("You are attempting to overwrite an aliased file that is missing.\n\
The file cannot be written because the path is needed to restore the original audio to the project.\n\
Choose File > Check Dependencies to view the locations of all missing files.\n\
If you still wish to export, please choose a different filename or folder."));
overwritingMissingAlias = true;
}
}
}
if (overwritingMissingAlias)
continue;
if (mFilename.FileExists()) {
wxString prompt;
prompt.Printf(_("A file named \"%s\" already exists. Replace?"),
mFilename.GetFullPath().c_str());
int action = wxMessageBox(prompt,
_("Warning"),
wxYES_NO | wxICON_EXCLAMATION);
if (action != wxYES) {
continue;
}
}
break;
}
// Let user edit MetaData // Let user edit MetaData
if (mPlugins[mFormat]->GetCanMetaData(mSubFormat)) { if (mPlugins[mFormat]->GetCanMetaData(mSubFormat)) {