No-op; fix GPL address and use the explicit-program-name version.
[dcpomatic.git] / src / lib / send_problem_report_job.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 "send_problem_report_job.h"
22 #include "compose.hpp"
23 #include "film.h"
24 #include "cross.h"
25 #include "film.h"
26 #include "log.h"
27 #include "version.h"
28 #include "emailer.h"
29 #include "environment_info.h"
30 #include <boost/foreach.hpp>
31
32 #include "i18n.h"
33
34 using std::string;
35 using std::list;
36 using boost::shared_ptr;
37
38 /** @param film Film thta the problem is with, or 0 */
39 SendProblemReportJob::SendProblemReportJob (
40         shared_ptr<const Film> film,
41         string from,
42         string summary
43         )
44         : Job (film)
45         , _from (from)
46         , _summary (summary)
47 {
48
49 }
50
51 string
52 SendProblemReportJob::name () const
53 {
54         if (!_film) {
55                 return _("Email problem report");
56         }
57
58         return String::compose (_("Email problem report for %1"), _film->name());
59 }
60
61 string
62 SendProblemReportJob::json_name () const
63 {
64         return N_("send_problem_report");
65 }
66
67 void
68 SendProblemReportJob::run ()
69 {
70         sub (_("Sending email"));
71         set_progress_unknown ();
72
73         string body = _summary + "\n\n";
74
75         body += "Version: " + string (dcpomatic_version) + " " + string (dcpomatic_git_commit) + "\n\n";
76
77         BOOST_FOREACH (string i, environment_info ()) {
78                 body += i + "\n";
79         }
80
81         body += "\n";
82
83         if (_film) {
84                 body += "log head and tail:\n";
85                 body += "---<8----\n";
86                 body += _film->log()->head_and_tail (4096);
87                 body += "---<8----\n\n";
88
89                 add_file (body, "ffprobe.log");
90                 add_file (body, "metadata.xml");
91         }
92
93         list<string> to;
94         to.push_back ("carl@dcpomatic.com");
95
96         Emailer emailer (_from, to, "DCP-o-matic problem report", body);
97         emailer.send ("main.carlh.net", 2525);
98
99         set_progress (1);
100         set_state (FINISHED_OK);
101 }
102
103 void
104 SendProblemReportJob::add_file (string& body, boost::filesystem::path file) const
105 {
106         FILE* f = fopen_boost (_film->file (file), "r");
107         if (!f) {
108                 return;
109         }
110
111         body += file.string() + ":\n";
112         body += "---<8----\n";
113         uintmax_t const size = boost::filesystem::file_size (_film->file (file));
114         char* buffer = new char[size + 1];
115         int const N = fread (buffer, 1, size, f);
116         buffer[N] = '\0';
117         body += buffer;
118         delete[] buffer;
119         body += "---<8----\n\n";
120         fclose (f);
121 }