Basics of in-place i18n with support for wxStaticText and wxCheckBox.
[dcpomatic.git] / src / wx / report_problem_dialog.cc
1 /*
2     Copyright (C) 2014-2018 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 #include "report_problem_dialog.h"
22 #include "wx_util.h"
23 #include "static_text.h"
24 #include "check_box.h"
25 #include "lib/config.h"
26 #include "lib/job_manager.h"
27 #include "lib/send_problem_report_job.h"
28 #include <wx/sizer.h>
29
30 using std::string;
31 using boost::shared_ptr;
32
33 /** @param parent Parent window.
34  *  @param film Film that we are working on, or 0.
35  */
36 ReportProblemDialog::ReportProblemDialog (wxWindow* parent, shared_ptr<Film> film)
37         : wxDialog (parent, wxID_ANY, _("Report A Problem"))
38         , _film (film)
39 {
40         _overall_sizer = new wxBoxSizer (wxVERTICAL);
41         SetSizer (_overall_sizer);
42
43         _table = new wxFlexGridSizer (2, DCPOMATIC_SIZER_X_GAP, DCPOMATIC_SIZER_Y_GAP);
44         _table->AddGrowableCol (1, 1);
45
46         _overall_sizer->Add (_table, 1, wxEXPAND | wxALL, DCPOMATIC_DIALOG_BORDER);
47
48         wxSizer* buttons = CreateSeparatedButtonSizer (wxOK | wxCANCEL);
49         if (buttons) {
50                 _overall_sizer->Add (buttons, wxSizerFlags().Expand().DoubleBorder());
51         }
52
53         wxString t = _("My problem is");
54         int flags = wxALIGN_TOP | wxLEFT | wxRIGHT;
55 #ifdef __WXOSX__
56         flags |= wxALIGN_RIGHT;
57         t += wxT (":");
58 #endif
59         wxStaticText* m = new StaticText (this, t);
60         _table->Add (m, 1, flags, 6);
61
62         _summary = new wxTextCtrl (this, wxID_ANY, wxT (""), wxDefaultPosition, wxSize (320, 240), wxTE_MULTILINE);
63         _table->Add (_summary, 1, wxEXPAND | wxALIGN_TOP);
64
65         _send_logs = new CheckBox (this, _("Send logs"));
66         _send_logs->SetValue (true);
67         _table->Add (_send_logs, 1, wxEXPAND);
68         _table->AddSpacer (0);
69
70         add_label_to_sizer (_table, this, _("Your email address"), true);
71         _email = new wxTextCtrl (this, wxID_ANY, wxT (""));
72         _email->SetValue (std_to_wx (Config::instance()->kdm_from ()));
73         _table->Add (_email, 1, wxEXPAND);
74
75         /* We can't use Wrap() here as it doesn't work with markup:
76          * http://trac.wxwidgets.org/ticket/13389
77          */
78
79         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>");
80         wxString out;
81         int const width = 45;
82         int current = 0;
83         for (size_t i = 0; i < in.Length(); ++i) {
84                 if (in[i] == ' ' && current >= width) {
85                         out += '\n';
86                         current = 0;
87                 } else {
88                         out += in[i];
89                         ++current;
90                 }
91         }
92
93         wxStaticText* n = new StaticText (this, wxT (""));
94         n->SetLabelMarkup (out);
95         _table->AddSpacer (0);
96         _table->Add (n, 1, wxEXPAND);
97
98         _overall_sizer->Layout ();
99         _overall_sizer->SetSizeHints (this);
100 }
101
102 void
103 ReportProblemDialog::report ()
104 {
105         if (_email->GetValue().IsEmpty ()) {
106                 error_dialog (this, _("Please enter an email address so that we can contact you with any queries about the problem."));
107                 return;
108         }
109
110         if (_email->GetValue() == "carl@dcpomatic.com" || _email->GetValue() == "cth@carlh.net") {
111                 error_dialog (this, wxString::Format (_("Enter your email address for the contact, not %s"), _email->GetValue().data()));
112                 return;
113         }
114
115         JobManager::instance()->add (shared_ptr<Job> (new SendProblemReportJob (_film, wx_to_std (_email->GetValue ()), wx_to_std (_summary->GetValue ()))));
116 }