2 Copyright (C) 2012-2019 Carl Hetherington <cth@carlh.net>
4 This file is part of DCP-o-matic.
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.
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.
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/>.
22 #include "check_box.h"
23 #include "dcpomatic_button.h"
25 #include "message_dialog.h"
26 #include "static_text.h"
28 #include "lib/analyse_audio_job.h"
29 #include "lib/compose.hpp"
30 #include "lib/config.h"
32 #include "lib/job_manager.h"
33 #include "lib/send_notification_email_job.h"
34 #include "lib/transcode_job.h"
35 #include <dcp/warnings.h>
36 LIBDCP_DISABLE_WARNINGS
38 LIBDCP_ENABLE_WARNINGS
39 #include <boost/algorithm/string.hpp>
43 using std::shared_ptr;
48 JobView::JobView (shared_ptr<Job> job, wxWindow* parent, wxWindow* container, wxFlexGridSizer* table)
52 , _container (container)
62 int n = insert_position ();
64 _gauge_message = new wxBoxSizer (wxVERTICAL);
65 _gauge = new wxGauge (_container, wxID_ANY, 100);
66 /* This seems to be required to allow the gauge to shrink under OS X */
67 _gauge->SetMinSize (wxSize (0, -1));
68 _gauge_message->Add (_gauge, 0, wxEXPAND | wxLEFT | wxRIGHT);
69 _message = new StaticText (_container, wxT(" \n "), wxDefaultPosition, wxDefaultSize, wxST_ELLIPSIZE_MIDDLE);
70 _gauge_message->Add (_message, 1, wxEXPAND | wxALL, 6);
71 _table->Insert (n, _gauge_message, 1, wxEXPAND | wxLEFT | wxRIGHT);
74 _buttons = new wxBoxSizer (wxHORIZONTAL);
76 _cancel = new Button (_container, _("Cancel"));
77 _cancel->Bind (wxEVT_BUTTON, &JobView::cancel_clicked, this);
78 _buttons->Add (_cancel, 1, wxALIGN_CENTER_VERTICAL | wxRIGHT, DCPOMATIC_BUTTON_STACK_GAP);
80 _details = new Button (_container, _("Details..."));
81 _details->Bind (wxEVT_BUTTON, &JobView::details_clicked, this);
82 _details->Enable (false);
83 _buttons->Add (_details, 1, wxALIGN_CENTER_VERTICAL | wxRIGHT, DCPOMATIC_BUTTON_STACK_GAP);
85 finish_setup (_container, _buttons);
87 _controls = new wxBoxSizer (wxVERTICAL);
88 _controls->Add (_buttons);
89 _notify = new CheckBox (_container, _("Notify when complete"));
90 _notify->bind(&JobView::notify_clicked, this);
91 _notify->SetValue (Config::instance()->default_notify());
92 _controls->Add (_notify, 0, wxTOP, DCPOMATIC_BUTTON_STACK_GAP);
94 _table->Insert (n, _controls, 1, wxALIGN_CENTER_VERTICAL | wxALL, 3);
96 _progress_connection = _job->Progress.connect (boost::bind (&JobView::progress, this));
97 _finished_connection = _job->Finished.connect (boost::bind (&JobView::finished, this));
106 JobView::maybe_pulse ()
108 if (_gauge && _job->running()) {
109 auto elapsed = _job->seconds_since_last_progress_update();
110 if (!_job->progress() || !elapsed || *elapsed > 2) {
120 string whole = "<b>" + _job->name () + "</b>\n";
121 if (!_job->sub_name().empty ()) {
122 whole += _job->sub_name() + " ";
124 auto s = _job->status ();
125 /* Watch out for < > in the error string */
126 boost::algorithm::replace_all (s, "<", "<");
127 boost::algorithm::replace_all (s, ">", ">");
129 if (whole != _last_message) {
130 _message->SetLabelMarkup (std_to_wx (whole));
131 /* This hack fixes the size of _message on OS X */
132 _message->InvalidateBestSize ();
133 _message->SetSize (_message->GetBestSize ());
134 _gauge_message->Layout ();
135 _last_message = whole;
137 if (_job->progress ()) {
138 _gauge->SetValue (min (100.0f, _job->progress().get() * 100));
148 if (!_job->finished_cancelled ()) {
149 _gauge->SetValue (100);
152 _cancel->Enable (false);
153 _notify->Enable (false);
154 if (!_job->error_details().empty ()) {
155 _details->Enable (true);
158 if (_job->message()) {
159 MessageDialog dialog(_parent, std_to_wx(_job->name()), std_to_wx(_job->message().get()));
163 if (_job->enable_notify() && _notify->GetValue()) {
164 if (Config::instance()->notification(Config::MESSAGE_BOX)) {
165 wxMessageBox (std_to_wx(_job->name() + ": " + _job->status()), _("DCP-o-matic"), wxICON_INFORMATION);
167 if (Config::instance()->notification(Config::EMAIL)) {
168 string body = Config::instance()->notification_email();
169 boost::algorithm::replace_all (body, "$JOB_NAME", _job->name());
170 boost::algorithm::replace_all (body, "$JOB_STATUS", _job->status());
171 JobManager::instance()->add_after (_job, shared_ptr<Job> (new SendNotificationEmailJob (body)));
178 JobView::details_clicked (wxCommandEvent &)
180 auto s = _job->error_summary();
181 s[0] = toupper (s[0]);
182 error_dialog (_parent, std_to_wx(s), std_to_wx(_job->error_details()));
187 JobView::cancel_clicked (wxCommandEvent &)
189 if (confirm_dialog (_parent, _("Are you sure you want to cancel this job?"))) {
196 JobView::insert (int pos)
198 _table->Insert (pos, _gauge_message, 1, wxEXPAND | wxLEFT | wxRIGHT);
199 _table->Insert (pos + 1, _controls, 1, wxALIGN_CENTER_VERTICAL | wxALL, 3);
207 _table->Detach (_gauge_message);
208 _table->Detach (_controls);
213 JobView::notify_clicked ()
215 Config::instance()->set_default_notify (_notify->GetValue ());