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

A PrefsPanel used to select directories. More...

#include <DirectoriesPrefs.h>

Inheritance diagram for DirectoriesPrefs:
PrefsPanel wxPanelWrapper wxTabTraversalWrapper< wxPanel >

Public Member Functions

 DirectoriesPrefs (wxWindow *parent, wxWindowID winid)
 
 ~DirectoriesPrefs ()
 
bool Commit () override
 
bool Validate () override
 
wxString HelpPageName () override
 
void PopulateOrExchange (ShuttleGui &S) override
 
- Public Member Functions inherited from PrefsPanel
 PrefsPanel (wxWindow *parent, wxWindowID winid, const wxString &title)
 
virtual ~PrefsPanel ()
 
virtual void Preview ()
 
virtual bool ShowsPreviewButton ()
 
virtual void PopulateOrExchange (ShuttleGui &WXUNUSED(S))
 
virtual void Cancel ()
 
- Public Member Functions inherited from wxPanelWrapper
 wxPanelWrapper ()
 
 wxPanelWrapper (wxWindow *parent, wxWindowID winid=wxID_ANY, const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxDefaultSize, long style=wxTAB_TRAVERSAL|wxNO_BORDER, const wxString &name=_("Panel"))
 
bool Create (wxWindow *parent, wxWindowID winid=wxID_ANY, const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxDefaultSize, long style=wxTAB_TRAVERSAL|wxNO_BORDER, const wxString &name=_("Panel"))
 
- Public Member Functions inherited from wxTabTraversalWrapper< wxPanel >
 wxTabTraversalWrapper (Args &&...args)
 

Private Member Functions

void Populate ()
 Creates the dialog and its contents. More...
 
void UpdateFreeSpace (wxCommandEvent &e)
 
void OnChooseTempDir (wxCommandEvent &e)
 

Private Attributes

wxStaticText * mFreeSpace
 
wxTextCtrl * mTempDir
 

Detailed Description

A PrefsPanel used to select directories.

Definition at line 21 of file DirectoriesPrefs.h.

Constructor & Destructor Documentation

DirectoriesPrefs::DirectoriesPrefs ( wxWindow *  parent,
wxWindowID  winid 
)

Definition at line 51 of file DirectoriesPrefs.cpp.

53 : PrefsPanel(parent, winid, _("Directories")),
54  mFreeSpace(NULL),
55  mTempDir(NULL)
56 {
57  Populate();
58 }
wxStaticText * mFreeSpace
void Populate()
Creates the dialog and its contents.
wxTextCtrl * mTempDir
PrefsPanel(wxWindow *parent, wxWindowID winid, const wxString &title)
Definition: PrefsPanel.h:48
_("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
DirectoriesPrefs::~DirectoriesPrefs ( )

Definition at line 60 of file DirectoriesPrefs.cpp.

61 {
62 }

Member Function Documentation

bool DirectoriesPrefs::Commit ( )
overridevirtual

Implements PrefsPanel.

Definition at line 266 of file DirectoriesPrefs.cpp.

References eIsSavingToPrefs, and PopulateOrExchange().

267 {
268  ShuttleGui S(this, eIsSavingToPrefs);
270 
271  return true;
272 }
Derived from ShuttleGuiBase, an Audacity specific class for shuttling data to and from GUI...
Definition: ShuttleGui.h:409
void PopulateOrExchange(ShuttleGui &S) override
wxString DirectoriesPrefs::HelpPageName ( )
overridevirtual

Reimplemented from PrefsPanel.

Definition at line 274 of file DirectoriesPrefs.cpp.

275 {
276  return "Directories_Preferences";
277 }
void DirectoriesPrefs::OnChooseTempDir ( wxCommandEvent &  e)
private

Definition at line 133 of file DirectoriesPrefs.cpp.

References _(), AudacityApp::defaultTempDir, gPrefs, AudacityApp::IsTempDirectoryNameOK(), mTempDir, UpdateFreeSpace(), and wxGetApp().

134 {
135  wxString oldTempDir = gPrefs->Read(wxT("/Directories/TempDir"), wxGetApp().defaultTempDir);
136 
137  // Because we went through InitTempDir() during initialisation,
138  // the old temp directory name in prefs should already be OK. Just in case there is
139  // some way we hadn't thought of for it to be not OK,
140  // we avoid prompting with it in that case and use the suggested default instead.
141  if( !AudacityApp::IsTempDirectoryNameOK( oldTempDir ) )
142  oldTempDir = wxGetApp().defaultTempDir;
143 
144  wxDirDialogWrapper dlog(this,
145  _("Choose a location to place the temporary directory"),
146  oldTempDir );
147  int retval = dlog.ShowModal();
148  if (retval != wxID_CANCEL && dlog.GetPath() != wxT("")) {
149  wxFileName tmpDirPath;
150  tmpDirPath.AssignDir(dlog.GetPath());
151 
152  // Append an "audacity_temp" directory to this path if necessary (the
153  // default, the existing pref (as stored in the control), and any path
154  // ending in a directory with the same name as what we'd add should be OK
155  // already)
156  wxString newDirName;
157 #if defined(__WXMAC__)
158  newDirName = wxT("SessionData");
159 #elif defined(__WXMSW__)
160  // Clearing Bug 1271 residual issue. Let's NOT have temp in the name.
161  newDirName = wxT("SessionData");
162 #else
163  newDirName = wxT(".audacity_temp");
164 #endif
165  wxArrayString dirsInPath = tmpDirPath.GetDirs();
166 
167  // If the default temp dir or user's pref dir don't end in '/' they cause
168  // wxFileName's == operator to construct a wxFileName representing a file
169  // (that doesn't exist) -- hence the constructor calls
170  if (tmpDirPath != wxFileName(wxGetApp().defaultTempDir, wxT("")) &&
171  tmpDirPath != wxFileName(mTempDir->GetValue(), wxT("")) &&
172  (dirsInPath.GetCount() == 0 ||
173  dirsInPath[dirsInPath.GetCount()-1] != newDirName))
174  {
175  tmpDirPath.AppendDir(newDirName);
176  }
177 
178  mTempDir->SetValue(tmpDirPath.GetPath(wxPATH_GET_VOLUME|wxPATH_GET_SEPARATOR));
179  UpdateFreeSpace(e);
180  }
181 }
AudacityPrefs * gPrefs
Definition: Prefs.cpp:73
static bool IsTempDirectoryNameOK(const wxString &Name)
void UpdateFreeSpace(wxCommandEvent &e)
wxTextCtrl * mTempDir
_("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
AudacityApp & wxGetApp()
wxString defaultTempDir
Default temp directory.
Definition: AudacityApp.h:141
void DirectoriesPrefs::Populate ( )
private

Creates the dialog and its contents.

Definition at line 65 of file DirectoriesPrefs.cpp.

References eIsCreatingFromPrefs, PopulateOrExchange(), and UpdateFreeSpace().

66 {
67  //------------------------- Main section --------------------
68  // Now construct the GUI itself.
69  // Use 'eIsCreatingFromPrefs' so that the GUI is
70  // initialised with values from gPrefs.
73  // ----------------------- End of main section --------------
74 
75  wxCommandEvent e;
76  UpdateFreeSpace(e);
77 }
Derived from ShuttleGuiBase, an Audacity specific class for shuttling data to and from GUI...
Definition: ShuttleGui.h:409
void PopulateOrExchange(ShuttleGui &S) override
void UpdateFreeSpace(wxCommandEvent &e)
void DirectoriesPrefs::PopulateOrExchange ( ShuttleGui S)
override

Definition at line 79 of file DirectoriesPrefs.cpp.

References _(), ShuttleGuiBase::AddButton(), ShuttleGuiBase::AddFixedText(), ShuttleGui::AddSpace(), ShuttleGuiBase::AddVariableText(), ChooseButtonID, ShuttleGuiBase::EndMultiColumn(), ShuttleGuiBase::EndScroller(), ShuttleGuiBase::EndStatic(), ShuttleGuiBase::EndTwoColumn(), ShuttleGui::Id(), mFreeSpace, mTempDir, ShuttleGui::Prop(), ShuttleGuiBase::SetBorder(), ShuttleGuiBase::SetStretchyCol(), ShuttleGuiBase::StartHorizontalLay(), ShuttleGuiBase::StartMultiColumn(), ShuttleGuiBase::StartScroller(), ShuttleGuiBase::StartStatic(), ShuttleGuiBase::StartTwoColumn(), TempDirID, ShuttleGuiBase::TieCheckBox(), ShuttleGuiBase::TieNumericTextBox(), and ShuttleGuiBase::TieTextBox().

Referenced by Commit(), and Populate().

80 {
81  S.SetBorder(2);
82  S.StartScroller();
83 
84  S.StartStatic(_("Temporary files directory"));
85  {
86  S.StartMultiColumn(2, wxEXPAND);
87  {
88  S.SetStretchyCol(1);
89 
90  S.Id(TempDirID);
91  mTempDir = S.TieTextBox(_("&Location:"),
92  wxT("/Directories/TempDir"),
93  wxT(""),
94  30);
95  }
96  S.EndMultiColumn();
97  S.StartHorizontalLay(wxEXPAND);
98  {
99  S.Prop(0).AddFixedText(_("Free Space:"));
100  mFreeSpace = S.Prop(0).AddVariableText( {} );
101  S.Prop(10).AddSpace( 10 );
102  S.Id(ChooseButtonID).Prop(0).AddButton(_("C&hoose..."));
103  }
104 
105  }
106  S.EndStatic();
107 
108 #ifdef DEPRECATED_AUDIO_CACHE
109  // See http://bugzilla.audacityteam.org/show_bug.cgi?id=545.
110  S.StartStatic(_("Audio cache"));
111  {
112  S.TieCheckBox(_("Play and/or record using &RAM (useful for slow drives)"),
113  wxT("/Directories/CacheBlockFiles"),
114  false);
115 
116  S.StartTwoColumn();
117  {
118  S.TieNumericTextBox(_("Mi&nimum Free Memory (MB):"),
119  wxT("/Directories/CacheLowMem"),
120  16,
121  9);
122  }
123  S.EndTwoColumn();
124 
125  S.AddVariableText(_("If the available system memory falls below this value, audio will no longer\nbe cached in memory and will be written to disk."))->Wrap(600);
126  }
127  S.EndStatic();
128 #endif // DEPRECATED_AUDIO_CACHE
129  S.EndScroller();
130 
131 }
void EndMultiColumn()
void EndScroller()
Definition: ShuttleGui.cpp:828
wxStaticText * mFreeSpace
wxScrolledWindow * StartScroller(int iStyle=0)
Definition: ShuttleGui.cpp:795
void StartTwoColumn()
Definition: ShuttleGui.h:136
void StartHorizontalLay(int PositionFlags=wxALIGN_CENTRE, int iProp=1)
void StartMultiColumn(int nCols, int PositionFlags=wxALIGN_LEFT)
ShuttleGui & Id(int id)
wxTextCtrl * TieNumericTextBox(const wxString &Prompt, WrappedType &WrappedRef, const int nChars)
void AddFixedText(const wxString &Str, bool bCenter=false)
Definition: ShuttleGui.cpp:397
wxTextCtrl * mTempDir
_("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
wxCheckBox * TieCheckBox(const wxString &Prompt, WrappedType &WrappedRef)
wxStaticText * AddVariableText(const wxString &Str, bool bCenter=false, int PositionFlags=0)
Definition: ShuttleGui.cpp:414
wxStaticBox * StartStatic(const wxString &Str, int iProp=0)
Definition: ShuttleGui.cpp:763
ShuttleGui & Prop(int iProp)
Definition: ShuttleGui.h:418
wxSizerItem * AddSpace(int width, int height)
void SetBorder(int Border)
Definition: ShuttleGui.h:286
void EndTwoColumn()
Definition: ShuttleGui.h:137
wxButton * AddButton(const wxString &Text, int PositionFlags=wxALIGN_CENTRE)
Definition: ShuttleGui.cpp:341
void SetStretchyCol(int i)
Used to modify an already placed FlexGridSizer to make a column stretchy.
Definition: ShuttleGui.cpp:203
wxTextCtrl * TieTextBox(const wxString &Prompt, WrappedType &WrappedRef, const int nChars)
void DirectoriesPrefs::UpdateFreeSpace ( wxCommandEvent &  e)
private

Definition at line 183 of file DirectoriesPrefs.cpp.

References _(), Internat::FormatSize(), label, mFreeSpace, and mTempDir.

Referenced by OnChooseTempDir(), and Populate().

184 {
185  wxString tempDir;
186  wxString label;
187 
188  if (mTempDir != NULL) {
189  tempDir = mTempDir->GetValue();
190  }
191 
192  if (wxDirExists(tempDir)) {
193  wxLongLong space;
194  wxGetDiskSpace(tempDir, NULL, &space);
195  label = Internat::FormatSize(space);
196  }
197  else {
198  label = _("unavailable - above location doesn't exist");
199  }
200 
201  if( mFreeSpace != NULL ) {
202  mFreeSpace->SetLabel(label);
203  mFreeSpace->SetName(label); // fix for bug 577 (NVDA/Narrator screen readers do not read static text in dialogs)
204  }
205 }
static wxString FormatSize(wxLongLong size)
Convert a number to a string while formatting it in bytes, KB, MB, GB.
Definition: Internat.cpp:191
wxString label
Definition: Tags.cpp:727
wxStaticText * mFreeSpace
wxTextCtrl * mTempDir
_("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
bool DirectoriesPrefs::Validate ( )
override

Definition at line 207 of file DirectoriesPrefs.cpp.

References _(), AudacityMessageBox(), gPrefs, AudacityApp::IsTempDirectoryNameOK(), and mTempDir.

208 {
209  wxFileName tempDir;
210  tempDir.SetPath(mTempDir->GetValue());
211 
212  wxString path{tempDir.GetPath()};
213  if( !AudacityApp::IsTempDirectoryNameOK( path ) ) {
215  wxString::Format(_("Directory %s is not suitable (at risk of being cleaned out)"),
216  path),
217  _("Error"),
218  wxOK | wxICON_ERROR);
219  return false;
220  }
221  if (!tempDir.DirExists()) {
222  int ans = AudacityMessageBox(
223  wxString::Format(_("Directory %s does not exist. Create it?"),
224  path),
225  _("New Temporary Directory"),
226  wxYES_NO | wxCENTRE | wxICON_EXCLAMATION);
227 
228  if (ans != wxYES) {
229  return false;
230  }
231 
232  if (!tempDir.Mkdir(0755, wxPATH_MKDIR_FULL)) {
233  /* wxWidgets throws up a decent looking dialog */
234  return false;
235  }
236  }
237  else {
238  /* If the directory already exists, make sure it is writable */
239  wxLogNull logNo;
240  tempDir.AppendDir(wxT("canicreate"));
241  path = tempDir.GetPath();
242  if (!tempDir.Mkdir(0755)) {
244  wxString::Format(_("Directory %s is not writable"),
245  path),
246  _("Error"),
247  wxOK | wxICON_ERROR);
248  return false;
249  }
250  tempDir.Rmdir();
251  tempDir.RemoveLastDir();
252  }
253 
254  wxFileName oldDir;
255  oldDir.SetPath(gPrefs->Read(wxT("/Directories/TempDir")));
256  if (tempDir != oldDir) {
258  _("Changes to temporary directory will not take effect until Audacity is restarted"),
259  _("Temp Directory Update"),
260  wxOK | wxCENTRE | wxICON_INFORMATION);
261  }
262 
263  return true;
264 }
AudacityPrefs * gPrefs
Definition: Prefs.cpp:73
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 bool IsTempDirectoryNameOK(const wxString &Name)
wxTextCtrl * mTempDir
_("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

Member Data Documentation

wxStaticText* DirectoriesPrefs::mFreeSpace
private

Definition at line 36 of file DirectoriesPrefs.h.

Referenced by PopulateOrExchange(), and UpdateFreeSpace().

wxTextCtrl* DirectoriesPrefs::mTempDir
private

Definition at line 37 of file DirectoriesPrefs.h.

Referenced by OnChooseTempDir(), PopulateOrExchange(), UpdateFreeSpace(), and Validate().


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