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 
29 #include "AllThemeResources.h"
30 #include "Theme.h"
31 #include "HelpText.h"
32 #include "Prefs.h"
33 #include "ShuttleGui.h"
34 #include "HelpSystem.h"
35 
36 #include "SentryReport.h"
37 #include "CodeConversions.h"
38 
39 constexpr int MaxUserCommentLength = 2000;
40 
41 BEGIN_EVENT_TABLE(ErrorReportDialog, wxDialogWrapper)
46 
48  wxWindow* parent, const TranslatableString& dlogTitle,
49  const TranslatableString& message, const wxString& helpUrl,
50  const wxString& log, const bool modal)
52  parent, wxID_ANY, dlogTitle, wxDefaultPosition, wxDefaultSize,
53  wxDEFAULT_DIALOG_STYLE)
54  , mHelpUrl(helpUrl)
55  , mIsModal(modal)
56 {
58  audacity::ToUTF8(dlogTitle.Debug()),message.Debug());
59 
60  if (!log.empty())
61  ex.AddData("log", log);
62 
63  mReport = std::make_unique<audacity::sentry::Report> (ex);
64 
65  ShuttleGui S(this, eIsCreating);
66 
67  const wxFont headingFont = wxFont(wxFontInfo(12).Bold());
68  const wxFont textFont = wxFont(wxFontInfo(10));
69 
70  S.SetBorder(0);
71 
72  S.StartHorizontalLay(wxEXPAND, 0);
73  {
74  S.AddSpace(40, 0);
75  S.StartVerticalLay(wxEXPAND, 0);
76  {
77  S.AddSpace(0, 32);
78 
79  S.StartHorizontalLay(wxEXPAND, 1);
80  {
81  S.StartVerticalLay(0);
82  {
83  wxBitmap bitmap = wxArtProvider::GetBitmap(
84  wxART_WARNING, wxART_MESSAGE_BOX, wxSize(24, 24));
85 
86  S.Prop(0).AddWindow(
87  safenew wxStaticBitmap(S.GetParent(), -1, bitmap));
88 
89  S.AddSpace(0, 0, 1);
90  }
91  S.EndVerticalLay();
92 
93  S.AddSpace(10, 0);
94 
95  S.StartVerticalLay(0);
96  {
97  S.AddSpace(0, 7);
98 
99  S.Prop(1)
100  .AddVariableText(message, false, 0, 560)
101  ->SetFont(headingFont);
102  }
103  S.EndVerticalLay();
104  }
105  S.EndHorizontalLay();
106 
107  S.AddSpace(0, 20);
108 
110  "Click \"Send\" to submit the report to Audacity. This information is collected anonymously."))
111  ->SetFont(textFont);
112 
113  S.AddSpace(0, 20);
114 
115  S.AddVariableText(XO("Problem details"))->SetFont(textFont);
116 
117  S.AddSpace(0, 6);
118 
119  S.Style(wxTE_RICH | wxTE_READONLY | wxTE_MULTILINE | wxTE_DONTWRAP)
120  .MinSize(wxSize(0, 152))
121  .Name(XO("Problem details"))
122  .AddTextBox({}, mReport->GetReportPreview(), 0);
123 
124  S.AddSpace(0, 20);
125 
126  S.AddVariableText(XO("Comments"))->SetFont(textFont);
127 
128  S.AddSpace(0, 6);
129 
130  mCommentsControl = S.Style(wxTE_MULTILINE)
131  .MinSize(wxSize(0, 76))
132  .Name(XO("Comments"))
133  .AddTextBox({}, {}, 0);
134 
135  mCommentsControl->SetMaxLength(MaxUserCommentLength);
136 
137  S.AddSpace(0, 20);
138 
139  S.StartHorizontalLay(wxEXPAND);
140  {
141  if (!mHelpUrl.empty())
142  {
143  wxBitmapButton* helpButton =
144  S.Id(wxID_HELP).AddBitmapButton(theTheme.Bitmap(bmpHelpIcon));
145  // For screen readers
146  helpButton->SetToolTip(XO("Help").Translation());
147  helpButton->SetLabel(XO("Help").Translation());
148  }
149 
150  S.AddSpace(0, 0, 1);
151 
152  S.Id(wxID_NO).AddButton(XC("&Don't send", "crash reporter button"));
153 
154  S.AddSpace(13, 0);
155 
156  S.Id(wxID_YES).AddButton(XC("&Send", "crash reporter button"));
157  }
158  S.EndHorizontalLay();
159 
160  S.AddSpace(0, 20);
161  }
162  S.EndVerticalLay();
163 
164  S.AddSpace(28, 0);
165  }
166  S.EndHorizontalLay();
167 
168  S.SetBorder(2);
169 
170  Layout();
171  GetSizer()->Fit(this);
172  SetMinSize(GetSize());
173  Center();
174 }
175 
177 {
178 }
179 
180 void ErrorReportDialog::OnSend(wxCommandEvent& event)
181 {
182  Disable();
183 
184  mReport->AddUserComment(audacity::ToUTF8(mCommentsControl->GetValue()));
185 
186  mReport->Send(
187  [this](int code, std::string body) {
188  CallAfter([this]() {
189  EndModal(true);
190  });
191  });
192 }
193 
194 void ErrorReportDialog::OnDontSend(wxCommandEvent& event)
195 {
196  EndModal(true);
197 }
198 
199 void ErrorReportDialog::OnHelp(wxCommandEvent& event)
200 {
201  if (mHelpUrl.StartsWith(wxT("innerlink:")))
202  {
204  this, TitleText(mHelpUrl.Mid(10)), HelpText(mHelpUrl.Mid(10)), false,
205  true);
206  return;
207  }
208 
209  HelpSystem::ShowHelp(this, mHelpUrl, false);
210 }
211 
213  wxWindow* parent, const TranslatableString& dlogTitle,
214  const TranslatableString& message, const wxString& helpPage,
215  const wxString& log)
216 {
217  ErrorReportDialog dlog(parent, dlogTitle, message, helpPage, log);
218 
219  dlog.CentreOnParent();
220  dlog.ShowModal();
221 }
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:37
ShowErrorReportDialog
void ShowErrorReportDialog(wxWindow *parent, const TranslatableString &dlogTitle, const TranslatableString &message, const wxString &helpPage, const wxString &log)
Displays an error dialog that allows to send the error report.
Definition: ErrorReportDialog.cpp:212
SentryReport.h
Declare a class to report errors to Sentry.
ShuttleGuiBase::StartVerticalLay
void StartVerticalLay(int iProp=1)
Definition: ShuttleGui.cpp:1177
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:2421
ErrorReportDialog::mHelpUrl
wxString mHelpUrl
Definition: ErrorReportDialog.h:53
ShuttleGui::MinSize
ShuttleGui & MinSize()
Definition: ShuttleGui.h:727
XO
#define XO(s)
Definition: Internat.h:31
XC
#define XC(s, c)
Definition: Internat.h:37
ErrorReportDialog::mCommentsControl
wxTextCtrl * mCommentsControl
Definition: ErrorReportDialog.h:55
ErrorReportDialog::OnSend
void OnSend(wxCommandEvent &event)
Definition: ErrorReportDialog.cpp:180
ShuttleGui::Id
ShuttleGui & Id(int id)
Definition: ShuttleGui.cpp:2248
ErrorReportDialog.h
ThemeBase::Bitmap
wxBitmap & Bitmap(int iIndex)
Definition: Theme.cpp:1212
ShuttleGui::Style
ShuttleGui & Style(long iStyle)
Definition: ShuttleGui.h:721
HelpText.h
HelpSystem::ShowHtmlText
static void ShowHtmlText(wxWindow *pParent, const TranslatableString &Title, const wxString &HtmlText, bool bIsFile=false, bool bModal=false)
Definition: HelpSystem.cpp:126
ShuttleGuiBase::EndHorizontalLay
void EndHorizontalLay()
Definition: ShuttleGui.cpp:1170
ShuttleGuiBase::StartHorizontalLay
void StartHorizontalLay(int PositionFlags=wxALIGN_CENTRE, int iProp=1)
Definition: ShuttleGui.cpp:1160
ShuttleGuiBase::AddTextBox
wxTextCtrl * AddTextBox(const TranslatableString &Caption, const wxString &Value, const int nChars)
Definition: ShuttleGui.cpp:631
ShuttleGuiBase::EndVerticalLay
void EndVerticalLay()
Definition: ShuttleGui.cpp:1196
ErrorReportDialog::mReport
std::unique_ptr< audacity::sentry::Report > mReport
Definition: ErrorReportDialog.h:51
Theme.h
ShuttleGuiBase::GetParent
wxWindow * GetParent()
Definition: ShuttleGui.h:490
ShuttleGui.h
ShuttleGui::Prop
ShuttleGui & Prop(int iProp)
Definition: ShuttleGui.h:719
ShuttleGuiBase::AddButton
wxButton * AddButton(const TranslatableString &Text, int PositionFlags=wxALIGN_CENTRE, bool setDefault=false)
Definition: ShuttleGui.cpp:353
ShuttleGui::Name
ShuttleGui & Name(const TranslatableString &name)
Definition: ShuttleGui.h:657
wxDialogWrapper
Definition: wxPanelWrapper.h:81
ShuttleGuiBase::AddWindow
wxWindow * AddWindow(wxWindow *pWindow)
Definition: ShuttleGui.cpp:292
HelpSystem::ShowHelp
static void ShowHelp(wxWindow *parent, const wxString &localFileName, const wxString &remoteURL, bool bModal=false, bool alwaysDefaultBrowser=false)
Definition: HelpSystem.cpp:238
MaxUserCommentLength
constexpr int MaxUserCommentLength
Definition: ErrorReportDialog.cpp:39
ShuttleGuiBase::AddBitmapButton
wxBitmapButton * AddBitmapButton(const wxBitmap &Bitmap, int PositionFlags=wxALIGN_CENTRE, bool setDefault=false)
Definition: ShuttleGui.cpp:372
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:176
theTheme
AUDACITY_DLL_API Theme theTheme
Definition: Theme.cpp:202
Prefs.h
ShuttleGuiBase::SetBorder
void SetBorder(int Border)
Definition: ShuttleGui.h:484
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:456
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:199
ShuttleGui
Derived from ShuttleGuiBase, an Audacity specific class for shuttling data to and from GUI.
Definition: ShuttleGui.h:625
ErrorReportDialog::OnDontSend
void OnDontSend(wxCommandEvent &event)
Definition: ErrorReportDialog.cpp:194