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