forked from Sneeds-Feed-and-Seed/sneedacity
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSneedacityFileConfig.cpp
132 lines (108 loc) · 3.83 KB
/
SneedacityFileConfig.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
/**********************************************************************
Sneedacity: A Digital Audio Editor
SneedacityFileConfig.cpp
Paul Licameli split from Prefs.cpp
**********************************************************************/
#include "SneedacityFileConfig.h"
#include "widgets/HelpSystem.h"
#include "widgets/wxPanelWrapper.h"
#include "ShuttleGui.h"
#include "../images/Help.xpm"
#include <wx/app.h>
#include <wx/bmpbuttn.h>
#include <wx/sizer.h>
SneedacityFileConfig::SneedacityFileConfig(
const wxString& appName,
const wxString& vendorName,
const wxString& localFilename,
const wxString& globalFilename,
long style,
const wxMBConv& conv
)
: FileConfig{ appName, vendorName, localFilename, globalFilename, style, conv }
{}
SneedacityFileConfig::~SneedacityFileConfig() = default;
std::unique_ptr<SneedacityFileConfig> SneedacityFileConfig::Create(
const wxString& appName,
const wxString& vendorName,
const wxString& localFilename,
const wxString& globalFilename,
long style,
const wxMBConv& conv
)
{
// Private ctor means make_unique can't compile, so this verbosity:
auto result = std::unique_ptr<SneedacityFileConfig>{
safenew SneedacityFileConfig{
appName, vendorName, localFilename, globalFilename, style, conv } };
result->Init();
return result;
}
void SneedacityFileConfig::Warn()
{
wxDialogWrapper dlg(nullptr, wxID_ANY, XO("Sneedacity Configuration Error"));
ShuttleGui S(&dlg, eIsCreating);
wxButton *retryButton;
wxButton *quitButton;
S.SetBorder(5);
S.StartVerticalLay(wxEXPAND, 1);
{
S.SetBorder(15);
S.StartHorizontalLay(wxALIGN_RIGHT, 0);
{
S.AddFixedText(
XO("The following configuration file could not be accessed:\n\n"
"\t%s\n\n"
"This could be caused by many reasons, but the most likely are that "
"the disk is full or you do not have write permissions to the file. "
"More information can be obtained by clicking the help button below.\n\n"
"You can attempt to correct the issue and then click \"Retry\" to continue.\n\n"
"If you choose to \"Quit Sneedacity\", your project may be left in an unsaved "
"state which will be recovered the next time you open it.")
.Format(GetFilePath()),
false,
500);
}
S.EndHorizontalLay();
S.SetBorder(5);
S.StartHorizontalLay(wxALIGN_RIGHT, 0);
{
// Can't use themed bitmap since the theme manager might not be
// initialized yet and it requires a configuration file.
wxButton *b = S.Id(wxID_HELP).AddBitmapButton(wxBitmap(Help_xpm));
b->SetToolTip( XO("Help").Translation() );
b->SetLabel(XO("Help").Translation()); // for screen readers
b = S.Id(wxID_CANCEL).AddButton(XXO("&Quit Sneedacity"));
b = S.Id(wxID_OK).AddButton(XXO("&Retry"));
dlg.SetAffirmativeId(wxID_OK);
b->SetDefault();
b->SetFocus();
}
S.EndHorizontalLay();
}
S.EndVerticalLay();
dlg.Layout();
dlg.GetSizer()->Fit(&dlg);
dlg.SetMinSize(dlg.GetSize());
dlg.Center();
auto onButton = [&](wxCommandEvent &e)
{
dlg.EndModal(e.GetId());
};
dlg.Bind(wxEVT_BUTTON, onButton);
switch (dlg.ShowModal())
{
case wxID_HELP:
// Can't use the HelpSystem since the theme manager may not
// yet be initialized and it requires a configuration file.
OpenInDefaultBrowser("https://" +
HelpSystem::HelpHostname +
HelpSystem::HelpServerHomeDir +
"Error:_Sneedacity_settings_file_unwritable");
break;
case wxID_CANCEL:
_exit(-1);
break;
}
dlg.Unbind(wxEVT_BUTTON, onButton);
}