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/>.
23 #include "message_dialog.h"
24 #include "static_text.h"
25 #include "check_box.h"
26 #include "dcpomatic_button.h"
28 #include "lib/job_manager.h"
29 #include "lib/compose.hpp"
30 #include "lib/config.h"
31 #include "lib/send_notification_email_job.h"
32 #include "lib/transcode_job.h"
33 #include "lib/analyse_audio_job.h"
35 #include <boost/algorithm/string.hpp>
39 using std::shared_ptr;
41 using std::dynamic_pointer_cast;
43 JobView::JobView (shared_ptr<Job> job, wxWindow* parent, wxWindow* container, wxFlexGridSizer* table)
47 , _container (container)
56 int n = insert_position ();
58 _gauge_message = new wxBoxSizer (wxVERTICAL);
59 _gauge = new wxGauge (_container, wxID_ANY, 100);
60 /* This seems to be required to allow the gauge to shrink under OS X */
61 _gauge->SetMinSize (wxSize (0, -1));
62 _gauge_message->Add (_gauge, 0, wxEXPAND | wxLEFT | wxRIGHT);
63 _message = new StaticText (_container, wxT(" \n "), wxDefaultPosition, wxDefaultSize, wxST_ELLIPSIZE_MIDDLE);
64 _gauge_message->Add (_message, 1, wxEXPAND | wxALL, 6);
65 _table->Insert (n, _gauge_message, 1, wxEXPAND | wxLEFT | wxRIGHT);
68 _buttons = new wxBoxSizer (wxHORIZONTAL);
70 _cancel = new Button (_container, _("Cancel"));
71 _cancel->Bind (wxEVT_BUTTON, &JobView::cancel_clicked, this);
72 _buttons->Add (_cancel, 1, wxALIGN_CENTER_VERTICAL | wxRIGHT, DCPOMATIC_BUTTON_STACK_GAP);
74 _details = new Button (_container, _("Details..."));
75 _details->Bind (wxEVT_BUTTON, &JobView::details_clicked, this);
76 _details->Enable (false);
77 _buttons->Add (_details, 1, wxALIGN_CENTER_VERTICAL | wxRIGHT, DCPOMATIC_BUTTON_STACK_GAP);
79 finish_setup (_container, _buttons);
81 _controls = new wxBoxSizer (wxVERTICAL);
82 _controls->Add (_buttons);
83 _notify = new CheckBox (_container, _("Notify when complete"));
84 _notify->Bind (wxEVT_CHECKBOX, bind (&JobView::notify_clicked, this));
85 _notify->SetValue (Config::instance()->default_notify());
86 _controls->Add (_notify, 0, wxTOP, DCPOMATIC_BUTTON_STACK_GAP);
88 _table->Insert (n, _controls, 1, wxALIGN_CENTER_VERTICAL | wxALL, 3);
90 _progress_connection = _job->Progress.connect (boost::bind (&JobView::progress, this));
91 _finished_connection = _job->Finished.connect (boost::bind (&JobView::finished, this));
99 JobView::maybe_pulse ()
101 if (_gauge && _job->running() && !_job->progress()) {
109 string whole = "<b>" + _job->name () + "</b>\n";
110 if (!_job->sub_name().empty ()) {
111 whole += _job->sub_name() + " ";
113 string s = _job->status ();
114 /* Watch out for < > in the error string */
115 boost::algorithm::replace_all (s, "<", "<");
116 boost::algorithm::replace_all (s, ">", ">");
118 if (whole != _last_message) {
119 _message->SetLabelMarkup (std_to_wx (whole));
120 /* This hack fixes the size of _message on OS X */
121 _message->InvalidateBestSize ();
122 _message->SetSize (_message->GetBestSize ());
123 _gauge_message->Layout ();
124 _last_message = whole;
126 if (_job->progress ()) {
127 _gauge->SetValue (min (100.0f, _job->progress().get() * 100));
136 if (!_job->finished_cancelled ()) {
137 _gauge->SetValue (100);
140 _cancel->Enable (false);
141 _notify->Enable (false);
142 if (!_job->error_details().empty ()) {
143 _details->Enable (true);
146 if (_job->message()) {
147 MessageDialog* d = new MessageDialog (_parent, _job->name(), _job->message().get());
152 if ((dynamic_pointer_cast<TranscodeJob>(_job) || dynamic_pointer_cast<AnalyseAudioJob>(_job)) && _notify->GetValue()) {
153 if (Config::instance()->notification(Config::MESSAGE_BOX)) {
154 wxMessageBox (std_to_wx(_job->name() + ": " + _job->status()), _("DCP-o-matic"), wxICON_INFORMATION);
156 if (Config::instance()->notification(Config::EMAIL)) {
157 string body = Config::instance()->notification_email();
158 boost::algorithm::replace_all (body, "$JOB_NAME", _job->name());
159 boost::algorithm::replace_all (body, "$JOB_STATUS", _job->status());
160 JobManager::instance()->add_after (_job, shared_ptr<Job> (new SendNotificationEmailJob (body)));
166 JobView::details_clicked (wxCommandEvent &)
168 string s = _job->error_summary();
169 s[0] = toupper (s[0]);
170 error_dialog (_parent, std_to_wx(s), std_to_wx(_job->error_details()));
174 JobView::cancel_clicked (wxCommandEvent &)
176 if (confirm_dialog (_parent, _("Are you sure you want to cancel this job?"))) {
182 JobView::insert (int pos)
184 _table->Insert (pos, _gauge_message, 1, wxEXPAND | wxLEFT | wxRIGHT);
185 _table->Insert (pos + 1, _controls, 1, wxALIGN_CENTER_VERTICAL | wxALL, 3);
192 _table->Detach (_gauge_message);
193 _table->Detach (_controls);
197 JobView::notify_clicked ()
199 Config::instance()->set_default_notify (_notify->GetValue ());