Audacity 3.2.0
AudacityFileConfig.cpp
Go to the documentation of this file.
1/**********************************************************************
2
3Audacity: A Digital Audio Editor
4
5AudacityFileConfig.cpp
6
7Paul Licameli split from Prefs.cpp
8
9**********************************************************************/
10
11
12#include "AudacityFileConfig.h"
13
14#include "HelpSystem.h"
15#include "wxPanelWrapper.h"
16#include "ShuttleGui.h"
17#include "../images/Help.xpm"
18
19#include <wx/app.h>
20#include <wx/bmpbuttn.h>
21#include <wx/sizer.h>
22
24 const wxString& appName,
25 const wxString& vendorName,
26 const wxString& localFilename,
27 const wxString& globalFilename,
28 long style,
29 const wxMBConv& conv
30)
31: FileConfig{ appName, vendorName, localFilename, globalFilename, style, conv }
32{}
33
35
36std::unique_ptr<AudacityFileConfig> AudacityFileConfig::Create(
37 const wxString& appName,
38 const wxString& vendorName,
39 const wxString& localFilename,
40 const wxString& globalFilename,
41 long style,
42 const wxMBConv& conv
43)
44{
45 // Private ctor means make_unique can't compile, so this verbosity:
46 auto result = std::unique_ptr<AudacityFileConfig>{
48 appName, vendorName, localFilename, globalFilename, style, conv } };
49 result->Init();
50 return result;
51}
52
54{
55 wxDialogWrapper dlg(nullptr, wxID_ANY, XO("Audacity Configuration Error"));
56
58
59 wxButton *retryButton;
60 wxButton *quitButton;
61
62 S.SetBorder(5);
63 S.StartVerticalLay(wxEXPAND, 1);
64 {
65 S.SetBorder(15);
66 S.StartHorizontalLay(wxALIGN_RIGHT, 0);
67 {
68 S.AddFixedText(
69 XO("The following configuration file could not be accessed:\n\n"
70 "\t%s\n\n"
71 "This could be caused by many reasons, but the most likely are that "
72 "the disk is full or you do not have write permissions to the file. "
73 "More information can be obtained by clicking the help button below.\n\n"
74 "You can attempt to correct the issue and then click \"Retry\" to continue.\n\n"
75 "If you choose to \"Quit Audacity\", your project may be left in an unsaved "
76 "state which will be recovered the next time you open it.")
78 false,
79 500);
80 }
81 S.EndHorizontalLay();
82
83 S.SetBorder(5);
84 S.StartHorizontalLay(wxALIGN_RIGHT, 0);
85 {
86 // Can't use themed bitmap since the theme manager might not be
87 // initialized yet and it requires a configuration file.
88 wxButton *b = S.Id(wxID_HELP).AddBitmapButton(wxBitmap(Help_xpm));
89 b->SetToolTip( XO("Help").Translation() );
90 b->SetLabel(XO("Help").Translation()); // for screen readers
91
92 b = S.Id(wxID_CANCEL).AddButton(XXO("&Quit Audacity"));
93 b = S.Id(wxID_OK).AddButton(XXO("&Retry"));
94 dlg.SetAffirmativeId(wxID_OK);
95
96 b->SetDefault();
97 b->SetFocus();
98 }
99 S.EndHorizontalLay();
100 }
101 S.EndVerticalLay();
102
103 dlg.Layout();
104 dlg.GetSizer()->Fit(&dlg);
105 dlg.SetMinSize(dlg.GetSize());
106 dlg.Center();
107
108 auto onButton = [&](wxCommandEvent &e)
109 {
110 dlg.EndModal(e.GetId());
111 };
112
113 dlg.Bind(wxEVT_BUTTON, onButton);
114
115 switch (dlg.ShowModal())
116 {
117 case wxID_HELP:
118 // Can't use the HelpSystem since the theme manager may not
119 // yet be initialized and it requires a configuration file.
120 OpenInDefaultBrowser("https://" +
123 "Error:_Audacity_settings_file_unwritable");
124 break;
125
126 case wxID_CANCEL:
127 _exit(-1);
128 break;
129 }
130
131 dlg.Unbind(wxEVT_BUTTON, onButton);
132}
XO("Cut/Copy/Paste")
XXO("&Cut/Copy/Paste Toolbar")
#define safenew
Definition: MemoryX.h:10
@ eIsCreating
Definition: ShuttleGui.h:37
#define S(N)
Definition: ToChars.cpp:64
Our own specialisation of FileConfig.
static std::unique_ptr< AudacityFileConfig > Create(const wxString &appName={}, const wxString &vendorName={}, const wxString &localFilename={}, const wxString &globalFilename={}, long style=wxCONFIG_USE_LOCAL_FILE|wxCONFIG_USE_GLOBAL_FILE, const wxMBConv &conv=wxConvAuto())
Require a call to this factory, to guarantee proper two-phase initialization.
AudacityFileConfig(const wxString &appName, const wxString &vendorName, const wxString &localFilename, const wxString &globalFilename, long style, const wxMBConv &conv)
Disallow direct constructor call, because a two-phase initialization is required.
~AudacityFileConfig() override
const FilePath & GetFilePath() const
Definition: FileConfig.h:81
void Init()
Definition: FileConfig.cpp:45
Abstract base class used in importing a file.
static const wxString HelpHostname
Definition: HelpSystem.h:96
static const wxString HelpServerHomeDir
Definition: HelpSystem.h:101
Derived from ShuttleGuiBase, an Audacity specific class for shuttling data to and from GUI.
Definition: ShuttleGui.h:625
bool OpenInDefaultBrowser(const wxString &url)
Open an URL in default browser.
Definition: BasicUI.cpp:240