Audacity  3.0.3
ErrorReportDialog.cpp
Go to the documentation of this file.
1 /**********************************************************************
2 
3  Audacity: A Digital Audio Editor
4 
5  ErrorReportDialog.cpp
6 
7  Dmitry Vedenko
8 
9 **********************************************************************/
10 
11 #include "ErrorReportDialog.h"
12 
13 #include <wx/app.h>
14 #include <wx/artprov.h>
15 #include <wx/button.h>
16 #include <wx/collpane.h>
17 #include <wx/dialog.h>
18 #include <wx/html/htmlwin.h>
19 #include <wx/icon.h>
20 #include <wx/intl.h>
21 #include <wx/settings.h>
22 #include <wx/sizer.h>
23 #include <wx/statbmp.h>
24 #include <wx/stattext.h>
25 #include <wx/statusbr.h>
26 #include <wx/textctrl.h>
27 #include <wx/bmpbuttn.h>
28 
30 #include "AllThemeResources.h"
31 #include "Theme.h"
32 #include "HelpText.h"
33 #include "Prefs.h"
34 #include "ShuttleGui.h"
35 #include "HelpSystem.h"
36 
37 #include "SentryReport.h"
38 #include "CodeConversions.h"
39 
40 constexpr int MaxUserCommentLength = 2000;
41 constexpr bool ErrorReportDialogHasUserComment = false;
42 
43 BEGIN_EVENT_TABLE(ErrorReportDialog, wxDialogWrapper)
48 
50  wxWindow* parent, const TranslatableString& dlogTitle,
51  const TranslatableString& message, const ManualPageID& helpUrl,
52  const wxString& log, const bool modal)
54  parent, wxID_ANY, dlogTitle, wxDefaultPosition, wxDefaultSize,
55  wxDEFAULT_DIALOG_STYLE)
56  , mHelpUrl(helpUrl)
57  , mIsModal(modal)
58 {
60  audacity::ToUTF8(dlogTitle.Debug()),message.Debug());
61 
62  if (!log.empty())
63  ex.AddData("log", log);
64 
65  mReport = std::make_unique<audacity::sentry::Report> (ex);
66 
67  ShuttleGui S(this, eIsCreating);
68 
69  const wxFont headingFont = wxFont(wxFontInfo(12).Bold());
70  const wxFont textFont = wxFont(wxFontInfo(10));
71 
72  S.SetBorder(0);
73 
74  S.StartHorizontalLay(wxEXPAND, 0);
75  {
76  S.AddSpace(40, 0);
77  S.StartVerticalLay(wxEXPAND, 0);
78  {
79  S.AddSpace(0, 32);
80 
81  S.StartHorizontalLay(wxEXPAND, 1);
82  {
83  S.StartVerticalLay(0);
84  {
85  wxBitmap bitmap = wxArtProvider::GetBitmap(
86  wxART_WARNING, wxART_MESSAGE_BOX, wxSize(24, 24));
87 
88  S.Prop(0).AddWindow(
89  safenew wxStaticBitmap(S.GetParent(), -1, bitmap));
90 
91  S.AddSpace(0, 0, 1);
92  }
93  S.EndVerticalLay();
94 
95  S.AddSpace(10, 0);
96 
97  S.StartVerticalLay(0);
98  {
99  S.AddSpace(0, 7);
100 
101  S.Prop(1)
102  .AddVariableText(message, false, 0, 560)
103  ->SetFont(headingFont);
104  }
105  S.EndVerticalLay();
106  }
107  S.EndHorizontalLay();
108 
109  S.AddSpace(0, 20);
110 
112  "Click \"Send\" to submit the report to Audacity. This information is collected anonymously."))
113  ->SetFont(textFont);
114 
115  S.AddSpace(0, 20);
116 
117  S.AddVariableText(XO("Problem details"))->SetFont(textFont);
118 
119  S.AddSpace(0, 6);
120 
121  S.Style(wxTE_RICH | wxTE_READONLY | wxTE_MULTILINE | wxTE_DONTWRAP)
122  .MinSize(wxSize(0, 152))
123  .Name(XO("Problem details"))
124  .AddTextBox({}, mReport->GetReportPreview(), 0);
125 
126  S.AddSpace(0, 20);
127 
128  if constexpr (ErrorReportDialogHasUserComment)
129  {
130  S.AddVariableText(XO("Comments"))->SetFont(textFont);
131 
132  S.AddSpace(0, 6);
133 
134  mCommentsControl = S.Style(wxTE_MULTILINE)
135  .MinSize(wxSize(0, 76))
136  .Name(XO("Comments"))
137  .AddTextBox({}, {}, 0);
138 
139  mCommentsControl->SetMaxLength(MaxUserCommentLength);
140 
141  S.AddSpace(0, 20);
142  }
143 
144  /* i18n-hint: %s will be replaced with "our Privacy Policy" */
145  AccessibleLinksFormatter privacyPolicy(XO("See %s for more info."));
146 
147  privacyPolicy.FormatLink(
148  /* i18n-hint: Title of hyperlink to the privacy policy. This is an
149  object of "See". */
150  wxT("%s"), XO("our Privacy Policy"),
151  "https://www.audacityteam.org/about/desktop-privacy-notice/");
152 
153  privacyPolicy.Populate(S);
154 
155  S.AddSpace(0, 20);
156 
157  S.StartHorizontalLay(wxEXPAND);
158  {
159  if (!mHelpUrl.empty())
160  {
161  wxBitmapButton* helpButton =
162  S.Id(wxID_HELP).AddBitmapButton(theTheme.Bitmap(bmpHelpIcon));
163  // For screen readers
164  helpButton->SetToolTip(XO("Help").Translation());
165  helpButton->SetLabel(XO("Help").Translation());
166  }
167 
168  S.AddSpace(0, 0, 1);
169 
170  S.Id(wxID_NO).AddButton(XC("&Don't send", "crash reporter button"));
171 
172  S.AddSpace(13, 0);
173 
174  S.Id(wxID_YES).AddButton(XC("&Send", "crash reporter button"));
175  }
176  S.EndHorizontalLay();
177 
178  S.AddSpace(0, 20);
179  }
180  S.EndVerticalLay();
181 
182  S.AddSpace(28, 0);
183  }
184  S.EndHorizontalLay();
185 
186  S.SetBorder(2);
187 
188  Layout();
189  GetSizer()->Fit(this);
190  SetMinSize(GetSize());
191  Center();
192 }
193 
195 {
196 }
197 
198 void ErrorReportDialog::OnSend(wxCommandEvent& event)
199 {
200  Disable();
201 
202  if (mCommentsControl != nullptr)
203  mReport->AddUserComment(audacity::ToUTF8(mCommentsControl->GetValue()));
204 
205  mReport->Send(
206  [this](int code, std::string body) {
207  CallAfter([this]() {
208  EndModal(true);
209  });
210  });
211 }
212 
213 void ErrorReportDialog::OnDontSend(wxCommandEvent& event)
214 {
215  EndModal(true);
216 }
217 
218 void ErrorReportDialog::OnHelp(wxCommandEvent& event)
219 {
220  const auto &helpUrl = mHelpUrl.GET();
221  if (helpUrl.StartsWith(wxT("innerlink:")))
222  {
224  this, TitleText(helpUrl.Mid(10)), HelpText(helpUrl.Mid(10)), false,
225  true);
226  return;
227  }
228 
229  HelpSystem::ShowHelp(this, mHelpUrl, false);
230 }
EVT_BUTTON
EVT_BUTTON(wxID_NO, DependencyDialog::OnNo) EVT_BUTTON(wxID_YES
TranslatableString
Holds a msgid for the translation catalog; may also bind format arguments.
Definition: TranslatableString.h:32
eIsCreating
@ eIsCreating
Definition: ShuttleGui.h:38
SentryReport.h
Declare a class to report errors to Sentry.
ShuttleGuiBase::StartVerticalLay
void StartVerticalLay(int iProp=1)
Definition: ShuttleGui.cpp:1184
HelpSystem.h
ErrorReportDialog
A dialog, that has "Send", "Don't send" and help buttons.
Definition: ErrorReportDialog.h:36
AllThemeResources.h
ShuttleGui::AddSpace
wxSizerItem * AddSpace(int width, int height, int prop=0)
Definition: ShuttleGui.cpp:2459
ShuttleGui::MinSize
ShuttleGui & MinSize()
Definition: ShuttleGui.h:733
XO
#define XO(s)
Definition: Internat.h:31
XC
#define XC(s, c)
Definition: Internat.h:37
BasicUI::CallAfter
void CallAfter(Action action)
Schedule an action to be done later, and in the main thread.
Definition: BasicUI.cpp:38
ErrorReportDialog::mCommentsControl
wxTextCtrl * mCommentsControl
Definition: ErrorReportDialog.h:55
ErrorReportDialog::OnSend
void OnSend(wxCommandEvent &event)
Definition: ErrorReportDialog.cpp:198
HelpSystem::ShowHelp
static void ShowHelp(wxWindow *parent, const FilePath &localFileName, const URLString &remoteURL, bool bModal=false, bool alwaysDefaultBrowser=false)
Definition: HelpSystem.cpp:237
ShuttleGui::Id
ShuttleGui & Id(int id)
Definition: ShuttleGui.cpp:2274
ErrorReportDialog.h
ThemeBase::Bitmap
wxBitmap & Bitmap(int iIndex)
Definition: Theme.cpp:1216
ErrorReportDialog::mHelpUrl
ManualPageID mHelpUrl
Definition: ErrorReportDialog.h:53
ShuttleGui::Style
ShuttleGui & Style(long iStyle)
Definition: ShuttleGui.h:727
HelpText.h
HelpSystem::ShowHtmlText
static void ShowHtmlText(wxWindow *pParent, const TranslatableString &Title, const wxString &HtmlText, bool bIsFile=false, bool bModal=false)
Definition: HelpSystem.cpp:125
ShuttleGuiBase::EndHorizontalLay
void EndHorizontalLay()
Definition: ShuttleGui.cpp:1177
ShuttleGuiBase::StartHorizontalLay
void StartHorizontalLay(int PositionFlags=wxALIGN_CENTRE, int iProp=1)
Definition: ShuttleGui.cpp:1167
ShuttleGuiBase::AddTextBox
wxTextCtrl * AddTextBox(const TranslatableString &Caption, const wxString &Value, const int nChars)
Definition: ShuttleGui.cpp:638
ShuttleGuiBase::EndVerticalLay
void EndVerticalLay()
Definition: ShuttleGui.cpp:1203
ErrorReportDialog::mReport
std::unique_ptr< audacity::sentry::Report > mReport
Definition: ErrorReportDialog.h:51
Theme.h
ShuttleGuiBase::GetParent
wxWindow * GetParent()
Definition: ShuttleGui.h:496
ShuttleGuiBase::AddWindow
wxWindow * AddWindow(wxWindow *pWindow, int PositionFlags=wxALIGN_CENTRE)
Definition: ShuttleGui.cpp:299
ShuttleGui.h
ShuttleGui::Prop
ShuttleGui & Prop(int iProp)
Definition: ShuttleGui.h:725
ShuttleGuiBase::AddButton
wxButton * AddButton(const TranslatableString &Text, int PositionFlags=wxALIGN_CENTRE, bool setDefault=false)
Definition: ShuttleGui.cpp:360
Identifier::GET
const wxString & GET() const
Explicit conversion to wxString, meant to be ugly-looking and demanding of a comment why it's correct...
Definition: Identifier.h:66
ShuttleGui::Name
ShuttleGui & Name(const TranslatableString &name)
Definition: ShuttleGui.h:663
wxDialogWrapper
Definition: wxPanelWrapper.h:81
TaggedIdentifier< ManualPageIDTag >
MaxUserCommentLength
constexpr int MaxUserCommentLength
Definition: ErrorReportDialog.cpp:40
ShuttleGuiBase::AddBitmapButton
wxBitmapButton * AddBitmapButton(const wxBitmap &Bitmap, int PositionFlags=wxALIGN_CENTRE, bool setDefault=false)
Definition: ShuttleGui.cpp:379
audacity::sentry::Exception::Create
static Exception Create(std::string type, AnonymizedMessage value)
Create a new exception.
Definition: SentryReport.cpp:224
ErrorReportDialog::~ErrorReportDialog
~ErrorReportDialog()
Definition: ErrorReportDialog.cpp:194
theTheme
AUDACITY_DLL_API Theme theTheme
Definition: Theme.cpp:203
Prefs.h
ShuttleGuiBase::SetBorder
void SetBorder(int Border)
Definition: ShuttleGui.h:489
audacity::sentry::Exception
A DTO for the Sentry Exception interface.
Definition: SentryReport.h:31
CodeConversions.h
Declare functions to preform UTF-8 to std::wstring conversions.
ShuttleGuiBase::AddVariableText
wxStaticText * AddVariableText(const TranslatableString &Str, bool bCenter=false, int PositionFlags=0, int wrapWidth=0)
Definition: ShuttleGui.cpp:463
HelpText
AUDACITY_DLL_API wxString HelpText(const wxString &Key)
safenew
#define safenew
Definition: MemoryX.h:10
audacity::ToUTF8
std::string ToUTF8(const std::wstring &wstr)
Definition: CodeConversions.cpp:19
TitleText
AUDACITY_DLL_API TranslatableString TitleText(const wxString &Key)
END_EVENT_TABLE
END_EVENT_TABLE()
audacity::sentry::Exception::AddData
Exception & AddData(std::string key, AnonymizedMessage value)
Add a payload to the exception.
Definition: SentryReport.cpp:238
ErrorReportDialog::OnHelp
void OnHelp(wxCommandEvent &event)
Definition: ErrorReportDialog.cpp:218
ErrorReportDialogHasUserComment
constexpr bool ErrorReportDialogHasUserComment
Definition: ErrorReportDialog.cpp:41
ShuttleGui
Derived from ShuttleGuiBase, an Audacity specific class for shuttling data to and from GUI.
Definition: ShuttleGui.h:631
ErrorReportDialog::OnDontSend
void OnDontSend(wxCommandEvent &event)
Definition: ErrorReportDialog.cpp:213