Add comment.
[dcpomatic.git] / src / wx / report_problem_dialog.cc
1 /*
2     Copyright (C) 2014-2015 Carl Hetherington <cth@carlh.net>
3
4     This program is free software; you can redistribute it and/or modify
5     it under the terms of the GNU General Public License as published by
6     the Free Software Foundation; either version 2 of the License, or
7     (at your option) any later version.
8
9     This program is distributed in the hope that it will be useful,
10     but WITHOUT ANY WARRANTY; without even the implied warranty of
11     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12     GNU General Public License for more details.
13
14     You should have received a copy of the GNU General Public License
15     along with this program; if not, write to the Free Software
16     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17
18 */
19
20 #include "report_problem_dialog.h"
21 #include "wx_util.h"
22 #include "lib/config.h"
23 #include "lib/job_manager.h"
24 #include "lib/send_problem_report_job.h"
25 #include <wx/sizer.h>
26
27 using std::string;
28 using boost::shared_ptr;
29
30 /** @param film Film that we are working on, or 0 */
31 ReportProblemDialog::ReportProblemDialog (wxWindow* parent, shared_ptr<Film> film)
32         : wxDialog (parent, wxID_ANY, _("Report A Problem"))
33         , _film (film)
34 {
35         _overall_sizer = new wxBoxSizer (wxVERTICAL);
36         SetSizer (_overall_sizer);
37
38         _table = new wxFlexGridSizer (2, DCPOMATIC_SIZER_X_GAP, DCPOMATIC_SIZER_Y_GAP);
39         _table->AddGrowableCol (1, 1);
40
41         _overall_sizer->Add (_table, 1, wxEXPAND | wxALL, DCPOMATIC_DIALOG_BORDER);
42
43         wxSizer* buttons = CreateSeparatedButtonSizer (wxOK | wxCANCEL);
44         if (buttons) {
45                 _overall_sizer->Add (buttons, wxSizerFlags().Expand().DoubleBorder());
46         }
47
48         wxString t = _("My problem is");
49         int flags = wxALIGN_TOP | wxLEFT | wxRIGHT;
50 #ifdef __WXOSX__
51         flags |= wxALIGN_RIGHT;
52         t += wxT (":");
53 #endif
54         wxStaticText* m = new wxStaticText (this, wxID_ANY, t);
55         _table->Add (m, 1, flags, 6);
56
57         _summary = new wxTextCtrl (this, wxID_ANY, wxT (""), wxDefaultPosition, wxSize (320, 240), wxTE_MULTILINE);
58         _table->Add (_summary, 1, wxEXPAND | wxALIGN_TOP);
59
60         _send_logs = new wxCheckBox (this, wxID_ANY, _("Send logs"));
61         _send_logs->SetValue (true);
62         _table->Add (_send_logs, 1, wxEXPAND);
63         _table->AddSpacer (0);
64
65         add_label_to_sizer (_table, this, _("Contact email"), true);
66         _email = new wxTextCtrl (this, wxID_ANY, wxT (""));
67         _email->SetValue (std_to_wx (Config::instance()->kdm_from ()));
68         _table->Add (_email, 1, wxEXPAND);
69
70         _overall_sizer->Layout ();
71         _overall_sizer->SetSizeHints (this);
72 }
73
74 void
75 ReportProblemDialog::report ()
76 {
77         if (_email->GetValue().IsEmpty ()) {
78                 error_dialog (this, _("Please enter an email address so that we can contact you with any queries about the problem."));
79                 return;
80         }
81
82         JobManager::instance()->add (shared_ptr<Job> (new SendProblemReportJob (_film, wx_to_std (_email->GetValue ()), wx_to_std (_summary->GetValue ()))));
83 }