Merge branch '2.0' of ssh://main.carlh.net/home/carl/git/dcpomatic into 2.0
[dcpomatic.git] / src / wx / report_problem_dialog.cc
1 /*
2     Copyright (C) 2014 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 ReportProblemDialog::ReportProblemDialog (wxWindow* parent, shared_ptr<Film> film)
31         : wxDialog (parent, wxID_ANY, _("Report A Problem"))
32         , _film (film)
33 {
34         _overall_sizer = new wxBoxSizer (wxVERTICAL);
35         SetSizer (_overall_sizer);
36
37         _table = new wxFlexGridSizer (2, DCPOMATIC_SIZER_X_GAP, DCPOMATIC_SIZER_Y_GAP);
38         _table->AddGrowableCol (1, 1);
39
40         _overall_sizer->Add (_table, 1, wxEXPAND | wxALL, DCPOMATIC_DIALOG_BORDER);
41
42         wxSizer* buttons = CreateSeparatedButtonSizer (wxOK | wxCANCEL);
43         if (buttons) {
44                 _overall_sizer->Add (buttons, wxSizerFlags().Expand().DoubleBorder());
45         }
46
47         wxString t = _("My problem is");
48         int flags = wxALIGN_TOP | wxLEFT | wxRIGHT;
49 #ifdef __WXOSX__
50         if (left) {
51                 flags |= wxALIGN_RIGHT;
52                 t += wxT (":");
53         }
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         _overall_sizer->Layout ();
72         _overall_sizer->SetSizeHints (this);
73 }
74
75 void
76 ReportProblemDialog::report ()
77 {
78         if (_email->GetValue().IsEmpty ()) {
79                 error_dialog (this, _("Please enter an email address so that we can contact you with any queries about the problem."));
80                 return;
81         }
82
83         JobManager::instance()->add (shared_ptr<Job> (new SendProblemReportJob (_film, wx_to_std (_email->GetValue ()), wx_to_std (_summary->GetValue ()))));
84 }