Audacity  3.0.3
AudacityFileConfig.cpp
Go to the documentation of this file.
1 /**********************************************************************
2 
3 Audacity: A Digital Audio Editor
4 
5 AudacityFileConfig.cpp
6 
7 Paul Licameli split from Prefs.cpp
8 
9 **********************************************************************/
10 
11 
12 #include "AudacityFileConfig.h"
13 
14 #include "widgets/HelpSystem.h"
15 #include "widgets/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 
36 std::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 
57  ShuttleGui S(&dlg, eIsCreating);
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.")
77  .Format(GetFilePath()),
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 }
HelpSystem::HelpHostname
static const wxString HelpHostname
Definition: HelpSystem.h:96
eIsCreating
@ eIsCreating
Definition: ShuttleGui.h:38
ShuttleGuiBase::StartVerticalLay
void StartVerticalLay(int iProp=1)
Definition: ShuttleGui.cpp:1184
HelpSystem.h
AudacityFileConfig::AudacityFileConfig
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.
Definition: AudacityFileConfig.cpp:23
FileConfig::GetFilePath
const FilePath & GetFilePath() const
Definition: FileConfig.h:81
Format
Abstract base class used in importing a file.
XO
#define XO(s)
Definition: Internat.h:31
wxPanelWrapper.h
AudacityFileConfig::~AudacityFileConfig
~AudacityFileConfig() override
ShuttleGui::Id
ShuttleGui & Id(int id)
Definition: ShuttleGui.cpp:2274
HelpSystem::HelpServerHomeDir
static const wxString HelpServerHomeDir
Definition: HelpSystem.h:101
AudacityFileConfig
Our own specialisation of FileConfig.
Definition: AudacityFileConfig.h:20
XXO
#define XXO(s)
Definition: Internat.h:44
ShuttleGuiBase::EndHorizontalLay
void EndHorizontalLay()
Definition: ShuttleGui.cpp:1177
ShuttleGuiBase::StartHorizontalLay
void StartHorizontalLay(int PositionFlags=wxALIGN_CENTRE, int iProp=1)
Definition: ShuttleGui.cpp:1167
ShuttleGuiBase::EndVerticalLay
void EndVerticalLay()
Definition: ShuttleGui.cpp:1203
ShuttleGuiBase::AddFixedText
void AddFixedText(const TranslatableString &Str, bool bCenter=false, int wrapWidth=0)
Definition: ShuttleGui.cpp:440
AudacityFileConfig::Create
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.
Definition: AudacityFileConfig.cpp:36
FileConfig::Init
void Init()
Definition: FileConfig.cpp:45
AudacityFileConfig.h
ShuttleGui.h
ShuttleGuiBase::AddButton
wxButton * AddButton(const TranslatableString &Text, int PositionFlags=wxALIGN_CENTRE, bool setDefault=false)
Definition: ShuttleGui.cpp:360
FileConfig
Definition: FileConfig.h:22
OpenInDefaultBrowser
void OpenInDefaultBrowser(const URLString &link)
Definition: HelpSystem.cpp:522
wxDialogWrapper
Definition: wxPanelWrapper.h:81
ShuttleGuiBase::AddBitmapButton
wxBitmapButton * AddBitmapButton(const wxBitmap &Bitmap, int PositionFlags=wxALIGN_CENTRE, bool setDefault=false)
Definition: ShuttleGui.cpp:379
AudacityFileConfig::Warn
void Warn() override
Override to notify the user of error conditions involving writability of config files.
Definition: AudacityFileConfig.cpp:53
ShuttleGuiBase::SetBorder
void SetBorder(int Border)
Definition: ShuttleGui.h:489
safenew
#define safenew
Definition: MemoryX.h:10
ShuttleGui
Derived from ShuttleGuiBase, an Audacity specific class for shuttling data to and from GUI.
Definition: ShuttleGui.h:631