Audacity  2.2.2
Classes | Enumerations | Functions
AutoRecovery.cpp File Reference
#include "AutoRecovery.h"
#include "Audacity.h"
#include "FileNames.h"
#include "blockfile/SimpleBlockFile.h"
#include "Sequence.h"
#include "ShuttleGui.h"
#include <wx/wxprec.h>
#include <wx/filefn.h>
#include <wx/dir.h>
#include <wx/dialog.h>
#include <wx/app.h>
#include "WaveTrack.h"
#include "widgets/ErrorDialog.h"

Go to the source code of this file.

Classes

class  AutoRecoveryDialog
 The AutoRecoveryDialog prompts the user whether to recover previous Audacity projects that were closed incorrectly. More...
 

Enumerations

enum  { ID_RECOVER_ALL = 10000, ID_RECOVER_NONE, ID_QUIT_AUDACITY, ID_FILE_LIST }
 
enum  FieldTypes {
  FT_StartTag, FT_EndTag, FT_String, FT_Int,
  FT_Bool, FT_Long, FT_LongLong, FT_SizeT,
  FT_Float, FT_Double, FT_Data, FT_Raw,
  FT_Push, FT_Pop, FT_Name
}
 

Functions

static bool HaveFilesToRecover ()
 
static bool RemoveAllAutoSaveFiles ()
 
static bool RecoverAllProjects (AudacityProject **pproj)
 
bool ShowAutoRecoveryDialogIfNeeded (AudacityProject **pproj, bool *didRecoverAnything)
 

Enumeration Type Documentation

anonymous enum
Enumerator
ID_RECOVER_ALL 
ID_RECOVER_NONE 
ID_QUIT_AUDACITY 
ID_FILE_LIST 

Definition at line 37 of file AutoRecovery.cpp.

enum FieldTypes

AutoSaveFile class

Enumerator
FT_StartTag 
FT_EndTag 
FT_String 
FT_Int 
FT_Bool 
FT_Long 
FT_LongLong 
FT_SizeT 
FT_Float 
FT_Double 
FT_Data 
FT_Raw 
FT_Push 
FT_Pop 
FT_Name 

Definition at line 464 of file AutoRecovery.cpp.

465 {
466  FT_StartTag, // type, ID, name
467  FT_EndTag, // type, ID, name
468  FT_String, // type, ID, name, string length, string
469  FT_Int, // type, ID, value
470  FT_Bool, // type, ID, value
471  FT_Long, // type, ID, value
472  FT_LongLong, // type, ID, value
473  FT_SizeT, // type, ID, value
474  FT_Float, // type, ID, value
475  FT_Double, // type, ID, value
476  FT_Data, // type, string length, string
477  FT_Raw, // type, string length, string
478  FT_Push, // type only
479  FT_Pop, // type only
480  FT_Name // type, name length, name
481 };

Function Documentation

static bool HaveFilesToRecover ( )
static

Definition at line 157 of file AutoRecovery.cpp.

References _(), AudacityMessageBox(), and FileNames::AutoSaveDir().

Referenced by ShowAutoRecoveryDialogIfNeeded(), and TimerRecordDialog::TimerRecordDialog().

158 {
159  wxDir dir(FileNames::AutoSaveDir());
160  if (!dir.IsOpened())
161  {
162  AudacityMessageBox(_("Could not enumerate files in auto save directory."),
163  _("Error"), wxICON_STOP);
164  return false;
165  }
166 
167  wxString filename;
168  bool c = dir.GetFirst(&filename, wxT("*.autosave"), wxDIR_FILES);
169 
170  return c;
171 }
int AudacityMessageBox(const wxString &message, const wxString &caption=AudacityMessageBoxCaptionStr(), long style=wxOK|wxCENTRE, wxWindow *parent=NULL, int x=wxDefaultCoord, int y=wxDefaultCoord)
Definition: ErrorDialog.h:92
static wxString AutoSaveDir()
Definition: FileNames.cpp:109
_("Move Track &Down")+wxT("\t")+(GetActiveProject() -> GetCommandManager() ->GetKeyFromName(wxT("TrackMoveDown")).Raw()), OnMoveTrack) POPUP_MENU_ITEM(OnMoveTopID, _("Move Track to &Top")+wxT("\t")+(GetActiveProject() ->GetCommandManager() ->GetKeyFromName(wxT("TrackMoveTop")).Raw()), OnMoveTrack) POPUP_MENU_ITEM(OnMoveBottomID, _("Move Track to &Bottom")+wxT("\t")+(GetActiveProject() ->GetCommandManager() ->GetKeyFromName(wxT("TrackMoveBottom")).Raw()), OnMoveTrack)#define SET_TRACK_NAME_PLUGIN_SYMBOLclass SetTrackNameCommand:public AudacityCommand
static bool RecoverAllProjects ( AudacityProject **  pproj)
static

Definition at line 194 of file AutoRecovery.cpp.

References _(), AudacityMessageBox(), FileNames::AutoSaveDir(), and AudacityProject::OpenProject().

Referenced by ShowAutoRecoveryDialogIfNeeded().

195 {
196  wxDir dir(FileNames::AutoSaveDir());
197  if (!dir.IsOpened())
198  {
199  AudacityMessageBox(_("Could not enumerate files in auto save directory."),
200  _("Error"), wxICON_STOP);
201  return false;
202  }
203 
204  // Open a project window for each auto save file
205  wxString filename;
206 
207  wxArrayString files;
208  wxDir::GetAllFiles(FileNames::AutoSaveDir(), &files,
209  wxT("*.autosave"), wxDIR_FILES);
210 
211  for (unsigned int i = 0; i < files.GetCount(); i++)
212  {
213  AudacityProject* proj{};
214  if (*pproj)
215  {
216  // Reuse existing project window
217  proj = *pproj;
218  *pproj = NULL;
219  }
220 
221  // Open project. When an auto-save file has been opened successfully,
222  // the opened auto-save file is automatically deleted and a NEW one
223  // is created.
224  AudacityProject::OpenProject( proj, files[i], false );
225  }
226 
227  return true;
228 }
int AudacityMessageBox(const wxString &message, const wxString &caption=AudacityMessageBoxCaptionStr(), long style=wxOK|wxCENTRE, wxWindow *parent=NULL, int x=wxDefaultCoord, int y=wxDefaultCoord)
Definition: ErrorDialog.h:92
AudacityProject provides the main window, with tools and tracks contained within it.
Definition: Project.h:176
static wxString AutoSaveDir()
Definition: FileNames.cpp:109
_("Move Track &Down")+wxT("\t")+(GetActiveProject() -> GetCommandManager() ->GetKeyFromName(wxT("TrackMoveDown")).Raw()), OnMoveTrack) POPUP_MENU_ITEM(OnMoveTopID, _("Move Track to &Top")+wxT("\t")+(GetActiveProject() ->GetCommandManager() ->GetKeyFromName(wxT("TrackMoveTop")).Raw()), OnMoveTrack) POPUP_MENU_ITEM(OnMoveBottomID, _("Move Track to &Bottom")+wxT("\t")+(GetActiveProject() ->GetCommandManager() ->GetKeyFromName(wxT("TrackMoveBottom")).Raw()), OnMoveTrack)#define SET_TRACK_NAME_PLUGIN_SYMBOLclass SetTrackNameCommand:public AudacityCommand
static AudacityProject * OpenProject(AudacityProject *pProject, const wxString &fileNameArg, bool addtohistory=true)
Definition: Project.cpp:2967
static bool RemoveAllAutoSaveFiles ( )
static

Definition at line 173 of file AutoRecovery.cpp.

References FileNames::AutoSaveDir().

Referenced by ShowAutoRecoveryDialogIfNeeded().

174 {
175  wxArrayString files;
176  wxDir::GetAllFiles(FileNames::AutoSaveDir(), &files,
177  wxT("*.autosave"), wxDIR_FILES);
178 
179  for (unsigned int i = 0; i < files.GetCount(); i++)
180  {
181  if (!wxRemoveFile(files[i]))
182  {
183  // I don't think this error message is actually useful.
184  // -dmazzoni
185  //AudacityMessageBox(wxT("Could not remove auto save file: " + files[i]),
186  // _("Error"), wxICON_STOP);
187  return false;
188  }
189  }
190 
191  return true;
192 }
static wxString AutoSaveDir()
Definition: FileNames.cpp:109
bool ShowAutoRecoveryDialogIfNeeded ( AudacityProject **  pproj,
bool *  didRecoverAnything 
)

Definition at line 230 of file AutoRecovery.cpp.

References HaveFilesToRecover(), ID_RECOVER_ALL, ID_RECOVER_NONE, RecoverAllProjects(), and RemoveAllAutoSaveFiles().

Referenced by AudacityApp::OnInit().

232 {
233  if (didRecoverAnything)
234  *didRecoverAnything = false;
235  if (HaveFilesToRecover())
236  {
237  // Under wxGTK3, the auto recovery dialog will not get
238  // the focus since the project window hasn't been allowed
239  // to completely initialize.
240  //
241  // Yielding seems to allow the initialization to complete.
242  //
243  // Additionally, it also corrects a sizing issue in the dialog
244  // related to wxWidgets bug:
245  //
246  // http://trac.wxwidgets.org/ticket/16440
247  //
248  // This must be done before "dlg" is declared.
249  wxEventLoopBase::GetActive()->YieldFor(wxEVT_CATEGORY_UI);
250 
251  int ret = AutoRecoveryDialog{nullptr}.ShowModal();
252 
253  switch (ret)
254  {
255  case ID_RECOVER_NONE:
256  return RemoveAllAutoSaveFiles();
257 
258  case ID_RECOVER_ALL:
259  if (didRecoverAnything)
260  *didRecoverAnything = true;
261  return RecoverAllProjects(pproj);
262 
263  default:
264  // This includes ID_QUIT_AUDACITY
265  return false;
266  }
267  } else
268  {
269  // Nothing to recover, move along
270  return true;
271  }
272 }
static bool RecoverAllProjects(AudacityProject **pproj)
static bool RemoveAllAutoSaveFiles()
The AutoRecoveryDialog prompts the user whether to recover previous Audacity projects that were close...
static bool HaveFilesToRecover()