Audacity 3.2.0
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:
[legend]
Collaboration diagram for DirectoriesPrefs:
[legend]

Public Member Functions

 DirectoriesPrefs (wxWindow *parent, wxWindowID winid)
 
 ~DirectoriesPrefs ()
 
ComponentInterfaceSymbol GetSymbol () const override
 
TranslatableString GetDescription () const override
 
bool Commit () override
 
bool Validate () override
 
ManualPageID HelpPageName () override
 If not empty string, the Help button is added below the panel. More...
 
void PopulateOrExchange (ShuttleGui &S) override
 
- Public Member Functions inherited from PrefsPanel
 PrefsPanel (wxWindow *parent, wxWindowID winid, const TranslatableString &title)
 
virtual ~PrefsPanel ()
 
virtual void Preview ()
 
virtual bool Commit ()=0
 
virtual PluginPath GetPath () const override
 
virtual VendorSymbol GetVendor () const override
 
virtual wxString GetVersion () const override
 
virtual bool ShowsPreviewButton ()
 
virtual void PopulateOrExchange (ShuttleGui &WXUNUSED(S))
 
virtual ManualPageID HelpPageName ()
 If not empty string, the Help button is added below the panel. More...
 
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 TranslatableString &name=XO("Panel"))
 
bool Create (wxWindow *parent, wxWindowID winid=wxID_ANY, const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxDefaultSize, long style=wxTAB_TRAVERSAL|wxNO_BORDER, const TranslatableString &name=XO("Panel"))
 
void SetLabel (const TranslatableString &label)
 
void SetName (const TranslatableString &name)
 
void SetToolTip (const TranslatableString &toolTip)
 
void SetName ()
 
- Public Member Functions inherited from wxTabTraversalWrapper< wxPanel >
 wxTabTraversalWrapper (Args &&... args)
 
 wxTabTraversalWrapper (const wxTabTraversalWrapper &)=delete
 
 wxTabTraversalWrapper (wxTabTraversalWrapper &&)=delete
 
wxTabTraversalWrapperoperator= (const wxTabTraversalWrapper &)=delete
 
wxTabTraversalWrapperoperator= (wxTabTraversalWrapper &&)=delete
 

Private Member Functions

void Populate ()
 Creates the dialog and its contents. More...
 
void OnTempText (wxCommandEvent &evt)
 
void OnTempBrowse (wxCommandEvent &evt)
 
void OnBrowse (wxCommandEvent &evt)
 
void OnText (wxCommandEvent &evt)
 

Private Attributes

ReadOnlyTextmFreeSpace
 
wxTextCtrl * mTempText
 
wxTextCtrl * mOpenText
 
wxTextCtrl * mSaveText
 
wxTextCtrl * mImportText
 
wxTextCtrl * mExportText
 
wxTextCtrl * mMacrosText
 

Additional Inherited Members

- Public Types inherited from PrefsPanel
using Factories = std::vector< PrefsPanel::PrefsNode >
 
using Factory = std::function< PrefsPanel *(wxWindow *parent, wxWindowID winid, AudacityProject *) >
 
- Static Public Member Functions inherited from PrefsPanel
static FactoriesDefaultFactories ()
 

Detailed Description

A PrefsPanel used to select directories.

Definition at line 24 of file DirectoriesPrefs.h.

Constructor & Destructor Documentation

◆ DirectoriesPrefs()

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

Definition at line 139 of file DirectoriesPrefs.cpp.

141: PrefsPanel(parent, winid, XO("Directories")),
142 mFreeSpace(NULL),
143 mTempText(NULL)
144{
145 Populate();
146}
XO("Cut/Copy/Paste")
void Populate()
Creates the dialog and its contents.
wxTextCtrl * mTempText
ReadOnlyText * mFreeSpace
PrefsPanel(wxWindow *parent, wxWindowID winid, const TranslatableString &title)
Definition: PrefsPanel.h:94

◆ ~DirectoriesPrefs()

DirectoriesPrefs::~DirectoriesPrefs ( )

Definition at line 148 of file DirectoriesPrefs.cpp.

149{
150}

Member Function Documentation

◆ Commit()

bool DirectoriesPrefs::Commit ( )
overridevirtual

Implements PrefsPanel.

Definition at line 507 of file DirectoriesPrefs.cpp.

508{
511
512 return true;
513}
@ eIsSavingToPrefs
Definition: ShuttleGui.h:47
#define S(N)
Definition: ToChars.cpp:64
void PopulateOrExchange(ShuttleGui &S) override
Derived from ShuttleGuiBase, an Audacity specific class for shuttling data to and from GUI.
Definition: ShuttleGui.h:640

References eIsSavingToPrefs, PopulateOrExchange(), and S.

Here is the call graph for this function:

◆ GetDescription()

TranslatableString DirectoriesPrefs::GetDescription ( ) const
overridevirtual

Implements ComponentInterface.

Definition at line 157 of file DirectoriesPrefs.cpp.

158{
159 return XO("Preferences for Directories");
160}

References XO().

Here is the call graph for this function:

◆ GetSymbol()

ComponentInterfaceSymbol DirectoriesPrefs::GetSymbol ( ) const
overridevirtual

Implements ComponentInterface.

Definition at line 152 of file DirectoriesPrefs.cpp.

153{
155}
#define DIRECTORIES_PREFS_PLUGIN_SYMBOL

References DIRECTORIES_PREFS_PLUGIN_SYMBOL.

◆ HelpPageName()

ManualPageID DirectoriesPrefs::HelpPageName ( )
overridevirtual

If not empty string, the Help button is added below the panel.

Default returns empty string.

Reimplemented from PrefsPanel.

Definition at line 162 of file DirectoriesPrefs.cpp.

163{
164 return "Directories_Preferences";
165}

◆ OnBrowse()

void DirectoriesPrefs::OnBrowse ( wxCommandEvent &  evt)
private

Definition at line 350 of file DirectoriesPrefs.cpp.

351{
352 long id = evt.GetId() - ButtonsStart;
353 wxTextCtrl *tc = (wxTextCtrl *) FindWindow(id + TextsStart);
354
355 wxString location = tc->GetValue();
356
357 wxDirDialogWrapper dlog(this,
358 XO("Choose a location"),
359 location);
360 int retval = dlog.ShowModal();
361
362 if (retval == wxID_CANCEL)
363 {
364 return;
365 }
366
367 if (evt.GetId() == SaveButtonID)
368 {
369 if (FATFilesystemDenied(dlog.GetPath(),
370 XO("Projects cannot be saved to FAT drives.")))
371 {
372 return;
373 }
374 }
375
376 //Checks if the location for Open,Save.Import,Export and Macro Output has write permissions(Browse Buttons)
377 if (!FileNames::WritableLocationCheck(dlog.GetPath(), XO("Cannot set the preference.")))
378 {
379 return;
380 }
381
382 tc->SetValue(dlog.GetPath());
383}
@ SaveButtonID
FILES_API bool WritableLocationCheck(const FilePath &path, const TranslatableString &message)
Check location on writable access and return true if checked successfully.
FILES_API bool FATFilesystemDenied(const FilePath &path, const TranslatableString &msg, const BasicUI::WindowPlacement &placement={})

References TempDirectory::FATFilesystemDenied(), SaveButtonID, FileNames::WritableLocationCheck(), and XO().

Here is the call graph for this function:

◆ OnTempBrowse()

void DirectoriesPrefs::OnTempBrowse ( wxCommandEvent &  evt)
private

Definition at line 266 of file DirectoriesPrefs.cpp.

267{
268 wxString oldTemp = gPrefs->Read(PreferenceKey(Operation::Open, PathType::_None),
270
271 // Because we went through InitTemp() during initialisation,
272 // the old temp directory name in prefs should already be OK. Just in case there is
273 // some way we hadn't thought of for it to be not OK,
274 // we avoid prompting with it in that case and use the suggested default instead.
275 if (!IsTempDirectoryNameOK(oldTemp))
276 {
277 oldTemp = DefaultTempDir();
278 }
279
280 wxDirDialogWrapper dlog(this,
281 XO("Choose a location to place the temporary directory"),
282 oldTemp);
283 int retval = dlog.ShowModal();
284 if (retval != wxID_CANCEL && !dlog.GetPath().empty())
285 {
286 wxFileName tmpDirPath;
287 tmpDirPath.AssignDir(dlog.GetPath());
288
289 if (FATFilesystemDenied(tmpDirPath.GetFullPath(),
290 XO("Temporary files directory cannot be on a FAT drive."))) {
291 return;
292 }
293
294 //Checks if the temporary directory has write permissions(via Browse Button)
295 if (!FileNames::WritableLocationCheck(dlog.GetPath(), XO("Cannot set the preference.")))
296 {
297 return;
298 }
299
300 // Append an "audacity_temp" directory to this path if necessary (the
301 // default, the existing pref (as stored in the control), and any path
302 // ending in a directory with the same name as what we'd add should be OK
303 // already)
304 wxString newDirName;
305#if defined(__WXMAC__)
306 newDirName = wxT("SessionData");
307#elif defined(__WXMSW__)
308 // Clearing Bug 1271 residual issue. Let's NOT have temp in the name.
309 newDirName = wxT("SessionData");
310#else
311 newDirName = wxT(".audacity_temp");
312#endif
313 auto dirsInPath = tmpDirPath.GetDirs();
314
315 // If the default temp dir or user's pref dir don't end in '/' they cause
316 // wxFileName's == operator to construct a wxFileName representing a file
317 // (that doesn't exist) -- hence the constructor calls
318 if (tmpDirPath != wxFileName(DefaultTempDir(), wxT("")) &&
319 tmpDirPath != wxFileName(mTempText->GetValue(), wxT("")) &&
320 (dirsInPath.size() == 0 ||
321 dirsInPath[dirsInPath.size()-1] != newDirName))
322 {
323 tmpDirPath.AppendDir(newDirName);
324 }
325
326 mTempText->SetValue(tmpDirPath.GetPath(wxPATH_GET_VOLUME|wxPATH_GET_SEPARATOR));
327 OnTempText(evt);
328 }
329}
wxT("CloseDown"))
audacity::BasicSettings * gPrefs
Definition: Prefs.cpp:68
void OnTempText(wxCommandEvent &evt)
virtual bool Read(const wxString &key, bool *value) const =0
FILES_API wxString PreferenceKey(FileNames::Operation op, FileNames::PathType type)
FILES_API bool IsTempDirectoryNameOK(const FilePath &Name)
FILES_API const FilePath & DefaultTempDir()

References TempDirectory::DefaultTempDir(), TempDirectory::FATFilesystemDenied(), gPrefs, TempDirectory::IsTempDirectoryNameOK(), mTempText, OnTempText(), FileNames::PreferenceKey(), audacity::BasicSettings::Read(), FileNames::WritableLocationCheck(), wxT(), and XO().

Here is the call graph for this function:

◆ OnTempText()

void DirectoriesPrefs::OnTempText ( wxCommandEvent &  evt)
private

Definition at line 331 of file DirectoriesPrefs.cpp.

332{
334
335 if (mTempText && mFreeSpace)
336 {
337 FilePath path = mTempText->GetValue();
338
339 wxLongLong space;
340 wxGetDiskSpace(path, NULL, &space);
341
342 label = wxDirExists(path)
343 ? Internat::FormatSize(space)
344 : XO("unavailable - above location doesn't exist");
345
347 }
348}
wxString FilePath
Definition: Project.h:21
TranslatableString label
Definition: TagsEditor.cpp:165
static TranslatableString FormatSize(wxLongLong size)
Convert a number to a string while formatting it in bytes, KB, MB, GB.
Definition: Internat.cpp:179
void SetValue(const wxString &value)
Definition: ReadOnlyText.h:124
Holds a msgid for the translation catalog; may also bind format arguments.
wxString Translation() const

References Internat::FormatSize(), label, mFreeSpace, mTempText, ReadOnlyText::SetValue(), TranslatableString::Translation(), and XO().

Referenced by OnTempBrowse(), and Populate().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ OnText()

void DirectoriesPrefs::OnText ( wxCommandEvent &  evt)
private

◆ Populate()

void DirectoriesPrefs::Populate ( )
private

Creates the dialog and its contents.

Definition at line 168 of file DirectoriesPrefs.cpp.

169{
170 //------------------------- Main section --------------------
171 // Now construct the GUI itself.
172 // Use 'eIsCreatingFromPrefs' so that the GUI is
173 // initialised with values from gPrefs.
176 // ----------------------- End of main section --------------
177
178 wxCommandEvent e;
179 OnTempText(e);
180}
@ eIsCreatingFromPrefs
Definition: ShuttleGui.h:46

References eIsCreatingFromPrefs, OnTempText(), PopulateOrExchange(), and S.

Here is the call graph for this function:

◆ PopulateOrExchange()

void DirectoriesPrefs::PopulateOrExchange ( ShuttleGui S)
override

Definition at line 182 of file DirectoriesPrefs.cpp.

183{
184 S.SetBorder(2);
185 S.StartScroller();
186
187 S.StartStatic(XO("Default directories"));
188 {
189 S.AddSpace(1);
190 S.AddFixedText(XO("Leave a field empty to go to the last directory used for that operation.\n"
191 "Fill in a field to always go to that directory for that operation."), false, 450);
192 S.AddSpace(5);
193
194 S.StartMultiColumn(3, wxEXPAND);
195 {
196 S.SetStretchyCol(1);
197
198 S.Id(OpenTextID);
199 mOpenText = S.TieTextBox(XXO("O&pen:"),
200 {PreferenceKey(Operation::Open, PathType::User),
201 wxT("")},
202 30);
203 S.Id(OpenButtonID).AddButton(XXO("&Browse..."));
204
205 S.Id(SaveTextID);
206 mSaveText = S.TieTextBox(XXO("S&ave:"),
207 {PreferenceKey(Operation::Save, PathType::User),
208 wxT("")},
209 30);
210 if( mSaveText )
211 mSaveText->SetValidator(FilesystemValidator(XO("Projects cannot be saved to FAT drives.")));
212 S.Id(SaveButtonID).AddButton(XXO("B&rowse..."));
213
214 S.Id(ImportTextID);
215 mImportText = S.TieTextBox(XXO("&Import:"),
216 {PreferenceKey(Operation::Import, PathType::User),
217 wxT("")},
218 30);
219 S.Id(ImportButtonID).AddButton(XXO("Br&owse..."));
220
221 S.Id(ExportTextID);
222 mExportText = S.TieTextBox(XXO("&Export:"),
223 {PreferenceKey(Operation::Export, PathType::User),
224 wxT("")},
225 30);
226 S.Id(ExportButtonID).AddButton(XXO("Bro&wse..."));
227
228 S.Id(MacrosTextID);
229 mMacrosText = S.TieTextBox(XXO("&Macro output:"),
230 {PreferenceKey(Operation::MacrosOut, PathType::User),
231 wxT("")},
232 30);
233 S.Id(MacrosButtonID).AddButton(XXO("Bro&wse..."));
234
235
236 }
237 S.EndMultiColumn();
238 }
239 S.EndStatic();
240
241 S.StartStatic(XO("Temporary files directory"));
242 {
243 S.StartMultiColumn(3, wxEXPAND);
244 {
245 S.SetStretchyCol(1);
246
247 S.Id(TempTextID);
248 mTempText = S.TieTextBox(XXO("&Location:"),
249 {PreferenceKey(Operation::Temp, PathType::_None),
250 wxT("")},
251 30);
252 if( mTempText )
253 mTempText->SetValidator(FilesystemValidator(XO("Temporary files directory cannot be on a FAT drive.")));
254 S.Id(TempButtonID).AddButton(XXO("Brow&se..."));
255
256 mFreeSpace = S
257 .AddReadOnlyText(XXO("&Free Space:"), "");
258 }
259 S.EndMultiColumn();
260 }
261 S.EndStatic();
262
263 S.EndScroller();
264}
@ ImportButtonID
@ ExportButtonID
XXO("&Cut/Copy/Paste Toolbar")
wxTextCtrl * mMacrosText
wxTextCtrl * mOpenText
wxTextCtrl * mSaveText
wxTextCtrl * mExportText
wxTextCtrl * mImportText

References ExportButtonID, ImportButtonID, mExportText, mFreeSpace, mImportText, mMacrosText, mOpenText, mSaveText, mTempText, FileNames::PreferenceKey(), S, SaveButtonID, wxT(), XO(), and XXO().

Referenced by Commit(), and Populate().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ Validate()

bool DirectoriesPrefs::Validate ( )
override

Definition at line 416 of file DirectoriesPrefs.cpp.

417{
418 wxFileName Temp;
419 Temp.SetPath(mTempText->GetValue());
420
421 wxString path{Temp.GetPath()};
422 if( !IsTempDirectoryNameOK( path ) ) {
424 XO("Directory %s is not suitable (at risk of being cleaned out)")
425 .Format( path ),
426 XO("Error"),
427 wxOK | wxICON_ERROR);
428 return false;
429 }
430
431 if (!Temp.DirExists()) {
432 if(CreateDirectory(path, XO("'Temporary Directory' cannot be set.")) == false)
433 return false;
434 }
435 else {
436 /* If the directory already exists, make sure it is writable */
438 XO("'Temporary files' directory cannot be set.")))
439 {
440 return false;
441 }
442 wxLogNull logNo;
443 Temp.AppendDir(wxT("canicreate"));
444 path = Temp.GetPath();
445 if (!Temp.Mkdir(0755)) {
447 XO("Directory %s is not writable")
448 .Format( path ),
449 XO("Error"),
450 wxOK | wxICON_ERROR);
451 return false;
452 }
453 Temp.Rmdir();
454 Temp.RemoveLastDir();
455 }
456
457 wxFileName oldDir;
458 oldDir.SetPath(TempDir());
459 if (Temp != oldDir) {
461 XO(
462"Changes to temporary directory will not take effect until Audacity is restarted"),
463 XO("Temp Directory Update"),
464 wxOK | wxCENTRE | wxICON_INFORMATION);
465 }
466
467 const wxString openPathString = mOpenText->GetValue();
468 const wxString savePathString = mSaveText->GetValue();
469 const wxString importPathString = mImportText->GetValue();
470 const wxString exportPathString = mExportText->GetValue();
471 const wxString macroPathString = mMacrosText->GetValue();
472 //error messages if the directories could not be set.
473 const std::initializer_list<TranslatableString> messagesPreference{
474 XO("'Open' directory cannot be set.") ,
475 XO("'Save' directory cannot be set.") ,
476 XO("'Import' directory cannot be set.") ,
477 XO("'Export' directory cannot be set.") ,
478 XO("'Macro Output' directory cannot be set.") ,
479 };
480
481 //flag for checking if at least one directory write protected
482 //will not be 0 if any of the paths are not writable
483 int flag = 0;
484 //id for indexing error messages to the initializer_list.
485 int id = 0;
486 //Checks if the location for Open,Save,Import,Export and Macro Output has write permissions(When OK is clicked)
487 for (auto &string : { openPathString, savePathString, importPathString, exportPathString, macroPathString} ) {
488 const wxFileName currentPath { string };
489 const auto & message = *(messagesPreference.begin() + id);
490 if(!string.empty()){
491 if (currentPath.DirExists()){
492 if(!FileNames::WritableLocationCheck(string, message))
493 flag++;
494 }
495 else {
496 return CreateDirectory(string, message);
497 }
498 }
499 id++;
500 }
501 if (flag != 0)
502 return false;
503
504 return true;
505}
int AudacityMessageBox(const TranslatableString &message, const TranslatableString &caption, long style, wxWindow *parent, int x, int y)
bool CreateDirectory(const wxString pathString, const TranslatableString &message)
int id
static std::once_flag flag
Abstract base class used in importing a file.
FILES_API wxString TempDir()

References AudacityMessageBox(), CreateDirectory(), flag, id, TempDirectory::IsTempDirectoryNameOK(), mExportText, mImportText, mMacrosText, mOpenText, mSaveText, mTempText, TempDirectory::TempDir(), FileNames::WritableLocationCheck(), wxT(), and XO().

Here is the call graph for this function:

Member Data Documentation

◆ mExportText

wxTextCtrl* DirectoriesPrefs::mExportText
private

Definition at line 51 of file DirectoriesPrefs.h.

Referenced by PopulateOrExchange(), and Validate().

◆ mFreeSpace

ReadOnlyText* DirectoriesPrefs::mFreeSpace
private

Definition at line 46 of file DirectoriesPrefs.h.

Referenced by OnTempText(), and PopulateOrExchange().

◆ mImportText

wxTextCtrl* DirectoriesPrefs::mImportText
private

Definition at line 50 of file DirectoriesPrefs.h.

Referenced by PopulateOrExchange(), and Validate().

◆ mMacrosText

wxTextCtrl* DirectoriesPrefs::mMacrosText
private

Definition at line 52 of file DirectoriesPrefs.h.

Referenced by PopulateOrExchange(), and Validate().

◆ mOpenText

wxTextCtrl* DirectoriesPrefs::mOpenText
private

Definition at line 48 of file DirectoriesPrefs.h.

Referenced by PopulateOrExchange(), and Validate().

◆ mSaveText

wxTextCtrl* DirectoriesPrefs::mSaveText
private

Definition at line 49 of file DirectoriesPrefs.h.

Referenced by PopulateOrExchange(), and Validate().

◆ mTempText

wxTextCtrl* DirectoriesPrefs::mTempText
private

Definition at line 47 of file DirectoriesPrefs.h.

Referenced by OnTempBrowse(), OnTempText(), PopulateOrExchange(), and Validate().


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