Extract all uses of DCP-o-matic name to allow branding.
[dcpomatic.git] / src / lib / send_problem_report_job.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 "compose.hpp"
23 #include "cross.h"
24 #include "email.h"
25 #include "environment_info.h"
26 #include "film.h"
27 #include "film.h"
28 #include "log.h"
29 #include "send_problem_report_job.h"
30 #include "variant.h"
31 #include "version.h"
32 #include <libxml++/libxml++.h>
33
34 #include "i18n.h"
35
36
37 using std::list;
38 using std::shared_ptr;
39 using std::string;
40
41
42 /** @param film Film that the problem is with, or 0.
43  *  @param from Email address to use for From:
44  *  @param summary Summary of the problem.
45  */
46 SendProblemReportJob::SendProblemReportJob (
47         shared_ptr<const Film> film,
48         string from,
49         string summary
50         )
51         : Job (film)
52         , _from (from)
53         , _summary (summary)
54 {
55
56 }
57
58
59 SendProblemReportJob::~SendProblemReportJob ()
60 {
61         stop_thread ();
62 }
63
64
65 string
66 SendProblemReportJob::name () const
67 {
68         if (!_film) {
69                 return _("Email problem report");
70         }
71
72         return String::compose (_("Email problem report for %1"), _film->name());
73 }
74
75
76 string
77 SendProblemReportJob::json_name () const
78 {
79         return N_("send_problem_report");
80 }
81
82
83 void
84 SendProblemReportJob::run ()
85 {
86         sub (_("Sending email"));
87         set_progress_unknown ();
88
89         string body = _summary + "\n\n";
90
91         body += "Version: " + string(dcpomatic_version) + " " + string(dcpomatic_git_commit) + "\n\n";
92
93         for (auto i: environment_info ()) {
94                 body += i + "\n";
95         }
96
97         body += "\n";
98
99         if (_film) {
100                 body += "log head and tail:\n";
101                 body += "---<8----\n";
102                 body += _film->log()->head_and_tail (4096);
103                 body += "---<8----\n\n";
104
105                 add_file (body, "ffprobe.log");
106
107                 body += "---<8----\n";
108                 body += _film->metadata()->write_to_string_formatted("UTF-8");
109                 body += "---<8----\n";
110         }
111
112         Email email(_from, {"carl@dcpomatic.com"}, variant::insert_dcpomatic("%1 problem report"), body);
113         email.send("main.carlh.net", 2525, EmailProtocol::STARTTLS);
114
115         set_progress (1);
116         set_state (FINISHED_OK);
117 }
118
119
120 void
121 SendProblemReportJob::add_file (string& body, boost::filesystem::path file) const
122 {
123         body += file.string() + ":\n";
124         body += "---<8----\n";
125         try {
126                 body += dcp::file_to_string (_film->file(file));
127         } catch (...) {
128                 body += "[could not be read]\n";
129         }
130         body += "---<8----\n\n";
131 }