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