Missed update to private test repo version.
[dcpomatic.git] / src / wx / report_problem_dialog.cc
1 /*
2     Copyright (C) 2014-2021 Carl Hetherington <cth@carlh.net>
3
4     This file is part of DCP-o-matic.
5
6     DCP-o-matic is free software; you can redistribute it and/or modify
7     it under the terms of the GNU General Public License as published by
8     the Free Software Foundation; either version 2 of the License, or
9     (at your option) any later version.
10
11     DCP-o-matic is distributed in the hope that it will be useful,
12     but WITHOUT ANY WARRANTY; without even the implied warranty of
13     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14     GNU General Public License for more details.
15
16     You should have received a copy of the GNU General Public License
17     along with DCP-o-matic.  If not, see <http://www.gnu.org/licenses/>.
18
19 */
20
21
22 #include "check_box.h"
23 #include "report_problem_dialog.h"
24 #include "static_text.h"
25 #include "wx_util.h"
26 #include "lib/config.h"
27 #include "lib/job_manager.h"
28 #include "lib/send_problem_report_job.h"
29 #include <dcp/warnings.h>
30 LIBDCP_DISABLE_WARNINGS
31 #include <wx/sizer.h>
32 LIBDCP_ENABLE_WARNINGS
33
34
35 using std::make_shared;
36 using std::string;
37 using std::shared_ptr;
38
39
40 /** @param parent Parent window.
41  *  @param film Film that we are working on, or 0.
42  */
43 ReportProblemDialog::ReportProblemDialog (wxWindow* parent, shared_ptr<Film> film)
44         : wxDialog (parent, wxID_ANY, _("Report A Problem"))
45         , _film (film)
46 {
47         _overall_sizer = new wxBoxSizer (wxVERTICAL);
48         SetSizer (_overall_sizer);
49
50         _table = new wxFlexGridSizer (2, DCPOMATIC_SIZER_X_GAP, DCPOMATIC_SIZER_Y_GAP);
51         _table->AddGrowableCol (1, 1);
52
53         _overall_sizer->Add (_table, 1, wxEXPAND | wxALL, DCPOMATIC_DIALOG_BORDER);
54
55         auto buttons = CreateSeparatedButtonSizer (wxOK | wxCANCEL);
56         if (buttons) {
57                 _overall_sizer->Add (buttons, wxSizerFlags().Expand().DoubleBorder());
58         }
59
60         auto t = _("My problem is");
61         int flags = wxALIGN_TOP | wxLEFT | wxRIGHT;
62 #ifdef __WXOSX__
63         flags |= wxALIGN_RIGHT;
64         t += wxT (":");
65 #endif
66         auto m = new StaticText (this, t);
67         _table->Add (m, 1, flags, 6);
68
69         _summary = new wxTextCtrl (this, wxID_ANY, wxT(""), wxDefaultPosition, wxSize(320, 240), wxTE_MULTILINE);
70         _table->Add (_summary, 1, wxEXPAND | wxALIGN_TOP);
71
72         _send_logs = new CheckBox (this, _("Send logs"));
73         _send_logs->SetValue (true);
74         _table->Add (_send_logs, 1, wxEXPAND);
75         _table->AddSpacer (0);
76
77         add_label_to_sizer (_table, this, _("Your email address"), true, 0, wxALIGN_CENTRE_VERTICAL);
78         _email = new wxTextCtrl (this, wxID_ANY, wxT (""));
79         _email->SetValue (std_to_wx (Config::instance()->kdm_from ()));
80         _table->Add (_email, 1, wxEXPAND);
81
82         /* We can't use Wrap() here as it doesn't work with markup:
83          * http://trac.wxwidgets.org/ticket/13389
84          */
85
86         wxString in = _("<i>It is important that you enter a valid email address here, otherwise I can't ask you for more details on your problem.</i>");
87         wxString out;
88         int const width = 45;
89         int current = 0;
90         for (size_t i = 0; i < in.Length(); ++i) {
91                 if (in[i] == ' ' && current >= width) {
92                         out += '\n';
93                         current = 0;
94                 } else {
95                         out += in[i];
96                         ++current;
97                 }
98         }
99
100         auto n = new StaticText (this, wxT(""));
101         n->SetLabelMarkup (out);
102         _table->AddSpacer (0);
103         _table->Add (n, 1, wxEXPAND);
104
105         _overall_sizer->Layout ();
106         _overall_sizer->SetSizeHints (this);
107
108         _summary->SetFocus ();
109 }
110
111
112 void
113 ReportProblemDialog::report ()
114 {
115         if (_email->GetValue().IsEmpty()) {
116                 error_dialog (this, _("Please enter an email address so that we can contact you with any queries about the problem."));
117                 return;
118         }
119
120         if (_email->GetValue() == "carl@dcpomatic.com" || _email->GetValue() == "cth@carlh.net") {
121                 error_dialog (this, wxString::Format(_("Enter your email address for the contact, not %s"), _email->GetValue().data()));
122                 return;
123         }
124
125         JobManager::instance()->add (make_shared<SendProblemReportJob>(_film, wx_to_std(_email->GetValue()), wx_to_std(_summary->GetValue())));
126 }
127